Search in sources :

Example 16 with Arena

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

the class CustomItemListener method useUtility.

/**
 * Handle utilities utilization.
 */
@EventHandler
public void useUtility(PlayerInteractEvent event) {
    // Check if player is trying to place a utility item
    Player player = event.getPlayer();
    Arena playerArena = getPlayerArena(player);
    if (playerArena == null) {
        return;
    }
    ItemStack hand = getItemUsed(player);
    // Handle splash potion through other methods
    if (hand.getType() == Material.SPLASH_POTION) {
        return;
    }
    String utility = getUtilityFromItem(hand);
    if (utility == null) {
        return;
    }
    // Make sure we allow gear items to be used
    if (utility.contains("bow") || utility.contains("sword") || utility.contains("pickaxe")) {
        return;
    }
    // Stop if not left-click
    if (!event.getAction().toString().contains("RIGHT_CLICK")) {
        return;
    }
    if (event.getAction().toString().contains("RIGHT_CLICK_BLOCK")) {
        List<String> cancel = MissileWarsPlugin.getPlugin().getConfig().getStringList("cancel-schematic");
        for (String s : cancel) {
            if (event.getClickedBlock().getType() == Material.getMaterial(s)) {
                event.setCancelled(true);
                ConfigUtils.sendConfigMessage("messages.cannot-place-structure", player, null, null);
                return;
            }
        }
        if (utility.contains("creeper")) {
            Location spawnLoc = event.getClickedBlock().getRelative(event.getBlockFace()).getLocation();
            Creeper creeper = (Creeper) spawnLoc.getWorld().spawnEntity(spawnLoc.toCenterLocation().add(0, -0.5, 0), EntityType.CREEPER);
            if (utility.contains("charged")) {
                creeper.setPowered(true);
            }
            hand.setAmount(hand.getAmount() - 1);
            event.setCancelled(true);
            return;
        }
    }
    // Do proper action based on utility type
    if (utility.equalsIgnoreCase("fireball")) {
        event.setCancelled(true);
        Fireball fireball = (Fireball) player.getWorld().spawnEntity(player.getEyeLocation().clone().add(player.getEyeLocation().getDirection()), EntityType.FIREBALL);
        fireball.setYield(2);
        fireball.setIsIncendiary(true);
        fireball.setDirection(player.getEyeLocation().getDirection());
        fireball.setShooter(player);
        hand.setAmount(hand.getAmount() - 1);
        for (Player players : player.getWorld().getPlayers()) {
            ConfigUtils.sendConfigSound("spawn-fireball", players, player.getLocation());
        }
        playerArena.getPlayerInArena(player.getUniqueId()).incrementUtility();
    } else if (utility.equalsIgnoreCase("canopy")) {
        event.setCancelled(true);
        if (canopy_cooldown.contains(player.getUniqueId())) {
            return;
        }
        if (!player.isOnGround()) {
            ConfigUtils.sendConfigMessage("messages.canopy-fail", player, null, null);
            return;
        }
        ConfigUtils.sendConfigMessage("messages.canopy-activate", player, null, null);
        canopy_cooldown.add(player.getUniqueId());
        spawnCanopy(player, playerArena);
    }
}
Also used : Player(org.bukkit.entity.Player) MissileWarsPlayer(com.leomelonseeds.missilewars.teams.MissileWarsPlayer) Fireball(org.bukkit.entity.Fireball) Creeper(org.bukkit.entity.Creeper) ItemStack(org.bukkit.inventory.ItemStack) Arena(com.leomelonseeds.missilewars.arenas.Arena) Location(org.bukkit.Location) EventHandler(org.bukkit.event.EventHandler)

Example 17 with Arena

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

Example 18 with Arena

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

the class Deck method givePoolItem.

/**
 * Give a random item from the pool to a given player if they have space.
 *
 * @param player the player to give the pool item too
 */
public void givePoolItem(Player player) {
    // Ensure Deck has pool items
    if (pool.isEmpty()) {
        return;
    }
    double chance = 0.375;
    List<ItemStack> toUse = rand.nextDouble() < chance ? utility : missiles;
    ItemStack poolItem;
    // Don't give players the same item twice
    do {
        poolItem = toUse.get(rand.nextInt(toUse.size()));
    } while (lastTwo.contains(poolItem));
    // Add item to the list
    lastTwo.addFirst(poolItem);
    if (lastTwo.size() > 2) {
        lastTwo.removeLast();
    }
    Arena arena = MissileWarsPlugin.getPlugin().getArenaManager().getArena(player.getUniqueId());
    double toohigh = ConfigUtils.getMapNumber(arena.getMapType(), arena.getMapName(), "too-high");
    double toofar = ConfigUtils.getMapNumber(arena.getMapType(), arena.getMapName(), "too-far");
    Location loc = player.getLocation();
    // Don't give item if they are out of bounds
    if (loc.getBlockY() > toohigh || loc.getBlockX() < toofar) {
        refuseItem(player, poolItem, "messages.out-of-bounds");
        return;
    }
    // Don't give item if their inventory space is full
    if (!hasInventorySpace(player)) {
        refuseItem(player, poolItem, "messages.inventory-limit");
        return;
    }
    player.getInventory().addItem(poolItem);
}
Also used : ItemStack(org.bukkit.inventory.ItemStack) Arena(com.leomelonseeds.missilewars.arenas.Arena) Location(org.bukkit.Location)

Example 19 with Arena

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

the class ArenaGameruleListener method onPearl.

/**
 * Make sure players can't teleport with ender pearls
 */
@EventHandler
public void onPearl(PlayerTeleportEvent event) {
    // Ensure it's an ender pearl
    if (event.getCause() != TeleportCause.ENDER_PEARL) {
        return;
    }
    // Ensure it was in an arena world
    String possibleArenaName = event.getPlayer().getWorld().getName().replace("mwarena_", "");
    Arena possibleArena = MissileWarsPlugin.getPlugin().getArenaManager().getArena(possibleArenaName);
    if (possibleArena == null) {
        return;
    }
    event.setCancelled(true);
}
Also used : Arena(com.leomelonseeds.missilewars.arenas.Arena) EventHandler(org.bukkit.event.EventHandler)

Example 20 with Arena

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

the class ArenaGameruleListener method onRespawn.

/**
 * Just in case a player somehow respawns in the lobby
 */
@EventHandler
public void onRespawn(PlayerPostRespawnEvent event) {
    Player player = event.getPlayer();
    ArenaManager manager = MissileWarsPlugin.getPlugin().getArenaManager();
    Arena playerArena = manager.getArena(player.getUniqueId());
    if (playerArena != null && event.getRespawnedLocation().getWorld().getName().equals("world")) {
        ConfigUtils.sendConfigMessage("messages.spawn-obstructed", player, null, null);
        player.teleport(playerArena.getPlayerSpawn(player));
    }
}
Also used : ArenaManager(com.leomelonseeds.missilewars.arenas.ArenaManager) Player(org.bukkit.entity.Player) MissileWarsPlayer(com.leomelonseeds.missilewars.teams.MissileWarsPlayer) 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