diff --git a/src/main/java/me/goodandevil/skyblock/api/event/island/IslandLevelChangeEvent.java b/src/main/java/me/goodandevil/skyblock/api/event/island/IslandLevelChangeEvent.java index 10f6f90b..aa9d2a9e 100644 --- a/src/main/java/me/goodandevil/skyblock/api/event/island/IslandLevelChangeEvent.java +++ b/src/main/java/me/goodandevil/skyblock/api/event/island/IslandLevelChangeEvent.java @@ -12,7 +12,7 @@ public class IslandLevelChangeEvent extends IslandEvent { private final IslandLevel level; public IslandLevelChangeEvent(Island island, IslandLevel level) { - super(island, true); + super(island); this.level = level; } diff --git a/src/main/java/me/goodandevil/skyblock/island/IslandManager.java b/src/main/java/me/goodandevil/skyblock/island/IslandManager.java index 37857fd3..6ce27331 100644 --- a/src/main/java/me/goodandevil/skyblock/island/IslandManager.java +++ b/src/main/java/me/goodandevil/skyblock/island/IslandManager.java @@ -128,7 +128,12 @@ public class IslandManager { islandPositionList.setZ(z); } - return new org.bukkit.Location(skyblock.getWorldManager().getWorld(world), x, 72, z); + Config config = skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "config.yml")); + FileConfiguration configLoad = config.getFileConfiguration(); + + int islandHeight = configLoad.getInt("Island.World." + world.name() + ".IslandSpawnHeight", 72); + + return new org.bukkit.Location(skyblock.getWorldManager().getWorld(world), x, islandHeight, z); } } diff --git a/src/main/java/me/goodandevil/skyblock/levelling/LevellingManager.java b/src/main/java/me/goodandevil/skyblock/levelling/LevellingManager.java index b8fee277..0a12f6b4 100644 --- a/src/main/java/me/goodandevil/skyblock/levelling/LevellingManager.java +++ b/src/main/java/me/goodandevil/skyblock/levelling/LevellingManager.java @@ -30,9 +30,11 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Objects; +import java.util.Set; import java.util.logging.Level; public class LevellingManager { @@ -81,6 +83,7 @@ public class LevellingManager { boolean isWildStackerEnabled = Bukkit.getPluginManager().isPluginEnabled("WildStacker"); Map levellingData = new HashMap<>(); + Set spawnerLocations = new HashSet<>(); // These have to be checked synchronously :( List blacklistedMaterials = new ArrayList<>(); blacklistedMaterials.add(Materials.AIR.getPostMaterial()); @@ -95,7 +98,7 @@ public class LevellingManager { if (!chunk.isReadyToScan()) return; if (chunk.isFinished()) { - finalizeMaterials(levellingData, player, island); + Bukkit.getScheduler().scheduleSyncDelayedTask(skyblock, () -> finalizeMaterials(levellingData, spawnerLocations, player, island), 1); cancel(); return; } @@ -164,23 +167,24 @@ public class LevellingManager { if (isWildStackerEnabled && spawnerType == null) { com.bgsoftware.wildstacker.api.handlers.SystemManager wildStacker = com.bgsoftware.wildstacker.api.WildStackerAPI.getWildStacker().getSystemManager(); - if (wildStacker.isStackedSpawner(location.getBlock())) { - com.bgsoftware.wildstacker.api.objects.StackedSpawner spawner = wildStacker.getStackedSpawner(location); + com.bgsoftware.wildstacker.api.objects.StackedSpawner spawner = wildStacker.getStackedSpawner(location); + if (spawner != null) { amount = spawner.getStackAmount(); spawnerType = spawner.getSpawnedType(); } } if (spawnerType == null) { - spawnerType = ((CreatureSpawner) location.getBlock().getState()).getSpawnedType(); + spawnerLocations.add(location); + continue; } } else { if (isWildStackerEnabled) { World world = Bukkit.getWorld(chunkSnapshotList.getWorldName()); Location location = new Location(world, chunkSnapshotList.getX() * 16 + x, y, chunkSnapshotList.getZ() * 16 + z); com.bgsoftware.wildstacker.api.handlers.SystemManager wildStacker = com.bgsoftware.wildstacker.api.WildStackerAPI.getWildStacker().getSystemManager(); - if (wildStacker.isStackedBarrel(location.getBlock())) { - com.bgsoftware.wildstacker.api.objects.StackedBarrel barrel = wildStacker.getStackedBarrel(location.getBlock()); + com.bgsoftware.wildstacker.api.objects.StackedBarrel barrel = wildStacker.getStackedBarrel(location); + if (barrel != null) { amount = barrel.getStackAmount(); blockMaterial = barrel.getType(); blockData = barrel.getData(); @@ -196,7 +200,9 @@ public class LevellingManager { Location location = new Location(world, chunkSnapshotList.getX() * 16 + x, y, chunkSnapshotList.getZ() * 16 + z); if (stackableManager.isStacked(location)) { Stackable stackable = stackableManager.getStack(location, blockMaterial); - amount = stackable.getSize(); + if (stackable != null) { + amount = stackable.getSize(); + } } } } @@ -219,7 +225,20 @@ public class LevellingManager { }.runTaskTimerAsynchronously(skyblock, 0L, 1L); } - private void finalizeMaterials(Map levellingData, Player player, Island island) { + private void finalizeMaterials(Map levellingData, Set spawnerLocations, Player player, Island island) { + for (Location location : spawnerLocations) { + if (!(location.getBlock().getState() instanceof CreatureSpawner)) + continue; + + int amount = 1; + EntityType spawnerType = ((CreatureSpawner) location.getBlock().getState()).getSpawnedType(); + + LevellingData data = new LevellingData(Materials.SPAWNER.parseMaterial(), (byte) 0, spawnerType); + Long totalAmountInteger = levellingData.get(data); + long totalAmount = totalAmountInteger == null ? amount : totalAmountInteger + amount; + levellingData.put(data, totalAmount); + } + Map materials = new HashMap<>(); for (LevellingData data : levellingData.keySet()) { long amount = levellingData.get(data); @@ -241,8 +260,7 @@ public class LevellingManager { level.setLastCalculatedLevel(level.getLevel()); level.setMaterials(materials); - Bukkit.getServer().getPluginManager().callEvent( - new IslandLevelChangeEvent(island.getAPIWrapper(), island.getAPIWrapper().getLevel())); + Bukkit.getServer().getPluginManager().callEvent(new IslandLevelChangeEvent(island.getAPIWrapper(), island.getAPIWrapper().getLevel())); if (player != null) { me.goodandevil.skyblock.menus.Levelling.getInstance().open(player); diff --git a/src/main/java/me/goodandevil/skyblock/placeholder/EZPlaceholder.java b/src/main/java/me/goodandevil/skyblock/placeholder/EZPlaceholder.java index f3d4c2c3..2394fc39 100644 --- a/src/main/java/me/goodandevil/skyblock/placeholder/EZPlaceholder.java +++ b/src/main/java/me/goodandevil/skyblock/placeholder/EZPlaceholder.java @@ -47,6 +47,8 @@ public class EZPlaceholder extends PlaceholderExpansion implements Listener { return skyblock.getDescription().getVersion(); } + public boolean persist() { return true; } + public String onPlaceholderRequest(Player player, String identifier) { PlaceholderManager placeholderManager = skyblock.getPlaceholderManager(); LeaderboardManager leaderboardManager = skyblock.getLeaderboardManager(); @@ -143,13 +145,4 @@ public class EZPlaceholder extends PlaceholderExpansion implements Listener { return placeholderManager.getPlaceholder(player, "fabledskyblock_" + identifier); } - /** - * If a player uses '/papi reload' then we need to reload this expansion - */ - @EventHandler - public void onExpansionUnregister(ExpansionUnregisterEvent event) { - if (event.getExpansion() instanceof EZPlaceholder) { - Bukkit.getScheduler().scheduleSyncDelayedTask(skyblock, this::register, 20L); - } - } } diff --git a/src/main/java/me/goodandevil/skyblock/utils/AbstractAnvilGUI.java b/src/main/java/me/goodandevil/skyblock/utils/AbstractAnvilGUI.java index f421601e..a2b66993 100644 --- a/src/main/java/me/goodandevil/skyblock/utils/AbstractAnvilGUI.java +++ b/src/main/java/me/goodandevil/skyblock/utils/AbstractAnvilGUI.java @@ -3,6 +3,7 @@ package me.goodandevil.skyblock.utils; import me.goodandevil.skyblock.SkyBlock; import me.goodandevil.skyblock.utils.version.NMSUtil; import org.bukkit.Bukkit; +import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -22,7 +23,6 @@ import java.util.HashMap; import java.util.Map; public class AbstractAnvilGUI { - private static Class BlockPositionClass; private static Class PacketPlayOutOpenWindowClass; private static Class IChatBaseComponentClass; @@ -35,6 +35,7 @@ public class AbstractAnvilGUI { private static Class WorldClass; private static Class PlayerInventoryClass; private static Class ContainersClass; + private static Class CraftPlayerClass; private Player player; private Map items = new HashMap<>(); @@ -52,6 +53,7 @@ public class AbstractAnvilGUI { ContainerClass = NMSUtil.getNMSClass("Container"); WorldClass = NMSUtil.getNMSClass("World"); PlayerInventoryClass = NMSUtil.getNMSClass("PlayerInventory"); + CraftPlayerClass = NMSUtil.getCraftClass("entity.CraftPlayer"); if (NMSUtil.getVersionNumber() > 13) { ContainerAccessClass = NMSUtil.getNMSClass("ContainerAccess"); @@ -59,84 +61,77 @@ public class AbstractAnvilGUI { } } - public AbstractAnvilGUI(final Player player, final AnvilClickEventHandler handler) { + public AbstractAnvilGUI(Player player, AnvilClickEventHandler handler) { + SkyBlock instance = SkyBlock.getInstance(); this.player = player; this.listener = new Listener() { - @EventHandler(priority = EventPriority.LOWEST) + @EventHandler(priority = EventPriority.HIGHEST) public void onInventoryClick(InventoryClickEvent event) { - if (event.getWhoClicked() instanceof Player) { + if (event.getWhoClicked() instanceof Player && event.getInventory().equals(AbstractAnvilGUI.this.inv)) { + event.setCancelled(true); - if (event.getInventory().equals(inv)) { - event.setCancelled(true); + ItemStack item = event.getCurrentItem(); + int slot = event.getRawSlot(); - ItemStack item = event.getCurrentItem(); - int slot = event.getRawSlot(); - String name = ""; + if (item == null || item.getType().equals(Material.AIR) || slot != 2) + return; - if (item != null) { - if (item.hasItemMeta()) { - ItemMeta meta = item.getItemMeta(); + String name = ""; - if (meta != null && meta.hasDisplayName()) { - name = meta.getDisplayName(); - } - } - } + ItemMeta meta = item.getItemMeta(); + if (meta != null && meta.hasDisplayName()) + name = meta.getDisplayName(); - AnvilClickEvent clickEvent = new AnvilClickEvent(AnvilSlot.bySlot(slot), name); + AnvilClickEvent clickEvent = new AnvilClickEvent(AnvilSlot.bySlot(slot), name); + handler.onAnvilClick(clickEvent); - handler.onAnvilClick(clickEvent); + if (clickEvent.getWillClose()) + event.getWhoClicked().closeInventory(); - if (clickEvent.getWillClose()) { - event.getWhoClicked().closeInventory(); - } - - if (clickEvent.getWillDestroy()) { - destroy(); - } - } + if (clickEvent.getWillDestroy()) + AbstractAnvilGUI.this.destroy(); } } - @EventHandler(priority = EventPriority.LOWEST) + @EventHandler(priority = EventPriority.HIGHEST) public void onInventoryClose(InventoryCloseEvent event) { - if (event.getPlayer() instanceof Player) { + if (event.getPlayer() instanceof Player && AbstractAnvilGUI.this.inv.equals(event.getInventory())) { Inventory inv = event.getInventory(); player.setLevel(player.getLevel() - 1); - if (inv.equals(inv)) { - inv.clear(); - destroy(); - } + inv.clear(); + Bukkit.getScheduler().scheduleSyncDelayedTask(instance, () -> { + AbstractAnvilGUI.this.destroy(); + }, 1L); } } - @EventHandler(priority = EventPriority.LOWEST) + @EventHandler(priority = EventPriority.HIGHEST) public void onPlayerQuit(PlayerQuitEvent event) { - if (event.getPlayer().equals(getPlayer())) { + if (event.getPlayer().equals(AbstractAnvilGUI.this.player)) { player.setLevel(player.getLevel() - 1); - destroy(); + AbstractAnvilGUI.this.destroy(); } } }; - Bukkit.getPluginManager().registerEvents(listener, SkyBlock.getInstance()); + Bukkit.getPluginManager().registerEvents(this.listener, instance); } public Player getPlayer() { - return player; + return this.player; } public void setSlot(AnvilSlot slot, ItemStack item) { - items.put(slot, item); + this.items.put(slot, item); } public void open() { - player.setLevel(player.getLevel() + 1); + this.player.setLevel(this.player.getLevel() + 1); try { - Object craftPlayer = NMSUtil.getCraftClass("entity.CraftPlayer").cast(player); - Method getHandleMethod = craftPlayer.getClass().getMethod("getHandle"); + Object craftPlayer = CraftPlayerClass.cast(this.player); + Method getHandleMethod = CraftPlayerClass.getMethod("getHandle"); Object entityPlayer = getHandleMethod.invoke(craftPlayer); Object playerInventory = NMSUtil.getFieldObject(entityPlayer, NMSUtil.getField(entityPlayer.getClass(), "inventory", false)); Object world = NMSUtil.getFieldObject(entityPlayer, NMSUtil.getField(entityPlayer.getClass(), "world", false)); @@ -159,10 +154,10 @@ public class AbstractAnvilGUI { Method getBukkitViewMethod = container.getClass().getMethod("getBukkitView"); Object bukkitView = getBukkitViewMethod.invoke(container); Method getTopInventoryMethod = bukkitView.getClass().getMethod("getTopInventory"); - inv = (Inventory) getTopInventoryMethod.invoke(bukkitView); + this.inv = (Inventory) getTopInventoryMethod.invoke(bukkitView); - for (AnvilSlot slot : items.keySet()) { - inv.setItem(slot.getSlot(), items.get(slot)); + for (AnvilSlot slot : this.items.keySet()) { + this.inv.setItem(slot.getSlot(), this.items.get(slot)); } Method nextContainerCounterMethod = entityPlayer.getClass().getMethod("nextContainerCounter"); @@ -183,7 +178,7 @@ public class AbstractAnvilGUI { .newInstance(c, "minecraft:anvil", inventoryTitle, 0); } - NMSUtil.sendPacket(player, packet); + NMSUtil.sendPacket(this.player, packet); Field activeContainerField = NMSUtil.getField(EntityHumanClass, "activeContainer", true); @@ -203,12 +198,12 @@ public class AbstractAnvilGUI { } public void destroy() { - player = null; - items = null; + this.player = null; + this.items = null; - HandlerList.unregisterAll(listener); + HandlerList.unregisterAll(this.listener); - listener = null; + this.listener = null; } public enum AnvilSlot { @@ -233,7 +228,7 @@ public class AbstractAnvilGUI { } public int getSlot() { - return slot; + return this.slot; } } @@ -256,15 +251,15 @@ public class AbstractAnvilGUI { } public AnvilSlot getSlot() { - return slot; + return this.slot; } public String getName() { - return name; + return this.name; } public boolean getWillClose() { - return close; + return this.close; } public void setWillClose(boolean close) { @@ -272,7 +267,7 @@ public class AbstractAnvilGUI { } public boolean getWillDestroy() { - return destroy; + return this.destroy; } public void setWillDestroy(boolean destroy) { @@ -280,4 +275,4 @@ public class AbstractAnvilGUI { } } -} +} \ No newline at end of file diff --git a/src/main/java/me/goodandevil/skyblock/utils/structure/SchematicUtil.java b/src/main/java/me/goodandevil/skyblock/utils/structure/SchematicUtil.java index e7b21ec4..2947377c 100644 --- a/src/main/java/me/goodandevil/skyblock/utils/structure/SchematicUtil.java +++ b/src/main/java/me/goodandevil/skyblock/utils/structure/SchematicUtil.java @@ -1,15 +1,5 @@ package me.goodandevil.skyblock.utils.structure; -import com.sk89q.worldedit.EditSession; -import com.sk89q.worldedit.WorldEdit; -import com.sk89q.worldedit.bukkit.BukkitWorld; -import com.sk89q.worldedit.extent.clipboard.Clipboard; -import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat; -import com.sk89q.worldedit.extent.clipboard.io.ClipboardReader; -import com.sk89q.worldedit.function.operation.Operation; -import com.sk89q.worldedit.function.operation.Operations; -import com.sk89q.worldedit.math.BlockVector3; -import com.sk89q.worldedit.session.ClipboardHolder; import me.goodandevil.skyblock.SkyBlock; import me.goodandevil.skyblock.utils.version.NMSUtil; import org.bukkit.Bukkit; @@ -29,16 +19,16 @@ public class SchematicUtil { Bukkit.getScheduler().runTask(SkyBlock.getInstance(), () -> { if (NMSUtil.getVersionNumber() > 12) { // WorldEdit 7 - ClipboardFormat format = com.sk89q.worldedit.extent.clipboard.io.ClipboardFormats.findByFile(schematicFile); - try (ClipboardReader reader = format.getReader(new FileInputStream(schematicFile))) { - Clipboard clipboard = reader.read(); - try (EditSession editSession = WorldEdit.getInstance().getEditSessionFactory().getEditSession(new BukkitWorld(location.getWorld()), -1)) { - Operation operation = new ClipboardHolder(clipboard) + com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat format = com.sk89q.worldedit.extent.clipboard.io.ClipboardFormats.findByFile(schematicFile); + try (com.sk89q.worldedit.extent.clipboard.io.ClipboardReader reader = format.getReader(new FileInputStream(schematicFile))) { + com.sk89q.worldedit.extent.clipboard.Clipboard clipboard = reader.read(); + try (com.sk89q.worldedit.EditSession editSession = com.sk89q.worldedit.WorldEdit.getInstance().getEditSessionFactory().getEditSession(new com.sk89q.worldedit.bukkit.BukkitWorld(location.getWorld()), -1)) { + com.sk89q.worldedit.function.operation.Operation operation = new com.sk89q.worldedit.session.ClipboardHolder(clipboard) .createPaste(editSession) - .to(BlockVector3.at(location.getX(), location.getY(), location.getZ())) + .to(com.sk89q.worldedit.math.BlockVector3.at(location.getX(), location.getY(), location.getZ())) .ignoreAirBlocks(true) .build(); - Operations.complete(operation); + com.sk89q.worldedit.function.operation.Operations.complete(operation); } catch (Exception e) { e.printStackTrace(); } diff --git a/src/main/java/me/goodandevil/skyblock/utils/version/NMSUtil.java b/src/main/java/me/goodandevil/skyblock/utils/version/NMSUtil.java index 6bc54997..65205a20 100644 --- a/src/main/java/me/goodandevil/skyblock/utils/version/NMSUtil.java +++ b/src/main/java/me/goodandevil/skyblock/utils/version/NMSUtil.java @@ -33,7 +33,7 @@ public class NMSUtil { } } - public static Class getCraftClass(String className) throws ClassNotFoundException { + public static Class getCraftClass(String className) { try { String fullName = "org.bukkit.craftbukkit." + getVersion() + className; Class clazz = Class.forName(fullName); diff --git a/src/main/java/me/goodandevil/skyblock/world/WorldManager.java b/src/main/java/me/goodandevil/skyblock/world/WorldManager.java index 1e145296..6902e626 100644 --- a/src/main/java/me/goodandevil/skyblock/world/WorldManager.java +++ b/src/main/java/me/goodandevil/skyblock/world/WorldManager.java @@ -40,6 +40,10 @@ public class WorldManager { boolean netherWorldEnabled = configLoad.getBoolean("Island.World.Nether.Enable"); boolean endWorldEnabled = configLoad.getBoolean("Island.World.End.Enable"); + World.Environment normalWorldEnvironment = World.Environment.valueOf(configLoad.getString("Island.World.Normal.Environment")); + World.Environment netherWorldEnvironment = World.Environment.valueOf(configLoad.getString("Island.World.Nether.Environment")); + World.Environment endWorldEnvironment = World.Environment.valueOf(configLoad.getString("Island.World.End.Environment")); + normalWorld = Bukkit.getServer().getWorld(normalWorldName); netherWorld = Bukkit.getServer().getWorld(netherWorldName); endWorld = Bukkit.getServer().getWorld(endWorldName); @@ -47,28 +51,28 @@ public class WorldManager { if (normalWorld == null) { Bukkit.getServer().getLogger().log(Level.INFO, "SkyBlock | Info: Generating VoidWorld '" + normalWorldName + "'."); - normalWorld = WorldCreator.name(normalWorldName).type(WorldType.FLAT).environment(World.Environment.NORMAL) + normalWorld = WorldCreator.name(normalWorldName).type(WorldType.FLAT).environment(normalWorldEnvironment) .generator(new VoidGenerator()).createWorld(); - Bukkit.getServer().getScheduler().runTask(skyblock, () -> registerMultiverse(normalWorldName, World.Environment.NORMAL)); + Bukkit.getServer().getScheduler().runTask(skyblock, () -> registerMultiverse(normalWorldName, normalWorldEnvironment)); } if (netherWorld == null && netherWorldEnabled) { Bukkit.getServer().getLogger().log(Level.INFO, "SkyBlock | Info: Generating VoidWorld '" + netherWorldName + "'."); - netherWorld = WorldCreator.name(netherWorldName).type(WorldType.FLAT).environment(World.Environment.NETHER) + netherWorld = WorldCreator.name(netherWorldName).type(WorldType.FLAT).environment(netherWorldEnvironment) .generator(new VoidGenerator()).createWorld(); - Bukkit.getServer().getScheduler().runTask(skyblock, () -> registerMultiverse(netherWorldName, World.Environment.NETHER)); + Bukkit.getServer().getScheduler().runTask(skyblock, () -> registerMultiverse(netherWorldName, netherWorldEnvironment)); } if (endWorld == null && endWorldEnabled) { Bukkit.getServer().getLogger().log(Level.INFO, "SkyBlock | Info: Generating VoidWorld '" + endWorldName + "'."); - endWorld = WorldCreator.name(endWorldName).type(WorldType.FLAT).environment(World.Environment.THE_END) + endWorld = WorldCreator.name(endWorldName).type(WorldType.FLAT).environment(endWorldEnvironment) .generator(new VoidGenerator()).createWorld(); - Bukkit.getServer().getScheduler().runTask(skyblock, () -> registerMultiverse(endWorldName, World.Environment.THE_END)); + Bukkit.getServer().getScheduler().runTask(skyblock, () -> registerMultiverse(endWorldName, endWorldEnvironment)); } } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 6a4849e3..6000ad8d 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -35,18 +35,22 @@ Island: # Time until player can create another island. Time: 60 World: - # [!] The Island height is 72 blocks. - # Delete the Island world when changing the liquid option. + # Delete the Island world when changing the liquid option. # If lava disabled, the world will be a water world. # -1 to disable Nether and End unlock prices. + # Valid Enrivonments: NORMAL, NETHER, THE_END Normal: Name: "island_normal_world" + IslandSpawnHeight: 72 + Environment: NORMAL Liquid: Enable: false Lava: false Height: 60 Nether: Name: "island_nether_world" + IslandSpawnHeight: 72 + Environment: NETHER UnlockPrice: 10000 Enable: true Liquid: @@ -55,6 +59,8 @@ Island: Height: 60 End: Name: "island_end_world" + IslandSpawnHeight: 72 + Environment: THE_END UnlockPrice: 50000 Enable: true Liquid: