Skip to content

Commit

Permalink
2.3.1 Release
Browse files Browse the repository at this point in the history
  • Loading branch information
kennytv authored Aug 16, 2018
2 parents a3b836b + 25e2f4d commit 4204129
Show file tree
Hide file tree
Showing 20 changed files with 121 additions and 66 deletions.
4 changes: 2 additions & 2 deletions Maintenance-API/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<artifactId>maintenance-base</artifactId>
<groupId>eu.kennytv</groupId>
<version>2.3</version>
<version>2.3.1</version>
</parent>

<artifactId>maintenance-api</artifactId>
Expand All @@ -16,7 +16,7 @@
<dependency>
<groupId>net.md-5</groupId>
<artifactId>bungeecord-api</artifactId>
<version>1.12-SNAPSHOT</version>
<version>1.13-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public interface IMaintenance {
boolean isMaintenance();

/**
* @return true if a timer task is currently running
* @return true if a start- or endtimer task is currently running
*/
boolean isTaskRunning();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
public interface ISettings {

/**
* Note that the value might need a few seconds to update, if you're on BungeeCord with MySQL enabled
*
* @return true if maintenance is currently enabled
*/
boolean isMaintenance();
Expand Down Expand Up @@ -40,10 +42,10 @@ public interface ISettings {
/**
* Removes a player from the maintenance whitelist.
*
* @param name name of the player to remove in lowercase letters
* @param name name of the player to remove with original lower-/uppercase letters
* @return true if removing the player was successful
* @deprecated if a player changes their name, the list will still contain the old one
* @see #removeWhitelistedPlayer(UUID)
* @deprecated if a player changes their name, the list will still contain the old one and thus this might not work
*/
@Deprecated
boolean removeWhitelistedPlayer(String name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/**
* Utility class to get the {@link IMaintenance} instance for the BungeeCord version of the plugin.
* <p>
* This class is NOT available for the Spigot version!
* Only access this class if you're running the plugin on a BungeeCord server!
* </p>
*
* @author KennyTV
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
import org.bukkit.plugin.Plugin;

/**
* Utility class to get the {@link IMaintenance} instance for the Spigot/Bukkit version of the plugin.
* Utility class to get the {@link IMaintenance} instance for the Spigot version of the plugin.
* <p>
* This class is NOT available for the BungeeCord version!
* Only access this class if you're running the plugin on a Spigot server!
* </p>
*
* @author KennyTV
Expand Down
6 changes: 3 additions & 3 deletions Maintenance-Bungee/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<artifactId>maintenance-base</artifactId>
<groupId>eu.kennytv</groupId>
<version>2.3</version>
<version>2.3.1</version>
</parent>

<artifactId>maintenance-bungee</artifactId>
Expand All @@ -29,7 +29,7 @@
<dependency>
<groupId>net.md-5</groupId>
<artifactId>bungeecord-api</artifactId>
<version>1.12-SNAPSHOT</version>
<version>1.13-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand All @@ -41,7 +41,7 @@
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
<version>3.1.0</version>
<version>3.2.0</version>
<scope>compile</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package eu.kennytv.maintenance.bungee;

import com.google.common.collect.Lists;
import eu.kennytv.maintenance.bungee.listener.ProxyPingListener;
import eu.kennytv.maintenance.bungee.mysql.MySQL;
import eu.kennytv.maintenance.core.Settings;
Expand All @@ -11,6 +10,7 @@
import net.md_5.bungee.config.YamlConfiguration;

import java.io.*;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.sql.SQLException;
import java.util.List;
Expand All @@ -26,6 +26,9 @@ public final class SettingsBungee extends Settings {
private Configuration config;
private Configuration whitelist;

private long millisecondsToCheck;
private long lastMySQLCheck;

SettingsBungee(final MaintenanceBungeeBase plugin) {
this.plugin = plugin;

Expand Down Expand Up @@ -58,6 +61,16 @@ public final class SettingsBungee extends Settings {
}
}

@Override
public void updateExtraConfig() {
// 2.3.1 mysql.update-interval
if (!configContains("mysql.update-interval")) {
setToConfig("mysql.update-interval", 15);
saveConfig();
reloadConfigs();
}
}

@Override
public void reloadConfigs() {
reloadConfigs(false);
Expand All @@ -67,20 +80,12 @@ public void reloadConfigs() {
public void saveConfig() {
final File file = new File(plugin.getDataFolder(), "bungee-config.yml");
try {
YamlConfiguration.getProvider(YamlConfiguration.class).save(config, new OutputStreamWriter(new FileOutputStream(file), "UTF8"));
YamlConfiguration.getProvider(YamlConfiguration.class).save(config, new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8));
} catch (final IOException e) {
throw new RuntimeException("Unable to save bungee-config.yml!", e);
}
}

@Override
public void updateConfig() {
if (!config.contains("pingmessage")) return;
config.set("pingmessages", Lists.newArrayList(getConfigString("pingmessage")));
config.set("pingmessage", null);
saveConfig();
}

@Override
public void saveWhitelistedPlayers() {
final File file = new File(plugin.getDataFolder(), "WhitelistedPlayers.yml");
Expand All @@ -94,7 +99,7 @@ public void saveWhitelistedPlayers() {
private void reloadConfigs(final boolean createdNewWhitelist) {
final File file = new File(plugin.getDataFolder(), "bungee-config.yml");
try {
config = YamlConfiguration.getProvider(YamlConfiguration.class).load(new InputStreamReader(new FileInputStream(file), "UTF8"));
config = YamlConfiguration.getProvider(YamlConfiguration.class).load(new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8));
whitelist = YamlConfiguration.getProvider(YamlConfiguration.class).load(new File(plugin.getDataFolder(), "WhitelistedPlayers.yml"));
} catch (final IOException e) {
throw new RuntimeException("Unable to load bungee-config.yml!", e);
Expand All @@ -112,6 +117,11 @@ private void reloadConfigs(final boolean createdNewWhitelist) {
public void loadExtraSettings() {
whitelistedPlayers.clear();
whitelist.getKeys().forEach(key -> whitelistedPlayers.put(UUID.fromString(key), whitelist.getString(key)));
if (mySQL != null) {
final long configValue = config.getInt("mysql.update-interval");
millisecondsToCheck = configValue > 0 ? configValue * 1000 : -1;
lastMySQLCheck = 0;
}
}

@Override
Expand Down Expand Up @@ -149,7 +159,12 @@ public boolean createFiles() {

@Override
public String getConfigString(final String path) {
return ChatColor.translateAlternateColorCodes('&', config.getString(path));
final String s = config.getString(path);
if (s == null) {
plugin.getLogger().warning("The config is missing the following string: " + path);
return "null";
}
return ChatColor.translateAlternateColorCodes('&', s);
}

@Override
Expand All @@ -172,23 +187,29 @@ public void setToConfig(final String path, final Object var) {
config.set(path, var);
}

@Override
public boolean configContains(final String path) {
return config.contains(path);
}

@Override
public String getColoredString(final String message) {
return ChatColor.translateAlternateColorCodes('&', message);
}

@Override
public boolean isMaintenance() {
if (mySQL != null) {
if (mySQL != null && (millisecondsToCheck == -1 || System.currentTimeMillis() - lastMySQLCheck > millisecondsToCheck)) {
mySQL.executeQuery(maintenanceQuery, rs -> {
try {
if (rs.next())
maintenance = Boolean.parseBoolean(rs.getString("value"));
rs.close();
} catch (final SQLException e) {
e.printStackTrace();
}
}, "maintenance");
if (millisecondsToCheck != -1)
lastMySQLCheck = System.currentTimeMillis();
}

return maintenance;
Expand All @@ -203,6 +224,8 @@ public void setMaintenanceToSQL(final boolean maintenance) {
plugin.getProxy().getScheduler().runAsync(plugin, () -> {
final String s = String.valueOf(maintenance);
mySQL.executeUpdate(updateQuery, "maintenance", s, s);
if (millisecondsToCheck != -1)
lastMySQLCheck = System.currentTimeMillis();
});
this.maintenance = maintenance;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,4 @@ public void executeUpdate(final String query, final Object... objects) {
executeUpdate(query, res -> {
}, objects);
}

public void close() {
if (hikariDataSource != null && !hikariDataSource.isClosed())
hikariDataSource.close();
}
}
6 changes: 5 additions & 1 deletion Maintenance-Bungee/src/main/resources/bungee-config.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# MaintenanceBungee Plugin by KennyTV
# MaintenanceBungee Plugin by KennyTV
# Version ${project.version}

# Enables maintenance-mode.
Expand Down Expand Up @@ -50,3 +50,7 @@ mysql:
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 to 0 to make a database request on every single ping.
update-interval: 15
2 changes: 1 addition & 1 deletion Maintenance-Core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<artifactId>maintenance-base</artifactId>
<groupId>eu.kennytv</groupId>
<version>2.3</version>
<version>2.3.1</version>
</parent>

<artifactId>maintenance-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,28 @@ protected void loadSettings() {
broadcastIntervalls = new HashSet<>(getConfigIntList("timer-broadcasts-for-minutes"));
playerCountMessage = getConfigString("playercountmessage");
playerCountHoverMessage = getConfigString("playercounthovermessage");
if (hasCustomIcon())
if (customMaintenanceIcon)
reloadMaintenanceIcon();

loadExtraSettings();
}

@Deprecated
public abstract void updateConfig();
private void updateConfig() {
// 2.3 pingmessage -> pingmessages
if (configContains("pingmessage")) {
final List<Object> list = new ArrayList<>();
list.add(getConfigString("pingmessage"));
setToConfig("pingmessages", list);
setToConfig("pingmessage", null);
saveConfig();
reloadConfigs();
}

updateExtraConfig();
}

public void updateExtraConfig() {
}

public abstract void saveWhitelistedPlayers();

Expand All @@ -70,6 +84,8 @@ protected void loadSettings() {

public abstract void setToConfig(String path, Object var);

public abstract boolean configContains(String path);

public abstract String getColoredString(String s);

public List<String> getPingMessages() {
Expand Down Expand Up @@ -121,6 +137,7 @@ public void setMaintenance(final boolean maintenance) {
}

public String getRandomPingMessage() {
if (pingMessages.isEmpty()) return "";
final String s = pingMessages.size() > 1 ? pingMessages.get(RANDOM.nextInt(pingMessages.size())) : pingMessages.get(0);
return getColoredString(s.replace("%NEWLINE%", "\n"));
}
Expand Down Expand Up @@ -158,7 +175,7 @@ public boolean removeWhitelistedPlayer(final UUID uuid) {
@Override
public boolean removeWhitelistedPlayer(final String name) {
if (!whitelistedPlayers.containsValue(name)) return false;
final UUID uuid = whitelistedPlayers.entrySet().stream().filter(entry -> entry.getValue().equals(name)).findFirst().get().getKey();
final UUID uuid = whitelistedPlayers.entrySet().stream().filter(entry -> entry.getValue().equals(name)).findAny().get().getKey();
whitelistedPlayers.remove(uuid);
setWhitelist(uuid.toString(), null);
saveWhitelistedPlayers();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,19 +186,30 @@ public void execute(final SenderInfo sender, final String[] args) {
private void sendUsage(final SenderInfo sender) {
sender.sendMessage("");
sender.sendMessage("§8===========[ §e" + name + " §8| §eVersion: §e" + plugin.getVersion() + " §8]===========");
sender.sendMessage("§6/maintenance reload §7(Reloads the config file, whitelist file and the server-icon)");
sender.sendMessage("§6/maintenance on §7(Enables maintenance mode");
sender.sendMessage("§6/maintenance off §7(Disables maintenance mode)");
sender.sendMessage("§6/maintenance starttimer <minutes> §7(After the given time in minutes, maintenance mode will be enabled. Broadcast settings for the timer can be found in the config)");
sender.sendMessage("§6/maintenance endtimer <minutes> §7(Enables maintenance mode. After the given time in minutes, maintenance mode will be disabled)");
sender.sendMessage("§6/maintenance timer abort §7(If running, the current timer will be aborted)");
sender.sendMessage("§6/maintenance whitelist §7(Shows all whitelisted players for the maintenance mode)");
sender.sendMessage("§6/maintenance add <player> §7(Adds the player to the maintenance whitelist, so they can join the server even though maintenance is enabled)");
sender.sendMessage("§6/maintenance remove <player> §7(Removes the player from the maintenance whitelist)");
sender.sendMessage("§6/maintenance setmotd <index> <1/2> <message> §7(Sets a motd for maintenance mode)");
sender.sendMessage("§6/maintenance motd §7(Lists the currently set maintenance motds)");
sender.sendMessage("§6/maintenance update §7(Remotely downloads the newest version of the plugin onto your server)");
sender.sendMessage("§9Created by: KennyTV");
if (sender.hasPermission("maintenance.reload"))
sender.sendMessage("§6/maintenance reload §7(Reloads the config file, whitelist file and the server-icon)");
if (sender.hasPermission("maintenance.toggle")) {
sender.sendMessage("§6/maintenance on §7(Enables maintenance mode");
sender.sendMessage("§6/maintenance off §7(Disables maintenance mode)");
}
if (sender.hasPermission("maintenance.timer")) {
sender.sendMessage("§6/maintenance starttimer <minutes> §7(After the given time in minutes, maintenance mode will be enabled. Broadcast settings for the timer can be found in the config)");
sender.sendMessage("§6/maintenance endtimer <minutes> §7(Enables maintenance mode. After the given time in minutes, maintenance mode will be disabled)");
sender.sendMessage("§6/maintenance timer abort §7(If running, the current timer will be aborted)");
}
if (sender.hasPermission("maintenance.whitelist.list"))
sender.sendMessage("§6/maintenance whitelist §7(Shows all whitelisted players for the maintenance mode)");
if (sender.hasPermission("maintenance.whitelist.add"))
sender.sendMessage("§6/maintenance add <player> §7(Adds the player to the maintenance whitelist, so they can join the server even though maintenance is enabled)");
if (sender.hasPermission("maintenance.whitelist.remove"))
sender.sendMessage("§6/maintenance remove <player> §7(Removes the player from the maintenance whitelist)");
if (sender.hasPermission("maintenance.setmotd"))
sender.sendMessage("§6/maintenance setmotd <index> <1/2> <message> §7(Sets a motd for maintenance mode)");
if (sender.hasPermission("maintenance.motd"))
sender.sendMessage("§6/maintenance motd §7(Lists the currently set maintenance motds)");
if (sender.hasPermission("maintenance.update"))
sender.sendMessage("§6/maintenance update §7(Remotely downloads the newest version of the plugin onto your server)");
sender.sendMessage("§7Created by §bKennyTV");
sender.sendMessage("§8===========[ §e" + name + " §8| §eVersion: §e" + plugin.getVersion() + " §8]===========");
sender.sendMessage("");
}
Expand Down
2 changes: 1 addition & 1 deletion Maintenance-Parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<artifactId>maintenance-base</artifactId>
<groupId>eu.kennytv</groupId>
<version>2.3</version>
<version>2.3.1</version>
</parent>

<artifactId>maintenance-parent</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion Maintenance-Spigot/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<artifactId>maintenance-base</artifactId>
<groupId>eu.kennytv</groupId>
<version>2.3</version>
<version>2.3.1</version>
</parent>

<artifactId>maintenance-spigot</artifactId>
Expand Down
Loading

0 comments on commit 4204129

Please sign in to comment.