From 26d36c5ca2d1e124e27cb569b3b1c3cb20b3c419 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Fri, 6 Sep 2019 06:33:06 +0200 Subject: [PATCH] Rework + Modsystem + Eventsystem --- src/de/steamwar/bungeecore/ArenaMode.java | 3 +- src/de/steamwar/bungeecore/Broadcaster.java | 25 + src/de/steamwar/bungeecore/BungeeCore.java | 265 +++++--- src/de/steamwar/bungeecore/EventStarter.java | 66 ++ src/de/steamwar/bungeecore/ModSystem.java | 431 ------------ .../steamwar/bungeecore/PlayerListener.java | 266 -------- .../steamwar/bungeecore/SubserverSystem.java | 49 +- .../bungeecore/commands/AlertCommand.java | 9 +- .../bungeecore/commands/BanCommand.java | 62 +- .../{Command.java => BasicCommand.java} | 16 +- .../bungeecore/commands/BauCommand.java | 382 ++++++----- .../bungeecore/commands/ChallengeCommand.java | 72 +- .../bungeecore/commands/DenyCommand.java | 4 +- .../bungeecore/commands/EventCommand.java | 119 ++++ .../commands/EventreloadCommand.java | 15 + .../bungeecore/commands/FightCommand.java | 105 ++- .../bungeecore/commands/ForgeCommand.java | 6 +- .../bungeecore/commands/HelpCommand.java | 19 +- .../bungeecore/commands/JoinmeCommand.java | 16 +- .../bungeecore/commands/KickCommand.java | 17 +- .../bungeecore/commands/MsgCommand.java | 23 +- .../bungeecore/commands/MuteCommand.java | 38 ++ .../bungeecore/commands/PingCommand.java | 4 +- .../bungeecore/commands/PollCommand.java | 51 ++ .../bungeecore/commands/RCommand.java | 21 +- .../commands/ServerSwitchCommand.java | 2 +- .../commands/ServerTeamchatCommand.java | 6 +- .../bungeecore/commands/TeamCommand.java | 637 +++++++++++------- .../bungeecore/commands/TeamchatCommand.java | 16 +- .../bungeecore/commands/WebpwCommand.java | 15 +- .../bungeecore/listeners/BanListener.java | 57 ++ .../bungeecore/listeners/BasicListener.java | 12 + .../bungeecore/listeners/ChatListener.java | 153 +++++ .../listeners/ConnectionListener.java | 132 ++++ .../bungeecore/listeners/PollSystem.java | 62 ++ .../bungeecore/listeners/mods/Forge.java | 388 +++++++++++ .../bungeecore/listeners/mods/LabyMod.java | 153 +++++ .../bungeecore/listeners/mods/Utils.java | 66 ++ .../bungeecore/sql/BannedUserIPs.java | 45 +- src/de/steamwar/bungeecore/sql/Bauwelt.java | 30 +- .../bungeecore/sql/BauweltMember.java | 58 +- src/de/steamwar/bungeecore/sql/Event.java | 112 +++ .../steamwar/bungeecore/sql/EventFight.java | 137 ++++ src/de/steamwar/bungeecore/sql/Mod.java | 77 +++ .../steamwar/bungeecore/sql/Permission.java | 9 - .../steamwar/bungeecore/sql/PollAnswer.java | 44 ++ src/de/steamwar/bungeecore/sql/SQL.java | 87 +++ .../steamwar/bungeecore/sql/SteamwarUser.java | 209 ++++++ src/de/steamwar/bungeecore/sql/Team.java | 24 +- .../bungeecore/sql/TeamTeilnahme.java | 54 ++ .../steamwar/bungeecore/sql/WarkingUser.java | 167 ----- src/de/steamwar/bungeecore/sql/sql.java | 117 ---- 52 files changed, 3110 insertions(+), 1843 deletions(-) create mode 100644 src/de/steamwar/bungeecore/Broadcaster.java create mode 100644 src/de/steamwar/bungeecore/EventStarter.java delete mode 100644 src/de/steamwar/bungeecore/ModSystem.java delete mode 100644 src/de/steamwar/bungeecore/PlayerListener.java rename src/de/steamwar/bungeecore/commands/{Command.java => BasicCommand.java} (57%) create mode 100644 src/de/steamwar/bungeecore/commands/EventCommand.java create mode 100644 src/de/steamwar/bungeecore/commands/EventreloadCommand.java create mode 100644 src/de/steamwar/bungeecore/commands/MuteCommand.java create mode 100644 src/de/steamwar/bungeecore/commands/PollCommand.java create mode 100644 src/de/steamwar/bungeecore/listeners/BanListener.java create mode 100644 src/de/steamwar/bungeecore/listeners/BasicListener.java create mode 100644 src/de/steamwar/bungeecore/listeners/ChatListener.java create mode 100644 src/de/steamwar/bungeecore/listeners/ConnectionListener.java create mode 100644 src/de/steamwar/bungeecore/listeners/PollSystem.java create mode 100644 src/de/steamwar/bungeecore/listeners/mods/Forge.java create mode 100644 src/de/steamwar/bungeecore/listeners/mods/LabyMod.java create mode 100644 src/de/steamwar/bungeecore/listeners/mods/Utils.java create mode 100644 src/de/steamwar/bungeecore/sql/Event.java create mode 100644 src/de/steamwar/bungeecore/sql/EventFight.java create mode 100644 src/de/steamwar/bungeecore/sql/Mod.java delete mode 100644 src/de/steamwar/bungeecore/sql/Permission.java create mode 100644 src/de/steamwar/bungeecore/sql/PollAnswer.java create mode 100644 src/de/steamwar/bungeecore/sql/SQL.java create mode 100644 src/de/steamwar/bungeecore/sql/SteamwarUser.java create mode 100644 src/de/steamwar/bungeecore/sql/TeamTeilnahme.java delete mode 100644 src/de/steamwar/bungeecore/sql/WarkingUser.java delete mode 100644 src/de/steamwar/bungeecore/sql/sql.java diff --git a/src/de/steamwar/bungeecore/ArenaMode.java b/src/de/steamwar/bungeecore/ArenaMode.java index e96627e..bfb0fbb 100644 --- a/src/de/steamwar/bungeecore/ArenaMode.java +++ b/src/de/steamwar/bungeecore/ArenaMode.java @@ -4,5 +4,6 @@ public enum ArenaMode { AirShip, WarShip, WarGear, - MiniWarGear + MiniWarGear, + UNKNOWN } diff --git a/src/de/steamwar/bungeecore/Broadcaster.java b/src/de/steamwar/bungeecore/Broadcaster.java new file mode 100644 index 0000000..6d81deb --- /dev/null +++ b/src/de/steamwar/bungeecore/Broadcaster.java @@ -0,0 +1,25 @@ +package de.steamwar.bungeecore; + +import net.md_5.bungee.api.ProxyServer; + +import java.util.concurrent.TimeUnit; + +class Broadcaster { + + private static String [] broadCastMsgs; + private int lastBroadCast = 0; + + Broadcaster(){ + ProxyServer.getInstance().getScheduler().schedule(BungeeCore.get(), () -> { + BungeeCore.broadcast(BungeeCore.CHAT_PREFIX + broadCastMsgs[lastBroadCast]); + lastBroadCast++; + if(lastBroadCast == broadCastMsgs.length){ + lastBroadCast = 0; + } + }, 10, 10, TimeUnit.MINUTES); + } + + static void setBroadCastMsgs(String[] broadCastMsgs) { + Broadcaster.broadCastMsgs = broadCastMsgs; + } +} diff --git a/src/de/steamwar/bungeecore/BungeeCore.java b/src/de/steamwar/bungeecore/BungeeCore.java index d5a14e1..7f394d4 100644 --- a/src/de/steamwar/bungeecore/BungeeCore.java +++ b/src/de/steamwar/bungeecore/BungeeCore.java @@ -1,10 +1,22 @@ package de.steamwar.bungeecore; import de.steamwar.bungeecore.commands.*; -import de.steamwar.bungeecore.sql.WarkingUser; -import de.steamwar.bungeecore.sql.sql; +import de.steamwar.bungeecore.listeners.BanListener; +import de.steamwar.bungeecore.listeners.ChatListener; +import de.steamwar.bungeecore.listeners.ConnectionListener; +import de.steamwar.bungeecore.listeners.PollSystem; +import de.steamwar.bungeecore.listeners.mods.Forge; +import de.steamwar.bungeecore.listeners.mods.LabyMod; +import de.steamwar.bungeecore.sql.SQL; +import de.steamwar.bungeecore.sql.SteamwarUser; +import net.md_5.bungee.api.ChatMessageType; +import net.md_5.bungee.api.CommandSender; +import net.md_5.bungee.api.ProxyServer; +import net.md_5.bungee.api.chat.ClickEvent; +import net.md_5.bungee.api.chat.HoverEvent; +import net.md_5.bungee.api.chat.TextComponent; import net.md_5.bungee.api.config.ServerInfo; -import net.md_5.bungee.api.plugin.Command; +import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.plugin.Plugin; import net.md_5.bungee.config.Configuration; import net.md_5.bungee.config.ConfigurationProvider; @@ -13,6 +25,7 @@ import net.md_5.bungee.config.YamlConfiguration; import java.io.File; import java.io.IOException; import java.time.format.DateTimeFormatter; +import java.util.EnumMap; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -21,131 +34,179 @@ import java.util.logging.Level; public class BungeeCore extends Plugin { - public static BungeeCore instance; - public static String ChatPrefix; - public static String WorldFolder; - public static String BauweltPrototyp; - public static final String ServerTeamchatPrefix = "§8STC §e"; - public static final String TeamchatPrefix = "§8TC §e"; - public static final DateTimeFormatter DateFormat = DateTimeFormatter.ofPattern("dd.MM.yyyy"); - public static String LobbyServer; - private static String [] BroadCastMsgs; - private static int LastBroadCast = 0; + public static final String SERVER_TEAMCHAT_PREFIX = "§8STC §e"; + public static final String TEAMCHAT_PREFIX = "§8TC §e"; + public static final DateTimeFormatter DATE_FORMAT = DateTimeFormatter.ofPattern("dd.MM.yyyy"); + + public static String CHAT_PREFIX; + public static String WORLD_FOLDER; + public static String BAUWELT_PROTOTYP; + public static String LOBBY_SERVER; + + private static BungeeCore instance; + public static final Map serverPermissions = new HashMap<>(); public static final Map commands = new HashMap<>(); - public static final Map> arenaMaps = new HashMap<>(); + public static final Map> arenaMaps = new EnumMap<>(ArenaMode.class); @Override public void onEnable(){ - instance = this; + setInstance(this); + loadConfig(); + + new ConnectionListener(); + new Forge(); + new LabyMod(); + new ChatListener(); + new BanListener(); + + commands.put("/bau", ""); + + new TeamchatCommand(); + new MsgCommand(); + new RCommand(); + new PingCommand(); + new WebpwCommand(); + new AlertCommand(); + new KickCommand(); + new JoinmeCommand(); + new FightCommand(); + new HelpCommand(); + new BanCommand(); + new DenyCommand("watchcat", "wc"); + new ChallengeCommand(); + new TeamCommand(); + new ServerTeamchatCommand(); + new ForgeCommand(); + new EventCommand(); + new EventreloadCommand(); + new PollCommand(); + new MuteCommand(); + + new EventStarter(); + new Broadcaster(); + + getProxy().getScheduler().schedule(this, SteamwarUser::clearCache, 1, 1, TimeUnit.HOURS); + } + + @Override + public void onDisable(){ + SQL.close(); + } + + public static BungeeCore get() { + return instance; + } + + public static TextComponent stringToText(String msg){ + return new TextComponent(TextComponent.fromLegacyText(msg)); + } + public static void send(ProxiedPlayer player, String msg){ + send(player, msg, null, null); + } + public static void send(CommandSender sender, String msg){ + sender.sendMessage(stringToText(msg)); + } + public static void send(ProxiedPlayer player, ChatMessageType type, String msg){ + send(player, type, msg, null, null); + } + public static void send(ProxiedPlayer player, String msg, String onHover, ClickEvent onClick){ + send(player, ChatMessageType.SYSTEM, msg, onHover, onClick); + } + public static void send(ProxiedPlayer player, ChatMessageType type, String msg, String onHover, ClickEvent onClick){ + TextComponent message = stringToText(msg); + if(onHover != null) + message.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText(onHover))); + if(onClick != null) + message.setClickEvent(onClick); + player.sendMessage(type, message); + } + public static void broadcast(String msg){ + ProxyServer.getInstance().broadcast(stringToText(msg)); + } + public static void broadcast(String msg, String onHover, ClickEvent onClick){ + TextComponent message = stringToText(msg); + if(onHover != null) + message.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText(onHover))); + if(onClick != null) + message.setClickEvent(onClick); + ProxyServer.getInstance().broadcast(message); + } + + public static void log(final ServerInfo server, final String msg){ + log(server.getName() + ": " + msg); + } + public static void log(final ProxiedPlayer player, final String msg){ + log(player.getName() + ": " + msg); + } + public static void log(final String msg){ + log(Level.INFO, msg); + } + public static void log(final Level logLevel, final String msg){ + get().getLogger().log(logLevel, msg); + } + public static void log(final String msg, final Throwable e){ + get().getLogger().log(Level.SEVERE, msg, e); + } + + private static void loadConfig(){ Configuration config; try{ - if(!getDataFolder().exists()){ - getDataFolder().mkdir(); - } - File configFile = new File(getDataFolder().getPath(), "config.yml"); + if(!get().getDataFolder().exists() && !get().getDataFolder().mkdir()) + throw new IOException(); + File configFile = new File(get().getDataFolder().getPath(), "config.yml"); if(!configFile.exists()){ - configFile.createNewFile(); - config = ConfigurationProvider.getProvider(YamlConfiguration.class).load(configFile); - config.set("prefix", "SteamWar» "); - config.set("lobbyserver", "Lobby"); - config.set("db.url", "jdbc:mysql://127.0.0.1:3306/core"); - config.set("db.weburl", "jdbc:mysql://127.0.0.1:3306/Website"); - config.set("db.username", "root"); - config.set("db.password", "$password"); - String [] cmd = {"l", "hub", "lobby"}; - config.set("servers.HunjyLobby.commands", cmd); - String [] bcs = {"Standardmitteilung!"}; - config.set("broadcasts", bcs); - config.set("servers.HunjyLobby.permission", "bungeecore.server.user"); - ConfigurationProvider.getProvider(YamlConfiguration.class).save(config, configFile); + boolean created = configFile.createNewFile(); + if(created) + ProxyServer.getInstance().stop("Config file not initialized"); + else + ProxyServer.getInstance().stop("Could not save conig file"); + return; } config = ConfigurationProvider.getProvider(YamlConfiguration.class).load(configFile); }catch(IOException e){ - System.err.println("Error not create/load config.yml, Aborting!"); + log("Could not save/load config.yml", e); + ProxyServer.getInstance().stop(); return; } - ChatPrefix = config.getString("prefix"); - WorldFolder = config.getString("worldfolder"); - BauweltPrototyp = config.getString("bauweltprototyp"); - LobbyServer = config.getString("lobbyserver"); - sql.connect( + CHAT_PREFIX = config.getString("prefix"); + WORLD_FOLDER = config.getString("worldfolder"); + BAUWELT_PROTOTYP = config.getString("bauweltprototyp"); + LOBBY_SERVER = config.getString("lobbyserver"); + Broadcaster.setBroadCastMsgs(config.getStringList("broadcasts").toArray(new String[1])); + PollSystem.init(config.getString("poll.question"), config.getStringList("poll.answers")); + Persistent.setChatPrefix(CHAT_PREFIX); + Persistent.setLobbyServer(LOBBY_SERVER); + + SQL.connect( config.getString("db.url"), config.getString("db.weburl"), config.getString("db.username"), config.getString("db.password") ); - getProxy().getPluginManager().registerListener(this, new PlayerListener()); - getProxy().getPluginManager().registerListener(this, new ModSystem()); - - final Configuration servers = config.getSection("servers"); - for(final String serverName : servers.getKeys()){ - final Configuration server = servers.getSection(serverName); - List commands = server.getStringList("commands"); - serverPermissions.put(serverName, "bungeecore.server." + server.getString("permission")); - String cmd = commands.remove(0); - addCmd(new ServerSwitchCommand( - cmd, - serverName, - serverPermissions.get(serverName), - commands.toArray(new String[0]) - )); - } - commands.put("/bau", ""); - commands.remove("/bauserver"); - final Configuration maps = config.getSection("maps"); for(final String modeName : maps.getKeys()){ arenaMaps.put(ArenaMode.valueOf(modeName), maps.getStringList(modeName)); } - addCmd(new TeamchatCommand()); - addCmd(new MsgCommand()); - addCmd(new RCommand()); - addCmd(new PingCommand()); - addCmd(new WebpwCommand()); - addCmd(new AlertCommand()); - addCmd(new KickCommand()); - addCmd(new JoinmeCommand()); - addCmd(new FightCommand()); - addCmd(new HelpCommand()); - addCmd(new BanCommand()); - addCmd(new DenyCommand("watchcat", "wc")); - addCmd(new ChallengeCommand()); - addCmd(new TeamCommand()); - addCmd(new ServerTeamchatCommand()); - addCmd(new ForgeCommand()); - - BroadCastMsgs = config.getStringList("broadcasts").toArray(new String[1]); - getProxy().getScheduler().schedule(this, () -> { - getProxy().broadcast(ChatPrefix + BroadCastMsgs[LastBroadCast]); - LastBroadCast++; - if(LastBroadCast == BroadCastMsgs.length){ - LastBroadCast = 0; - } - }, 10, 10, TimeUnit.MINUTES); - - Persistent.setChatPrefix(ChatPrefix); - Persistent.setLobbyServer(LobbyServer); - getProxy().getScheduler().schedule(this, WarkingUser::clearCache, 1, 1, TimeUnit.HOURS); + final Configuration servers = config.getSection("servers"); + for(final String serverName : servers.getKeys()){ + final Configuration server = servers.getSection(serverName); + List cmds = server.getStringList("commands"); + serverPermissions.put(serverName, "bungeecore.server." + server.getString("permission")); + String cmd = cmds.remove(0); + new ServerSwitchCommand( + cmd, + serverName, + serverPermissions.get(serverName), + cmds.toArray(new String[0]) + ); + } } - @Override - public void onDisable(){ - sql.close(); - } - - static void log(final String message, final ServerInfo server){ - log("[" + server.getName() + "] " + message); - } - - public static void log(final String message){ - instance.getLogger().log(Level.INFO, message); - } - - private void addCmd(Command cmd){ - getProxy().getPluginManager().registerCommand(this, cmd); + private static void setInstance(BungeeCore core){ + instance = core; } } diff --git a/src/de/steamwar/bungeecore/EventStarter.java b/src/de/steamwar/bungeecore/EventStarter.java new file mode 100644 index 0000000..058f372 --- /dev/null +++ b/src/de/steamwar/bungeecore/EventStarter.java @@ -0,0 +1,66 @@ +package de.steamwar.bungeecore; + +import de.steamwar.bungeecore.sql.EventFight; +import de.steamwar.bungeecore.sql.SteamwarUser; +import de.steamwar.bungeecore.sql.Team; +import net.md_5.bungee.api.ProxyServer; +import net.md_5.bungee.api.connection.ProxiedPlayer; +import net.md_5.bungee.api.scheduler.ScheduledTask; + +import java.sql.Timestamp; +import java.util.HashMap; +import java.util.Map; +import java.util.Queue; +import java.util.concurrent.TimeUnit; + +public class EventStarter implements Runnable { + + private static final Map eventServer = new HashMap<>(); + private static ScheduledTask task = null; + + EventStarter(){ + EventFight.loadAllComingFights(); + + if(task != null) + task.cancel(); + + ProxyServer.getInstance().getScheduler().schedule(BungeeCore.get(), this, 1, 10, TimeUnit.SECONDS); + } + + public static Map getEventServer() { + return eventServer; + } + + @Override + public void run() { + eventServer.entrySet().removeIf(entry -> !Subserver.getServerList().contains(entry.getValue())); + Queue fights = EventFight.getFights(); + + EventFight next; + while((next = nextFight(fights)) != null){ + Team blue = Team.get(next.getTeamBlue()); + Team red = Team.get(next.getTeamRed()); + String serverName = blue.getTeamKuerzel() + " vs " + red.getTeamKuerzel(); + Subserver subserver = SubserverSystem.startEventArena(next, serverName); + + ProxiedPlayer leiter = ProxyServer.getInstance().getPlayer(SteamwarUser.get(next.getKampfleiter()).getUuid()); + if(leiter != null) + subserver.sendPlayer(leiter); + + eventServer.put(blue, subserver); + eventServer.put(red, subserver); + BungeeCore.broadcast(BungeeCore.CHAT_PREFIX + "§7Hier §eklicken §7für den Kampf §e" + blue.getTeamName() + " §8vs §e" + red.getTeamName()); + } + } + + private EventFight nextFight(Queue fights){ + EventFight next = fights.peek(); + if(next == null) + return null; + + if(!next.getStartTime().before(new Timestamp(System.currentTimeMillis()))) + return null; + + return fights.poll(); + } +} diff --git a/src/de/steamwar/bungeecore/ModSystem.java b/src/de/steamwar/bungeecore/ModSystem.java deleted file mode 100644 index fae9a8f..0000000 --- a/src/de/steamwar/bungeecore/ModSystem.java +++ /dev/null @@ -1,431 +0,0 @@ -package de.steamwar.bungeecore; - -import com.google.common.base.Charsets; -import io.netty.buffer.ByteBuf; -import io.netty.buffer.UnpooledByteBufAllocator; -import javafx.util.Pair; -import net.md_5.bungee.api.ProxyServer; -import net.md_5.bungee.api.connection.Connection; -import net.md_5.bungee.api.connection.ProxiedPlayer; -import net.md_5.bungee.api.event.PluginMessageEvent; -import net.md_5.bungee.api.event.PostLoginEvent; -import net.md_5.bungee.api.plugin.Listener; -import net.md_5.bungee.event.EventHandler; - -import java.util.Arrays; - -public class ModSystem implements Listener { - - private static final String FMLHS; - private static final byte[] REGISTER; - private static final byte[] HELLO; - private static final byte[] MODS; - private static final byte[] REGISTRY; - private static boolean enabled; - - public static void toggleEnabled(){ - enabled = !enabled; - } - - static{ - enabled = false; - - FMLHS = "FML|HS"; - - ByteBuf buf = UnpooledByteBufAllocator.DEFAULT.directBuffer(7); - buf.writeByte(6); - buf.writeCharSequence(FMLHS, Charsets.UTF_8); - REGISTER = new byte[buf.readableBytes()]; - buf.readBytes(REGISTER); - - HELLO = new byte[]{0, 2, 0, 0, 0, 0}; - - //Packet 2, ein Mod, minecraft 1.12.2 - MODS = new byte[]{2, 1, 9, 109, 105, 110, 101, 99, 114, 97, 102, 116, 6, 49, 46, 49, 50, 46, 50}; - - ByteBuf bb = UnpooledByteBufAllocator.DEFAULT.directBuffer(100); - bb.writeByte(3); - bb.writeByte(0); - bb.writeByte(9); - bb.writeCharSequence("minecraft", Charsets.UTF_8); - bb.writeByte(253); //VarInt 253, Missing: 36, 253, 254 - bb.writeByte(1); //VarInt +128 - registerId(bb, 0, "air"); - registerId(bb, 1, "stone"); - registerId(bb, 2, "grass"); - registerId(bb, 3, "dirt"); - registerId(bb, 4, "cobblestone"); - registerId(bb, 5, "planks"); - registerId(bb, 6, "sapling"); - registerId(bb, 7, "bedrock"); - registerId(bb, 8, "flowing_water"); - registerId(bb, 9, "water"); - registerId(bb, 10, "flowing_lava"); - registerId(bb, 11, "lava"); - registerId(bb, 12, "sand"); - registerId(bb, 13, "gravel"); - registerId(bb, 14, "gold_ore"); - registerId(bb, 15, "iron_ore"); - registerId(bb, 16, "coal_ore"); - registerId(bb, 17, "log"); - registerId(bb, 18, "leaves"); - registerId(bb, 19, "sponge"); - registerId(bb, 20, "glass"); - registerId(bb, 21, "lapis_ore"); - registerId(bb, 22, "lapis_block"); - registerId(bb, 23, "dispenser"); - registerId(bb, 24, "sandstone"); - registerId(bb, 25, "noteblock"); - registerId(bb, 26, "bed"); - registerId(bb, 27, "golden_rail"); - registerId(bb, 28, "detector_rail"); - registerId(bb, 29, "sticky_piston"); - registerId(bb, 30, "web"); - registerId(bb, 31, "tallgrass"); - registerId(bb, 32, "deadbush"); - registerId(bb, 33, "piston"); - registerId(bb, 34, "piston_head"); - registerId(bb, 35, "wool"); - registerId(bb, 37, "yellow_flower"); - registerId(bb, 38, "red_flower"); - registerId(bb, 39, "brown_mushroom"); - registerId(bb, 40, "red_mushroom"); - registerId(bb, 41, "gold_block"); - registerId(bb, 42, "iron_block"); - registerId(bb, 43, "double_stone_slab"); - registerId(bb, 44, "stone_slab"); - registerId(bb, 45, "brick_block"); - registerId(bb, 46, "tnt"); - registerId(bb, 47, "bookshelf"); - registerId(bb, 48, "mossy_cobblestone"); - registerId(bb, 49, "obsidian"); - registerId(bb, 50, "torch"); - registerId(bb, 51, "fire"); - registerId(bb, 52, "mob_spawner"); - registerId(bb, 53, "oak_stairs"); - registerId(bb, 54, "chest"); - registerId(bb, 55, "redstone_wire"); - registerId(bb, 56, "diamond_ore"); - registerId(bb, 57, "diamond_block"); - registerId(bb, 58, "crafting_table"); - registerId(bb, 59, "wheat"); - registerId(bb, 60, "farmland"); - registerId(bb, 61, "furnace"); - registerId(bb, 62, "lit_furnace"); - registerId(bb, 63, "standing_sign"); - registerId(bb, 64, "wooden_door"); - registerId(bb, 65, "ladder"); - registerId(bb, 66, "rail"); - registerId(bb, 67, "stone_stairs"); - registerId(bb, 68, "wall_sign"); - registerId(bb, 69, "lever"); - registerId(bb, 70, "stone_pressure_plate"); - registerId(bb, 71, "iron_door"); - registerId(bb, 72, "wooden_pressure_plate"); - registerId(bb, 73, "redstone_ore"); - registerId(bb, 74, "lit_redstone_ore"); - registerId(bb, 75, "unlit_redstone_torch"); - registerId(bb, 76, "redstone_torch"); - registerId(bb, 77, "stone_button"); - registerId(bb, 78, "snow_layer"); - registerId(bb, 79, "ice"); - registerId(bb, 80, "snow"); - registerId(bb, 81, "cactus"); - registerId(bb, 82, "clay"); - registerId(bb, 83, "reeds"); - registerId(bb, 84, "jukebox"); - registerId(bb, 85, "fence"); - registerId(bb, 86, "pumpkin"); - registerId(bb, 87, "netherrack"); - registerId(bb, 88, "soul_sand"); - registerId(bb, 89, "glowstone"); - registerId(bb, 90, "portal"); - registerId(bb, 91, "lit_pumpkin"); - registerId(bb, 92, "cake"); - registerId(bb, 93, "unpowered_repeater"); - registerId(bb, 94, "powered_repeater"); - registerId(bb, 95, "stained_glass"); - registerId(bb, 96, "trapdoor"); - registerId(bb, 97, "monster_egg"); - registerId(bb, 98, "stonebrick"); - registerId(bb, 99, "brown_mushroom_block"); - registerId(bb, 100, "red_mushroom_block"); - registerId(bb, 101, "iron_bars"); - registerId(bb, 102, "glass_pane"); - registerId(bb, 103, "melon_block"); - registerId(bb, 104, "pumpkin_stem"); - registerId(bb, 105, "melon_stem"); - registerId(bb, 106, "vine"); - registerId(bb, 107, "fence_gate"); - registerId(bb, 108, "brick_stairs"); - registerId(bb, 109, "stone_brick_stairs"); - registerId(bb, 110, "mycelium"); - registerId(bb, 111, "waterlily"); - registerId(bb, 112, "nether_brick"); - registerId(bb, 113, "nether_brick_fence"); - registerId(bb, 114, "nether_brick_stairs"); - registerId(bb, 115, "nether_wart"); - registerId(bb, 116, "enchanting_table"); - registerId(bb, 117, "brewing_stand"); - registerId(bb, 118, "cauldron"); - registerId(bb, 119, "end_portal"); - registerId(bb, 120, "end_portal_frame"); - registerId(bb, 121, "end_stone"); - registerId(bb, 122, "dragon_egg"); - registerId(bb, 123, "redstone_lamp"); - registerId(bb, 124, "lit_redstone_lamp"); - registerId(bb, 125, "double_wooden_slab"); - registerId(bb, 126, "wooden_slab"); - registerId(bb, 127, "cocoa"); - registerId(bb, 128, "sandstone_stairs"); - registerId(bb, 129, "emerald_ore"); - registerId(bb, 130, "ender_chest"); - registerId(bb, 131, "tripwire_hook"); - registerId(bb, 132, "tripwire"); - registerId(bb, 133, "emerald_block"); - registerId(bb, 134, "spruce_stairs"); - registerId(bb, 135, "birch_stairs"); - registerId(bb, 136, "jungle_stairs"); - registerId(bb, 137, "command_block"); - registerId(bb, 138, "beacon"); - registerId(bb, 139, "cobblestone_wall"); - registerId(bb, 140, "flower_pot"); - registerId(bb, 141, "carrots"); - registerId(bb, 142, "potatoes"); - registerId(bb, 143, "wooden_button"); - registerId(bb, 144, "skull"); - registerId(bb, 145, "anvil"); - registerId(bb, 146, "trapped_chest"); - registerId(bb, 147, "light_weighted_pressure_plate"); - registerId(bb, 148, "heavy_weighted_pressure_plate"); - registerId(bb, 149, "unpowered_comparator"); - registerId(bb, 150, "powered_comparator"); - registerId(bb, 151, "daylight_detector"); - registerId(bb, 152, "redstone_block"); - registerId(bb, 153, "quartz_ore"); - registerId(bb, 154, "hopper"); - registerId(bb, 155, "quartz_block"); - registerId(bb, 156, "quartz_stairs"); - registerId(bb, 157, "activator_rail"); - registerId(bb, 158, "dropper"); - registerId(bb, 159, "stained_hardened_clay"); - registerId(bb, 160, "stained_glass_pane"); - registerId(bb, 161, "leaves2"); - registerId(bb, 162, "log2"); - registerId(bb, 163, "acacia_stairs"); - registerId(bb, 164, "dark_oak_stairs"); - registerId(bb, 165, "slime"); - registerId(bb, 166, "barrier"); - registerId(bb, 167, "iron_trapdoor"); - registerId(bb, 168, "prismarine"); - registerId(bb, 169, "sea_lantern"); - registerId(bb, 170, "hay_block"); - registerId(bb, 171, "carpet"); - registerId(bb, 172, "hardened_clay"); - registerId(bb, 173, "coal_block"); - registerId(bb, 174, "packed_ice"); - registerId(bb, 175, "double_plant"); - registerId(bb, 176, "standing_banner"); - registerId(bb, 177, "wall_banner"); - registerId(bb, 178, "daylight_detector_inverted"); - registerId(bb, 179, "red_sandstone"); - registerId(bb, 180, "red_sandstone_stairs"); - registerId(bb, 181, "double_stone_slab2"); - registerId(bb, 182, "stone_slab2"); - registerId(bb, 183, "spruce_fence_gate"); - registerId(bb, 184, "birch_fence_gate"); - registerId(bb, 185, "jungle_fence_gate"); - registerId(bb, 186, "dark_oak_fence_gate"); - registerId(bb, 187, "acacia_fence_gate"); - registerId(bb, 188, "spruce_fence"); - registerId(bb, 189, "birch_fence"); - registerId(bb, 190, "jungle_fence"); - registerId(bb, 191, "dark_oak_fence"); - registerId(bb, 192, "acacia_fence"); - registerId(bb, 193, "spruce_door"); - registerId(bb, 194, "birch_door"); - registerId(bb, 195, "jungle_door"); - registerId(bb, 196, "acacia_door"); - registerId(bb, 197, "dark_oak_door"); - registerId(bb, 198, "end_rod"); - registerId(bb, 199, "chorus_plant"); - registerId(bb, 200, "chorus_flower"); - registerId(bb, 201, "purpur_block"); - registerId(bb, 202, "purpur_pillar"); - registerId(bb, 203, "purpur_stairs"); - registerId(bb, 204, "purpur_double_slab"); - registerId(bb, 205, "purpur_slab"); - registerId(bb, 206, "end_bricks"); - registerId(bb, 207, "beetroots"); - registerId(bb, 208, "grass_path"); - registerId(bb, 209, "end_gateway"); - registerId(bb, 210, "repeating_command_block"); - registerId(bb, 211, "chain_command_block"); - registerId(bb, 212, "frosted_ice"); - registerId(bb, 213, "magma"); - registerId(bb, 214, "nether_wart_block"); - registerId(bb, 215, "red_nether_brick"); - registerId(bb, 216, "bone_block"); - registerId(bb, 217, "structure_void"); - registerId(bb, 218, "observer"); - registerId(bb, 219, "white_shulker_box"); - registerId(bb, 220, "orange_shulker_box"); - registerId(bb, 221, "magenta_shulker_box"); - registerId(bb, 222, "light_blue_shulker_box"); - registerId(bb, 223, "yellow_shulker_box"); - registerId(bb, 224, "lime_shulker_box"); - registerId(bb, 225, "pink_shulker_box"); - registerId(bb, 226, "gray_shulker_box"); - registerId(bb, 227, "silver_shulker_box"); - registerId(bb, 228, "cyan_shulker_box"); - registerId(bb, 229, "purple_shulker_box"); - registerId(bb, 230, "blue_shulker_box"); - registerId(bb, 231, "brown_shulker_box"); - registerId(bb, 232, "green_shulker_box"); - registerId(bb, 233, "red_shulker_box"); - registerId(bb, 234, "black_shulker_box"); - registerId(bb, 235, "white_glazed_terracotta"); - registerId(bb, 236, "orange_glazed_terracotta"); - registerId(bb, 237, "magenta_glazed_terracotta"); - registerId(bb, 238, "light_blue_glazed_terracotta"); - registerId(bb, 239, "yellow_glazed_terracotta"); - registerId(bb, 240, "lime_glazed_terracotta"); - registerId(bb, 241, "pink_glazed_terracotta"); - registerId(bb, 242, "gray_glazed_terracotta"); - registerId(bb, 243, "light_gray_glazed_terracotta"); - registerId(bb, 244, "cyan_glazed_terracotta"); - registerId(bb, 245, "purple_glazed_terracotta"); - registerId(bb, 246, "blue_glazed_terracotta"); - registerId(bb, 247, "brown_glazed_terracotta"); - registerId(bb, 248, "green_glazed_terracotta"); - registerId(bb, 249, "red_glazed_terracotta"); - registerId(bb, 250, "black_glazed_terracotta"); - registerId(bb, 251, "concrete"); - registerId(bb, 252, "concrete_powder"); - registerId(bb, 255, "structure_block"); - bb.writeByte(0); - bb.writeByte(0); - REGISTRY = new byte[bb.readableBytes()]; - bb.readBytes(REGISTRY); - } - - @EventHandler - public void onPostLogin(PostLoginEvent event) { - ProxiedPlayer player = event.getPlayer(); - - if(!enabled) - return; - - if(player.getPendingConnection().getVersion() > 340){ - //1.13+ - player.sendData("minecraft:register", REGISTER); - }else{ - //1.12- - player.sendData("REGISTER", REGISTER); - } - - player.sendData(FMLHS, HELLO); - } - - @EventHandler - public void onPluginMessageEvent(PluginMessageEvent e){ - System.out.println(e.getSender().getAddress().getHostString() + " " + e.getTag() + " " + Arrays.toString(e.getData())); - - if(e.getTag().equals("LMC")) { - e.setCancelled(true); - byte[] data = e.getData(); - Pair purpose = readString(data, 0); - Pair value = readString(data, purpose.getKey()); - System.out.println(purpose.getValue()); - System.out.println(value.getValue()); - return; - }else if(!e.getTag().equals(FMLHS)){ - return; - } - - if(!enabled) - return; - e.setCancelled(true); - byte[] data = e.getData(); - ProxiedPlayer p = getPlayer(e.getSender()); - if(p == null) - return; - - switch(data[0]){ - case 2: - Pair numMods = readVarInt(data, 1); - System.out.println("Number of mods: " + numMods); - int bytePos = 1 + numMods.getKey(); - for(int i = 0; i < numMods.getValue(); i++){ - byte[] name = Arrays.copyOfRange(data, bytePos + 1, bytePos + data[bytePos] + 1); - bytePos += 1 + data[bytePos]; - byte[] version = Arrays.copyOfRange(data, bytePos + 1, bytePos + data[bytePos] + 1); - bytePos += 1 + data[bytePos]; - - System.out.println(new String(name) + " " + new String(version)); - } - - p.sendData(FMLHS, MODS); - break; - case -1: - switch(data[1]){ - case 2: - p.sendData(FMLHS, REGISTRY); - break; - case 3: - p.sendData(FMLHS, new byte[]{-1, 2}); - break; - case 4: - p.sendData(FMLHS, new byte[]{-1, 3}); - break; - default: - break; - } - break; - case 1: - default: - break; - } - } - - private static void registerId(ByteBuf bb, int id, String name){ - bb.writeByte(name.length()); - bb.writeCharSequence(name, Charsets.UTF_8); - bb.writeByte(id); - if(id > 127) - bb.writeByte(1); - } - - private static ProxiedPlayer getPlayer(Connection c){ - for(ProxiedPlayer p : ProxyServer.getInstance().getPlayers()){ - if(p.getPendingConnection().getAddress().equals(c.getAddress())){ - return p; - } - } - return null; - } - - private static Pair readVarInt(byte[] array, int startPos) { - int numRead = 0; - int result = 0; - byte read; - do { - read = array[startPos + numRead]; - int value = (read & 0b01111111); - result |= (value << (7 * numRead)); - - numRead++; - if (numRead > 5) { - break; - } - } while ((read & 0b10000000) != 0); - - return new Pair<>(numRead, result); - } - - private static Pair readString(byte[] array, int startPos){ - Pair varInt = readVarInt(array, startPos); - startPos += varInt.getKey(); - return new Pair<>(varInt.getValue()+varInt.getKey(), new String(Arrays.copyOfRange(array, startPos, startPos + varInt.getValue()), Charsets.UTF_8)); - } -} diff --git a/src/de/steamwar/bungeecore/PlayerListener.java b/src/de/steamwar/bungeecore/PlayerListener.java deleted file mode 100644 index d6adf69..0000000 --- a/src/de/steamwar/bungeecore/PlayerListener.java +++ /dev/null @@ -1,266 +0,0 @@ -package de.steamwar.bungeecore; - -import de.steamwar.bungeecore.commands.BauCommand; -import de.steamwar.bungeecore.commands.ChallengeCommand; -import de.steamwar.bungeecore.sql.BannedUserIPs; -import de.steamwar.bungeecore.sql.Team; -import de.steamwar.bungeecore.sql.WarkingUser; -import net.md_5.bungee.api.AbstractReconnectHandler; -import net.md_5.bungee.api.ChatColor; -import net.md_5.bungee.api.ProxyServer; -import net.md_5.bungee.api.chat.ClickEvent; -import net.md_5.bungee.api.chat.ComponentBuilder; -import net.md_5.bungee.api.chat.HoverEvent; -import net.md_5.bungee.api.chat.TextComponent; -import net.md_5.bungee.api.config.ServerInfo; -import net.md_5.bungee.api.connection.ProxiedPlayer; -import net.md_5.bungee.api.event.*; -import net.md_5.bungee.api.plugin.Listener; -import net.md_5.bungee.event.EventHandler; - -import java.util.Iterator; -import java.util.List; - -public class PlayerListener implements Listener { - - @EventHandler - public void onLogin(LoginEvent event) { - WarkingUser user = new WarkingUser(event.getConnection()); - if(user.isBanned()) { - user.updateBanIP(event.getConnection().getAddress().getAddress().getHostAddress()); - event.setCancelled(true); - if (user.getBanTime().before(WarkingUser.PermaBan)) { - event.setCancelReason(new TextComponent(BungeeCore.ChatPrefix + "§cDu bist permanent gebannt. §r§lGrund§r: §c" + user.getBanReason())); - } else { - event.setCancelReason(new TextComponent(BungeeCore.ChatPrefix + " Du bist bis zum " + - user.getBanTime().toLocalDateTime().format(BungeeCore.DateFormat) + " gebannt. §r§lGrund§r: §c" + user.getBanReason())); - } - return; - } - - List ips = BannedUserIPs.get(event.getConnection().getAddress().getAddress().getHostAddress()); - if(!ips.isEmpty()){ - StringBuilder potentialBan = new StringBuilder(); - potentialBan.append(BungeeCore.ChatPrefix); - potentialBan.append("§cMögliche Bannumgehung durch §r"); - potentialBan.append(user.getUserName()); - potentialBan.append("§c:"); - - for(BannedUserIPs banned : ips){ - WarkingUser bannedUser = new WarkingUser(banned.getUserID()); - potentialBan.append(" §e"); - potentialBan.append(banned.getTimestamp().toLocalDateTime().format(BungeeCore.DateFormat)); - potentialBan.append(" §c"); - potentialBan.append(bannedUser.getUserName()); - } - - TextComponent msg = new TextComponent(potentialBan.toString()); - msg.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§cBanne Spieler wegen Bannumgehung").create())); - msg.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/ban " + user.getUserName() + " perma Bannumgehung")); - for (ProxiedPlayer target : ProxyServer.getInstance().getPlayers()){ - if ((target.hasPermission("bungeecore.teamchat")) - && (target.getChatMode() == ProxiedPlayer.ChatMode.COMMANDS_ONLY - || target.getChatMode() == ProxiedPlayer.ChatMode.SHOWN)){ - target.sendMessage(msg); - } - } - } - } - - @EventHandler - public void onPostLogin(PostLoginEvent event) { - ProxiedPlayer player = event.getPlayer(); - WarkingUser user = WarkingUser.get(player.getUniqueId()); - player.removeGroups("Admin", "team"); - switch(user.getUserGroup()){ - case "Admin": - player.addGroups("admin", "team"); - player.setPermission("bungeecore.group.admin", true); - player.setDisplayName("§4Admin " + player.getName() + "§r"); - break; - case "Developer": - player.addGroups("admin", "team"); - player.setPermission("bungeecore.group.developer", true); - player.setDisplayName("§3Developer " + player.getName() + "§r"); - break; - case "Moderator": - player.addGroups("admin", "team"); - player.setPermission("bungeecore.group.moderator", true); - player.setDisplayName("§bModerator " + player.getName() + "§r"); - break; - case "Supporter": - player.addGroups("team"); - player.setPermission("bungeecore.group.supporter", true); - player.setDisplayName("§1Supporter " + player.getName() + "§r"); - break; - case "Builder": - player.addGroups("team"); - player.setPermission("bungeecore.group.builder", true); - player.setDisplayName("§2Architekt " + player.getName() + "§r"); - break; - case "Youtuber": - player.setPermission("bungeecore.group.youtuber", true); - player.setDisplayName("§5Youtuber " + player.getName() + "§r"); - break; - case "Member": - default: - player.setDisplayName(player.getName()); - break; - } - - for(Subserver subserver : Subserver.getServerList()){ - if(subserver.getType() == Servertype.ARENA){ - Iterator it = subserver.getServer().getPlayers().iterator(); - if(it.hasNext()){ - TextComponent tc = new TextComponent(BungeeCore.ChatPrefix + "§7Klicke §ehier§7, um §e" + subserver.getServer().getName() + " §7beizutreten"); - tc.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§eArena beitreten").create())); - tc.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/join " + it.next().getName())); - player.sendMessage(tc); - } - } - } - - if(player.getPendingConnection().getVersion() < 335 || player.getPendingConnection().getVersion() > 340){ - player.sendMessage(BungeeCore.ChatPrefix + "§cWir empfehlen die Minecraft-Version 1.12.2"); - } - } - - /** To redirect players to the lobby in case of server closure. */ - @EventHandler - public void onServerKickEvent(ServerKickEvent ev) - { - ServerInfo kickedFrom; - - if (ev.getPlayer().getServer() != null){ - kickedFrom = ev.getPlayer().getServer().getInfo(); - }else if (ProxyServer.getInstance().getReconnectHandler() != null){ - kickedFrom = ProxyServer.getInstance().getReconnectHandler().getServer(ev.getPlayer()); - }else{ - kickedFrom = AbstractReconnectHandler.getForcedHost(ev.getPlayer().getPendingConnection()); - if (kickedFrom == null){ - kickedFrom = ProxyServer.getInstance().getServerInfo(ev.getPlayer().getPendingConnection().getListener().getDefaultServer()); - } - } - - ServerInfo kickTo = ProxyServer.getInstance().getServerInfo(BungeeCore.LobbyServer); - - if (kickedFrom != null && kickedFrom.equals(kickTo)) { - return; - } - - ev.setCancelled(true); - ev.setCancelServer(kickTo); - } - - @EventHandler - public void onDisconnect(PlayerDisconnectEvent e){ - ChallengeCommand.challenges.remove(e.getPlayer()); - } - - private void localChat(ChatEvent e, String [] command){ - System.out.println(((ProxiedPlayer) e.getSender()).getDisplayName() + ": " + e.getMessage()); - if(command.length == 1){ - ((ProxiedPlayer) e.getSender()).sendMessage(BungeeCore.ChatPrefix + "§8/§e" + command[0].substring(1) + " §8[§7Nachricht§8]"); - e.setCancelled(true); - return; - } - e.setMessage(e.getMessage().substring(command[0].length() + 1)); - } - - @EventHandler - public void onChatEvent(ChatEvent e){ - if(e.getMessage().startsWith("/")){ - String [] command = e.getMessage().split(" "); - if(command[0].contains(":")){ - e.setCancelled(true); - if(e.getSender() instanceof ProxiedPlayer){ - ProxiedPlayer sender = (ProxiedPlayer) e.getSender(); - sender.sendMessage(BungeeCore.ChatPrefix + "§cUnbekannter Befehl."); - } - }else if((command[0].equalsIgnoreCase("/bau") || command[0].equalsIgnoreCase("/b")) && e.getSender() instanceof ProxiedPlayer){ - System.out.println(((ProxiedPlayer) e.getSender()).getDisplayName() + ": " + e.getMessage()); - BauCommand.onBau(e, command); - }else if(command[0].equalsIgnoreCase("/bc") || command[0].equalsIgnoreCase("/bauchat") || command[0].equalsIgnoreCase("/local")){ - localChat(e, command); - } - }else{ - if(e.getSender() instanceof ProxiedPlayer){ - ProxiedPlayer sender = (ProxiedPlayer) e.getSender(); - if(sender.getChatMode() != ProxiedPlayer.ChatMode.SHOWN){ - sender.sendMessage(BungeeCore.ChatPrefix + "§cUm Chatnachrichten versenden zu können, musst du erst einmal welche empfangen!"); - e.setCancelled(true); - return; - } - - Subserver subserver = Subserver.getSubserver(sender); - if(subserver != null && subserver.getType() == Servertype.ARENA) - return; - - String name = sender.getDisplayName(); - String message = e.getMessage(); - String chatsuffix = "§7» "; - e.setCancelled(true); - - WarkingUser user = WarkingUser.get(sender.getUniqueId()); - if(sender.hasPermission("bungeecore.group.admin")){ - chatsuffix = "§7» §e"; - message = ChatColor.translateAlternateColorCodes('&', message); - }else if( - sender.hasPermission("bungeecore.group.developer") || - sender.hasPermission("bungeecore.group.moderator") || - sender.hasPermission("bungeecore.group.supporter") || - sender.hasPermission("bungeecore.group.builder")){ - chatsuffix = "§7» §r"; - message = ChatColor.translateAlternateColorCodes('&', message); - }else if(sender.hasPermission("bungeecore.group.youtuber")){ - message = ChatColor.translateAlternateColorCodes('&', message); - } - - String msg = name + chatsuffix + message; - if(user.getTeam() != 0){ - msg = "§8" + Team.get(user.getTeam()).getTeamKuerzel() + " §r" + msg; - } - for(ProxiedPlayer target : ProxyServer.getInstance().getPlayers()){ - Subserver targetServer = Subserver.getSubserver(target); - if(target.getChatMode() == ProxiedPlayer.ChatMode.SHOWN && (targetServer == null || targetServer.getType() != Servertype.ARENA)){ - target.sendMessage(msg); - } - } - BungeeCore.log(msg, sender.getServer().getInfo()); - } - } - } - - @EventHandler - public void onTabCompleteEvent(TabCompleteEvent e){ - List suggestions = e.getSuggestions(); - String [] cursor = e.getCursor().split(" "); - String last = cursor[cursor.length - 1]; - for(ProxiedPlayer player : ProxyServer.getInstance().getPlayers()){ - String name = player.getName(); - if(last.isEmpty() || name.startsWith(last)){ - suggestions.add(name); - } - } - if(e.getSender() instanceof ProxiedPlayer && cursor.length == 1 && cursor[0].startsWith("/")){ - ProxiedPlayer player = (ProxiedPlayer) e.getSender(); - for(String cmd : BungeeCore.commands.keySet()){ - if(cmd.startsWith(cursor[0]) && player.hasPermission(BungeeCore.commands.get(cmd))){ - suggestions.add(cmd); - } - } - } - } - - @EventHandler - public void onTabCompleteResponseEvent(TabCompleteResponseEvent e){ - List suggestions = e.getSuggestions(); - for(int i = 0; i < suggestions.size(); i++){ - String suggestion = suggestions.get(i); - if(suggestion.startsWith("/") && suggestion.contains(":")){ - suggestions.remove(suggestion); - i--; - } - } - } -} diff --git a/src/de/steamwar/bungeecore/SubserverSystem.java b/src/de/steamwar/bungeecore/SubserverSystem.java index 8e69e24..55bc421 100644 --- a/src/de/steamwar/bungeecore/SubserverSystem.java +++ b/src/de/steamwar/bungeecore/SubserverSystem.java @@ -1,12 +1,10 @@ package de.steamwar.bungeecore; import de.steamwar.bungeecore.sql.Bauwelt; -import de.steamwar.bungeecore.sql.WarkingUser; +import de.steamwar.bungeecore.sql.EventFight; +import de.steamwar.bungeecore.sql.SteamwarUser; import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.chat.ClickEvent; -import net.md_5.bungee.api.chat.ComponentBuilder; -import net.md_5.bungee.api.chat.HoverEvent; -import net.md_5.bungee.api.chat.TextComponent; import net.md_5.bungee.api.connection.ProxiedPlayer; import java.io.File; @@ -16,23 +14,30 @@ import java.util.UUID; public class SubserverSystem { private SubserverSystem(){} + private static final String MC_SCRIPT = "/home/minecraft/mc"; + public static void sendDeniedMessage(ProxiedPlayer p, UUID owner){ ProxiedPlayer o = ProxyServer.getInstance().getPlayer(owner); if(o == null) return; - o.sendMessage(BungeeCore.ChatPrefix + "§e" + p.getName() + " §7möchte auf deine Bauwelt."); - TextComponent tc = new TextComponent("§7Klicke §ehier§7, wenn du das erlauben möchtest."); - tc.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§e/bau addmember " + p.getName()).create())); - tc.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/bau addmember " + p.getName())); - o.sendMessage(tc); + BungeeCore.send(o, BungeeCore.CHAT_PREFIX + "§e" + p.getName() + " §7möchte auf deine Bauwelt."); + BungeeCore.send(o, "§7Klicke §ehier§7, wenn du das erlauben möchtest.", + "§e/bau addmember " + p.getName(), + new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/bau addmember " + p.getName())); } public static Subserver startArena(ArenaMode modus, String map){ int port = freePort(2500); String serverName = modus.name() + (port - 2500); return new Subserver(Servertype.ARENA, serverName, port, - "/home/minecraft/mc", "-a", modus.name(), serverName, Integer.toString(port), map); + MC_SCRIPT, "-a", modus.name(), serverName, Integer.toString(port), map, "0"); + } + + public static Subserver startEventArena(EventFight eventFight, String serverName){ + int port = freePort(2500); + return new Subserver(Servertype.ARENA, serverName, port, + MC_SCRIPT, "-a", eventFight.getSpielmodus().name(), serverName, Integer.toString(port), eventFight.getMap(), Integer.toString(eventFight.getFightID())); } public static void sendToBauServer(ProxiedPlayer p, UUID owner){ @@ -43,28 +48,38 @@ public class SubserverSystem { } } - File w = new File(BungeeCore.WorldFolder + owner); + File w = new File(BungeeCore.WORLD_FOLDER + owner); if (!w.exists() || !w.isDirectory()){ try { Process pr; ProcessBuilder pb = new ProcessBuilder( - "cp", "-r", BungeeCore.BauweltPrototyp, BungeeCore.WorldFolder + owner); + "cp", "-r", BungeeCore.BAUWELT_PROTOTYP, BungeeCore.WORLD_FOLDER + owner); pr = pb.start(); pr.waitFor(); - } catch (InterruptedException | IOException e) { - e.printStackTrace(); - p.sendMessage(BungeeCore.ChatPrefix + "§cDas Erstellen der Welt ist fehlgeschlagen."); + } catch (IOException e) { + BungeeCore.log("Could not create Bauwelt", e); + BungeeCore.send(p, BungeeCore.CHAT_PREFIX + "§cDas Erstellen der Welt ist fehlgeschlagen."); return; + } catch (InterruptedException e){ + BungeeCore.log("Could not create Bauwelt", e); + BungeeCore.send(p, BungeeCore.CHAT_PREFIX + "§cDas Erstellen der Welt ist fehlgeschlagen."); + Thread.currentThread().interrupt(); } if(Bauwelt.getBauwelt(owner) == null) new Bauwelt(owner, false, false); } - WarkingUser user = WarkingUser.get(owner); + SteamwarUser user = SteamwarUser.get(owner); int port = freePort(4000); new Bauserver(user.getUserName() + "s Bau", owner, port, - "/home/minecraft/mc", "-b", owner.toString(), Integer.toString(port)).sendPlayer(p); + MC_SCRIPT, "-b", owner.toString(), Integer.toString(port)).sendPlayer(p); + } + + public static void sendToTestServer(ProxiedPlayer p, ArenaMode m, String map){ + int port = freePort(4000); + String serverName = p.getName() + "s Bau"; + new Bauserver(serverName, p.getUniqueId(), port, MC_SCRIPT, "-a", m.name(), serverName, Integer.toString(port), map, "-1").sendPlayer(p); } private static int freePort(int start){ diff --git a/src/de/steamwar/bungeecore/commands/AlertCommand.java b/src/de/steamwar/bungeecore/commands/AlertCommand.java index 69db6c6..24671a5 100644 --- a/src/de/steamwar/bungeecore/commands/AlertCommand.java +++ b/src/de/steamwar/bungeecore/commands/AlertCommand.java @@ -3,9 +3,8 @@ package de.steamwar.bungeecore.commands; import de.steamwar.bungeecore.BungeeCore; import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.CommandSender; -import net.md_5.bungee.api.ProxyServer; -public class AlertCommand extends Command { +public class AlertCommand extends BasicCommand { public AlertCommand() { super("alert", "bungeecore.alert", "broadcast", "bbc"); @@ -14,17 +13,17 @@ public class AlertCommand extends Command { @Override public void execute(CommandSender sender, String[] args) { if(args.length == 0){ - sender.sendMessage(BungeeCore.ChatPrefix + "/alert [Nachricht]"); + BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "/alert [Nachricht]"); return; } StringBuilder msgBuilder = new StringBuilder(); - msgBuilder.append(BungeeCore.ChatPrefix); + msgBuilder.append(BungeeCore.CHAT_PREFIX); for (String arg : args){ msgBuilder.append(arg).append(" "); } String msg = msgBuilder.toString(); msg = ChatColor.translateAlternateColorCodes('&', msg); - ProxyServer.getInstance().broadcast(msg); + BungeeCore.broadcast(msg); } } diff --git a/src/de/steamwar/bungeecore/commands/BanCommand.java b/src/de/steamwar/bungeecore/commands/BanCommand.java index 3cbd8d4..e81688c 100644 --- a/src/de/steamwar/bungeecore/commands/BanCommand.java +++ b/src/de/steamwar/bungeecore/commands/BanCommand.java @@ -1,16 +1,16 @@ package de.steamwar.bungeecore.commands; import de.steamwar.bungeecore.BungeeCore; -import de.steamwar.bungeecore.sql.WarkingUser; -import net.md_5.bungee.api.*; -import net.md_5.bungee.api.connection.ProxiedPlayer; +import de.steamwar.bungeecore.sql.SteamwarUser; +import net.md_5.bungee.api.CommandSender; + import java.sql.Timestamp; import java.text.ParseException; import java.text.SimpleDateFormat; import java.time.Instant; -import java.util.*; +import java.util.Date; -public class BanCommand extends Command { +public class BanCommand extends BasicCommand { public BanCommand() { super("ban", "bungeecore.ban"); @@ -19,49 +19,39 @@ public class BanCommand extends Command { @Override public void execute(CommandSender sender, String[] args) { if(args.length < 3){ - sender.sendMessage(BungeeCore.ChatPrefix + "/ban [Spieler] [dd.mm.yyyy oder perma] [Grund]"); + BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "/ban [Spieler] [dd.mm.yyyy oder perma] [Grund]"); return; } - WarkingUser target = WarkingUser.get(args[0]); - if(target.getUserName() == null){ - sender.sendMessage(BungeeCore.ChatPrefix + "§cDer Spieler existiert nicht."); + SteamwarUser target = user(sender, args[0]); + if(target == null) return; - } - StringBuilder msgBuilder = new StringBuilder(); - msgBuilder.append(BungeeCore.ChatPrefix); - Timestamp banTime; - if(args[1].equalsIgnoreCase("perma")) { - msgBuilder.append("§cDu bist permanent gebannt. §r§lGrund§r: §c"); - banTime = Timestamp.from(Instant.ofEpochSecond(946674800)); - }else{ - SimpleDateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy"); - try{ - Date parsedDate = dateFormat.parse(args[1]); - banTime = new java.sql.Timestamp(parsedDate.getTime()); - msgBuilder.append(" Du bist bis zum "); - msgBuilder.append(banTime.toLocalDateTime().format(BungeeCore.DateFormat)); - msgBuilder.append(" gebannt. §r§lGrund§r: §c"); - }catch(ParseException e){ - sender.sendMessage(BungeeCore.ChatPrefix + "§cUngültige Zeitangabe."); - return; - } - } + Timestamp banTime = parseTime(sender, args[1]); + if(banTime == null) + return; StringBuilder banReason = new StringBuilder(); for (int i = 2; i < args.length; i++){ banReason.append(args[i]).append(" "); } String msg = banReason.toString(); - msgBuilder.append(msg); - sender.sendMessage(BungeeCore.ChatPrefix + "Du hast " + target.getUserName() + " gebannt. Grund: §c" + msg); - ProxiedPlayer targetPlayer = ProxyServer.getInstance().getPlayer(target.getUUID()); - if(targetPlayer != null){ - target.banPlayer(targetPlayer.getAddress().getAddress().getHostAddress(), banTime, msg); - targetPlayer.disconnect(msgBuilder.toString()); + BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "Du hast " + target.getUserName() + " gebannt. Grund: §c" + msg); + target.ban(banTime, msg); + } + + public static Timestamp parseTime(CommandSender sender, String arg){ + if(arg.equalsIgnoreCase("perma")) { + return Timestamp.from(Instant.ofEpochSecond(946674800)); }else{ - target.banPlayer("", banTime, msg); + SimpleDateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy"); + try{ + Date parsedDate = dateFormat.parse(arg); + return new java.sql.Timestamp(parsedDate.getTime()); + }catch(ParseException e){ + BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "§cUngültige Zeitangabe."); + return null; + } } } } diff --git a/src/de/steamwar/bungeecore/commands/Command.java b/src/de/steamwar/bungeecore/commands/BasicCommand.java similarity index 57% rename from src/de/steamwar/bungeecore/commands/Command.java rename to src/de/steamwar/bungeecore/commands/BasicCommand.java index f159368..1a9e384 100644 --- a/src/de/steamwar/bungeecore/commands/Command.java +++ b/src/de/steamwar/bungeecore/commands/BasicCommand.java @@ -1,22 +1,25 @@ package de.steamwar.bungeecore.commands; import de.steamwar.bungeecore.BungeeCore; +import de.steamwar.bungeecore.sql.SteamwarUser; import net.md_5.bungee.api.CommandSender; import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.connection.ProxiedPlayer; +import net.md_5.bungee.api.plugin.Command; import net.md_5.bungee.api.plugin.TabExecutor; import java.util.ArrayList; import java.util.List; -public abstract class Command extends net.md_5.bungee.api.plugin.Command implements TabExecutor { +abstract class BasicCommand extends Command implements TabExecutor { - public Command(String name, String permission, String... aliases) { + public BasicCommand(String name, String permission, String... aliases) { super(name, permission, aliases); BungeeCore.commands.put("/" + name, permission); + ProxyServer.getInstance().getPluginManager().registerCommand(BungeeCore.get(), this); } - public Iterable allPlayers(String begin) { + Iterable allPlayers(String begin) { List suggestions = new ArrayList<>(); for(ProxiedPlayer player : ProxyServer.getInstance().getPlayers()){ String playerName = player.getName(); @@ -29,4 +32,11 @@ public abstract class Command extends net.md_5.bungee.api.plugin.Command impleme public Iterable onTabComplete(CommandSender commandSender, String[] args) { return new ArrayList<>(); } + + protected SteamwarUser user(CommandSender sender, String arg){ + SteamwarUser target = SteamwarUser.get(arg); + if(target == null) + BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "§cDer Spieler existiert nicht."); + return target; + } } diff --git a/src/de/steamwar/bungeecore/commands/BauCommand.java b/src/de/steamwar/bungeecore/commands/BauCommand.java index 9f4d17d..61804cb 100644 --- a/src/de/steamwar/bungeecore/commands/BauCommand.java +++ b/src/de/steamwar/bungeecore/commands/BauCommand.java @@ -3,244 +3,246 @@ package de.steamwar.bungeecore.commands; import de.steamwar.bungeecore.*; import de.steamwar.bungeecore.sql.Bauwelt; import de.steamwar.bungeecore.sql.BauweltMember; -import de.steamwar.bungeecore.sql.Permission; -import de.steamwar.bungeecore.sql.WarkingUser; +import de.steamwar.bungeecore.sql.SteamwarUser; import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.event.ChatEvent; import java.io.File; -import java.util.UUID; public class BauCommand { private BauCommand(){} + private static final String UNKNOWN_PLAYER = BungeeCore.CHAT_PREFIX + "§cUnbekannter Spieler"; + public static void onBau(ChatEvent e, String[] command){ ProxiedPlayer p = (ProxiedPlayer) e.getSender(); Subserver server = Subserver.getSubserver(p); - Bauserver bau = server != null && server.getType() == Servertype.BAUSERVER ? (Bauserver)server : null; + Bauserver bau = (server != null && server.getType() == Servertype.BAUSERVER) ? (Bauserver)server : null; boolean ownBau = bau != null && bau.getOwner().equals(p.getUniqueId()); e.setCancelled(true); + BungeeCore.send(p, e.getMessage()); if(command.length == 1){ SubserverSystem.sendToBauServer(p, p.getUniqueId()); - }else if(ownBau && command.length != 2 && ( - command[1].equalsIgnoreCase("togglebuild") || - command[1].equalsIgnoreCase("togglewe") || - command[1].equalsIgnoreCase("toggleworld"))) { - e.setCancelled(false); - }else if(command[1].equalsIgnoreCase("addmember")){ - if (!hasWorld(p)){ - return; - }else if (command.length == 2) { - p.sendMessage(BungeeCore.ChatPrefix + "/bau addmember "); - return; - } + return; + } - UUID id = WarkingUser.get(command[2]).getUUID(); - if (id == null) { - p.sendMessage(BungeeCore.ChatPrefix + "§cUnbekannter Spieler"); - return; - }else if (BauweltMember.getBauMember(p.getUniqueId(), id) != null) { - p.sendMessage(BungeeCore.ChatPrefix + "§cDieser Spieler ist bereits Mitglied auf deiner Welt"); - return; - } - - new BauweltMember(p.getUniqueId(), id, true, false, false); - p.sendMessage(BungeeCore.ChatPrefix + "§aDer Spieler wurde zu deiner Welt hinzugefügt"); - - ProxiedPlayer z = ProxyServer.getInstance().getPlayer(id); - if(z != null) - z.sendMessage(BungeeCore.ChatPrefix + "§aDu wurdest zu der Welt von §6" + p.getName() + " §ahinzugefügt"); - }else if(command[1].equalsIgnoreCase("tp")){ - if (command.length == 2) { - p.sendMessage(BungeeCore.ChatPrefix + "/bau tp "); - return; - } - - UUID worldOwner = WarkingUser.get(command[2]).getUUID(); - if (worldOwner == null) { - p.sendMessage(BungeeCore.ChatPrefix + "§cUnbekannter Spieler"); - return; - }else if (!hasPermission(worldOwner, p, Permission.member)){ - SubserverSystem.sendDeniedMessage(p, worldOwner); - p.sendMessage(BungeeCore.ChatPrefix + "§cDu darfst dich nicht auf diese Welt teleportieren"); - return; - } - SubserverSystem.sendToBauServer(p, worldOwner); - }else if(command[1].equalsIgnoreCase("togglebuild")){ - if (command.length == 2) { - p.sendMessage(BungeeCore.ChatPrefix + "/bau togglebuild "); - return; - } - - UUID id = WarkingUser.get(command[2]).getUUID(); - if(!toggleCheck(p, id)){ - return; - } - - BauweltMember target = BauweltMember.getBauMember(p.getUniqueId(), id); - toggleBuild(p, target); - }else if(command[1].equalsIgnoreCase("togglewe")){ - if (command.length == 2) { - p.sendMessage(BungeeCore.ChatPrefix + "/bau togglewe "); - return; - } - - UUID id = WarkingUser.get(command[2]).getUUID(); - if(!toggleCheck(p, id)){ - return; - } - - BauweltMember target = BauweltMember.getBauMember(p.getUniqueId(), id); - toggleWE(p, target); - }else if(command[1].equalsIgnoreCase("toggleworld")) { - if (command.length == 2) { - p.sendMessage(BungeeCore.ChatPrefix + "/bau toggleworld "); - return; - } - - UUID id = WarkingUser.get(command[2]).getUUID(); - if (!toggleCheck(p, id)) { - return; - } - - BauweltMember target = BauweltMember.getBauMember(p.getUniqueId(), id); - toggleTestblock(p, target); - }else if(command[1].equalsIgnoreCase("delmember")){ - if (command.length == 2) { - p.sendMessage(BungeeCore.ChatPrefix + "/bau delmember "); - return; - } - - UUID id = WarkingUser.get(command[2]).getUUID(); - if(!toggleCheck(p, id)){ - return; - } - - BauweltMember target = BauweltMember.getBauMember(p.getUniqueId(), id); - removePlayer(p, target); - }else if(command[1].equalsIgnoreCase("resetall") || - command[1].equalsIgnoreCase("delete")){ - p.sendMessage(BungeeCore.ChatPrefix + "§aDeine Welt wird zurückgesetzt. Einen Moment bitte..."); - ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.instance, () -> { - for(Subserver subserver : Subserver.getServerList()){ - if(subserver.getType() == Servertype.BAUSERVER && ((Bauserver)subserver).getOwner().equals(p.getUniqueId())){ - subserver.stop(); - break; - } - } - File directory = new File(BungeeCore.WorldFolder + p.getUniqueId().toString()); - del(directory); - }); - }else{ - HelpCommand.sendBauHelp(p); + switch(command[1].toLowerCase()){ + case "addmember": + addmember(p, command); + break; + case "tp": + case "teleport": + teleport(p, command); + break; + case "togglebuild": + if(ownBau && command.length > 2) + e.setCancelled(false); + else + togglebuild(p, command); + break; + case "togglewe": + if(ownBau && command.length > 2) + e.setCancelled(false); + else + togglewe(p, command); + break; + case "toggleworld": + if(ownBau && command.length > 2) + e.setCancelled(false); + else + toggleworld(p, command); + break; + case "delmember": + delmember(p, command); + break; + case "resetall": + case "delete": + delete(p); + break; + case "testarena": + case "test": + testarena(p, command); + break; + default: + HelpCommand.sendBauHelp(p); } } - public static void toggleBuild(ProxiedPlayer p, BauweltMember target){ + private static void addmember(ProxiedPlayer p, String[] command){ + if (Bauwelt.getBauwelt(p.getUniqueId()) == null){ + BungeeCore.send(p,BungeeCore.CHAT_PREFIX + "§cDu hast keine Bauwelt"); + return; + }else if (command.length == 2) { + BungeeCore.send(p, BungeeCore.CHAT_PREFIX + "/bau addmember "); + return; + } + + SteamwarUser target = SteamwarUser.get(command[2]); + if (target == null) { + BungeeCore.send(p, UNKNOWN_PLAYER); + return; + }else if (BauweltMember.getBauMember(p.getUniqueId(), target.getUuid()) != null) { + BungeeCore.send(p, BungeeCore.CHAT_PREFIX + "§cDieser Spieler ist bereits Mitglied auf deiner Welt"); + return; + } + + new BauweltMember(p.getUniqueId(), target.getUuid(), true, false, false); + BungeeCore.send(p, BungeeCore.CHAT_PREFIX + "§aDer Spieler wurde zu deiner Welt hinzugefügt"); + + ProxiedPlayer z = ProxyServer.getInstance().getPlayer(target.getUuid()); + if(z != null) + BungeeCore.send(z, BungeeCore.CHAT_PREFIX + "§aDu wurdest zu der Welt von §6" + p.getName() + " §ahinzugefügt"); + } + + private static void teleport(ProxiedPlayer p, String[] command){ + if (command.length == 2) { + BungeeCore.send(p, BungeeCore.CHAT_PREFIX + "/bau tp "); + return; + } + + SteamwarUser worldOwner = SteamwarUser.get(command[2]); + if (worldOwner == null) { + BungeeCore.send(p, UNKNOWN_PLAYER); + return; + }else if (!p.getUniqueId().equals(worldOwner.getUuid()) && BauweltMember.getBauMember(worldOwner.getUuid(), p.getUniqueId()) == null){ + SubserverSystem.sendDeniedMessage(p, worldOwner.getUuid()); + BungeeCore.send(p, BungeeCore.CHAT_PREFIX + "§cDu darfst dich nicht auf diese Welt teleportieren"); + return; + } + SubserverSystem.sendToBauServer(p, worldOwner.getUuid()); + } + + private static void togglebuild(ProxiedPlayer p, String[] command){ + BauweltMember target = toggle(p, command, "togglebuild"); + if(target == null) + return; + target.setBuild(!target.isBuild()); - ProxiedPlayer z = ProxyServer.getInstance().getPlayer(WarkingUser.get(target.getMemberID()).getUUID()); - if (z != null) { - if (target.isBuild()) { - z.sendMessage(BungeeCore.ChatPrefix + "§aDu kannst nun auf der Welt von §6" + p.getName() + "§a bauen"); - }else { - z.sendMessage(BungeeCore.ChatPrefix + "§cDu kannst nun nicht mehr auf der Welt von §6" + p.getName() + "§c bauen"); - } - } - if (target.isBuild()) { - p.sendMessage(BungeeCore.ChatPrefix + "§aDer Spieler darf nun bauen"); - } else { - p.sendMessage(BungeeCore.ChatPrefix + "§cDer Spieler darf nun nicht mehr bauen"); - } + isAllowedTo(target.isBuild(), p, target, "bauen"); } - public static void toggleWE(ProxiedPlayer p, BauweltMember target){ + private static void togglewe(ProxiedPlayer p, String[] command){ + BauweltMember target = toggle(p, command, "togglewe"); + if(target == null) + return; + target.setWorldEdit(!target.isWorldEdit()); - ProxiedPlayer z = ProxyServer.getInstance().getPlayer(WarkingUser.get(target.getMemberID()).getUUID()); - if (z != null) { - if (target.isWorldEdit()) { - z.sendMessage(BungeeCore.ChatPrefix + "§aDu kannst nun auf der Welt von §6" + p.getName() + "§a WorldEdit verwenden"); - }else { - z.sendMessage(BungeeCore.ChatPrefix + "§cDu kannst nun nicht mehr auf der Welt von §6" + p.getName() + "§c WorldEdit verwenden"); - } - } - if (target.isWorldEdit()) { - p.sendMessage(BungeeCore.ChatPrefix + "§aDer Spieler darf nun WorldEdit verwenden"); - } else { - p.sendMessage(BungeeCore.ChatPrefix + "§cDer Spieler darf nun kein WorldEdit mehr verwenden"); - } + isAllowedTo(target.isWorldEdit(), p, target, "WorldEdit verwenden"); } - public static void toggleTestblock(ProxiedPlayer p, BauweltMember target){ + private static void toggleworld(ProxiedPlayer p, String[] command){ + BauweltMember target = toggle(p, command, "toggleworld"); + if(target == null) + return; + target.setWorld(!target.isWorld()); - ProxiedPlayer z = ProxyServer.getInstance().getPlayer(WarkingUser.get(target.getMemberID()).getUUID()); - if (z != null) { - if (target.isWorld()) { - z.sendMessage(BungeeCore.ChatPrefix + "§aDu kannst nun auf der Welt von §6" + p.getName() + "§a Einstellungen vornehmen"); - }else { - z.sendMessage(BungeeCore.ChatPrefix + "§cDu kannst nun nicht mehr auf der Welt von §6" + p.getName() + "§c Einstellungen vornehmen"); - } - } - if (target.isWorld()) { - p.sendMessage(BungeeCore.ChatPrefix + "§aDer Spieler darf nun Einstellungen vornehmen"); - } else { - p.sendMessage(BungeeCore.ChatPrefix + "§cDer Spieler darf nun nicht mehr Einstellungen vornehmen"); - } + isAllowedTo(target.isWorld(), p, target, "Einstellungen vornehmen"); } - public static void removePlayer(ProxiedPlayer p, BauweltMember target){ + private static void delmember(ProxiedPlayer p, String[] command){ + if (command.length == 2) { + BungeeCore.send(p, BungeeCore.CHAT_PREFIX + "/bau delmember "); + return; + } + + BauweltMember target = member(p, SteamwarUser.get(command[2])); + if(target == null) + return; + target.remove(); - ProxiedPlayer z = ProxyServer.getInstance().getPlayer(WarkingUser.get(target.getMemberID()).getUUID()); + ProxiedPlayer z = ProxyServer.getInstance().getPlayer(SteamwarUser.get(target.getMemberID()).getUuid()); if(z != null){ - z.sendMessage(BungeeCore.ChatPrefix + "§cDu wurdest von der Welt von §6" + p.getName() + " §centfernt."); + BungeeCore.send(z, BungeeCore.CHAT_PREFIX + "§cDu wurdest von der Welt von §6" + p.getName() + " §centfernt."); Subserver server = Subserver.getSubserver(z); if(server != null && server.getType() == Servertype.BAUSERVER && ((Bauserver)server).getOwner().equals(p.getUniqueId())) - z.connect(ProxyServer.getInstance().getServerInfo(BungeeCore.LobbyServer)); + z.connect(ProxyServer.getInstance().getServerInfo(BungeeCore.LOBBY_SERVER)); } - p.sendMessage(BungeeCore.ChatPrefix + "§cDer Spieler wurde entfernt."); + BungeeCore.send(p, BungeeCore.CHAT_PREFIX + "§cDer Spieler wurde entfernt."); } - private static boolean toggleCheck(ProxiedPlayer p, UUID id){ - if (id == null) { - p.sendMessage(BungeeCore.ChatPrefix + "§cUnbekannter Spieler"); - return false; + private static void delete(ProxiedPlayer p){ + BungeeCore.send(p, BungeeCore.CHAT_PREFIX + "§aDeine Welt wird zurückgesetzt."); + ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.get(), () -> { + for (Subserver subserver : Subserver.getServerList()) { + if (subserver.getType() == Servertype.BAUSERVER && ((Bauserver) subserver).getOwner().equals(p.getUniqueId())) { + subserver.stop(); + break; + } + } + File directory = new File(BungeeCore.WORLD_FOLDER + p.getUniqueId().toString()); + del(directory); + }); + } + + private static void testarena(ProxiedPlayer p, String[] command){ + if (command.length == 2) { + BungeeCore.send(p, BungeeCore.CHAT_PREFIX + "/bau testarena "); + return; } - BauweltMember target = BauweltMember.getBauMember(p.getUniqueId(), id); + ArenaMode mode = FightCommand.stringToArenaMode(command[2]); + if(mode == ArenaMode.UNKNOWN){ + BungeeCore.send(p, BungeeCore.CHAT_PREFIX + "§cUnbekannter Spielmodus: " + command[2]); + return; + } + + BungeeCore.send(p, BungeeCore.CHAT_PREFIX + "§aDeine Testarena wird gestartet. Einen Moment bitte..."); + ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.get(), () -> { + for (Subserver subserver : Subserver.getServerList()) { + if (subserver.getType() == Servertype.BAUSERVER && ((Bauserver) subserver).getOwner().equals(p.getUniqueId())) { + subserver.stop(); + break; + } + } + SubserverSystem.sendToTestServer(p, mode, FightCommand.getMap(p, mode, new String[0])); + }); + } + + private static BauweltMember member(ProxiedPlayer p, SteamwarUser member){ + if (member == null) { + BungeeCore.send(p, UNKNOWN_PLAYER); + return null; + } + + BauweltMember target = BauweltMember.getBauMember(p.getUniqueId(), member.getUuid()); if (target == null) { - p.sendMessage(BungeeCore.ChatPrefix + "§cDer Spieler ist kein Mitglied deiner Welt!"); - return false; + BungeeCore.send(p, BungeeCore.CHAT_PREFIX + "§cDer Spieler ist kein Mitglied deiner Welt!"); + return null; } - return true; + return target; } - public static boolean hasPermission(UUID welt, ProxiedPlayer member, Permission perm){ - if(member.getUniqueId().equals(welt)) - return true; + private static BauweltMember toggle(ProxiedPlayer p, String[] command, String subcommand){ + if (command.length == 2) { + BungeeCore.send(p, BungeeCore.CHAT_PREFIX + "/bau " + subcommand + " "); + return null; + } - BauweltMember member1 = BauweltMember.getBauMember(welt, member.getUniqueId()); - if(member1 == null) - return false; + SteamwarUser member = SteamwarUser.get(command[2]); + return member(p, member); + } - switch(perm){ - case build: - return member1.isBuild(); - case worldedit: - return member1.isWorldEdit(); - case world: - return member1.isWorld(); - case member: - return true; - default: - return false; + private static void isAllowedTo(boolean permission, ProxiedPlayer p, BauweltMember target, String what){ + ProxiedPlayer player = ProxyServer.getInstance().getPlayer(SteamwarUser.get(target.getMemberID()).getUuid()); + + if(permission){ + if(player != null) + BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§aDu kannst nun auf der Welt von §e" + player.getName() + "§a " + what); + BungeeCore.send(p, BungeeCore.CHAT_PREFIX + "§aDer Spieler darf nun " + what); + }else{ + if(player != null) + BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§cDu kannst nun nicht mehr auf der Welt von §e" + player.getName() + "§c " + what); + BungeeCore.send(p, BungeeCore.CHAT_PREFIX + "§cDer Spieler darf nun nicht mehr " + what); } } private static void del(File dir){ if (dir.isDirectory()){ String[] entries = dir.list(); + assert entries != null; for (String entry : entries) { File aktFile = new File(dir.getPath(), entry); del(aktFile); @@ -251,12 +253,4 @@ public class BauCommand { dir.delete(); } } - - private static boolean hasWorld(ProxiedPlayer p){ - if (Bauwelt.getBauwelt(p.getUniqueId()).getUUID() == null) { - p.sendMessage(BungeeCore.ChatPrefix + "§cDu hast keine Bauwelt"); - return false; - } - return true; - } } diff --git a/src/de/steamwar/bungeecore/commands/ChallengeCommand.java b/src/de/steamwar/bungeecore/commands/ChallengeCommand.java index 93c0c39..f58b914 100644 --- a/src/de/steamwar/bungeecore/commands/ChallengeCommand.java +++ b/src/de/steamwar/bungeecore/commands/ChallengeCommand.java @@ -4,16 +4,13 @@ import de.steamwar.bungeecore.*; import net.md_5.bungee.api.CommandSender; import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.chat.ClickEvent; -import net.md_5.bungee.api.chat.ComponentBuilder; -import net.md_5.bungee.api.chat.HoverEvent; -import net.md_5.bungee.api.chat.TextComponent; import net.md_5.bungee.api.connection.ProxiedPlayer; import java.util.*; -public class ChallengeCommand extends Command { +public class ChallengeCommand extends BasicCommand { - public static final Map> challenges = new HashMap<>(); + private static final Map> challenges = new HashMap<>(); public ChallengeCommand() { super("challenge", ""); @@ -22,8 +19,7 @@ public class ChallengeCommand extends Command { @Override public void execute(CommandSender sender, String[] args) { if(args.length != 2){ - sender.sendMessage(BungeeCore.ChatPrefix + "§7Mit §e/challenge §7kannst du jemanden herausfordern!"); - sender.sendMessage(BungeeCore.ChatPrefix + "§8/§echallenge §8[§7Spieler§8] §8[§7Spielmodus§8]"); + BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "§8/§echallenge §8[§7Spieler§8] §8[§7Spielmodus§8]"); return; } if(!(sender instanceof ProxiedPlayer)){ @@ -34,50 +30,30 @@ public class ChallengeCommand extends Command { Subserver subserver = Subserver.getSubserver(player); if(subserver != null && subserver.getType() == Servertype.ARENA){ - player.sendMessage(BungeeCore.ChatPrefix + "§cDu befindest dich bereits in einer Arena."); + BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§cDu befindest dich bereits in einer Arena."); return; } - ProxiedPlayer target = (ProxiedPlayer) ProxyServer.getInstance().getPlayer(args[0]); + ProxiedPlayer target = ProxyServer.getInstance().getPlayer(args[0]); if(target == null){ - player.sendMessage(BungeeCore.ChatPrefix + "§cDer gewünschte Spieler ist nicht online."); + BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§cDer gewünschte Spieler ist nicht online."); return; } subserver = Subserver.getSubserver(target); if(subserver != null && subserver.getType() == Servertype.ARENA){ - player.sendMessage(BungeeCore.ChatPrefix + "§cDer Herausgeforderte ist bereits in einer Arena."); + BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§cDer Herausgeforderte ist bereits in einer Arena."); return; } - String map; - ArenaMode mode; - switch(args[1].toLowerCase()){ - case "as": - case "airship": - map = FightCommand.getMap(sender, ArenaMode.AirShip, new String[0]); - mode = ArenaMode.AirShip; - break; - case "ws": - case "warship": - map = FightCommand.getMap(sender, ArenaMode.WarShip, new String[0]); - mode = ArenaMode.WarShip; - break; - case "wg": - case "wargear": - map = FightCommand.getMap(sender, ArenaMode.WarGear, new String[0]); - mode = ArenaMode.WarGear; - break; - case "mwg": - case "miniwargear": - map = FightCommand.getMap(sender, ArenaMode.MiniWarGear, new String[0]); - mode = ArenaMode.MiniWarGear; - break; - default: - sender.sendMessage(BungeeCore.ChatPrefix + "§cUnbekannter Spielmodus: " + args[1]); - return; + ArenaMode mode = FightCommand.stringToArenaMode(args[1]); + if(mode == ArenaMode.UNKNOWN){ + BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§cUnbekannter Spielmodus: " + args[1]); + return; } + String map = FightCommand.getMap(sender, mode, new String[0]); + if(challenges.containsKey(target) && challenges.get(target).contains(player)){ challenges.remove(target); challenges.remove(player); @@ -87,10 +63,9 @@ public class ChallengeCommand extends Command { arena.sendPlayer(player); arena.sendPlayer(target); - TextComponent tc = new TextComponent(BungeeCore.ChatPrefix + "§e" + mode.name() + "§7-§eDuell§7: " + player.getName() + " vs " + target.getName()); - tc.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§aZuschauen").create())); - tc.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/join " + player.getName())); - ProxyServer.getInstance().broadcast(tc); + BungeeCore.broadcast(BungeeCore.CHAT_PREFIX + "§e" + mode.name() + "§7-§eDuell§7: " + player.getName() + " vs " + target.getName(), + "§aZuschauen", + new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/join " + player.getName())); }else{ if(!challenges.containsKey(player)){ challenges.put(player, new LinkedList<>()); @@ -98,16 +73,19 @@ public class ChallengeCommand extends Command { challenges.get(player).add(target); - player.sendMessage(BungeeCore.ChatPrefix + "§7Du hast §e" + target.getName() + " §7zu einem §e" + mode.name() + "-Kampf §7herausgefordert!"); - target.sendMessage(BungeeCore.ChatPrefix + "§e" + player.getName() + " §7 hat dich zu einem §e" + mode.name() + "-Kampf §7herausgefordert!"); + BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§7Du hast §e" + target.getName() + " §7zu einem §e" + mode.name() + "-Kampf §7herausgefordert!"); + BungeeCore.send(target, BungeeCore.CHAT_PREFIX + "§e" + player.getName() + " §7 hat dich zu einem §e" + mode.name() + "-Kampf §7herausgefordert!"); - TextComponent tc = new TextComponent(BungeeCore.ChatPrefix + "§7Klicke §ehier§7, um die Herausforderung anzunehmen"); - tc.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§aHerausforderung annehmen").create())); - tc.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/challenge " + player.getName() + " " + mode.name())); - target.sendMessage(tc); + BungeeCore.send(target, BungeeCore.CHAT_PREFIX + "§7Klicke §ehier§7, um die Herausforderung anzunehmen", + "§aHerausforderung annehmen", + new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/challenge " + player.getName() + " " + mode.name())); } } + public static void remove(ProxiedPlayer player){ + challenges.remove(player); + } + @Override public Iterable onTabComplete(CommandSender commandSender, String[] args) { List gamemodes = new ArrayList<>(); diff --git a/src/de/steamwar/bungeecore/commands/DenyCommand.java b/src/de/steamwar/bungeecore/commands/DenyCommand.java index b8f5d84..afbe5e7 100644 --- a/src/de/steamwar/bungeecore/commands/DenyCommand.java +++ b/src/de/steamwar/bungeecore/commands/DenyCommand.java @@ -5,7 +5,7 @@ import net.md_5.bungee.api.CommandSender; import net.md_5.bungee.api.chat.TextComponent; import net.md_5.bungee.api.connection.ProxiedPlayer; -public class DenyCommand extends Command { +public class DenyCommand extends BasicCommand { public DenyCommand(String cmd, String ...aliases) { super(cmd, "", aliases); @@ -15,7 +15,7 @@ public class DenyCommand extends Command { public void execute(CommandSender sender, String[] args) { if(sender instanceof ProxiedPlayer){ ProxiedPlayer player = (ProxiedPlayer) sender; - player.sendMessage(new TextComponent(BungeeCore.ChatPrefix + "§cUnbekannter Befehl.")); + player.sendMessage(new TextComponent(BungeeCore.CHAT_PREFIX + "§cUnbekannter Befehl.")); } } } \ No newline at end of file diff --git a/src/de/steamwar/bungeecore/commands/EventCommand.java b/src/de/steamwar/bungeecore/commands/EventCommand.java new file mode 100644 index 0000000..2d74771 --- /dev/null +++ b/src/de/steamwar/bungeecore/commands/EventCommand.java @@ -0,0 +1,119 @@ +package de.steamwar.bungeecore.commands; + +import de.steamwar.bungeecore.BungeeCore; +import de.steamwar.bungeecore.EventStarter; +import de.steamwar.bungeecore.Subserver; +import de.steamwar.bungeecore.sql.Event; +import de.steamwar.bungeecore.sql.EventFight; +import de.steamwar.bungeecore.sql.Team; +import de.steamwar.bungeecore.sql.TeamTeilnahme; +import net.md_5.bungee.api.CommandSender; +import net.md_5.bungee.api.connection.ProxiedPlayer; + +import java.time.Instant; +import java.time.format.DateTimeFormatter; +import java.time.temporal.ChronoUnit; +import java.util.List; +import java.util.Set; + +public class EventCommand extends BasicCommand { + + private static final DateTimeFormatter TIME_FORMAT = DateTimeFormatter.ofPattern("HH:mm"); + public static final DateTimeFormatter DATE_FORMAT = DateTimeFormatter.ofPattern("dd.MM."); + + public EventCommand() { + super("event", ""); + } + + @Override + public void execute(CommandSender sender, String[] args) { + if(!(sender instanceof ProxiedPlayer)) + return; + ProxiedPlayer player = (ProxiedPlayer) sender; + + Event currentEvent = Event.get(); + + if(currentEvent == null) { + noCurrentEvent(player); + return; + } + + if(args.length != 1){ + eventOverview(player, currentEvent); + return; + } + + Team team = Team.get(args[0]); + if(team == null){ + BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§cDieses Team gibt es nicht"); + return; + } + + Subserver eventArena = EventStarter.getEventServer().get(team); + if(eventArena == null || !Subserver.getServerList().contains(eventArena)){ + BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§cDas Team kämpft derzeit nicht"); + return; + } + + eventArena.sendPlayer(player); + } + + private void noCurrentEvent(ProxiedPlayer player){ + BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§cDerzeit findet kein Event statt"); + List coming = Event.getComing(); + if(!coming.isEmpty()){ + BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§eKommende Events§8:"); + for(Event e : coming){ + BungeeCore.send(player, "§7" + + e.getStart().toLocalDateTime().format(DATE_FORMAT) + + "§8-§7" + + e.getEnd().toLocalDateTime().format(DATE_FORMAT) + + "§8: §e" + + e.getEventName()); + Set teams = TeamTeilnahme.getTeams(e.getEventID()); + if(!teams.isEmpty()){ + StringBuilder tline = new StringBuilder("§7 Mit§8: §e"); + for(Team t : teams){ + tline.append(t.getTeamKuerzel()).append(" "); + } + BungeeCore.send(player, tline.toString()); + } + } + } + } + + private void eventOverview(ProxiedPlayer player, Event currentEvent){ + BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§8/§eevent §8[§eTeam§8] - §7Um dich zum Kampf zu teleportieren"); + + List fights = EventFight.getEvent(currentEvent.getEventID()); + Instant now = Instant.now(); + + BungeeCore.send(player, "§e§l" + currentEvent.getEventName()); + + for(EventFight fight : fights){ + Team blue = Team.get(fight.getTeamBlue()); + Team red = Team.get(fight.getTeamRed()); + StringBuilder fline = new StringBuilder("§7") + .append(fight.getStartTime().toLocalDateTime().format(TIME_FORMAT)) + .append(" §e") + .append(blue.getTeamKuerzel()) + .append("§8:§e") + .append(red.getTeamKuerzel()); + + if(now.isAfter(fight.getStartTime().toInstant().plus(35, ChronoUnit.MINUTES))){ + switch(fight.getErgebnis()){ + case 1: + fline.append("§8: §7Sieg §e").append(blue.getTeamKuerzel()); + break; + case 2: + fline.append("§8: §7Sieg §e").append(red.getTeamKuerzel()); + break; + default: + fline.append("§8: §7Unentschieden"); + } + } + + BungeeCore.send(player, fline.toString()); + } + } +} diff --git a/src/de/steamwar/bungeecore/commands/EventreloadCommand.java b/src/de/steamwar/bungeecore/commands/EventreloadCommand.java new file mode 100644 index 0000000..2a02fbd --- /dev/null +++ b/src/de/steamwar/bungeecore/commands/EventreloadCommand.java @@ -0,0 +1,15 @@ +package de.steamwar.bungeecore.commands; + +import de.steamwar.bungeecore.sql.EventFight; +import net.md_5.bungee.api.CommandSender; + +public class EventreloadCommand extends BasicCommand { + public EventreloadCommand() { + super("eventreload", "bungeecore.softreload"); + } + + @Override + public void execute(CommandSender sender, String[] args) { + EventFight.loadAllComingFights(); + } +} diff --git a/src/de/steamwar/bungeecore/commands/FightCommand.java b/src/de/steamwar/bungeecore/commands/FightCommand.java index 1d0a151..1180e73 100644 --- a/src/de/steamwar/bungeecore/commands/FightCommand.java +++ b/src/de/steamwar/bungeecore/commands/FightCommand.java @@ -17,7 +17,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Random; -public class FightCommand extends Command { +public class FightCommand extends BasicCommand { public FightCommand() { super("fight", "", "f"); @@ -30,7 +30,7 @@ public class FightCommand extends Command { if(map.equalsIgnoreCase(realMap)) return realMap; } - sender.sendMessage(BungeeCore.ChatPrefix + "§cDie gewünschte Arena gibt es nicht."); + BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "§cDie gewünschte Arena gibt es nicht."); return null; }else{ List l = BungeeCore.arenaMaps.get(mode); @@ -39,15 +39,34 @@ public class FightCommand extends Command { } } + static ArenaMode stringToArenaMode(String input){ + switch(input.toLowerCase()){ + case "as": + case "airship": + return ArenaMode.AirShip; + case "ws": + case "warship": + return ArenaMode.WarShip; + case "wg": + case "wargear": + return ArenaMode.WarGear; + case "mwg": + case "miniwargear": + return ArenaMode.MiniWarGear; + default: + return ArenaMode.UNKNOWN; + } + } + @Override public void execute(CommandSender sender, String[] args) { if(args.length != 1 && args.length != 2){ - sender.sendMessage(BungeeCore.ChatPrefix + "§7Mit §e/fight §7kannst du einen neuen Kampf starten!"); - sender.sendMessage(BungeeCore.ChatPrefix + "§8/§efight §8[§7Spielmodus§8] <§7Arena§8>"); - sender.sendMessage(BungeeCore.ChatPrefix + "§8/§efight AirShip §8- §7Starte einen §eAirShip§8-§7Kampf§8!"); - sender.sendMessage(BungeeCore.ChatPrefix + "§8/§efight WarShip §8- §7Starte einen §eWarShip§8-§7Kampf§8!"); - sender.sendMessage(BungeeCore.ChatPrefix + "§8/§efight WarGear §8- §7Starte einen §eWarGear§8-§7Kampf§8!"); - sender.sendMessage(BungeeCore.ChatPrefix + "§8/§efight MiniWarGear §8- §7Starte einen §eMiniWarGear§8-§7Kampf"); + BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "§7Mit §e/fight §7kannst du einen neuen Kampf starten!"); + BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "§8/§efight §8[§7Spielmodus§8] <§7Arena§8>"); + BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "§8/§efight AirShip §8- §7Starte einen §eAirShip§8-§7Kampf§8!"); + BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "§8/§efight WarShip §8- §7Starte einen §eWarShip§8-§7Kampf§8!"); + BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "§8/§efight WarGear §8- §7Starte einen §eWarGear§8-§7Kampf§8!"); + BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "§8/§efight MiniWarGear §8- §7Starte einen §eMiniWarGear§8-§7Kampf"); return; } @@ -56,53 +75,41 @@ public class FightCommand extends Command { Subserver subserver = Subserver.getSubserver(player); if(subserver != null && subserver.getType() == Servertype.ARENA){ - sender.sendMessage(BungeeCore.ChatPrefix + "§cDu befindest dich bereits in einer Arena."); + BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "§cDu befindest dich bereits in einer Arena."); return; } - String map; + String map = null; Subserver arena; - String spielModus; - switch(args[0].toLowerCase()){ - case "as": - case "airship": - map = getMap(sender, ArenaMode.AirShip, args); - if(map == null) - return; + ArenaMode mode = stringToArenaMode(args[0]); + + if(mode != ArenaMode.UNKNOWN){ + map = getMap(sender, mode, args); + if(map == null) + return; + } + + switch(mode){ + case AirShip: arena = SubserverSystem.startArena(ArenaMode.AirShip, map); - spielModus = "AirShip"; break; - case "ws": - case "warship": - map = getMap(sender, ArenaMode.WarShip, args); - if(map == null) - return; + case WarShip: arena = SubserverSystem.startArena(ArenaMode.WarShip, map); - spielModus = "WarShip"; break; - case "wg": - case "wargear": - map = getMap(sender, ArenaMode.WarGear, args); - if(map == null) - return; + case WarGear: arena = SubserverSystem.startArena(ArenaMode.WarGear, map); - spielModus = "WarGear"; break; - case "mwg": - case "miniwargear": - map = getMap(sender, ArenaMode.MiniWarGear, args); - if(map == null) - return; + case MiniWarGear: arena = SubserverSystem.startArena(ArenaMode.MiniWarGear, map); - spielModus = "MiniWarGear"; break; + case UNKNOWN: default: - sender.sendMessage(BungeeCore.ChatPrefix + "§cUnbekannter Spielmodus: " + args[0]); + BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "§cUnbekannter Spielmodus: " + args[0]); return; } arena.sendPlayer(player); - TextComponent tc = new TextComponent(BungeeCore.ChatPrefix + "§7Klicke §ehier§7, um §e" + spielModus + " §7gegen §e" + player.getName() + " §7zu §7kämpfen!"); + TextComponent tc = new TextComponent(BungeeCore.CHAT_PREFIX + "§7Klicke §ehier§7, um §e" + mode.name() + " §7gegen §e" + player.getName() + " §7zu §7kämpfen!"); tc.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§aGegen §7" + player.getName() + " §ekämpfen").create())); tc.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/join " + player.getName())); ProxyServer.getInstance().broadcast(tc); @@ -122,26 +129,8 @@ public class FightCommand extends Command { gamemodes.add("MiniWarGear"); gamemodes.add("MWG"); }else if(args.length == 2){ - switch(args[1].toLowerCase()){ - case "as": - case "airship": - gamemodes.addAll(BungeeCore.arenaMaps.get(ArenaMode.AirShip)); - break; - case "ws": - case "warship": - gamemodes.addAll(BungeeCore.arenaMaps.get(ArenaMode.WarShip)); - break; - case "wg": - case "wargear": - gamemodes.addAll(BungeeCore.arenaMaps.get(ArenaMode.WarGear)); - break; - case "mwg": - case "miniwargear": - gamemodes.addAll(BungeeCore.arenaMaps.get(ArenaMode.MiniWarGear)); - break; - default: - break; - } + ArenaMode mode = stringToArenaMode(args[1]); + gamemodes.addAll(BungeeCore.arenaMaps.get(mode)); } return gamemodes; } diff --git a/src/de/steamwar/bungeecore/commands/ForgeCommand.java b/src/de/steamwar/bungeecore/commands/ForgeCommand.java index 3771a0a..b5a9abe 100644 --- a/src/de/steamwar/bungeecore/commands/ForgeCommand.java +++ b/src/de/steamwar/bungeecore/commands/ForgeCommand.java @@ -1,9 +1,9 @@ package de.steamwar.bungeecore.commands; -import de.steamwar.bungeecore.ModSystem; +import de.steamwar.bungeecore.listeners.mods.Forge; import net.md_5.bungee.api.CommandSender; -public class ForgeCommand extends Command { +public class ForgeCommand extends BasicCommand { public ForgeCommand() { super("forge", "bungeecore.softreload"); @@ -11,6 +11,6 @@ public class ForgeCommand extends Command { @Override public void execute(CommandSender sender, String[] args) { - ModSystem.toggleEnabled(); + Forge.toggleEnabled(); } } diff --git a/src/de/steamwar/bungeecore/commands/HelpCommand.java b/src/de/steamwar/bungeecore/commands/HelpCommand.java index 390d97f..20a4a25 100644 --- a/src/de/steamwar/bungeecore/commands/HelpCommand.java +++ b/src/de/steamwar/bungeecore/commands/HelpCommand.java @@ -8,7 +8,7 @@ import net.md_5.bungee.api.chat.HoverEvent; import net.md_5.bungee.api.chat.TextComponent; import net.md_5.bungee.api.connection.ProxiedPlayer; -public class HelpCommand extends Command { +public class HelpCommand extends BasicCommand { public HelpCommand() { super("help", "", "?"); } @@ -16,42 +16,42 @@ public class HelpCommand extends Command { @Override public void execute(CommandSender sender, String[] args) { if(args.length != 1){ - TextComponent tc = new TextComponent(BungeeCore.ChatPrefix + "§7Kehre von überall mit §8/§el §7zur Lobby zurück!"); + TextComponent tc = new TextComponent(BungeeCore.CHAT_PREFIX + "§7Kehre von überall mit §8/§el §7zur Lobby zurück!"); tc.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§eZurück zur Lobby").create())); tc.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/l")); sender.sendMessage(tc); - tc = new TextComponent(BungeeCore.ChatPrefix + "§7Komme mit §8/§ebau §7auf den Bauserver!"); + tc = new TextComponent(BungeeCore.CHAT_PREFIX + "§7Komme mit §8/§ebau §7auf den Bauserver!"); tc.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§eZum Bauserver").create())); tc.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/bauserver")); sender.sendMessage(tc); - tc = new TextComponent(BungeeCore.ChatPrefix + "§7Erhalte mit §8/§ehelp bauserver §7Hilfe zum Bauserver!"); + tc = new TextComponent(BungeeCore.CHAT_PREFIX + "§7Erhalte mit §8/§ehelp bauserver §7Hilfe zum Bauserver!"); tc.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§eHilfe zum Bauserver").create())); tc.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/help bauserver")); sender.sendMessage(tc); - tc = new TextComponent(BungeeCore.ChatPrefix + "§7Starte mit §8/§efight §7einen neuen Kampf!"); + tc = new TextComponent(BungeeCore.CHAT_PREFIX + "§7Starte mit §8/§efight §7einen neuen Kampf!"); tc.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§eZum Kampfsystem").create())); tc.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/fight")); sender.sendMessage(tc); - tc = new TextComponent(BungeeCore.ChatPrefix + "§7Tippe §8/§echallenge§7, um jemanden herauszufordern!"); + tc = new TextComponent(BungeeCore.CHAT_PREFIX + "§7Tippe §8/§echallenge§7, um jemanden herauszufordern!"); tc.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§eHerausfordern").create())); tc.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/challenge")); sender.sendMessage(tc); - tc = new TextComponent(BungeeCore.ChatPrefix + "§8/§eteam§7 für das Teamsystem!"); + tc = new TextComponent(BungeeCore.CHAT_PREFIX + "§8/§eteam§7 für das Teamsystem!"); tc.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§eTeamverwaltung").create())); tc.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/team")); sender.sendMessage(tc); - tc = new TextComponent(BungeeCore.ChatPrefix + "§7Trete mit §8/§ejoin §8[§eSpieler§8] §7einem Kampf bei!"); + tc = new TextComponent(BungeeCore.CHAT_PREFIX + "§7Trete mit §8/§ejoin §8[§eSpieler§8] §7einem Kampf bei!"); tc.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§eSpieler beitreten").create())); tc.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/join")); sender.sendMessage(tc); - tc = new TextComponent(BungeeCore.ChatPrefix + "§7Schreibe mit §8/§elocal §7nur auf dem lokalen Server!"); + tc = new TextComponent(BungeeCore.CHAT_PREFIX + "§7Schreibe mit §8/§elocal §7nur auf dem lokalen Server!"); tc.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§eLokaler Chat").create())); tc.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/local")); sender.sendMessage(tc); @@ -65,6 +65,7 @@ public class HelpCommand extends Command { sender.sendMessage("§8/§espeed §8- §7Ändert deine Fluggeschwindigkeit"); sender.sendMessage("§8/§env §8- §7(de)aktiviert Nachtsicht"); sender.sendMessage("§8/§etrace §8- §7Gibt einen Überblick über den TNT-Tracer"); + sender.sendMessage("§8/§eloader §8- §7Nutze den automatischen Kanonenlader"); sender.sendMessage("§8/§eprotect §8- §7Schützt den Boden der (M)WG-Region"); sender.sendMessage("§8/§efreeze §8- §7Unterbindet Blockupdates"); sender.sendMessage("§8/§eskull §8- §7Gibt dir den Kopf eines Spielers"); diff --git a/src/de/steamwar/bungeecore/commands/JoinmeCommand.java b/src/de/steamwar/bungeecore/commands/JoinmeCommand.java index a96ffbb..6e41ee6 100644 --- a/src/de/steamwar/bungeecore/commands/JoinmeCommand.java +++ b/src/de/steamwar/bungeecore/commands/JoinmeCommand.java @@ -13,7 +13,7 @@ import net.md_5.bungee.api.connection.ProxiedPlayer; import java.util.ArrayList; -public class JoinmeCommand extends Command { +public class JoinmeCommand extends BasicCommand { private static final String DENY_MESSAGE = "§cDu kannst diesem Spieler derzeit nicht folgen."; @@ -27,17 +27,17 @@ public class JoinmeCommand extends Command { ProxiedPlayer player = (ProxiedPlayer) sender; if (args.length == 0 && player.hasPermission("bungeecore.joinme")) { - TextComponent tc = new TextComponent(BungeeCore.ChatPrefix + "§7Klicke §ehier§8, §7um zu §e" + player.getName() + " §7auf §e" + player.getServer().getInfo().getName() + " §7zu kommen§8!"); + TextComponent tc = new TextComponent(BungeeCore.CHAT_PREFIX + "§7Klicke §ehier§8, §7um zu §e" + player.getName() + " §7auf §e" + player.getServer().getInfo().getName() + " §7zu kommen§8!"); tc.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§aSpieler folgen").create())); tc.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/join " + player.getName())); ProxyServer.getInstance().broadcast(tc); } else if (args.length == 1) { ProxiedPlayer target = ProxyServer.getInstance().getPlayer(args[0]); if(target == null || !target.isConnected()){ - player.sendMessage(BungeeCore.ChatPrefix + "§cDieser Spieler ist offline."); + player.sendMessage(BungeeCore.CHAT_PREFIX + "§cDieser Spieler ist offline."); return; }else if(target.equals(player)){ - player.sendMessage(BungeeCore.ChatPrefix + "§cSei eins mit dir selbst!"); + player.sendMessage(BungeeCore.CHAT_PREFIX + "§cSei eins mit dir selbst!"); return; } ServerInfo server = target.getServer().getInfo(); @@ -55,18 +55,18 @@ public class JoinmeCommand extends Command { subserver.sendPlayer(player); } else { SubserverSystem.sendDeniedMessage(player, bauserver.getOwner()); - player.sendMessage(BungeeCore.ChatPrefix + DENY_MESSAGE); + player.sendMessage(BungeeCore.CHAT_PREFIX + DENY_MESSAGE); } } }else if(ServerPerm != null && !player.hasPermission(ServerPerm)){ - player.sendMessage(BungeeCore.ChatPrefix + DENY_MESSAGE); + player.sendMessage(BungeeCore.CHAT_PREFIX + DENY_MESSAGE); }else if(ServerPerm == null && !player.getGroups().contains("team")) { - player.sendMessage(BungeeCore.ChatPrefix + DENY_MESSAGE); + player.sendMessage(BungeeCore.CHAT_PREFIX + DENY_MESSAGE); }else{ player.connect(server); } } else { - player.sendMessage(BungeeCore.ChatPrefix + "§7Mit §8/§ejoin §8[§eSpieler§8] §7kannst du einem Spieler folgen §8(z.B. in eine Arena)§7."); + player.sendMessage(BungeeCore.CHAT_PREFIX + "§7Mit §8/§ejoin §8[§eSpieler§8] §7kannst du einem Spieler folgen §8(z.B. in eine Arena)§7."); } } } diff --git a/src/de/steamwar/bungeecore/commands/KickCommand.java b/src/de/steamwar/bungeecore/commands/KickCommand.java index e2c8317..edf56b3 100644 --- a/src/de/steamwar/bungeecore/commands/KickCommand.java +++ b/src/de/steamwar/bungeecore/commands/KickCommand.java @@ -7,7 +7,7 @@ import net.md_5.bungee.api.connection.ProxiedPlayer; import java.util.ArrayList; -public class KickCommand extends Command { +public class KickCommand extends BasicCommand { public KickCommand() { super("kick", "bungeecore.kick"); @@ -16,34 +16,33 @@ public class KickCommand extends Command { @Override public void execute(CommandSender sender, String[] args) { if(args.length == 0){ - sender.sendMessage(BungeeCore.ChatPrefix + "/kick [Spieler] [Nachricht]"); + BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "/kick [Spieler] [Nachricht]"); return; } ProxiedPlayer target = ProxyServer.getInstance().getPlayer(args[0]); if(target == null){ - sender.sendMessage(BungeeCore.ChatPrefix + "§cDieser Spieler ist derzeit nicht online!"); + BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "§cDieser Spieler ist derzeit nicht online!"); return; } if(args.length == 1){ - target.disconnect(BungeeCore.ChatPrefix + "§cDu wurdest gekickt."); + target.disconnect(BungeeCore.stringToText(BungeeCore.CHAT_PREFIX + "§cDu wurdest gekickt.")); }else{ StringBuilder msgBuilder = new StringBuilder(); - msgBuilder.append(BungeeCore.ChatPrefix).append("§c"); + msgBuilder.append(BungeeCore.CHAT_PREFIX).append("§c"); for (int i = 1; i < args.length; i++){ msgBuilder.append(args[i]).append(" "); } - target.disconnect(msgBuilder.toString()); + target.disconnect(BungeeCore.stringToText(msgBuilder.toString())); } - sender.sendMessage(BungeeCore.ChatPrefix + "Der Spieler " + target.getName() + " wurde gekickt."); + BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "Der Spieler " + target.getName() + " wurde gekickt."); } @Override public Iterable onTabComplete(CommandSender commandSender, String[] args) { - if(args.length == 1){ + if(args.length == 1) return allPlayers(args[0]); - } return new ArrayList<>(); } } diff --git a/src/de/steamwar/bungeecore/commands/MsgCommand.java b/src/de/steamwar/bungeecore/commands/MsgCommand.java index c2da9db..33dd194 100644 --- a/src/de/steamwar/bungeecore/commands/MsgCommand.java +++ b/src/de/steamwar/bungeecore/commands/MsgCommand.java @@ -1,6 +1,7 @@ package de.steamwar.bungeecore.commands; import de.steamwar.bungeecore.BungeeCore; +import de.steamwar.bungeecore.sql.SteamwarUser; import net.md_5.bungee.api.CommandSender; import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.connection.ProxiedPlayer; @@ -8,9 +9,9 @@ import net.md_5.bungee.api.connection.ProxiedPlayer; import java.util.ArrayList; import java.util.HashMap; -public class MsgCommand extends Command { +public class MsgCommand extends BasicCommand { - protected static final HashMap lastChats = new HashMap<>(); + static final HashMap lastChats = new HashMap<>(); public MsgCommand() { super("msg", "", "w", "tell"); @@ -22,19 +23,25 @@ public class MsgCommand extends Command { ProxiedPlayer player = (ProxiedPlayer) sender; if (args.length < 2) { - player.sendMessage(BungeeCore.ChatPrefix + "/msg [Benutzer] [Nachricht]"); + BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "/msg [Benutzer] [Nachricht]"); + return; + } + + SteamwarUser user = SteamwarUser.get(player); + if(user.isMuted()){ + sender.sendMessage(user.muteMessage()); return; } ProxiedPlayer target = ProxyServer.getInstance().getPlayer(args[0]); if(target == null){ - player.sendMessage(BungeeCore.ChatPrefix + "§cDieser Spieler ist derzeit nicht online!"); + BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§cDieser Spieler ist derzeit nicht online!"); return; }else if(target.getChatMode() != ProxiedPlayer.ChatMode.SHOWN){ - player.sendMessage(BungeeCore.ChatPrefix + "§cDieser Spieler empfängt derzeit keine Chatnachrichten!"); + BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§cDieser Spieler empfängt derzeit keine Chatnachrichten!"); return; }else if(target.equals(player)){ - player.sendMessage(BungeeCore.ChatPrefix + "§cNachrichten an dich selbst hast du wirklich nicht nötig!"); + BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§cNachrichten an dich selbst hast du wirklich nicht nötig!"); return; } @@ -44,8 +51,8 @@ public class MsgCommand extends Command { msgBuilder.append(args[i]).append(" "); } String msg = msgBuilder.toString(); - player.sendMessage(msg); - target.sendMessage(msg); + BungeeCore.send(player, msg); + BungeeCore.send(target, msg); BungeeCore.log(msg); lastChats.put(player.getName().toLowerCase(), target); diff --git a/src/de/steamwar/bungeecore/commands/MuteCommand.java b/src/de/steamwar/bungeecore/commands/MuteCommand.java new file mode 100644 index 0000000..cec2dcf --- /dev/null +++ b/src/de/steamwar/bungeecore/commands/MuteCommand.java @@ -0,0 +1,38 @@ +package de.steamwar.bungeecore.commands; + +import de.steamwar.bungeecore.BungeeCore; +import de.steamwar.bungeecore.sql.SteamwarUser; +import net.md_5.bungee.api.CommandSender; + +import java.sql.Timestamp; + +public class MuteCommand extends BasicCommand { + + public MuteCommand() { + super("mute", "bungeecore.ban"); + } + + @Override + public void execute(CommandSender sender, String[] args) { + if(args.length < 3){ + BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "/mute [Spieler] [dd.mm.yyyy oder perma] [Grund]"); + return; + } + + SteamwarUser target = user(sender, args[0]); + if(target == null) + return; + + Timestamp muteTime = BanCommand.parseTime(sender, args[1]); + if(muteTime == null) + return; + + StringBuilder muteReason = new StringBuilder(); + for (int i = 2; i < args.length; i++){ + muteReason.append(args[i]).append(" "); + } + String msg = muteReason.toString(); + BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "Du hast " + target.getUserName() + " gemuted. Grund: §c" + msg); + target.mute(muteTime, msg); + } +} diff --git a/src/de/steamwar/bungeecore/commands/PingCommand.java b/src/de/steamwar/bungeecore/commands/PingCommand.java index e538fcb..28bd9b1 100644 --- a/src/de/steamwar/bungeecore/commands/PingCommand.java +++ b/src/de/steamwar/bungeecore/commands/PingCommand.java @@ -4,7 +4,7 @@ import de.steamwar.bungeecore.BungeeCore; import net.md_5.bungee.api.CommandSender; import net.md_5.bungee.api.connection.ProxiedPlayer; -public class PingCommand extends Command { +public class PingCommand extends BasicCommand { public PingCommand() { super("ping", ""); @@ -14,7 +14,7 @@ public class PingCommand extends Command { public void execute(CommandSender sender, String[] args) { if(sender instanceof ProxiedPlayer){ ProxiedPlayer player = (ProxiedPlayer) sender; - player.sendMessage(BungeeCore.ChatPrefix + "§7Dein Ping beträgt §c" + player.getPing() + "§r§7 ms!"); + player.sendMessage(BungeeCore.CHAT_PREFIX + "§7Dein Ping beträgt §c" + player.getPing() + "§r§7 ms!"); } } } diff --git a/src/de/steamwar/bungeecore/commands/PollCommand.java b/src/de/steamwar/bungeecore/commands/PollCommand.java new file mode 100644 index 0000000..f6f7b1c --- /dev/null +++ b/src/de/steamwar/bungeecore/commands/PollCommand.java @@ -0,0 +1,51 @@ +package de.steamwar.bungeecore.commands; + +import de.steamwar.bungeecore.BungeeCore; +import de.steamwar.bungeecore.listeners.PollSystem; +import de.steamwar.bungeecore.sql.PollAnswer; +import de.steamwar.bungeecore.sql.SteamwarUser; +import net.md_5.bungee.api.CommandSender; +import net.md_5.bungee.api.connection.ProxiedPlayer; + +public class PollCommand extends BasicCommand { + + public PollCommand() { + super("poll", ""); + } + + @Override + public void execute(CommandSender sender, String[] args) { + if(!(sender instanceof ProxiedPlayer)) + return; + + ProxiedPlayer player = (ProxiedPlayer) sender; + + if(PollSystem.noCurrentPoll()){ + BungeeCore.send(player, "§cDerzeit läuft keine Umfrage."); + return; + } + + if(args.length == 0){ + PollSystem.sendPoll(player); + return; + } + + int answer; + try { + answer = Integer.parseUnsignedInt(args[0]); + if(answer < 1 || answer >= PollSystem.answers()) + throw new NumberFormatException(); + }catch(NumberFormatException e){ + BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§cDas ist keine Antwortmöglichkeit!"); + return; + } + + PollAnswer pollAnswer = PollAnswer.get(SteamwarUser.get(player.getUniqueId()).getId()); + if(pollAnswer.hasAnswered()) + BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§aDeine Antwort wurde aktualisiert"); + else + BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§aDeine Antwort wurde registriert"); + + pollAnswer.setAnswer(answer); + } +} diff --git a/src/de/steamwar/bungeecore/commands/RCommand.java b/src/de/steamwar/bungeecore/commands/RCommand.java index 0392ea2..2ff68d2 100644 --- a/src/de/steamwar/bungeecore/commands/RCommand.java +++ b/src/de/steamwar/bungeecore/commands/RCommand.java @@ -1,10 +1,11 @@ package de.steamwar.bungeecore.commands; import de.steamwar.bungeecore.BungeeCore; +import de.steamwar.bungeecore.sql.SteamwarUser; import net.md_5.bungee.api.CommandSender; import net.md_5.bungee.api.connection.ProxiedPlayer; -public class RCommand extends Command { +public class RCommand extends BasicCommand { public RCommand() { super("r", "", "reply"); @@ -15,21 +16,27 @@ public class RCommand extends Command { if(sender instanceof ProxiedPlayer){ ProxiedPlayer player = (ProxiedPlayer) sender; if(args.length == 0){ - player.sendMessage(BungeeCore.ChatPrefix + "/r [Antwort]"); + BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "/r [Antwort]"); + return; + } + + SteamwarUser user = SteamwarUser.get(player); + if(user.isMuted()){ + sender.sendMessage(user.muteMessage()); return; } ProxiedPlayer target = MsgCommand.lastChats.get(player.getName().toLowerCase()); if(target == null){ - player.sendMessage(BungeeCore.ChatPrefix + "§cDu hast bisher mit niemandem geschrieben!"); + BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§cDu hast bisher mit niemandem geschrieben!"); return; } if(!target.isConnected()){ - player.sendMessage(BungeeCore.ChatPrefix + "§cDieser Spieler ist derzeit nicht online!"); + BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§cDieser Spieler ist derzeit nicht online!"); return; }else if(target.getChatMode() != ProxiedPlayer.ChatMode.SHOWN){ - player.sendMessage(BungeeCore.ChatPrefix + "§cDieser Spieler empfängt derzeit keine Chatnachrichten!"); + BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§cDieser Spieler empfängt derzeit keine Chatnachrichten!"); return; } @@ -39,8 +46,8 @@ public class RCommand extends Command { msgBuilder.append(arg).append(" "); } String msg = msgBuilder.toString(); - player.sendMessage(msg); - target.sendMessage(msg); + BungeeCore.send(player, msg); + BungeeCore.send(target, msg); BungeeCore.log(msg); MsgCommand.lastChats.put(target.getName().toLowerCase(), player); diff --git a/src/de/steamwar/bungeecore/commands/ServerSwitchCommand.java b/src/de/steamwar/bungeecore/commands/ServerSwitchCommand.java index 45a48a6..d075890 100644 --- a/src/de/steamwar/bungeecore/commands/ServerSwitchCommand.java +++ b/src/de/steamwar/bungeecore/commands/ServerSwitchCommand.java @@ -5,7 +5,7 @@ import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.config.ServerInfo; import net.md_5.bungee.api.connection.ProxiedPlayer; -public class ServerSwitchCommand extends Command { +public class ServerSwitchCommand extends BasicCommand { private String serverName; diff --git a/src/de/steamwar/bungeecore/commands/ServerTeamchatCommand.java b/src/de/steamwar/bungeecore/commands/ServerTeamchatCommand.java index 5301740..91612b6 100644 --- a/src/de/steamwar/bungeecore/commands/ServerTeamchatCommand.java +++ b/src/de/steamwar/bungeecore/commands/ServerTeamchatCommand.java @@ -6,7 +6,7 @@ import net.md_5.bungee.api.CommandSender; import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.connection.ProxiedPlayer; -public class ServerTeamchatCommand extends Command{ +public class ServerTeamchatCommand extends BasicCommand { public ServerTeamchatCommand() { super("stc", "bungeecore.teamchat","serverteamchat"); @@ -18,12 +18,12 @@ public class ServerTeamchatCommand extends Command{ ProxiedPlayer player = (ProxiedPlayer) sender; if(args.length == 0){ - player.sendMessage(BungeeCore.ChatPrefix + "/stc [Nachricht an das Team]"); + player.sendMessage(BungeeCore.CHAT_PREFIX + "/stc [Nachricht an das Team]"); return; } StringBuilder msgBuilder = new StringBuilder(); - msgBuilder.append(BungeeCore.ServerTeamchatPrefix).append(sender.getName()).append("» §r"); + msgBuilder.append(BungeeCore.SERVER_TEAMCHAT_PREFIX).append(sender.getName()).append("» §r"); for (String arg : args){ msgBuilder.append(arg).append(" "); } diff --git a/src/de/steamwar/bungeecore/commands/TeamCommand.java b/src/de/steamwar/bungeecore/commands/TeamCommand.java index 63876b2..522093a 100644 --- a/src/de/steamwar/bungeecore/commands/TeamCommand.java +++ b/src/de/steamwar/bungeecore/commands/TeamCommand.java @@ -1,39 +1,52 @@ package de.steamwar.bungeecore.commands; import de.steamwar.bungeecore.BungeeCore; +import de.steamwar.bungeecore.sql.Event; +import de.steamwar.bungeecore.sql.SteamwarUser; import de.steamwar.bungeecore.sql.Team; -import de.steamwar.bungeecore.sql.WarkingUser; +import de.steamwar.bungeecore.sql.TeamTeilnahme; import net.md_5.bungee.api.CommandSender; import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.chat.ClickEvent; -import net.md_5.bungee.api.chat.ComponentBuilder; -import net.md_5.bungee.api.chat.HoverEvent; -import net.md_5.bungee.api.chat.TextComponent; import net.md_5.bungee.api.connection.ProxiedPlayer; +import java.time.Instant; import java.util.*; -public class TeamCommand extends Command { +public class TeamCommand extends BasicCommand { public TeamCommand() { super("team", ""); } - private static Map> invitations = new HashMap<>(); + private static Map> invitations = new HashMap<>(); private void help(CommandSender sender){ - sender.sendMessage(BungeeCore.ChatPrefix + "§7Mit §e/team §7verwaltest du dein Team"); - sender.sendMessage(BungeeCore.ChatPrefix + "§8/§eteam create §8- §7Erstelle dein eigenes Team"); - sender.sendMessage(BungeeCore.ChatPrefix + "§8/§eteam join §8- §7Trete einem Team bei"); - sender.sendMessage(BungeeCore.ChatPrefix + "§8/§eteamchat §8- §7Sende Nachrichten an dein Team"); - sender.sendMessage(BungeeCore.ChatPrefix + "§8/§eteam leave §8- §7Verlasse dein Team"); - sender.sendMessage(BungeeCore.ChatPrefix + "§8/§eteam list §8- §7Liste alle Teams auf"); - sender.sendMessage(BungeeCore.ChatPrefix + "§8/§eteam info §8- §7Informiere dich über ein Team"); - sender.sendMessage(BungeeCore.ChatPrefix + "§8/§eteam invite §8- §7Lade jemanden in dein Team ein"); - sender.sendMessage(BungeeCore.ChatPrefix + "§8/§eteam remove §8- §7Entferne jemanden aus deinem Team"); - sender.sendMessage(BungeeCore.ChatPrefix + "§8/§eteam changekuerzel §8- §7Ändere dein Teamkürzel"); - sender.sendMessage(BungeeCore.ChatPrefix + "§8/§eteam changename §8- §7Ändere deinen Teamnamen"); - sender.sendMessage(BungeeCore.ChatPrefix + "§8/§eteam changeleader §8- §7Ernenne jemanden zum Teamleader"); + BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "§7Mit §e/team §7verwaltest du dein Team"); + BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "§8/§eteam list §8- §7Liste alle Teams auf"); + BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "§8/§eteam info §8- §7Informiere dich über ein Team"); + if(!(sender instanceof ProxiedPlayer)) + return; + + ProxiedPlayer player = (ProxiedPlayer) sender; + SteamwarUser user = SteamwarUser.get(player.getUniqueId()); + if(user.getTeam() == 0) { + BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "§8/§eteam create §8- §7Erstelle dein eigenes Team"); + BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "§8/§eteam join §8- §7Trete einem Team bei"); + }else{ + BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "§8/§eteamchat §8- §7Sende Nachrichten an dein Team"); + BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "§8/§eteam event §8- §7Nehme an Events teil"); + BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "§8/§eteam leave §8- §7Verlasse dein Team"); + + Team team = Team.get(user.getTeam()); + if(team.getTeamLeader() == user.getId()){ + BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "§8/§eteam invite §8- §7Lade jemanden in dein Team ein"); + BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "§8/§eteam remove §8- §7Entferne jemanden aus deinem Team"); + BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "§8/§eteam changekuerzel §8- §7Ändere dein Teamkürzel"); + BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "§8/§eteam changename §8- §7Ändere deinen Teamnamen"); + BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "§8/§eteam changeleader §8- §7Ernenne jemanden zum Teamleader"); + } + } } @Override @@ -47,264 +60,370 @@ public class TeamCommand extends Command { return; ProxiedPlayer player = (ProxiedPlayer) sender; - WarkingUser user = WarkingUser.get(player.getUniqueId()); + SteamwarUser user = SteamwarUser.get(player.getUniqueId()); Team team = Team.get(user.getTeam()); - WarkingUser target; - ProxiedPlayer p; switch(args[0].toLowerCase()){ case "create": - if(unwantedInTeam(player, user)) - return; - - if(args.length < 3){ - player.sendMessage(BungeeCore.ChatPrefix + "§8/§eteam create §8[§eTeamkürzel§8] §8[§eTeamname§8]"); - return; - } - - if(checkTeamKuerzel(player, team, args[1])) - return; - - if(checkTeamName(player, team, args[2])) - return; - - Team.create(args[1], args[2], user.getId()); - user.setTeam(Team.get(args[1]).getTeamId()); - player.sendMessage(BungeeCore.ChatPrefix + "§7Du hast das Team §e" + args[2] + " §7gegründet!"); + create(player, user, team, args); break; case "join": - if(unwantedInTeam(player, user)) - return; - - if(!invitations.containsKey(user)){ - player.sendMessage(BungeeCore.ChatPrefix + "§7Du hast keine Einladungen erhalten."); - return; - } - - List invs = invitations.get(user); - Team t = null; - - if(invs.size() == 1){ - t = invs.get(0); - }else{ - if(args.length != 2){ - player.sendMessage(BungeeCore.ChatPrefix + "§8/§eteam join §8[§eTeam§8]"); - StringBuilder sb = new StringBuilder().append("§7Du wurdest von diesen Teams eingeladen§8: §e"); - for(Team inv : invs){ - sb.append(inv.getTeamName()).append(" "); - } - player.sendMessage(sb.toString()); - return; - } - - for(Team inv : invs){ - if(inv.getTeamName().equals(args[1])){ - t = inv; - break; - } - } - if(t == null){ - player.sendMessage(BungeeCore.ChatPrefix + "§cVon diesem Team wurdest du nicht eingeladen"); - return; - } - } - - user.setTeam(t.getTeamId()); - invitations.remove(user); - player.sendMessage(BungeeCore.ChatPrefix + "§7Du bist dem Team §e" + t.getTeamName() + " §7beigetreten!"); + join(player, user, args); break; case "leave": - if(notInTeam(player, user)) - return; - - if(team.getTeamLeader() == user.getId() && team.size() > 1){ - player.sendMessage(BungeeCore.ChatPrefix + "§cBitte ernenne zunächst ein anderes Teammitglied zum Leader"); - return; - } - - user.setTeam(0); - - if(team.getTeamLeader() == user.getId()){ - team.disband(); - } - - player.sendMessage(BungeeCore.ChatPrefix + "§7Du hast dein Team verlassen!"); + leave(player, user, team); break; case "invite": - if(notLeader(player, user, team)) - return; - - if(args.length != 2){ - player.sendMessage(BungeeCore.ChatPrefix + "§8/§eteam invite §8[§eSpieler§8]"); - return; - } - - target = WarkingUser.get(args[1]); - if(target == null){ - player.sendMessage(BungeeCore.ChatPrefix + "§cDiesen Spieler gibt es nicht"); - return; - }else if(target.getTeam() != 0){ - player.sendMessage(BungeeCore.ChatPrefix + "§cDieser Spieler ist bereits in einem Team"); - return; - } - - if(!invitations.containsKey(target)) - invitations.put(target, new LinkedList<>()); - - if(invitations.get(target).contains(team)){ - player.sendMessage(BungeeCore.ChatPrefix + "§cDu hast diesen Spieler bereits eingeladen"); - return; - } - - invitations.get(target).add(team); - - player.sendMessage(BungeeCore.ChatPrefix + "§7Du hast §e" + args[1] + " §7in das Team eingeladen!"); - p = ProxyServer.getInstance().getPlayer(target.getUUID()); - if(p != null) - p.sendMessage(BungeeCore.ChatPrefix + "§7Du wurdest in das Team §e" + team.getTeamName() + " §7eingeladen!"); + invite(player, user, team, args); break; case "remove": - if(notLeader(player, user, team)) - return; - - if(args.length != 2){ - player.sendMessage(BungeeCore.ChatPrefix + "§8/§eteam remove §8[§eSpieler§8]"); - return; - } - - target = WarkingUser.get(args[1]); - if(target == null){ - player.sendMessage(BungeeCore.ChatPrefix + "§cDiesen Spieler gibt es nicht"); - return; - } - - if(invitations.containsKey(target)){ - if(invitations.get(target).remove(team)){ - player.sendMessage(BungeeCore.ChatPrefix + "§7Die Einladung wurde zurückgezogen"); - if(invitations.get(target).isEmpty()) - invitations.remove(target); - }else{ - player.sendMessage(BungeeCore.ChatPrefix + "§cDieser Spieler hat keine Einladung erhalten"); - } - return; - } - - if(target.getTeam() != user.getTeam()){ - player.sendMessage(BungeeCore.ChatPrefix + "§cDieser Spieler ist nicht in deinem Team"); - return; - } - - target.setTeam(0); - - player.sendMessage(BungeeCore.ChatPrefix + "§7Der Spieler wurde aus dem Team entfernt"); - p = ProxyServer.getInstance().getPlayer(target.getUUID()); - if(p != null) - p.sendMessage(BungeeCore.ChatPrefix + "§cDu wurdest aus dem Team entfernt"); + remove(player, user, team, args); break; case "changekuerzel": - if(notLeader(player, user, team)) - return; - - if(args.length < 2){ - player.sendMessage(BungeeCore.ChatPrefix + "§8/§eteam changekuerzel §8[§eTeamkürzel§8]"); - return; - } - - if(checkTeamKuerzel(player, team, args[1])) - return; - - team.setTeamKuerzel(args[1]); - player.sendMessage(BungeeCore.ChatPrefix + "§7Du hast das Kürzel des Teams geändert!"); + changekuerzel(player, user, team, args); break; case "changename": - if(notLeader(player, user, team)) - return; - - if(args.length < 2){ - player.sendMessage(BungeeCore.ChatPrefix + "§8/§eteam changename §8[§eTeamname§8]"); - return; - } - - if(checkTeamName(player, team, args[1])) - return; - - team.setTeamName(args[1]); - player.sendMessage(BungeeCore.ChatPrefix + "§7Du hast das Team umbenannt!"); + changename(player, user, team, args); break; case "changeleader": - if(notLeader(player, user, team)) - return; - - if(args.length < 2){ - player.sendMessage(BungeeCore.ChatPrefix + "§cBitte gib ein Teammitglied an"); - return; - } - - target = WarkingUser.get(args[1]); - if(target == null){ - player.sendMessage(BungeeCore.ChatPrefix + "§cDen Spieler " + args[1] + " gibt es nicht"); - return; - } - - if(target.getTeam() != user.getTeam()){ - player.sendMessage(BungeeCore.ChatPrefix + "§cDer Spieler ist nicht in deinem Team"); - return; - } - - team.setTeamLeader(target.getId()); - player.sendMessage(BungeeCore.ChatPrefix + "§7Du hast den Spieler §e" + args[1] + " §7zum Leader gemacht!"); + changeleader(player, user, team, args); break; case "info": - if(args.length == 1 && user.getTeam() == 0){ - player.sendMessage(BungeeCore.ChatPrefix + "§8/§eteam info §8[§eTeamname§8]"); - return; - }else if(user.getTeam() == 0 || args.length == 2){ - team = Team.get(args[1]); - } - - if(team == null){ - player.sendMessage(BungeeCore.ChatPrefix + "§cDieses Team gibt es nicht"); - return; - } - - player.sendMessage("§7Team §e" + team.getTeamName() + " §8[§e" + team.getTeamKuerzel() + "§8]"); - player.sendMessage("§7Leader§8: " + WarkingUser.get(team.getTeamLeader()).getUserName()); - - StringBuilder sb = new StringBuilder(); - sb.append("§7Member§8: §e"); - List members = team.getMembers(); - - for(int i : members){ - WarkingUser m = WarkingUser.get(i); - sb.append(m.getUserName()).append(" "); - } - - player.sendMessage(sb.toString()); + info(player, user, team, args); break; case "list": - player.sendMessage(BungeeCore.ChatPrefix + "§7§lTeamliste"); - List all = Team.getAll(); - for(Team tm : all){ - TextComponent tc = new TextComponent("§8" + tm.getTeamKuerzel() + " §e" + tm.getTeamName() + " §8[§7" + WarkingUser.get(tm.getTeamLeader()).getUserName() + "§8]"); - tc.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§7Teaminfo").create())); - tc.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/team info " + tm.getTeamKuerzel())); - player.sendMessage(tc); - } + list(player); + break; + case "event": + event(player, user, team, args); break; default: help(player); } } + private void create(ProxiedPlayer player, SteamwarUser user, Team team, String[] args){ + if(unwantedInTeam(player, user)) + return; + + if(args.length < 3){ + BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§8/§eteam create §8[§eTeamkürzel§8] §8[§eTeamname§8]"); + return; + } + + if(checkTeamKuerzel(player, team, args[1])) + return; + + if(checkTeamName(player, team, args[2])) + return; + + Team.create(args[1], args[2], user.getId()); + user.setTeam(Team.get(args[1]).getTeamId()); + BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§7Du hast das Team §e" + args[2] + " §7gegründet!"); + } + + private void join(ProxiedPlayer player, SteamwarUser user, String[] args){ + if(unwantedInTeam(player, user)) + return; + + if(notDuringEvent(player)) + return; + + if(!invitations.containsKey(user)){ + BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§7Du hast keine Einladungen erhalten."); + return; + } + + List invs = invitations.get(user); + Team t = null; + + if(invs.size() == 1){ + t = invs.get(0); + }else{ + if(args.length != 2){ + BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§8/§eteam join §8[§eTeam§8]"); + StringBuilder sb = new StringBuilder().append("§7Du wurdest von diesen Teams eingeladen§8: §e"); + for(Team inv : invs){ + sb.append(inv.getTeamName()).append(" "); + } + BungeeCore.send(player, sb.toString()); + return; + } + + for(Team inv : invs){ + if(inv.getTeamName().equals(args[1])){ + t = inv; + break; + } + } + + if(t == null){ + BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§cVon diesem Team wurdest du nicht eingeladen"); + return; + } + } + + user.setTeam(t.getTeamId()); + invitations.remove(user); + BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§7Du bist dem Team §e" + t.getTeamName() + " §7beigetreten!"); + } + + private void leave(ProxiedPlayer player, SteamwarUser user, Team team){ + if(notInTeam(player, user)) + return; + + if(team.getTeamLeader() == user.getId() && team.size() > 1){ + BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§cBitte ernenne zunächst ein anderes Teammitglied zum Leader"); + return; + } + + user.setTeam(0); + + if(team.getTeamLeader() == user.getId()){ + team.disband(); + } + + BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§7Du hast dein Team verlassen!"); + } + + + private void invite(ProxiedPlayer player, SteamwarUser user, Team team, String[] args){ + if(notLeader(player, user, team)) + return; + + if(notDuringEvent(player)) + return; + + if(args.length != 2){ + BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§8/§eteam invite §8[§eSpieler§8]"); + return; + } + + SteamwarUser target = SteamwarUser.get(args[1]); + if(target == null){ + BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§cDiesen Spieler gibt es nicht"); + return; + }else if(target.getTeam() != 0){ + BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§cDieser Spieler ist bereits in einem Team"); + return; + } + + if(!invitations.containsKey(target)) + invitations.put(target, new LinkedList<>()); + + if(invitations.get(target).contains(team)){ + BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§cDu hast diesen Spieler bereits eingeladen"); + return; + } + + invitations.get(target).add(team); + + BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§7Du hast §e" + args[1] + " §7in das Team eingeladen!"); + ProxiedPlayer p = ProxyServer.getInstance().getPlayer(target.getUuid()); + if(p != null) + BungeeCore.send(p, BungeeCore.CHAT_PREFIX + "§7Du wurdest in das Team §e" + team.getTeamName() + " §7eingeladen!"); + } + + private void remove(ProxiedPlayer player, SteamwarUser user, Team team, String[] args){ + if(notLeader(player, user, team)) + return; + + if(args.length != 2){ + BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§8/§eteam remove §8[§eSpieler§8]"); + return; + } + + SteamwarUser target = SteamwarUser.get(args[1]); + if(target == null){ + BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§cDiesen Spieler gibt es nicht"); + return; + } + + if(invitations.containsKey(target)){ + if(invitations.get(target).remove(team)){ + BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§7Die Einladung wurde zurückgezogen"); + if(invitations.get(target).isEmpty()) + invitations.remove(target); + }else{ + BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§cDieser Spieler hat keine Einladung erhalten"); + } + return; + } + + if(target.getTeam() != user.getTeam()){ + BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§cDieser Spieler ist nicht in deinem Team"); + return; + } + + target.setTeam(0); + + BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§7Der Spieler wurde aus dem Team entfernt"); + ProxiedPlayer p = ProxyServer.getInstance().getPlayer(target.getUuid()); + if(p != null) + BungeeCore.send(p, BungeeCore.CHAT_PREFIX + "§cDu wurdest aus dem Team entfernt"); + } + + private void changekuerzel(ProxiedPlayer player, SteamwarUser user, Team team, String[] args){ + if(notLeader(player, user, team)) + return; + + if(notDuringEvent(player)) + return; + + if(args.length < 2){ + BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§8/§eteam changekuerzel §8[§eTeamkürzel§8]"); + return; + } + + if(checkTeamKuerzel(player, team, args[1])) + return; + + team.setTeamKuerzel(args[1]); + BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§7Du hast das Kürzel des Teams geändert!"); + } + + private void changename(ProxiedPlayer player, SteamwarUser user, Team team, String[] args){ + if(notLeader(player, user, team)) + return; + + if(notDuringEvent(player)) + return; + + if(args.length < 2){ + BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§8/§eteam changename §8[§eTeamname§8]"); + return; + } + + if(checkTeamName(player, team, args[1])) + return; + + team.setTeamName(args[1]); + BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§7Du hast das Team umbenannt!"); + } + + private void changeleader(ProxiedPlayer player, SteamwarUser user, Team team, String[] args){ + if(notLeader(player, user, team)) + return; + + if(notDuringEvent(player)) + return; + + if(args.length < 2){ + BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§cBitte gib ein Teammitglied an"); + return; + } + + SteamwarUser target = SteamwarUser.get(args[1]); + if(target == null){ + BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§cDen Spieler " + args[1] + " gibt es nicht"); + return; + } + + if(target.getTeam() != user.getTeam()){ + BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§cDer Spieler ist nicht in deinem Team"); + return; + } + + team.setTeamLeader(target.getId()); + BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§7Du hast den Spieler §e" + args[1] + " §7zum Leader gemacht!"); + } + + private void info(ProxiedPlayer player, SteamwarUser user, Team team, String[] args){ + if(args.length == 1 && user.getTeam() == 0){ + BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§8/§eteam info §8[§eTeamname§8]"); + return; + }else if(user.getTeam() == 0 || args.length == 2){ + team = Team.get(args[1]); + } + + if(team == null){ + BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§cDieses Team gibt es nicht"); + return; + } + + BungeeCore.send(player, "§7Team §e" + team.getTeamName() + " §8[§e" + team.getTeamKuerzel() + "§8]"); + BungeeCore.send(player, "§7Leader§8: " + SteamwarUser.get(team.getTeamLeader()).getUserName()); + + StringBuilder sb = new StringBuilder(); + sb.append("§7Member§8: §e"); + List members = team.getMembers(); + for(int i : members){ + SteamwarUser m = SteamwarUser.get(i); + sb.append(m.getUserName()).append(" "); + } + BungeeCore.send(player, sb.toString()); + + Set events = TeamTeilnahme.getEvents(team.getTeamId()); + if(!events.isEmpty()){ + sb = new StringBuilder("§7Events§8: §e"); + for(Event e : events) + sb.append(e.getEventName()).append(" "); + BungeeCore.send(player, sb.toString()); + } + } + + private void list(ProxiedPlayer player){ + BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§7§lTeamliste"); + List all = Team.getAll(); + for(Team tm : all){ + BungeeCore.send(player, + "§8" + tm.getTeamKuerzel() + " §e" + tm.getTeamName() + " §8[§7" + SteamwarUser.get(tm.getTeamLeader()).getUserName() + "§8]", + "§7Teaminfo", + new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/team info " + tm.getTeamKuerzel())); + } + } + + private void event(ProxiedPlayer player, SteamwarUser user, Team team, String[] args){ + if(notInTeam(player, user)) + return; + + if(args.length < 2){ + BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§8/§eteam event §8[§eEvent§8] - §7um daran teilzunehmen"); + Set events = TeamTeilnahme.getEvents(team.getTeamId()); + if(!events.isEmpty()){ + BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§7Dein Team nimmt an folgenden Events teil§8:"); + for(Event e : events) + BungeeCore.send(player, "§7" + e.getStart().toLocalDateTime().format(EventCommand.DATE_FORMAT) + "§8: §e" + e.getEventName()); + } + return; + } + + if(notLeader(player, user, team)) + return; + + if(notDuringEvent(player)) + return; + + Event event = Event.get(args[1]); + if(event == null){ + BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§cDieses Event gibt es nicht"); + return; + } + + if(Instant.now().isAfter(event.getEnd().toInstant())){ + BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§cDieses Event ist bereits vorbei"); + return; + } + + if(TeamTeilnahme.nimmtTeil(team.getTeamId(), event.getEventID())){ + TeamTeilnahme.notTeilnehmen(team.getTeamId(), event.getEventID()); + BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§7Dein Team nimmt nicht mehr am Event teil"); + }else{ + TeamTeilnahme.teilnehmen(team.getTeamId(), event.getEventID()); + BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§7Dein Team nimmt nun am Event §e" + event.getEventName() + " §7 teil!"); + BungeeCore.send(player, "§7Um die Teilnahme abzusagen, wiederhole den Befehl"); + } + } + private boolean checkTeamName(ProxiedPlayer player, Team team, String arg){ if(arg.length() < 4 || arg.length() > 15){ - player.sendMessage(BungeeCore.ChatPrefix + "§cEin Teamname muss aus 4 bis 15 Buchstaben bestehen"); + BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§cEin Teamname muss aus 4 bis 15 Buchstaben bestehen"); return true; } Team t = Team.get(arg); if(t != null && t.getTeamId() != team.getTeamId()){ - player.sendMessage(BungeeCore.ChatPrefix + "§cEs gibt bereits ein Team mit diesem Namen"); + BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§cEs gibt bereits ein Team mit diesem Namen"); return true; } return false; @@ -312,39 +431,47 @@ public class TeamCommand extends Command { private boolean checkTeamKuerzel(ProxiedPlayer player, Team team, String arg){ if(arg.length() < 2 || arg.length() > 4){ - player.sendMessage(BungeeCore.ChatPrefix + "§cEin Teamkürzel muss aus 2 bis 4 Buchstaben bestehen"); + BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§cEin Teamkürzel muss aus 2 bis 4 Buchstaben bestehen"); return true; } Team t = Team.get(arg); if(t != null && (team == null || t.getTeamId() != team.getTeamId())){ - player.sendMessage(BungeeCore.ChatPrefix + "§cEs gibt bereits ein Team mit diesem Namen"); + BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§cEs gibt bereits ein Team mit diesem Namen"); return true; } return false; } - private boolean unwantedInTeam(ProxiedPlayer player, WarkingUser user){ + private boolean unwantedInTeam(ProxiedPlayer player, SteamwarUser user){ if(user.getTeam() != 0){ - player.sendMessage(BungeeCore.ChatPrefix + "§cDu bist bereits in einem Team"); + BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§cDu bist bereits in einem Team"); return true; } return false; } - private boolean notInTeam(ProxiedPlayer player, WarkingUser user){ + private boolean notInTeam(ProxiedPlayer player, SteamwarUser user){ if(user.getTeam() == 0){ - player.sendMessage(BungeeCore.ChatPrefix + "§cDu bist in keinem Team"); + BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§cDu bist in keinem Team"); return true; } return false; } - private boolean notLeader(ProxiedPlayer player, WarkingUser user, Team team){ + private boolean notLeader(ProxiedPlayer player, SteamwarUser user, Team team){ if(notInTeam(player, user)) return true; if(team.getTeamLeader() != user.getId()){ - player.sendMessage(BungeeCore.ChatPrefix + "§cDu bist nicht der Teamleader"); + BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§cDu bist nicht der Teamleader"); + return true; + } + return false; + } + + private boolean notDuringEvent(ProxiedPlayer player){ + if(Event.get() != null){ + BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§cDies ist während eines Events nicht möglich"); return true; } return false; @@ -360,9 +487,21 @@ public class TeamCommand extends Command { tab.add("leave"); tab.add("info"); tab.add("remove"); + tab.add("event"); tab.add("changekuerzel"); tab.add("changename"); tab.add("changeleader"); + }else if(args.length == 2){ + if(args[1].equalsIgnoreCase("event")){ + List coming = Event.getComing(); + coming.forEach(event -> tab.add(event.getEventName())); + }else if(args[1].equalsIgnoreCase("join") || args[1].equalsIgnoreCase("info")){ + List teams = Team.getAll(); + teams.forEach(team -> { + tab.add(team.getTeamName()); + tab.add(team.getTeamKuerzel()); + }); + } } return tab; } diff --git a/src/de/steamwar/bungeecore/commands/TeamchatCommand.java b/src/de/steamwar/bungeecore/commands/TeamchatCommand.java index a4de984..34f4cc3 100644 --- a/src/de/steamwar/bungeecore/commands/TeamchatCommand.java +++ b/src/de/steamwar/bungeecore/commands/TeamchatCommand.java @@ -1,13 +1,14 @@ package de.steamwar.bungeecore.commands; import de.steamwar.bungeecore.BungeeCore; -import de.steamwar.bungeecore.sql.WarkingUser; +import de.steamwar.bungeecore.sql.SteamwarUser; import net.md_5.bungee.api.ChatColor; +import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.CommandSender; import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.connection.ProxiedPlayer; -public class TeamchatCommand extends Command { +public class TeamchatCommand extends BasicCommand { public TeamchatCommand() { super("tc", "","teamchat"); @@ -17,20 +18,20 @@ public class TeamchatCommand extends Command { public void execute(CommandSender sender, String[] args) { if(sender instanceof ProxiedPlayer){ ProxiedPlayer player = (ProxiedPlayer) sender; - WarkingUser user = WarkingUser.get(player.getUniqueId()); + SteamwarUser user = SteamwarUser.get(player.getUniqueId()); if(user.getTeam() == 0){ - player.sendMessage(BungeeCore.ChatPrefix + "§cDu bist in keinem Team"); + BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§cDu bist in keinem Team"); return; } if(args.length == 0){ - player.sendMessage(BungeeCore.TeamchatPrefix + "/teamchat [Nachricht an das Team]"); + BungeeCore.send(player, BungeeCore.TEAMCHAT_PREFIX + "/teamchat [Nachricht an das Team]"); return; } StringBuilder msgBuilder = new StringBuilder(); - msgBuilder.append(BungeeCore.TeamchatPrefix).append(sender.getName()).append("§8» §r"); + msgBuilder.append(BungeeCore.TEAMCHAT_PREFIX).append(sender.getName()).append("§8» §r"); for (String arg : args){ msgBuilder.append(arg).append(" "); } @@ -38,9 +39,10 @@ public class TeamchatCommand extends Command { msg = ChatColor.translateAlternateColorCodes('&', msg); for (ProxiedPlayer target : ProxyServer.getInstance().getPlayers()){ - WarkingUser targetuser = WarkingUser.get(target.getUniqueId()); + SteamwarUser targetuser = SteamwarUser.get(target.getUniqueId()); if (targetuser.getTeam() == user.getTeam() && target.getChatMode() == ProxiedPlayer.ChatMode.SHOWN){ + BungeeCore.send(target, ChatMessageType.CHAT, msg); target.sendMessage(msg); } } diff --git a/src/de/steamwar/bungeecore/commands/WebpwCommand.java b/src/de/steamwar/bungeecore/commands/WebpwCommand.java index 6a5e0d6..072d58f 100644 --- a/src/de/steamwar/bungeecore/commands/WebpwCommand.java +++ b/src/de/steamwar/bungeecore/commands/WebpwCommand.java @@ -1,12 +1,11 @@ package de.steamwar.bungeecore.commands; import de.steamwar.bungeecore.BungeeCore; -import de.steamwar.bungeecore.sql.WarkingUser; -import de.steamwar.bungeecore.sql.sql; +import de.steamwar.bungeecore.sql.SteamwarUser; import net.md_5.bungee.api.CommandSender; import net.md_5.bungee.api.connection.ProxiedPlayer; -public class WebpwCommand extends Command { +public class WebpwCommand extends BasicCommand { public WebpwCommand() { super("webpw", ""); @@ -17,18 +16,18 @@ public class WebpwCommand extends Command { if(sender instanceof ProxiedPlayer){ ProxiedPlayer player = (ProxiedPlayer) sender; if(args.length != 2){ - player.sendMessage(BungeeCore.ChatPrefix + "/webpw [Passwort] [Passwort wiederholen]"); + BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "/webpw [Passwort] [Passwort wiederholen]"); return; }else if(!args[0].equals(args[1])){ - player.sendMessage(BungeeCore.ChatPrefix + "§cDie Passwörter stimmen nicht überein!"); + BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§cDie Passwörter stimmen nicht überein!"); return; }else if(args[0].length() < 6){ - player.sendMessage(BungeeCore.ChatPrefix + "§cDas Passwort muss mindestens 6 Zeichen lang sein!"); + BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§cDas Passwort muss mindestens 6 Zeichen lang sein!"); return; } - sql.setWebpw(WarkingUser.get(player.getUniqueId()), args[0]); - player.sendMessage(BungeeCore.ChatPrefix + "Webpasswort gesetzt!"); + SteamwarUser.get(player.getUniqueId()).setWebpw(args[0]); + BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§7Webpasswort gesetzt!"); } } } diff --git a/src/de/steamwar/bungeecore/listeners/BanListener.java b/src/de/steamwar/bungeecore/listeners/BanListener.java new file mode 100644 index 0000000..f28e24c --- /dev/null +++ b/src/de/steamwar/bungeecore/listeners/BanListener.java @@ -0,0 +1,57 @@ +package de.steamwar.bungeecore.listeners; + +import de.steamwar.bungeecore.BungeeCore; +import de.steamwar.bungeecore.sql.BannedUserIPs; +import de.steamwar.bungeecore.sql.SteamwarUser; +import net.md_5.bungee.api.ProxyServer; +import net.md_5.bungee.api.chat.ClickEvent; +import net.md_5.bungee.api.chat.ComponentBuilder; +import net.md_5.bungee.api.chat.HoverEvent; +import net.md_5.bungee.api.chat.TextComponent; +import net.md_5.bungee.api.connection.ProxiedPlayer; +import net.md_5.bungee.api.event.LoginEvent; +import net.md_5.bungee.event.EventHandler; + +import java.util.List; + +public class BanListener extends BasicListener { + + @EventHandler + public void onLogin(LoginEvent event) { + SteamwarUser user = SteamwarUser.getOrCreate(event.getConnection()); + if(user.isBanned()) { + user.updateBanIP(event.getConnection().getAddress().getAddress().getHostAddress()); + event.setCancelled(true); + event.setCancelReason(user.banMessage()); + return; + } + + List ips = BannedUserIPs.get(event.getConnection().getAddress().getAddress().getHostAddress()); + if(!ips.isEmpty()){ + StringBuilder potentialBan = new StringBuilder(); + potentialBan.append(BungeeCore.CHAT_PREFIX); + potentialBan.append("§cMögliche Bannumgehung durch §r"); + potentialBan.append(user.getUserName()); + potentialBan.append("§c:"); + + for(BannedUserIPs banned : ips){ + SteamwarUser bannedUser = SteamwarUser.get(banned.getUserID()); + potentialBan.append(" §e"); + potentialBan.append(banned.getTimestamp().toLocalDateTime().format(BungeeCore.DATE_FORMAT)); + potentialBan.append(" §c"); + potentialBan.append(bannedUser.getUserName()); + } + + TextComponent msg = new TextComponent(potentialBan.toString()); + msg.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§cBanne Spieler wegen Bannumgehung").create())); + msg.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/ban " + user.getUserName() + " perma Bannumgehung")); + for (ProxiedPlayer target : ProxyServer.getInstance().getPlayers()){ + if ((target.hasPermission("bungeecore.teamchat")) + && (target.getChatMode() == ProxiedPlayer.ChatMode.COMMANDS_ONLY + || target.getChatMode() == ProxiedPlayer.ChatMode.SHOWN)){ + target.sendMessage(msg); + } + } + } + } +} diff --git a/src/de/steamwar/bungeecore/listeners/BasicListener.java b/src/de/steamwar/bungeecore/listeners/BasicListener.java new file mode 100644 index 0000000..457f1df --- /dev/null +++ b/src/de/steamwar/bungeecore/listeners/BasicListener.java @@ -0,0 +1,12 @@ +package de.steamwar.bungeecore.listeners; + +import de.steamwar.bungeecore.BungeeCore; +import net.md_5.bungee.api.ProxyServer; +import net.md_5.bungee.api.plugin.Listener; + +public abstract class BasicListener implements Listener { + + public BasicListener(){ + ProxyServer.getInstance().getPluginManager().registerListener(BungeeCore.get(), this); + } +} diff --git a/src/de/steamwar/bungeecore/listeners/ChatListener.java b/src/de/steamwar/bungeecore/listeners/ChatListener.java new file mode 100644 index 0000000..458cabb --- /dev/null +++ b/src/de/steamwar/bungeecore/listeners/ChatListener.java @@ -0,0 +1,153 @@ +package de.steamwar.bungeecore.listeners; + +import de.steamwar.bungeecore.BungeeCore; +import de.steamwar.bungeecore.Servertype; +import de.steamwar.bungeecore.Subserver; +import de.steamwar.bungeecore.commands.BauCommand; +import de.steamwar.bungeecore.sql.Team; +import de.steamwar.bungeecore.sql.SteamwarUser; +import net.md_5.bungee.api.ChatColor; +import net.md_5.bungee.api.ChatMessageType; +import net.md_5.bungee.api.ProxyServer; +import net.md_5.bungee.api.connection.ProxiedPlayer; +import net.md_5.bungee.api.event.ChatEvent; +import net.md_5.bungee.api.event.TabCompleteEvent; +import net.md_5.bungee.api.event.TabCompleteResponseEvent; +import net.md_5.bungee.event.EventHandler; + +import java.util.List; + +public class ChatListener extends BasicListener { + + @EventHandler + public void onChatEvent(ChatEvent e){ + if(e.getMessage().startsWith("/")) + onCommand(e); + else + onChat(e); + } + + private void onCommand(ChatEvent e){ + String [] command = e.getMessage().split(" "); + if(command[0].contains(":")){ + e.setCancelled(true); + if(e.getSender() instanceof ProxiedPlayer){ + ProxiedPlayer sender = (ProxiedPlayer) e.getSender(); + BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "§cUnbekannter Befehl."); + } + }else if((command[0].equalsIgnoreCase("/bau") || command[0].equalsIgnoreCase("/b")) && e.getSender() instanceof ProxiedPlayer){ + BauCommand.onBau(e, command); + }else if(command[0].equalsIgnoreCase("/bc") || command[0].equalsIgnoreCase("/bauchat") || command[0].equalsIgnoreCase("/local")){ + localChat(e, command); + } + } + + private void onChat(ChatEvent e){ + if(e.getSender() instanceof ProxiedPlayer){ + ProxiedPlayer sender = (ProxiedPlayer) e.getSender(); + if(sender.getChatMode() != ProxiedPlayer.ChatMode.SHOWN){ + BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "§cUm Chatnachrichten versenden zu können, musst du auch welche empfangen!"); + e.setCancelled(true); + return; + } + + SteamwarUser user = SteamwarUser.get(sender); + if(user.isMuted()){ + sender.sendMessage(user.muteMessage()); + e.setCancelled(true); + return; + } + + Subserver subserver = Subserver.getSubserver(sender); + if(subserver != null && subserver.getType() == Servertype.ARENA) + return; + + e.setCancelled(true); + publicChat(user, sender, e.getMessage()); + } + } + + private void publicChat(SteamwarUser user, ProxiedPlayer sender, String message){ + String name = sender.getDisplayName(); + String chatsuffix = "§7» "; + + if(sender.hasPermission("bungeecore.group.admin")){ + chatsuffix = "§7» §e"; + message = ChatColor.translateAlternateColorCodes('&', message); + }else if( + sender.hasPermission("bungeecore.group.developer") || + sender.hasPermission("bungeecore.group.moderator") || + sender.hasPermission("bungeecore.group.supporter") || + sender.hasPermission("bungeecore.group.builder")){ + chatsuffix = "§7» §r"; + message = ChatColor.translateAlternateColorCodes('&', message); + }else if(sender.hasPermission("bungeecore.group.youtuber")){ + message = ChatColor.translateAlternateColorCodes('&', message); + } + + String msg = name + chatsuffix + message; + if(user.getTeam() != 0){ + msg = "§8" + Team.get(user.getTeam()).getTeamKuerzel() + " §r" + msg; + } + for(ProxiedPlayer target : ProxyServer.getInstance().getPlayers()){ + Subserver targetServer = Subserver.getSubserver(target); + if(targetServer == null || targetServer.getType() != Servertype.ARENA){ + BungeeCore.send(target, ChatMessageType.CHAT, msg); + } + } + BungeeCore.log(sender.getServer().getInfo(), msg); + } + + private void localChat(ChatEvent e, String [] command){ + ProxiedPlayer sender = (ProxiedPlayer) e.getSender(); + BungeeCore.log(sender, e.getMessage()); + if(command.length == 1){ + BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "§8/§e" + command[0].substring(1) + " §8[§7Nachricht§8]"); + e.setCancelled(true); + return; + } + + SteamwarUser user = SteamwarUser.get(sender); + if(user.isMuted()){ + sender.sendMessage(user.muteMessage()); + e.setCancelled(true); + return; + } + + e.setMessage(e.getMessage().substring(command[0].length() + 1)); + } + + @EventHandler + public void onTabCompleteEvent(TabCompleteEvent e){ + List suggestions = e.getSuggestions(); + String [] cursor = e.getCursor().split(" "); + String last = cursor[cursor.length - 1]; + for(ProxiedPlayer player : ProxyServer.getInstance().getPlayers()){ + String name = player.getName(); + if(last.isEmpty() || name.startsWith(last)){ + suggestions.add(name); + } + } + if(e.getSender() instanceof ProxiedPlayer && cursor.length == 1 && cursor[0].startsWith("/")){ + ProxiedPlayer player = (ProxiedPlayer) e.getSender(); + for(String cmd : BungeeCore.commands.keySet()){ + if(cmd.startsWith(cursor[0]) && player.hasPermission(BungeeCore.commands.get(cmd))){ + suggestions.add(cmd); + } + } + } + } + + @EventHandler + public void onTabCompleteResponseEvent(TabCompleteResponseEvent e){ + List suggestions = e.getSuggestions(); + int i = 0; + while (i < suggestions.size()) { + String suggestion = suggestions.get(i); + if(suggestion.startsWith("/") && suggestion.contains(":")) + suggestions.remove(i); + else + i++; + } + } +} diff --git a/src/de/steamwar/bungeecore/listeners/ConnectionListener.java b/src/de/steamwar/bungeecore/listeners/ConnectionListener.java new file mode 100644 index 0000000..10c281d --- /dev/null +++ b/src/de/steamwar/bungeecore/listeners/ConnectionListener.java @@ -0,0 +1,132 @@ +package de.steamwar.bungeecore.listeners; + +import de.steamwar.bungeecore.BungeeCore; +import de.steamwar.bungeecore.Servertype; +import de.steamwar.bungeecore.Subserver; +import de.steamwar.bungeecore.commands.ChallengeCommand; +import de.steamwar.bungeecore.sql.SteamwarUser; +import net.md_5.bungee.api.AbstractReconnectHandler; +import net.md_5.bungee.api.ProxyServer; +import net.md_5.bungee.api.chat.ClickEvent; +import net.md_5.bungee.api.chat.ComponentBuilder; +import net.md_5.bungee.api.chat.HoverEvent; +import net.md_5.bungee.api.chat.TextComponent; +import net.md_5.bungee.api.config.ServerInfo; +import net.md_5.bungee.api.connection.ProxiedPlayer; +import net.md_5.bungee.api.event.PlayerDisconnectEvent; +import net.md_5.bungee.api.event.PostLoginEvent; +import net.md_5.bungee.api.event.ServerDisconnectEvent; +import net.md_5.bungee.api.event.ServerKickEvent; +import net.md_5.bungee.event.EventHandler; + +import java.util.Collection; +import java.util.Iterator; + +public class ConnectionListener extends BasicListener { + + private static final String ADMIN_GROUP = "admin"; + private static final String TEAM_GROUP = "team"; + + @EventHandler + public void onPostLogin(PostLoginEvent event) { + ProxiedPlayer player = event.getPlayer(); + SteamwarUser user = SteamwarUser.get(player.getUniqueId()); + player.removeGroups("Admin", "team"); + switch(user.getUserGroup()){ + case "Admin": + player.addGroups(ADMIN_GROUP, TEAM_GROUP); + player.setPermission("bungeecore.group.admin", true); + player.setDisplayName("§4Admin " + player.getName() + "§r"); + break; + case "Developer": + player.addGroups(ADMIN_GROUP, TEAM_GROUP); + player.setPermission("bungeecore.group.developer", true); + player.setDisplayName("§3Developer " + player.getName() + "§r"); + break; + case "Moderator": + player.addGroups(ADMIN_GROUP, TEAM_GROUP); + player.setPermission("bungeecore.group.moderator", true); + player.setDisplayName("§bModerator " + player.getName() + "§r"); + break; + case "Supporter": + player.addGroups(TEAM_GROUP); + player.setPermission("bungeecore.group.supporter", true); + player.setDisplayName("§1Supporter " + player.getName() + "§r"); + break; + case "Builder": + player.addGroups(TEAM_GROUP); + player.setPermission("bungeecore.group.builder", true); + player.setDisplayName("§2Architekt " + player.getName() + "§r"); + break; + case "Youtuber": + player.setPermission("bungeecore.group.youtuber", true); + player.setDisplayName("§5Youtuber " + player.getName() + "§r"); + break; + case "Member": + default: + player.setDisplayName(player.getName()); + break; + } + + for(Subserver subserver : Subserver.getServerList()){ + if(subserver.getType() == Servertype.ARENA){ + Iterator it = subserver.getServer().getPlayers().iterator(); + if(it.hasNext()){ + TextComponent tc = new TextComponent(BungeeCore.CHAT_PREFIX + "§7Klicke §ehier§7, um §e" + subserver.getServer().getName() + " §7beizutreten"); + tc.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§eArena beitreten").create())); + tc.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/join " + it.next().getName())); + player.sendMessage(tc); + } + } + } + + if(player.getPendingConnection().getVersion() < 335 || player.getPendingConnection().getVersion() > 340){ + player.sendMessage(BungeeCore.CHAT_PREFIX + "§cWir empfehlen die Minecraft-Version 1.12.2"); + } + } + + /** To redirect players to the lobby in case of server closure. */ + @EventHandler + public void onServerKickEvent(ServerKickEvent ev) + { + ServerInfo kickedFrom; + + if (ev.getPlayer().getServer() != null){ + kickedFrom = ev.getPlayer().getServer().getInfo(); + }else if (ProxyServer.getInstance().getReconnectHandler() != null){ + kickedFrom = ProxyServer.getInstance().getReconnectHandler().getServer(ev.getPlayer()); + }else{ + kickedFrom = AbstractReconnectHandler.getForcedHost(ev.getPlayer().getPendingConnection()); + if (kickedFrom == null){ + kickedFrom = ProxyServer.getInstance().getServerInfo(ev.getPlayer().getPendingConnection().getListener().getDefaultServer()); + } + } + + ServerInfo kickTo = ProxyServer.getInstance().getServerInfo(BungeeCore.LOBBY_SERVER); + + if (kickedFrom != null && kickedFrom.equals(kickTo)) { + return; + } + + ev.setCancelled(true); + ev.setCancelServer(kickTo); + } + + @EventHandler + public void onDisconnect(PlayerDisconnectEvent e){ + ChallengeCommand.remove(e.getPlayer()); + } + + @EventHandler + public void onServerDisconnect(ServerDisconnectEvent e){ + ServerInfo server = e.getTarget(); + Subserver subserver = Subserver.getSubserver(server); + if(subserver == null) + return; + + ProxiedPlayer player = e.getPlayer(); + Collection players = server.getPlayers(); + if(players.isEmpty() || (players.size() == 1 && players.contains(player))) + subserver.stop(); + } +} diff --git a/src/de/steamwar/bungeecore/listeners/PollSystem.java b/src/de/steamwar/bungeecore/listeners/PollSystem.java new file mode 100644 index 0000000..0cf5ce3 --- /dev/null +++ b/src/de/steamwar/bungeecore/listeners/PollSystem.java @@ -0,0 +1,62 @@ +package de.steamwar.bungeecore.listeners; + +import de.steamwar.bungeecore.BungeeCore; +import de.steamwar.bungeecore.sql.PollAnswer; +import de.steamwar.bungeecore.sql.SteamwarUser; +import net.md_5.bungee.api.chat.ClickEvent; +import net.md_5.bungee.api.connection.ProxiedPlayer; +import net.md_5.bungee.api.event.PostLoginEvent; +import net.md_5.bungee.event.EventHandler; + +import java.util.List; + +public class PollSystem extends BasicListener { + + private static String question; + private static List answers; + + public static void init(String question, List answers){ + PollSystem.question = question; + PollSystem.answers = answers; + + if(noCurrentPoll()) + return; + new PollSystem(); + } + + @EventHandler + public void onPostLogin(PostLoginEvent event){ + ProxiedPlayer player = event.getPlayer(); + SteamwarUser user = SteamwarUser.get(player.getUniqueId()); + + PollAnswer answer = PollAnswer.get(user.getId()); + if(answer.hasAnswered()) + return; + + sendPoll(player); + } + + public static void sendPoll(ProxiedPlayer player){ + BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§e§lUmfrage"); + BungeeCore.send(player, "§7Klicke die Antwort an, die dir gefällt!"); + BungeeCore.send(player, "§e" + question); + + for(int i = 0; i < answers.size(); i++){ + BungeeCore.send(player, "§7" + answers.get(i), + "§eDiese Antwort wählen", + new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/poll " + (i+1))); + } + } + + public static boolean noCurrentPoll(){ + return question != null && !question.equals(""); + } + + public static String getQuestion() { + return question; + } + + public static int answers(){ + return answers.size(); + } +} diff --git a/src/de/steamwar/bungeecore/listeners/mods/Forge.java b/src/de/steamwar/bungeecore/listeners/mods/Forge.java new file mode 100644 index 0000000..fb2098c --- /dev/null +++ b/src/de/steamwar/bungeecore/listeners/mods/Forge.java @@ -0,0 +1,388 @@ +package de.steamwar.bungeecore.listeners.mods; + +import de.steamwar.bungeecore.BungeeCore; +import de.steamwar.bungeecore.listeners.BasicListener; +import de.steamwar.bungeecore.sql.Mod; +import io.netty.buffer.ByteBuf; +import io.netty.buffer.UnpooledByteBufAllocator; +import javafx.util.Pair; +import net.md_5.bungee.api.connection.Connection; +import net.md_5.bungee.api.connection.ProxiedPlayer; +import net.md_5.bungee.api.event.PluginMessageEvent; +import net.md_5.bungee.api.event.PostLoginEvent; +import net.md_5.bungee.event.EventHandler; + +import java.nio.charset.StandardCharsets; +import java.util.Arrays; +import java.util.LinkedList; +import java.util.List; + +public class Forge extends BasicListener { + + private static final String FMLHS = "FML|HS"; + private static final byte[] REGISTER; + private static final byte[] HELLO = new byte[]{0, 2, 0, 0, 0, 0}; + //Packet 2, ein Mod, minecraft 1.12.2 + private static final byte[] MODS = new byte[]{2, 1, 9, 109, 105, 110, 101, 99, 114, 97, 102, 116, 6, 49, 46, 49, 50, 46, 50}; + private static final byte[] REGISTRY; + private static boolean enabled = false; + + public static void toggleEnabled(){ + enabled = !enabled; + } + + static{ + ByteBuf buf = UnpooledByteBufAllocator.DEFAULT.directBuffer(7); + buf.writeByte(6); + buf.writeCharSequence(FMLHS, StandardCharsets.UTF_8); + REGISTER = new byte[buf.readableBytes()]; + buf.readBytes(REGISTER); + buf.clear(); + + buf = UnpooledByteBufAllocator.DEFAULT.directBuffer(100); + buf.writeByte(3); // Packet 3 + buf.writeByte(0); // Boolean no following packet 3 + buf.writeByte(9); // Stringlength 9 (namespace minecraft) + buf.writeCharSequence("minecraft", StandardCharsets.UTF_8); + buf.writeByte(253); // VarInt 253, Missing: 36, 253, 254 + buf.writeByte(1); // VarInt +128 + registerId(buf, 0, "air"); + registerId(buf, 1, "stone"); + registerId(buf, 2, "grass"); + registerId(buf, 3, "dirt"); + registerId(buf, 4, "cobblestone"); + registerId(buf, 5, "planks"); + registerId(buf, 6, "sapling"); + registerId(buf, 7, "bedrock"); + registerId(buf, 8, "flowing_water"); + registerId(buf, 9, "water"); + registerId(buf, 10, "flowing_lava"); + registerId(buf, 11, "lava"); + registerId(buf, 12, "sand"); + registerId(buf, 13, "gravel"); + registerId(buf, 14, "gold_ore"); + registerId(buf, 15, "iron_ore"); + registerId(buf, 16, "coal_ore"); + registerId(buf, 17, "log"); + registerId(buf, 18, "leaves"); + registerId(buf, 19, "sponge"); + registerId(buf, 20, "glass"); + registerId(buf, 21, "lapis_ore"); + registerId(buf, 22, "lapis_block"); + registerId(buf, 23, "dispenser"); + registerId(buf, 24, "sandstone"); + registerId(buf, 25, "noteblock"); + registerId(buf, 26, "bed"); + registerId(buf, 27, "golden_rail"); + registerId(buf, 28, "detector_rail"); + registerId(buf, 29, "sticky_piston"); + registerId(buf, 30, "web"); + registerId(buf, 31, "tallgrass"); + registerId(buf, 32, "deadbush"); + registerId(buf, 33, "piston"); + registerId(buf, 34, "piston_head"); + registerId(buf, 35, "wool"); + registerId(buf, 37, "yellow_flower"); + registerId(buf, 38, "red_flower"); + registerId(buf, 39, "brown_mushroom"); + registerId(buf, 40, "red_mushroom"); + registerId(buf, 41, "gold_block"); + registerId(buf, 42, "iron_block"); + registerId(buf, 43, "double_stone_slab"); + registerId(buf, 44, "stone_slab"); + registerId(buf, 45, "brick_block"); + registerId(buf, 46, "tnt"); + registerId(buf, 47, "bookshelf"); + registerId(buf, 48, "mossy_cobblestone"); + registerId(buf, 49, "obsidian"); + registerId(buf, 50, "torch"); + registerId(buf, 51, "fire"); + registerId(buf, 52, "mob_spawner"); + registerId(buf, 53, "oak_stairs"); + registerId(buf, 54, "chest"); + registerId(buf, 55, "redstone_wire"); + registerId(buf, 56, "diamond_ore"); + registerId(buf, 57, "diamond_block"); + registerId(buf, 58, "crafting_table"); + registerId(buf, 59, "wheat"); + registerId(buf, 60, "farmland"); + registerId(buf, 61, "furnace"); + registerId(buf, 62, "lit_furnace"); + registerId(buf, 63, "standing_sign"); + registerId(buf, 64, "wooden_door"); + registerId(buf, 65, "ladder"); + registerId(buf, 66, "rail"); + registerId(buf, 67, "stone_stairs"); + registerId(buf, 68, "wall_sign"); + registerId(buf, 69, "lever"); + registerId(buf, 70, "stone_pressure_plate"); + registerId(buf, 71, "iron_door"); + registerId(buf, 72, "wooden_pressure_plate"); + registerId(buf, 73, "redstone_ore"); + registerId(buf, 74, "lit_redstone_ore"); + registerId(buf, 75, "unlit_redstone_torch"); + registerId(buf, 76, "redstone_torch"); + registerId(buf, 77, "stone_button"); + registerId(buf, 78, "snow_layer"); + registerId(buf, 79, "ice"); + registerId(buf, 80, "snow"); + registerId(buf, 81, "cactus"); + registerId(buf, 82, "clay"); + registerId(buf, 83, "reeds"); + registerId(buf, 84, "jukebox"); + registerId(buf, 85, "fence"); + registerId(buf, 86, "pumpkin"); + registerId(buf, 87, "netherrack"); + registerId(buf, 88, "soul_sand"); + registerId(buf, 89, "glowstone"); + registerId(buf, 90, "portal"); + registerId(buf, 91, "lit_pumpkin"); + registerId(buf, 92, "cake"); + registerId(buf, 93, "unpowered_repeater"); + registerId(buf, 94, "powered_repeater"); + registerId(buf, 95, "stained_glass"); + registerId(buf, 96, "trapdoor"); + registerId(buf, 97, "monster_egg"); + registerId(buf, 98, "stonebrick"); + registerId(buf, 99, "brown_mushroom_block"); + registerId(buf, 100, "red_mushroom_block"); + registerId(buf, 101, "iron_bars"); + registerId(buf, 102, "glass_pane"); + registerId(buf, 103, "melon_block"); + registerId(buf, 104, "pumpkin_stem"); + registerId(buf, 105, "melon_stem"); + registerId(buf, 106, "vine"); + registerId(buf, 107, "fence_gate"); + registerId(buf, 108, "brick_stairs"); + registerId(buf, 109, "stone_brick_stairs"); + registerId(buf, 110, "mycelium"); + registerId(buf, 111, "waterlily"); + registerId(buf, 112, "nether_brick"); + registerId(buf, 113, "nether_brick_fence"); + registerId(buf, 114, "nether_brick_stairs"); + registerId(buf, 115, "nether_wart"); + registerId(buf, 116, "enchanting_table"); + registerId(buf, 117, "brewing_stand"); + registerId(buf, 118, "cauldron"); + registerId(buf, 119, "end_portal"); + registerId(buf, 120, "end_portal_frame"); + registerId(buf, 121, "end_stone"); + registerId(buf, 122, "dragon_egg"); + registerId(buf, 123, "redstone_lamp"); + registerId(buf, 124, "lit_redstone_lamp"); + registerId(buf, 125, "double_wooden_slab"); + registerId(buf, 126, "wooden_slab"); + registerId(buf, 127, "cocoa"); + registerId(buf, 128, "sandstone_stairs"); + registerId(buf, 129, "emerald_ore"); + registerId(buf, 130, "ender_chest"); + registerId(buf, 131, "tripwire_hook"); + registerId(buf, 132, "tripwire"); + registerId(buf, 133, "emerald_block"); + registerId(buf, 134, "spruce_stairs"); + registerId(buf, 135, "birch_stairs"); + registerId(buf, 136, "jungle_stairs"); + registerId(buf, 137, "command_block"); + registerId(buf, 138, "beacon"); + registerId(buf, 139, "cobblestone_wall"); + registerId(buf, 140, "flower_pot"); + registerId(buf, 141, "carrots"); + registerId(buf, 142, "potatoes"); + registerId(buf, 143, "wooden_button"); + registerId(buf, 144, "skull"); + registerId(buf, 145, "anvil"); + registerId(buf, 146, "trapped_chest"); + registerId(buf, 147, "light_weighted_pressure_plate"); + registerId(buf, 148, "heavy_weighted_pressure_plate"); + registerId(buf, 149, "unpowered_comparator"); + registerId(buf, 150, "powered_comparator"); + registerId(buf, 151, "daylight_detector"); + registerId(buf, 152, "redstone_block"); + registerId(buf, 153, "quartz_ore"); + registerId(buf, 154, "hopper"); + registerId(buf, 155, "quartz_block"); + registerId(buf, 156, "quartz_stairs"); + registerId(buf, 157, "activator_rail"); + registerId(buf, 158, "dropper"); + registerId(buf, 159, "stained_hardened_clay"); + registerId(buf, 160, "stained_glass_pane"); + registerId(buf, 161, "leaves2"); + registerId(buf, 162, "log2"); + registerId(buf, 163, "acacia_stairs"); + registerId(buf, 164, "dark_oak_stairs"); + registerId(buf, 165, "slime"); + registerId(buf, 166, "barrier"); + registerId(buf, 167, "iron_trapdoor"); + registerId(buf, 168, "prismarine"); + registerId(buf, 169, "sea_lantern"); + registerId(buf, 170, "hay_block"); + registerId(buf, 171, "carpet"); + registerId(buf, 172, "hardened_clay"); + registerId(buf, 173, "coal_block"); + registerId(buf, 174, "packed_ice"); + registerId(buf, 175, "double_plant"); + registerId(buf, 176, "standing_banner"); + registerId(buf, 177, "wall_banner"); + registerId(buf, 178, "daylight_detector_inverted"); + registerId(buf, 179, "red_sandstone"); + registerId(buf, 180, "red_sandstone_stairs"); + registerId(buf, 181, "double_stone_slab2"); + registerId(buf, 182, "stone_slab2"); + registerId(buf, 183, "spruce_fence_gate"); + registerId(buf, 184, "birch_fence_gate"); + registerId(buf, 185, "jungle_fence_gate"); + registerId(buf, 186, "dark_oak_fence_gate"); + registerId(buf, 187, "acacia_fence_gate"); + registerId(buf, 188, "spruce_fence"); + registerId(buf, 189, "birch_fence"); + registerId(buf, 190, "jungle_fence"); + registerId(buf, 191, "dark_oak_fence"); + registerId(buf, 192, "acacia_fence"); + registerId(buf, 193, "spruce_door"); + registerId(buf, 194, "birch_door"); + registerId(buf, 195, "jungle_door"); + registerId(buf, 196, "acacia_door"); + registerId(buf, 197, "dark_oak_door"); + registerId(buf, 198, "end_rod"); + registerId(buf, 199, "chorus_plant"); + registerId(buf, 200, "chorus_flower"); + registerId(buf, 201, "purpur_block"); + registerId(buf, 202, "purpur_pillar"); + registerId(buf, 203, "purpur_stairs"); + registerId(buf, 204, "purpur_double_slab"); + registerId(buf, 205, "purpur_slab"); + registerId(buf, 206, "end_bricks"); + registerId(buf, 207, "beetroots"); + registerId(buf, 208, "grass_path"); + registerId(buf, 209, "end_gateway"); + registerId(buf, 210, "repeating_command_block"); + registerId(buf, 211, "chain_command_block"); + registerId(buf, 212, "frosted_ice"); + registerId(buf, 213, "magma"); + registerId(buf, 214, "nether_wart_block"); + registerId(buf, 215, "red_nether_brick"); + registerId(buf, 216, "bone_block"); + registerId(buf, 217, "structure_void"); + registerId(buf, 218, "observer"); + registerId(buf, 219, "white_shulker_box"); + registerId(buf, 220, "orange_shulker_box"); + registerId(buf, 221, "magenta_shulker_box"); + registerId(buf, 222, "light_blue_shulker_box"); + registerId(buf, 223, "yellow_shulker_box"); + registerId(buf, 224, "lime_shulker_box"); + registerId(buf, 225, "pink_shulker_box"); + registerId(buf, 226, "gray_shulker_box"); + registerId(buf, 227, "silver_shulker_box"); + registerId(buf, 228, "cyan_shulker_box"); + registerId(buf, 229, "purple_shulker_box"); + registerId(buf, 230, "blue_shulker_box"); + registerId(buf, 231, "brown_shulker_box"); + registerId(buf, 232, "green_shulker_box"); + registerId(buf, 233, "red_shulker_box"); + registerId(buf, 234, "black_shulker_box"); + registerId(buf, 235, "white_glazed_terracotta"); + registerId(buf, 236, "orange_glazed_terracotta"); + registerId(buf, 237, "magenta_glazed_terracotta"); + registerId(buf, 238, "light_blue_glazed_terracotta"); + registerId(buf, 239, "yellow_glazed_terracotta"); + registerId(buf, 240, "lime_glazed_terracotta"); + registerId(buf, 241, "pink_glazed_terracotta"); + registerId(buf, 242, "gray_glazed_terracotta"); + registerId(buf, 243, "light_gray_glazed_terracotta"); + registerId(buf, 244, "cyan_glazed_terracotta"); + registerId(buf, 245, "purple_glazed_terracotta"); + registerId(buf, 246, "blue_glazed_terracotta"); + registerId(buf, 247, "brown_glazed_terracotta"); + registerId(buf, 248, "green_glazed_terracotta"); + registerId(buf, 249, "red_glazed_terracotta"); + registerId(buf, 250, "black_glazed_terracotta"); + registerId(buf, 251, "concrete"); + registerId(buf, 252, "concrete_powder"); + registerId(buf, 255, "structure_block"); + buf.writeByte(0); // 0 Dummys + buf.writeByte(0); // 0 Subsitutions + REGISTRY = new byte[buf.readableBytes()]; + buf.readBytes(REGISTRY); + } + + @EventHandler + public void onPostLogin(PostLoginEvent event) { + ProxiedPlayer player = event.getPlayer(); + + if(!enabled) + return; + + if(player.getPendingConnection().getVersion() > 340) + player.sendData("minecraft:register", REGISTER); //1.13+ + else + player.sendData("REGISTER", REGISTER); //1.12- + + player.sendData(FMLHS, HELLO); + } + + @EventHandler + public void onPluginMessageEvent(PluginMessageEvent e){ + BungeeCore.log(e.getSender().getAddress().getHostString() + " " + e.getTag() + " " + Arrays.toString(e.getData())); + + if(!enabled) + return; + + if(!e.getTag().equals(FMLHS)) + return; + + e.setCancelled(true); + byte[] data = e.getData(); + + Connection sender = e.getSender(); + if(!(sender instanceof ProxiedPlayer)) + return; + ProxiedPlayer p = (ProxiedPlayer) sender; + + switch(data[0]){ + case 2: + Pair numMods = Utils.readVarInt(data, 1); + List mods = new LinkedList<>(); + + int bytePos = 1 + numMods.getKey(); + for(int i = 0; i < numMods.getValue(); i++){ + byte[] name = Arrays.copyOfRange(data, bytePos + 1, bytePos + data[bytePos] + 1); + bytePos += 1 + data[bytePos]; + byte[] version = Arrays.copyOfRange(data, bytePos + 1, bytePos + data[bytePos] + 1); + bytePos += 1 + data[bytePos]; + + mods.add(Mod.get(new String(name), Mod.Platform.FORGE)); + BungeeCore.log(new String(name) + " " + new String(version)); + } + + Utils.handleMods(p, mods); + p.sendData(FMLHS, MODS); + break; + case -1: + switch(data[1]){ + case 2: + p.sendData(FMLHS, REGISTRY); + break; + case 3: + p.sendData(FMLHS, new byte[]{-1, 2}); + break; + case 4: + p.sendData(FMLHS, new byte[]{-1, 3}); + break; + default: + break; + } + break; + case 1: + default: + break; + } + } + + private static void registerId(ByteBuf bb, int id, String name){ + bb.writeByte(name.length()); + bb.writeCharSequence(name, StandardCharsets.UTF_8); + bb.writeByte(id); + if(id > 127) + bb.writeByte(1); + } +} diff --git a/src/de/steamwar/bungeecore/listeners/mods/LabyMod.java b/src/de/steamwar/bungeecore/listeners/mods/LabyMod.java new file mode 100644 index 0000000..43f1224 --- /dev/null +++ b/src/de/steamwar/bungeecore/listeners/mods/LabyMod.java @@ -0,0 +1,153 @@ +package de.steamwar.bungeecore.listeners.mods; + +import com.google.gson.stream.JsonReader; +import de.steamwar.bungeecore.BungeeCore; +import de.steamwar.bungeecore.listeners.BasicListener; +import de.steamwar.bungeecore.sql.Mod; +import javafx.util.Pair; +import net.md_5.bungee.api.ProxyServer; +import net.md_5.bungee.api.connection.Connection; +import net.md_5.bungee.api.connection.ProxiedPlayer; +import net.md_5.bungee.api.event.PlayerDisconnectEvent; +import net.md_5.bungee.api.event.PluginMessageEvent; +import net.md_5.bungee.event.EventHandler; + +import java.io.IOException; +import java.io.StringReader; +import java.nio.charset.StandardCharsets; +import java.util.*; + +public class LabyMod extends BasicListener { + + private static Set labyModUsers = new HashSet<>(); + + @EventHandler + public void onPluginMessageEvent(PluginMessageEvent event){ + if(!event.getTag().equals("LMC")) + return; + + Connection sender = event.getSender(); + if(!(sender instanceof ProxiedPlayer)) + return; + + event.setCancelled(true); + labyModUsers.add((ProxiedPlayer) sender); + byte[] data = event.getData(); + + ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.get(), () -> runAsync(data, (ProxiedPlayer) sender)); + } + + private void runAsync(byte[] data, ProxiedPlayer player) { + Pair purpose = readString(data, 0); + if(!"INFO".equals(purpose.getValue())) + return; + + Pair value = readString(data, purpose.getKey()); + BungeeCore.log(value.getValue()); + List mods = new LinkedList<>(); + + try{ + InfoPacket info = new InfoPacket(value.getValue()); + for(InfoPacket.Addon addon : info.addons) { + mods.add(Mod.get(addon.name, Mod.Platform.LABYMOD)); + } + }catch(IOException e){ + BungeeCore.log("Could not read JSON", e); + } + + Utils.handleMods(player, mods); + //TODO CCP & SHADOW + } + + private Pair readString(byte[] array, int startPos){ + Pair varInt = Utils.readVarInt(array, startPos); + startPos += varInt.getKey(); + return new Pair<>(varInt.getValue()+varInt.getKey(), new String(Arrays.copyOfRange(array, startPos, startPos + varInt.getValue()), StandardCharsets.UTF_8)); + } + + private static class InfoPacket{ + String version = null; + Feature ccp = null; + Feature shadow = null; + List addons = new LinkedList<>(); + + InfoPacket(String input) throws IOException { + JsonReader reader = new JsonReader(new StringReader(input)); + reader.beginObject(); + while(reader.hasNext()){ + String name = reader.nextName(); + switch(name){ + case "version": + version = reader.nextString(); + break; + case "ccp": + ccp = new Feature(reader); + break; + case "shadow": + shadow = new Feature(reader); + break; + case "addons": + reader.beginArray(); + while(reader.hasNext()){ + addons.add(new Addon(reader)); + } + reader.endArray(); + break; + default: + reader.skipValue(); + } + } + reader.endObject(); + reader.close(); + } + + static class Addon{ + UUID uuid = null; + String name = null; + + Addon(JsonReader reader) throws IOException { + reader.beginObject(); + while(reader.hasNext()){ + String n = reader.nextName(); + if(n.equals("uuid")) + try{ + uuid = UUID.fromString(reader.nextString()); + }catch(IllegalArgumentException ignored){ + //ignored + } + else if(n.equals("name")) + name = reader.nextString(); + else + reader.skipValue(); + } + reader.endObject(); + } + } + + static class Feature{ + boolean enabled; + int version; + + Feature(JsonReader reader) throws IOException { + reader.beginObject(); + while(reader.hasNext()){ + String name = reader.nextName(); + if(name.equals("version")) + version = reader.nextInt(); + else if(name.equals("enabled")) + enabled = reader.nextBoolean(); + else + reader.skipValue(); + } + reader.endObject(); + } + } + } + + @EventHandler + public void onDisconnect(PlayerDisconnectEvent event){ + labyModUsers.remove(event.getPlayer()); + } + + //TODO: PlayerHandshakeEvent +} diff --git a/src/de/steamwar/bungeecore/listeners/mods/Utils.java b/src/de/steamwar/bungeecore/listeners/mods/Utils.java new file mode 100644 index 0000000..d68e276 --- /dev/null +++ b/src/de/steamwar/bungeecore/listeners/mods/Utils.java @@ -0,0 +1,66 @@ +package de.steamwar.bungeecore.listeners.mods; + +import de.steamwar.bungeecore.BungeeCore; +import de.steamwar.bungeecore.sql.Mod; +import de.steamwar.bungeecore.sql.Mod.ModType; +import de.steamwar.bungeecore.sql.SteamwarUser; +import javafx.util.Pair; +import net.md_5.bungee.api.connection.ProxiedPlayer; + +import java.sql.Timestamp; +import java.time.Instant; +import java.time.temporal.ChronoUnit; +import java.util.Iterator; +import java.util.List; + +class Utils { + private Utils(){} + + static Pair readVarInt(byte[] array, int startPos) { + int numRead = 0; + int result = 0; + byte read; + do { + read = array[startPos + numRead]; + int value = (read & 0b01111111); + result |= (value << (7 * numRead)); + + numRead++; + if (numRead > 5) { + break; + } + } while ((read & 0b10000000) != 0); + + return new Pair<>(numRead, result); + } + + static void handleMods(ProxiedPlayer player, List mods){ + ModType max = ModType.YELLOW; + Iterator it = mods.iterator(); + while(it.hasNext()){ + Mod mod = it.next(); + if(mod.getModType() == ModType.UNKLASSIFIED || mod.getModType() == ModType.GREEN) + it.remove(); + else if(mod.getModType() == ModType.RED) + max = ModType.RED; + } + + if(mods.isEmpty()) + return; + + if(mods.size() == 1){ + if(max == ModType.YELLOW) + player.disconnect(BungeeCore.stringToText("§7Deaktiviere den Mod §e" + mods.get(0).getModName() + "§7, um weiter auf §eSteam§8War §7spielen zu können.")); + else + SteamwarUser.get(player.getUniqueId()).ban(Timestamp.from(Instant.now().plus(1, ChronoUnit.DAYS)), "Versuchte Benutzung des Mods " + mods.get(0).getModName()); + }else{ + StringBuilder sb = new StringBuilder(); + mods.forEach(mod -> sb.append(mod.getModName()).append('\n')); + + if(max == ModType.YELLOW) + player.disconnect(BungeeCore.stringToText("§7Deaktiviere die Mods\n§e" + sb.toString() + "§7um weiter auf §eSteam§8War §7spielen zu können.")); + else + SteamwarUser.get(player.getUniqueId()).ban(Timestamp.from(Instant.now().plus(1, ChronoUnit.DAYS)), "Versuchte Benutzung der Mods\n" + sb.toString()); + } + } +} diff --git a/src/de/steamwar/bungeecore/sql/BannedUserIPs.java b/src/de/steamwar/bungeecore/sql/BannedUserIPs.java index a421970..1b6f36f 100644 --- a/src/de/steamwar/bungeecore/sql/BannedUserIPs.java +++ b/src/de/steamwar/bungeecore/sql/BannedUserIPs.java @@ -1,5 +1,7 @@ package de.steamwar.bungeecore.sql; +import de.steamwar.bungeecore.BungeeCore; + import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Timestamp; @@ -8,57 +10,58 @@ import java.util.List; public class BannedUserIPs { - private int UserID; - private Timestamp Timestamp; - private String IP; + private int userID; + private Timestamp timestamp; - private BannedUserIPs(int userID, Timestamp timestamp, String ip){ - UserID = userID; - Timestamp = timestamp; - IP = ip; + private BannedUserIPs(int userID, Timestamp timestamp){ + this.userID = userID; + this.timestamp = timestamp; } public static List get(int userID){ List userIPs = new ArrayList<>(); - ResultSet dbentry = sql.select("SELECT * FROM BannedUserIPs WHERE UserID = '" + userID + "' ORDER BY Timestamp ASC"); + ResultSet dbentry = SQL.select("SELECT * FROM BannedUserIPs WHERE UserID = '" + userID + "' ORDER BY Timestamp ASC"); try { while(dbentry.next()){ userIPs.add(new BannedUserIPs( userID, - dbentry.getTimestamp("Timestamp"), - dbentry.getString("IP"))); + dbentry.getTimestamp("Timestamp"))); } } catch (SQLException e) { - e.printStackTrace(); + BungeeCore.log("Get BannedUserIPs failed", e); } return userIPs; } public static List get(String ip){ List userIDs = new ArrayList<>(); - ResultSet dbentry = sql.select("SELECT * FROM BannedUserIPs WHERE IP = '" + ip + "' ORDER BY Timestamp DESC"); + ResultSet dbentry = SQL.select("SELECT * FROM BannedUserIPs WHERE IP = '" + ip + "' ORDER BY Timestamp DESC"); try { while(dbentry.next()){ userIDs.add(new BannedUserIPs( dbentry.getInt("UserID"), - dbentry.getTimestamp("Timestamp"), - ip)); + dbentry.getTimestamp("Timestamp"))); } } catch (SQLException e) { - e.printStackTrace(); + BungeeCore.log("Get BannedUserIPs failed", e); } return userIDs; } + static void banIP(SteamwarUser user, String ip){ + SQL.update("INSERT INTO BannedUserIPs\n" + + " (UserID, Timestamp, IP)\n" + + "VALUES\n" + + " (" + user.getId() + ", NOW(), '" + ip + "')\n" + + "ON DUPLICATE KEY UPDATE\n" + + " Timestamp=NOW()"); + } + public int getUserID() { - return UserID; + return userID; } public java.sql.Timestamp getTimestamp() { - return Timestamp; - } - - public String getIP() { - return IP; + return timestamp; } } diff --git a/src/de/steamwar/bungeecore/sql/Bauwelt.java b/src/de/steamwar/bungeecore/sql/Bauwelt.java index 13a6ad9..2e94607 100644 --- a/src/de/steamwar/bungeecore/sql/Bauwelt.java +++ b/src/de/steamwar/bungeecore/sql/Bauwelt.java @@ -1,20 +1,22 @@ package de.steamwar.bungeecore.sql; +import de.steamwar.bungeecore.BungeeCore; + import java.sql.ResultSet; import java.sql.SQLException; import java.util.UUID; public class Bauwelt { - private final int UserID; - private boolean TNTDmg; - private boolean FireDmg; + private final int userID; + private boolean tntDmg; + private boolean fireDmg; private Bauwelt(int userID, boolean tntDmg, boolean fireDmg, boolean updateDB){ - UserID = userID; - TNTDmg = tntDmg; - FireDmg = fireDmg; + this.userID = userID; + this.tntDmg = tntDmg; + this.fireDmg = fireDmg; if(updateDB) updateDB(); } @@ -24,24 +26,24 @@ public class Bauwelt { } public Bauwelt(UUID userID, boolean tntDmg, boolean fireDmg){ - this(WarkingUser.get(userID).getId(), tntDmg, fireDmg, true); + this(SteamwarUser.get(userID).getId(), tntDmg, fireDmg); } private void updateDB(){ - sql.update("INSERT INTO Bauwelt" + + SQL.update("INSERT INTO Bauwelt" + " (UserID, TNTDmg, FireDmg)" + " VALUES" + - " ('" + UserID + "', '" + sql.booleanToInt(TNTDmg) + "', '" + sql.booleanToInt(FireDmg) + "')" + + " ('" + userID + "', '" + SQL.booleanToInt(tntDmg) + "', '" + SQL.booleanToInt(fireDmg) + "')" + " ON DUPLICATE KEY UPDATE" + " TNTDmg = VALUES(TNTDmg), FireDmg = VALUES(FireDmg)"); } public static Bauwelt getBauwelt(UUID user){ - return getBauwelt(WarkingUser.get(user).getId()); + return getBauwelt(SteamwarUser.get(user).getId()); } public static Bauwelt getBauwelt(int userId){ - ResultSet bauwelt = sql.select("SELECT * FROM Bauwelt WHERE UserID = '" + userId + "'"); + ResultSet bauwelt = SQL.select("SELECT * FROM Bauwelt WHERE UserID = '" + userId + "'"); try { if(bauwelt == null || !bauwelt.next()){ return null; @@ -50,16 +52,16 @@ public class Bauwelt { boolean fireDmg = bauwelt.getBoolean("FireDmg"); return new Bauwelt(userId, tntDmg, fireDmg, false); } catch (SQLException e) { - e.printStackTrace(); + BungeeCore.log("Could not get Bauwelt", e); } return null; } public int getUserID() { - return UserID; + return userID; } public UUID getUUID(){ - return WarkingUser.get(UserID).getUUID(); + return SteamwarUser.get(userID).getUuid(); } } \ No newline at end of file diff --git a/src/de/steamwar/bungeecore/sql/BauweltMember.java b/src/de/steamwar/bungeecore/sql/BauweltMember.java index 523947a..6884477 100644 --- a/src/de/steamwar/bungeecore/sql/BauweltMember.java +++ b/src/de/steamwar/bungeecore/sql/BauweltMember.java @@ -1,5 +1,7 @@ package de.steamwar.bungeecore.sql; +import de.steamwar.bungeecore.BungeeCore; + import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; @@ -7,19 +9,19 @@ import java.util.List; import java.util.UUID; public class BauweltMember{ - private final int BauweltID; - private final int MemberID; - private boolean Build; - private boolean WorldEdit; - private boolean World; + private final int bauweltID; + private final int memberID; + private boolean build; + private boolean worldEdit; + private boolean world; private BauweltMember(int ownerID, int memberID, boolean build, boolean worldEdit, boolean world, boolean updateDB){ - BauweltID = ownerID; - MemberID = memberID; - Build = build; - WorldEdit = worldEdit; - World = world; + bauweltID = ownerID; + this.memberID = memberID; + this.build = build; + this.worldEdit = worldEdit; + this.world = world; if(updateDB) updateDB(); } @@ -29,28 +31,28 @@ public class BauweltMember{ } public BauweltMember(UUID ownerID, UUID memberID, boolean build, boolean worldEdit, boolean world){ - this(WarkingUser.get(ownerID).getId(), WarkingUser.get(memberID).getId(), build, worldEdit, world, true); + this(SteamwarUser.get(ownerID).getId(), SteamwarUser.get(memberID).getId(), build, worldEdit, world); } public void remove(){ - sql.update("DELETE FROM BauweltMember WHERE BauweltID = " + BauweltID + " AND MemberID = " + MemberID); + SQL.update("DELETE FROM BauweltMember WHERE BauweltID = " + bauweltID + " AND MemberID = " + memberID); } private void updateDB(){ - sql.update("INSERT INTO BauweltMember" + + SQL.update("INSERT INTO BauweltMember" + " (BauweltID, MemberID, Build, WorldEdit, World)" + " VALUES" + - " ('" + BauweltID + "', '" + MemberID + "', '" + sql.booleanToInt(Build) + "', '" + sql.booleanToInt(WorldEdit) + "', '" + sql.booleanToInt(World) + "')" + + " ('" + bauweltID + "', '" + memberID + "', '" + SQL.booleanToInt(build) + "', '" + SQL.booleanToInt(worldEdit) + "', '" + SQL.booleanToInt(world) + "')" + " ON DUPLICATE KEY UPDATE" + " Build = VALUES(Build), WorldEdit = VALUES(WorldEdit), World = VALUES(World)"); } public static BauweltMember getBauMember(UUID ownerID, UUID memberID){ - return getBauMember(WarkingUser.get(ownerID).getId(), WarkingUser.get(memberID).getId()); + return getBauMember(SteamwarUser.get(ownerID).getId(), SteamwarUser.get(memberID).getId()); } public static BauweltMember getBauMember(int ownerID, int memberID){ - ResultSet member = sql.select("SELECT * FROM BauweltMember WHERE BauweltID = '" + ownerID + "' AND MemberID = '" + memberID + "'"); + ResultSet member = SQL.select("SELECT * FROM BauweltMember WHERE BauweltID = '" + ownerID + "' AND MemberID = '" + memberID + "'"); try { if(member == null || !member.next()){ return null; @@ -60,18 +62,18 @@ public class BauweltMember{ boolean world = member.getBoolean("World"); return new BauweltMember(ownerID, memberID, build, worldEdit, world, false); } catch (SQLException e) { - e.printStackTrace(); + BungeeCore.log("Could not load BauweltMember", e); } return null; } public static List getMembers(UUID bauweltID){ - return getMembers(WarkingUser.get(bauweltID).getId()); + return getMembers(SteamwarUser.get(bauweltID).getId()); } public static List getMembers(int bauweltID){ try{ - ResultSet memberlist = sql.select("SELECT * FROM BauweltMember WHERE BauweltID = '" + bauweltID + "'"); + ResultSet memberlist = SQL.select("SELECT * FROM BauweltMember WHERE BauweltID = '" + bauweltID + "'"); List members = new ArrayList<>(); while(memberlist.next()){ int memberID = memberlist.getInt("MemberID"); @@ -82,43 +84,43 @@ public class BauweltMember{ } return members; }catch(SQLException e){ - e.printStackTrace(); + BungeeCore.log("Could not load BauweltMembers", e); } return new ArrayList<>(); } public int getBauweltID() { - return BauweltID; + return bauweltID; } public int getMemberID() { - return MemberID; + return memberID; } public boolean isBuild() { - return Build; + return build; } public void setBuild(boolean build) { - Build = build; + this.build = build; updateDB(); } public boolean isWorldEdit() { - return WorldEdit; + return worldEdit; } public void setWorldEdit(boolean worldEdit) { - WorldEdit = worldEdit; + this.worldEdit = worldEdit; updateDB(); } public boolean isWorld() { - return World; + return world; } public void setWorld(boolean world) { - World = world; + this.world = world; updateDB(); } } \ No newline at end of file diff --git a/src/de/steamwar/bungeecore/sql/Event.java b/src/de/steamwar/bungeecore/sql/Event.java new file mode 100644 index 0000000..4711507 --- /dev/null +++ b/src/de/steamwar/bungeecore/sql/Event.java @@ -0,0 +1,112 @@ +package de.steamwar.bungeecore.sql; + +import de.steamwar.bungeecore.BungeeCore; + +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Timestamp; +import java.time.Instant; +import java.util.LinkedList; +import java.util.List; + +public class Event { + + private final int eventID; + private final String eventName; + private final Timestamp start; + private final Timestamp end; + private final int maximumTeamMembers; + private final boolean publicSchemsOnly; + + private static Event current = null; + + private Event(int eventID, String eventName, Timestamp start, Timestamp end, int maximumTeamMembers, boolean publicSchemsOnly){ + this.eventID = eventID; + this.eventName = eventName; + this.start = start; + this.end = end; + this.maximumTeamMembers = maximumTeamMembers; + this.publicSchemsOnly = publicSchemsOnly; + } + + public static Event get(){ + if(current != null && current.now()) + return current; + + ResultSet rs = SQL.select("SELECT * FROM Event WHERE Start < now() AND End > now()"); + try{ + if(!rs.next()){ + current = null; + return null; + } + + current = new Event(rs.getInt("EventID"), rs.getString("EventName"), rs.getTimestamp("Start"), rs.getTimestamp("End"), rs.getInt("MaximumTeamMembers"), rs.getBoolean("PublicSchemsOnly")); + return current; + }catch (SQLException e){ + BungeeCore.log("Failed to load current Event", e); + throw new SecurityException(); + } + } + + public static Event get(int eventID){ + ResultSet rs = SQL.select("SELECT * FROM Event WHERE EventID = " + eventID); + try{ + if(!rs.next()) + throw new IllegalArgumentException(); + + return new Event(eventID, rs.getString("EventName"), rs.getTimestamp("Start"), rs.getTimestamp("End"), rs.getInt("MaximumTeamMembers"), rs.getBoolean("PublicSchemsOnly")); + }catch (SQLException e){ + BungeeCore.log("Failed to load Event", e); + throw new SecurityException(); + } + } + + public static Event get(String eventName){ + ResultSet rs = SQL.select("SELECT * FROM Event WHERE lower(EventName) = '" + SQL.disarmString(eventName.toLowerCase()) + "'"); + try{ + if(!rs.next()) + return null; + + return new Event(rs.getInt("EventID"), rs.getString("EventName"), rs.getTimestamp("Start"), rs.getTimestamp("End"), rs.getInt("MaximumTeamMembers"), rs.getBoolean("PublicSchemsOnly")); + }catch (SQLException e){ + BungeeCore.log("Failed to load Event by name", e); + throw new SecurityException(); + } + } + + public static List getComing(){ + List events = new LinkedList<>(); + ResultSet rs = SQL.select("SELECT * FROM Event WHERE Start > now()"); + try{ + while(rs.next()) + events.add(new Event(rs.getInt("EventID"), rs.getString("EventName"), rs.getTimestamp("Start"), rs.getTimestamp("End"), rs.getInt("MaximumTeamMembers"), rs.getBoolean("PublicSchemsOnly"))); + }catch (SQLException e){ + BungeeCore.log("Failed to load Events", e); + } + return events; + } + + private boolean now(){ + Instant now = Instant.now(); + return now.isAfter(start.toInstant()) && now.isBefore(end.toInstant()); + } + + public int getEventID() { + return eventID; + } + public String getEventName() { + return eventName; + } + public Timestamp getStart() { + return start; + } + public Timestamp getEnd() { + return end; + } + public int getMaximumTeamMembers() { + return maximumTeamMembers; + } + public boolean publicSchemsOnly() { + return publicSchemsOnly; + } +} diff --git a/src/de/steamwar/bungeecore/sql/EventFight.java b/src/de/steamwar/bungeecore/sql/EventFight.java new file mode 100644 index 0000000..e2f4b74 --- /dev/null +++ b/src/de/steamwar/bungeecore/sql/EventFight.java @@ -0,0 +1,137 @@ +package de.steamwar.bungeecore.sql; + +import de.steamwar.bungeecore.ArenaMode; +import de.steamwar.bungeecore.BungeeCore; + +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Timestamp; +import java.util.*; + +public class EventFight implements Comparable { + + private static Queue fights = new PriorityQueue<>(); + + private int eventID; + private int fightID; + private Timestamp startTime; + private ArenaMode spielmodus; + private String map; + private int teamBlue; + private int teamRed; + private int kampfleiter; + private int ergebnis; + + private EventFight(int eventID, int fightID, Timestamp startTime, ArenaMode spielmodus, String map, int teamBlue, int teamRed, int kampfleiter, int ergebnis){ + this.eventID = eventID; + this.fightID = fightID; + this.startTime = startTime; + this.spielmodus = spielmodus; + this.map = map; + this.teamBlue = teamBlue; + this.teamRed = teamRed; + this.kampfleiter = kampfleiter; + this.ergebnis = ergebnis; + } + + public static void loadAllComingFights(){ + ResultSet rs = SQL.select("SELECT * FROM EventFight WHERE StartTime > now()"); + fights.clear(); + try{ + while(rs.next()){ + fights.add(new EventFight( + rs.getInt("EventID"), + rs.getInt("FightID"), + rs.getTimestamp("StartTime"), + ArenaMode.valueOf(rs.getString("Spielmodus")), + rs.getString("Map"), + rs.getInt("TeamBlue"), + rs.getInt("TeamRed"), + rs.getInt("Kampfleiter"), + rs.getInt("Ergebnis"))); + } + }catch (SQLException e){ + BungeeCore.log("Failed to load EventFights", e); + } + } + + public static List getEvent(int eventID){ + ResultSet rs = SQL.select("SELECT * FROM EventFight WHERE EventID = " + eventID + " ORDER BY FightID ASC"); + List fights = new LinkedList<>(); + try{ + while(rs.next()) + fights.add(new EventFight( + eventID, + rs.getInt("FightID"), + rs.getTimestamp("StartTime"), + ArenaMode.valueOf(rs.getString("Spielmodus")), + rs.getString("Map"), + rs.getInt("TeamBlue"), + rs.getInt("TeamRed"), + rs.getInt("Kampfleiter"), + rs.getInt("Ergebnis"))); + }catch (SQLException e){ + BungeeCore.log("Failed to load EventFights", e); + } + return fights; + } + + public static Queue getFights() { + return fights; + } + + public Timestamp getStartTime() { + return startTime; + } + + public ArenaMode getSpielmodus() { + return spielmodus; + } + + public String getMap() { + return map; + } + + public int getTeamBlue() { + return teamBlue; + } + + public int getTeamRed() { + return teamRed; + } + + public int getEventID() { + return eventID; + } + + public int getFightID() { + return fightID; + } + + public int getKampfleiter() { + return kampfleiter; + } + + public int getErgebnis() { + return ergebnis; + } + + @Override + public int hashCode(){ + return fightID; + } + + @Override + public boolean equals(Object o){ + if(o == null) + return false; + if(!(o instanceof EventFight)) + return false; + return fightID == ((EventFight) o).fightID; + } + + @Override + public int compareTo(EventFight o) { + return startTime.compareTo(o.startTime); + } +} diff --git a/src/de/steamwar/bungeecore/sql/Mod.java b/src/de/steamwar/bungeecore/sql/Mod.java new file mode 100644 index 0000000..61e628d --- /dev/null +++ b/src/de/steamwar/bungeecore/sql/Mod.java @@ -0,0 +1,77 @@ +package de.steamwar.bungeecore.sql; + +import de.steamwar.bungeecore.BungeeCore; + +import java.sql.ResultSet; +import java.sql.SQLException; + +public class Mod { + private final String modName; + private final Platform platform; + private final ModType modType; + + private Mod(String modName, Platform platform, ModType modType) { + this.modName = modName; + this.platform = platform; + this.modType = modType; + } + + public static Mod get(String modName, Platform platform){ + modName = SQL.disarmString(modName); + ResultSet rs = SQL.select("SELECT * FROM Mods WHERE ModName = '" + modName + "' AND Platform = " + platform.value); + try{ + if(rs.next()) + return new Mod(modName, platform, ModType.valueOf(rs.getInt("ModType"))); + }catch (SQLException e){ + BungeeCore.log("Failed to load Mod", e); + throw new SecurityException(); + } + SQL.update("INSERT INTO Mods (ModName, Platform) VALUES ('" + modName + "'," + platform.value + ")"); + return new Mod(modName, platform, ModType.UNKLASSIFIED); + } + + public String getModName() { + return modName; + } + + public Platform getPlatform() { + return platform; + } + + public ModType getModType() { + return modType; + } + + public enum Platform{ + FORGE(0), + LABYMOD(1); + + Platform(int value){ + this.value = value; + } + int value; + public int get() { + return value; + } + } + + public enum ModType { + UNKLASSIFIED(0), + GREEN(1), + YELLOW(2), + RED(3); + + static ModType valueOf(int value){ + for(ModType mt : values()){ + if(value == mt.value) + return mt; + } + throw new EnumConstantNotPresentException(ModType.class, Integer.toString(value)); + } + + ModType(int value){ + this.value = value; + } + int value; + } +} diff --git a/src/de/steamwar/bungeecore/sql/Permission.java b/src/de/steamwar/bungeecore/sql/Permission.java deleted file mode 100644 index 0064e6c..0000000 --- a/src/de/steamwar/bungeecore/sql/Permission.java +++ /dev/null @@ -1,9 +0,0 @@ -package de.steamwar.bungeecore.sql; - -public enum Permission { - world, - worldedit, - build, - member, - owner -} diff --git a/src/de/steamwar/bungeecore/sql/PollAnswer.java b/src/de/steamwar/bungeecore/sql/PollAnswer.java new file mode 100644 index 0000000..56901a7 --- /dev/null +++ b/src/de/steamwar/bungeecore/sql/PollAnswer.java @@ -0,0 +1,44 @@ +package de.steamwar.bungeecore.sql; + +import de.steamwar.bungeecore.BungeeCore; +import de.steamwar.bungeecore.listeners.PollSystem; + +import java.sql.ResultSet; +import java.sql.SQLException; + +public class PollAnswer { + + private final int userID; + private final String question; + private int answer; + + private PollAnswer(ResultSet rs) throws SQLException { + this(rs.getInt("UserID"), rs.getString("Question")); + answer = rs.getInt("Answer"); + } + private PollAnswer(int userID, String question){ + this.userID = userID; + this.question = question; + } + + public static PollAnswer get(int userID){ + ResultSet rs = SQL.select("SELECT * FROM PollAnswer WHERE UserID = " + userID + " AND Question = '" + PollSystem.getQuestion() + "'"); + try { + if(!rs.next()) + return new PollAnswer(userID, PollSystem.getQuestion()); + return new PollAnswer(rs); + } catch (SQLException e) { + BungeeCore.log("Unable to get PollAnswer", e); + throw new SecurityException(); + } + } + + public boolean hasAnswered(){ + return answer == 0; + } + + public void setAnswer(int answer){ + this.answer = answer; + SQL.update("INSERT INTO PollAnswer (UserID, Question, Answer) VALUES (" + userID + ",'" + question + "'," + answer + ") ON DUPLICATE KEY UPDATE Answer = VALUES(Answer)"); + } +} diff --git a/src/de/steamwar/bungeecore/sql/SQL.java b/src/de/steamwar/bungeecore/sql/SQL.java new file mode 100644 index 0000000..c993e68 --- /dev/null +++ b/src/de/steamwar/bungeecore/sql/SQL.java @@ -0,0 +1,87 @@ +package de.steamwar.bungeecore.sql; + +import de.steamwar.bungeecore.BungeeCore; +import net.md_5.bungee.api.ProxyServer; + +import java.sql.*; + + +public class SQL { + private SQL(){} + + private static Connection con; + private static Connection webcon; + private static String url; + private static String weburl; + private static String user; + private static String password; + + public static void connect(String url, String weburl, String user, String password) { + SQL.url = url; + SQL.weburl = weburl; + SQL.user = user; + SQL.password = password; + try { + con = DriverManager.getConnection(url + "?autoreconnect=true", user, password); + webcon = DriverManager.getConnection(weburl + "?autoreconnect=true", user, password); + }catch (SQLException e) { + ProxyServer.getInstance().stop(); + throw new SecurityException("Could not start SQL-Exception", e); + } + } + + public static void close() { + try { + if(con != null) + con.close(); + if(webcon != null) + webcon.close(); + }catch (SQLException e) { + BungeeCore.log("Could not close SQL-Connection", e); + } + } + + private static void sqlException(){ + close(); + connect(url, weburl, user, password); + } + + static void update(String qry) { + try (PreparedStatement st = con.prepareStatement(qry)) { + st.executeUpdate(); + } catch (SQLException e) { + sqlException(); + try (PreparedStatement st = con.prepareStatement(qry)) { + st.executeUpdate(); + } catch (SQLException ex) { + BungeeCore.log("Could not execute update statement", ex); + } + } + } + + static ResultSet select(String qry){ + try{ + PreparedStatement st = con.prepareStatement(qry); + return st.executeQuery(); + } catch (SQLException e) { + sqlException(); + try { + PreparedStatement st = con.prepareStatement(qry); + return st.executeQuery(); + } catch (SQLException ex) { + throw new SecurityException("Could not run Select-Statement", ex); + } + } + } + + static String disarmString(String s){ + return s.replace("'", ""); + } + + static Integer booleanToInt(boolean b){ + if(b) + return 1; + else + return 0; + } +} diff --git a/src/de/steamwar/bungeecore/sql/SteamwarUser.java b/src/de/steamwar/bungeecore/sql/SteamwarUser.java new file mode 100644 index 0000000..5698d62 --- /dev/null +++ b/src/de/steamwar/bungeecore/sql/SteamwarUser.java @@ -0,0 +1,209 @@ +package de.steamwar.bungeecore.sql; + +import de.steamwar.bungeecore.BungeeCore; +import net.md_5.bungee.api.ProxyServer; +import net.md_5.bungee.api.chat.TextComponent; +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.HashMap; +import java.util.Map; +import java.util.UUID; + +public class SteamwarUser { + private final int id; + private final UUID uuid; + private String userName; + private String userGroup; + private Timestamp banTime; + private String banReason; + private int team; + private Timestamp muteTime; + private String muteReason; + + private static final Map usersByName = new HashMap<>(); + private static final Map usersByUUID = new HashMap<>(); + private static final Map usersById = new HashMap<>(); + private static final Timestamp PERMA_BAN = Timestamp.from(Instant.ofEpochSecond(946684800)); + private static final String SELECT_UUID = "SELECT * FROM UserData WHERE UUID = '"; + + private SteamwarUser(ResultSet rs) throws SQLException { + id = rs.getInt("id"); + uuid = UUID.fromString(rs.getString("UUID")); + userName = rs.getString("UserName"); + userGroup = rs.getString("UserGroup"); + banTime = rs.getTimestamp("BanTime"); + banReason = rs.getString("BanReason"); + team = rs.getInt("Team"); + muteTime = rs.getTimestamp("MuteTime"); + muteReason = rs.getString("MuteReason"); + usersById.put(id, this); + usersByName.put(userName.toLowerCase(), this); + usersByUUID.put(uuid, this); + } + + public static SteamwarUser getOrCreate(PendingConnection connection){ + SteamwarUser user = SteamwarUser.get(connection.getUniqueId()); + + if(user != null){ + String userName = SQL.disarmString(connection.getName()); + if(!user.userName.equals(userName)){ + SQL.update("UPDATE UserData SET UserName = '" + userName + "'"); + user.userName = userName; + } + }else{ + SQL.update("INSERT INTO UserData (UUID, UserName, UserGroup) VALUES ('" + connection.getUniqueId() + "', '" + connection.getName() + "', 'Member')"); + user = dbInit(SQL.select(SELECT_UUID + connection.getUniqueId().toString() + "'")); + if(user == null) + throw new SecurityException("user == null"); + } + + return user; + } + + public static SteamwarUser get(String userName){ + userName = SQL.disarmString(userName).toLowerCase(); + if(usersByName.containsKey(userName)) + return usersByName.get(userName); + return dbInit(SQL.select("SELECT * FROM UserData WHERE lower(UserName) = '" + userName + "'")); + } + + public static SteamwarUser get(UUID uuid){ + if(usersByUUID.containsKey(uuid)) + return usersByUUID.get(uuid); + return dbInit(SQL.select(SELECT_UUID + uuid.toString() + "'")); + } + + public static SteamwarUser get(ProxiedPlayer player){ + return get(player.getUniqueId()); + } + + public static SteamwarUser get(int id){ + if(usersById.containsKey(id)) + return usersById.get(id); + return dbInit(SQL.select("SELECT * FROM UserData WHERE id = " + id)); + } + + public static void clearCache(){ + usersById.clear(); + usersByName.clear(); + usersByUUID.clear(); + } + + public void setWebpw(String password){ + SQL.update("INSERT INTO User\n" + + " (UID, WebPassword)\n" + + "VALUES\n" + + " (" + id + ", password('"+ SQL.disarmString(password) + "'))\n" + + "ON DUPLICATE KEY UPDATE\n" + + " WebPassword = VALUES(WebPassword)"); + } + + public void setTeam(int team){ + this.team = team; + SQL.update("Update UserData SET Team = " + team + " WHERE id = " + id); + } + + public int getId() { + return id; + } + + public UUID getUuid() { + return uuid; + } + + public String getUserName() { + return userName; + } + + public String getUserGroup() { + return userGroup; + } + + public int getTeam(){ + return team; + } + + public boolean isBanned() { + if (banTime == null) { + return false; + } else if (banTime.after(new Date()) || banTime.before(PERMA_BAN)) { + return true; + } else { + SQL.update("UPDATE UserData SET BanTime = NULL, BanReason = '' WHERE id = " + id); + SQL.update("DELETE FROM BannedUserIPs WHERE UserID = '" + getId() + "'"); + banTime = null; + banReason = ""; + return false; + } + } + + public boolean isMuted(){ + if(muteTime == null){ + return false; + }else if(muteTime.after(new Date()) || muteTime.before(PERMA_BAN)){ + return true; + }else{ + SQL.update("UPDATE UserData SET MuteTime = NULL, MuteReason = '' WHERE id = " + id); + muteTime = null; + muteReason = ""; + return false; + } + } + + public TextComponent banMessage(){ + if (banTime.before(PERMA_BAN)) { + return BungeeCore.stringToText(BungeeCore.CHAT_PREFIX + "§cDu bist permanent gebannt. §r§lGrund§r: §c" + banReason); + } else { + return BungeeCore.stringToText(BungeeCore.CHAT_PREFIX + " Du bist bis zum " + + banTime.toLocalDateTime().format(BungeeCore.DATE_FORMAT) + " gebannt. §r§lGrund§r: §c" + banReason); + } + } + + public TextComponent muteMessage(){ + if (muteTime.before(PERMA_BAN)) { + return BungeeCore.stringToText(BungeeCore.CHAT_PREFIX + "§cDu bist permanent gemuted. §r§lGrund§r: §c" + muteReason); + } else { + return BungeeCore.stringToText(BungeeCore.CHAT_PREFIX + " Du bist bis zum " + + muteTime.toLocalDateTime().format(BungeeCore.DATE_FORMAT) + " gemuted. §r§lGrund§r: §c" + muteReason); + } + } + + public void updateBanIP(String ip){ + BannedUserIPs.banIP(this, ip); + } + + public void ban(Timestamp time, String banReason){ + SQL.update("UPDATE UserData SET BanTime = '" + time.toString() + "', BanReason = '" + banReason + "' WHERE id = " + id); + banTime = time; + this.banReason = banReason; + + ProxiedPlayer player = ProxyServer.getInstance().getPlayer(uuid); + if(player != null){ + updateBanIP(player.getAddress().getAddress().getHostAddress()); + player.disconnect(banMessage()); + }else + updateBanIP(""); + } + + public void mute(Timestamp time, String muteReason){ + SQL.update("UPDATE UserData SET MuteTime = '" + time.toString() + "', MuteReason = '" + muteReason + "' WHERE id = " + id); + muteTime = time; + this.muteReason = muteReason; + } + + private static SteamwarUser dbInit(ResultSet rs){ + try { + if(!rs.next()) + return null; + return new SteamwarUser(rs); + } catch (SQLException e) { + throw new SecurityException(e); + } + } +} diff --git a/src/de/steamwar/bungeecore/sql/Team.java b/src/de/steamwar/bungeecore/sql/Team.java index 608a94c..8a2a9ad 100644 --- a/src/de/steamwar/bungeecore/sql/Team.java +++ b/src/de/steamwar/bungeecore/sql/Team.java @@ -1,12 +1,14 @@ package de.steamwar.bungeecore.sql; +import de.steamwar.bungeecore.BungeeCore; + import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import java.util.LinkedList; import java.util.List; -import static de.steamwar.bungeecore.sql.sql.select; +import static de.steamwar.bungeecore.sql.SQL.select; public class Team { private final int teamId; @@ -24,7 +26,7 @@ public class Team { } public static void create(String kuerzel, String name, int leader){ - sql.update("INSERT INTO Team" + + SQL.update("INSERT INTO Team" + " (TeamKuerzel, TeamName, TeamLeader)" + " VALUES" + " ('" + kuerzel + "', '" + name + "', '" + leader + "')"); @@ -44,7 +46,7 @@ public class Team { for(Team team : teamCache) if(team.teamKuerzel.equalsIgnoreCase(name)) return team; - return load(select("SELECT * FROM Team WHERE lower(TeamName) = '" + sql.disarmString(name).toLowerCase() + "' OR lower(TeamKuerzel) = '" + sql.disarmString(name).toLowerCase() + "'")); + return load(select("SELECT * FROM Team WHERE lower(TeamName) = '" + SQL.disarmString(name).toLowerCase() + "' OR lower(TeamKuerzel) = '" + SQL.disarmString(name).toLowerCase() + "'")); } public static List getAll(){ @@ -59,7 +61,7 @@ public class Team { allTeams.add(load(rs)); } } catch (SQLException e) { - e.printStackTrace(); + BungeeCore.log("Could not get all Teams", e); } return allTeams; } @@ -81,13 +83,13 @@ public class Team { teamCache.add(team); return team; } catch (SQLException e) { - e.printStackTrace(); + BungeeCore.log("Could not load Team", e); return null; } } private void updateDB(){ - sql.update("INSERT INTO Team" + + SQL.update("INSERT INTO Team" + " (TeamID, TeamKuerzel, TeamName, TeamLeader)" + " VALUES" + " ('" + teamId + "', '" + teamKuerzel + "', '" + teamName + "', '" + teamLeader + "')" + @@ -104,7 +106,7 @@ public class Team { } public void setTeamKuerzel(String teamKuerzel) { - this.teamKuerzel = sql.disarmString(teamKuerzel); + this.teamKuerzel = SQL.disarmString(teamKuerzel); updateDB(); } @@ -113,7 +115,7 @@ public class Team { } public void setTeamName(String teamName) { - this.teamName = sql.disarmString(teamName); + this.teamName = SQL.disarmString(teamName); updateDB(); } @@ -132,13 +134,13 @@ public class Team { rs.next(); return rs.getInt("COUNT(id)"); }catch (SQLException e) { - e.printStackTrace(); + BungeeCore.log("Could not get Teamsize", e); return 1000; } } public void disband(){ - sql.update("DELETE FROM Team WHERE TeamID = " + teamId); + SQL.update("DELETE FROM Team WHERE TeamID = " + teamId); teamCache.remove(this); } @@ -151,7 +153,7 @@ public class Team { } return members; }catch(SQLException e){ - e.printStackTrace(); + BungeeCore.log("Could not get Teammembers", e); } return new ArrayList<>(); } diff --git a/src/de/steamwar/bungeecore/sql/TeamTeilnahme.java b/src/de/steamwar/bungeecore/sql/TeamTeilnahme.java new file mode 100644 index 0000000..9b1458f --- /dev/null +++ b/src/de/steamwar/bungeecore/sql/TeamTeilnahme.java @@ -0,0 +1,54 @@ +package de.steamwar.bungeecore.sql; + +import de.steamwar.bungeecore.BungeeCore; + +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.HashSet; +import java.util.Set; + +public class TeamTeilnahme { + private TeamTeilnahme(){} + + public static void teilnehmen(int teamID, int eventID){ + SQL.update("INSERT INTO TeamTeilnahme (TeamID, EventID) VALUES (" + teamID + "," + eventID + ")"); + } + + public static void notTeilnehmen(int teamID, int eventID){ + SQL.update("DELETE FROM TeamTeilnahme WHERE TeamID = " + teamID + " AND EventID = " + eventID); + } + + public static boolean nimmtTeil(int teamID, int eventID){ + ResultSet rs = SQL.select("SELECT * FROM TeamTeilnahme WHERE TeamID = " + teamID + " AND EventID = " + eventID); + try{ + return rs.next(); + }catch (SQLException e){ + BungeeCore.log("Failed to load TeamTeilnahme", e); + throw new SecurityException(); + } + } + + public static Set getTeams(int eventID){ + Set teams = new HashSet<>(); + ResultSet rs = SQL.select("SELECT * FROM TeamTeilnahme WHERE EventID = " + eventID); + try{ + while(rs.next()) + teams.add(Team.get(rs.getInt("TeamID"))); + }catch (SQLException e){ + BungeeCore.log("Failed to load TeamTeilnahmen", e); + } + return teams; + } + + public static Set getEvents(int teamID){ + Set events = new HashSet<>(); + ResultSet rs = SQL.select("SELECT * FROM TeamTeilnahme WHERE TeamID = " + teamID); + try{ + while(rs.next()) + events.add(Event.get(rs.getInt("EventID"))); + }catch (SQLException e){ + BungeeCore.log("Failed to load TeamTeilnahmen", e); + } + return events; + } +} diff --git a/src/de/steamwar/bungeecore/sql/WarkingUser.java b/src/de/steamwar/bungeecore/sql/WarkingUser.java deleted file mode 100644 index 28530a0..0000000 --- a/src/de/steamwar/bungeecore/sql/WarkingUser.java +++ /dev/null @@ -1,167 +0,0 @@ -package de.steamwar.bungeecore.sql; - -import net.md_5.bungee.api.connection.PendingConnection; - -import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.Timestamp; -import java.time.Instant; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; -import java.util.UUID; - -public class WarkingUser { - private int id; - private UUID UUID; - private String UserName; - private String UserGroup; - private Timestamp BanTime; - private String BanReason; - private int Team; - - private static final List allUsers = new ArrayList<>(); - public static Timestamp PermaBan = Timestamp.from(Instant.ofEpochSecond(946684800)); - - public WarkingUser(int id){ - init(sql.select("SELECT * FROM UserData WHERE id = " + id)); - } - - 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 lower(UserName) = '" + UserName.toLowerCase() + "'")); - } - - public WarkingUser(PendingConnection connection){ - ResultSet dbplayer = sql.select("SELECT * FROM UserData WHERE UUID = '" + connection.getUniqueId().toString() + "'"); - try { - if(dbplayer.next()){ - dbplayer.beforeFirst(); - init(dbplayer); - if(!dbplayer.getString("UserName").equals(connection.getName())){ - UserName = connection.getName(); - sql.update("UPDATE UserData SET UserName = '" + UserName + "' WHERE id = " + id); - } - }else{ - UUID = connection.getUniqueId(); - UserName = connection.getName(); - UserGroup = "Member"; - sql.update("INSERT INTO UserData (UUID, UserName, UserGroup) VALUES ('" + getUUID().toString() + "', '" + getUserName() + "', '" + getUserGroup() + "')"); - - dbplayer = sql.select("SELECT * FROM UserData WHERE UUID = '" + getUUID().toString() + "'"); - init(dbplayer); - } - } catch (SQLException e) { - e.printStackTrace(); - } - } - - public static WarkingUser get(String userName){ - userName = sql.disarmString(userName); - for(WarkingUser user : allUsers) - if(user.getUserName().equalsIgnoreCase(userName)) - return user; - return new WarkingUser(userName); - } - - public static WarkingUser get(UUID uuid){ - for(WarkingUser user : allUsers) - if(user.getUUID().equals(uuid)) - return user; - return new WarkingUser(uuid); - } - - public static WarkingUser get(int id){ - for(WarkingUser user : allUsers) - if(user.getId() == id) - return user; - return new WarkingUser(id); - } - - public static void clearCache(){ - allUsers.clear(); - } - - 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"); - Team = dbplayer.getInt("Team"); - allUsers.add(this); - } catch (SQLException e) { - e.printStackTrace(); - } - } - - public boolean isBanned(){ - if(getBanTime() == null){ - return false; - }else if(getBanTime().after(new Date()) || getBanTime().before(PermaBan)){ - return true; - }else{ - sql.update("UPDATE UserData SET BanTime = NULL, BanReason = '' WHERE UUID = '" + getUUID().toString() + "'"); - sql.update("DELETE FROM BannedUserIPs WHERE UserID = '" + getId() + "'"); - BanTime = null; - BanReason = ""; - return false; - } - } - - public void updateBanIP(String ip){ - sql.update("INSERT INTO BannedUserIPs\n" + - " (UserID, Timestamp, IP)\n" + - "VALUES\n" + - " (" + id + ", NOW(), '" + ip + "')\n" + - "ON DUPLICATE KEY UPDATE\n" + - " Timestamp=NOW()"); - } - - public void banPlayer(String ip, Timestamp time, String banReason){ - sql.update("UPDATE UserData SET BanTime = '" + time.toString() + "', BanReason = '" + banReason + "' WHERE id = " + id); - if(ip != null) - updateBanIP(ip); - } - - public int getId() { - return id; - } - - public UUID getUUID() { - return UUID; - } - - public String getUserName() { - return UserName; - } - - public String getUserGroup() { - return UserGroup; - } - - public Timestamp getBanTime() { - return BanTime; - } - - public String getBanReason() { - return BanReason; - } - - public int getTeam(){ - return Team; - } - - public void setTeam(int team){ - Team = team; - sql.update("Update UserData SET Team = " + team + " WHERE id = " + id); - } -} diff --git a/src/de/steamwar/bungeecore/sql/sql.java b/src/de/steamwar/bungeecore/sql/sql.java deleted file mode 100644 index 294c7df..0000000 --- a/src/de/steamwar/bungeecore/sql/sql.java +++ /dev/null @@ -1,117 +0,0 @@ -package de.steamwar.bungeecore.sql; - - import java.sql.Connection; - import java.sql.DriverManager; - import java.sql.PreparedStatement; - import java.sql.ResultSet; - import java.sql.SQLException; - - -public class sql { - private static Connection con; - private static Connection webcon; - private static String url; - private static String weburl; - private static String user; - private static String password; - - - public static void connect(String url, String weburl, String user, String password) { - sql.url = url; - sql.weburl = weburl; - sql.user = user; - sql.password = password; - try { - con = DriverManager.getConnection(url + "?autoreconnect=true", user, password); - webcon = DriverManager.getConnection(weburl + "?autoreconnect=true", user, password); - }catch (SQLException e) { - e.printStackTrace(); - } - } - - public static void close() { - try { - if(con != null) - con.close(); - if(webcon != null) - webcon.close(); - }catch (SQLException e) { - e.printStackTrace(); - } - } - - public static void update(String qry) { - try { - PreparedStatement st = con.prepareStatement(qry); - st.executeUpdate(); - } catch (SQLException e) { - close(); - connect(url, weburl, user, password); - try { - PreparedStatement st = con.prepareStatement(qry); - st.executeUpdate(); - } catch (SQLException ex) { - ex.printStackTrace(); - } - } - } - - public static ResultSet select(String qry){ - try { - PreparedStatement st = con.prepareStatement(qry); - return st.executeQuery(); - } catch (SQLException e) { - close(); - connect(url, weburl, user, password); - try { - PreparedStatement st = con.prepareStatement(qry); - return st.executeQuery(); - } catch (SQLException ex) { - ex.printStackTrace(); - } - } - - return null; - } - - public static String disarmString(String s){ - return s.replace("'", ""); - } - - public static Integer booleanToInt(boolean b){ - if(b) - return 1; - else - return 0; - } - - public static void setWebpw(WarkingUser user, String password){ - try { - PreparedStatement st = webcon.prepareStatement("INSERT INTO User\n" + - " (UID, WebPassword)\n" + - "VALUES\n" + - " (?, password(?))\n" + - "ON DUPLICATE KEY UPDATE\n" + - " WebPassword = VALUES(WebPassword)"); - st.setInt(1, user.getId()); - st.setString(2, password); - st.executeUpdate(); - } catch (SQLException e) { - close(); - connect(url, weburl, sql.user, sql.password); - try { - PreparedStatement st = webcon.prepareStatement("INSERT INTO User\n" + - " (UID, WebPassword)\n" + - "VALUES\n" + - " (?, password(?))\n" + - "ON DUPLICATE KEY UPDATE\n" + - " WebPassword = VALUES(WebPassword)"); - st.setInt(1, user.getId()); - st.setString(2, password); - st.executeUpdate(); - } catch (SQLException ex) { - ex.printStackTrace(); - } - } - } -}