Skip to content

Commit

Permalink
killed the dragon
Browse files Browse the repository at this point in the history
used NBTAPI to edit level.dat values and prevent the dragon or bedrock portal from spawning because im cool like that
  • Loading branch information
sh0inx committed Oct 8, 2023
1 parent 6292d20 commit a299a3c
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 4 deletions.
10 changes: 7 additions & 3 deletions src/main/java/com/iridium/iridiumskyblock/IridiumSkyblock.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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) {
Expand Down

0 comments on commit a299a3c

Please sign in to comment.