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);
}
}
}
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);
}
}
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());
}
}
}
}
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;
}
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);
}
}
Aggregations