Search in sources :

Example 1 with Arena

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);
}
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) Component(net.kyori.adventure.text.Component) Arena(com.leomelonseeds.missilewars.arenas.Arena) EventHandler(org.bukkit.event.EventHandler)

Example 2 with Arena

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);
    }
}
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) Projectile(org.bukkit.entity.Projectile) EventHandler(org.bukkit.event.EventHandler)

Example 3 with Arena

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());
            }
        });
    }
}
Also used : EntityType(org.bukkit.entity.EntityType) ArenaManager(com.leomelonseeds.missilewars.arenas.ArenaManager) PortalCreateEvent(org.bukkit.event.world.PortalCreateEvent) Projectile(org.bukkit.entity.Projectile) Arena(com.leomelonseeds.missilewars.arenas.Arena) Player(org.bukkit.entity.Player) EventHandler(org.bukkit.event.EventHandler) Block(org.bukkit.block.Block) Component(net.kyori.adventure.text.Component) MissileWarsPlayer(com.leomelonseeds.missilewars.teams.MissileWarsPlayer) SpawnReason(org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason) Material(org.bukkit.Material) BlockPlaceEvent(org.bukkit.event.block.BlockPlaceEvent) EntityDamageByEntityEvent(org.bukkit.event.entity.EntityDamageByEntityEvent) EntityDamageEvent(org.bukkit.event.entity.EntityDamageEvent) Listener(org.bukkit.event.Listener) DamageCause(org.bukkit.event.entity.EntityDamageEvent.DamageCause) TeleportCause(org.bukkit.event.player.PlayerTeleportEvent.TeleportCause) CreatureSpawnEvent(org.bukkit.event.entity.CreatureSpawnEvent) BlockBreakEvent(org.bukkit.event.block.BlockBreakEvent) EntityType(org.bukkit.entity.EntityType) PlayerPostRespawnEvent(com.destroystokyo.paper.event.player.PlayerPostRespawnEvent) PlayerDeathEvent(org.bukkit.event.entity.PlayerDeathEvent) ConfigUtils(com.leomelonseeds.missilewars.utilities.ConfigUtils) FoodLevelChangeEvent(org.bukkit.event.entity.FoodLevelChangeEvent) PlayerTeleportEvent(org.bukkit.event.player.PlayerTeleportEvent) MissileWarsPlugin(com.leomelonseeds.missilewars.MissileWarsPlugin) EntityExplodeEvent(org.bukkit.event.entity.EntityExplodeEvent) Arena(com.leomelonseeds.missilewars.arenas.Arena) EventHandler(org.bukkit.event.EventHandler)

Example 4 with Arena

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);
}
Also used : Block(org.bukkit.block.Block) Arena(com.leomelonseeds.missilewars.arenas.Arena) EventHandler(org.bukkit.event.EventHandler)

Example 5 with Arena

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