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