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

View File

@ -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<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.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<String> bindName = permissionRouterProps.getRouteBind(player, section);
if (bindName.isPresent()) {
ServerSection bind = plugin.getSectionManager().getByName(bindName.get());
if (bind != null) {
return bind;
Map<String, String> routes = permissionRouterProps.getRules().get(section.getName());
if (routes != null) {
for (Map.Entry<String, String> 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;
}

View File

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

View File

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

View File

@ -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<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=[]
# 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 <user>"
}
}
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=""