Skip to content

Commit

Permalink
Add LockDownCommands to Redis Branch
Browse files Browse the repository at this point in the history
*Add LockDown
*Add LockDownStatus
*Add LockDownEnd
  • Loading branch information
Narimm committed Feb 9, 2016
1 parent 1db4c79 commit a51d0c0
Show file tree
Hide file tree
Showing 8 changed files with 407 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*/

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="/<command> <time> [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="/<command>")
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="/<command>")
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());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
14 changes: 7 additions & 7 deletions bungee/src/main/java/net/cubespace/geSuit/geSuitPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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();
Expand All @@ -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);
Expand All @@ -302,6 +301,7 @@ private void initializeAddons() {
spawns.loadSpawns();
geoIpLookup.initialize();
mutes.startMuteCheckTimer(this);
lockdowns.initialize();
}

public void loadLanguage() {
Expand Down
Original file line number Diff line number Diff line change
@@ -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());
}
}
}

}
Original file line number Diff line number Diff line change
@@ -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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, CommandBuilder> builders;
private Set<String> registered;

Expand Down
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*/

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);
}
Loading

0 comments on commit a51d0c0

Please sign in to comment.