use of com.andrei1058.bedwars.arena.team.BedWarsTeam in project BedWars1058 by andrei1058.
the class DamageDeathMove method onMove.
@EventHandler
public void onMove(PlayerMoveEvent e) {
if (Arena.isInArena(e.getPlayer())) {
IArena a = Arena.getArenaByPlayer(e.getPlayer());
if (e.getFrom().getChunk() != e.getTo().getChunk()) {
/* update armor-stands hidden by nms */
String iso = Language.getPlayerLanguage(e.getPlayer()).getIso();
for (IGenerator o : a.getOreGenerators()) {
o.updateHolograms(e.getPlayer(), iso);
}
for (ITeam t : a.getTeams()) {
for (IGenerator o : t.getGenerators()) {
o.updateHolograms(e.getPlayer(), iso);
}
}
for (ShopHolo sh : ShopHolo.getShopHolo()) {
if (sh.getA() == a) {
sh.updateForPlayer(e.getPlayer(), iso);
}
}
// hide armor for those with invisibility potions
if (!a.getShowTime().isEmpty()) {
// generic hide packets
for (Map.Entry<Player, Integer> entry : a.getShowTime().entrySet()) {
if (entry.getValue() > 1) {
BedWars.nms.hideArmor(entry.getKey(), e.getPlayer());
}
}
// if the moving player has invisible armor
if (a.getShowTime().containsKey(e.getPlayer())) {
for (Player p : a.getPlayers()) {
nms.hideArmor(e.getPlayer(), p);
}
}
if (a.getShowTime().containsKey(e.getPlayer())) {
for (Player p : a.getSpectators()) {
nms.hideArmor(e.getPlayer(), p);
}
}
}
}
if (a.isSpectator(e.getPlayer()) || a.isReSpawning(e.getPlayer())) {
if (e.getTo().getY() < 0) {
e.getPlayer().teleport(a.isSpectator(e.getPlayer()) ? a.getSpectatorLocation() : a.getReSpawnLocation(), PlayerTeleportEvent.TeleportCause.PLUGIN);
e.getPlayer().setAllowFlight(true);
e.getPlayer().setFlying(true);
// how to remove fall velocity?
}
} else {
if (a.getStatus() == GameState.playing) {
if (e.getPlayer().getLocation().getBlockY() <= a.getYKillHeight()) {
nms.voidKill(e.getPlayer());
}
for (ITeam t : a.getTeams()) {
if (e.getPlayer().getLocation().distance(t.getBed()) < 4) {
if (t.isMember(e.getPlayer()) && t instanceof BedWarsTeam) {
if (((BedWarsTeam) t).getBedHolo(e.getPlayer()) == null)
continue;
if (!((BedWarsTeam) t).getBedHolo(e.getPlayer()).isHidden()) {
((BedWarsTeam) t).getBedHolo(e.getPlayer()).hide();
}
}
} else {
if (t.isMember(e.getPlayer()) && t instanceof BedWarsTeam) {
if (((BedWarsTeam) t).getBedHolo(e.getPlayer()) == null)
continue;
if (((BedWarsTeam) t).getBedHolo(e.getPlayer()).isHidden()) {
((BedWarsTeam) t).getBedHolo(e.getPlayer()).show();
}
}
}
}
if (e.getFrom() != e.getTo()) {
Arena.afkCheck.remove(e.getPlayer().getUniqueId());
BedWars.getAPI().getAFKUtil().setPlayerAFK(e.getPlayer(), false);
}
} else {
if (e.getPlayer().getLocation().getBlockY() <= 0) {
ITeam bwt = a.getTeam(e.getPlayer());
if (bwt != null) {
e.getPlayer().teleport(bwt.getSpawn());
} else {
e.getPlayer().teleport(a.getSpectatorLocation());
}
}
}
}
} else {
if (e.getPlayer().getWorld().getName().equalsIgnoreCase(config.getLobbyWorldName()) && BedWars.getServerType() == ServerType.MULTIARENA) {
if (e.getTo().getY() < 0) {
e.getPlayer().teleport(config.getConfigLoc("lobbyLoc"));
}
}
}
}
use of com.andrei1058.bedwars.arena.team.BedWarsTeam in project BedWars1058 by andrei1058.
the class Arena method init.
/**
* Use this method when the world was loaded successfully.
*/
@Override
public void init(World world) {
if (!autoscale) {
if (getArenaByName(arenaName) != null)
return;
}
removeFromEnableQueue(this);
debug("Initialized arena " + getArenaName() + " with map " + world.getName());
this.world = world;
this.worldName = world.getName();
getConfig().setName(worldName);
world.getEntities().stream().filter(e -> e.getType() != EntityType.PLAYER).filter(e -> e.getType() != EntityType.PAINTING).filter(e -> e.getType() != EntityType.ITEM_FRAME).forEach(Entity::remove);
for (String s : getConfig().getList(ConfigPath.ARENA_GAME_RULES)) {
String[] rule = s.split(":");
if (rule.length == 2)
world.setGameRuleValue(rule[0], rule[1]);
}
world.setAutoSave(false);
/* Clear setup armor-stands */
for (Entity e : world.getEntities()) {
if (e.getType() == EntityType.ARMOR_STAND) {
if (!((ArmorStand) e).isVisible())
e.remove();
}
}
// Create teams
for (String team : yml.getConfigurationSection("Team").getKeys(false)) {
if (getTeam(team) != null) {
BedWars.plugin.getLogger().severe("A team with name: " + team + " was already loaded for arena: " + getArenaName());
continue;
}
BedWarsTeam bwt = new BedWarsTeam(team, TeamColor.valueOf(yml.getString("Team." + team + ".Color").toUpperCase()), cm.getArenaLoc("Team." + team + ".Spawn"), cm.getArenaLoc("Team." + team + ".Bed"), cm.getArenaLoc("Team." + team + ".Shop"), cm.getArenaLoc("Team." + team + ".Upgrade"), this);
teams.add(bwt);
bwt.spawnGenerators();
}
// Load diamond/ emerald generators
Location location;
for (String type : Arrays.asList("Diamond", "Emerald")) {
if (yml.get("generator." + type) != null) {
for (String s : yml.getStringList("generator." + type)) {
location = cm.convertStringToArenaLocation(s);
if (location == null) {
plugin.getLogger().severe("Invalid location for " + type + " generator: " + s);
continue;
}
oreGenerators.add(new OreGenerator(location, this, GeneratorType.valueOf(type.toUpperCase()), null));
}
}
}
arenas.add(this);
arenaByName.put(getArenaName(), this);
arenaByIdentifier.put(worldName, this);
world.getWorldBorder().setCenter(cm.getArenaLoc("waiting.Loc"));
world.getWorldBorder().setSize(yml.getInt("worldBorder"));
/* Check if lobby removal is set */
if (!getConfig().getYml().isSet(ConfigPath.ARENA_WAITING_POS1) && getConfig().getYml().isSet(ConfigPath.ARENA_WAITING_POS2)) {
plugin.getLogger().severe("Lobby Pos1 isn't set! The arena's lobby won't be removed!");
}
if (getConfig().getYml().isSet(ConfigPath.ARENA_WAITING_POS1) && !getConfig().getYml().isSet(ConfigPath.ARENA_WAITING_POS2)) {
plugin.getLogger().severe("Lobby Pos2 isn't set! The arena's lobby won't be removed!");
}
/* Register arena signs */
registerSigns();
// Call event
Bukkit.getPluginManager().callEvent(new ArenaEnableEvent(this));
// Re Spawn Session Location
respawnLocation = cm.getArenaLoc(ConfigPath.ARENA_SPEC_LOC);
if (respawnLocation == null) {
respawnLocation = cm.getArenaLoc("waiting.Loc");
}
if (respawnLocation == null) {
respawnLocation = world.getSpawnLocation();
}
//
// Spectator location
spectatorLocation = cm.getArenaLoc(ConfigPath.ARENA_SPEC_LOC);
if (spectatorLocation == null) {
spectatorLocation = cm.getArenaLoc("waiting.Loc");
}
if (spectatorLocation == null) {
spectatorLocation = world.getSpawnLocation();
}
//
// Waiting location
waitingLocation = cm.getArenaLoc("waiting.Loc");
if (waitingLocation == null) {
waitingLocation = world.getSpawnLocation();
}
//
changeStatus(GameState.waiting);
//
for (NextEvent ne : NextEvent.values()) {
nextEvents.add(ne.toString());
}
upgradeDiamondsCount = getGeneratorsCfg().getInt(getGeneratorsCfg().getYml().get(getGroup() + "." + ConfigPath.GENERATOR_DIAMOND_TIER_II_START) == null ? "Default." + ConfigPath.GENERATOR_DIAMOND_TIER_II_START : getGroup() + "." + ConfigPath.GENERATOR_DIAMOND_TIER_II_START);
upgradeEmeraldsCount = getGeneratorsCfg().getInt(getGeneratorsCfg().getYml().get(getGroup() + "." + ConfigPath.GENERATOR_EMERALD_TIER_II_START) == null ? "Default." + ConfigPath.GENERATOR_EMERALD_TIER_II_START : getGroup() + "." + ConfigPath.GENERATOR_EMERALD_TIER_II_START);
plugin.getLogger().info("Load done: " + getArenaName());
// entity tracking range - player
YamlConfiguration yaml = YamlConfiguration.loadConfiguration(new File("spigot.yml"));
renderDistance = yaml.get("world-settings." + getWorldName() + ".entity-tracking-range.players") == null ? yaml.getInt("world-settings.default.entity-tracking-range.players") : yaml.getInt("world-settings." + getWorldName() + ".entity-tracking-range.players");
}
Aggregations