mirror of
https://github.com/BGHDDevelopment/PlayerBalancer.git
synced 2024-11-26 20:55:42 +01:00
Added option to disable prevention of connections in the same section
This commit is contained in:
parent
bd5cf508c9
commit
cefe7f9372
@ -11,7 +11,7 @@
|
||||
|
||||
<name>PlayerBalancer Plugin</name>
|
||||
<artifactId>playerbalancer-plugin</artifactId>
|
||||
<version>2.1.4.2</version>
|
||||
<version>2.1.4.3</version>
|
||||
|
||||
<build>
|
||||
<finalName>PlayerBalancer</finalName>
|
||||
|
@ -1,58 +0,0 @@
|
||||
package com.jaimemartz.playerbalancer.commands;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.jaimemartz.playerbalancer.PlayerBalancer;
|
||||
import com.jaimemartz.playerbalancer.connection.ConnectionIntent;
|
||||
import com.jaimemartz.playerbalancer.section.ServerSection;
|
||||
import com.jaimemartz.playerbalancer.settings.props.MessagesProps;
|
||||
import com.jaimemartz.playerbalancer.settings.props.shared.CommandProps;
|
||||
import com.jaimemartz.playerbalancer.utils.MessageUtils;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
import net.md_5.bungee.api.chat.ComponentBuilder;
|
||||
import net.md_5.bungee.api.config.ServerInfo;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import net.md_5.bungee.api.plugin.Command;
|
||||
|
||||
public abstract class AbstractMoveCommand extends Command {
|
||||
private final PlayerBalancer plugin;
|
||||
private final MessagesProps messages;
|
||||
|
||||
public AbstractMoveCommand(PlayerBalancer plugin, CommandProps commandProps) {
|
||||
super(commandProps.getName(), commandProps.getPermission(), commandProps.getAliasesArray());
|
||||
this.messages = plugin.getSettings().getMessagesProps();
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
if (sender instanceof ProxiedPlayer) {
|
||||
ProxiedPlayer player = (ProxiedPlayer) sender;
|
||||
ServerSection target = getSection(player);
|
||||
|
||||
if (target != null) {
|
||||
if (args.length == 1) {
|
||||
try {
|
||||
int number = Integer.parseInt(args[0]);
|
||||
if (number <= 0) {
|
||||
MessageUtils.send(player, messages.getInvalidInputMessage());
|
||||
} else if (number > target.getServers().size()) {
|
||||
MessageUtils.send(player, messages.getInvalidInputMessage());
|
||||
} else {
|
||||
ServerInfo server = Iterables.get(target.getServers(), number - 1);
|
||||
ConnectionIntent.direct(plugin, player, server, null);
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
MessageUtils.send(player, messages.getInvalidInputMessage());
|
||||
}
|
||||
} else {
|
||||
ConnectionIntent.simple(plugin, player, target);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
sender.sendMessage(new ComponentBuilder("This command can only be executed by a player").color(ChatColor.RED).create());
|
||||
}
|
||||
}
|
||||
|
||||
public abstract ServerSection getSection(ProxiedPlayer player);
|
||||
}
|
@ -1,25 +1,83 @@
|
||||
package com.jaimemartz.playerbalancer.commands;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.jaimemartz.playerbalancer.PlayerBalancer;
|
||||
import com.jaimemartz.playerbalancer.connection.ConnectionIntent;
|
||||
import com.jaimemartz.playerbalancer.section.ServerSection;
|
||||
import com.jaimemartz.playerbalancer.settings.props.MessagesProps;
|
||||
import com.jaimemartz.playerbalancer.settings.props.features.FallbackCommandProps;
|
||||
import com.jaimemartz.playerbalancer.settings.props.shared.CommandProps;
|
||||
import com.jaimemartz.playerbalancer.utils.MessageUtils;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
import net.md_5.bungee.api.chat.ComponentBuilder;
|
||||
import net.md_5.bungee.api.config.ServerInfo;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import net.md_5.bungee.api.connection.Server;
|
||||
import net.md_5.bungee.api.plugin.Command;
|
||||
|
||||
public class FallbackCommand extends AbstractMoveCommand {
|
||||
public class FallbackCommand extends Command {
|
||||
private final PlayerBalancer plugin;
|
||||
private final MessagesProps messages;
|
||||
private final FallbackCommandProps props;
|
||||
protected final FallbackCommandProps props;
|
||||
|
||||
/**
|
||||
* Constructor for `fallback-command`
|
||||
*/
|
||||
public FallbackCommand(PlayerBalancer plugin) {
|
||||
super(plugin, plugin.getSettings().getFallbackCommandProps().getCommand());
|
||||
this.props = plugin.getSettings().getFallbackCommandProps();
|
||||
this(plugin, plugin.getSettings().getFallbackCommandProps().getCommand());
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for `section-command` or others
|
||||
*/
|
||||
public FallbackCommand(PlayerBalancer plugin, CommandProps commandProps) {
|
||||
super(commandProps.getName(), commandProps.getPermission(), commandProps.getAliasesArray());
|
||||
this.messages = plugin.getSettings().getMessagesProps();
|
||||
this.props = plugin.getSettings().getFallbackCommandProps();
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
if (sender instanceof ProxiedPlayer) {
|
||||
ProxiedPlayer player = (ProxiedPlayer) sender;
|
||||
ServerSection target = getSection(player);
|
||||
|
||||
if (target != null) {
|
||||
if (args.length == 1) {
|
||||
try {
|
||||
int number = Integer.parseInt(args[0]);
|
||||
if (number <= 0) {
|
||||
MessageUtils.send(player, messages.getInvalidInputMessage());
|
||||
} else if (number > target.getServers().size()) {
|
||||
MessageUtils.send(player, messages.getInvalidInputMessage());
|
||||
} else {
|
||||
ServerInfo server = Iterables.get(target.getServers(), number - 1);
|
||||
ConnectionIntent.direct(plugin, player, server, null);
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
MessageUtils.send(player, messages.getInvalidInputMessage());
|
||||
}
|
||||
} else {
|
||||
if (props.isPreventSameSection()) {
|
||||
Server current = player.getServer();
|
||||
if (current != null) {
|
||||
if (target.getServers().contains(current.getInfo())) {
|
||||
MessageUtils.send(player, plugin.getSettings().getMessagesProps().getSameSectionMessage());
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ConnectionIntent.simple(plugin, player, target);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
sender.sendMessage(new ComponentBuilder("This command can only be executed by a player").color(ChatColor.RED).create());
|
||||
}
|
||||
}
|
||||
|
||||
public ServerSection getSection(ProxiedPlayer player) {
|
||||
ServerSection current = plugin.getSectionManager().getByPlayer(player);
|
||||
|
||||
@ -54,4 +112,6 @@ public class FallbackCommand extends AbstractMoveCommand {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -28,10 +28,17 @@ public abstract class ConnectionIntent {
|
||||
(str) -> str.replace("{section}", section.getName())
|
||||
);
|
||||
|
||||
//Prevents removing servers from the section
|
||||
if (servers == section.getServers()) {
|
||||
throw new IllegalStateException("The servers list parameter is the same reference, this cannot happen");
|
||||
}
|
||||
|
||||
//Prevents connections to the same server
|
||||
Server current = player.getServer();
|
||||
if (current != null) {
|
||||
servers.remove(current.getInfo());
|
||||
}
|
||||
|
||||
if (section.getImplicitProvider() != ProviderType.NONE) {
|
||||
ServerInfo target = this.fetchServer(player, section, provider, servers);
|
||||
if (target != null) {
|
||||
@ -93,16 +100,6 @@ public abstract class ConnectionIntent {
|
||||
|
||||
//TODO Create this as a type
|
||||
public static void simple(PlayerBalancer plugin, ProxiedPlayer player, ServerSection section) {
|
||||
//TODO Make this apply to all situations except kicks
|
||||
//TODO (It already works like that, but I want a better way)
|
||||
Server current = player.getServer();
|
||||
if (current != null) {
|
||||
if (section.getServers().contains(current.getInfo())) {
|
||||
MessageUtils.send(player, plugin.getSettings().getMessagesProps().getSameSectionMessage());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
new ConnectionIntent(plugin, player, section) {
|
||||
@Override
|
||||
public void connect(ServerInfo server, Callback<Boolean> callback) {
|
||||
|
@ -1,10 +1,10 @@
|
||||
package com.jaimemartz.playerbalancer.section;
|
||||
|
||||
import com.jaimemartz.playerbalancer.PlayerBalancer;
|
||||
import com.jaimemartz.playerbalancer.commands.AbstractMoveCommand;
|
||||
import com.jaimemartz.playerbalancer.commands.FallbackCommand;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
|
||||
public class SectionCommand extends AbstractMoveCommand {
|
||||
public class SectionCommand extends FallbackCommand {
|
||||
private final ServerSection section;
|
||||
|
||||
public SectionCommand(PlayerBalancer plugin, ServerSection section) {
|
||||
|
@ -21,6 +21,9 @@ public class FallbackCommandProps {
|
||||
@Setting
|
||||
private boolean restrictive;
|
||||
|
||||
@Setting(value = "prevent-same-section")
|
||||
private boolean preventSameSection;
|
||||
|
||||
@Setting
|
||||
private Map<String, String> rules;
|
||||
|
||||
@ -56,6 +59,14 @@ public class FallbackCommandProps {
|
||||
this.restrictive = restrictive;
|
||||
}
|
||||
|
||||
public boolean isPreventSameSection() {
|
||||
return preventSameSection;
|
||||
}
|
||||
|
||||
public void setPreventSameSection(boolean preventSameSection) {
|
||||
this.preventSameSection = preventSameSection;
|
||||
}
|
||||
|
||||
public Map<String, String> getRules() {
|
||||
return rules;
|
||||
}
|
||||
@ -71,6 +82,7 @@ public class FallbackCommandProps {
|
||||
", command=" + command +
|
||||
", excludedSections=" + excludedSections +
|
||||
", restrictive=" + restrictive +
|
||||
", preventSameSection=" + preventSameSection +
|
||||
", rules=" + rules +
|
||||
'}';
|
||||
}
|
||||
|
@ -167,6 +167,11 @@ features {
|
||||
# When true, players will not be able to get connected to sections that are parents of the principal section
|
||||
restrictive=true
|
||||
|
||||
# When true, players will not be able get connected within servers of the same section
|
||||
# This does not affect the parametized variant of the command (/command [number])
|
||||
# This also affects section commands
|
||||
prevent-same-section=true
|
||||
|
||||
# You can override the behavior with rules, overriding the parent section
|
||||
# This will set the section to go when you come from the section specified
|
||||
rules {
|
||||
@ -199,7 +204,7 @@ features {
|
||||
debug-info=false
|
||||
|
||||
# You can override the behavior with rules, overriding the parent section
|
||||
# This will set the section to go when you come from the section specified
|
||||
# When you get kicked from the section on the left, you go to the one on the right
|
||||
rules {
|
||||
section-from=section-to
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user