mirror of
https://github.com/kennytv/Maintenance.git
synced 2026-11-04 16:50:07 -05:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b30476ae3f | ||
|
|
9d417a12f1 | ||
|
|
fd5406b95d | ||
|
|
0ef59e557d | ||
|
|
15ed1db347 | ||
|
|
429d5b90d4 | ||
|
|
b3ab931aca | ||
|
|
21b42d0c72 | ||
|
|
7b1e1a27ba | ||
|
|
fb7b1e791f |
No files matched your search
Binary file not shown.
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<artifactId>maintenance-base</artifactId>
|
||||
<groupId>eu.kennytv</groupId>
|
||||
<version>2.2.1</version>
|
||||
<version>2.2.2</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>maintenance-api</artifactId>
|
||||
@@ -22,7 +22,7 @@
|
||||
<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,7 +19,7 @@ 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();
|
||||
|
||||
@@ -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,14 @@ 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
|
||||
* @return true if maintenance is currently enabled
|
||||
*/
|
||||
boolean isMaintenance();
|
||||
|
||||
@@ -21,9 +25,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();
|
||||
|
||||
@@ -40,7 +42,8 @@ public interface ISettings {
|
||||
*
|
||||
* @param name name of the player to remove in lowercase letters
|
||||
* @return true if removing the player was successful
|
||||
* @deprecated if a player changes their name, the list will still contain their 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);
|
||||
@@ -53,4 +56,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();
|
||||
}
|
||||
@@ -10,7 +10,7 @@ import net.md_5.bungee.api.plugin.Plugin;
|
||||
* </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();
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,7 @@ import org.bukkit.plugin.Plugin;
|
||||
* </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();
|
||||
}
|
||||
}
|
||||
@@ -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.2.2</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>maintenance-bungee</artifactId>
|
||||
|
||||
+10
-6
@@ -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() {
|
||||
|
||||
-7
@@ -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,8 +1,11 @@
|
||||
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;
|
||||
|
||||
@@ -18,11 +21,18 @@ public final class SettingsBungee extends Settings {
|
||||
private final MySQL mySQL;
|
||||
|
||||
private final MaintenanceBungeeBase plugin;
|
||||
private final IPingListener pingListener;
|
||||
private Configuration config;
|
||||
private Configuration whitelist;
|
||||
|
||||
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");
|
||||
@@ -165,6 +175,11 @@ public final class SettingsBungee extends Settings {
|
||||
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);
|
||||
|
||||
+14
-13
@@ -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)
|
||||
@@ -36,16 +35,18 @@ public final class ProxyPingListener implements Listener {
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -38,7 +38,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
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<artifactId>maintenance-base</artifactId>
|
||||
<groupId>eu.kennytv</groupId>
|
||||
<version>2.2.1</version>
|
||||
<version>2.2.2</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>maintenance-core</artifactId>
|
||||
|
||||
@@ -16,11 +16,21 @@ public abstract class MaintenanceModePlugin implements IMaintenance {
|
||||
private final String prefix;
|
||||
private String newestVersion;
|
||||
|
||||
// Changed the loading of the maintenance icon to be more predictable
|
||||
// It will load directly on startup and can now reloaded by using the "/maintenance reload" command as well
|
||||
// Changed the reload message to read the proper changes
|
||||
// API fix
|
||||
|
||||
protected MaintenanceModePlugin(final String prefix, final String version) {
|
||||
this.prefix = prefix;
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isMaintenance() {
|
||||
return getSettings().isMaintenance();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getVersion() {
|
||||
return version;
|
||||
|
||||
@@ -41,6 +41,8 @@ public abstract class Settings implements ISettings {
|
||||
broadcastIntervalls = Sets.newHashSet(getBroadcastIntervallList());
|
||||
playerCountMessage = getConfigString("playercountmessage");
|
||||
playerCountHoverMessage = getConfigString("playercounthovermessage");
|
||||
if (hasCustomIcon())
|
||||
reloadMaintenanceIcon();
|
||||
|
||||
loadExtraSettings();
|
||||
}
|
||||
|
||||
+1
-1
@@ -39,7 +39,7 @@ public abstract class MaintenanceCommand {
|
||||
}
|
||||
|
||||
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());
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
package eu.kennytv.maintenance.core.listener;
|
||||
|
||||
public interface IPingListener {
|
||||
|
||||
boolean loadIcon();
|
||||
}
|
||||
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<artifactId>maintenance-base</artifactId>
|
||||
<groupId>eu.kennytv</groupId>
|
||||
<version>2.2.1</version>
|
||||
<version>2.2.2</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>maintenance-parent</artifactId>
|
||||
|
||||
@@ -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.2.2</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>maintenance-spigot</artifactId>
|
||||
|
||||
+10
-6
@@ -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;
|
||||
}
|
||||
}
|
||||
+5
-21
@@ -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);
|
||||
@@ -124,6 +104,10 @@ public final class MaintenanceSpigotPlugin extends MaintenanceModePlugin {
|
||||
return MaintenanceSpigotAPI.getAPI();
|
||||
}
|
||||
|
||||
public MaintenanceSpigotBase getBase() {
|
||||
return plugin;
|
||||
}
|
||||
|
||||
public Server getServer() {
|
||||
return plugin.getServer();
|
||||
}
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
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.file.Files;
|
||||
@@ -12,11 +16,22 @@ 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();
|
||||
}
|
||||
@@ -107,4 +122,9 @@ public final class SettingsSpigot extends Settings {
|
||||
public void setToConfig(final String path, final Object var) {
|
||||
config.set(path, var);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean reloadMaintenanceIcon() {
|
||||
return pingListener.loadIcon();
|
||||
}
|
||||
}
|
||||
+18
-15
@@ -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,17 +17,17 @@ 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) {
|
||||
@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);
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
+14
-13
@@ -1,5 +1,6 @@
|
||||
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;
|
||||
@@ -12,16 +13,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)
|
||||
@@ -31,16 +30,18 @@ public final class ServerListPingListener implements Listener {
|
||||
event.setMaxPlayers(0);
|
||||
event.setMotd(settings.getPingMessage().replace("%NEWLINE%", "\n"));
|
||||
|
||||
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 = Bukkit.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;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user