From ce1b3a25bf09589c13636d467515d9b64284dcc3 Mon Sep 17 00:00:00 2001 From: joethei Date: Sat, 18 Feb 2017 18:08:45 +0100 Subject: [PATCH] + translated messages + first unit tests --- .ci/settings.xml | 2 +- Commons.iml | 6 +- pom.xml | 38 ++++------- .../java/eu/univento/commons/Commons.java | 3 +- .../configuration/ConfigurationHandler.java | 2 +- .../commons/database/AsyncMongoDB.java | 12 ++-- .../univento/commons/database/AsyncMySQL.java | 4 +- .../commons/database/DatabaseManager.java | 2 + .../eu/univento/commons/database/MongoDB.java | 2 +- .../eu/univento/commons/database/MySQL.java | 2 +- .../commons/player/DatabasePlayer.java | 22 +++---- .../univento/commons/player/ban/BanData.java | 2 +- .../commons/player/ban/BanReason.java | 2 +- .../commons/player/kick/KickData.java | 2 +- .../player/language/MessageConstant.java | 6 +- .../commons/player/mute/MuteData.java | 2 +- .../commons/player/mute/MuteReason.java | 2 +- .../player/settings/PlayerSettings.java | 2 +- .../commons/player/uuid/UUIDFetcher.java | 2 +- .../commons/player/warn/WarnReason.java | 2 +- .../commons/security/SecurityHandler.java | 8 +-- src/main/resources/language_de.properties | 16 +++++ .../java/eu/univento/commons/CommonsTest.java | 63 +++++++++++++++++++ 23 files changed, 140 insertions(+), 64 deletions(-) create mode 100644 src/test/java/eu/univento/commons/CommonsTest.java diff --git a/.ci/settings.xml b/.ci/settings.xml index 6a2eed7..9c09dd4 100644 --- a/.ci/settings.xml +++ b/.ci/settings.xml @@ -1,5 +1,5 @@ diff --git a/Commons.iml b/Commons.iml index 0570d92..b9ba292 100644 --- a/Commons.iml +++ b/Commons.iml @@ -6,6 +6,7 @@ + @@ -18,8 +19,6 @@ - - @@ -32,5 +31,8 @@ + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml index f4aa5eb..512989a 100644 --- a/pom.xml +++ b/pom.xml @@ -1,7 +1,5 @@ - + 4.0.0 eu.univento @@ -9,7 +7,6 @@ 1.0-SNAPSHOT univento.eu Common Code - https://development.univento.eu/docs/Commons @@ -45,27 +42,6 @@ - - org.apache.maven.plugins - maven-site-plugin - 3.4 - - en - - - - org.apache.maven.plugins - maven-javadoc-plugin - 2.10.4 - - - attach-javadocs - - javadoc - - - - @@ -76,6 +52,7 @@ + org.projectlombok @@ -152,5 +129,16 @@ slack-webhook 1.2.1 + + com.github.nsp + JSkills + master-0.9.0-g8b333ec-15 + + + junit + junit + 4.12 + test + \ No newline at end of file diff --git a/src/main/java/eu/univento/commons/Commons.java b/src/main/java/eu/univento/commons/Commons.java index ec94c55..30abf3f 100644 --- a/src/main/java/eu/univento/commons/Commons.java +++ b/src/main/java/eu/univento/commons/Commons.java @@ -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); diff --git a/src/main/java/eu/univento/commons/configuration/ConfigurationHandler.java b/src/main/java/eu/univento/commons/configuration/ConfigurationHandler.java index c21fd17..c8045d1 100644 --- a/src/main/java/eu/univento/commons/configuration/ConfigurationHandler.java +++ b/src/main/java/eu/univento/commons/configuration/ConfigurationHandler.java @@ -6,7 +6,7 @@ import java.util.Properties; /** * @author joethei - * @version 0.1 + * @version 1.0 */ public class ConfigurationHandler { diff --git a/src/main/java/eu/univento/commons/database/AsyncMongoDB.java b/src/main/java/eu/univento/commons/database/AsyncMongoDB.java index b944580..ccd808b 100644 --- a/src/main/java/eu/univento/commons/database/AsyncMongoDB.java +++ b/src/main/java/eu/univento/commons/database/AsyncMongoDB.java @@ -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 consumer) { + consumer.accept(mongoDB.getDatabase()); + } } \ No newline at end of file diff --git a/src/main/java/eu/univento/commons/database/AsyncMySQL.java b/src/main/java/eu/univento/commons/database/AsyncMySQL.java index 2d550ae..492767a 100644 --- a/src/main/java/eu/univento/commons/database/AsyncMySQL.java +++ b/src/main/java/eu/univento/commons/database/AsyncMySQL.java @@ -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 consumer) { executor.execute(() -> { - ResultSet result = null; + ResultSet result; result = mySQL.query(query); ResultSet finalResult = result; consumer.accept(finalResult); diff --git a/src/main/java/eu/univento/commons/database/DatabaseManager.java b/src/main/java/eu/univento/commons/database/DatabaseManager.java index 76a10dd..abd47c5 100644 --- a/src/main/java/eu/univento/commons/database/DatabaseManager.java +++ b/src/main/java/eu/univento/commons/database/DatabaseManager.java @@ -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; diff --git a/src/main/java/eu/univento/commons/database/MongoDB.java b/src/main/java/eu/univento/commons/database/MongoDB.java index 3b9a4fb..1b63e83 100644 --- a/src/main/java/eu/univento/commons/database/MongoDB.java +++ b/src/main/java/eu/univento/commons/database/MongoDB.java @@ -9,7 +9,7 @@ import java.util.Collections; /** * @author joethei - * @version 0.1 + * @version 1.0 */ public class MongoDB { diff --git a/src/main/java/eu/univento/commons/database/MySQL.java b/src/main/java/eu/univento/commons/database/MySQL.java index a85a665..5474a0d 100644 --- a/src/main/java/eu/univento/commons/database/MySQL.java +++ b/src/main/java/eu/univento/commons/database/MySQL.java @@ -10,7 +10,7 @@ import java.sql.SQLException; /** * @author joethei - * @version 0.1 + * @version 1.2 */ public class MySQL { diff --git a/src/main/java/eu/univento/commons/player/DatabasePlayer.java b/src/main/java/eu/univento/commons/player/DatabasePlayer.java index 97c9236..afb4485 100644 --- a/src/main/java/eu/univento/commons/player/DatabasePlayer.java +++ b/src/main/java/eu/univento/commons/player/DatabasePlayer.java @@ -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 muteCollection; private final MongoCollection 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 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 cursor = playerCollection.find(new Document("uuid", uuid.toString())); cursor.cursorType(CursorType.NonTailable); @@ -417,10 +417,10 @@ public class DatabasePlayer { } public ArrayList getArrayListFromDatabase(String name) { - return (ArrayList) getObjectFromDatbase(name); + return (ArrayList) getObjectFromDatabase(name); } public Map getMapFromDatabase(String name) { - return (Map) getObjectFromDatbase(name); + return (Map) getObjectFromDatabase(name); } } \ No newline at end of file diff --git a/src/main/java/eu/univento/commons/player/ban/BanData.java b/src/main/java/eu/univento/commons/player/ban/BanData.java index 336db1f..c76146f 100644 --- a/src/main/java/eu/univento/commons/player/ban/BanData.java +++ b/src/main/java/eu/univento/commons/player/ban/BanData.java @@ -11,7 +11,7 @@ import java.util.UUID; /** * @author joethei - * @version 0.1 + * @version 1.0 */ public class BanData { diff --git a/src/main/java/eu/univento/commons/player/ban/BanReason.java b/src/main/java/eu/univento/commons/player/ban/BanReason.java index 958f8bc..b152743 100644 --- a/src/main/java/eu/univento/commons/player/ban/BanReason.java +++ b/src/main/java/eu/univento/commons/player/ban/BanReason.java @@ -2,7 +2,7 @@ package eu.univento.commons.player.ban; /** * @author joethei - * @version 0.1 + * @version 1.0 */ public enum BanReason { diff --git a/src/main/java/eu/univento/commons/player/kick/KickData.java b/src/main/java/eu/univento/commons/player/kick/KickData.java index 4bca3c8..3e113ba 100644 --- a/src/main/java/eu/univento/commons/player/kick/KickData.java +++ b/src/main/java/eu/univento/commons/player/kick/KickData.java @@ -7,7 +7,7 @@ import java.util.UUID; /** * @author joethei - * @version 0.1 + * @version 1.0 */ public class KickData { diff --git a/src/main/java/eu/univento/commons/player/language/MessageConstant.java b/src/main/java/eu/univento/commons/player/language/MessageConstant.java index 3080eae..1c5b5b8 100644 --- a/src/main/java/eu/univento/commons/player/language/MessageConstant.java +++ b/src/main/java/eu/univento/commons/player/language/MessageConstant.java @@ -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; - } } \ No newline at end of file diff --git a/src/main/java/eu/univento/commons/player/mute/MuteData.java b/src/main/java/eu/univento/commons/player/mute/MuteData.java index 770e09d..9c45745 100644 --- a/src/main/java/eu/univento/commons/player/mute/MuteData.java +++ b/src/main/java/eu/univento/commons/player/mute/MuteData.java @@ -11,7 +11,7 @@ import java.util.UUID; /** * @author joethei - * @version 0.1 + * @version 1.0 */ public class MuteData { diff --git a/src/main/java/eu/univento/commons/player/mute/MuteReason.java b/src/main/java/eu/univento/commons/player/mute/MuteReason.java index c89eee4..9492ae7 100644 --- a/src/main/java/eu/univento/commons/player/mute/MuteReason.java +++ b/src/main/java/eu/univento/commons/player/mute/MuteReason.java @@ -2,7 +2,7 @@ package eu.univento.commons.player.mute; /** * @author joethei - * @version 0.1 + * @version 1.0 */ public enum MuteReason { diff --git a/src/main/java/eu/univento/commons/player/settings/PlayerSettings.java b/src/main/java/eu/univento/commons/player/settings/PlayerSettings.java index bb3a71d..bbe8dd8 100644 --- a/src/main/java/eu/univento/commons/player/settings/PlayerSettings.java +++ b/src/main/java/eu/univento/commons/player/settings/PlayerSettings.java @@ -7,7 +7,7 @@ import java.util.Map; /** * @author joethei - * @version 0.1 + * @version 1.0 */ public class PlayerSettings { diff --git a/src/main/java/eu/univento/commons/player/uuid/UUIDFetcher.java b/src/main/java/eu/univento/commons/player/uuid/UUIDFetcher.java index 3ac14e2..36b0a71 100644 --- a/src/main/java/eu/univento/commons/player/uuid/UUIDFetcher.java +++ b/src/main/java/eu/univento/commons/player/uuid/UUIDFetcher.java @@ -110,4 +110,4 @@ public class UUIDFetcher { this.name = name; } } -} +} \ No newline at end of file diff --git a/src/main/java/eu/univento/commons/player/warn/WarnReason.java b/src/main/java/eu/univento/commons/player/warn/WarnReason.java index 7f386fb..ad07236 100644 --- a/src/main/java/eu/univento/commons/player/warn/WarnReason.java +++ b/src/main/java/eu/univento/commons/player/warn/WarnReason.java @@ -4,7 +4,7 @@ import lombok.Getter; /** * @author joethei - * @version 0.1 + * @version 1.0 */ @Getter diff --git a/src/main/java/eu/univento/commons/security/SecurityHandler.java b/src/main/java/eu/univento/commons/security/SecurityHandler.java index db4bf6d..c06158e 100644 --- a/src/main/java/eu/univento/commons/security/SecurityHandler.java +++ b/src/main/java/eu/univento/commons/security/SecurityHandler.java @@ -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 consumer) { diff --git a/src/main/resources/language_de.properties b/src/main/resources/language_de.properties index 57f2bfe..4a18e23 100644 --- a/src/main/resources/language_de.properties +++ b/src/main/resources/language_de.properties @@ -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 diff --git a/src/test/java/eu/univento/commons/CommonsTest.java b/src/test/java/eu/univento/commons/CommonsTest.java new file mode 100644 index 0000000..c982bf0 --- /dev/null +++ b/src/test/java/eu/univento/commons/CommonsTest.java @@ -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(); + } + */ +} \ No newline at end of file