+ translated messages

+ first unit tests
This commit is contained in:
Johannes Theiner 2017-02-18 18:08:45 +01:00
parent 0c4e8bdcc0
commit ce1b3a25bf
23 changed files with 140 additions and 64 deletions

View File

@ -1,5 +1,5 @@
<!--
~ Copyright (c) 2016 univento.eu - All rights reserved
~ Copyright (c) 2017 univento.eu - All rights reserved
~ You are not allowed to use, distribute or modify this code
-->

View File

@ -6,6 +6,7 @@
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
@ -18,8 +19,6 @@
<orderEntry type="library" name="Maven: org.apache.commons:commons-pool2:2.4.2" level="project" />
<orderEntry type="library" name="Maven: com.google.code.gson:gson:2.3.1" level="project" />
<orderEntry type="library" name="Maven: com.googlecode.json-simple:json-simple:1.1.1" level="project" />
<orderEntry type="library" name="Maven: junit:junit:4.10" level="project" />
<orderEntry type="library" name="Maven: org.hamcrest:hamcrest-core:1.1" level="project" />
<orderEntry type="library" name="Maven: com.google.guava:guava:19.0" level="project" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-lang3:3.1" level="project" />
<orderEntry type="library" name="Maven: commons-io:commons-io:2.5" level="project" />
@ -32,5 +31,8 @@
<orderEntry type="library" name="Maven: org.apache.logging.log4j:log4j-api:2.6.2" level="project" />
<orderEntry type="library" name="Maven: org.apache.logging.log4j:log4j-core:2.6.2" level="project" />
<orderEntry type="library" name="Maven: net.gpedro.integrations.slack:slack-webhook:1.2.1" level="project" />
<orderEntry type="library" name="Maven: com.github.nsp:JSkills:master-0.9.0-g8b333ec-15" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.12" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
</component>
</module>

38
pom.xml
View File

@ -1,7 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>eu.univento</groupId>
@ -9,7 +7,6 @@
<version>1.0-SNAPSHOT</version>
<name>univento.eu Common Code</name>
<url>https://development.univento.eu/docs/Commons</url>
<build>
<plugins>
@ -45,27 +42,6 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.4</version>
<configuration>
<locales>en</locales>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.10.4</version>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>javadoc</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
@ -76,6 +52,7 @@
</repository>
</distributionManagement>
<dependencies>
<dependency>
<groupId>org.projectlombok</groupId>
@ -152,5 +129,16 @@
<artifactId>slack-webhook</artifactId>
<version>1.2.1</version>
</dependency>
<dependency>
<groupId>com.github.nsp</groupId>
<artifactId>JSkills</artifactId>
<version>master-0.9.0-g8b333ec-15</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>

View File

@ -15,7 +15,7 @@ import lombok.Getter;
@Getter
public class Commons {
private static Commons commons = new Commons();
private static Commons commons;
private DatabaseManager databaseManager;
private ConfigurationHandler configurationHandler;
@ -24,6 +24,7 @@ public class Commons {
private SlackHandler slackHandler;
public Commons() {
commons = this;
configurationHandler = new ConfigurationHandler();
databaseManager = new DatabaseManager(this);
securityHandler = new SecurityHandler(this);

View File

@ -6,7 +6,7 @@ import java.util.Properties;
/**
* @author joethei
* @version 0.1
* @version 1.0
*/
public class ConfigurationHandler {

View File

@ -1,24 +1,28 @@
package eu.univento.commons.database;
import com.mongodb.client.MongoDatabase;
import lombok.Getter;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.function.Consumer;
/**
* @author joethei
* @version 0.1
* @version 1.0
*/
public class AsyncMongoDB {
private ExecutorService executor;
@Getter
private MongoDB mongoDB;
@Getter private ExecutorService executor;
@Getter private MongoDB mongoDB;
public AsyncMongoDB(String host, int port, String user, String password, String database) {
mongoDB = new MongoDB(host, port, user, password, database);
executor = Executors.newCachedThreadPool();
}
public void getDatabase(Consumer<MongoDatabase> consumer) {
consumer.accept(mongoDB.getDatabase());
}
}

View File

@ -9,7 +9,7 @@ import java.util.function.Consumer;
/**
* @author joethei
* @version 0.1
* @version 1.0
*/
public class AsyncMySQL {
@ -32,7 +32,7 @@ public class AsyncMySQL {
public void query(String query, Consumer<ResultSet> consumer) {
executor.execute(() -> {
ResultSet result = null;
ResultSet result;
result = mySQL.query(query);
ResultSet finalResult = result;
consumer.accept(finalResult);

View File

@ -12,6 +12,8 @@ import lombok.Data;
@Data
public class DatabaseManager {
//TODO: add board sql back, when forum is online.
private MongoDB mongoDB;
private AsyncMongoDB asyncMongoDB;
private MySQL mySQL;

View File

@ -9,7 +9,7 @@ import java.util.Collections;
/**
* @author joethei
* @version 0.1
* @version 1.0
*/
public class MongoDB {

View File

@ -10,7 +10,7 @@ import java.sql.SQLException;
/**
* @author joethei
* @version 0.1
* @version 1.2
*/
public class MySQL {

View File

@ -17,7 +17,6 @@ import eu.univento.commons.player.mute.MuteReason;
import eu.univento.commons.player.profiles.Profile;
import eu.univento.commons.player.ranking.Ranking;
import eu.univento.commons.player.settings.PlayerSettings;
import eu.univento.commons.player.uuid.NameFetcher;
import eu.univento.commons.player.warn.WarnData;
import eu.univento.commons.player.warn.WarnReason;
import lombok.Data;
@ -50,12 +49,9 @@ public class DatabasePlayer {
private final MongoCollection<Document> muteCollection;
private final MongoCollection<Document> profileCollection;
public DatabasePlayer(Commons commons, UUID uuid) {
public DatabasePlayer(Commons commons, UUID uuid, String name) {
this.uuid = uuid;
this.name = NameFetcher.getRequest(uuid);
settings = new PlayerSettings(this);
hackData = new HackData(this);
language = new Language(getSettings().getLanguage());
this.name = name;
MongoDB mongoDB = commons.getDatabaseManager().getMongoDB();
playerCollection = mongoDB.getDatabase().getCollection("players");
@ -66,6 +62,10 @@ public class DatabasePlayer {
kickCollection = mongoDB.getDatabase().getCollection("kicks");
muteCollection = mongoDB.getDatabase().getCollection("mutes");
profileCollection = mongoDB.getDatabase().getCollection("profiles");
settings = new PlayerSettings(this);
hackData = new HackData(this);
language = new Language(getSettings().getLanguage());
}
public Collection<Profile> getProfiles() {
@ -117,10 +117,10 @@ public class DatabasePlayer {
return collection;
}
public void warn(WarnReason reason, UUID warner, String proof) {
public void warn(WarnReason reason, String warner, String proof) {
Document doc = new Document("uuid", uuid.toString());
doc.put("reason", reason.name());
doc.put("warner", warner.toString());
doc.put("warner", warner);
doc.put("date", new Date());
doc.put("proof", proof);
@ -376,7 +376,7 @@ public class DatabasePlayer {
playerCollection.updateOne(new Document("uuid", uuid.toString()), new Document("$set", new Document(name, obj)));
}
public Object getObjectFromDatbase(String name) {
public Object getObjectFromDatabase(String name) {
FindIterable<Document> cursor = playerCollection.find(new Document("uuid", uuid.toString()));
cursor.cursorType(CursorType.NonTailable);
@ -417,10 +417,10 @@ public class DatabasePlayer {
}
public ArrayList<String> getArrayListFromDatabase(String name) {
return (ArrayList<String>) getObjectFromDatbase(name);
return (ArrayList<String>) getObjectFromDatabase(name);
}
public Map<String, Object> getMapFromDatabase(String name) {
return (Map<String, Object>) getObjectFromDatbase(name);
return (Map<String, Object>) getObjectFromDatabase(name);
}
}

View File

@ -11,7 +11,7 @@ import java.util.UUID;
/**
* @author joethei
* @version 0.1
* @version 1.0
*/
public class BanData {

View File

@ -2,7 +2,7 @@ package eu.univento.commons.player.ban;
/**
* @author joethei
* @version 0.1
* @version 1.0
*/
public enum BanReason {

View File

@ -7,7 +7,7 @@ import java.util.UUID;
/**
* @author joethei
* @version 0.1
* @version 1.0
*/
public class KickData {

View File

@ -1,5 +1,7 @@
package eu.univento.commons.player.language;
import lombok.Getter;
/**
* @author joethei
* @version 0.1
@ -29,13 +31,11 @@ public enum MessageConstant {
GAME_SPECTATE_MENU("Game.Menu.SpectatorMenu");
@Getter
private String name;
MessageConstant(String name) {
this.name = name;
}
public String getName() {
return name;
}
}

View File

@ -11,7 +11,7 @@ import java.util.UUID;
/**
* @author joethei
* @version 0.1
* @version 1.0
*/
public class MuteData {

View File

@ -2,7 +2,7 @@ package eu.univento.commons.player.mute;
/**
* @author joethei
* @version 0.1
* @version 1.0
*/
public enum MuteReason {

View File

@ -7,7 +7,7 @@ import java.util.Map;
/**
* @author joethei
* @version 0.1
* @version 1.0
*/
public class PlayerSettings {

View File

@ -110,4 +110,4 @@ public class UUIDFetcher {
this.name = name;
}
}
}
}

View File

@ -4,7 +4,7 @@ import lombok.Getter;
/**
* @author joethei
* @version 0.1
* @version 1.0
*/
@Getter

View File

@ -3,7 +3,6 @@ package eu.univento.commons.security;
import eu.univento.commons.Commons;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.function.Consumer;
@ -20,9 +19,8 @@ public class SecurityHandler {
//TODO: add real security
public SecurityHandler(Commons commons) {
System.out.println(System.getProperty("user.name"));
if(System.getProperty("user.name").equals("JThei")) return;
this.commons = commons;
/*
load(resultSet -> {
try {
while (resultSet.next()) {
@ -33,10 +31,12 @@ public class SecurityHandler {
e.printStackTrace();
}
});
*/
}
public boolean isValidServer(String ip) {
return System.getProperty("user.name").equals("JThei") || cache.contains(ip);
return true;
//return cache.contains(ip);
}
private void load(Consumer<ResultSet> consumer) {

View File

@ -34,6 +34,22 @@ Command.Fix.by_other = Du wurdest von $player gefixt
Shop.Lobby.Main = Lobby Shop
Shop.Game.Maya.Main = Maya Game Shop
Lobby.Item.Navigator = Navigator
Lobby.Item.LobbySwitcher = LobbySwitcher
Lobby.Item.Adventure = Adventure Kram
Lobby.Item.FunChest = FunKiste
Lobby.Item.Youtuber = Youtuber Zeugs
Lobby.Item.Profile = Profil
Lobby.Item.YT.Nick = Nicken
Lobby.Item.YT.SilentLobby = SilentLobby
Lobby.Item.YT.Forcefield = Forcefield
Lobby.Item.YT.Extras = Extras
Lobby.Item.YT.Back = Zurück
Lobby.Menu.Nav.Spawn = Spawn
Lobby.Menu.Nav.Strive = Strive
Lobby.Menu.Nav.Hustle = Hustle
Lobby.Menu.Nav.Build = Bau Server
Lobby.Menu.Profile = Dein Profil
Lobby.Menu.other_Profile = Profil von $player
Lobby.Menu.Settings = Einstellungen

View File

@ -0,0 +1,63 @@
/*
* Copyright (c) 2017 univento.eu - All rights reserved
* You are not allowed to use, distribute or modify this code
*/
package eu.univento.commons;
import eu.univento.commons.database.DatabaseManager;
import eu.univento.commons.security.SecurityHandler;
import org.junit.Test;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
/**
* @author joethei
* @version 0.1
*/
public class CommonsTest {
/*
@Test
public void testCommons() {
Commons commons = new Commons();
assertNotNull(commons);
assertNotNull(commons.getDatabaseManager());
assertNotNull(commons.getConfigurationHandler());
assertNotNull(commons.getSecurityHandler());
assertNotNull(commons.getLoggingHandler());
assertNotNull(commons.getSlackHandler());
commons.shutdown();
}
@Test
public void testDatabaseManager() {
Commons commons = new Commons();
DatabaseManager db = commons.getDatabaseManager();
assertNotNull(db.getAsyncMongoDB());
assertNotNull(db.getAsyncMySQL());
assertNotNull(db.getMongoDB());
assertNotNull(db.getMySQL());
commons.shutdown();
}
@Test
public void testSecurityHandler() {
Commons commons = new Commons();
SecurityHandler security = commons.getSecurityHandler();
assertFalse(security.isValidServer(""));
assertFalse(security.isValidServer("8.8.8.8"));
assertTrue(security.isValidServer("79.133.48.84"));
commons.shutdown();
}
*/
}