Search in sources :

Example 6 with Arena

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

the class CustomItemListener method getPlayerArena.

/**
 * Get the Arena the current player is in.
 *
 * @param player the player
 * @return the Arena the player is in
 */
private Arena getPlayerArena(Player player) {
    ArenaManager manager = MissileWarsPlugin.getPlugin().getArenaManager();
    Arena arena = manager.getArena(player.getUniqueId());
    return arena;
}
Also used : ArenaManager(com.leomelonseeds.missilewars.arenas.ArenaManager) Arena(com.leomelonseeds.missilewars.arenas.Arena)

Example 7 with Arena

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

the class CustomItemListener method architectLeaves.

// Check for architect leaves to despawn them after a while
@EventHandler
public void architectLeaves(BlockPlaceEvent event) {
    Player player = event.getPlayer();
    Arena playerArena = getPlayerArena(player);
    if ((playerArena == null) || !event.getItemInHand().getType().toString().contains("LEAVES")) {
        return;
    }
    playerArena.addLeaf(event.getBlockPlaced().getLocation(), player);
}
Also used : Player(org.bukkit.entity.Player) MissileWarsPlayer(com.leomelonseeds.missilewars.teams.MissileWarsPlayer) Arena(com.leomelonseeds.missilewars.arenas.Arena) EventHandler(org.bukkit.event.EventHandler)

Example 8 with Arena

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

the class CustomItemListener method handleUtilityCollisions.

/**
 * Utility should go through players
 */
@EventHandler
public void handleUtilityCollisions(ProjectileHitEvent event) {
    // Ensure we are tracking a utility thrown by a player
    if (!(event.getEntity().getType() == EntityType.SNOWBALL || event.getEntity().getType() == EntityType.EGG || event.getEntity().getType() == EntityType.ENDER_PEARL)) {
        return;
    }
    Projectile thrown = event.getEntity();
    // If it has a custom name, it definitely is a missile wars item
    if (!(thrown.getShooter() instanceof Player) || (thrown.getCustomName() == null)) {
        return;
    }
    // Make sure it's in an arena
    Player thrower = (Player) thrown.getShooter();
    Arena playerArena = getPlayerArena(thrower);
    if (playerArena == null) {
        return;
    }
    // Make them go through entities
    if (event.getHitEntity() != null) {
        event.setCancelled(true);
        return;
    }
}
Also used : 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 9 with Arena

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

the class CustomItemListener method useStructureItem.

/**
 * Handle missile and other structure item spawning.
 */
@EventHandler
public void useStructureItem(PlayerInteractEvent event) {
    // Check if player is trying to place a structure item
    MissileWarsPlugin plugin = MissileWarsPlugin.getPlugin();
    Player player = event.getPlayer();
    Arena playerArena = getPlayerArena(player);
    if (playerArena == null) {
        return;
    }
    ItemStack hand = getItemUsed(player);
    Block clicked = event.getClickedBlock();
    String structureName = getStructureFromItem(hand);
    if (structureName == null) {
        return;
    }
    // Switch to throwing logic if using a throwable
    if (structureName.contains("shield_") || structureName.contains("platform_") || structureName.contains("torpedo_") || structureName.contains("obsidian_")) {
        return;
    }
    // Stop if not left-click on block
    if (!event.getAction().toString().contains("RIGHT") || clicked == null) {
        return;
    }
    event.setCancelled(true);
    List<String> cancel = plugin.getConfig().getStringList("cancel-schematic");
    for (String s : cancel) {
        if (clicked.getType() == Material.getMaterial(s)) {
            ConfigUtils.sendConfigMessage("messages.cannot-place-structure", player, null, null);
            return;
        }
    }
    // Place structure
    String mapName = "default-map";
    if (playerArena.getMapName() != null) {
        mapName = playerArena.getMapName();
    }
    if (SchematicManager.spawnNBTStructure(structureName, clicked.getLocation(), isRedTeam(player), mapName)) {
        hand.setAmount(hand.getAmount() - 1);
        playerArena.getPlayerInArena(player.getUniqueId()).incrementMissiles();
    } else {
        ConfigUtils.sendConfigMessage("messages.cannot-place-structure", player, null, null);
    }
}
Also used : Player(org.bukkit.entity.Player) MissileWarsPlayer(com.leomelonseeds.missilewars.teams.MissileWarsPlayer) Block(org.bukkit.block.Block) ItemStack(org.bukkit.inventory.ItemStack) MissileWarsPlugin(com.leomelonseeds.missilewars.MissileWarsPlugin) Arena(com.leomelonseeds.missilewars.arenas.Arena) EventHandler(org.bukkit.event.EventHandler)

Example 10 with Arena

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

the class JoinLeaveListener method onWorldChange.

/**
 * Remove player from Arena if they leave the world.
 */
@EventHandler
public void onWorldChange(PlayerChangedWorldEvent event) {
    Player player = event.getPlayer();
    if (event.getFrom().getName().contains("mwarena")) {
        ArenaManager manager = MissileWarsPlugin.getPlugin().getArenaManager();
        Arena playerArena = manager.getArena(player.getUniqueId());
        if (playerArena == null || player.getWorld().equals(playerArena.getWorld())) {
            return;
        }
        // Check 1 tick later to make 100% sure
        Bukkit.getScheduler().runTaskLater(MissileWarsPlugin.getPlugin(), () -> {
            if (player.getWorld().getName().equals("world")) {
                playerArena.removePlayer(player.getUniqueId());
            }
        }, 1);
    }
}
Also used : ArenaManager(com.leomelonseeds.missilewars.arenas.ArenaManager) Player(org.bukkit.entity.Player) 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