Maybe we don't need custom commands, they will be removed in the next commit

This commit is contained in:
Jaime Martínez Rincón 2018-01-07 22:50:08 +01:00
parent f3c10291b8
commit 3533077c9b
7 changed files with 53 additions and 35 deletions

View File

@ -2,9 +2,9 @@ package com.jaimemartz.playerbalancer.commands;
import com.jaimemartz.playerbalancer.PlayerBalancer; import com.jaimemartz.playerbalancer.PlayerBalancer;
import com.jaimemartz.playerbalancer.settings.props.features.CustomFindCommandProps; 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.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; import net.md_5.bungee.api.plugin.Command;
public class CustomFindCommand extends Command { public class CustomFindCommand extends Command {
@ -28,6 +28,21 @@ public class CustomFindCommand extends Command {
@Override @Override
public void execute(CommandSender sender, String[] args) { 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());
}
} }
} }

View File

@ -8,7 +8,6 @@ import net.md_5.bungee.api.connection.ProxiedPlayer;
import java.util.Map; import java.util.Map;
//todo improve this
public class ServerAssignRegistry { public class ServerAssignRegistry {
private static final Table<ProxiedPlayer, ServerSection, ServerInfo> table = HashBasedTable.create(); private static final Table<ProxiedPlayer, ServerSection, ServerInfo> table = HashBasedTable.create();

View File

@ -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.EventHandler;
import net.md_5.bungee.event.EventPriority; import net.md_5.bungee.event.EventPriority;
import java.util.Optional; import java.util.Map;
public class ServerConnectListener implements Listener { public class ServerConnectListener implements Listener {
private final PlayerBalancer plugin; private final PlayerBalancer plugin;
@ -64,17 +64,29 @@ public class ServerConnectListener implements Listener {
if (section != null) { if (section != null) {
if (permissionRouterProps.isEnabled()) { if (permissionRouterProps.isEnabled()) {
Optional<String> bindName = permissionRouterProps.getRouteBind(player, section); Map<String, String> routes = permissionRouterProps.getRules().get(section.getName());
if (bindName.isPresent()) {
ServerSection bind = plugin.getSectionManager().getByName(bindName.get()); if (routes != null) {
if (bind != null) { for (Map.Entry<String, String> route : routes.entrySet()) {
return bind; 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) //Checks only for servers (not the section server)
if (section.getServers().contains(target)) { if (!target.equals(section.getServer())) {
if (plugin.getSectionManager().isDummy(section)) { if (plugin.getSectionManager().isDummy(section)) {
return null; return null;
} }

View File

@ -98,8 +98,10 @@ public class StatusManager implements Listener {
} }
public boolean isAccessible(ServerInfo server) { public boolean isAccessible(ServerInfo server) {
if (overriders.containsKey(server)) { Boolean override = overriders.get(server);
return overriders.get(server);
if (override != null) {
return override;
} }
ServerStatus status = getStatus(server); ServerStatus status = getStatus(server);

View File

@ -19,11 +19,14 @@ public class CustomFindCommandProps {
@ConfigSerializable @ConfigSerializable
@Data @Data
private static class Formats { public static class Formats {
@Setting @Setting
private String result; private String result;
@Setting @Setting
private String offline; private String missing;
@Setting
private String usage;
} }
} }

View File

@ -1,13 +1,10 @@
package com.jaimemartz.playerbalancer.settings.props.features; package com.jaimemartz.playerbalancer.settings.props.features;
import com.jaimemartz.playerbalancer.section.ServerSection;
import lombok.Data; import lombok.Data;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import ninja.leaping.configurate.objectmapping.Setting; import ninja.leaping.configurate.objectmapping.Setting;
import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable; import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable;
import java.util.Map; import java.util.Map;
import java.util.Optional;
@ConfigSerializable @ConfigSerializable
@Data @Data
@ -17,18 +14,4 @@ public class PermissionRouterProps {
@Setting @Setting
private Map<String, Map<String, String>> rules; private Map<String, Map<String, String>> rules;
public Optional<String> getRouteBind(ProxiedPlayer player, ServerSection section) {
Map<String, String> routes = rules.get(section.getName());
if (routes != null) {
for (Map.Entry<String, String> route : routes.entrySet()) {
if (player.hasPermission(route.getKey())) {
return Optional.of(route.getValue());
}
}
}
return Optional.empty();
}
} }

View File

@ -112,7 +112,7 @@ features {
dummy-sections=[] dummy-sections=[]
# Reiterative sections remember the server the player connected to previously # 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=[] reiterative-sections=[]
# When true, section servers will show the sum of the players on all servers on that section # 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 { custom-find-command {
enabled=false enabled=false
# Leave permission empty for no permission
command { command {
name=find name=find
permission="" permission=""
@ -232,14 +233,16 @@ features {
} }
formats { formats {
result="" result="&a{name} &cis online at &a{server}"
offline="" missing="&cThere is no such player named {name}"
usage="&cUsage: /find <user>"
} }
} }
custom-list-command { custom-list-command {
enabled=false enabled=false
# Leave permission empty for no permission
command { command {
name=glist name=glist
permission="" permission=""
@ -255,6 +258,7 @@ features {
custom-server-command { custom-server-command {
enabled=false enabled=false
# Leave permission empty for no permission
command { command {
name=server name=server
permission="" permission=""