Search in sources :

Example 6 with XMaterial

use of com.iridium.iridiumcore.dependencies.xseries.XMaterial in project IridiumSkyblock by Iridium-Development.

the class EnchantItemListener method monitorItemEnchant.

@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void monitorItemEnchant(EnchantItemEvent event) {
    if (!IridiumSkyblockAPI.getInstance().isIslandWorld(event.getEnchanter().getWorld()))
        return;
    Player player = event.getEnchanter();
    User user = IridiumSkyblock.getInstance().getUserManager().getUser(player);
    Optional<Island> island = user.getIsland();
    XMaterial material = XMaterial.matchXMaterial(event.getItem().getType());
    island.ifPresent(value -> IridiumSkyblock.getInstance().getMissionManager().handleMissionUpdates(value, "ENCHANT", material.name(), 1));
}
Also used : Player(org.bukkit.entity.Player) User(com.iridium.iridiumskyblock.database.User) XMaterial(com.iridium.iridiumcore.dependencies.xseries.XMaterial) Island(com.iridium.iridiumskyblock.database.Island) EventHandler(org.bukkit.event.EventHandler)

Example 7 with XMaterial

use of com.iridium.iridiumcore.dependencies.xseries.XMaterial in project IridiumSkyblock by Iridium-Development.

the class OceanGenerator method generateChunkData.

/**
 * Generates an ocean.
 *
 * @param world     The world that we try to generate
 * @param random    A random which should be used. We don't need this
 * @param chunkX    The x position of the chunk
 * @param chunkZ    The y position of the chunk
 * @param biomeGrid The biome grid of the chunk
 * @return The data of this chunk. None all the time to generate void
 */
@Override
@NotNull
public ChunkData generateChunkData(@NotNull World world, @NotNull Random random, int chunkX, int chunkZ, @NotNull BiomeGrid biomeGrid) {
    SimplexOctaveGenerator generator = new SimplexOctaveGenerator(new Random(world.getSeed()), 8);
    final ChunkData chunkData = createChunkData(world);
    generator.setScale(0.005D);
    XMaterial bottomMaterial = IridiumSkyblock.getInstance().getConfiguration().generatorSettings.oceanFloorBottomMaterial;
    XMaterial topMaterial = IridiumSkyblock.getInstance().getConfiguration().generatorSettings.oceanFloorTopMaterial;
    int waterHeight = IridiumSkyblock.getInstance().getConfiguration().generatorSettings.waterHeight;
    int maxOceanFloorLevel = IridiumSkyblock.getInstance().getConfiguration().generatorSettings.maxOceanFloorLevel;
    int minOceanFloorLevel = IridiumSkyblock.getInstance().getConfiguration().generatorSettings.minOceanFloorLevel;
    for (int x = 0; x < 16; x++) {
        for (int z = 0; z < 16; z++) {
            int currentFloorHeight = (int) ((generator.noise(chunkX * 16 + x, chunkZ * 16 + z, 1.5D, 0.5D, true) + 1) * (maxOceanFloorLevel - minOceanFloorLevel) + minOceanFloorLevel);
            // Generate layer of bedrock
            chunkData.setBlock(x, LocationUtils.getMinHeight(world), z, Objects.requireNonNull(XMaterial.BEDROCK.parseMaterial()));
            // Generate gravel layer
            for (int y = LocationUtils.getMinHeight(world) + 1; y < currentFloorHeight; y++) {
                chunkData.setBlock(x, y, z, Objects.requireNonNull(bottomMaterial.parseMaterial()));
            }
            // Generate sand on top of gravel
            chunkData.setBlock(x, currentFloorHeight, z, Objects.requireNonNull(topMaterial.parseMaterial()));
            // Generate water or lava on top of the floor
            XMaterial oceanMaterial = world.getEnvironment() == Environment.NETHER ? XMaterial.LAVA : XMaterial.WATER;
            for (int y = currentFloorHeight + 1; y <= waterHeight; y++) {
                chunkData.setBlock(x, y, z, Objects.requireNonNull(oceanMaterial.parseMaterial()));
            }
        }
    }
    return chunkData;
}
Also used : Random(java.util.Random) SimplexOctaveGenerator(org.bukkit.util.noise.SimplexOctaveGenerator) XMaterial(com.iridium.iridiumcore.dependencies.xseries.XMaterial) NotNull(org.jetbrains.annotations.NotNull)

Example 8 with XMaterial

use of com.iridium.iridiumcore.dependencies.xseries.XMaterial in project IridiumSkyblock by Iridium-Development.

the class EditWarpCommand method execute.

/**
 * Executes the command for the specified {@link CommandSender} with the provided arguments.
 * Not called when the command execution was invalid (no permission, no player or command disabled).
 * Shows an overview over the members of the Island and allows quick rank management.
 *
 * @param sender The CommandSender which executes this command
 * @param args   The arguments used with this command. They contain the sub-command
 */
@Override
public boolean execute(CommandSender sender, String[] args) {
    if (args.length < 3) {
        sender.sendMessage(StringUtils.color(syntax.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
        return false;
    }
    Player player = (Player) sender;
    User user = IridiumSkyblock.getInstance().getUserManager().getUser(player);
    Optional<Island> island = user.getIsland();
    if (!island.isPresent()) {
        player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().noIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
        return false;
    }
    if (!IridiumSkyblock.getInstance().getIslandManager().getIslandPermission(island.get(), IridiumSkyblock.getInstance().getUserManager().getUser(player), PermissionType.MANAGE_WARPS)) {
        player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().cannotManageWarps.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
        return false;
    }
    List<IslandWarp> islandWarps = IridiumSkyblock.getInstance().getDatabaseManager().getIslandWarpTableManager().getEntries(island.get());
    Optional<IslandWarp> islandWarp = islandWarps.stream().filter(warp -> warp.getName().equalsIgnoreCase(args[1])).findFirst();
    if (!islandWarp.isPresent()) {
        player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().unknownWarp.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
        return false;
    }
    // TODO: Use subcommand system
    switch(args[2]) {
        case "icon":
            if (args.length != 4) {
                sender.sendMessage("/is editwarp <name> icon <icon>");
            }
            Optional<XMaterial> xMaterial = XMaterial.matchXMaterial(args[3]);
            if (xMaterial.isPresent()) {
                islandWarp.get().setIcon(xMaterial.get());
                player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().warpIconSet.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
                return true;
            } else {
                player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().noSuchMaterial.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
                return false;
            }
        case "description":
            if (args.length < 4) {
                sender.sendMessage("/is editwarp <name> description <description>");
                return false;
            }
            String description = String.join(" ", Arrays.copyOfRange(args, 3, args.length));
            islandWarp.get().setDescription(description);
            player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().warpDescriptionSet.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
            return true;
    }
    return false;
}
Also used : Arrays(java.util.Arrays) CommandSender(org.bukkit.command.CommandSender) User(com.iridium.iridiumskyblock.database.User) Island(com.iridium.iridiumskyblock.database.Island) Player(org.bukkit.entity.Player) Collectors(java.util.stream.Collectors) XMaterial(com.iridium.iridiumcore.dependencies.xseries.XMaterial) StringUtils(com.iridium.iridiumcore.utils.StringUtils) OfflinePlayer(org.bukkit.OfflinePlayer) IslandWarp(com.iridium.iridiumskyblock.database.IslandWarp) List(java.util.List) PermissionType(com.iridium.iridiumskyblock.PermissionType) Duration(java.time.Duration) Optional(java.util.Optional) Collections(java.util.Collections) IridiumSkyblock(com.iridium.iridiumskyblock.IridiumSkyblock) Player(org.bukkit.entity.Player) OfflinePlayer(org.bukkit.OfflinePlayer) User(com.iridium.iridiumskyblock.database.User) IslandWarp(com.iridium.iridiumskyblock.database.IslandWarp) XMaterial(com.iridium.iridiumcore.dependencies.xseries.XMaterial) Island(com.iridium.iridiumskyblock.database.Island)

Example 9 with XMaterial

use of com.iridium.iridiumcore.dependencies.xseries.XMaterial in project IridiumSkyblock by Iridium-Development.

the class BlockPlaceListener method monitorBlockPlace.

@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void monitorBlockPlace(BlockPlaceEvent event) {
    if (!IridiumSkyblockAPI.getInstance().isIslandWorld(event.getBlock().getWorld()))
        return;
    Player player = event.getPlayer();
    User user = IridiumSkyblock.getInstance().getUserManager().getUser(player);
    XMaterial material = XMaterial.matchXMaterial(event.getBlock().getType());
    user.getIsland().ifPresent(island -> {
        IridiumSkyblock.getInstance().getMissionManager().handleMissionUpdates(island, "PLACE", material.name(), 1);
        IslandBlocks islandBlocks = IridiumSkyblock.getInstance().getIslandManager().getIslandBlock(island, material);
        islandBlocks.setAmount(islandBlocks.getAmount() + 1);
        if (event.getBlock().getState() instanceof CreatureSpawner) {
            CreatureSpawner creatureSpawner = (CreatureSpawner) event.getBlock().getState();
            IslandSpawners islandSpawners = IridiumSkyblock.getInstance().getIslandManager().getIslandSpawners(island, creatureSpawner.getSpawnedType());
            islandSpawners.setAmount(islandSpawners.getAmount() + 1);
        }
    });
}
Also used : Player(org.bukkit.entity.Player) User(com.iridium.iridiumskyblock.database.User) XMaterial(com.iridium.iridiumcore.dependencies.xseries.XMaterial) IslandBlocks(com.iridium.iridiumskyblock.database.IslandBlocks) CreatureSpawner(org.bukkit.block.CreatureSpawner) IslandSpawners(com.iridium.iridiumskyblock.database.IslandSpawners) EventHandler(org.bukkit.event.EventHandler)

Example 10 with XMaterial

use of com.iridium.iridiumcore.dependencies.xseries.XMaterial in project IridiumSkyblock by Iridium-Development.

the class BlockPlaceListener method onBlockPlaceEvent.

@EventHandler(ignoreCancelled = true)
public void onBlockPlaceEvent(BlockPlaceEvent event) {
    Player player = event.getPlayer();
    User user = IridiumSkyblock.getInstance().getUserManager().getUser(player);
    Optional<Island> island = IridiumSkyblock.getInstance().getIslandManager().getIslandViaLocation(event.getBlock().getLocation());
    if (!island.isPresent()) {
        World world = event.getBlock().getLocation().getWorld();
        if (IridiumSkyblockAPI.getInstance().isIslandWorld(world)) {
            if (!user.isBypassing())
                event.setCancelled(true);
        }
        return;
    }
    XMaterial material = XMaterial.matchXMaterial(event.getBlock().getType());
    if (!IridiumSkyblock.getInstance().getIslandManager().getIslandPermission(island.get(), user, PermissionType.BLOCK_PLACE)) {
        event.setCancelled(true);
        player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().cannotPlaceBlocks.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
        return;
    }
    int limitUpgradeLevel = IridiumSkyblock.getInstance().getIslandManager().getIslandUpgrade(island.get(), "blocklimit").getLevel();
    int blockLimit = IridiumSkyblock.getInstance().getUpgrades().blockLimitUpgrade.upgrades.get(limitUpgradeLevel).limits.getOrDefault(material, 0);
    if (blockLimit > 0 && IridiumSkyblock.getInstance().getIslandManager().getIslandBlockAmount(island.get(), material) >= blockLimit) {
        player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().blockLimitReached.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix).replace("%limit%", String.valueOf(blockLimit)).replace("%block%", WordUtils.capitalizeFully(material.name().toLowerCase().replace("_", " ")))));
        event.setCancelled(true);
    }
}
Also used : Player(org.bukkit.entity.Player) User(com.iridium.iridiumskyblock.database.User) World(org.bukkit.World) XMaterial(com.iridium.iridiumcore.dependencies.xseries.XMaterial) Island(com.iridium.iridiumskyblock.database.Island) EventHandler(org.bukkit.event.EventHandler)

Aggregations

XMaterial (com.iridium.iridiumcore.dependencies.xseries.XMaterial)15 Player (org.bukkit.entity.Player)10 EventHandler (org.bukkit.event.EventHandler)9 Island (com.iridium.iridiumskyblock.database.Island)6 User (com.iridium.iridiumskyblock.database.User)6 StringUtils (com.iridium.iridiumcore.utils.StringUtils)3 Collectors (java.util.stream.Collectors)3 Block (org.bukkit.block.Block)3 CreatureSpawner (org.bukkit.block.CreatureSpawner)3 InventoryHolder (org.bukkit.inventory.InventoryHolder)3 ItemStack (org.bukkit.inventory.ItemStack)3 ItemStackUtils (com.iridium.iridiumcore.utils.ItemStackUtils)2 IridiumSkyblock (com.iridium.iridiumskyblock.IridiumSkyblock)2 Arrays (java.util.Arrays)2 List (java.util.List)2 Random (java.util.Random)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 NBTCompound (com.iridium.iridiumcore.dependencies.nbtapi.NBTCompound)1 NBTItem (com.iridium.iridiumcore.dependencies.nbtapi.NBTItem)1 PaperLib (com.iridium.iridiumcore.dependencies.paperlib.PaperLib)1