Compare commits

..
57 Commits
Author SHA1 Message Date
KennyTV 420412978e 2.3.1 Release 2018-08-16 17:56:28 +02:00
KennyTV 25e2f4dae2 2.3.1 Release 2018-08-16 17:54:57 +02:00
KennyTV d767be96b5 Fix 2018-08-15 11:54:35 +02:00
KennyTV 6d73acca9b Only check the mysql delay if it's at least a second 2018-08-15 11:11:25 +02:00
KennyTV 1f116374ad Fix permission checks for help page 2018-08-11 11:10:25 +02:00
KennyTV d0b7d96208 Fix updated config being overwritten again 2018-08-08 11:56:32 +02:00
KennyTV 16285d7064 Change some javadocs 2018-08-07 23:31:02 +02:00
KennyTV 1f27084fe1 Return empty string for pingmessages if config list is empty 2018-08-07 23:04:09 +02:00
KennyTV 261aace0db Remove unnecessary (second) result closing 2018-08-07 22:58:06 +02:00
KennyTV 344b910214 Remove unused method 2018-08-07 22:49:22 +02:00
KennyTV fbaa4896e1 Replace deprecated ProtocolLib packet 2018-08-07 14:55:19 +02:00
KennyTV 2f93064f60 Some pom changes 2018-08-07 13:51:59 +02:00
KennyTV 65b47c5e07 Only show the commands you have the permission to execute in the helppage 2018-08-06 21:12:36 +02:00
KennyTV d70d01f2d3 Fix config updating unnecessary value in Spigot version 2018-07-27 12:34:09 +02:00
KennyTV 769d7d3bcd Minor improvement 2018-07-27 12:28:07 +02:00
KennyTV a5f47688e0 Minor improvement 2018-07-27 11:50:19 +02:00
KennyTV 7d2e6a25a4 Move license and whitelistedplayers file to core module 2018-07-25 00:29:06 +02:00
KennyTV 69999b3b7a Fix MySQL millisecondsToCheck variable 2018-07-24 22:29:03 +02:00
KennyTV 94d1bd4eb9 Only make a request to the database at least x seconds after the last one 2018-07-23 11:52:30 +02:00
KennyTV c18e8b7ab7 Add warning and backup string if config value is null 2018-07-23 11:10:16 +02:00
KennyTV 9f45187300 Add warning and backup string if config value is null 2018-07-23 11:09:08 +02:00
KennyTV 0c6ba8a9b7 Updated BungeeCord dependency to 1.13-SNAPSHOT 2018-07-21 11:02:55 +02:00
KennyTV 1af69f2e8b Version increase to 2.3.1-SNAPSHOT 2018-07-18 15:50:35 +02:00
KennyTV a3b836b1c5 2.3 Release 2018-07-17 11:45:43 +02:00
KennyTV 1eca6c81ad Version increase for the 2.3 Release 2018-07-17 11:41:03 +02:00
KennyTV b9b4a78b5c Minor cleanup 2018-07-16 21:52:27 +02:00
KennyTV fda23c5539 The whitelist command now also shows the UUID of the player 2018-07-16 20:25:05 +02:00
KennyTV 8297321971 Changed help message order 2018-07-16 18:04:14 +02:00
KennyTV cfeaf00f26 Fixed wrong command descriptions 2018-07-16 13:22:46 +02:00
KennyTV 5ee1b32249 Uncommented new help messages 2018-07-16 13:07:59 +02:00
KennyTV b69f0dc90e Added missing motd command permission 2018-07-14 22:27:20 +02:00
KennyTV fe6cae4e47 Added motdlist command 2018-07-09 16:33:51 +02:00
KennyTV b494b5c23c Reworked setmotd command 2018-07-09 15:49:54 +02:00
KennyTV 3bd3395128 Removed setmotd command 2018-07-08 11:29:20 +02:00
KennyTV 3e3f63220d Config fix 2018-07-08 11:25:47 +02:00
KennyTV ccba0f042f Version increase to 2.3-SNAPSHOT 2018-07-08 11:20:18 +02:00
KennyTV abdd89259d Added multiple pingmessages + minor improvements 2018-07-08 10:54:51 +02:00
KennyTV 256f203c48 Minor code change 2018-06-18 11:17:47 +02:00
KennyTV 205412b02c Minor improvement 2018-06-18 11:17:06 +02:00
KennyTV 990289feb2 Fixed a problem with the setmotd command 2018-06-17 20:57:50 +02:00
KennyTV 44b1ff1a1f Fixed a typo 2018-06-17 20:27:01 +02:00
KennyTV f9e11bb9e5 Removed unused method 2018-06-17 19:58:21 +02:00
KennyTV eef1584b1c Small logic change 2018-06-17 18:51:35 +02:00
KennyTV 937dd84d1c Added permission per subcommand 2018-06-17 18:40:47 +02:00
KennyTV 80b9fe280b Message change 2018-06-17 18:29:58 +02:00
KennyTV 3892892792 Version increase to 2.2.3-SNAPSHOT 2018-06-17 18:06:59 +02:00
KennyTV 519551e76c Removed Spigot dependency from Core module 2018-06-17 14:36:18 +02:00
KennyTV b30476ae3f 2.2.2 Release 2018-06-17 11:24:35 +02:00
KennyTV 9d417a12f1 2.2.2 Release 2018-06-17 11:22:43 +02:00
KennyTV fd5406b95d 2.2.2 Release 2018-06-17 11:21:10 +02:00
KennyTV 0ef59e557d Maintenance icon fix and reload command message change 2018-06-14 12:35:10 +02:00
KennyTV 15ed1db347 Made the loading of the maintenance icon more structured 2018-06-14 12:10:33 +02:00
KennyTV 429d5b90d4 Api fix 2018-06-10 10:44:42 +02:00
KennyTV b3ab931aca Removed old config comment 2018-06-09 11:26:58 +02:00
KennyTV 21b42d0c72 Version increase to 2.2.2-SNAPSHOT
Some minor pom changes
2018-06-09 10:14:21 +02:00
KennyTV 7b1e1a27ba Merge remote-tracking branch 'origin/master' 2018-04-23 11:39:04 +02:00
KennyTV fb7b1e791f Some javadoc and comment changes 2018-04-23 11:38:51 +02:00
34 changed files with 432 additions and 261 deletions

No files matched your search

Binary file not shown.
+3 -3
View File
@@ -6,7 +6,7 @@
<parent>
<artifactId>maintenance-base</artifactId>
<groupId>eu.kennytv</groupId>
<version>2.2.1</version>
<version>2.3.1</version>
</parent>
<artifactId>maintenance-api</artifactId>
@@ -16,13 +16,13 @@
<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>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.10.2-R0.1-SNAPSHOT</version>
<version>1.12.2-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
@@ -1,5 +1,9 @@
package eu.kennytv.maintenance.api;
/**
* @author KennyTV
* @since 2.1
*/
public interface IMaintenance {
/**
@@ -15,12 +19,12 @@ public interface IMaintenance {
void setMaintenance(boolean maintenance);
/**
* @return true if maintenance is enabled on the proxy
* @return true if maintenance is currently enabled
*/
boolean isMaintenance();
/**
* @return true if a timer task is currently running
* @return true if a start- or endtimer task is currently running
*/
boolean isTaskRunning();
@@ -30,7 +34,7 @@ public interface IMaintenance {
String getVersion();
/**
* @return {@link ISettings} for more options
* @return {@link ISettings} for options regarding configuration files
*/
ISettings getSettings();
}
@@ -0,0 +1,15 @@
package eu.kennytv.maintenance.api;
/**
* @author KennyTV
* @since 2.2.2
*/
public interface IMaintenanceBase {
/**
* Returns API instance of IMaintenance.
*
* @return {@link IMaintenance} instance
*/
IMaintenance getApi();
}
@@ -3,10 +3,16 @@ package eu.kennytv.maintenance.api;
import java.util.Map;
import java.util.UUID;
/**
* @author KennyTV
* @since 2.1
*/
public interface ISettings {
/**
* @return true if maintenance is enabled on the proxy
* 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();
@@ -21,9 +27,7 @@ public interface ISettings {
boolean hasCustomIcon();
/**
* The keyset of the map contains the uuids as a string, the values the names of the players.
*
* @return map of uuids of whitelisted players with their last seen names
* @return map of uuids of whitelisted players with their given names
*/
Map<UUID, String> getWhitelistedPlayers();
@@ -38,9 +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 their old one
* @deprecated if a player changes their name, the list will still contain the old one
* @see #removeWhitelistedPlayer(UUID)
*/
@Deprecated
boolean removeWhitelistedPlayer(String name);
@@ -53,4 +58,11 @@ public interface ISettings {
* @return true if adding the player was successful
*/
boolean addWhitelistedPlayer(UUID uuid, String name);
/**
* Reloads the maintenance-icon.png image from the server folder.
*
* @return true if loading the image was successful
*/
boolean reloadMaintenanceIcon();
}
@@ -6,11 +6,11 @@ import net.md_5.bungee.api.plugin.Plugin;
/**
* 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
* @since 1.0
* @since 2.1
*/
public final class MaintenanceBungeeAPI {
@@ -24,6 +24,6 @@ public final class MaintenanceBungeeAPI {
if (maintenance == null)
ProxyServer.getInstance().getLogger().warning("Could not get instance of MaintenanceBungee!");
return (IMaintenance) maintenance;
return ((IMaintenanceBase) maintenance).getApi();
}
}
@@ -4,13 +4,13 @@ import org.bukkit.Bukkit;
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
* @since 1.0
* @since 2.1
*/
public final class MaintenanceSpigotAPI {
@@ -24,6 +24,6 @@ public final class MaintenanceSpigotAPI {
if (maintenance == null)
Bukkit.getLogger().warning("Could not get instance of MaintenanceSpigot!");
return (IMaintenance) maintenance;
return ((IMaintenanceBase) maintenance).getApi();
}
}
+4 -5
View File
@@ -3,11 +3,10 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>eu.kennytv</groupId>
<artifactId>maintenance-base</artifactId>
<version>2.2.1</version>
<groupId>eu.kennytv</groupId>
<version>2.3.1</version>
</parent>
<artifactId>maintenance-bungee</artifactId>
@@ -30,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>
@@ -42,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>
@@ -1,18 +1,22 @@
package eu.kennytv.maintenance.bungee;
import eu.kennytv.maintenance.api.IMaintenance;
import eu.kennytv.maintenance.api.IMaintenanceBase;
import net.md_5.bungee.api.plugin.Plugin;
import java.io.File;
/**
* @author KennyTV
* @since 2.1
*/
public final class MaintenanceBungeeBase extends Plugin {
public final class MaintenanceBungeeBase extends Plugin implements IMaintenanceBase {
private IMaintenance maintenance;
@Override
public void onEnable() {
new MaintenanceBungeePlugin(this);
maintenance = new MaintenanceBungeePlugin(this);
}
@Override
public IMaintenance getApi() {
return maintenance;
}
File getPluginFile() {
@@ -6,7 +6,6 @@ import eu.kennytv.maintenance.api.MaintenanceBungeeAPI;
import eu.kennytv.maintenance.bungee.command.MaintenanceBungeeCommand;
import eu.kennytv.maintenance.bungee.command.MaintenanceBungeeCommandBase;
import eu.kennytv.maintenance.bungee.listener.PostLoginListener;
import eu.kennytv.maintenance.bungee.listener.ProxyPingListener;
import eu.kennytv.maintenance.bungee.metrics.MetricsLite;
import eu.kennytv.maintenance.core.MaintenanceModePlugin;
import eu.kennytv.maintenance.core.hook.ServerListPlusHook;
@@ -36,7 +35,6 @@ public final class MaintenanceBungeePlugin extends MaintenanceModePlugin {
final PluginManager pm = getProxy().getPluginManager();
pm.registerListener(plugin, new PostLoginListener(this, settings));
pm.registerListener(plugin, new ProxyPingListener(plugin, settings));
final MaintenanceBungeeCommand maintenanceCommand = new MaintenanceBungeeCommand(this, settings);
pm.registerCommand(plugin, new MaintenanceBungeeCommandBase(maintenanceCommand));
@@ -77,11 +75,6 @@ public final class MaintenanceBungeePlugin extends MaintenanceModePlugin {
getProxy().broadcast(settings.getMaintenanceDeactivated());
}
@Override
public boolean isMaintenance() {
return settings.isMaintenance();
}
@Override
public int schedule(final Runnable runnable) {
return getProxy().getScheduler().schedule(plugin, runnable, 0, 1, TimeUnit.MINUTES).getId();
@@ -1,12 +1,16 @@
package eu.kennytv.maintenance.bungee;
import eu.kennytv.maintenance.bungee.listener.ProxyPingListener;
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.plugin.PluginManager;
import net.md_5.bungee.config.Configuration;
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;
@@ -18,11 +22,21 @@ public final class SettingsBungee extends Settings {
private final MySQL mySQL;
private final MaintenanceBungeeBase plugin;
private final IPingListener pingListener;
private Configuration config;
private Configuration whitelist;
private long millisecondsToCheck;
private long lastMySQLCheck;
SettingsBungee(final MaintenanceBungeeBase plugin) {
this.plugin = plugin;
final PluginManager pm = plugin.getProxy().getPluginManager();
final ProxyPingListener listener = new ProxyPingListener(plugin, this);
pm.registerListener(plugin, listener);
pingListener = listener;
reloadConfigs(createFiles());
final Configuration mySQLSection = config.getSection("mysql");
@@ -47,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);
@@ -56,7 +80,7 @@ public final class SettingsBungee extends Settings {
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);
}
@@ -75,7 +99,7 @@ public final class SettingsBungee extends Settings {
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);
@@ -93,6 +117,11 @@ public final class SettingsBungee extends Settings {
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
@@ -130,7 +159,12 @@ public final class SettingsBungee extends Settings {
@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
@@ -139,8 +173,13 @@ public final class SettingsBungee extends Settings {
}
@Override
public List<Integer> getBroadcastIntervallList() {
return config.getIntList("timer-broadcasts-for-minutes");
public List<Integer> getConfigIntList(final String path) {
return config.getIntList(path);
}
@Override
public List<String> getConfigList(final String path) {
return config.getStringList(path);
}
@Override
@@ -148,27 +187,45 @@ public final class SettingsBungee extends Settings {
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;
}
@Override
public boolean reloadMaintenanceIcon() {
return pingListener.loadIcon();
}
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;
}
@@ -5,7 +5,6 @@ import eu.kennytv.maintenance.bungee.SettingsBungee;
import eu.kennytv.maintenance.bungee.util.ProxiedSenderInfo;
import eu.kennytv.maintenance.core.command.MaintenanceCommand;
import eu.kennytv.maintenance.core.util.SenderInfo;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.HoverEvent;
@@ -58,15 +57,10 @@ public final class MaintenanceBungeeCommand extends MaintenanceCommand {
final TextComponent tc = new TextComponent("§6× §8[§aUpdate§8]");
tc.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/maintenance forceupdate"));
tc.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText("§aClick here to update the plugin")));
tc.addExtra(" §8< §7Or use the command §c/maintenace forceupdate");
tc.addExtra(" §8< §7Or use the command §c/maintenance forceupdate");
((ProxiedSenderInfo) sender).sendMessage(tc);
} else
sender.sendMessage(plugin.getPrefix() + "§aYou already have the latest version of the plugin!");
}
@Override
protected String getColoredString(final String message) {
return ChatColor.translateAlternateColorCodes('&', message);
}
}
@@ -2,6 +2,7 @@ package eu.kennytv.maintenance.bungee.listener;
import eu.kennytv.maintenance.bungee.MaintenanceBungeeBase;
import eu.kennytv.maintenance.bungee.SettingsBungee;
import eu.kennytv.maintenance.core.listener.IPingListener;
import net.md_5.bungee.api.Favicon;
import net.md_5.bungee.api.ServerPing;
import net.md_5.bungee.api.event.ProxyPingEvent;
@@ -13,16 +14,14 @@ import javax.imageio.ImageIO;
import java.io.File;
import java.io.IOException;
public final class ProxyPingListener implements Listener {
public final class ProxyPingListener implements Listener, IPingListener {
private final MaintenanceBungeeBase plugin;
private final SettingsBungee settings;
private final File icon;
private Favicon favicon;
public ProxyPingListener(final MaintenanceBungeeBase plugin, final SettingsBungee settings) {
this.plugin = plugin;
this.settings = settings;
icon = new File("maintenance-icon.png");
}
@EventHandler(priority = EventPriority.HIGHEST)
@@ -30,22 +29,27 @@ public final class ProxyPingListener implements Listener {
if (!settings.isMaintenance()) return;
final ServerPing ping = event.getResponse();
ping.setVersion(new ServerPing.Protocol(settings.getPlayerCountMessage(), 1));
ping.setDescription(settings.getPingMessage().replace("%NEWLINE%", "\n"));
ping.setPlayers(new ServerPing.Players(0, 0, new ServerPing.PlayerInfo[]{
ping.getVersion().setProtocol(1);
ping.getVersion().setName(settings.getPlayerCountMessage());
ping.setDescription(settings.getRandomPingMessage());
ping.getPlayers().setOnline(0);
ping.getPlayers().setMax(0);
ping.getPlayers().setSample(new ServerPing.PlayerInfo[]{
new ServerPing.PlayerInfo(settings.getPlayerCountHoverMessage().replace("%NEWLINE%", "\n"), "")
}));
});
if (settings.hasCustomIcon()) {
if (favicon != null)
ping.setFavicon(favicon);
else {
try {
favicon = Favicon.create(ImageIO.read(icon));
} 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.hasCustomIcon() && favicon != null)
ping.setFavicon(favicon);
}
@Override
public boolean loadIcon() {
try {
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)?");
return false;
}
return true;
}
}
@@ -65,9 +65,4 @@ public final class MySQL {
executeUpdate(query, res -> {
}, objects);
}
public void close() {
if (hikariDataSource != null && !hikariDataSource.isClosed())
hikariDataSource.close();
}
}
@@ -1,11 +1,14 @@
# MaintenanceBungee Plugin by KennyTV
# MaintenanceBungee Plugin by KennyTV
# Version ${project.version}
# Enables maintenance-mode.
enable-maintenance-mode: false
# The message shown in the multiplayer server list motd.
pingmessage: "&cMaintenance mode!%NEWLINE%&6We will be back soon!"
# If you put in multiple entries, one of them will be chosen randomly on every ping.
pingmessages:
- "&cMaintenance mode!%NEWLINE%&6We will be back soon!"
#- "Another entry"
# Is shown at the top right corner of the server in the serverlist,
# where the playercount would normally be displayed.
@@ -38,7 +41,6 @@ join-notification: "&e%PLAYER% &ctried to join the server."
custom-maintenance-icon: false
# Only enable MySQL if you really know what you are doing.
# You need to have a table with the two following columns: 'setting' and 'value'.
mysql:
use-mysql: false
host: host
@@ -48,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
+1 -7
View File
@@ -6,19 +6,13 @@
<parent>
<artifactId>maintenance-base</artifactId>
<groupId>eu.kennytv</groupId>
<version>2.2.1</version>
<version>2.3.1</version>
</parent>
<artifactId>maintenance-core</artifactId>
<name>Maintenance-Core</name>
<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.12.2-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>net.minecrell</groupId>
<artifactId>ServerListPlus</artifactId>
@@ -21,6 +21,11 @@ public abstract class MaintenanceModePlugin implements IMaintenance {
this.version = version;
}
@Override
public boolean isMaintenance() {
return getSettings().isMaintenance();
}
@Override
public String getVersion() {
return version;
@@ -1,21 +1,17 @@
package eu.kennytv.maintenance.core;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import eu.kennytv.maintenance.api.ISettings;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.*;
public abstract class Settings implements ISettings {
protected final Map<UUID, String> whitelistedPlayers = Maps.newHashMap();
private static final Random RANDOM = new Random();
protected final Map<UUID, String> whitelistedPlayers = new HashMap<>();
protected boolean maintenance;
private Set<Integer> broadcastIntervalls;
private List<String> pingMessages;
private String timerBroadcastMessage;
private String endtimerBroadcastMessage;
private String pingMessage;
private String kickMessage;
private String joinNotification;
private String noPermMessage;
@@ -27,9 +23,11 @@ public abstract class Settings implements ISettings {
private boolean customMaintenanceIcon;
protected void loadSettings() {
updateConfig();
pingMessages = getConfigList("pingmessages");
timerBroadcastMessage = getConfigString("starttimer-broadcast-mesage");
endtimerBroadcastMessage = getConfigString("endtimer-broadcast-mesage");
pingMessage = getConfigString("pingmessage");
kickMessage = getConfigString("kickmessage");
joinNotification = getConfigString("join-notification");
noPermMessage = getConfigString("no-permission");
@@ -38,13 +36,32 @@ public abstract class Settings implements ISettings {
maintenance = getConfigBoolean("enable-maintenance-mode");
joinNotifications = getConfigBoolean("send-join-notification");
customMaintenanceIcon = getConfigBoolean("custom-maintenance-icon");
broadcastIntervalls = Sets.newHashSet(getBroadcastIntervallList());
broadcastIntervalls = new HashSet<>(getConfigIntList("timer-broadcasts-for-minutes"));
playerCountMessage = getConfigString("playercountmessage");
playerCountHoverMessage = getConfigString("playercounthovermessage");
if (customMaintenanceIcon)
reloadMaintenanceIcon();
loadExtraSettings();
}
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();
public abstract boolean createFiles();
@@ -53,7 +70,9 @@ public abstract class Settings implements ISettings {
public abstract boolean getConfigBoolean(String path);
public abstract List<Integer> getBroadcastIntervallList();
public abstract List<Integer> getConfigIntList(String path);
public abstract List<String> getConfigList(String path);
public abstract void loadExtraSettings();
@@ -65,6 +84,18 @@ public abstract class Settings implements ISettings {
public abstract void setToConfig(String path, Object var);
public abstract boolean configContains(String path);
public abstract String getColoredString(String s);
public List<String> getPingMessages() {
return pingMessages;
}
public Set<Integer> getBroadcastIntervalls() {
return broadcastIntervalls;
}
public String getTimerBroadcastMessage() {
return timerBroadcastMessage;
}
@@ -73,10 +104,6 @@ public abstract class Settings implements ISettings {
return endtimerBroadcastMessage;
}
public String getPingMessage() {
return pingMessage;
}
public String getKickMessage() {
return kickMessage;
}
@@ -109,6 +136,12 @@ public abstract class Settings implements ISettings {
this.maintenance = 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"));
}
@Override
public boolean isMaintenance() {
return maintenance;
@@ -124,10 +157,6 @@ public abstract class Settings implements ISettings {
return customMaintenanceIcon;
}
public Set<Integer> getBroadcastIntervalls() {
return broadcastIntervalls;
}
@Override
public Map<UUID, String> getWhitelistedPlayers() {
return whitelistedPlayers;
@@ -146,7 +175,7 @@ public abstract class Settings implements ISettings {
@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();
@@ -3,7 +3,6 @@ package eu.kennytv.maintenance.core.command;
import eu.kennytv.maintenance.core.MaintenanceModePlugin;
import eu.kennytv.maintenance.core.Settings;
import eu.kennytv.maintenance.core.runnable.MaintenanceRunnable;
import eu.kennytv.maintenance.core.util.MessageUtil;
import eu.kennytv.maintenance.core.util.SenderInfo;
import java.util.Arrays;
@@ -22,37 +21,23 @@ public abstract class MaintenanceCommand {
}
public void execute(final SenderInfo sender, final String[] args) {
if (!sender.hasPermission("maintenance.admin")) {
sender.sendMessage(settings.getNoPermMessage());
return;
}
if (checkPermission(sender, "command")) return;
if (args.length == 1) {
if (args[0].equalsIgnoreCase("on")) {
if (checkPermission(sender, "toggle")) return;
plugin.setMaintenance(true);
} else if (args[0].equalsIgnoreCase("off")) {
if (checkPermission(sender, "toggle")) return;
plugin.setMaintenance(false);
} else if (args[0].equalsIgnoreCase("reload")) {
if (!sender.hasPermission("maintenance.reload")) {
sender.sendMessage(settings.getNoPermMessage());
return;
}
if (checkPermission(sender, "reload")) return;
settings.reloadConfigs();
sender.sendMessage(plugin.getPrefix() + "§aReloaded config.yml");
sender.sendMessage(plugin.getPrefix() + "§aReloaded config, whitelistedplayers and the maintenance icon");
} else if (args[0].equalsIgnoreCase("update")) {
if (!sender.hasPermission("maintenance.admin")) {
sender.sendMessage(settings.getNoPermMessage());
return;
}
if (checkPermission(sender, "update")) return;
checkForUpdate(sender);
} else if (args[0].equals("forceupdate")) {
if (!sender.hasPermission("maintenance.admin")) {
sender.sendMessage(settings.getNoPermMessage());
return;
}
if (checkPermission(sender, "update")) return;
sender.sendMessage(plugin.getPrefix() + "§c§lDownloading update...");
if (plugin.installUpdate())
@@ -60,6 +45,7 @@ public abstract class MaintenanceCommand {
else
sender.sendMessage(plugin.getPrefix() + "§4Failed!");
} else if (args[0].equalsIgnoreCase("whitelist")) {
if (checkPermission(sender, "whitelist.list")) return;
final Map<UUID, String> players = settings.getWhitelistedPlayers();
if (players.isEmpty()) {
sender.sendMessage(plugin.getPrefix() + "§cThe maintenance whitelist is empty! Use \"/maintenance add <player>\" to add someone!");
@@ -67,15 +53,26 @@ public abstract class MaintenanceCommand {
sender.sendMessage(plugin.getPrefix() + "§cUse \"/maintenance add <player>\" to add someone. Alternatively, you can add the uuid of a player to the WhitelistedPlayers.yml as seen in the example in the file!");
} else {
sender.sendMessage("§6Whitelisted players for maintenance:");
players.forEach((key, value) -> sender.sendMessage("§8- §e" + value));
players.forEach((key, value) -> sender.sendMessage("§8- §e" + value + " §8(§7" + key + "§8)"));
sender.sendMessage("");
}
} else if (args[0].equalsIgnoreCase("motd")) {
if (checkPermission(sender, "motd")) return;
sender.sendMessage(plugin.getPrefix() + "§7List of your maintenance motds:");
for (int i = 0; i < settings.getPingMessages().size(); i++) {
sender.sendMessage("§b" + (i + 1) + "§8§m---------");
for (final String motd : settings.getColoredString(settings.getPingMessages().get(i)).split("%NEWLINE%")) {
sender.sendMessage(motd);
}
}
sender.sendMessage("§8§m----------");
} else
sendUsage(sender);
} else if (args.length == 2) {
if (args[0].equalsIgnoreCase("endtimer")) {
if (!MessageUtil.isNumeric(args[1])) {
sender.sendMessage(plugin.getPrefix() + "§6/maintenance timer endtimer <minutes>");
if (checkPermission(sender, "timer")) return;
if (!isNumeric(args[1])) {
sender.sendMessage(plugin.getPrefix() + "§6/maintenance endtimer <minutes>");
return;
}
if (plugin.isTaskRunning()) {
@@ -97,8 +94,9 @@ public abstract class MaintenanceCommand {
sender.sendMessage(plugin.getPrefix() + "§aStarted timer: §7Maintenance mode will be deactivated in §6" + minutes + " minutes§7.");
plugin.setTaskId(plugin.schedule(new MaintenanceRunnable(plugin, settings, minutes, false)));
} else if (args[0].equalsIgnoreCase("starttimer")) {
if (!MessageUtil.isNumeric(args[1])) {
sender.sendMessage(plugin.getPrefix() + "§6/maintenance timer starttimer <minutes>");
if (checkPermission(sender, "timer")) return;
if (!isNumeric(args[1])) {
sender.sendMessage(plugin.getPrefix() + "§6/maintenance starttimer <minutes>");
return;
}
if (plugin.isTaskRunning()) {
@@ -120,6 +118,7 @@ public abstract class MaintenanceCommand {
plugin.setTaskId(plugin.schedule(new MaintenanceRunnable(plugin, settings, minutes, true)));
} else if (args[0].equalsIgnoreCase("timer")) {
if (args[1].equalsIgnoreCase("abort") || args[1].equalsIgnoreCase("stop") || args[1].equalsIgnoreCase("cancel")) {
if (checkPermission(sender, "timer")) return;
if (!plugin.isTaskRunning()) {
sender.sendMessage(plugin.getPrefix() + "§cThere's currently no running timer.");
return;
@@ -130,40 +129,56 @@ public abstract class MaintenanceCommand {
} else
sendUsage(sender);
} else if (args[0].equalsIgnoreCase("add")) {
if (checkPermission(sender, "whitelist.add")) return;
addPlayerToWhitelist(sender, args[1]);
} else if (args[0].equalsIgnoreCase("remove")) {
if (checkPermission(sender, "whitelist.remove")) return;
removePlayerFromWhitelist(sender, args[1]);
} else
sendUsage(sender);
} else if (args.length == 3) {
if (args[0].equalsIgnoreCase("setmotd")) {
if (!MessageUtil.isNumeric(args[1])) {
sender.sendMessage(plugin.getPrefix() + "§cThe first argument has to be numeric!");
return;
}
} else if (args.length > 3 && args[0].equalsIgnoreCase("setmotd")) {
if (checkPermission(sender, "setmotd")) return;
if (!isNumeric(args[1])) {
sender.sendMessage(plugin.getPrefix() + "§cThe first argument has to be the motd index!");
return;
}
final int line = Integer.parseInt(args[1]);
if (line < 1 || line > 2) {
sender.sendMessage(plugin.getPrefix() + "§cThe first argument has to be a 1 or a 2!");
return;
}
final int index = Integer.parseInt(args[1]);
if (index < 1 || index > settings.getPingMessages().size() + 1) {
sender.sendMessage(plugin.getPrefix() + "§cYou currently have " + settings.getPingMessages().size()
+ " motds, so you have to pick a number between 1 and " + (settings.getPingMessages().size() + 1));
return;
}
final String message = getColoredString(String.join(" ", Arrays.copyOfRange(args, 2, args.length)));
final String oldMessage = settings.getConfigString("pingmessage");
final String newMessage;
if (line == 1)
newMessage = oldMessage.contains("%NEWLINE%") ?
message + "%NEWLINE%" + oldMessage.split("%NEWLINE%", 2)[1] : message;
else
newMessage = oldMessage.contains("%NEWLINE%") ?
oldMessage.split("%NEWLINE%", 2)[0] + "%NEWLINE%" + message : oldMessage + "%NEWLINE%" + message;
if (!isNumeric(args[2])) {
sender.sendMessage(plugin.getPrefix() + "§cThe second argument has to be the line number (1 or 2)!");
return;
}
settings.setToConfig("pingmessage", newMessage);
settings.saveConfig();
settings.reloadConfigs();
sender.sendMessage(plugin.getPrefix() + "§aSet line " + line + " of the maintenance motd to §f" + message);
} else
sendUsage(sender);
final int line = Integer.parseInt(args[2]);
if (line != 1 && line != 2) {
sender.sendMessage(plugin.getPrefix() + "§cThe second argument has to be the line number (1 or 2)!");
return;
}
final String message = String.join(" ", Arrays.copyOfRange(args, 3, args.length));
final String oldMessage = index > settings.getPingMessages().size() ? "" : settings.getPingMessages().get(index - 1);
final String newMessage;
if (line == 1)
newMessage = oldMessage.contains("%NEWLINE%") ?
message + "%NEWLINE%" + oldMessage.split("%NEWLINE%", 2)[1] : message;
else
newMessage = oldMessage.contains("%NEWLINE%") ?
oldMessage.split("%NEWLINE%", 2)[0] + "%NEWLINE%" + message : oldMessage + "%NEWLINE%" + message;
if (index > settings.getPingMessages().size())
settings.getPingMessages().add(newMessage);
else
settings.getPingMessages().set(index - 1, newMessage);
settings.setToConfig("pingmessages", settings.getPingMessages());
settings.saveConfig();
settings.reloadConfigs();
sender.sendMessage(plugin.getPrefix() + "§aSet line " + line + " of the " + index + ". maintenance motd to §f" + settings.getColoredString(message));
} else
sendUsage(sender);
}
@@ -171,27 +186,54 @@ public abstract class MaintenanceCommand {
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)");
sender.sendMessage("§6/maintenance on §7(Enables maintenance mode");
sender.sendMessage("§6/maintenance off §7(Disables maintenance mode)");
sender.sendMessage("§6/maintenance setmotd <1/2> <message> §7(Sets the motd for 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 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 whitelist §7(Shows all whitelisted players for the maintenance mode)");
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("");
}
private boolean checkPermission(final SenderInfo sender, final String permission) {
if (!sender.hasPermission("maintenance." + permission)) {
sender.sendMessage(settings.getNoPermMessage());
return true;
}
return false;
}
private boolean isNumeric(final String string) {
try {
Integer.parseInt(string);
} catch (final NumberFormatException nfe) {
return false;
}
return true;
}
protected abstract void addPlayerToWhitelist(SenderInfo sender, String name);
protected abstract void removePlayerFromWhitelist(SenderInfo sender, String name);
protected abstract void checkForUpdate(SenderInfo sender);
protected abstract String getColoredString(String message);
}
@@ -0,0 +1,6 @@
package eu.kennytv.maintenance.core.listener;
public interface IPingListener {
boolean loadIcon();
}
@@ -1,13 +0,0 @@
package eu.kennytv.maintenance.core.util;
public final class MessageUtil {
public static boolean isNumeric(final String string) {
try {
Integer.parseInt(string);
} catch (final NumberFormatException nfe) {
return false;
}
return true;
}
}
+1 -1
View File
@@ -6,7 +6,7 @@
<parent>
<artifactId>maintenance-base</artifactId>
<groupId>eu.kennytv</groupId>
<version>2.2.1</version>
<version>2.3.1</version>
</parent>
<artifactId>maintenance-parent</artifactId>
+2 -3
View File
@@ -3,11 +3,10 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>eu.kennytv</groupId>
<artifactId>maintenance-base</artifactId>
<version>2.2.1</version>
<groupId>eu.kennytv</groupId>
<version>2.3.1</version>
</parent>
<artifactId>maintenance-spigot</artifactId>
@@ -1,21 +1,25 @@
package eu.kennytv.maintenance.spigot;
import eu.kennytv.maintenance.api.IMaintenance;
import eu.kennytv.maintenance.api.IMaintenanceBase;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.File;
/**
* @author KennyTV
* @since 2.1
*/
public final class MaintenanceSpigotBase extends JavaPlugin {
public final class MaintenanceSpigotBase extends JavaPlugin implements IMaintenanceBase {
private IMaintenance maintenance;
@Override
public void onEnable() {
new MaintenanceSpigotPlugin(this);
maintenance = new MaintenanceSpigotPlugin(this);
}
File getPluginFile() {
return getFile();
}
@Override
public IMaintenance getApi() {
return maintenance;
}
}
@@ -6,9 +6,7 @@ import eu.kennytv.maintenance.api.MaintenanceSpigotAPI;
import eu.kennytv.maintenance.core.MaintenanceModePlugin;
import eu.kennytv.maintenance.core.hook.ServerListPlusHook;
import eu.kennytv.maintenance.spigot.command.MaintenanceSpigotCommand;
import eu.kennytv.maintenance.spigot.listener.PacketListener;
import eu.kennytv.maintenance.spigot.listener.PlayerLoginListener;
import eu.kennytv.maintenance.spigot.listener.ServerListPingListener;
import eu.kennytv.maintenance.spigot.metrics.MetricsLite;
import net.minecrell.serverlistplus.core.plugin.ServerListPlusPlugin;
import org.bukkit.Server;
@@ -19,20 +17,12 @@ import java.io.File;
/**
* @author KennyTV
* @since 1.0
* @since 2.0
*/
public final class MaintenanceSpigotPlugin extends MaintenanceModePlugin {
private final MaintenanceSpigotBase plugin;
private final SettingsSpigot settings;
// Added "/maintenance setmotd <1/2> <message>" command to edit the maintenance mode motd via a command
// The Bungee version of the plugin will now automatically create a MySQL table if it is enabled, so you won't have to manually create one anymore
// Fixed the ServerListPlus motd only changing on using the command, but not on the server startup
// Fixed an error with canceling the start-/endtimer in the Bungee version
// Fixed an error with removing players from the whitelist in the Spigot version
// Fixed some other minor bugs
// Some internal code cleanup
MaintenanceSpigotPlugin(final MaintenanceSpigotBase plugin) {
super("§8[§eMaintenanceSpigot§8] ", plugin.getDescription().getVersion());
@@ -47,11 +37,6 @@ public final class MaintenanceSpigotPlugin extends MaintenanceModePlugin {
new MetricsLite(plugin);
if (pm.getPlugin("ProtocolLib") != null)
new PacketListener(this, plugin, settings);
else
pm.registerEvents(new ServerListPingListener(plugin, settings), plugin);
// ServerListPlus integration
final Plugin serverListPlus = pm.getPlugin("ServerListPlus");
if (serverListPlus != null) {
@@ -83,11 +68,6 @@ public final class MaintenanceSpigotPlugin extends MaintenanceModePlugin {
getServer().broadcastMessage(settings.getMaintenanceDeactivated());
}
@Override
public boolean isMaintenance() {
return settings.isMaintenance();
}
@Override
public int schedule(final Runnable runnable) {
return getServer().getScheduler().scheduleSyncRepeatingTask(plugin, runnable, 0, 1200);
@@ -1,22 +1,38 @@
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.ServerListPingListener;
import org.bukkit.ChatColor;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.PluginManager;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.List;
import java.util.UUID;
public final class SettingsSpigot extends Settings {
private final MaintenanceSpigotBase plugin;
private final IPingListener pingListener;
private FileConfiguration config;
private FileConfiguration whitelist;
SettingsSpigot(final MaintenanceSpigotBase plugin) {
this.plugin = plugin;
final PluginManager pm = plugin.getServer().getPluginManager();
if (pm.getPlugin("ProtocolLib") != null) {
pingListener = new PacketListener(plugin, this);
} else {
final ServerListPingListener listener = new ServerListPingListener(plugin, this);
pm.registerEvents(listener, plugin);
pingListener = listener;
}
createFiles();
reloadConfigs();
}
@@ -43,7 +59,7 @@ public final class SettingsSpigot extends Settings {
public void reloadConfigs() {
final File file = new File(plugin.getDataFolder(), "spigot-config.yml");
try {
config = YamlConfiguration.loadConfiguration(new InputStreamReader(new FileInputStream(file), "UTF8"));
config = YamlConfiguration.loadConfiguration(new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8));
whitelist = YamlConfiguration.loadConfiguration(new File(plugin.getDataFolder(), "WhitelistedPlayers.yml"));
} catch (final IOException e) {
throw new RuntimeException("Unable to load spigot-config.yml!", e);
@@ -90,7 +106,12 @@ public final class SettingsSpigot extends Settings {
@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
@@ -99,12 +120,32 @@ public final class SettingsSpigot extends Settings {
}
@Override
public List<Integer> getBroadcastIntervallList() {
return config.getIntegerList("timer-broadcasts-for-minutes");
public List<Integer> getConfigIntList(final String path) {
return config.getIntegerList(path);
}
@Override
public List<String> getConfigList(final String path) {
return config.getStringList(path);
}
@Override
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 reloadMaintenanceIcon() {
return pingListener.loadIcon();
}
}
@@ -6,7 +6,6 @@ import eu.kennytv.maintenance.spigot.MaintenanceSpigotPlugin;
import eu.kennytv.maintenance.spigot.SettingsSpigot;
import eu.kennytv.maintenance.spigot.util.BukkitSenderInfo;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
@@ -77,9 +76,4 @@ public final class MaintenanceSpigotCommand extends MaintenanceCommand implement
} else
sender.sendMessage(plugin.getPrefix() + "§aYou already have the latest version of the plugin!");
}
@Override
protected String getColoredString(final String message) {
return ChatColor.translateAlternateColorCodes('&', message);
}
}
@@ -8,8 +8,8 @@ import com.comphenix.protocol.events.PacketEvent;
import com.comphenix.protocol.wrappers.WrappedGameProfile;
import com.comphenix.protocol.wrappers.WrappedServerPing;
import com.google.common.collect.Lists;
import eu.kennytv.maintenance.core.listener.IPingListener;
import eu.kennytv.maintenance.spigot.MaintenanceSpigotBase;
import eu.kennytv.maintenance.spigot.MaintenanceSpigotPlugin;
import eu.kennytv.maintenance.spigot.SettingsSpigot;
import javax.imageio.ImageIO;
@@ -17,21 +17,21 @@ import java.io.File;
import java.util.List;
import java.util.UUID;
public final class PacketListener {
private final File icon;
public final class PacketListener implements IPingListener {
private final MaintenanceSpigotBase pl;
private WrappedServerPing.CompressedImage image;
public PacketListener(final MaintenanceSpigotPlugin pl, final MaintenanceSpigotBase base, final SettingsSpigot settings) {
icon = new File("maintenance-icon.png");
public PacketListener(final MaintenanceSpigotBase base, final SettingsSpigot settings) {
this.pl = base;
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(base, ListenerPriority.HIGHEST,
PacketType.Status.Server.OUT_SERVER_INFO) {
PacketType.Status.Server.SERVER_INFO) {
@Override
public void onPacketSending(final PacketEvent event) {
if (!pl.isMaintenance()) return;
if (!settings.isMaintenance()) return;
final WrappedServerPing ping = event.getPacket().getServerPings().read(0);
ping.setVersionProtocol(0);
ping.setMotD(settings.getPingMessage().replace("%NEWLINE%", "\n"));
ping.setMotD(settings.getRandomPingMessage());
ping.setVersionName(settings.getPlayerCountMessage());
final List<WrappedGameProfile> players = Lists.newArrayList();
@@ -39,17 +39,20 @@ public final class PacketListener {
players.add(new WrappedGameProfile(UUID.randomUUID(), string));
ping.setPlayers(players);
if (!settings.hasCustomIcon()) return;
if (image != null) {
if (settings.hasCustomIcon() && image != null)
ping.setFavicon(image);
return;
}
try {
image = WrappedServerPing.CompressedImage.fromPng(ImageIO.read(icon));
} catch (final Exception e) {
pl.getServer().getLogger().warning("§4Could not load 'maintenance-icon.png' - did you create one in your Spigot/Bukkit folder (not the plugins folder)?");
}
}
});
}
@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)?");
return false;
}
return true;
}
}
@@ -1,8 +1,8 @@
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.Bukkit;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
@@ -12,16 +12,14 @@ import org.bukkit.util.CachedServerIcon;
import javax.imageio.ImageIO;
import java.io.File;
public final class ServerListPingListener implements Listener {
public final class ServerListPingListener implements Listener, IPingListener {
private final MaintenanceSpigotBase plugin;
private final SettingsSpigot settings;
private final File icon;
private CachedServerIcon serverIcon;
public ServerListPingListener(final MaintenanceSpigotBase plugin, final SettingsSpigot settings) {
this.plugin = plugin;
this.settings = settings;
icon = new File("maintenance-icon.png");
}
@EventHandler(priority = EventPriority.HIGHEST)
@@ -29,18 +27,20 @@ public final class ServerListPingListener implements Listener {
if (!settings.isMaintenance()) return;
event.setMaxPlayers(0);
event.setMotd(settings.getPingMessage().replace("%NEWLINE%", "\n"));
event.setMotd(settings.getRandomPingMessage());
if (settings.hasCustomIcon()) {
if (serverIcon != null)
event.setServerIcon(serverIcon);
else {
try {
serverIcon = Bukkit.loadServerIcon(ImageIO.read(icon));
} catch (final Exception e) {
plugin.getLogger().warning("§4Could not load 'maintenance-icon.png' - did you create one in your Spigot/Bukkit folder (not the plugins folder)?");
}
}
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;
}
}
@@ -17,6 +17,7 @@ import java.io.IOException;
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;
@@ -227,7 +228,7 @@ public final class MetricsLite {
}
final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
final GZIPOutputStream gzip = new GZIPOutputStream(outputStream);
gzip.write(str.getBytes("UTF-8"));
gzip.write(str.getBytes(StandardCharsets.UTF_8));
gzip.close();
return outputStream.toByteArray();
}
@@ -5,7 +5,10 @@
enable-maintenance-mode: false
# The message shown in the multiplayer server list motd.
pingmessage: "&cMaintenance mode!%NEWLINE%&6We will be back soon!"
# If you put in multiple entries, one of them will be chosen randomly on every ping.
pingmessages:
- "&cMaintenance mode!%NEWLINE%&6We will be back soon!"
#- "Another entry"
# Is shown at the top right corner of the server in the serverlist,
# where the playercount would normally be displayed.
+3 -3
View File
@@ -6,9 +6,9 @@
<groupId>eu.kennytv</groupId>
<artifactId>maintenance-base</artifactId>
<packaging>pom</packaging>
<version>2.2.1</version>
<version>2.3.1</version>
<name>Maintenance</name>
<packaging>pom</packaging>
<modules>
<module>maintenance-parent</module>
@@ -31,7 +31,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.1.0</version>
<version>3.1.1</version>
<executions>
<execution>
<phase>package</phase>