forked from Cube-Space/geSuit
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add LockDownCommands to Redis Branch
*Add LockDown *Add LockDownStatus *Add LockDownEnd
- Loading branch information
Showing
8 changed files
with
407 additions
and
8 deletions.
There are no files selected for viewing
76 changes: 76 additions & 0 deletions
76
bungee/src/main/java/net/cubespace/geSuit/commands/LockDownCommands.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
bungee/src/main/java/net/cubespace/geSuit/moderation/LockdownListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} | ||
} | ||
|
||
} |
161 changes: 161 additions & 0 deletions
161
bungee/src/main/java/net/cubespace/geSuit/moderation/LockdownManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
common/src/main/java/net/cubespace/geSuit/remote/moderation/LockDownActions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
Oops, something went wrong.