Add gamerules, list and script.

This commit is contained in:
benwoo1110 2020-12-17 13:46:23 +08:00
parent d494017186
commit c8d1aa467d
4 changed files with 136 additions and 0 deletions

View File

@ -34,8 +34,10 @@ 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.ListCommand;
import com.onarandombox.MultiverseCore.commands_acf.ReloadCommand;
import com.onarandombox.MultiverseCore.commands_acf.RemoveCommand;
import com.onarandombox.MultiverseCore.commands_acf.ScriptCommand;
import com.onarandombox.MultiverseCore.commands_acf.SpawnCommand;
import com.onarandombox.MultiverseCore.commands_acf.UsageCommand;
import com.onarandombox.MultiverseCore.commands_helper.CommandTools;
@ -740,6 +742,8 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
this.commandHandler.registerCommand(new SpawnCommand(this));
this.commandHandler.registerCommand(new ReloadCommand(this));
this.commandHandler.registerCommand(new RemoveCommand(this));
this.commandHandler.registerCommand(new ListCommand(this));
this.commandHandler.registerCommand(new ScriptCommand(this));
}
/**

View File

@ -0,0 +1,51 @@
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.Description;
import co.aikar.commands.annotation.Flags;
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.ChatColor;
import org.bukkit.GameRule;
import org.bukkit.World;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;
@CommandAlias("mv")
public class GamerulesCommand extends MultiverseCommand {
public GamerulesCommand(MultiverseCore plugin) {
super(plugin);
}
@Subcommand("info")
@CommandPermission("multiverse.core.gamerule.list")
@Syntax("[world]")
@CommandCompletion("@MVWorlds")
@Description("See the list gamerules values for a given world.")
public void onGamerulesCommand(@NotNull CommandSender sender,
@NotNull @Flags("other|defaultself") MultiverseWorld world) {
World CBWorld = world.getCBWorld();
StringBuilder gameRules = new StringBuilder();
for (String gameRule : CBWorld.getGameRules()) {
if (gameRules.length() != 0) {
gameRules.append(ChatColor.WHITE).append(", ");
}
gameRules.append(ChatColor.AQUA)
.append(gameRule)
.append(ChatColor.WHITE)
.append(": ")
.append(ChatColor.GREEN)
.append(CBWorld.getGameRuleValue(GameRule.getByName(gameRule)));
}
sender.sendMessage("=== Gamerules for " + ChatColor.AQUA + world.getName() + ChatColor.WHITE + " ===");
sender.sendMessage(gameRules.toString());
}
}

View File

@ -0,0 +1,31 @@
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.Default;
import co.aikar.commands.annotation.Description;
import co.aikar.commands.annotation.Subcommand;
import co.aikar.commands.annotation.Syntax;
import com.onarandombox.MultiverseCore.MultiverseCore;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;
@CommandAlias("mv")
public class ListCommand extends MultiverseCommand {
public ListCommand(MultiverseCore plugin) {
super(plugin);
}
@Subcommand("list")
@CommandPermission("multiverse.core.list.worlds")
@Syntax("[page]")
@Description("Displays a listing of all worlds that you can enter.")
public void onListCommand(@NotNull CommandSender sender,
@Default("1") int page) {
sender.sendMessage(this.plugin.getMVWorldManager().getMVWorlds().toString());
sender.sendMessage("Page of: " + page);
}
}

View File

@ -0,0 +1,50 @@
package com.onarandombox.MultiverseCore.commands_acf;
import buscript.Buscript;
import co.aikar.commands.annotation.CommandAlias;
import co.aikar.commands.annotation.CommandCompletion;
import co.aikar.commands.annotation.CommandPermission;
import co.aikar.commands.annotation.Description;
import co.aikar.commands.annotation.Flags;
import co.aikar.commands.annotation.Subcommand;
import co.aikar.commands.annotation.Syntax;
import com.onarandombox.MultiverseCore.MultiverseCore;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.io.File;
@CommandAlias("mv")
public class ScriptCommand extends MultiverseCommand {
public ScriptCommand(MultiverseCore plugin) {
super(plugin);
}
@Subcommand("script")
@CommandPermission("multiverse.core.script")
@CommandCompletion(" @players")
@Syntax("<script> [player]")
@Description("Runs a script.")
public void onScriptCommand(@NotNull CommandSender sender,
@NotNull String targetScript,
@NotNull @Flags("other|defaultself") Player player) {
Buscript scriptAPI = this.plugin.getScriptAPI();
if (scriptAPI == null) {
sender.sendMessage("Buscript failed to load while the server was starting. Scripts cannot be run.");
return;
}
File file = new File(scriptAPI.getScriptFolder(), targetScript);
if (!file.exists()) {
sender.sendMessage("That script file does not exist in the Multiverse-Core scripts directory!");
return;
}
scriptAPI.executeScript(file, targetScript, player);
sender.sendMessage(String.format("Script '%s%s%s' finished!", ChatColor.GOLD, file.getName(), ChatColor.WHITE));
}
}