From a299a3c21d0045474d9c90dac9cc45a0266933cb Mon Sep 17 00:00:00 2001 From: Shyanne Date: Sun, 8 Oct 2023 13:39:24 -0400 Subject: [PATCH 1/2] killed the dragon used NBTAPI to edit level.dat values and prevent the dragon or bedrock portal from spawning because im cool like that --- .../iridiumskyblock/IridiumSkyblock.java | 10 +++-- .../managers/IslandManager.java | 37 ++++++++++++++++++- 2 files changed, 43 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/iridium/iridiumskyblock/IridiumSkyblock.java b/src/main/java/com/iridium/iridiumskyblock/IridiumSkyblock.java index 4de2f3959..1a0c99238 100644 --- a/src/main/java/com/iridium/iridiumskyblock/IridiumSkyblock.java +++ b/src/main/java/com/iridium/iridiumskyblock/IridiumSkyblock.java @@ -89,9 +89,13 @@ public void onEnable() { this.teamManager = new IslandManager(); - this.teamManager.createWorld(World.Environment.NORMAL, configuration.worldName); - this.teamManager.createWorld(World.Environment.NETHER, configuration.worldName + "_nether"); - this.teamManager.createWorld(World.Environment.THE_END, configuration.worldName + "_the_end"); + try { + this.teamManager.createWorld(World.Environment.NORMAL, configuration.worldName); + this.teamManager.createWorld(World.Environment.NETHER, configuration.worldName + "_nether"); + this.teamManager.createWorld(World.Environment.THE_END, configuration.worldName + "_the_end"); + } catch (IOException e) { + throw new RuntimeException(e); + } this.schematicManager = new SchematicManager(); this.userManager = new UserManager(); diff --git a/src/main/java/com/iridium/iridiumskyblock/managers/IslandManager.java b/src/main/java/com/iridium/iridiumskyblock/managers/IslandManager.java index 381d16b3f..212356d93 100644 --- a/src/main/java/com/iridium/iridiumskyblock/managers/IslandManager.java +++ b/src/main/java/com/iridium/iridiumskyblock/managers/IslandManager.java @@ -1,6 +1,7 @@ package com.iridium.iridiumskyblock.managers; import com.iridium.iridiumcore.dependencies.nbtapi.NBTCompound; +import com.iridium.iridiumcore.dependencies.nbtapi.NBTFile; import com.iridium.iridiumcore.dependencies.nbtapi.NBTItem; import com.iridium.iridiumcore.dependencies.paperlib.PaperLib; import com.iridium.iridiumcore.dependencies.xseries.XMaterial; @@ -37,6 +38,8 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.io.File; +import java.io.IOException; import java.time.LocalDateTime; import java.util.*; import java.util.concurrent.CompletableFuture; @@ -49,12 +52,44 @@ public IslandManager() { super(IridiumSkyblock.getInstance()); } - public void createWorld(World.Environment environment, String name) { + public void createWorld(World.Environment environment, String name) throws IOException { if (!IridiumSkyblock.getInstance().getConfiguration().enabledWorlds.getOrDefault(environment, true)) return; WorldCreator worldCreator = new WorldCreator(name) .generator(IridiumSkyblock.getInstance().getDefaultWorldGenerator(name, null)) .environment(environment); Bukkit.createWorld(worldCreator); + + if(Bukkit.getWorld(worldCreator.name()).getEnvironment() == World.Environment.THE_END) { + + Bukkit.unloadWorld(worldCreator.name(), true); + + File file = new File(worldCreator.name() + File.separator + "level.dat"); + NBTFile worldFile = new NBTFile(file); + + if(worldFile.getCompound("Data").getCompound("DragonFight") == null) { + IridiumSkyblock.getInstance().getLogger().warning("Cannot load \"DragonFight\" compound because \"DragonFight\" is null."); + return; + } + + NBTCompound compound = worldFile.getCompound("Data").getCompound("DragonFight"); + Byte PreviouslyKilled = compound.getByte("PreviouslyKilled"); + Byte DragonKilled = compound.getByte("DragonKilled"); + Byte NeedsStateScanning = compound.getByte("NeedsStateScanning"); + + if(PreviouslyKilled == (byte) 0) { + compound.setByte("PreviouslyKilled", (byte) 1); + } + if(DragonKilled == 0) { + compound.setByte("DragonKilled", (byte) 1); + } + if(NeedsStateScanning == 1) { + compound.setByte("NeedsStateScanning", (byte) 0); + } + + worldFile.save(); + + Bukkit.createWorld(worldCreator); + } } public void setIslandBiome(@NotNull Island island, @NotNull XBiome biome) { From 282716fb3b8d746c9a7ce0a4b8cae16fa460cf01 Mon Sep 17 00:00:00 2001 From: Peaches_MLG Date: Sat, 21 Oct 2023 12:41:41 +0100 Subject: [PATCH 2/2] boop --- .../iridiumskyblock/IridiumSkyblock.java | 10 ++--- .../managers/IslandManager.java | 44 +++++++++---------- 2 files changed, 23 insertions(+), 31 deletions(-) diff --git a/src/main/java/com/iridium/iridiumskyblock/IridiumSkyblock.java b/src/main/java/com/iridium/iridiumskyblock/IridiumSkyblock.java index 1a0c99238..4de2f3959 100644 --- a/src/main/java/com/iridium/iridiumskyblock/IridiumSkyblock.java +++ b/src/main/java/com/iridium/iridiumskyblock/IridiumSkyblock.java @@ -89,13 +89,9 @@ public void onEnable() { this.teamManager = new IslandManager(); - try { - this.teamManager.createWorld(World.Environment.NORMAL, configuration.worldName); - this.teamManager.createWorld(World.Environment.NETHER, configuration.worldName + "_nether"); - this.teamManager.createWorld(World.Environment.THE_END, configuration.worldName + "_the_end"); - } catch (IOException e) { - throw new RuntimeException(e); - } + this.teamManager.createWorld(World.Environment.NORMAL, configuration.worldName); + this.teamManager.createWorld(World.Environment.NETHER, configuration.worldName + "_nether"); + this.teamManager.createWorld(World.Environment.THE_END, configuration.worldName + "_the_end"); this.schematicManager = new SchematicManager(); this.userManager = new UserManager(); diff --git a/src/main/java/com/iridium/iridiumskyblock/managers/IslandManager.java b/src/main/java/com/iridium/iridiumskyblock/managers/IslandManager.java index 212356d93..dcfd43f95 100644 --- a/src/main/java/com/iridium/iridiumskyblock/managers/IslandManager.java +++ b/src/main/java/com/iridium/iridiumskyblock/managers/IslandManager.java @@ -52,42 +52,38 @@ public IslandManager() { super(IridiumSkyblock.getInstance()); } - public void createWorld(World.Environment environment, String name) throws IOException { + public void createWorld(World.Environment environment, String name) { if (!IridiumSkyblock.getInstance().getConfiguration().enabledWorlds.getOrDefault(environment, true)) return; WorldCreator worldCreator = new WorldCreator(name) .generator(IridiumSkyblock.getInstance().getDefaultWorldGenerator(name, null)) .environment(environment); - Bukkit.createWorld(worldCreator); + World world = Bukkit.createWorld(worldCreator); - if(Bukkit.getWorld(worldCreator.name()).getEnvironment() == World.Environment.THE_END) { + if (world != null && world.getEnvironment() == World.Environment.THE_END) { + Bukkit.unloadWorld(world.getName(), true); - Bukkit.unloadWorld(worldCreator.name(), true); + try { + File file = new File(worldCreator.name() + File.separator + "level.dat"); + NBTFile worldFile = new NBTFile(file); - File file = new File(worldCreator.name() + File.separator + "level.dat"); - NBTFile worldFile = new NBTFile(file); + if (worldFile.getCompound("Data").getCompound("DragonFight") == null) { + IridiumSkyblock.getInstance().getLogger().warning("Cannot load \"DragonFight\" compound because \"DragonFight\" is null."); + return; + } - if(worldFile.getCompound("Data").getCompound("DragonFight") == null) { - IridiumSkyblock.getInstance().getLogger().warning("Cannot load \"DragonFight\" compound because \"DragonFight\" is null."); - return; - } + NBTCompound compound = worldFile.getCompound("Data").getCompound("DragonFight"); - NBTCompound compound = worldFile.getCompound("Data").getCompound("DragonFight"); - Byte PreviouslyKilled = compound.getByte("PreviouslyKilled"); - Byte DragonKilled = compound.getByte("DragonKilled"); - Byte NeedsStateScanning = compound.getByte("NeedsStateScanning"); + compound.setBoolean("PreviouslyKilled", true); + compound.setBoolean("DragonKilled", true); + compound.setBoolean("NeedsStateScanning", false); - if(PreviouslyKilled == (byte) 0) { - compound.setByte("PreviouslyKilled", (byte) 1); - } - if(DragonKilled == 0) { - compound.setByte("DragonKilled", (byte) 1); + worldFile.save(); + } catch (Exception exception) { + exception.printStackTrace(); + IridiumSkyblock.getInstance().getLogger().warning("Failed to delete dragon from world"); } - if(NeedsStateScanning == 1) { - compound.setByte("NeedsStateScanning", (byte) 0); - } - - worldFile.save(); + // Note this world is already created, we are just loading it here Bukkit.createWorld(worldCreator); } }