Search in sources :

Example 26 with GamePlayer

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

the class MatchStartCountdown method onTick.

@Override
public void onTick(long ticks) {
    Game game = this.plugin.getGames().getCurrentGame();
    if (game == null) {
        return;
    } else if (this.getProgress() > 1) {
        return;
    }
    String message = this.getPrintMessage(this.getStartMessage());
    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) BossBar(pl.themolka.arcade.bossbar.BossBar)

Example 27 with GamePlayer

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

the class Point method heartbeat.

public void heartbeat(long ticks) {
    if (this.isPermanent() && this.isCompleted()) {
        return;
    }
    Match match = this.game.getMatch();
    Multimap<Participator, GamePlayer> competitors = ArrayListMultimap.create();
    for (GamePlayer player : this.getPlayers()) {
        if (this.canCapture(player) && this.canDominate(player)) {
            Participator competitor = match.findWinnerByPlayer(player);
            if (competitor != null && (competitor.equals(player) || this.canCapture(competitor))) {
                competitors.put(competitor, player);
            }
        }
    }
    Multimap<Participator, GamePlayer> dominators = this.getDominatorStrategy().getDominators(competitors);
    if (dominators == null) {
        dominators = DominatorStrategy.EMPTY_DOMINATORS;
    }
    List<Participator> canCapture = new ArrayList<>();
    for (Participator competitor : dominators.keySet()) {
        if (this.canCapture(competitor)) {
            canCapture.add(competitor);
        }
    }
    // Heartbeat the current state.
    Participator oldOwner = this.getOwner();
    this.getState().heartbeat(ticks, match, competitors, dominators, canCapture, oldOwner);
    Participator newOwner = this.getOwner();
    double pointReward = this.getPointReward();
    if (oldOwner != null && newOwner != null && oldOwner.equals(newOwner) && pointReward != Score.ZERO) {
        // Give reward points for owning the point.
        this.heartbeatReward(oldOwner, pointReward);
    }
}
Also used : Participator(pl.themolka.arcade.game.Participator) GamePlayer(pl.themolka.arcade.game.GamePlayer) ArrayList(java.util.ArrayList) Match(pl.themolka.arcade.match.Match)

Example 28 with GamePlayer

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

the class WoolChestTracker method restoreWoolChest.

private void restoreWoolChest(InventoryHolder inventoryHolder, GamePlayer player, List<GamePlayer> viewers) {
    if (inventoryHolder == null) {
        return;
    }
    Inventory inventory = inventoryHolder.getInventory();
    if (!player.isParticipating()) {
        return;
    } else if (inventoryHolder instanceof DoubleChest) {
        DoubleChest doubleChest = (DoubleChest) inventoryHolder;
        // restore both blocks
        this.restoreWoolChest(doubleChest.getLeftSide(), player, viewers);
        this.restoreWoolChest(doubleChest.getRightSide(), player, viewers);
        return;
    } else if (!(inventoryHolder instanceof BlockState)) {
        return;
    }
    Block block = ((BlockState) inventoryHolder).getBlock();
    ChestImage image = this.getChestImage(block);
    if (image == null || !image.woolChest || image.snapshot.isEmpty()) {
        return;
    }
    boolean restoreWools = true;
    // Don't retrace wools if there are players viewing this chest.
    for (GamePlayer viewer : viewers) {
        if (viewer.isParticipating() && !viewer.equals(player)) {
            restoreWools = false;
        }
    }
    if (restoreWools) {
        WoolChestRestoreEvent event = new WoolChestRestoreEvent(this.game.getPlugin(), block, inventory, player, viewers);
        this.game.getPlugin().getEventBus().publish(event);
        if (!event.isCanceled()) {
            inventory.clear();
            for (Map.Entry<Integer, ItemStack> entry : image.snapshot.entrySet()) {
                inventory.setItem(entry.getKey(), entry.getValue().clone());
            }
        }
    }
}
Also used : BlockState(org.bukkit.block.BlockState) GamePlayer(pl.themolka.arcade.game.GamePlayer) Block(org.bukkit.block.Block) DoubleChest(org.bukkit.block.DoubleChest) ItemStack(org.bukkit.inventory.ItemStack) HashMap(java.util.HashMap) Map(java.util.Map) Inventory(org.bukkit.inventory.Inventory)

Example 29 with GamePlayer

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

the class ChatChannel method sendChatMessage.

@Override
public int sendChatMessage(Sender author, String message) {
    int empty = 0;
    if (this.getPermission() != null && !author.hasPermission(this.getPermission())) {
        author.sendError(PERMISSION_ERROR);
        return empty;
    } else if (message.isEmpty()) {
        author.sendError(EMPTY_MESSAGE);
        return empty;
    }
    String name;
    if (author.isConsole()) {
        name = ConsoleSender.getConsoleColoredName();
    } else {
        GamePlayer player = author.getGamePlayer();
        name = player.hasDisplayName() ? player.getFullName() : player.getUsername();
    }
    // event
    ChannelMessageEvent event = new ChannelMessageEvent(this.plugin, this, author, name, message);
    this.plugin.getEventBus().publish(event);
    if (!event.isCanceled()) {
        return this.sendMessage(event.getAuthorName(), event.getMessage());
    }
    return empty;
}
Also used : GamePlayer(pl.themolka.arcade.game.GamePlayer)

Example 30 with GamePlayer

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

the class ProtectionListeners method antiLogout.

/**
 * Call a {@link PlayerDeathEvent} and handle this logout as a escape from
 * death by the enemy. If the player wasn't escaped the
 * {@link Player#getKiller()} returns null. This method is used to drop the
 * players items on the ground.
 */
@Handler(priority = Priority.LAST)
public void antiLogout(PlayerQuitEvent event) {
    GamePlayer player = event.getGamePlayer();
    Player bukkit = event.getBukkitPlayer();
    if (player != null && bukkit != null && player.isParticipating()) {
        PlayerDeathEvent death = new PlayerDeathEvent(bukkit, this.getDropsFor(bukkit), bukkit.getTotalExperience(), null);
        // call the fake event
        this.plugin.getServer().getPluginManager().callEvent(death);
    }
}
Also used : GamePlayer(pl.themolka.arcade.game.GamePlayer) Player(org.bukkit.entity.Player) GamePlayer(pl.themolka.arcade.game.GamePlayer) PlayerDeathEvent(org.bukkit.event.entity.PlayerDeathEvent) Handler(net.engio.mbassy.listener.Handler) 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