Merge remote-tracking branch 'origin/master'

This commit is contained in:
Pyrbu 2023-04-20 16:10:20 +01:00
commit 61593b07a8
7 changed files with 44 additions and 44 deletions

@ -19,7 +19,7 @@ public class Command extends BukkitCommand {
try { try {
COMMAND_MAP = (CommandMap) CacheRegistry.BUKKIT_COMMAND_MAP.load().get(Bukkit.getServer()); COMMAND_MAP = (CommandMap) CacheRegistry.BUKKIT_COMMAND_MAP.load().get(Bukkit.getServer());
} catch (IllegalAccessException exception) { } catch (IllegalAccessException exception) {
throw new IllegalStateException("can't access bukkit command map."); throw new IllegalStateException("Unable to register Bukkit command map.");
} }
} }
@ -69,17 +69,17 @@ public class Command extends BukkitCommand {
public boolean execute(CommandSender sender, String commandLabel, String[] args) { public boolean execute(CommandSender sender, String commandLabel, String[] args) {
Optional<Map.Entry<CommandInformation, CommandInvoker>> subCommandOptional = this.subCommands.entrySet().stream().filter(command -> command.getKey().name().contentEquals((args.length > 0) ? args[0] : "")).findFirst(); Optional<Map.Entry<CommandInformation, CommandInvoker>> subCommandOptional = this.subCommands.entrySet().stream().filter(command -> command.getKey().name().contentEquals((args.length > 0) ? args[0] : "")).findFirst();
if (subCommandOptional.isEmpty()) { if (subCommandOptional.isEmpty()) {
sender.sendMessage(ChatColor.RED + "can't find command: " + commandLabel + "."); sender.sendMessage(ChatColor.RED + "Unable to locate the following command: " + commandLabel + ".");
return false; return false;
} }
try { try {
Map.Entry<CommandInformation, CommandInvoker> subCommand = subCommandOptional.get(); Map.Entry<CommandInformation, CommandInvoker> subCommand = subCommandOptional.get();
subCommand.getValue().execute(new io.github.znetworkw.znpcservers.commands.CommandSender(sender), loadArgs(subCommand.getKey(), Arrays.asList(args))); subCommand.getValue().execute(new io.github.znetworkw.znpcservers.commands.CommandSender(sender), loadArgs(subCommand.getKey(), Arrays.asList(args)));
} catch (CommandExecuteException e) { } catch (CommandExecuteException e) {
sender.sendMessage(ChatColor.RED + "can't execute command."); sender.sendMessage(ChatColor.RED + "Cannot execute this command or this command execution has failed.");
e.printStackTrace(); e.printStackTrace();
} catch (CommandPermissionException e) { } catch (CommandPermissionException e) {
sender.sendMessage(ChatColor.RED + "no permission for run this command."); sender.sendMessage(ChatColor.RED + "You do not have permission to execute this command.");
} }
return true; return true;
} }

@ -20,7 +20,7 @@ public class CommandInvoker {
throw new CommandPermissionException("Only players may execute this command."); throw new CommandPermissionException("Only players may execute this command.");
} }
if (this.permission.length() > 0 && !sender.getCommandSender().hasPermission(this.permission)) { if (this.permission.length() > 0 && !sender.getCommandSender().hasPermission(this.permission)) {
throw new CommandPermissionException("Insufficient permission."); throw new CommandPermissionException("You cannot execute this command.");
} }
try { try {
this.commandMethod.invoke(this.command, sender, command); this.commandMethod.invoke(this.command, sender, command);

@ -51,7 +51,7 @@ public class CommandSender {
public Player getPlayer() { public Player getPlayer() {
if (this.type != SenderType.PLAYER) if (this.type != SenderType.PLAYER)
throw new IllegalStateException("sender is not a player."); throw new IllegalStateException("The following sender is not a player.");
return (Player) getCommandSender(); return (Player) getCommandSender();
} }

@ -47,15 +47,15 @@ public class DefaultCommand extends Command {
@CommandInformation(arguments = {}, name = "", permission = "") @CommandInformation(arguments = {}, name = "", permission = "")
public void defaultCommand(CommandSender sender, Map<String, String> args) { public void defaultCommand(CommandSender sender, Map<String, String> args) {
sender.sendMessage("&6&m------------------------------------------"); sender.sendMessage("&6&m------------------------------------------");
sender.sendMessage("&b&lZNPCS &8\u00BB &7ZNetwork"); sender.sendMessage("&b&lZNPCS &8\u00BB &7ZNetwork & Pyr");
sender.sendMessage("&6https://www.spigotmc.org/resources/znpcs.80940"); sender.sendMessage("&6https://www.spigotmc.org/resources/znpcsplus.109380/");
Objects.requireNonNull(sender); Objects.requireNonNull(sender);
getCommands().forEach(sender::sendMessage); getCommands().forEach(sender::sendMessage);
sender.sendMessage(ChatColor.DARK_GRAY + "Hover over the commands to see help for the command."); sender.sendMessage(ChatColor.DARK_GRAY + "Hover over the commands to view command arguments.");
sender.sendMessage("&6&m------------------------------------------"); sender.sendMessage("&6&m------------------------------------------");
} }
@CommandInformation(arguments = {"id", "type", "name"}, name = "create", permission = "znpcs.cmd.create", help = {" &f&l* &e/znpcs create <npc_id> PLAYER Qentin"}) @CommandInformation(arguments = {"id", "type", "name"}, name = "create", permission = "znpcs.cmd.create", help = {" &f&l* &e/znpcs create <npc_id> PLAYER Steve"})
public void createNPC(CommandSender sender, Map<String, String> args) { public void createNPC(CommandSender sender, Map<String, String> args) {
if (args.size() < 3) { if (args.size() < 3) {
Configuration.MESSAGES.sendMessage(sender.getCommandSender(), ConfigurationValue.INCORRECT_USAGE); Configuration.MESSAGES.sendMessage(sender.getCommandSender(), ConfigurationValue.INCORRECT_USAGE);
@ -116,7 +116,7 @@ public class DefaultCommand extends Command {
TextComponent textComponent2 = new TextComponent("[TELEPORT]"); TextComponent textComponent2 = new TextComponent("[TELEPORT]");
textComponent2.setBold(true); textComponent2.setBold(true);
textComponent2.setColor(ChatColor.DARK_GREEN); textComponent2.setColor(ChatColor.DARK_GREEN);
textComponent2.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, (new ComponentBuilder("Click to teleport this npc!")) textComponent2.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, (new ComponentBuilder("Click to teleport this NPC!"))
.color(ChatColor.GREEN).create())); .color(ChatColor.GREEN).create()));
textComponent2.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/znpcs teleport " + npcModel textComponent2.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/znpcs teleport " + npcModel
@ -126,7 +126,7 @@ public class DefaultCommand extends Command {
TextComponent textComponent3 = new TextComponent("[DELETE]"); TextComponent textComponent3 = new TextComponent("[DELETE]");
textComponent3.setBold(true); textComponent3.setBold(true);
textComponent3.setColor(ChatColor.DARK_RED); textComponent3.setColor(ChatColor.DARK_RED);
textComponent3.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, (new ComponentBuilder("Click to delete this npc!")) textComponent3.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, (new ComponentBuilder("Click to delete this NPC!"))
.color(ChatColor.RED).create())); .color(ChatColor.RED).create()));
textComponent3.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/znpcs delete " + npcModel textComponent3.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/znpcs delete " + npcModel
@ -158,7 +158,7 @@ public class DefaultCommand extends Command {
DO_APPLY_SKIN.apply(sender.getPlayer(), foundNPC, args.get("skin")); DO_APPLY_SKIN.apply(sender.getPlayer(), foundNPC, args.get("skin"));
} }
@CommandInformation(arguments = {"id", "slot"}, name = "equip", permission = "znpcs.cmd.equip", help = {" &f&l* &e/znpcs equip <npc_id> [HAND,OFFHAND,HELMET,CHESTPLATE,LEGGINGS,BOOTS]", "&8(You need to have the item in your hand.)"}) @CommandInformation(arguments = {"id", "slot"}, name = "equip", permission = "znpcs.cmd.equip", help = {" &f&l* &e/znpcs equip <npc_id> [HAND/OFFHAND/HELMET/CHESTPLATE/LEGGINGS/BOOTS]", "&8(You need to have the item in your hand)."})
public void equip(CommandSender sender, Map<String, String> args) { public void equip(CommandSender sender, Map<String, String> args) {
if (args.size() < 2) { if (args.size() < 2) {
Configuration.MESSAGES.sendMessage(sender.getCommandSender(), ConfigurationValue.INCORRECT_USAGE); Configuration.MESSAGES.sendMessage(sender.getCommandSender(), ConfigurationValue.INCORRECT_USAGE);
@ -251,7 +251,7 @@ public class DefaultCommand extends Command {
Configuration.MESSAGES.sendMessage(sender.getCommandSender(), ConfigurationValue.SUCCESS); Configuration.MESSAGES.sendMessage(sender.getCommandSender(), ConfigurationValue.SUCCESS);
} }
@CommandInformation(arguments = {"add", "remove", "cooldown", "list"}, name = "action", isMultiple = true, permission = "znpcs.cmd.action", help = {" &f&l* &e/znpcs action add <npc_id> SERVER skywars", " &f&l* &e/znpcs action add <npc_id> CMD spawn", " &f&l* &e/znpcs action remove <npc_id> <action_id>", " &f&l* &e/znpcs action cooldown <npc_id> <action_id> <delay_in_seconds>", " &f&l* &e/znpcs action list <npc_id>"}) @CommandInformation(arguments = {"add", "remove", "cooldown", "list"}, name = "action", isMultiple = true, permission = "znpcs.cmd.action", help = {" &f&l* &e/znpcs action add <npc_id> SERVER survival", " &f&l* &e/znpcs action add <npc_id> CMD spawn", " &f&l* &e/znpcs action remove <npc_id> <action_id>", " &f&l* &e/znpcs action cooldown <npc_id> <action_id> <delay_in_seconds>", " &f&l* &e/znpcs action list <npc_id>"})
public void action(CommandSender sender, Map<String, String> args) { public void action(CommandSender sender, Map<String, String> args) {
if (args.size() < 1) { if (args.size() < 1) {
Configuration.MESSAGES.sendMessage(sender.getCommandSender(), ConfigurationValue.INCORRECT_USAGE); Configuration.MESSAGES.sendMessage(sender.getCommandSender(), ConfigurationValue.INCORRECT_USAGE);
@ -445,7 +445,7 @@ public class DefaultCommand extends Command {
return; return;
} }
if (znpcUser.isHasPath()) { if (znpcUser.isHasPath()) {
sender.getPlayer().sendMessage(ChatColor.RED + "You already have a path creator active, to remove it use /znpcs path exit."); sender.getPlayer().sendMessage(ChatColor.RED + "You already have a path creator active! To remove it, type " + ChatColor.WHITE + "/znpcs path exit" + ChatColor.RED + ".");
return; return;
} }
NPCPath.AbstractTypeWriter.forCreation(pathName, znpcUser, NPCPath.AbstractTypeWriter.TypeWriter.MOVEMENT); NPCPath.AbstractTypeWriter.forCreation(pathName, znpcUser, NPCPath.AbstractTypeWriter.TypeWriter.MOVEMENT);
@ -481,7 +481,7 @@ public class DefaultCommand extends Command {
sender.getPlayer().teleport(foundNPC.getLocation()); sender.getPlayer().teleport(foundNPC.getLocation());
} }
@CommandInformation(arguments = {"id", "height"}, name = "height", permission = "znpcs.cmd.height", help = {" &f&l* &e/znpcs height <npc_id> 2", "&8Add more height to the hologram of the npc"}) @CommandInformation(arguments = {"id", "height"}, name = "height", permission = "znpcs.cmd.height", help = {" &f&l* &e/znpcs height <npc_id> 2", "&8Set a greater or lesser distance of a hologram from the NPC."})
public void changeHologramHeight(CommandSender sender, Map<String, String> args) { public void changeHologramHeight(CommandSender sender, Map<String, String> args) {
if (args.size() < 2) { if (args.size() < 2) {
Configuration.MESSAGES.sendMessage(sender.getCommandSender(), ConfigurationValue.INCORRECT_USAGE); Configuration.MESSAGES.sendMessage(sender.getCommandSender(), ConfigurationValue.INCORRECT_USAGE);
@ -507,7 +507,7 @@ public class DefaultCommand extends Command {
Configuration.MESSAGES.sendMessage(sender.getCommandSender(), ConfigurationValue.SUCCESS); Configuration.MESSAGES.sendMessage(sender.getCommandSender(), ConfigurationValue.SUCCESS);
} }
@CommandInformation(arguments = {"create", "remove", "gui", "set"}, name = "conversation", isMultiple = true, permission = "znpcs.cmd.conversation", help = {" &f&l* &e/znpcs conversation create first", " &f&l* &e/znpcs conversation remove first", " &f&l* &e/znpcs conversation set <npc_id> first [CLICK:RADIUS]", " &f&l* &e/znpcs conversation gui &8(&7Open a gui to manage the conversations&8)", "&8RADIUS: &7it is activated when the player is near the npc", "&8CLICK: &7it is activated when the player interacts with the npc"}) @CommandInformation(arguments = {"create", "remove", "gui", "set"}, name = "conversation", isMultiple = true, permission = "znpcs.cmd.conversation", help = {" &f&l* &e/znpcs conversation create first", " &f&l* &e/znpcs conversation remove first", " &f&l* &e/znpcs conversation set <npc_id> first [CLICK/RADIUS]", " &f&l* &e/znpcs conversation gui &8(&7Opens a GUI to manage conversations&8)", "&8RADIUS: &7Activates when the player is near the NPC", "&8CLICK: &7Activates when the player interacts with the NPC"})
public void conversations(CommandSender sender, Map<String, String> args) { public void conversations(CommandSender sender, Map<String, String> args) {
if (args.size() < 1) { if (args.size() < 1) {
Configuration.MESSAGES.sendMessage(sender.getCommandSender(), ConfigurationValue.INCORRECT_USAGE); Configuration.MESSAGES.sendMessage(sender.getCommandSender(), ConfigurationValue.INCORRECT_USAGE);

@ -119,7 +119,7 @@ public class ConversationGUI extends ZInventory {
}); });
} }
this.addItem(ItemStackBuilder.forMaterial(Material.EMERALD).setName(ChatColor.AQUA + "ADD A NEW ACTION").setLore("&7click here...").build(), this.getRows() - 5, clickEvent -> { this.addItem(ItemStackBuilder.forMaterial(Material.EMERALD).setName(ChatColor.AQUA + "ADD A NEW ACTION").setLore("&7click here...").build(), this.getRows() - 5, clickEvent -> {
Utils.sendTitle(this.getPlayer(), "&d&lADD ACTION", "&7Type the action..."); Utils.sendTitle(this.getPlayer(), "&d&lADD ACTION", "&7Type the new action...");
EventService.addService(ZUser.find(this.getPlayer()), AsyncPlayerChatEvent.class).addConsumer(event -> { EventService.addService(ZUser.find(this.getPlayer()), AsyncPlayerChatEvent.class).addConsumer(event -> {
if (ConfigurationConstants.NPC_CONVERSATIONS.contains(this.conversation) && this.conversation.getTexts().contains(this.conversationKey)) { if (ConfigurationConstants.NPC_CONVERSATIONS.contains(this.conversation) && this.conversation.getTexts().contains(this.conversationKey)) {
List<String> stringList = SPACE_SPLITTER.splitToList(event.getMessage()); List<String> stringList = SPACE_SPLITTER.splitToList(event.getMessage());

@ -34,7 +34,7 @@ public class Configuration {
} }
private Configuration(String name, Path path) { private Configuration(String name, Path path) {
if (!path.getFileName().toString().endsWith(".json")) throw new IllegalStateException("invalid configuration format for: " + path.getFileName()); if (!path.getFileName().toString().endsWith(".json")) throw new IllegalStateException("Invalid configuration format for: " + path.getFileName());
this.name = name; this.name = name;
this.path = path; this.path = path;
this.configurationValues = ConfigurationValue.VALUES_BY_NAME.get(name).stream().collect(Collectors.toMap((c) -> c, ConfigurationValue::getValue)); this.configurationValues = ConfigurationValue.VALUES_BY_NAME.get(name).stream().collect(Collectors.toMap((c) -> c, ConfigurationValue::getValue));
@ -54,7 +54,7 @@ public class Configuration {
} }
} catch (NoSuchFileException ignored) { } catch (NoSuchFileException ignored) {
} catch (IOException ex) { } catch (IOException ex) {
throw new IllegalStateException("Failed to read config: " + this.name); throw new IllegalStateException("Failed to read configuration: " + this.name);
} }
} }
@ -62,7 +62,7 @@ public class Configuration {
try (Writer writer = Files.newBufferedWriter(this.path, CHARSET)) { try (Writer writer = Files.newBufferedWriter(this.path, CHARSET)) {
ZNPCsPlus.GSON.toJson(this.configurationValues.size() == 1 ? this.configurationValues.values().iterator().next() : this.configurationValues, writer); ZNPCsPlus.GSON.toJson(this.configurationValues.size() == 1 ? this.configurationValues.values().iterator().next() : this.configurationValues, writer);
} catch (IOException ex) { } catch (IOException ex) {
throw new IllegalStateException("Failed to save config: " + this.name); throw new IllegalStateException("Failed to save configuration: " + this.name);
} }
} }

@ -22,35 +22,35 @@ public enum ConfigurationValue {
LINE_SPACING("config", 0.3D, Double.class), LINE_SPACING("config", 0.3D, Double.class),
ANIMATION_RGB("config", Boolean.FALSE, Boolean.class), ANIMATION_RGB("config", Boolean.FALSE, Boolean.class),
NO_PERMISSION("messages", "&cYou do not have permission to execute this command.", String.class), NO_PERMISSION("messages", "&cYou do not have permission to execute this command.", String.class),
SUCCESS("messages", "&aDone!", String.class), SUCCESS("messages", "&aSuccess!", String.class),
INCORRECT_USAGE("messages", "&cThe arguements you specified are not valid, do &f/znpcs help&c for assistance and examples.", String.class), INCORRECT_USAGE("messages", "&cThe arguments you specified are invalid. Type &f/znpcs help&c for examples.", String.class),
COMMAND_NOT_FOUND("messages", "&cThe command you specified does not exist!", String.class), COMMAND_NOT_FOUND("messages", "&cThe command you specified does not exist!", String.class),
COMMAND_ERROR("messages", "&cThere was an error executing the command, see the console for more information.", String.class), COMMAND_ERROR("messages", "&cAn error occurred when executing this command. See console for more information.", String.class),
INVALID_NUMBER("messages", "&cHey!, The inserted number/id does not look like a number, please use integer values only!", String.class), INVALID_NUMBER("messages", "&cThe ID you have specified is invalid. Please use positive integers only!", String.class),
NPC_NOT_FOUND("messages", "&cHey!, I couldn't find a npc with this id!", String.class), NPC_NOT_FOUND("messages", "&cNo NPCs could be found with this ID!", String.class),
TOO_FEW_ARGUMENTS("messages", "&cThis command does not have enough arguements, do &f/znpcs help&c for assistance and examples.", String.class), TOO_FEW_ARGUMENTS("messages", "&cThis command does not contain enough arguments. Type &f/znpcs help&c or view our documentation for a list/examples of existing arguments.", String.class),
PATH_START("messages", "&aDone, now walk where you want the npc to walk towards, when finished type &f/znpcs path exit", String.class), PATH_START("messages", "&aSuccess! Move to create a path for your NPC. When finished, type &f/znpcs path exit&c to exit path creation.", String.class),
EXIT_PATH("messages", "&cYou have exited the waypoint creation.", String.class), EXIT_PATH("messages", "&cYou have exited path creation.", String.class),
PATH_FOUND("messages", "&cThere is already a path with this name.", String.class), PATH_FOUND("messages", "&cThere is already a path with this name.", String.class),
NPC_FOUND("messages", "&cThere is already an NPC with this id.", String.class), NPC_FOUND("messages", "&cThere is already an NPC with this ID.", String.class),
NO_PATH_FOUND("messages", "&cNo path found.", String.class), NO_PATH_FOUND("messages", "&cThe path you have specified does not exist.", String.class),
NO_SKIN_FOUND("messages", "&cSkin not found.", String.class), NO_SKIN_FOUND("messages", "&cThe skin username/URL you have specified does not exist or is invalid.", String.class),
NO_NPC_FOUND("messages", "&cNo npc found.", String.class), NO_NPC_FOUND("messages", "&cThe NPC you have specified does not exist.", String.class),
NO_ACTION_FOUND("messages", "&cThis action was not valid! Check the wiki for valid action types.", String.class), NO_ACTION_FOUND("messages", "&cThis action does not exist! Type &f/znpcs help&c or view our documentation for a list/examples of existing action types.", String.class),
METHOD_NOT_FOUND("messages", "&cThis method was not found! Check the wiki for valid action types.", String.class), METHOD_NOT_FOUND("messages", "&cThis method does not exist! Type &f/znpcs help&c or view our documentation for a list/examples of existing methods.", String.class),
INVALID_NAME_LENGTH("messages", "&cThe name you specified is too short or long, it must be in the range of (3 to 16) characters.", String.class), INVALID_NAME_LENGTH("messages", "&cThe name you specified either too short or long. Please enter a positive integer of (3 to 16) characters.", String.class),
UNSUPPORTED_ENTITY("messages", "&cThis entity type not available for your current version.", String.class), UNSUPPORTED_ENTITY("messages", "&cThis entity type not available in your current server version.", String.class),
PATH_SET_INCORRECT_USAGE("messages", "&eUsage: &aset <npc_id> <path_name>", String.class), PATH_SET_INCORRECT_USAGE("messages", "&eUsage: &aset <npc_id> <path_name>", String.class),
ACTION_ADD_INCORRECT_USAGE("messages", "&eUsage: &a<SERVER:CMD:MESSAGE:CONSOLE> <actionValue>", String.class), ACTION_ADD_INCORRECT_USAGE("messages", "&eUsage: &a<SERVER/CMD/MESSAGE/CONSOLE> <actionValue>", String.class),
ACTION_DELAY_INCORRECT_USAGE("messages", "&eUsage: &a<action_id> <delay>", String.class), ACTION_DELAY_INCORRECT_USAGE("messages", "&eUsage: &a<action_id> <delay>", String.class),
CONVERSATION_SET_INCORRECT_USAGE("messages", "&cUsage: <npc_id> <conversation_name> <RADIUS:CLICK>", String.class), CONVERSATION_SET_INCORRECT_USAGE("messages", "&cUsage: <npc_id> <conversation_name> <RADIUS/CLICK>", String.class),
NO_CONVERSATION_FOUND("messages", "&cThis conversation was not found.", String.class), NO_CONVERSATION_FOUND("messages", "&cThe conversation you have specified does not exist!", String.class),
CONVERSATION_FOUND("messages", "&cThere is already a conversation with this name.", String.class), CONVERSATION_FOUND("messages", "&cThere is already a conversation with this name.", String.class),
INVALID_SIZE("messages", "&cThe position cannot exceed the limit.", String.class), INVALID_SIZE("messages", "&cThe position you have specified cannot exceed the limit.", String.class),
FETCHING_SKIN("messages", "&aFetching skin for name: &f%s&a, wait...", String.class), FETCHING_SKIN("messages", "&aFetching skin for name: &f%s&a. Please wait...", String.class),
CANT_GET_SKIN("messages", "&cCould not fetch skin for name: %s.", String.class), CANT_GET_SKIN("messages", "&cCould not fetch skin for name: %s.", String.class),
GET_SKIN("messages", "&aSkin fetched!", String.class), GET_SKIN("messages", "&aSkin successfully fetched!", String.class),
CONVERSATION_LIST("conversations", new ArrayList<>(), Conversation.class); CONVERSATION_LIST("Conversations", new ArrayList<>(), Conversation.class);
public static final Map<String, ImmutableSet<ConfigurationValue>> VALUES_BY_NAME; public static final Map<String, ImmutableSet<ConfigurationValue>> VALUES_BY_NAME;