From 0b719be63357f07364d494a5f1d713af668c21b4 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sun, 10 Mar 2019 22:11:13 +0100 Subject: [PATCH] Finalizing BanSystem --- src/de/warking/bungeecore/BungeeCore.java | 4 ++- .../bungeecore/PlayerJoinListener.java | 24 ----------------- src/de/warking/bungeecore/WarkingUser.java | 26 +++++++++++++++++-- 3 files changed, 27 insertions(+), 27 deletions(-) delete mode 100644 src/de/warking/bungeecore/PlayerJoinListener.java diff --git a/src/de/warking/bungeecore/BungeeCore.java b/src/de/warking/bungeecore/BungeeCore.java index 3cc5f213..ff1d6cf8 100644 --- a/src/de/warking/bungeecore/BungeeCore.java +++ b/src/de/warking/bungeecore/BungeeCore.java @@ -8,11 +8,13 @@ import net.md_5.bungee.config.YamlConfiguration; import java.io.File; import java.io.IOException; +import java.time.format.DateTimeFormatter; public class BungeeCore extends Plugin { private Configuration config; public static String ChatPrefix; + public static DateTimeFormatter DateFormat = DateTimeFormatter.ofPattern("dd.MM.yyyy HH:mm"); @Override public void onEnable(){ @@ -45,7 +47,7 @@ public class BungeeCore extends Plugin { config.getString("db.password") ); - getProxy().getPluginManager().registerListener(this, new PlayerJoinListener()); + getProxy().getPluginManager().registerListener(this, new PlayerListener()); final Configuration servers = config.getSection("servers"); for(final String cmd : servers.getKeys()){ diff --git a/src/de/warking/bungeecore/PlayerJoinListener.java b/src/de/warking/bungeecore/PlayerJoinListener.java deleted file mode 100644 index 1cab613a..00000000 --- a/src/de/warking/bungeecore/PlayerJoinListener.java +++ /dev/null @@ -1,24 +0,0 @@ -package de.warking.bungeecore; - -import net.md_5.bungee.api.connection.ProxiedPlayer; -import net.md_5.bungee.api.event.PostLoginEvent; -import net.md_5.bungee.api.plugin.Listener; -import net.md_5.bungee.event.EventHandler; - -public class PlayerJoinListener implements Listener { - - @EventHandler - public void onPostLogin(PostLoginEvent event) { - ProxiedPlayer player = event.getPlayer(); - WarkingUser user = new WarkingUser(player); - if(user.isBanned()){ - if(user.BanTime.equals(WarkingUser.PermaBan)){ - player.disconnect(BungeeCore.ChatPrefix + "§cDu bist permanent gebannt. §r§lGrund§r: §c" + user.BanReason); - }else{ - player.disconnect(BungeeCore.ChatPrefix + " Du bist auf bis zum " + - user.BanTime.getDay() + "." + user.BanTime.getMonth() + "." + user.BanTime.getYear() + " " + - user.BanTime.getHours() + ":" + user.BanTime.getMinutes() + " gebannt. §r§lGrund§r: §c" + user.BanReason); - } - } - } -} diff --git a/src/de/warking/bungeecore/WarkingUser.java b/src/de/warking/bungeecore/WarkingUser.java index 6c0af020..7bf506c1 100644 --- a/src/de/warking/bungeecore/WarkingUser.java +++ b/src/de/warking/bungeecore/WarkingUser.java @@ -1,10 +1,12 @@ package de.warking.bungeecore; +import net.md_5.bungee.api.connection.PendingConnection; import net.md_5.bungee.api.connection.ProxiedPlayer; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Timestamp; +import java.time.Instant; import java.util.Date; import java.util.UUID; @@ -16,7 +18,7 @@ public class WarkingUser { public Timestamp BanTime; public String BanReason; - public static Timestamp PermaBan = new Timestamp(2000,1,1,0,0,0,0); + public static Timestamp PermaBan = Timestamp.from(Instant.ofEpochSecond(946684800)); public WarkingUser(UUID UUID){ init(sql.select("SELECT * FROM UserData WHERE UUID = '" + UUID.toString() + "'")); @@ -26,6 +28,26 @@ public class WarkingUser { init(sql.select("SELECT * FROM UserData WHERE UserName = '" + UserName + "'")); } + public WarkingUser(PendingConnection connection){ + ResultSet dbplayer = sql.select("SELECT * FROM UserData WHERE UUID = '" + connection.getUniqueId().toString() + "'"); + try { + if(dbplayer.next()){ + dbplayer.beforeFirst(); + init(dbplayer); + }else{ + UUID = connection.getUniqueId(); + UserName = connection.getName(); + UserGroup = "Member"; + sql.update("INSERT INTO UserData (UUID, UserName, UserGroup) VALUES ('" + UUID.toString() + "', '" + UserName + "', '" + UserGroup + "')"); + + dbplayer = sql.select("SELECT * FROM UserData WHERE UUID = '" + UUID.toString() + "'"); + init(dbplayer); + } + } catch (SQLException e) { + e.printStackTrace(); + } + } + public WarkingUser(ProxiedPlayer player){ ResultSet dbplayer = sql.select("SELECT * FROM UserData WHERE UUID = '" + player.getUniqueId().toString() + "'"); try { @@ -65,7 +87,7 @@ public class WarkingUser { public boolean isBanned(){ if(BanTime == null){ return false; - }else if(BanTime.after(new Date()) || BanTime.equals(PermaBan)){ + }else if(BanTime.after(new Date()) || BanTime.before(PermaBan)){ return true; }else{ sql.update("UPDATE UserData SET BanTime = NULL, BanReason = '' WHERE UUID = '" + UUID.toString() + "'");