Fix random players being able to stop any game

* Moves /tstopgame and /spec to proper command classes
* Only enables /tstopgame on tournament servers
* /tstopgame can be run by eventmods, not a hardcoded list
This commit is contained in:
Dan Mulloy 2018-06-08 11:11:15 -04:00 committed by Alexander Meech
parent 0cfc909124
commit f30570da25
3 changed files with 122 additions and 75 deletions

View File

@ -141,7 +141,9 @@ import nautilus.game.arcade.command.GameCommand;
import nautilus.game.arcade.command.GoToNextGameCommand;
import nautilus.game.arcade.command.KitUnlockCommand;
import nautilus.game.arcade.command.ReturnToHubCommand;
import nautilus.game.arcade.command.SpectatorCommand;
import nautilus.game.arcade.command.TauntCommand;
import nautilus.game.arcade.command.TournamentStopCommand;
import nautilus.game.arcade.events.GameStateChangeEvent;
import nautilus.game.arcade.game.Game;
import nautilus.game.arcade.game.Game.GameState;
@ -186,11 +188,11 @@ public class ArcadeManager extends MiniPlugin implements IRelation
JOIN_FULL_STAFF,
BYPASS_WHITELIST,
BYPASS_MPS_WHITELIST,
RETURN_TO_HUB_COMMAND
RETURN_TO_HUB_COMMAND,
TOURNAMENT_STOP_COMMAND,
SPECTATOR_COMMAND
}
private static final List<String> TOURNAMENT_CONTROLLERS = Arrays.asList("Malfunction", "adeelzee", "gr8p", "HelloItsMeJack", "Aussi", "Jesusman3", "TyTy2017", "KingShook", "Sw1ck", "doodzee", "Chr1mz", "Giovanna", "xApolloJustice", "bawzee", "MessedUpLogic", "dehfi", "Geothermal", "captainfence", "Ecal", "Raydnn", "Otisdiver", "AussieFighter", "snevahmadaa", "eMoa", "Vilare", "xLouis", "PizzaMan319");
// Modules
private BlockRestore _blockRestore;
private Blood _blood;
@ -400,6 +402,12 @@ public class ArcadeManager extends MiniPlugin implements IRelation
addCommand(new CancelNextGameCommand(this));
addCommand(new TauntCommand(this));
addCommand(new ReturnToHubCommand(this));
addCommand(new SpectatorCommand(this));
if (IsTournamentServer())
{
addCommand(new TournamentStopCommand(this));
}
require(PersonalServerManager.class);
require(CommunityManager.class);
@ -614,11 +622,13 @@ public class ArcadeManager extends MiniPlugin implements IRelation
PermissionGroup.BUILDER.setPermission(Perm.KIT_UNLOCK_COMMAND, true, true);
PermissionGroup.PLAYER.setPermission(Perm.TAUNT_COMMAND, true, true);
PermissionGroup.ADMIN.setPermission(Perm.GAME_COMMAND, true, true);
if (UtilServer.isTestServer())
{
PermissionGroup.QA.setPermission(Perm.GAME_COMMAND, true, true);
PermissionGroup.MAPLEAD.setPermission(Perm.GAME_COMMAND, false, true);
}
if (UtilServer.isTestServer() || UtilServer.isDevServer())
{
PermissionGroup.ADMIN.setPermission(Perm.AUTO_OP, true, true);
@ -627,6 +637,7 @@ public class ArcadeManager extends MiniPlugin implements IRelation
{
PermissionGroup.LT.setPermission(Perm.AUTO_OP, true, true);
}
PermissionGroup.BUILDER.setPermission(Perm.FEATURED_SERVER, true, true);
PermissionGroup.CONTENT.setPermission(Perm.FEATURED_SERVER, true, true);
PermissionGroup.TRAINEE.setPermission(Perm.INFORM_RANKED_MODERATION_POTENTIAL, true, true);
@ -635,6 +646,8 @@ public class ArcadeManager extends MiniPlugin implements IRelation
PermissionGroup.BUILDER.setPermission(Perm.BYPASS_WHITELIST, true, true);
PermissionGroup.TRAINEE.setPermission(Perm.BYPASS_WHITELIST, false, false);
PermissionGroup.MOD.setPermission(Perm.BYPASS_MPS_WHITELIST, true, true);
PermissionGroup.EVENTMOD.setPermission(Perm.TOURNAMENT_STOP_COMMAND, false, true);
PermissionGroup.PLAYER.setPermission(Perm.SPECTATOR_COMMAND, true, true);
}
@Override
@ -1386,89 +1399,51 @@ public class ArcadeManager extends MiniPlugin implements IRelation
event.SetCancelled(true);
}
}
@EventHandler
public void tournamentStopGame(PlayerCommandPreprocessEvent event)
public void toggleSpectator(Player player)
{
if (event.getMessage().trim().equalsIgnoreCase("/tstopgame") && TOURNAMENT_CONTROLLERS.contains(event.getPlayer().getName()))
if (_game != null && _game.InProgress())
{
event.setCancelled(true);
if (GetGame() == null)
{
UtilPlayer.message(event.getPlayer(), F.main("Game", "There is no game to stop!"));
return;
}
if (GetGame().GetState() == GameState.End)
{
UtilPlayer.message(event.getPlayer(), F.main("Game", "The game is already ending, it cannot be ended again"));
return;
}
else if (GetGame().GetState() == GameState.Recruit)
{
GetGame().SetState(GameState.Dead);
}
else
{
GetGame().SetState(GameState.End);
}
HandlerList.unregisterAll(GetGame());
GetGame().Announce(C.cAqua + C.Bold + event.getPlayer().getName() + " has stopped the game.");
UtilPlayer.message(player, F.main("Game", "You cannot toggle Spectator during games."));
return;
}
}
@EventHandler
public void Observer(PlayerCommandPreprocessEvent event)
{
if (event.getMessage().equalsIgnoreCase("/spec"))
if (isVanished(player))
{
event.setCancelled(true);
UtilPlayer.message(player, F.main("Game", "You cannot toggle spectator while vanished."));
return;
}
if (_game != null && _game.InProgress())
if (!_specList.remove(player))
{
if (_game != null && !_game.SpectatorAllowed)
{
UtilPlayer.message(event.getPlayer(), F.main("Game", "You cannot toggle Spectator during games."));
UtilPlayer.message(player, F.main("Game", "You are not allowed to toggle Spectator in this game!"));
return;
}
_specList.add(player);
if (isVanished(event.getPlayer()))
UtilPlayer.message(player, F.main("Game", "You are now a Spectator!"));
}
else
{
UtilPlayer.message(player, F.main("Game", "You are no longer a Spectator!"));
}
// Clean
if (_game != null)
{
// Remove Data
_game.RemoveTeamPreference(player);
_game.GetPlayerKits().remove(player);
_game.GetPlayerGems().remove(player);
// Leave Team
GameTeam team = _game.GetTeam(player);
if (team != null)
{
UtilPlayer.message(event.getPlayer(), F.main("Game", "You cannot toggle spectator while vanished."));
return;
}
if (!_specList.remove(event.getPlayer()))
{
if (_game != null && !_game.SpectatorAllowed)
{
UtilPlayer.message(event.getPlayer(), F.main("Game", "You are not allowed to toggle Spectator in this game!"));
return;
}
_specList.add(event.getPlayer());
UtilPlayer.message(event.getPlayer(), F.main("Game", "You are now a Spectator!"));
}
else
{
UtilPlayer.message(event.getPlayer(), F.main("Game", "You are no longer a Spectator!"));
}
// Clean
if (_game != null)
{
// Remove Data
_game.RemoveTeamPreference(event.getPlayer());
_game.GetPlayerKits().remove(event.getPlayer());
_game.GetPlayerGems().remove(event.getPlayer());
// Leave Team
GameTeam team = _game.GetTeam(event.getPlayer());
if (team != null)
{
team.RemovePlayer(event.getPlayer());
}
team.RemovePlayer(player);
}
}
}

View File

@ -0,0 +1,20 @@
package nautilus.game.arcade.command;
import org.bukkit.entity.Player;
import mineplex.core.command.CommandBase;
import nautilus.game.arcade.ArcadeManager;
public class SpectatorCommand extends CommandBase<ArcadeManager>
{
public SpectatorCommand(ArcadeManager plugin)
{
super(plugin, ArcadeManager.Perm.SPECTATOR_COMMAND, "spectator", "spec");
}
@Override
public void Execute(Player caller, String[] args)
{
Plugin.toggleSpectator(caller);
}
}

View File

@ -0,0 +1,52 @@
package nautilus.game.arcade.command;
import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList;
import mineplex.core.command.CommandBase;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.game.Game;
public class TournamentStopCommand extends CommandBase<ArcadeManager>
{
public TournamentStopCommand(ArcadeManager plugin)
{
super(plugin, ArcadeManager.Perm.TOURNAMENT_STOP_COMMAND, "tstopgame");
}
@Override
public void Execute(Player caller, String[] args)
{
if (!Plugin.IsTournamentServer())
{
UtilPlayer.message(caller, F.main("Game", "This command can only be used on tournament servers!"));
return;
}
if (Plugin.GetGame() == null)
{
UtilPlayer.message(caller, F.main("Game", "There is no game to stop!"));
return;
}
if (Plugin.GetGame().GetState() == Game.GameState.End)
{
UtilPlayer.message(caller, F.main("Game", "The game is already ending, it cannot be ended again"));
return;
}
else if (Plugin.GetGame().GetState() == Game.GameState.Recruit)
{
Plugin.GetGame().SetState(Game.GameState.Dead);
}
else
{
Plugin.GetGame().SetState(Game.GameState.End);
}
HandlerList.unregisterAll(Plugin.GetGame());
Plugin.GetGame().Announce(C.cAqua + C.Bold + caller + " has stopped the game.");
}
}