From d90e9e7dff1e9a3ea707fa3f60066221593bc4a1 Mon Sep 17 00:00:00 2001 From: William Burns Date: Wed, 27 Apr 2016 20:54:52 +0100 Subject: [PATCH] Add a system for allowing all players to use game commands when in the correct mode. --- .../nautilus/game/arcade/ArcadeManager.java | 62 +++++++++++++++++++ .../arcade/command/GameCmdModeCommand.java | 61 ++++++++++++++++++ .../game/arcade/command/GameCommand.java | 8 +-- .../game/arcade/command/SetCommand.java | 7 ++- .../game/arcade/command/StartCommand.java | 5 ++ .../game/arcade/command/StopCommand.java | 5 ++ 6 files changed, 143 insertions(+), 5 deletions(-) create mode 100644 Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/command/GameCmdModeCommand.java diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java index c642dee43..3e33c7708 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java @@ -76,6 +76,7 @@ import nautilus.game.arcade.addons.SoupAddon; import nautilus.game.arcade.addons.TeamArmorAddon; import nautilus.game.arcade.addons.compass.CompassAddon; import nautilus.game.arcade.command.DisguiseCommand; +import nautilus.game.arcade.command.GameCmdModeCommand; import nautilus.game.arcade.command.GameCommand; import nautilus.game.arcade.command.KitUnlockCommand; import nautilus.game.arcade.command.RequiredRankCommand; @@ -213,6 +214,10 @@ public class ArcadeManager extends MiniPlugin implements IRelation //Server Property private Rank _requiredRank; + //Game commands + public static final String GAME_CMD_MODE_FILE = "GAME_CMD_MODE.dat"; + private boolean _gameCommandMode; + public ArcadeManager(Arcade plugin, ServerStatusManager serverStatusManager, GameServerConfig serverConfig, CoreClientManager clientManager, DonationManager donationManager, DamageManager damageManager, StatsManager statsManager, IncognitoManager incognitoManager, AchievementManager achievementManager, DisguiseManager disguiseManager, Creature creature, Teleport teleport, Blood blood, Chat chat, @@ -355,6 +360,8 @@ public class ArcadeManager extends MiniPlugin implements IRelation } loadRequiredRank(); + + _gameCommandMode = checkGameCommandMode(); } @Override @@ -365,6 +372,7 @@ public class ArcadeManager extends MiniPlugin implements IRelation addCommand(new KitUnlockCommand(this)); addCommand(new DisguiseCommand(this)); addCommand(new RequiredRankCommand(this)); + addCommand(new GameCmdModeCommand(this)); } public GameChatManager getGameChatManager() @@ -1550,4 +1558,58 @@ public class ArcadeManager extends MiniPlugin implements IRelation { return new ArcadePlayer(player, getCustomDataManager(), this); } + + /** + * Returns whether this server has a file, stating that it allows game commands. + * + * @return Whether this server is in game command mode. + */ + private boolean checkGameCommandMode() + { + return new File(GAME_CMD_MODE_FILE).exists(); + } + + /** + * @return Whether this server is in game command mode. + */ + public boolean isGameCommandMode() + { + return _gameCommandMode; + } + + /** + * Sets this server's game command mode state. + * + * @param state Whether to enable or disable game commands. + */ + public void setGameCommandMode(boolean state) + { + _gameCommandMode = state; + } + + /** + * Finds whether or not a player can use a game command or not. + *

+ * Sends a denial alert if they can't. + * + * @param player The player attempting to use the command. + * @return Whether or not the player can successfully use the command. + */ + public boolean canPlayerUseGameCmd(Player player) + { + if (_gameCommandMode) + { + // When enabled, anyone can use game commands. + return true; + } + + // Check whether they are of high enough rank status. + if (!GetClients().hasRank(player, Rank.JNR_DEV)) + { + player.sendMessage(F.main("Server", "You are not allowed to use game commands.")); + return false; + } + + return true; + } } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/command/GameCmdModeCommand.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/command/GameCmdModeCommand.java new file mode 100644 index 000000000..7bd1080e4 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/command/GameCmdModeCommand.java @@ -0,0 +1,61 @@ +package nautilus.game.arcade.command; + +import java.io.File; +import java.io.IOException; + +import org.bukkit.entity.Player; + +import mineplex.core.command.CommandBase; +import mineplex.core.common.Rank; +import mineplex.core.common.util.C; +import mineplex.core.common.util.F; +import nautilus.game.arcade.ArcadeManager; + +/** + * A command to toggle this server's game command mode state. + */ +public class GameCmdModeCommand extends CommandBase +{ + public GameCmdModeCommand(ArcadeManager plugin) + { + super(plugin, Rank.JNR_DEV, "gamecmdmode"); + } + + @Override + public void Execute(Player caller, String[] args) + { + File file = new File(ArcadeManager.GAME_CMD_MODE_FILE); + + if (Plugin.isGameCommandMode()) + { + // Disable game command mode. + if (file.exists()) + { + file.delete(); + } + + Plugin.setGameCommandMode(false); + caller.sendMessage(F.main("Server", "Game commands are now " + C.cRed + "disabled" + + C.cGray + ".")); + } + else + { + // Enable game command mode. + if (!file.exists()) + { + try + { + file.createNewFile(); + } + catch (IOException e) + { + e.printStackTrace(); + } + } + + Plugin.setGameCommandMode(true); + caller.sendMessage(F.main("Server", "Game commands are now " + C.cGreen + "enabled" + + C.cGray + ".")); + } + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/command/GameCommand.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/command/GameCommand.java index 76e4edb1c..67b11d9eb 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/command/GameCommand.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/command/GameCommand.java @@ -12,7 +12,7 @@ public class GameCommand extends MultiCommandBase { public GameCommand(ArcadeManager plugin) { - super(plugin, Rank.ADMIN, new Rank[] {Rank.MAPLEAD, Rank.JNR_DEV}, "game"); + super(plugin, Rank.ALL, "game"); AddCommand(new StartCommand(Plugin)); AddCommand(new StopCommand(Plugin)); @@ -23,9 +23,9 @@ public class GameCommand extends MultiCommandBase protected void Help(Player caller, String[] args) { UtilPlayer.message(caller, F.main(Plugin.getName(), "Commands List:")); - UtilPlayer.message(caller, F.help("/game start", "Start the current game", Rank.ADMIN)); - UtilPlayer.message(caller, F.help("/game stop", "Stop the current game", Rank.ADMIN)); - UtilPlayer.message(caller, F.help("/game set (MapSource) (Map)", "Set the current game or next game", Rank.ADMIN)); + UtilPlayer.message(caller, F.help("/game start", "Start the current game", Rank.ALL)); + UtilPlayer.message(caller, F.help("/game stop", "Stop the current game", Rank.ALL)); + UtilPlayer.message(caller, F.help("/game set (MapSource) (Map)", "Set the current game or next game", Rank.ALL)); UtilPlayer.message(caller, F.main("Tip", "Use TAB for games/maps!")); } } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/command/SetCommand.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/command/SetCommand.java index 78cc48c23..6dd746703 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/command/SetCommand.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/command/SetCommand.java @@ -26,7 +26,12 @@ public class SetCommand extends CommandBase { if (Plugin.GetGame() == null) return; - + + if (!Plugin.canPlayerUseGameCmd(caller)) + { + return; + } + if (args.length == 0) { caller.sendMessage(F.help("/game set (MapSource) (Map)", "Set the current game or next game", Rank.ADMIN)); diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/command/StartCommand.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/command/StartCommand.java index 2d45496ae..f8e058e58 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/command/StartCommand.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/command/StartCommand.java @@ -18,6 +18,11 @@ public class StartCommand extends CommandBase @Override public void Execute(Player caller, String[] args) { + if (!Plugin.canPlayerUseGameCmd(caller)) + { + return; + } + if (Plugin.GetGame() == null || Plugin.GetGame().GetState() == GameState.Loading) { caller.sendMessage(C.cRed + C.Bold + "Game is loading..."); diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/command/StopCommand.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/command/StopCommand.java index d7a255c84..f4b5ab7ad 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/command/StopCommand.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/command/StopCommand.java @@ -19,6 +19,11 @@ public class StopCommand extends CommandBase @Override public void Execute(Player caller, String[] args) { + if (!Plugin.canPlayerUseGameCmd(caller)) + { + return; + } + if (Plugin.GetGame() == null) return;