Skip to content

Commit

Permalink
Fixed up some NMS, added setworldspawn, implemented ability to edit D…
Browse files Browse the repository at this point in the history
…ataConfig within the API, removed deprecated property methods, added variety of utility functions resulting in cleaner code, and fixed documentation in relation to commands
  • Loading branch information
Swofty-Developments committed Nov 24, 2023
1 parent d65af13 commit 0521d47
Show file tree
Hide file tree
Showing 29 changed files with 283 additions and 241 deletions.
26 changes: 18 additions & 8 deletions .docs/usage/commands-and-permissions.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ Permission required: none.<br>
Usage: `/swm version`<br>
Description: shows the plugin version.

### /swm reload
### /swm reloadconfig
Permission required: `swm.reload`
Usage: `/swm reload`<br>
Usage: `/swm reloadconfig`<br>
Since version: 1.1.0.<br>
Description: reloads the config files.

Expand All @@ -30,19 +30,19 @@ Description: teleports yourself to a world. If you want to teleport someone else
## World Listing commands

### /swm list
Permission required: `swm.worldlist`<br>
Permission required: `swm.listworld`<br>
Usage: `/swm list [slime] [page]`<br>
Description: lists all worlds, including loaded non-SRF worlds. If you use the `slime` argument, only SRF worlds will be shown.

### /swm dslist
Permission required: `swm.dslist`<br>
Usage: `/swm list <data-source> [page]`<br>
Usage: `/swm dslist <data-source> [page]`<br>
Since version: 2.0.0.<br>
Description: lists all worlds contained inside a specified data source. Note that this command doesn't just list the worlds that are inside the config file, but every world inside the data source.

## World Creation and Loading commands

### /swm import
### /swm importworld
Permission required: `swm.importworld`<br>
Usage: `/swm import <path-to-world> <data-source> [new-world-name]`<br>
Since version: 1.1.0.<br>
Expand All @@ -53,7 +53,7 @@ Permission required: `swm.loadworld`<br>
Usage: `/swm load <world>`<br>
Description: Loads a world from the config file. Remember to configure the world after converting it to the SRF. More on that [here](https://github.com/Grinderwolf/Slime-World-Manager/wiki/Configuring-worlds).

### /swm load-template
### /swm loadtemplate
Permission required: `swm.loadworld.template`<br>
Usage: `/swm load-template <template-world> <world>`<br>
Since version: 2.0.0.<br>
Expand All @@ -69,15 +69,25 @@ Description: Creates a clone of the provided template world. If not provided, SW

### /swm create
Permission required: `swm.createworld`<br>
Usage: `/swm create <world> <data-source>`<br>
Usage: `/swm create <world> <data-source> [overworld/nether/end]`<br>
Since version: 1.1.0.<br>
Description: Creates an empty world and stores it in the provided data source. This command will also automatically save the world in the config file.

### /swm unload
### /swm unloadworld
Permission required: `swm.unloadworld`<br>
Usage: `/swm unload <world>`<br>
Description: Unloads a world from the server.

### /swm unlockworld
Permission required: `swm.unlockworld`<br>
Usage: `/swm unlockworld <world>`<br>
Description: Unlocks a world from the server, used primarily for debug reasons.

### /swm setworldspawn
Permission required: `swm.setworldspawn`<br>
Usage: `/swm setworldspawn`<br>
Description: Sets the spawn of the world that you're in

**This command also works for traditional worlds, not just SRF worlds.**

## World Management commands
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<groupId>net.swofty</groupId>
<artifactId>swoftyworldmanager</artifactId>
<packaging>pom</packaging>
<version>3.0.6</version>
<version>3.1.0</version>
<modules>
<module>swoftyworldmanager-api</module>
<module>swoftyworldmanager-nms</module>
Expand Down
10 changes: 9 additions & 1 deletion swoftyworldmanager-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<artifactId>swoftyworldmanager</artifactId>
<groupId>net.swofty</groupId>
<version>3.0.6</version>
<version>3.1.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand All @@ -16,6 +16,14 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<dependency>
<groupId>org.spongepowered</groupId>
<artifactId>configurate-yaml</artifactId>
<version>3.7-SNAPSHOT</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@

import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentHashMap;

/**
* Main class of the SWM API. From here, you can load
Expand All @@ -24,29 +27,6 @@
*/
public interface SlimePlugin {

/**
* Loads a world using a specificied {@link SlimeLoader}.
* This world can then be added to the server's world
* list by using the {@link #generateWorld(SlimeWorld)} method.
*
* @param loader {@link SlimeLoader} used to retrieve the world.
* @param worldName Name of the world.
* @param properties Properties of the world contained within a {@link SlimeWorld.SlimeProperties} object.
*
* @return A {@link SlimeWorld}, which is the in-memory representation of the world.
*
* @throws UnknownWorldException if the world cannot be found.
* @throws IOException if the world cannot be obtained from the speficied data source.
* @throws CorruptedWorldException if the world retrieved cannot be parsed into a {@link SlimeWorld} object.
* @throws NewerFormatException if the world uses a newer version of the SRF.
* @throws WorldInUseException if the world is already being used on another server when trying to open it without read-only mode enabled.
*
* @deprecated see {@link #loadWorld(SlimeLoader, String, boolean, SlimePropertyMap)}
*/
@Deprecated
SlimeWorld loadWorld(SlimeLoader loader, String worldName, SlimeWorld.SlimeProperties properties) throws
UnknownWorldException, IOException, CorruptedWorldException, NewerFormatException, WorldInUseException;

/**
* Loads a world using a specificied {@link SlimeLoader}.
* This world can then be added to the server's world
Expand All @@ -68,25 +48,6 @@ SlimeWorld loadWorld(SlimeLoader loader, String worldName, SlimeWorld.SlimePrope
SlimeWorld loadWorld(SlimeLoader loader, String worldName, boolean readOnly, SlimePropertyMap propertyMap) throws
UnknownWorldException, IOException, CorruptedWorldException, NewerFormatException, WorldInUseException;

/**
* Creates an empty world and stores it using a specified
* {@link SlimeLoader}. This world can then be added to
* the server's world list by using the {@link #generateWorld(SlimeWorld)} method.
*
* @param loader {@link SlimeLoader} used to store the world.
* @param worldName Name of the world.
* @param properties Properties of the world contained within a {@link SlimeWorld.SlimeProperties} object.
*
* @return A {@link SlimeWorld}, which is the in-memory representation of the world.
*
* @throws WorldAlreadyExistsException if the provided data source already contains a world with the same name.
* @throws IOException if the world could not be stored.
*
* @deprecated see {@link #createEmptyWorld(SlimeLoader, String, boolean, SlimePropertyMap)}
*/
@Deprecated
SlimeWorld createEmptyWorld(SlimeLoader loader, String worldName, SlimeWorld.SlimeProperties properties) throws WorldAlreadyExistsException, IOException;

/**
* Creates an empty world and stores it using a specified
* {@link SlimeLoader}. This world can then be added to
Expand Down Expand Up @@ -160,4 +121,6 @@ SlimeWorld loadWorld(SlimeLoader loader, String worldName, boolean readOnly, Sli
*/
void importWorld(File worldDir, String worldName, SlimeLoader loader) throws WorldAlreadyExistsException,
InvalidWorldException, WorldLoadedException, WorldTooBigException, IOException;

Map<String, SlimeWorld> getSlimeWorlds();
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,6 @@ default void unloadWorld(boolean save) {
unloadWorld(save, null);
}

/**
* Returns the properties of the world. These properties are automatically
* kept up-to-date when the world is loaded and its properties are updated.
*
* @return A {@link SlimeProperties} object with all the current properties of the world.
* @deprecated see {@link #getPropertyMap()}.
*/
@Deprecated
SlimeProperties getProperties();

/**
* Returns the property map.
*
Expand Down Expand Up @@ -153,38 +143,4 @@ default void unloadWorld(boolean save) {
* @return true if the world is locked, false otherwise
*/
boolean isLocked();

/**
* All the currently-available properties of the world.
*
* @deprecated see {@link SlimePropertyMap}
*/
@Getter
@Builder(toBuilder = true)
@Deprecated
class SlimeProperties {

private final double spawnX;
@Builder.Default
private final double spawnY = 255;
private final double spawnZ;

private final int difficulty;

@Accessors(fluent = true)
@Builder.Default
private final boolean allowMonsters = true;
@Accessors(fluent = true)
@Builder.Default
private final boolean allowAnimals = true;

@With
private final boolean readOnly;

@Builder.Default
private final boolean pvp = true;

@Builder.Default
private final String environment = "NORMAL";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package net.swofty.swm.api.world.data;

public interface ConfigManager {
/**
* Returns the world config.
*
* @return The world config.
*/
WorldsConfig getWorldConfig();
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package net.swofty.swm.plugin.config;
package net.swofty.swm.api.world.data;

import lombok.Data;
import net.swofty.swm.api.world.properties.SlimeProperties;
import net.swofty.swm.api.world.properties.SlimePropertyMap;
import lombok.Data;
import ninja.leaping.configurate.objectmapping.Setting;
import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable;
import org.bukkit.Difficulty;
import org.bukkit.World;

@Data
@ConfigSerializable
Expand Down Expand Up @@ -40,12 +38,6 @@ public class WorldData {
private boolean readOnly = false;

public SlimePropertyMap toPropertyMap() {
try {
Enum.valueOf(Difficulty.class, this.difficulty.toUpperCase());
} catch (IllegalArgumentException ex) {
throw new IllegalArgumentException("unknown difficulty '" + this.difficulty + "'");
}

String[] spawnLocationSplit = spawn.split(", ");

double spawnX, spawnY, spawnZ;
Expand All @@ -60,22 +52,6 @@ public SlimePropertyMap toPropertyMap() {

String environment = this.environment;

try {
Enum.valueOf(World.Environment.class, environment.toUpperCase());
} catch (IllegalArgumentException ex) {
try {
int envId = Integer.parseInt(environment);

if (envId < -1 || envId > 1) {
throw new NumberFormatException(environment);
}

environment = World.Environment.getEnvironment(envId).name();
} catch (NumberFormatException ex2) {
throw new IllegalArgumentException("unknown environment '" + this.environment + "'");
}
}

SlimePropertyMap propertyMap = new SlimePropertyMap();

propertyMap.setValue(SlimeProperties.SPAWN_X, (int) spawnX);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package net.swofty.swm.api.world.data;

import java.util.Map;

public interface WorldsConfig {
/**
* Saves WorldConfig to the YAML
*/
void save();

Map<String, WorldData> getWorlds();
}
4 changes: 2 additions & 2 deletions swoftyworldmanager-classmodifier/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<artifactId>swoftyworldmanager</artifactId>
<groupId>net.swofty</groupId>
<version>3.0.6</version>
<version>3.1.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down Expand Up @@ -38,7 +38,7 @@
<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
<version>2.0</version>
<version>1.24</version>
</dependency>
</dependencies>

Expand Down
2 changes: 1 addition & 1 deletion swoftyworldmanager-importer/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<artifactId>swoftyworldmanager</artifactId>
<groupId>net.swofty</groupId>
<version>3.0.6</version>
<version>3.1.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>swoftyworldmanager-importer</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion swoftyworldmanager-nms/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<artifactId>swoftyworldmanager</artifactId>
<groupId>net.swofty</groupId>
<version>3.0.6</version>
<version>3.1.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,6 @@ public void addWorldToServerList(Object worldObject) {
throw new IllegalArgumentException("World " + worldName + " already exists! Maybe it's an outdated SlimeWorld object?");
}

LOGGER.info("Loading world " + worldName);
long startTime = System.currentTimeMillis();

server.setReady(true);
MinecraftServer mcServer = MinecraftServer.getServer();

Expand All @@ -93,7 +90,7 @@ public void addWorldToServerList(Object worldObject) {
Bukkit.getPluginManager().callEvent(new WorldInitEvent(server.getWorld()));
Bukkit.getPluginManager().callEvent(new WorldLoadEvent(server.getWorld()));

LOGGER.info("World " + worldName + " loaded in " + (System.currentTimeMillis() - startTime) + "ms.");
LOGGER.info("World " + worldName + " loaded.");
}

public SlimeWorld getSlimeWorld(World world) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class CraftSlimeWorld implements SlimeWorld {
private final CompoundTag extraData;
private final List<CompoundTag> worldMaps;

private final SlimePropertyMap propertyMap;
private SlimePropertyMap propertyMap;

private final boolean readOnly;

Expand Down Expand Up @@ -148,19 +148,6 @@ public SlimeWorld clone(String worldName, SlimeLoader loader, boolean lock) thro
return world;
}

@Override
public SlimeWorld.SlimeProperties getProperties() {
return SlimeWorld.SlimeProperties.builder().spawnX(propertyMap.getValue(SPAWN_X))
.spawnY(propertyMap.getValue(SPAWN_Y))
.spawnZ(propertyMap.getValue(SPAWN_Z))
.environment(propertyMap.getValue(ENVIRONMENT).toString())
.pvp(propertyMap.getValue(PVP))
.allowMonsters(propertyMap.getValue(ALLOW_MONSTERS))
.allowAnimals(propertyMap.getValue(ALLOW_ANIMALS))
.difficulty(Difficulty.valueOf(propertyMap.getValue(DIFFICULTY).toString().toUpperCase()).getValue())
.readOnly(readOnly).build();
}

// World Serialization methods

public byte[] serialize() {
Expand Down
Loading

0 comments on commit 0521d47

Please sign in to comment.