Skip to content

Commit

Permalink
10/13 commands ported to new system.
Browse files Browse the repository at this point in the history
  • Loading branch information
creatorfromhell committed Nov 23, 2023
1 parent dd00781 commit ccca780
Show file tree
Hide file tree
Showing 21 changed files with 688 additions and 775 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,21 @@
* 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.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.SpawnCommand;
import me.lokka30.phantomworlds.commands.phantomworlds.parameters.sub.TeleportCommand;
import me.lokka30.phantomworlds.commands.phantomworlds.parameters.sub.UnloadCommand;
import org.bukkit.World;
import org.bukkit.entity.Player;
import revxrsal.commands.annotation.Command;
import revxrsal.commands.annotation.DefaultFor;
import revxrsal.commands.annotation.Optional;
import revxrsal.commands.annotation.Subcommand;
import revxrsal.commands.bukkit.BukkitCommandActor;
import revxrsal.commands.bukkit.annotation.CommandPermission;
Expand All @@ -35,67 +48,79 @@ public class PWCommand {
@Subcommand({"create", "+", "new"})
@CommandPermission("phantomworlds.command.phantomworlds.create")
public void create(BukkitCommandActor actor) {
//todo: port create command
}

@Subcommand({"compatibility"})
@CommandPermission("phantomworlds.command.phantomworlds.compatibility")
public void compatibility(BukkitCommandActor actor) {
CompatibilityCommand.onCommand(actor);
}

@Subcommand({"delete", "-", "remove", "del"})
@CommandPermission("phantomworlds.command.phantomworlds.delete")
public void delete(BukkitCommandActor actor) {

public void delete(BukkitCommandActor actor, final World world) {
DeleteCommand.onCommand(actor, world);
}

@Subcommand({"backup", "archive", "bu"})
@CommandPermission("phantomworlds.command.phantomworlds.backup")
public void backup(BukkitCommandActor actor) {

public void backup(BukkitCommandActor actor, final World world) {
BackupCommand.onCommand(actor, world);
}

@Subcommand({"create", "+", "new"})
@DefaultFor({"pw", "phantomworlds"})
@CommandPermission("phantomworlds.command.phantomworlds.list")
public void list(BukkitCommandActor actor) {

ListCommand.onCommand(actor);
}

@Subcommand({"debug"})
@CommandPermission("phantomworlds.command.phantomworlds.debug")
public void debug(BukkitCommandActor actor) {

public void debug(BukkitCommandActor actor, final String level) {
DebugCommand.onCommand(actor, level);
}

@Subcommand({"gamerule", "rule"})
@CommandPermission("phantomworlds.command.phantomworlds.gamerule")
public void gamerule(BukkitCommandActor actor) {

//todo: port gamerule command
}

@Subcommand({"info", "i"})
@CommandPermission("phantomworlds.command.phantomworlds.info")
public void info(BukkitCommandActor actor) {

InfoCommand.onCommand(actor);
}

@Subcommand({"reload", "r"})
@CommandPermission("phantomworlds.command.phantomworlds.reload")
public void reload(BukkitCommandActor actor) {

ReloadCommand.onCommand(actor);
}

@Subcommand({"setspawn"})
@CommandPermission("phantomworlds.command.phantomworlds.setspawn")
public void setspawn(BukkitCommandActor actor) {

//todo: port setspawn command
}

@Subcommand({"teleport", "tp"})
@CommandPermission("phantomworlds.command.phantomworlds.teleport")
public void tp(BukkitCommandActor actor) {
public void tp(BukkitCommandActor actor, final World world, @Optional final Player player) {
TeleportCommand.onCommand(actor, world, player);
}

@Subcommand({"spawn"})
@CommandPermission("phantomworlds.command.phantomworlds.spawn")
public void spawn(BukkitCommandActor actor, final World world, @Optional final Player player) {
SpawnCommand.onCommand(actor, world, player);
}

@Subcommand({"unload", "u"})
@CommandPermission("phantomworlds.command.phantomworlds.unload")
public void unload(BukkitCommandActor actor) {

public void unload(BukkitCommandActor actor, final World world) {
UnloadCommand.onCommand(actor, world);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,9 @@

import me.lokka30.microlib.messaging.MultiMessage;
import me.lokka30.phantomworlds.PhantomWorlds;
import me.lokka30.phantomworlds.commands.phantomworlds.subcommands.CompatibilitySubcommand;
import me.lokka30.phantomworlds.commands.phantomworlds.subcommands.CreateSubcommand;
import me.lokka30.phantomworlds.commands.phantomworlds.subcommands.DebugSubcommand;
import me.lokka30.phantomworlds.commands.phantomworlds.subcommands.GameruleSubcommand;
import me.lokka30.phantomworlds.commands.phantomworlds.subcommands.InfoSubcommand;
import me.lokka30.phantomworlds.commands.phantomworlds.subcommands.ListSubcommand;
import me.lokka30.phantomworlds.commands.phantomworlds.subcommands.ReloadSubcommand;
import me.lokka30.phantomworlds.commands.phantomworlds.subcommands.SetSpawnSubcommand;
import me.lokka30.phantomworlds.commands.phantomworlds.subcommands.TeleportSubcommand;
import me.lokka30.phantomworlds.commands.phantomworlds.subcommands.UnloadSubcommand;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;
Expand All @@ -32,14 +25,7 @@ public class PhantomWorldsCommand implements TabExecutor {

final CreateSubcommand createSubcommand = new CreateSubcommand();
final GameruleSubcommand gameruleSubcommand = new GameruleSubcommand();
final UnloadSubcommand unloadSubcommand = new UnloadSubcommand();
final TeleportSubcommand teleportSubcommand = new TeleportSubcommand();
final ListSubcommand listSubcommand = new ListSubcommand();
final SetSpawnSubcommand setSpawnSubcommand = new SetSpawnSubcommand();
final ReloadSubcommand reloadSubcommand = new ReloadSubcommand();
final InfoSubcommand infoSubcommand = new InfoSubcommand();
final DebugSubcommand debugSubcommand = new DebugSubcommand();
final CompatibilitySubcommand compatibilitySubcommand = new CompatibilitySubcommand();

/**
* @since v2.0.0
Expand Down Expand Up @@ -67,32 +53,9 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd,
case "gamerule":
gameruleSubcommand.parseCommand(sender, cmd, label, args);
break;
case "unload":
unloadSubcommand.parseCommand(sender, cmd, label, args);
break;
case "teleport":
case "tp":
case "spawn":
teleportSubcommand.parseCommand(sender, cmd, label, args);
break;
case "list":
listSubcommand.parseCommand(sender, cmd, label, args);
break;
case "setspawn":
setSpawnSubcommand.parseCommand(sender, cmd, label, args);
break;
case "reload":
reloadSubcommand.parseCommand(sender, cmd, label, args);
break;
case "info":
infoSubcommand.parseCommand(sender, cmd, label, args);
break;
case "debug":
debugSubcommand.parseCommand(sender, cmd, label, args);
break;
case "compatibility":
compatibilitySubcommand.parseCommand(sender, cmd, label, args);
break;
default:
(new MultiMessage(
PhantomWorlds.instance().messages.getConfig()
Expand Down Expand Up @@ -146,24 +109,8 @@ public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Comman
return createSubcommand.parseTabCompletion(sender, cmd, label, args);
case "gamerule":
return gameruleSubcommand.parseTabCompletion(sender, cmd, label, args);
case "info":
return infoSubcommand.parseTabCompletion(sender, cmd, label, args);
case "list":
return listSubcommand.parseTabCompletion(sender, cmd, label, args);
case "setspawn":
return setSpawnSubcommand.parseTabCompletion(sender, cmd, label, args);
case "reload":
return reloadSubcommand.parseTabCompletion(sender, cmd, label, args);
case "teleport":
case "tp":
case "spawn":
return teleportSubcommand.parseTabCompletion(sender, cmd, label, args);
case "unload":
return unloadSubcommand.parseTabCompletion(sender, cmd, label, args);
case "debug":
return debugSubcommand.parseTabCompletion(sender, cmd, label, args);
case "compatibility":
return compatibilitySubcommand.parseTabCompletion(sender, cmd, label, args);
default:
return Collections.emptyList();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
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 <http://www.gnu.org/licenses/>.
*/

import me.lokka30.microlib.messaging.MultiMessage;
import me.lokka30.phantomworlds.PhantomWorlds;
import org.bukkit.World;
import revxrsal.commands.bukkit.BukkitCommandActor;

import java.util.Arrays;

/**
* BackupCommand
*
* @author creatorfromhell
* @since 2.0.5.0
*/
public class BackupCommand {

public static void onCommand(final BukkitCommandActor actor, final World world) {

if(!PhantomWorlds.worldManager().backupWorld(world.getName())) {
(new MultiMessage(
PhantomWorlds.instance().messages.getConfig()
.getStringList("command.phantomworlds.subcommands.backup.failure"), 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());
}

(new MultiMessage(
PhantomWorlds.instance().messages.getConfig()
.getStringList("command.phantomworlds.subcommands.backup.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());
}
}
Original file line number Diff line number Diff line change
@@ -1,59 +1,47 @@
package me.lokka30.phantomworlds.commands.phantomworlds.subcommands;
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 <http://www.gnu.org/licenses/>.
*/

import me.lokka30.microlib.messaging.MultiMessage;
import me.lokka30.phantomworlds.PhantomWorlds;
import me.lokka30.phantomworlds.commands.Subcommand;
import me.lokka30.phantomworlds.misc.CompatibilityChecker;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import revxrsal.commands.bukkit.BukkitCommandActor;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
* @author lokka30
* @since v2.0.0
* CompatibilityCommand
*
* @author creatorfromhell
* @since 2.0.5.0
*/
public class CompatibilitySubcommand implements Subcommand {

/**
* @since v2.0.0
*/
@Override
public void parseCommand(CommandSender sender, Command cmd, String label, String[] args) {
if(!sender.hasPermission("phantomworlds.command.phantomworlds.compatibility")) {
(new MultiMessage(
PhantomWorlds.instance().messages.getConfig().getStringList("common.no-permission"), Arrays.asList(
new MultiMessage.Placeholder("prefix",
PhantomWorlds.instance().messages.getConfig().getString("common.prefix", "&b&lPhantomWorlds: &7"),
true),
new MultiMessage.Placeholder("permission",
"phantomworlds.command.phantomworlds.compatibility", false)
))).send(sender);
return;
}

if(args.length != 1) {
(new MultiMessage(
PhantomWorlds.instance().messages.getConfig()
.getStringList("command.phantomworlds.subcommands.compatibility.usage"),
Arrays.asList(
new MultiMessage.Placeholder("prefix", PhantomWorlds.instance().messages.getConfig()
.getString("common.prefix", "&b&lPhantomWorlds: &7"), true),
new MultiMessage.Placeholder("label", label, false)
))).send(sender);
return;
}
public class CompatibilityCommand {

public static void onCommand(final BukkitCommandActor actor) {
(new MultiMessage(
PhantomWorlds.instance().messages.getConfig()
.getStringList("command.phantomworlds.subcommands.compatibility.start"),
Collections.singletonList(
new MultiMessage.Placeholder("prefix",
PhantomWorlds.instance().messages.getConfig().getString("common.prefix", "&b&lPhantomWorlds: &7"),
true)
))).send(sender);
))).send(actor.getSender());

PhantomWorlds.instance().compatibilityChecker.checkAll();

Expand All @@ -64,7 +52,7 @@ public void parseCommand(CommandSender sender, Command cmd, String label, String
Collections.singletonList(
new MultiMessage.Placeholder("prefix", PhantomWorlds.instance().messages.getConfig()
.getString("common.prefix", "&b&lPhantomWorlds: &7"), true)
))).send(sender);
))).send(actor.getSender());
return;
}

Expand All @@ -77,7 +65,7 @@ public void parseCommand(CommandSender sender, Command cmd, String label, String
true),
new MultiMessage.Placeholder("amount",
String.valueOf(PhantomWorlds.instance().compatibilityChecker.incompatibilities.size()), false)
))).send(sender);
))).send(actor.getSender());

for(int i = 0; i < PhantomWorlds.instance().compatibilityChecker.incompatibilities.size(); i++) {
CompatibilityChecker.Incompatibility incompatibility = PhantomWorlds.instance().compatibilityChecker.incompatibilities.get(
Expand All @@ -94,15 +82,7 @@ public void parseCommand(CommandSender sender, Command cmd, String label, String
new MultiMessage.Placeholder("reason", incompatibility.reason, true),
new MultiMessage.Placeholder("recommendation", incompatibility.recommendation,
true)
))).send(sender);
))).send(actor.getSender());
}
}

/**
* @since v2.0.0
*/
@Override
public List<String> parseTabCompletion(CommandSender sender, Command cmd, String label, String[] args) {
return Collections.emptyList();
}
}
Loading

0 comments on commit ccca780

Please sign in to comment.