Skip to content

Commit

Permalink
Various Fixes, add unloaded/Archived to /pw list, add /pw load comman…
Browse files Browse the repository at this point in the history
…d, fix backup system.
  • Loading branch information
creatorfromhell committed Dec 3, 2023
1 parent 15ab2db commit 04e511f
Show file tree
Hide file tree
Showing 24 changed files with 708 additions and 149 deletions.
50 changes: 37 additions & 13 deletions src/main/java/me/lokka30/phantomworlds/PhantomWorlds.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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.
Expand All @@ -106,22 +111,15 @@ 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();
miscStartupProcedures();

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)");
Expand Down Expand Up @@ -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();
}
Expand All @@ -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);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,35 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

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
Expand All @@ -47,88 +56,111 @@
@Command({"pw", "phantomworlds"})
public class PWCommand {

@Subcommand({"help", "?"})
@DefaultFor({"pw", "phantomworlds"})
public void help(BukkitCommandActor actor, CommandHelp<String> 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);
}
}
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*/

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<WorldFolder> {

@Override
public WorldFolder resolve(@NotNull ValueResolverContext context) throws Throwable {
final String value = context.arguments().pop();

return new WorldFolder(value);
}
}

This file was deleted.

Loading

0 comments on commit 04e511f

Please sign in to comment.