diff --git a/src/main/java/me/lokka30/phantomworlds/PhantomWorlds.java b/src/main/java/me/lokka30/phantomworlds/PhantomWorlds.java
index b4b718d..2f89630 100644
--- a/src/main/java/me/lokka30/phantomworlds/PhantomWorlds.java
+++ b/src/main/java/me/lokka30/phantomworlds/PhantomWorlds.java
@@ -2,9 +2,13 @@
import me.lokka30.microlib.files.YamlConfigFile;
import me.lokka30.microlib.maths.QuickTimer;
+import me.lokka30.microlib.messaging.MultiMessage;
import me.lokka30.microlib.other.UpdateChecker;
import me.lokka30.phantomworlds.commands.phantomworlds.PWCommand;
import me.lokka30.phantomworlds.commands.phantomworlds.PhantomWorldsCommand;
+import me.lokka30.phantomworlds.commands.phantomworlds.parameters.resolvers.WorldFolderResolver;
+import me.lokka30.phantomworlds.commands.phantomworlds.parameters.suggestion.WorldFolderSuggestion;
+import me.lokka30.phantomworlds.commands.phantomworlds.utils.WorldFolder;
import me.lokka30.phantomworlds.listeners.player.PlayerChangeWorldListener;
import me.lokka30.phantomworlds.listeners.player.PlayerDeathListener;
import me.lokka30.phantomworlds.listeners.player.PlayerJoinListener;
@@ -17,11 +21,13 @@
import me.lokka30.phantomworlds.misc.Utils;
import me.lokka30.phantomworlds.scheduler.BackupScheduler;
import org.bstats.bukkit.Metrics;
+import org.bukkit.ChatColor;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitTask;
import revxrsal.commands.bukkit.BukkitCommandHandler;
import java.io.File;
+import java.util.ArrayList;
import java.util.concurrent.TimeUnit;
import java.util.logging.Logger;
@@ -90,8 +96,7 @@ public class PhantomWorlds extends JavaPlugin {
/*
Used to check if world are loaded
*/
- private boolean isWorldLoaded;
-
+ private boolean isWorldLoaded = false;
/**
* This method is called by Bukkit when it loads PhantomWorlds.
@@ -106,14 +111,7 @@ public void onEnable() {
QuickTimer timer = new QuickTimer(TimeUnit.MILLISECONDS);
checkCompatibility();
loadFiles();
-
- isWorldLoaded = false;
- getServer().getPluginManager().registerEvents(new PlayerChangeWorldListener(this), this);
- getServer().getPluginManager().registerEvents(new PlayerDeathListener(this), this);
- getServer().getPluginManager().registerEvents(new PlayerJoinListener(this), this);
- getServer().getPluginManager().registerEvents(new PlayerPortalListener(this), this);
-
- getServer().getPluginManager().registerEvents(new WorldInitListener(this), this);
+ loadWorlds();
registerCommands();
registerListeners();
@@ -121,7 +119,7 @@ public void onEnable() {
if(settings.getConfig().getBoolean("backup-scheduler", true)) {
getLogger().info("Starting up Backup scheduler...");
- backupService = new BackupScheduler().runTaskTimerAsynchronously(this, 0, settings.getConfig().getInt("backup-delay") * 20L);
+ backupService = new BackupScheduler().runTaskTimerAsynchronously(this, settings.getConfig().getInt("backup-delay") * 20L, settings.getConfig().getInt("backup-delay") * 20L);
}
getLogger().info("Start-up complete (took " + timer.getDuration() + "ms)");
@@ -213,9 +211,30 @@ public void loadWorlds() {
*/
void registerCommands() {
getLogger().info("Registering commands...");
- Utils.registerCommand(new PhantomWorldsCommand(), "phantomworlds");
+ //Utils.registerCommand(new PhantomWorldsCommand(), "phantomworlds");
this.command = BukkitCommandHandler.create(this);
+
+ //Set our command help writer
+ command.setHelpWriter((command, actor) -> {
+ if(command.getDescription() == null) {
+ return "";
+ }
+
+ final String description = PhantomWorlds.instance().messages.getConfig().getString(command.getDescription());
+ if(description == null) {
+ return "";
+ }
+
+ return ChatColor.translateAlternateColorCodes('&', description);
+ });
+
+ //Register Resolvers
+ this.command.registerValueResolver(WorldFolder.class, new WorldFolderResolver());
+
+ //Register Suggestors
+ this.command.getAutoCompleter().registerParameterSuggestions(WorldFolder.class, new WorldFolderSuggestion());
+
this.command.register(new PWCommand());
this.command.registerBrigadier();
}
@@ -228,7 +247,12 @@ void registerCommands() {
*/
void registerListeners() {
getLogger().info("Registering listeners...");
- /* Register any listeners here. */
+ getServer().getPluginManager().registerEvents(new PlayerChangeWorldListener(this), this);
+ getServer().getPluginManager().registerEvents(new PlayerDeathListener(this), this);
+ getServer().getPluginManager().registerEvents(new PlayerJoinListener(this), this);
+ getServer().getPluginManager().registerEvents(new PlayerPortalListener(this), this);
+
+ //getServer().getPluginManager().registerEvents(new WorldInitListener(this), this);
}
/**
diff --git a/src/main/java/me/lokka30/phantomworlds/commands/phantomworlds/PWCommand.java b/src/main/java/me/lokka30/phantomworlds/commands/phantomworlds/PWCommand.java
index 4f5857a..f9ea0b8 100644
--- a/src/main/java/me/lokka30/phantomworlds/commands/phantomworlds/PWCommand.java
+++ b/src/main/java/me/lokka30/phantomworlds/commands/phantomworlds/PWCommand.java
@@ -17,26 +17,35 @@
* along with this program. If not, see .
*/
-import me.lokka30.phantomworlds.commands.phantomworlds.parameters.sub.BackupCommand;
-import me.lokka30.phantomworlds.commands.phantomworlds.parameters.sub.CompatibilityCommand;
-import me.lokka30.phantomworlds.commands.phantomworlds.parameters.sub.DebugCommand;
-import me.lokka30.phantomworlds.commands.phantomworlds.parameters.sub.DeleteCommand;
-import me.lokka30.phantomworlds.commands.phantomworlds.parameters.sub.ImportCommand;
-import me.lokka30.phantomworlds.commands.phantomworlds.parameters.sub.InfoCommand;
-import me.lokka30.phantomworlds.commands.phantomworlds.parameters.sub.ListCommand;
-import me.lokka30.phantomworlds.commands.phantomworlds.parameters.sub.ReloadCommand;
-import me.lokka30.phantomworlds.commands.phantomworlds.parameters.sub.SetSpawnCommand;
-import me.lokka30.phantomworlds.commands.phantomworlds.parameters.sub.SpawnCommand;
-import me.lokka30.phantomworlds.commands.phantomworlds.parameters.sub.TeleportCommand;
-import me.lokka30.phantomworlds.commands.phantomworlds.parameters.sub.UnloadCommand;
+import me.lokka30.microlib.messaging.MultiMessage;
+import me.lokka30.phantomworlds.PhantomWorlds;
+import me.lokka30.phantomworlds.commands.phantomworlds.sub.BackupCommand;
+import me.lokka30.phantomworlds.commands.phantomworlds.sub.CompatibilityCommand;
+import me.lokka30.phantomworlds.commands.phantomworlds.sub.DebugCommand;
+import me.lokka30.phantomworlds.commands.phantomworlds.sub.DeleteCommand;
+import me.lokka30.phantomworlds.commands.phantomworlds.sub.ImportCommand;
+import me.lokka30.phantomworlds.commands.phantomworlds.sub.InfoCommand;
+import me.lokka30.phantomworlds.commands.phantomworlds.sub.ListCommand;
+import me.lokka30.phantomworlds.commands.phantomworlds.sub.LoadCommand;
+import me.lokka30.phantomworlds.commands.phantomworlds.sub.ReloadCommand;
+import me.lokka30.phantomworlds.commands.phantomworlds.sub.SetSpawnCommand;
+import me.lokka30.phantomworlds.commands.phantomworlds.sub.SpawnCommand;
+import me.lokka30.phantomworlds.commands.phantomworlds.sub.TeleportCommand;
+import me.lokka30.phantomworlds.commands.phantomworlds.sub.UnloadCommand;
+import me.lokka30.phantomworlds.commands.phantomworlds.utils.WorldFolder;
import org.bukkit.World;
import org.bukkit.entity.Player;
import revxrsal.commands.annotation.Command;
+import revxrsal.commands.annotation.Default;
import revxrsal.commands.annotation.DefaultFor;
+import revxrsal.commands.annotation.Description;
import revxrsal.commands.annotation.Optional;
import revxrsal.commands.annotation.Subcommand;
import revxrsal.commands.bukkit.BukkitCommandActor;
import revxrsal.commands.bukkit.annotation.CommandPermission;
+import revxrsal.commands.help.CommandHelp;
+
+import java.util.ArrayList;
/**
* PWCommand
@@ -47,88 +56,111 @@
@Command({"pw", "phantomworlds"})
public class PWCommand {
+ @Subcommand({"help", "?"})
+ @DefaultFor({"pw", "phantomworlds"})
+ public void help(BukkitCommandActor actor, CommandHelp helpEntries, @Default("1") int page) {
+ for(final String entry : helpEntries.paginate(page, 5)) {
+ (new MultiMessage(
+ PhantomWorlds.instance().messages.getConfig().getStringList(entry), new ArrayList<>()
+ )).send(actor.getSender());
+ }
+ }
+
@Subcommand({"backup", "archive", "bu"})
@CommandPermission("phantomworlds.command.phantomworlds.backup")
- public void backup(BukkitCommandActor actor, final World world) {
+ @Description("command.phantomworlds.usages.backup")
+ public void backup(BukkitCommandActor actor, @Optional final World world) {
BackupCommand.onCommand(actor, world);
}
@Subcommand({"create", "+", "new"})
@CommandPermission("phantomworlds.command.phantomworlds.create")
+ @Description("command.phantomworlds.usages.create")
public void create(BukkitCommandActor actor) {
//todo: port create command
}
@Subcommand({"compatibility"})
@CommandPermission("phantomworlds.command.phantomworlds.compatibility")
+ @Description("command.phantomworlds.usages.compatibility")
public void compatibility(BukkitCommandActor actor) {
CompatibilityCommand.onCommand(actor);
}
@Subcommand({"debug"})
@CommandPermission("phantomworlds.command.phantomworlds.debug")
- public void debug(BukkitCommandActor actor, final String level) {
+ @Description("command.phantomworlds.usages.debug")
+ public void debug(BukkitCommandActor actor, @Optional final String level) {
DebugCommand.onCommand(actor, level);
}
@Subcommand({"delete", "-", "remove", "del"})
@CommandPermission("phantomworlds.command.phantomworlds.delete")
- public void delete(BukkitCommandActor actor, final World world) {
+ @Description("command.phantomworlds.usages.delete")
+ public void delete(BukkitCommandActor actor, @Optional final World world) {
DeleteCommand.onCommand(actor, world);
}
- @Subcommand({"create", "+", "new"})
- @DefaultFor({"pw", "phantomworlds"})
+ @Subcommand({"list", "l"})
@CommandPermission("phantomworlds.command.phantomworlds.list")
+ @Description("command.phantomworlds.usages.list")
public void list(BukkitCommandActor actor) {
ListCommand.onCommand(actor);
}
- @Subcommand({"gamerule", "rule"})
- @CommandPermission("phantomworlds.command.phantomworlds.gamerule")
- public void gamerule(BukkitCommandActor actor) {
- //todo: port gamerule command
- }
-
@Subcommand({"import", "im"})
@CommandPermission("phantomworlds.command.phantomworlds.import")
- public void importCMD(BukkitCommandActor actor, final World world) {
+ @Description("command.phantomworlds.usages.import")
+ public void importCMD(BukkitCommandActor actor, @Optional final World world) {
ImportCommand.onCommand(actor, world);
}
@Subcommand({"info", "i"})
@CommandPermission("phantomworlds.command.phantomworlds.info")
+ @Description("command.phantomworlds.usages.info")
public void info(BukkitCommandActor actor) {
InfoCommand.onCommand(actor);
}
+ @Subcommand({"load"})
+ @CommandPermission("phantomworlds.command.phantomworlds.load")
+ @Description("command.phantomworlds.usages.load")
+ public void load(BukkitCommandActor actor, @Optional final WorldFolder world) {
+ LoadCommand.onCommand(actor, world);
+ }
+
@Subcommand({"reload", "r"})
@CommandPermission("phantomworlds.command.phantomworlds.reload")
+ @Description("command.phantomworlds.usages.reload")
public void reload(BukkitCommandActor actor) {
ReloadCommand.onCommand(actor);
}
@Subcommand({"setspawn"})
@CommandPermission("phantomworlds.command.phantomworlds.setspawn")
+ @Description("command.phantomworlds.usages.setspawn")
public void setspawn(BukkitCommandActor actor, @Optional Double x, @Optional Double y, @Optional Double z, @Optional World world, @Optional Float yaw, @Optional Float pitch) {
SetSpawnCommand.onCommand(actor, x, y, z, world, yaw, pitch);
}
@Subcommand({"spawn"})
@CommandPermission("phantomworlds.command.phantomworlds.spawn")
- public void spawn(BukkitCommandActor actor, final World world, @Optional final Player player) {
+ @Description("command.phantomworlds.usages.spawn")
+ public void spawn(BukkitCommandActor actor, @Optional final World world, @Optional final Player player) {
SpawnCommand.onCommand(actor, world, player);
}
@Subcommand({"teleport", "tp"})
@CommandPermission("phantomworlds.command.phantomworlds.teleport")
- public void tp(BukkitCommandActor actor, final World world, @Optional final Player player) {
+ @Description("command.phantomworlds.usages.tp")
+ public void tp(BukkitCommandActor actor, @Optional final World world, @Optional final Player player) {
TeleportCommand.onCommand(actor, world, player);
}
@Subcommand({"unload", "u"})
@CommandPermission("phantomworlds.command.phantomworlds.unload")
- public void unload(BukkitCommandActor actor, final World world) {
+ @Description("command.phantomworlds.usages.unload")
+ public void unload(BukkitCommandActor actor, @Optional final World world) {
UnloadCommand.onCommand(actor, world);
}
}
\ No newline at end of file
diff --git a/src/main/java/me/lokka30/phantomworlds/commands/phantomworlds/parameters/resolvers/WorldFolderResolver.java b/src/main/java/me/lokka30/phantomworlds/commands/phantomworlds/parameters/resolvers/WorldFolderResolver.java
new file mode 100644
index 0000000..fa2e277
--- /dev/null
+++ b/src/main/java/me/lokka30/phantomworlds/commands/phantomworlds/parameters/resolvers/WorldFolderResolver.java
@@ -0,0 +1,38 @@
+package me.lokka30.phantomworlds.commands.phantomworlds.parameters.resolvers;
+/*
+ * The New Economy
+ * Copyright (C) 2022 - 2023 Daniel "creatorfromhell" Vidmar
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ */
+
+import me.lokka30.phantomworlds.commands.phantomworlds.utils.WorldFolder;
+import org.jetbrains.annotations.NotNull;
+import revxrsal.commands.process.ValueResolver;
+
+/**
+ * StatusResolver
+ *
+ * @author creatorfromhell
+ * @since 0.1.2.0
+ */
+public class WorldFolderResolver implements ValueResolver {
+
+ @Override
+ public WorldFolder resolve(@NotNull ValueResolverContext context) throws Throwable {
+ final String value = context.arguments().pop();
+
+ return new WorldFolder(value);
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/me/lokka30/phantomworlds/commands/phantomworlds/parameters/sub/ListCommand.java b/src/main/java/me/lokka30/phantomworlds/commands/phantomworlds/parameters/sub/ListCommand.java
deleted file mode 100644
index 40aecd1..0000000
--- a/src/main/java/me/lokka30/phantomworlds/commands/phantomworlds/parameters/sub/ListCommand.java
+++ /dev/null
@@ -1,58 +0,0 @@
-package me.lokka30.phantomworlds.commands.phantomworlds.parameters.sub;
-/*
- * Phantom Worlds
- * Copyright (C) 2023 Daniel "creatorfromhell" Vidmar
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see .
- */
-
-import me.lokka30.microlib.messaging.MultiMessage;
-import me.lokka30.phantomworlds.PhantomWorlds;
-import org.bukkit.Bukkit;
-import org.bukkit.World;
-import revxrsal.commands.bukkit.BukkitCommandActor;
-
-import java.util.Arrays;
-
-/**
- * ListCommand
- *
- * @author creatorfromhell
- * @since 2.0.5.0
- */
-public class ListCommand {
-
- public static void onCommand(final BukkitCommandActor actor, Integer... test) {
- (new MultiMessage(
- PhantomWorlds.instance().messages.getConfig()
- .getStringList("command.phantomworlds.subcommands.list.header"), Arrays.asList(
- new MultiMessage.Placeholder("prefix",
- PhantomWorlds.instance().messages.getConfig().getString("common.prefix", "&b&lPhantomWorlds: &7"),
- true),
- new MultiMessage.Placeholder("amount", String.valueOf(Bukkit.getWorlds().size()), false)
- ))).send(actor.getSender());
-
- //TODO: Unloaded, archived, last backup times.
- for(final World world : Bukkit.getWorlds()) {
- (new MultiMessage(
- PhantomWorlds.instance().messages.getConfig()
- .getStringList("command.phantomworlds.subcommands.list.entry"), Arrays.asList(
- new MultiMessage.Placeholder("prefix",
- PhantomWorlds.instance().messages.getConfig().getString("common.prefix", "&b&lPhantomWorlds: &7"),
- true),
- new MultiMessage.Placeholder("world", world.getName(), false)
- ))).send(actor.getSender());
- }
- }
-}
\ No newline at end of file
diff --git a/src/main/java/me/lokka30/phantomworlds/commands/phantomworlds/parameters/suggestion/WorldFolderSuggestion.java b/src/main/java/me/lokka30/phantomworlds/commands/phantomworlds/parameters/suggestion/WorldFolderSuggestion.java
new file mode 100644
index 0000000..516d577
--- /dev/null
+++ b/src/main/java/me/lokka30/phantomworlds/commands/phantomworlds/parameters/suggestion/WorldFolderSuggestion.java
@@ -0,0 +1,52 @@
+package me.lokka30.phantomworlds.commands.phantomworlds.parameters.suggestion;
+/*
+ * The New Economy
+ * Copyright (C) 2022 - 2023 Daniel "creatorfromhell" Vidmar
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ */
+
+import org.bukkit.Bukkit;
+import org.jetbrains.annotations.NotNull;
+import revxrsal.commands.autocomplete.SuggestionProvider;
+import revxrsal.commands.command.CommandActor;
+import revxrsal.commands.command.ExecutableCommand;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+/**
+ * RegionSuggestion
+ *
+ * @author creatorfromhell
+ * @since 0.1.2.0
+ */
+public class WorldFolderSuggestion implements SuggestionProvider {
+
+ @Override
+ public @NotNull Collection getSuggestions(@NotNull List list, @NotNull CommandActor commandActor, @NotNull ExecutableCommand executableCommand) throws Throwable {
+
+ final List folders = new ArrayList<>();
+ final File directory = Bukkit.getWorldContainer();
+
+ for(File file : directory.listFiles()) {
+ if(file.isDirectory()) {
+ folders.add(file.getName());
+ }
+ }
+ return folders;
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/me/lokka30/phantomworlds/commands/phantomworlds/parameters/sub/BackupCommand.java b/src/main/java/me/lokka30/phantomworlds/commands/phantomworlds/sub/BackupCommand.java
similarity index 90%
rename from src/main/java/me/lokka30/phantomworlds/commands/phantomworlds/parameters/sub/BackupCommand.java
rename to src/main/java/me/lokka30/phantomworlds/commands/phantomworlds/sub/BackupCommand.java
index 8a39eb3..578b898 100644
--- a/src/main/java/me/lokka30/phantomworlds/commands/phantomworlds/parameters/sub/BackupCommand.java
+++ b/src/main/java/me/lokka30/phantomworlds/commands/phantomworlds/sub/BackupCommand.java
@@ -1,4 +1,4 @@
-package me.lokka30.phantomworlds.commands.phantomworlds.parameters.sub;
+package me.lokka30.phantomworlds.commands.phantomworlds.sub;
/*
* Phantom Worlds
@@ -20,6 +20,7 @@
import me.lokka30.microlib.messaging.MultiMessage;
import me.lokka30.phantomworlds.PhantomWorlds;
+import me.lokka30.phantomworlds.misc.Utils;
import org.bukkit.World;
import revxrsal.commands.bukkit.BukkitCommandActor;
@@ -35,6 +36,10 @@ public class BackupCommand {
public static void onCommand(final BukkitCommandActor actor, final World world) {
+ if(!Utils.checkWorld(actor.getSender(), "command.phantomworlds.subcommands.backup.usage", world)) {
+ return;
+ }
+
if(!PhantomWorlds.worldManager().backupWorld(world.getName())) {
(new MultiMessage(
PhantomWorlds.instance().messages.getConfig()
diff --git a/src/main/java/me/lokka30/phantomworlds/commands/phantomworlds/parameters/sub/CompatibilityCommand.java b/src/main/java/me/lokka30/phantomworlds/commands/phantomworlds/sub/CompatibilityCommand.java
similarity index 98%
rename from src/main/java/me/lokka30/phantomworlds/commands/phantomworlds/parameters/sub/CompatibilityCommand.java
rename to src/main/java/me/lokka30/phantomworlds/commands/phantomworlds/sub/CompatibilityCommand.java
index ff98169..b3ad57e 100644
--- a/src/main/java/me/lokka30/phantomworlds/commands/phantomworlds/parameters/sub/CompatibilityCommand.java
+++ b/src/main/java/me/lokka30/phantomworlds/commands/phantomworlds/sub/CompatibilityCommand.java
@@ -1,4 +1,4 @@
-package me.lokka30.phantomworlds.commands.phantomworlds.parameters.sub;
+package me.lokka30.phantomworlds.commands.phantomworlds.sub;
/*
* Phantom Worlds
* Copyright (C) 2023 Daniel "creatorfromhell" Vidmar
diff --git a/src/main/java/me/lokka30/phantomworlds/commands/phantomworlds/parameters/sub/DebugCommand.java b/src/main/java/me/lokka30/phantomworlds/commands/phantomworlds/sub/DebugCommand.java
similarity index 88%
rename from src/main/java/me/lokka30/phantomworlds/commands/phantomworlds/parameters/sub/DebugCommand.java
rename to src/main/java/me/lokka30/phantomworlds/commands/phantomworlds/sub/DebugCommand.java
index 30380f2..80283fb 100644
--- a/src/main/java/me/lokka30/phantomworlds/commands/phantomworlds/parameters/sub/DebugCommand.java
+++ b/src/main/java/me/lokka30/phantomworlds/commands/phantomworlds/sub/DebugCommand.java
@@ -1,4 +1,4 @@
-package me.lokka30.phantomworlds.commands.phantomworlds.parameters.sub;
+package me.lokka30.phantomworlds.commands.phantomworlds.sub;
/*
* Phantom Worlds
* Copyright (C) 2023 Daniel "creatorfromhell" Vidmar
@@ -31,7 +31,9 @@
public class DebugCommand {
public static void onCommand(final BukkitCommandActor actor, final String level) {
- switch(level.toLowerCase(Locale.ROOT)) {
+
+ final String parsed = (level == null)? "nothing" : level;
+ switch(parsed.toLowerCase(Locale.ROOT)) {
case "dump":
actor.getSender().sendMessage(
MessageUtils.colorizeStandardCodes("&b&lPhantomWorlds: &7Incomplete."));
@@ -39,7 +41,7 @@ public static void onCommand(final BukkitCommandActor actor, final String level)
default:
actor.getSender().sendMessage(MessageUtils.colorizeStandardCodes(
"&b&lPhantomWorlds: &7Invalid debug method '%method%'.")
- .replace("%method%", level)
+ .replace("%method%", parsed)
);
actor.getSender().sendMessage(MessageUtils.colorizeStandardCodes(
diff --git a/src/main/java/me/lokka30/phantomworlds/commands/phantomworlds/parameters/sub/DeleteCommand.java b/src/main/java/me/lokka30/phantomworlds/commands/phantomworlds/sub/DeleteCommand.java
similarity index 92%
rename from src/main/java/me/lokka30/phantomworlds/commands/phantomworlds/parameters/sub/DeleteCommand.java
rename to src/main/java/me/lokka30/phantomworlds/commands/phantomworlds/sub/DeleteCommand.java
index 3fdfac9..f2f21db 100644
--- a/src/main/java/me/lokka30/phantomworlds/commands/phantomworlds/parameters/sub/DeleteCommand.java
+++ b/src/main/java/me/lokka30/phantomworlds/commands/phantomworlds/sub/DeleteCommand.java
@@ -1,4 +1,4 @@
-package me.lokka30.phantomworlds.commands.phantomworlds.parameters.sub;
+package me.lokka30.phantomworlds.commands.phantomworlds.sub;
/*
* Phantom Worlds
* Copyright (C) 2023 Daniel "creatorfromhell" Vidmar
@@ -19,6 +19,7 @@
import me.lokka30.microlib.messaging.MultiMessage;
import me.lokka30.phantomworlds.PhantomWorlds;
+import me.lokka30.phantomworlds.misc.Utils;
import org.bukkit.World;
import org.bukkit.entity.Player;
import revxrsal.commands.bukkit.BukkitCommandActor;
@@ -35,6 +36,10 @@ public class DeleteCommand {
public static void onCommand(final BukkitCommandActor actor, final World world) {
+ if(!Utils.checkWorld(actor.getSender(), "command.phantomworlds.subcommands.delete.usage", world)) {
+ return;
+ }
+
if(actor.getSender() instanceof Player) {
if(world.getPlayers().contains((Player)actor.getSender())) {
diff --git a/src/main/java/me/lokka30/phantomworlds/commands/phantomworlds/parameters/sub/ImportCommand.java b/src/main/java/me/lokka30/phantomworlds/commands/phantomworlds/sub/ImportCommand.java
similarity index 50%
rename from src/main/java/me/lokka30/phantomworlds/commands/phantomworlds/parameters/sub/ImportCommand.java
rename to src/main/java/me/lokka30/phantomworlds/commands/phantomworlds/sub/ImportCommand.java
index 5efefb9..9303baf 100644
--- a/src/main/java/me/lokka30/phantomworlds/commands/phantomworlds/parameters/sub/ImportCommand.java
+++ b/src/main/java/me/lokka30/phantomworlds/commands/phantomworlds/sub/ImportCommand.java
@@ -1,4 +1,4 @@
-package me.lokka30.phantomworlds.commands.phantomworlds.parameters.sub;
+package me.lokka30.phantomworlds.commands.phantomworlds.sub;
/*
* Phantom Worlds
* Copyright (C) 2023 Daniel "creatorfromhell" Vidmar
@@ -17,12 +17,16 @@
* along with this program. If not, see .
*/
+import me.lokka30.microlib.messaging.MultiMessage;
import me.lokka30.phantomworlds.PhantomWorlds;
import me.lokka30.phantomworlds.world.PhantomWorld;
import org.bukkit.GameMode;
import org.bukkit.World;
import revxrsal.commands.bukkit.BukkitCommandActor;
+import java.util.Arrays;
+import java.util.Collections;
+
/**
* ImportCommand
*
@@ -34,13 +38,26 @@ public class ImportCommand {
public static void onCommand(final BukkitCommandActor actor, final World world) {
if(world == null) {
- //TODO: send message world doesn't exist, can't import.
+ (new MultiMessage(
+ PhantomWorlds.instance().messages.getConfig().getStringList(
+ "command.phantomworlds.subcommands.import.failure-exist"),
+ Collections.singletonList(
+ new MultiMessage.Placeholder("prefix", PhantomWorlds.instance().messages.getConfig()
+ .getString("common.prefix", "&b&lPhantomWorlds: &7"), true)
+ ))).send(actor.getSender());
return;
}
final String cfgPath = "worlds-to-load." + world.getName() + ".";
if(PhantomWorlds.instance().data.getConfig().contains(cfgPath)) {
- //TODO: Already a PhantomWorlds managed world.
+ (new MultiMessage(
+ PhantomWorlds.instance().messages.getConfig().getStringList(
+ "command.phantomworlds.subcommands.import.failure-already"),
+ Arrays.asList(
+ new MultiMessage.Placeholder("prefix", PhantomWorlds.instance().messages.getConfig()
+ .getString("common.prefix", "&b&lPhantomWorlds: &7"), true),
+ new MultiMessage.Placeholder("world", world.getName(), false)
+ ))).send(actor.getSender());
return;
}
@@ -50,6 +67,13 @@ public static void onCommand(final BukkitCommandActor actor, final World world)
world.getAllowAnimals(), world.getKeepSpawnInMemory(), world.getPVP(), world.getDifficulty(), GameMode.SURVIVAL
);
pworld.save();
- //TODO: world imported and will be managed by phantomworlds
+ (new MultiMessage(
+ PhantomWorlds.instance().messages.getConfig().getStringList(
+ "command.phantomworlds.subcommands.import.success"),
+ Arrays.asList(
+ new MultiMessage.Placeholder("prefix", PhantomWorlds.instance().messages.getConfig()
+ .getString("common.prefix", "&b&lPhantomWorlds: &7"), true),
+ new MultiMessage.Placeholder("world", world.getName(), false)
+ ))).send(actor.getSender());
}
}
\ No newline at end of file
diff --git a/src/main/java/me/lokka30/phantomworlds/commands/phantomworlds/parameters/sub/InfoCommand.java b/src/main/java/me/lokka30/phantomworlds/commands/phantomworlds/sub/InfoCommand.java
similarity index 96%
rename from src/main/java/me/lokka30/phantomworlds/commands/phantomworlds/parameters/sub/InfoCommand.java
rename to src/main/java/me/lokka30/phantomworlds/commands/phantomworlds/sub/InfoCommand.java
index 8a54c46..324e39c 100644
--- a/src/main/java/me/lokka30/phantomworlds/commands/phantomworlds/parameters/sub/InfoCommand.java
+++ b/src/main/java/me/lokka30/phantomworlds/commands/phantomworlds/sub/InfoCommand.java
@@ -1,4 +1,4 @@
-package me.lokka30.phantomworlds.commands.phantomworlds.parameters.sub;
+package me.lokka30.phantomworlds.commands.phantomworlds.sub;
/*
* Phantom Worlds
* Copyright (C) 2023 Daniel "creatorfromhell" Vidmar
diff --git a/src/main/java/me/lokka30/phantomworlds/commands/phantomworlds/sub/ListCommand.java b/src/main/java/me/lokka30/phantomworlds/commands/phantomworlds/sub/ListCommand.java
new file mode 100644
index 0000000..143cd59
--- /dev/null
+++ b/src/main/java/me/lokka30/phantomworlds/commands/phantomworlds/sub/ListCommand.java
@@ -0,0 +1,123 @@
+package me.lokka30.phantomworlds.commands.phantomworlds.sub;
+/*
+ * Phantom Worlds
+ * Copyright (C) 2023 Daniel "creatorfromhell" Vidmar
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ */
+
+import me.lokka30.microlib.messaging.MultiMessage;
+import me.lokka30.phantomworlds.PhantomWorlds;
+import org.bukkit.Bukkit;
+import org.bukkit.World;
+import revxrsal.commands.bukkit.BukkitCommandActor;
+
+import java.io.File;
+import java.util.Arrays;
+import java.util.HashSet;
+
+/**
+ * ListCommand
+ *
+ * @author creatorfromhell
+ * @since 2.0.5.0
+ */
+public class ListCommand {
+
+ public static void onCommand(final BukkitCommandActor actor) {
+ (new MultiMessage(
+ PhantomWorlds.instance().messages.getConfig()
+ .getStringList("command.phantomworlds.subcommands.list.header-loaded"), Arrays.asList(
+ new MultiMessage.Placeholder("prefix",
+ PhantomWorlds.instance().messages.getConfig().getString("common.prefix", "&b&lPhantomWorlds: &7"),
+ true),
+ new MultiMessage.Placeholder("amount", String.valueOf(Bukkit.getWorlds().size()), false)
+ ))).send(actor.getSender());
+
+ final HashSet loaded = new HashSet<>();
+
+ //TODO: archived, last backup times.
+ for(final World world : Bukkit.getWorlds()) {
+ loaded.add(world.getName());
+ }
+
+ for(String world : loaded) {
+ (new MultiMessage(
+ PhantomWorlds.instance().messages.getConfig()
+ .getStringList("command.phantomworlds.subcommands.list.entry"), Arrays.asList(
+ new MultiMessage.Placeholder("prefix",
+ PhantomWorlds.instance().messages.getConfig().getString("common.prefix", "&b&lPhantomWorlds: &7"),
+ true),
+ new MultiMessage.Placeholder("world", world, false)
+ ))).send(actor.getSender());
+ }
+
+ final HashSet unloaded = new HashSet<>();
+ final File directory = Bukkit.getWorldContainer();
+
+ for(File file : directory.listFiles()) {
+ if(file.isDirectory() && !loaded.contains(file.getName())) {
+ unloaded.add(file.getName());
+ }
+ }
+
+ (new MultiMessage(
+ PhantomWorlds.instance().messages.getConfig()
+ .getStringList("command.phantomworlds.subcommands.list.header-unloaded"), Arrays.asList(
+ new MultiMessage.Placeholder("prefix",
+ PhantomWorlds.instance().messages.getConfig().getString("common.prefix", "&b&lPhantomWorlds: &7"),
+ true),
+ new MultiMessage.Placeholder("amount", String.valueOf(unloaded.size()), false)
+ ))).send(actor.getSender());
+
+ for(String world : unloaded) {
+ (new MultiMessage(
+ PhantomWorlds.instance().messages.getConfig()
+ .getStringList("command.phantomworlds.subcommands.list.entry"), Arrays.asList(
+ new MultiMessage.Placeholder("prefix",
+ PhantomWorlds.instance().messages.getConfig().getString("common.prefix", "&b&lPhantomWorlds: &7"),
+ true),
+ new MultiMessage.Placeholder("world", world, false)
+ ))).send(actor.getSender());
+ }
+
+ final HashSet archived = new HashSet<>();
+ final File dir = new File(PhantomWorlds.instance().getDataFolder(), PhantomWorlds.BACKUP_FOLDER);
+ for(File file : dir.listFiles()) {
+ if(file.isDirectory() && !loaded.contains(file.getName()) && !unloaded.contains(file.getName())) {
+ archived.add(file.getName());
+ }
+ }
+
+ (new MultiMessage(
+ PhantomWorlds.instance().messages.getConfig()
+ .getStringList("command.phantomworlds.subcommands.list.header-archived"), Arrays.asList(
+ new MultiMessage.Placeholder("prefix",
+ PhantomWorlds.instance().messages.getConfig().getString("common.prefix", "&b&lPhantomWorlds: &7"),
+ true),
+ new MultiMessage.Placeholder("amount", String.valueOf(archived.size()), false)
+ ))).send(actor.getSender());
+
+ for(String world : archived) {
+ (new MultiMessage(
+ PhantomWorlds.instance().messages.getConfig()
+ .getStringList("command.phantomworlds.subcommands.list.entry"), Arrays.asList(
+ new MultiMessage.Placeholder("prefix",
+ PhantomWorlds.instance().messages.getConfig().getString("common.prefix", "&b&lPhantomWorlds: &7"),
+ true),
+ new MultiMessage.Placeholder("world", world, false)
+ ))).send(actor.getSender());
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/me/lokka30/phantomworlds/commands/phantomworlds/sub/LoadCommand.java b/src/main/java/me/lokka30/phantomworlds/commands/phantomworlds/sub/LoadCommand.java
new file mode 100644
index 0000000..f1bdfc9
--- /dev/null
+++ b/src/main/java/me/lokka30/phantomworlds/commands/phantomworlds/sub/LoadCommand.java
@@ -0,0 +1,107 @@
+package me.lokka30.phantomworlds.commands.phantomworlds.sub;
+/*
+ * Phantom Worlds
+ * Copyright (C) 2023 Daniel "creatorfromhell" Vidmar
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ */
+
+import me.lokka30.microlib.messaging.MultiMessage;
+import me.lokka30.phantomworlds.PhantomWorlds;
+import me.lokka30.phantomworlds.commands.phantomworlds.utils.WorldFolder;
+import me.lokka30.phantomworlds.misc.WorldLoadResponse;
+import org.bukkit.Bukkit;
+import revxrsal.commands.bukkit.BukkitCommandActor;
+
+import java.io.File;
+import java.util.Arrays;
+
+import static me.lokka30.phantomworlds.misc.WorldLoadResponse.ALREADY_LOADED;
+import static me.lokka30.phantomworlds.misc.WorldLoadResponse.INVALID;
+import static me.lokka30.phantomworlds.misc.WorldLoadResponse.LOADED;
+
+/**
+ * LoadCommand
+ *
+ * @author creatorfromhell
+ * @since 2.0.5.0
+ */
+public class LoadCommand {
+
+ public static void onCommand(final BukkitCommandActor actor, final WorldFolder world) {
+
+ if(world == null || world.getFolder() == null) {
+ (new MultiMessage(
+ PhantomWorlds.instance().messages.getConfig()
+ .getStringList("command.phantomworlds.usages.load"), Arrays.asList(
+ new MultiMessage.Placeholder("prefix",
+ PhantomWorlds.instance().messages.getConfig().getString("common.prefix", "&b&lPhantomWorlds: &7"),
+ true),
+ new MultiMessage.Placeholder("label", "pw", false)
+ ))).send(actor.getSender());
+ return;
+ }
+
+ final WorldLoadResponse response = PhantomWorlds.worldManager().loadWorld(world.getFolder());
+
+ if(response == ALREADY_LOADED) {
+ (new MultiMessage(
+ PhantomWorlds.instance().messages.getConfig()
+ .getStringList("command.phantomworlds.subcommands.create.already-loaded"),
+ Arrays.asList(
+ new MultiMessage.Placeholder("prefix", PhantomWorlds.instance().messages.getConfig()
+ .getString("common.prefix", "&b&lPhantomWorlds: &7"), true),
+ new MultiMessage.Placeholder("world", world.getFolder(), false),
+ new MultiMessage.Placeholder("label", "pw", false)
+ ))).send(actor.getSender());
+ return;
+ }
+
+ if(response == INVALID) {
+ (new MultiMessage(
+ PhantomWorlds.instance().messages.getConfig()
+ .getStringList("command.phantomworlds.subcommands.create.failure-folder"),
+ Arrays.asList(
+ new MultiMessage.Placeholder("prefix", PhantomWorlds.instance().messages.getConfig()
+ .getString("common.prefix", "&b&lPhantomWorlds: &7"), true),
+ new MultiMessage.Placeholder("world", world.getFolder(), false),
+ new MultiMessage.Placeholder("label", "pw", false)
+ ))).send(actor.getSender());
+ return;
+ }
+
+ if(response != LOADED) {
+
+ (new MultiMessage(
+ PhantomWorlds.instance().messages.getConfig()
+ .getStringList("command.phantomworlds.subcommands.create.failure-loading"),
+ Arrays.asList(
+ new MultiMessage.Placeholder("prefix", PhantomWorlds.instance().messages.getConfig()
+ .getString("common.prefix", "&b&lPhantomWorlds: &7"), true),
+ new MultiMessage.Placeholder("world", world.getFolder(), false),
+ new MultiMessage.Placeholder("label", "pw", false)
+ ))).send(actor.getSender());
+ return;
+ }
+
+ (new MultiMessage(
+ PhantomWorlds.instance().messages.getConfig().getStringList(
+ "command.phantomworlds.subcommands.load.success"),
+ Arrays.asList(
+ new MultiMessage.Placeholder("prefix", PhantomWorlds.instance().messages.getConfig()
+ .getString("common.prefix", "&b&lPhantomWorlds: &7"), true),
+ new MultiMessage.Placeholder("world", world.getFolder(), false)
+ ))).send(actor.getSender());
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/me/lokka30/phantomworlds/commands/phantomworlds/parameters/sub/ReloadCommand.java b/src/main/java/me/lokka30/phantomworlds/commands/phantomworlds/sub/ReloadCommand.java
similarity index 97%
rename from src/main/java/me/lokka30/phantomworlds/commands/phantomworlds/parameters/sub/ReloadCommand.java
rename to src/main/java/me/lokka30/phantomworlds/commands/phantomworlds/sub/ReloadCommand.java
index 0317ea3..8e03eb7 100644
--- a/src/main/java/me/lokka30/phantomworlds/commands/phantomworlds/parameters/sub/ReloadCommand.java
+++ b/src/main/java/me/lokka30/phantomworlds/commands/phantomworlds/sub/ReloadCommand.java
@@ -1,4 +1,4 @@
-package me.lokka30.phantomworlds.commands.phantomworlds.parameters.sub;
+package me.lokka30.phantomworlds.commands.phantomworlds.sub;
/*
* Phantom Worlds
* Copyright (C) 2023 Daniel "creatorfromhell" Vidmar
diff --git a/src/main/java/me/lokka30/phantomworlds/commands/phantomworlds/parameters/sub/SetSpawnCommand.java b/src/main/java/me/lokka30/phantomworlds/commands/phantomworlds/sub/SetSpawnCommand.java
similarity index 98%
rename from src/main/java/me/lokka30/phantomworlds/commands/phantomworlds/parameters/sub/SetSpawnCommand.java
rename to src/main/java/me/lokka30/phantomworlds/commands/phantomworlds/sub/SetSpawnCommand.java
index 16ddf22..6dd3722 100644
--- a/src/main/java/me/lokka30/phantomworlds/commands/phantomworlds/parameters/sub/SetSpawnCommand.java
+++ b/src/main/java/me/lokka30/phantomworlds/commands/phantomworlds/sub/SetSpawnCommand.java
@@ -1,4 +1,4 @@
-package me.lokka30.phantomworlds.commands.phantomworlds.parameters.sub;
+package me.lokka30.phantomworlds.commands.phantomworlds.sub;
/*
* Phantom Worlds
* Copyright (C) 2023 Daniel "creatorfromhell" Vidmar
diff --git a/src/main/java/me/lokka30/phantomworlds/commands/phantomworlds/parameters/sub/SpawnCommand.java b/src/main/java/me/lokka30/phantomworlds/commands/phantomworlds/sub/SpawnCommand.java
similarity index 80%
rename from src/main/java/me/lokka30/phantomworlds/commands/phantomworlds/parameters/sub/SpawnCommand.java
rename to src/main/java/me/lokka30/phantomworlds/commands/phantomworlds/sub/SpawnCommand.java
index 2a53ecf..46b5a36 100644
--- a/src/main/java/me/lokka30/phantomworlds/commands/phantomworlds/parameters/sub/SpawnCommand.java
+++ b/src/main/java/me/lokka30/phantomworlds/commands/phantomworlds/sub/SpawnCommand.java
@@ -1,4 +1,4 @@
-package me.lokka30.phantomworlds.commands.phantomworlds.parameters.sub;
+package me.lokka30.phantomworlds.commands.phantomworlds.sub;
/*
* Phantom Worlds
* Copyright (C) 2023 Daniel "creatorfromhell" Vidmar
@@ -31,6 +31,9 @@
public class SpawnCommand {
public static void onCommand(final BukkitCommandActor actor, final World world, final Player player) {
- Utils.teleportToWorld(actor.getSender(), "spawn", "spawn", (player == null)? actor.getSender().getName() : player.getName(), world.getName());
+ if(actor.isConsole() && !Utils.checkWorld(actor.getSender(), "command.phantomworlds.subcommands.spawn.usage", world)) {
+ return;
+ }
+ Utils.teleportToWorld(actor.getSender(), "spawn", "spawn", (player == null)? actor.getSender().getName() : player.getName(), (actor.isPlayer() && world == null)? actor.getAsPlayer().getWorld().getName() : world.getName());
}
}
\ No newline at end of file
diff --git a/src/main/java/me/lokka30/phantomworlds/commands/phantomworlds/parameters/sub/TeleportCommand.java b/src/main/java/me/lokka30/phantomworlds/commands/phantomworlds/sub/TeleportCommand.java
similarity index 87%
rename from src/main/java/me/lokka30/phantomworlds/commands/phantomworlds/parameters/sub/TeleportCommand.java
rename to src/main/java/me/lokka30/phantomworlds/commands/phantomworlds/sub/TeleportCommand.java
index fe39be7..5485d01 100644
--- a/src/main/java/me/lokka30/phantomworlds/commands/phantomworlds/parameters/sub/TeleportCommand.java
+++ b/src/main/java/me/lokka30/phantomworlds/commands/phantomworlds/sub/TeleportCommand.java
@@ -1,4 +1,4 @@
-package me.lokka30.phantomworlds.commands.phantomworlds.parameters.sub;
+package me.lokka30.phantomworlds.commands.phantomworlds.sub;
/*
* Phantom Worlds
* Copyright (C) 2023 Daniel "creatorfromhell" Vidmar
@@ -31,6 +31,9 @@
public class TeleportCommand {
public static void onCommand(final BukkitCommandActor actor, final World world, final Player player) {
+ if(!Utils.checkWorld(actor.getSender(), "command.phantomworlds.subcommands.teleport.usage", world)) {
+ return;
+ }
Utils.teleportToWorld(actor.getSender(), "teleport", "teleport", (player == null)? actor.getSender().getName() : player.getName(), world.getName());
}
}
\ No newline at end of file
diff --git a/src/main/java/me/lokka30/phantomworlds/commands/phantomworlds/parameters/sub/UnloadCommand.java b/src/main/java/me/lokka30/phantomworlds/commands/phantomworlds/sub/UnloadCommand.java
similarity index 93%
rename from src/main/java/me/lokka30/phantomworlds/commands/phantomworlds/parameters/sub/UnloadCommand.java
rename to src/main/java/me/lokka30/phantomworlds/commands/phantomworlds/sub/UnloadCommand.java
index 1006fc2..67df729 100644
--- a/src/main/java/me/lokka30/phantomworlds/commands/phantomworlds/parameters/sub/UnloadCommand.java
+++ b/src/main/java/me/lokka30/phantomworlds/commands/phantomworlds/sub/UnloadCommand.java
@@ -1,4 +1,4 @@
-package me.lokka30.phantomworlds.commands.phantomworlds.parameters.sub;
+package me.lokka30.phantomworlds.commands.phantomworlds.sub;
/*
* Phantom Worlds
* Copyright (C) 2023 Daniel "creatorfromhell" Vidmar
@@ -20,7 +20,6 @@
import me.lokka30.microlib.messaging.MultiMessage;
import me.lokka30.phantomworlds.PhantomWorlds;
import me.lokka30.phantomworlds.misc.Utils;
-import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.entity.Player;
import revxrsal.commands.bukkit.BukkitCommandActor;
@@ -36,6 +35,9 @@
public class UnloadCommand {
public static void onCommand(final BukkitCommandActor actor, final World world) {
+ if(!Utils.checkWorld(actor.getSender(), "command.phantomworlds.subcommands.unload.usage", world)) {
+ return;
+ }
if(actor.getSender() instanceof Player) {
diff --git a/src/main/java/me/lokka30/phantomworlds/commands/phantomworlds/utils/WorldFolder.java b/src/main/java/me/lokka30/phantomworlds/commands/phantomworlds/utils/WorldFolder.java
new file mode 100644
index 0000000..6de0436
--- /dev/null
+++ b/src/main/java/me/lokka30/phantomworlds/commands/phantomworlds/utils/WorldFolder.java
@@ -0,0 +1,37 @@
+package me.lokka30.phantomworlds.commands.phantomworlds.utils;
+/*
+ * Phantom Worlds
+ * Copyright (C) 2023 Daniel "creatorfromhell" Vidmar
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ */
+
+/**
+ * WorldFolder
+ *
+ * @author creatorfromhell
+ * @since 2.0.5.0
+ */
+public class WorldFolder {
+
+ private final String folder;
+
+ public WorldFolder(String folder) {
+ this.folder = folder;
+ }
+
+ public String getFolder() {
+ return folder;
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/me/lokka30/phantomworlds/managers/WorldManager.java b/src/main/java/me/lokka30/phantomworlds/managers/WorldManager.java
index 201a514..89e453d 100644
--- a/src/main/java/me/lokka30/phantomworlds/managers/WorldManager.java
+++ b/src/main/java/me/lokka30/phantomworlds/managers/WorldManager.java
@@ -2,6 +2,7 @@
import me.lokka30.phantomworlds.PhantomWorlds;
import me.lokka30.phantomworlds.misc.Utils;
+import me.lokka30.phantomworlds.misc.WorldLoadResponse;
import me.lokka30.phantomworlds.world.PhantomWorld;
import org.bukkit.Bukkit;
import org.bukkit.Difficulty;
@@ -38,34 +39,21 @@ public void loadManagedWorlds() {
final HashSet worldsToDiscardFromDataFile = new HashSet<>();
+ //This should be outside our for each
+ if(!Bukkit.getWorldContainer().exists()) {
+ PhantomWorlds.logger().severe("World container doesn't exist!");
+ return;
+ }
+
//noinspection ConstantConditions
- for(final String worldName : PhantomWorlds.instance().data.getConfig().getConfigurationSection("worlds-to-load")
- .getKeys(false)) {
- if(Bukkit.getWorld(worldName) != null) {
- continue;
- }
+ for(final String worldName : PhantomWorlds.instance().data.getConfig().getConfigurationSection("worlds-to-load").getKeys(false)) {
- if(!Bukkit.getWorldContainer().exists()) {
- PhantomWorlds.logger().severe("World container doesn't exist for world " + worldName + "!");
- return;
- }
+ final WorldLoadResponse response = loadWorld(worldName);
- final File worldFolder = new File(Bukkit.getWorldContainer(), worldName);
- if(!worldFolder.exists()) {
- // The world was deleted/moved by the user so it must be re-imported. PW should no longer attempt to load that world.
- PhantomWorlds.logger().info("Discarding world '" + worldName + "' from PhantomWorlds' "
- + "data file as it no longer exists on the server.");
+ if(response.equals(WorldLoadResponse.INVALID)) {
worldsToDiscardFromDataFile.add(worldName);
- continue;
}
- if(PhantomWorlds.instance().data.getConfig().getBoolean("worlds-to-load." + worldName + ".skip-autoload", false)) {
- PhantomWorlds.logger().info("Skipping autoload of world '" + worldName + "'.");
- continue;
- }
-
- PhantomWorlds.logger().info("Loading world '" + worldName + "'...");
- getPhantomWorldFromData(worldName).create();
}
for(String worldName : worldsToDiscardFromDataFile) {
@@ -80,6 +68,36 @@ public void loadManagedWorlds() {
}
}
+ /**
+ * Used to load a world based on the name.
+ * @param worldName The name of the world.
+ * @return The {@link WorldLoadResponse response} from the loading process.
+ */
+ public WorldLoadResponse loadWorld(final String worldName) {
+
+ if(Bukkit.getWorld(worldName) != null) {
+ return WorldLoadResponse.NOT_FOUND;
+ }
+
+ final File worldFolder = new File(Bukkit.getWorldContainer(), worldName);
+ if(!worldFolder.exists()) {
+
+ // The world was deleted/moved by the user so it must be re-imported. PW should no longer attempt to load that world.
+ PhantomWorlds.logger().info("Discarding world '" + worldName + "' from PhantomWorlds' "
+ + "data file as it no longer exists on the server.");
+ return WorldLoadResponse.INVALID;
+ }
+
+ if(PhantomWorlds.instance().data.getConfig().getBoolean("worlds-to-load." + worldName + ".skip-autoload", false)) {
+ PhantomWorlds.logger().info("Skipping autoload of world '" + worldName + "'.");
+ return WorldLoadResponse.CONFIG_SKIPPED;
+ }
+
+ PhantomWorlds.logger().info("Loading world '" + worldName + "'...");
+ getPhantomWorldFromData(worldName).create();
+ return WorldLoadResponse.LOADED;
+ }
+
/**
* This creates a PhantomWorld object by scanning the data file by the specified name. Developers
* are expected to make sure the specified world exists prior to retrieving it.
diff --git a/src/main/java/me/lokka30/phantomworlds/misc/Utils.java b/src/main/java/me/lokka30/phantomworlds/misc/Utils.java
index 9166172..68f3ea4 100644
--- a/src/main/java/me/lokka30/phantomworlds/misc/Utils.java
+++ b/src/main/java/me/lokka30/phantomworlds/misc/Utils.java
@@ -200,12 +200,60 @@ public static Optional parseFromString(CommandSender sender, final Stri
}
public static void zipFolder(File sourceFolder, String destinationZipFile) throws IOException {
- try (
- FileOutputStream fos = new FileOutputStream(destinationZipFile);
- ZipOutputStream zos = new ZipOutputStream(fos)
- ) {
- zipFolder(sourceFolder, sourceFolder.getName(), zos);
+ try(FileOutputStream fos = new FileOutputStream(destinationZipFile);
+ ZipOutputStream zos = new ZipOutputStream(fos)) {
+
+ //zipFolder(sourceFolder, sourceFolder.getName(), zos);
+
+ zipFile(sourceFolder, sourceFolder.getName(), zos);
+ zos.closeEntry();
+ zos.flush();
+ zos.close();
+ fos.flush();
+ } catch(Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ public static void zipFile(File fileToZip, String fileName, ZipOutputStream zipOut) throws IOException {
+ if(fileToZip.isHidden()) {
+ return;
+ }
+
+ if(fileToZip.isDirectory()) {
+
+ if(fileName.endsWith("/")) {
+
+ zipOut.putNextEntry(new ZipEntry(fileName));
+ zipOut.closeEntry();
+ } else {
+
+ zipOut.putNextEntry(new ZipEntry(fileName + "/"));
+ zipOut.closeEntry();
+ }
+
+ File[] children = fileToZip.listFiles();
+ if(children == null) {
+ return;
+ }
+
+ for(File childFile : children) {
+ zipFile(childFile, fileName + "/" + childFile.getName(), zipOut);
+ }
+ return;
+ }
+
+ FileInputStream fis = new FileInputStream(fileToZip);
+ ZipEntry zipEntry = new ZipEntry(fileName);
+ zipOut.putNextEntry(zipEntry);
+
+ byte[] bytes = new byte[1024];
+ int length;
+
+ while((length = fis.read(bytes)) >= 0) {
+ zipOut.write(bytes, 0, length);
}
+ fis.close();
}
public static void zipFolder(final File folder, final String parentFolder, final ZipOutputStream zos) throws IOException {
@@ -334,4 +382,21 @@ public static Location parseSpawn(final World world) {
}
return world.getSpawnLocation();
}
+
+ public static boolean checkWorld(@NotNull final CommandSender sender, final String usage, @Nullable final World world) {
+ if(world == null) {
+
+ (new MultiMessage(
+ PhantomWorlds.instance().messages.getConfig()
+ .getStringList(usage), Arrays.asList(
+ new MultiMessage.Placeholder("prefix",
+ PhantomWorlds.instance().messages.getConfig().getString("common.prefix", "&b&lPhantomWorlds: &7"),
+ true),
+ new MultiMessage.Placeholder("label", "pw", false)
+ ))).send(sender);
+
+ return false;
+ }
+ return true;
+ }
}
\ No newline at end of file
diff --git a/src/main/java/me/lokka30/phantomworlds/misc/WorldLoadResponse.java b/src/main/java/me/lokka30/phantomworlds/misc/WorldLoadResponse.java
new file mode 100644
index 0000000..948a524
--- /dev/null
+++ b/src/main/java/me/lokka30/phantomworlds/misc/WorldLoadResponse.java
@@ -0,0 +1,32 @@
+package me.lokka30.phantomworlds.misc;
+/*
+ * Phantom Worlds
+ * Copyright (C) 2023 Daniel "creatorfromhell" Vidmar
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ */
+
+/**
+ * WorldLoadResponse
+ *
+ * @author creatorfromhell
+ * @since 2.0.5.0
+ */
+public enum WorldLoadResponse {
+ LOADED,
+ NOT_FOUND,
+ ALREADY_LOADED,
+ INVALID,
+ CONFIG_SKIPPED
+}
\ No newline at end of file
diff --git a/src/main/resources/messages.yml b/src/main/resources/messages.yml
index 0022c6d..f0dc800 100644
--- a/src/main/resources/messages.yml
+++ b/src/main/resources/messages.yml
@@ -18,19 +18,36 @@ command:
usage:
- '%prefix% Available commands:'
- - '&8 &m->&b /%label% create &8- &7create/import a world'
+ - '&8 &m->&b /%label% create &8- &7create a world'
+ - '&8 &m->&b /%label% import &8- &7import a world'
- '&8 &m->&b /%label% list &8- &7list loaded worlds'
- '&8 &m->&b /%label% teleport &8- &7teleport to a loaded world''s spawnpoint'
- - '&8 &m->&b /%label% spawn &8- &7teleport to the spawn of the current world'
+ - '&8 &m->&b /%label% spawn [player] &8- &7teleport to the spawn of the current world'
- '&8 &m->&b /%label% setspawn &8- &7set the spawnpoint of a world'
- - '&8 &m->&b /%label% gamerule &8- &7set the gamerules of a world'
- '&8 &m->&b /%label% delete &8- &7delete a world'
- '&8 &m->&b /%label% backup &8- &backup a world'
- '&8 &m->&b /%label% unload &8- &7unload a loaded world'
+ - '&8 &m->&b /%label% load &8- &7load an unloaded world'
- '&8 &m->&b /%label% reload &8- &7reload all config & data files'
- '&8 &m->&b /%label% info &8- &7view info about the plugin'
- '&8 &m->&b /%label% compatibility &8- &7check for incompatibilities'
+ usages:
+
+ create: '&b/pw create [options...] &8- &7create a world'
+ import: '&b/pw import &8- &7import a world'
+ list: '&b/pw list &8- &7list worlds'
+ tp: '&b/pw teleport [player] &8- &7teleport to a loaded world''s spawnpoint'
+ spawn: '&b/pw spawn &8- &7teleport to the spawn of the current world'
+ setspawn: '&b/pw setspawn [x] [y] [z] [world] [yaw] [pitch] &8- &7set the spawnpoint of a world'
+ delete: '&b/pw delete &8- &7delete a world'
+ backup: '&b/pw backup &8- &backup a world'
+ unload: '&b/pw unload &8- &7unload a loaded world'
+ load: '&b/pw load &8- &7load an unloaded world'
+ reload: '&b/pw reload &8- &7reload all config & data files'
+ info: '&b/pw info &8- &7view info about the plugin'
+ compatibility: '&b/pw compatibility &8- &7check for incompatibilities'
+
invalid-subcommand:
- '%prefix% Invalid subcommand ''&b%arg%&7''.'
@@ -130,6 +147,20 @@ command:
failure:
- '%prefix% Issue while deleting the world ''&b%world%&7''.'
+ import:
+
+ usage:
+ - '%prefix% Invalid usage, try ''&b/%label% import &7''.'
+
+ success:
+ - '%prefix% You have imported the world ''&b%world%&7''.'
+
+ failure-exist:
+ - '%prefix% Issue while importing the world. The world does not exist!'
+
+ failure-already:
+ - '%prefix% Issue while importing the world ''&b%world%&7''. The world is already managed by PhantomWorlds!'
+
info:
success:
@@ -142,6 +173,20 @@ command:
usage:
- '%prefix% Invalid usage, try ''&b/%label% info&7''.'
+ load:
+
+ usage:
+ - '%prefix% Invalid usage, try ''&b/%label% load &7''.'
+
+ success:
+ - '%prefix% You have loaded the world ''&b%world%&7''.'
+
+ failure-folder:
+ - '%prefix% Issue while loading the world. The world folder does not exist!'
+
+ failure-loading:
+ - '%prefix% Unknown issue while loading the world.'
+
list:
usage:
@@ -151,10 +196,10 @@ command:
- '%prefix% Worlds loaded &8(&b%amount%&8)&7:'
header-unloaded:
- - '%prefix% Worlds loaded &8(&b%amount%&8)&7:'
+ - '%prefix% Worlds unloaded &8(&b%amount%&8)&7:'
header-archived:
- - '%prefix% Worlds loaded &8(&b%amount%&8)&7:'
+ - '%prefix% Worlds archived &8(&b%amount%&8)&7:'
entry:
- '&8 &m->&b %world%'
diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml
index b4c93d0..6f75121 100644
--- a/src/main/resources/plugin.yml
+++ b/src/main/resources/plugin.yml
@@ -12,7 +12,7 @@ website: 'https://github.com/lokka30/PhantomWorlds'
main: 'me.lokka30.phantomworlds.PhantomWorlds'
api-version: '1.13'
-load: STARTUP
+load: POSTWORLD
commands:
phantomworlds: