Search in sources :

Example 1 with GamePlayer

use of pl.themolka.arcade.game.GamePlayer in project Arcade2 by ShootGame.

the class NobodyStrategy method getDominators.

@Override
public Multimap<Participator, GamePlayer> getDominators(Multimap<Participator, GamePlayer> competitors) {
    Multimap<Participator, GamePlayer> dominators = ArrayListMultimap.create();
    for (Map.Entry<Participator, Collection<GamePlayer>> entry : competitors.asMap().entrySet()) {
        Participator competitor = entry.getKey();
        Collection<GamePlayer> players = entry.getValue();
        int playerCount = players.size();
        int dominatorCount = 0;
        for (Map.Entry<Participator, Collection<GamePlayer>> dominator : dominators.asMap().entrySet()) {
            // All competitors have same player counts - break the loop.
            dominatorCount = dominator.getValue().size();
            break;
        }
        if (playerCount < dominatorCount) {
            continue;
        } else if (playerCount > dominatorCount) {
            // Do not clear the map when player counts are equal.
            dominators.clear();
        }
        dominators.putAll(competitor, players);
    }
    return dominators;
}
Also used : Participator(pl.themolka.arcade.game.Participator) GamePlayer(pl.themolka.arcade.game.GamePlayer) Collection(java.util.Collection) Map(java.util.Map)

Example 2 with GamePlayer

use of pl.themolka.arcade.game.GamePlayer in project Arcade2 by ShootGame.

the class WoolChestTracker method dontBreakWoolChests.

@Handler(priority = Priority.LOWEST)
public void dontBreakWoolChests(BlockTransformEvent event) {
    if (event.isCanceled()) {
        return;
    }
    Block block = event.getBlock();
    if (!block.getType().equals(Material.CHEST)) {
        return;
    }
    if (block.getState() instanceof InventoryHolder) {
        // Register the wool chest is we haven't seen it yet.
        this.registerWoolChest((InventoryHolder) block.getState());
    }
    ChestImage image = this.getChestImage(block);
    if (image != null && image.woolChest) {
        GamePlayer player = event.getGamePlayer();
        WoolChestBreakEvent breakEvent = new WoolChestBreakEvent(this.game.getPlugin(), block, player);
        // This event is canceled by default.
        breakEvent.setCanceled(true);
        this.game.getPlugin().getEventBus().publish(breakEvent);
        if (breakEvent.isCanceled()) {
            event.setCanceled(true);
            if (player != null) {
                player.sendError("You may not break wool chests.");
            }
        }
    }
}
Also used : GamePlayer(pl.themolka.arcade.game.GamePlayer) Block(org.bukkit.block.Block) InventoryHolder(org.bukkit.inventory.InventoryHolder) Handler(net.engio.mbassy.listener.Handler) EventHandler(org.bukkit.event.EventHandler)

Example 3 with GamePlayer

use of pl.themolka.arcade.game.GamePlayer in project Arcade2 by ShootGame.

the class WoolChestTracker method restoreWoolChests.

@EventHandler(priority = EventPriority.HIGHEST)
public void restoreWoolChests(InventoryCloseEvent event) {
    HumanEntity human = event.getPlayer();
    if (human instanceof Player) {
        GamePlayer player = this.game.getGame().getPlayer((Player) human);
        if (player == null) {
            return;
        }
        List<GamePlayer> viewers = new ArrayList<>();
        for (HumanEntity humanViewer : event.getViewers()) {
            if (humanViewer instanceof Player) {
                GamePlayer viewer = this.game.getGame().getPlayer((Player) humanViewer);
                if (viewer != null) {
                    viewers.add(viewer);
                }
            }
        }
        this.restoreWoolChest(event.getInventory().getHolder(), player, viewers);
    }
}
Also used : Player(org.bukkit.entity.Player) GamePlayer(pl.themolka.arcade.game.GamePlayer) GamePlayer(pl.themolka.arcade.game.GamePlayer) HumanEntity(org.bukkit.entity.HumanEntity) ArrayList(java.util.ArrayList) EventHandler(org.bukkit.event.EventHandler)

Example 4 with GamePlayer

use of pl.themolka.arcade.game.GamePlayer in project Arcade2 by ShootGame.

the class WoolPickupTracker method pickupBetweenInventories.

// 
// Listeners
// 
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void pickupBetweenInventories(InventoryClickEvent event) {
    HumanEntity human = event.getWhoClicked();
    if (human instanceof Player) {
        GamePlayer picker = this.game.getGame().getPlayer((Player) human);
        if (!picker.isParticipating()) {
            return;
        }
        ItemStack item = event.getCurrentItem();
        if (item != null && WoolUtils.isWool(item, this.wool.getColor())) {
            this.pickup(picker, item);
        }
    }
}
Also used : GamePlayer(pl.themolka.arcade.game.GamePlayer) Player(org.bukkit.entity.Player) GamePlayer(pl.themolka.arcade.game.GamePlayer) HumanEntity(org.bukkit.entity.HumanEntity) ItemStack(org.bukkit.inventory.ItemStack) EventHandler(org.bukkit.event.EventHandler)

Example 5 with GamePlayer

use of pl.themolka.arcade.game.GamePlayer in project Arcade2 by ShootGame.

the class WoolPickupTracker method pickupFromGround.

@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void pickupFromGround(PlayerPickupItemEvent event) {
    GamePlayer picker = this.game.getGame().getPlayer(event.getPlayer());
    if (picker == null || !picker.isParticipating()) {
        return;
    }
    ItemStack item = event.getItem().getItemStack();
    if (item != null && WoolUtils.isWool(item, this.wool.getColor())) {
        this.pickup(picker, item);
    }
}
Also used : GamePlayer(pl.themolka.arcade.game.GamePlayer) ItemStack(org.bukkit.inventory.ItemStack) EventHandler(org.bukkit.event.EventHandler)

Aggregations

GamePlayer (pl.themolka.arcade.game.GamePlayer)41 EventHandler (org.bukkit.event.EventHandler)17 Handler (net.engio.mbassy.listener.Handler)13 Player (org.bukkit.entity.Player)6 ItemStack (org.bukkit.inventory.ItemStack)5 Participator (pl.themolka.arcade.game.Participator)5 ArcadePlayer (pl.themolka.arcade.session.ArcadePlayer)5 Block (org.bukkit.block.Block)4 Game (pl.themolka.arcade.game.Game)4 ArrayList (java.util.ArrayList)3 CommandException (pl.themolka.arcade.command.CommandException)3 Map (java.util.Map)2 TextComponent (net.md_5.bungee.api.chat.TextComponent)2 Location (org.bukkit.Location)2 HumanEntity (org.bukkit.entity.HumanEntity)2 BossBar (pl.themolka.arcade.bossbar.BossBar)2 Observers (pl.themolka.arcade.match.Observers)2 SpawnApply (pl.themolka.arcade.spawn.SpawnApply)2 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1