Skip to content

Commit

Permalink
stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
uweb committed Jul 10, 2023
1 parent f02833b commit fb4b417
Show file tree
Hide file tree
Showing 22 changed files with 713 additions and 161 deletions.
32 changes: 32 additions & 0 deletions README.md
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
122 changes: 61 additions & 61 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,75 +2,75 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<modelVersion>4.0.0</modelVersion>

<groupId>de.uweb95</groupId>
<artifactId>WorldCreator</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<groupId>de.uweb95</groupId>
<artifactId>WorldCreator</artifactId>
<version>1.0</version>
<packaging>jar</packaging>

<name>WorldCreator</name>
<name>WorldCreator</name>

<description>A simple plugin to generate and import worlds</description>
<properties>
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<url>https://mc.lunar-software.eu</url>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>16</source>
<target>16</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>

<repositories>
<repository>
<id>papermc-repo</id>
<url>https://repo.papermc.io/repository/maven-public/</url>
</repository>
<repository>
<id>sonatype</id>
<url>https://oss.sonatype.org/content/groups/public/</url>
</repository>
</repositories>
<repositories>
<repository>
<id>papermc-repo</id>
<url>https://repo.papermc.io/repository/maven-public/</url>
</repository>
<repository>
<id>sonatype</id>
<url>https://oss.sonatype.org/content/groups/public/</url>
</repository>
</repositories>

<dependencies>
<dependency>
<groupId>io.papermc.paper</groupId>
<artifactId>paper-api</artifactId>
<version>1.20-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
<dependencies>
<dependency>
<groupId>io.papermc.paper</groupId>
<artifactId>paper-api</artifactId>
<version>1.20-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
70 changes: 66 additions & 4 deletions src/main/java/de/uweb95/worldcreator/WorldCreator.java
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;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.uweb95.minebay.commands;
package de.uweb95.worldcreator.commands;

import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
Expand Down
31 changes: 22 additions & 9 deletions src/main/java/de/uweb95/worldcreator/commands/CommandManager.java
Original file line number Diff line number Diff line change
@@ -1,27 +1,40 @@
package de.uweb95.minebay.commands;
package de.uweb95.worldcreator.commands;

import de.uweb95.minebay.util.Message;
import de.uweb95.minebay.util.Translation;
import de.uweb95.worldcreator.util.Message;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

import java.util.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class CommandManager implements CommandInterface {
private final Map<String, CommandInterface> commands = new HashMap<>();

/**
* Register a command
*
* @param command command name
* @param commandClass command class instance
*/
public void registerCommand(String command, CommandInterface commandClass) {
commands.put(command, commandClass);
}

/**
* Remove a registered command
*
* @param command command name
*/
public void unregisterCommand(String command) {
commands.remove(command);
}

@Override
public boolean checkPermissions(Player player) {
return player.hasPermission("minebay");
return true;
}

@Override
Expand All @@ -33,7 +46,8 @@ public boolean executeCommand(CommandSender sender, Command command, String comm
}

if (selectedCommand != null) {
if (sender instanceof Player && !selectedCommand.checkPermissions((Player) sender)) {
if (sender instanceof Player && (!sender.isOp() && !sender.hasPermission("wc.admin") && !selectedCommand.checkPermissions((Player) sender))) {
sender.sendMessage(Message.pluginMessage("You don't have the permissions to use this command."));
return false;
}

Expand Down Expand Up @@ -66,10 +80,9 @@ public List<String> onTabComplete(CommandSender sender, Command command, String
}

private void sendHelpMessage(CommandSender sender) {
StringBuilder builder = new StringBuilder(Translation.getTranslation("help")).append("\n");

StringBuilder builder = new StringBuilder("World creator options:\n");
commands.forEach((key, value) -> builder.append(key).append("\n"));

builder.append("Use the 'help' command to see further information for each command.");
sender.sendMessage(Message.pluginMessage(builder.toString()));
}
}
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;
}
}
Loading

0 comments on commit fb4b417

Please # to comment.