Add a system for allowing all players to use game commands when in the correct mode.

This commit is contained in:
William Burns 2016-04-27 20:54:52 +01:00
parent 807b12e846
commit d90e9e7dff
6 changed files with 143 additions and 5 deletions

View File

@ -76,6 +76,7 @@ import nautilus.game.arcade.addons.SoupAddon;
import nautilus.game.arcade.addons.TeamArmorAddon; import nautilus.game.arcade.addons.TeamArmorAddon;
import nautilus.game.arcade.addons.compass.CompassAddon; import nautilus.game.arcade.addons.compass.CompassAddon;
import nautilus.game.arcade.command.DisguiseCommand; import nautilus.game.arcade.command.DisguiseCommand;
import nautilus.game.arcade.command.GameCmdModeCommand;
import nautilus.game.arcade.command.GameCommand; import nautilus.game.arcade.command.GameCommand;
import nautilus.game.arcade.command.KitUnlockCommand; import nautilus.game.arcade.command.KitUnlockCommand;
import nautilus.game.arcade.command.RequiredRankCommand; import nautilus.game.arcade.command.RequiredRankCommand;
@ -213,6 +214,10 @@ public class ArcadeManager extends MiniPlugin implements IRelation
//Server Property //Server Property
private Rank _requiredRank; 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, public ArcadeManager(Arcade plugin, ServerStatusManager serverStatusManager, GameServerConfig serverConfig,
CoreClientManager clientManager, DonationManager donationManager, DamageManager damageManager, CoreClientManager clientManager, DonationManager donationManager, DamageManager damageManager,
StatsManager statsManager, IncognitoManager incognitoManager, AchievementManager achievementManager, DisguiseManager disguiseManager, Creature creature, Teleport teleport, Blood blood, Chat chat, 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(); loadRequiredRank();
_gameCommandMode = checkGameCommandMode();
} }
@Override @Override
@ -365,6 +372,7 @@ public class ArcadeManager extends MiniPlugin implements IRelation
addCommand(new KitUnlockCommand(this)); addCommand(new KitUnlockCommand(this));
addCommand(new DisguiseCommand(this)); addCommand(new DisguiseCommand(this));
addCommand(new RequiredRankCommand(this)); addCommand(new RequiredRankCommand(this));
addCommand(new GameCmdModeCommand(this));
} }
public GameChatManager getGameChatManager() public GameChatManager getGameChatManager()
@ -1550,4 +1558,58 @@ public class ArcadeManager extends MiniPlugin implements IRelation
{ {
return new ArcadePlayer(player, getCustomDataManager(), this); 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.
* <p>
* 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;
}
} }

View File

@ -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<ArcadeManager>
{
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 + "."));
}
}
}

View File

@ -12,7 +12,7 @@ public class GameCommand extends MultiCommandBase<ArcadeManager>
{ {
public GameCommand(ArcadeManager plugin) 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 StartCommand(Plugin));
AddCommand(new StopCommand(Plugin)); AddCommand(new StopCommand(Plugin));
@ -23,9 +23,9 @@ public class GameCommand extends MultiCommandBase<ArcadeManager>
protected void Help(Player caller, String[] args) protected void Help(Player caller, String[] args)
{ {
UtilPlayer.message(caller, F.main(Plugin.getName(), "Commands List:")); 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 start", "Start the current game", Rank.ALL));
UtilPlayer.message(caller, F.help("/game stop", "Stop the current game", Rank.ADMIN)); UtilPlayer.message(caller, F.help("/game stop", "Stop the current game", Rank.ALL));
UtilPlayer.message(caller, F.help("/game set <GameType> (MapSource) (Map)", "Set the current game or next game", Rank.ADMIN)); UtilPlayer.message(caller, F.help("/game set <GameType> (MapSource) (Map)", "Set the current game or next game", Rank.ALL));
UtilPlayer.message(caller, F.main("Tip", "Use TAB for games/maps!")); UtilPlayer.message(caller, F.main("Tip", "Use TAB for games/maps!"));
} }
} }

View File

@ -27,6 +27,11 @@ public class SetCommand extends CommandBase<ArcadeManager>
if (Plugin.GetGame() == null) if (Plugin.GetGame() == null)
return; return;
if (!Plugin.canPlayerUseGameCmd(caller))
{
return;
}
if (args.length == 0) if (args.length == 0)
{ {
caller.sendMessage(F.help("/game set <GameType> (MapSource) (Map)", "Set the current game or next game", Rank.ADMIN)); caller.sendMessage(F.help("/game set <GameType> (MapSource) (Map)", "Set the current game or next game", Rank.ADMIN));

View File

@ -18,6 +18,11 @@ public class StartCommand extends CommandBase<ArcadeManager>
@Override @Override
public void Execute(Player caller, String[] args) public void Execute(Player caller, String[] args)
{ {
if (!Plugin.canPlayerUseGameCmd(caller))
{
return;
}
if (Plugin.GetGame() == null || Plugin.GetGame().GetState() == GameState.Loading) if (Plugin.GetGame() == null || Plugin.GetGame().GetState() == GameState.Loading)
{ {
caller.sendMessage(C.cRed + C.Bold + "Game is loading..."); caller.sendMessage(C.cRed + C.Bold + "Game is loading...");

View File

@ -19,6 +19,11 @@ public class StopCommand extends CommandBase<ArcadeManager>
@Override @Override
public void Execute(Player caller, String[] args) public void Execute(Player caller, String[] args)
{ {
if (!Plugin.canPlayerUseGameCmd(caller))
{
return;
}
if (Plugin.GetGame() == null) if (Plugin.GetGame() == null)
return; return;