Search in sources :

Example 11 with XMaterial

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

the class BlockValueGUI method addContent.

@Override
public void addContent(Inventory inventory) {
    inventory.clear();
    InventoryUtils.fillInventory(inventory, getNoItemGUI().background);
    inventory.setItem(inventory.getSize() - 3, ItemStackUtils.makeItem(IridiumSkyblock.getInstance().getInventories().nextPage));
    inventory.setItem(inventory.getSize() - 7, ItemStackUtils.makeItem(IridiumSkyblock.getInstance().getInventories().previousPage));
    if (guiType == BlockValueType.BLOCK) {
        IridiumSkyblock.getInstance().getBlockValues().blockValues.entrySet().stream().filter(valuableBlockEntry -> (page == 1 ? valuableBlockEntry.getValue().page <= 1 : valuableBlockEntry.getValue().page == page)).forEachOrdered(valuableBlock -> {
            XMaterial material = valuableBlock.getKey();
            ValuableBlock blockInfo = valuableBlock.getValue();
            ItemStack blockItem = ItemStackUtils.makeItem(material, 1, StringUtils.color(blockInfo.name), getColoredValueLore(blockInfo.value));
            inventory.setItem(blockInfo.slot, blockItem);
        });
    } else if (guiType == BlockValueType.SPAWNER) {
        IridiumSkyblock.getInstance().getBlockValues().spawnerValues.entrySet().stream().filter(valuableSpawnerEntry -> (page == 1 ? valuableSpawnerEntry.getValue().page <= 1 : valuableSpawnerEntry.getValue().page == page)).forEachOrdered(valuableSpawner -> {
            ValuableBlock spawnerInfo = valuableSpawner.getValue();
            ItemStack spawnerItem = ItemStackUtils.makeItem(XMaterial.SPAWNER, 1, StringUtils.color(spawnerInfo.name), getColoredValueLore(spawnerInfo.value));
            inventory.setItem(spawnerInfo.slot, spawnerItem);
        });
    }
    if (IridiumSkyblock.getInstance().getConfiguration().backButtons && getPreviousInventory() != null) {
        inventory.setItem(inventory.getSize() + IridiumSkyblock.getInstance().getInventories().backButton.slot, ItemStackUtils.makeItem(IridiumSkyblock.getInstance().getInventories().backButton));
    }
}
Also used : Arrays(java.util.Arrays) ItemStackUtils(com.iridium.iridiumcore.utils.ItemStackUtils) InventoryClickEvent(org.bukkit.event.inventory.InventoryClickEvent) Player(org.bukkit.entity.Player) Collectors(java.util.stream.Collectors) Inventory(org.bukkit.inventory.Inventory) XMaterial(com.iridium.iridiumcore.dependencies.xseries.XMaterial) StringUtils(com.iridium.iridiumcore.utils.StringUtils) ItemStack(org.bukkit.inventory.ItemStack) ValuableBlock(com.iridium.iridiumskyblock.configs.BlockValues.ValuableBlock) List(java.util.List) InventoryUtils(com.iridium.iridiumcore.utils.InventoryUtils) IridiumSkyblock(com.iridium.iridiumskyblock.IridiumSkyblock) XMaterial(com.iridium.iridiumcore.dependencies.xseries.XMaterial) ItemStack(org.bukkit.inventory.ItemStack) ValuableBlock(com.iridium.iridiumskyblock.configs.BlockValues.ValuableBlock)

Example 12 with XMaterial

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

the class ItemCraftListener method monitorItemCraft.

@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void monitorItemCraft(CraftItemEvent event) {
    if (!IridiumSkyblockAPI.getInstance().isIslandWorld(event.getWhoClicked().getWorld()))
        return;
    int amount = event.isShiftClick() ? Arrays.stream(event.getInventory().getMatrix()).filter(Objects::nonNull).map(ItemStack::getAmount).sorted().findFirst().orElse(1) * event.getRecipe().getResult().getAmount() : event.getRecipe().getResult().getAmount();
    Player player = (Player) event.getWhoClicked();
    User user = IridiumSkyblock.getInstance().getUserManager().getUser(player);
    Optional<Island> island = user.getIsland();
    XMaterial material = XMaterial.matchXMaterial(event.getRecipe().getResult().getType());
    island.ifPresent(value -> IridiumSkyblock.getInstance().getMissionManager().handleMissionUpdates(value, "CRAFT", material.name(), amount));
}
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 13 with XMaterial

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

the class OceanGenerator method generateWater.

public void generateWater(World world, int x, int z) {
    SimplexOctaveGenerator generator = new SimplexOctaveGenerator(new Random(world.getSeed()), 8);
    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;
    int currentFloorHeight = (int) ((generator.noise(x, z, 1.5D, 0.5D, true) + 1) * (maxOceanFloorLevel - minOceanFloorLevel) + minOceanFloorLevel);
    int minHeightWorld = LocationUtils.getMinHeight(world);
    // Generate layer of bedrock
    if (world.getBlockAt(x, minHeightWorld, z).getType() != XMaterial.BEDROCK.parseMaterial()) {
        if (world.getBlockAt(x, minHeightWorld, z).getState() instanceof InventoryHolder) {
            ((InventoryHolder) world.getBlockAt(x, minHeightWorld, z).getState()).getInventory().clear();
        }
        world.getBlockAt(x, minHeightWorld, z).setType(Material.BEDROCK, false);
    }
    // Generate gravel layer
    for (int y = minHeightWorld + 1; y < currentFloorHeight; y++) {
        Block block = world.getBlockAt(x, y, z);
        if (block.getType() != bottomMaterial.parseMaterial() && bottomMaterial.parseMaterial() != null) {
            if (block.getState() instanceof InventoryHolder) {
                ((InventoryHolder) block.getState()).getInventory().clear();
            }
            block.setType(bottomMaterial.parseMaterial(), false);
        }
    }
    // Generate sand on top of gravel
    if (world.getBlockAt(x, currentFloorHeight, z).getType() != topMaterial.parseMaterial() && topMaterial.parseMaterial() != null) {
        if (world.getBlockAt(x, currentFloorHeight, z).getState() instanceof InventoryHolder) {
            ((InventoryHolder) world.getBlockAt(x, currentFloorHeight, z).getState()).getInventory().clear();
        }
        world.getBlockAt(x, currentFloorHeight, z).setType(topMaterial.parseMaterial(), false);
    }
    // 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++) {
        Block block = world.getBlockAt(x, y, z);
        if (block.getType() != oceanMaterial.parseMaterial() && oceanMaterial.parseMaterial() != null) {
            if (block.getState() instanceof InventoryHolder) {
                ((InventoryHolder) block.getState()).getInventory().clear();
            }
            block.setType(oceanMaterial.parseMaterial(), false);
        }
    }
    // Replace everything else with air
    for (int y = waterHeight + 1; y < world.getMaxHeight(); y++) {
        Block block = world.getBlockAt(x, y, z);
        if (block.getType() != Material.AIR) {
            if (block.getState() instanceof InventoryHolder) {
                ((InventoryHolder) block.getState()).getInventory().clear();
            }
            block.setType(Material.AIR, false);
        }
    }
}
Also used : Random(java.util.Random) SimplexOctaveGenerator(org.bukkit.util.noise.SimplexOctaveGenerator) Block(org.bukkit.block.Block) XMaterial(com.iridium.iridiumcore.dependencies.xseries.XMaterial) InventoryHolder(org.bukkit.inventory.InventoryHolder)

Example 14 with XMaterial

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

the class Schematic method paste.

@Override
public void paste(File file, Location location, Boolean ignoreAirBlock, CompletableFuture<Void> completableFuture) {
    SchematicData schematicData;
    try {
        schematicData = schematicCache.getOrDefault(file, SchematicData.loadSchematic(file));
        schematicCache.put(file, schematicData);
    } catch (IOException e) {
        e.printStackTrace();
        return;
    }
    short length = schematicData.length;
    short width = schematicData.width;
    short height = schematicData.height;
    // Centers the schematic
    location.subtract(width / 2.00, height / 2.00, length / 2.00);
    for (int x = 0; x < width; ++x) {
        for (int y = 0; y < height; ++y) {
            for (int z = 0; z < length; ++z) {
                int index = y * width * length + z * width + x;
                Block block = new Location(location.getWorld(), x + location.getX(), y + location.getY(), z + location.getZ()).getBlock();
                for (String blockData : schematicData.palette.keySet()) {
                    int i = SchematicData.getChildTag(schematicData.palette, blockData, IntTag.class).getValue();
                    if (schematicData.blockdata[index] == i) {
                        block.setBlockData(Bukkit.createBlockData(blockData), false);
                    }
                }
            }
        }
    }
    for (Tag tag : schematicData.tileEntities) {
        if (!(tag instanceof CompoundTag))
            continue;
        CompoundTag t = (CompoundTag) tag;
        Map<String, Tag> tags = t.getValue();
        int[] pos = SchematicData.getChildTag(tags, "Pos", IntArrayTag.class).getValue();
        int x = pos[0];
        int y = pos[1];
        int z = pos[2];
        Block block = new Location(location.getWorld(), x + location.getX(), y + location.getY(), z + location.getZ()).getBlock();
        String id = SchematicData.getChildTag(tags, "Id", StringTag.class).getValue().toLowerCase().replace("minecraft:", "");
        if (id.equalsIgnoreCase("chest")) {
            List<Tag> items = SchematicData.getChildTag(tags, "Items", ListTag.class).getValue();
            if (block.getState() instanceof Chest) {
                Chest chest = (Chest) block.getState();
                for (Tag item : items) {
                    if (!(item instanceof CompoundTag))
                        continue;
                    Map<String, Tag> itemtag = ((CompoundTag) item).getValue();
                    byte slot = SchematicData.getChildTag(itemtag, "Slot", ByteTag.class).getValue();
                    String name = (SchematicData.getChildTag(itemtag, "id", StringTag.class).getValue()).toLowerCase().replace("minecraft:", "").replace("reeds", "sugar_cane");
                    Byte amount = SchematicData.getChildTag(itemtag, "Count", ByteTag.class).getValue();
                    Optional<XMaterial> optionalXMaterial = XMaterial.matchXMaterial(name.toUpperCase());
                    if (optionalXMaterial.isPresent()) {
                        XMaterial material = optionalXMaterial.get();
                        ItemStack itemStack = material.parseItem();
                        if (itemStack != null) {
                            itemStack.setAmount(amount);
                            chest.getBlockInventory().setItem(slot, itemStack);
                        }
                    }
                }
            }
        }
    }
    completableFuture.complete(null);
}
Also used : Chest(org.bukkit.block.Chest) IOException(java.io.IOException) XMaterial(com.iridium.iridiumcore.dependencies.xseries.XMaterial) Block(org.bukkit.block.Block) ItemStack(org.bukkit.inventory.ItemStack) Location(org.bukkit.Location)

Example 15 with XMaterial

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

the class IslandManager method recalculateIsland.

/**
 * Recalculates the island async with specified ChunkSnapshots.
 *
 * @param island The specified Island
 * @param chunks The Island's Chunks
 */
private void recalculateIsland(@NotNull Island island, @NotNull List<Chunk> chunks) {
    chunks.stream().map(chunk -> chunk.getChunkSnapshot(true, false, false)).forEach(chunk -> {
        World world = Bukkit.getWorld(chunk.getWorldName());
        int maxHeight = world == null ? 255 : world.getMaxHeight() - 1;
        for (int x = 0; x < 16; x++) {
            for (int z = 0; z < 16; z++) {
                if (island.isInIsland(x + (chunk.getX() * 16), z + (chunk.getZ() * 16))) {
                    final int maxy = Math.min(maxHeight, chunk.getHighestBlockYAt(x, z));
                    for (int y = LocationUtils.getMinHeight(world); y <= maxy; y++) {
                        XMaterial material = XMaterial.matchXMaterial(chunk.getBlockType(x, y, z));
                        if (material.equals(XMaterial.AIR))
                            continue;
                        IslandBlocks islandBlock = IridiumSkyblock.getInstance().getIslandManager().getIslandBlock(island, material);
                        islandBlock.setAmount(islandBlock.getAmount() + 1);
                    }
                }
            }
        }
    });
    if (!Bukkit.isPrimaryThread()) {
        Bukkit.getScheduler().runTask(IridiumSkyblock.getInstance(), () -> getAllTileInIsland(island, chunks));
    } else {
        getAllTileInIsland(island, chunks);
    }
}
Also used : IslandRegenSettings(com.iridium.iridiumskyblock.configs.Configuration.IslandRegenSettings) IntStream(java.util.stream.IntStream) IridiumSkyblockAPI(com.iridium.iridiumskyblock.api.IridiumSkyblockAPI) java.util(java.util) NBTCompound(com.iridium.iridiumcore.dependencies.nbtapi.NBTCompound) ItemStackUtils(com.iridium.iridiumcore.utils.ItemStackUtils) LocalDateTime(java.time.LocalDateTime) CompletableFuture(java.util.concurrent.CompletableFuture) Player(org.bukkit.entity.Player) XMaterial(com.iridium.iridiumcore.dependencies.xseries.XMaterial) org.bukkit(org.bukkit) BankItem(com.iridium.iridiumskyblock.bank.BankItem) com.iridium.iridiumskyblock(com.iridium.iridiumskyblock) Block(org.bukkit.block.Block) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) LocationUtils(com.iridium.iridiumskyblock.utils.LocationUtils) XBiome(com.iridium.iridiumcore.dependencies.xseries.XBiome) IslandDeleteEvent(com.iridium.iridiumskyblock.api.IslandDeleteEvent) Placeholder(com.iridium.iridiumcore.utils.Placeholder) PaperLib(com.iridium.iridiumcore.dependencies.paperlib.PaperLib) CreatureSpawner(org.bukkit.block.CreatureSpawner) Entity(org.bukkit.entity.Entity) ImmutableMap(com.google.common.collect.ImmutableMap) BlockState(org.bukkit.block.BlockState) EntityType(org.bukkit.entity.EntityType) Collectors(java.util.stream.Collectors) StringUtils(com.iridium.iridiumcore.utils.StringUtils) ItemStack(org.bukkit.inventory.ItemStack) Schematics(com.iridium.iridiumskyblock.configs.Schematics) InventoryHolder(org.bukkit.inventory.InventoryHolder) Nullable(org.jetbrains.annotations.Nullable) IslandRegenEvent(com.iridium.iridiumskyblock.api.IslandRegenEvent) com.iridium.iridiumskyblock.database(com.iridium.iridiumskyblock.database) PlayerTeleportEvent(org.bukkit.event.player.PlayerTeleportEvent) PlayerUtils(com.iridium.iridiumskyblock.utils.PlayerUtils) BukkitTask(org.bukkit.scheduler.BukkitTask) OceanGenerator(com.iridium.iridiumskyblock.generators.OceanGenerator) NotNull(org.jetbrains.annotations.NotNull) NBTItem(com.iridium.iridiumcore.dependencies.nbtapi.NBTItem) XMaterial(com.iridium.iridiumcore.dependencies.xseries.XMaterial)

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