Search in sources :

Example 11 with Game

use of com.ebicep.warlords.game.Game in project Warlords by ebicep.

the class DebugMenuPlayerOptions method openPlayerMenu.

public static void openPlayerMenu(Player player, WarlordsPlayer target) {
    if (target == null)
        return;
    String targetName = target.getName();
    Menu menu = new Menu("Player Options: " + targetName, 9 * 5);
    ItemStack[] firstRow = { new ItemBuilder(Material.EXP_BOTTLE).name(ChatColor.GREEN + "Energy").get(), new ItemBuilder(Material.INK_SACK, 1, (byte) 8).name(ChatColor.GREEN + "Cooldown").get(), new ItemBuilder(Material.DIAMOND_CHESTPLATE).name(ChatColor.GREEN + "Damage").get(), new ItemBuilder(Material.RABBIT_FOOT).name(ChatColor.GREEN + "Crits").get(), new ItemBuilder(Material.AIR).get(), new ItemBuilder(new Potion(PotionType.INSTANT_DAMAGE), 1, true).name(ChatColor.GREEN + "Kill").flags(ItemFlag.HIDE_POTION_EFFECTS).get(), new ItemBuilder(Material.WOOL, 1, (short) (Warlords.getPlayerSettings(player.getUniqueId()).getWantedTeam() == Team.BLUE ? 14 : 11)).name(ChatColor.GREEN + "Swap to the " + (Warlords.getPlayerSettings(player.getUniqueId()).getWantedTeam() == Team.BLUE ? Team.RED.coloredPrefix() : Team.BLUE.coloredPrefix()) + ChatColor.GREEN + " team").get() };
    ItemStack[] secondRow = { new ItemBuilder(Material.SUGAR).name(ChatColor.GREEN + "Modify Speed").get(), new ItemBuilder(new Potion(PotionType.INSTANT_HEAL), 1, true).name(ChatColor.GREEN + "Add Health").flags(ItemFlag.HIDE_POTION_EFFECTS).get(), new ItemBuilder(Material.DIAMOND_SWORD).name(ChatColor.GREEN + "Take Damage").flags(ItemFlag.HIDE_ATTRIBUTES).get(), new ItemBuilder(Material.BREWING_STAND_ITEM).name(ChatColor.GREEN + "Cooldowns").get(), new ItemBuilder(Material.EYE_OF_ENDER).name(ChatColor.GREEN + "Teleport To").get(), new ItemBuilder(Material.BANNER).name(ChatColor.GREEN + "Flag Options").get(), new ItemBuilder(Material.NETHER_STAR).name(ChatColor.GREEN + "Change Spec").get() };
    for (int i = 0; i < firstRow.length; i++) {
        int index = i + 1;
        menu.setItem(index, 1, firstRow[i], (m, e) -> {
            switch(index) {
                case 1:
                    Bukkit.getServer().dispatchCommand(player, "wl energy " + (target.isInfiniteEnergy() ? "enable" : "disable") + " " + targetName);
                    break;
                case 2:
                    Bukkit.getServer().dispatchCommand(player, "wl cooldown " + (target.isDisableCooldowns() ? "enable" : "disable") + " " + targetName);
                    break;
                case 3:
                    Bukkit.getServer().dispatchCommand(player, "wl damage " + (target.isTakeDamage() ? "disable" : "enable") + " " + targetName);
                    break;
                case 4:
                    Bukkit.getServer().dispatchCommand(player, "wl crits " + (target.isCanCrit() ? "disable" : "enable") + " " + targetName);
                    break;
                case 6:
                    Bukkit.getServer().dispatchCommand(player, "kill " + targetName);
                    break;
                case 7:
                    Game game = target.getGame();
                    Team currentTeam = target.getTeam();
                    Team otherTeam = target.getTeam().enemy();
                    game.setPlayerTeam(player, otherTeam);
                    target.setTeam(otherTeam);
                    target.getGameState().updatePlayerName(target);
                    Warlords.getPlayerSettings(target.getUuid()).setWantedTeam(otherTeam);
                    LobbyLocationMarker randomLobbyLocation = LobbyLocationMarker.getRandomLobbyLocation(game, otherTeam);
                    if (randomLobbyLocation != null) {
                        Location teleportDestination = MapSymmetryMarker.getSymmetry(game).getOppositeLocation(game, currentTeam, otherTeam, target.getLocation(), randomLobbyLocation.getLocation());
                        target.teleport(teleportDestination);
                    }
                    ArmorManager.resetArmor(Bukkit.getPlayer(target.getUuid()), Warlords.getPlayerSettings(target.getUuid()).getSelectedClass(), otherTeam);
                    player.sendMessage(ChatColor.RED + "DEV: " + currentTeam.teamColor() + target.getName() + "§a was swapped to the " + otherTeam.coloredPrefix() + " §ateam");
                    openPlayerMenu(player, target);
                    break;
            }
        });
    }
    for (int i = 0; i < secondRow.length; i++) {
        int index = i + 1;
        menu.setItem(index, 2, secondRow[i], (m, e) -> {
            switch(index) {
                case 1:
                    // TODO
                    break;
                case 2:
                    openAmountMenu(player, target, "heal");
                    break;
                case 3:
                    openAmountMenu(player, target, "takedamage");
                    break;
                case 4:
                    openCooldownsMenu(player, target);
                    break;
                case 5:
                    openTeleportLocations(player, target);
                    break;
                case 6:
                    openFlagOptionMenu(player, target);
                    break;
                case 7:
                    openSpecMenu(player, target);
                    break;
            }
        });
    }
    menu.setItem(3, 4, MENU_BACK, (m, e) -> {
        if (player.getUniqueId() == target.getUuid()) {
            DebugMenu.openDebugMenu(player);
        } else {
            openTeamMenu(player);
        }
    });
    menu.setItem(4, 4, MENU_CLOSE, ACTION_CLOSE_MENU);
    menu.openForPlayer(player);
}
Also used : LobbyLocationMarker(com.ebicep.warlords.game.option.marker.LobbyLocationMarker) ItemBuilder(com.ebicep.warlords.util.bukkit.ItemBuilder) Game(com.ebicep.warlords.game.Game) Potion(org.bukkit.potion.Potion) Team(com.ebicep.warlords.game.Team) Menu(com.ebicep.warlords.menu.Menu) ItemStack(org.bukkit.inventory.ItemStack) Location(org.bukkit.Location) PlayerFlagLocation(com.ebicep.warlords.game.flags.PlayerFlagLocation) GroundFlagLocation(com.ebicep.warlords.game.flags.GroundFlagLocation) SpawnFlagLocation(com.ebicep.warlords.game.flags.SpawnFlagLocation)

Example 12 with Game

use of com.ebicep.warlords.game.Game in project Warlords by ebicep.

the class WarlordsPlayer method addDamageInstance.

private void addDamageInstance(WarlordsDamageHealingEvent event) {
    WarlordsPlayer attacker = event.getAttacker();
    String ability = event.getAbility();
    float min = event.getMin();
    float max = event.getMax();
    int critChance = event.getCritChance();
    int critMultiplier = event.getCritMultiplier();
    boolean ignoreReduction = event.isIgnoreReduction();
    boolean isLastStandFromShield = event.isIsLastStandFromShield();
    boolean isMeleeHit = ability.isEmpty();
    boolean isFallDamage = ability.equals("Fall");
    // Spawn Protection / Undying Army / Game State
    if ((dead && !cooldownManager.checkUndyingArmy(false)) || getGameState() != getGame().getState()) {
        return;
    }
    int initialHealth = health;
    for (AbstractCooldown<?> abstractCooldown : getCooldownManager().getCooldownsDistinct()) {
        abstractCooldown.doBeforeReductionFromSelf(event);
    }
    for (AbstractCooldown<?> abstractCooldown : attacker.getCooldownManager().getCooldownsDistinct()) {
        abstractCooldown.doBeforeReductionFromAttacker(event);
    }
    for (AbstractCooldown<?> abstractCooldown : attacker.getCooldownManager().getCooldownsDistinct()) {
        critChance = abstractCooldown.addCritChanceFromAttacker(event, critChance);
        critMultiplier = abstractCooldown.addCritMultiplierFromAttacker(event, critMultiplier);
    }
    // crit
    float damageValue = (int) ((Math.random() * (max - min)) + min);
    int crit = (int) ((Math.random() * (100)));
    boolean isCrit = false;
    if (crit <= critChance && attacker.canCrit) {
        isCrit = true;
        damageValue *= critMultiplier / 100f;
    }
    final float damageHealValueBeforeReduction = damageValue;
    addAbsorbed(Math.abs(damageValue - (damageValue *= 1 - spec.getDamageResistance() / 100f)));
    if (attacker == this && (isFallDamage || isMeleeHit)) {
        if (isMeleeHit) {
            // True damage
            sendMessage(GIVE_ARROW + ChatColor.GRAY + " You took " + ChatColor.RED + Math.round(min) + ChatColor.GRAY + " melee damage.");
            regenTimer = 10;
            if (health - min <= 0 && !cooldownManager.checkUndyingArmy(false)) {
                if (entity instanceof Player) {
                    PacketUtils.sendTitle((Player) entity, ChatColor.RED + "YOU DIED!", ChatColor.GRAY + "You took " + ChatColor.RED + Math.round(min) + ChatColor.GRAY + " melee damage and died.", 0, 40, 0);
                }
                health = 0;
                die(attacker);
            } else {
                health -= min;
                playHurtAnimation(this.entity, attacker);
            }
        } else {
            // Fall Damage
            sendMessage(GIVE_ARROW + ChatColor.GRAY + " You took " + ChatColor.RED + Math.round(damageValue) + ChatColor.GRAY + " fall damage.");
            regenTimer = 10;
            if (health - damageValue < 0 && !cooldownManager.checkUndyingArmy(false)) {
                // Title card "YOU DIED!"
                if (entity instanceof Player) {
                    PacketUtils.sendTitle((Player) entity, ChatColor.RED + "YOU DIED!", ChatColor.GRAY + "You took " + ChatColor.RED + Math.round(damageValue) + ChatColor.GRAY + " fall damage and died.", 0, 40, 0);
                }
                health = 0;
                die(attacker);
            } else {
                health -= damageValue;
                playHurtAnimation(entity, attacker);
            }
            addAbsorbed(Math.abs(damageValue * spec.getDamageResistance() / 100));
        }
        cancelHealingPowerUp();
        return;
    }
    // Reduction before Intervene.
    if (!ignoreReduction) {
        // Flag carrier multiplier.
        damageValue *= getFlagDamageMultiplier();
        // Checks whether the player is standing in a Hammer of Light.
        if (!HammerOfLight.standingInHammer(attacker, entity)) {
            for (AbstractCooldown<?> abstractCooldown : getCooldownManager().getCooldownsDistinct()) {
                damageValue = abstractCooldown.modifyDamageBeforeInterveneFromSelf(event, damageValue);
            }
            for (AbstractCooldown<?> abstractCooldown : attacker.getCooldownManager().getCooldownsDistinct()) {
                damageValue = abstractCooldown.modifyDamageBeforeInterveneFromAttacker(event, damageValue);
            }
        }
    }
    // Intervene
    Optional<RegularCooldown> optionalInterveneCooldown = new CooldownFilter<>(this, RegularCooldown.class).filterCooldownClass(Intervene.class).filter(regularCooldown -> regularCooldown.getFrom() != this).findFirst();
    if (optionalInterveneCooldown.isPresent() && !HammerOfLight.standingInHammer(attacker, entity) && isEnemy(attacker)) {
        Intervene intervene = (Intervene) optionalInterveneCooldown.get().getCooldownObject();
        WarlordsPlayer intervenedBy = optionalInterveneCooldown.get().getFrom();
        damageValue *= .5;
        intervenedBy.addAbsorbed(damageValue);
        intervenedBy.setRegenTimer(10);
        intervene.addDamagePrevented(damageValue);
        intervenedBy.addDamageInstance(attacker, "Intervene", damageValue, damageValue, isCrit ? 100 : -1, 100, false);
        Location loc = getLocation();
        // EFFECTS + SOUNDS
        Utils.playGlobalSound(loc, "warrior.intervene.block", 2, 1);
        playHitSound(attacker);
        entity.playEffect(EntityEffect.HURT);
        intervenedBy.getEntity().playEffect(EntityEffect.HURT);
        // Red line particle if the player gets hit
        EffectUtils.playParticleLinkAnimation(getLocation(), intervenedBy.getLocation(), 255, 0, 0, 2);
        // Remove horses.
        removeHorse();
        intervenedBy.removeHorse();
        for (AbstractCooldown<?> abstractCooldown : attacker.getCooldownManager().getCooldownsDistinct()) {
            abstractCooldown.onInterveneFromAttacker(event, damageValue);
        }
    } else {
        // Damage reduction after Intervene
        if (!ignoreReduction) {
            if (!HammerOfLight.standingInHammer(attacker, entity)) {
                // Example: .8 = 20% reduction.
                for (AbstractCooldown<?> abstractCooldown : getCooldownManager().getCooldownsDistinct()) {
                    damageValue = abstractCooldown.modifyDamageAfterInterveneFromSelf(event, damageValue);
                }
                for (AbstractCooldown<?> abstractCooldown : attacker.getCooldownManager().getCooldownsDistinct()) {
                    damageValue = abstractCooldown.modifyDamageAfterInterveneFromAttacker(event, damageValue);
                }
            }
        }
        // Arcane Shield
        List<ArcaneShield> arcaneShields = new CooldownFilter<>(this, RegularCooldown.class).filterCooldownClassAndMapToObjectsOfClass(ArcaneShield.class).collect(Collectors.toList());
        if (!arcaneShields.isEmpty() && isEnemy(attacker) && !HammerOfLight.standingInHammer(attacker, entity)) {
            ArcaneShield arcaneShield = arcaneShields.get(0);
            // adding dmg to shield
            arcaneShield.addShieldHealth(-damageValue);
            // check if broken
            if (arcaneShield.getShieldHealth() < 0) {
                if (entity instanceof Player) {
                    ((EntityLiving) ((CraftPlayer) entity).getHandle()).setAbsorptionHearts(0);
                }
                cooldownManager.removeCooldown(arcaneShield);
                addDamageInstance(new WarlordsDamageHealingEvent(this, attacker, ability, -arcaneShield.getShieldHealth(), -arcaneShield.getShieldHealth(), isCrit ? 100 : -1, 100, false, true, true));
                addAbsorbed(-(arcaneShield.getShieldHealth()));
                return;
            } else {
                if (entity instanceof Player) {
                    ((EntityLiving) ((CraftPlayer) entity).getHandle()).setAbsorptionHearts((float) (arcaneShield.getShieldHealth() / (maxHealth * .5) * 20));
                }
                if (isMeleeHit) {
                    sendMessage(GIVE_ARROW + ChatColor.GRAY + " You absorbed " + attacker.getName() + "'s melee " + ChatColor.GRAY + "hit.");
                    attacker.sendMessage(RECEIVE_ARROW + ChatColor.GRAY + " Your melee hit was absorbed by " + name);
                } else {
                    sendMessage(GIVE_ARROW + ChatColor.GRAY + " You absorbed " + attacker.getName() + "'s " + ability + " " + ChatColor.GRAY + "hit.");
                    attacker.sendMessage(RECEIVE_ARROW + ChatColor.GRAY + " Your " + ability + " was absorbed by " + name + ChatColor.GRAY + ".");
                }
                addAbsorbed(Math.abs(damageHealValueBeforeReduction));
            }
            for (AbstractCooldown<?> abstractCooldown : getCooldownManager().getCooldownsDistinct()) {
                abstractCooldown.onShieldFromSelf(event, damageValue, isCrit);
            }
            for (AbstractCooldown<?> abstractCooldown : attacker.getCooldownManager().getCooldownsDistinct()) {
                abstractCooldown.onShieldFromAttacker(event, damageValue, isCrit);
            }
            playHurtAnimation(this.entity, attacker);
            if (!isMeleeHit) {
                playHitSound(attacker);
            }
            removeHorse();
        } else {
            boolean debt = getCooldownManager().hasCooldownFromName("Spirits Respite");
            if (isEnemy(attacker)) {
                hitBy.put(attacker, 10);
                cancelHealingPowerUp();
                removeHorse();
                regenTimer = 10;
                sendDamageMessage(attacker, this, ability, damageValue, isCrit, isMeleeHit);
                if (spec instanceof Vindicator) {
                    ((SoulShackle) spec.getRed()).addToShacklePool(damageValue);
                }
                // Repentance
                if (spec instanceof Spiritguard) {
                    ((Repentance) spec.getBlue()).addToPool(damageValue);
                }
                for (AbstractCooldown<?> abstractCooldown : getCooldownManager().getCooldownsDistinct()) {
                    abstractCooldown.onDamageFromSelf(event, damageValue, isCrit);
                }
                for (AbstractCooldown<?> abstractCooldown : attacker.getCooldownManager().getCooldownsDistinct()) {
                    abstractCooldown.onDamageFromAttacker(event, damageValue, isCrit);
                }
            }
            updateJimmyHealth();
            // debt and healing
            if (!debt && takeDamage) {
                this.health -= Math.round(damageValue);
            }
            attacker.addDamage(damageValue);
            playHurtAnimation(this.entity, attacker);
            recordDamage.add(damageValue);
            // The player died.
            if (this.health <= 0 && !cooldownManager.checkUndyingArmy(false)) {
                if (attacker.entity instanceof Player) {
                    ((Player) attacker.entity).playSound(attacker.getLocation(), Sound.ORB_PICKUP, 500f, 1);
                    ((Player) attacker.entity).playSound(attacker.getLocation(), Sound.ORB_PICKUP, 500f, 0.5f);
                }
                attacker.addKill();
                sendMessage(ChatColor.GRAY + "You were killed by " + attacker.getColoredName());
                attacker.sendMessage(ChatColor.GRAY + "You killed " + getColoredName());
                gameState.getGame().forEachOnlinePlayer((p, t) -> {
                    if (p != this.entity && p != attacker.entity) {
                        p.sendMessage(getColoredName() + ChatColor.GRAY + " was killed by " + attacker.getColoredName());
                    }
                });
                for (WarlordsPlayer enemy : PlayerFilter.playingGame(game).enemiesOf(this).stream().collect(Collectors.toList())) {
                    for (AbstractCooldown<?> abstractCooldown : enemy.getCooldownManager().getCooldownsDistinct()) {
                        abstractCooldown.onDeathFromEnemies(event, damageValue, isCrit, enemy == attacker);
                    }
                }
                // Title card "YOU DIED!"
                if (this.entity instanceof Player) {
                    PacketUtils.sendTitle((Player) entity, ChatColor.RED + "YOU DIED!", ChatColor.GRAY + attacker.getName() + " killed you.", 0, 40, 0);
                }
                die(attacker);
            } else {
                if (!isMeleeHit && this != attacker && damageValue != 0) {
                    playHitSound(attacker);
                }
            }
        }
    }
    for (AbstractCooldown<?> abstractCooldown : getCooldownManager().getCooldownsDistinct()) {
        abstractCooldown.onEndFromSelf(event, damageValue, isCrit);
    }
    for (AbstractCooldown<?> abstractCooldown : attacker.getCooldownManager().getCooldownsDistinct()) {
        abstractCooldown.onEndFromAttacker(event, damageValue, isCrit);
    }
    getCooldownManager().getCooldowns().removeAll(new CooldownFilter<>(attacker, DamageHealCompleteCooldown.class).stream().collect(Collectors.toList()));
    attacker.getCooldownManager().getCooldowns().removeAll(new CooldownFilter<>(attacker, DamageHealCompleteCooldown.class).stream().collect(Collectors.toList()));
// WarlordsDamageHealingFinalEvent finalEvent = new WarlordsDamageHealingFinalEvent(
// this,
// attacker,
// ability,
// initialHealth,
// damageValue,
// critChance,
// critMultiplier,
// isCrit,
// true);
// secondStats.addDamageHealingEventAsSelf(finalEvent);
// attacker.getSecondStats().addDamageHealingEventAsAttacker(finalEvent);
// 
// checkForAchievementsDamage(attacker);
}
Also used : EffectUtils(com.ebicep.warlords.effects.EffectUtils) ItemFlag(org.bukkit.inventory.ItemFlag) PatternType(org.bukkit.block.banner.PatternType) Enchantment(org.bukkit.enchantments.Enchantment) Zombie(org.bukkit.entity.Zombie) DatabaseManager(com.ebicep.warlords.database.DatabaseManager) Player(org.bukkit.entity.Player) DatabasePlayer(com.ebicep.warlords.database.repositories.player.pojos.general.DatabasePlayer) ChallengeAchievements(com.ebicep.warlords.achievements.types.ChallengeAchievements) org.bukkit(org.bukkit) AbstractPlayerClass(com.ebicep.warlords.classes.AbstractPlayerClass) ItemBuilder(com.ebicep.warlords.util.bukkit.ItemBuilder) CustomHorse(com.ebicep.customentities.CustomHorse) FlagInfo(com.ebicep.warlords.game.flags.FlagInfo) Achievement(com.ebicep.warlords.achievements.Achievement) SpawnLocationMarker(com.ebicep.warlords.game.option.marker.SpawnLocationMarker) CraftWorld(org.bukkit.craftbukkit.v1_8_R3.CraftWorld) Spiritguard(com.ebicep.warlords.classes.shaman.specs.spiritguard.Spiritguard) TeleportUtils(com.ebicep.warlords.util.bukkit.TeleportUtils) AbstractAbility(com.ebicep.warlords.classes.AbstractAbility) PlayerFlagLocation(com.ebicep.warlords.game.flags.PlayerFlagLocation) CompassTargetMarker(com.ebicep.warlords.game.option.marker.CompassTargetMarker) HealingPowerup(com.ebicep.warlords.abilties.internal.HealingPowerup) Entity(org.bukkit.entity.Entity) Team(com.ebicep.warlords.game.Team) Warlords(com.ebicep.warlords.Warlords) FlagHolder(com.ebicep.warlords.game.option.marker.FlagHolder) LivingEntity(org.bukkit.entity.LivingEntity) NumberFormat(com.ebicep.warlords.util.java.NumberFormat) Collectors(java.util.stream.Collectors) PlayerFilter(com.ebicep.warlords.util.warlords.PlayerFilter) ItemStack(org.bukkit.inventory.ItemStack) WarlordsRespawnEvent(com.ebicep.warlords.events.WarlordsRespawnEvent) Vindicator(com.ebicep.warlords.classes.rogue.specs.Vindicator) Game(com.ebicep.warlords.game.Game) RegularCooldown(com.ebicep.warlords.player.cooldowns.cooldowns.RegularCooldown) AbstractCooldown(com.ebicep.warlords.player.cooldowns.AbstractCooldown) EntityLiving(net.minecraft.server.v1_8_R3.EntityLiving) CooldownFilter(com.ebicep.warlords.player.cooldowns.CooldownFilter) GenericAttributes(net.minecraft.server.v1_8_R3.GenericAttributes) WarlordsDamageHealingEvent(com.ebicep.warlords.events.WarlordsDamageHealingEvent) PotionEffectType(org.bukkit.potion.PotionEffectType) Utils(com.ebicep.warlords.util.warlords.Utils) GameAddon(com.ebicep.warlords.game.GameAddon) java.util(java.util) ItemMeta(org.bukkit.inventory.meta.ItemMeta) PacketUtils(com.ebicep.warlords.util.bukkit.PacketUtils) Pattern(org.bukkit.block.banner.Pattern) PlayingState(com.ebicep.warlords.game.state.PlayingState) CooldownManager(com.ebicep.warlords.player.cooldowns.CooldownManager) CraftEntity(org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity) NBTTagCompound(net.minecraft.server.v1_8_R3.NBTTagCompound) FixedMetadataValue(org.bukkit.metadata.FixedMetadataValue) BannerMeta(org.bukkit.inventory.meta.BannerMeta) Nonnull(javax.annotation.Nonnull) com.ebicep.warlords.abilties(com.ebicep.warlords.abilties) Nullable(javax.annotation.Nullable) WarlordsDeathEvent(com.ebicep.warlords.events.WarlordsDeathEvent) DamageHealCompleteCooldown(com.ebicep.warlords.player.cooldowns.cooldowns.DamageHealCompleteCooldown) CraftPlayer(org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer) EntityEquipment(org.bukkit.inventory.EntityEquipment) RegularCooldown(com.ebicep.warlords.player.cooldowns.cooldowns.RegularCooldown) Player(org.bukkit.entity.Player) DatabasePlayer(com.ebicep.warlords.database.repositories.player.pojos.general.DatabasePlayer) CraftPlayer(org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer) CooldownFilter(com.ebicep.warlords.player.cooldowns.CooldownFilter) Vindicator(com.ebicep.warlords.classes.rogue.specs.Vindicator) EntityLiving(net.minecraft.server.v1_8_R3.EntityLiving) Spiritguard(com.ebicep.warlords.classes.shaman.specs.spiritguard.Spiritguard) DamageHealCompleteCooldown(com.ebicep.warlords.player.cooldowns.cooldowns.DamageHealCompleteCooldown) WarlordsDamageHealingEvent(com.ebicep.warlords.events.WarlordsDamageHealingEvent) PlayerFlagLocation(com.ebicep.warlords.game.flags.PlayerFlagLocation)

Example 13 with Game

use of com.ebicep.warlords.game.Game in project Warlords by ebicep.

the class PlayingState method begin.

@Override
@SuppressWarnings("null")
public void begin() {
    this.game.setAcceptsSpectators(true);
    this.game.setAcceptsPlayers(false);
    this.resetTimer();
    RemoveEntities.doRemove(this.game);
    for (Option option : game.getOptions()) {
        option.start(game);
    }
    this.game.forEachOfflinePlayer((player, team) -> {
        if (team != null) {
            PlayerSettings playerSettings = Warlords.getPlayerSettings(player.getUniqueId());
            Warlords.addPlayer(new WarlordsPlayer(player, this, team, playerSettings));
        }
    });
    this.game.forEachOfflineWarlordsPlayer(wp -> {
        CustomScoreboard customScoreboard = Warlords.playerScoreboards.get(wp.getUuid());
        updateBasedOnGameState(customScoreboard, wp);
        if (wp.getEntity() instanceof Player) {
            wp.applySkillBoost((Player) wp.getEntity());
        }
    });
    if (DatabaseManager.playerService != null) {
        Warlords.newChain().async(() -> game.forEachOfflinePlayer((player, team) -> {
            DatabasePlayer databasePlayer = DatabaseManager.playerService.findByUUID(player.getUniqueId());
            DatabaseManager.updatePlayerAsync(databasePlayer);
            DatabaseManager.loadPlayer(player.getUniqueId(), PlayersCollections.SEASON_5, () -> {
            });
            DatabaseManager.loadPlayer(player.getUniqueId(), PlayersCollections.WEEKLY, () -> {
            });
            DatabaseManager.loadPlayer(player.getUniqueId(), PlayersCollections.DAILY, () -> {
            });
        })).execute();
    } else {
        System.out.println("ATTENTION - playerService is null");
    }
    game.registerEvents(new Listener() {

        @EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
        public void onWin(WarlordsGameTriggerWinEvent event) {
            game.setNextState(new EndState(game, event));
            winEvent = event;
        }
    });
    GameRunnable.create(game, this::updateScoreboard).runTaskTimer(0, 10);
    new GameRunnable(game) {

        @Override
        public void run() {
            counter++;
            timer += GameRunnable.SECOND;
            if (counter >= 60) {
                counter -= 60;
                PlayerFilter.playingGame(game).forEach(wp -> wp.getMinuteStats().advanceMinute());
            }
            PlayerFilter.playingGame(game).forEach(wp -> wp.getSecondStats().advanceSecond());
        }
    }.runTaskTimer(0, GameRunnable.SECOND);
    game.registerGameMarker(TimerSkipAbleMarker.class, (delay) -> {
        counter += delay / GameRunnable.SECOND;
        timer += delay;
    });
    Warlords.getInstance().hideAndUnhidePeople();
}
Also used : DisplaySlot(org.bukkit.scoreboard.DisplaySlot) Utils(com.ebicep.warlords.util.warlords.Utils) GameAddon(com.ebicep.warlords.game.GameAddon) DatabaseManager(com.ebicep.warlords.database.DatabaseManager) CustomScoreboard(com.ebicep.warlords.player.CustomScoreboard) Player(org.bukkit.entity.Player) DatabaseGameBase(com.ebicep.warlords.database.repositories.games.pojos.DatabaseGameBase) DatabasePlayer(com.ebicep.warlords.database.repositories.player.pojos.general.DatabasePlayer) Objective(org.bukkit.scoreboard.Objective) Scoreboard(org.bukkit.scoreboard.Scoreboard) ArrayList(java.util.ArrayList) EventHandler(org.bukkit.event.EventHandler) GameMode(org.bukkit.GameMode) Location(org.bukkit.Location) SpawnLocationMarker(com.ebicep.warlords.game.option.marker.SpawnLocationMarker) RecordGamesCommand(com.ebicep.warlords.commands.debugcommands.RecordGamesCommand) ScoreboardHandler(com.ebicep.warlords.game.option.marker.scoreboard.ScoreboardHandler) LobbyLocationMarker(com.ebicep.warlords.game.option.marker.LobbyLocationMarker) TimerSkipAbleMarker(com.ebicep.warlords.game.option.marker.TimerSkipAbleMarker) RemoveEntities(com.ebicep.warlords.util.bukkit.RemoveEntities) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) LocationMarker(com.ebicep.warlords.game.option.marker.LocationMarker) Listener(org.bukkit.event.Listener) BotManager(com.ebicep.jda.BotManager) GameRunnable(com.ebicep.warlords.util.warlords.GameRunnable) Team(com.ebicep.warlords.game.Team) Warlords(com.ebicep.warlords.Warlords) SRCalculator(com.ebicep.warlords.sr.SRCalculator) PlayersCollections(com.ebicep.warlords.database.repositories.player.PlayersCollections) PlayerSettings(com.ebicep.warlords.player.PlayerSettings) PlayerFilter(com.ebicep.warlords.util.warlords.PlayerFilter) WarlordsGameTriggerWinEvent(com.ebicep.warlords.events.WarlordsGameTriggerWinEvent) List(java.util.List) Stream(java.util.stream.Stream) Game(com.ebicep.warlords.game.Game) ExperienceManager(com.ebicep.warlords.player.ExperienceManager) EventPriority(org.bukkit.event.EventPriority) WarlordsPlayer(com.ebicep.warlords.player.WarlordsPlayer) ChatColor(org.bukkit.ChatColor) Option(com.ebicep.warlords.game.option.Option) Comparator(java.util.Comparator) Player(org.bukkit.entity.Player) DatabasePlayer(com.ebicep.warlords.database.repositories.player.pojos.general.DatabasePlayer) WarlordsPlayer(com.ebicep.warlords.player.WarlordsPlayer) Listener(org.bukkit.event.Listener) WarlordsPlayer(com.ebicep.warlords.player.WarlordsPlayer) EventHandler(org.bukkit.event.EventHandler) PlayerSettings(com.ebicep.warlords.player.PlayerSettings) GameRunnable(com.ebicep.warlords.util.warlords.GameRunnable) CustomScoreboard(com.ebicep.warlords.player.CustomScoreboard) WarlordsGameTriggerWinEvent(com.ebicep.warlords.events.WarlordsGameTriggerWinEvent) Option(com.ebicep.warlords.game.option.Option) DatabasePlayer(com.ebicep.warlords.database.repositories.player.pojos.general.DatabasePlayer)

Example 14 with Game

use of com.ebicep.warlords.game.Game in project Warlords by ebicep.

the class GameMenu method openTeamMenu.

public static void openTeamMenu(Player player) {
    Team selectedTeam = Warlords.getPlayerSettings(player.getUniqueId()).getWantedTeam();
    Menu menu = new Menu("Team Selector", 9 * 4);
    List<Team> values = new ArrayList<>(Arrays.asList(Team.values()));
    for (int i = 0; i < values.size(); i++) {
        Team team = values.get(i);
        ItemBuilder builder = new ItemBuilder(team.getItem()).name(team.teamColor() + team.getName()).flags(ItemFlag.HIDE_ENCHANTS);
        List<String> lore = new ArrayList<>();
        if (team == selectedTeam) {
            lore.add(ChatColor.GREEN + "Currently selected!");
            builder.enchant(Enchantment.OXYGEN, 1);
        } else {
            lore.add(ChatColor.YELLOW + "Click to select!");
        }
        builder.lore(lore);
        menu.setItem(9 / 2 - values.size() % 2 + i * 2 - 1, 1, builder.get(), (m, e) -> {
            if (selectedTeam != team) {
                player.sendMessage(ChatColor.GREEN + "You have joined the " + team.teamColor() + team.getName() + ChatColor.GREEN + " team!");
                Optional<Game> playerGame = Warlords.getGameManager().getPlayerGame(player.getUniqueId());
                if (playerGame.isPresent()) {
                    Game game = playerGame.get();
                    Team oldTeam = game.getPlayerTeam(player.getUniqueId());
                    game.setPlayerTeam(player, team);
                    LobbyLocationMarker randomLobbyLocation = LobbyLocationMarker.getRandomLobbyLocation(game, team);
                    if (randomLobbyLocation != null) {
                        Location teleportDestination = MapSymmetryMarker.getSymmetry(game).getOppositeLocation(game, oldTeam, team, player.getLocation(), randomLobbyLocation.getLocation());
                        player.teleport(teleportDestination);
                        Warlords.setRejoinPoint(player.getUniqueId(), teleportDestination);
                    }
                }
                ArmorManager.resetArmor(player, Warlords.getPlayerSettings(player.getUniqueId()).getSelectedClass(), team);
                Warlords.getPlayerSettings(player.getUniqueId()).setWantedTeam(team);
            }
            openTeamMenu(player);
        });
    }
    menu.setItem(4, 3, Menu.MENU_CLOSE, ACTION_CLOSE_MENU);
    menu.openForPlayer(player);
}
Also used : LobbyLocationMarker(com.ebicep.warlords.game.option.marker.LobbyLocationMarker) ItemBuilder(com.ebicep.warlords.util.bukkit.ItemBuilder) Game(com.ebicep.warlords.game.Game) Team(com.ebicep.warlords.game.Team)

Example 15 with Game

use of com.ebicep.warlords.game.Game in project Warlords by ebicep.

the class DatabaseGameBase method createGameSwitcherHologram.

private static void createGameSwitcherHologram(Player player) {
    HolographicDisplaysAPI.get(Warlords.getInstance()).getHolograms().stream().filter(h -> h.getVisibilitySettings().isVisibleTo(player) && h.getPosition().toLocation().equals(DatabaseGameBase.gameSwitchLocation)).forEach(Hologram::delete);
    Hologram gameSwitcher = HolographicDisplaysAPI.get(Warlords.getInstance()).createHologram(DatabaseGameBase.gameSwitchLocation);
    gameSwitcher.getLines().appendText(ChatColor.AQUA.toString() + ChatColor.UNDERLINE + "Last " + previousGames.size() + " Games");
    gameSwitcher.getLines().appendText("");
    int selectedGame = LeaderboardManager.playerGameHolograms.get(player.getUniqueId());
    int gameBefore = getGameBefore(selectedGame);
    int gameAfter = getGameAfter(selectedGame);
    if (previousGames.isEmpty()) {
        return;
    }
    ClickableHologramLine beforeLine;
    ClickableHologramLine afterLine;
    if (gameBefore == previousGames.size() - 1) {
        beforeLine = gameSwitcher.getLines().appendText(ChatColor.GRAY + "Latest Game");
    } else {
        beforeLine = gameSwitcher.getLines().appendText(ChatColor.GRAY.toString() + (gameBefore + 1) + ". " + previousGames.get(gameBefore).getDate());
    }
    if (selectedGame == previousGames.size() - 1) {
        gameSwitcher.getLines().appendText(ChatColor.GREEN + "Latest Game");
    } else {
        gameSwitcher.getLines().appendText(ChatColor.GREEN.toString() + (selectedGame + 1) + ". " + previousGames.get(selectedGame).getDate());
    }
    if (gameAfter == previousGames.size() - 1) {
        afterLine = gameSwitcher.getLines().appendText(ChatColor.GRAY + "Latest Game");
    } else {
        afterLine = gameSwitcher.getLines().appendText(ChatColor.GRAY.toString() + (gameAfter + 1) + ". " + previousGames.get(gameAfter).getDate());
    }
    beforeLine.setClickListener((clicker) -> {
        LeaderboardManager.playerGameHolograms.put(player.getUniqueId(), gameBefore);
        setGameHologramVisibility(player);
    });
    afterLine.setClickListener((clicker) -> {
        LeaderboardManager.playerGameHolograms.put(player.getUniqueId(), gameAfter);
        setGameHologramVisibility(player);
    });
    gameSwitcher.getVisibilitySettings().setGlobalVisibility(VisibilitySettings.Visibility.HIDDEN);
    gameSwitcher.getVisibilitySettings().setIndividualVisibility(player, VisibilitySettings.Visibility.VISIBLE);
}
Also used : GameAddon(com.ebicep.warlords.game.GameAddon) java.util(java.util) GameMap(com.ebicep.warlords.game.GameMap) SimpleDateFormat(java.text.SimpleDateFormat) DatabaseManager(com.ebicep.warlords.database.DatabaseManager) Player(org.bukkit.entity.Player) DatabasePlayer(com.ebicep.warlords.database.repositories.player.pojos.general.DatabasePlayer) Location(org.bukkit.Location) HolographicDisplaysAPI(me.filoghost.holographicdisplays.api.beta.HolographicDisplaysAPI) Transient(org.springframework.data.annotation.Transient) Nonnull(javax.annotation.Nonnull) GameMode(com.ebicep.warlords.game.GameMode) Nullable(javax.annotation.Nullable) DateFormat(java.text.DateFormat) Warlords(com.ebicep.warlords.Warlords) Hologram(me.filoghost.holographicdisplays.api.beta.hologram.Hologram) VisibilitySettings(me.filoghost.holographicdisplays.api.beta.hologram.VisibilitySettings) PlayersCollections(com.ebicep.warlords.database.repositories.player.PlayersCollections) PlayerFilter(com.ebicep.warlords.util.warlords.PlayerFilter) Field(org.springframework.data.mongodb.core.mapping.Field) WarlordsGameTriggerWinEvent(com.ebicep.warlords.events.WarlordsGameTriggerWinEvent) TimeUnit(java.util.concurrent.TimeUnit) Game(com.ebicep.warlords.game.Game) GamesCollections(com.ebicep.warlords.database.repositories.games.GamesCollections) WarlordsPlayer(com.ebicep.warlords.player.WarlordsPlayer) LeaderboardManager(com.ebicep.warlords.database.leaderboards.LeaderboardManager) ClickableHologramLine(me.filoghost.holographicdisplays.api.beta.hologram.line.ClickableHologramLine) ChatColor(org.bukkit.ChatColor) Id(org.springframework.data.annotation.Id) Hologram(me.filoghost.holographicdisplays.api.beta.hologram.Hologram) ClickableHologramLine(me.filoghost.holographicdisplays.api.beta.hologram.line.ClickableHologramLine)

Aggregations

Game (com.ebicep.warlords.game.Game)25 Team (com.ebicep.warlords.game.Team)15 ChatColor (org.bukkit.ChatColor)13 Warlords (com.ebicep.warlords.Warlords)12 WarlordsPlayer (com.ebicep.warlords.player.WarlordsPlayer)12 Nonnull (javax.annotation.Nonnull)12 Nullable (javax.annotation.Nullable)12 Player (org.bukkit.entity.Player)11 GameRunnable (com.ebicep.warlords.util.warlords.GameRunnable)9 java.util (java.util)8 GameAddon (com.ebicep.warlords.game.GameAddon)7 Utils (com.ebicep.warlords.util.warlords.Utils)7 ScoreboardHandler (com.ebicep.warlords.game.option.marker.scoreboard.ScoreboardHandler)6 PacketUtils (com.ebicep.warlords.util.bukkit.PacketUtils)6 PlayerFilter (com.ebicep.warlords.util.warlords.PlayerFilter)6 Location (org.bukkit.Location)6 WarlordsGameTriggerWinEvent (com.ebicep.warlords.events.WarlordsGameTriggerWinEvent)5 GameHolder (com.ebicep.warlords.game.GameManager.GameHolder)5 SimpleScoreboardHandler (com.ebicep.warlords.game.option.marker.scoreboard.SimpleScoreboardHandler)5 PlayingState (com.ebicep.warlords.game.state.PlayingState)5