Skip to content

Commit

Permalink
2.5 Release
Browse files Browse the repository at this point in the history
  • Loading branch information
kennytv authored Nov 17, 2018
2 parents b29462a + 7384b2e commit 3b4a66b
Show file tree
Hide file tree
Showing 36 changed files with 890 additions and 211 deletions.
Binary file modified Maintenance-API.jar
Binary file not shown.
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.4</version>
<version>2.5</version>
</parent>

<artifactId>maintenance-api</artifactId>
Expand All @@ -22,7 +22,7 @@
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.12.2-R0.1-SNAPSHOT</version>
<version>1.13.2-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package eu.kennytv.maintenance.api.bungee;

import eu.kennytv.maintenance.api.IMaintenance;
import net.md_5.bungee.api.config.ServerInfo;

/**
* @author KennyTV
* @since 2.5
*/
public interface IMaintenanceBungee extends IMaintenance {

/**
* Enables/disables maintenance mode on a proxied server.
* If enabled, all non-permitted players will be kicked.
* If MySQL is enabled, it will also be written into the database.
*
* @param maintenance true to enable, false to disable maintenance mode
*/
boolean setMaintenanceToServer(ServerInfo server, boolean maintenance);

/**
* @return true if maintenance is currently enabled on the proxied server
*/
boolean isMaintenance(ServerInfo server);

/**
* @return true if a start- or endtimer task is currently running regarding the proxied server
*/
boolean isServerTaskRunning(ServerInfo server);
}
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
package eu.kennytv.maintenance.api;
package eu.kennytv.maintenance.api.bungee;

import eu.kennytv.maintenance.api.IMaintenanceBase;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.plugin.Plugin;

/**
* Utility class to get the {@link IMaintenance} instance for the BungeeCord version of the plugin.
* Utility class to get the {@link IMaintenanceBungee} instance for the BungeeCord version of the plugin.
* <p>
* Only access this class if you're running the plugin on a BungeeCord server!
* </p>
*
* @author KennyTV
* @since 2.1
* @since 2.5
*/
public final class MaintenanceBungeeAPI {

/**
* Returns API instance of IMaintenance.
*
* @return {@link IMaintenance} instance
* @return {@link IMaintenanceBungee} instance
*/
public static IMaintenance getAPI() {
public static IMaintenanceBungee getAPI() {
final Plugin maintenance = ProxyServer.getInstance().getPluginManager().getPlugin("MaintenanceBungee");
if (maintenance == null)
ProxyServer.getInstance().getLogger().warning("Could not get instance of MaintenanceBungee!");

return ((IMaintenanceBase) maintenance).getApi();
return (IMaintenanceBungee) ((IMaintenanceBase) maintenance).getApi();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package eu.kennytv.maintenance.api;
package eu.kennytv.maintenance.api.spigot;

import eu.kennytv.maintenance.api.IMaintenance;
import eu.kennytv.maintenance.api.IMaintenanceBase;
import org.bukkit.Bukkit;
import org.bukkit.plugin.Plugin;

Expand All @@ -10,7 +12,7 @@
* </p>
*
* @author KennyTV
* @since 2.1
* @since 2.5
*/
public final class MaintenanceSpigotAPI {

Expand All @@ -23,7 +25,6 @@ public static IMaintenance getAPI() {
final Plugin maintenance = Bukkit.getPluginManager().getPlugin("MaintenanceSpigot");
if (maintenance == null)
Bukkit.getLogger().warning("Could not get instance of MaintenanceSpigot!");

return ((IMaintenanceBase) maintenance).getApi();
}
}
2 changes: 1 addition & 1 deletion 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.4</version>
<version>2.5</version>
</parent>

<artifactId>maintenance-bungee</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,52 @@

import eu.kennytv.maintenance.api.IMaintenance;
import eu.kennytv.maintenance.api.ISettings;
import eu.kennytv.maintenance.api.MaintenanceBungeeAPI;
import eu.kennytv.maintenance.api.bungee.IMaintenanceBungee;
import eu.kennytv.maintenance.api.bungee.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.ServerConnectListener;
import eu.kennytv.maintenance.bungee.metrics.MetricsLite;
import eu.kennytv.maintenance.bungee.runnable.SingleMaintenanceRunnable;
import eu.kennytv.maintenance.core.MaintenanceModePlugin;
import eu.kennytv.maintenance.core.Settings;
import eu.kennytv.maintenance.core.hook.ServerListPlusHook;
import eu.kennytv.maintenance.core.runnable.MaintenanceRunnableBase;
import eu.kennytv.maintenance.core.util.ServerType;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.config.ServerInfo;
import net.md_5.bungee.api.plugin.Plugin;
import net.md_5.bungee.api.plugin.PluginManager;
import net.minecrell.serverlistplus.core.plugin.ServerListPlusPlugin;

import java.io.File;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.logging.Logger;

/**
* @author KennyTV
* @since 1.0
*/
public final class MaintenanceBungeePlugin extends MaintenanceModePlugin {
public final class MaintenanceBungeePlugin extends MaintenanceModePlugin implements IMaintenanceBungee {
private final MaintenanceBungeeBase plugin;
private final SettingsBungee settings;
private final Map<String, Integer> serverTaskIds = new HashMap<>();

MaintenanceBungeePlugin(final MaintenanceBungeeBase plugin) {
super("§8[§eMaintenanceBungee§8] ", plugin.getDescription().getVersion());
super("§8[§eMaintenanceBungee§8] ", plugin.getDescription().getVersion(), ServerType.BUNGEE);

this.plugin = plugin;
plugin.getLogger().info("Plugin by KennyTV");
plugin.getLogger().info(getUpdateMessage());

settings = new SettingsBungee(this, plugin);

final PluginManager pm = getProxy().getPluginManager();
pm.registerListener(plugin, new PostLoginListener(this, settings));
pm.registerListener(plugin, new ServerConnectListener(this, settings));
final MaintenanceBungeeCommand maintenanceCommand = new MaintenanceBungeeCommand(this, settings);
pm.registerCommand(plugin, new MaintenanceBungeeCommandBase(maintenanceCommand));

Expand All @@ -61,7 +74,6 @@ public void setMaintenance(final boolean maintenance) {
}

serverActions(maintenance);

if (isTaskRunning())
cancelTask();
}
Expand All @@ -80,10 +92,63 @@ void serverActions(final boolean maintenance) {
}

@Override
public int startMaintenanceRunnable(final Runnable runnable) {
public boolean isMaintenance(final ServerInfo server) {
return settings.getMaintenanceServers().contains(server.getName());
}

@Override
public boolean setMaintenanceToServer(final ServerInfo server, final boolean maintenance) {
if (maintenance) {
if (!settings.getMaintenanceServers().add(server.getName())) return false;

final ServerInfo fallback = getProxy().getServerInfo(settings.getFallbackServer());
if (fallback == null)
plugin.getLogger().warning("The fallback server set in the SpigotServers.yml could not be found! Instead kicking players from that server off the network!");
else if (fallback.equals(server))
plugin.getLogger().warning("Maintenance has been enabled on the fallback server! If a player joins on a proxied server, they will be kicked completely instead of being sent to the fallback server!");
server.getPlayers().forEach(p -> {
if (!p.hasPermission("maintenance.bypass") && !settings.getWhitelistedPlayers().containsKey(p.getUniqueId())) {
if (fallback != null && fallback.canAccess(p)) {
p.sendMessage(settings.getMessage("singleMaintenanceActivated").replace("%SERVER%", server.getName()));
p.connect(fallback);
} else
p.disconnect(settings.getMessage("singleMaintenanceKickComplete").replace("%NEWLINE%", "\n").replace("%SERVER%", server.getName()));
} else {
p.sendMessage(settings.getMessage("singleMaintenanceActivated").replace("%SERVER%", server.getName()));
}
});
} else {
if (!settings.getMaintenanceServers().remove(server.getName())) return false;
server.getPlayers().forEach(p -> p.sendMessage(settings.getMessage("singleMaintenanceDeactivated").replace("%SERVER%", server.getName())));
}

/*if (mySQL != null) {
mySQL.executeUpdate(serversQuery, "spigotServers-with-maintenance", maintenanceServers, maintenanceServers);
} else {
spigotServers.set("maintenance-on", maintenanceServers);
saveSpigotServers();
}*/
cancelSingleTask(server);
settings.saveServersToConfig();
return true;
}

@Override
public boolean isServerTaskRunning(final ServerInfo server) {
return serverTaskIds.containsKey(server.getName());
}

@Override
protected int startMaintenanceRunnable(final Runnable runnable) {
return getProxy().getScheduler().schedule(plugin, runnable, 0, 1, TimeUnit.SECONDS).getId();
}

public MaintenanceRunnableBase startSingleMaintenanceRunnable(final ServerInfo server, final int minutes, final boolean enable) {
final MaintenanceRunnableBase runnable = new SingleMaintenanceRunnable(this, (Settings) getSettings(), minutes, enable, server);
serverTaskIds.put(server.getName(), getProxy().getScheduler().schedule(plugin, runnable, 0, 1, TimeUnit.SECONDS).getId());
return runnable;
}

@Override
public void async(final Runnable runnable) {
getProxy().getScheduler().runAsync(plugin, runnable);
Expand All @@ -96,6 +161,12 @@ public void cancelTask() {
taskId = 0;
}

public void cancelSingleTask(final ServerInfo server) {
final Integer task = serverTaskIds.remove(server.getName());
if (task != null)
getProxy().getScheduler().cancel(task);
}

@Override
public ISettings getSettings() {
return settings;
Expand All @@ -119,4 +190,8 @@ public static IMaintenance getAPI() {
public ProxyServer getProxy() {
return plugin.getProxy();
}

public Logger getLogger() {
return plugin.getLogger();
}
}
Loading

0 comments on commit 3b4a66b

Please sign in to comment.