Archiviert
1
0

Rework + Modsystem + Eventsystem

Dieser Commit ist enthalten in:
Lixfel 2019-09-06 06:33:06 +02:00
Ursprung 725d22834d
Commit 26d36c5ca2
52 geänderte Dateien mit 3110 neuen und 1843 gelöschten Zeilen

Datei anzeigen

@ -4,5 +4,6 @@ public enum ArenaMode {
AirShip, AirShip,
WarShip, WarShip,
WarGear, WarGear,
MiniWarGear MiniWarGear,
UNKNOWN
} }

Datei anzeigen

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

Datei anzeigen

@ -1,10 +1,22 @@
package de.steamwar.bungeecore; package de.steamwar.bungeecore;
import de.steamwar.bungeecore.commands.*; import de.steamwar.bungeecore.commands.*;
import de.steamwar.bungeecore.sql.WarkingUser; import de.steamwar.bungeecore.listeners.BanListener;
import de.steamwar.bungeecore.sql.sql; 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.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.api.plugin.Plugin;
import net.md_5.bungee.config.Configuration; import net.md_5.bungee.config.Configuration;
import net.md_5.bungee.config.ConfigurationProvider; 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.File;
import java.io.IOException; import java.io.IOException;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.EnumMap;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -21,131 +34,179 @@ import java.util.logging.Level;
public class BungeeCore extends Plugin { public class BungeeCore extends Plugin {
public static BungeeCore instance; public static final String SERVER_TEAMCHAT_PREFIX = "§8STC §e";
public static String ChatPrefix; public static final String TEAMCHAT_PREFIX = "§8TC §e";
public static String WorldFolder; public static final DateTimeFormatter DATE_FORMAT = DateTimeFormatter.ofPattern("dd.MM.yyyy");
public static String BauweltPrototyp;
public static final String ServerTeamchatPrefix = "§8STC §e"; public static String CHAT_PREFIX;
public static final String TeamchatPrefix = "§8TC §e"; public static String WORLD_FOLDER;
public static final DateTimeFormatter DateFormat = DateTimeFormatter.ofPattern("dd.MM.yyyy"); public static String BAUWELT_PROTOTYP;
public static String LobbyServer; public static String LOBBY_SERVER;
private static String [] BroadCastMsgs;
private static int LastBroadCast = 0; private static BungeeCore instance;
public static final Map<String, String> serverPermissions = new HashMap<>(); public static final Map<String, String> serverPermissions = new HashMap<>();
public static final Map<String, String> commands = new HashMap<>(); public static final Map<String, String> commands = new HashMap<>();
public static final Map<ArenaMode, List<String>> arenaMaps = new HashMap<>(); public static final Map<ArenaMode, List<String>> arenaMaps = new EnumMap<>(ArenaMode.class);
@Override @Override
public void onEnable(){ 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; Configuration config;
try{ try{
if(!getDataFolder().exists()){ if(!get().getDataFolder().exists() && !get().getDataFolder().mkdir())
getDataFolder().mkdir(); throw new IOException();
} File configFile = new File(get().getDataFolder().getPath(), "config.yml");
File configFile = new File(getDataFolder().getPath(), "config.yml");
if(!configFile.exists()){ if(!configFile.exists()){
configFile.createNewFile(); boolean created = configFile.createNewFile();
config = ConfigurationProvider.getProvider(YamlConfiguration.class).load(configFile); if(created)
config.set("prefix", "SteamWar» "); ProxyServer.getInstance().stop("Config file not initialized");
config.set("lobbyserver", "Lobby"); else
config.set("db.url", "jdbc:mysql://127.0.0.1:3306/core"); ProxyServer.getInstance().stop("Could not save conig file");
config.set("db.weburl", "jdbc:mysql://127.0.0.1:3306/Website"); return;
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);
} }
config = ConfigurationProvider.getProvider(YamlConfiguration.class).load(configFile); config = ConfigurationProvider.getProvider(YamlConfiguration.class).load(configFile);
}catch(IOException e){ }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; return;
} }
ChatPrefix = config.getString("prefix"); CHAT_PREFIX = config.getString("prefix");
WorldFolder = config.getString("worldfolder"); WORLD_FOLDER = config.getString("worldfolder");
BauweltPrototyp = config.getString("bauweltprototyp"); BAUWELT_PROTOTYP = config.getString("bauweltprototyp");
LobbyServer = config.getString("lobbyserver"); LOBBY_SERVER = config.getString("lobbyserver");
sql.connect( 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.url"),
config.getString("db.weburl"), config.getString("db.weburl"),
config.getString("db.username"), config.getString("db.username"),
config.getString("db.password") 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<String> 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"); final Configuration maps = config.getSection("maps");
for(final String modeName : maps.getKeys()){ for(final String modeName : maps.getKeys()){
arenaMaps.put(ArenaMode.valueOf(modeName), maps.getStringList(modeName)); arenaMaps.put(ArenaMode.valueOf(modeName), maps.getStringList(modeName));
} }
addCmd(new TeamchatCommand()); final Configuration servers = config.getSection("servers");
addCmd(new MsgCommand()); for(final String serverName : servers.getKeys()){
addCmd(new RCommand()); final Configuration server = servers.getSection(serverName);
addCmd(new PingCommand()); List<String> cmds = server.getStringList("commands");
addCmd(new WebpwCommand()); serverPermissions.put(serverName, "bungeecore.server." + server.getString("permission"));
addCmd(new AlertCommand()); String cmd = cmds.remove(0);
addCmd(new KickCommand()); new ServerSwitchCommand(
addCmd(new JoinmeCommand()); cmd,
addCmd(new FightCommand()); serverName,
addCmd(new HelpCommand()); serverPermissions.get(serverName),
addCmd(new BanCommand()); cmds.toArray(new String[0])
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);
} }
@Override private static void setInstance(BungeeCore core){
public void onDisable(){ instance = core;
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);
} }
} }

Datei anzeigen

@ -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<Team, Subserver> 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<Team, Subserver> getEventServer() {
return eventServer;
}
@Override
public void run() {
eventServer.entrySet().removeIf(entry -> !Subserver.getServerList().contains(entry.getValue()));
Queue<EventFight> 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<EventFight> fights){
EventFight next = fights.peek();
if(next == null)
return null;
if(!next.getStartTime().before(new Timestamp(System.currentTimeMillis())))
return null;
return fights.poll();
}
}

Datei anzeigen

@ -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<Integer, String> purpose = readString(data, 0);
Pair<Integer, String> 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<Integer, Integer> 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<Integer, Integer> 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<Integer, String> readString(byte[] array, int startPos){
Pair<Integer, Integer> 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));
}
}

Datei anzeigen

@ -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<BannedUserIPs> 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<ProxiedPlayer> 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<String> 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<String> 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--;
}
}
}
}

Datei anzeigen

@ -1,12 +1,10 @@
package de.steamwar.bungeecore; package de.steamwar.bungeecore;
import de.steamwar.bungeecore.sql.Bauwelt; 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.ProxyServer;
import net.md_5.bungee.api.chat.ClickEvent; 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.connection.ProxiedPlayer;
import java.io.File; import java.io.File;
@ -16,23 +14,30 @@ import java.util.UUID;
public class SubserverSystem { public class SubserverSystem {
private SubserverSystem(){} private SubserverSystem(){}
private static final String MC_SCRIPT = "/home/minecraft/mc";
public static void sendDeniedMessage(ProxiedPlayer p, UUID owner){ public static void sendDeniedMessage(ProxiedPlayer p, UUID owner){
ProxiedPlayer o = ProxyServer.getInstance().getPlayer(owner); ProxiedPlayer o = ProxyServer.getInstance().getPlayer(owner);
if(o == null) if(o == null)
return; return;
o.sendMessage(BungeeCore.ChatPrefix + "§e" + p.getName() + " §7möchte auf deine Bauwelt."); BungeeCore.send(o, BungeeCore.CHAT_PREFIX + "§e" + p.getName() + " §7möchte auf deine Bauwelt.");
TextComponent tc = new TextComponent("§7Klicke §ehier§7, wenn du das erlauben möchtest."); BungeeCore.send(o, "§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())); "§e/bau addmember " + p.getName(),
tc.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/bau addmember " + p.getName())); new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/bau addmember " + p.getName()));
o.sendMessage(tc);
} }
public static Subserver startArena(ArenaMode modus, String map){ public static Subserver startArena(ArenaMode modus, String map){
int port = freePort(2500); int port = freePort(2500);
String serverName = modus.name() + (port - 2500); String serverName = modus.name() + (port - 2500);
return new Subserver(Servertype.ARENA, serverName, port, 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){ 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()){ if (!w.exists() || !w.isDirectory()){
try { try {
Process pr; Process pr;
ProcessBuilder pb = new ProcessBuilder( ProcessBuilder pb = new ProcessBuilder(
"cp", "-r", BungeeCore.BauweltPrototyp, BungeeCore.WorldFolder + owner); "cp", "-r", BungeeCore.BAUWELT_PROTOTYP, BungeeCore.WORLD_FOLDER + owner);
pr = pb.start(); pr = pb.start();
pr.waitFor(); pr.waitFor();
} catch (InterruptedException | IOException e) { } catch (IOException e) {
e.printStackTrace(); BungeeCore.log("Could not create Bauwelt", e);
p.sendMessage(BungeeCore.ChatPrefix + "§cDas Erstellen der Welt ist fehlgeschlagen."); BungeeCore.send(p, BungeeCore.CHAT_PREFIX + "§cDas Erstellen der Welt ist fehlgeschlagen.");
return; 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) if(Bauwelt.getBauwelt(owner) == null)
new Bauwelt(owner, false, false); new Bauwelt(owner, false, false);
} }
WarkingUser user = WarkingUser.get(owner); SteamwarUser user = SteamwarUser.get(owner);
int port = freePort(4000); int port = freePort(4000);
new Bauserver(user.getUserName() + "s Bau", owner, port, 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){ private static int freePort(int start){

Datei anzeigen

@ -3,9 +3,8 @@ package de.steamwar.bungeecore.commands;
import de.steamwar.bungeecore.BungeeCore; import de.steamwar.bungeecore.BungeeCore;
import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.CommandSender; 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() { public AlertCommand() {
super("alert", "bungeecore.alert", "broadcast", "bbc"); super("alert", "bungeecore.alert", "broadcast", "bbc");
@ -14,17 +13,17 @@ public class AlertCommand extends Command {
@Override @Override
public void execute(CommandSender sender, String[] args) { public void execute(CommandSender sender, String[] args) {
if(args.length == 0){ if(args.length == 0){
sender.sendMessage(BungeeCore.ChatPrefix + "/alert [Nachricht]"); BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "/alert [Nachricht]");
return; return;
} }
StringBuilder msgBuilder = new StringBuilder(); StringBuilder msgBuilder = new StringBuilder();
msgBuilder.append(BungeeCore.ChatPrefix); msgBuilder.append(BungeeCore.CHAT_PREFIX);
for (String arg : args){ for (String arg : args){
msgBuilder.append(arg).append(" "); msgBuilder.append(arg).append(" ");
} }
String msg = msgBuilder.toString(); String msg = msgBuilder.toString();
msg = ChatColor.translateAlternateColorCodes('&', msg); msg = ChatColor.translateAlternateColorCodes('&', msg);
ProxyServer.getInstance().broadcast(msg); BungeeCore.broadcast(msg);
} }
} }

Datei anzeigen

@ -1,16 +1,16 @@
package de.steamwar.bungeecore.commands; package de.steamwar.bungeecore.commands;
import de.steamwar.bungeecore.BungeeCore; import de.steamwar.bungeecore.BungeeCore;
import de.steamwar.bungeecore.sql.WarkingUser; import de.steamwar.bungeecore.sql.SteamwarUser;
import net.md_5.bungee.api.*; import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.text.ParseException; import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.time.Instant; import java.time.Instant;
import java.util.*; import java.util.Date;
public class BanCommand extends Command { public class BanCommand extends BasicCommand {
public BanCommand() { public BanCommand() {
super("ban", "bungeecore.ban"); super("ban", "bungeecore.ban");
@ -19,49 +19,39 @@ public class BanCommand extends Command {
@Override @Override
public void execute(CommandSender sender, String[] args) { public void execute(CommandSender sender, String[] args) {
if(args.length < 3){ 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; return;
} }
WarkingUser target = WarkingUser.get(args[0]); SteamwarUser target = user(sender, args[0]);
if(target.getUserName() == null){ if(target == null)
sender.sendMessage(BungeeCore.ChatPrefix + "§cDer Spieler existiert nicht.");
return; return;
}
StringBuilder msgBuilder = new StringBuilder(); Timestamp banTime = parseTime(sender, args[1]);
msgBuilder.append(BungeeCore.ChatPrefix); if(banTime == null)
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; return;
}
}
StringBuilder banReason = new StringBuilder(); StringBuilder banReason = new StringBuilder();
for (int i = 2; i < args.length; i++){ for (int i = 2; i < args.length; i++){
banReason.append(args[i]).append(" "); banReason.append(args[i]).append(" ");
} }
String msg = banReason.toString(); String msg = banReason.toString();
msgBuilder.append(msg); BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "Du hast " + target.getUserName() + " gebannt. Grund: §c" + msg);
sender.sendMessage(BungeeCore.ChatPrefix + "Du hast " + target.getUserName() + " gebannt. Grund: §c" + msg); target.ban(banTime, msg);
ProxiedPlayer targetPlayer = ProxyServer.getInstance().getPlayer(target.getUUID()); }
if(targetPlayer != null){
target.banPlayer(targetPlayer.getAddress().getAddress().getHostAddress(), banTime, msg); public static Timestamp parseTime(CommandSender sender, String arg){
targetPlayer.disconnect(msgBuilder.toString()); if(arg.equalsIgnoreCase("perma")) {
return Timestamp.from(Instant.ofEpochSecond(946674800));
}else{ }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;
}
} }
} }
} }

Datei anzeigen

@ -1,22 +1,25 @@
package de.steamwar.bungeecore.commands; package de.steamwar.bungeecore.commands;
import de.steamwar.bungeecore.BungeeCore; import de.steamwar.bungeecore.BungeeCore;
import de.steamwar.bungeecore.sql.SteamwarUser;
import net.md_5.bungee.api.CommandSender; import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.connection.ProxiedPlayer; 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 net.md_5.bungee.api.plugin.TabExecutor;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; 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); super(name, permission, aliases);
BungeeCore.commands.put("/" + name, permission); BungeeCore.commands.put("/" + name, permission);
ProxyServer.getInstance().getPluginManager().registerCommand(BungeeCore.get(), this);
} }
public Iterable<String> allPlayers(String begin) { Iterable<String> allPlayers(String begin) {
List<String> suggestions = new ArrayList<>(); List<String> suggestions = new ArrayList<>();
for(ProxiedPlayer player : ProxyServer.getInstance().getPlayers()){ for(ProxiedPlayer player : ProxyServer.getInstance().getPlayers()){
String playerName = player.getName(); String playerName = player.getName();
@ -29,4 +32,11 @@ public abstract class Command extends net.md_5.bungee.api.plugin.Command impleme
public Iterable<String> onTabComplete(CommandSender commandSender, String[] args) { public Iterable<String> onTabComplete(CommandSender commandSender, String[] args) {
return new ArrayList<>(); 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;
}
} }

Datei anzeigen

@ -3,244 +3,246 @@ package de.steamwar.bungeecore.commands;
import de.steamwar.bungeecore.*; import de.steamwar.bungeecore.*;
import de.steamwar.bungeecore.sql.Bauwelt; import de.steamwar.bungeecore.sql.Bauwelt;
import de.steamwar.bungeecore.sql.BauweltMember; import de.steamwar.bungeecore.sql.BauweltMember;
import de.steamwar.bungeecore.sql.Permission; import de.steamwar.bungeecore.sql.SteamwarUser;
import de.steamwar.bungeecore.sql.WarkingUser;
import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.event.ChatEvent; import net.md_5.bungee.api.event.ChatEvent;
import java.io.File; import java.io.File;
import java.util.UUID;
public class BauCommand { public class BauCommand {
private BauCommand(){} private BauCommand(){}
private static final String UNKNOWN_PLAYER = BungeeCore.CHAT_PREFIX + "§cUnbekannter Spieler";
public static void onBau(ChatEvent e, String[] command){ public static void onBau(ChatEvent e, String[] command){
ProxiedPlayer p = (ProxiedPlayer) e.getSender(); ProxiedPlayer p = (ProxiedPlayer) e.getSender();
Subserver server = Subserver.getSubserver(p); 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()); boolean ownBau = bau != null && bau.getOwner().equals(p.getUniqueId());
e.setCancelled(true); e.setCancelled(true);
BungeeCore.send(p, e.getMessage());
if(command.length == 1){ if(command.length == 1){
SubserverSystem.sendToBauServer(p, p.getUniqueId()); 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 <Spieler>");
return; return;
} }
UUID id = WarkingUser.get(command[2]).getUUID(); switch(command[1].toLowerCase()){
if (id == null) { case "addmember":
p.sendMessage(BungeeCore.ChatPrefix + "§cUnbekannter Spieler"); addmember(p, command);
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 <Spieler>");
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 <Spieler>");
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 <Spieler>");
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 <Spieler>");
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 <Spieler>");
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; break;
} case "tp":
} case "teleport":
File directory = new File(BungeeCore.WorldFolder + p.getUniqueId().toString()); teleport(p, command);
del(directory); break;
}); case "togglebuild":
}else{ 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); 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 <Spieler>");
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 <Spieler>");
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()); target.setBuild(!target.isBuild());
ProxiedPlayer z = ProxyServer.getInstance().getPlayer(WarkingUser.get(target.getMemberID()).getUUID()); isAllowedTo(target.isBuild(), p, target, "bauen");
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");
}
} }
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()); target.setWorldEdit(!target.isWorldEdit());
ProxiedPlayer z = ProxyServer.getInstance().getPlayer(WarkingUser.get(target.getMemberID()).getUUID()); isAllowedTo(target.isWorldEdit(), p, target, "WorldEdit verwenden");
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");
}
} }
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()); target.setWorld(!target.isWorld());
ProxiedPlayer z = ProxyServer.getInstance().getPlayer(WarkingUser.get(target.getMemberID()).getUUID()); isAllowedTo(target.isWorld(), p, target, "Einstellungen vornehmen");
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");
}
} }
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 <Spieler>");
return;
}
BauweltMember target = member(p, SteamwarUser.get(command[2]));
if(target == null)
return;
target.remove(); 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){ 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); Subserver server = Subserver.getSubserver(z);
if(server != null && server.getType() == Servertype.BAUSERVER && ((Bauserver)server).getOwner().equals(p.getUniqueId())) 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){ private static void delete(ProxiedPlayer p){
if (id == null) { BungeeCore.send(p, BungeeCore.CHAT_PREFIX + "§aDeine Welt wird zurückgesetzt.");
p.sendMessage(BungeeCore.ChatPrefix + "§cUnbekannter Spieler"); ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.get(), () -> {
return false; 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);
});
} }
BauweltMember target = BauweltMember.getBauMember(p.getUniqueId(), id); private static void testarena(ProxiedPlayer p, String[] command){
if (command.length == 2) {
BungeeCore.send(p, BungeeCore.CHAT_PREFIX + "/bau testarena <Spielmodus>");
return;
}
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) { if (target == null) {
p.sendMessage(BungeeCore.ChatPrefix + "§cDer Spieler ist kein Mitglied deiner Welt!"); BungeeCore.send(p, BungeeCore.CHAT_PREFIX + "§cDer Spieler ist kein Mitglied deiner Welt!");
return false; return null;
} }
return true; return target;
} }
public static boolean hasPermission(UUID welt, ProxiedPlayer member, Permission perm){ private static BauweltMember toggle(ProxiedPlayer p, String[] command, String subcommand){
if(member.getUniqueId().equals(welt)) if (command.length == 2) {
return true; BungeeCore.send(p, BungeeCore.CHAT_PREFIX + "/bau " + subcommand + " <Spieler>");
return null;
}
BauweltMember member1 = BauweltMember.getBauMember(welt, member.getUniqueId()); SteamwarUser member = SteamwarUser.get(command[2]);
if(member1 == null) return member(p, member);
return false; }
switch(perm){ private static void isAllowedTo(boolean permission, ProxiedPlayer p, BauweltMember target, String what){
case build: ProxiedPlayer player = ProxyServer.getInstance().getPlayer(SteamwarUser.get(target.getMemberID()).getUuid());
return member1.isBuild();
case worldedit: if(permission){
return member1.isWorldEdit(); if(player != null)
case world: BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§aDu kannst nun auf der Welt von §e" + player.getName() + "§a " + what);
return member1.isWorld(); BungeeCore.send(p, BungeeCore.CHAT_PREFIX + "§aDer Spieler darf nun " + what);
case member: }else{
return true; if(player != null)
default: BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§cDu kannst nun nicht mehr auf der Welt von §e" + player.getName() + "§c " + what);
return false; BungeeCore.send(p, BungeeCore.CHAT_PREFIX + "§cDer Spieler darf nun nicht mehr " + what);
} }
} }
private static void del(File dir){ private static void del(File dir){
if (dir.isDirectory()){ if (dir.isDirectory()){
String[] entries = dir.list(); String[] entries = dir.list();
assert entries != null;
for (String entry : entries) { for (String entry : entries) {
File aktFile = new File(dir.getPath(), entry); File aktFile = new File(dir.getPath(), entry);
del(aktFile); del(aktFile);
@ -251,12 +253,4 @@ public class BauCommand {
dir.delete(); 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;
}
} }

Datei anzeigen

@ -4,16 +4,13 @@ import de.steamwar.bungeecore.*;
import net.md_5.bungee.api.CommandSender; import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.chat.ClickEvent; 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.connection.ProxiedPlayer;
import java.util.*; import java.util.*;
public class ChallengeCommand extends Command { public class ChallengeCommand extends BasicCommand {
public static final Map<ProxiedPlayer, List<ProxiedPlayer>> challenges = new HashMap<>(); private static final Map<ProxiedPlayer, List<ProxiedPlayer>> challenges = new HashMap<>();
public ChallengeCommand() { public ChallengeCommand() {
super("challenge", ""); super("challenge", "");
@ -22,8 +19,7 @@ public class ChallengeCommand extends Command {
@Override @Override
public void execute(CommandSender sender, String[] args) { public void execute(CommandSender sender, String[] args) {
if(args.length != 2){ if(args.length != 2){
sender.sendMessage(BungeeCore.ChatPrefix + "§7Mit §e/challenge §7kannst du jemanden herausfordern!"); BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "§8/§echallenge §8[§7Spieler§8] §8[§7Spielmodus§8]");
sender.sendMessage(BungeeCore.ChatPrefix + "§8/§echallenge §8[§7Spieler§8] §8[§7Spielmodus§8]");
return; return;
} }
if(!(sender instanceof ProxiedPlayer)){ if(!(sender instanceof ProxiedPlayer)){
@ -34,50 +30,30 @@ public class ChallengeCommand extends Command {
Subserver subserver = Subserver.getSubserver(player); Subserver subserver = Subserver.getSubserver(player);
if(subserver != null && subserver.getType() == Servertype.ARENA){ 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; return;
} }
ProxiedPlayer target = (ProxiedPlayer) ProxyServer.getInstance().getPlayer(args[0]); ProxiedPlayer target = ProxyServer.getInstance().getPlayer(args[0]);
if(target == null){ 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; return;
} }
subserver = Subserver.getSubserver(target); subserver = Subserver.getSubserver(target);
if(subserver != null && subserver.getType() == Servertype.ARENA){ 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; return;
} }
String map; ArenaMode mode = FightCommand.stringToArenaMode(args[1]);
ArenaMode mode; if(mode == ArenaMode.UNKNOWN){
switch(args[1].toLowerCase()){ BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§cUnbekannter Spielmodus: " + args[1]);
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; return;
} }
String map = FightCommand.getMap(sender, mode, new String[0]);
if(challenges.containsKey(target) && challenges.get(target).contains(player)){ if(challenges.containsKey(target) && challenges.get(target).contains(player)){
challenges.remove(target); challenges.remove(target);
challenges.remove(player); challenges.remove(player);
@ -87,10 +63,9 @@ public class ChallengeCommand extends Command {
arena.sendPlayer(player); arena.sendPlayer(player);
arena.sendPlayer(target); arena.sendPlayer(target);
TextComponent tc = new TextComponent(BungeeCore.ChatPrefix + "§e" + mode.name() + "§7-§eDuell§7: " + player.getName() + " vs " + target.getName()); BungeeCore.broadcast(BungeeCore.CHAT_PREFIX + "§e" + mode.name() + "§7-§eDuell§7: " + player.getName() + " vs " + target.getName(),
tc.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§aZuschauen").create())); "§aZuschauen",
tc.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/join " + player.getName())); new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/join " + player.getName()));
ProxyServer.getInstance().broadcast(tc);
}else{ }else{
if(!challenges.containsKey(player)){ if(!challenges.containsKey(player)){
challenges.put(player, new LinkedList<>()); challenges.put(player, new LinkedList<>());
@ -98,16 +73,19 @@ public class ChallengeCommand extends Command {
challenges.get(player).add(target); challenges.get(player).add(target);
player.sendMessage(BungeeCore.ChatPrefix + "§7Du hast §e" + target.getName() + " §7zu einem §e" + mode.name() + "-Kampf §7herausgefordert!"); BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§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(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"); BungeeCore.send(target, BungeeCore.CHAT_PREFIX + "§7Klicke §ehier§7, um die Herausforderung anzunehmen",
tc.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§aHerausforderung annehmen").create())); "§aHerausforderung annehmen",
tc.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/challenge " + player.getName() + " " + mode.name())); new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/challenge " + player.getName() + " " + mode.name()));
target.sendMessage(tc);
} }
} }
public static void remove(ProxiedPlayer player){
challenges.remove(player);
}
@Override @Override
public Iterable<String> onTabComplete(CommandSender commandSender, String[] args) { public Iterable<String> onTabComplete(CommandSender commandSender, String[] args) {
List<String> gamemodes = new ArrayList<>(); List<String> gamemodes = new ArrayList<>();

Datei anzeigen

@ -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.chat.TextComponent;
import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.connection.ProxiedPlayer;
public class DenyCommand extends Command { public class DenyCommand extends BasicCommand {
public DenyCommand(String cmd, String ...aliases) { public DenyCommand(String cmd, String ...aliases) {
super(cmd, "", aliases); super(cmd, "", aliases);
@ -15,7 +15,7 @@ public class DenyCommand extends Command {
public void execute(CommandSender sender, String[] args) { public void execute(CommandSender sender, String[] args) {
if(sender instanceof ProxiedPlayer){ if(sender instanceof ProxiedPlayer){
ProxiedPlayer player = (ProxiedPlayer) sender; ProxiedPlayer player = (ProxiedPlayer) sender;
player.sendMessage(new TextComponent(BungeeCore.ChatPrefix + "§cUnbekannter Befehl.")); player.sendMessage(new TextComponent(BungeeCore.CHAT_PREFIX + "§cUnbekannter Befehl."));
} }
} }
} }

Datei anzeigen

@ -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<Event> 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<Team> 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<EventFight> 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());
}
}
}

Datei anzeigen

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

Datei anzeigen

@ -17,7 +17,7 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Random; import java.util.Random;
public class FightCommand extends Command { public class FightCommand extends BasicCommand {
public FightCommand() { public FightCommand() {
super("fight", "", "f"); super("fight", "", "f");
@ -30,7 +30,7 @@ public class FightCommand extends Command {
if(map.equalsIgnoreCase(realMap)) if(map.equalsIgnoreCase(realMap))
return 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; return null;
}else{ }else{
List<String> l = BungeeCore.arenaMaps.get(mode); List<String> 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 @Override
public void execute(CommandSender sender, String[] args) { public void execute(CommandSender sender, String[] args) {
if(args.length != 1 && args.length != 2){ if(args.length != 1 && args.length != 2){
sender.sendMessage(BungeeCore.ChatPrefix + "§7Mit §e/fight §7kannst du einen neuen Kampf starten!"); BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "§7Mit §e/fight §7kannst du einen neuen Kampf starten!");
sender.sendMessage(BungeeCore.ChatPrefix + "§8/§efight §8[§7Spielmodus§8] <§7Arena§8>"); BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "§8/§efight §8[§7Spielmodus§8] <§7Arena§8>");
sender.sendMessage(BungeeCore.ChatPrefix + "§8/§efight AirShip §8- §7Starte einen §eAirShip§8-§7Kampf§8!"); BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "§8/§efight AirShip §8- §7Starte einen §eAirShip§8-§7Kampf§8!");
sender.sendMessage(BungeeCore.ChatPrefix + "§8/§efight WarShip §8- §7Starte einen §eWarShip§8-§7Kampf§8!"); BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "§8/§efight WarShip §8- §7Starte einen §eWarShip§8-§7Kampf§8!");
sender.sendMessage(BungeeCore.ChatPrefix + "§8/§efight WarGear §8- §7Starte einen §eWarGear§8-§7Kampf§8!"); BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "§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 + "§8/§efight MiniWarGear §8- §7Starte einen §eMiniWarGear§8-§7Kampf");
return; return;
} }
@ -56,53 +75,41 @@ public class FightCommand extends Command {
Subserver subserver = Subserver.getSubserver(player); Subserver subserver = Subserver.getSubserver(player);
if(subserver != null && subserver.getType() == Servertype.ARENA){ 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; return;
} }
String map; String map = null;
Subserver arena; Subserver arena;
String spielModus; ArenaMode mode = stringToArenaMode(args[0]);
switch(args[0].toLowerCase()){
case "as": if(mode != ArenaMode.UNKNOWN){
case "airship": map = getMap(sender, mode, args);
map = getMap(sender, ArenaMode.AirShip, args);
if(map == null) if(map == null)
return; return;
}
switch(mode){
case AirShip:
arena = SubserverSystem.startArena(ArenaMode.AirShip, map); arena = SubserverSystem.startArena(ArenaMode.AirShip, map);
spielModus = "AirShip";
break; break;
case "ws": case WarShip:
case "warship":
map = getMap(sender, ArenaMode.WarShip, args);
if(map == null)
return;
arena = SubserverSystem.startArena(ArenaMode.WarShip, map); arena = SubserverSystem.startArena(ArenaMode.WarShip, map);
spielModus = "WarShip";
break; break;
case "wg": case WarGear:
case "wargear":
map = getMap(sender, ArenaMode.WarGear, args);
if(map == null)
return;
arena = SubserverSystem.startArena(ArenaMode.WarGear, map); arena = SubserverSystem.startArena(ArenaMode.WarGear, map);
spielModus = "WarGear";
break; break;
case "mwg": case MiniWarGear:
case "miniwargear":
map = getMap(sender, ArenaMode.MiniWarGear, args);
if(map == null)
return;
arena = SubserverSystem.startArena(ArenaMode.MiniWarGear, map); arena = SubserverSystem.startArena(ArenaMode.MiniWarGear, map);
spielModus = "MiniWarGear";
break; break;
case UNKNOWN:
default: default:
sender.sendMessage(BungeeCore.ChatPrefix + "§cUnbekannter Spielmodus: " + args[0]); BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "§cUnbekannter Spielmodus: " + args[0]);
return; return;
} }
arena.sendPlayer(player); 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.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())); tc.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/join " + player.getName()));
ProxyServer.getInstance().broadcast(tc); ProxyServer.getInstance().broadcast(tc);
@ -122,26 +129,8 @@ public class FightCommand extends Command {
gamemodes.add("MiniWarGear"); gamemodes.add("MiniWarGear");
gamemodes.add("MWG"); gamemodes.add("MWG");
}else if(args.length == 2){ }else if(args.length == 2){
switch(args[1].toLowerCase()){ ArenaMode mode = stringToArenaMode(args[1]);
case "as": gamemodes.addAll(BungeeCore.arenaMaps.get(mode));
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;
}
} }
return gamemodes; return gamemodes;
} }

Datei anzeigen

@ -1,9 +1,9 @@
package de.steamwar.bungeecore.commands; package de.steamwar.bungeecore.commands;
import de.steamwar.bungeecore.ModSystem; import de.steamwar.bungeecore.listeners.mods.Forge;
import net.md_5.bungee.api.CommandSender; import net.md_5.bungee.api.CommandSender;
public class ForgeCommand extends Command { public class ForgeCommand extends BasicCommand {
public ForgeCommand() { public ForgeCommand() {
super("forge", "bungeecore.softreload"); super("forge", "bungeecore.softreload");
@ -11,6 +11,6 @@ public class ForgeCommand extends Command {
@Override @Override
public void execute(CommandSender sender, String[] args) { public void execute(CommandSender sender, String[] args) {
ModSystem.toggleEnabled(); Forge.toggleEnabled();
} }
} }

Datei anzeigen

@ -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.chat.TextComponent;
import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.connection.ProxiedPlayer;
public class HelpCommand extends Command { public class HelpCommand extends BasicCommand {
public HelpCommand() { public HelpCommand() {
super("help", "", "?"); super("help", "", "?");
} }
@ -16,42 +16,42 @@ public class HelpCommand extends Command {
@Override @Override
public void execute(CommandSender sender, String[] args) { public void execute(CommandSender sender, String[] args) {
if(args.length != 1){ 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.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§eZurück zur Lobby").create()));
tc.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/l")); tc.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/l"));
sender.sendMessage(tc); 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.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§eZum Bauserver").create()));
tc.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/bauserver")); tc.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/bauserver"));
sender.sendMessage(tc); 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.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§eHilfe zum Bauserver").create()));
tc.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/help bauserver")); tc.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/help bauserver"));
sender.sendMessage(tc); 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.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§eZum Kampfsystem").create()));
tc.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/fight")); tc.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/fight"));
sender.sendMessage(tc); 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.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§eHerausfordern").create()));
tc.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/challenge")); tc.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/challenge"));
sender.sendMessage(tc); 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.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§eTeamverwaltung").create()));
tc.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/team")); tc.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/team"));
sender.sendMessage(tc); 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.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§eSpieler beitreten").create()));
tc.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/join")); tc.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/join"));
sender.sendMessage(tc); 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.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§eLokaler Chat").create()));
tc.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/local")); tc.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/local"));
sender.sendMessage(tc); sender.sendMessage(tc);
@ -65,6 +65,7 @@ public class HelpCommand extends Command {
sender.sendMessage("§8/§espeed §8- §7Ändert deine Fluggeschwindigkeit"); sender.sendMessage("§8/§espeed §8- §7Ändert deine Fluggeschwindigkeit");
sender.sendMessage("§8/§env §8- §7(de)aktiviert Nachtsicht"); sender.sendMessage("§8/§env §8- §7(de)aktiviert Nachtsicht");
sender.sendMessage("§8/§etrace §8- §7Gibt einen Überblick über den TNT-Tracer"); 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/§eprotect §8- §7Schützt den Boden der (M)WG-Region");
sender.sendMessage("§8/§efreeze §8- §7Unterbindet Blockupdates"); sender.sendMessage("§8/§efreeze §8- §7Unterbindet Blockupdates");
sender.sendMessage("§8/§eskull §8- §7Gibt dir den Kopf eines Spielers"); sender.sendMessage("§8/§eskull §8- §7Gibt dir den Kopf eines Spielers");

Datei anzeigen

@ -13,7 +13,7 @@ import net.md_5.bungee.api.connection.ProxiedPlayer;
import java.util.ArrayList; 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."; 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; ProxiedPlayer player = (ProxiedPlayer) sender;
if (args.length == 0 && player.hasPermission("bungeecore.joinme")) { 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.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§aSpieler folgen").create()));
tc.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/join " + player.getName())); tc.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/join " + player.getName()));
ProxyServer.getInstance().broadcast(tc); ProxyServer.getInstance().broadcast(tc);
} else if (args.length == 1) { } else if (args.length == 1) {
ProxiedPlayer target = ProxyServer.getInstance().getPlayer(args[0]); ProxiedPlayer target = ProxyServer.getInstance().getPlayer(args[0]);
if(target == null || !target.isConnected()){ if(target == null || !target.isConnected()){
player.sendMessage(BungeeCore.ChatPrefix + "§cDieser Spieler ist offline."); player.sendMessage(BungeeCore.CHAT_PREFIX + "§cDieser Spieler ist offline.");
return; return;
}else if(target.equals(player)){ }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; return;
} }
ServerInfo server = target.getServer().getInfo(); ServerInfo server = target.getServer().getInfo();
@ -55,18 +55,18 @@ public class JoinmeCommand extends Command {
subserver.sendPlayer(player); subserver.sendPlayer(player);
} else { } else {
SubserverSystem.sendDeniedMessage(player, bauserver.getOwner()); 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)){ }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")) { }else if(ServerPerm == null && !player.getGroups().contains("team")) {
player.sendMessage(BungeeCore.ChatPrefix + DENY_MESSAGE); player.sendMessage(BungeeCore.CHAT_PREFIX + DENY_MESSAGE);
}else{ }else{
player.connect(server); player.connect(server);
} }
} else { } 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.");
} }
} }
} }

Datei anzeigen

@ -7,7 +7,7 @@ import net.md_5.bungee.api.connection.ProxiedPlayer;
import java.util.ArrayList; import java.util.ArrayList;
public class KickCommand extends Command { public class KickCommand extends BasicCommand {
public KickCommand() { public KickCommand() {
super("kick", "bungeecore.kick"); super("kick", "bungeecore.kick");
@ -16,34 +16,33 @@ public class KickCommand extends Command {
@Override @Override
public void execute(CommandSender sender, String[] args) { public void execute(CommandSender sender, String[] args) {
if(args.length == 0){ if(args.length == 0){
sender.sendMessage(BungeeCore.ChatPrefix + "/kick [Spieler] [Nachricht]"); BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "/kick [Spieler] [Nachricht]");
return; return;
} }
ProxiedPlayer target = ProxyServer.getInstance().getPlayer(args[0]); ProxiedPlayer target = ProxyServer.getInstance().getPlayer(args[0]);
if(target == null){ 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; return;
} }
if(args.length == 1){ if(args.length == 1){
target.disconnect(BungeeCore.ChatPrefix + "§cDu wurdest gekickt."); target.disconnect(BungeeCore.stringToText(BungeeCore.CHAT_PREFIX + "§cDu wurdest gekickt."));
}else{ }else{
StringBuilder msgBuilder = new StringBuilder(); 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++){ for (int i = 1; i < args.length; i++){
msgBuilder.append(args[i]).append(" "); 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 @Override
public Iterable<String> onTabComplete(CommandSender commandSender, String[] args) { public Iterable<String> onTabComplete(CommandSender commandSender, String[] args) {
if(args.length == 1){ if(args.length == 1)
return allPlayers(args[0]); return allPlayers(args[0]);
}
return new ArrayList<>(); return new ArrayList<>();
} }
} }

Datei anzeigen

@ -1,6 +1,7 @@
package de.steamwar.bungeecore.commands; package de.steamwar.bungeecore.commands;
import de.steamwar.bungeecore.BungeeCore; import de.steamwar.bungeecore.BungeeCore;
import de.steamwar.bungeecore.sql.SteamwarUser;
import net.md_5.bungee.api.CommandSender; import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.connection.ProxiedPlayer; 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.ArrayList;
import java.util.HashMap; import java.util.HashMap;
public class MsgCommand extends Command { public class MsgCommand extends BasicCommand {
protected static final HashMap<String, ProxiedPlayer> lastChats = new HashMap<>(); static final HashMap<String, ProxiedPlayer> lastChats = new HashMap<>();
public MsgCommand() { public MsgCommand() {
super("msg", "", "w", "tell"); super("msg", "", "w", "tell");
@ -22,19 +23,25 @@ public class MsgCommand extends Command {
ProxiedPlayer player = (ProxiedPlayer) sender; ProxiedPlayer player = (ProxiedPlayer) sender;
if (args.length < 2) { 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; return;
} }
ProxiedPlayer target = ProxyServer.getInstance().getPlayer(args[0]); ProxiedPlayer target = ProxyServer.getInstance().getPlayer(args[0]);
if(target == null){ 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; return;
}else if(target.getChatMode() != ProxiedPlayer.ChatMode.SHOWN){ }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; return;
}else if(target.equals(player)){ }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; return;
} }
@ -44,8 +51,8 @@ public class MsgCommand extends Command {
msgBuilder.append(args[i]).append(" "); msgBuilder.append(args[i]).append(" ");
} }
String msg = msgBuilder.toString(); String msg = msgBuilder.toString();
player.sendMessage(msg); BungeeCore.send(player, msg);
target.sendMessage(msg); BungeeCore.send(target, msg);
BungeeCore.log(msg); BungeeCore.log(msg);
lastChats.put(player.getName().toLowerCase(), target); lastChats.put(player.getName().toLowerCase(), target);

Datei anzeigen

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

Datei anzeigen

@ -4,7 +4,7 @@ import de.steamwar.bungeecore.BungeeCore;
import net.md_5.bungee.api.CommandSender; import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.connection.ProxiedPlayer;
public class PingCommand extends Command { public class PingCommand extends BasicCommand {
public PingCommand() { public PingCommand() {
super("ping", ""); super("ping", "");
@ -14,7 +14,7 @@ public class PingCommand extends Command {
public void execute(CommandSender sender, String[] args) { public void execute(CommandSender sender, String[] args) {
if(sender instanceof ProxiedPlayer){ if(sender instanceof ProxiedPlayer){
ProxiedPlayer player = (ProxiedPlayer) sender; 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!");
} }
} }
} }

Datei anzeigen

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

Datei anzeigen

@ -1,10 +1,11 @@
package de.steamwar.bungeecore.commands; package de.steamwar.bungeecore.commands;
import de.steamwar.bungeecore.BungeeCore; import de.steamwar.bungeecore.BungeeCore;
import de.steamwar.bungeecore.sql.SteamwarUser;
import net.md_5.bungee.api.CommandSender; import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.connection.ProxiedPlayer;
public class RCommand extends Command { public class RCommand extends BasicCommand {
public RCommand() { public RCommand() {
super("r", "", "reply"); super("r", "", "reply");
@ -15,21 +16,27 @@ public class RCommand extends Command {
if(sender instanceof ProxiedPlayer){ if(sender instanceof ProxiedPlayer){
ProxiedPlayer player = (ProxiedPlayer) sender; ProxiedPlayer player = (ProxiedPlayer) sender;
if(args.length == 0){ 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; return;
} }
ProxiedPlayer target = MsgCommand.lastChats.get(player.getName().toLowerCase()); ProxiedPlayer target = MsgCommand.lastChats.get(player.getName().toLowerCase());
if(target == null){ 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; return;
} }
if(!target.isConnected()){ 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; return;
}else if(target.getChatMode() != ProxiedPlayer.ChatMode.SHOWN){ }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; return;
} }
@ -39,8 +46,8 @@ public class RCommand extends Command {
msgBuilder.append(arg).append(" "); msgBuilder.append(arg).append(" ");
} }
String msg = msgBuilder.toString(); String msg = msgBuilder.toString();
player.sendMessage(msg); BungeeCore.send(player, msg);
target.sendMessage(msg); BungeeCore.send(target, msg);
BungeeCore.log(msg); BungeeCore.log(msg);
MsgCommand.lastChats.put(target.getName().toLowerCase(), player); MsgCommand.lastChats.put(target.getName().toLowerCase(), player);

Datei anzeigen

@ -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.config.ServerInfo;
import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.connection.ProxiedPlayer;
public class ServerSwitchCommand extends Command { public class ServerSwitchCommand extends BasicCommand {
private String serverName; private String serverName;

Datei anzeigen

@ -6,7 +6,7 @@ import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.connection.ProxiedPlayer;
public class ServerTeamchatCommand extends Command{ public class ServerTeamchatCommand extends BasicCommand {
public ServerTeamchatCommand() { public ServerTeamchatCommand() {
super("stc", "bungeecore.teamchat","serverteamchat"); super("stc", "bungeecore.teamchat","serverteamchat");
@ -18,12 +18,12 @@ public class ServerTeamchatCommand extends Command{
ProxiedPlayer player = (ProxiedPlayer) sender; ProxiedPlayer player = (ProxiedPlayer) sender;
if(args.length == 0){ if(args.length == 0){
player.sendMessage(BungeeCore.ChatPrefix + "/stc [Nachricht an das Team]"); player.sendMessage(BungeeCore.CHAT_PREFIX + "/stc [Nachricht an das Team]");
return; return;
} }
StringBuilder msgBuilder = new StringBuilder(); 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){ for (String arg : args){
msgBuilder.append(arg).append(" "); msgBuilder.append(arg).append(" ");
} }

Datei anzeigen

@ -1,39 +1,52 @@
package de.steamwar.bungeecore.commands; package de.steamwar.bungeecore.commands;
import de.steamwar.bungeecore.BungeeCore; 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.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.CommandSender;
import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.chat.ClickEvent; 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.connection.ProxiedPlayer;
import java.time.Instant;
import java.util.*; import java.util.*;
public class TeamCommand extends Command { public class TeamCommand extends BasicCommand {
public TeamCommand() { public TeamCommand() {
super("team", ""); super("team", "");
} }
private static Map<WarkingUser, List<Team>> invitations = new HashMap<>(); private static Map<SteamwarUser, List<Team>> invitations = new HashMap<>();
private void help(CommandSender sender){ private void help(CommandSender sender){
sender.sendMessage(BungeeCore.ChatPrefix + "§7Mit §e/team §7verwaltest du dein Team"); BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "§7Mit §e/team §7verwaltest du dein Team");
sender.sendMessage(BungeeCore.ChatPrefix + "§8/§eteam create §8- §7Erstelle dein eigenes Team"); BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "§8/§eteam list §8- §7Liste alle Teams auf");
sender.sendMessage(BungeeCore.ChatPrefix + "§8/§eteam join §8- §7Trete einem Team bei"); BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "§8/§eteam info §8- §7Informiere dich über ein Team");
sender.sendMessage(BungeeCore.ChatPrefix + "§8/§eteamchat §8- §7Sende Nachrichten an dein Team"); if(!(sender instanceof ProxiedPlayer))
sender.sendMessage(BungeeCore.ChatPrefix + "§8/§eteam leave §8- §7Verlasse dein Team"); return;
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"); ProxiedPlayer player = (ProxiedPlayer) sender;
sender.sendMessage(BungeeCore.ChatPrefix + "§8/§eteam invite §8- §7Lade jemanden in dein Team ein"); SteamwarUser user = SteamwarUser.get(player.getUniqueId());
sender.sendMessage(BungeeCore.ChatPrefix + "§8/§eteam remove §8- §7Entferne jemanden aus deinem Team"); if(user.getTeam() == 0) {
sender.sendMessage(BungeeCore.ChatPrefix + "§8/§eteam changekuerzel §8- §7Ändere dein Teamkürzel"); BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "§8/§eteam create §8- §7Erstelle dein eigenes Team");
sender.sendMessage(BungeeCore.ChatPrefix + "§8/§eteam changename §8- §7Ändere deinen Teamnamen"); BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "§8/§eteam join §8- §7Trete einem Team bei");
sender.sendMessage(BungeeCore.ChatPrefix + "§8/§eteam changeleader §8- §7Ernenne jemanden zum Teamleader"); }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 @Override
@ -47,18 +60,54 @@ public class TeamCommand extends Command {
return; return;
ProxiedPlayer player = (ProxiedPlayer) sender; ProxiedPlayer player = (ProxiedPlayer) sender;
WarkingUser user = WarkingUser.get(player.getUniqueId()); SteamwarUser user = SteamwarUser.get(player.getUniqueId());
Team team = Team.get(user.getTeam()); Team team = Team.get(user.getTeam());
WarkingUser target;
ProxiedPlayer p;
switch(args[0].toLowerCase()){ switch(args[0].toLowerCase()){
case "create": case "create":
create(player, user, team, args);
break;
case "join":
join(player, user, args);
break;
case "leave":
leave(player, user, team);
break;
case "invite":
invite(player, user, team, args);
break;
case "remove":
remove(player, user, team, args);
break;
case "changekuerzel":
changekuerzel(player, user, team, args);
break;
case "changename":
changename(player, user, team, args);
break;
case "changeleader":
changeleader(player, user, team, args);
break;
case "info":
info(player, user, team, args);
break;
case "list":
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)) if(unwantedInTeam(player, user))
return; return;
if(args.length < 3){ if(args.length < 3){
player.sendMessage(BungeeCore.ChatPrefix + "§8/§eteam create §8[§eTeamkürzel§8] §8[§eTeamname§8]"); BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§8/§eteam create §8[§eTeamkürzel§8] §8[§eTeamname§8]");
return; return;
} }
@ -70,14 +119,18 @@ public class TeamCommand extends Command {
Team.create(args[1], args[2], user.getId()); Team.create(args[1], args[2], user.getId());
user.setTeam(Team.get(args[1]).getTeamId()); user.setTeam(Team.get(args[1]).getTeamId());
player.sendMessage(BungeeCore.ChatPrefix + "§7Du hast das Team §e" + args[2] + " §7gegründet!"); BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§7Du hast das Team §e" + args[2] + " §7gegründet!");
break; }
case "join":
private void join(ProxiedPlayer player, SteamwarUser user, String[] args){
if(unwantedInTeam(player, user)) if(unwantedInTeam(player, user))
return; return;
if(notDuringEvent(player))
return;
if(!invitations.containsKey(user)){ if(!invitations.containsKey(user)){
player.sendMessage(BungeeCore.ChatPrefix + "§7Du hast keine Einladungen erhalten."); BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§7Du hast keine Einladungen erhalten.");
return; return;
} }
@ -88,12 +141,12 @@ public class TeamCommand extends Command {
t = invs.get(0); t = invs.get(0);
}else{ }else{
if(args.length != 2){ if(args.length != 2){
player.sendMessage(BungeeCore.ChatPrefix + "§8/§eteam join §8[§eTeam§8]"); 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"); StringBuilder sb = new StringBuilder().append("§7Du wurdest von diesen Teams eingeladen§8: §e");
for(Team inv : invs){ for(Team inv : invs){
sb.append(inv.getTeamName()).append(" "); sb.append(inv.getTeamName()).append(" ");
} }
player.sendMessage(sb.toString()); BungeeCore.send(player, sb.toString());
return; return;
} }
@ -103,22 +156,24 @@ public class TeamCommand extends Command {
break; break;
} }
} }
if(t == null){ if(t == null){
player.sendMessage(BungeeCore.ChatPrefix + "§cVon diesem Team wurdest du nicht eingeladen"); BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§cVon diesem Team wurdest du nicht eingeladen");
return; return;
} }
} }
user.setTeam(t.getTeamId()); user.setTeam(t.getTeamId());
invitations.remove(user); invitations.remove(user);
player.sendMessage(BungeeCore.ChatPrefix + "§7Du bist dem Team §e" + t.getTeamName() + " §7beigetreten!"); BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§7Du bist dem Team §e" + t.getTeamName() + " §7beigetreten!");
break; }
case "leave":
private void leave(ProxiedPlayer player, SteamwarUser user, Team team){
if(notInTeam(player, user)) if(notInTeam(player, user))
return; return;
if(team.getTeamLeader() == user.getId() && team.size() > 1){ if(team.getTeamLeader() == user.getId() && team.size() > 1){
player.sendMessage(BungeeCore.ChatPrefix + "§cBitte ernenne zunächst ein anderes Teammitglied zum Leader"); BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§cBitte ernenne zunächst ein anderes Teammitglied zum Leader");
return; return;
} }
@ -128,23 +183,28 @@ public class TeamCommand extends Command {
team.disband(); team.disband();
} }
player.sendMessage(BungeeCore.ChatPrefix + "§7Du hast dein Team verlassen!"); BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§7Du hast dein Team verlassen!");
break; }
case "invite":
private void invite(ProxiedPlayer player, SteamwarUser user, Team team, String[] args){
if(notLeader(player, user, team)) if(notLeader(player, user, team))
return; return;
if(notDuringEvent(player))
return;
if(args.length != 2){ if(args.length != 2){
player.sendMessage(BungeeCore.ChatPrefix + "§8/§eteam invite §8[§eSpieler§8]"); BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§8/§eteam invite §8[§eSpieler§8]");
return; return;
} }
target = WarkingUser.get(args[1]); SteamwarUser target = SteamwarUser.get(args[1]);
if(target == null){ if(target == null){
player.sendMessage(BungeeCore.ChatPrefix + "§cDiesen Spieler gibt es nicht"); BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§cDiesen Spieler gibt es nicht");
return; return;
}else if(target.getTeam() != 0){ }else if(target.getTeam() != 0){
player.sendMessage(BungeeCore.ChatPrefix + "§cDieser Spieler ist bereits in einem Team"); BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§cDieser Spieler ist bereits in einem Team");
return; return;
} }
@ -152,61 +212,66 @@ public class TeamCommand extends Command {
invitations.put(target, new LinkedList<>()); invitations.put(target, new LinkedList<>());
if(invitations.get(target).contains(team)){ if(invitations.get(target).contains(team)){
player.sendMessage(BungeeCore.ChatPrefix + "§cDu hast diesen Spieler bereits eingeladen"); BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§cDu hast diesen Spieler bereits eingeladen");
return; return;
} }
invitations.get(target).add(team); invitations.get(target).add(team);
player.sendMessage(BungeeCore.ChatPrefix + "§7Du hast §e" + args[1] + " §7in das Team eingeladen!"); BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§7Du hast §e" + args[1] + " §7in das Team eingeladen!");
p = ProxyServer.getInstance().getPlayer(target.getUUID()); ProxiedPlayer p = ProxyServer.getInstance().getPlayer(target.getUuid());
if(p != null) if(p != null)
p.sendMessage(BungeeCore.ChatPrefix + "§7Du wurdest in das Team §e" + team.getTeamName() + " §7eingeladen!"); BungeeCore.send(p, BungeeCore.CHAT_PREFIX + "§7Du wurdest in das Team §e" + team.getTeamName() + " §7eingeladen!");
break; }
case "remove":
private void remove(ProxiedPlayer player, SteamwarUser user, Team team, String[] args){
if(notLeader(player, user, team)) if(notLeader(player, user, team))
return; return;
if(args.length != 2){ if(args.length != 2){
player.sendMessage(BungeeCore.ChatPrefix + "§8/§eteam remove §8[§eSpieler§8]"); BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§8/§eteam remove §8[§eSpieler§8]");
return; return;
} }
target = WarkingUser.get(args[1]); SteamwarUser target = SteamwarUser.get(args[1]);
if(target == null){ if(target == null){
player.sendMessage(BungeeCore.ChatPrefix + "§cDiesen Spieler gibt es nicht"); BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§cDiesen Spieler gibt es nicht");
return; return;
} }
if(invitations.containsKey(target)){ if(invitations.containsKey(target)){
if(invitations.get(target).remove(team)){ if(invitations.get(target).remove(team)){
player.sendMessage(BungeeCore.ChatPrefix + "§7Die Einladung wurde zurückgezogen"); BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§7Die Einladung wurde zurückgezogen");
if(invitations.get(target).isEmpty()) if(invitations.get(target).isEmpty())
invitations.remove(target); invitations.remove(target);
}else{ }else{
player.sendMessage(BungeeCore.ChatPrefix + "§cDieser Spieler hat keine Einladung erhalten"); BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§cDieser Spieler hat keine Einladung erhalten");
} }
return; return;
} }
if(target.getTeam() != user.getTeam()){ if(target.getTeam() != user.getTeam()){
player.sendMessage(BungeeCore.ChatPrefix + "§cDieser Spieler ist nicht in deinem Team"); BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§cDieser Spieler ist nicht in deinem Team");
return; return;
} }
target.setTeam(0); target.setTeam(0);
player.sendMessage(BungeeCore.ChatPrefix + "§7Der Spieler wurde aus dem Team entfernt"); BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§7Der Spieler wurde aus dem Team entfernt");
p = ProxyServer.getInstance().getPlayer(target.getUUID()); ProxiedPlayer p = ProxyServer.getInstance().getPlayer(target.getUuid());
if(p != null) if(p != null)
p.sendMessage(BungeeCore.ChatPrefix + "§cDu wurdest aus dem Team entfernt"); BungeeCore.send(p, BungeeCore.CHAT_PREFIX + "§cDu wurdest aus dem Team entfernt");
break; }
case "changekuerzel":
private void changekuerzel(ProxiedPlayer player, SteamwarUser user, Team team, String[] args){
if(notLeader(player, user, team)) if(notLeader(player, user, team))
return; return;
if(notDuringEvent(player))
return;
if(args.length < 2){ if(args.length < 2){
player.sendMessage(BungeeCore.ChatPrefix + "§8/§eteam changekuerzel §8[§eTeamkürzel§8]"); BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§8/§eteam changekuerzel §8[§eTeamkürzel§8]");
return; return;
} }
@ -214,14 +279,18 @@ public class TeamCommand extends Command {
return; return;
team.setTeamKuerzel(args[1]); team.setTeamKuerzel(args[1]);
player.sendMessage(BungeeCore.ChatPrefix + "§7Du hast das Kürzel des Teams geändert!"); BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§7Du hast das Kürzel des Teams geändert!");
break; }
case "changename":
private void changename(ProxiedPlayer player, SteamwarUser user, Team team, String[] args){
if(notLeader(player, user, team)) if(notLeader(player, user, team))
return; return;
if(notDuringEvent(player))
return;
if(args.length < 2){ if(args.length < 2){
player.sendMessage(BungeeCore.ChatPrefix + "§8/§eteam changename §8[§eTeamname§8]"); BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§8/§eteam changename §8[§eTeamname§8]");
return; return;
} }
@ -229,82 +298,132 @@ public class TeamCommand extends Command {
return; return;
team.setTeamName(args[1]); team.setTeamName(args[1]);
player.sendMessage(BungeeCore.ChatPrefix + "§7Du hast das Team umbenannt!"); BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§7Du hast das Team umbenannt!");
break; }
case "changeleader":
private void changeleader(ProxiedPlayer player, SteamwarUser user, Team team, String[] args){
if(notLeader(player, user, team)) if(notLeader(player, user, team))
return; return;
if(notDuringEvent(player))
return;
if(args.length < 2){ if(args.length < 2){
player.sendMessage(BungeeCore.ChatPrefix + "§cBitte gib ein Teammitglied an"); BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§cBitte gib ein Teammitglied an");
return; return;
} }
target = WarkingUser.get(args[1]); SteamwarUser target = SteamwarUser.get(args[1]);
if(target == null){ if(target == null){
player.sendMessage(BungeeCore.ChatPrefix + "§cDen Spieler " + args[1] + " gibt es nicht"); BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§cDen Spieler " + args[1] + " gibt es nicht");
return; return;
} }
if(target.getTeam() != user.getTeam()){ if(target.getTeam() != user.getTeam()){
player.sendMessage(BungeeCore.ChatPrefix + "§cDer Spieler ist nicht in deinem Team"); BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§cDer Spieler ist nicht in deinem Team");
return; return;
} }
team.setTeamLeader(target.getId()); team.setTeamLeader(target.getId());
player.sendMessage(BungeeCore.ChatPrefix + "§7Du hast den Spieler §e" + args[1] + " §7zum Leader gemacht!"); BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§7Du hast den Spieler §e" + args[1] + " §7zum Leader gemacht!");
break; }
case "info":
private void info(ProxiedPlayer player, SteamwarUser user, Team team, String[] args){
if(args.length == 1 && user.getTeam() == 0){ if(args.length == 1 && user.getTeam() == 0){
player.sendMessage(BungeeCore.ChatPrefix + "§8/§eteam info §8[§eTeamname§8]"); BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§8/§eteam info §8[§eTeamname§8]");
return; return;
}else if(user.getTeam() == 0 || args.length == 2){ }else if(user.getTeam() == 0 || args.length == 2){
team = Team.get(args[1]); team = Team.get(args[1]);
} }
if(team == null){ if(team == null){
player.sendMessage(BungeeCore.ChatPrefix + "§cDieses Team gibt es nicht"); BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§cDieses Team gibt es nicht");
return; return;
} }
player.sendMessage("§7Team §e" + team.getTeamName() + " §8[§e" + team.getTeamKuerzel() + "§8]"); BungeeCore.send(player, "§7Team §e" + team.getTeamName() + " §8[§e" + team.getTeamKuerzel() + "§8]");
player.sendMessage("§7Leader§8: " + WarkingUser.get(team.getTeamLeader()).getUserName()); BungeeCore.send(player, "§7Leader§8: " + SteamwarUser.get(team.getTeamLeader()).getUserName());
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append("§7Member§8: §e"); sb.append("§7Member§8: §e");
List<Integer> members = team.getMembers(); List<Integer> members = team.getMembers();
for(int i : members){ for(int i : members){
WarkingUser m = WarkingUser.get(i); SteamwarUser m = SteamwarUser.get(i);
sb.append(m.getUserName()).append(" "); sb.append(m.getUserName()).append(" ");
} }
BungeeCore.send(player, sb.toString());
player.sendMessage(sb.toString()); Set<Event> events = TeamTeilnahme.getEvents(team.getTeamId());
break; if(!events.isEmpty()){
case "list": sb = new StringBuilder("§7Events§8: §e");
player.sendMessage(BungeeCore.ChatPrefix + "§7§lTeamliste"); 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<Team> all = Team.getAll(); List<Team> all = Team.getAll();
for(Team tm : all){ for(Team tm : all){
TextComponent tc = new TextComponent("§8" + tm.getTeamKuerzel() + " §e" + tm.getTeamName() + " §8[§7" + WarkingUser.get(tm.getTeamLeader()).getUserName() + "§8]"); BungeeCore.send(player,
tc.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§7Teaminfo").create())); "§8" + tm.getTeamKuerzel() + " §e" + tm.getTeamName() + " §8[§7" + SteamwarUser.get(tm.getTeamLeader()).getUserName() + "§8]",
tc.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/team info " + tm.getTeamKuerzel())); "§7Teaminfo",
player.sendMessage(tc); new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/team info " + tm.getTeamKuerzel()));
} }
break; }
default:
help(player); 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<Event> 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){ private boolean checkTeamName(ProxiedPlayer player, Team team, String arg){
if(arg.length() < 4 || arg.length() > 15){ 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; return true;
} }
Team t = Team.get(arg); Team t = Team.get(arg);
if(t != null && t.getTeamId() != team.getTeamId()){ 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 true;
} }
return false; return false;
@ -312,39 +431,47 @@ public class TeamCommand extends Command {
private boolean checkTeamKuerzel(ProxiedPlayer player, Team team, String arg){ private boolean checkTeamKuerzel(ProxiedPlayer player, Team team, String arg){
if(arg.length() < 2 || arg.length() > 4){ 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; return true;
} }
Team t = Team.get(arg); Team t = Team.get(arg);
if(t != null && (team == null || t.getTeamId() != team.getTeamId())){ 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 true;
} }
return false; return false;
} }
private boolean unwantedInTeam(ProxiedPlayer player, WarkingUser user){ private boolean unwantedInTeam(ProxiedPlayer player, SteamwarUser user){
if(user.getTeam() != 0){ 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 true;
} }
return false; return false;
} }
private boolean notInTeam(ProxiedPlayer player, WarkingUser user){ private boolean notInTeam(ProxiedPlayer player, SteamwarUser user){
if(user.getTeam() == 0){ 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 true;
} }
return false; return false;
} }
private boolean notLeader(ProxiedPlayer player, WarkingUser user, Team team){ private boolean notLeader(ProxiedPlayer player, SteamwarUser user, Team team){
if(notInTeam(player, user)) if(notInTeam(player, user))
return true; return true;
if(team.getTeamLeader() != user.getId()){ 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 true;
} }
return false; return false;
@ -360,9 +487,21 @@ public class TeamCommand extends Command {
tab.add("leave"); tab.add("leave");
tab.add("info"); tab.add("info");
tab.add("remove"); tab.add("remove");
tab.add("event");
tab.add("changekuerzel"); tab.add("changekuerzel");
tab.add("changename"); tab.add("changename");
tab.add("changeleader"); tab.add("changeleader");
}else if(args.length == 2){
if(args[1].equalsIgnoreCase("event")){
List<Event> coming = Event.getComing();
coming.forEach(event -> tab.add(event.getEventName()));
}else if(args[1].equalsIgnoreCase("join") || args[1].equalsIgnoreCase("info")){
List<Team> teams = Team.getAll();
teams.forEach(team -> {
tab.add(team.getTeamName());
tab.add(team.getTeamKuerzel());
});
}
} }
return tab; return tab;
} }

Datei anzeigen

@ -1,13 +1,14 @@
package de.steamwar.bungeecore.commands; package de.steamwar.bungeecore.commands;
import de.steamwar.bungeecore.BungeeCore; 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.ChatColor;
import net.md_5.bungee.api.ChatMessageType;
import net.md_5.bungee.api.CommandSender; import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.connection.ProxiedPlayer;
public class TeamchatCommand extends Command { public class TeamchatCommand extends BasicCommand {
public TeamchatCommand() { public TeamchatCommand() {
super("tc", "","teamchat"); super("tc", "","teamchat");
@ -17,20 +18,20 @@ public class TeamchatCommand extends Command {
public void execute(CommandSender sender, String[] args) { public void execute(CommandSender sender, String[] args) {
if(sender instanceof ProxiedPlayer){ if(sender instanceof ProxiedPlayer){
ProxiedPlayer player = (ProxiedPlayer) sender; ProxiedPlayer player = (ProxiedPlayer) sender;
WarkingUser user = WarkingUser.get(player.getUniqueId()); SteamwarUser user = SteamwarUser.get(player.getUniqueId());
if(user.getTeam() == 0){ 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; return;
} }
if(args.length == 0){ 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; return;
} }
StringBuilder msgBuilder = new StringBuilder(); 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){ for (String arg : args){
msgBuilder.append(arg).append(" "); msgBuilder.append(arg).append(" ");
} }
@ -38,9 +39,10 @@ public class TeamchatCommand extends Command {
msg = ChatColor.translateAlternateColorCodes('&', msg); msg = ChatColor.translateAlternateColorCodes('&', msg);
for (ProxiedPlayer target : ProxyServer.getInstance().getPlayers()){ for (ProxiedPlayer target : ProxyServer.getInstance().getPlayers()){
WarkingUser targetuser = WarkingUser.get(target.getUniqueId()); SteamwarUser targetuser = SteamwarUser.get(target.getUniqueId());
if (targetuser.getTeam() == user.getTeam() if (targetuser.getTeam() == user.getTeam()
&& target.getChatMode() == ProxiedPlayer.ChatMode.SHOWN){ && target.getChatMode() == ProxiedPlayer.ChatMode.SHOWN){
BungeeCore.send(target, ChatMessageType.CHAT, msg);
target.sendMessage(msg); target.sendMessage(msg);
} }
} }

Datei anzeigen

@ -1,12 +1,11 @@
package de.steamwar.bungeecore.commands; package de.steamwar.bungeecore.commands;
import de.steamwar.bungeecore.BungeeCore; import de.steamwar.bungeecore.BungeeCore;
import de.steamwar.bungeecore.sql.WarkingUser; import de.steamwar.bungeecore.sql.SteamwarUser;
import de.steamwar.bungeecore.sql.sql;
import net.md_5.bungee.api.CommandSender; import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.connection.ProxiedPlayer;
public class WebpwCommand extends Command { public class WebpwCommand extends BasicCommand {
public WebpwCommand() { public WebpwCommand() {
super("webpw", ""); super("webpw", "");
@ -17,18 +16,18 @@ public class WebpwCommand extends Command {
if(sender instanceof ProxiedPlayer){ if(sender instanceof ProxiedPlayer){
ProxiedPlayer player = (ProxiedPlayer) sender; ProxiedPlayer player = (ProxiedPlayer) sender;
if(args.length != 2){ if(args.length != 2){
player.sendMessage(BungeeCore.ChatPrefix + "/webpw [Passwort] [Passwort wiederholen]"); BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "/webpw [Passwort] [Passwort wiederholen]");
return; return;
}else if(!args[0].equals(args[1])){ }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; return;
}else if(args[0].length() < 6){ }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; return;
} }
sql.setWebpw(WarkingUser.get(player.getUniqueId()), args[0]); SteamwarUser.get(player.getUniqueId()).setWebpw(args[0]);
player.sendMessage(BungeeCore.ChatPrefix + "Webpasswort gesetzt!"); BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§7Webpasswort gesetzt!");
} }
} }
} }

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

@ -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<String> 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<String> 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++;
}
}
}

Datei anzeigen

@ -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<ProxiedPlayer> 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<ProxiedPlayer> players = server.getPlayers();
if(players.isEmpty() || (players.size() == 1 && players.contains(player)))
subserver.stop();
}
}

Datei anzeigen

@ -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<String> answers;
public static void init(String question, List<String> 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();
}
}

Datei anzeigen

@ -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<Integer, Integer> numMods = Utils.readVarInt(data, 1);
List<Mod> 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);
}
}

Datei anzeigen

@ -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<ProxiedPlayer> 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<Integer, String> purpose = readString(data, 0);
if(!"INFO".equals(purpose.getValue()))
return;
Pair<Integer, String> value = readString(data, purpose.getKey());
BungeeCore.log(value.getValue());
List<Mod> 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<Integer, String> readString(byte[] array, int startPos){
Pair<Integer, Integer> 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<Addon> 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
}

Datei anzeigen

@ -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<Integer, Integer> 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<Mod> mods){
ModType max = ModType.YELLOW;
Iterator<Mod> 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());
}
}
}

Datei anzeigen

@ -1,5 +1,7 @@
package de.steamwar.bungeecore.sql; package de.steamwar.bungeecore.sql;
import de.steamwar.bungeecore.BungeeCore;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Timestamp; import java.sql.Timestamp;
@ -8,57 +10,58 @@ import java.util.List;
public class BannedUserIPs { public class BannedUserIPs {
private int UserID; private int userID;
private Timestamp Timestamp; private Timestamp timestamp;
private String IP;
private BannedUserIPs(int userID, Timestamp timestamp, String ip){ private BannedUserIPs(int userID, Timestamp timestamp){
UserID = userID; this.userID = userID;
Timestamp = timestamp; this.timestamp = timestamp;
IP = ip;
} }
public static List<BannedUserIPs> get(int userID){ public static List<BannedUserIPs> get(int userID){
List<BannedUserIPs> userIPs = new ArrayList<>(); List<BannedUserIPs> 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 { try {
while(dbentry.next()){ while(dbentry.next()){
userIPs.add(new BannedUserIPs( userIPs.add(new BannedUserIPs(
userID, userID,
dbentry.getTimestamp("Timestamp"), dbentry.getTimestamp("Timestamp")));
dbentry.getString("IP")));
} }
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); BungeeCore.log("Get BannedUserIPs failed", e);
} }
return userIPs; return userIPs;
} }
public static List<BannedUserIPs> get(String ip){ public static List<BannedUserIPs> get(String ip){
List<BannedUserIPs> userIDs = new ArrayList<>(); List<BannedUserIPs> 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 { try {
while(dbentry.next()){ while(dbentry.next()){
userIDs.add(new BannedUserIPs( userIDs.add(new BannedUserIPs(
dbentry.getInt("UserID"), dbentry.getInt("UserID"),
dbentry.getTimestamp("Timestamp"), dbentry.getTimestamp("Timestamp")));
ip));
} }
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); BungeeCore.log("Get BannedUserIPs failed", e);
} }
return userIDs; 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() { public int getUserID() {
return UserID; return userID;
} }
public java.sql.Timestamp getTimestamp() { public java.sql.Timestamp getTimestamp() {
return Timestamp; return timestamp;
}
public String getIP() {
return IP;
} }
} }

Datei anzeigen

@ -1,20 +1,22 @@
package de.steamwar.bungeecore.sql; package de.steamwar.bungeecore.sql;
import de.steamwar.bungeecore.BungeeCore;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.UUID; import java.util.UUID;
public class Bauwelt { public class Bauwelt {
private final int UserID; private final int userID;
private boolean TNTDmg; private boolean tntDmg;
private boolean FireDmg; private boolean fireDmg;
private Bauwelt(int userID, boolean tntDmg, boolean fireDmg, boolean updateDB){ private Bauwelt(int userID, boolean tntDmg, boolean fireDmg, boolean updateDB){
UserID = userID; this.userID = userID;
TNTDmg = tntDmg; this.tntDmg = tntDmg;
FireDmg = fireDmg; this.fireDmg = fireDmg;
if(updateDB) if(updateDB)
updateDB(); updateDB();
} }
@ -24,24 +26,24 @@ public class Bauwelt {
} }
public Bauwelt(UUID userID, boolean tntDmg, boolean fireDmg){ 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(){ private void updateDB(){
sql.update("INSERT INTO Bauwelt" + SQL.update("INSERT INTO Bauwelt" +
" (UserID, TNTDmg, FireDmg)" + " (UserID, TNTDmg, FireDmg)" +
" VALUES" + " VALUES" +
" ('" + UserID + "', '" + sql.booleanToInt(TNTDmg) + "', '" + sql.booleanToInt(FireDmg) + "')" + " ('" + userID + "', '" + SQL.booleanToInt(tntDmg) + "', '" + SQL.booleanToInt(fireDmg) + "')" +
" ON DUPLICATE KEY UPDATE" + " ON DUPLICATE KEY UPDATE" +
" TNTDmg = VALUES(TNTDmg), FireDmg = VALUES(FireDmg)"); " TNTDmg = VALUES(TNTDmg), FireDmg = VALUES(FireDmg)");
} }
public static Bauwelt getBauwelt(UUID user){ public static Bauwelt getBauwelt(UUID user){
return getBauwelt(WarkingUser.get(user).getId()); return getBauwelt(SteamwarUser.get(user).getId());
} }
public static Bauwelt getBauwelt(int userId){ 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 { try {
if(bauwelt == null || !bauwelt.next()){ if(bauwelt == null || !bauwelt.next()){
return null; return null;
@ -50,16 +52,16 @@ public class Bauwelt {
boolean fireDmg = bauwelt.getBoolean("FireDmg"); boolean fireDmg = bauwelt.getBoolean("FireDmg");
return new Bauwelt(userId, tntDmg, fireDmg, false); return new Bauwelt(userId, tntDmg, fireDmg, false);
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); BungeeCore.log("Could not get Bauwelt", e);
} }
return null; return null;
} }
public int getUserID() { public int getUserID() {
return UserID; return userID;
} }
public UUID getUUID(){ public UUID getUUID(){
return WarkingUser.get(UserID).getUUID(); return SteamwarUser.get(userID).getUuid();
} }
} }

Datei anzeigen

@ -1,5 +1,7 @@
package de.steamwar.bungeecore.sql; package de.steamwar.bungeecore.sql;
import de.steamwar.bungeecore.BungeeCore;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
@ -7,19 +9,19 @@ import java.util.List;
import java.util.UUID; import java.util.UUID;
public class BauweltMember{ public class BauweltMember{
private final int BauweltID; private final int bauweltID;
private final int MemberID; private final int memberID;
private boolean Build; private boolean build;
private boolean WorldEdit; private boolean worldEdit;
private boolean World; private boolean world;
private BauweltMember(int ownerID, int memberID, boolean build, boolean worldEdit, boolean world, boolean updateDB){ private BauweltMember(int ownerID, int memberID, boolean build, boolean worldEdit, boolean world, boolean updateDB){
BauweltID = ownerID; bauweltID = ownerID;
MemberID = memberID; this.memberID = memberID;
Build = build; this.build = build;
WorldEdit = worldEdit; this.worldEdit = worldEdit;
World = world; this.world = world;
if(updateDB) if(updateDB)
updateDB(); updateDB();
} }
@ -29,28 +31,28 @@ public class BauweltMember{
} }
public BauweltMember(UUID ownerID, UUID memberID, boolean build, boolean worldEdit, boolean world){ 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(){ 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(){ private void updateDB(){
sql.update("INSERT INTO BauweltMember" + SQL.update("INSERT INTO BauweltMember" +
" (BauweltID, MemberID, Build, WorldEdit, World)" + " (BauweltID, MemberID, Build, WorldEdit, World)" +
" VALUES" + " 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" + " ON DUPLICATE KEY UPDATE" +
" Build = VALUES(Build), WorldEdit = VALUES(WorldEdit), World = VALUES(World)"); " Build = VALUES(Build), WorldEdit = VALUES(WorldEdit), World = VALUES(World)");
} }
public static BauweltMember getBauMember(UUID ownerID, UUID memberID){ 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){ 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 { try {
if(member == null || !member.next()){ if(member == null || !member.next()){
return null; return null;
@ -60,18 +62,18 @@ public class BauweltMember{
boolean world = member.getBoolean("World"); boolean world = member.getBoolean("World");
return new BauweltMember(ownerID, memberID, build, worldEdit, world, false); return new BauweltMember(ownerID, memberID, build, worldEdit, world, false);
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); BungeeCore.log("Could not load BauweltMember", e);
} }
return null; return null;
} }
public static List<BauweltMember> getMembers(UUID bauweltID){ public static List<BauweltMember> getMembers(UUID bauweltID){
return getMembers(WarkingUser.get(bauweltID).getId()); return getMembers(SteamwarUser.get(bauweltID).getId());
} }
public static List<BauweltMember> getMembers(int bauweltID){ public static List<BauweltMember> getMembers(int bauweltID){
try{ try{
ResultSet memberlist = sql.select("SELECT * FROM BauweltMember WHERE BauweltID = '" + bauweltID + "'"); ResultSet memberlist = SQL.select("SELECT * FROM BauweltMember WHERE BauweltID = '" + bauweltID + "'");
List<BauweltMember> members = new ArrayList<>(); List<BauweltMember> members = new ArrayList<>();
while(memberlist.next()){ while(memberlist.next()){
int memberID = memberlist.getInt("MemberID"); int memberID = memberlist.getInt("MemberID");
@ -82,43 +84,43 @@ public class BauweltMember{
} }
return members; return members;
}catch(SQLException e){ }catch(SQLException e){
e.printStackTrace(); BungeeCore.log("Could not load BauweltMembers", e);
} }
return new ArrayList<>(); return new ArrayList<>();
} }
public int getBauweltID() { public int getBauweltID() {
return BauweltID; return bauweltID;
} }
public int getMemberID() { public int getMemberID() {
return MemberID; return memberID;
} }
public boolean isBuild() { public boolean isBuild() {
return Build; return build;
} }
public void setBuild(boolean build) { public void setBuild(boolean build) {
Build = build; this.build = build;
updateDB(); updateDB();
} }
public boolean isWorldEdit() { public boolean isWorldEdit() {
return WorldEdit; return worldEdit;
} }
public void setWorldEdit(boolean worldEdit) { public void setWorldEdit(boolean worldEdit) {
WorldEdit = worldEdit; this.worldEdit = worldEdit;
updateDB(); updateDB();
} }
public boolean isWorld() { public boolean isWorld() {
return World; return world;
} }
public void setWorld(boolean world) { public void setWorld(boolean world) {
World = world; this.world = world;
updateDB(); updateDB();
} }
} }

Datei anzeigen

@ -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<Event> getComing(){
List<Event> 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;
}
}

Datei anzeigen

@ -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<EventFight> {
private static Queue<EventFight> 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<EventFight> getEvent(int eventID){
ResultSet rs = SQL.select("SELECT * FROM EventFight WHERE EventID = " + eventID + " ORDER BY FightID ASC");
List<EventFight> 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<EventFight> 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);
}
}

Datei anzeigen

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

Datei anzeigen

@ -1,9 +0,0 @@
package de.steamwar.bungeecore.sql;
public enum Permission {
world,
worldedit,
build,
member,
owner
}

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

@ -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<String, SteamwarUser> usersByName = new HashMap<>();
private static final Map<UUID, SteamwarUser> usersByUUID = new HashMap<>();
private static final Map<Integer, SteamwarUser> 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);
}
}
}

Datei anzeigen

@ -1,12 +1,14 @@
package de.steamwar.bungeecore.sql; package de.steamwar.bungeecore.sql;
import de.steamwar.bungeecore.BungeeCore;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import static de.steamwar.bungeecore.sql.sql.select; import static de.steamwar.bungeecore.sql.SQL.select;
public class Team { public class Team {
private final int teamId; private final int teamId;
@ -24,7 +26,7 @@ public class Team {
} }
public static void create(String kuerzel, String name, int leader){ public static void create(String kuerzel, String name, int leader){
sql.update("INSERT INTO Team" + SQL.update("INSERT INTO Team" +
" (TeamKuerzel, TeamName, TeamLeader)" + " (TeamKuerzel, TeamName, TeamLeader)" +
" VALUES" + " VALUES" +
" ('" + kuerzel + "', '" + name + "', '" + leader + "')"); " ('" + kuerzel + "', '" + name + "', '" + leader + "')");
@ -44,7 +46,7 @@ public class Team {
for(Team team : teamCache) for(Team team : teamCache)
if(team.teamKuerzel.equalsIgnoreCase(name)) if(team.teamKuerzel.equalsIgnoreCase(name))
return team; 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<Team> getAll(){ public static List<Team> getAll(){
@ -59,7 +61,7 @@ public class Team {
allTeams.add(load(rs)); allTeams.add(load(rs));
} }
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); BungeeCore.log("Could not get all Teams", e);
} }
return allTeams; return allTeams;
} }
@ -81,13 +83,13 @@ public class Team {
teamCache.add(team); teamCache.add(team);
return team; return team;
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); BungeeCore.log("Could not load Team", e);
return null; return null;
} }
} }
private void updateDB(){ private void updateDB(){
sql.update("INSERT INTO Team" + SQL.update("INSERT INTO Team" +
" (TeamID, TeamKuerzel, TeamName, TeamLeader)" + " (TeamID, TeamKuerzel, TeamName, TeamLeader)" +
" VALUES" + " VALUES" +
" ('" + teamId + "', '" + teamKuerzel + "', '" + teamName + "', '" + teamLeader + "')" + " ('" + teamId + "', '" + teamKuerzel + "', '" + teamName + "', '" + teamLeader + "')" +
@ -104,7 +106,7 @@ public class Team {
} }
public void setTeamKuerzel(String teamKuerzel) { public void setTeamKuerzel(String teamKuerzel) {
this.teamKuerzel = sql.disarmString(teamKuerzel); this.teamKuerzel = SQL.disarmString(teamKuerzel);
updateDB(); updateDB();
} }
@ -113,7 +115,7 @@ public class Team {
} }
public void setTeamName(String teamName) { public void setTeamName(String teamName) {
this.teamName = sql.disarmString(teamName); this.teamName = SQL.disarmString(teamName);
updateDB(); updateDB();
} }
@ -132,13 +134,13 @@ public class Team {
rs.next(); rs.next();
return rs.getInt("COUNT(id)"); return rs.getInt("COUNT(id)");
}catch (SQLException e) { }catch (SQLException e) {
e.printStackTrace(); BungeeCore.log("Could not get Teamsize", e);
return 1000; return 1000;
} }
} }
public void disband(){ public void disband(){
sql.update("DELETE FROM Team WHERE TeamID = " + teamId); SQL.update("DELETE FROM Team WHERE TeamID = " + teamId);
teamCache.remove(this); teamCache.remove(this);
} }
@ -151,7 +153,7 @@ public class Team {
} }
return members; return members;
}catch(SQLException e){ }catch(SQLException e){
e.printStackTrace(); BungeeCore.log("Could not get Teammembers", e);
} }
return new ArrayList<>(); return new ArrayList<>();
} }

Datei anzeigen

@ -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<Team> getTeams(int eventID){
Set<Team> 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<Event> getEvents(int teamID){
Set<Event> 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;
}
}

Datei anzeigen

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

Datei anzeigen

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