From 3533077c9bfa3d2a16938198e324d08771865783 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaime=20Mart=C3=ADnez=20Rinc=C3=B3n?= Date: Sun, 7 Jan 2018 22:50:08 +0100 Subject: [PATCH] Maybe we don't need custom commands, they will be removed in the next commit --- .../commands/CustomFindCommand.java | 21 ++++++++++++--- .../connection/ServerAssignRegistry.java | 1 - .../listeners/ServerConnectListener.java | 26 ++++++++++++++----- .../playerbalancer/ping/StatusManager.java | 6 +++-- .../features/CustomFindCommandProps.java | 7 +++-- .../props/features/PermissionRouterProps.java | 17 ------------ Main Plugin/src/main/resources/default.conf | 10 ++++--- 7 files changed, 53 insertions(+), 35 deletions(-) diff --git a/Main Plugin/src/main/java/com/jaimemartz/playerbalancer/commands/CustomFindCommand.java b/Main Plugin/src/main/java/com/jaimemartz/playerbalancer/commands/CustomFindCommand.java index d25aa30..ed6868d 100644 --- a/Main Plugin/src/main/java/com/jaimemartz/playerbalancer/commands/CustomFindCommand.java +++ b/Main Plugin/src/main/java/com/jaimemartz/playerbalancer/commands/CustomFindCommand.java @@ -2,9 +2,9 @@ package com.jaimemartz.playerbalancer.commands; import com.jaimemartz.playerbalancer.PlayerBalancer; import com.jaimemartz.playerbalancer.settings.props.features.CustomFindCommandProps; -import net.md_5.bungee.api.ChatColor; +import com.jaimemartz.playerbalancer.utils.MessageUtils; import net.md_5.bungee.api.CommandSender; -import net.md_5.bungee.api.chat.ComponentBuilder; +import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.plugin.Command; public class CustomFindCommand extends Command { @@ -28,6 +28,21 @@ public class CustomFindCommand extends Command { @Override public void execute(CommandSender sender, String[] args) { - sender.sendMessage(new ComponentBuilder("Not implemented yet.").color(ChatColor.RED).create()); + if (args.length == 1) { + ProxiedPlayer player = plugin.getProxy().getPlayer(args[0]); + + if (player != null && player.getServer() != null) { + MessageUtils.send(player, props.getFormats().getResult(), (str) -> + str.replace("{server}", player.getServer().getInfo().getName()) + .replace("{name}", player.getName()) + ); + } else { + MessageUtils.send(player, props.getFormats().getMissing(), (str) -> + str.replace("{name}", player.getName()) + ); + } + } else { + MessageUtils.send(sender, props.getFormats().getUsage()); + } } } diff --git a/Main Plugin/src/main/java/com/jaimemartz/playerbalancer/connection/ServerAssignRegistry.java b/Main Plugin/src/main/java/com/jaimemartz/playerbalancer/connection/ServerAssignRegistry.java index cb9dc2b..8d7ce26 100644 --- a/Main Plugin/src/main/java/com/jaimemartz/playerbalancer/connection/ServerAssignRegistry.java +++ b/Main Plugin/src/main/java/com/jaimemartz/playerbalancer/connection/ServerAssignRegistry.java @@ -8,7 +8,6 @@ import net.md_5.bungee.api.connection.ProxiedPlayer; import java.util.Map; -//todo improve this public class ServerAssignRegistry { private static final Table table = HashBasedTable.create(); diff --git a/Main Plugin/src/main/java/com/jaimemartz/playerbalancer/listeners/ServerConnectListener.java b/Main Plugin/src/main/java/com/jaimemartz/playerbalancer/listeners/ServerConnectListener.java index e535aa7..ceedb65 100644 --- a/Main Plugin/src/main/java/com/jaimemartz/playerbalancer/listeners/ServerConnectListener.java +++ b/Main Plugin/src/main/java/com/jaimemartz/playerbalancer/listeners/ServerConnectListener.java @@ -15,7 +15,7 @@ import net.md_5.bungee.api.plugin.Listener; import net.md_5.bungee.event.EventHandler; import net.md_5.bungee.event.EventPriority; -import java.util.Optional; +import java.util.Map; public class ServerConnectListener implements Listener { private final PlayerBalancer plugin; @@ -64,17 +64,29 @@ public class ServerConnectListener implements Listener { if (section != null) { if (permissionRouterProps.isEnabled()) { - Optional bindName = permissionRouterProps.getRouteBind(player, section); - if (bindName.isPresent()) { - ServerSection bind = plugin.getSectionManager().getByName(bindName.get()); - if (bind != null) { - return bind; + Map routes = permissionRouterProps.getRules().get(section.getName()); + + if (routes != null) { + for (Map.Entry route : routes.entrySet()) { + if (player.hasPermission(route.getKey())) { + ServerSection bind = plugin.getSectionManager().getByName(route.getValue()); + ServerSection current = plugin.getSectionManager().getByPlayer(player); + + if (bind != null) { + if (current == bind) + break; + + return bind; + } + + break; + } } } } //Checks only for servers (not the section server) - if (section.getServers().contains(target)) { + if (!target.equals(section.getServer())) { if (plugin.getSectionManager().isDummy(section)) { return null; } diff --git a/Main Plugin/src/main/java/com/jaimemartz/playerbalancer/ping/StatusManager.java b/Main Plugin/src/main/java/com/jaimemartz/playerbalancer/ping/StatusManager.java index df6846f..fdec7ad 100644 --- a/Main Plugin/src/main/java/com/jaimemartz/playerbalancer/ping/StatusManager.java +++ b/Main Plugin/src/main/java/com/jaimemartz/playerbalancer/ping/StatusManager.java @@ -98,8 +98,10 @@ public class StatusManager implements Listener { } public boolean isAccessible(ServerInfo server) { - if (overriders.containsKey(server)) { - return overriders.get(server); + Boolean override = overriders.get(server); + + if (override != null) { + return override; } ServerStatus status = getStatus(server); diff --git a/Main Plugin/src/main/java/com/jaimemartz/playerbalancer/settings/props/features/CustomFindCommandProps.java b/Main Plugin/src/main/java/com/jaimemartz/playerbalancer/settings/props/features/CustomFindCommandProps.java index dc31588..7fc598b 100644 --- a/Main Plugin/src/main/java/com/jaimemartz/playerbalancer/settings/props/features/CustomFindCommandProps.java +++ b/Main Plugin/src/main/java/com/jaimemartz/playerbalancer/settings/props/features/CustomFindCommandProps.java @@ -19,11 +19,14 @@ public class CustomFindCommandProps { @ConfigSerializable @Data - private static class Formats { + public static class Formats { @Setting private String result; @Setting - private String offline; + private String missing; + + @Setting + private String usage; } } diff --git a/Main Plugin/src/main/java/com/jaimemartz/playerbalancer/settings/props/features/PermissionRouterProps.java b/Main Plugin/src/main/java/com/jaimemartz/playerbalancer/settings/props/features/PermissionRouterProps.java index ea1c51f..cb79771 100644 --- a/Main Plugin/src/main/java/com/jaimemartz/playerbalancer/settings/props/features/PermissionRouterProps.java +++ b/Main Plugin/src/main/java/com/jaimemartz/playerbalancer/settings/props/features/PermissionRouterProps.java @@ -1,13 +1,10 @@ package com.jaimemartz.playerbalancer.settings.props.features; -import com.jaimemartz.playerbalancer.section.ServerSection; import lombok.Data; -import net.md_5.bungee.api.connection.ProxiedPlayer; import ninja.leaping.configurate.objectmapping.Setting; import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable; import java.util.Map; -import java.util.Optional; @ConfigSerializable @Data @@ -17,18 +14,4 @@ public class PermissionRouterProps { @Setting private Map> rules; - - public Optional getRouteBind(ProxiedPlayer player, ServerSection section) { - Map routes = rules.get(section.getName()); - - if (routes != null) { - for (Map.Entry route : routes.entrySet()) { - if (player.hasPermission(route.getKey())) { - return Optional.of(route.getValue()); - } - } - } - - return Optional.empty(); - } } diff --git a/Main Plugin/src/main/resources/default.conf b/Main Plugin/src/main/resources/default.conf index 1a5c4fd..3babc3e 100644 --- a/Main Plugin/src/main/resources/default.conf +++ b/Main Plugin/src/main/resources/default.conf @@ -112,7 +112,7 @@ features { dummy-sections=[] # Reiterative sections remember the server the player connected to previously - # The plugin will keep connecting the player to that server until a change occurs + # The plugin will keep connecting the player to that server repeatedly reiterative-sections=[] # When true, section servers will show the sum of the players on all servers on that section @@ -225,6 +225,7 @@ features { custom-find-command { enabled=false + # Leave permission empty for no permission command { name=find permission="" @@ -232,14 +233,16 @@ features { } formats { - result="" - offline="" + result="&a{name} &cis online at &a{server}" + missing="&cThere is no such player named {name}" + usage="&cUsage: /find " } } custom-list-command { enabled=false + # Leave permission empty for no permission command { name=glist permission="" @@ -255,6 +258,7 @@ features { custom-server-command { enabled=false + # Leave permission empty for no permission command { name=server permission=""