-
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.
- Loading branch information
uweb
committed
Jul 10, 2023
1 parent
f02833b
commit fb4b417
Showing
22 changed files
with
713 additions
and
161 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
## World Creator | ||
This Plugin allows you to manage worlds. | ||
|
||
Tested server version: Paper 1.20.1 | ||
|
||
### Commands | ||
The Main-Command is ```/wc``` or ```/worldcreator``` | ||
|
||
- ```create <worldName> <type>``` Create a new world, type can be ```DEFAULT```, ```FLAT```, ```LARGEBIOMES``` | ||
or ```AMPLIFIED``` | ||
- ```import <worldName>``` Import an existing world | ||
- ```tp <worldName>``` Teleport to world spawn | ||
- ```delete <worldName>``` Unload and delete an existing world and all its files | ||
- ```load <worldName>``` Load an existing world | ||
- ```unload <worldName>``` Unload an existing world | ||
- ```rule <worldName> <gamerule> <value>``` Change the gamerule for the given world | ||
- ```list``` Shows a list of all available worlds | ||
- ```help``` Shows a list of all available commands | ||
- ```version``` Shows the plugin version | ||
|
||
### Permissions | ||
Permissions for the commands: | ||
- ```wc.create``` | ||
- ```wc.import``` | ||
- ```wc.delete``` | ||
- ```wc.load``` | ||
- ```wc.unload``` | ||
- ```wc.list``` | ||
- ```wc.help``` | ||
- ```wc.version``` | ||
- ```wc.teleport``` | ||
- ```wc.admin``` Permission to use all commands |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,79 @@ | ||
package de.uweb95.worldcreator; | ||
|
||
import de.uweb95.worldcreator.commands.*; | ||
import de.uweb95.worldcreator.util.Configuration; | ||
import de.uweb95.worldcreator.util.UpdateChecker; | ||
import de.uweb95.worldcreator.util.WorldConfiguration; | ||
import org.bukkit.command.Command; | ||
import org.bukkit.command.CommandExecutor; | ||
import org.bukkit.command.CommandSender; | ||
import org.bukkit.command.TabCompleter; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.plugin.java.JavaPlugin; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public final class WorldCreator extends JavaPlugin { | ||
import java.util.List; | ||
import java.util.logging.Logger; | ||
|
||
public final class WorldCreator extends JavaPlugin implements CommandExecutor, TabCompleter { | ||
private static Logger logger; | ||
private static WorldCreator instance; | ||
CommandManager commandManager; | ||
|
||
@Override | ||
public void onEnable() { | ||
// Plugin startup logic | ||
instance = this; | ||
logger = getLogger(); | ||
UpdateChecker.CheckForUpdate(); | ||
Configuration.loadConfig("worlds.yml"); | ||
|
||
commandManager = new CommandManager(); | ||
registerCommands(); | ||
|
||
// Initialize configuration object and load all enabled worlds | ||
WorldConfiguration.getInstance(); | ||
} | ||
|
||
private void registerCommands() { | ||
commandManager.registerCommand("create", new CreateWorldCommand()); | ||
commandManager.registerCommand("import", new ImportWorldCommand()); | ||
commandManager.registerCommand("tp", new TeleportCommand()); | ||
commandManager.registerCommand("delete", new DeleteWorldCommand()); | ||
commandManager.registerCommand("load", new LoadWorldCommand()); | ||
commandManager.registerCommand("unload", new UnloadWorldCommand()); | ||
commandManager.registerCommand("rule", new RuleCommand()); | ||
commandManager.registerCommand("list", new ListWorldsCommand()); | ||
commandManager.registerCommand("help", new HelpCommand()); | ||
commandManager.registerCommand("version", new VersionCommand()); | ||
} | ||
|
||
@Override | ||
public void onDisable() { | ||
// Plugin shutdown logic | ||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { | ||
if (command.getLabel().equalsIgnoreCase("wc") || command.getLabel().equalsIgnoreCase("worldcreator")) { | ||
if (sender instanceof Player && !commandManager.checkPermissions((Player) sender)) { | ||
return false; | ||
} | ||
|
||
return commandManager.executeCommand(sender, command, label, args); | ||
} | ||
|
||
return false; | ||
} | ||
|
||
public List<String> onTabComplete(@NotNull CommandSender sender, Command command, @NotNull String alias, String[] args) { | ||
if (command.getLabel().equalsIgnoreCase("wc") || command.getLabel().equalsIgnoreCase("worldcreator")) { | ||
if (sender instanceof Player && commandManager.checkPermissions((Player) sender)) | ||
return commandManager.onTabComplete(sender, command, alias, args); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
public static Logger logger() { | ||
return logger; | ||
} | ||
|
||
public static WorldCreator getInstance() { | ||
return instance; | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
src/main/java/de/uweb95/worldcreator/commands/CommandInterface.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
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
43 changes: 35 additions & 8 deletions
43
src/main/java/de/uweb95/worldcreator/commands/CreateWorldCommand.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,34 +1,61 @@ | ||
package de.uweb95.minebay.commands; | ||
package de.uweb95.worldcreator.commands; | ||
|
||
import de.uweb95.minebay.util.Message; | ||
import org.bukkit.Bukkit; | ||
import org.bukkit.World; | ||
import de.uweb95.worldcreator.util.Message; | ||
import de.uweb95.worldcreator.util.WorldConfiguration; | ||
import de.uweb95.worldcreator.util.WorldHelper; | ||
import org.bukkit.WorldCreator; | ||
import org.bukkit.WorldType; | ||
import org.bukkit.command.Command; | ||
import org.bukkit.command.CommandSender; | ||
import org.bukkit.entity.Player; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class CreateWorldCommand implements CommandInterface { | ||
@Override | ||
public boolean checkPermissions(Player player) { | ||
return player.hasPermission("minebay.user") || player.hasPermission("minebay.admin"); | ||
return player.hasPermission("wc.create"); | ||
} | ||
|
||
@Override | ||
public boolean executeCommand(CommandSender sender, Command command, String commandLabel, String[] args) { | ||
if (args.length < 2) { | ||
sender.sendMessage(Message.pluginMessage("Not enough options, see /wc help for usage.")); | ||
return true; | ||
} | ||
|
||
WorldCreator worldCreator = new WorldCreator("world_test"); | ||
worldCreator.type(WorldType.NORMAL); | ||
String worldName = WorldHelper.getWorldFromArgs(args); | ||
WorldType type = WorldType.getByName(args[2]); | ||
|
||
if (type == null) { | ||
sender.sendMessage(Message.pluginMessage("World type must be DEFAULT, FLAT, LARGEBIOMES or AMPLIFIED!")); | ||
return true; | ||
} | ||
|
||
WorldCreator worldCreator = new WorldCreator(worldName); | ||
worldCreator.type(type); | ||
worldCreator.createWorld(); | ||
WorldConfiguration.getInstance().setWorldLoad(worldName, true); | ||
|
||
sender.sendMessage(Message.pluginMessage("World created successfully!")); | ||
|
||
return true; | ||
} | ||
|
||
@Override | ||
public List<String> onTabComplete(CommandSender sender, Command command, String commandLabel, String[] args) { | ||
return null; | ||
List<String> options = new ArrayList<>(); | ||
|
||
if (args.length == 2) { | ||
options.add("<WORLD NAME>"); | ||
} else if (args.length == 3) { | ||
options.add("DEFAULT"); | ||
options.add("FLAT"); | ||
options.add("LARGEBIOMES"); | ||
options.add("AMPLIFIED"); | ||
} | ||
|
||
return options; | ||
} | ||
} |
Oops, something went wrong.