Search in sources :

Example 1 with BedWarsTeam

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"));
            }
        }
    }
}
Also used : ShopHolo(com.andrei1058.bedwars.api.arena.shop.ShopHolo) IArena(com.andrei1058.bedwars.api.arena.IArena) IGenerator(com.andrei1058.bedwars.api.arena.generator.IGenerator) ITeam(com.andrei1058.bedwars.api.arena.team.ITeam) BedWarsTeam(com.andrei1058.bedwars.arena.team.BedWarsTeam) EventHandler(org.bukkit.event.EventHandler)

Example 2 with BedWarsTeam

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");
}
Also used : JoinNPC(com.andrei1058.bedwars.support.citizens.JoinNPC) ClickEvent(net.md_5.bungee.api.chat.ClickEvent) Player(org.bukkit.entity.Player) org.bukkit(org.bukkit) GameStartingTask(com.andrei1058.bedwars.arena.tasks.GameStartingTask) ShopHolo(com.andrei1058.bedwars.api.arena.shop.ShopHolo) ArenaRestartEvent(com.andrei1058.bedwars.api.events.server.ArenaRestartEvent) Block(org.bukkit.block.Block) GameState(com.andrei1058.bedwars.api.arena.GameState) GameRestartingTask(com.andrei1058.bedwars.arena.tasks.GameRestartingTask) PlayerDrops(com.andrei1058.bedwars.listeners.dropshandler.PlayerDrops) PlayerJoinArenaEvent(com.andrei1058.bedwars.api.events.player.PlayerJoinArenaEvent) NextEvent(com.andrei1058.bedwars.api.arena.NextEvent) BlockStatusListener(com.andrei1058.bedwars.listeners.blockstatus.BlockStatusListener) Sign(org.bukkit.block.Sign) StartingTask(com.andrei1058.bedwars.api.tasks.StartingTask) NextEventChangeEvent(com.andrei1058.bedwars.api.events.gameplay.NextEventChangeEvent) Entity(org.bukkit.entity.Entity) TeamAssigner(com.andrei1058.bedwars.arena.team.TeamAssigner) PerMinuteTask(com.andrei1058.bedwars.levels.internal.PerMinuteTask) PlayingTask(com.andrei1058.bedwars.api.tasks.PlayingTask) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Despawnable(com.andrei1058.bedwars.api.entity.Despawnable) EntityType(org.bukkit.entity.EntityType) Instant(java.time.Instant) ItemStack(org.bukkit.inventory.ItemStack) ArenaDisableEvent(com.andrei1058.bedwars.api.events.server.ArenaDisableEvent) GameEndEvent(com.andrei1058.bedwars.api.events.gameplay.GameEndEvent) MoneyPerMinuteTask(com.andrei1058.bedwars.money.internal.MoneyPerMinuteTask) IArena(com.andrei1058.bedwars.api.arena.IArena) ReJoinTask(com.andrei1058.bedwars.arena.tasks.ReJoinTask) BaseListener.isOnABase(com.andrei1058.bedwars.arena.upgrades.BaseListener.isOnABase) NotNull(org.jetbrains.annotations.NotNull) PotionEffectType(org.bukkit.potion.PotionEffectType) WithEconomy(com.andrei1058.bedwars.support.vault.WithEconomy) TeamColor(com.andrei1058.bedwars.api.arena.team.TeamColor) PlayerLeaveArenaEvent(com.andrei1058.bedwars.api.events.player.PlayerLeaveArenaEvent) ServerType(com.andrei1058.bedwars.api.server.ServerType) java.util(java.util) SupportPAPI(com.andrei1058.bedwars.support.papi.SupportPAPI) ArenaConfig(com.andrei1058.bedwars.configuration.ArenaConfig) Level(java.util.logging.Level) TextComponent(net.md_5.bungee.api.chat.TextComponent) PlayerReJoinEvent(com.andrei1058.bedwars.api.events.player.PlayerReJoinEvent) PlayerKillEvent(com.andrei1058.bedwars.api.events.player.PlayerKillEvent) Language(com.andrei1058.bedwars.api.language.Language) BedWars(com.andrei1058.bedwars.BedWars) BedWarsTeam(com.andrei1058.bedwars.arena.team.BedWarsTeam) ITeam(com.andrei1058.bedwars.api.arena.team.ITeam) BukkitScheduler(org.bukkit.scheduler.BukkitScheduler) Region(com.andrei1058.bedwars.api.region.Region) ShopCache(com.andrei1058.bedwars.shop.ShopCache) ITeamAssigner(com.andrei1058.bedwars.api.arena.team.ITeamAssigner) GamePlayingTask(com.andrei1058.bedwars.arena.tasks.GamePlayingTask) Sounds(com.andrei1058.bedwars.configuration.Sounds) IGenerator(com.andrei1058.bedwars.api.arena.generator.IGenerator) GeneratorType(com.andrei1058.bedwars.api.arena.generator.GeneratorType) Messages(com.andrei1058.bedwars.api.language.Messages) File(java.io.File) PotionEffect(org.bukkit.potion.PotionEffect) BedWarsScoreboard(com.andrei1058.bedwars.sidebar.BedWarsScoreboard) Vector(org.bukkit.util.Vector) ConfigPath(com.andrei1058.bedwars.api.configuration.ConfigPath) RestartingTask(com.andrei1058.bedwars.api.tasks.RestartingTask) InternalLevel(com.andrei1058.bedwars.levels.internal.InternalLevel) PlayerTeleportEvent(org.bukkit.event.player.PlayerTeleportEvent) YamlConfiguration(org.bukkit.configuration.file.YamlConfiguration) ArenaEnableEvent(com.andrei1058.bedwars.api.events.server.ArenaEnableEvent) ArmorStand(org.bukkit.entity.ArmorStand) GameStateChangeEvent(com.andrei1058.bedwars.api.events.gameplay.GameStateChangeEvent) Entity(org.bukkit.entity.Entity) NextEvent(com.andrei1058.bedwars.api.arena.NextEvent) BedWarsTeam(com.andrei1058.bedwars.arena.team.BedWarsTeam) YamlConfiguration(org.bukkit.configuration.file.YamlConfiguration) ArenaEnableEvent(com.andrei1058.bedwars.api.events.server.ArenaEnableEvent) File(java.io.File)

Aggregations

IArena (com.andrei1058.bedwars.api.arena.IArena)2 IGenerator (com.andrei1058.bedwars.api.arena.generator.IGenerator)2 ShopHolo (com.andrei1058.bedwars.api.arena.shop.ShopHolo)2 ITeam (com.andrei1058.bedwars.api.arena.team.ITeam)2 BedWarsTeam (com.andrei1058.bedwars.arena.team.BedWarsTeam)2 BedWars (com.andrei1058.bedwars.BedWars)1 GameState (com.andrei1058.bedwars.api.arena.GameState)1 NextEvent (com.andrei1058.bedwars.api.arena.NextEvent)1 GeneratorType (com.andrei1058.bedwars.api.arena.generator.GeneratorType)1 ITeamAssigner (com.andrei1058.bedwars.api.arena.team.ITeamAssigner)1 TeamColor (com.andrei1058.bedwars.api.arena.team.TeamColor)1 ConfigPath (com.andrei1058.bedwars.api.configuration.ConfigPath)1 Despawnable (com.andrei1058.bedwars.api.entity.Despawnable)1 GameEndEvent (com.andrei1058.bedwars.api.events.gameplay.GameEndEvent)1 GameStateChangeEvent (com.andrei1058.bedwars.api.events.gameplay.GameStateChangeEvent)1 NextEventChangeEvent (com.andrei1058.bedwars.api.events.gameplay.NextEventChangeEvent)1 PlayerJoinArenaEvent (com.andrei1058.bedwars.api.events.player.PlayerJoinArenaEvent)1 PlayerKillEvent (com.andrei1058.bedwars.api.events.player.PlayerKillEvent)1 PlayerLeaveArenaEvent (com.andrei1058.bedwars.api.events.player.PlayerLeaveArenaEvent)1 PlayerReJoinEvent (com.andrei1058.bedwars.api.events.player.PlayerReJoinEvent)1