Search in sources :

Example 1 with WarningMessage

use of com.magmaguy.elitemobs.utils.WarningMessage in project EliteMobs by MagmaGuy.

the class CustomSpawn method generateRandomSpawnLocation.

public Location generateRandomSpawnLocation() {
    if (customSpawnConfigFields == null) {
        new WarningMessage("Something tried to spawn but has invalid custom spawn config fields! This isn't good.", true);
        new WarningMessage("Bosses: ");
        getCustomBossEntities().forEach((customBossEntity) -> {
            if (customBossEntity != null)
                if (customBossEntity.getName() != null)
                    new WarningMessage(customBossEntity.getCustomBossesConfigFields().getName());
        });
        if (timedEvent != null) {
            new WarningMessage("Event: " + timedEvent.getCustomEventsConfigFields().getFilename());
            timedEvent.end();
        }
        return null;
    }
    // If there are no players online, don't spawn anything - this condition shouldn't be reachable in the first place
    if (Bukkit.getOnlinePlayers().isEmpty()) {
        keepTrying = false;
        if (timedEvent != null)
            timedEvent.end();
        return null;
    }
    // Go through online players and select the ones in valid worlds
    List<Player> validPlayers = new ArrayList<>();
    if (world == null)
        for (Player player : Bukkit.getOnlinePlayers()) {
            if (!PlayerData.isInMemory(player.getUniqueId()))
                continue;
            Location playerLocation = player.getLocation();
            if (!ValidWorldsConfig.getValidWorlds().contains(playerLocation.getWorld().getName()))
                continue;
            if (!playerLocation.getWorld().getGameRuleValue(GameRule.DO_MOB_SPAWNING))
                continue;
            if (!customSpawnConfigFields.getValidWorlds().isEmpty())
                if (!customSpawnConfigFields.getValidWorlds().contains(playerLocation.getWorld()))
                    continue;
            if (!customSpawnConfigFields.getValidWorldEnvironments().isEmpty())
                if (!customSpawnConfigFields.getValidWorldEnvironments().contains(Objects.requireNonNull(playerLocation.getWorld()).getEnvironment()))
                    continue;
            if (GuildRank.getActiveGuildRank(player) == 0)
                continue;
            validPlayers.add(player);
        }
    else
        validPlayers.addAll(world.getPlayers());
    // If there are no players in valid worlds, skip
    if (validPlayers.isEmpty())
        return null;
    // Select a random player
    Player selectedPlayer = validPlayers.get(ThreadLocalRandom.current().nextInt(validPlayers.size()));
    // Randomize vector between 24 and 128 block away from a source location
    Vector randomizedVector = new Vector(ThreadLocalRandom.current().nextInt(24, 128), // this doesn't really matter, it likely gets modified later
    0, ThreadLocalRandom.current().nextInt(24, 128));
    // Allow negative X and Z values
    if (ThreadLocalRandom.current().nextBoolean())
        randomizedVector.setX(randomizedVector.getX() * -1);
    if (ThreadLocalRandom.current().nextBoolean())
        randomizedVector.setY(randomizedVector.getY() * -1);
    // Temp location - do not run checks on it yet
    Location location = selectedPlayer.getLocation().clone().add(randomizedVector);
    // This doesn't matter too much since it will be parsed later, also these values are already tweaked for 1.18.
    if (VersionChecker.serverVersionOlderThan(18, 1))
        location.setY(ThreadLocalRandom.current().nextInt(-0, 256));
    else
        location.setY(ThreadLocalRandom.current().nextInt(-64, 256));
    World world = location.getWorld();
    // Set Y level - Location isn't final yet
    if (customSpawnConfigFields.isSurfaceSpawn())
        // this won't work for Nether environments, but who wants surface spawns on the Nether?
        location = Objects.requireNonNull(location.getWorld()).getHighestBlockAt(location).getLocation().add(new Vector(0.5, 1, 0.5));
    else if (customSpawnConfigFields.isUndergroundSpawn()) {
        // Let's hope there's caves
        if (location.getY() > Objects.requireNonNull(location.getWorld()).getHighestBlockAt(location).getY()) {
            for (int y = (int) location.getY(); y > -64; y--) {
                Location tempLocation = location.clone();
                tempLocation.setY(y);
                if (location.getBlock().getType().equals(Material.VOID_AIR))
                    return null;
                if (y < customSpawnConfigFields.getLowestYLevel())
                    return null;
                Block groundBlock = location.clone().subtract(new Vector(0, 1, 0)).getBlock();
                if (!groundBlock.getType().isSolid())
                    continue;
                // Check temp location block
                if (!tempLocation.getBlock().getType().isAir())
                    continue;
                // Check block above temp location
                if (!tempLocation.add(new Vector(0, 1, 0)).getBlock().getType().isAir())
                    continue;
                location = tempLocation;
                break;
            }
        }
    } else
        // Straight upwards check
        location.setY(getHighestValidBlock(location, getHighestValidBlock(location, customSpawnConfigFields.getHighestYLevel())));
    // Prevent spawning right on top of players
    assert world != null;
    for (Player player : world.getPlayers()) if (player.getLocation().distanceSquared(location) < Math.pow(24, 2))
        return null;
    // Nether ceiling check
    if (location.getY() > 127 && world.getEnvironment().equals(World.Environment.NETHER))
        return null;
    // Custom height check
    if (location.getY() == -100 || location.getY() > customSpawnConfigFields.getHighestYLevel() || location.getY() < customSpawnConfigFields.getLowestYLevel())
        return null;
    // Check WorldGuard flags
    if (EliteMobs.worldGuardIsEnabled) {
        if (!WorldGuardFlagChecker.doEventFlag(location))
            return null;
        if (!WorldGuardFlagChecker.doEliteMobsSpawnFlag(location))
            return null;
        if (!WorldGuardFlagChecker.doMobSpawnFlag(location))
            return null;
    }
    // Light level check - following 1.18 rules
    if (!customSpawnConfigFields.isCanSpawnInLight())
        if (location.getBlock().getLightLevel() > 8)
            return null;
    return location;
}
Also used : WarningMessage(com.magmaguy.elitemobs.utils.WarningMessage) Player(org.bukkit.entity.Player) ArrayList(java.util.ArrayList) Block(org.bukkit.block.Block) Vector(org.bukkit.util.Vector)

Example 2 with WarningMessage

use of com.magmaguy.elitemobs.utils.WarningMessage in project EliteMobs by MagmaGuy.

the class CustomBossBossBar method createBossBar.

private void createBossBar(Player player) {
    String locationString = (int) customBossEntity.getLocation().getX() + ", " + (int) customBossEntity.getLocation().getY() + ", " + (int) customBossEntity.getLocation().getZ();
    BossBar bossBar = Bukkit.createBossBar(bossBarMessage(player, locationString), BarColor.GREEN, BarStyle.SOLID, BarFlag.PLAY_BOSS_MUSIC);
    if (customBossEntity.getHealth() / customBossEntity.getMaxHealth() > 1 || customBossEntity.getHealth() / customBossEntity.getMaxHealth() < 0) {
        new WarningMessage("The following boss had more health than it should: " + customBossEntity.getName());
        new WarningMessage("This is a problem usually caused by running more than one plugin that modifies mob health!" + " EliteMobs can't fix this issue because it is being caused by another plugin." + " If you want EliteMobs to work correctly, find a way to fix this issue with whatever other plugin is causing it.");
        return;
    }
    bossBars.put(player, bossBar);
    updateBossBar(player, bossBar);
    bossBar.addPlayer(player);
}
Also used : WarningMessage(com.magmaguy.elitemobs.utils.WarningMessage) BossBar(org.bukkit.boss.BossBar)

Example 3 with WarningMessage

use of com.magmaguy.elitemobs.utils.WarningMessage in project EliteMobs by MagmaGuy.

the class ElitePowerParser method parsePowers.

public static HashSet<ElitePower> parsePowers(List<String> powers) {
    HashSet<ElitePower> elitePowers = new HashSet<>();
    CustomSummonPower customSummonPower = null;
    for (String powerName : powers) {
        if (powerName.split(":")[0].equalsIgnoreCase("summon") || powerName.split(":")[0].equalsIgnoreCase("summonable"))
            if (customSummonPower == null) {
                customSummonPower = new CustomSummonPower(powerName);
                elitePowers.add(customSummonPower);
            } else
                customSummonPower.addEntry(powerName);
        else {
            String[] parsedPowerName = powerName.split(":");
            if (ElitePower.getElitePower(parsedPowerName[0]) != null) {
                ElitePower elitePower = ElitePower.getElitePower(parsedPowerName[0]);
                elitePowers.add(elitePower);
                if (elitePower instanceof BonusCoins)
                    if (parsedPowerName.length > 1)
                        try {
                            ((BonusCoins) elitePower).setCoinMultiplier(Double.parseDouble(parsedPowerName[1]));
                        } catch (Exception ex) {
                            new WarningMessage("Multiplier " + parsedPowerName[1] + " for Bonus Coins power is not a valid multiplier!");
                        }
            } else
                new WarningMessage("Warning: power name " + powerName + " is not registered! Skipping it for custom mob construction...");
        }
    }
    return elitePowers;
}
Also used : CustomSummonPower(com.magmaguy.elitemobs.powers.meta.CustomSummonPower) WarningMessage(com.magmaguy.elitemobs.utils.WarningMessage) BonusCoins(com.magmaguy.elitemobs.powers.bosspowers.BonusCoins) ElitePower(com.magmaguy.elitemobs.powers.meta.ElitePower) HashSet(java.util.HashSet)

Example 4 with WarningMessage

use of com.magmaguy.elitemobs.utils.WarningMessage in project EliteMobs by MagmaGuy.

the class RegionalBossEntity method save.

public static void save() {
    for (CustomBossesConfigFields customBossesConfigFields : regionalBossesFromConfigFields.keySet()) {
        if (!customBossesConfigFields.isFilesOutOfSync())
            continue;
        customBossesConfigFields.setFilesOutOfSync(false);
        List<String> spawnLocations = new ArrayList<>();
        for (RegionalBossEntity regionalBossEntity : regionalBossesFromConfigFields.get(customBossesConfigFields)) spawnLocations.add(regionalBossEntity.rawString);
        customBossesConfigFields.getFileConfiguration().set("spawnLocations", spawnLocations);
        try {
            customBossesConfigFields.getFileConfiguration().save(customBossesConfigFields.getFile());
        } catch (Exception ex) {
            new WarningMessage("Failed to save respawn timer for " + customBossesConfigFields.getFileConfiguration().getName() + " !");
        }
    }
}
Also used : CustomBossesConfigFields(com.magmaguy.elitemobs.config.custombosses.CustomBossesConfigFields) WarningMessage(com.magmaguy.elitemobs.utils.WarningMessage) ArrayList(java.util.ArrayList)

Example 5 with WarningMessage

use of com.magmaguy.elitemobs.utils.WarningMessage in project EliteMobs by MagmaGuy.

the class CustomBossMegaConsumer method setEquipment.

private void setEquipment(LivingEntity livingEntity) {
    try {
        livingEntity.getEquipment().setHelmet(customBossesConfigFields.getHelmet());
        livingEntity.getEquipment().setChestplate(customBossesConfigFields.getChestplate());
        livingEntity.getEquipment().setLeggings(customBossesConfigFields.getLeggings());
        livingEntity.getEquipment().setBoots(customBossesConfigFields.getBoots());
        livingEntity.getEquipment().setItemInMainHand(customBossesConfigFields.getMainHand());
        livingEntity.getEquipment().setItemInOffHand(customBossesConfigFields.getOffHand());
        if (livingEntity.getEquipment().getHelmet() != null) {
            ItemMeta helmetMeta = livingEntity.getEquipment().getHelmet().getItemMeta();
            if (helmetMeta != null) {
                helmetMeta.setUnbreakable(true);
                livingEntity.getEquipment().getHelmet().setItemMeta(helmetMeta);
            }
        }
    } catch (Exception ex) {
        new WarningMessage("Tried to assign a material slot to an invalid entity! Boss is from file" + customBossesConfigFields.getFilename());
    }
}
Also used : WarningMessage(com.magmaguy.elitemobs.utils.WarningMessage) ItemMeta(org.bukkit.inventory.meta.ItemMeta)

Aggregations

WarningMessage (com.magmaguy.elitemobs.utils.WarningMessage)76 InfoMessage (com.magmaguy.elitemobs.utils.InfoMessage)11 Vector (org.bukkit.util.Vector)11 Item (org.bukkit.entity.Item)10 File (java.io.File)9 CustomBossEntity (com.magmaguy.elitemobs.mobconstructor.custombosses.CustomBossEntity)8 FlagConflictException (com.sk89q.worldguard.protection.flags.registry.FlagConflictException)7 RegionManager (com.sk89q.worldguard.protection.managers.RegionManager)6 RegionContainer (com.sk89q.worldguard.protection.regions.RegionContainer)6 ArrayList (java.util.ArrayList)6 ZipFile (com.magmaguy.elitemobs.utils.ZipFile)5 GlobalProtectedRegion (com.sk89q.worldguard.protection.regions.GlobalProtectedRegion)5 ProtectedRegion (com.sk89q.worldguard.protection.regions.ProtectedRegion)5 Location (org.bukkit.Location)5 ItemStack (org.bukkit.inventory.ItemStack)5 CustomBossesConfigFields (com.magmaguy.elitemobs.config.custombosses.CustomBossesConfigFields)3 Minidungeon (com.magmaguy.elitemobs.dungeons.Minidungeon)3 IOException (java.io.IOException)3 Material (org.bukkit.Material)3 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)3