This commit is contained in:
parent
f387c63183
commit
627e533e9c
18 changed files with 1015 additions and 0 deletions
|
@ -6,6 +6,7 @@ import java.lang.reflect.InvocationTargetException;
|
|||
import me.unurled.sacredrealms.sr.SR;
|
||||
import me.unurled.sacredrealms.sr.commands.admin.AttributeCommand;
|
||||
import me.unurled.sacredrealms.sr.commands.admin.ClientBuildCommand;
|
||||
import me.unurled.sacredrealms.sr.commands.admin.EntityTypeCommand;
|
||||
import me.unurled.sacredrealms.sr.commands.admin.LevelCommand;
|
||||
import me.unurled.sacredrealms.sr.commands.player.ResetAdventureCommand;
|
||||
import me.unurled.sacredrealms.sr.managers.Manager;
|
||||
|
@ -38,6 +39,7 @@ public class CommandManager extends Manager {
|
|||
registerCommand("attributes", AttributeCommand.class);
|
||||
registerCommand("clientbuild", ClientBuildCommand.class);
|
||||
registerCommand("level", LevelCommand.class);
|
||||
registerCommand("entitytype", EntityTypeCommand.class);
|
||||
|
||||
registerCommand("resetadventure", ResetAdventureCommand.class);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,171 @@
|
|||
package me.unurled.sacredrealms.sr.commands.admin;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import me.unurled.sacredrealms.sr.components.entity.EntityManager;
|
||||
import me.unurled.sacredrealms.sr.components.entity.SREntityType;
|
||||
import me.unurled.sacredrealms.sr.gui.entitytype.EntityTypeGUI;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabExecutor;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import xyz.xenondevs.invui.window.Window;
|
||||
|
||||
public class EntityTypeCommand implements TabExecutor {
|
||||
|
||||
/**
|
||||
* Executes the given command, returning its success. <br>
|
||||
* If false is returned, then the "usage" plugin.yml entry for this command (if defined) will be
|
||||
* sent to the player.
|
||||
*
|
||||
* @param sender Source of the command
|
||||
* @param command Command which was executed
|
||||
* @param label Alias of the command which was used
|
||||
* @param args Passed command arguments
|
||||
* @return true if a valid command, otherwise false
|
||||
*/
|
||||
@Override
|
||||
public boolean onCommand(
|
||||
@NotNull CommandSender sender,
|
||||
@NotNull Command command,
|
||||
@NotNull String label,
|
||||
@NotNull String[] args) {
|
||||
if (!sender.hasPermission("sr.entitytype")) {
|
||||
sender.sendMessage("You do not have permission to use this command.");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args.length == 0) {
|
||||
sender.sendMessage("Usage: /entitytype <create|delete|edit|list>");
|
||||
return true;
|
||||
}
|
||||
|
||||
switch (args[0].toLowerCase()) {
|
||||
case "create":
|
||||
if (args.length < 2) {
|
||||
sender.sendMessage("Usage: /entitytype create <ID>");
|
||||
return true;
|
||||
}
|
||||
if (!(sender instanceof Player p)) {
|
||||
sender.sendMessage("You must be a player to use this command.");
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case "delete":
|
||||
if (args.length < 2) {
|
||||
sender.sendMessage("Usage: /entitytype delete <ID>");
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case "edit":
|
||||
if (args.length < 2) {
|
||||
sender.sendMessage("Usage: /entitytype edit <ID>");
|
||||
return true;
|
||||
}
|
||||
if (!(sender instanceof Player p)) {
|
||||
sender.sendMessage("You must be a player to use this command.");
|
||||
return true;
|
||||
}
|
||||
if (args.length < 3) {
|
||||
EntityManager em = EntityManager.getInstance(EntityManager.class);
|
||||
if (!em.getTypes().stream().map(SREntityType::getID).toList().contains(args[1])) {
|
||||
sender.sendMessage("Invalid entity type.");
|
||||
return true;
|
||||
}
|
||||
SREntityType type = em.getType(args[1]);
|
||||
Window window =
|
||||
Window.single()
|
||||
.setViewer(p)
|
||||
.setTitle(args[1])
|
||||
.setGui(EntityTypeGUI.createGui(type))
|
||||
.build();
|
||||
return true;
|
||||
}
|
||||
if (args.length < 4) {
|
||||
sender.sendMessage(
|
||||
"Usage: /entitytype edit <ID> <type|behavior|loot|item|stats|name|level>");
|
||||
return true;
|
||||
}
|
||||
if (args[2].equalsIgnoreCase("type")) {
|
||||
if (args.length < 5) {
|
||||
sender.sendMessage("Usage: /entitytype edit <ID> type <type>");
|
||||
return true;
|
||||
}
|
||||
try {
|
||||
EntityType type = EntityType.valueOf(args[4]);
|
||||
EntityManager em = EntityManager.getInstance(EntityManager.class);
|
||||
try {
|
||||
em.getType(args[1]).setType(type);
|
||||
} catch (Exception e) {
|
||||
sender.sendMessage("An error occurred while setting the entity type.");
|
||||
return true;
|
||||
}
|
||||
} catch (IllegalArgumentException e) {
|
||||
sender.sendMessage("Invalid entity type.");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "list":
|
||||
if (!(sender instanceof Player p)) {
|
||||
sender.sendMessage("You must be a player to use this command.");
|
||||
return true;
|
||||
}
|
||||
Window window =
|
||||
Window.single().setViewer(p).setTitle(args[1]).setGui(EntityTypeGUI.listGui()).build();
|
||||
window.open();
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Requests a list of possible completions for a command argument.
|
||||
*
|
||||
* @param sender Source of the command. For players tab-completing a command inside of a command
|
||||
* block, this will be the player, not the command block.
|
||||
* @param command Command which was executed
|
||||
* @param label Alias of the command which was used
|
||||
* @param args The arguments passed to the command, including final partial argument to be
|
||||
* completed
|
||||
* @return A List of possible completions for the final argument, or null to default to the
|
||||
* command executor
|
||||
*/
|
||||
@Override
|
||||
public @Nullable List<String> onTabComplete(
|
||||
@NotNull CommandSender sender,
|
||||
@NotNull Command command,
|
||||
@NotNull String label,
|
||||
@NotNull String[] args) {
|
||||
if (sender.hasPermission("sr.entitytype")) {
|
||||
if (args.length == 1) {
|
||||
return List.of("create", "delete", "edit", "list");
|
||||
}
|
||||
if (args.length == 2) {
|
||||
return EntityManager.getInstance(EntityManager.class).getTypes().stream()
|
||||
.map(SREntityType::getID)
|
||||
.toList();
|
||||
}
|
||||
if (args.length == 3) {
|
||||
if (args[0].equalsIgnoreCase("edit")) {
|
||||
return List.of("type", "behavior", "loot", "item", "stats", "name", "level");
|
||||
}
|
||||
}
|
||||
if (args.length == 4) {
|
||||
if (args[0].equalsIgnoreCase("edit")) {
|
||||
if (args[2].equalsIgnoreCase("type")) {
|
||||
return List.of(
|
||||
Arrays.stream(EntityType.values())
|
||||
.filter(EntityType::isAlive)
|
||||
.map(EntityType::name)
|
||||
.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue