From ae2a1d5779ebd65b4ed5f61cba1f01037c3bda9b Mon Sep 17 00:00:00 2001 From: yoyosource Date: Tue, 14 Jun 2022 20:10:07 +0200 Subject: [PATCH 1/4] Update ArenaCommand --- .../bungeecore/commands/ArenaCommand.java | 20 ++++++++----------- 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/src/de/steamwar/bungeecore/commands/ArenaCommand.java b/src/de/steamwar/bungeecore/commands/ArenaCommand.java index 339c66a..929510f 100644 --- a/src/de/steamwar/bungeecore/commands/ArenaCommand.java +++ b/src/de/steamwar/bungeecore/commands/ArenaCommand.java @@ -19,30 +19,26 @@ package de.steamwar.bungeecore.commands; -import de.steamwar.bungeecore.Message; import de.steamwar.bungeecore.Servertype; import de.steamwar.bungeecore.Subserver; -import net.md_5.bungee.api.CommandSender; +import de.steamwar.command.SWCommand; +import de.steamwar.messages.ChatSender; import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.config.ServerInfo; import net.md_5.bungee.api.connection.ProxiedPlayer; -public class ArenaCommand extends BasicCommand { +public class ArenaCommand extends SWCommand { public ArenaCommand() { - super("arena", null); + super("arena"); } - @Override - public void execute(CommandSender sender, String[] args) { - if(!(sender instanceof ProxiedPlayer)) - return; - ProxiedPlayer player = (ProxiedPlayer) sender; - - ServerInfo server = ProxyServer.getInstance().getServerInfo(String.join(" ", args)); + @Register + public void arenaJoin(ProxiedPlayer player, String... serverInfo) { + ServerInfo server = ProxyServer.getInstance().getServerInfo(String.join(" ", serverInfo)); Subserver subserver = Subserver.getSubserver(server); if(server == null || subserver == null || subserver.getType() != Servertype.ARENA) { - Message.send("ARENA_NOT_FOUND", player); + ChatSender.of(player).system("ARENA_NOT_FOUND"); return; } From 5c55bdacdec610469cb782a162f53d39f4309e4b Mon Sep 17 00:00:00 2001 From: yoyosource Date: Tue, 14 Jun 2022 20:16:36 +0200 Subject: [PATCH 2/4] Add tab completion to ArenaCommand --- .../bungeecore/commands/ArenaCommand.java | 26 +++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/de/steamwar/bungeecore/commands/ArenaCommand.java b/src/de/steamwar/bungeecore/commands/ArenaCommand.java index 929510f..2108fa7 100644 --- a/src/de/steamwar/bungeecore/commands/ArenaCommand.java +++ b/src/de/steamwar/bungeecore/commands/ArenaCommand.java @@ -22,11 +22,16 @@ package de.steamwar.bungeecore.commands; import de.steamwar.bungeecore.Servertype; import de.steamwar.bungeecore.Subserver; import de.steamwar.command.SWCommand; +import de.steamwar.command.TypeMapper; import de.steamwar.messages.ChatSender; +import net.md_5.bungee.api.CommandSender; 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.util.Collection; +import java.util.stream.Collectors; + public class ArenaCommand extends SWCommand { public ArenaCommand() { @@ -34,8 +39,7 @@ public class ArenaCommand extends SWCommand { } @Register - public void arenaJoin(ProxiedPlayer player, String... serverInfo) { - ServerInfo server = ProxyServer.getInstance().getServerInfo(String.join(" ", serverInfo)); + public void arenaJoin(ProxiedPlayer player, ServerInfo server) { Subserver subserver = Subserver.getSubserver(server); if(server == null || subserver == null || subserver.getType() != Servertype.ARENA) { ChatSender.of(player).system("ARENA_NOT_FOUND"); @@ -44,4 +48,22 @@ public class ArenaCommand extends SWCommand { TpCommand.teleport(player, server); } + + @ClassMapper(ServerInfo.class) + public TypeMapper serverInfoTypeMapper() { + return new TypeMapper() { + @Override + public ServerInfo map(CommandSender commandSender, String[] previousArguments, String s) { + return ProxyServer.getInstance().getServerInfo(s); + } + + @Override + public Collection tabCompletes(CommandSender sender, String[] previousArguments, String s) { + return ProxyServer.getInstance().getServersCopy().values().stream().filter(server -> { + Subserver subserver = Subserver.getSubserver(server); + return subserver != null && subserver.getType() == Servertype.ARENA; + }).map(ServerInfo::getName).collect(Collectors.toList()); + } + }; + } } From 183248c0b10c38e1e4920a719f72819f2bc8ebef Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 17 Jul 2022 20:38:59 +0200 Subject: [PATCH 3/4] Update ArenaCommand --- .../bungeecore/commands/ArenaCommand.java | 29 ++++++++++--------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/src/de/steamwar/bungeecore/commands/ArenaCommand.java b/src/de/steamwar/bungeecore/commands/ArenaCommand.java index 2108fa7..b73d6d2 100644 --- a/src/de/steamwar/bungeecore/commands/ArenaCommand.java +++ b/src/de/steamwar/bungeecore/commands/ArenaCommand.java @@ -39,22 +39,25 @@ public class ArenaCommand extends SWCommand { } @Register - public void arenaJoin(ProxiedPlayer player, ServerInfo server) { - Subserver subserver = Subserver.getSubserver(server); - if(server == null || subserver == null || subserver.getType() != Servertype.ARENA) { - ChatSender.of(player).system("ARENA_NOT_FOUND"); - return; - } - - TpCommand.teleport(player, server); + public void arenaJoin(ProxiedPlayer player, Subserver server) { + TpCommand.teleport(player, server.getServer()); } - @ClassMapper(ServerInfo.class) - public TypeMapper serverInfoTypeMapper() { - return new TypeMapper() { + @ClassMapper(value = ServerInfo.class, local = true) + public TypeMapper serverInfoTypeMapper() { + return new TypeMapper() { @Override - public ServerInfo map(CommandSender commandSender, String[] previousArguments, String s) { - return ProxyServer.getInstance().getServerInfo(s); + public Subserver map(CommandSender commandSender, String[] previousArguments, String s) { + return Subserver.getSubserver(ProxyServer.getInstance().getServerInfo(s)); + } + + @Override + public boolean validate(CommandSender sender, Subserver value, MessageSender messageSender) { + if (value == null || value.getType() != Servertype.ARENA) { + messageSender.send("ARENA_NOT_FOUND"); + return false; + } + return true; } @Override From 8bcefb102c8f17cebb46ad3930d1d8aaf4799654 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Mon, 18 Jul 2022 16:19:48 +0200 Subject: [PATCH 4/4] Update ArenaCommand --- src/de/steamwar/bungeecore/commands/ArenaCommand.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/de/steamwar/bungeecore/commands/ArenaCommand.java b/src/de/steamwar/bungeecore/commands/ArenaCommand.java index b73d6d2..83558ae 100644 --- a/src/de/steamwar/bungeecore/commands/ArenaCommand.java +++ b/src/de/steamwar/bungeecore/commands/ArenaCommand.java @@ -30,6 +30,7 @@ import net.md_5.bungee.api.config.ServerInfo; import net.md_5.bungee.api.connection.ProxiedPlayer; import java.util.Collection; +import java.util.List; import java.util.stream.Collectors; public class ArenaCommand extends SWCommand { @@ -62,10 +63,10 @@ public class ArenaCommand extends SWCommand { @Override public Collection tabCompletes(CommandSender sender, String[] previousArguments, String s) { - return ProxyServer.getInstance().getServersCopy().values().stream().filter(server -> { - Subserver subserver = Subserver.getSubserver(server); - return subserver != null && subserver.getType() == Servertype.ARENA; - }).map(ServerInfo::getName).collect(Collectors.toList()); + List subserverList = Subserver.getServerList(); + synchronized (subserverList) { + return subserverList.stream().filter(subserver -> subserver.getType() == Servertype.ARENA).map(subserver -> subserver.getServer().getName()).collect(Collectors.toList()); + } } }; }