use of com.leomelonseeds.missilewars.arenas.Arena in project MissileWars by Leomelonseeds.
the class ArenaGameruleListener method onDeath.
/**
* Handle player deaths.
*/
@EventHandler
public void onDeath(PlayerDeathEvent event) {
// Check if player was killed in an Arena
Player player = event.getEntity();
ArenaManager manager = MissileWarsPlugin.getPlugin().getArenaManager();
Arena playerArena = manager.getArena(player.getUniqueId());
if (playerArena == null) {
player.setBedSpawnLocation(ConfigUtils.getSpawnLocation(), true);
return;
}
// Find killer and increment kills
if (player.getKiller() != null) {
MissileWarsPlayer killer = playerArena.getPlayerInArena(player.getKiller().getUniqueId());
killer.incrementKills();
ConfigUtils.sendConfigSound("player-kill", killer.getMCPlayer());
}
Component deathMessage = event.deathMessage();
event.setDeathMessage("");
// Count death if player is on a team
if (!playerArena.getTeam(player.getUniqueId()).equals("no team")) {
MissileWarsPlayer missileWarsPlayer = playerArena.getPlayerInArena(player.getUniqueId());
missileWarsPlayer.incrementDeaths();
for (Player p : player.getWorld().getPlayers()) {
p.sendMessage(deathMessage);
}
}
player.setBedSpawnLocation(playerArena.getPlayerSpawn(player), true);
}
use of com.leomelonseeds.missilewars.arenas.Arena in project MissileWars by Leomelonseeds.
the class ArenaGameruleListener method onEntityDamage.
/**
* Handle friendly fire.
*/
@EventHandler
public void onEntityDamage(EntityDamageByEntityEvent event) {
// Ensure we are handling a player in an arena
if (event.getEntityType() != EntityType.PLAYER) {
return;
}
Player player = (Player) event.getEntity();
ArenaManager arenaManager = MissileWarsPlugin.getPlugin().getArenaManager();
Arena arena = arenaManager.getArena(player.getUniqueId());
if ((arena == null) || !arena.isRunning()) {
return;
}
// Check if player is damaged by a player
Player damager = null;
if (event.getDamager().getType() == EntityType.PLAYER) {
damager = (Player) event.getDamager();
} else if (event.getDamager() instanceof Projectile) {
Projectile projectile = (Projectile) event.getDamager();
if (projectile.getShooter() instanceof Player) {
damager = (Player) projectile.getShooter();
}
}
if (damager == null) {
return;
}
// Stop event if damager and damaged are on same team
if (arena.getTeam(player.getUniqueId()).equalsIgnoreCase(arena.getTeam(damager.getUniqueId())) && !arena.getTeam(player.getUniqueId()).equalsIgnoreCase("no team")) {
event.setCancelled(true);
}
}
use of com.leomelonseeds.missilewars.arenas.Arena in project MissileWars by Leomelonseeds.
the class ArenaGameruleListener method onExplode.
/**
* Handle fireball and TNT explosions.
*/
@EventHandler
public void onExplode(EntityExplodeEvent event) {
// Ensure it was in an arena world
String possibleArenaName = event.getEntity().getWorld().getName().replace("mwarena_", "");
Arena possibleArena = MissileWarsPlugin.getPlugin().getArenaManager().getArena(possibleArenaName);
if (possibleArena == null) {
return;
}
// Check for shield breaks
event.blockList().forEach(block -> {
// Register shield breaking
possibleArena.registerShieldBlockEdit(block.getLocation(), false);
});
EntityType entity = event.getEntityType();
// Ensure its actually a fireball
if (entity == EntityType.FIREBALL) {
// Remove all portals from block list
event.blockList().removeIf(block -> block.getType() == Material.NETHER_PORTAL);
} else // Check for TNT explosions of portals
if (entity == EntityType.PRIMED_TNT || entity == EntityType.MINECART_TNT || entity == EntityType.CREEPER) {
event.blockList().forEach(block -> {
// Register portal brake if block was broken
if (block.getType() == Material.NETHER_PORTAL) {
possibleArena.registerPortalBreak(block.getLocation());
}
});
}
}
use of com.leomelonseeds.missilewars.arenas.Arena in project MissileWars by Leomelonseeds.
the class ArenaGameruleListener method onPlace.
/**
* Handle shield block breaks places.
*/
@EventHandler
public void onPlace(BlockPlaceEvent 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;
}
// Ain't no way bruh
if (block.getLocation().getBlockY() > MissileWarsPlugin.getPlugin().getConfig().getInt("max-height")) {
ConfigUtils.sendConfigMessage("messages.cannot-place-structure", event.getPlayer(), null, null);
event.setCancelled(true);
return;
}
// Register block break
possibleArena.registerShieldBlockEdit(block.getLocation(), true);
}
use of com.leomelonseeds.missilewars.arenas.Arena in project MissileWars by Leomelonseeds.
the class ArenaInventoryListener method selectArena.
/**
* Handle arena selection.
*/
@EventHandler
public void selectArena(InventoryClickEvent event) {
// Check if player is selecting an Arena
if (!(event.getWhoClicked() instanceof Player)) {
return;
}
Player player = (Player) event.getWhoClicked();
if (!selectingArena.contains(player)) {
return;
}
// Check for arena selection
event.setCancelled(true);
if (event.getClickedInventory() == null || !event.getClickedInventory().equals(event.getView().getTopInventory())) {
return;
}
ArenaManager manager = MissileWarsPlugin.getPlugin().getArenaManager();
Arena selectedArena = manager.getArena(event.getSlot());
if (selectedArena == null) {
return;
}
// Attempt to send player to arena
if (selectedArena.joinPlayer(player)) {
player.closeInventory();
} else {
ConfigUtils.sendConfigMessage("messages.arena-full", player, selectedArena, null);
}
}
Aggregations