From 1fa03cb94a662fa0c45b2c8e0c5d7ff2d7936946 Mon Sep 17 00:00:00 2001 From: joethei Date: Sat, 17 Sep 2016 11:55:07 +0200 Subject: [PATCH] added Ranking System --- Commons.iml | 13 +- pom.xml | 82 +++----- .../java/eu/univento/commons/Commons.java | 1 - .../commons/database/DatabaseManager.java | 1 + .../eu/univento/commons/database/MySQL.java | 19 +- .../eu/univento/commons/helpers/Location.java | 48 +++++ .../commons/logging/LoggingHandler.java | 4 - .../commons/player/DatabasePlayer.java | 27 ++- .../java/eu/univento/commons/player/Rank.java | 28 +-- .../univento/commons/player/ban/BanData.java | 2 + .../commons/player/ban/BanReason.java | 37 ++-- .../commons/player/hacks/HackData.java | 196 ++++++++++++++++++ .../commons/player/kick/KickData.java | 2 + .../commons/player/kick/KickReason.java | 1 + .../commons/player/mute/MuteData.java | 27 +++ .../commons/player/mute/MuteReason.java | 19 +- .../player/profiles/PlayerProfiles.java | 24 --- .../commons/player/profiles/Profile.java | 1 + .../commons/player/ranking/PlayerRanking.java | 20 ++ .../commons/player/ranking/Ranking.java | 41 ++++ .../commons/player/warn/WarnData.java | 6 +- .../commons/security/SecurityHandler.java | 4 +- ...enicator.java => CustomAuthenticator.java} | 9 +- .../java/eu/univento/commons/utils/Maths.java | 3 +- src/main/resources/language_de.properties | 2 +- 25 files changed, 452 insertions(+), 165 deletions(-) create mode 100644 src/main/java/eu/univento/commons/helpers/Location.java create mode 100644 src/main/java/eu/univento/commons/player/hacks/HackData.java delete mode 100644 src/main/java/eu/univento/commons/player/profiles/PlayerProfiles.java create mode 100644 src/main/java/eu/univento/commons/player/ranking/PlayerRanking.java create mode 100644 src/main/java/eu/univento/commons/player/ranking/Ranking.java rename src/main/java/eu/univento/commons/updater/{CustomAuthenicator.java => CustomAuthenticator.java} (62%) diff --git a/Commons.iml b/Commons.iml index d174c78..16f4f79 100644 --- a/Commons.iml +++ b/Commons.iml @@ -6,27 +6,30 @@ - + - - + + + - + + - + + \ No newline at end of file diff --git a/pom.xml b/pom.xml index 8e4a8b4..4039e5c 100644 --- a/pom.xml +++ b/pom.xml @@ -66,53 +66,15 @@ - - com.github.wvengen - proguard-maven-plugin - 2.0.13 - - - package - - proguard - - - - - true - ${project.build.finalName}.jar - ${project.build.finalName}-small.jar - true - - - - - ${java.home}/lib/rt.jar - ${java.home}/lib/jce.jar - - - - Commons - eu.univento.commons - - - - - - - - net.sf.proguard - proguard-base - 5.2.1 - runtime - - - - + + org.projectlombok + lombok + 1.16.8 + org.mongodb mongo-java-driver @@ -123,6 +85,16 @@ mongodb-driver-async 3.2.2 + + org.mongodb.morphia + morphia + 1.2.1 + + + com.zaxxer + HikariCP + 2.4.5 + io.netty netty-all @@ -133,26 +105,15 @@ gson 2.3.1 - - com.zaxxer - HikariCP - 2.4.5 - compile - - - com.google.guava - guava - 19.0 - com.googlecode.json-simple json-simple 1.1.1 - joda-time - joda-time - 2.9.4 + com.google.guava + guava + 19.0 org.apache.logging.log4j @@ -172,7 +133,12 @@ commons-io commons-io - RELEASE + 2.5 + + + joda-time + joda-time + 2.9.4 \ 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 3734f82..665e9f3 100644 --- a/src/main/java/eu/univento/commons/Commons.java +++ b/src/main/java/eu/univento/commons/Commons.java @@ -40,7 +40,6 @@ public class Commons { public void shutdown() { getDatabaseManager().closeConnections(); - //loggingHandler.shutdown(); } } \ No newline at end of file diff --git a/src/main/java/eu/univento/commons/database/DatabaseManager.java b/src/main/java/eu/univento/commons/database/DatabaseManager.java index 79cf4d7..a61594d 100644 --- a/src/main/java/eu/univento/commons/database/DatabaseManager.java +++ b/src/main/java/eu/univento/commons/database/DatabaseManager.java @@ -17,6 +17,7 @@ public class DatabaseManager { public DatabaseManager(Commons commons) { ConfigurationHandler config = commons.getConfigurationHandler(); + //TODO: remove hardcoded variables mongoDB = new MongoDB(config.getString("MongoDB.Host"), config.getInteger("MongoDB.Port"), config.getString("MongoDB.Username"), config.getString("MongoDB.Password"), config.getString("MongoDB.Database")); asyncMongoDB = new AsyncMongoDB(config.getString("MongoDB.Host"), config.getInteger("MongoDB.Port"), config.getString("MongoDB.Username"), config.getString("MongoDB.Password"), config.getString("MongoDB.Database")); mySQL = new MySQL(config.getString("MySQL.Host"), config.getString("MySQL.Port"), config.getString("MySQL.Database"), config.getString("MySQL.Username"), config.getString("MySQL.Password")); diff --git a/src/main/java/eu/univento/commons/database/MySQL.java b/src/main/java/eu/univento/commons/database/MySQL.java index c87f4ee..ba75b88 100644 --- a/src/main/java/eu/univento/commons/database/MySQL.java +++ b/src/main/java/eu/univento/commons/database/MySQL.java @@ -13,20 +13,10 @@ import java.sql.SQLException; * @version 0.1 */ public class MySQL { - private final String username; - private final String database; - private final String password; - private final String port; - private final String hostname; private final HikariDataSource dataSource; public MySQL(String hostname, String port, String database, String username, String password) { - this.username = username; - this.database = database; - this.password = password; - this.port = port; - this.hostname = hostname; HikariConfig config = new HikariConfig(); config.setJdbcUrl("jdbc:mysql://" + hostname + ":" + port + "/" + database); config.setUsername(username); @@ -38,8 +28,13 @@ public class MySQL { dataSource = new HikariDataSource(config); } - void close() { - dataSource.close(); + public void close() { + try { + dataSource.getConnection().close(); + dataSource.close(); + } catch (SQLException e) { + e.printStackTrace(); + } } public HikariDataSource getDataSource() { diff --git a/src/main/java/eu/univento/commons/helpers/Location.java b/src/main/java/eu/univento/commons/helpers/Location.java new file mode 100644 index 0000000..a09c2e6 --- /dev/null +++ b/src/main/java/eu/univento/commons/helpers/Location.java @@ -0,0 +1,48 @@ +package eu.univento.commons.helpers; + +/** + * @author joethei + * @version 0.1 + */ +public class Location { + + private final String world; + private final double x; + private final double y; + private final double z; + private final float pitch; + private final float yaw; + + public Location(String world, double x, double y, double z, float pitch, float yaw) { + this.world = world; + this.x = x; + this.y = y; + this.z = z; + this.pitch = pitch; + this.yaw = yaw; + } + + public String getWorld() { + return world; + } + + public double getX() { + return x; + } + + public double getY() { + return y; + } + + public double getZ() { + return z; + } + + public float getPitch() { + return pitch; + } + + public float getYaw() { + return yaw; + } +} \ No newline at end of file diff --git a/src/main/java/eu/univento/commons/logging/LoggingHandler.java b/src/main/java/eu/univento/commons/logging/LoggingHandler.java index 0d65ad3..ec5e171 100644 --- a/src/main/java/eu/univento/commons/logging/LoggingHandler.java +++ b/src/main/java/eu/univento/commons/logging/LoggingHandler.java @@ -35,8 +35,4 @@ public class LoggingHandler { public LoggingHandler() { } - - public void shutdown() { - LogManager.shutdown(); - } } \ No newline at end of file diff --git a/src/main/java/eu/univento/commons/player/DatabasePlayer.java b/src/main/java/eu/univento/commons/player/DatabasePlayer.java index b724b8a..7b762c9 100644 --- a/src/main/java/eu/univento/commons/player/DatabasePlayer.java +++ b/src/main/java/eu/univento/commons/player/DatabasePlayer.java @@ -8,12 +8,14 @@ import eu.univento.commons.database.MongoDB; import eu.univento.commons.player.ban.BanData; import eu.univento.commons.player.ban.BanReason; import eu.univento.commons.player.friend.FriendData; +import eu.univento.commons.player.hacks.HackData; import eu.univento.commons.player.kick.KickData; import eu.univento.commons.player.kick.KickReason; import eu.univento.commons.player.language.Language; import eu.univento.commons.player.mute.MuteData; import eu.univento.commons.player.mute.MuteReason; import eu.univento.commons.player.profiles.Profile; +import eu.univento.commons.player.ranking.PlayerRanking; import eu.univento.commons.player.settings.PlayerSettings; import eu.univento.commons.player.warn.WarnData; import eu.univento.commons.player.warn.WarnReason; @@ -29,10 +31,10 @@ import java.util.stream.Collectors; public class DatabasePlayer { private UUID uuid; - private Commons commons; - private final MongoDB mongoDB; private final PlayerSettings settings; + private final PlayerRanking ranking; + private final HackData hackData; private final MongoCollection playerCollection; private final MongoCollection friendCollection; @@ -44,11 +46,12 @@ public class DatabasePlayer { private final MongoCollection profileCollection; public DatabasePlayer(Commons commons, UUID uuid) { - this.commons = commons; this.uuid = uuid; settings = new PlayerSettings(this); + ranking = new PlayerRanking(this); + hackData = new HackData(this); - this.mongoDB = commons.getDatabaseManager().getMongoDB(); + MongoDB mongoDB = commons.getDatabaseManager().getMongoDB(); playerCollection = mongoDB.getDatabase().getCollection("players"); friendCollection = mongoDB.getDatabase().getCollection("friends"); onlinePlayerCollection = mongoDB.getDatabase().getCollection("online-players"); @@ -95,6 +98,14 @@ public class DatabasePlayer { return profileCollection; } + public PlayerRanking getPlayerRanking() { + return ranking; + } + + public HackData getHackData() { + return hackData; + } + public Collection getProfiles() { ArrayList list = getArrayListFromDatabase("profiles"); return list.stream().map(id -> new Profile(this, id)).collect(Collectors.toCollection(LinkedList::new)); @@ -118,9 +129,9 @@ public class DatabasePlayer { } public BanData getBan() { - if(!isBanned()) return null; FindIterable cursor = banCollection.find(new Document("uuid", uuid.toString())); cursor.cursorType(CursorType.NonTailable); + if(cursor.first() == null) return null; Document doc = cursor.first(); return new BanData(BanReason.valueOf(doc.getString("reason")), UUID.fromString(doc.getString("banner")), doc.getString("customMessage"), doc.getDate("date"), doc.getString("proof")); } @@ -192,9 +203,13 @@ public class DatabasePlayer { } public void mute(UUID muter, MuteReason reason) { + int i = 0; + if(getAllBans().size() > 1) { + for (MuteData mute : getAllMutes()) i =+ mute.getReason().getValue(); + } Document doc = new Document("uuid", uuid.toString()); Calendar calendar = Calendar.getInstance(); - calendar.add(Calendar.DAY_OF_YEAR, reason.getTime()); + calendar.add(Calendar.DAY_OF_YEAR, reason.getValue() + i); doc.put("reason", reason.name()); doc.put("muter", muter.toString()); doc.put("date", calendar.getTime()); diff --git a/src/main/java/eu/univento/commons/player/Rank.java b/src/main/java/eu/univento/commons/player/Rank.java index 1b3feea..e2c9bba 100644 --- a/src/main/java/eu/univento/commons/player/Rank.java +++ b/src/main/java/eu/univento/commons/player/Rank.java @@ -6,21 +6,21 @@ package eu.univento.commons.player; */ public enum Rank { - Admin(16, 107, 5, "§4", "§8[§4Admin§8] ", " §8»§7 ", "a", "§4Admin | "), - SrDeveloper(15, 141, 18, "§3", "§8[§3SrDev§8] ", " §8»§7 ", "c", "§3SrDev | "), - SrBuilder(14, 142, 15, "§2", "§8[§2SrBuilder§8] ", " §8»§7 ", "f", "§2SrBuilder | "), - SrSupporter(13, 149, 12, "§9", "§8[§9SrSupr§8] ", " §8»§7 ", "i", "§9SrSup | "), - Developer(12, 144, 17, "§3", "§8[§3Dev§8] ", " §8»§7 ", "d", "§3Dev | "), - Builder(11, 145, 14, "§2", "§8[§2Builder§8] ", " §8»§7 ", "g", "§2Builder | "), - Supporter(10, 146, 11, "§9", "§8[§9Sup§8] ", " §8»§7 ", "j", "§9Sup | "), - JrDeveloper(9, 147, 16, "§3", "§8[§3JrDev§8] ", " §8»§7 ", "e", "§3JrDev | "), - JrBuilder(8, 148, 13, "§2", "§8[§2JrBuilder§8] ", " §8»§7 ", "h", "§2JrBuilder | "), - JrSupporter(7, 149, 10, "§9", "§8[§9JrSup§8] ", " §8»§7 ", "k", "§9JrSup | "), - Manager(6, 150, 19, "§c", "§8[§cManager§8] ", " §8»§7 ", "b", "§cManager | "), - Grafik(5, 151, 8, "§e", "§8[§eGrafiker§8] ", " §8»§7 ", "l", "§eGrafik | "), - Sound(4, 152, 9, "§e", "§8[§eSound§8] ", " §8»§7 ", "m", "§eSound | "), + Admin(16, 107, 5, "§4", "§8[§4Admin§8] §4", " §8»§7 ", "a", "§4Admin | "), + SrDeveloper(15, 141, 18, "§3", "§8[§3SrDev§8] §3", " §8»§7 ", "c", "§3SrDev | "), + SrBuilder(14, 142, 15, "§2", "§8[§2SrBuilder§8] §2", " §8»§7 ", "f", "§2SrBuilder | "), + SrSupporter(13, 149, 12, "§9", "§8[§9SrSupr§8] §9", " §8»§7 ", "i", "§9SrSup | "), + Developer(12, 144, 17, "§3", "§8[§3Dev§8] §3", " §8»§7 ", "d", "§3Dev | "), + Builder(11, 145, 14, "§2", "§8[§2Builder§8] §2", " §8»§7 ", "g", "§2Builder | "), + Supporter(10, 146, 11, "§9", "§8[§9Sup§8] §9", " §8»§7 ", "j", "§9Sup | "), + JrDeveloper(9, 147, 16, "§3", "§8[§3JrDev§8] §3", " §8»§7 ", "e", "§3JrDev | "), + JrBuilder(8, 148, 13, "§2", "§8[§2JrBuilder§8] §2", " §8»§7 ", "h", "§2JrBuilder | "), + JrSupporter(7, 149, 10, "§9", "§8[§9JrSup§8] §9", " §8»§7 ", "k", "§9JrSup | "), + Manager(6, 150, 19, "§c", "§8[§cManager§8] §c", " §8»§7 ", "b", "§cManager | "), + Grafik(5, 151, 8, "§e", "§8[§eGrafiker§8] §e", " §8»§7 ", "l", "§eGrafik | "), + Sound(4, 152, 9, "§e", "§8[§eSound§8] §e", " §8»§7 ", "m", "§eSound | "), Partner(3, 155, 7, "§5", "§5", " §8»§7 ", "n", "§5"), - Premium(2, 156, 6, "§6", "§6", " §8§7» ", "o", "§6"), + Premium(2, 156, 6, "§6", "§6", " §8»§7 ", "o", "§6"), Player(1, 164, 2, "§7", "§7", " §8»§7 ", "p", "§7"); private final int value; 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 3cfa59a..336db1f 100644 --- a/src/main/java/eu/univento/commons/player/ban/BanData.java +++ b/src/main/java/eu/univento/commons/player/ban/BanData.java @@ -54,6 +54,8 @@ public class BanData { } public String getBannerName() { + if(banner == null) + return "Auto Ban"; return NameFetcher.getRequest(banner); } 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 481730f..958f8bc 100644 --- a/src/main/java/eu/univento/commons/player/ban/BanReason.java +++ b/src/main/java/eu/univento/commons/player/ban/BanReason.java @@ -6,26 +6,23 @@ package eu.univento.commons.player.ban; */ public enum BanReason { - //int represents ban points, ban points represent ban time - HACK_CRITICALS("Criticals Hack", 10), - HACK_AUTOCLICKER("AutoClicker Hack", 10), - HACK_GLIDE("Glide Hack", 10), - HACK_REACH("Reach Hack", 10), - HACK_NOSLOWDOWN("NoSlowDown Hack", 10), - HACK_REGEN("Regen Hack", 10), - HACK_AUTORESPAWN("AutoRespawn Hack", 10), - HACK_FASTPLACE("FastPlace Hack", 10), - HACK_KILLAURA("KillAura Hack", 10), - HACK_FLY("Fly Hack", 10), - HACK_WDL("Massive use of WorldDownloader", 10), - ADVERTISING("Advertising", 10), - GRIEFING("Griefing", 10), - INSULT("Insut", 10), - RACISM("Racism", 10), - BUGUSING("Bugusing", 10), - HACKED_ACCOUNT("using hacked account", 10), - TO_MANY_WARNS("To many warns", 10), - CUSTOM("Custom", 10); + HACK_CRITICALS("Ban.Reason.Hack.Criticals", 10), + HACK_AUTOCLICKER("Ban.Reason.Hack.Autoclicker", 10), + HACK_GLIDE("Ban.Reason.Hack.Glide", 10), + HACK_REACH("Ban.Reason.Hack.Reach", 10), + HACK_NOSLOWDOWN("Ban.Reason.Hack.NoSlowDown", 10), + HACK_REGEN("Ban.Reason.Hack.Regen", 10), + HACK_AUTORESPAWN("Ban.Reason.Hack.AutoRespawn", 10), + HACK_FASTPLACE("Ban.Reason.Hack.FastPlace", 10), + HACK_KILLAURA("Ban.Reason.Hack.KillAura", 10), + HACK_FLY("Ban.Reason.Hack.Fly", 10), + HACK_WDL("Ban.Reason.Hack.WDL", 10), + GRIEFING("Ban.Reason.Griefing", 10), + BUGUSING("Ban.Reason.Bugusing", 10), + HACKED_ACCOUNT("Ban.Reason.Hacked_Account", 10), + TO_MANY_WARNS("Ban.Reason.Warns", 10), + TO_MANY_MUTES("Ban.Reason.Mutes", 10), + CUSTOM("Ban.Reason.Custom", 10); private final String name; private final int value; diff --git a/src/main/java/eu/univento/commons/player/hacks/HackData.java b/src/main/java/eu/univento/commons/player/hacks/HackData.java new file mode 100644 index 0000000..cb9c1fe --- /dev/null +++ b/src/main/java/eu/univento/commons/player/hacks/HackData.java @@ -0,0 +1,196 @@ +package eu.univento.commons.player.hacks; + +import eu.univento.commons.helpers.Location; +import eu.univento.commons.player.DatabasePlayer; + +/** + * @author joethei + * @version 0.1 + */ +public class HackData { + + private DatabasePlayer player; + private Location lastLocation; + private Location realLocation; + private boolean lastHealth; + private long lastPlacedBlock; + private long lastBow; + private long lastRegen; + private long lastAnimation; + private long lastForcefield; + private long lastY; + private long highestY; + private boolean ascending; + private boolean descending; + private Location lastBlockLocation; + private double blocksMoved; + private int fakePlayer; + private long lastTimeFakePlayerAttack; + private long lastFood; + private long lastInventory; + private long lastNotification; + + public HackData(DatabasePlayer player) { + this.player = player; + } + + public DatabasePlayer getPlayer() { + return player; + } + + public void setPlayer(DatabasePlayer player) { + this.player = player; + } + + public Location getLastLocation() { + return lastLocation; + } + + public void setLastLocation(Location lastLocation) { + this.lastLocation = lastLocation; + } + + public Location getRealLocation() { + return realLocation; + } + + public void setRealLocation(Location realLocation) { + this.realLocation = realLocation; + } + + public boolean isLastHealth() { + return lastHealth; + } + + public void setLastHealth(boolean lastHealth) { + this.lastHealth = lastHealth; + } + + public long getLastPlacedBlock() { + return lastPlacedBlock; + } + + public void setLastPlacedBlock(long lastPlacedBlock) { + this.lastPlacedBlock = lastPlacedBlock; + } + + public long getLastBow() { + return lastBow; + } + + public void setLastBow(long lastBow) { + this.lastBow = lastBow; + } + + public long getLastRegen() { + return lastRegen; + } + + public void setLastRegen(long lastRegen) { + this.lastRegen = lastRegen; + } + + public long getLastAnimation() { + return lastAnimation; + } + + public void setLastAnimation(long lastAnimation) { + this.lastAnimation = lastAnimation; + } + + public long getLastForcefield() { + return lastForcefield; + } + + public void setLastForcefield(long lastForcefield) { + this.lastForcefield = lastForcefield; + } + + public long getLastY() { + return lastY; + } + + public void setLastY(long lastY) { + this.lastY = lastY; + } + + public long getHighestY() { + return highestY; + } + + public void setHighestY(long highestY) { + this.highestY = highestY; + } + + public boolean isAscending() { + return ascending; + } + + public void setAscending(boolean ascending) { + this.ascending = ascending; + } + + public boolean isDescending() { + return descending; + } + + public void setDescending(boolean descending) { + this.descending = descending; + } + + public Location getLastBlockLocation() { + return lastBlockLocation; + } + + public void setLastBlockLocation(Location lastBlockLocation) { + this.lastBlockLocation = lastBlockLocation; + } + + public double getBlocksMoved() { + return blocksMoved; + } + + public void setBlocksMoved(double blocksMoved) { + this.blocksMoved = blocksMoved; + } + + public int getFakePlayer() { + return fakePlayer; + } + + public void setFakePlayer(int fakePlayer) { + this.fakePlayer = fakePlayer; + } + + public long getLastTimeFakePlayerAttack() { + return lastTimeFakePlayerAttack; + } + + public void setLastTimeFakePlayerAttack(long lastTimeFakePlayerAttack) { + this.lastTimeFakePlayerAttack = lastTimeFakePlayerAttack; + } + + public long getLastFood() { + return lastFood; + } + + public void setLastFood(long lastFood) { + this.lastFood = lastFood; + } + + public long getLastInventory() { + return lastInventory; + } + + public void setLastInventory(long lastInventory) { + this.lastInventory = lastInventory; + } + + public long getLastNotification() { + return lastNotification; + } + + public void setLastNotification(long lastNotification) { + this.lastNotification = lastNotification; + } +} \ No newline at end of file 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 eac452a..4bca3c8 100644 --- a/src/main/java/eu/univento/commons/player/kick/KickData.java +++ b/src/main/java/eu/univento/commons/player/kick/KickData.java @@ -34,6 +34,8 @@ public class KickData { } public String getKickerName() { + if(kicker == null) + return "Auto Kick"; return NameFetcher.getRequest(kicker); } } \ No newline at end of file diff --git a/src/main/java/eu/univento/commons/player/kick/KickReason.java b/src/main/java/eu/univento/commons/player/kick/KickReason.java index 0caf741..6aefb75 100644 --- a/src/main/java/eu/univento/commons/player/kick/KickReason.java +++ b/src/main/java/eu/univento/commons/player/kick/KickReason.java @@ -12,6 +12,7 @@ public enum KickReason { private int points; KickReason(String name, int points) { + this.name = name; this.points = points; } 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 b7aa951..770e09d 100644 --- a/src/main/java/eu/univento/commons/player/mute/MuteData.java +++ b/src/main/java/eu/univento/commons/player/mute/MuteData.java @@ -1,6 +1,10 @@ package eu.univento.commons.player.mute; import eu.univento.commons.player.uuid.NameFetcher; +import org.joda.time.DateTime; +import org.joda.time.Period; +import org.joda.time.format.PeriodFormatter; +import org.joda.time.format.PeriodFormatterBuilder; import java.util.Date; import java.util.UUID; @@ -40,6 +44,29 @@ public class MuteData { } public String getMuterName() { + if(muter == null) + return "Auto Mute"; return NameFetcher.getRequest(muter); } + + public String getTimeTillUnmute() { + assert getDate() != null; + final DateTime end = new DateTime(getDate().getTime()); + final DateTime now = new DateTime(new Date().getTime()); + Period period = new Period(now, end); + PeriodFormatter formatter = new PeriodFormatterBuilder().printZeroAlways().minimumPrintedDigits(2) + .appendYears().appendSuffix(" Jahr", " Jahre") + .appendSeparator(", ") + .appendMonths().appendSuffix(" Monat", " Monate") + .appendSeparator(", ") + .appendDays().appendSuffix(" Tag", " Tage") + .appendSeparator(" und ") + .appendHours().appendSuffix(" Stunde", " Stunden") + .appendMinutes().appendSuffix(" Minute", " Minuten") + .appendSeconds().appendSuffix(" Sekunde", " Sekunden") + .toFormatter(); + + return period.toString(formatter); + } + } \ No newline at end of file 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 8949fa1..c89eee4 100644 --- a/src/main/java/eu/univento/commons/player/mute/MuteReason.java +++ b/src/main/java/eu/univento/commons/player/mute/MuteReason.java @@ -6,21 +6,28 @@ package eu.univento.commons.player.mute; */ public enum MuteReason { - SPAM("Spam", 30); + SPAM("Mute.Reason.Spam", 1), + ADVERTISMENT("Mute.Reason.Advertisement", 3), + RASISM("Mute.Reason.Rasim", 5), + SEXISM("Mute.Reason.Sexism", 1), + THREAT("Mute.Reason.Threat", 30), + INSULT("Mute.Reason.Insult", 1), + WORD_CHOICE("Mute.Reason.Word_Choice", 1); + private String name; - private int time; + private int value; - MuteReason(String name, int time) { + MuteReason(String name, int value) { this.name = name; - this.time = time; + this.value = value; } public String getName() { return name; } - public int getTime() { - return time; + public int getValue() { + return value; } } \ No newline at end of file diff --git a/src/main/java/eu/univento/commons/player/profiles/PlayerProfiles.java b/src/main/java/eu/univento/commons/player/profiles/PlayerProfiles.java deleted file mode 100644 index 5a302dc..0000000 --- a/src/main/java/eu/univento/commons/player/profiles/PlayerProfiles.java +++ /dev/null @@ -1,24 +0,0 @@ -package eu.univento.commons.player.profiles; - -import com.mongodb.client.MongoCollection; -import eu.univento.commons.player.DatabasePlayer; -import org.bson.Document; - -import java.util.UUID; - -/** - * @author joethei - * @version 0.1 - */ -public class PlayerProfiles { - - private UUID uuid; - private final MongoCollection collection; - - public PlayerProfiles(DatabasePlayer player) { - this.uuid = player.getUuid(); - this.collection = player.getProfileCollection(); - } - - -} \ No newline at end of file diff --git a/src/main/java/eu/univento/commons/player/profiles/Profile.java b/src/main/java/eu/univento/commons/player/profiles/Profile.java index 66d946f..4142e21 100644 --- a/src/main/java/eu/univento/commons/player/profiles/Profile.java +++ b/src/main/java/eu/univento/commons/player/profiles/Profile.java @@ -24,6 +24,7 @@ public class Profile { private Collection items; public Profile(DatabasePlayer player, String id) { + this.player = player; this.id = id; FindIterable cursor = player.getProfileCollection().find(new Document("_id", id)); cursor.cursorType(CursorType.NonTailable); diff --git a/src/main/java/eu/univento/commons/player/ranking/PlayerRanking.java b/src/main/java/eu/univento/commons/player/ranking/PlayerRanking.java new file mode 100644 index 0000000..53467d2 --- /dev/null +++ b/src/main/java/eu/univento/commons/player/ranking/PlayerRanking.java @@ -0,0 +1,20 @@ +package eu.univento.commons.player.ranking; + +import eu.univento.commons.player.DatabasePlayer; + +/** + * @author joethei + * @version 0.1 + */ +public class PlayerRanking { + + private final DatabasePlayer player; + + public PlayerRanking(DatabasePlayer player){ + this.player = player; + } + + public Ranking getRanking() { + return Ranking.getRanking(player.getIntegerFromDatabase("ranking")); + } +} \ No newline at end of file diff --git a/src/main/java/eu/univento/commons/player/ranking/Ranking.java b/src/main/java/eu/univento/commons/player/ranking/Ranking.java new file mode 100644 index 0000000..7e321ae --- /dev/null +++ b/src/main/java/eu/univento/commons/player/ranking/Ranking.java @@ -0,0 +1,41 @@ +package eu.univento.commons.player.ranking; + +/** + * @author joethei + * @version 0.1 + */ +public enum Ranking { + + SILVER_1("Silver 1", 2, 5); + + private String name; + private int min; + private int max; + + Ranking(String name, int min, int max) { + this.name = name; + this.min = min; + this.max = max; + } + + public String getName() { + return name; + } + + public int getMin() { + return min; + } + + public int getMax() { + return max; + } + + public static Ranking getRanking(int ranking) { + for(Ranking rank : values()) { + if(rank.getMax() > ranking && rank.getMin() < ranking) { + return rank; + } + } + return null; + } +} \ No newline at end of file diff --git a/src/main/java/eu/univento/commons/player/warn/WarnData.java b/src/main/java/eu/univento/commons/player/warn/WarnData.java index de31979..ba524a6 100644 --- a/src/main/java/eu/univento/commons/player/warn/WarnData.java +++ b/src/main/java/eu/univento/commons/player/warn/WarnData.java @@ -40,10 +40,8 @@ public class WarnData { } public String getWarnerName() { - if(warner == null) { + if(warner == null) return "Auto Warn"; - }else { - return NameFetcher.getRequest(warner); - } + return NameFetcher.getRequest(warner); } } \ No newline at end of file diff --git a/src/main/java/eu/univento/commons/security/SecurityHandler.java b/src/main/java/eu/univento/commons/security/SecurityHandler.java index 890844e..575d64b 100644 --- a/src/main/java/eu/univento/commons/security/SecurityHandler.java +++ b/src/main/java/eu/univento/commons/security/SecurityHandler.java @@ -1,7 +1,6 @@ package eu.univento.commons.security; import eu.univento.commons.Commons; -import eu.univento.commons.database.AsyncMySQL; import java.sql.SQLException; import java.util.function.Consumer; @@ -19,8 +18,7 @@ public class SecurityHandler { } public void isValidServer(String ip, Consumer consumer) { - AsyncMySQL sql = commons.getDatabaseManager().getAsyncMySQL(); - sql.query("SELECT * FROM Servers WHERE ip='" + ip + "';", resultSet -> { + commons.getDatabaseManager().getAsyncMySQL().query("SELECT * FROM Servers WHERE ip='" + ip + "';", resultSet -> { try { consumer.accept(resultSet.next()); } catch (SQLException e) { diff --git a/src/main/java/eu/univento/commons/updater/CustomAuthenicator.java b/src/main/java/eu/univento/commons/updater/CustomAuthenticator.java similarity index 62% rename from src/main/java/eu/univento/commons/updater/CustomAuthenicator.java rename to src/main/java/eu/univento/commons/updater/CustomAuthenticator.java index 2c17dad..ce5ef73 100644 --- a/src/main/java/eu/univento/commons/updater/CustomAuthenicator.java +++ b/src/main/java/eu/univento/commons/updater/CustomAuthenticator.java @@ -7,18 +7,17 @@ import java.net.PasswordAuthentication; * @author joethei * @version 0.1 */ -public class CustomAuthenicator extends Authenticator{ +public class CustomAuthenticator extends Authenticator{ private static String username = ""; private static String password = ""; protected PasswordAuthentication getPasswordAuthentication() { - return new PasswordAuthentication (username, - password.toCharArray()); + return new PasswordAuthentication (username, password.toCharArray()); } public static void setPasswordAuthentication(String username, String password) { - CustomAuthenicator.username = username; - CustomAuthenicator.password = password; + CustomAuthenticator.username = username; + CustomAuthenticator.password = password; } } \ No newline at end of file diff --git a/src/main/java/eu/univento/commons/utils/Maths.java b/src/main/java/eu/univento/commons/utils/Maths.java index e0a287b..4f8c1bc 100644 --- a/src/main/java/eu/univento/commons/utils/Maths.java +++ b/src/main/java/eu/univento/commons/utils/Maths.java @@ -11,8 +11,7 @@ import java.util.regex.Pattern; * @version 1.5 */ -final class Maths -{ +final class Maths { public static final float nanoToSec = 1.0E-009F; public static final float FLOAT_ROUNDING_ERROR = 1.0E-006F; public static final float PI = 3.141593F; diff --git a/src/main/resources/language_de.properties b/src/main/resources/language_de.properties index 389f41a..57f2bfe 100644 --- a/src/main/resources/language_de.properties +++ b/src/main/resources/language_de.properties @@ -13,7 +13,7 @@ Server.ts_ip = TeamSpeak IP: ts.univento.eu Server.board_ip = Foren Adresse: forum.univento.eu Command.prefix = univento.eu Default Command Prefix -Command.command_not_found = Dieser Befehl konnte nicht gefunden werden +Command.not_found = Dieser Befehl konnte nicht gefunden werden Command.not_online = Der Spieler $player ist nicht online Command.no_perms = Um diesen Befehl zu benutzen hast du keine Rechte