SteamWar/BungeeCore
Archiviert
13
2

Finalizing BanSystem

Dieser Commit ist enthalten in:
Lixfel 2019-03-10 22:11:13 +01:00
Ursprung fba69de688
Commit 0b719be633
3 geänderte Dateien mit 27 neuen und 27 gelöschten Zeilen

Datei anzeigen

@ -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()){

Datei anzeigen

@ -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);
}
}
}
}

Datei anzeigen

@ -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() + "'");