use of com.andrei1058.bedwars.api.language.Language in project BedWars1058 by andrei1058.
the class Arena method removePlayer.
/**
* Remove a player from the arena
*
* @param p Player to be removed
* @param disconnect True if the player was disconnected
*/
public void removePlayer(@NotNull Player p, boolean disconnect) {
if (leaving.contains(p)) {
return;
} else {
leaving.add(p);
}
debug("Player removed: " + p.getName() + " arena: " + getArenaName());
respawnSessions.remove(p);
ITeam team = null;
Arena.afkCheck.remove(p.getUniqueId());
BedWars.getAPI().getAFKUtil().setPlayerAFK(p, false);
if (getStatus() == GameState.playing) {
for (ITeam t : getTeams()) {
if (t.isMember(p)) {
team = t;
t.getMembers().remove(p);
// noinspection deprecation
t.destroyBedHolo(p);
}
}
}
List<ShopCache.CachedItem> cacheList = new ArrayList<>();
if (ShopCache.getShopCache(p.getUniqueId()) != null) {
// noinspection ConstantConditions
cacheList = ShopCache.getShopCache(p.getUniqueId()).getCachedPermanents();
}
LastHit lastHit = LastHit.getLastHit(p);
Player lastDamager = (lastHit == null) ? null : (lastHit.getDamager() instanceof Player) ? (Player) lastHit.getDamager() : null;
if (lastHit != null) {
// accept damager in last 13 seconds only.
if (lastHit.getTime() < System.currentTimeMillis() - 13_000) {
lastDamager = null;
}
}
Bukkit.getPluginManager().callEvent(new PlayerLeaveArenaEvent(p, this, lastDamager));
// players.remove must be under call event in order to check if the player is a spectator or not
players.remove(p);
removeArenaByPlayer(p, this);
for (PotionEffect pf : p.getActivePotionEffects()) {
p.removePotionEffect(pf.getType());
}
if (p.getPassenger() != null && p.getPassenger().getType() == EntityType.ARMOR_STAND)
p.getPassenger().remove();
boolean teamuri = false;
for (Player on : getPlayers()) {
if (getParty().hasParty(on)) {
teamuri = true;
}
}
if (status == GameState.starting && (maxInTeam > players.size() && teamuri || players.size() < minPlayers && !teamuri)) {
changeStatus(GameState.waiting);
for (Player on : players) {
on.sendMessage(getMsg(on, Messages.ARENA_START_COUNTDOWN_STOPPED_INSUFF_PLAYERS_CHAT));
}
} else if (status == GameState.playing) {
BedWars.debug("removePlayer debug1");
int alive_teams = 0;
for (ITeam t : getTeams()) {
if (t == null)
continue;
if (!t.getMembers().isEmpty()) {
alive_teams++;
}
}
if (alive_teams == 1 && !BedWars.isShuttingDown()) {
checkWinner();
Bukkit.getScheduler().runTaskLater(BedWars.plugin, () -> changeStatus(GameState.restarting), 10L);
if (team != null) {
if (!team.isBedDestroyed()) {
for (Player p2 : this.getPlayers()) {
p2.sendMessage(getMsg(p2, Messages.TEAM_ELIMINATED_CHAT).replace("{TeamColor}", team.getColor().chat().toString()).replace("{TeamName}", team.getDisplayName(Language.getPlayerLanguage(p2))));
}
for (Player p2 : this.getSpectators()) {
p2.sendMessage(getMsg(p2, Messages.TEAM_ELIMINATED_CHAT).replace("{TeamColor}", team.getColor().chat().toString()).replace("{TeamName}", team.getDisplayName(Language.getPlayerLanguage(p2))));
}
}
}
} else if (alive_teams == 0 && !BedWars.isShuttingDown()) {
Bukkit.getScheduler().runTaskLater(BedWars.plugin, () -> changeStatus(GameState.restarting), 10L);
} else if (!BedWars.isShuttingDown()) {
// ReJoin feature
new ReJoin(p, this, team, cacheList);
}
// pvp log out
if (team != null) {
ITeam killerTeam = getTeam(lastDamager);
if (lastDamager != null && isPlayer(lastDamager) && killerTeam != null) {
String message;
PlayerKillEvent.PlayerKillCause cause;
if (team.isBedDestroyed()) {
cause = PlayerKillEvent.PlayerKillCause.PLAYER_DISCONNECT_FINAL;
message = Messages.PLAYER_DIE_PVP_LOG_OUT_FINAL;
} else {
message = Messages.PLAYER_DIE_PVP_LOG_OUT_REGULAR;
cause = PlayerKillEvent.PlayerKillCause.PLAYER_DISCONNECT;
}
PlayerKillEvent event = new PlayerKillEvent(this, p, lastDamager, player -> Language.getMsg(player, message), cause);
for (Player inGame : getPlayers()) {
Language lang = Language.getPlayerLanguage(inGame);
inGame.sendMessage(event.getMessage().apply(inGame).replace("{PlayerTeamName}", team.getDisplayName(lang)).replace("{PlayerColor}", team.getColor().chat().toString()).replace("{PlayerName}", p.getDisplayName()).replace("{KillerColor}", killerTeam.getColor().chat().toString()).replace("{KillerName}", lastDamager.getDisplayName()).replace("{KillerTeamName}", killerTeam.getDisplayName(lang)));
}
for (Player inGame : getSpectators()) {
Language lang = Language.getPlayerLanguage(inGame);
inGame.sendMessage(event.getMessage().apply(inGame).replace("{PlayerTeamName}", team.getDisplayName(lang)).replace("{PlayerColor}", team.getColor().chat().toString()).replace("{PlayerName}", p.getDisplayName()).replace("{KillerColor}", killerTeam.getColor().chat().toString()).replace("{KillerName}", lastDamager.getDisplayName()).replace("{KillerTeamName}", killerTeam.getDisplayName(lang)));
}
PlayerDrops.handlePlayerDrops(this, p, lastDamager, team, killerTeam, cause, new ArrayList<>(Arrays.asList(p.getInventory().getContents())));
}
}
}
for (Player on : getPlayers()) {
on.sendMessage(getMsg(on, Messages.COMMAND_LEAVE_MSG).replace("{vPrefix}", getChatSupport().getPrefix(p)).replace("{vSuffix}", getChatSupport().getSuffix(p)).replace("{playername}", p.getName()).replace("{player}", p.getDisplayName()));
}
for (Player on : getSpectators()) {
on.sendMessage(getMsg(on, Messages.COMMAND_LEAVE_MSG).replace("{vPrefix}", getChatSupport().getPrefix(p)).replace("{playername}", p.getName()).replace("{player}", p.getDisplayName()));
}
if (getServerType() == ServerType.SHARED) {
BedWarsScoreboard sb = BedWarsScoreboard.getSBoard(p.getUniqueId());
if (sb != null) {
sb.remove();
}
this.sendToMainLobby(p);
} else if (getServerType() == ServerType.BUNGEE) {
Misc.moveToLobbyOrKick(p, this, true);
return;
} else {
this.sendToMainLobby(p);
}
/* restore player inventory */
PlayerGoods pg = PlayerGoods.getPlayerGoods(p);
if (pg == null) {
// if there is no previous backup of the inventory send lobby items if multi arena
if (BedWars.getServerType() == ServerType.MULTIARENA) {
// Send items
Arena.sendLobbyCommandItems(p);
}
} else {
pg.restore();
}
playerLocation.remove(p);
for (PotionEffect pf : p.getActivePotionEffects()) {
p.removePotionEffect(pf.getType());
}
if (!BedWars.isShuttingDown()) {
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, () -> {
for (Player on : Bukkit.getOnlinePlayers()) {
if (on.equals(p))
continue;
if (getArenaByPlayer(on) == null) {
BedWars.nms.spigotShowPlayer(p, on);
BedWars.nms.spigotShowPlayer(on, p);
} else {
BedWars.nms.spigotHidePlayer(p, on);
BedWars.nms.spigotHidePlayer(on, p);
}
}
if (!disconnect)
BedWarsScoreboard.giveScoreboard(p, null, false);
}, 5L);
}
/* Remove also the party */
if (getParty().hasParty(p)) {
if (getParty().isOwner(p)) {
if (status != GameState.restarting) {
if (getParty().isInternal()) {
for (Player mem : new ArrayList<>(getParty().getMembers(p))) {
mem.sendMessage(getMsg(mem, Messages.ARENA_LEAVE_PARTY_DISBANDED));
}
}
getParty().disband(p);
// prevent arena from staring with a single player
teamuri = false;
for (Player on : getPlayers()) {
if (getParty().hasParty(on)) {
teamuri = true;
}
}
if (status == GameState.starting && (maxInTeam > players.size() && teamuri || players.size() < minPlayers && !teamuri)) {
changeStatus(GameState.waiting);
for (Player on : players) {
on.sendMessage(getMsg(on, Messages.ARENA_START_COUNTDOWN_STOPPED_INSUFF_PLAYERS_CHAT));
}
}
}
}
}
p.setFlying(false);
p.setAllowFlight(false);
// Remove from ReJoin if game ended
if (status == GameState.restarting) {
if (ReJoin.exists(p)) {
// noinspection ConstantConditions
if (ReJoin.getPlayer(p).getArena() == this) {
// noinspection ConstantConditions
ReJoin.getPlayer(p).destroy(false);
}
}
}
// Remove from magic milk
if (magicMilk.containsKey(p.getUniqueId())) {
int taskId = magicMilk.remove(p.getUniqueId());
if (taskId > 0) {
Bukkit.getScheduler().cancelTask(taskId);
}
}
showTime.remove(p);
refreshSigns();
JoinNPC.updateNPCs(getGroup());
// remove player from party if leaves and the owner is still in the arena while waiting or starting
if (getStatus() == GameState.waiting || getStatus() == GameState.starting) {
if (BedWars.getParty().hasParty(p) && !BedWars.getParty().isOwner(p)) {
for (Player pl : BedWars.getParty().getMembers(p)) {
if (BedWars.getParty().isOwner(pl) && pl.getWorld().getName().equalsIgnoreCase(getArenaName())) {
BedWars.getParty().removeFromParty(p);
break;
}
}
}
}
if (lastHit != null) {
lastHit.remove();
}
}
use of com.andrei1058.bedwars.api.language.Language in project BedWars1058 by andrei1058.
the class Arena method setStatus.
/**
* Set game status without starting stats.
*/
public void setStatus(GameState status) {
if (this.status != GameState.playing && status == GameState.playing) {
startTime = Instant.now();
}
// if countdown cancelled
if (this.status == GameState.starting && status == GameState.waiting) {
for (Player player : getPlayers()) {
Language playerLang = Language.getPlayerLanguage(player);
nms.sendTitle(player, playerLang.m(Messages.ARENA_STATUS_START_COUNTDOWN_CANCELLED_TITLE), playerLang.m(Messages.ARENA_STATUS_START_COUNTDOWN_CANCELLED_SUB_TITLE), 0, 40, 0);
}
}
this.status = status;
}
use of com.andrei1058.bedwars.api.language.Language in project BedWars1058 by andrei1058.
the class GameStartingTask method run.
@Override
public void run() {
if (countdown == 0) {
if (BedWars.config.getBoolean(ConfigPath.GENERAL_CONFIGURATION_EXPERIMENTAL_TEAM_ASSIGNER)) {
getArena().getTeamAssigner().assignTeams(getArena());
} else {
LegacyTeamAssigner.assignTeams(getArena());
}
// Disable generators for empty teams if required
for (ITeam team : getArena().getTeams()) {
nms.colorBed(team);
if (team.getMembers().isEmpty()) {
team.setBedDestroyed(true);
if (getArena().getConfig().getBoolean(ConfigPath.ARENA_DISABLE_GENERATOR_FOR_EMPTY_TEAMS)) {
for (IGenerator gen : team.getGenerators()) {
gen.disable();
}
}
}
}
Bukkit.getScheduler().runTaskLater(BedWars.plugin, () -> {
// Enable diamond/ emerald generators
for (IGenerator og : getArena().getOreGenerators()) {
if (og.getType() == GeneratorType.EMERALD || og.getType() == GeneratorType.DIAMOND)
og.enableRotation();
}
}, 60L);
// Spawn players
spawnPlayers();
// Lobby removal
BedWars.getAPI().getRestoreAdapter().onLobbyRemoval(arena);
task.cancel();
getArena().changeStatus(GameState.playing);
// Check if emerald should be first based on time
if (getArena().getUpgradeDiamondsCount() < getArena().getUpgradeEmeraldsCount()) {
getArena().setNextEvent(NextEvent.DIAMOND_GENERATOR_TIER_II);
} else {
getArena().setNextEvent(NextEvent.EMERALD_GENERATOR_TIER_II);
}
// Spawn shopkeepers
for (ITeam bwt : getArena().getTeams()) {
bwt.spawnNPCs();
}
return;
}
// Send countdown
if (getCountdown() % 10 == 0 || getCountdown() <= 5) {
if (getCountdown() < 5) {
Sounds.playSound(ConfigPath.SOUNDS_COUNTDOWN_TICK_X + getCountdown(), getArena().getPlayers());
} else {
Sounds.playSound(ConfigPath.SOUNDS_COUNTDOWN_TICK, getArena().getPlayers());
}
for (Player player : getArena().getPlayers()) {
Language playerLang = Language.getPlayerLanguage(player);
String[] titleSubtitle = Language.getCountDownTitle(playerLang, getCountdown());
nms.sendTitle(player, titleSubtitle[0], titleSubtitle[1], 4, 22, 4);
player.sendMessage(getMsg(player, Messages.ARENA_STATUS_START_COUNTDOWN_CHAT).replace("{time}", String.valueOf(getCountdown())));
}
}
countdown--;
}
use of com.andrei1058.bedwars.api.language.Language in project BedWars1058 by andrei1058.
the class OreGenerator method enableRotation.
@Override
public void enableRotation() {
// loadDefaults(false);
// if (getType() == GeneratorType.EMERALD || getType() == GeneratorType.DIAMOND) {
rotation.add(this);
for (Language lan : Language.getLanguages()) {
IGenHolo h = armorStands.get(lan.getIso());
if (h == null) {
armorStands.put(lan.getIso(), new HoloGram(lan.getIso()));
}
}
for (IGenHolo hg : armorStands.values()) {
hg.updateForAll();
}
item = createArmorStand(null, location.clone().add(0, 0.5, 0));
item.setHelmet(new ItemStack(type == GeneratorType.DIAMOND ? Material.DIAMOND_BLOCK : Material.EMERALD_BLOCK));
// }
}
use of com.andrei1058.bedwars.api.language.Language in project BedWars1058 by andrei1058.
the class CmdLang method execute.
@Override
public boolean execute(String[] args, CommandSender s) {
if (s instanceof ConsoleCommandSender)
return false;
Player p = (Player) s;
if (Arena.getArenaByPlayer(p) != null)
return false;
if (args.length == 0) {
p.sendMessage(getMsg(p, Messages.COMMAND_LANG_LIST_HEADER));
for (Language l : Language.getLanguages()) {
p.sendMessage(getMsg(p, Messages.COMMAND_LANG_LIST_FORMAT).replace("{iso}", l.getIso()).replace("{name}", l.getLangName()));
}
p.sendMessage(getMsg(p, Messages.COMMAND_LANG_USAGE));
return true;
} else if (Language.isLanguageExist(args[0])) {
if (Arena.getArenaByPlayer(p) == null) {
if (Language.setPlayerLanguage(p.getUniqueId(), args[0])) {
Bukkit.getScheduler().runTaskLater(plugin, () -> p.sendMessage(getMsg(p, Messages.COMMAND_LANG_SELECTED_SUCCESSFULLY)), 3L);
} else {
p.sendMessage(getMsg(p, Messages.COMMAND_LANG_LIST_HEADER));
for (Language l : Language.getLanguages()) {
p.sendMessage(getMsg(p, Messages.COMMAND_LANG_LIST_FORMAT).replace("{iso}", l.getIso()).replace("{name}", l.getLangName()));
}
p.sendMessage(getMsg(p, Messages.COMMAND_LANG_USAGE));
return true;
}
} else {
p.sendMessage(getMsg(p, Messages.COMMAND_LANG_USAGE_DENIED));
}
} else {
p.sendMessage(getMsg(p, Messages.COMMAND_LANG_SELECTED_NOT_EXIST));
}
return true;
}
Aggregations