Search in sources :

Example 11 with ArenaManager

use of com.leomelonseeds.missilewars.arenas.ArenaManager 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)

Example 12 with ArenaManager

use of com.leomelonseeds.missilewars.arenas.ArenaManager 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 13 with ArenaManager

use of com.leomelonseeds.missilewars.arenas.ArenaManager 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 14 with ArenaManager

use of com.leomelonseeds.missilewars.arenas.ArenaManager 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)

Example 15 with ArenaManager

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

the class ArenaInventoryListener method onItemDrop.

/**
 * Manage item dropping.
 */
@EventHandler
public void onItemDrop(PlayerDropItemEvent event) {
    // Check if player is in Arena
    Player player = event.getPlayer();
    ArenaManager manager = MissileWarsPlugin.getPlugin().getArenaManager();
    Arena arena = manager.getArena(player.getUniqueId());
    if (arena == null) {
        return;
    }
    // Stop drops entirely if player not on team
    if ((arena.getTeam(player.getUniqueId()).equals("no team"))) {
        event.setCancelled(true);
        return;
    }
    // Stop drops of gear items
    MissileWarsPlayer mwPlayer = arena.getPlayerInArena(player.getUniqueId());
    if (mwPlayer.getDeck().getGear().contains(event.getItemDrop().getItemStack())) {
        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

ArenaManager (com.leomelonseeds.missilewars.arenas.ArenaManager)16 Arena (com.leomelonseeds.missilewars.arenas.Arena)15 Player (org.bukkit.entity.Player)13 EventHandler (org.bukkit.event.EventHandler)10 MissileWarsPlayer (com.leomelonseeds.missilewars.teams.MissileWarsPlayer)9 JSONObject (org.json.JSONObject)2 MissileWarsPlugin (com.leomelonseeds.missilewars.MissileWarsPlugin)1 MissileWarsCommand (com.leomelonseeds.missilewars.commands.MissileWarsCommand)1 SpectateCommand (com.leomelonseeds.missilewars.commands.SpectateCommand)1 VoteMapCommand (com.leomelonseeds.missilewars.commands.VoteMapCommand)1 DeckManager (com.leomelonseeds.missilewars.decks.DeckManager)1 ArenaGameruleListener (com.leomelonseeds.missilewars.listener.ArenaGameruleListener)1 ArenaInventoryListener (com.leomelonseeds.missilewars.listener.ArenaInventoryListener)1 CustomItemListener (com.leomelonseeds.missilewars.listener.CustomItemListener)1 JoinLeaveListener (com.leomelonseeds.missilewars.listener.JoinLeaveListener)1 WorldCreationListener (com.leomelonseeds.missilewars.listener.WorldCreationListener)1 MissileWarsTeam (com.leomelonseeds.missilewars.teams.MissileWarsTeam)1 JSONManager (com.leomelonseeds.missilewars.utilities.JSONManager)1 MissileWarsPlaceholder (com.leomelonseeds.missilewars.utilities.MissileWarsPlaceholder)1 DecimalFormat (java.text.DecimalFormat)1