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));
}
}
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);
}
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;
}
}
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);
}
}
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);
}
}
Aggregations