Skip to content

Commit

Permalink
compare lowercase addresses/names, cleanup code
Browse files Browse the repository at this point in the history
  • Loading branch information
JulianVennen committed May 27, 2022
1 parent 09a2407 commit cf08d49
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 24 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ This plugin can be used on proxies that don't run on exaroton as well.
### Start/Stop commands
Start a server and automatically add it to the network
when it goes online with `/exaroton start <server>`.
To stop a server and remove it use `/exaroton stop`.
To stop a server and remove it, use `/exaroton stop`.
Restarting a server is possible with `/exaroton restart`.

To start watching a server, or to add a server that is already online
use `/exaroton add`. To remove a server from the proxy and stop watching
it use `/exaroton remove`.
it, use `/exaroton remove`.

The commands require the permission nodes `exaroton.<subcommand>` e.g.
`exaroton.stop`.
Expand All @@ -40,7 +40,7 @@ Automatically start exaroton servers defined in the plugin config
when the proxy starts and add them to the network.
This can be enabled in the config.

### Autostop
### Auto-stop
Automatically stop exaroton servers defined in the plugin config
when the proxy shuts down.
This can be enabled in the config.
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ dependencies {
shadow group: 'net.md-5', name: 'bungeecord-api', version: '1.16-R0.5-SNAPSHOT'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.2'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.2'
implementation 'com.exaroton:api:1.4.0'
implementation 'com.exaroton:api:1.4.2'
}

ext.isReleaseVersion = !version.endsWith("SNAPSHOT")
Expand Down
16 changes: 9 additions & 7 deletions src/main/java/com/exaroton/bungee/ExarotonPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public class ExarotonPlugin extends Plugin {

/**
* server status listeners
* serverid -> status listener
* server id -> status listener
*/
private final HashMap<String, ServerStatusListener> statusListeners = new HashMap<>();

Expand Down Expand Up @@ -225,7 +225,10 @@ public Server findServer(String query, boolean force) throws APIException {
* @return does the server match exactly
*/
public boolean matchExact(Server server, String query) {
return server.getAddress().equals(query) || server.getName().equals(query) || server.getId().equals(query);
query = query.toLowerCase(Locale.ROOT);
return server.getAddress().toLowerCase(Locale.ROOT).equals(query) ||
server.getName().toLowerCase(Locale.ROOT).equals(query) ||
server.getId().equals(query);
}

/**
Expand Down Expand Up @@ -490,14 +493,13 @@ public void autoStartServers() {
continue;
}

if (server.hasStatus(new int[]{ServerStatus.STARTING,
ServerStatus.LOADING, ServerStatus.PREPARING, ServerStatus.RESTARTING})) {
if (server.hasStatus(ServerStatus.STARTING, ServerStatus.LOADING, ServerStatus.PREPARING, ServerStatus.RESTARTING)) {
logger.log(Level.INFO, name + " is already online or starting!");
this.listenToStatus(server, null, name, ServerStatus.ONLINE);
continue;
}

if (!server.hasStatus(new int[]{ServerStatus.OFFLINE, ServerStatus.CRASHED})) {
if (!server.hasStatus(ServerStatus.OFFLINE, ServerStatus.CRASHED)) {
logger.log(Level.SEVERE, "Can't start " + name + ": Server isn't offline.");
continue;
}
Expand Down Expand Up @@ -564,12 +566,12 @@ public void autoStopServers() {
}

String name = findServerName(server.getAddress(), server.getName());
if (server.hasStatus(new int[]{ServerStatus.OFFLINE, ServerStatus.CRASHED})) {
if (server.hasStatus(ServerStatus.OFFLINE, ServerStatus.CRASHED)) {
logger.log(Level.INFO, name + " is already offline!");
continue;
}

if (server.hasStatus(new int[]{ServerStatus.SAVING, ServerStatus.STOPPING})) {
if (server.hasStatus(ServerStatus.SAVING, ServerStatus.STOPPING)) {
logger.log(Level.INFO, name + " is already stopping!");
continue;
}
Expand Down
12 changes: 5 additions & 7 deletions src/main/java/com/exaroton/bungee/ExarotonPluginAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,15 @@
import net.md_5.bungee.api.config.ServerInfo;
import net.md_5.bungee.api.connection.ProxiedPlayer;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

public class ExarotonPluginAPI {

private static ExarotonPlugin plugin;

/**
* find a server by it's
* find a server by its
* - proxy name
* - id
* - address (e.g. example.exaroton.me)
Expand All @@ -40,7 +38,7 @@ public static boolean startServer(Server server) throws APIException {
throw new NullPointerException("No server provided!");
}

if (!server.hasStatus(new int[]{ServerStatus.OFFLINE, ServerStatus.CRASHED})) {
if (!server.hasStatus(ServerStatus.OFFLINE, ServerStatus.CRASHED)) {
return false;
}

Expand Down Expand Up @@ -116,7 +114,7 @@ public static boolean addServer(Server server) {
}

/**
* watch this server
* watch this server,
* add it the proxy when it becomes online
* remove it when it goes offline
* @param server server to watch
Expand Down Expand Up @@ -154,9 +152,9 @@ public static void switchServer(ProxiedPlayer player, Server server) throws APIE
throw new NullPointerException("No server provided!");
}

if (server.hasStatus(new int[]{ServerStatus.OFFLINE, ServerStatus.CRASHED, ServerStatus.LOADING, ServerStatus.STARTING, ServerStatus.PREPARING})) {
if (server.hasStatus(ServerStatus.OFFLINE, ServerStatus.CRASHED, ServerStatus.LOADING, ServerStatus.STARTING, ServerStatus.PREPARING)) {
ServerStatusListener listener = watchServer(server);
if (server.hasStatus(new int[]{ServerStatus.OFFLINE, ServerStatus.CRASHED})) {
if (server.hasStatus(ServerStatus.OFFLINE, ServerStatus.CRASHED)) {
server.start();
}
try {
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/com/exaroton/bungee/Message.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
import net.md_5.bungee.api.chat.TextComponent;

import java.util.Collection;
import java.util.Map;
import java.util.Set;

public class Message {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import com.exaroton.bungee.SubCommand;
import net.md_5.bungee.api.CommandSender;

import java.util.List;
import java.util.logging.Level;

public class AddServer extends SubCommand {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public void execute(CommandSender sender, String[] args) {
return;
}

if (!server.hasStatus(new int[]{ServerStatus.OFFLINE, ServerStatus.CRASHED})) {
if (!server.hasStatus(ServerStatus.OFFLINE, ServerStatus.CRASHED)) {
sender.sendMessage(Message.SERVER_NOT_OFFLINE);
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@

import com.exaroton.api.APIException;
import com.exaroton.api.server.Server;
import com.exaroton.api.server.ServerStatus;
import com.exaroton.bungee.*;
import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.connection.ProxiedPlayer;

import java.util.concurrent.ExecutionException;
import java.util.logging.Level;

public class SwitchServer extends SubCommand {
Expand Down

0 comments on commit cf08d49

Please sign in to comment.