Search in sources :

Example 1 with Capturable

use of pl.themolka.arcade.capture.Capturable in project Arcade2 by ShootGame.

the class Wool method onWoolPlace.

@Handler(priority = Priority.HIGHER)
public void onWoolPlace(BlockTransformEvent event) {
    Block block = event.getBlock();
    if (!WoolUtils.isWool(block) || !this.getMonument().contains(block)) {
        return;
    }
    GamePlayer player = event.getGamePlayer();
    if (player == null) {
        // Endermans, TNTs and other entities are not permitted to place wools.
        event.setCanceled(true);
        return;
    }
    if (!WoolUtils.isWool(block, this.getColor())) {
        for (Capturable otherCapturable : this.game.getCapturables()) {
            if (otherCapturable instanceof Wool) {
                Wool otherWool = (Wool) otherCapturable;
                if (WoolUtils.isWool(block, otherWool.getColor()) && otherWool.getMonument().contains(block)) {
                    // This will be handled in its correct listener, return.
                    return;
                }
            }
        }
        event.setCanceled(true);
        player.sendError("Only " + this.getColoredName() + Messageable.ERROR_COLOR + " may be placed here!");
        return;
    }
    event.setCanceled(true);
    if (this.isCompleted()) {
        player.sendError(ChatColor.GOLD + this.getColoredName() + Messageable.ERROR_COLOR + " has already been captured!");
    } else if (this.hasOwner() && this.getOwner().contains(player)) {
        player.sendError("You may not capture your own " + ChatColor.GOLD + this.getColoredName() + Messageable.ERROR_COLOR + "!");
    } else {
        Participator competitor = this.game.getMatch().findWinnerByPlayer(player);
        if (competitor == null) {
            return;
        }
        WoolPlaceEvent placeEvent = new WoolPlaceEvent(this.game.getPlugin(), this, competitor, player);
        this.game.getPlugin().getEventBus().publish(placeEvent);
        if (placeEvent.isCanceled()) {
            return;
        }
        event.setCanceled(false);
        this.capture(placeEvent.getCompleter(), player);
    }
}
Also used : Capturable(pl.themolka.arcade.capture.Capturable) Participator(pl.themolka.arcade.game.Participator) GamePlayer(pl.themolka.arcade.game.GamePlayer) Block(org.bukkit.block.Block) Handler(net.engio.mbassy.listener.Handler) EventHandler(org.bukkit.event.EventHandler)

Example 2 with Capturable

use of pl.themolka.arcade.capture.Capturable in project Arcade2 by ShootGame.

the class FlagPayloadRender method onInventoryClick.

@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onInventoryClick(InventoryClickEvent event) {
    ItemStack item = event.getCurrentItem();
    for (Capturable capturable : this.game.getCapturables()) {
        if (capturable instanceof Flag && ((Flag) capturable).getItem().isSimilar(item)) {
            event.setCancelled(true);
            event.setResult(Event.Result.DENY);
            break;
        }
    }
}
Also used : Capturable(pl.themolka.arcade.capture.Capturable) ItemStack(org.bukkit.inventory.ItemStack) EventHandler(org.bukkit.event.EventHandler)

Aggregations

EventHandler (org.bukkit.event.EventHandler)2 Capturable (pl.themolka.arcade.capture.Capturable)2 Handler (net.engio.mbassy.listener.Handler)1 Block (org.bukkit.block.Block)1 ItemStack (org.bukkit.inventory.ItemStack)1 GamePlayer (pl.themolka.arcade.game.GamePlayer)1 Participator (pl.themolka.arcade.game.Participator)1