Merge pull request #36 from Mineplex-LLC/feature/game-cmd-mode
Game Command Mode System
This commit is contained in:
commit
15dbf57ce5
@ -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.
|
||||
* <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;
|
||||
}
|
||||
}
|
||||
|
@ -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 + "."));
|
||||
}
|
||||
}
|
||||
}
|
@ -12,7 +12,7 @@ public class GameCommand extends MultiCommandBase<ArcadeManager>
|
||||
{
|
||||
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<ArcadeManager>
|
||||
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 <GameType> (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 <GameType> (MapSource) (Map)", "Set the current game or next game", Rank.ALL));
|
||||
UtilPlayer.message(caller, F.main("Tip", "Use TAB for games/maps!"));
|
||||
}
|
||||
}
|
||||
|
@ -26,7 +26,12 @@ public class SetCommand extends CommandBase<ArcadeManager>
|
||||
{
|
||||
if (Plugin.GetGame() == null)
|
||||
return;
|
||||
|
||||
|
||||
if (!Plugin.canPlayerUseGameCmd(caller))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (args.length == 0)
|
||||
{
|
||||
caller.sendMessage(F.help("/game set <GameType> (MapSource) (Map)", "Set the current game or next game", Rank.ADMIN));
|
||||
|
@ -18,6 +18,11 @@ public class StartCommand extends CommandBase<ArcadeManager>
|
||||
@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...");
|
||||
|
@ -19,6 +19,11 @@ public class StopCommand extends CommandBase<ArcadeManager>
|
||||
@Override
|
||||
public void Execute(Player caller, String[] args)
|
||||
{
|
||||
if (!Plugin.canPlayerUseGameCmd(caller))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (Plugin.GetGame() == null)
|
||||
return;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user