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