Search in sources :

Example 21 with Arena

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

the class ArenaGameruleListener method onPortalCreate.

/**
 * Make sure players can't create portals
 */
@EventHandler
public void onPortalCreate(PortalCreateEvent event) {
    // Ensure it was in an arena world
    String possibleArenaName = event.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 22 with Arena

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

the class ArenaGameruleListener method onBreak.

/**
 * Handle shield block breaks breaks.
 */
@EventHandler
public void onBreak(BlockBreakEvent event) {
    Block block = event.getBlock();
    // Ensure it was in an arena world
    String possibleArenaName = block.getWorld().getName().replace("mwarena_", "");
    Arena possibleArena = MissileWarsPlugin.getPlugin().getArenaManager().getArena(possibleArenaName);
    if (possibleArena == null) {
        return;
    }
    // Fix dumb bug. No break obsidian
    if (block.getType().toString().contains("OBSIDIAN")) {
        event.setCancelled(true);
        return;
    }
    // Register block break
    possibleArena.registerShieldBlockEdit(block.getLocation(), false);
}
Also used : Block(org.bukkit.block.Block) Arena(com.leomelonseeds.missilewars.arenas.Arena) EventHandler(org.bukkit.event.EventHandler)

Example 23 with Arena

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

the class ArenaInventoryListener method onMapVote.

/**
 * Handle map voting
 */
@EventHandler
public void onMapVote(InventoryClickEvent event) {
    // Check if player is in an Arena
    if (!(event.getWhoClicked() instanceof Player)) {
        return;
    }
    Player player = (Player) event.getWhoClicked();
    ArenaManager manager = MissileWarsPlugin.getPlugin().getArenaManager();
    Arena arena = manager.getArena(player.getUniqueId());
    // Ensure map vote inventory is open
    if ((arena == null) || !event.getView().getTitle().equals(ConfigUtils.getConfigText("inventories.map-voting.title", player, null, null))) {
        return;
    }
    // Cancel click and try to register vote
    event.setCancelled(true);
    ItemStack clicked = event.getCurrentItem();
    if (clicked == null || !clicked.hasItemMeta() || !clicked.getItemMeta().hasDisplayName()) {
        return;
    }
    String mapVotedFor = arena.registerVote(player.getUniqueId(), clicked.getItemMeta().getDisplayName());
    player.sendMessage(ChatColor.GREEN + "Voted for " + mapVotedFor);
    arena.openMapVote(player);
}
Also used : ArenaManager(com.leomelonseeds.missilewars.arenas.ArenaManager) Player(org.bukkit.entity.Player) MissileWarsPlayer(com.leomelonseeds.missilewars.teams.MissileWarsPlayer) ItemStack(org.bukkit.inventory.ItemStack) Arena(com.leomelonseeds.missilewars.arenas.Arena) EventHandler(org.bukkit.event.EventHandler)

Example 24 with Arena

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

the class ArenaInventoryListener method stopItemMoving.

/**
 * Stop players from changing their armor/bow items.
 */
@EventHandler
public void stopItemMoving(InventoryClickEvent event) {
    // Obtain player
    if (!(event.getClickedInventory() instanceof PlayerInventory)) {
        return;
    }
    Player player = (Player) event.getWhoClicked();
    // Check if player is in an active arena
    ArenaManager manager = MissileWarsPlugin.getPlugin().getArenaManager();
    Arena arena = manager.getArena(player.getUniqueId());
    if (arena == null || !arena.isRunning()) {
        return;
    }
    // Stop armor removals and first slot changes
    if (event.getSlotType() == InventoryType.SlotType.ARMOR) {
        event.setCancelled(true);
        return;
    }
}
Also used : ArenaManager(com.leomelonseeds.missilewars.arenas.ArenaManager) Player(org.bukkit.entity.Player) MissileWarsPlayer(com.leomelonseeds.missilewars.teams.MissileWarsPlayer) PlayerInventory(org.bukkit.inventory.PlayerInventory) Arena(com.leomelonseeds.missilewars.arenas.Arena) EventHandler(org.bukkit.event.EventHandler)

Example 25 with Arena

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

the class ArenaInventoryListener method onItemPickup.

/**
 * Manage item pickups.
 */
@EventHandler
public void onItemPickup(EntityPickupItemEvent event) {
    // Check if player is in Arena
    if (!(event.getEntity() instanceof Player)) {
        return;
    }
    Player player = (Player) event.getEntity();
    ArenaManager manager = MissileWarsPlugin.getPlugin().getArenaManager();
    Arena arena = manager.getArena(player.getUniqueId());
    if (arena == null) {
        return;
    }
    MissileWarsPlayer mwPlayer = arena.getPlayerInArena(player.getUniqueId());
    // Cancel event if player cannot pick up item based on their given deck
    if (mwPlayer.getDeck() != null && !mwPlayer.getDeck().hasInventorySpace(mwPlayer.getMCPlayer())) {
        event.setCancelled(true);
    }
}
Also used : ArenaManager(com.leomelonseeds.missilewars.arenas.ArenaManager) Player(org.bukkit.entity.Player) MissileWarsPlayer(com.leomelonseeds.missilewars.teams.MissileWarsPlayer) 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