-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from TheNextLvl-net/updates
Updates
- Loading branch information
Showing
16 changed files
with
109 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
api/src/main/java/net/thenextlvl/worlds/api/model/Generator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package net.thenextlvl.worlds.api.model; | ||
|
||
import com.google.common.base.Preconditions; | ||
import net.thenextlvl.worlds.api.WorldsProvider; | ||
import org.bukkit.generator.BiomeProvider; | ||
import org.bukkit.generator.ChunkGenerator; | ||
import org.bukkit.plugin.Plugin; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
public record Generator(Plugin plugin, @Nullable String id) { | ||
public String serialize() { | ||
return id != null ? plugin.getName() + ":" + id : plugin.getName(); | ||
} | ||
|
||
public static Generator deserialize(WorldsProvider provider, String serialized) { | ||
var split = serialized.split(":", 2); | ||
var generator = provider.getServer().getPluginManager().getPlugin(split[0]); | ||
Preconditions.checkNotNull(generator, "Unknown plugin"); | ||
Preconditions.checkState(generator.isEnabled(), "Plugin is not enabled"); | ||
Preconditions.checkState(provider.generatorView().hasGenerator(generator), "Plugin has no generator"); | ||
return new Generator(generator, split.length > 1 ? split[1] : null); | ||
} | ||
|
||
public @Nullable ChunkGenerator generator(String worldName) { | ||
return plugin().getDefaultWorldGenerator(worldName, id()); | ||
} | ||
|
||
public @Nullable BiomeProvider biomeProvider(String worldName) { | ||
return plugin().getDefaultBiomeProvider(worldName, id()); | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
api/src/main/java/net/thenextlvl/worlds/api/model/LevelExtras.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,12 @@ | ||
package net.thenextlvl.worlds.api.model; | ||
|
||
import net.thenextlvl.worlds.api.view.GeneratorView; | ||
import org.bukkit.NamespacedKey; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
public record LevelExtras( | ||
@Nullable NamespacedKey key, | ||
@Nullable Generator generator, | ||
boolean enabled | ||
) { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 5 additions & 15 deletions
20
plugin/src/main/java/net/thenextlvl/worlds/command/argument/GeneratorArgument.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,15 @@ | ||
package net.thenextlvl.worlds.command.argument; | ||
|
||
import com.google.common.base.Preconditions; | ||
import com.mojang.brigadier.arguments.StringArgumentType; | ||
import core.paper.command.WrappedArgumentType; | ||
import net.thenextlvl.worlds.WorldsPlugin; | ||
import net.thenextlvl.worlds.api.model.Generator; | ||
import net.thenextlvl.worlds.command.suggestion.GeneratorSuggestionProvider; | ||
import org.bukkit.plugin.Plugin; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
public class GeneratorArgument extends WrappedArgumentType<String, GeneratorArgument.Generator> { | ||
public class GeneratorArgument extends WrappedArgumentType<String, Generator> { | ||
public GeneratorArgument(WorldsPlugin plugin) { | ||
super(StringArgumentType.string(), (reader, type) -> { | ||
var split = type.split(":", 2); | ||
var generator = plugin.getServer().getPluginManager().getPlugin(split[0]); | ||
Preconditions.checkNotNull(generator, "Unknown plugin"); | ||
Preconditions.checkState(generator.isEnabled(), "Plugin is not enabled"); | ||
Preconditions.checkState(plugin.generatorView().hasGenerator(generator), "Plugin has no generator"); | ||
return new Generator(generator, split.length > 1 ? split[1] : null); | ||
}, new GeneratorSuggestionProvider(plugin)); | ||
} | ||
|
||
public record Generator(Plugin plugin, @Nullable String id) { | ||
super(StringArgumentType.string(), (reader, type) -> | ||
Generator.deserialize(plugin, type), | ||
new GeneratorSuggestionProvider(plugin)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters