geforkt von SteamWar/BungeeCore
Finalizing BanSystem
Dieser Commit ist enthalten in:
Ursprung
fba69de688
Commit
0b719be633
@ -8,11 +8,13 @@ import net.md_5.bungee.config.YamlConfiguration;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
|
|
||||||
public class BungeeCore extends Plugin {
|
public class BungeeCore extends Plugin {
|
||||||
|
|
||||||
private Configuration config;
|
private Configuration config;
|
||||||
public static String ChatPrefix;
|
public static String ChatPrefix;
|
||||||
|
public static DateTimeFormatter DateFormat = DateTimeFormatter.ofPattern("dd.MM.yyyy HH:mm");
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable(){
|
public void onEnable(){
|
||||||
@ -45,7 +47,7 @@ public class BungeeCore extends Plugin {
|
|||||||
config.getString("db.password")
|
config.getString("db.password")
|
||||||
);
|
);
|
||||||
|
|
||||||
getProxy().getPluginManager().registerListener(this, new PlayerJoinListener());
|
getProxy().getPluginManager().registerListener(this, new PlayerListener());
|
||||||
|
|
||||||
final Configuration servers = config.getSection("servers");
|
final Configuration servers = config.getSection("servers");
|
||||||
for(final String cmd : servers.getKeys()){
|
for(final String cmd : servers.getKeys()){
|
||||||
|
@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,10 +1,12 @@
|
|||||||
package de.warking.bungeecore;
|
package de.warking.bungeecore;
|
||||||
|
|
||||||
|
import net.md_5.bungee.api.connection.PendingConnection;
|
||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||||
|
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
|
import java.time.Instant;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@ -16,7 +18,7 @@ public class WarkingUser {
|
|||||||
public Timestamp BanTime;
|
public Timestamp BanTime;
|
||||||
public String BanReason;
|
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){
|
public WarkingUser(UUID UUID){
|
||||||
init(sql.select("SELECT * FROM UserData WHERE UUID = '" + UUID.toString() + "'"));
|
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 + "'"));
|
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){
|
public WarkingUser(ProxiedPlayer player){
|
||||||
ResultSet dbplayer = sql.select("SELECT * FROM UserData WHERE UUID = '" + player.getUniqueId().toString() + "'");
|
ResultSet dbplayer = sql.select("SELECT * FROM UserData WHERE UUID = '" + player.getUniqueId().toString() + "'");
|
||||||
try {
|
try {
|
||||||
@ -65,7 +87,7 @@ public class WarkingUser {
|
|||||||
public boolean isBanned(){
|
public boolean isBanned(){
|
||||||
if(BanTime == null){
|
if(BanTime == null){
|
||||||
return false;
|
return false;
|
||||||
}else if(BanTime.after(new Date()) || BanTime.equals(PermaBan)){
|
}else if(BanTime.after(new Date()) || BanTime.before(PermaBan)){
|
||||||
return true;
|
return true;
|
||||||
}else{
|
}else{
|
||||||
sql.update("UPDATE UserData SET BanTime = NULL, BanReason = '' WHERE UUID = '" + UUID.toString() + "'");
|
sql.update("UPDATE UserData SET BanTime = NULL, BanReason = '' WHERE UUID = '" + UUID.toString() + "'");
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren