Skip to content

Commit

Permalink
Removed all checking and saving of versions in binary format, fixed c…
Browse files Browse the repository at this point in the history
…ommands in terms of naming consistency, added more QOL such as tab completers, fixed documentation to stay inline with refractor, fixed waiting time for world loading
  • Loading branch information
Swofty-Developments committed Oct 11, 2023
1 parent 91ad6f4 commit ac287f9
Show file tree
Hide file tree
Showing 10 changed files with 66 additions and 177 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import java.io.File;
import java.io.IOException;
import java.util.concurrent.CompletableFuture;

/**
* Main class of the SWM API. From here, you can load
Expand Down Expand Up @@ -109,7 +110,7 @@ SlimeWorld loadWorld(SlimeLoader loader, String worldName, boolean readOnly, Sli
*
* @param world {@link SlimeWorld} world to be added to the server's world list
*/
void generateWorld(SlimeWorld world);
CompletableFuture<Void> generateWorld(SlimeWorld world);

/**
* Migrates a {@link SlimeWorld} to another datasource.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@
*/
public class ClassModifier {

// Required for Paper 1.13 as javassist can't compile this class
public static final BooleanSupplier BOOLEAN_SUPPLIER = () -> true;

private static CLSMBridge customLoader;

public static CompletableFuture getFutureChunk(Object world, int x, int z) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
@RequiredArgsConstructor
public class CraftCLSMBridge implements CLSMBridge {

private final v1_8_R3SlimeNMS nmsInstance;
private final SlimeNMS nmsInstance;

@Override
public Object[] getDefaultWorlds() {
Expand Down Expand Up @@ -39,7 +39,7 @@ public boolean skipWorldAdd(Object world) {
return !worldServer.isReady();
}

static void initialize(v1_8_R3SlimeNMS instance) {
static void initialize(SlimeNMS instance) {
ClassModifier.setLoader(new CraftCLSMBridge(instance));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import net.swofty.swm.api.world.SlimeWorld;
import net.swofty.swm.api.world.properties.SlimeProperties;
import net.swofty.swm.nms.CraftSlimeWorld;
import net.swofty.swm.nms.SlimeNMS;
import lombok.Getter;
import net.minecraft.server.v1_8_R3.MinecraftServer;
import net.minecraft.server.v1_8_R3.WorldServer;
Expand All @@ -16,7 +15,7 @@
import org.bukkit.event.world.WorldLoadEvent;

@Getter
public class v1_8_R3SlimeNMS implements SlimeNMS {
public class SlimeNMS {

private static final Logger LOGGER = LogManager.getLogger("SWM");

Expand All @@ -28,16 +27,15 @@ public class v1_8_R3SlimeNMS implements SlimeNMS {
private WorldServer defaultNetherWorld;
private WorldServer defaultEndWorld;

public v1_8_R3SlimeNMS() {
public SlimeNMS() {
try {
CraftCLSMBridge.initialize(this);
} catch (NoClassDefFoundError ex) {
LOGGER.error("Failed to find ClassModifier classes. Are you sure you installed it correctly?");
System.exit(1); // No ClassModifier, no party
System.exit(1); // No ClassModifier, no party, sadge
}
}

@Override
public void setDefaultWorlds(SlimeWorld normalWorld, SlimeWorld netherWorld, SlimeWorld endWorld) {
if (normalWorld != null) {
World.Environment env = World.Environment.valueOf(normalWorld.getPropertyMap().getValue(SlimeProperties.ENVIRONMENT).toUpperCase());
Expand All @@ -62,7 +60,6 @@ public void setDefaultWorlds(SlimeWorld normalWorld, SlimeWorld netherWorld, Sli
loadingDefaultWorlds = false;
}

@Override
public Object createNMSWorld(SlimeWorld world) {
CustomDataManager dataManager = new CustomDataManager(world);
MinecraftServer mcServer = MinecraftServer.getServer();
Expand All @@ -84,12 +81,6 @@ public Object createNMSWorld(SlimeWorld world) {
return new CustomWorldServer((CraftSlimeWorld) world, dataManager, dimension);
}

@Override
public void generateWorld(SlimeWorld world) {
addWorldToServerList(createNMSWorld(world));
}

@Override
public void addWorldToServerList(Object worldObject) {
if (!(worldObject instanceof WorldServer)) {
throw new IllegalArgumentException("World object must be an instance of WorldServer!");
Expand Down Expand Up @@ -117,7 +108,6 @@ public void addWorldToServerList(Object worldObject) {
LOGGER.info("World " + worldName + " loaded in " + (System.currentTimeMillis() - startTime) + "ms.");
}

@Override
public SlimeWorld getSlimeWorld(World world) {
CraftWorld craftWorld = (CraftWorld) world;

Expand Down
6 changes: 1 addition & 5 deletions swoftyworldmanager-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
<dependency>
<groupId>com.github.luben</groupId>
<artifactId>zstd-jni</artifactId>
<version>1.4.1-1</version>
<version>1.5.5-6</version>
</dependency>
<dependency>
<groupId>com.zaxxer</groupId>
Expand Down Expand Up @@ -119,10 +119,6 @@
<pattern>org.bson</pattern>
<shadedPattern>net.swofty.swm.internal.org.bson</shadedPattern>
</relocation>
<relocation>
<pattern>com.github.luben.zstd</pattern>
<shadedPattern>net.swofty.swm.internal.zstd</shadedPattern>
</relocation>
</relocations>
</configuration>
</plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
import net.swofty.swm.api.world.properties.SlimeProperties;
import net.swofty.swm.api.world.properties.SlimePropertyMap;
import net.swofty.swm.nms.CraftSlimeWorld;
import net.swofty.swm.nms.SlimeNMS;
import net.swofty.swm.nms.v1_8_R3.v1_8_R3SlimeNMS;
import net.swofty.swm.nms.v1_8_R3.SlimeNMS;
import net.swofty.swm.plugin.command.CommandLoader;
import net.swofty.swm.plugin.command.SWMCommand;
import net.swofty.swm.plugin.loaders.LoaderUtils;
Expand All @@ -30,6 +29,7 @@
import java.io.*;
import java.lang.reflect.Field;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

Expand Down Expand Up @@ -150,7 +150,7 @@ public void onEnable() {
}

private SlimeNMS getNMSBridge() throws InvalidVersionException {
return new v1_8_R3SlimeNMS();
return new SlimeNMS();
}

private List<String> loadWorlds() {
Expand Down Expand Up @@ -261,7 +261,7 @@ public SlimeWorld createEmptyWorld(SlimeLoader loader, String worldName, boolean
new CompoundMap()), new ArrayList<>(), propertyMap, readOnly, !readOnly);
loader.saveWorld(worldName, world.serialize(), !readOnly);

Logging.info("World " + worldName + " created in " + (System.currentTimeMillis() - start) + "ms.");
Logging.info("World " + worldName + " created (in-memory) in " + (System.currentTimeMillis() - start) + "ms.");

return world;
}
Expand All @@ -282,20 +282,28 @@ private SlimePropertyMap propertiesToMap(SlimeWorld.SlimeProperties properties)
}

@Override
public void generateWorld(SlimeWorld world) {
public CompletableFuture<Void> generateWorld(SlimeWorld world) {
Objects.requireNonNull(world, "SlimeWorld cannot be null");

if (!world.isReadOnly() && !world.isLocked()) {
throw new IllegalArgumentException("This world cannot be loaded, as it has not been locked.");
}

CompletableFuture<Void> future = new CompletableFuture<>();

/*
Async World Generation
*/
worldGeneratorService.submit(() -> {
Object nmsWorld = nms.createNMSWorld(world);
Bukkit.getScheduler().runTask(this, () -> nms.addWorldToServerList(nmsWorld));
System.out.println("TEST 6");
Bukkit.getScheduler().runTask(this, () -> {
nms.addWorldToServerList(nmsWorld);
future.complete(null);
});
});

return future;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,29 +66,32 @@ public void run(CommandSource sender, String[] args) {
try {
long start = System.currentTimeMillis();

System.out.println("TEST 1");

WorldData worldData = new WorldData();
worldData.setSpawn("0, 64, 0");

SlimePropertyMap propertyMap = worldData.toPropertyMap();
System.out.println("TEST 2");
SlimeWorld slimeWorld = SWMPlugin.getInstance().createEmptyWorld(loader, worldName, false, propertyMap);

Bukkit.getScheduler().runTask(SWMPlugin.getInstance(), () -> {
try {
SWMPlugin.getInstance().generateWorld(slimeWorld);

// Bedrock block
Location location = new Location(Bukkit.getWorld(worldName), 0, 61, 0);
location.getBlock().setType(Material.BEDROCK);

// Config
config.getWorlds().put(worldName, worldData);
config.save();

sender.send(Logging.COMMAND_PREFIX + ChatColor.GREEN + "World " + ChatColor.YELLOW + worldName
+ ChatColor.GREEN + " created in " + (System.currentTimeMillis() - start) + "ms!");
} catch (IllegalArgumentException ex) {
sender.send(Logging.COMMAND_PREFIX + ChatColor.RED + "Failed to create world " + worldName + ": " + ex.getMessage() + ".");
}
System.out.println("TEST 3");
SWMPlugin.getInstance().generateWorld(slimeWorld).thenRun(() -> {
System.out.println("TEST 4");
// Bedrock block
Location location = new Location(Bukkit.getWorld(worldName), 0, 61, 0);
location.getBlock().setType(Material.BEDROCK);

// Config
config.getWorlds().put(worldName, worldData);
config.save();

System.out.println("TEST 5");
sender.send(Logging.COMMAND_PREFIX + ChatColor.GREEN + "World " + ChatColor.YELLOW + worldName
+ ChatColor.GREEN + " created in " + (System.currentTimeMillis() - start) + "ms!");
}).exceptionally(ex -> {
sender.send(Logging.COMMAND_PREFIX + ChatColor.RED + "Failed to create world " + worldName + ": " + ex.getMessage() + ".");
return null;
});
} catch (WorldAlreadyExistsException ex) {
sender.send(Logging.COMMAND_PREFIX + ChatColor.RED + "Failed to create world " + worldName +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public void run(CommandSource sender, String[] args) {
return;
}

target = (Player) sender;
target = sender.getPlayer();
}

if (target == null) {
Expand Down
Loading

0 comments on commit ac287f9

Please sign in to comment.