Search in sources :

Example 1 with XMaterial

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

the class FurnaceSmeltListener method monitorFurnaceSmelt.

@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void monitorFurnaceSmelt(FurnaceSmeltEvent event) {
    Optional<Island> island = IridiumSkyblock.getInstance().getIslandManager().getIslandViaLocation(event.getBlock().getLocation());
    XMaterial material = XMaterial.matchXMaterial(event.getSource().getType());
    island.ifPresent(value -> IridiumSkyblock.getInstance().getMissionManager().handleMissionUpdates(value, "SMELT", material.name(), 1));
}
Also used : XMaterial(com.iridium.iridiumcore.dependencies.xseries.XMaterial) Island(com.iridium.iridiumskyblock.database.Island) EventHandler(org.bukkit.event.EventHandler)

Example 2 with XMaterial

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

the class PlayerInteractListener method onPlayerInteract.

@EventHandler
public void onPlayerInteract(PlayerInteractEvent event) {
    Player player = event.getPlayer();
    User user = IridiumSkyblock.getInstance().getUserManager().getUser(player);
    user.getIsland().ifPresent(island -> {
        if (event.getAction() != Action.PHYSICAL) {
            int islandCrystals = IridiumSkyblock.getInstance().getIslandManager().getIslandCrystals(event.getPlayer().getInventory().getItemInMainHand());
            if (islandCrystals > 0) {
                // Required because Spigot likes to trigger this event for each hand which removes two items
                if (event.getHand() == EquipmentSlot.HAND) {
                    int amount = event.getPlayer().getInventory().getItemInMainHand().getAmount();
                    if (amount == 1) {
                        event.getPlayer().getInventory().setItemInMainHand(null);
                    } else {
                        event.getPlayer().getInventory().getItemInMainHand().setAmount(amount - 1);
                    }
                    IslandBank islandBank = IridiumSkyblock.getInstance().getIslandManager().getIslandBank(island, IridiumSkyblock.getInstance().getBankItems().crystalsBankItem);
                    islandBank.setNumber(islandBank.getNumber() + islandCrystals);
                    player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().bankDeposited.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix).replace("%type%", IridiumSkyblock.getInstance().getBankItems().crystalsBankItem.getDisplayName()).replace("%amount%", String.valueOf(islandCrystals))));
                    event.setCancelled(true);
                }
            }
        }
    });
    if (event.getClickedBlock() == null)
        return;
    IridiumSkyblock.getInstance().getIslandManager().getIslandViaLocation(event.getClickedBlock().getLocation()).ifPresent(island -> {
        XMaterial material = XMaterial.matchXMaterial(event.getClickedBlock().getType());
        String materialName = material.name();
        if (!IridiumSkyblock.getInstance().getIslandManager().getIslandPermission(island, user, PermissionType.INTERACT)) {
            event.setCancelled(true);
            if (hasNoCooldown(player)) {
                player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().cannotInteract.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
            }
            return;
        }
        if (event.getAction() == Action.PHYSICAL && material == XMaterial.FARMLAND) {
            if (!IridiumSkyblock.getInstance().getIslandManager().getIslandPermission(island, user, PermissionType.TRAMPLE_CROPS)) {
                event.setCancelled(true);
                if (hasNoCooldown(player)) {
                    player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().cannotTrampleCrops.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
                }
            }
        } else if (materialName.contains("DOOR")) {
            if (!IridiumSkyblock.getInstance().getIslandManager().getIslandPermission(island, user, PermissionType.DOORS)) {
                event.setCancelled(true);
                if (hasNoCooldown(player)) {
                    player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().cannotOpenDoors.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
                }
            }
        } else if (event.getClickedBlock().getState() instanceof InventoryHolder) {
            if (!IridiumSkyblock.getInstance().getIslandManager().getIslandPermission(island, user, PermissionType.OPEN_CONTAINERS)) {
                event.setCancelled(true);
                if (hasNoCooldown(player)) {
                    player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().cannotOpenContainers.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
                }
            }
        } else if (redstoneMaterials.contains(material) || materialName.contains("BUTTON") || materialName.contains("PRESSURE_PLATE")) {
            if (!IridiumSkyblock.getInstance().getIslandManager().getIslandPermission(island, user, PermissionType.REDSTONE)) {
                event.setCancelled(true);
                if (hasNoCooldown(player)) {
                    player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().cannotUseRedstone.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
                }
            }
        } else if (materialName.contains("MINECART") || materialName.contains("BOAT") || materialName.contains("EGG") || materialName.contains("BUCKET") || material == XMaterial.END_CRYSTAL || material == XMaterial.ARMOR_STAND) {
            if (!IridiumSkyblock.getInstance().getIslandManager().getIslandPermission(island, user, PermissionType.INTERACT_ENTITIES)) {
                event.setCancelled(true);
                if (hasNoCooldown(player)) {
                    player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().cannotSpawnEntities.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
                }
            }
        }
    });
}
Also used : IslandBank(com.iridium.iridiumskyblock.database.IslandBank) Player(org.bukkit.entity.Player) User(com.iridium.iridiumskyblock.database.User) XMaterial(com.iridium.iridiumcore.dependencies.xseries.XMaterial) InventoryHolder(org.bukkit.inventory.InventoryHolder) EventHandler(org.bukkit.event.EventHandler)

Example 3 with XMaterial

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

the class BlockBreakListener method monitorBlockBreak.

@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void monitorBlockBreak(BlockBreakEvent 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 -> {
        BlockData blockData = event.getBlock().getBlockData();
        if (blockData instanceof Ageable) {
            Ageable ageable = (Ageable) blockData;
            if (ageable.getAge() == ageable.getMaximumAge()) {
                IridiumSkyblock.getInstance().getMissionManager().handleMissionUpdates(island, "MINE", material.name(), 1);
            }
        } else {
            IridiumSkyblock.getInstance().getMissionManager().handleMissionUpdates(island, "MINE", material.name(), 1);
        }
        IslandBooster islandBooster = IridiumSkyblock.getInstance().getIslandManager().getIslandBooster(island, "experience");
        if (islandBooster.isActive()) {
            event.setExpToDrop(event.getExpToDrop() * 2);
        }
        IslandBlocks islandBlocks = IridiumSkyblock.getInstance().getIslandManager().getIslandBlock(island, material);
        if (islandBlocks.getAmount() > 0) {
            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());
            if (islandSpawners.getAmount() > 0) {
                islandSpawners.setAmount(islandSpawners.getAmount() - 1);
            }
        }
    });
}
Also used : Player(org.bukkit.entity.Player) XMaterial(com.iridium.iridiumcore.dependencies.xseries.XMaterial) BlockData(org.bukkit.block.data.BlockData) Ageable(org.bukkit.block.data.Ageable) CreatureSpawner(org.bukkit.block.CreatureSpawner) EventHandler(org.bukkit.event.EventHandler)

Example 4 with XMaterial

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

the class BlockBreakListener method onBlockBreak.

@EventHandler(ignoreCancelled = true)
public void onBlockBreak(BlockBreakEvent 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())
        return;
    XMaterial material = XMaterial.matchXMaterial(event.getBlock().getType());
    if (!IridiumSkyblock.getInstance().getIslandManager().getIslandPermission(island.get(), user, PermissionType.BLOCK_BREAK)) {
        event.setCancelled(true);
        player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().cannotBreakBlocks.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
    } else if (material.equals(XMaterial.SPAWNER) && !IridiumSkyblock.getInstance().getIslandManager().getIslandPermission(island.get(), user, PermissionType.SPAWNERS)) {
        event.setCancelled(true);
        player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().cannotMineSpawners.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
    }
}
Also used : Player(org.bukkit.entity.Player) XMaterial(com.iridium.iridiumcore.dependencies.xseries.XMaterial) EventHandler(org.bukkit.event.EventHandler)

Example 5 with XMaterial

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

the class BlockFormListener method onBlockForm.

@EventHandler(ignoreCancelled = true)
public void onBlockForm(BlockFormEvent event) {
    if (!IridiumSkyblockAPI.getInstance().isIslandWorld(event.getBlock().getWorld()))
        return;
    XMaterial newMaterial = XMaterial.matchXMaterial(event.getNewState().getType());
    // Custom basalt generators should only work in nether
    if (newMaterial == XMaterial.COBBLESTONE || newMaterial == XMaterial.STONE || (newMaterial == XMaterial.BASALT && event.getBlock().getLocation().getWorld().getEnvironment() == World.Environment.NETHER)) {
        Optional<Island> island = IridiumSkyblock.getInstance().getIslandManager().getIslandViaLocation(event.getNewState().getLocation());
        if (island.isPresent()) {
            int upgradeLevel = IridiumSkyblock.getInstance().getIslandManager().getIslandUpgrade(island.get(), "generator").getLevel();
            RandomAccessList<XMaterial> randomMaterialList = newMaterial == XMaterial.BASALT ? netherOreLevels.get(upgradeLevel) : normalOreLevels.get(upgradeLevel);
            if (randomMaterialList == null)
                return;
            Optional<XMaterial> xMaterialOptional = randomMaterialList.nextElement();
            if (!xMaterialOptional.isPresent())
                return;
            Material material = xMaterialOptional.get().parseMaterial();
            if (material == Material.COBBLESTONE && newMaterial == XMaterial.STONE)
                material = Material.STONE;
            if (material != null)
                event.getNewState().setType(material);
        }
    }
}
Also used : XMaterial(com.iridium.iridiumcore.dependencies.xseries.XMaterial) Material(org.bukkit.Material) 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