Add generator command.

This commit is contained in:
benwoo1110 2020-12-17 21:57:23 +08:00
parent 5413b92ce2
commit 391ba7b4fa
2 changed files with 59 additions and 0 deletions

View File

@ -36,6 +36,7 @@ import com.onarandombox.MultiverseCore.commands_acf.CoordCommand;
import com.onarandombox.MultiverseCore.commands_acf.CreateCommand;
import com.onarandombox.MultiverseCore.commands_acf.GameRuleCommand;
import com.onarandombox.MultiverseCore.commands_acf.GamerulesCommand;
import com.onarandombox.MultiverseCore.commands_acf.GeneratorCommand;
import com.onarandombox.MultiverseCore.commands_acf.ListCommand;
import com.onarandombox.MultiverseCore.commands_acf.ReloadCommand;
import com.onarandombox.MultiverseCore.commands_acf.RemoveCommand;
@ -747,6 +748,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 GeneratorCommand(this));
//TODO: Can combine both gamerules class into one.
this.commandHandler.registerCommand(new GamerulesCommand(this));
this.commandHandler.registerCommand(new GameRuleCommand(this));

View File

@ -0,0 +1,57 @@
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.Subcommand;
import co.aikar.commands.annotation.Syntax;
import com.dumptruckman.minecraft.util.Logging;
import com.onarandombox.MultiverseCore.MultiverseCore;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.plugin.Plugin;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
@CommandAlias("mv")
public class GeneratorCommand extends MultiverseCommand {
public GeneratorCommand(MultiverseCore plugin) {
super(plugin);
}
@Subcommand("gens|generators")
@CommandPermission("multiverse.core.generator")
@Description("Shows a list of Loaded Generator Plugins.")
public void onGeneratorCommand(CommandSender sender) {
//TODO: Figure out why this loggin message exist...
Logging.info("PLEASE IGNORE the 'Plugin X does not contain any generators' message below!");
List<String> generators = Arrays.stream(this.plugin.getServer().getPluginManager().getPlugins())
.filter(Plugin::isEnabled)
.filter(p -> p.getDefaultWorldGenerator("world", "") != null)
.map(p -> p.getDescription().getName())
.collect(Collectors.toList());
if (generators.size() == 0) {
sender.sendMessage(ChatColor.RED + "No Generator Plugins found.");
return;
}
StringBuilder loadedGens = new StringBuilder();
boolean altColor = false;
for (String s : generators) {
loadedGens.append(altColor ? ChatColor.YELLOW : ChatColor.WHITE)
.append(s)
.append(' ');
altColor ^= true;
}
sender.sendMessage(ChatColor.AQUA + "--- Loaded Generator Plugins ---");
sender.sendMessage(loadedGens.toString());
}
}