From a188ce2c6f8f8f5f07d3fd90de7a1ac04a9c3f3c Mon Sep 17 00:00:00 2001 From: Lixfel Date: Mon, 13 May 2024 17:23:42 +0200 Subject: [PATCH] WIP message deprecation Signed-off-by: Lixfel --- src/de/steamwar/bungeecore/BungeeCore.java | 12 +- .../bungeecore/commands/AlertCommand.java | 5 +- .../bungeecore/commands/ArenaCommand.java | 16 +- .../bungeecore/commands/BauCommand.java | 106 +++++----- .../bungeecore/commands/BugCommand.java | 13 +- .../commands/BuilderCloudCommand.java | 47 +++-- .../bungeecore/commands/ChallengeCommand.java | 20 +- .../bungeecore/commands/CheckCommand.java | 72 ++++--- .../bungeecore/commands/DevCommand.java | 33 ++- .../bungeecore/commands/EventCommand.java | 46 ++-- .../commands/EventRescheduleCommand.java | 11 +- .../commands/EventreloadCommand.java | 6 +- .../bungeecore/commands/FightCommand.java | 42 ++-- .../bungeecore/commands/GDPRQuery.java | 44 ++-- .../bungeecore/commands/HelpCommand.java | 28 ++- .../bungeecore/commands/HistoricCommand.java | 8 +- .../bungeecore/commands/IgnoreCommand.java | 4 +- .../bungeecore/commands/JoinmeCommand.java | 6 +- .../bungeecore/commands/KickCommand.java | 5 +- .../bungeecore/commands/ListCommand.java | 8 +- .../bungeecore/commands/LocalCommand.java | 5 +- .../bungeecore/commands/ModCommand.java | 33 ++- .../bungeecore/commands/MsgCommand.java | 12 +- .../bungeecore/commands/PingCommand.java | 7 +- .../bungeecore/commands/PlaytimeCommand.java | 7 +- .../bungeecore/commands/PollCommand.java | 32 ++- .../commands/PollresultCommand.java | 23 +- .../commands/PunishmentCommand.java | 197 ++++++++++-------- .../bungeecore/commands/TypeMappers.java | 12 +- .../bungeecore/inventory/SWInventory.java | 1 + .../bungeecore/listeners/ChatListener.java | 8 +- .../bungeecore/listeners/PollSystem.java | 34 +-- src/de/steamwar/bungeecore/util/BauLock.java | 18 +- .../steamwar/command/CommandRegistering.java | 37 ---- src/de/steamwar/command/SWCommand.java | 46 ++-- src/de/steamwar/command/TypeMapper.java | 6 +- src/de/steamwar/command/TypeUtils.java | 11 +- src/de/steamwar/command/TypeValidator.java | 5 +- .../steamwar/messages/BungeeCore.properties | 4 +- .../messages/BungeeCore_de.properties | 4 +- src/de/steamwar/messages/Chatter.java | 85 ++++---- src/de/steamwar/messages/ChatterGroup.java | 10 +- src/de/steamwar/messages/PlayerChatter.java | 61 ++++++ 43 files changed, 574 insertions(+), 616 deletions(-) delete mode 100644 src/de/steamwar/command/CommandRegistering.java create mode 100644 src/de/steamwar/messages/PlayerChatter.java diff --git a/src/de/steamwar/bungeecore/BungeeCore.java b/src/de/steamwar/bungeecore/BungeeCore.java index 56dbe30..f005033 100644 --- a/src/de/steamwar/bungeecore/BungeeCore.java +++ b/src/de/steamwar/bungeecore/BungeeCore.java @@ -27,10 +27,8 @@ import de.steamwar.bungeecore.mods.ServerListPing; import de.steamwar.bungeecore.mods.*; import de.steamwar.bungeecore.network.BungeeNetworkHandler; import de.steamwar.bungeecore.tablist.TablistManager; -import de.steamwar.command.SWCommandUtils; -import de.steamwar.command.SWTypeMapperCreator; -import de.steamwar.command.TabCompletionCache; -import de.steamwar.command.TypeMapper; +import de.steamwar.command.*; +import de.steamwar.messages.Chatter; import de.steamwar.sql.Punishment; import de.steamwar.sql.SteamwarUser; import de.steamwar.sql.Team; @@ -80,14 +78,14 @@ public class BungeeCore extends Plugin { errorLogger = new ErrorLogger(); - SWCommandUtils.init((SWTypeMapperCreator, CommandSender, Object>) (mapper, tabCompleter) -> new TypeMapper() { + SWCommandUtils.init((SWTypeMapperCreator, Chatter, Object>) (mapper, tabCompleter) -> new TypeMapper() { @Override - public Object map(CommandSender commandSender, String[] previousArguments, String s) { + public Object map(Chatter sender, PreviousArguments previousArguments, String s) { return mapper.apply(s); } @Override - public Collection tabCompletes(CommandSender sender, String[] previousArguments, String s) { + public Collection tabCompletes(Chatter sender, PreviousArguments previousArguments, String s) { return tabCompleter.apply(sender, s); } }); diff --git a/src/de/steamwar/bungeecore/commands/AlertCommand.java b/src/de/steamwar/bungeecore/commands/AlertCommand.java index 210f5b0..2e856bb 100644 --- a/src/de/steamwar/bungeecore/commands/AlertCommand.java +++ b/src/de/steamwar/bungeecore/commands/AlertCommand.java @@ -24,7 +24,6 @@ import de.steamwar.bungeecore.listeners.ConnectionListener; import de.steamwar.command.SWCommand; import de.steamwar.messages.Chatter; import net.md_5.bungee.api.ChatColor; -import net.md_5.bungee.api.CommandSender; public class AlertCommand extends SWCommand { @@ -33,9 +32,9 @@ public class AlertCommand extends SWCommand { } @Register(description = "USAGE_ALERT") - public void broadcast(CommandSender sender, @OptionalValue("") @StaticValue("-discord") String sendToDiscord, String... message) { + public void broadcast(Chatter sender, @OptionalValue("") @StaticValue("-discord") String sendToDiscord, String... message) { if (message.length == 0) { - Chatter.of(sender).system("USAGE_ALERT"); + sender.system("USAGE_ALERT"); return; } diff --git a/src/de/steamwar/bungeecore/commands/ArenaCommand.java b/src/de/steamwar/bungeecore/commands/ArenaCommand.java index 10bac32..274d45f 100644 --- a/src/de/steamwar/bungeecore/commands/ArenaCommand.java +++ b/src/de/steamwar/bungeecore/commands/ArenaCommand.java @@ -24,9 +24,9 @@ import de.steamwar.bungeecore.Subserver; import de.steamwar.command.PreviousArguments; import de.steamwar.command.SWCommand; import de.steamwar.command.TypeMapper; -import net.md_5.bungee.api.CommandSender; +import de.steamwar.messages.Chatter; +import de.steamwar.messages.PlayerChatter; import net.md_5.bungee.api.ProxyServer; -import net.md_5.bungee.api.connection.ProxiedPlayer; import java.util.Collection; import java.util.List; @@ -39,29 +39,29 @@ public class ArenaCommand extends SWCommand { } @Register - public void arenaJoin(ProxiedPlayer player, Subserver server) { - TpCommand.teleport(player, server.getServer()); + public void arenaJoin(PlayerChatter sender, Subserver server) { + TpCommand.teleport(sender.getPlayer(), server.getServer()); } @ClassMapper(value = Subserver.class, local = true) public TypeMapper serverInfoTypeMapper() { return new TypeMapper() { @Override - public Subserver map(CommandSender commandSender, String[] previousArguments, String s) { + public Subserver map(Chatter sender, PreviousArguments previousArguments, String s) { return Subserver.getSubserver(ProxyServer.getInstance().getServerInfo(s)); } @Override - public boolean validate(CommandSender sender, Subserver value, MessageSender messageSender) { + public boolean validate(Chatter sender, Subserver value, MessageSender messageSender) { if (value == null || value.getType() != Servertype.ARENA) { - messageSender.send("ARENA_NOT_FOUND"); + sender.system("ARENA_NOT_FOUND"); return false; } return true; } @Override - public Collection tabCompletes(CommandSender sender, PreviousArguments previousArguments, String s) { + public Collection tabCompletes(Chatter sender, PreviousArguments previousArguments, String s) { List subserverList = Subserver.getServerList(); synchronized (subserverList) { return subserverList.stream().filter(subserver -> subserver.getType() == Servertype.ARENA).map(subserver -> subserver.getServer().getName()).collect(Collectors.toList()); diff --git a/src/de/steamwar/bungeecore/commands/BauCommand.java b/src/de/steamwar/bungeecore/commands/BauCommand.java index 39388ff..d106703 100644 --- a/src/de/steamwar/bungeecore/commands/BauCommand.java +++ b/src/de/steamwar/bungeecore/commands/BauCommand.java @@ -31,12 +31,11 @@ import de.steamwar.command.SWCommand; import de.steamwar.command.TypeMapper; import de.steamwar.command.TypeValidator; import de.steamwar.messages.Chatter; +import de.steamwar.messages.PlayerChatter; import de.steamwar.network.packets.server.BaumemberUpdatePacket; import de.steamwar.sql.BauweltMember; import de.steamwar.sql.SteamwarUser; -import net.md_5.bungee.api.CommandSender; import net.md_5.bungee.api.ProxyServer; -import net.md_5.bungee.api.connection.ProxiedPlayer; import java.util.Collection; import java.util.function.Consumer; @@ -46,26 +45,26 @@ public class BauCommand extends SWCommand { private final HelpCommand command; - public BauCommand(HelpCommand command){ + public BauCommand(HelpCommand command) { super("bau", null, "b", "build", "gs"); this.command = command; } @Register(noTabComplete = true) - public void genericHelp(ProxiedPlayer p, String... args) { - this.command.sendBauHelp(p); + public void genericHelp(Chatter sender, String... args) { + this.command.sendBauHelp(sender); } @Register - public void toBau(ProxiedPlayer p, @OptionalValue(value = "", onlyUINIG = true) ServerVersion version) { - new ServerStarter().build(version, p.getUniqueId()).send(p).start(); + public void toBau(PlayerChatter sender, @OptionalValue(value = "", onlyUINIG = true) ServerVersion version) { + new ServerStarter().build(version, sender.user().getUUID()).send(sender.getPlayer()).start(); } @Register(value = "addmember", description = "BAU_ADDMEMBER_USAGE") - public void addmember(ProxiedPlayer p, @Validator("addMemberTarget") SteamwarUser target) { - BauweltMember.addMember(p.getUniqueId(), target.getUUID()); - Chatter.of(p).system("BAU_ADDMEMBER_ADDED"); - Chatter.of(target.getUUID()).system("BAU_ADDMEMBER_ADDED_TARGET", p); + public void addmember(Chatter sender, @Validator("addMemberTarget") SteamwarUser target) { + BauweltMember.addMember(sender.user().getUUID(), target.getUUID()); + sender.system("BAU_ADDMEMBER_ADDED"); + Chatter.of(target.getUUID()).system("BAU_ADDMEMBER_ADDED_TARGET", sender); } @Validator(value = "addMemberTarget", local = true) @@ -75,11 +74,11 @@ public class BauCommand extends SWCommand { messageSender.send("UNKNOWN_PLAYER"); return false; } - if (((ProxiedPlayer) sender).getUniqueId().equals(value.getUUID())) { + if (sender.user().getUUID().equals(value.getUUID())) { messageSender.send("BAU_ADDMEMBER_SELFADD"); return false; } - if (BauweltMember.getBauMember(((ProxiedPlayer) sender).getUniqueId(), value.getUUID()) != null) { + if (BauweltMember.getBauMember(sender.user().getId(), value.getId()) != null) { messageSender.send("BAU_ADDMEMBER_ISADDED"); return false; } @@ -89,8 +88,8 @@ public class BauCommand extends SWCommand { @Register(value = "tp", description = "BAU_TP_USAGE") @Register("teleport") - public void teleport(ProxiedPlayer p, @Validator("teleportTarget") SteamwarUser worldOwner, @OptionalValue(value = "", onlyUINIG = true) ServerVersion version) { - new ServerStarter().build(version, worldOwner.getUUID()).send(p).start(); + public void teleport(PlayerChatter sender, @Validator("teleportTarget") SteamwarUser worldOwner, @OptionalValue(value = "", onlyUINIG = true) ServerVersion version) { + new ServerStarter().build(version, worldOwner.getUUID()).send(sender.getPlayer()).start(); } @Validator(value = "teleportTarget", local = true) @@ -100,47 +99,45 @@ public class BauCommand extends SWCommand { messageSender.send("UNKNOWN_PLAYER"); return false; } - ProxiedPlayer p = (ProxiedPlayer) sender; - if (!p.getUniqueId().equals(value.getUUID()) && BauweltMember.getBauMember(value.getUUID(), p.getUniqueId()) == null) { - SubserverSystem.sendDeniedMessage(Chatter.of(p), value.getUUID()); + if (sender.user().getId() != value.getId() && BauweltMember.getBauMember(value.getId(), sender.user().getId()) == null) { + SubserverSystem.sendDeniedMessage(sender, value.getUUID()); messageSender.send("BAU_TP_NOALLOWED"); return false; } - return !BauLock.checkNotifyLocked(value, p); + return !BauLock.checkNotifyLocked(value, sender); }; } @Register("info") - public void info(ProxiedPlayer p) { - Chat19.chat(p, "/bauinfo"); + public void info(PlayerChatter sender) { + Chat19.chat(sender.getPlayer(), "/bauinfo"); } @Register("setspectator") - public void setSpectator(ProxiedPlayer p, @Mapper("addedUsers") @AllowNull @OptionalValue("") SteamwarUser user) { - setPerms(p, user, "setspectator", "BAU_MEMBER_SET_SPECTATOR", member -> { + public void setSpectator(Chatter sender, @Mapper("addedUsers") @AllowNull @OptionalValue("") SteamwarUser user) { + setPerms(sender, user, "setspectator", "BAU_MEMBER_SET_SPECTATOR", member -> { member.setBuild(false); member.setSupervisor(false); }); } @Register("setbuild") - public void setBuild(ProxiedPlayer p, @Mapper("addedUsers") @AllowNull @OptionalValue("") SteamwarUser user) { - setPerms(p, user, "setbuild", "BAU_MEMBER_SET_BUILDER", member -> { + public void setBuild(Chatter sender, @Mapper("addedUsers") @AllowNull @OptionalValue("") SteamwarUser user) { + setPerms(sender, user, "setbuild", "BAU_MEMBER_SET_BUILDER", member -> { member.setBuild(true); member.setSupervisor(false); }); } @Register("setsupervisor") - public void setSupervisor(ProxiedPlayer p, @Mapper("addedUsers") @AllowNull @OptionalValue("") SteamwarUser user) { - setPerms(p, user, "setsupervisor", "BAU_MEMBER_SET_SUPERVISOR", member -> { + public void setSupervisor(Chatter sender, @Mapper("addedUsers") @AllowNull @OptionalValue("") SteamwarUser user) { + setPerms(sender, user, "setsupervisor", "BAU_MEMBER_SET_SUPERVISOR", member -> { member.setBuild(true); member.setSupervisor(true); }); } - private void setPerms(ProxiedPlayer p, SteamwarUser user, String name, String permName, Consumer setter) { - Chatter owner = Chatter.of(p); + private void setPerms(Chatter owner, SteamwarUser user, String name, String permName, Consumer setter) { if (user == null) { owner.system("BAU_MEMBER_SET_USAGE", name); return; @@ -149,28 +146,25 @@ public class BauCommand extends SWCommand { withMember(owner, user, target -> { setter.accept(target); - Bauserver bauserver = Bauserver.get(p.getUniqueId()); + Bauserver bauserver = Bauserver.get(owner.user().getUUID()); if(bauserver != null) bauserver.getServer().getPlayers().stream().findAny().ifPresent(player -> NetworkSender.send(player, new BaumemberUpdatePacket())); - Chatter.of(user.getUUID()).system("BAU_MEMBER_SET_TARGET", p.getName(), new Message(permName)); + Chatter.of(user.getUUID()).system("BAU_MEMBER_SET_TARGET", owner, new Message(permName)); owner.system("BAU_MEMBER_SET", new Message(permName)); }); } @Register(value = "delmember", description = "BAU_DELMEMBER_USAGE") - public void delmember(ProxiedPlayer p, @Mapper("addedUsers") SteamwarUser user) { - Chatter owner = Chatter.of(p); + public void delmember(Chatter owner, @Mapper("addedUsers") SteamwarUser user) { withMember(owner, user, target -> { target.remove(); Chatter member = Chatter.of(user.getUUID()); - member.system("BAU_DELMEMBER_DELETED_TARGET", p); - member.withPlayer(toRemove -> { - Subserver currentServer = Subserver.getSubserver(toRemove.getServer().getInfo()); - if (currentServer != null && currentServer.getType() == Servertype.BAUSERVER && ((Bauserver) currentServer).getOwner().equals(p.getUniqueId())) { - toRemove.connect(ProxyServer.getInstance().getServerInfo(BungeeCore.LOBBY_SERVER)); - } + member.system("BAU_DELMEMBER_DELETED_TARGET", owner); + member.withPlayer(player -> { + if (Bauserver.get(owner.user().getUUID()).getServer().getPlayers().contains(player)) + player.connect(ProxyServer.getInstance().getServerInfo(BungeeCore.LOBBY_SERVER)); }); owner.system("BAU_DELMEMBER_DELETED"); @@ -181,13 +175,13 @@ public class BauCommand extends SWCommand { public TypeMapper addedUsers() { return new TypeMapper() { @Override - public SteamwarUser map(CommandSender commandSender, String[] previousArguments, String s) { - return SteamwarUser.get(s); + public SteamwarUser map(Chatter sender, PreviousArguments previousArguments, String s) { + return sender.user(); } @Override - public Collection tabCompletes(CommandSender sender, PreviousArguments previousArguments, String s) { - return BauweltMember.getMembers(Chatter.of(sender).user().getId()).stream() + public Collection tabCompletes(Chatter sender, PreviousArguments previousArguments, String s) { + return BauweltMember.getMembers(sender.user().getId()).stream() .map(bauweltMember -> SteamwarUser.get(bauweltMember.getMemberID()).getUserName()) .collect(Collectors.toList()); } @@ -196,20 +190,18 @@ public class BauCommand extends SWCommand { @Register("resetall") @Register("delete") - public void delete(ProxiedPlayer p, @OptionalValue(value = "", onlyUINIG = true) ServerVersion version) { - Chatter player = Chatter.of(p); - - SWInventory inventory = new SWInventory(player, 9, new Message("BAU_DELETE_GUI_NAME")); + public void delete(Chatter sender, @OptionalValue(value = "", onlyUINIG = true) ServerVersion version) { + SWInventory inventory = new SWInventory(sender, 9, new Message("BAU_DELETE_GUI_NAME")); inventory.addItem(0, new SWItem(new Message("BAU_DELETE_GUI_DELETE"), 10), click -> { - String world = version.getWorldFolder(ServerStarter.WORLDS_BASE_PATH) + (version != ServerVersion.SPIGOT_12 ? player.user().getId() : p.getUniqueId().toString()); + String world = version.getWorldFolder(ServerStarter.WORLDS_BASE_PATH) + (version != ServerVersion.SPIGOT_12 ? sender.user().getId() : sender.user().getUUID().toString()); ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.get(), () -> { - Bauserver subserver = Bauserver.get(p.getUniqueId()); + Bauserver subserver = Bauserver.get(sender.user().getUUID()); if(subserver != null) subserver.stop(); SubserverSystem.deleteFolder(BungeeCore.local, world); - player.system("BAU_DELETE_DELETED"); + sender.system("BAU_DELETE_DELETED"); }); inventory.close(); @@ -220,20 +212,20 @@ public class BauCommand extends SWCommand { @Register("test") @Register("testarena") - public void testarena(ProxiedPlayer p, @Mapper("nonHistoricArenaMode") @OptionalValue("") @AllowNull ArenaMode arenaMode, @Mapper("arenaMap") @OptionalValue("") @AllowNull String map) { - FightCommand.createArena(p, "/bau testarena ", false, arenaMode, map, false, (player, mode, m) -> - ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.get(), () -> new ServerStarter().test(mode, m, p).start()) + public void testarena(PlayerChatter sender, @Mapper("nonHistoricArenaMode") @OptionalValue("") @AllowNull ArenaMode arenaMode, @Mapper("arenaMap") @OptionalValue("") @AllowNull String map) { + FightCommand.createArena(sender.getPlayer(), "/bau testarena ", false, arenaMode, map, false, (player, mode, m) -> + ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.get(), () -> new ServerStarter().test(mode, m, sender.getPlayer()).start()) ); } @Register(value = "lock", description = "BAU_LOCKED_OPTIONS") - public void lock(ProxiedPlayer p, BauLockState bauLockState) { - BauLock.setLocked(p, bauLockState); + public void lock(Chatter sender, BauLockState bauLockState) { + BauLock.setLocked(sender, bauLockState); } @Register("unlock") - public void unlock(ProxiedPlayer p) { - BauLock.setLocked(p, BauLockState.OPEN); + public void unlock(Chatter sender) { + BauLock.setLocked(sender, BauLockState.OPEN); } private static void withMember(Chatter owner, SteamwarUser member, Consumer function) { diff --git a/src/de/steamwar/bungeecore/commands/BugCommand.java b/src/de/steamwar/bungeecore/commands/BugCommand.java index d537628..84ee6df 100644 --- a/src/de/steamwar/bungeecore/commands/BugCommand.java +++ b/src/de/steamwar/bungeecore/commands/BugCommand.java @@ -20,10 +20,8 @@ package de.steamwar.bungeecore.commands; import de.steamwar.sql.SWException; -import de.steamwar.sql.SteamwarUser; import de.steamwar.command.SWCommand; import de.steamwar.messages.Chatter; -import net.md_5.bungee.api.connection.ProxiedPlayer; public class BugCommand extends SWCommand { public BugCommand() { @@ -31,10 +29,11 @@ public class BugCommand extends SWCommand { } @Register - public void bugMessage(ProxiedPlayer player, String... message) { - String server = player.getServer().getInfo().getName(); - SteamwarUser user = SteamwarUser.get(player.getUniqueId()); - SWException.log(String.join(" ", message), server + " " + player.getName() + " " + user.getId()); - Chatter.of(player).system("BUG_MESSAGE"); + public void bugMessage(Chatter sender, String... message) { + SWException.log( + String.join(" ", message), + sender.withPlayerOrOffline(player -> player.getServer().getInfo().getName(), () -> "offline") + " " + sender.user().getUserName() + " " + sender.user().getId() + ); + sender.system("BUG_MESSAGE"); } } diff --git a/src/de/steamwar/bungeecore/commands/BuilderCloudCommand.java b/src/de/steamwar/bungeecore/commands/BuilderCloudCommand.java index 8cf195c..012b94d 100644 --- a/src/de/steamwar/bungeecore/commands/BuilderCloudCommand.java +++ b/src/de/steamwar/bungeecore/commands/BuilderCloudCommand.java @@ -9,14 +9,15 @@ import de.steamwar.command.PreviousArguments; import de.steamwar.command.SWCommand; import de.steamwar.command.TypeMapper; import de.steamwar.messages.Chatter; -import net.md_5.bungee.api.CommandSender; +import de.steamwar.messages.PlayerChatter; import net.md_5.bungee.api.ProxyServer; -import net.md_5.bungee.api.connection.ProxiedPlayer; import java.io.File; import java.io.IOException; import java.nio.file.Files; -import java.util.*; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; import java.util.stream.Collectors; public class BuilderCloudCommand extends SWCommand { @@ -26,32 +27,32 @@ public class BuilderCloudCommand extends SWCommand { } @Register(value = "create", description = "BUILDERCLOUD_CREATE_USAGE") - public void create(ProxiedPlayer player, @ErrorMessage("BUILDERCLOUD_VERSION") ServerVersion version, @Mapper("map") String map, @OptionalValue("") @Mapper("generator") @AllowNull File generator) { + public void create(Chatter sender, @ErrorMessage("BUILDERCLOUD_VERSION") ServerVersion version, @Mapper("map") String map, @OptionalValue("") @Mapper("generator") @AllowNull File generator) { mapFile(version, map).mkdir(); - new ServerStarter().builder(version, map, generator).send(player).start(); + sender.withPlayer(p -> new ServerStarter().builder(version, map, generator).send(p).start()); } @Register(description = "BUILDERCLOUD_USAGE") - public void start(ProxiedPlayer player, @ErrorMessage("BUILDERCLOUD_VERSION") ServerVersion version, @Mapper("map") String map) { + public void start(PlayerChatter sender, @ErrorMessage("BUILDERCLOUD_VERSION") ServerVersion version, @Mapper("map") String map) { if(!mapFile(version, map).exists()) { - Chatter.of(player).system("BUILDERCLOUD_UNKNOWN_MAP"); + sender.system("BUILDERCLOUD_UNKNOWN_MAP"); return; } - new ServerStarter().builder(version, map, null).send(player).start(); + new ServerStarter().builder(version, map, null).send(sender.getPlayer()).start(); } @Register(value = "rename", description = "BUILDERCLOUD_RENAME_USAGE") - public void rename(ProxiedPlayer player, @ErrorMessage("BUILDERCLOUD_VERSION") ServerVersion version, @Mapper("map") String oldName, String newName) { + public void rename(Chatter sender, @ErrorMessage("BUILDERCLOUD_VERSION") ServerVersion version, @Mapper("map") String oldName, String newName) { File oldMap = mapFile(version, oldName); if(!oldMap.exists()) { - Chatter.of(player).system("BUILDERCLOUD_UNKNOWN_MAP"); + sender.system("BUILDERCLOUD_UNKNOWN_MAP"); return; } File newMap = mapFile(version, newName); if(newMap.exists()) { - Chatter.of(player).system("BUILDERCLOUD_EXISTING_MAP"); + sender.system("BUILDERCLOUD_EXISTING_MAP"); return; } @@ -61,20 +62,20 @@ public class BuilderCloudCommand extends SWCommand { throw new SecurityException(e); } - Chatter.of(player).system("BUILDERCLOUD_RENAMED"); + sender.system("BUILDERCLOUD_RENAMED"); } @Register(value = "deploy", description = "BUILDERCLOUD_DEPLOY_USAGE") - public void deploy(ProxiedPlayer player, @Mapper("nonHistoricArenaMode") ArenaMode arenaMode, @ErrorMessage("BUILDERCLOUD_VERSION") ServerVersion version, @Mapper("map") String map) { + public void deploy(Chatter sender, @Mapper("nonHistoricArenaMode") ArenaMode arenaMode, @ErrorMessage("BUILDERCLOUD_VERSION") ServerVersion version, @Mapper("map") String map) { if(!mapFile(version, map).exists()) { - Chatter.of(player).system("BUILDERCLOUD_UNKNOWN_MAP"); + sender.system("BUILDERCLOUD_UNKNOWN_MAP"); return; } ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.get(), () -> { BungeeCore.local.execute("/binarys/deployarena.py", arenaMode.getConfig(), Integer.toString(version.getVersionSuffix()), map); ArenaMode.init(); - Chatter.of(player).system("BUILDERCLOUD_DEPLOY_FINISHED"); + sender.system("BUILDERCLOUD_DEPLOY_FINISHED"); }); } @@ -84,13 +85,13 @@ public class BuilderCloudCommand extends SWCommand { return new TypeMapper() { @Override - public String map(CommandSender commandSender, String[] previousArguments, String s) { + public String map(Chatter sender, PreviousArguments previousArguments, String s) { return s; } @Override - public Collection tabCompletes(CommandSender sender, PreviousArguments previousArguments, String s) { - File folder = getWorldFolder(previousArguments.userArgs, 1); + public Collection tabCompletes(Chatter sender, PreviousArguments previousArguments, String s) { + File folder = getWorldFolder(previousArguments, 1); String[] files; if(folder == null || (files = folder.list()) == null) @@ -107,7 +108,7 @@ public class BuilderCloudCommand extends SWCommand { return new TypeMapper() { @Override - public File map(CommandSender commandSender, String[] previousArguments, String s) { + public File map(Chatter sender, PreviousArguments previousArguments, String s) { if(s.isEmpty()) return null; @@ -124,8 +125,8 @@ public class BuilderCloudCommand extends SWCommand { } @Override - public Collection tabCompletes(CommandSender sender, PreviousArguments previousArguments, String s) { - File folder = getWorldFolder(previousArguments.userArgs, 2); + public Collection tabCompletes(Chatter sender, PreviousArguments previousArguments, String s) { + File folder = getWorldFolder(previousArguments, 2); String[] files; if(folder == null || (files = folder.list()) == null) @@ -140,8 +141,8 @@ public class BuilderCloudCommand extends SWCommand { return new File(version.getWorldFolder(ServerStarter.BUILDER_BASE_PATH), map); } - private File getWorldFolder(String[] previousArguments, int offset) { - ServerVersion v = ServerVersion.get(previousArguments[previousArguments.length - offset]); + private File getWorldFolder(PreviousArguments previousArguments, int offset) { + ServerVersion v = ServerVersion.get(previousArguments.userArgs[previousArguments.userArgs.length - offset]); if(v == null) return null; return new File(v.getWorldFolder(ServerStarter.BUILDER_BASE_PATH)); diff --git a/src/de/steamwar/bungeecore/commands/ChallengeCommand.java b/src/de/steamwar/bungeecore/commands/ChallengeCommand.java index 32d0748..fe5ab51 100644 --- a/src/de/steamwar/bungeecore/commands/ChallengeCommand.java +++ b/src/de/steamwar/bungeecore/commands/ChallengeCommand.java @@ -21,6 +21,7 @@ package de.steamwar.bungeecore.commands; import de.steamwar.bungeecore.*; import de.steamwar.messages.Chatter; +import de.steamwar.messages.PlayerChatter; import de.steamwar.sql.IgnoreSystem; import de.steamwar.command.SWCommand; import de.steamwar.command.TypeValidator; @@ -38,13 +39,14 @@ public class ChallengeCommand extends SWCommand { } @Register(description = "CHALLENGE_USAGE") - public void challenge(@Validator("arenaPlayer") ProxiedPlayer player, @Validator("target") ProxiedPlayer target, @Mapper("nonHistoricArenaMode") @OptionalValue("") @AllowNull ArenaMode arenaMode, @Mapper("arenaMap") @OptionalValue("") @AllowNull String map) { - FightCommand.createArena(player, "/challenge " + target.getName() + " ", false, arenaMode, map, false, (p, mode, m) -> { + public void challenge(@Validator("arenaPlayer") PlayerChatter sender, @Validator("target") ProxiedPlayer target, @Mapper("nonHistoricArenaMode") @OptionalValue("") @AllowNull ArenaMode arenaMode, @Mapper("arenaMap") @OptionalValue("") @AllowNull String map) { + FightCommand.createArena(sender, "/challenge " + target.getName() + " ", false, arenaMode, map, false, (chatter, mode, m) -> { + ProxiedPlayer p = sender.getPlayer(); if(challenges.containsKey(target) && challenges.get(target).contains(p)){ challenges.remove(target); challenges.remove(p); - new ServerStarter().arena(mode, map).blueLeader(player).redLeader(target).callback( + new ServerStarter().arena(mode, map).blueLeader(sender.getPlayer()).redLeader(target).callback( arena -> Chatter.broadcast().system("CHALLENGE_BROADCAST", "CHALLENGE_BROADCAST_HOVER", new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/arena " + arena.getServer().getName()), mode.getDisplayName(), p.getName(), target.getName()) ).start(); }else{ @@ -54,7 +56,7 @@ public class ChallengeCommand extends SWCommand { challenges.get(p).add(target); - Chatter.of(p).system("CHALLENGE_CHALLENGED", target.getName(), mode.getDisplayName()); + sender.system("CHALLENGE_CHALLENGED", target.getName(), mode.getDisplayName()); Chatter.of(target).system("CHALLENGE_CHALLENGED_TARGET", p.getName(), mode.getDisplayName(), mode.getMaps().size() != 1 ? new Message("CHALLENGE_CHALLENGED_MAP", m) : ""); Chatter.of(target).system("CHALLENGE_ACCEPT", new Message("CHALLENGE_ACCEPT_HOVER"), new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/challenge " + p.getName() + " " + mode.getChatName() + " " + m)); @@ -66,21 +68,21 @@ public class ChallengeCommand extends SWCommand { public TypeValidator targetValidator() { return (sender, value, messageSender) -> { if (value == null) { - messageSender.send("CHALLENGE_OFFLINE"); + sender.system("CHALLENGE_OFFLINE"); return false; } if (sender == value) { - messageSender.send("CHALLENGE_SELF"); + sender.system("CHALLENGE_SELF"); return false; } - if (IgnoreSystem.isIgnored(value.getUniqueId(), ((ProxiedPlayer) sender).getUniqueId())) { - messageSender.send("CHALLENGE_IGNORED"); + if (IgnoreSystem.isIgnored(value.getUniqueId(), sender.user().getUUID())) { + sender.system("CHALLENGE_IGNORED"); return false; } Subserver subserver = Subserver.getSubserver(value); if (subserver != null && subserver.getType() == Servertype.ARENA) { - messageSender.send("CHALLENGE_INARENA"); + sender.system("CHALLENGE_INARENA"); return false; } return true; diff --git a/src/de/steamwar/bungeecore/commands/CheckCommand.java b/src/de/steamwar/bungeecore/commands/CheckCommand.java index 3ab407c..5e97c83 100644 --- a/src/de/steamwar/bungeecore/commands/CheckCommand.java +++ b/src/de/steamwar/bungeecore/commands/CheckCommand.java @@ -24,6 +24,7 @@ import de.steamwar.bungeecore.bot.util.DiscordAlert; import de.steamwar.bungeecore.listeners.ConnectionListener; import de.steamwar.command.SWCommand; import de.steamwar.messages.Chatter; +import de.steamwar.messages.PlayerChatter; import de.steamwar.sql.*; import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.ChatMessageType; @@ -79,11 +80,10 @@ public class CheckCommand extends SWCommand { } @Register(value = "list", description = "CHECK_HELP_LIST") - public void list(ProxiedPlayer player) { - Chatter chatter = Chatter.of(player); + public void list(Chatter sender) { List schematicList = getSchemsToCheck(); - chatter.prefixless("CHECK_LIST_HEADER", schematicList.size()); + sender.system("CHECK_LIST_HEADER", schematicList.size()); for (SchematicNode schematic : schematicList) { CheckSession current = currentSchems.get(schematic.getId()); @@ -91,15 +91,15 @@ public class CheckCommand extends SWCommand { String color = waitedMillis > 14400000 ? (waitedMillis > 86400000 ? "c" : "e") : "a"; long hours = waitedMillis / 3600000; long minutes = (waitedMillis - hours * 3600000) / 60000; - Message waitTime = new Message("CHECK_LIST_WAIT", player, color, hours, (minutes < 10) ? "0" + minutes : minutes); + Message waitTime = new Message("CHECK_LIST_WAIT", color, hours, (minutes < 10) ? "0" + minutes : minutes); if (current == null) { - chatter.prefixless("CHECK_LIST_TO_CHECK", + sender.prefixless("CHECK_LIST_TO_CHECK", new Message("CHECK_LIST_TO_CHECK_HOVER"), new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/check schematic " + schematic.getId()), waitTime, schematic.getSchemtype().getKuerzel(), SteamwarUser.get(schematic.getOwner()).getUserName(), schematic.getName()); } else { - chatter.prefixless("CHECK_LIST_CHECKING", + sender.prefixless("CHECK_LIST_CHECKING", new Message("CHECK_LIST_CHECKING_HOVER"), new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/join " + current.checker.user().getUserName()), waitTime, @@ -109,35 +109,33 @@ public class CheckCommand extends SWCommand { } @Register(value = "schematic", noTabComplete = true) - public void schematic(ProxiedPlayer player, String schemID) { - Chatter chatter = Chatter.of(player); - if(isChecking(player)){ - chatter.system("CHECK_SCHEMATIC_ALREADY_CHECKING"); + public void schematic(PlayerChatter sender, String schemID) { + if(isChecking(sender.getPlayer())){ + sender.system("CHECK_SCHEMATIC_ALREADY_CHECKING"); return; } - SteamwarUser checkingUser = SteamwarUser.get(player.getUniqueId()); SchematicNode schem = SchematicNode.getSchematicNode(Integer.parseInt(schemID)); if(!schem.getSchemtype().check()){ - ProxyServer.getInstance().getLogger().log(Level.SEVERE, () -> player.getName() + " tried to check an uncheckable schematic!"); + ProxyServer.getInstance().getLogger().log(Level.SEVERE, () -> sender.user().getUserName() + " tried to check an uncheckable schematic!"); return; - }else if(schem.getOwner() == checkingUser.getId()) { - chatter.system("CHECK_SCHEMATIC_OWN"); + }else if(schem.getOwner() == sender.user().getId()) { + sender.system("CHECK_SCHEMATIC_OWN"); return; } - int playerTeam = checkingUser.hasPerm(UserPerm.MODERATION) ? 0 : checkingUser.getTeam(); + int playerTeam = sender.user().hasPerm(UserPerm.MODERATION) ? 0 : sender.user().getTeam(); if (playerTeam != 0 && SteamwarUser.get(schem.getOwner()).getTeam() == playerTeam) { - chatter.system("CHECK_SCHEMATIC_OWN_TEAM"); - return; + sender.system("CHECK_SCHEMATIC_OWN_TEAM"); + return; } - new CheckSession(chatter, schem); + new CheckSession(sender, schem); } @Register(value = "cancel", description = "CHECK_HELP_CANCEL") @Register("abort") - public void abortCommand(ProxiedPlayer player) { - abort(player); + public void abortCommand(PlayerChatter sender) { + abort(sender.getPlayer()); } public static void abort(ProxiedPlayer player) { @@ -149,24 +147,24 @@ public class CheckCommand extends SWCommand { } @Register(value = "next", description = "CHECK_HELP_NEXT") - public void next(ProxiedPlayer player) { - if(notChecking(player)) + public void next(PlayerChatter sender) { + if(notChecking(sender.getPlayer())) return; - currentCheckers.get(player.getUniqueId()).next(); + currentCheckers.get(sender.getPlayer().getUniqueId()).next(); } @Register(value = "accept") - public void accept(ProxiedPlayer player, @OptionalValue("") String rank) { - next(player); + public void accept(PlayerChatter sender) { + next(sender); } @Register(value = "decline", description = "CHECK_HELP_DECLINE") - public void decline(ProxiedPlayer player, String... message) { - if(notChecking(player)) + public void decline(PlayerChatter sender, String... message) { + if(notChecking(sender.getPlayer())) return; - currentCheckers.get(player.getUniqueId()).decline(String.join(" ", message)); + currentCheckers.get(sender.getPlayer().getUniqueId()).decline(String.join(" ", message)); } public static List getSchemsToCheck(){ @@ -193,20 +191,20 @@ public class CheckCommand extends SWCommand { } private static class CheckSession{ - private final Chatter checker; + private final PlayerChatter checker; private final SchematicNode schematic; private final Timestamp startTime; private final ListIterator checkList; - private CheckSession(Chatter checker, SchematicNode schematic){ + private CheckSession(PlayerChatter checker, SchematicNode schematic){ this.checker = checker; this.schematic = schematic; this.startTime = Timestamp.from(Instant.now()); this.checkList = checkQuestions.get(schematic.getSchemtype()).listIterator(); - ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.get(), () -> checker.withPlayer(player -> { + ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.get(), () -> { ArenaMode mode = ArenaMode.getBySchemType(fightTypes.get(schematic.getSchemtype())); - if(!new ServerStarter().test(mode, mode.getRandomMap(), player).check(schematic.getId()).start()) { + if(!new ServerStarter().test(mode, mode.getRandomMap(), checker.getPlayer()).check(schematic.getId()).start()) { remove(); return; } @@ -216,7 +214,7 @@ public class CheckCommand extends SWCommand { for(CheckedSchematic previous : CheckedSchematic.previousChecks(schematic)) checker.prefixless("CHECK_SCHEMATIC_PREVIOUS", previous.getEndTime(), SteamwarUser.get(previous.getValidator()).getUserName(), previous.getDeclineReason()); next(); - })); + }); } private void next() { @@ -248,9 +246,9 @@ public class CheckCommand extends SWCommand { private void accept(){ if(concludeCheckSession("freigegeben", fightTypes.get(schematic.getSchemtype()))) { Chatter owner = Chatter.of(SteamwarUser.get(schematic.getOwner()).getUUID()); - owner.withPlayerOrDiscord( + owner.withPlayerOrOffline( player -> owner.system("CHECK_ACCEPTED", schematic.getSchemtype().name(), schematic.getName()), - user -> DiscordAlert.send(owner, Color.GREEN, new Message("DC_TITLE_SCHEMINFO"), new Message("DC_SCHEM_ACCEPT", schematic.getName()), true) + () -> DiscordAlert.send(owner, Color.GREEN, new Message("DC_TITLE_SCHEMINFO"), new Message("DC_SCHEM_ACCEPT", schematic.getName()), true) ); Chatter.serverteam().system("CHECK_ACCEPTED_TEAM", schematic.getName(), owner.user().getUserName()); } @@ -259,9 +257,9 @@ public class CheckCommand extends SWCommand { private void decline(String reason){ if(concludeCheckSession(reason, SchematicType.Normal)) { Chatter owner = Chatter.of(SteamwarUser.get(schematic.getOwner()).getUUID()); - owner.withPlayerOrDiscord( + owner.withPlayerOrOffline( player -> owner.system("CHECK_DECLINED", schematic.getSchemtype().name(), schematic.getName(), reason), - user -> DiscordAlert.send(owner, Color.RED, new Message("DC_TITLE_SCHEMINFO"), new Message("DC_SCHEM_DECLINE", schematic.getName(), reason), false) + () -> DiscordAlert.send(owner, Color.RED, new Message("DC_TITLE_SCHEMINFO"), new Message("DC_SCHEM_DECLINE", schematic.getName(), reason), false) ); Chatter.serverteam().system("CHECK_DECLINED_TEAM", schematic.getName(), owner.user().getUserName(), reason); } diff --git a/src/de/steamwar/bungeecore/commands/DevCommand.java b/src/de/steamwar/bungeecore/commands/DevCommand.java index d0048c4..fc3ffca 100644 --- a/src/de/steamwar/bungeecore/commands/DevCommand.java +++ b/src/de/steamwar/bungeecore/commands/DevCommand.java @@ -19,14 +19,15 @@ package de.steamwar.bungeecore.commands; -import de.steamwar.bungeecore.Message; +import de.steamwar.command.SWCommand; +import de.steamwar.command.SWCommandUtils; +import de.steamwar.command.TypeMapper; +import de.steamwar.command.TypeValidator; +import de.steamwar.messages.PlayerChatter; import de.steamwar.sql.Punishment; import de.steamwar.sql.SteamwarUser; -import de.steamwar.command.*; -import de.steamwar.messages.Chatter; import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.config.ServerInfo; -import net.md_5.bungee.api.connection.ProxiedPlayer; import java.io.File; import java.net.InetSocketAddress; @@ -43,46 +44,42 @@ public class DevCommand extends SWCommand { } @Register - public void simpleCommand(@Validator ProxiedPlayer player) { + public void simpleCommand(@Validator PlayerChatter sender) { updateDevServers(); - Chatter sender = Chatter.of(player); if (devServers.isEmpty()) { sender.system("DEV_NO_SERVER"); return; } else if (devServers.size() == 1) { - player.connect(devServers.values().stream().findAny().get()); + sender.getPlayer().connect(devServers.values().stream().findAny().get()); return; } - ServerInfo info = devServers.get(player.getName().toLowerCase()); + ServerInfo info = devServers.get(sender.getPlayer().getName().toLowerCase()); if (info == null) { sender.system("DEV_UNKNOWN_SERVER"); return; } - player.connect(info); + sender.getPlayer().connect(info); } @Register - public void selectedCommand(@Validator ProxiedPlayer player, @Mapper("dev") String name) { + public void selectedCommand(@Validator PlayerChatter sender, @Mapper("dev") String name) { updateDevServers(); - Chatter sender = Chatter.of(player); ServerInfo info = devServers.get(name.toLowerCase()); if (info == null) { sender.system("DEV_NO_SERVER"); return; } - player.connect(info); + sender.getPlayer().connect(info); } - @ClassValidator(value = ProxiedPlayer.class, local = true) - public TypeValidator punishmentGuardChecker() { + @ClassValidator(value = PlayerChatter.class, local = true) + public TypeValidator punishmentGuardChecker() { return (sender, value, messageSender) -> { - SteamwarUser user = SteamwarUser.get(value.getUniqueId()); - if (user.isPunished(Punishment.PunishmentType.NoDevServer)) { - Message message = PunishmentCommand.punishmentMessage(user, Punishment.PunishmentType.NoDevServer); - messageSender.send(message.getFormat(), message.getParams()); + if (sender.user().isPunished(Punishment.PunishmentType.NoDevServer)) { + sender.system(PunishmentCommand.punishmentMessage(sender.user(), Punishment.PunishmentType.NoDevServer)); return false; } return true; diff --git a/src/de/steamwar/bungeecore/commands/EventCommand.java b/src/de/steamwar/bungeecore/commands/EventCommand.java index 0386006..926dd32 100644 --- a/src/de/steamwar/bungeecore/commands/EventCommand.java +++ b/src/de/steamwar/bungeecore/commands/EventCommand.java @@ -25,9 +25,8 @@ import de.steamwar.bungeecore.SubserverSystem; import de.steamwar.command.SWCommand; import de.steamwar.command.TypeValidator; import de.steamwar.messages.Chatter; +import de.steamwar.messages.PlayerChatter; import de.steamwar.sql.*; -import net.md_5.bungee.api.CommandSender; -import net.md_5.bungee.api.connection.ProxiedPlayer; import java.time.Instant; import java.time.format.DateTimeFormatter; @@ -42,80 +41,77 @@ public class EventCommand extends SWCommand { } @Validator("noEvent") - public TypeValidator noEventValidator() { + public TypeValidator noEventValidator() { return (sender, value, messageSender) -> Event.get() == null; } @Register - public void noCurrentEvent(@Validator("noEvent") CommandSender sender) { - Chatter player = Chatter.of(sender); - player.system("EVENT_NO_CURRENT"); + public void noCurrentEvent(@Validator("noEvent") Chatter sender) { + sender.system("EVENT_NO_CURRENT"); List coming = Event.getComing(); if(coming.isEmpty()) return; - player.system("EVENT_COMING"); + sender.system("EVENT_COMING"); Instant now = Instant.now(); - DateTimeFormatter format = DateTimeFormatter.ofPattern(player.parseToPlain("EVENT_DATE_FORMAT")); + DateTimeFormatter format = DateTimeFormatter.ofPattern(sender.parseToPlain("EVENT_DATE_FORMAT")); for(Event e : coming){ - player.prefixless("EVENT_COMING_EVENT", e.getStart().toLocalDateTime().format(format), e.getEnd().toLocalDateTime().format(format), e.getEventName()); + sender.prefixless("EVENT_COMING_EVENT", e.getStart().toLocalDateTime().format(format), e.getEnd().toLocalDateTime().format(format), e.getEventName()); if(now.isBefore(e.getDeadline().toInstant())) - player.prefixless("EVENT_COMING_DEADLINE", e.getDeadline()); + sender.prefixless("EVENT_COMING_DEADLINE", e.getDeadline()); SchematicType schemType = e.getSchematicType(); if (schemType != null && schemType.getDeadline() != null && now.isBefore(schemType.getDeadline().toInstant())) - player.prefixless("EVENT_COMING_SCHEM_DEADLINE", schemType.getDeadline()); + sender.prefixless("EVENT_COMING_SCHEM_DEADLINE", schemType.getDeadline()); Set teams = TeamTeilnahme.getTeams(e.getEventID()); if(!teams.isEmpty()) - player.prefixless("EVENT_COMING_TEAMS", teams.stream().map(team -> player.parseToLegacy("EVENT_COMING_TEAM", team.getTeamColor(), team.getTeamKuerzel())).collect(Collectors.joining(" "))); + sender.prefixless("EVENT_COMING_TEAMS", teams.stream().map(team -> sender.parseToLegacy("EVENT_COMING_TEAM", team.getTeamColor(), team.getTeamKuerzel())).collect(Collectors.joining(" "))); } } @Register - public void eventOverview(@Validator(value = "noEvent", invert = true) CommandSender sender) { - Chatter player = Chatter.of(sender); - player.system("EVENT_USAGE"); + public void eventOverview(@Validator(value = "noEvent", invert = true) Chatter sender) { + sender.system("EVENT_USAGE"); Event currentEvent = Event.get(); - player.system("EVENT_CURRENT_EVENT", currentEvent.getEventName()); + sender.system("EVENT_CURRENT_EVENT", currentEvent.getEventName()); - DateTimeFormatter format = DateTimeFormatter.ofPattern(player.parseToPlain("EVENT_TIME_FORMAT")); + DateTimeFormatter format = DateTimeFormatter.ofPattern(sender.parseToPlain("EVENT_TIME_FORMAT")); for(EventFight fight : EventFight.getEvent(currentEvent.getEventID())){ Team blue = Team.get(fight.getTeamBlue()); Team red = Team.get(fight.getTeamRed()); - StringBuilder fline = new StringBuilder(player.parseToLegacy("EVENT_CURRENT_FIGHT", fight.getStartTime().toLocalDateTime().format(format), blue.getTeamColor(), blue.getTeamKuerzel(), red.getTeamColor(), red.getTeamKuerzel())); + StringBuilder fline = new StringBuilder(sender.parseToLegacy("EVENT_CURRENT_FIGHT", fight.getStartTime().toLocalDateTime().format(format), blue.getTeamColor(), blue.getTeamKuerzel(), red.getTeamColor(), red.getTeamKuerzel())); if(fight.hasFinished()){ switch(fight.getErgebnis()){ case 1: - fline.append(player.parseToLegacy("EVENT_CURRENT_FIGHT_WIN", blue.getTeamColor(), blue.getTeamKuerzel())); + fline.append(sender.parseToLegacy("EVENT_CURRENT_FIGHT_WIN", blue.getTeamColor(), blue.getTeamKuerzel())); break; case 2: - fline.append(player.parseToLegacy("EVENT_CURRENT_FIGHT_WIN", red.getTeamColor(), red.getTeamKuerzel())); + fline.append(sender.parseToLegacy("EVENT_CURRENT_FIGHT_WIN", red.getTeamColor(), red.getTeamKuerzel())); break; default: - fline.append(player.parseToLegacy("EVENT_CURRENT_FIGHT_DRAW")); + fline.append(sender.parseToLegacy("EVENT_CURRENT_FIGHT_DRAW")); } } - player.prefixless("PLAIN_STRING", fline.toString()); + sender.prefixless("PLAIN_STRING", fline.toString()); } } @Register - public void eventWithTeam(@Validator(value = "noEvent", invert = true) ProxiedPlayer player, @ErrorMessage("EVENT_NO_TEAM") Team team) { - Chatter sender = Chatter.of(player); + public void eventWithTeam(@Validator(value = "noEvent", invert = true) PlayerChatter sender, @ErrorMessage("EVENT_NO_TEAM") Team team) { Subserver eventArena = EventStarter.getEventServer().get(team.getTeamId()); if(eventArena == null || !Subserver.getServerList().contains(eventArena)){ sender.system("EVENT_NO_FIGHT_TEAM"); return; } if (!PunishmentCommand.isPunishedWithMessage(sender, Punishment.PunishmentType.NoFightServer)) { - SubserverSystem.sendPlayer(eventArena, player); + SubserverSystem.sendPlayer(eventArena, sender.getPlayer()); } } } diff --git a/src/de/steamwar/bungeecore/commands/EventRescheduleCommand.java b/src/de/steamwar/bungeecore/commands/EventRescheduleCommand.java index d2d6538..edb82f7 100644 --- a/src/de/steamwar/bungeecore/commands/EventRescheduleCommand.java +++ b/src/de/steamwar/bungeecore/commands/EventRescheduleCommand.java @@ -25,7 +25,6 @@ import de.steamwar.messages.Chatter; import de.steamwar.sql.Event; import de.steamwar.sql.EventFight; import de.steamwar.sql.Team; -import net.md_5.bungee.api.CommandSender; import java.sql.Timestamp; import java.util.Date; @@ -39,12 +38,10 @@ public class EventRescheduleCommand extends SWCommand { } @Register - public void reschedule(CommandSender sender, Team teamBlue, Team teamRed) { - Chatter player = Chatter.of(sender); - + public void reschedule(Chatter sender, Team teamBlue, Team teamRed) { Event event = Event.get(); if(event == null){ - player.system("EVENTRESCHEDULE_UNKNOWN_TEAM"); + sender.system("EVENTRESCHEDULE_UNKNOWN_TEAM"); return; } @@ -57,13 +54,13 @@ public class EventRescheduleCommand extends SWCommand { continue; if(fight.getTeamBlue() == teamBlue.getTeamId() && fight.getTeamRed() == teamRed.getTeamId()){ - player.system("EVENTRESCHEDULE_STARTING"); + sender.system("EVENTRESCHEDULE_STARTING"); fight.reschedule(); EventFight.loadAllComingFights(); return; } } - player.system("EVENTRESCHEDULE_NO_FIGHT"); + sender.system("EVENTRESCHEDULE_NO_FIGHT"); } } diff --git a/src/de/steamwar/bungeecore/commands/EventreloadCommand.java b/src/de/steamwar/bungeecore/commands/EventreloadCommand.java index 1e419e7..df1e9d4 100644 --- a/src/de/steamwar/bungeecore/commands/EventreloadCommand.java +++ b/src/de/steamwar/bungeecore/commands/EventreloadCommand.java @@ -20,9 +20,9 @@ package de.steamwar.bungeecore.commands; import de.steamwar.bungeecore.listeners.ConnectionListener; -import de.steamwar.sql.EventFight; import de.steamwar.command.SWCommand; -import net.md_5.bungee.api.CommandSender; +import de.steamwar.messages.Chatter; +import de.steamwar.sql.EventFight; public class EventreloadCommand extends SWCommand { public EventreloadCommand() { @@ -30,7 +30,7 @@ public class EventreloadCommand extends SWCommand { } @Register - public void execute(CommandSender sender) { + public void execute(Chatter sender) { EventFight.loadAllComingFights(); } } diff --git a/src/de/steamwar/bungeecore/commands/FightCommand.java b/src/de/steamwar/bungeecore/commands/FightCommand.java index 61e7bb5..76c9dbb 100644 --- a/src/de/steamwar/bungeecore/commands/FightCommand.java +++ b/src/de/steamwar/bungeecore/commands/FightCommand.java @@ -24,6 +24,7 @@ import de.steamwar.bungeecore.inventory.SWInventory; import de.steamwar.bungeecore.inventory.SWItem; import de.steamwar.command.SWCommand; import de.steamwar.messages.Chatter; +import de.steamwar.messages.PlayerChatter; import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.chat.ClickEvent; @@ -58,20 +59,18 @@ public class FightCommand extends SWCommand { sender.sendMessage(ChatMessageType.SYSTEM, start); } - private static boolean alreadyInArena(ProxiedPlayer player){ - Subserver subserver = Subserver.getSubserver(player); + private static boolean alreadyInArena(PlayerChatter sender){ + Subserver subserver = Subserver.getSubserver(sender.getPlayer()); if(subserver != null && subserver.getType() == Servertype.ARENA){ - Chatter.of(player).system("FIGHT_IN_ARENA"); + sender.system("FIGHT_IN_ARENA"); return true; } return false; } - static void createArena(ProxiedPlayer player, String precommand, boolean allowMerging, ArenaMode arenaMode, String map, boolean historic, FightCallback callback) { - Chatter sender = Chatter.of(player); - - if(alreadyInArena(player)) + static void createArena(PlayerChatter sender, String precommand, boolean allowMerging, ArenaMode arenaMode, String map, boolean historic, FightCallback callback) { + if(alreadyInArena(sender)) return; if (arenaMode == null) { @@ -83,13 +82,13 @@ public class FightCommand extends SWCommand { map = arenaMode.getRandomMap(); if (!allowMerging) { - callback.run(player, arenaMode, map); + callback.run(sender, arenaMode, map); } else { - suggestMerging(player, arenaMode, map, callback); + suggestMerging(sender, arenaMode, map, callback); } } - public static void suggestMerging(ProxiedPlayer player, ArenaMode mode, String map, FightCallback declineMerge) { + private static void suggestMerging(PlayerChatter sender, ArenaMode mode, String map, FightCallback declineMerge) { Arenaserver mergable = null; synchronized (Subserver.getServerList()) { for (Subserver subserver : Subserver.getServerList()) { @@ -104,15 +103,14 @@ public class FightCommand extends SWCommand { } if(mergable == null) { - declineMerge.run(player, mode, map); + declineMerge.run(sender, mode, map); return; } - Chatter chatter = Chatter.of(player); - SWInventory inventory = new SWInventory(chatter, 9, new Message("FIGHT_MERGE_TITLE")); + SWInventory inventory = new SWInventory(sender, 9, new Message("FIGHT_MERGE_TITLE")); inventory.addItem(0, new SWItem(new Message("FIGHT_MERGE_DECLINE"), 1), click -> { inventory.close(); - declineMerge.run(player, mode, map); + declineMerge.run(sender, mode, map); }); Arenaserver finalMergable = mergable; SWItem item = new SWItem(new Message("FIGHT_MERGE_INFO", mode.getDisplayName(), finalMergable.getMap()), 11); @@ -120,25 +118,25 @@ public class FightCommand extends SWCommand { inventory.addItem(4, item, click -> {}); inventory.addItem(8, new SWItem(new Message("FIGHT_MERGE_ACCEPT"), 10), click -> { if(Subserver.getServerList().contains(finalMergable)) { - finalMergable.sendPlayer(player); + finalMergable.sendPlayer(sender.getPlayer()); } else { - chatter.system("FIGHT_MERGE_OFFLINE"); - declineMerge.run(player, mode, map); + sender.system("FIGHT_MERGE_OFFLINE"); + declineMerge.run(sender, mode, map); } }); inventory.open(); } @Register - public void fight(@Validator("arenaPlayer") ProxiedPlayer player, @Mapper("nonHistoricArenaMode") @OptionalValue("") @AllowNull ArenaMode arenaMode, @Mapper("arenaMap") @OptionalValue("") @AllowNull String map) { - createArena(player, "/fight ", true, arenaMode, map, false, - (p, mode, m) -> new ServerStarter().arena(mode, m).blueLeader(p).callback( - arena -> Chatter.broadcast().system("FIGHT_BROADCAST", "FIGHT_BROADCAST_HOVER", new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/arena " + arena.getServer().getName()), mode.getDisplayName(), p.getName()) + public void fight(@Validator("arenaPlayer") PlayerChatter sender, @Mapper("nonHistoricArenaMode") @OptionalValue("") @AllowNull ArenaMode arenaMode, @Mapper("arenaMap") @OptionalValue("") @AllowNull String map) { + createArena(sender, "/fight ", true, arenaMode, map, false, + (p, mode, m) -> new ServerStarter().arena(mode, m).blueLeader(p.getPlayer()).callback( + arena -> Chatter.broadcast().system("FIGHT_BROADCAST", "FIGHT_BROADCAST_HOVER", new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/arena " + arena.getServer().getName()), mode.getDisplayName(), p.getPlayer().getName()) ).start() ); } public interface FightCallback { - void run(ProxiedPlayer player, ArenaMode mode, String map); + void run(PlayerChatter player, ArenaMode mode, String map); } } diff --git a/src/de/steamwar/bungeecore/commands/GDPRQuery.java b/src/de/steamwar/bungeecore/commands/GDPRQuery.java index 0158edf..2baf0d4 100644 --- a/src/de/steamwar/bungeecore/commands/GDPRQuery.java +++ b/src/de/steamwar/bungeecore/commands/GDPRQuery.java @@ -1,12 +1,13 @@ package de.steamwar.bungeecore.commands; import de.steamwar.bungeecore.BungeeCore; -import de.steamwar.bungeecore.Message; -import de.steamwar.sql.internal.Statement; -import de.steamwar.sql.SteamwarUser; +import de.steamwar.bungeecore.listeners.ConnectionListener; import de.steamwar.command.SWCommand; +import de.steamwar.messages.Chatter; +import de.steamwar.messages.PlayerChatter; +import de.steamwar.sql.SteamwarUser; +import de.steamwar.sql.internal.Statement; import net.md_5.bungee.BungeeCord; -import net.md_5.bungee.api.connection.ProxiedPlayer; import java.io.*; import java.util.zip.ZipEntry; @@ -15,48 +16,42 @@ import java.util.zip.ZipOutputStream; public class GDPRQuery extends SWCommand { public GDPRQuery() { - super("gdprquery", "bungeecore.softreload"); + super("gdprquery", ConnectionListener.SOFTRELOAD_PERMISSION); } @Register - public void generate(ProxiedPlayer player) { - generate(player, player); + public void generate(PlayerChatter sender) { + generate(sender, sender.user()); } @Register - public void generate(ProxiedPlayer player, ProxiedPlayer forPlayer) { - SteamwarUser user = SteamwarUser.get(forPlayer.getUniqueId()); - if(user == null) { - Message.send("UNKNOWN_PLAYER", player); - return; - } - + public void generate(Chatter sender, SteamwarUser user) { BungeeCord.getInstance().getScheduler().runAsync(BungeeCore.get(), () -> { try { - createZip(player, user); + createZip(sender, user); } catch (IOException e) { throw new SecurityException("Could not create zip", e); } }); } - private void createZip(ProxiedPlayer player, SteamwarUser user) throws IOException { - printUpdate(player, "GDPR_STATUS_WEBSITE"); + private void createZip(Chatter sender, SteamwarUser user) throws IOException { + sender.system("GDPR_STATUS_WEBSITE"); ZipOutputStream out = new ZipOutputStream(new FileOutputStream(user.getUserName() + ".zip")); copy(getClass().getClassLoader().getResourceAsStream("GDPRQueryREADME.md"), out, "README.md"); copy(getClass().getClassLoader().getResourceAsStream("GDPRQueryREADME.md"), out, "README.txt"); - printUpdate(player, "GDPR_STATUS_WORLD"); + sender.system("GDPR_STATUS_WORLD"); copyBauwelt(user, out, "/home/minecraft/userworlds/" + user.getUUID().toString(), "BuildWorld12"); copyBauwelt(user, out, "/home/minecraft/userworlds15/" + user.getId(), "BuildWorld15"); - printUpdate(player, "GDPR_STATUS_INVENTORIES"); + sender.system("GDPR_STATUS_INVENTORIES"); copyPlayerdata(user, out, "/home/minecraft/userworlds", "BuildInventories12"); copyPlayerdata(user, out, "/home/minecraft/userworlds15", "BuildInventories15"); - printUpdate(player, "GDPR_STATUS_DATABASE"); + sender.system("GDPR_STATUS_DATABASE"); sqlCSV(user, out, bannedIPs, "BannedIPs.csv"); sqlCSV(user, out, bauweltMember, "BuildMember.csv"); sqlCSV(user, out, bauweltMembers, "BuildMembers.csv"); @@ -78,11 +73,11 @@ public class GDPRQuery extends SWCommand { schematics(user, out); userConfig(user, out); - printUpdate(player, "GDPR_STATUS_LOGS"); + sender.system("GDPR_STATUS_LOGS"); copyLogs(user, out, new File("/logs"), "logs"); out.close(); - printUpdate(player, "GDPR_STATUS_FINISHED"); + sender.system("GDPR_STATUS_FINISHED"); } private static final Statement bannedIPs = new Statement("SELECT Timestamp, IP FROM BannedUserIPs WHERE UserID = ?"); @@ -233,11 +228,6 @@ public class GDPRQuery extends SWCommand { } } - private void printUpdate(ProxiedPlayer player, String message) { - if (player.isConnected()) - Message.send(message, player); - } - private void copy(File file, ZipOutputStream out, String path) throws IOException { try(FileInputStream in = new FileInputStream(file)) { copy(in, out, path); diff --git a/src/de/steamwar/bungeecore/commands/HelpCommand.java b/src/de/steamwar/bungeecore/commands/HelpCommand.java index 36b9d7e..e46da5a 100644 --- a/src/de/steamwar/bungeecore/commands/HelpCommand.java +++ b/src/de/steamwar/bungeecore/commands/HelpCommand.java @@ -23,7 +23,6 @@ import de.steamwar.bungeecore.Message; import de.steamwar.command.SWCommand; import de.steamwar.messages.Chatter; import net.md_5.bungee.api.chat.ClickEvent; -import net.md_5.bungee.api.connection.ProxiedPlayer; public class HelpCommand extends SWCommand { @@ -32,9 +31,7 @@ public class HelpCommand extends SWCommand { } @Register - public void genericCommand(ProxiedPlayer player) { - Chatter sender = Chatter.of(player); - + public void genericCommand(Chatter sender) { printPage(sender, ClickEvent.Action.RUN_COMMAND, "HELP_LOBBY", "/l", "HELP_BAU", "/build", @@ -48,33 +45,32 @@ public class HelpCommand extends SWCommand { } @Register({"build","world"}) - public void buildWorld(ProxiedPlayer player) { - printPage(Chatter.of(player), "HELP_BAU_GROUP_WORLD_TITLE", "HELP_TNT", "HELP_FIRE", "HELP_FREEZE", "HELP_TPSLIMIT", "HELP_PROTECT", "HELP_RESET"); + public void buildWorld(Chatter sender) { + printPage(sender, "HELP_BAU_GROUP_WORLD_TITLE", "HELP_TNT", "HELP_FIRE", "HELP_FREEZE", "HELP_TPSLIMIT", "HELP_PROTECT", "HELP_RESET"); } @Register({"build","player"}) - public void buildPlayer(ProxiedPlayer player) { - printPage(Chatter.of(player), "HELP_BAU_GROUP_PLAYER_TITLE", "HELP_SPEED", "HELP_NV", "HELP_WV", "HELP_DEBUGSTICK", "HELP_TRACE", "HELP_LOADER"); + public void buildPlayer(Chatter sender) { + printPage(sender, "HELP_BAU_GROUP_PLAYER_TITLE", "HELP_SPEED", "HELP_NV", "HELP_WV", "HELP_DEBUGSTICK", "HELP_TRACE", "HELP_LOADER"); } @Register({"build","worldedit"}) @Register({"build","we"}) @Register({"build","world-edit"}) @Register({"build","edit"}) - public void buildWorldedit(ProxiedPlayer player) { - printPage(Chatter.of(player), "HELP_BAU_GROUP_WE_TITLE", "HELP_WE_POS1", "HELP_WE_POS2", "HELP_WE_COPY", "HELP_WE_PASTE", "HELP_WE_FLOPY", "HELP_WE_FLOPYP", "HELP_WE_ROTATE_90", "HELP_WE_ROTATE_180", "HELP_WE_ROTATE_N90"); + public void buildWorldedit(Chatter sender) { + printPage(sender, "HELP_BAU_GROUP_WE_TITLE", "HELP_WE_POS1", "HELP_WE_POS2", "HELP_WE_COPY", "HELP_WE_PASTE", "HELP_WE_FLOPY", "HELP_WE_FLOPYP", "HELP_WE_ROTATE_90", "HELP_WE_ROTATE_180", "HELP_WE_ROTATE_N90"); } @Register({"build","other"}) - public void buildOther(ProxiedPlayer player) { - Chatter sender = Chatter.of(player); + public void buildOther(Chatter sender) { printPage(sender, "HELP_BAU_GROUP_OTHER_TITLE", "HELP_TESTBLOCK", "HELP_SKULL", "HELP_BAUINFO"); sender.prefixless("HELP_SCHEMSUBMIT", new Message("HELP_SCHEMSUBMIT_HOVER"), new ClickEvent(ClickEvent.Action.OPEN_URL, "https://www.youtube.com/watch?v=9QrQ3UBWveE")); } @Register("build") - public void sendBauHelpGroup(ProxiedPlayer player) { - printPage(Chatter.of(player), ClickEvent.Action.RUN_COMMAND, + public void sendBauHelpGroup(Chatter sender) { + printPage(sender, ClickEvent.Action.RUN_COMMAND, "HELP_BAU_GROUP_ADMIN", "/help build admin", "HELP_BAU_GROUP_WORLD", "/help build world", "HELP_BAU_GROUP_PLAYER", "/help build player", @@ -86,8 +82,8 @@ public class HelpCommand extends SWCommand { @Register({"build","admin"}) @Register({"build","owner"}) @Register({"build","bauwelt"}) - public void sendBauHelp(ProxiedPlayer player) { - printPage(Chatter.of(player), ClickEvent.Action.SUGGEST_COMMAND, + public void sendBauHelp(Chatter sender) { + printPage(sender, ClickEvent.Action.SUGGEST_COMMAND, "HELP_BAU_TP", "/build tp ", "HELP_BAU_ADDMEMBER", "/build addmember ", "HELP_BAU_DELMEMBER", "/build delmember ", diff --git a/src/de/steamwar/bungeecore/commands/HistoricCommand.java b/src/de/steamwar/bungeecore/commands/HistoricCommand.java index e7f7451..c44e042 100644 --- a/src/de/steamwar/bungeecore/commands/HistoricCommand.java +++ b/src/de/steamwar/bungeecore/commands/HistoricCommand.java @@ -23,8 +23,8 @@ import de.steamwar.bungeecore.ArenaMode; import de.steamwar.bungeecore.ServerStarter; import de.steamwar.command.SWCommand; import de.steamwar.messages.Chatter; +import de.steamwar.messages.PlayerChatter; import net.md_5.bungee.api.chat.ClickEvent; -import net.md_5.bungee.api.connection.ProxiedPlayer; public class HistoricCommand extends SWCommand { public HistoricCommand() { @@ -32,9 +32,9 @@ public class HistoricCommand extends SWCommand { } @Register - public void historic(@Validator("arenaPlayer") ProxiedPlayer player, @Mapper("historicArenaMode") @OptionalValue("") @AllowNull ArenaMode arenaMode, @Mapper("arenaMap") @OptionalValue("") @AllowNull String map) { - FightCommand.createArena(player, "/historic ", true, arenaMode, map, true, (p, mode, m) -> new ServerStarter().arena(mode, m).blueLeader(p).callback( - arena -> Chatter.broadcast().system("HISTORIC_BROADCAST", "HISTORIC_BROADCAST_HOVER", new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/arena " + arena.getServer().getName()), mode.getDisplayName(), p.getName()) + public void historic(@Validator("arenaPlayer") PlayerChatter player, @Mapper("historicArenaMode") @OptionalValue("") @AllowNull ArenaMode arenaMode, @Mapper("arenaMap") @OptionalValue("") @AllowNull String map) { + FightCommand.createArena(player, "/historic ", true, arenaMode, map, true, (p, mode, m) -> new ServerStarter().arena(mode, m).blueLeader(p.getPlayer()).callback( + arena -> Chatter.broadcast().system("HISTORIC_BROADCAST", "HISTORIC_BROADCAST_HOVER", new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/arena " + arena.getServer().getName()), mode.getDisplayName(), p.getPlayer().getName()) ).start()); } } diff --git a/src/de/steamwar/bungeecore/commands/IgnoreCommand.java b/src/de/steamwar/bungeecore/commands/IgnoreCommand.java index 47ba16a..2a09460 100644 --- a/src/de/steamwar/bungeecore/commands/IgnoreCommand.java +++ b/src/de/steamwar/bungeecore/commands/IgnoreCommand.java @@ -23,7 +23,6 @@ import de.steamwar.command.SWCommand; import de.steamwar.messages.Chatter; import de.steamwar.sql.IgnoreSystem; import de.steamwar.sql.SteamwarUser; -import net.md_5.bungee.api.connection.ProxiedPlayer; public class IgnoreCommand extends SWCommand { @@ -32,8 +31,7 @@ public class IgnoreCommand extends SWCommand { } @Register(description = "USAGE_IGNORE") - public void genericCommand(ProxiedPlayer p, @ErrorMessage("UNKNOWN_PLAYER") SteamwarUser target) { - Chatter player = Chatter.of(p); + public void genericCommand(Chatter player, @ErrorMessage("UNKNOWN_PLAYER") SteamwarUser target) { SteamwarUser user = player.user(); if(target.equals(user)){ diff --git a/src/de/steamwar/bungeecore/commands/JoinmeCommand.java b/src/de/steamwar/bungeecore/commands/JoinmeCommand.java index aa894e5..3df9bf8 100644 --- a/src/de/steamwar/bungeecore/commands/JoinmeCommand.java +++ b/src/de/steamwar/bungeecore/commands/JoinmeCommand.java @@ -22,8 +22,8 @@ package de.steamwar.bungeecore.commands; import de.steamwar.bungeecore.listeners.ConnectionListener; import de.steamwar.command.SWCommand; import de.steamwar.messages.Chatter; +import de.steamwar.messages.PlayerChatter; import net.md_5.bungee.api.chat.ClickEvent; -import net.md_5.bungee.api.connection.ProxiedPlayer; public class JoinmeCommand extends SWCommand { @@ -32,7 +32,7 @@ public class JoinmeCommand extends SWCommand { } @Register - public void genericCommand(ProxiedPlayer player) { - Chatter.broadcast().system("JOINME_BROADCAST", "JOINME_BROADCAST_HOVER", new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/join " + player.getName()), player, player.getServer().getInfo().getName()); + public void genericCommand(PlayerChatter sender) { + Chatter.broadcast().system("JOINME_BROADCAST", "JOINME_BROADCAST_HOVER", new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/join " + sender.getPlayer().getName()), sender, sender.getPlayer().getServer().getInfo().getName()); } } diff --git a/src/de/steamwar/bungeecore/commands/KickCommand.java b/src/de/steamwar/bungeecore/commands/KickCommand.java index 7a0b873..08176ab 100644 --- a/src/de/steamwar/bungeecore/commands/KickCommand.java +++ b/src/de/steamwar/bungeecore/commands/KickCommand.java @@ -22,7 +22,6 @@ package de.steamwar.bungeecore.commands; import de.steamwar.bungeecore.listeners.ConnectionListener; import de.steamwar.command.SWCommand; import de.steamwar.messages.Chatter; -import net.md_5.bungee.api.CommandSender; import net.md_5.bungee.api.connection.ProxiedPlayer; public class KickCommand extends SWCommand { @@ -32,12 +31,12 @@ public class KickCommand extends SWCommand { } @Register(description = "KICK_USAGE") - public void genericCommand(CommandSender sender, @ErrorMessage("KICK_OFFLINE") ProxiedPlayer target, String... message) { + public void genericCommand(Chatter sender, @ErrorMessage("KICK_OFFLINE") ProxiedPlayer target, String... message) { if (message.length == 0) { Chatter.disconnect(target).system("KICK_NORMAL"); } else { Chatter.disconnect(target).system("KICK_CUSTOM", String.join(" ", message)); } - Chatter.of(sender).system("KICK_CONFIRM", target); + sender.system("KICK_CONFIRM", target); } } diff --git a/src/de/steamwar/bungeecore/commands/ListCommand.java b/src/de/steamwar/bungeecore/commands/ListCommand.java index f1e31af..bba9ff3 100644 --- a/src/de/steamwar/bungeecore/commands/ListCommand.java +++ b/src/de/steamwar/bungeecore/commands/ListCommand.java @@ -62,16 +62,14 @@ public class ListCommand extends SWCommand { } @Register - public void list(CommandSender sender) { - Chatter chatter = Chatter.of(sender); - + public void list(Chatter sender) { TreeMap> playerMap = getCustomTablist(); for (String server : playerMap.navigableKeySet()) { String serverName = server; if (server.equals("Bau")) { - serverName = chatter.parseToLegacy("TABLIST_BAU"); + serverName = sender.parseToLegacy("TABLIST_BAU"); } - chatter.prefixless("LIST_COMMAND", serverName, playerMap.get(server).stream().map(CommandSender::getName).collect(Collectors.joining(", "))); + sender.prefixless("LIST_COMMAND", serverName, playerMap.get(server).stream().map(CommandSender::getName).collect(Collectors.joining(", "))); } } } diff --git a/src/de/steamwar/bungeecore/commands/LocalCommand.java b/src/de/steamwar/bungeecore/commands/LocalCommand.java index ab77eb3..862ba77 100644 --- a/src/de/steamwar/bungeecore/commands/LocalCommand.java +++ b/src/de/steamwar/bungeecore/commands/LocalCommand.java @@ -21,8 +21,7 @@ package de.steamwar.bungeecore.commands; import de.steamwar.bungeecore.listeners.ChatListener; import de.steamwar.command.SWCommand; -import net.md_5.bungee.api.CommandSender; -import net.md_5.bungee.api.connection.ProxiedPlayer; +import de.steamwar.messages.PlayerChatter; public class LocalCommand extends SWCommand { @@ -31,7 +30,7 @@ public class LocalCommand extends SWCommand { } @Register - public void genericCommand(ProxiedPlayer player, String... message) { + public void genericCommand(PlayerChatter player, String... message) { ChatListener.localChat(player, String.join(" ", message)); } } diff --git a/src/de/steamwar/bungeecore/commands/ModCommand.java b/src/de/steamwar/bungeecore/commands/ModCommand.java index 59fd46c..4af186d 100644 --- a/src/de/steamwar/bungeecore/commands/ModCommand.java +++ b/src/de/steamwar/bungeecore/commands/ModCommand.java @@ -27,8 +27,8 @@ import de.steamwar.bungeecore.inventory.SWStreamInv; import de.steamwar.bungeecore.listeners.ConnectionListener; import de.steamwar.command.SWCommand; import de.steamwar.messages.Chatter; +import de.steamwar.messages.PlayerChatter; import de.steamwar.sql.Mod; -import net.md_5.bungee.api.connection.ProxiedPlayer; import java.util.HashMap; import java.util.Map; @@ -45,12 +45,12 @@ public class ModCommand extends SWCommand { public static final Map playerFilterType = new HashMap<>(); @Register - public void mods(ProxiedPlayer p) { - playerFilterType.putIfAbsent(p.getUniqueId(), Mod.ModType.UNKLASSIFIED); - openGui(Chatter.of(p)); + public void mods(PlayerChatter sender) { + playerFilterType.putIfAbsent(sender.getPlayer().getUniqueId(), Mod.ModType.UNKLASSIFIED); + openGui(sender); } - private void openGui(Chatter player) { + private void openGui(PlayerChatter player) { SWStreamInv swStreamInv = new SWStreamInv<>(player, new Message("MOD_COMMAND_GUI_TITLE"), (click, mod) -> openTypeGUI(player, "MOD_COMMAND_CLASSICIATION_GUI", type -> { mod.setModType(type); SWInventory.close(player); @@ -68,7 +68,7 @@ public class ModCommand extends SWCommand { swStreamInv.open(); } - private void openTypeGUI(Chatter player, String title, Consumer function) { + private void openTypeGUI(PlayerChatter player, String title, Consumer function) { SWInventory inv = new SWInventory(player, 9, new Message(title)); inv.addItem(1, new SWItem(new Message("MOD_UNCLASSIFIED"), 8), click -> function.accept(Mod.ModType.UNKLASSIFIED)); @@ -86,39 +86,36 @@ public class ModCommand extends SWCommand { } @Register(value = {"set"},description = "MOD_COMMAND_SET_USAGE") - public void set(ProxiedPlayer p, String modName, Mod.Platform platform, Mod.ModType newModType) { - Chatter player = Chatter.of(p); + public void set(Chatter sender, String modName, Mod.Platform platform, Mod.ModType newModType) { Mod mod = Mod.get(modName, platform); if(mod == null) { - player.system("MOD_COMMAND_NOT_FOUND_IN_DATABASE", modName, platform.name()); + sender.system("MOD_COMMAND_NOT_FOUND_IN_DATABASE", modName, platform.name()); return; } mod.setModType(newModType); - player.system("MOD_CHANGED_TYPE", modName, platform.name(), newModType.name()); + sender.system("MOD_CHANGED_TYPE", modName, platform.name(), newModType.name()); } @Register(value = {"get"},description = "MOD_COMMAND_GET_USAGE") - public void get(ProxiedPlayer p, String modName, Mod.Platform platform) { - Chatter player = Chatter.of(p); + public void get(Chatter sender, String modName, Mod.Platform platform) { Mod mod = Mod.get(modName, platform); if(mod == null) { - player.system("MOD_COMMAND_NOT_FOUND_IN_DATABASE", modName, platform.name()); + sender.system("MOD_COMMAND_NOT_FOUND_IN_DATABASE", modName, platform.name()); return; } - player.system("MOD_COMMAND_INFO", modName, platform.name(), mod.getModType().name()); + sender.system("MOD_COMMAND_INFO", modName, platform.name(), mod.getModType().name()); } @Register(value = {"next"}) - public void next(ProxiedPlayer p) { - Chatter player = Chatter.of(p); + public void next(Chatter sender) { Mod mod = Mod.findFirstMod(); if(mod == null) { - player.system("MOD_NO_MORE_UNCLASSIFIED_MODS"); + sender.system("MOD_NO_MORE_UNCLASSIFIED_MODS"); return; } - player.system("MOD_FOUND_NEXT_MOD", mod.getModName(), mod.getPlatform().name()); + sender.system("MOD_FOUND_NEXT_MOD", mod.getModName(), mod.getPlatform().name()); } } diff --git a/src/de/steamwar/bungeecore/commands/MsgCommand.java b/src/de/steamwar/bungeecore/commands/MsgCommand.java index b25ea63..0816b3b 100644 --- a/src/de/steamwar/bungeecore/commands/MsgCommand.java +++ b/src/de/steamwar/bungeecore/commands/MsgCommand.java @@ -23,6 +23,7 @@ import de.steamwar.bungeecore.listeners.ChatListener; import de.steamwar.command.SWCommand; import de.steamwar.messages.Chatter; import de.steamwar.messages.ChatterGroup; +import de.steamwar.messages.PlayerChatter; import de.steamwar.sql.IgnoreSystem; import net.md_5.bungee.api.connection.ProxiedPlayer; @@ -35,26 +36,25 @@ public class MsgCommand extends SWCommand { } @Register(description = "MSG_USAGE") - public void genericCommand(ProxiedPlayer sender, @ErrorMessage(value = "MSG_OFFLINE") ProxiedPlayer target, @ErrorMessage(value = "MSG_USAGE", allowEAs = false) String... message) { + public void genericCommand(PlayerChatter sender, @ErrorMessage(value = "MSG_OFFLINE") ProxiedPlayer target, @ErrorMessage(value = "MSG_USAGE", allowEAs = false) String... message) { msg(sender, target, message); } - public static void msg(ProxiedPlayer player, ProxiedPlayer target, String[] args) { - Chatter sender = Chatter.of(player); + public static void msg(PlayerChatter sender, ProxiedPlayer target, String[] args) { if(target == null || !target.isConnected()) { sender.system("MSG_OFFLINE"); return; } - if (IgnoreSystem.isIgnored(target.getUniqueId(), player.getUniqueId())) { + if (IgnoreSystem.isIgnored(target.getUniqueId(), sender.user().getUUID())) { sender.system("MSG_IGNORED"); return; } Chatter receiver = Chatter.of(target); ChatListener.sendChat(sender, new ChatterGroup(sender, receiver), "CHAT_MSG", receiver, String.join(" ", args)); - lastChats.put(player, target); - lastChats.put(target, player); + lastChats.put(sender.getPlayer(), target); + lastChats.put(target, sender.getPlayer()); } public static void remove(ProxiedPlayer player){ diff --git a/src/de/steamwar/bungeecore/commands/PingCommand.java b/src/de/steamwar/bungeecore/commands/PingCommand.java index 707eef5..c6342f9 100644 --- a/src/de/steamwar/bungeecore/commands/PingCommand.java +++ b/src/de/steamwar/bungeecore/commands/PingCommand.java @@ -20,8 +20,7 @@ package de.steamwar.bungeecore.commands; import de.steamwar.command.SWCommand; -import de.steamwar.messages.Chatter; -import net.md_5.bungee.api.connection.ProxiedPlayer; +import de.steamwar.messages.PlayerChatter; public class PingCommand extends SWCommand { @@ -30,7 +29,7 @@ public class PingCommand extends SWCommand { } @Register - public void genericCommand(ProxiedPlayer player) { - Chatter.of(player).system("PING_RESPONSE", player.getPing()); + public void genericCommand(PlayerChatter sender) { + sender.system("PING_RESPONSE", sender.getPlayer().getPing()); } } diff --git a/src/de/steamwar/bungeecore/commands/PlaytimeCommand.java b/src/de/steamwar/bungeecore/commands/PlaytimeCommand.java index 6323fb1..a5be015 100644 --- a/src/de/steamwar/bungeecore/commands/PlaytimeCommand.java +++ b/src/de/steamwar/bungeecore/commands/PlaytimeCommand.java @@ -22,7 +22,6 @@ package de.steamwar.bungeecore.commands; import de.steamwar.command.SWCommand; import de.steamwar.messages.Chatter; import de.steamwar.sql.SteamwarUser; -import net.md_5.bungee.api.connection.ProxiedPlayer; import java.text.NumberFormat; @@ -33,12 +32,12 @@ public class PlaytimeCommand extends SWCommand { } @Register - public void genericCommand(ProxiedPlayer player) { - SteamwarUser user = SteamwarUser.get(player.getUniqueId()); + public void genericCommand(Chatter sender) { + SteamwarUser user = sender.user(); NumberFormat format = NumberFormat.getNumberInstance(user.getLocale()); format.setMaximumFractionDigits(2); String formattedText = format.format((user.getOnlinetime() / (double) 3600)); - Chatter.of(player).system("HOURS_PLAYED", formattedText); + sender.system("HOURS_PLAYED", formattedText); } } diff --git a/src/de/steamwar/bungeecore/commands/PollCommand.java b/src/de/steamwar/bungeecore/commands/PollCommand.java index 6cae84d..cb944d9 100644 --- a/src/de/steamwar/bungeecore/commands/PollCommand.java +++ b/src/de/steamwar/bungeecore/commands/PollCommand.java @@ -19,13 +19,11 @@ package de.steamwar.bungeecore.commands; -import de.steamwar.bungeecore.Message; import de.steamwar.bungeecore.listeners.PollSystem; -import de.steamwar.sql.PollAnswer; -import de.steamwar.sql.SteamwarUser; import de.steamwar.command.SWCommand; import de.steamwar.command.TypeValidator; -import net.md_5.bungee.api.connection.ProxiedPlayer; +import de.steamwar.messages.Chatter; +import de.steamwar.sql.PollAnswer; public class PollCommand extends SWCommand { @@ -34,39 +32,33 @@ public class PollCommand extends SWCommand { } @Register - public void genericCommand(ProxiedPlayer player) { - PollSystem.sendPoll(player); + public void genericCommand(Chatter sender) { + PollSystem.sendPoll(sender); } @Register(noTabComplete = true) - public void answerPoll(@Validator ProxiedPlayer player, String answerString) { + public void answerPoll(@Validator Chatter sender, String answerString) { int answer; try { answer = Integer.parseUnsignedInt(answerString); if(answer < 1 || answer > PollSystem.answers()) throw new NumberFormatException(); }catch(NumberFormatException e){ - Message.send("POLL_NO_ANSWER", player); + sender.system("POLL_NO_ANSWER"); return; } - PollAnswer pollAnswer = PollAnswer.get(SteamwarUser.get(player.getUniqueId()).getId()); + PollAnswer pollAnswer = PollAnswer.get(sender.user().getId()); if(pollAnswer.hasAnswered()) - Message.send("POLL_ANSWER_REFRESH", player); + sender.system("POLL_ANSWER_REFRESH"); else - Message.send("POLL_ANSWER_NEW", player); + sender.system("POLL_ANSWER_NEW"); pollAnswer.setAnswer(answer); } - @ClassValidator(value = ProxiedPlayer.class, local = true) - public TypeValidator noPoll() { - return (sender, value, messageSender) -> { - if(PollSystem.noCurrentPoll()){ - messageSender.send("POLL_NO_POLL"); - return false; - } - return true; - }; + @ClassValidator(value = Chatter.class, local = true) + public TypeValidator noPoll() { + return PollSystem.noPoll(); } } diff --git a/src/de/steamwar/bungeecore/commands/PollresultCommand.java b/src/de/steamwar/bungeecore/commands/PollresultCommand.java index 4e62b4c..9b4d082 100644 --- a/src/de/steamwar/bungeecore/commands/PollresultCommand.java +++ b/src/de/steamwar/bungeecore/commands/PollresultCommand.java @@ -19,13 +19,12 @@ package de.steamwar.bungeecore.commands; -import de.steamwar.bungeecore.Message; import de.steamwar.bungeecore.listeners.ConnectionListener; import de.steamwar.bungeecore.listeners.PollSystem; -import de.steamwar.sql.PollAnswer; import de.steamwar.command.SWCommand; import de.steamwar.command.TypeValidator; -import net.md_5.bungee.api.connection.ProxiedPlayer; +import de.steamwar.messages.Chatter; +import de.steamwar.sql.PollAnswer; import java.util.Map; @@ -36,22 +35,16 @@ public class PollresultCommand extends SWCommand { } @Register - public void genericCommand(@Validator ProxiedPlayer player) { + public void genericCommand(@Validator Chatter sender) { Map voted = PollAnswer.getCurrentResults(); - Message.send("POLLRESULT_HEADER", player, voted.values().stream().reduce(Integer::sum).orElse(0), PollAnswer.getCurrentPoll()); + sender.system("POLLRESULT_HEADER", voted.values().stream().reduce(Integer::sum).orElse(0), PollAnswer.getCurrentPoll()); for (Map.Entry e: voted.entrySet()) { - Message.send("POLLRESULT_LIST", player, PollSystem.getAnswer(e.getKey()), e.getValue()); + sender.prefixless("POLLRESULT_LIST", PollSystem.getAnswer(e.getKey()), e.getValue()); } } - @ClassValidator(value = ProxiedPlayer.class, local = true) - public TypeValidator noPoll() { - return (sender, value, messageSender) -> { - if (PollSystem.noCurrentPoll()) { - messageSender.send("POLL_NO_POLL"); - return false; - } - return true; - }; + @ClassValidator(value = Chatter.class, local = true) + public TypeValidator noPoll() { + return PollSystem.noPoll(); } } diff --git a/src/de/steamwar/bungeecore/commands/PunishmentCommand.java b/src/de/steamwar/bungeecore/commands/PunishmentCommand.java index d279492..44f5855 100644 --- a/src/de/steamwar/bungeecore/commands/PunishmentCommand.java +++ b/src/de/steamwar/bungeecore/commands/PunishmentCommand.java @@ -54,7 +54,6 @@ import java.util.stream.Collectors; public class PunishmentCommand { private static final String API_URL = "https://api.mojang.com/users/profiles/minecraft/"; - private static final JsonParser jsonParser = new JsonParser(); public static SteamwarUser getOrCreateOfflinePlayer(String name) { SteamwarUser user = SteamwarUser.get(name); @@ -73,7 +72,7 @@ public class PunishmentCommand { private static UUID getUUIDofOfflinePlayer(String playerName) { try { final URL url = new URL(API_URL + playerName); - String uuid = jsonParser.parse(new Scanner(url.openConnection().getInputStream()).nextLine()).getAsJsonObject().get("id").getAsString(); + String uuid = JsonParser.parseString(new Scanner(url.openConnection().getInputStream()).nextLine()).getAsJsonObject().get("id").getAsString(); return UUID.fromString(uuid.replaceFirst("(\\w{8})(\\w{4})(\\w{4})(\\w{4})(\\w{12})", "$1-$2-$3-$4-$5")); } catch (NoSuchElementException e) { // ignore, player does not exist @@ -93,8 +92,6 @@ public class PunishmentCommand { } public static void ban(SteamwarUser user, Timestamp time, String banReason, SteamwarUser punisher, boolean perma) { - user.punish(Punishment.PunishmentType.Ban, time, banReason, punisher.getId(), perma); - ProxiedPlayer player = ProxyServer.getInstance().getPlayer(user.getUUID()); if (player != null) { String ip = IPSanitizer.getTrueAddress(player.getPendingConnection()).getHostAddress(); @@ -119,94 +116,17 @@ public class PunishmentCommand { } public PunishmentCommand(String command, Punishment.PunishmentType punishmentType) { - new SWCommand(command, ConnectionListener.BAN_PERMISSION) { + new PunishCommand(command, punishmentType); - @Register - public void genericCommand(ProxiedPlayer player, @Mapper("toPunish") String toPunish, String date, @ErrorMessage(allowEAs = false, value = "PUNISHMENT_USAGE_REASON") String... message) { - SteamwarUser punisher = SteamwarUser.get(player.getUniqueId()); - if (punishmentType.isNeedsAdmin() && !punisher.hasPerm(UserPerm.MODERATION)) { - return; - } + if (punishmentType.getUnpunishmentMessage() == null) + return; - SteamwarUser target = unsafeUser(player, toPunish); - if (target == null) - return; - - Timestamp banTime = parseTime(player, date); - if (banTime == null) - return; - - boolean isPerma = date.equalsIgnoreCase("perma"); - String msg = String.join(" ", message); - if(punishmentType == Punishment.PunishmentType.Ban) - ban(target, banTime, msg, punisher, isPerma); - else - target.punish(punishmentType, banTime, msg, punisher.getId(), isPerma); - Chatter.serverteam().system(punishmentType.getTeamMessage(), new Message("PREFIX"), target.getUserName(), player.getName(), new Message((isPerma ? "PUNISHMENT_PERMA" : "PUNISHMENT_UNTIL"), banTime), msg); - } - - @Register - public void genericError(ProxiedPlayer player, String... args) { - Chatter.of(player).send(true, ChatMessageType.CHAT, null, null, new Message("PUNISHMENT_USAGE", command)); - } - - @Mapper(value = "toPunish", local = true) - public TypeMapper allUsers() { - return new TypeMapper() { - @Override - public String map(CommandSender commandSender, String[] previousArguments, String s) { - return s; - } - - @Override - public Collection tabCompletes(CommandSender sender, PreviousArguments previousArguments, String s) { - List players = BungeeCord.getInstance().getPlayers().stream() - .map(CommandSender::getName) - .collect(Collectors.toList()); - players.add(s); - return players; - } - }; - } - }; - - if (punishmentType.getUnpunishmentMessage() == null) return; - String antiCommand = "un" + command; - new SWCommand(antiCommand, ConnectionListener.BAN_PERMISSION) { - @Register - public void genericCommand(ProxiedPlayer player, @ErrorMessage("UNKNOWN_PLAYER") SteamwarUser target) { - if (punishmentType.isNeedsAdmin() && !SteamwarUser.get(player.getUniqueId()).hasPerm(UserPerm.MODERATION)) { - return; - } - - if (!target.isPunished(punishmentType)) { - Message.send(punishmentType.getUsageNotPunished(), player); - return; - } - - Message.send(punishmentType.getUnpunishmentMessage(), player, target.getUserName()); - target.punish(punishmentType, Timestamp.from(new Date().toInstant()), antiCommand, SteamwarUser.get(player.getName()).getId(), false); - if(punishmentType == Punishment.PunishmentType.Ban) - BannedUserIPs.unbanIPs(target.getId()); - } - - @Register - public void genericError(ProxiedPlayer player, String... args) { - Chatter.of(player).send(true, ChatMessageType.CHAT, null, null, new Message("UNPUNISHMENT_USAGE", antiCommand)); - } - }; + new UnpunishCommand("un" + command, punishmentType); } - protected SteamwarUser unsafeUser(CommandSender sender, String arg){ - SteamwarUser target = getOrCreateOfflinePlayer(arg); - if(target == null) - Message.send("UNKNOWN_PLAYER", sender); - return target; - } + private static final Pattern RELATIVE_PATTERN = Pattern.compile("([1-9]\\d*[hdwmy])+"); - private static Pattern RELATIVE_PATTERN = Pattern.compile("([1-9]\\d*[hdwmy])+"); - - public static Timestamp parseTime(CommandSender sender, String arg) { + public static Timestamp parseTime(Chatter player, String arg) { if (arg.equalsIgnoreCase("perma")) { return Punishment.PERMA_TIME; } else { @@ -251,12 +171,109 @@ public class PunishmentCommand { Date parsedDate = dateFormat.parse(arg.split("_")[0]); return new java.sql.Timestamp(parsedDate.getTime()); } catch (ParseException exception) { - if (sender != null) { - Message.send("INVALID_TIME", sender); - } + player.system("INVALID_TIME"); return null; } } } } + + private static class PunishCommand extends SWCommand { + + private final String command; + private final Punishment.PunishmentType punishmentType; + + private PunishCommand(String command, Punishment.PunishmentType punishmentType) { + super(command, ConnectionListener.BAN_PERMISSION); + this.command = command; + this.punishmentType = punishmentType; + } + + private SteamwarUser unsafeUser(Chatter sender, String arg) { + SteamwarUser target = getOrCreateOfflinePlayer(arg); + if(target == null) + sender.system("UNKNOWN_PLAYER"); + return target; + } + + @Register + public void genericCommand(Chatter sender, @Mapper("toPunish") String toPunish, String date, @ErrorMessage(allowEAs = false, value = "PUNISHMENT_USAGE_REASON") String... message) { + SteamwarUser punisher = sender.user(); + if (punishmentType.isNeedsAdmin() && !punisher.hasPerm(UserPerm.MODERATION)) + return; + + SteamwarUser target = unsafeUser(sender, toPunish); + if (target == null) + return; + + Timestamp banTime = parseTime(sender, date); + if (banTime == null) + return; + + boolean isPerma = date.equalsIgnoreCase("perma"); + String msg = String.join(" ", message); + target.punish(punishmentType, banTime, msg, punisher.getId(), isPerma); + if(punishmentType == Punishment.PunishmentType.Ban) + ban(target, banTime, msg, punisher, isPerma); + Chatter.serverteam().system(punishmentType.getTeamMessage(), new Message("PREFIX"), target, sender, new Message((isPerma ? "PUNISHMENT_PERMA" : "PUNISHMENT_UNTIL"), banTime), msg); + } + + @Register + public void genericError(Chatter sender, String... args) { + sender.send(true, ChatMessageType.CHAT, null, null, new Message("PUNISHMENT_USAGE", command)); + } + + @Mapper(value = "toPunish", local = true) + public TypeMapper allUsers() { + return new TypeMapper() { + @Override + public String map(Chatter sender, PreviousArguments previousArguments, String s) { + return s; + } + + @Override + public Collection tabCompletes(Chatter sender, PreviousArguments previousArguments, String s) { + List players = BungeeCord.getInstance().getPlayers().stream() + .map(CommandSender::getName) + .collect(Collectors.toList()); + players.add(s); + return players; + } + }; + } + } + + private static class UnpunishCommand extends SWCommand { + + private final String command; + private final Punishment.PunishmentType punishmentType; + + private UnpunishCommand(String command, Punishment.PunishmentType punishmentType) { + super(command, ConnectionListener.BAN_PERMISSION); + this.command = command; + this.punishmentType = punishmentType; + } + + @Register + public void genericCommand(Chatter sender, @ErrorMessage("UNKNOWN_PLAYER") SteamwarUser target) { + if (punishmentType.isNeedsAdmin() && !sender.user().hasPerm(UserPerm.MODERATION)) + return; + + if (!target.isPunished(punishmentType)) { + sender.system(punishmentType.getUsageNotPunished()); + return; + } + + target.punish(punishmentType, Timestamp.from(new Date().toInstant()), command, sender.user().getId(), false); + if(punishmentType == Punishment.PunishmentType.Ban) + BannedUserIPs.unbanIPs(target.getId()); + + sender.system(punishmentType.getUnpunishmentMessage(), target.getUserName()); + } + + @Register + public void genericError(Chatter sender, String... args) { + sender.send(true, ChatMessageType.CHAT, null, null, new Message("UNPUNISHMENT_USAGE", command)); + } + } } diff --git a/src/de/steamwar/bungeecore/commands/TypeMappers.java b/src/de/steamwar/bungeecore/commands/TypeMappers.java index 549f197..d2efdb9 100644 --- a/src/de/steamwar/bungeecore/commands/TypeMappers.java +++ b/src/de/steamwar/bungeecore/commands/TypeMappers.java @@ -24,6 +24,7 @@ import de.steamwar.command.SWCommandUtils; import de.steamwar.command.TypeMapper; import de.steamwar.command.TypeValidator; import de.steamwar.messages.Chatter; +import de.steamwar.messages.PlayerChatter; import de.steamwar.sql.Punishment; import lombok.experimental.UtilityClass; import net.md_5.bungee.api.CommandSender; @@ -41,15 +42,8 @@ public class TypeMappers { SWCommandUtils.addMapper("arenaMap", arenaMapTypeMapper()); } - private static TypeValidator arenaPlayer() { - return (sender, value, messageSender) -> { - Chatter player = Chatter.of(value); - if (PunishmentCommand.isPunishedWithMessage(player, Punishment.PunishmentType.NoFightServer)) { - return false; - } - - return true; - }; + private static TypeValidator arenaPlayer() { + return (sender, player, messageSender) -> !PunishmentCommand.isPunishedWithMessage(player, Punishment.PunishmentType.NoFightServer); } private static TypeMapper arenaModeTypeMapper(boolean historic) { diff --git a/src/de/steamwar/bungeecore/inventory/SWInventory.java b/src/de/steamwar/bungeecore/inventory/SWInventory.java index a100f2d..5102444 100644 --- a/src/de/steamwar/bungeecore/inventory/SWInventory.java +++ b/src/de/steamwar/bungeecore/inventory/SWInventory.java @@ -66,6 +66,7 @@ public class SWInventory { addItem(pos, item, new ArrayList<>(), callback); } + @Deprecated public void addItem(int pos, SWItem item, List lore, InvCallback callback) { item.setCallback(callback); item.setLore(lore); diff --git a/src/de/steamwar/bungeecore/listeners/ChatListener.java b/src/de/steamwar/bungeecore/listeners/ChatListener.java index 7270165..fc14d03 100644 --- a/src/de/steamwar/bungeecore/listeners/ChatListener.java +++ b/src/de/steamwar/bungeecore/listeners/ChatListener.java @@ -26,6 +26,7 @@ import de.steamwar.bungeecore.network.NetworkSender; import de.steamwar.bungeecore.util.Chat19; import de.steamwar.messages.Chatter; import de.steamwar.messages.ChatterGroup; +import de.steamwar.messages.PlayerChatter; import de.steamwar.network.packets.server.PingPacket; import de.steamwar.sql.*; import net.md_5.bungee.api.ChatColor; @@ -122,20 +123,19 @@ public class ChatListener extends BasicListener { } } - public static void localChat(ProxiedPlayer player, String message) { - Chatter sender = Chatter.of(player); + public static void localChat(PlayerChatter sender, String message) { if(message.length() == 0){ sender.system("CHAT_BC_USAGE"); return; } - if(ChatListener.filteredCommand(player, message)) + if(ChatListener.filteredCommand(sender.getPlayer(), message)) return; if(!message.startsWith("/") && chatFilter(sender, message)) return; - Chat19.chat(player, message); + Chat19.chat(sender.getPlayer(), message); } private static boolean chatFilter(Chatter sender, String message) { diff --git a/src/de/steamwar/bungeecore/listeners/PollSystem.java b/src/de/steamwar/bungeecore/listeners/PollSystem.java index b0bf952..4814c64 100644 --- a/src/de/steamwar/bungeecore/listeners/PollSystem.java +++ b/src/de/steamwar/bungeecore/listeners/PollSystem.java @@ -20,10 +20,10 @@ package de.steamwar.bungeecore.listeners; import de.steamwar.bungeecore.Message; +import de.steamwar.command.TypeValidator; +import de.steamwar.messages.Chatter; import de.steamwar.sql.PollAnswer; -import de.steamwar.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; @@ -47,29 +47,37 @@ public class PollSystem extends BasicListener { @EventHandler public void onPostLogin(PostLoginEvent event){ - ProxiedPlayer player = event.getPlayer(); - SteamwarUser user = SteamwarUser.get(player.getUniqueId()); + Chatter player = Chatter.of(event.getPlayer()); - PollAnswer answer = PollAnswer.get(user.getId()); + PollAnswer answer = PollAnswer.get(player.user().getId()); if(answer.hasAnswered()) return; sendPoll(player); } - public static void sendPoll(ProxiedPlayer player){ - Message.send("POLL_HEADER", player); - Message.sendPrefixless("POLL_HEADER2", player); - Message.sendPrefixless("POLL_QUESTION", player, question); + public static void sendPoll(Chatter player) { + player.system("POLL_HEADER"); + player.prefixless("POLL_HEADER2"); + player.prefixless("POLL_QUESTION", question); - for(int i = 1; i <= answers.size(); i++){ - Message.send("POLL_ANWSER", player, Message.parse("POLL_ANWSER_HOVER", player, answers.get(i-1)), - new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/poll " + i), answers.get(i-1)); + for(int i = 1; i <= answers.size(); i++) { + player.prefixless("POLL_ANSWER", new Message("POLL_ANSWER_HOVER", answers.get(i-1)), new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/poll " + i), answers.get(i-1)); } } public static boolean noCurrentPoll(){ - return question == null || question.equals(""); + return question == null || question.isEmpty(); + } + + public static TypeValidator noPoll() { + return (sender, value, messageSender) -> { + if (PollSystem.noCurrentPoll()) { + sender.system("POLL_NO_POLL"); + return false; + } + return true; + }; } public static int answers(){ diff --git a/src/de/steamwar/bungeecore/util/BauLock.java b/src/de/steamwar/bungeecore/util/BauLock.java index fe0a5a4..0007381 100644 --- a/src/de/steamwar/bungeecore/util/BauLock.java +++ b/src/de/steamwar/bungeecore/util/BauLock.java @@ -19,27 +19,22 @@ package de.steamwar.bungeecore.util; -import de.steamwar.bungeecore.Message; import de.steamwar.messages.Chatter; import de.steamwar.sql.SteamwarUser; import de.steamwar.sql.UserConfig; import de.steamwar.sql.UserPerm; import lombok.experimental.UtilityClass; -import net.md_5.bungee.api.ProxyServer; -import net.md_5.bungee.api.connection.ProxiedPlayer; @UtilityClass public class BauLock { private static final String BAU_LOCK_CONFIG_NAME = "baulockstate"; - public static void setLocked(ProxiedPlayer p, BauLockState state) { - SteamwarUser owner = SteamwarUser.get(p.getUniqueId()); - UserConfig.updatePlayerConfig(owner.getId(), BAU_LOCK_CONFIG_NAME, state == BauLockState.OPEN ? null : state.name()); - Message.send("BAU_LOCKED_" + state.name(), p); + public static void setLocked(Chatter owner, BauLockState state) { + UserConfig.updatePlayerConfig(owner.user().getId(), BAU_LOCK_CONFIG_NAME, state == BauLockState.OPEN ? null : state.name()); + owner.system("BAU_LOCKED_" + state.name()); } - public static boolean checkNotifyLocked(SteamwarUser owner, ProxiedPlayer player) { - Chatter sender = Chatter.of(player); + public static boolean checkNotifyLocked(SteamwarUser owner, Chatter sender) { SteamwarUser target = sender.user(); if (owner.getId() == target.getId()) return false; @@ -69,10 +64,7 @@ public class BauLock { if(locked) { sender.system("BAU_LOCKED_NOALLOWED"); - - ProxiedPlayer ownerPlayer = ProxyServer.getInstance().getPlayer(owner.getUUID()); - if(ownerPlayer != null) - Chatter.of(ownerPlayer).system("BAU_LOCK_BLOCKED", player.getName()); + Chatter.of(owner.getUUID()).system("BAU_LOCK_BLOCKED", sender); } return locked; diff --git a/src/de/steamwar/command/CommandRegistering.java b/src/de/steamwar/command/CommandRegistering.java deleted file mode 100644 index b6a4994..0000000 --- a/src/de/steamwar/command/CommandRegistering.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2020 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.steamwar.command; - -import de.steamwar.bungeecore.BungeeCore; -import lombok.experimental.UtilityClass; -import net.md_5.bungee.api.ProxyServer; -import net.md_5.bungee.api.plugin.Command; - -@UtilityClass -class CommandRegistering { - - static void unregister(Command command) { - ProxyServer.getInstance().getPluginManager().unregisterCommand(command); - } - - static void register(Command command) { - ProxyServer.getInstance().getPluginManager().registerCommand(BungeeCore.get(), command); - } -} diff --git a/src/de/steamwar/command/SWCommand.java b/src/de/steamwar/command/SWCommand.java index 536a891..a6a50d9 100644 --- a/src/de/steamwar/command/SWCommand.java +++ b/src/de/steamwar/command/SWCommand.java @@ -23,27 +23,28 @@ import de.steamwar.bungeecore.BungeeCore; import de.steamwar.bungeecore.Message; import de.steamwar.messages.Chatter; 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.connection.ProxiedPlayer; import net.md_5.bungee.api.plugin.Command; import net.md_5.bungee.api.plugin.TabExecutor; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.concurrent.atomic.AtomicInteger; import java.util.function.Supplier; import java.util.logging.Level; -public class SWCommand extends AbstractSWCommand { +public class SWCommand extends AbstractSWCommand { static { TypeUtils.init(); } - private String permission; + private final String permission; private Command command; - private List defaultHelpMessages = new ArrayList<>(); + private final List defaultHelpMessages = new ArrayList<>(); protected SWCommand(String command) { this(command, null); @@ -54,7 +55,7 @@ public class SWCommand extends AbstractSWCommand { } protected SWCommand(String command, String permission, String... aliases) { - super(CommandSender.class, command, aliases); + super(Chatter.class, command, aliases); this.permission = permission; create = true; createAndSafeCommand(command, aliases); @@ -70,12 +71,12 @@ public class SWCommand extends AbstractSWCommand { this.command = new TabCompletableCommand(command, permission, aliases) { @Override public void execute(CommandSender commandSender, String[] strings) { - SWCommand.this.execute(commandSender, null, strings); + SWCommand.this.execute(Chatter.of(commandSender), null, strings); } @Override public Iterable onTabComplete(CommandSender commandSender, String[] strings) { - return SWCommand.this.tabComplete(commandSender, null, strings); + return SWCommand.this.tabComplete(Chatter.of(commandSender), null, strings); } }; } @@ -89,19 +90,19 @@ public class SWCommand extends AbstractSWCommand { @Override public void unregister() { if (command == null) return; - CommandRegistering.unregister(this.command); + ProxyServer.getInstance().getPluginManager().unregisterCommand(this.command); } @Override public void register() { if (command == null) return; - CommandRegistering.register(this.command); + ProxyServer.getInstance().getPluginManager().registerCommand(BungeeCore.get(), this.command); } @Override - protected void commandSystemError(CommandSender sender, CommandFrameworkException e) { + protected void commandSystemError(Chatter sender, CommandFrameworkException e) { BungeeCore.get().getLogger().log(Level.SEVERE, e.getMessage(), e); - Chatter.of(sender).prefixless("COMMAND_SYSTEM_ERROR"); + sender.prefixless("COMMAND_SYSTEM_ERROR"); } @Override @@ -114,16 +115,15 @@ public class SWCommand extends AbstractSWCommand { } @Override - protected void sendMessage(CommandSender sender, String message, Object[] args) { - Chatter.of(sender).system(message, args); + protected void sendMessage(Chatter sender, String message, Object[] args) { + sender.system(message, args); } @Register(noTabComplete = true) - public void internalHelp(ProxiedPlayer p, String... args) { - Chatter chatter = Chatter.of(p); + public void internalHelp(Chatter sender, String... args) { try { - chatter.prefixless("COMMAND_HELP_HEAD", command.getName()); - defaultHelpMessages.forEach(chatter::prefixless); + sender.prefixless("COMMAND_HELP_HEAD", command.getName()); + defaultHelpMessages.forEach(sender::prefixless); } catch (Exception e) { BungeeCore.get().getLogger().log(Level.WARNING, "Failed to send help message", e); return; @@ -131,7 +131,7 @@ public class SWCommand extends AbstractSWCommand { AtomicInteger atomicInteger = new AtomicInteger(); if (args.length != 0) { commandList.forEach(subCommand -> { - List tabCompletes = subCommand.tabComplete(p, args); + List tabCompletes = subCommand.tabComplete(sender, args); if (tabCompletes == null || tabCompletes.isEmpty()) { atomicInteger.incrementAndGet(); return; @@ -139,7 +139,7 @@ public class SWCommand extends AbstractSWCommand { boolean hasTabCompletes = tabCompletes.stream() .anyMatch(s -> s.toLowerCase().startsWith(args[args.length - 1].toLowerCase())); if (hasTabCompletes) { - send(chatter, subCommand); + send(sender, subCommand); } else { atomicInteger.incrementAndGet(); } @@ -147,14 +147,14 @@ public class SWCommand extends AbstractSWCommand { } if (args.length == 0 || atomicInteger.get() == commandList.size()) { commandList.forEach(subCommand -> { - if (subCommand.validator == null || subCommand.validator.validate(p, p, (s, args1) -> {})) { - send(chatter, subCommand); + if (subCommand.validator == null || subCommand.validator.validate(sender, sender, (s, args1) -> {})) { + send(sender, subCommand); } }); } } - private void send(Chatter chatter, SubCommand subCommand) { + private void send(Chatter chatter, SubCommand subCommand) { try { for (String s : subCommand.description) { String hover = "§8/§e" + command.getName() + " " + String.join(" ", subCommand.subCommand); @@ -162,7 +162,7 @@ public class SWCommand extends AbstractSWCommand { chatter.prefixless(s, new Message("PLAIN_STRING", hover), new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, suggest)); } } catch (Exception e) { - BungeeCore.get().getLogger().log(Level.WARNING, "Failed to send description of registered method '" + subCommand.method + "' with description '" + subCommand.description + "'", e); + BungeeCore.get().getLogger().log(Level.WARNING, "Failed to send description of registered method '" + subCommand.method + "' with description '" + Arrays.toString(subCommand.description) + "'", e); } } } diff --git a/src/de/steamwar/command/TypeMapper.java b/src/de/steamwar/command/TypeMapper.java index 1d9cb72..5b59226 100644 --- a/src/de/steamwar/command/TypeMapper.java +++ b/src/de/steamwar/command/TypeMapper.java @@ -19,11 +19,11 @@ package de.steamwar.command; -import net.md_5.bungee.api.CommandSender; +import de.steamwar.messages.Chatter; -public interface TypeMapper extends AbstractTypeMapper { +public interface TypeMapper extends AbstractTypeMapper { /** * The CommandSender can be null! */ - T map(CommandSender commandSender, String[] previousArguments, String s); + T map(Chatter sender, PreviousArguments previousArguments, String s); } diff --git a/src/de/steamwar/command/TypeUtils.java b/src/de/steamwar/command/TypeUtils.java index 2a6d7a7..8b834e5 100644 --- a/src/de/steamwar/command/TypeUtils.java +++ b/src/de/steamwar/command/TypeUtils.java @@ -21,11 +21,11 @@ package de.steamwar.command; import de.steamwar.bungeecore.ServerVersion; import de.steamwar.bungeecore.commands.TypeMappers; +import de.steamwar.messages.Chatter; import de.steamwar.sql.SteamwarUser; import de.steamwar.sql.Team; import lombok.experimental.UtilityClass; import net.md_5.bungee.BungeeCord; -import net.md_5.bungee.api.CommandSender; import net.md_5.bungee.api.connection.ProxiedPlayer; import java.util.Collection; @@ -41,9 +41,10 @@ public class TypeUtils { SWCommandUtils.addMapper(SteamwarUser.class, SWCommandUtils.createMapper(SteamwarUser::get, s -> BungeeCord.getInstance().getPlayers().stream().map(ProxiedPlayer::getName).collect(Collectors.toList()))); SWCommandUtils.addMapper(ServerVersion.class, new TypeMapper() { @Override - public ServerVersion map(CommandSender sender, String[] previousArguments, String s) { - if (sender instanceof ProxiedPlayer && s.isEmpty()) { - int version = ((ProxiedPlayer) sender).getPendingConnection().getVersion(); + public ServerVersion map(Chatter sender, PreviousArguments previousArguments, String s) { + ProxiedPlayer player = sender.getPlayer(); + if(player != null && s.isEmpty()) { + int version = player.getPendingConnection().getVersion(); if (version > 762) { // Version > 1.19.4 return ServerVersion.PAPER_20; } else if (version > 578) { // Version > 1.15.2 @@ -59,7 +60,7 @@ public class TypeUtils { } @Override - public Collection tabCompletes(CommandSender sender, PreviousArguments previousArguments, String s) { + public Collection tabCompletes(Chatter sender, PreviousArguments previousArguments, String s) { return ServerVersion.chatVersions(); } }); diff --git a/src/de/steamwar/command/TypeValidator.java b/src/de/steamwar/command/TypeValidator.java index 6bb76f6..2986b7d 100644 --- a/src/de/steamwar/command/TypeValidator.java +++ b/src/de/steamwar/command/TypeValidator.java @@ -19,7 +19,6 @@ package de.steamwar.command; -import net.md_5.bungee.api.CommandSender; +import de.steamwar.messages.Chatter; -public interface TypeValidator extends AbstractValidator { -} +public interface TypeValidator extends AbstractValidator {} diff --git a/src/de/steamwar/messages/BungeeCore.properties b/src/de/steamwar/messages/BungeeCore.properties index 64c80e4..7f092d6 100644 --- a/src/de/steamwar/messages/BungeeCore.properties +++ b/src/de/steamwar/messages/BungeeCore.properties @@ -569,8 +569,8 @@ EVENTMODE_KICK=§cYou are not an event participant. POLL_HEADER=§e§lPoll POLL_HEADER2=§7Click the answer you like! POLL_QUESTION=§e{0} -POLL_ANWSER=§7{0} -POLL_ANWSER_HOVER=§eChoose {0} +POLL_ANSWER=§7{0} +POLL_ANSWER_HOVER=§eChoose {0} #TablistManager TABLIST_PHASE_WEBSITE=§8Website: https://§eSteam§8War.de diff --git a/src/de/steamwar/messages/BungeeCore_de.properties b/src/de/steamwar/messages/BungeeCore_de.properties index 40a350b..b90367a 100644 --- a/src/de/steamwar/messages/BungeeCore_de.properties +++ b/src/de/steamwar/messages/BungeeCore_de.properties @@ -545,8 +545,8 @@ EVENTMODE_KICK=§cDu bist kein Eventteilnehmer. POLL_HEADER=§e§lUmfrage POLL_HEADER2=§7Klicke die Antwort an, die dir gefällt! POLL_QUESTION=§e{0} -POLL_ANWSER=§7{0} -POLL_ANWSER_HOVER=§e{0} §ewählen +POLL_ANSWER=§7{0} +POLL_ANSWER_HOVER=§e{0} §ewählen #TablistManager TABLIST_PHASE_WEBSITE=§8Website: https://§eSteam§8War.de diff --git a/src/de/steamwar/messages/Chatter.java b/src/de/steamwar/messages/Chatter.java index fc12240..8e9f2c7 100644 --- a/src/de/steamwar/messages/Chatter.java +++ b/src/de/steamwar/messages/Chatter.java @@ -44,8 +44,9 @@ import java.util.Date; import java.util.Locale; import java.util.ResourceBundle; import java.util.UUID; -import java.util.function.BiConsumer; import java.util.function.Consumer; +import java.util.function.Function; +import java.util.function.Supplier; import java.util.logging.Level; import java.util.stream.Stream; @@ -78,11 +79,25 @@ public interface Chatter { Locale getLocale(); boolean chatShown(); - void sendMessage(ChatMessageType type, BaseComponent... msg); - void withPlayerOrDiscord(Consumer withPlayer, Consumer withDiscord); + void sendMessage(ChatMessageType type, BaseComponent msg); + ProxiedPlayer getPlayer(); + default T withPlayerOrOffline(Function withPlayer, Supplier withOffline) { + ProxiedPlayer player = getPlayer(); + if(player == null) + return withOffline.get(); + else + return withPlayer.apply(player); + } + default void withPlayerOrOffline(Consumer withPlayer, Runnable withOffline) { + ProxiedPlayer player = getPlayer(); + if(player == null) + withOffline.run(); + else + withPlayer.accept(player); + } default void withPlayer(Consumer function) { - withPlayerOrDiscord(function, user -> {}); + withPlayerOrOffline(function, () -> {}); } default void chat(Message message) { @@ -164,41 +179,12 @@ public interface Chatter { return TextComponent.fromLegacy(format.format(params)); } - static Chatter ofProxiedPlayer(ProxiedPlayer player, BiConsumer sendMessage) { - return new Chatter() { - @Override - public SteamwarUser user() { - return SteamwarUser.get(player.getUniqueId()); - } - - @Override - public Locale getLocale() { - return user().getLocale(); - } - - @Override - public boolean chatShown() { - return player.getChatMode() == ProxiedPlayer.ChatMode.SHOWN; - } - - @Override - public void sendMessage(ChatMessageType type, BaseComponent... msg) { - sendMessage.accept(type, msg); - } - - @Override - public void withPlayerOrDiscord(Consumer withPlayer, Consumer withDiscord) { - withPlayer.accept(player); - } - }; + static PlayerChatter of(ProxiedPlayer player) { + return new PlayerChatter(player, player::sendMessage); } - static Chatter of(ProxiedPlayer player) { - return ofProxiedPlayer(player, player::sendMessage); - } - - static Chatter disconnect(ProxiedPlayer player) { - return ofProxiedPlayer(player, (type, msg) -> player.disconnect(msg)); + static PlayerChatter disconnect(ProxiedPlayer player) { + return new PlayerChatter(player, (type, msg) -> player.disconnect(msg)); } static Chatter of(CommandSender sender) { @@ -218,12 +204,16 @@ public interface Chatter { } @Override - public void sendMessage(ChatMessageType type, BaseComponent... msg) { + public void sendMessage(ChatMessageType type, BaseComponent msg) { sender.sendMessage(msg); } }; } + static Chatter of(SteamwarUser user) { + return of(user.getUUID()); + } + static Chatter of(UUID uuid) { ProxiedPlayer player = ProxyServer.getInstance().getPlayer(uuid); if(player != null) @@ -241,7 +231,7 @@ public interface Chatter { } @Override - public void sendMessage(ChatMessageType type, BaseComponent... msg) { + public void sendMessage(ChatMessageType type, BaseComponent msg) { // Nowhere to send } }; @@ -264,8 +254,9 @@ public interface Chatter { } @Override - public void sendMessage(ChatMessageType type, BaseComponent... msg) { - event.setCancelReason(msg); + public void sendMessage(ChatMessageType type, BaseComponent msg) { + event.setReason(msg); + event.setCancelled(true); } }; } @@ -283,9 +274,9 @@ public interface Chatter { } @Override - public void sendMessage(ChatMessageType type, BaseComponent... msg) { + public void sendMessage(ChatMessageType type, BaseComponent msg) { try { - channel.send(" " + new TextComponent(msg).toPlainText()); + channel.send(" " + msg.toPlainText()); } catch (Exception e) { BungeeCore.get().getLogger().log(Level.SEVERE, "Could not send chat message to discord", e); } @@ -306,7 +297,7 @@ public interface Chatter { } @Override - public void sendMessage(ChatMessageType type, BaseComponent... msg) { + public void sendMessage(ChatMessageType type, BaseComponent msg) { try { message.delete().queue(); } catch (Exception e) { @@ -319,12 +310,12 @@ public interface Chatter { abstract class PlayerlessChatter implements Chatter { @Override public Locale getLocale() { - return Locale.getDefault(); + return user().getLocale(); } @Override - public void withPlayerOrDiscord(Consumer withPlayer, Consumer withDiscord) { - withDiscord.accept(user()); + public ProxiedPlayer getPlayer() { + return ProxyServer.getInstance().getPlayer(user().getUUID()); } } } diff --git a/src/de/steamwar/messages/ChatterGroup.java b/src/de/steamwar/messages/ChatterGroup.java index ebdd92a..d2d5289 100644 --- a/src/de/steamwar/messages/ChatterGroup.java +++ b/src/de/steamwar/messages/ChatterGroup.java @@ -27,11 +27,10 @@ import net.md_5.bungee.api.chat.BaseComponent; import net.md_5.bungee.api.chat.ClickEvent; import java.util.Arrays; -import java.util.Locale; import java.util.stream.Stream; @Getter -public class ChatterGroup implements Chatter { +public class ChatterGroup extends Chatter.PlayerlessChatter { final Chatter[] chatters; @@ -60,12 +59,7 @@ public class ChatterGroup implements Chatter { } @Override - public Locale getLocale() { - throw new UnsupportedOperationException(); - } - - @Override - public void sendMessage(ChatMessageType type, BaseComponent... msg) { + public void sendMessage(ChatMessageType type, BaseComponent msg) { throw new UnsupportedOperationException(); } } diff --git a/src/de/steamwar/messages/PlayerChatter.java b/src/de/steamwar/messages/PlayerChatter.java new file mode 100644 index 0000000..b2720d6 --- /dev/null +++ b/src/de/steamwar/messages/PlayerChatter.java @@ -0,0 +1,61 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2024 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.messages; + +import de.steamwar.sql.SteamwarUser; +import lombok.AllArgsConstructor; +import net.md_5.bungee.api.ChatMessageType; +import net.md_5.bungee.api.chat.BaseComponent; +import net.md_5.bungee.api.connection.ProxiedPlayer; + +import java.util.Locale; +import java.util.function.BiConsumer; + +@AllArgsConstructor +public class PlayerChatter implements Chatter { + + private final ProxiedPlayer player; + private final BiConsumer sendMessage; + + @Override + public SteamwarUser user() { + return SteamwarUser.get(player.getUniqueId()); + } + + @Override + public Locale getLocale() { + return user().getLocale(); + } + + @Override + public boolean chatShown() { + return player.getChatMode() == ProxiedPlayer.ChatMode.SHOWN; + } + + @Override + public void sendMessage(ChatMessageType type, BaseComponent msg) { + sendMessage.accept(type, msg); + } + + @Override + public ProxiedPlayer getPlayer() { + return player; + } +}