Adding BanSystem
Dieser Commit ist enthalten in:
Ursprung
9cac4c6dcd
Commit
fba69de688
@ -45,6 +45,8 @@ public class BungeeCore extends Plugin {
|
||||
config.getString("db.password")
|
||||
);
|
||||
|
||||
getProxy().getPluginManager().registerListener(this, new PlayerJoinListener());
|
||||
|
||||
final Configuration servers = config.getSection("servers");
|
||||
for(final String cmd : servers.getKeys()){
|
||||
final Configuration server = servers.getSection(cmd);
|
||||
|
24
src/de/warking/bungeecore/PlayerJoinListener.java
Normale Datei
24
src/de/warking/bungeecore/PlayerJoinListener.java
Normale Datei
@ -0,0 +1,24 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
77
src/de/warking/bungeecore/WarkingUser.java
Normale Datei
77
src/de/warking/bungeecore/WarkingUser.java
Normale Datei
@ -0,0 +1,77 @@
|
||||
package de.warking.bungeecore;
|
||||
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.Date;
|
||||
import java.util.UUID;
|
||||
|
||||
public class WarkingUser {
|
||||
public int id;
|
||||
public UUID UUID;
|
||||
public String UserName;
|
||||
public String UserGroup;
|
||||
public Timestamp BanTime;
|
||||
public String BanReason;
|
||||
|
||||
public static Timestamp PermaBan = new Timestamp(2000,1,1,0,0,0,0);
|
||||
|
||||
public WarkingUser(UUID UUID){
|
||||
init(sql.select("SELECT * FROM UserData WHERE UUID = '" + UUID.toString() + "'"));
|
||||
}
|
||||
|
||||
public WarkingUser(String UserName){
|
||||
init(sql.select("SELECT * FROM UserData WHERE UserName = '" + UserName + "'"));
|
||||
}
|
||||
|
||||
public WarkingUser(ProxiedPlayer player){
|
||||
ResultSet dbplayer = sql.select("SELECT * FROM UserData WHERE UUID = '" + player.getUniqueId().toString() + "'");
|
||||
try {
|
||||
if(dbplayer.next()){
|
||||
dbplayer.beforeFirst();
|
||||
init(dbplayer);
|
||||
}else{
|
||||
UUID = player.getUniqueId();
|
||||
UserName = player.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();
|
||||
}
|
||||
}
|
||||
|
||||
private void init(ResultSet dbplayer){
|
||||
try {
|
||||
if(!dbplayer.next()){
|
||||
return;
|
||||
}
|
||||
id = dbplayer.getInt("id");
|
||||
this.UUID = java.util.UUID.fromString(dbplayer.getString("UUID"));
|
||||
UserName = dbplayer.getString("UserName");
|
||||
UserGroup = dbplayer.getString("UserGroup");
|
||||
BanTime = dbplayer.getTimestamp("BanTime");
|
||||
BanReason = dbplayer.getString("BanReason");
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isBanned(){
|
||||
if(BanTime == null){
|
||||
return false;
|
||||
}else if(BanTime.after(new Date()) || BanTime.equals(PermaBan)){
|
||||
return true;
|
||||
}else{
|
||||
sql.update("UPDATE UserData SET BanTime = NULL, BanReason = '' WHERE UUID = '" + UUID.toString() + "'");
|
||||
BanTime = null;
|
||||
BanReason = "";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
@ -48,4 +48,7 @@ public class sql {
|
||||
|
||||
return null;
|
||||
}
|
||||
public static Connection getCon(){
|
||||
return con;
|
||||
}
|
||||
}
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren