Spaces at the start of line comments

This commit is contained in:
Jaime Martinez Rincon 2020-06-20 22:28:24 +02:00
parent 29099a493f
commit 2d2a7d8f9e
15 changed files with 57 additions and 61 deletions

View File

@ -19,7 +19,7 @@ public class PlayerBalancerAddon extends JavaPlugin {
@Override @Override
public void onDisable() { public void onDisable() {
//Nothing to do... // Nothing to do...
} }
public PluginMessageManager getManager() { public PluginMessageManager getManager() {

View File

@ -22,8 +22,8 @@ public class PlayerBalancerPlaceholderExpansion extends PlaceholderExpansion {
if (section == null) if (section == null)
return null; return null;
//For the first call this placeholder will return 0 // For the first call this placeholder will return 0
//For the next one, the result of the previous one // For the next one, the result of the previous one
plugin.getManager().getSectionPlayerCount(section, (count) -> { plugin.getManager().getSectionPlayerCount(section, (count) -> {
sectionPlayerCounts.put(section, count); sectionPlayerCounts.put(section, count);
}); });

View File

@ -27,7 +27,7 @@ public class PluginMessageManager implements PluginMessageListener {
plugin.getServer().getMessenger().registerIncomingPluginChannel(plugin, PB_CHANNEL, this); plugin.getServer().getMessenger().registerIncomingPluginChannel(plugin, PB_CHANNEL, this);
plugin.getServer().getMessenger().registerOutgoingPluginChannel(plugin, PB_CHANNEL); plugin.getServer().getMessenger().registerOutgoingPluginChannel(plugin, PB_CHANNEL);
//In case we need to use BungeeCord channels // In case we need to use BungeeCord channels
plugin.getServer().getMessenger().registerIncomingPluginChannel(plugin, BC_CHANNEL, this); plugin.getServer().getMessenger().registerIncomingPluginChannel(plugin, BC_CHANNEL, this);
plugin.getServer().getMessenger().registerOutgoingPluginChannel(plugin, BC_CHANNEL); plugin.getServer().getMessenger().registerOutgoingPluginChannel(plugin, BC_CHANNEL);
} }

View File

@ -78,7 +78,7 @@ public class PlayerBalancer extends Plugin {
public boolean checkUpToDate() { public boolean checkUpToDate() {
try { try {
URLConnection con = new URL("https://api.spigotmc.org/legacy/update.php?resource=10788").openConnection(); URLConnection con = new URL("https:// api.spigotmc.org/legacy/update.php?resource=10788").openConnection();
String reply = new BufferedReader(new InputStreamReader(con.getInputStream())).readLine(); String reply = new BufferedReader(new InputStreamReader(con.getInputStream())).readLine();
return getDescription().getVersion().equals(reply); return getDescription().getVersion().equals(reply);
} catch (IOException e) { } catch (IOException e) {
@ -89,7 +89,7 @@ public class PlayerBalancer extends Plugin {
@Override @Override
public void onDisable() { public void onDisable() {
//Nothing else to do than normal stop // Nothing else to do than normal stop
this.execStop(); this.execStop();
} }
@ -198,7 +198,7 @@ public class PlayerBalancer extends Plugin {
} }
if (settings.getGeneralProps().isEnabled()) { if (settings.getGeneralProps().isEnabled()) {
//Do not try to do anything if the plugin has not loaded correctly // Do not try to do anything if the plugin has not loaded correctly
if (failed) return; if (failed) return;
if (settings.getGeneralProps().isAutoReload()) { if (settings.getGeneralProps().isAutoReload()) {

View File

@ -39,14 +39,10 @@ public abstract class ConnectionIntent {
.replace("{alias}", safeNull(section.getProps().getAlias())) .replace("{alias}", safeNull(section.getProps().getAlias()))
); );
// Ensure a new copy of the section servers
List<ServerInfo> servers = new ArrayList<>(section.getServers()); List<ServerInfo> servers = new ArrayList<>(section.getServers());
//Prevents removing servers from the section // Prevents connections to the same server
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(); Server current = player.getServer();
if (current != null) { if (current != null) {
servers.remove(current.getInfo()); servers.remove(current.getInfo());
@ -56,7 +52,7 @@ public abstract class ConnectionIntent {
ServerInfo target = this.fetchServer(player, section, section.getImplicitProvider(), servers); ServerInfo target = this.fetchServer(player, section, section.getImplicitProvider(), servers);
if (target != null) { if (target != null) {
this.connect(target, (response, throwable) -> { this.connect(target, (response, throwable) -> {
if (response) { //only if the connect has been executed correctly if (response) { // only if the connect has been executed correctly
MessageUtils.send(player, plugin.getSettings().getMessagesProps().getConnectedMessage(), MessageUtils.send(player, plugin.getSettings().getMessagesProps().getConnectedMessage(),
(str) -> str.replace("{server}", target.getName()) (str) -> str.replace("{server}", target.getName())
.replace("{section}", section.getName()) .replace("{section}", section.getName())

View File

@ -37,7 +37,7 @@ public enum PasteHelper {
try (FileInputStream stream = new FileInputStream(file)) { try (FileInputStream stream = new FileInputStream(file)) {
try (InputStreamReader reader = new InputStreamReader(stream, "UTF-8")) { try (InputStreamReader reader = new InputStreamReader(stream, "UTF-8")) {
String content = CharStreams.toString(reader); String content = CharStreams.toString(reader);
HastebinPaste paste = new HastebinPaste("https://file.properties/paste/", content); HastebinPaste paste = new HastebinPaste("https:// file.properties/paste/", content);
return paste.paste(); return paste.paste();
} }
} }
@ -62,7 +62,7 @@ public enum PasteHelper {
try (InputStreamReader reader = new InputStreamReader(stream, StandardCharsets.UTF_8)) { try (InputStreamReader reader = new InputStreamReader(stream, StandardCharsets.UTF_8)) {
String content = CharStreams.toString(reader); String content = CharStreams.toString(reader);
content = content.replaceAll("[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}", "?.?.?.?"); content = content.replaceAll("[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}", "?.?.?.?");
HastebinPaste paste = new HastebinPaste("https://file.properties/paste/", content); HastebinPaste paste = new HastebinPaste("https:// file.properties/paste/", content);
return paste.paste(); return paste.paste();
} }
} }
@ -86,7 +86,7 @@ public enum PasteHelper {
try (FileInputStream stream = new FileInputStream(file)) { try (FileInputStream stream = new FileInputStream(file)) {
try (InputStreamReader reader = new InputStreamReader(stream, StandardCharsets.UTF_8)) { try (InputStreamReader reader = new InputStreamReader(stream, StandardCharsets.UTF_8)) {
String content = CharStreams.toString(reader); String content = CharStreams.toString(reader);
HastebinPaste paste = new HastebinPaste("https://file.properties/paste/", content); HastebinPaste paste = new HastebinPaste("https:// file.properties/paste/", content);
return paste.paste(); return paste.paste();
} }
} }

View File

@ -31,7 +31,7 @@ public class PluginMessageListener implements Listener {
this.plugin = plugin; this.plugin = plugin;
GsonBuilder builder = new GsonBuilder(); GsonBuilder builder = new GsonBuilder();
//Only serialize the name of ServerInfo // Only serialize the name of ServerInfo
builder.registerTypeAdapter(ServerInfo.class, (JsonSerializer<ServerInfo>) (server, type, context) -> builder.registerTypeAdapter(ServerInfo.class, (JsonSerializer<ServerInfo>) (server, type, context) ->
context.serialize(server.getName()) context.serialize(server.getName())
); );

View File

@ -56,7 +56,7 @@ public class ServerConnectListener implements Listener {
ServerSection section = plugin.getSectionManager().getByServer(target); ServerSection section = plugin.getSectionManager().getByServer(target);
if (section != null) { if (section != null) {
//Checks only for servers (not the section server) // Checks only for servers (not the section server)
if (!target.equals(section.getServer())) { if (!target.equals(section.getServer())) {
if (plugin.getSectionManager().isDummy(section)) { if (plugin.getSectionManager().isDummy(section)) {
return null; return null;

View File

@ -37,7 +37,7 @@ public enum PingTactic {
try { try {
server.ping((ping, throwable) -> { server.ping((ping, throwable) -> {
if (ping != null) { if (ping != null) {
//using deprecated method for bungee 1.8 compatibility // Using deprecated method for bungee 1.8 compatibility
callback.done(new ServerStatus( callback.done(new ServerStatus(
ping.getDescription(), ping.getDescription(),
ping.getPlayers().getOnline(), ping.getPlayers().getOnline(),

View File

@ -236,8 +236,8 @@ public class SectionManager {
public void registerServer(ServerInfo server, ServerSection section) { public void registerServer(ServerInfo server, ServerSection section) {
if (!isDummy(section)) { if (!isDummy(section)) {
// Checking for already we already added this server to other section // Checking for already we already added this server to other section
// This can only happen if another non dummy section registers this server // This can only happen if another non dummy section registers this server
if (servers.containsKey(server)) { if (servers.containsKey(server)) {
ServerSection other = servers.get(server); ServerSection other = servers.get(server);
throw new IllegalArgumentException(String.format( throw new IllegalArgumentException(String.format(
@ -259,7 +259,7 @@ public class SectionManager {
public void calculateServers(ServerSection section) { public void calculateServers(ServerSection section) {
Set<ServerInfo> results = new HashSet<>(); Set<ServerInfo> results = new HashSet<>();
//Searches for matches // Searches for matches
section.getProps().getServerEntries().forEach(entry -> { section.getProps().getServerEntries().forEach(entry -> {
Pattern pattern = Pattern.compile(entry); Pattern pattern = Pattern.compile(entry);
plugin.getProxy().getServers().forEach((name, server) -> { plugin.getProxy().getServers().forEach((name, server) -> {
@ -270,7 +270,7 @@ public class SectionManager {
}); });
}); });
//Checks if there are servers previously matched that are no longer valid // Checks if there are servers previously matched that are no longer valid
section.getServers().forEach(server -> { section.getServers().forEach(server -> {
if (!results.contains(server)) { if (!results.contains(server)) {
servers.remove(server); servers.remove(server);
@ -281,7 +281,7 @@ public class SectionManager {
} }
}); });
//Add matched servers to the section // Add matched servers to the section
int addedServers = 0; int addedServers = 0;
for (ServerInfo server : results) { for (ServerInfo server : results) {
if (!section.getServers().contains(server)) { if (!section.getServers().contains(server)) {
@ -306,7 +306,7 @@ public class SectionManager {
public int calculatePosition(ServerSection section) { public int calculatePosition(ServerSection section) {
ServerSection current = section; ServerSection current = section;
//Calculate above principal // Calculate above principal
int iterations = 0; int iterations = 0;
while (current != null) { while (current != null) {
if (current == principal) { if (current == principal) {
@ -317,7 +317,7 @@ public class SectionManager {
iterations++; iterations++;
} }
//Calculate below principal // Calculate below principal
if (principal != null) { if (principal != null) {
iterations = 0; iterations = 0;
current = principal; current = principal;

View File

@ -47,7 +47,7 @@ public class SectionServer extends BungeeServerInfo {
@Override @Override
public boolean sendData(String channel, byte[] data, boolean queue) { public boolean sendData(String channel, byte[] data, boolean queue) {
//Nothing to do // Nothing to do
return true; return true;
} }

View File

@ -11,7 +11,7 @@ public class AdapterWrapper implements ConfigurationAdapter {
private final ConfigurationAdapter wrapped; private final ConfigurationAdapter wrapped;
public AdapterWrapper(ConfigurationAdapter adapter) { public AdapterWrapper(ConfigurationAdapter adapter) {
//Prevents memory leak // Prevents memory leak
if (adapter instanceof AdapterWrapper) { if (adapter instanceof AdapterWrapper) {
this.wrapped = ((AdapterWrapper) adapter).wrapped; this.wrapped = ((AdapterWrapper) adapter).wrapped;
} else { } else {

View File

@ -98,14 +98,14 @@ public class AlphanumComparator implements Comparator<String>
String thatChunk = getChunk(s2, s2Length, thatMarker); String thatChunk = getChunk(s2, s2Length, thatMarker);
thatMarker += thatChunk.length(); thatMarker += thatChunk.length();
// If both chunks contain numeric characters, sort them numerically // If both chunks contain numeric characters, sort them numerically
int result = 0; int result = 0;
if (isDigit(thisChunk.charAt(0)) && isDigit(thatChunk.charAt(0))) if (isDigit(thisChunk.charAt(0)) && isDigit(thatChunk.charAt(0)))
{ {
// Simple chunk comparison by length. // Simple chunk comparison by length.
int thisChunkLength = thisChunk.length(); int thisChunkLength = thisChunk.length();
result = thisChunkLength - thatChunk.length(); result = thisChunkLength - thatChunk.length();
// If equal, the first different number counts // If equal, the first different number counts
if (result == 0) if (result == 0)
{ {
for (int i = 0; i < thisChunkLength; i++) for (int i = 0; i < thisChunkLength; i++)

View File

@ -20,35 +20,35 @@ public final class LevenshteinDistance {
int len0 = lhs.length() + 1; int len0 = lhs.length() + 1;
int len1 = rhs.length() + 1; int len1 = rhs.length() + 1;
// the array of distances // the array of distances
int[] cost = new int[len0]; int[] cost = new int[len0];
int[] newcost = new int[len0]; int[] newcost = new int[len0];
// initial cost of skipping prefix in String s0 // initial cost of skipping prefix in String s0
for (int i = 0; i < len0; i++) cost[i] = i; for (int i = 0; i < len0; i++) cost[i] = i;
// dynamically computing the array of distances // dynamically computing the array of distances
// transformation cost for each letter in s1 // transformation cost for each letter in s1
for (int j = 1; j < len1; j++) { for (int j = 1; j < len1; j++) {
// initial cost of skipping prefix in String s1 // initial cost of skipping prefix in String s1
newcost[0] = j; newcost[0] = j;
// transformation cost for each letter in s0 // transformation cost for each letter in s0
for (int i = 1; i < len0; i++) { for (int i = 1; i < len0; i++) {
// matching current letters in both strings // matching current letters in both strings
int match = (lhs.charAt(i - 1) == rhs.charAt(j - 1)) ? 0 : 1; int match = (lhs.charAt(i - 1) == rhs.charAt(j - 1)) ? 0 : 1;
// computing cost for each transformation // computing cost for each transformation
int cost_replace = cost[i - 1] + match; int cost_replace = cost[i - 1] + match;
int cost_insert = cost[i] + 1; int cost_insert = cost[i] + 1;
int cost_delete = newcost[i - 1] + 1; int cost_delete = newcost[i - 1] + 1;
// keep minimum cost // keep minimum cost
newcost[i] = Math.min(Math.min(cost_insert, cost_delete), cost_replace); newcost[i] = Math.min(Math.min(cost_insert, cost_delete), cost_replace);
} }
// swap cost/newcost arrays // swap cost/newcost arrays
int[] swap = cost; int[] swap = cost;
cost = newcost; cost = newcost;
newcost = swap; newcost = swap;

View File

@ -56,31 +56,31 @@ public final class ServerListPing {
DataInputStream dataInputStream = new DataInputStream(socket.getInputStream())) { DataInputStream dataInputStream = new DataInputStream(socket.getInputStream())) {
ByteArrayOutputStream b = new ByteArrayOutputStream(); ByteArrayOutputStream b = new ByteArrayOutputStream();
DataOutputStream handshake = new DataOutputStream(b); DataOutputStream handshake = new DataOutputStream(b);
handshake.writeByte(0x00); //packet id for handshake handshake.writeByte(0x00); // packet id for handshake
writeVarInt(handshake, 4); //protocol version writeVarInt(handshake, 4); // protocol version
writeVarInt(handshake, host.getHostString().length()); //host length writeVarInt(handshake, host.getHostString().length()); // host length
handshake.writeBytes(host.getHostString()); //host string handshake.writeBytes(host.getHostString()); // host string
handshake.writeShort(host.getPort()); //port handshake.writeShort(host.getPort()); // port
writeVarInt(handshake, 1); //state (1 for handshake) writeVarInt(handshake, 1); // state (1 for handshake)
writeVarInt(dataOutputStream, b.size()); //prepend size writeVarInt(dataOutputStream, b.size()); // prepend size
dataOutputStream.write(b.toByteArray()); //write handshake packet dataOutputStream.write(b.toByteArray()); // write handshake packet
dataOutputStream.writeByte(0x01); //size is only 1 dataOutputStream.writeByte(0x01); // size is only 1
dataOutputStream.writeByte(0x00); //packet id for ping dataOutputStream.writeByte(0x00); // packet id for ping
int size = readVarInt(dataInputStream); //size of packet int size = readVarInt(dataInputStream); // size of packet
int id = readVarInt(dataInputStream); //packet id int id = readVarInt(dataInputStream); // packet id
if (id == -1) { if (id == -1) {
throw new IOException("Premature end of stream."); throw new IOException("Premature end of stream.");
} }
if (id != 0x00) { //we want a status response if (id != 0x00) { // we want a status response
throw new IOException("Invalid packetID"); throw new IOException("Invalid packetID");
} }
int length = readVarInt(dataInputStream); //length of json string int length = readVarInt(dataInputStream); // length of json string
if (length == -1) { if (length == -1) {
throw new IOException("Premature end of stream."); throw new IOException("Premature end of stream.");
} }
@ -90,14 +90,14 @@ public final class ServerListPing {
} }
byte[] in = new byte[length]; byte[] in = new byte[length];
dataInputStream.readFully(in); //read json string dataInputStream.readFully(in); // read json string
String json = new String(in); String json = new String(in);
long now = System.currentTimeMillis(); long now = System.currentTimeMillis();
dataOutputStream.writeByte(0x09); //size of packet dataOutputStream.writeByte(0x09); // size of packet
dataOutputStream.writeByte(0x01); //0x01 for ping dataOutputStream.writeByte(0x01); // 0x01 for ping
dataOutputStream.writeLong(now); //time!? dataOutputStream.writeLong(now); // time!?
readVarInt(dataInputStream); readVarInt(dataInputStream);
id = readVarInt(dataInputStream); id = readVarInt(dataInputStream);
@ -109,7 +109,7 @@ public final class ServerListPing {
throw new IOException("Invalid packetID"); throw new IOException("Invalid packetID");
} }
long pingTime = dataInputStream.readLong(); //read response long pingTime = dataInputStream.readLong(); // read response
StatusResponse response = gson.fromJson(json, StatusResponse.class); StatusResponse response = gson.fromJson(json, StatusResponse.class);
response.time = (int) (now - pingTime); response.time = (int) (now - pingTime);
return response; return response;