mirror of
https://github.com/Multiverse/Multiverse-Core.git
synced 2024-11-22 10:36:06 +01:00
Clean up.
This commit is contained in:
parent
7493ce5dd8
commit
a77ad6d7ab
@ -34,6 +34,7 @@ import com.onarandombox.MultiverseCore.api.MultiverseMessaging;
|
||||
import com.onarandombox.MultiverseCore.api.SafeTTeleporter;
|
||||
import com.onarandombox.MultiverseCore.commands_acf.CoordCommand;
|
||||
import com.onarandombox.MultiverseCore.commands_acf.CreateCommand;
|
||||
import com.onarandombox.MultiverseCore.commands_acf.GamerulesCommand;
|
||||
import com.onarandombox.MultiverseCore.commands_acf.ListCommand;
|
||||
import com.onarandombox.MultiverseCore.commands_acf.ReloadCommand;
|
||||
import com.onarandombox.MultiverseCore.commands_acf.RemoveCommand;
|
||||
@ -744,6 +745,7 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
|
||||
this.commandHandler.registerCommand(new RemoveCommand(this));
|
||||
this.commandHandler.registerCommand(new ListCommand(this));
|
||||
this.commandHandler.registerCommand(new ScriptCommand(this));
|
||||
this.commandHandler.registerCommand(new GamerulesCommand(this));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -12,6 +12,8 @@ import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@CommandAlias("mv")
|
||||
@ -26,20 +28,18 @@ public class ConfigCommand extends MultiverseCommand {
|
||||
@Subcommand("show")
|
||||
@Description("Show multiverse config values.")
|
||||
public void onShowCommand(@NotNull CommandSender sender) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
List<String> configList = new ArrayList<>();
|
||||
Map<String, Object> serializedConfig = this.plugin.getMVConfig().serialize();
|
||||
|
||||
for (Map.Entry<String, Object> entry : serializedConfig.entrySet()) {
|
||||
builder.append(ChatColor.GREEN)
|
||||
.append(entry.getKey())
|
||||
.append(ChatColor.WHITE).append(" = ").append(ChatColor.GOLD)
|
||||
.append(entry.getValue().toString())
|
||||
.append(ChatColor.WHITE).append(", ");
|
||||
|
||||
configList.add(ChatColor.GREEN + entry.getKey()
|
||||
+ ChatColor.WHITE + " = "
|
||||
+ ChatColor.GOLD + entry.getValue().toString()
|
||||
+ ChatColor.WHITE);
|
||||
}
|
||||
|
||||
String message = builder.toString();
|
||||
message = message.substring(0, message.length() - 2);
|
||||
sender.sendMessage(message);
|
||||
sender.sendMessage(String.join(", ", configList));
|
||||
}
|
||||
|
||||
@Subcommand("set")
|
||||
@ -58,7 +58,7 @@ public class ConfigCommand extends MultiverseCommand {
|
||||
}
|
||||
|
||||
if (!this.plugin.saveMVConfigs()) {
|
||||
sender.sendMessage(ChatColor.RED + "FAIL!" + ChatColor.WHITE + " Check your console for details!");
|
||||
sender.sendMessage(ChatColor.RED + "Failed to save config! Check your console for details.");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -68,6 +68,7 @@ public class ConfigCommand extends MultiverseCommand {
|
||||
this.plugin.getMVWorldManager().setFirstSpawnWorld(value);
|
||||
}
|
||||
|
||||
//TODO: Show properties and values that where updated.
|
||||
sender.sendMessage(ChatColor.GREEN + "SUCCESS!" + ChatColor.WHITE + " Values were updated successfully!");
|
||||
this.plugin.loadConfigs();
|
||||
}
|
||||
|
@ -48,6 +48,7 @@ public class DebugCommand extends MultiverseCommand {
|
||||
displayDebugMode(sender);
|
||||
}
|
||||
|
||||
//TODO: See if can move this to CommandContext Integer.class
|
||||
private int parseDebugLevel(@NotNull String debugLevel) {
|
||||
if (debugLevel.equalsIgnoreCase("off")) {
|
||||
return 0;
|
||||
|
@ -3,8 +3,10 @@ package com.onarandombox.MultiverseCore.commands_acf;
|
||||
import co.aikar.commands.annotation.CommandAlias;
|
||||
import co.aikar.commands.annotation.CommandCompletion;
|
||||
import co.aikar.commands.annotation.CommandPermission;
|
||||
import co.aikar.commands.annotation.Conditions;
|
||||
import co.aikar.commands.annotation.Description;
|
||||
import co.aikar.commands.annotation.Flags;
|
||||
import co.aikar.commands.annotation.Single;
|
||||
import co.aikar.commands.annotation.Subcommand;
|
||||
import co.aikar.commands.annotation.Syntax;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
@ -23,22 +25,22 @@ public class DeleteCommand extends MultiverseCommand {
|
||||
@Subcommand("delete")
|
||||
@CommandPermission("multiverse.core.delete")
|
||||
@Syntax("<world>")
|
||||
@CommandCompletion("@MVWorlds")
|
||||
@CommandCompletion("@MVWorlds|@unloadedWorlds")
|
||||
@Description("")
|
||||
public void onDeleteCommand(@NotNull CommandSender sender,
|
||||
@NotNull @Flags("other") MultiverseWorld world) {
|
||||
@NotNull @Single @Conditions("isWorldInConfig") String worldName) {
|
||||
|
||||
this.plugin.getCommandQueueManager().addToQueue(sender, deleteRunnable(sender, world));
|
||||
this.plugin.getCommandQueueManager().addToQueue(sender, deleteRunnable(sender, worldName));
|
||||
}
|
||||
|
||||
private Runnable deleteRunnable(@NotNull CommandSender sender,
|
||||
@NotNull MultiverseWorld world) {
|
||||
@NotNull String worldName) {
|
||||
|
||||
return () -> {
|
||||
//TODO: deleteWorld method should take world object directly
|
||||
String resultMessage = (this.plugin.getMVWorldManager().deleteWorld(world.getName()))
|
||||
? ChatColor.GREEN + "World '" + world.getName() + "' Deleted!"
|
||||
: ChatColor.RED + "World '" + world.getName() + "' could NOT be deleted!";
|
||||
String resultMessage = (this.plugin.getMVWorldManager().deleteWorld(worldName))
|
||||
? ChatColor.GREEN + "World '" + worldName + "' Deleted!"
|
||||
: ChatColor.RED + "World '" + worldName + "' could NOT be deleted!";
|
||||
|
||||
sender.sendMessage(resultMessage);
|
||||
};
|
||||
|
@ -10,7 +10,6 @@ import co.aikar.commands.annotation.Subcommand;
|
||||
import co.aikar.commands.annotation.Syntax;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
||||
import com.onarandombox.MultiverseCore.commands_helper.WorldAndPage;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
|
@ -25,6 +25,7 @@ public class ListCommand extends MultiverseCommand {
|
||||
public void onListCommand(@NotNull CommandSender sender,
|
||||
@Default("1") int page) {
|
||||
|
||||
//TODO: Do the actual fancy list display
|
||||
sender.sendMessage(this.plugin.getMVWorldManager().getMVWorlds().toString());
|
||||
sender.sendMessage("Page of: " + page);
|
||||
}
|
||||
|
@ -3,7 +3,9 @@ package com.onarandombox.MultiverseCore.commands_acf;
|
||||
import co.aikar.commands.annotation.CommandAlias;
|
||||
import co.aikar.commands.annotation.CommandCompletion;
|
||||
import co.aikar.commands.annotation.CommandPermission;
|
||||
import co.aikar.commands.annotation.Conditions;
|
||||
import co.aikar.commands.annotation.Description;
|
||||
import co.aikar.commands.annotation.Flags;
|
||||
import co.aikar.commands.annotation.Single;
|
||||
import co.aikar.commands.annotation.Subcommand;
|
||||
import co.aikar.commands.annotation.Syntax;
|
||||
@ -26,12 +28,12 @@ public class LoadCommand extends MultiverseCommand {
|
||||
@CommandCompletion("@unloadedWorlds")
|
||||
@Description("Loads a world into Multiverse.")
|
||||
public void onLoadCommand(@NotNull CommandSender sender,
|
||||
@NotNull @Single String world) {
|
||||
@NotNull @Single @Conditions("isUnloadedWorld") String worldName) {
|
||||
|
||||
if (!this.plugin.getMVWorldManager().loadWorld(world)) {
|
||||
sender.sendMessage("Error trying to load world '" + world + "'!");
|
||||
if (!this.plugin.getMVWorldManager().loadWorld(worldName)) {
|
||||
sender.sendMessage("Error trying to load world '" + worldName + "'!");
|
||||
return;
|
||||
}
|
||||
Command.broadcastCommandMessage(sender, "Loaded world '" + world + "'!");
|
||||
Command.broadcastCommandMessage(sender, "Loaded world '" + worldName + "'!");
|
||||
}
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ public class ReloadCommand extends MultiverseCommand {
|
||||
this.plugin.getAnchorManager().loadAnchors();
|
||||
this.plugin.getMVWorldManager().loadWorlds(true);
|
||||
|
||||
List<String> configsLoaded = new ArrayList<String>();
|
||||
List<String> configsLoaded = new ArrayList<>();
|
||||
configsLoaded.add("Multiverse-Core - config.yml");
|
||||
configsLoaded.add("Multiverse-Core - worlds.yml");
|
||||
configsLoaded.add("Multiverse-Core - anchors.yml");
|
||||
@ -37,10 +37,7 @@ public class ReloadCommand extends MultiverseCommand {
|
||||
MVConfigReloadEvent configReload = new MVConfigReloadEvent(configsLoaded);
|
||||
this.plugin.getServer().getPluginManager().callEvent(configReload);
|
||||
|
||||
for (String s : configReload.getAllConfigsLoaded()) {
|
||||
sender.sendMessage(s);
|
||||
}
|
||||
|
||||
configReload.getAllConfigsLoaded().forEach(sender::sendMessage);
|
||||
sender.sendMessage(ChatColor.GREEN + "Reload Complete!");
|
||||
}
|
||||
}
|
||||
|
@ -3,12 +3,12 @@ package com.onarandombox.MultiverseCore.commands_acf;
|
||||
import co.aikar.commands.annotation.CommandAlias;
|
||||
import co.aikar.commands.annotation.CommandCompletion;
|
||||
import co.aikar.commands.annotation.CommandPermission;
|
||||
import co.aikar.commands.annotation.Conditions;
|
||||
import co.aikar.commands.annotation.Description;
|
||||
import co.aikar.commands.annotation.Flags;
|
||||
import co.aikar.commands.annotation.Single;
|
||||
import co.aikar.commands.annotation.Subcommand;
|
||||
import co.aikar.commands.annotation.Syntax;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@ -25,12 +25,10 @@ public class RemoveCommand extends MultiverseCommand {
|
||||
@Syntax("<world>")
|
||||
@Description("Unloads a world from Multiverse and removes it from worlds.yml, this does NOT DELETE the world folder.")
|
||||
public void onRemoveCommand(@NotNull CommandSender sender,
|
||||
@NotNull @Flags("other") MultiverseWorld world) {
|
||||
@NotNull @Single @Conditions("isWorldInConfig") String worldName) {
|
||||
|
||||
String resultMessage = (this.plugin.getMVWorldManager().removeWorldFromConfig(world.getName()))
|
||||
sender.sendMessage((this.plugin.getMVWorldManager().removeWorldFromConfig(worldName))
|
||||
? "World removed from config!"
|
||||
: "Error trying to remove world from config!";
|
||||
|
||||
sender.sendMessage(resultMessage);
|
||||
: "Error trying to remove world from config!");
|
||||
}
|
||||
}
|
||||
|
@ -45,7 +45,7 @@ public class SpawnCommand extends MultiverseCommand {
|
||||
spawnAccurately(player);
|
||||
|
||||
String senderName = (sender instanceof ConsoleCommandSender)
|
||||
? ChatColor.LIGHT_PURPLE + "the console"
|
||||
? ChatColor.LIGHT_PURPLE + "console"
|
||||
: ChatColor.YELLOW + sender.getName();
|
||||
|
||||
player.sendMessage("You were teleported by " + senderName);
|
||||
|
@ -34,9 +34,9 @@ public class CommandQueueManager {
|
||||
|
||||
cancelPreviousInQueue(sender);
|
||||
|
||||
QueuedCommand queuedCommand = new QueuedCommand(sender, runnable, validPeriod);
|
||||
QueuedCommand queuedCommand = new QueuedCommand(sender, runnable);
|
||||
queuedCommands.put(sender, queuedCommand);
|
||||
queuedCommand.setExpireTask(runExpireLater(queuedCommand));
|
||||
queuedCommand.setExpireTask(runExpireLater(queuedCommand, validPeriod));
|
||||
|
||||
sender.sendMessage("The command you are trying to run is deemed dangerous.");
|
||||
sender.sendMessage("Run /mv confirm to continue.");
|
||||
@ -47,15 +47,16 @@ public class CommandQueueManager {
|
||||
if (previousCommand == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
previousCommand.cancelExpiryTask();
|
||||
queuedCommands.remove(sender);
|
||||
}
|
||||
|
||||
private BukkitTask runExpireLater(@NotNull QueuedCommand queuedCommand) {
|
||||
private BukkitTask runExpireLater(@NotNull QueuedCommand queuedCommand, int validPeriod) {
|
||||
return Bukkit.getScheduler().runTaskLater(
|
||||
this.plugin,
|
||||
expireRunnable(queuedCommand),
|
||||
queuedCommand.getValidInterval()
|
||||
validPeriod
|
||||
);
|
||||
}
|
||||
|
||||
@ -66,8 +67,9 @@ public class CommandQueueManager {
|
||||
Logging.finer("This is an old command already.");
|
||||
return;
|
||||
}
|
||||
|
||||
Logging.finer("Command is expired, removing...");
|
||||
this.queuedCommands.remove(queuedCommand.getSender());
|
||||
Logging.finer("Command expired and is removed.");
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -66,9 +66,10 @@ public class CommandTools {
|
||||
this::suggestPotentialWorlds
|
||||
);
|
||||
|
||||
this.commandHandler.getCommandCompletions().registerStaticCompletion(
|
||||
//TODO: Change to static
|
||||
this.commandHandler.getCommandCompletions().registerAsyncCompletion(
|
||||
"MVConfigs",
|
||||
suggestMVConfig()
|
||||
this::suggestMVConfig
|
||||
);
|
||||
|
||||
this.commandHandler.getCommandCompletions().registerStaticCompletion(
|
||||
@ -139,7 +140,7 @@ public class CommandTools {
|
||||
|
||||
|
||||
@NotNull
|
||||
private Set<String> suggestMVConfig() {
|
||||
private Set<String> suggestMVConfig(@NotNull BukkitCommandCompletionContext context) {
|
||||
return this.plugin.getMVConfig().serialize().keySet();
|
||||
}
|
||||
|
||||
@ -509,6 +510,18 @@ public class CommandTools {
|
||||
this::checkIsMVWorld
|
||||
);
|
||||
|
||||
this.commandHandler.getCommandConditions().addCondition(
|
||||
String.class,
|
||||
"isUnloadedWorld",
|
||||
this::checkIsUnloadedWorld
|
||||
);
|
||||
|
||||
this.commandHandler.getCommandConditions().addCondition(
|
||||
String.class,
|
||||
"isWorldInConfig",
|
||||
this::checkIsWorldInConfig
|
||||
);
|
||||
|
||||
this.commandHandler.getCommandConditions().addCondition(
|
||||
String.class,
|
||||
"worldFolderExist",
|
||||
@ -522,12 +535,13 @@ public class CommandTools {
|
||||
);
|
||||
}
|
||||
|
||||
//TODO: Message seems a bit too targeted to create world only
|
||||
private void checkIsMVWorld(@NotNull ConditionContext<BukkitCommandIssuer> context,
|
||||
@NotNull BukkitCommandExecutionContext executionContext,
|
||||
@NotNull String worldName) {
|
||||
|
||||
boolean shouldBeMVWorld = Boolean.parseBoolean(context.getConfig());
|
||||
boolean isMVWorld = this.plugin.getMVWorldManager().isMVWorld(worldName);
|
||||
boolean isMVWorld = this.worldManager.isMVWorld(worldName);
|
||||
|
||||
if (isMVWorld && !shouldBeMVWorld) {
|
||||
executionContext.getSender().sendMessage(ChatColor.RED + "Multiverse cannot create " + ChatColor.GOLD + ChatColor.UNDERLINE
|
||||
@ -541,9 +555,32 @@ public class CommandTools {
|
||||
}
|
||||
}
|
||||
|
||||
private void checkWorldFolderExist(@NotNull ConditionContext<BukkitCommandIssuer> context,
|
||||
@NotNull BukkitCommandExecutionContext executionContext,
|
||||
@NotNull String worldFolder) {
|
||||
private void checkIsUnloadedWorld(@NotNull ConditionContext<BukkitCommandIssuer> context,
|
||||
@NotNull BukkitCommandExecutionContext executionContext,
|
||||
@NotNull String worldName) {
|
||||
|
||||
if (this.worldManager.isMVWorld(worldName)) {
|
||||
throw new ConditionFailedException("World '" + worldName + "' is already loaded.");
|
||||
}
|
||||
|
||||
if (!this.worldManager.getUnloadedWorlds().contains(worldName)) {
|
||||
throw new ConditionFailedException("World '" + worldName + "' not found.");
|
||||
}
|
||||
}
|
||||
|
||||
private void checkIsWorldInConfig(@NotNull ConditionContext<BukkitCommandIssuer> context,
|
||||
@NotNull BukkitCommandExecutionContext executionContext,
|
||||
@NotNull String worldName) {
|
||||
|
||||
//TODO: Should have direct API for it, instead of check both loaded and unloaded.
|
||||
if (!this.worldManager.isMVWorld(worldName) && !this.worldManager.getUnloadedWorlds().contains(worldName)) {
|
||||
throw new ConditionFailedException("World '" + worldName + "' not found.");
|
||||
}
|
||||
}
|
||||
|
||||
private void checkWorldFolderExist(@NotNull ConditionContext<BukkitCommandIssuer> context,
|
||||
@NotNull BukkitCommandExecutionContext executionContext,
|
||||
@NotNull String worldFolder) {
|
||||
|
||||
boolean shouldExist = Boolean.parseBoolean(context.getConfig());
|
||||
boolean worldFileExist = new File(this.plugin.getServer().getWorldContainer(), worldFolder).exists();
|
||||
@ -560,9 +597,9 @@ public class CommandTools {
|
||||
}
|
||||
}
|
||||
|
||||
private void checkValidWorldFolder (@NotNull ConditionContext<BukkitCommandIssuer> context,
|
||||
@NotNull BukkitCommandExecutionContext executionContext,
|
||||
@NotNull String worldName) {
|
||||
private void checkValidWorldFolder(@NotNull ConditionContext<BukkitCommandIssuer> context,
|
||||
@NotNull BukkitCommandExecutionContext executionContext,
|
||||
@NotNull String worldName) {
|
||||
|
||||
File worldFolder = new File(this.plugin.getServer().getWorldContainer(), worldName);
|
||||
if (!worldFolder.isDirectory()) {
|
||||
|
@ -6,13 +6,11 @@ import org.bukkit.scheduler.BukkitTask;
|
||||
public class QueuedCommand {
|
||||
private final CommandSender sender;
|
||||
private final Runnable runnable;
|
||||
private final int validInterval;
|
||||
private BukkitTask expireTask;
|
||||
|
||||
public QueuedCommand(CommandSender sender, Runnable runnable, int validPeriod) {
|
||||
public QueuedCommand(CommandSender sender, Runnable runnable) {
|
||||
this.sender = sender;
|
||||
this.runnable = runnable;
|
||||
this.validInterval = validPeriod;
|
||||
}
|
||||
|
||||
public void runCommand() {
|
||||
@ -31,8 +29,4 @@ public class QueuedCommand {
|
||||
public CommandSender getSender() {
|
||||
return sender;
|
||||
}
|
||||
|
||||
public int getValidInterval() {
|
||||
return validInterval;
|
||||
}
|
||||
}
|
||||
|
@ -1,21 +0,0 @@
|
||||
package com.onarandombox.MultiverseCore.commands_helper;
|
||||
|
||||
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
||||
|
||||
public class WorldAndPage {
|
||||
private final MultiverseWorld world;
|
||||
private final int page;
|
||||
|
||||
public WorldAndPage(MultiverseWorld world, int page) {
|
||||
this.world = world;
|
||||
this.page = page;
|
||||
}
|
||||
|
||||
public MultiverseWorld getWorld() {
|
||||
return world;
|
||||
}
|
||||
|
||||
public int getPage() {
|
||||
return page;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user