Search in sources :

Example 6 with GamePlayer

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

the class Wool method onWoolCraft.

// 
// Listeners
// 
@EventHandler(ignoreCancelled = true)
public void onWoolCraft(PrepareItemCraftEvent event) {
    if (this.isCraftable()) {
        return;
    }
    ItemStack result = event.getInventory().getResult();
    if (result == null || !WoolUtils.isWool(result, this.color)) {
        return;
    }
    GamePlayer player = this.getGame().getPlayer(event.getActor());
    if (player != null) {
        player.sendError("You may not craft " + ChatColor.GOLD + this.getColoredName() + Messageable.ERROR_COLOR + ".");
    }
    event.getInventory().setResult(null);
}
Also used : GamePlayer(pl.themolka.arcade.game.GamePlayer) ItemStack(org.bukkit.inventory.ItemStack) EventHandler(org.bukkit.event.EventHandler)

Example 7 with GamePlayer

use of pl.themolka.arcade.game.GamePlayer 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 8 with GamePlayer

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

the class ChannelListeners method onChannelMention.

@Handler(priority = Priority.LOW)
public void onChannelMention(ChannelMessageEvent event) {
    if (event.isCanceled()) {
        return;
    }
    int mentioned = 0;
    for (String split : event.getMessage().split(" ")) {
        if (mentioned >= CHANNEL_MENTION_LIMIT || !split.startsWith(CHANNEL_MENTION_KEY)) {
            break;
        }
        String username = split.substring(1);
        if (username.isEmpty() || username.length() < ArcadePlayer.USERNAME_MIN_LENGTH || username.length() > ArcadePlayer.USERNAME_MAX_LENGTH) {
            continue;
        }
        GamePlayer player = this.game.getGame().findPlayer(username);
        if (player == null) {
            continue;
        } else if (!event.getChannel().hasMember(player)) {
            event.getAuthor().sendError("Player " + player.getFullName() + ChatColor.RED + " is not a member of this channel.");
            continue;
        }
        event.setMessage(event.getMessage().replace(split, player.getFullName()));
        // notify
        player.sendInfo("You have been mentioned by " + event.getAuthorName());
        player.getPlayer().play(ArcadeSound.CHAT_MENTION);
        mentioned++;
    }
}
Also used : GamePlayer(pl.themolka.arcade.game.GamePlayer) EventHandler(org.bukkit.event.EventHandler) Handler(net.engio.mbassy.listener.Handler)

Example 9 with GamePlayer

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

the class CycleCountdown method onTick.

@Override
public void onTick(long ticks) {
    if (!this.plugin.getGames().getQueue().hasNextMap()) {
        this.cancelCountdown();
        return;
    } else if (this.getProgress() > 1) {
        return;
    }
    OfflineMap nextMap = this.plugin.getGames().getQueue().getNextMap();
    Game game = this.plugin.getGames().getCurrentGame();
    if (game == null) {
        return;
    }
    String message = this.getPrintMessage(this.getCycleMessage(nextMap.getName()));
    BossBar bossBar = this.getBossBar();
    bossBar.setProgress(Percentage.finite(this.getProgress()));
    bossBar.setText(new TextComponent(message));
    for (ArcadePlayer online : this.plugin.getPlayers()) {
        GamePlayer player = online.getGamePlayer();
        if (player != null) {
            bossBar.addPlayer(player, BAR_PRIORITY);
        }
    }
}
Also used : TextComponent(net.md_5.bungee.api.chat.TextComponent) Game(pl.themolka.arcade.game.Game) ArcadePlayer(pl.themolka.arcade.session.ArcadePlayer) GamePlayer(pl.themolka.arcade.game.GamePlayer) OfflineMap(pl.themolka.arcade.map.OfflineMap) BossBar(pl.themolka.arcade.bossbar.BossBar)

Example 10 with GamePlayer

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

the class LivesGame method eliminate.

public void eliminate(GamePlayer player, Team fallbackTeam) {
    if (this.remaining.containsKey(player)) {
        PlayerEliminateEvent event = new PlayerEliminateEvent(this.getPlugin(), player, this.remaining.getOrDefault(player, ZERO), player.getBukkit().getLocation());
        this.getPlugin().getEventBus().publish(event);
        if (event.isCanceled() && fallbackTeam != null) {
            this.remaining.put(event.getPlayer(), event.getRemainingLives());
            return;
        }
        GamePlayer eventPlayer = event.getPlayer();
        this.remaining.remove(eventPlayer);
        this.eliminated.add(eventPlayer);
        if (fallbackTeam != null) {
            fallbackTeam.join(eventPlayer, true, true);
        }
        // I don't know if it should be done here.
        this.match.refreshWinners();
    }
}
Also used : GamePlayer(pl.themolka.arcade.game.GamePlayer)

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