mirror of
https://github.com/BGHDDevelopment/PlayerBalancer.git
synced 2025-02-17 04:31:45 +01:00
Message for when you try to connect to the same section
This commit is contained in:
parent
6b3293c0c2
commit
f97e9a46eb
@ -29,21 +29,21 @@ public class FallbackCommand extends Command {
|
|||||||
ProxiedPlayer player = (ProxiedPlayer) sender;
|
ProxiedPlayer player = (ProxiedPlayer) sender;
|
||||||
|
|
||||||
Callable<ServerSection> callable = () -> {
|
Callable<ServerSection> callable = () -> {
|
||||||
ServerSection section = plugin.getSectionManager().getByServer(player.getServer().getInfo());
|
ServerSection current = plugin.getSectionManager().getByPlayer(player);
|
||||||
|
|
||||||
if (section != null) {
|
if (current != null) {
|
||||||
if ((ConfigEntries.FALLBACK_COMMAND_IGNORED_SECTIONS.get()).contains(section.getName())) {
|
if ((ConfigEntries.FALLBACK_COMMAND_IGNORED_SECTIONS.get()).contains(current.getName())) {
|
||||||
MessageUtils.send(player, ConfigEntries.UNAVAILABLE_MESSAGE.get());
|
MessageUtils.send(player, ConfigEntries.UNAVAILABLE_MESSAGE.get());
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
Configuration rules = plugin.getConfigHandle().getSection("settings.fallback-command.rules");
|
Configuration rules = plugin.getConfigHandle().getSection("settings.fallback-command.rules");
|
||||||
String bind = rules.getString(section.getName());
|
String bind = rules.getString(current.getName());
|
||||||
ServerSection target = plugin.getSectionManager().getByName(bind);
|
ServerSection target = plugin.getSectionManager().getByName(bind);
|
||||||
|
|
||||||
if (target == null) {
|
if (target == null) {
|
||||||
if (section.getParent() != null) {
|
if (current.getParent() != null) {
|
||||||
target = section.getParent();
|
target = current.getParent();
|
||||||
} else {
|
} else {
|
||||||
MessageUtils.send(player, ConfigEntries.UNAVAILABLE_MESSAGE.get());
|
MessageUtils.send(player, ConfigEntries.UNAVAILABLE_MESSAGE.get());
|
||||||
return null;
|
return null;
|
||||||
@ -51,7 +51,7 @@ public class FallbackCommand extends Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (ConfigEntries.FALLBACK_COMMAND_RESTRICTED.get()) {
|
if (ConfigEntries.FALLBACK_COMMAND_RESTRICTED.get()) {
|
||||||
if (section.getPosition() >= 0 && target.getPosition() < 0) {
|
if (current.getPosition() >= 0 && target.getPosition() < 0) {
|
||||||
MessageUtils.send(player, ConfigEntries.UNAVAILABLE_MESSAGE.get());
|
MessageUtils.send(player, ConfigEntries.UNAVAILABLE_MESSAGE.get());
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -68,24 +68,29 @@ public class FallbackCommand extends Command {
|
|||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
ServerSection section = callable.call();
|
ServerSection target = callable.call();
|
||||||
if (section != null) {
|
if (target != null) {
|
||||||
if (args.length == 1) {
|
if (args.length == 1) {
|
||||||
try {
|
try {
|
||||||
int number = Integer.parseInt(args[0]);
|
int number = Integer.parseInt(args[0]);
|
||||||
if (number <= 0) {
|
if (number <= 0) {
|
||||||
MessageUtils.send(player, ConfigEntries.INVALID_INPUT_MESSAGE.get());
|
MessageUtils.send(player, ConfigEntries.INVALID_INPUT_MESSAGE.get());
|
||||||
} else if (number > section.getServers().size()) {
|
} else if (number > target.getServers().size()) {
|
||||||
MessageUtils.send(player, ConfigEntries.FAILURE_MESSAGE.get());
|
MessageUtils.send(player, ConfigEntries.FAILURE_MESSAGE.get());
|
||||||
} else {
|
} else {
|
||||||
ServerInfo server = section.getSortedServers().get(number - 1);
|
ServerInfo server = target.getSortedServers().get(number - 1);
|
||||||
ConnectionIntent.direct(plugin, player, server);
|
ConnectionIntent.direct(plugin, player, server);
|
||||||
}
|
}
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
MessageUtils.send(player, ConfigEntries.INVALID_INPUT_MESSAGE.get());
|
MessageUtils.send(player, ConfigEntries.INVALID_INPUT_MESSAGE.get());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ConnectionIntent.simple(plugin, player, section);
|
ServerSection current = plugin.getSectionManager().getByPlayer(player);
|
||||||
|
if (current != target) {
|
||||||
|
ConnectionIntent.simple(plugin, player, target);
|
||||||
|
} else {
|
||||||
|
MessageUtils.send(player, ConfigEntries.SAME_SECTION.get());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -49,6 +49,7 @@ public class ConfigEntries implements ConfigEntryHolder {
|
|||||||
public static final ConfigEntry<String> UNAVAILABLE_MESSAGE = new ConfigEntry<>(0, "settings.messages.unavailable-server", null);
|
public static final ConfigEntry<String> UNAVAILABLE_MESSAGE = new ConfigEntry<>(0, "settings.messages.unavailable-server", null);
|
||||||
public static final ConfigEntry<String> KICK_MESSAGE = new ConfigEntry<>(0, "settings.messages.player-kicked", null);
|
public static final ConfigEntry<String> KICK_MESSAGE = new ConfigEntry<>(0, "settings.messages.player-kicked", null);
|
||||||
public static final ConfigEntry<String> BYPASS_MESSAGE = new ConfigEntry<>(0, "settings.messages.player-bypass", null);
|
public static final ConfigEntry<String> BYPASS_MESSAGE = new ConfigEntry<>(0, "settings.messages.player-bypass", null);
|
||||||
|
public static final ConfigEntry<String> SAME_SECTION = new ConfigEntry<>(0, "settings.messages.same-section", null);
|
||||||
|
|
||||||
public static final ConfigEntry<String> CONFIG_VERSION = new ConfigEntry<>(0, "version", null);
|
public static final ConfigEntry<String> CONFIG_VERSION = new ConfigEntry<>(0, "version", null);
|
||||||
}
|
}
|
||||||
|
@ -101,6 +101,7 @@ public abstract class ConnectionIntent {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//todo make this return true or false depending if the player really got moved or not
|
||||||
public static void direct(PlayerBalancer plugin, ProxiedPlayer player, ServerInfo server) {
|
public static void direct(PlayerBalancer plugin, ProxiedPlayer player, ServerInfo server) {
|
||||||
PlayerLocker.lock(player);
|
PlayerLocker.lock(player);
|
||||||
player.connect(server);
|
player.connect(server);
|
||||||
|
@ -28,7 +28,6 @@ public class SectionCommand extends Command {
|
|||||||
public void execute(CommandSender sender, String[] args) {
|
public void execute(CommandSender sender, String[] args) {
|
||||||
if (sender instanceof ProxiedPlayer) {
|
if (sender instanceof ProxiedPlayer) {
|
||||||
ProxiedPlayer player = (ProxiedPlayer) sender;
|
ProxiedPlayer player = (ProxiedPlayer) sender;
|
||||||
|
|
||||||
//todo share this code with the fallback command instead of having it duplicated
|
//todo share this code with the fallback command instead of having it duplicated
|
||||||
if (args.length == 1) {
|
if (args.length == 1) {
|
||||||
try {
|
try {
|
||||||
@ -45,7 +44,12 @@ public class SectionCommand extends Command {
|
|||||||
MessageUtils.send(sender, ConfigEntries.INVALID_INPUT_MESSAGE.get());
|
MessageUtils.send(sender, ConfigEntries.INVALID_INPUT_MESSAGE.get());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ConnectionIntent.simple(plugin, player, section);
|
ServerSection current = plugin.getSectionManager().getByPlayer(player);
|
||||||
|
if (current != section) {
|
||||||
|
ConnectionIntent.simple(plugin, player, section);
|
||||||
|
} else {
|
||||||
|
MessageUtils.send(player, ConfigEntries.SAME_SECTION.get());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
sender.sendMessage(new ComponentBuilder("This command can only be executed by a player").color(ChatColor.RED).create());
|
sender.sendMessage(new ComponentBuilder("This command can only be executed by a player").color(ChatColor.RED).create());
|
||||||
|
@ -5,8 +5,11 @@ import lombok.Setter;
|
|||||||
import com.jaimemartz.playerbalancer.PlayerBalancer;
|
import com.jaimemartz.playerbalancer.PlayerBalancer;
|
||||||
import com.jaimemartz.playerbalancer.configuration.ConfigEntries;
|
import com.jaimemartz.playerbalancer.configuration.ConfigEntries;
|
||||||
import net.md_5.bungee.api.config.ServerInfo;
|
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.scheduler.ScheduledTask;
|
import net.md_5.bungee.api.scheduler.ScheduledTask;
|
||||||
import net.md_5.bungee.config.Configuration;
|
import net.md_5.bungee.config.Configuration;
|
||||||
|
import org.apache.commons.lang3.Validate;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -133,4 +136,18 @@ public class SectionManager {
|
|||||||
|
|
||||||
return servers.get(server);
|
return servers.get(server);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ServerSection getByPlayer(ProxiedPlayer player) {
|
||||||
|
if (player == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
Server server = player.getServer();
|
||||||
|
|
||||||
|
if (server == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return getByServer(server.getInfo());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -118,6 +118,7 @@ settings:
|
|||||||
unavailable-server: '&cThis command cannot be executed on this server'
|
unavailable-server: '&cThis command cannot be executed on this server'
|
||||||
player-kicked: '&cYou have been kicked from &a{from} &cand you are being moved to &a{to}&c, reason: &a{reason}'
|
player-kicked: '&cYou have been kicked from &a{from} &cand you are being moved to &a{to}&c, reason: &a{reason}'
|
||||||
player-bypass: '&cYou have not been moved because you have the playerbalancer.bypass permission'
|
player-bypass: '&cYou have not been moved because you have the playerbalancer.bypass permission'
|
||||||
|
same-section: '&cYou are already connected to a server of this section!'
|
||||||
|
|
||||||
# Here you have an example of what you can do with the sections
|
# Here you have an example of what you can do with the sections
|
||||||
# The plugin will print out info telling you if your config is right or not
|
# The plugin will print out info telling you if your config is right or not
|
||||||
|
Loading…
Reference in New Issue
Block a user