mirror of
https://github.com/BGHDDevelopment/PlayerBalancer.git
synced 2024-09-17 10:14:10 +02:00
Some little changes
This commit is contained in:
parent
0ee5d5538b
commit
1538f48159
@ -11,9 +11,8 @@
|
||||
### Things to do:
|
||||
- [ ] Create a spigot addon that adds connector signs and placeholders
|
||||
- [ ] 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
|
||||
- [x] Make the plugin API be not so dependent on a instance of PlayerBalancer
|
||||
- [ ] Separate connection providers in classes instead of being hardcoded in an enum
|
||||
- [ ] Make the feature `marker-descs` work per section
|
||||
- [ ] Implement fast connect (dimension change)
|
||||
- [ ] Implement a way to redirect premium players to a section and cracked ones to other section (not sure how this works)
|
||||
- [x] Unify the code that loads serverName into a section (duplicated at SectionManager and ServerSection)
|
||||
|
@ -79,6 +79,20 @@ public class ManageCommand extends Command {
|
||||
.color(manager.isPrincipal(section) ? ChatColor.GREEN : ChatColor.RED)
|
||||
.create());
|
||||
|
||||
sender.sendMessage(new ComponentBuilder("Dummy: ")
|
||||
.color(ChatColor.GRAY)
|
||||
.append(manager.isDummy(section) ? "yes" : "no")
|
||||
.color(manager.isDummy(section) ? ChatColor.GREEN : ChatColor.RED)
|
||||
.create()
|
||||
);
|
||||
|
||||
sender.sendMessage(new ComponentBuilder("Reiterative: ")
|
||||
.color(ChatColor.GRAY)
|
||||
.append(manager.isReiterative(section) ? "yes" : "no")
|
||||
.color(manager.isReiterative(section) ? ChatColor.GREEN : ChatColor.RED)
|
||||
.create()
|
||||
);
|
||||
|
||||
if (section.getParent() != null) {
|
||||
sender.sendMessage(new ComponentBuilder("Parent: ")
|
||||
.color(ChatColor.GRAY)
|
||||
@ -111,20 +125,6 @@ public class ManageCommand extends Command {
|
||||
.create()
|
||||
);
|
||||
|
||||
sender.sendMessage(new ComponentBuilder("Dummy: ")
|
||||
.color(ChatColor.GRAY)
|
||||
.append(manager.isDummy(section) ? "yes" : "no")
|
||||
.color(manager.isDummy(section) ? ChatColor.GREEN : ChatColor.RED)
|
||||
.create()
|
||||
);
|
||||
|
||||
sender.sendMessage(new ComponentBuilder("Reiterative: ")
|
||||
.color(ChatColor.GRAY)
|
||||
.append(manager.isReiterative(section) ? "yes" : "no")
|
||||
.color(manager.isReiterative(section) ? ChatColor.GREEN : ChatColor.RED)
|
||||
.create()
|
||||
);
|
||||
|
||||
if (section.getServer() != null) {
|
||||
sender.sendMessage(new ComponentBuilder("Section Server: ")
|
||||
.color(ChatColor.GRAY)
|
||||
|
@ -14,6 +14,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
//TODO I don't like this, improve it
|
||||
public abstract class ConnectionIntent {
|
||||
protected final PlayerBalancer plugin;
|
||||
protected final ProxiedPlayer player;
|
||||
|
@ -13,18 +13,18 @@ import java.util.concurrent.ThreadLocalRandom;
|
||||
public enum ProviderType {
|
||||
NONE {
|
||||
@Override
|
||||
public ServerInfo requestTarget(PlayerBalancer plugin, ServerSection section, List<ServerInfo> list, ProxiedPlayer player) {
|
||||
public ServerInfo requestTarget(PlayerBalancer plugin, ServerSection section, List<ServerInfo> servers, ProxiedPlayer player) {
|
||||
return null;
|
||||
}
|
||||
},
|
||||
|
||||
LOWEST {
|
||||
@Override
|
||||
public ServerInfo requestTarget(PlayerBalancer plugin, ServerSection section, List<ServerInfo> list, ProxiedPlayer player) {
|
||||
public ServerInfo requestTarget(PlayerBalancer plugin, ServerSection section, List<ServerInfo> servers, ProxiedPlayer player) {
|
||||
int min = Integer.MAX_VALUE;
|
||||
ServerInfo target = null;
|
||||
|
||||
for (ServerInfo server : list) {
|
||||
for (ServerInfo server : servers) {
|
||||
int count = plugin.getNetworkManager().getPlayers(server);
|
||||
|
||||
if (count < min) {
|
||||
@ -39,11 +39,11 @@ public enum ProviderType {
|
||||
|
||||
BALANCED {
|
||||
@Override
|
||||
public ServerInfo requestTarget(PlayerBalancer plugin, ServerSection section, List<ServerInfo> list, ProxiedPlayer player) {
|
||||
public ServerInfo requestTarget(PlayerBalancer plugin, ServerSection section, List<ServerInfo> servers, ProxiedPlayer player) {
|
||||
List<ServerInfo> results = new ArrayList<>();
|
||||
int min = Integer.MAX_VALUE;
|
||||
|
||||
for (ServerInfo server : list) {
|
||||
for (ServerInfo server : servers) {
|
||||
int count = plugin.getNetworkManager().getPlayers(server);
|
||||
|
||||
if (count <= min) {
|
||||
@ -55,38 +55,38 @@ public enum ProviderType {
|
||||
}
|
||||
}
|
||||
|
||||
return results.get(ThreadLocalRandom.current().nextInt(list.size()));
|
||||
return results.get(ThreadLocalRandom.current().nextInt(servers.size()));
|
||||
}
|
||||
},
|
||||
|
||||
RANDOM {
|
||||
@Override
|
||||
public ServerInfo requestTarget(PlayerBalancer plugin, ServerSection section, List<ServerInfo> list, ProxiedPlayer player) {
|
||||
return list.get(ThreadLocalRandom.current().nextInt(list.size()));
|
||||
public ServerInfo requestTarget(PlayerBalancer plugin, ServerSection section, List<ServerInfo> servers, ProxiedPlayer player) {
|
||||
return servers.get(ThreadLocalRandom.current().nextInt(servers.size()));
|
||||
}
|
||||
},
|
||||
|
||||
PROGRESSIVE {
|
||||
@Override
|
||||
public ServerInfo requestTarget(PlayerBalancer plugin, ServerSection section, List<ServerInfo> list, ProxiedPlayer player) {
|
||||
for (ServerInfo server : list) {
|
||||
public ServerInfo requestTarget(PlayerBalancer plugin, ServerSection section, List<ServerInfo> servers, ProxiedPlayer player) {
|
||||
for (ServerInfo server : servers) {
|
||||
ServerStatus status = plugin.getStatusManager().getStatus(server);
|
||||
if (plugin.getNetworkManager().getPlayers(server) < status.getMaximum()) {
|
||||
return server;
|
||||
}
|
||||
}
|
||||
|
||||
return list.get(ThreadLocalRandom.current().nextInt(list.size()));
|
||||
return servers.get(ThreadLocalRandom.current().nextInt(servers.size()));
|
||||
}
|
||||
},
|
||||
|
||||
FILLER {
|
||||
@Override
|
||||
public ServerInfo requestTarget(PlayerBalancer plugin, ServerSection section, List<ServerInfo> list, ProxiedPlayer player) {
|
||||
public ServerInfo requestTarget(PlayerBalancer plugin, ServerSection section, List<ServerInfo> servers, ProxiedPlayer player) {
|
||||
int max = Integer.MIN_VALUE;
|
||||
ServerInfo target = null;
|
||||
|
||||
for (ServerInfo server : list) {
|
||||
for (ServerInfo server : servers) {
|
||||
ServerStatus status = plugin.getStatusManager().getStatus(server);
|
||||
int count = plugin.getNetworkManager().getPlayers(server);
|
||||
|
||||
@ -100,5 +100,5 @@ public enum ProviderType {
|
||||
}
|
||||
};
|
||||
|
||||
public abstract ServerInfo requestTarget(PlayerBalancer plugin, ServerSection section, List<ServerInfo> list, ProxiedPlayer player);
|
||||
public abstract ServerInfo requestTarget(PlayerBalancer plugin, ServerSection section, List<ServerInfo> servers, ProxiedPlayer player);
|
||||
}
|
@ -11,21 +11,21 @@ import java.util.Map;
|
||||
public class ServerAssignRegistry {
|
||||
private static final Table<ProxiedPlayer, ServerSection, ServerInfo> table = HashBasedTable.create();
|
||||
|
||||
public static void assignTarget(ProxiedPlayer player, ServerSection group, ServerInfo server) {
|
||||
public static void assignTarget(ProxiedPlayer player, ServerSection section, ServerInfo server) {
|
||||
synchronized (table) {
|
||||
table.put(player, group, server);
|
||||
table.put(player, section, server);
|
||||
}
|
||||
}
|
||||
|
||||
public static void revokeTarget(ProxiedPlayer player, ServerSection group) {
|
||||
public static void revokeTarget(ProxiedPlayer player, ServerSection section) {
|
||||
synchronized (table) {
|
||||
table.remove(player, group);
|
||||
table.remove(player, section);
|
||||
}
|
||||
}
|
||||
|
||||
public static ServerInfo getAssignedServer(ProxiedPlayer player, ServerSection group) {
|
||||
public static ServerInfo getAssignedServer(ProxiedPlayer player, ServerSection section) {
|
||||
synchronized (table) {
|
||||
return table.get(player, group);
|
||||
return table.get(player, section);
|
||||
}
|
||||
}
|
||||
|
||||
@ -41,9 +41,9 @@ public class ServerAssignRegistry {
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean hasAssignedServer(ProxiedPlayer player, ServerSection group) {
|
||||
public static boolean hasAssignedServer(ProxiedPlayer player, ServerSection section) {
|
||||
synchronized (table) {
|
||||
return table.contains(player, group);
|
||||
return table.contains(player, section);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2,23 +2,16 @@ package com.jaimemartz.playerbalancer.section;
|
||||
|
||||
import com.jaimemartz.playerbalancer.PlayerBalancer;
|
||||
import com.jaimemartz.playerbalancer.commands.FallbackCommand;
|
||||
import com.jaimemartz.playerbalancer.settings.props.shared.CommandProps;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
|
||||
public class SectionCommand extends FallbackCommand {
|
||||
private final ServerSection section;
|
||||
|
||||
public SectionCommand(PlayerBalancer plugin, CommandProps props, ServerSection section) {
|
||||
super(plugin, props);
|
||||
public SectionCommand(PlayerBalancer plugin, ServerSection section) {
|
||||
super(plugin, section.getProps().getCommandProps());
|
||||
this.section = section;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
super.execute(sender, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServerSection getSection(ProxiedPlayer player) {
|
||||
return section;
|
||||
|
@ -3,7 +3,6 @@ package com.jaimemartz.playerbalancer.section;
|
||||
import com.jaimemartz.playerbalancer.PlayerBalancer;
|
||||
import com.jaimemartz.playerbalancer.settings.props.features.BalancerProps;
|
||||
import com.jaimemartz.playerbalancer.settings.props.shared.SectionProps;
|
||||
import com.jaimemartz.playerbalancer.utils.FakeServer;
|
||||
import com.jaimemartz.playerbalancer.utils.FixedAdapter;
|
||||
import net.md_5.bungee.api.config.ServerInfo;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
@ -208,7 +207,7 @@ public class SectionManager {
|
||||
@Override
|
||||
public void execute(String sectionName, SectionProps sectionProps, ServerSection section) throws RuntimeException {
|
||||
if (sectionProps.getServerName() != null) {
|
||||
FakeServer server = new FakeServer(section);
|
||||
SectionServer server = new SectionServer(section);
|
||||
section.setServer(server);
|
||||
plugin.getSectionManager().register(server, section);
|
||||
FixedAdapter.getFakeServers().put(server.getName(), server);
|
||||
@ -219,8 +218,8 @@ public class SectionManager {
|
||||
new SectionStage("Section command processing") {
|
||||
@Override
|
||||
public void execute(String sectionName, SectionProps sectionProps, ServerSection section) throws RuntimeException {
|
||||
if (sectionProps.getCommand() != null) {
|
||||
SectionCommand command = new SectionCommand(plugin, sectionProps.getCommand(), section);
|
||||
if (sectionProps.getCommandProps() != null) {
|
||||
SectionCommand command = new SectionCommand(plugin, section);
|
||||
section.setCommand(command);
|
||||
plugin.getProxy().getPluginManager().registerCommand(plugin, command);
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
package com.jaimemartz.playerbalancer.utils;
|
||||
package com.jaimemartz.playerbalancer.section;
|
||||
|
||||
import com.jaimemartz.playerbalancer.section.ServerSection;
|
||||
import net.md_5.bungee.BungeeServerInfo;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
|
||||
@ -9,10 +8,10 @@ import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
public class FakeServer extends BungeeServerInfo {
|
||||
public class SectionServer extends BungeeServerInfo {
|
||||
private final ServerSection section;
|
||||
|
||||
public FakeServer(ServerSection section) {
|
||||
public SectionServer(ServerSection section) {
|
||||
|
||||
super(
|
||||
"@" + section.getProps().getServerName(),
|
@ -27,8 +27,9 @@ public class ServerSection {
|
||||
this.name = name;
|
||||
this.props = props;
|
||||
|
||||
AlphanumComparator<ServerInfo> comparator = new AlphanumComparator<>();
|
||||
this.servers = Collections.synchronizedSortedSet(new TreeSet<>(comparator));
|
||||
this.servers = Collections.synchronizedSortedSet(new TreeSet<>((lhs, rhs) ->
|
||||
AlphanumComparator.getInstance().compare(lhs.getName(), rhs.getName())
|
||||
));
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
|
@ -17,8 +17,8 @@ public class SectionProps {
|
||||
@Setting(value = "servers")
|
||||
private List<String> serverEntries;
|
||||
|
||||
@Setting(value = "section-command")
|
||||
private CommandProps command;
|
||||
@Setting(value = "section-commandProps")
|
||||
private CommandProps commandProps;
|
||||
|
||||
@Setting(value = "section-server")
|
||||
private String serverName;
|
||||
@ -47,12 +47,12 @@ public class SectionProps {
|
||||
this.serverEntries = serverEntries;
|
||||
}
|
||||
|
||||
public CommandProps getCommand() {
|
||||
return command;
|
||||
public CommandProps getCommandProps() {
|
||||
return commandProps;
|
||||
}
|
||||
|
||||
public void setCommand(CommandProps command) {
|
||||
this.command = command;
|
||||
public void setCommandProps(CommandProps commandProps) {
|
||||
this.commandProps = commandProps;
|
||||
}
|
||||
|
||||
public String getServerName() {
|
||||
@ -69,7 +69,7 @@ public class SectionProps {
|
||||
"provider=" + provider +
|
||||
", parentName='" + parentName + '\'' +
|
||||
", serverEntries=" + serverEntries +
|
||||
", command=" + command +
|
||||
", commandProps=" + commandProps +
|
||||
", serverName='" + serverName + '\'' +
|
||||
'}';
|
||||
}
|
||||
|
@ -7,43 +7,44 @@ package com.jaimemartz.playerbalancer.utils;
|
||||
*
|
||||
* The Alphanum Algorithm is discussed at http://www.DaveKoelle.com
|
||||
*
|
||||
* Released under the MIT License - https://opensource.org/licenses/MIT
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or any later version.
|
||||
* Copyright 2007-2017 David Koelle
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
* The above copyright notice and this permission notice shall be included
|
||||
* in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
||||
* USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import java.util.Comparator;
|
||||
|
||||
/**
|
||||
* This is an updated version with enhancements made by Daniel Migowski,
|
||||
* Andre Bogus, and David Koelle
|
||||
*
|
||||
* To convert to use Templates (Java 1.5+):
|
||||
* - Change "implements Comparator" to "implements Comparator<String>"
|
||||
* - Change "compare(Object o1, Object o2)" to "compare(String s1, String s2)"
|
||||
* - Remove the type checking and casting in compare().
|
||||
* Andre Bogus, and David Koelle. Updated by David Koelle in 2017.
|
||||
*
|
||||
* To use this class:
|
||||
* Use the static "sort" method from the java.util.Collections class:
|
||||
* Collections.sort(your list, new AlphanumComparator());
|
||||
*/
|
||||
public final class AlphanumComparator<T> implements Comparator<T>
|
||||
public class AlphanumComparator implements Comparator<String>
|
||||
{
|
||||
private final boolean isDigit(char ch)
|
||||
{
|
||||
return ch >= 48 && ch <= 57;
|
||||
return ((ch >= 48) && (ch <= 57));
|
||||
}
|
||||
|
||||
/** Length of string is passed in for improved efficiency (only need to calculate it once) **/
|
||||
@ -77,14 +78,12 @@ public final class AlphanumComparator<T> implements Comparator<T>
|
||||
return chunk.toString();
|
||||
}
|
||||
|
||||
public int compare(Object o1, Object o2)
|
||||
public int compare(String s1, String s2)
|
||||
{
|
||||
if (!(o1 instanceof String) || !(o2 instanceof String))
|
||||
if ((s1 == null) || (s2 == null))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
String s1 = (String)o1;
|
||||
String s2 = (String)o2;
|
||||
|
||||
int thisMarker = 0;
|
||||
int thatMarker = 0;
|
||||
@ -118,7 +117,8 @@ public final class AlphanumComparator<T> implements Comparator<T>
|
||||
}
|
||||
}
|
||||
}
|
||||
} else
|
||||
}
|
||||
else
|
||||
{
|
||||
result = thisChunk.compareTo(thatChunk);
|
||||
}
|
||||
@ -129,4 +129,9 @@ public final class AlphanumComparator<T> implements Comparator<T>
|
||||
|
||||
return s1Length - s2Length;
|
||||
}
|
||||
|
||||
private static final AlphanumComparator instance = new AlphanumComparator();
|
||||
public static AlphanumComparator getInstance() {
|
||||
return instance;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user