mirror of
https://github.com/BGHDDevelopment/PlayerBalancer.git
synced 2024-11-23 11:15:30 +01:00
Added aliases, permission router, and progress for custom commands
This commit is contained in:
parent
c582c05eaa
commit
f3c10291b8
@ -1,14 +1,12 @@
|
||||
package com.jaimemartz.playerbalancer;
|
||||
|
||||
import com.google.common.reflect.TypeToken;
|
||||
import com.jaimemartz.playerbalancer.commands.FallbackCommand;
|
||||
import com.jaimemartz.playerbalancer.commands.MainCommand;
|
||||
import com.jaimemartz.playerbalancer.commands.ManageCommand;
|
||||
import com.jaimemartz.playerbalancer.commands.*;
|
||||
import com.jaimemartz.playerbalancer.connection.ServerAssignRegistry;
|
||||
import com.jaimemartz.playerbalancer.helper.NetworkManager;
|
||||
import com.jaimemartz.playerbalancer.helper.PasteHelper;
|
||||
import com.jaimemartz.playerbalancer.helper.PlayerLocker;
|
||||
import com.jaimemartz.playerbalancer.listeners.*;
|
||||
import com.jaimemartz.playerbalancer.manager.NetworkManager;
|
||||
import com.jaimemartz.playerbalancer.manager.PasteHelper;
|
||||
import com.jaimemartz.playerbalancer.manager.PlayerLocker;
|
||||
import com.jaimemartz.playerbalancer.ping.StatusManager;
|
||||
import com.jaimemartz.playerbalancer.section.SectionManager;
|
||||
import com.jaimemartz.playerbalancer.settings.SettingsHolder;
|
||||
@ -41,7 +39,7 @@ public class PlayerBalancer extends Plugin {
|
||||
private final StringBuilder logsBuilder = new StringBuilder();
|
||||
|
||||
private FallbackCommand fallbackCommand;
|
||||
private Command mainCommand, manageCommand;
|
||||
private Command mainCommand, manageCommand, findCommand, listCommand, serverCommand;
|
||||
private Listener connectListener, kickListener, reloadListener, pluginMessageListener;
|
||||
|
||||
@Override
|
||||
@ -181,23 +179,27 @@ public class PlayerBalancer extends Plugin {
|
||||
getProxy().getPluginManager().registerListener(this, kickListener);
|
||||
}
|
||||
|
||||
//After the modules have loaded (hopefully?)
|
||||
getProxy().getScheduler().schedule(this, () -> {
|
||||
if (settings.getFeaturesProps().getCustomFindCommandProps().isEnabled()) {
|
||||
Plugin plugin = getProxy().getPluginManager().getPlugin("cmd_find");
|
||||
if (plugin != null) {
|
||||
getProxy().getPluginManager().unregisterCommands(plugin);
|
||||
getLogger().info("Unregistered commands of the plugin: " + plugin.getDescription().getName());
|
||||
}
|
||||
tryUnregisterCommands("cmd_find");
|
||||
findCommand = new CustomFindCommand(this);
|
||||
getProxy().getPluginManager().registerCommand(this, findCommand);
|
||||
}
|
||||
|
||||
if (settings.getFeaturesProps().getCustomListCommandProps().isEnabled()) {
|
||||
Plugin plugin = getProxy().getPluginManager().getPlugin("cmd_list");
|
||||
if (plugin != null) {
|
||||
getProxy().getPluginManager().unregisterCommands(plugin);
|
||||
getLogger().info("Unregistered commands of the plugin: " + plugin.getDescription().getName());
|
||||
}
|
||||
tryUnregisterCommands("cmd_list");
|
||||
listCommand = new CustomListCommand(this);
|
||||
getProxy().getPluginManager().registerCommand(this, listCommand);
|
||||
}
|
||||
}, 1L, TimeUnit.SECONDS);
|
||||
|
||||
if (settings.getFeaturesProps().getCustomServerCommandProps().isEnabled()) {
|
||||
tryUnregisterCommands("cmd_server");
|
||||
serverCommand = new CustomServerCommand(this);
|
||||
getProxy().getPluginManager().registerCommand(this, serverCommand);
|
||||
}
|
||||
|
||||
}, 5L, TimeUnit.SECONDS);
|
||||
|
||||
PasteHelper.reset();
|
||||
getLogger().info("The plugin has finished loading without any problems");
|
||||
@ -214,6 +216,16 @@ public class PlayerBalancer extends Plugin {
|
||||
}
|
||||
}
|
||||
|
||||
private void tryUnregisterCommands(String pluginName) {
|
||||
Plugin plugin = getProxy().getPluginManager().getPlugin(pluginName);
|
||||
if (plugin != null) {
|
||||
getProxy().getPluginManager().unregisterCommands(plugin);
|
||||
getLogger().info("Unregistered all commands of the plugin: " + pluginName);
|
||||
} else {
|
||||
getLogger().warning("Could not find the plugin: " + pluginName);
|
||||
}
|
||||
}
|
||||
|
||||
private void execStop() {
|
||||
if (mainCommand != null) {
|
||||
getProxy().getPluginManager().unregisterCommand(mainCommand);
|
||||
@ -269,6 +281,27 @@ public class PlayerBalancer extends Plugin {
|
||||
manageCommand = null;
|
||||
}
|
||||
|
||||
if (settings.getFeaturesProps().getCustomFindCommandProps().isEnabled()) {
|
||||
if (findCommand != null) {
|
||||
getProxy().getPluginManager().unregisterCommand(findCommand);
|
||||
findCommand = null;
|
||||
}
|
||||
}
|
||||
|
||||
if (settings.getFeaturesProps().getCustomListCommandProps().isEnabled()) {
|
||||
if (listCommand != null) {
|
||||
getProxy().getPluginManager().unregisterCommand(listCommand);
|
||||
listCommand = null;
|
||||
}
|
||||
}
|
||||
|
||||
if (settings.getFeaturesProps().getCustomServerCommandProps().isEnabled()) {
|
||||
if (serverCommand != null) {
|
||||
getProxy().getPluginManager().unregisterCommand(serverCommand);
|
||||
serverCommand = null;
|
||||
}
|
||||
}
|
||||
|
||||
if (sectionManager != null) {
|
||||
sectionManager.flush();
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
package com.jaimemartz.playerbalancer.commands.custom;
|
||||
package com.jaimemartz.playerbalancer.commands;
|
||||
|
||||
import com.jaimemartz.playerbalancer.PlayerBalancer;
|
||||
import com.jaimemartz.playerbalancer.settings.props.features.CustomFindCommandProps;
|
@ -1,4 +1,4 @@
|
||||
package com.jaimemartz.playerbalancer.commands.custom;
|
||||
package com.jaimemartz.playerbalancer.commands;
|
||||
|
||||
import com.jaimemartz.playerbalancer.PlayerBalancer;
|
||||
import com.jaimemartz.playerbalancer.settings.props.features.CustomListCommandProps;
|
@ -1,4 +1,4 @@
|
||||
package com.jaimemartz.playerbalancer.commands.custom;
|
||||
package com.jaimemartz.playerbalancer.commands;
|
||||
|
||||
import com.jaimemartz.playerbalancer.PlayerBalancer;
|
||||
import com.jaimemartz.playerbalancer.settings.props.features.CustomServerCommandProps;
|
@ -87,8 +87,16 @@ public class FallbackCommand extends Command {
|
||||
return null;
|
||||
}
|
||||
|
||||
ServerSection target = plugin.getSectionManager().getBind(props.getRules(), current)
|
||||
.orElse(current.getParent());
|
||||
ServerSection target = current.getParent();
|
||||
|
||||
String bindName = props.getRules().get(current.getName());
|
||||
if (bindName != null) {
|
||||
ServerSection bind = plugin.getSectionManager().getByName(bindName);
|
||||
if (bind != null) {
|
||||
target = bind;
|
||||
}
|
||||
}
|
||||
|
||||
if (target == null) {
|
||||
MessageUtils.send(player, messages.getUnavailableServerMessage());
|
||||
return null;
|
||||
|
@ -2,7 +2,7 @@ package com.jaimemartz.playerbalancer.commands;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import com.jaimemartz.playerbalancer.PlayerBalancer;
|
||||
import com.jaimemartz.playerbalancer.manager.PasteHelper;
|
||||
import com.jaimemartz.playerbalancer.helper.PasteHelper;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
import net.md_5.bungee.api.chat.ClickEvent;
|
||||
|
@ -109,6 +109,13 @@ public class ManageCommand extends Command {
|
||||
.create());
|
||||
}
|
||||
|
||||
sender.sendMessage(new ComponentBuilder("Alias: ")
|
||||
.color(ChatColor.GRAY)
|
||||
.append(String.valueOf(section.getProps().getAlias()))
|
||||
.color(ChatColor.AQUA)
|
||||
.create()
|
||||
);
|
||||
|
||||
sender.sendMessage(new ComponentBuilder("Position: ")
|
||||
.color(ChatColor.GRAY)
|
||||
.append(String.valueOf(section.getPosition()))
|
||||
|
@ -1,7 +1,7 @@
|
||||
package com.jaimemartz.playerbalancer.connection;
|
||||
|
||||
import com.jaimemartz.playerbalancer.PlayerBalancer;
|
||||
import com.jaimemartz.playerbalancer.manager.PlayerLocker;
|
||||
import com.jaimemartz.playerbalancer.helper.PlayerLocker;
|
||||
import com.jaimemartz.playerbalancer.section.ServerSection;
|
||||
import com.jaimemartz.playerbalancer.utils.MessageUtils;
|
||||
import net.md_5.bungee.api.Callback;
|
||||
@ -26,6 +26,7 @@ public abstract class ConnectionIntent {
|
||||
|
||||
MessageUtils.send(player, plugin.getSettings().getMessagesProps().getConnectingMessage(),
|
||||
(str) -> str.replace("{section}", section.getName())
|
||||
.replace("{alias}", section.getProps().getAlias())
|
||||
);
|
||||
|
||||
//Prevents removing servers from the section
|
||||
@ -46,6 +47,8 @@ public abstract class ConnectionIntent {
|
||||
if (response) { //only if the connect has been executed correctly
|
||||
MessageUtils.send(player, plugin.getSettings().getMessagesProps().getConnectedMessage(),
|
||||
(str) -> str.replace("{server}", target.getName())
|
||||
.replace("{section}", section.getName())
|
||||
.replace("{alias}", section.getProps().getAlias())
|
||||
);
|
||||
}
|
||||
});
|
||||
|
@ -1,4 +1,4 @@
|
||||
package com.jaimemartz.playerbalancer.manager;
|
||||
package com.jaimemartz.playerbalancer.helper;
|
||||
|
||||
import com.imaginarycode.minecraft.redisbungee.RedisBungee;
|
||||
import com.jaimemartz.playerbalancer.PlayerBalancer;
|
@ -1,4 +1,4 @@
|
||||
package com.jaimemartz.playerbalancer.manager;
|
||||
package com.jaimemartz.playerbalancer.helper;
|
||||
|
||||
import com.google.common.io.CharStreams;
|
||||
import com.jaimemartz.playerbalancer.PlayerBalancer;
|
@ -1,4 +1,4 @@
|
||||
package com.jaimemartz.playerbalancer.manager;
|
||||
package com.jaimemartz.playerbalancer.helper;
|
||||
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
|
@ -2,7 +2,7 @@ package com.jaimemartz.playerbalancer.listeners;
|
||||
|
||||
import com.jaimemartz.playerbalancer.PlayerBalancer;
|
||||
import com.jaimemartz.playerbalancer.connection.ServerAssignRegistry;
|
||||
import com.jaimemartz.playerbalancer.manager.PlayerLocker;
|
||||
import com.jaimemartz.playerbalancer.helper.PlayerLocker;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import net.md_5.bungee.api.event.PlayerDisconnectEvent;
|
||||
import net.md_5.bungee.api.plugin.Listener;
|
||||
|
@ -7,7 +7,7 @@ import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.JsonSerializer;
|
||||
import com.jaimemartz.playerbalancer.PlayerBalancer;
|
||||
import com.jaimemartz.playerbalancer.connection.ConnectionIntent;
|
||||
import com.jaimemartz.playerbalancer.manager.PlayerLocker;
|
||||
import com.jaimemartz.playerbalancer.helper.PlayerLocker;
|
||||
import com.jaimemartz.playerbalancer.ping.ServerStatus;
|
||||
import com.jaimemartz.playerbalancer.section.ServerSection;
|
||||
import net.md_5.bungee.api.config.ServerInfo;
|
||||
|
@ -3,8 +3,9 @@ package com.jaimemartz.playerbalancer.listeners;
|
||||
import com.jaimemartz.playerbalancer.PlayerBalancer;
|
||||
import com.jaimemartz.playerbalancer.connection.ConnectionIntent;
|
||||
import com.jaimemartz.playerbalancer.connection.ServerAssignRegistry;
|
||||
import com.jaimemartz.playerbalancer.manager.PlayerLocker;
|
||||
import com.jaimemartz.playerbalancer.helper.PlayerLocker;
|
||||
import com.jaimemartz.playerbalancer.section.ServerSection;
|
||||
import com.jaimemartz.playerbalancer.settings.props.features.PermissionRouterProps;
|
||||
import com.jaimemartz.playerbalancer.utils.MessageUtils;
|
||||
import net.md_5.bungee.api.Callback;
|
||||
import net.md_5.bungee.api.config.ServerInfo;
|
||||
@ -14,11 +15,17 @@ 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;
|
||||
|
||||
public class ServerConnectListener implements Listener {
|
||||
private final PlayerBalancer plugin;
|
||||
|
||||
private final PermissionRouterProps permissionRouterProps;
|
||||
|
||||
public ServerConnectListener(PlayerBalancer plugin) {
|
||||
this.plugin = plugin;
|
||||
|
||||
this.permissionRouterProps = plugin.getSettings().getFeaturesProps().getPermissionRouterProps();
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
@ -26,6 +33,9 @@ public class ServerConnectListener implements Listener {
|
||||
ProxiedPlayer player = event.getPlayer();
|
||||
ServerInfo target = event.getTarget();
|
||||
|
||||
if (PlayerLocker.isLocked(player))
|
||||
return;
|
||||
|
||||
ServerSection section = getSection(player, target);
|
||||
|
||||
if (section == null)
|
||||
@ -53,8 +63,14 @@ public class ServerConnectListener implements Listener {
|
||||
ServerSection section = plugin.getSectionManager().getByServer(target);
|
||||
|
||||
if (section != null) {
|
||||
if (PlayerLocker.isLocked(player)) {
|
||||
return 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Checks only for servers (not the section server)
|
||||
|
@ -2,7 +2,7 @@ package com.jaimemartz.playerbalancer.listeners;
|
||||
|
||||
import com.jaimemartz.playerbalancer.PlayerBalancer;
|
||||
import com.jaimemartz.playerbalancer.connection.ConnectionIntent;
|
||||
import com.jaimemartz.playerbalancer.manager.PlayerLocker;
|
||||
import com.jaimemartz.playerbalancer.helper.PlayerLocker;
|
||||
import com.jaimemartz.playerbalancer.section.ServerSection;
|
||||
import com.jaimemartz.playerbalancer.settings.props.MessagesProps;
|
||||
import com.jaimemartz.playerbalancer.settings.props.features.KickHandlerProps;
|
||||
@ -111,8 +111,16 @@ public class ServerKickListener implements Listener {
|
||||
}
|
||||
|
||||
if (current != null) {
|
||||
ServerSection target = plugin.getSectionManager().getBind(props.getRules(), current)
|
||||
.orElse(current.getParent());
|
||||
ServerSection target = current.getParent();
|
||||
|
||||
String bindName = props.getRules().get(current.getName());
|
||||
if (bindName != null) {
|
||||
ServerSection bind = plugin.getSectionManager().getByName(bindName);
|
||||
if (bind != null) {
|
||||
target = bind;
|
||||
}
|
||||
}
|
||||
|
||||
if (target == null) {
|
||||
MessageUtils.send(player, messages.getUnavailableServerMessage());
|
||||
return null;
|
||||
|
@ -349,12 +349,6 @@ public class SectionManager {
|
||||
return reiterativeSections.contains(section.getName());
|
||||
}
|
||||
|
||||
public Optional<ServerSection> getBind(Map<String, String> rules, ServerSection section) {
|
||||
String bind = rules.get(section.getName());
|
||||
ServerSection res = this.getByName(bind);
|
||||
return Optional.ofNullable(res);
|
||||
}
|
||||
|
||||
public Map<String, ServerSection> getSections() {
|
||||
return sections;
|
||||
}
|
||||
|
@ -31,4 +31,7 @@ public class FeaturesProps {
|
||||
|
||||
@Setting(value = "custom-server-command")
|
||||
private CustomServerCommandProps customServerCommandProps;
|
||||
|
||||
@Setting(value = "permission-router")
|
||||
private PermissionRouterProps permissionRouterProps;
|
||||
}
|
||||
|
@ -0,0 +1,34 @@
|
||||
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
|
||||
public class PermissionRouterProps {
|
||||
@Setting
|
||||
private boolean enabled;
|
||||
|
||||
@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();
|
||||
}
|
||||
}
|
@ -13,6 +13,9 @@ public class SectionProps {
|
||||
@Setting
|
||||
private ProviderType provider;
|
||||
|
||||
@Setting
|
||||
private String alias;
|
||||
|
||||
@Setting(value = "parent")
|
||||
private String parentName;
|
||||
|
||||
|
@ -28,8 +28,8 @@ general {
|
||||
# Effectively remove (i.e comment) a message to disable it
|
||||
# Supported variables are shown in the default messages
|
||||
messages {
|
||||
# connecting-server="&aConnecting to a {section} server" # this message is disabled by default!
|
||||
connected-server="&aConnected to {server}"
|
||||
# connecting-server="&aConnecting to an {section} ({alias}) server" # this message is disabled by default!
|
||||
connected-server="&aConnected to {server} (an {alias} server)"
|
||||
invalid-input="&cThis is an invalid input type for this command"
|
||||
misc-failure="&cCould not find a server to get connected to"
|
||||
player-bypass="&cYou have not been moved because you have the playerbalancer.bypass permission"
|
||||
@ -70,6 +70,7 @@ features {
|
||||
|
||||
general-lobbies {
|
||||
parent="auth-lobbies"
|
||||
alias="General Lobbies"
|
||||
servers=[
|
||||
"Lobby[1-3]"
|
||||
]
|
||||
@ -141,8 +142,8 @@ features {
|
||||
# When the description of a server matches these, it will be set as non accessible
|
||||
# Be aware of colors, it is recommended to use the "contains" rule below or some others
|
||||
marker-descs=[
|
||||
"(?i).*maintenance*" # match if contains (regex)
|
||||
"Game in progress", # match if exactly equal
|
||||
"(?i).*maintenance*", # match if contains (regex)
|
||||
"Game in progress" # match if exactly equal
|
||||
]
|
||||
}
|
||||
|
||||
@ -237,12 +238,12 @@ features {
|
||||
}
|
||||
|
||||
custom-list-command {
|
||||
enabled = false
|
||||
enabled=false
|
||||
|
||||
command {
|
||||
name = glist
|
||||
permission = ""
|
||||
aliases = []
|
||||
name=glist
|
||||
permission=""
|
||||
aliases=[]
|
||||
}
|
||||
|
||||
formats {
|
||||
@ -252,16 +253,26 @@ features {
|
||||
}
|
||||
|
||||
custom-server-command {
|
||||
enabled = false
|
||||
enabled=false
|
||||
|
||||
command {
|
||||
name = glist
|
||||
permission = ""
|
||||
aliases = []
|
||||
name=server
|
||||
permission=""
|
||||
aliases=[]
|
||||
}
|
||||
|
||||
formats {
|
||||
# Nothing yet
|
||||
}
|
||||
}
|
||||
|
||||
permission-router {
|
||||
enabled=false
|
||||
|
||||
routes {
|
||||
general-lobbies {
|
||||
special.permission=other-lobby-section,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user