Skip to content

Commit

Permalink
Cleaned up documentation and added events (thanks Paul)
Browse files Browse the repository at this point in the history
  • Loading branch information
Swofty-Developments committed Nov 24, 2023
1 parent 0521d47 commit 1c47aa0
Show file tree
Hide file tree
Showing 27 changed files with 141 additions and 24 deletions.
9 changes: 9 additions & 0 deletions .docs/api/events.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
## Events

### PreGenerateWorldEvent
This event is called when the #generateWorld method is first ran either through an API call or through the plugin.
The SlimeWorld is exposed and can be modified. The event is not cancellable.

### PostGenerateWorldEvent
This event is called after the #generateWorld method is ran either through an API call or through the plugin.
The SlimeWorld is exposed and can be modified. The event is not cancellable.
2 changes: 2 additions & 0 deletions .docs/api/import-world.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
## Importing a world

You need three things to import a world: a world folder, a world name and a data source. Here's an example of how to import a world:
```java
SlimePlugin plugin = (SlimePlugin) Bukkit.getPluginManager().getPlugin("SwoftyWorldManager");
Expand Down
2 changes: 2 additions & 0 deletions .docs/api/load-world.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
## Loading a world

First, retrieve the SwoftyWorldManager plugin API:
```java
SlimePlugin plugin = (SlimePlugin) Bukkit.getPluginManager().getPlugin("SwoftyWorldManager");
Expand Down
2 changes: 2 additions & 0 deletions .docs/api/migrate-world.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
## Migrating a world

To migrate a world you need three things: a world name, the data source where the world is currently stored in and another data source to store the world. Here's an example of a world migration:
```java
SlimePlugin plugin = (SlimePlugin) Bukkit.getPluginManager().getPlugin("SwoftyWorldManager");
Expand Down
4 changes: 2 additions & 2 deletions .docs/api/properties.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Properties API
## Properties

Property "types" are handled by [SlimeProperty][1] instances. Whilst not allowing to create [SlimeProperty][1] objects, there is a [list of all availeable properties][2]. Properties and their values are stored in [SlimePropertyMaps][3].
Property "types" are handled by [SlimeProperty][1] instances. Whilst not allowing to create [SlimeProperty][1] objects, there is a [list of all available properties][2]. Properties and their values are stored in [SlimePropertyMaps][3].


**Example Usage:**
Expand Down
9 changes: 2 additions & 7 deletions .docs/api/setup-dev.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
## Building custom source

### Building

To build SWM, execute the following command int the project root:
Expand All @@ -11,13 +13,6 @@ mvn clean install
If your plugin wants to use Slime World Manager add the following in your pom.xml

### Maven

```xml
<repository>
<id>swm-repo</id>
<url>https://repo.glaremasters.me/repository/concuncan/</url>
</repository>
```
```xml
<dependency>
<groupId>net.swofty</groupId>
Expand Down
2 changes: 2 additions & 0 deletions .docs/api/unload-world.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
## Unloading a world

Given that you have your SlimeWorld object, you can unload it using the following method:
```java
slimeworld.unloadWorld(true);
Expand Down
2 changes: 2 additions & 0 deletions .docs/api/use-data-source.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
## Custom Data Sources

Slime World Manager supports three data sources out of the box: the filesystem, MySQL and MongoDB. However, there are situations where you might want to use other data sources. To do so, you can create your own implementation of the SlimeLoader interface.

SlimeLoaders are classes used to load worlds from specific data sources. Remember to check out the [docs](https://grinderwolf.github.io/Slime-World-Manager/apidocs/) for the SlimeLoader interface prior to creating your own implementation, as it contains information on what every method should exactly do. You can also take a look at the [FileLoader class](../../swoftyworldmanager-plugin/src/main/java/com/grinderwolf/swm/plugin/loaders/FileLoader.java) for an example of a SlimeLoader.
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ Javadocs can be found [here](https://swofty-developments.github.io/Continued-Sli
* [Migrating a world](.docs/api/migrate-world.md)
* [Importing a world](.docs/api/import-world.md)
* [Unload a world](.docs/api/unload-world.md)
* [Events](.docs/api/events.md)
* [Using other data sources](.docs/api/use-data-source.md)
* [FAQ](.docs/faq.md)

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.1.0</version>
<version>3.1.1</version>
<modules>
<module>swoftyworldmanager-api</module>
<module>swoftyworldmanager-nms</module>
Expand Down
8 changes: 7 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.1.0</version>
<version>3.1.1</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand All @@ -22,6 +22,12 @@
<artifactId>configurate-yaml</artifactId>
<version>3.7-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.8.8-R0.1-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import net.swofty.swm.api.exceptions.WorldTooBigException;
import net.swofty.swm.api.loaders.SlimeLoader;
import net.swofty.swm.api.world.SlimeWorld;
import net.swofty.swm.api.world.data.ConfigManager;
import net.swofty.swm.api.world.properties.SlimePropertyMap;

import java.io.File;
Expand All @@ -27,6 +28,15 @@
*/
public interface SlimePlugin {

/**
* Returns the {@link ConfigManager} of the plugin.
* This can be used to retrieve the {@link net.swofty.swm.api.world.data.WorldsConfig}
* objects.
*
* @return The {@link ConfigManager} of the plugin.
*/
ConfigManager getConfigManager();

/**
* Loads a world using a specificied {@link SlimeLoader}.
* This world can then be added to the server's world
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package net.swofty.swm.api.events;

import net.swofty.swm.api.world.SlimeWorld;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;

import java.util.Objects;

public class PostGenerateWorldEvent extends Event {

private static final HandlerList handlers = new HandlerList();
private final SlimeWorld slimeWorld;

public PostGenerateWorldEvent(SlimeWorld slimeWorld) {
super(false);
this.slimeWorld = Objects.requireNonNull(slimeWorld, "slimeWorld cannot be null");
}

public static HandlerList getHandlerList() {
return handlers;
}

@Override
public HandlerList getHandlers() {
return handlers;
}

public SlimeWorld getSlimeWorld() {
return slimeWorld;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package net.swofty.swm.api.events;

import lombok.Getter;
import net.swofty.swm.api.world.SlimeWorld;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;

import java.util.Objects;

public class PreGenerateWorldEvent extends Event implements Cancellable {

private static final HandlerList handlers = new HandlerList();
private boolean isCancelled;
@Getter
private SlimeWorld slimeWorld;

public PreGenerateWorldEvent(SlimeWorld slimeWorld) {
super(false);
this.slimeWorld = Objects.requireNonNull(slimeWorld, "slimeWorld cannot be null");
}

public static HandlerList getHandlerList() {
return handlers;
}

@Override
public HandlerList getHandlers() {
return handlers;
}

@Override
public boolean isCancelled() {
return this.isCancelled;
}

@Override
public void setCancelled(boolean cancelled) {
this.isCancelled = cancelled;
}

public void setSlimeWorld(SlimeWorld slimeWorld) {
this.slimeWorld = Objects.requireNonNull(slimeWorld, "slimeWorld cannot be null");
}
}
2 changes: 1 addition & 1 deletion 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.1.0</version>
<version>3.1.1</version>
</parent>
<modelVersion>4.0.0</modelVersion>

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.1.0</version>
<version>3.1.1</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.1.0</version>
<version>3.1.1</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<properties>
Expand Down
2 changes: 1 addition & 1 deletion swoftyworldmanager-plugin/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.1.0</version>
<version>3.1.1</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>swoftyworldmanager-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import com.flowpowered.nbt.CompoundMap;
import com.flowpowered.nbt.CompoundTag;
import net.swofty.swm.api.SlimePlugin;
import net.swofty.swm.api.events.PostGenerateWorldEvent;
import net.swofty.swm.api.events.PreGenerateWorldEvent;
import net.swofty.swm.api.exceptions.*;
import net.swofty.swm.api.loaders.SlimeLoader;
import net.swofty.swm.api.world.SlimeWorld;
Expand All @@ -22,6 +24,7 @@
import ninja.leaping.configurate.objectmapping.ObjectMappingException;
import org.bukkit.*;
import org.bukkit.command.CommandMap;
import org.bukkit.event.Event;
import org.bukkit.plugin.java.JavaPlugin;
import org.reflections.Reflections;

Expand Down Expand Up @@ -166,7 +169,7 @@ private SlimeNMS getNMSBridge() throws InvalidVersionException {

private List<String> loadWorlds() {
List<String> erroredWorlds = new ArrayList<>();
WorldsConfig config = new ConfigManager().getWorldConfig();
WorldsConfig config = getConfigManager().getWorldConfig();

for (Map.Entry<String, WorldData> entry : config.getWorlds().entrySet()) {
String worldName = entry.getKey();
Expand Down Expand Up @@ -215,6 +218,11 @@ private List<String> loadWorlds() {
return erroredWorlds;
}

@Override
public net.swofty.swm.api.world.data.ConfigManager getConfigManager() {
return new ConfigManager();
}

@Override
public SlimeWorld loadWorld(SlimeLoader loader, String worldName, boolean readOnly, SlimePropertyMap propertyMap) throws UnknownWorldException, IOException,
CorruptedWorldException, NewerFormatException, WorldInUseException {
Expand Down Expand Up @@ -265,6 +273,7 @@ public SlimeWorld createEmptyWorld(SlimeLoader loader, String worldName, boolean

@Override
public CompletableFuture<Void> generateWorld(SlimeWorld world) {
Bukkit.getPluginManager().callEvent(new PreGenerateWorldEvent(world));
Objects.requireNonNull(world, "SlimeWorld cannot be null");

if (!world.isReadOnly() && !world.isLocked()) {
Expand All @@ -280,6 +289,7 @@ public CompletableFuture<Void> generateWorld(SlimeWorld world) {
Object nmsWorld = nms.createNMSWorld(world);
Bukkit.getScheduler().runTask(this, () -> {
nms.addWorldToServerList(nmsWorld);
Bukkit.getPluginManager().callEvent(new PostGenerateWorldEvent(world));
future.complete(null);
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void run(CommandSource sender, String[] args) {

String templateWorldName = args[0];

WorldsConfig config = new ConfigManager().getWorldConfig();
WorldsConfig config = SWMPlugin.getInstance().getConfigManager().getWorldConfig();
WorldData worldData = config.getWorlds().get(templateWorldName);

if (worldData == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void run(CommandSource sender, String[] args) {

List<String> worldsList = new ArrayList<>(slimeWorlds.keySet());
worldsList.addAll(bukkitWorlds.stream().map(World::getName).collect(Collectors.toList()));
new ConfigManager().getWorldConfig().getWorlds().keySet().stream().filter((world) -> !worldsList.contains(world)).forEach(worldsList::add);
SWMPlugin.getInstance().getConfigManager().getWorldConfig().getWorlds().keySet().stream().filter((world) -> !worldsList.contains(world)).forEach(worldsList::add);

if (worldsList.isEmpty()) {
sender.send(Logging.COMMAND_PREFIX + ChatColor.RED + "There are no worlds configured.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public void run(CommandSource sender, String[] args) {
return;
}

WorldsConfig config = new ConfigManager().getWorldConfig();
WorldsConfig config = SWMPlugin.getInstance().getConfigManager().getWorldConfig();
WorldData worldData = config.getWorlds().get(worldName);

if (worldData == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void run(CommandSource sender, String[] args) {

String templateWorldName = args[0];

WorldsConfig config = new ConfigManager().getWorldConfig();
WorldsConfig config = SWMPlugin.getInstance().getConfigManager().getWorldConfig();
WorldData worldData = config.getWorlds().get(templateWorldName);

if (worldData == null) {
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) {
}

String worldName = args[0];
WorldsConfig config = new ConfigManager().getWorldConfig();
WorldsConfig config = SWMPlugin.getInstance().getConfigManager().getWorldConfig();
WorldData worldData = config.getWorlds().get(worldName);

if (worldData == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class subCommand_setworldspawn extends SWMCommand implements CommandCoold
@Override
public void run(CommandSource sender, String[] args) {
World world = sender.getPlayer().getWorld();
WorldsConfig config = new ConfigManager().getWorldConfig();
WorldsConfig config = SWMPlugin.getInstance().getConfigManager().getWorldConfig();
WorldData worldData = config.getWorlds().get(world.getName());

if (worldData == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void run(CommandSource sender, String[] args) {
return;
}

WorldsConfig config = new ConfigManager().getWorldConfig();
WorldsConfig config = SWMPlugin.getInstance().getConfigManager().getWorldConfig();
WorldData worldData = config.getWorlds().get(args[0]);

if (worldData == null || Bukkit.getWorld(args[0]) == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void run(CommandSource sender, String[] args) {
return;
}

WorldsConfig config = new ConfigManager().getWorldConfig();
WorldsConfig config = SWMPlugin.getInstance().getConfigManager().getWorldConfig();
WorldData worldData = config.getWorlds().get(args[0]);

if (worldData == null) {
Expand Down

0 comments on commit 1c47aa0

Please sign in to comment.