diff --git a/bungee/src/main/java/net/cubespace/geSuit/commands/LockDownCommands.java b/bungee/src/main/java/net/cubespace/geSuit/commands/LockDownCommands.java
new file mode 100644
index 00000000..71ca1d30
--- /dev/null
+++ b/bungee/src/main/java/net/cubespace/geSuit/commands/LockDownCommands.java
@@ -0,0 +1,76 @@
+/*
+ * Copyright 2016 AddstarMC
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+package net.cubespace.geSuit.commands;
+
+import net.cubespace.geSuit.core.commands.Command;
+import net.cubespace.geSuit.core.commands.CommandPriority;
+import net.cubespace.geSuit.core.commands.Optional;
+import net.cubespace.geSuit.core.commands.Varargs;
+import net.cubespace.geSuit.core.objects.DateDiff;
+import net.cubespace.geSuit.core.objects.Result;
+import net.cubespace.geSuit.remote.moderation.LockDownActions;
+import net.md_5.bungee.api.ChatColor;
+import net.md_5.bungee.api.CommandSender;
+import net.md_5.bungee.api.connection.ProxiedPlayer;
+
+/**
+ * Created by Narimm on 6/02/2016.
+ */
+@SuppressWarnings("deprecation")
+public class LockDownCommands {
+ private LockDownActions actions;
+
+
+ public LockDownCommands(LockDownActions actions) {
+ this.actions = actions;
+ }
+
+ @Command(name="!LockDown", permission="gesuit.lockdown.command.lockdown", usage="/ [reason]")
+ public void lockdown(CommandSender sender, DateDiff time, @Optional @Varargs String reason){
+ if (sender instanceof ProxiedPlayer) {
+ sender.sendMessage(ChatColor.RED + "Please use the version of this command without the !");
+ return;
+ }
+ Result result = actions.lockdown(sender.getName(),null,reason,time.fromNow());
+ if (result.getMessage() != null) {
+ sender.sendMessage(result.getMessage());
+ }
+ }
+ @Command(name="!LockDownStatus", permission = "gesuit.lockdown.command.status", usage="/")
+ public void lockDownStatus(CommandSender sender) {
+ if (sender instanceof ProxiedPlayer) {
+ sender.sendMessage(ChatColor.RED + "Please use the version of this command without the !");
+ return;
+ }
+ Result result = actions.status(sender.getName());
+ if (result.getMessage() != null) {
+ sender.sendMessage(result.getMessage());
+ }
+ }
+
+ @Command(name="!LockDownEnd", permission = "gesuit.lockdown.command.end", usage="/")
+ public void LockDownEnd(CommandSender sender) {
+ if (sender instanceof ProxiedPlayer) {
+ sender.sendMessage(ChatColor.RED + "Please use the version of this command without the !");
+ return;
+ }
+ Result result = actions.unLock(sender.getName());
+ if (result.getMessage() != null) {
+ sender.sendMessage(result.getMessage());
+ }
+ }
+}
diff --git a/bungee/src/main/java/net/cubespace/geSuit/config/ModerationConfig.java b/bungee/src/main/java/net/cubespace/geSuit/config/ModerationConfig.java
index a964397d..98e418c9 100644
--- a/bungee/src/main/java/net/cubespace/geSuit/config/ModerationConfig.java
+++ b/bungee/src/main/java/net/cubespace/geSuit/config/ModerationConfig.java
@@ -24,6 +24,12 @@ public ModerationConfig(File file) {
public Boolean TrackOnTime = true;
public int NameChangeNotifyTime = 20;
+ public String LockdownTime = "5m";
+ @Comment("if set to true the server will start lockedDown and will release in 5minutes")
+ public boolean LockedDown = false;
+ @Comment("if set and no message is set when the lockdown is started this will be used")
+ public String LockDownStartupMsg = "";
+
public int WarningExpiryDays = 180;
public String DefaultBanReason = "Unknown";
diff --git a/bungee/src/main/java/net/cubespace/geSuit/geSuitPlugin.java b/bungee/src/main/java/net/cubespace/geSuit/geSuitPlugin.java
index 01c7d6ae..0427b2f4 100644
--- a/bungee/src/main/java/net/cubespace/geSuit/geSuitPlugin.java
+++ b/bungee/src/main/java/net/cubespace/geSuit/geSuitPlugin.java
@@ -44,13 +44,7 @@
import net.cubespace.geSuit.database.DatabaseManager;
import net.cubespace.geSuit.general.BroadcastManager;
import net.cubespace.geSuit.general.GeoIPLookup;
-import net.cubespace.geSuit.moderation.BanListener;
-import net.cubespace.geSuit.moderation.BanManager;
-import net.cubespace.geSuit.moderation.MuteListener;
-import net.cubespace.geSuit.moderation.MuteManager;
-import net.cubespace.geSuit.moderation.TrackingListener;
-import net.cubespace.geSuit.moderation.TrackingManager;
-import net.cubespace.geSuit.moderation.WarningsManager;
+import net.cubespace.geSuit.moderation.*;
import net.cubespace.geSuit.remote.moderation.BanActions;
import net.cubespace.geSuit.remote.moderation.MuteActions;
import net.cubespace.geSuit.remote.moderation.TrackingActions;
@@ -87,6 +81,7 @@ public class geSuitPlugin extends Plugin implements ConnectionNotifier {
private SpawnManager spawns;
private WarpManager warps;
private MuteManager mutes;
+ private LockdownManager lockdowns;
public void onEnable() {
geSuit.setPlugin(this);
@@ -153,6 +148,7 @@ public void onEnable() {
getProxy().getPluginManager().registerListener(this, new TrackingListener(tracking, globalManager.getMessages(), getLogger()));
getProxy().getPluginManager().registerListener(this, new BanListener(bans, getLogger()));
getProxy().getPluginManager().registerListener(this, new MuteListener(mutes));
+ getProxy().getPluginManager().registerListener(this, new LockdownListener(lockdowns, getLogger()));
globalManager.broadcastNetworkUpdate();
}
@@ -269,6 +265,8 @@ private void initializeAddons() {
warnings = new WarningsManager(databaseManager.getWarnHistory(), bans, mutes, broadcastManager, moderationChannel, getLogger());
tracking = new TrackingManager(databaseManager.getTracking(), databaseManager.getOntime(), getLogger());
teleports = new TeleportsManager(teleportsChannel, this);
+ lockdowns = new LockdownManager(Global.getPlatform().getLogger());
+
// Register them
RemoteManager manager = Global.getRemoteManager();
@@ -291,6 +289,7 @@ private void initializeAddons() {
warnings.loadConfig(configManager.moderation());
mutes.loadConfig(configManager.moderation());
teleports.loadConfig(configManager.teleports());
+ lockdowns.loadConfig(configManager.moderation());
broadcastManager.loadConfig(configManager.broadcasts());
configManager.addReloadListener(bans);
configManager.addReloadListener(tracking);
@@ -302,6 +301,7 @@ private void initializeAddons() {
spawns.loadSpawns();
geoIpLookup.initialize();
mutes.startMuteCheckTimer(this);
+ lockdowns.initialize();
}
public void loadLanguage() {
diff --git a/bungee/src/main/java/net/cubespace/geSuit/moderation/LockdownListener.java b/bungee/src/main/java/net/cubespace/geSuit/moderation/LockdownListener.java
new file mode 100644
index 00000000..466e195d
--- /dev/null
+++ b/bungee/src/main/java/net/cubespace/geSuit/moderation/LockdownListener.java
@@ -0,0 +1,39 @@
+package net.cubespace.geSuit.moderation;
+
+
+import net.cubespace.geSuit.core.util.Utilities;
+import net.cubespace.geSuit.events.GlobalPlayerPreLoginEvent;
+import net.md_5.bungee.api.plugin.Listener;
+import net.md_5.bungee.event.EventHandler;
+import net.md_5.bungee.event.EventPriority;
+
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Created for use for the Add5tar MC Minecraft server
+ * Created by Narimm on 6/02/2016.
+ */
+public class LockdownListener implements Listener {
+ private final LockdownManager manager;
+ private final Logger logger;
+
+ public LockdownListener(LockdownManager man, Logger logger) {
+ manager = man;
+ this.logger = logger;
+ }
+
+ @EventHandler(priority = EventPriority.LOWEST)
+ public void doLockDownCheck(GlobalPlayerPreLoginEvent event) {
+ if (manager.checkExpiry()) {
+ //dont do anything lockdown expired
+ } else {
+ if (event.getPlayer().isNewPlayer()) {
+ event.setCancelled(true);
+ event.denyLogin(manager.denyMessage());
+ logger.log(Level.INFO, event.getPlayer().getName() + "(" + Utilities.toString(event.getPlayer().getUniqueId()) + ") login denied due to lockdown Expiry in" + manager.getExpiryIn());
+ }
+ }
+ }
+
+}
diff --git a/bungee/src/main/java/net/cubespace/geSuit/moderation/LockdownManager.java b/bungee/src/main/java/net/cubespace/geSuit/moderation/LockdownManager.java
new file mode 100644
index 00000000..e7177b92
--- /dev/null
+++ b/bungee/src/main/java/net/cubespace/geSuit/moderation/LockdownManager.java
@@ -0,0 +1,161 @@
+package net.cubespace.geSuit.moderation;
+
+import net.cubespace.geSuit.config.ConfigManager;
+import net.cubespace.geSuit.config.ConfigReloadListener;
+import net.cubespace.geSuit.config.ModerationConfig;
+import net.cubespace.geSuit.core.objects.DateDiff;
+import net.cubespace.geSuit.core.objects.Result;
+import net.cubespace.geSuit.core.objects.Result.Type;
+import net.cubespace.geSuit.remote.moderation.LockDownActions;
+
+import java.util.UUID;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Created for use for the Add5tar MC Minecraft server
+ * Created by Narimm on 6/02/2016.
+ */
+public class LockdownManager implements LockDownActions, ConfigReloadListener {
+
+ private boolean lockedDown = false;
+ private long expiryTime = 0; //The expiry time in Millisecs
+ private String optionalMessage = "";
+ private ModerationConfig config;
+ private final Logger logger;
+
+ public LockdownManager(Logger logger) {
+ this.logger = logger;
+ this.expiryTime = 0;
+ this.optionalMessage = "";
+ this.lockedDown = false;
+ }
+
+ public boolean isLockedDown() {
+ return lockedDown;
+ }
+
+ public void setLockedDown(boolean lockedDown) {
+ this.lockedDown = lockedDown;
+ }
+
+ public long getExpiryTime() {
+ return expiryTime;
+ }
+
+ public String getExpiryTimeString() {
+ return new DateDiff(expiryTime).toString();
+ }
+
+ public String getExpiryIn(){
+ Long cur = System.currentTimeMillis();
+ if (expiryTime>cur){
+ return new DateDiff(expiryTime-cur).toString();
+ }
+ return "0s";
+ }
+
+
+ public void setExpiryTime(long expiryTime) {
+ this.expiryTime = expiryTime;
+ }
+
+ public String getOptionalMessage() {
+ return optionalMessage;
+ }
+
+ public void setOptionalMessage(String optionalMessage) {
+ this.optionalMessage = optionalMessage;
+ }
+
+
+ public void initialize() {
+ this.expiryTime = DateDiff.valueOf(config.LockdownTime).fromNow();
+ setLockedDown(config.LockedDown);
+ setOptionalMessage(config.LockDownStartupMsg);
+ }
+
+ public void loadConfig(ModerationConfig config) {
+ this.config = config;
+
+ }
+
+ private Result startLockDown(String sender, UUID senderID, Long expiryTime, String msg) {
+ setExpiryTime(expiryTime);
+ setOptionalMessage(msg);
+ setLockedDown(true);
+ logger.log(Level.INFO,"Lockdown Started by" + sender+" Ends in"+ getExpiryIn());
+ if (isLockedDown()) {
+ String message = "Server is locked down until: " + getExpiryTimeString();
+ return new Result(Type.Success, message);
+ } else {
+ return new Result(Type.Fail, "Lockdown failed to start");
+ }
+ }
+
+ private Result endLockDown(String sender){
+ setExpiryTime(0);
+ setLockedDown(false);
+ setOptionalMessage(config.LockDownStartupMsg);
+
+ if(isLockedDown()){
+ logger.log(Level.WARNING,"Lockdown was attempted to end by" + sender +" but it is still active");
+ return new Result(Type.Fail,"Lockdown did not end. Critical Error contact Admins");
+ }
+ logger.log(Level.INFO,"Lockdown ended by" + sender);
+ return new Result(Type.Success,"Lockdown has been ended. Time and message reset to default");
+ }
+
+ public boolean checkExpiry() {
+ Result result = checkExpiryResult();
+ if (result.getType() == Type.Fail){
+ logger.log(Level.INFO,result.getMessage());
+ return false;
+ }
+ logger.log(Level.INFO,result.getMessage());
+ return true;
+ }
+
+ public Result checkExpiryResult() {
+ if (isLockedDown()) {
+ if (System.currentTimeMillis() >= getExpiryTime()) {
+ setExpiryTime(0);
+ setLockedDown(false);
+ setOptionalMessage(null);
+ return new Result(Type.Success,"Lockdown has expired automatically, time and message cleared.");
+ } else {
+ return new Result(Type.Fail, "Server is locked down until: " + getExpiryTimeString());
+ }
+ }
+
+ return new Result(Type.Success, "Server is not LockedDown");
+ }
+ public String denyMessage(){
+ if(optionalMessage != null){
+ return getOptionalMessage();
+ }
+ return "Server is undergoing maintenance. Please try again later";
+ }
+
+
+
+ @Override
+ public Result lockdown(String by, UUID byUUID, String reason, long expiryTime) {
+ return startLockDown(by, byUUID, expiryTime, reason);
+ }
+
+ @Override
+ public Result unLock(String sender) {
+ return endLockDown(sender);
+ }
+
+ @Override
+ public Result status(String by) {
+ return checkExpiryResult();
+ }
+
+ @Override
+ public void onConfigReloaded(ConfigManager manager) {
+ loadConfig(manager.moderation());
+ }
+}
diff --git a/common/src/main/java/net/cubespace/geSuit/core/commands/CommandManager.java b/common/src/main/java/net/cubespace/geSuit/core/commands/CommandManager.java
index 60349735..471967b1 100755
--- a/common/src/main/java/net/cubespace/geSuit/core/commands/CommandManager.java
+++ b/common/src/main/java/net/cubespace/geSuit/core/commands/CommandManager.java
@@ -16,7 +16,7 @@
*
* See {@link Command} for a detailed description of how to make the commands
*/
-public abstract class CommandManager {
+public abstract class CommandManager {
private Map builders;
private Set registered;
diff --git a/common/src/main/java/net/cubespace/geSuit/remote/moderation/LockDownActions.java b/common/src/main/java/net/cubespace/geSuit/remote/moderation/LockDownActions.java
new file mode 100644
index 00000000..c30480a3
--- /dev/null
+++ b/common/src/main/java/net/cubespace/geSuit/remote/moderation/LockDownActions.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2016 AddstarMC
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+package net.cubespace.geSuit.remote.moderation;
+
+import net.cubespace.geSuit.core.objects.Result;
+
+import java.util.UUID;
+
+/**
+ * Created for the AddstarMC Project.
+ * Created by Narimm on 6/02/2016.
+ */
+public interface LockDownActions {
+
+ public Result lockdown(String by, UUID byUUID, String reason, long expiryTime);
+
+ public Result unLock(String by);
+
+ public Result status(String by);
+}
diff --git a/modules/moderation/src/main/java/net/cubespace/geSuit/moderation/commands/LockDownCommands.java b/modules/moderation/src/main/java/net/cubespace/geSuit/moderation/commands/LockDownCommands.java
new file mode 100644
index 00000000..74095301
--- /dev/null
+++ b/modules/moderation/src/main/java/net/cubespace/geSuit/moderation/commands/LockDownCommands.java
@@ -0,0 +1,83 @@
+/*
+ * Copyright 2016 AddstarMC
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+package net.cubespace.geSuit.moderation.commands;
+
+import org.bukkit.command.CommandSender;
+
+
+import net.cubespace.geSuit.core.commands.Command;
+import net.cubespace.geSuit.core.commands.Optional;
+import net.cubespace.geSuit.core.commands.Varargs;
+import net.cubespace.geSuit.core.objects.DateDiff;
+import net.cubespace.geSuit.core.objects.Result;
+import net.cubespace.geSuit.remote.moderation.LockDownActions;
+
+/**
+ * Created for the AddstarMC Project.
+ * Created by Narimm on 9/02/2016.
+ */
+
+public class LockDownCommands {
+ private LockDownActions actions;
+
+ public LockDownCommands(LockDownActions actions) {
+ this.actions = actions;
+ }
+
+ /**
+ * Locks the Server Down until a time in the future.
+ *
+ * @param sender
+ * @param time
+ * @param reason
+ */
+ @Command(name = "!LockDown", permission = "gesuit.lockdown.command.lockdown", usage = "/ [reason]")
+ public void lockdown(CommandSender sender, DateDiff time, @Optional @Varargs String reason) {
+ Result result = actions.lockdown(sender.getName(), null, reason, time.fromNow());
+ if (result.getMessage() != null) {
+ sender.sendMessage(result.getMessage());
+ }
+ }
+
+ /**
+ * Checks the status of a lockdown and expires it if required.
+ *
+ * @param sender
+ */
+
+ @Command(name = "!LockDownStatus", permission = "gesuit.lockdown.command.status", usage = "/")
+ public void lockDownStatus(CommandSender sender) {
+ Result result = actions.status(sender.getName());
+ if (result.getMessage() != null) {
+ sender.sendMessage(result.getMessage());
+ }
+ }
+
+ /**
+ * Forces a lockdown to expire
+ *
+ * @param sender
+ */
+ @Command(name = "!LockDownEnd", permission = "gesuit.lockdown.command.end", usage = "/")
+ public void LockDownEnd(CommandSender sender) {
+ Result result = actions.unLock(sender.getName());
+ if (result.getMessage() != null) {
+ sender.sendMessage(result.getMessage());
+ }
+ }
+
+}