mirror of
https://github.com/BGHDDevelopment/PlayerBalancer.git
synced 2024-11-23 19:25:12 +01:00
Some little changes and fixes
This commit is contained in:
parent
34594eafaa
commit
5dd49b4caa
@ -9,7 +9,6 @@
|
|||||||
* Build with maven
|
* Build with maven
|
||||||
|
|
||||||
### Things to do:
|
### Things to do:
|
||||||
- [ ] Add support for wildcards, contains, equalsIgnoreCase and regex at the same time
|
|
||||||
- [ ] Create a spigot addon that adds connector signs and placeholders
|
- [ ] Create a spigot addon that adds connector signs and placeholders
|
||||||
- [ ] Separate the types of connections in classes instead of being in ConnectionIntent
|
- [ ] Separate the types of connections in classes instead of being in ConnectionIntent
|
||||||
- [ ] Make the plugin API be not so dependent on a instance of PlayerBalancer
|
- [ ] Make the plugin API be not so dependent on a instance of PlayerBalancer
|
||||||
|
@ -48,7 +48,7 @@ public class FallbackCommand extends Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ConnectionIntent.direct(plugin, player, server, (response, throwable) -> {
|
ConnectionIntent.direct(plugin, player, server, (response, throwable) -> {
|
||||||
//todo nothing to do?
|
//TODO Handle this
|
||||||
});
|
});
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
@ -146,16 +146,15 @@ public class ManageCommand extends Command {
|
|||||||
.color(ChatColor.GRAY)
|
.color(ChatColor.GRAY)
|
||||||
.append(section.getCommand().getName())
|
.append(section.getCommand().getName())
|
||||||
.color(ChatColor.AQUA)
|
.color(ChatColor.AQUA)
|
||||||
.event(new HoverEvent(HoverEvent.Action.SHOW_TEXT,
|
.event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("Permission: ")
|
||||||
new ComponentBuilder("Permission: ")
|
.color(ChatColor.GRAY)
|
||||||
.color(ChatColor.GRAY)
|
.append(section.getCommand().getPermission().equals("") ? "None" : section.getCommand().getPermission())
|
||||||
.append(section.getCommand().getPermission().equals("") ? "None" : section.getCommand().getPermission())
|
.color(ChatColor.AQUA)
|
||||||
.color(ChatColor.AQUA)
|
.append("\nAliases: ")
|
||||||
.append("\nAliases: ")
|
.color(ChatColor.GRAY)
|
||||||
.color(ChatColor.GRAY)
|
.append(Arrays.toString(section.getCommand().getAliases()))
|
||||||
.append(Arrays.toString(section.getCommand().getAliases()))
|
.color(ChatColor.AQUA)
|
||||||
.color(ChatColor.AQUA)
|
.create())
|
||||||
.create())
|
|
||||||
).create()
|
).create()
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
@ -179,20 +178,19 @@ public class ManageCommand extends Command {
|
|||||||
.color(ChatColor.GRAY)
|
.color(ChatColor.GRAY)
|
||||||
.append(server.getName())
|
.append(server.getName())
|
||||||
.color(ChatColor.AQUA)
|
.color(ChatColor.AQUA)
|
||||||
.event(new HoverEvent(HoverEvent.Action.SHOW_TEXT,
|
.event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("Accessible: ")
|
||||||
new ComponentBuilder("Accessible: ")
|
.color(ChatColor.GRAY)
|
||||||
.color(ChatColor.GRAY)
|
.append(status.isAccessible(plugin) ? "yes" : "no")
|
||||||
.append(status.isAccessible(plugin, null) ? "yes" : "no")
|
.color(status.isAccessible(plugin) ? ChatColor.GREEN : ChatColor.RED)
|
||||||
.color(status.isAccessible(plugin, null) ? ChatColor.GREEN : ChatColor.RED)
|
.append("\nDescription: ")
|
||||||
.append("\nDescription: ")
|
.color(ChatColor.GRAY)
|
||||||
.color(ChatColor.GRAY)
|
.append("\"")
|
||||||
.append("\"")
|
.color(ChatColor.AQUA)
|
||||||
.color(ChatColor.AQUA)
|
.append(status.getDescription())
|
||||||
.append(status.getDescription())
|
.color(ChatColor.WHITE)
|
||||||
.color(ChatColor.WHITE)
|
.append("\"")
|
||||||
.append("\"")
|
.color(ChatColor.AQUA)
|
||||||
.color(ChatColor.AQUA)
|
.create()))
|
||||||
.create()))
|
|
||||||
.append(String.format(" (%d/%d) ",
|
.append(String.format(" (%d/%d) ",
|
||||||
status.getOnline(),
|
status.getOnline(),
|
||||||
status.getMaximum()))
|
status.getMaximum()))
|
||||||
|
@ -73,7 +73,7 @@ public abstract class ConnectionIntent {
|
|||||||
if (ServerAssignRegistry.hasAssignedServer(player, section)) {
|
if (ServerAssignRegistry.hasAssignedServer(player, section)) {
|
||||||
ServerInfo target = ServerAssignRegistry.getAssignedServer(player, section);
|
ServerInfo target = ServerAssignRegistry.getAssignedServer(player, section);
|
||||||
ServerStatus status = plugin.getStatusManager().getStatus(target);
|
ServerStatus status = plugin.getStatusManager().getStatus(target);
|
||||||
if (status.isAccessible(plugin, player)) {
|
if (status.isAccessible(plugin)) {
|
||||||
return target;
|
return target;
|
||||||
} else {
|
} else {
|
||||||
ServerAssignRegistry.revokeTarget(player, section);
|
ServerAssignRegistry.revokeTarget(player, section);
|
||||||
@ -89,7 +89,7 @@ public abstract class ConnectionIntent {
|
|||||||
if (target == null) continue;
|
if (target == null) continue;
|
||||||
|
|
||||||
ServerStatus status = plugin.getStatusManager().getStatus(target);
|
ServerStatus status = plugin.getStatusManager().getStatus(target);
|
||||||
if (status.isAccessible(plugin, player)) {
|
if (status.isAccessible(plugin)) {
|
||||||
return target;
|
return target;
|
||||||
} else {
|
} else {
|
||||||
servers.remove(target);
|
servers.remove(target);
|
||||||
@ -101,7 +101,7 @@ public abstract class ConnectionIntent {
|
|||||||
|
|
||||||
public abstract void connect(ServerInfo server, Callback<Boolean> callback);
|
public abstract void connect(ServerInfo server, Callback<Boolean> callback);
|
||||||
|
|
||||||
//todo create this as a type
|
//TODO Create this as a type
|
||||||
public static void simple(PlayerBalancer plugin, ProxiedPlayer player, ServerSection section) {
|
public static void simple(PlayerBalancer plugin, ProxiedPlayer player, ServerSection section) {
|
||||||
new ConnectionIntent(plugin, player, section) {
|
new ConnectionIntent(plugin, player, section) {
|
||||||
@Override
|
@Override
|
||||||
@ -111,7 +111,7 @@ public abstract class ConnectionIntent {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
//todo create this as a type
|
//TODO Create this as a type
|
||||||
public static void direct(PlayerBalancer plugin, ProxiedPlayer player, ServerInfo server, Callback<Boolean> callback) {
|
public static void direct(PlayerBalancer plugin, ProxiedPlayer player, ServerInfo server, Callback<Boolean> callback) {
|
||||||
PlayerLocker.lock(player);
|
PlayerLocker.lock(player);
|
||||||
player.connect(server, (result, throwable) -> {
|
player.connect(server, (result, throwable) -> {
|
||||||
|
@ -40,7 +40,7 @@ public class ServerKickListener implements Listener {
|
|||||||
String reason = TextComponent.toPlainText(event.getKickReasonComponent());
|
String reason = TextComponent.toPlainText(event.getKickReasonComponent());
|
||||||
|
|
||||||
for (String string : props.getReasons()) {
|
for (String string : props.getReasons()) {
|
||||||
if (reason.matches(string) || reason.contains(string)) { //todo improve this
|
if (reason.matches(string)) {
|
||||||
matches = true;
|
matches = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,7 @@ import java.util.HashSet;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
//TODO improve this? maybe?
|
//TODO I don't like it, improve it
|
||||||
public class PlayerLocker {
|
public class PlayerLocker {
|
||||||
private static final Set<UUID> storage = Collections.synchronizedSet(new HashSet<UUID>());
|
private static final Set<UUID> storage = Collections.synchronizedSet(new HashSet<UUID>());
|
||||||
|
|
||||||
|
@ -2,7 +2,6 @@ package com.jaimemartz.playerbalancer.ping;
|
|||||||
|
|
||||||
import com.jaimemartz.playerbalancer.PlayerBalancer;
|
import com.jaimemartz.playerbalancer.PlayerBalancer;
|
||||||
import net.md_5.bungee.api.config.ServerInfo;
|
import net.md_5.bungee.api.config.ServerInfo;
|
||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
|
||||||
|
|
||||||
public final class ServerStatus {
|
public final class ServerStatus {
|
||||||
private final String description;
|
private final String description;
|
||||||
@ -23,14 +22,13 @@ public final class ServerStatus {
|
|||||||
this.maximum = maximum;
|
this.maximum = maximum;
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO improve this (set from the pinger if accessible or not) maybe?
|
public boolean isAccessible(PlayerBalancer plugin) {
|
||||||
public boolean isAccessible(PlayerBalancer plugin, ProxiedPlayer player) {
|
|
||||||
if (maximum == 0) {
|
if (maximum == 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (String pattern : plugin.getSettings().getServerCheckerProps().getMarkerDescs()) {
|
for (String pattern : plugin.getSettings().getServerCheckerProps().getMarkerDescs()) {
|
||||||
if (description.matches(pattern) || description.contains(pattern)) {
|
if (description.matches(pattern)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -63,8 +63,9 @@ public class StatusManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (plugin.getSettings().getServerCheckerProps().isDebug()) {
|
if (plugin.getSettings().getServerCheckerProps().isDebug()) {
|
||||||
plugin.getLogger().info(String.format("Updated server %s, status: [Description: \"%s\", Online Players: %s, Maximum Players: %s, Accessible: %s]",
|
plugin.getLogger().info(String.format(
|
||||||
server.getName(), status.getDescription(), status.getOnline(), status.getMaximum(), status.isAccessible(plugin, null)
|
"Updated server %s, status: [Description: \"%s\", Online Players: %s, Maximum Players: %s, Accessible: %s]",
|
||||||
|
server.getName(), status.getDescription(), status.getOnline(), status.getMaximum(), status.isAccessible(plugin)
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,10 +74,18 @@ public class SectionManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ServerSection other = servers.get(server);
|
ServerSection other = servers.get(server);
|
||||||
throw new IllegalArgumentException(String.format("The server \"%s\" is already in the section \"%s\"", server.getName(), other.getName()));
|
throw new IllegalArgumentException(String.format(
|
||||||
|
"The server \"%s\" is already in the section \"%s\"",
|
||||||
|
server.getName(),
|
||||||
|
other.getName()
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
plugin.getLogger().info(String.format("Registering server \"%s\" to section \"%s\"", server.getName(), section.getName()));
|
plugin.getLogger().info(String.format("Registering server \"%s\" to section \"%s\"",
|
||||||
|
server.getName(),
|
||||||
|
section.getName()
|
||||||
|
));
|
||||||
|
|
||||||
servers.put(server, section);
|
servers.put(server, section);
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -248,7 +256,7 @@ public class SectionManager {
|
|||||||
});
|
});
|
||||||
|
|
||||||
plugin.getLogger().info(String.format("Recognized %s server(s) out of %s in the section \"%s\"",
|
plugin.getLogger().info(String.format("Recognized %s server(s) out of %s in the section \"%s\"",
|
||||||
servers.size(),
|
results.size(),
|
||||||
section.getProps().getServerEntries(),
|
section.getProps().getServerEntries(),
|
||||||
section.getName()
|
section.getName()
|
||||||
));
|
));
|
||||||
|
Loading…
Reference in New Issue
Block a user