use of com.leomelonseeds.missilewars.arenas.ArenaManager in project MissileWars by Leomelonseeds.
the class JoinLeaveListener method onWorldChange.
/**
* Remove player from Arena if they leave the world.
*/
@EventHandler
public void onWorldChange(PlayerChangedWorldEvent event) {
Player player = event.getPlayer();
if (event.getFrom().getName().contains("mwarena")) {
ArenaManager manager = MissileWarsPlugin.getPlugin().getArenaManager();
Arena playerArena = manager.getArena(player.getUniqueId());
if (playerArena == null || player.getWorld().equals(playerArena.getWorld())) {
return;
}
// Check 1 tick later to make 100% sure
Bukkit.getScheduler().runTaskLater(MissileWarsPlugin.getPlugin(), () -> {
if (player.getWorld().getName().equals("world")) {
playerArena.removePlayer(player.getUniqueId());
}
}, 1);
}
}
use of com.leomelonseeds.missilewars.arenas.ArenaManager in project MissileWars by Leomelonseeds.
the class MissileWarsCommand method onCommand.
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
// Send info if no action taken
if (args.length == 0) {
sendErrorMsg(sender, "Usage: /umw <CreateArena/DeleteArena/Join/Leave/OpenGameMenu/EnqueueRed/EnqueueBlue/ForceStart>");
return true;
}
// Check for arena creation
String action = args[0];
MissileWarsPlugin plugin = MissileWarsPlugin.getPlugin();
ArenaManager arenaManager = plugin.getArenaManager();
if (action.equalsIgnoreCase("DeleteArena")) {
// Ensure player is allowed to create an arena
if (!sender.hasPermission("umw.delete-arena")) {
sendErrorMsg(sender, "You do not have permission to do that!");
return true;
}
// Validate given arena name
if (args.length < 2) {
sendErrorMsg(sender, "Usage: /umw DeleteArena <arena-name>");
return true;
}
String arenaName = args[1];
Arena toRemove = arenaManager.getArena(arenaName);
if (toRemove == null) {
sendErrorMsg(sender, "That arena does not exist!");
return true;
}
// Delete the arena
if (arenaManager.removeArena(toRemove)) {
sendSuccessMsg(sender, "The arena has been deleted!");
return true;
} else {
sendErrorMsg(sender, "Something went wrong deleting the arena. Notify an admin.");
return true;
}
}
if (action.equalsIgnoreCase("CreateArena")) {
// Ensure player is allowed to delete an arena
if (!sender.hasPermission("umw.create-arena")) {
sendErrorMsg(sender, "You do not have permission to do that!");
return true;
}
// Validate given arena name
if (args.length < 2) {
sendErrorMsg(sender, "Usage: /umw CreateArena <arena-name> [capacity]");
return true;
}
String arenaName = args[1];
if (arenaManager.getArena(arenaName) != null) {
sendErrorMsg(sender, "An arena with that name already exists!");
return true;
}
int arenaCapacity = MissileWarsPlugin.getPlugin().getConfig().getInt("arena-cap");
if (args.length > 2) {
try {
arenaCapacity = Integer.parseInt(args[2]);
} catch (NumberFormatException e) {
sendErrorMsg(sender, "Capacity must be a number!");
return true;
}
}
// Create new arena
if (arenaManager.createArena(arenaName, arenaCapacity)) {
sendSuccessMsg(sender, "New arena created!");
return true;
} else {
sendErrorMsg(sender, "Something went wrong creating the arena. Notify an admin.");
return true;
}
}
// Update all arenas. Might take a while
if (action.equalsIgnoreCase("PerformArenaUpgrade")) {
if (sender instanceof Player) {
return false;
}
MissileWarsPlugin.getPlugin().getArenaManager().performArenaUpgrade();
return true;
}
// Clear inventories the umw way
if (action.equalsIgnoreCase("clear")) {
if (args.length == 1) {
if (sender instanceof Player) {
Player player = (Player) sender;
InventoryUtils.clearInventory(player);
sendSuccessMsg(sender, "Inventory cleared!");
return true;
} else {
sendSuccessMsg(sender, "Must specify a target.");
return true;
}
} else if (args.length == 2) {
Player target = getCommandTarget(args, sender);
if (target == null) {
sendErrorMsg(sender, "No target found!");
return true;
}
InventoryUtils.clearInventory(target);
return true;
}
}
// Open game selector
if (action.equalsIgnoreCase("OpenGameMenu")) {
// Ensure player is allowed to open game menu
if (!sender.hasPermission("umw.open-arena-menu")) {
sendErrorMsg(sender, "You do not have permission to do that!");
return true;
}
// Check if opening for another player
Player target = getCommandTarget(args, sender);
if (target == null) {
sendErrorMsg(sender, "No target found!");
return true;
}
arenaManager.openArenaSelector(target);
sendSuccessMsg(sender, "Game selector opened!");
return true;
}
// Quit to waiting lobby of a game
if (action.equalsIgnoreCase("Leave") && sender instanceof Player) {
Player player = (Player) sender;
Arena arena = arenaManager.getArena(player.getUniqueId());
if (arena == null) {
sendErrorMsg(sender, "You must be in a game to do this!");
return true;
}
if (!(arena.leaveGame(player.getUniqueId()))) {
sendErrorMsg(sender, "You cannot do this now!");
return true;
}
return true;
}
// Join the fullest available game
if (action.equalsIgnoreCase("Join") && sender instanceof Player) {
Player player = (Player) sender;
// Require player to be in the lobby
if (!player.getWorld().getName().equals("world")) {
sendErrorMsg(sender, "You must be in the lobby to use this!");
return true;
}
// Allow player to join the fullest arena, or specify an arena name
if (args.length == 1) {
for (Arena arena : arenaManager.getLoadedArenas()) {
if (arena.getNumPlayers() < arena.getCapacity()) {
if (arena.joinPlayer(player)) {
return true;
}
}
}
} else if (args.length >= 2) {
for (Arena arena : arenaManager.getLoadedArenas()) {
if (arena.getName().equalsIgnoreCase(args[1])) {
if (arena.joinPlayer(player)) {
return true;
} else {
ConfigUtils.sendConfigMessage("messages.arena-full", player, arena, null);
return true;
}
}
}
sendErrorMsg(sender, "Please specify a valid arena name!");
return true;
}
sendErrorMsg(sender, "All arenas are full! Please open the menu and choose one to spectate.");
return true;
}
// Queue for red team
if (action.equalsIgnoreCase("EnqueueRed")) {
// Ensure player is allowed to open team menu
if (!sender.hasPermission("umw.enqueue")) {
sendErrorMsg(sender, "You do not have permission to do that!");
return true;
}
// Check if opening for another player
Player target = getCommandTarget(args, sender);
if (target == null) {
sendErrorMsg(sender, "No target found!");
return true;
}
// Check if player is in arena
Arena arena = arenaManager.getArena(target.getUniqueId());
if (arena == null) {
sendErrorMsg(sender, "Target is not in an arena");
return true;
}
// Enqueue for red team
arena.enqueueRed(target.getUniqueId());
sendSuccessMsg(sender, "Enqueued player for red team!");
return true;
}
// Queue for blue team
if (action.equalsIgnoreCase("EnqueueBlue")) {
// Ensure player is allowed to open team menu
if (!sender.hasPermission("umw.enqueue")) {
sendErrorMsg(sender, "You do not have permission to do that!");
return true;
}
// Check if opening for another player
Player target = getCommandTarget(args, sender);
if (target == null) {
sendErrorMsg(sender, "No target found!");
return true;
}
// Check if player is in arena
Arena arena = arenaManager.getArena(target.getUniqueId());
if (arena == null) {
sendErrorMsg(sender, "Target is not in an arena");
return true;
}
// Enqueue for red team
arena.enqueueBlue(target.getUniqueId());
sendSuccessMsg(sender, "Enqueued player for blue team!");
return true;
}
// Force start an arena
if (action.equalsIgnoreCase("ForceStart")) {
// Ensure sender has permission
if (!sender.hasPermission("umw.force-start")) {
sendErrorMsg(sender, "You do not have permission to do that!");
return true;
}
// Check for arena and start it
if (args.length < 2) {
sendErrorMsg(sender, "You must specify an arena name!");
return true;
}
Arena target = arenaManager.getArena(args[1]);
if (target == null) {
sendErrorMsg(sender, "Arena not found!");
return true;
}
if (target.start()) {
sendSuccessMsg(sender, "Arena started!");
} else {
sendErrorMsg(sender, "Arena is already running!");
}
return true;
}
if (action.equalsIgnoreCase("Deck")) {
Player player = (Player) sender;
Arena arena = arenaManager.getArena(player.getUniqueId());
if (!(arena == null || arena.getTeam(player.getUniqueId()).equals("no team"))) {
sendErrorMsg(sender, "You cannot change decks while playing.");
return true;
}
if (args.length != 2) {
sendErrorMsg(sender, "Usage: /mw deck Vanguard/Berserker/Sentinel/Architect");
return true;
}
String deck = StringUtils.capitalize(args[1].toLowerCase());
if (plugin.getDeckManager().getDeck(deck) == null) {
sendErrorMsg(sender, "Please specify a valid deck!");
return true;
}
// Update deck in cache
JSONObject currentDeck = plugin.getJSON().getPlayer(player.getUniqueId());
currentDeck.put("Deck", deck);
plugin.getJSON().setPlayer(player.getUniqueId(), currentDeck);
sendSuccessMsg(sender, "Set your deck to " + deck + "!");
return true;
}
return true;
}
use of com.leomelonseeds.missilewars.arenas.ArenaManager in project MissileWars by Leomelonseeds.
the class SpectateCommand method onCommand.
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
// Ensure sender is a Player
if (!(sender instanceof Player)) {
sendErrorMsg(sender, "You must be a player");
return true;
}
Player player = (Player) sender;
// Try to find Arena
ArenaManager arenaManager = MissileWarsPlugin.getPlugin().getArenaManager();
Arena arena = arenaManager.getArena(player.getUniqueId());
if (arena == null) {
sendErrorMsg(player, "You are not in an arena!");
return true;
}
// Check if player is currently spectating
MissileWarsPlayer missileWarsPlayer = arena.getPlayerInArena(player.getUniqueId());
if (arena.isSpectating(missileWarsPlayer)) {
arena.removeSpectator(missileWarsPlayer);
return true;
}
// Allow player to spectate
arena.addSpectator(player.getUniqueId());
return true;
}
use of com.leomelonseeds.missilewars.arenas.ArenaManager in project MissileWars by Leomelonseeds.
the class VoteMapCommand method onCommand.
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
// Ensure user is a player
if (!(sender instanceof Player)) {
sendErrorMsg(sender, "You are not a player!");
}
Player player = (Player) sender;
// Ensure player is in an arena that is not running
ArenaManager manager = MissileWarsPlugin.getPlugin().getArenaManager();
Arena playerArena = manager.getArena(player.getUniqueId());
if (playerArena == null) {
sendErrorMsg(player, "You are not in an arena!");
return true;
}
if (playerArena.isRunning() || playerArena.isResetting()) {
sendErrorMsg(player, "The game has already started!");
return true;
}
// Open voting menu
playerArena.openMapVote(player);
return true;
}
use of com.leomelonseeds.missilewars.arenas.ArenaManager in project MissileWars by Leomelonseeds.
the class JoinLeaveListener method onQuit.
/**
* Remove player from Arena if they DC.
*/
@EventHandler
public void onQuit(PlayerQuitEvent event) {
// Save player deck configuration
Player player = event.getPlayer();
MissileWarsPlugin.getPlugin().getJSON().savePlayer(player.getUniqueId());
// Get Arena player is in and remove them
ArenaManager manager = MissileWarsPlugin.getPlugin().getArenaManager();
Arena playerArena = manager.getArena(player.getUniqueId());
if (playerArena == null) {
InventoryUtils.saveInventory(player, true);
return;
}
playerArena.removePlayer(player.getUniqueId());
}
Aggregations