Search in sources :

Example 11 with Arena

use of com.leomelonseeds.missilewars.arenas.Arena 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;
}
Also used : ArenaManager(com.leomelonseeds.missilewars.arenas.ArenaManager) Player(org.bukkit.entity.Player) JSONObject(org.json.JSONObject) MissileWarsPlugin(com.leomelonseeds.missilewars.MissileWarsPlugin) Arena(com.leomelonseeds.missilewars.arenas.Arena)

Example 12 with Arena

use of com.leomelonseeds.missilewars.arenas.Arena 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;
}
Also used : ArenaManager(com.leomelonseeds.missilewars.arenas.ArenaManager) MissileWarsPlayer(com.leomelonseeds.missilewars.teams.MissileWarsPlayer) Player(org.bukkit.entity.Player) MissileWarsPlayer(com.leomelonseeds.missilewars.teams.MissileWarsPlayer) Arena(com.leomelonseeds.missilewars.arenas.Arena)

Example 13 with Arena

use of com.leomelonseeds.missilewars.arenas.Arena 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;
}
Also used : ArenaManager(com.leomelonseeds.missilewars.arenas.ArenaManager) Player(org.bukkit.entity.Player) Arena(com.leomelonseeds.missilewars.arenas.Arena)

Example 14 with Arena

use of com.leomelonseeds.missilewars.arenas.Arena in project MissileWars by Leomelonseeds.

the class CustomItemListener method useProjectile.

// private void despawnCanopy()
/**
 * Handle projectile items structure creation
 */
@EventHandler
public void useProjectile(ProjectileLaunchEvent event) {
    // Ensure we are tracking a utility thrown by a player
    if (!(event.getEntity().getType() == EntityType.SNOWBALL || event.getEntity().getType() == EntityType.EGG || event.getEntity().getType() == EntityType.ENDER_PEARL)) {
        return;
    }
    Projectile thrown = event.getEntity();
    if (!(thrown.getShooter() instanceof Player)) {
        return;
    }
    Player thrower = (Player) thrown.getShooter();
    Arena playerArena = getPlayerArena(thrower);
    if (playerArena == null) {
        return;
    }
    // Check if player is holding a structure item
    ItemStack hand = getItemUsed(thrower);
    String structureName = getStructureFromItem(hand);
    if (structureName == null) {
        return;
    }
    // Add meta for structure identification
    thrown.setCustomName(structureName);
    // Schedule structure spawn after 1 second if snowball is still alive
    new BukkitRunnable() {

        @Override
        public void run() {
            if (!thrown.isDead()) {
                if (!thrower.isOnline()) {
                    return;
                }
                spawnUtility(structureName, thrown.getLocation(), thrower, thrown, playerArena);
            }
        }
    }.runTaskLater(MissileWarsPlugin.getPlugin(), 20);
}
Also used : Player(org.bukkit.entity.Player) MissileWarsPlayer(com.leomelonseeds.missilewars.teams.MissileWarsPlayer) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) ItemStack(org.bukkit.inventory.ItemStack) Arena(com.leomelonseeds.missilewars.arenas.Arena) Projectile(org.bukkit.entity.Projectile) EventHandler(org.bukkit.event.EventHandler)

Example 15 with Arena

use of com.leomelonseeds.missilewars.arenas.Arena in project MissileWars by Leomelonseeds.

the class CustomItemListener method throwSplash.

/**
 * Handle projectile item utility creation
 */
@EventHandler
public void throwSplash(ProjectileLaunchEvent event) {
    if (event.getEntity().getType() != EntityType.SPLASH_POTION) {
        return;
    }
    ThrownPotion thrown = (ThrownPotion) event.getEntity();
    if (!(thrown.getShooter() instanceof Player)) {
        return;
    }
    Player thrower = (Player) thrown.getShooter();
    Arena playerArena = getPlayerArena(thrower);
    if (playerArena == null) {
        return;
    }
    // Check if player is holding a utility item
    ItemStack hand = getItemUsed(thrower);
    // Make sure it's splash potion of water
    if (getUtilityFromItem(hand) == null || !thrown.getEffects().isEmpty()) {
        return;
    }
    // Check the duration here
    thrown.setCustomName("splash:" + "1");
    playerArena.getPlayerInArena(thrower.getUniqueId()).incrementUtility();
}
Also used : Player(org.bukkit.entity.Player) MissileWarsPlayer(com.leomelonseeds.missilewars.teams.MissileWarsPlayer) ThrownPotion(org.bukkit.entity.ThrownPotion) ItemStack(org.bukkit.inventory.ItemStack) Arena(com.leomelonseeds.missilewars.arenas.Arena) EventHandler(org.bukkit.event.EventHandler)

Aggregations

Arena (com.leomelonseeds.missilewars.arenas.Arena)28 EventHandler (org.bukkit.event.EventHandler)21 Player (org.bukkit.entity.Player)20 ArenaManager (com.leomelonseeds.missilewars.arenas.ArenaManager)16 MissileWarsPlayer (com.leomelonseeds.missilewars.teams.MissileWarsPlayer)16 ItemStack (org.bukkit.inventory.ItemStack)6 Block (org.bukkit.block.Block)4 Projectile (org.bukkit.entity.Projectile)4 MissileWarsPlugin (com.leomelonseeds.missilewars.MissileWarsPlugin)3 Component (net.kyori.adventure.text.Component)2 Location (org.bukkit.Location)2 JSONObject (org.json.JSONObject)2 PlayerPostRespawnEvent (com.destroystokyo.paper.event.player.PlayerPostRespawnEvent)1 MissileWarsTeam (com.leomelonseeds.missilewars.teams.MissileWarsTeam)1 ConfigUtils (com.leomelonseeds.missilewars.utilities.ConfigUtils)1 DecimalFormat (java.text.DecimalFormat)1 ArrayList (java.util.ArrayList)1 ChatColor (org.bukkit.ChatColor)1 Material (org.bukkit.Material)1 Creeper (org.bukkit.entity.Creeper)1