Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
54d20e9e50 | ||
|
|
fd0e361474 | ||
|
|
551e38f882 | ||
|
|
d18f04c010 | ||
|
|
3b7f3043f1 | ||
|
|
faf2a8d083 | ||
|
|
42071e3bad | ||
|
|
978d32e947 | ||
|
|
fe670cb3e2 | ||
|
|
d2f4a7d9a5 | ||
|
|
b162ce1825 | ||
|
|
fbdcce3c3b | ||
|
|
2d939f095c | ||
|
|
034e2f2b98 | ||
|
|
f429ab0a60 | ||
|
|
5578d0879b | ||
|
|
8b1e6244ea | ||
|
|
49c7b9c775 | ||
|
|
da1c724464 | ||
|
|
de15150a04 | ||
|
|
0d1fb2b260 | ||
|
|
55d0779a33 | ||
|
|
8f41d464e1 | ||
|
|
1db2b6c934 |
No files matched your search
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<artifactId>maintenance-base</artifactId>
|
||||
<groupId>eu.kennytv</groupId>
|
||||
<version>2.5.1</version>
|
||||
<version>2.5.2</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>maintenance-api</artifactId>
|
||||
|
||||
@@ -65,4 +65,6 @@ public interface ISettings {
|
||||
* @return true if loading the image was successful
|
||||
*/
|
||||
boolean reloadMaintenanceIcon();
|
||||
|
||||
boolean debugEnabled();
|
||||
}
|
||||
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<artifactId>maintenance-base</artifactId>
|
||||
<groupId>eu.kennytv</groupId>
|
||||
<version>2.5.1</version>
|
||||
<version>2.5.2</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>maintenance-bungee</artifactId>
|
||||
|
||||
+14
-17
@@ -70,7 +70,6 @@ public final class MaintenanceBungeePlugin extends MaintenanceModePlugin impleme
|
||||
settings.setMaintenance(maintenance);
|
||||
settings.setToConfig("enable-maintenance-mode", maintenance);
|
||||
settings.saveConfig();
|
||||
settings.reloadConfigs();
|
||||
}
|
||||
|
||||
serverActions(maintenance);
|
||||
@@ -93,16 +92,25 @@ public final class MaintenanceBungeePlugin extends MaintenanceModePlugin impleme
|
||||
|
||||
@Override
|
||||
public boolean isMaintenance(final ServerInfo server) {
|
||||
return settings.getMaintenanceServers().contains(server.getName());
|
||||
return settings.isMaintenance(server);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setMaintenanceToServer(final ServerInfo server, final boolean maintenance) {
|
||||
if (maintenance) {
|
||||
if (!settings.getMaintenanceServers().add(server.getName())) return false;
|
||||
if (!settings.addMaintenanceServer(server.getName())) return false;
|
||||
} else {
|
||||
if (!settings.removeMaintenanceServer(server.getName())) return false;
|
||||
}
|
||||
serverActions(server, maintenance);
|
||||
cancelSingleTask(server);
|
||||
return true;
|
||||
}
|
||||
|
||||
void serverActions(final ServerInfo server, final boolean maintenance) {
|
||||
if (maintenance) {
|
||||
final ServerInfo fallback = getProxy().getServerInfo(settings.getFallbackServer());
|
||||
if (fallback == null)
|
||||
if (fallback == null && !server.getPlayers().isEmpty())
|
||||
plugin.getLogger().warning("The fallback server set in the SpigotServers.yml could not be found! Instead kicking players from that server off the network!");
|
||||
else if (fallback.equals(server))
|
||||
plugin.getLogger().warning("Maintenance has been enabled on the fallback server! If a player joins on a proxied server, they will be kicked completely instead of being sent to the fallback server!");
|
||||
@@ -117,20 +125,8 @@ public final class MaintenanceBungeePlugin extends MaintenanceModePlugin impleme
|
||||
p.sendMessage(settings.getMessage("singleMaintenanceActivated").replace("%SERVER%", server.getName()));
|
||||
}
|
||||
});
|
||||
} else {
|
||||
if (!settings.getMaintenanceServers().remove(server.getName())) return false;
|
||||
} else
|
||||
server.getPlayers().forEach(p -> p.sendMessage(settings.getMessage("singleMaintenanceDeactivated").replace("%SERVER%", server.getName())));
|
||||
}
|
||||
|
||||
/*if (mySQL != null) {
|
||||
mySQL.executeUpdate(serversQuery, "spigotServers-with-maintenance", maintenanceServers, maintenanceServers);
|
||||
} else {
|
||||
spigotServers.set("maintenance-on", maintenanceServers);
|
||||
saveSpigotServers();
|
||||
}*/
|
||||
cancelSingleTask(server);
|
||||
settings.saveServersToConfig();
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -191,6 +187,7 @@ public final class MaintenanceBungeePlugin extends MaintenanceModePlugin impleme
|
||||
return plugin.getProxy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Logger getLogger() {
|
||||
return plugin.getLogger();
|
||||
}
|
||||
|
||||
+97
-31
@@ -5,6 +5,7 @@ import eu.kennytv.maintenance.bungee.mysql.MySQL;
|
||||
import eu.kennytv.maintenance.core.Settings;
|
||||
import eu.kennytv.maintenance.core.listener.IPingListener;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import net.md_5.bungee.api.config.ServerInfo;
|
||||
import net.md_5.bungee.api.plugin.PluginManager;
|
||||
import net.md_5.bungee.config.Configuration;
|
||||
import net.md_5.bungee.config.YamlConfiguration;
|
||||
@@ -16,9 +17,10 @@ import java.sql.SQLException;
|
||||
import java.util.*;
|
||||
|
||||
public final class SettingsBungee extends Settings {
|
||||
private final String updateQuery;
|
||||
private final String mySQLTable;
|
||||
private final String serverTable;
|
||||
private final String maintenanceQuery;
|
||||
//private final String serversQuery;
|
||||
private final String serverQuery;
|
||||
private final MySQL mySQL;
|
||||
|
||||
private final MaintenanceBungeePlugin maintenancePlugin;
|
||||
@@ -33,6 +35,7 @@ public final class SettingsBungee extends Settings {
|
||||
|
||||
private long millisecondsToCheck;
|
||||
private long lastMySQLCheck;
|
||||
private long lastServerCheck;
|
||||
|
||||
SettingsBungee(final MaintenanceBungeePlugin maintenancePlugin, final MaintenanceBungeeBase plugin) {
|
||||
super(maintenancePlugin);
|
||||
@@ -61,17 +64,20 @@ public final class SettingsBungee extends Settings {
|
||||
mySQLSection.getString("database"));
|
||||
|
||||
// Varchar as the value regarding the possibility of saving stuff like the motd as well in future updates
|
||||
final String mySQLTable = mySQLSection.getString("table");
|
||||
mySQLTable = mySQLSection.getString("table", "maintenance_settings");
|
||||
serverTable = mySQLSection.getString("servertable", "maintenance_servers");
|
||||
mySQL.executeUpdate("CREATE TABLE IF NOT EXISTS " + mySQLTable + " (setting VARCHAR(16) PRIMARY KEY, value VARCHAR(255))");
|
||||
updateQuery = "INSERT INTO " + mySQLTable + " (setting, value) VALUES (?, ?) ON DUPLICATE KEY UPDATE value = ?";
|
||||
mySQL.executeUpdate("CREATE TABLE IF NOT EXISTS " + serverTable + " (server VARCHAR(64) PRIMARY KEY)");
|
||||
maintenanceQuery = "SELECT * FROM " + mySQLTable + " WHERE setting = ?";
|
||||
//serversQuery = "INSERT INTO " + serversTable + " (setting, value) VALUES (?, ?) ON DUPLICATE KEY UPDATE value = ?";
|
||||
serverQuery = "SELECT * FROM " + serverTable;
|
||||
maintenance = loadMaintenance();
|
||||
plugin.getLogger().info("Done!");
|
||||
} else {
|
||||
mySQL = null;
|
||||
updateQuery = null;
|
||||
mySQLTable = null;
|
||||
maintenanceQuery = null;
|
||||
//serversQuery = null;
|
||||
serverTable = null;
|
||||
serverQuery = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -171,13 +177,27 @@ public final class SettingsBungee extends Settings {
|
||||
final long configValue = config.getInt("mysql.update-interval");
|
||||
millisecondsToCheck = configValue > 0 ? configValue * 1000 : -1;
|
||||
lastMySQLCheck = 0;
|
||||
}/* else {
|
||||
lastServerCheck = 0;
|
||||
maintenanceServers = loadMaintenanceServersFromSQL();
|
||||
} else {
|
||||
final List<String> list = spigotServers.getStringList("maintenance-on");
|
||||
maintenanceServers = list == null ? new HashSet<>() : new HashSet<>(list);
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
final List<String> list = spigotServers.getStringList("maintenance-on");
|
||||
maintenanceServers = list == null ? new HashSet<>() : new HashSet<>(list);
|
||||
private Set<String> loadMaintenanceServersFromSQL() {
|
||||
final Set<String> maintenanceServers = new HashSet<>();
|
||||
mySQL.executeQuery(serverQuery, rs -> {
|
||||
try {
|
||||
while (rs.next()) {
|
||||
maintenanceServers.add(rs.getString("server"));
|
||||
}
|
||||
} catch (final SQLException e) {
|
||||
plugin.getLogger().warning("An error occured while trying to get the list of single servers with maintenance!");
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
return maintenanceServers;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -238,47 +258,89 @@ public final class SettingsBungee extends Settings {
|
||||
@Override
|
||||
public boolean isMaintenance() {
|
||||
if (mySQL != null && (millisecondsToCheck == -1 || System.currentTimeMillis() - lastMySQLCheck > millisecondsToCheck)) {
|
||||
mySQL.executeQuery(maintenanceQuery, rs -> {
|
||||
try {
|
||||
if (rs.next()) {
|
||||
final boolean databaseValue = Boolean.parseBoolean(rs.getString("value"));
|
||||
if (databaseValue != maintenance)
|
||||
maintenancePlugin.serverActions(maintenance);
|
||||
|
||||
maintenance = databaseValue;
|
||||
}
|
||||
|
||||
} catch (final SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}, "maintenance");
|
||||
final boolean databaseValue = loadMaintenance();
|
||||
if (databaseValue != maintenance) {
|
||||
maintenancePlugin.serverActions(maintenance);
|
||||
maintenance = databaseValue;
|
||||
}
|
||||
if (millisecondsToCheck != -1)
|
||||
lastMySQLCheck = System.currentTimeMillis();
|
||||
}
|
||||
return maintenance;
|
||||
}
|
||||
|
||||
private boolean loadMaintenance() {
|
||||
final boolean[] databaseValue = {false};
|
||||
mySQL.executeQuery(maintenanceQuery, rs -> {
|
||||
try {
|
||||
if (rs.next()) {
|
||||
databaseValue[0] = Boolean.parseBoolean(rs.getString("value"));
|
||||
}
|
||||
} catch (final SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}, "maintenance");
|
||||
return databaseValue[0];
|
||||
}
|
||||
|
||||
public boolean isMaintenance(final ServerInfo server) {
|
||||
if (mySQL != null && (millisecondsToCheck == -1 || System.currentTimeMillis() - lastServerCheck > millisecondsToCheck)) {
|
||||
final Set<String> databaseValue = loadMaintenanceServersFromSQL();
|
||||
if (!databaseValue.equals(maintenanceServers)) {
|
||||
maintenancePlugin.serverActions(server, maintenance);
|
||||
maintenanceServers = databaseValue;
|
||||
}
|
||||
if (millisecondsToCheck != -1)
|
||||
lastServerCheck = System.currentTimeMillis();
|
||||
}
|
||||
return maintenanceServers.contains(server.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean reloadMaintenanceIcon() {
|
||||
return pingListener.loadIcon();
|
||||
}
|
||||
|
||||
public void setMaintenanceToSQL(final boolean maintenance) {
|
||||
plugin.getProxy().getScheduler().runAsync(plugin, () -> {
|
||||
void setMaintenanceToSQL(final boolean maintenance) {
|
||||
maintenancePlugin.async(() -> {
|
||||
final String s = String.valueOf(maintenance);
|
||||
mySQL.executeUpdate(updateQuery, "maintenance", s, s);
|
||||
mySQL.executeUpdate("INSERT INTO " + mySQLTable + " (setting, value) VALUES (?, ?) ON DUPLICATE KEY UPDATE value = ?", "maintenance", s, s);
|
||||
if (millisecondsToCheck != -1)
|
||||
lastMySQLCheck = System.currentTimeMillis();
|
||||
});
|
||||
this.maintenance = maintenance;
|
||||
}
|
||||
|
||||
public MySQL getMySQL() {
|
||||
MySQL getMySQL() {
|
||||
return mySQL;
|
||||
}
|
||||
|
||||
public Set<String> getMaintenanceServers() {
|
||||
return maintenanceServers;
|
||||
boolean addMaintenanceServer(final String server) {
|
||||
if (mySQL != null) {
|
||||
maintenanceServers = loadMaintenanceServersFromSQL();
|
||||
if (!maintenanceServers.add(server)) return false;
|
||||
maintenancePlugin.async(() -> mySQL.executeUpdate("INSERT INTO " + serverTable + " (server) VALUES (?)", server));
|
||||
if (millisecondsToCheck != -1)
|
||||
lastServerCheck = System.currentTimeMillis();
|
||||
} else {
|
||||
if (!maintenanceServers.add(server)) return false;
|
||||
saveServersToConfig();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
boolean removeMaintenanceServer(final String server) {
|
||||
if (mySQL != null) {
|
||||
maintenanceServers = loadMaintenanceServersFromSQL();
|
||||
if (!maintenanceServers.remove(server)) return false;
|
||||
maintenancePlugin.async(() -> mySQL.executeUpdate("DELETE FROM " + serverTable + " WHERE server = ?", server));
|
||||
if (millisecondsToCheck != -1)
|
||||
lastServerCheck = System.currentTimeMillis();
|
||||
} else {
|
||||
if (!maintenanceServers.remove(server)) return false;
|
||||
saveServersToConfig();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void saveServersToConfig() {
|
||||
@@ -286,6 +348,10 @@ public final class SettingsBungee extends Settings {
|
||||
saveSpigotServers();
|
||||
}
|
||||
|
||||
public Set<String> getMaintenanceServers() {
|
||||
return maintenanceServers;
|
||||
}
|
||||
|
||||
public String getFallbackServer() {
|
||||
return fallbackServer;
|
||||
}
|
||||
|
||||
+7
-11
@@ -70,7 +70,7 @@ public final class MaintenanceBungeeCommand extends MaintenanceCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handleToggleServerCommand(final SenderInfo sender, final String args[]) {
|
||||
protected void handleToggleServerCommand(final SenderInfo sender, final String[] args) {
|
||||
final ServerInfo server = plugin.getProxy().getServerInfo(args[1]);
|
||||
if (server == null) {
|
||||
sender.sendMessage(settings.getMessage("serverNotFound"));
|
||||
@@ -78,19 +78,15 @@ public final class MaintenanceBungeeCommand extends MaintenanceCommand {
|
||||
}
|
||||
|
||||
final boolean maintenance = args[0].equalsIgnoreCase("on");
|
||||
if (maintenance == settingsBungee.getMaintenanceServers().contains(server.getName())) {
|
||||
sender.sendMessage(settings.getMessage(maintenance ? "alreadyEnabled" : "alreadyDisabled"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!plugin.setMaintenanceToServer(server, maintenance))
|
||||
sender.sendMessage(settings.getMessage(maintenance ? "singleServerAlreadyEnabled" : "singleServerAlreadyDisabled"));
|
||||
else if (!plugin.getProxy().getPlayer(sender.getUuid()).getServer().getInfo().equals(server))
|
||||
sender.sendMessage(settings.getMessage(maintenance ? "singleMaintenanceActivated" : "singleMaintenanceDeactivated").replace("%SERVER%", server.getName()));
|
||||
if (plugin.setMaintenanceToServer(server, maintenance)) {
|
||||
if (!sender.isPlayer() || !plugin.getProxy().getPlayer(sender.getUuid()).getServer().getInfo().equals(server))
|
||||
sender.sendMessage(settings.getMessage(maintenance ? "singleMaintenanceActivated" : "singleMaintenanceDeactivated").replace("%SERVER%", server.getName()));
|
||||
} else
|
||||
sender.sendMessage(settings.getMessage(maintenance ? "singleServerAlreadyEnabled" : "singleServerAlreadyDisabled").replace("%SERVER%", server.getName()));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handleTimerServerCommands(final SenderInfo sender, final String args[]) {
|
||||
protected void handleTimerServerCommands(final SenderInfo sender, final String[] args) {
|
||||
if (args[0].equalsIgnoreCase("endtimer")) {
|
||||
if (checkPermission(sender, "servertimer")) return;
|
||||
if (checkTimerArgs(sender, args[2], "singleEndtimerUsage")) return;
|
||||
|
||||
+2
@@ -53,6 +53,8 @@ public final class ProxyPingListener implements Listener, IPingListener {
|
||||
favicon = Favicon.create(ImageIO.read(new File("maintenance-icon.png")));
|
||||
} catch (final IOException | IllegalArgumentException e) {
|
||||
plugin.getLogger().warning("§4Could not load 'maintenance-icon.png' - did you create one in your Bungee folder (not the plugins folder)?");
|
||||
if (settings.debugEnabled())
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
||||
+1
-1
@@ -23,7 +23,7 @@ public final class ServerConnectListener implements Listener {
|
||||
public void serverConnect(final ServerConnectEvent event) {
|
||||
final ProxiedPlayer p = event.getPlayer();
|
||||
final ServerInfo target = event.getTarget();
|
||||
if (!settings.getMaintenanceServers().contains(target.getName())) return;
|
||||
if (!plugin.isMaintenance(target))return;
|
||||
if (p.hasPermission("maintenance.bypass") || settings.getWhitelistedPlayers().containsKey(p.getUniqueId()))
|
||||
return;
|
||||
|
||||
|
||||
+46
-42
@@ -3,7 +3,6 @@ package eu.kennytv.maintenance.bungee.metrics;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import net.md_5.bungee.api.plugin.Plugin;
|
||||
import net.md_5.bungee.api.scheduler.TaskScheduler;
|
||||
import net.md_5.bungee.config.Configuration;
|
||||
import net.md_5.bungee.config.ConfigurationProvider;
|
||||
import net.md_5.bungee.config.YamlConfiguration;
|
||||
@@ -14,33 +13,23 @@ import java.lang.reflect.InvocationTargetException;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Path;
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.logging.Level;
|
||||
import java.util.zip.GZIPOutputStream;
|
||||
|
||||
public final class MetricsLite {
|
||||
|
||||
static {
|
||||
final String defaultPackage = new String(new byte[]{'o', 'r', 'g', '.', 'b', 's', 't', 'a', 't', 's'});
|
||||
final String examplePackage = new String(new byte[]{'y', 'o', 'u', 'r', '.', 'p', 'a', 'c', 'k', 'a', 'g', 'e'});
|
||||
if (MetricsLite.class.getPackage().getName().equals(defaultPackage) || MetricsLite.class.getPackage().getName().equals(examplePackage)) {
|
||||
throw new IllegalStateException("bStats Metrics class has not been relocated correctly!");
|
||||
}
|
||||
}
|
||||
|
||||
public static final int B_STATS_VERSION = 1;
|
||||
|
||||
private static final String URL = "https://bStats.org/submitData/bungeecord";
|
||||
|
||||
private final Plugin plugin;
|
||||
|
||||
private boolean enabled;
|
||||
|
||||
private String serverUUID;
|
||||
|
||||
private boolean logFailedRequests;
|
||||
|
||||
private static boolean logSentData;
|
||||
private static boolean logResponseStatusText;
|
||||
private static final List<Object> knownMetricsInstances = new ArrayList<>();
|
||||
|
||||
public MetricsLite(final Plugin plugin) {
|
||||
@@ -67,7 +56,7 @@ public final class MetricsLite {
|
||||
} else {
|
||||
try {
|
||||
usedMetricsClass.getMethod("linkMetrics", Object.class).invoke(null, this);
|
||||
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
|
||||
} catch (final NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
|
||||
if (logFailedRequests) {
|
||||
plugin.getLogger().log(Level.WARNING, "Failed to link to first metrics class " + usedMetricsClass.getName() + "!", e);
|
||||
}
|
||||
@@ -75,6 +64,10 @@ public final class MetricsLite {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
public static void linkMetrics(final Object metrics) {
|
||||
knownMetricsInstances.add(metrics);
|
||||
}
|
||||
@@ -95,14 +88,7 @@ public final class MetricsLite {
|
||||
}
|
||||
|
||||
private void startSubmitting() {
|
||||
final Timer timer = new Timer(true);
|
||||
timer.scheduleAtFixedRate(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
final TaskScheduler scheduler = plugin.getProxy().getScheduler();
|
||||
scheduler.schedule(plugin, () -> submitData(), 0L, TimeUnit.SECONDS);
|
||||
}
|
||||
}, 1000 * 60 * 2, 1000 * 60 * 30);
|
||||
plugin.getProxy().getScheduler().schedule(plugin, this::submitData, 2, 30, TimeUnit.MINUTES);
|
||||
}
|
||||
|
||||
private JsonObject getServerData() {
|
||||
@@ -146,21 +132,19 @@ public final class MetricsLite {
|
||||
if (plugin instanceof JsonObject) {
|
||||
pluginData.add((JsonObject) plugin);
|
||||
}
|
||||
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException ignored) {
|
||||
} catch (final NoSuchMethodException | IllegalAccessException | InvocationTargetException ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
data.add("plugins", pluginData);
|
||||
|
||||
new Thread(() -> {
|
||||
try {
|
||||
sendData(data);
|
||||
} catch (Exception e) {
|
||||
if (logFailedRequests) {
|
||||
plugin.getLogger().log(Level.WARNING, "Could not submit plugin stats!", e);
|
||||
}
|
||||
try {
|
||||
sendData(plugin, data);
|
||||
} catch (final Exception e) {
|
||||
if (logFailedRequests) {
|
||||
plugin.getLogger().log(Level.WARNING, "Could not submit plugin stats!", e);
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
}
|
||||
|
||||
private void loadConfig() throws IOException {
|
||||
@@ -174,8 +158,10 @@ public final class MetricsLite {
|
||||
"#This has nearly no effect on the server performance!",
|
||||
"#Check out https://bStats.org/ to learn more :)",
|
||||
"enabled: true",
|
||||
"serverUuid: \"" + UUID.randomUUID() + "\"",
|
||||
"logFailedRequests: false");
|
||||
"serverUuid: \"" + UUID.randomUUID().toString() + "\"",
|
||||
"logFailedRequests: false",
|
||||
"logSentData: false",
|
||||
"logResponseStatusText: false");
|
||||
}
|
||||
|
||||
final Configuration configuration = ConfigurationProvider.getProvider(YamlConfiguration.class).load(configFile);
|
||||
@@ -183,6 +169,8 @@ public final class MetricsLite {
|
||||
enabled = configuration.getBoolean("enabled", true);
|
||||
serverUUID = configuration.getString("serverUuid");
|
||||
logFailedRequests = configuration.getBoolean("logFailedRequests", false);
|
||||
logSentData = configuration.getBoolean("logSentData", false);
|
||||
logResponseStatusText = configuration.getBoolean("logResponseStatusText", false);
|
||||
}
|
||||
|
||||
private Class<?> getFirstBStatsClass() {
|
||||
@@ -213,8 +201,8 @@ public final class MetricsLite {
|
||||
return null;
|
||||
}
|
||||
try (
|
||||
FileReader fileReader = new FileReader(file);
|
||||
BufferedReader bufferedReader = new BufferedReader(fileReader);
|
||||
final FileReader fileReader = new FileReader(file);
|
||||
final BufferedReader bufferedReader = new BufferedReader(fileReader);
|
||||
) {
|
||||
return bufferedReader.readLine();
|
||||
}
|
||||
@@ -225,8 +213,8 @@ public final class MetricsLite {
|
||||
file.createNewFile();
|
||||
}
|
||||
try (
|
||||
FileWriter fileWriter = new FileWriter(file);
|
||||
BufferedWriter bufferedWriter = new BufferedWriter(fileWriter)
|
||||
final FileWriter fileWriter = new FileWriter(file);
|
||||
final BufferedWriter bufferedWriter = new BufferedWriter(fileWriter)
|
||||
) {
|
||||
for (final String line : lines) {
|
||||
bufferedWriter.write(line);
|
||||
@@ -235,10 +223,13 @@ public final class MetricsLite {
|
||||
}
|
||||
}
|
||||
|
||||
private static void sendData(final JsonObject data) throws Exception {
|
||||
private static void sendData(final Plugin plugin, final JsonObject data) throws Exception {
|
||||
if (data == null) {
|
||||
throw new IllegalArgumentException("Data cannot be null");
|
||||
}
|
||||
if (logSentData) {
|
||||
plugin.getLogger().info("Sending data to bStats: " + data.toString());
|
||||
}
|
||||
|
||||
final HttpsURLConnection connection = (HttpsURLConnection) new URL(URL).openConnection();
|
||||
|
||||
@@ -258,7 +249,20 @@ public final class MetricsLite {
|
||||
outputStream.flush();
|
||||
outputStream.close();
|
||||
|
||||
connection.getInputStream().close();
|
||||
if (logResponseStatusText) {
|
||||
final InputStream inputStream = connection.getInputStream();
|
||||
final BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
|
||||
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
String line;
|
||||
while ((line = bufferedReader.readLine()) != null) {
|
||||
builder.append(line);
|
||||
}
|
||||
bufferedReader.close();
|
||||
plugin.getLogger().info("Sent data to bStats and received response: " + builder.toString());
|
||||
} else {
|
||||
connection.getInputStream().close();
|
||||
}
|
||||
}
|
||||
|
||||
private static byte[] compress(final String str) throws IOException {
|
||||
|
||||
+5
@@ -34,6 +34,11 @@ public final class ProxiedSenderInfo implements SenderInfo {
|
||||
sender.sendMessage(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPlayer() {
|
||||
return sender instanceof ProxiedPlayer;
|
||||
}
|
||||
|
||||
public void sendMessage(final TextComponent textComponent) {
|
||||
sender.sendMessage(textComponent);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
# MaintenanceBungee Plugin by KennyTV
|
||||
# Configs are cool, which means after the first plugin save, all comments will vanish
|
||||
# To still know what each field is for, check https://gist.github.com/KennyTV/a73f2aed1e278d4c927f9f6a3ef9fde2#file-bungee-config-yml
|
||||
|
||||
# Enables maintenance-mode.
|
||||
enable-maintenance-mode: false
|
||||
@@ -34,7 +36,7 @@ send-join-notification: false
|
||||
custom-maintenance-icon: false
|
||||
|
||||
# Changes the language of command feedback/messages.
|
||||
# Currently available are: en (English), de (German)
|
||||
# Currently available are: en (English), de (German), fr (French), pt (Portuguese)
|
||||
language: en
|
||||
|
||||
# Only enable MySQL if you really know what you are doing.
|
||||
@@ -45,8 +47,6 @@ mysql:
|
||||
database: database
|
||||
username: username
|
||||
password: password
|
||||
# A new table with this name will be created on first startup when 'use-mysql' is set to true.
|
||||
table: maintenance_settings
|
||||
# Requests to the database will only be made at least x seconds after the last request,
|
||||
# so there won't be a request on every single ping on a server with many players.
|
||||
# Set this to 0 to make a database request on every single ping.
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<artifactId>maintenance-base</artifactId>
|
||||
<groupId>eu.kennytv</groupId>
|
||||
<version>2.5.1</version>
|
||||
<version>2.5.2</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>maintenance-core</artifactId>
|
||||
|
||||
@@ -11,6 +11,7 @@ import java.net.HttpURLConnection;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public abstract class MaintenanceModePlugin implements IMaintenance {
|
||||
protected final Version version;
|
||||
@@ -155,4 +156,6 @@ public abstract class MaintenanceModePlugin implements IMaintenance {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public abstract Logger getLogger();
|
||||
}
|
||||
@@ -18,6 +18,7 @@ public abstract class Settings implements ISettings {
|
||||
private boolean customPlayerCountMessage;
|
||||
private boolean customMaintenanceIcon;
|
||||
private boolean joinNotifications;
|
||||
private boolean debug;
|
||||
|
||||
protected Settings(final MaintenanceModePlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
@@ -36,10 +37,25 @@ public abstract class Settings implements ISettings {
|
||||
playerCountHoverMessage = getColoredString(getConfigString("playercounthovermessage"));
|
||||
kickMessage = getColoredString(getConfigString("kickmessage"));
|
||||
languageName = getConfigString("language").toLowerCase();
|
||||
if (customMaintenanceIcon)
|
||||
debug = getConfigBoolean("debug");
|
||||
if (customMaintenanceIcon) {
|
||||
reloadMaintenanceIcon();
|
||||
}
|
||||
|
||||
loadExtraSettings();
|
||||
if (debug) {
|
||||
plugin.getLogger().info("enable-maintenance-mode:" + maintenance);
|
||||
plugin.getLogger().info("whitelistedPlayers:" + whitelistedPlayers);
|
||||
plugin.getLogger().info("timer-broadcast-for-seconds:" + broadcastIntervalls);
|
||||
plugin.getLogger().info("pingmessages:" + pingMessages);
|
||||
plugin.getLogger().info("playercountmessage:" + playerCountMessage);
|
||||
plugin.getLogger().info("playercounthovermessage:" + playerCountHoverMessage);
|
||||
plugin.getLogger().info("kickmessage:" + kickMessage);
|
||||
plugin.getLogger().info("language:" + languageName);
|
||||
plugin.getLogger().info("enable-playercountmessage:" + customPlayerCountMessage);
|
||||
plugin.getLogger().info("custom-maintenance-icon:" + customMaintenanceIcon);
|
||||
plugin.getLogger().info("send-join-notification:" + joinNotifications);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateConfig() {
|
||||
@@ -71,7 +87,6 @@ public abstract class Settings implements ISettings {
|
||||
|
||||
if (updateExtraConfig() || fileChanged) {
|
||||
saveConfig();
|
||||
reloadConfigs();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -193,4 +208,9 @@ public abstract class Settings implements ISettings {
|
||||
saveWhitelistedPlayers();
|
||||
return contains;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean debugEnabled() {
|
||||
return debug;
|
||||
}
|
||||
}
|
||||
+4
-6
@@ -167,7 +167,6 @@ public abstract class MaintenanceCommand {
|
||||
settings.getPingMessages().remove(index - 1);
|
||||
settings.setToConfig("pingmessages", settings.getPingMessages());
|
||||
settings.saveConfig();
|
||||
settings.reloadConfigs();
|
||||
sender.sendMessage(settings.getMessage("removedMotd").replace("%INDEX%", args[1]));
|
||||
} else
|
||||
sendUsage(sender);
|
||||
@@ -214,7 +213,6 @@ public abstract class MaintenanceCommand {
|
||||
settings.getPingMessages().set(index - 1, newMessage);
|
||||
settings.setToConfig("pingmessages", settings.getPingMessages());
|
||||
settings.saveConfig();
|
||||
settings.reloadConfigs();
|
||||
sender.sendMessage(settings.getMessage("setMotd").replace("%LINE%", args[2]).replace("%INDEX%", args[1])
|
||||
.replace("%MOTD%", "§f" + settings.getColoredString(message)));
|
||||
} else
|
||||
@@ -230,12 +228,12 @@ public abstract class MaintenanceCommand {
|
||||
protected void sendUsage(final SenderInfo sender, final int page) {
|
||||
final List<String> commands = new ArrayList<>();
|
||||
commandInfos.stream().filter(cmd -> cmd.hasPermission(sender)).forEach(cmd -> {
|
||||
for (String message : cmd.getMessages()) {
|
||||
for (final String message : cmd.getMessages()) {
|
||||
commands.add(message);
|
||||
}
|
||||
});
|
||||
if ((page - 1) * COMMANDS_PER_PAGE > commands.size()) {
|
||||
sender.sendMessage(plugin.getPrefix() + "§cThere is no page with that number!");
|
||||
sender.sendMessage(settings.getMessage("helpPageNotFound"));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -309,9 +307,9 @@ public abstract class MaintenanceCommand {
|
||||
protected void showMaintenanceStatus(SenderInfo sender) {
|
||||
}
|
||||
|
||||
protected void handleToggleServerCommand(SenderInfo sender, String args[]) {
|
||||
protected void handleToggleServerCommand(SenderInfo sender, String[] args) {
|
||||
}
|
||||
|
||||
protected void handleTimerServerCommands(SenderInfo sender, String args[]) {
|
||||
protected void handleTimerServerCommands(SenderInfo sender, String[] args) {
|
||||
}
|
||||
}
|
||||
@@ -11,4 +11,6 @@ public interface SenderInfo {
|
||||
boolean hasPermission(String permission);
|
||||
|
||||
void sendMessage(String message);
|
||||
|
||||
boolean isPlayer();
|
||||
}
|
||||
@@ -7,6 +7,7 @@ maintenanceDeactivated: "&8[&eMaintenance&8] &6Der Wartungsmodus ist nun deaktiv
|
||||
alreadyEnabled: "&8[&eMaintenance&8] &cDer Wartungsmodus ist bereits aktiviert!"
|
||||
alreadyDisabled: "&8[&eMaintenance&8] &cDer Wartungsmodus ist bereits deaktiviert!"
|
||||
helpUsage: "&8[&eMaintenance&8] &c/maintenance help <Seite>"
|
||||
helpPageNotFound: "&8[&eMaintenance&8] &cEs gibt keine Seite mit dieser Nummer!"
|
||||
endtimerBroadcast: "&8[&eMaintenance&8] &7Der Wartungsmodus wird deaktiviert in: &6%TIME%&7."
|
||||
endtimerStarted: "&8[&eMaintenance&8] &aGestarteter Timer: &7Der Wartungsmodus wird deaktiviert in: &6%TIME%&7."
|
||||
endtimerUsage: "&8[&eMaintenance&8] &c/maintenance endtimer <Minuten>"
|
||||
@@ -23,10 +24,9 @@ reload: "&8[&eMaintenance&8] &aConfig, WhitelistedPlayers, Language Datei und Ma
|
||||
removedMotd: "&8[&eMaintenance&8] &aDie %INDEX%. Maintenance MOTD wurde entfernt."
|
||||
removeMotdError: "&8[&eMaintenance&8] &cDu hast nur eine Maintenance MOTD, daher kannst du auch keine entfernen!"
|
||||
removeMotdUsage: "&8[&eMaintenance&8] &c/maintenance removemotd <Index>"
|
||||
serverNotFound: "&8[&eMaintenance&8] &cEs wurde kein Server mit diesem Namen gefunden!"
|
||||
setMotd: "&8[&eMaintenance&8] &aDie %LINE%. Zeile der %INDEX%. Maintenance MOTD wurde geändert zu: %MOTD%"
|
||||
setMotdUsage: "&8[&eMaintenance&8] &c/maintenance setmotd <Index> <1/2> <Text>"
|
||||
setMotdIndexError: "&8[&eMaintenance&8] §cMomentan gibt es %MOTDS% MOTDs, du musst also eine Zahl zwischen 1 and %NEWAMOUNT% wählen."
|
||||
setMotdIndexError: "&8[&eMaintenance&8] &cMomentan gibt es %MOTDS% MOTDs, du musst also eine Zahl zwischen 1 and %NEWAMOUNT% wählen."
|
||||
setMotdLineError: "&8[&eMaintenance&8] &cDas zweite Argument muss die Zeilennummer sein (1 oder 2)!"
|
||||
updateDownloading: "&8[&eMaintenance&8] &c&lUpdate wird heruntergeladen..."
|
||||
updateFailed: "&8[&eMaintenance&8] &4&lUpdate fehlgeschlagen!"
|
||||
@@ -50,6 +50,7 @@ hour: "Stunde"
|
||||
hours: "Stunden"
|
||||
|
||||
# Nachrichten für den Bungee Teil des Plugins, einfach ignorieren, falls das Plugin auf Spigot verwendet wird
|
||||
serverNotFound: "&8[&eMaintenance&8] &cEs wurde kein Server mit diesem Namen gefunden!"
|
||||
singleEndtimerBroadcast: "&8[&eMaintenance&8] &7Der Wartungsmodus auf Server %SERVER% wird deaktiviert in: &6%TIME%&7."
|
||||
singleEndtimerUsage: "&8[&eMaintenance&8] &c/maintenance endtimer <Server> <Minuten>"
|
||||
singleStarttimerBroadcast: "&8[&eMaintenance&8] &7Der Wartungsmodus auf Server %SERVER% wird aktiviert in: &6%TIME%&7."
|
||||
|
||||
@@ -7,6 +7,7 @@ maintenanceDeactivated: "&8[&eMaintenance&8] &6Maintenance mode is now deactivat
|
||||
alreadyEnabled: "&8[&eMaintenance&8] &cMaintenance is already enabled!"
|
||||
alreadyDisabled: "&8[&eMaintenance&8] &cMaintenance is already disabled!"
|
||||
helpUsage: "&8[&eMaintenance&8] &c/maintenance help <page>"
|
||||
helpPageNotFound: "&8[&eMaintenance&8] &cThere is no page with that number!"
|
||||
endtimerBroadcast: "&8[&eMaintenance&8] &7Maintenance mode will be disabled in &6%TIME%&7."
|
||||
endtimerStarted: "&8[&eMaintenance&8] &aStarted timer: &7Maintenance mode will be deactivated in &6%TIME%&7."
|
||||
endtimerUsage: "&8[&eMaintenance&8] &c/maintenance endtimer <minutes>"
|
||||
@@ -23,10 +24,9 @@ reload: "&8[&eMaintenance&8] &aReloaded config, whitelistedplayers, language fil
|
||||
removedMotd: "&8[&eMaintenance&8] &aRemoved motd number %INDEX%."
|
||||
removeMotdError: "&8[&eMaintenance&8] &cYou only have one motd, so you can't remove any!"
|
||||
removeMotdUsage: "&8[&eMaintenance&8] &c/maintenance removemotd <index>"
|
||||
serverNotFound: "&8[&eMaintenance&8] &cNo server with this name is registered on the proxy!"
|
||||
setMotd: "&8[&eMaintenance&8] &aSet line %LINE% of the %INDEX%. maintenance motd to %MOTD%"
|
||||
setMotdUsage: "&8[&eMaintenance&8] &c/maintenance setmotd <index> <1/2> <message>"
|
||||
setMotdIndexError: "&8[&eMaintenance&8] §cYou currently have %MOTDS% motds, so you have to pick a number between 1 and %NEWAMOUNT%."
|
||||
setMotdIndexError: "&8[&eMaintenance&8] &cYou currently have %MOTDS% motds, so you have to pick a number between 1 and %NEWAMOUNT%."
|
||||
setMotdLineError: "&8[&eMaintenance&8] &cThe second argument has to be the line number (1 or 2)!"
|
||||
updateDownloading: "&8[&eMaintenance&8] &c&lDownloading update..."
|
||||
updateFailed: "&8[&eMaintenance&8] &4&lUpdate failed!"
|
||||
@@ -50,6 +50,7 @@ hour: "hour"
|
||||
hours: "hours"
|
||||
|
||||
# Some messages for the Bungee part, just ignore them if you use the plugin on Spigot
|
||||
serverNotFound: "&8[&eMaintenance&8] &cNo server with this name is registered on the proxy!"
|
||||
singleEndtimerBroadcast: "&8[&eMaintenance&8] &7Maintenance mode on server %SERVER% will be disabled in &6%TIME%&7."
|
||||
singleEndtimerUsage: "&8[&eMaintenance&8] &c/maintenance endtimer <server> <minutes>"
|
||||
singleStarttimerBroadcast: "&8[&eMaintenance&8] &7Maintenance mode on server %SERVER% will be enabled in &6%TIME%&7."
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
# Maintenance Plugin par KennyTV
|
||||
# Ne supprime pas des mots entre les '%' si tu ne sait pas pourqoi exactement
|
||||
|
||||
noPermission: "&cVous n'avez pas la permission d'exécuter cette commande."
|
||||
maintenanceActivated: "&8[&eMaintenance&8] &6Le mode maintenance est maintenant activé."
|
||||
maintenanceDeactivated: "&8[&eMaintenance&8] &6Le mode maintenance est maintenant désactivé."
|
||||
alreadyEnabled: "&8[&eMaintenance&8] &cLa maintenance est déjà activée!"
|
||||
alreadyDisabled: "&8[&eMaintenance&8] &cLa maintenance est déjà désactivée!"
|
||||
helpUsage: "&8[&eMaintenance&8] &c/maintenance help <page>"
|
||||
helpPageNotFound: "&8[&eMaintenance&8] &cIl n'y a pas cette page!"
|
||||
endtimerBroadcast: "&8[&eMaintenance&8] &7Le mode maintenance sera désactivé dans &6%TIME%&7."
|
||||
endtimerStarted: "&8[&eMaintenance&8] &aminuterie: &7Le mode maintenance sera désactivé dans &6%TIME%&7."
|
||||
endtimerUsage: "&8[&eMaintenance&8] &c/maintenance endtimer <minutes>"
|
||||
starttimerBroadcast: "&8[&eMaintenance&8] &7MLe mode de maintenance sera activé dans &6%TIME%&7."
|
||||
starttimerStarted: "&8[&eMaintenance&8] &aminuterie: &7Le mode maintenance sera activé dans &6%TIME%&7."
|
||||
starttimerUsage: "&8[&eMaintenance&8] &c/maintenance starttimer <minutes>"
|
||||
timerAlreadyRunning: "&8[&eMaintenance&8] &cIl y a déjà un horaire prévu!"
|
||||
timerNotRunning: "&8[&eMaintenance&8] &cIl n'y a actuellement aucune maintenance prévue."
|
||||
timerCancelled: "&8[&eMaintenance&8] &cLa minuterie actuelle a été désactivée."
|
||||
timerTooLong: "&8[&eMaintenance&8] &cLe nombre doit être inférieur à 40320 (28 jours)!"
|
||||
joinNotification: "&8[&eMaintenance&8] &e%PLAYER% &ca essayé de rejoindre le serveur."
|
||||
motdList: "&8[&eMaintenance&8] &7Liste de vos motd pour la maintenance:"
|
||||
reload: "&8[&eMaintenance&8] &afichier config, liste blanche (whitelist) joueurs, fichier de langue et l'icône de maintenance, recharger."
|
||||
removedMotd: "&8[&eMaintenance&8] &aNuméro de motd supprimé %INDEX%."
|
||||
removeMotdError: "&8[&eMaintenance&8] &cVous n’avez qu’un motd, vous ne pouvez donc en supprimer!"
|
||||
removeMotdUsage: "&8[&eMaintenance&8] &c/maintenance removemotd <index>"
|
||||
setMotd: "&8[&eMaintenance&8] &aLigne fixe %LINE% du %INDEX%. maintenance motd à %MOTD%"
|
||||
setMotdUsage: "&8[&eMaintenance&8] &c/maintenance setmotd <index> <1/2> <message>"
|
||||
setMotdIndexError: "&8[&eMaintenance&8] &cVous avez actuellement %MOTDS% vous devez donc choisir un nombre compris entre 1 et %NEWAMOUNT%."
|
||||
setMotdLineError: "&8[&eMaintenance&8] &cLe deuxième argument doit être le numéro de ligne (1 ou 2)!"
|
||||
updateDownloading: "&8[&eMaintenance&8] &c&lTéléchargement de la mise à jour..."
|
||||
updateFailed: "&8[&eMaintenance&8] &4&lLa mise à jour a échoué!"
|
||||
updateFinished: "&8[&eMaintenance&8] &a&lLa mise à jour a été réussie! Pour éviter les problèmes liés aux tâches et terminer la mise à jour, vous devez redémarrer le serveur!"
|
||||
whitelistedPlayers: "&8[&eMaintenance&8] &6Liste blanche des joueurs pour la maintenance:"
|
||||
whitelistedPlayersFormat: "&8- &e%NAME% &8(&7%UUID%&8)"
|
||||
whitelistAdded: "&8[&eMaintenance&8] &aAdded &b%PLAYER% &aà la liste blanche de maintenance!"
|
||||
whitelistAlreadyAdded: "&8[&eMaintenance&8] &b%PLAYER% &cest déjà dans la liste blanche de maintenance!"
|
||||
whitelistRemoved: "&8[&eMaintenance&8] &aEnlevé &b%PLAYER% &ade la liste blanche de maintenance!"
|
||||
whitelistNotFound: "&8[&eMaintenance&8] &cCe joueur n'est pas dans la liste blanche de la maintenance!"
|
||||
whitelistEmtpy: "&8[&eMaintenance&8] &cLa liste blanche de maintenance est vide! Utilisation '/maintenance add <joueur>' ajouter quelqu'un!"
|
||||
whitelistEmptyDefault: "&8[&eMaintenance&8] &cUtilisation '/maintenance add <joueur>' ajouter quelqu'un. Alternativement, vous pouvez ajouter le uuid d'un joueur à la WhitelistedPlayers.yml comme on le voit dans l'exemple du fichier!"
|
||||
playerNotFound: "&8[&eMaintenance&8] &cAucun joueur avec ce nom n'a joué sur ce serveur auparavant."
|
||||
playerNotOnline: "&8[&eMaintenance&8] &cIl n'y a pas de joueur en ligne avec ce nom."
|
||||
|
||||
second: "second"
|
||||
seconds: "seconds"
|
||||
minute: "minute"
|
||||
minutes: "minutes"
|
||||
hour: "heur"
|
||||
hours: "heurs"
|
||||
|
||||
# Quelques messages pour la partie Bungee, ignorez-les si vous utilisez le plugin sur Spigot
|
||||
serverNotFound: "&8[&eMaintenance&8] &cAucun serveur avec ce nom n'est enregistré sur le proxy!"
|
||||
singleEndtimerBroadcast: "&8[&eMaintenance&8] &7maintenance sur serveur %SERVER% sera désactivé dans &6%TIME%&7."
|
||||
singleEndtimerUsage: "&8[&eMaintenance&8] &c/maintenance endtimer <serveur> <minutes>"
|
||||
singleStarttimerBroadcast: "&8[&eMaintenance&8] &7Maintenance sur le serveur %SERVER% sera activé dans &6%TIME%&7."
|
||||
singleStarttimerUsage: "&8[&eMaintenance&8] &c/maintenance starttimer <serveur> <minutes>"
|
||||
singleMaintenanceKick: "&8[&eMaintenance&8] &cLe serveur %SERVER% est actuellement en maintenance! Réessayez plus tard!"
|
||||
singleMaintenanceKickComplete: "&cLe serveur %SERVER% est en maintenance!%NEWLINE%&cVous pouvez essayer un autre serveur!"
|
||||
singleMaintenanceActivated: "&8[&eMaintenance&8] &6La maintenance est maintenant activé sur le serveur &e%SERVER%&6."
|
||||
singleMaintenanceDeactivated: "&8[&eMaintenance&8] &6La maintenance est maintenant désactivé sur le serveur &e%SERVER%&6."
|
||||
singleServerAlreadyEnabled: "&8[&eMaintenance&8] &cLa maintenance est déjà activée sur le serveur &e%SERVER%&c!"
|
||||
singleServerAlreadyDisabled: "&8[&eMaintenance&8] &cLa maintenance est déjà désactivée sur le serveur &e%SERVER%&c!"
|
||||
singleServerMaintenanceList: "&8[&eMaintenance&8] &7Serveurs proxy avec maintenance activée:"
|
||||
singleServerMaintenanceListEmpty: "&8[&eMaintenance&8] &7Il n'y a pas de serveurs proxy en maintenance."
|
||||
@@ -0,0 +1,65 @@
|
||||
# Maintenance Plugin by KennyTV
|
||||
# Nao removas o '%' se nao souberes exatamente o que estas a fazer
|
||||
|
||||
noPermission: "&cNao tens permissao para executar este comando."
|
||||
maintenanceActivated: "&8[&cManutencao&8] &6Manutencao esta agora ativada!"
|
||||
maintenanceDeactivated: "&8[&cManutencao&8] &6Manutencao esta agora desativada!"
|
||||
alreadyEnabled: "&8[&cManutencao&8] &cManutencao ja esta ativada!"
|
||||
alreadyDisabled: "&8[&cManutencao&8] &cManutencao ja esta desativada!"
|
||||
helpUsage: "&8[&cManutencao&8] &c/maintenance help <pagina>"
|
||||
helpPageNotFound: "&8[&eManutencao&8] &cNao existe nenhuma pagina com esse numero!"
|
||||
endtimerBroadcast: "&8[&cManutencao&8] &7Manutencao vai ser desativada em &6%TIME%&7"
|
||||
endtimerStarted: "&8[&cManutencao&8] &aTemporizador: &7Manutencao vai ser desativada em &6%TIME%&7"
|
||||
endtimerUsage: "&8&8[&cManutencao&8] &c/maintenance endtimer <minutos>"
|
||||
starttimerBroadcast: "&8[&cManutencao&8] &7Manutencao vai ser ativada em &6%TIME%&7"
|
||||
starttimerStarted: "&8[&cManutencao&8] &7Manutencao vai ser ativada em &6%TIME%&7"
|
||||
starttimerUsage: "&8[&cManutencao&8] &c/maintenance starttimer <minutos>"
|
||||
timerAlreadyRunning: "&8[&cManutencao&8] &cO Timer ja esta a decorrer!"
|
||||
timerNotRunning: "&8[&cManutencao&8] &cO Timer nao esta a decorrer!"
|
||||
timerCancelled: "&8[&cManutencao&8] &cO Timer foi cancelado!"
|
||||
timerTooLong: "&8[&cManutencao&8] &cO numero tem de ser menor que 40320 (28 dias)!"
|
||||
joinNotification: "&8[&cManutencao&8] &e%PLAYER% &ctentou entrar no servidor."
|
||||
motdList: "&8[&cManutencao&8] &7Lista de motds de manutencao:"
|
||||
reload: "&8[&cManutencao&8] &aReloaded config, whitelistedplayers, linguagem e icon de manutencao."
|
||||
removedMotd: "&8[&cManutencao&8] &aRemovida motd numero %INDEX%."
|
||||
removeMotdError: "&8[&cManutencao&8] &cSo tens uma motd, entao nao podes remover esta!"
|
||||
removeMotdUsage: "&8[&cManutencao&8] &c/maintenance removemotd <index>"
|
||||
setMotd: setMotd: "&8[&eManutencao&8] &aLinha %LINE% do %INDEX%. Motd de manutencao %MOTD%"
|
||||
setMotdUsage: "&8[&cManutencao&8] &c/maintenance setmotd <index> <1/2> <message>"
|
||||
setMotdIndexError: "&8[&cManutencao&8] §cTens atualmente %MOTDS% motds, entao escolhe um numero entre 1 e %NEWAMOUNT%."
|
||||
setMotdLineError: "&8[&cManutencao&8] &cO segundo argumento tem de ser na linha (1 ou 2)!"
|
||||
updateDownloading: "&8[&cManutencao&8] &c&lDownloading update..."
|
||||
updateFailed: "&8[&cManutencao&8] &4&lUpdate falhado!"
|
||||
updateFinished: "&8[&cManutencao&8] &a&lO update foi feito com sucesso! Reinicia o servidor paa evitar erros e acabar a atualizacao"
|
||||
whitelistedPlayers: "&8[&cManutencao&8] &6Whitelisted players para a manutencao:"
|
||||
whitelistedPlayersFormat: "&8- &e%NAME% &8(&7%UUID%&8)"
|
||||
whitelistAdded: "&8[&cManutencao&8] &aAdicionado &b%PLAYER% &ana whitelist!"
|
||||
whitelistAlreadyAdded: "&8[&cManutencao&8] &b%PLAYER% &cja esta na whitelist!"
|
||||
whitelistRemoved: "&8[&cManutencao&8] &b%PLAYER% &aremovido da whitelist!"
|
||||
whitelistNotFound: "&8[&cManutencao&8] &cEste jogador nao esta na whitelist!"
|
||||
whitelistEmtpy: "&8[&cManutencao&8] &cA whitelist esta vazia! Usa '/maintenance add <player>' para adicionar alguem!"
|
||||
whitelistEmptyDefault: "&8[&cManutencao&8] &cUsa '/maintenance add <player>' para adicionar alguem. Ou entao adicona o uuid do jogador no ficheiro WhitelistedPlayers.yml"
|
||||
playerNotFound: "&8[&cManutencao&8] &cNinguem com esse nome se registou no servidor."
|
||||
playerNotOnline: "&8[&cManutencao&8] &cNao esta ninguem online com esse nome"
|
||||
|
||||
second: "segundo"
|
||||
seconds: "segundos"
|
||||
minute: "minuto"
|
||||
minutes: "minutos"
|
||||
hour: "hora"
|
||||
hours: "horas"
|
||||
|
||||
# Algumas mensagens para o Bungee, ignora-as se estas a usar Spigot
|
||||
serverNotFound: "&8[&cManutencao&8] &cServidor nao encontrado!"
|
||||
singleEndtimerBroadcast: "&8[&cManutencao&8] &7Manutencao no %SERVER% vai ser desativada em &6%TIME%&7."
|
||||
singleEndtimerUsage: "&8[&cManutencao&8] &c/maintenance endtimer <servidor> <minutos>"
|
||||
singleStarttimerBroadcast: "&8[&cManutencao&8] &7Manutencao no %SERVER% vai ser ativada em &6%TIME%&7."
|
||||
singleStarttimerUsage: "&8[&cManutencao&8] &c/maintenance starttimer <servidor> <minutos>"
|
||||
singleMaintenanceKick: "&8[&cManutencao&8] &cO %SERVER% esta em manutencao! Tente mais tarde!"
|
||||
singleMaintenanceKickComplete: "&cO %SERVER% esta em manutencao!%NEWLINE%&cTente mais tarde!"
|
||||
singleMaintenanceActivated: "&8[&cManutencao&8] &6Manutencao esta agora ativada no &e%SERVER%&6."
|
||||
singleMaintenanceDeactivated: "&8[&cManutencao&8] &6Manutencao esta agora desativada no &e%SERVER%&6."
|
||||
singleServerAlreadyEnabled: "&8[&cManutencao&8] &cManutencao ja esta ativada no &e%SERVER%&c!"
|
||||
singleServerAlreadyDisabled: "&8[&cManutencao&8] &cManutencao ja esta desativada no &e%SERVER%&c!"
|
||||
singleServerMaintenanceList: "&8[&cManutencao&8] &7Servidores com manutencao ativa:"
|
||||
singleServerMaintenanceListEmpty: "&8[&cManutencao&8] &7Nao existem servidores com a manutencao ativa."
|
||||
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<artifactId>maintenance-base</artifactId>
|
||||
<groupId>eu.kennytv</groupId>
|
||||
<version>2.5.1</version>
|
||||
<version>2.5.2</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>maintenance-parent</artifactId>
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<artifactId>maintenance-base</artifactId>
|
||||
<groupId>eu.kennytv</groupId>
|
||||
<version>2.5.1</version>
|
||||
<version>2.5.2</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>maintenance-spigot</artifactId>
|
||||
@@ -33,7 +33,7 @@
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<version>1.13.1-R0.1-SNAPSHOT</version>
|
||||
<version>1.13.2-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
||||
+6
-1
@@ -15,6 +15,7 @@ import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* @author KennyTV
|
||||
@@ -53,7 +54,6 @@ public final class MaintenanceSpigotPlugin extends MaintenanceModePlugin {
|
||||
settings.setMaintenance(maintenance);
|
||||
settings.setToConfig("enable-maintenance-mode", maintenance);
|
||||
settings.saveConfig();
|
||||
settings.reloadConfigs();
|
||||
|
||||
if (isTaskRunning())
|
||||
cancelTask();
|
||||
@@ -110,4 +110,9 @@ public final class MaintenanceSpigotPlugin extends MaintenanceModePlugin {
|
||||
public Server getServer() {
|
||||
return plugin.getServer();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Logger getLogger() {
|
||||
return plugin.getLogger();
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,7 @@ package eu.kennytv.maintenance.spigot;
|
||||
|
||||
import eu.kennytv.maintenance.core.Settings;
|
||||
import eu.kennytv.maintenance.core.listener.IPingListener;
|
||||
import eu.kennytv.maintenance.spigot.listener.PacketListener;
|
||||
import eu.kennytv.maintenance.spigot.listener.ServerInfoPacketListener;
|
||||
import eu.kennytv.maintenance.spigot.listener.ServerListPingListener;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
@@ -28,7 +28,9 @@ public final class SettingsSpigot extends Settings {
|
||||
|
||||
final PluginManager pm = plugin.getServer().getPluginManager();
|
||||
if (pm.getPlugin("ProtocolLib") != null) {
|
||||
pingListener = new PacketListener(plugin, this);
|
||||
final ServerInfoPacketListener serverInfoListener = new ServerInfoPacketListener(plugin, this);
|
||||
pm.registerEvents(serverInfoListener, plugin);
|
||||
pingListener = serverInfoListener;
|
||||
} else {
|
||||
final ServerListPingListener listener = new ServerListPingListener(plugin, this);
|
||||
pm.registerEvents(listener, plugin);
|
||||
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
package eu.kennytv.maintenance.spigot.listener;
|
||||
|
||||
import eu.kennytv.maintenance.core.listener.IPingListener;
|
||||
import eu.kennytv.maintenance.spigot.MaintenanceSpigotBase;
|
||||
import eu.kennytv.maintenance.spigot.SettingsSpigot;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.util.CachedServerIcon;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.io.File;
|
||||
|
||||
public abstract class PingListenerBase implements IPingListener, Listener {
|
||||
protected final MaintenanceSpigotBase plugin;
|
||||
protected final SettingsSpigot settings;
|
||||
protected CachedServerIcon serverIcon;
|
||||
|
||||
protected PingListenerBase(final MaintenanceSpigotBase plugin, final SettingsSpigot settings) {
|
||||
this.plugin = plugin;
|
||||
this.settings = settings;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean loadIcon() {
|
||||
try {
|
||||
serverIcon = plugin.getServer().loadServerIcon(ImageIO.read(new File("maintenance-icon.png")));
|
||||
} catch (final Exception e) {
|
||||
plugin.getLogger().warning("Could not load 'maintenance-icon.png' - did you create one in your Spigot folder (not the plugins folder)?");
|
||||
if (settings.debugEnabled())
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
+22
-13
@@ -10,6 +10,10 @@ import com.comphenix.protocol.wrappers.WrappedServerPing;
|
||||
import eu.kennytv.maintenance.core.listener.IPingListener;
|
||||
import eu.kennytv.maintenance.spigot.MaintenanceSpigotBase;
|
||||
import eu.kennytv.maintenance.spigot.SettingsSpigot;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.server.ServerListPingEvent;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.io.File;
|
||||
@@ -17,12 +21,11 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public final class PacketListener implements IPingListener {
|
||||
private final MaintenanceSpigotBase pl;
|
||||
private WrappedServerPing.CompressedImage image;
|
||||
public final class ServerInfoPacketListener extends PingListenerBase {
|
||||
//private WrappedServerPing.CompressedImage image;
|
||||
|
||||
public PacketListener(final MaintenanceSpigotBase base, final SettingsSpigot settings) {
|
||||
this.pl = base;
|
||||
public ServerInfoPacketListener(final MaintenanceSpigotBase base, final SettingsSpigot settings) {
|
||||
super(base, settings);
|
||||
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(base, ListenerPriority.HIGHEST,
|
||||
PacketType.Status.Server.SERVER_INFO) {
|
||||
@Override
|
||||
@@ -35,29 +38,35 @@ public final class PacketListener implements IPingListener {
|
||||
if (settings.hasCustomPlayerCountMessage()) {
|
||||
ping.setVersionProtocol(0);
|
||||
ping.setVersionName(settings.getPlayerCountMessage()
|
||||
.replace("%ONLINE%", Integer.toString(pl.getServer().getOnlinePlayers().size()))
|
||||
.replace("%MAX%", Integer.toString(pl.getServer().getMaxPlayers())));
|
||||
.replace("%ONLINE%", Integer.toString(base.getServer().getOnlinePlayers().size()))
|
||||
.replace("%MAX%", Integer.toString(base.getServer().getMaxPlayers())));
|
||||
}
|
||||
|
||||
final List<WrappedGameProfile> players = new ArrayList<>();
|
||||
for (final String string : settings.getPlayerCountHoverMessage().split("%NEWLINE%"))
|
||||
players.add(new WrappedGameProfile(UUID.randomUUID(), string));
|
||||
ping.setPlayers(players);
|
||||
|
||||
if (settings.hasCustomIcon() && image != null)
|
||||
ping.setFavicon(image);
|
||||
//if (settings.hasCustomIcon() && image != null) ping.setFavicon(image);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void serverListPing(final ServerListPingEvent event) {
|
||||
if (settings.isMaintenance() && settings.hasCustomIcon() && serverIcon != null)
|
||||
event.setServerIcon(serverIcon);
|
||||
}
|
||||
|
||||
/*@Override
|
||||
public boolean loadIcon() {
|
||||
try {
|
||||
image = WrappedServerPing.CompressedImage.fromPng(ImageIO.read(new File("maintenance-icon.png")));
|
||||
} catch (final Exception e) {
|
||||
pl.getLogger().warning("§4Could not load 'maintenance-icon.png' - did you create one in your Spigot folder (not the plugins folder)?");
|
||||
pl.getLogger().warning("Could not load 'maintenance-icon.png' - did you create one in your Spigot folder (not the plugins folder)?");
|
||||
if (pl.getApi().getSettings().debugEnabled())
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}*/
|
||||
}
|
||||
+2
-23
@@ -1,25 +1,15 @@
|
||||
package eu.kennytv.maintenance.spigot.listener;
|
||||
|
||||
import eu.kennytv.maintenance.core.listener.IPingListener;
|
||||
import eu.kennytv.maintenance.spigot.MaintenanceSpigotBase;
|
||||
import eu.kennytv.maintenance.spigot.SettingsSpigot;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.server.ServerListPingEvent;
|
||||
import org.bukkit.util.CachedServerIcon;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.io.File;
|
||||
|
||||
public final class ServerListPingListener implements Listener, IPingListener {
|
||||
private final MaintenanceSpigotBase plugin;
|
||||
private final SettingsSpigot settings;
|
||||
private CachedServerIcon serverIcon;
|
||||
public final class ServerListPingListener extends PingListenerBase {
|
||||
|
||||
public ServerListPingListener(final MaintenanceSpigotBase plugin, final SettingsSpigot settings) {
|
||||
this.plugin = plugin;
|
||||
this.settings = settings;
|
||||
super(plugin, settings);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
@@ -32,15 +22,4 @@ public final class ServerListPingListener implements Listener, IPingListener {
|
||||
if (settings.hasCustomIcon() && serverIcon != null)
|
||||
event.setServerIcon(serverIcon);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean loadIcon() {
|
||||
try {
|
||||
serverIcon = plugin.getServer().loadServerIcon(ImageIO.read(new File("maintenance-icon.png")));
|
||||
} catch (final Exception e) {
|
||||
plugin.getLogger().warning("§4Could not load 'maintenance-icon.png' - did you create one in your Spigot folder (not the plugins folder)?");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
+42
-48
@@ -2,23 +2,17 @@ package eu.kennytv.maintenance.spigot.metrics;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
import org.bukkit.plugin.ServicePriority;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.*;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Collection;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
import java.util.UUID;
|
||||
@@ -27,24 +21,16 @@ import java.util.zip.GZIPOutputStream;
|
||||
|
||||
public final class MetricsLite {
|
||||
|
||||
static {
|
||||
if (System.getProperty("bstats.relocatecheck") == null || !System.getProperty("bstats.relocatecheck").equals("false")) {
|
||||
final String defaultPackage = new String(
|
||||
new byte[]{'o', 'r', 'g', '.', 'b', 's', 't', 'a', 't', 's', '.', 'b', 'u', 'k', 'k', 'i', 't'});
|
||||
final String examplePackage = new String(new byte[]{'y', 'o', 'u', 'r', '.', 'p', 'a', 'c', 'k', 'a', 'g', 'e'});
|
||||
if (MetricsLite.class.getPackage().getName().equals(defaultPackage) || MetricsLite.class.getPackage().getName().equals(examplePackage)) {
|
||||
throw new IllegalStateException("bStats Metrics class has not been relocated correctly!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static final int B_STATS_VERSION = 1;
|
||||
private static final String URL = "https://bStats.org/submitData/bukkit";
|
||||
private boolean enabled;
|
||||
private static boolean logFailedRequests;
|
||||
private static boolean logSentData;
|
||||
private static boolean logResponseStatusText;
|
||||
private static String serverUUID;
|
||||
private final JavaPlugin plugin;
|
||||
private final Plugin plugin;
|
||||
|
||||
public MetricsLite(final JavaPlugin plugin) {
|
||||
public MetricsLite(final Plugin plugin) {
|
||||
if (plugin == null) {
|
||||
throw new IllegalArgumentException("Plugin cannot be null!");
|
||||
}
|
||||
@@ -55,10 +41,11 @@ public final class MetricsLite {
|
||||
final YamlConfiguration config = YamlConfiguration.loadConfiguration(configFile);
|
||||
|
||||
if (!config.isSet("serverUuid")) {
|
||||
|
||||
config.addDefault("enabled", true);
|
||||
config.addDefault("serverUuid", UUID.randomUUID().toString());
|
||||
config.addDefault("logFailedRequests", false);
|
||||
config.addDefault("logSentData", false);
|
||||
config.addDefault("logResponseStatusText", false);
|
||||
|
||||
config.options().header(
|
||||
"bStats collects some data for plugin authors like how many servers are using their plugins.\n" +
|
||||
@@ -68,13 +55,16 @@ public final class MetricsLite {
|
||||
).copyDefaults(true);
|
||||
try {
|
||||
config.save(configFile);
|
||||
} catch (final IOException ignored) {
|
||||
} catch (IOException ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
serverUUID = config.getString("serverUuid");
|
||||
logFailedRequests = config.getBoolean("logFailedRequests", false);
|
||||
if (config.getBoolean("enabled", true)) {
|
||||
logSentData = config.getBoolean("logSentData", false);
|
||||
logResponseStatusText = config.getBoolean("logResponseStatusText", false);
|
||||
enabled = config.getBoolean("enabled", true);
|
||||
if (enabled) {
|
||||
boolean found = false;
|
||||
for (final Class<?> service : Bukkit.getServicesManager().getKnownServices()) {
|
||||
try {
|
||||
@@ -91,8 +81,12 @@ public final class MetricsLite {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
private void startSubmitting() {
|
||||
final Timer timer = new Timer(true); // We use a timer cause the Bukkit scheduler is affected by server lags
|
||||
final Timer timer = new Timer(true);
|
||||
timer.scheduleAtFixedRate(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
@@ -120,18 +114,9 @@ public final class MetricsLite {
|
||||
}
|
||||
|
||||
private JSONObject getServerData() {
|
||||
int playerAmount;
|
||||
try {
|
||||
final Method onlinePlayersMethod = Class.forName("org.bukkit.Server").getMethod("getOnlinePlayers");
|
||||
playerAmount = onlinePlayersMethod.getReturnType().equals(Collection.class)
|
||||
? ((Collection<?>) onlinePlayersMethod.invoke(Bukkit.getServer())).size()
|
||||
: ((Player[]) onlinePlayersMethod.invoke(Bukkit.getServer())).length;
|
||||
} catch (final Exception e) {
|
||||
playerAmount = Bukkit.getOnlinePlayers().size(); // Just use the new method if the Reflection failed
|
||||
}
|
||||
final int playerAmount = Bukkit.getOnlinePlayers().size();
|
||||
final int onlineMode = Bukkit.getOnlineMode() ? 1 : 0;
|
||||
String bukkitVersion = Bukkit.getVersion();
|
||||
bukkitVersion = bukkitVersion.substring(bukkitVersion.indexOf("MC: ") + 4, bukkitVersion.length() - 1);
|
||||
final String bukkitVersion = Bukkit.getVersion();
|
||||
|
||||
final String javaVersion = System.getProperty("java.version");
|
||||
final String osName = System.getProperty("os.name");
|
||||
@@ -178,7 +163,7 @@ public final class MetricsLite {
|
||||
|
||||
new Thread(() -> {
|
||||
try {
|
||||
sendData(data);
|
||||
sendData(plugin, data);
|
||||
} catch (final Exception e) {
|
||||
if (logFailedRequests) {
|
||||
plugin.getLogger().log(Level.WARNING, "Could not submit plugin stats of " + plugin.getName(), e);
|
||||
@@ -187,13 +172,16 @@ public final class MetricsLite {
|
||||
}).start();
|
||||
}
|
||||
|
||||
private static void sendData(final JSONObject data) throws Exception {
|
||||
private static void sendData(final Plugin plugin, final JSONObject data) throws Exception {
|
||||
if (data == null) {
|
||||
throw new IllegalArgumentException("Data cannot be null!");
|
||||
}
|
||||
if (Bukkit.isPrimaryThread()) {
|
||||
throw new IllegalAccessException("This method must not be called from the main thread!");
|
||||
}
|
||||
if (logSentData) {
|
||||
plugin.getLogger().info("Sending data to bStats: " + data.toString());
|
||||
}
|
||||
final HttpsURLConnection connection = (HttpsURLConnection) new URL(URL).openConnection();
|
||||
|
||||
final byte[] compressedData = compress(data.toString());
|
||||
@@ -201,9 +189,9 @@ public final class MetricsLite {
|
||||
connection.setRequestMethod("POST");
|
||||
connection.addRequestProperty("Accept", "application/json");
|
||||
connection.addRequestProperty("Connection", "close");
|
||||
connection.addRequestProperty("Content-Encoding", "gzip"); // We gzip our request
|
||||
connection.addRequestProperty("Content-Encoding", "gzip");
|
||||
connection.addRequestProperty("Content-Length", String.valueOf(compressedData.length));
|
||||
connection.setRequestProperty("Content-Type", "application/json"); // We send our data in JSON format
|
||||
connection.setRequestProperty("Content-Type", "application/json");
|
||||
connection.setRequestProperty("User-Agent", "MC-Server/" + B_STATS_VERSION);
|
||||
|
||||
connection.setDoOutput(true);
|
||||
@@ -212,16 +200,22 @@ public final class MetricsLite {
|
||||
outputStream.flush();
|
||||
outputStream.close();
|
||||
|
||||
connection.getInputStream().close();
|
||||
if (logResponseStatusText) {
|
||||
final InputStream inputStream = connection.getInputStream();
|
||||
final BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
|
||||
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
String line;
|
||||
while ((line = bufferedReader.readLine()) != null) {
|
||||
builder.append(line);
|
||||
}
|
||||
bufferedReader.close();
|
||||
plugin.getLogger().info("Sent data to bStats and received response: " + builder.toString());
|
||||
} else {
|
||||
connection.getInputStream().close();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gzips the given String.
|
||||
*
|
||||
* @param str The string to gzip.
|
||||
* @return The gzipped String.
|
||||
* @throws IOException If the compression failed.
|
||||
*/
|
||||
private static byte[] compress(final String str) throws IOException {
|
||||
if (str == null) {
|
||||
return null;
|
||||
|
||||
+5
@@ -32,4 +32,9 @@ public final class BukkitSenderInfo implements SenderInfo {
|
||||
public void sendMessage(final String message) {
|
||||
sender.sendMessage(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPlayer() {
|
||||
return sender instanceof Player;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
# MaintenanceSpigot Plugin by KennyTV
|
||||
# Important note: To use this plugin to its full extend, it requires the plugin 'ProtocolLib'
|
||||
# Also, configs are cool, which means after the first plugin save, all comments will vanish
|
||||
# To still know what each field is for, check https://gist.github.com/KennyTV/a73f2aed1e278d4c927f9f6a3ef9fde2#file-spigot-config-yml
|
||||
|
||||
# Enables maintenance-mode.
|
||||
enable-maintenance-mode: false
|
||||
@@ -35,5 +37,5 @@ send-join-notification: false
|
||||
custom-maintenance-icon: false
|
||||
|
||||
# Changes the language of command feedback/messages.
|
||||
# Currently available are: en (English), de (German)
|
||||
# Currently available are: en (English), de (German), fr (French), pt (Portuguese)
|
||||
language: en
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>eu.kennytv</groupId>
|
||||
<artifactId>maintenance-base</artifactId>
|
||||
<version>2.5.1</version>
|
||||
<version>2.5.2</version>
|
||||
<name>Maintenance</name>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.2.0</version>
|
||||
<version>3.2.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
|
||||
Reference in new issue
Block a user