diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/ZNpcsPlusBootstrap.java b/plugin/src/main/java/lol/pyr/znpcsplus/ZNpcsPlusBootstrap.java index 2028154..3bfde9e 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/ZNpcsPlusBootstrap.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/ZNpcsPlusBootstrap.java @@ -10,6 +10,8 @@ import org.bukkit.plugin.java.JavaPlugin; import java.io.File; import java.io.Reader; +import java.util.regex.Matcher; +import java.util.regex.Pattern; public class ZNpcsPlusBootstrap extends JavaPlugin { private ZNpcsPlus zNpcsPlus; @@ -78,10 +80,27 @@ public class ZNpcsPlusBootstrap extends JavaPlugin { if (zNpcsPlus != null) zNpcsPlus.onDisable(); } + private final static Pattern EMBEDDED_FILE_PATTERN = Pattern.compile("\\{@(.*?)}"); + + private String loadMessageFile(String file) { + Reader reader = getTextResource("messages/" + file + ".txt"); + if (reader == null) throw new RuntimeException(file + ".txt is missing from ZNPCsPlus jar!"); + String text = FileUtil.dumpReaderAsString(reader); + System.out.println(text); + Matcher matcher = EMBEDDED_FILE_PATTERN.matcher(text); + StringBuilder builder = new StringBuilder(); + int lastMatchEnd = 0; + while (matcher.find()) { + builder.append(text, lastMatchEnd, matcher.start()); + lastMatchEnd = matcher.end(); + builder.append(loadMessageFile(matcher.group(1))); + } + builder.append(text, lastMatchEnd, text.length()); + return builder.toString(); + } + protected Message loadHelpMessage(String name) { - Reader reader = getTextResource("help-messages/" + name + ".txt"); - if (reader == null) throw new RuntimeException(name + ".txt is missing from the help-messages folder in the ZNPCsPlus jar!"); - Component component = MiniMessage.miniMessage().deserialize(FileUtil.dumpReaderAsString(reader)); + Component component = MiniMessage.miniMessage().deserialize(loadMessageFile(name)); return context -> context.send(component); } diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/util/FileUtil.java b/plugin/src/main/java/lol/pyr/znpcsplus/util/FileUtil.java index cc1eb7c..47cb5a1 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/util/FileUtil.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/util/FileUtil.java @@ -9,12 +9,9 @@ public class FileUtil { BufferedReader bReader = new BufferedReader(reader); try { StringBuilder sb = new StringBuilder(); - String line = bReader.readLine(); - while (true) { - sb.append(line); - line = bReader.readLine(); - if (line == null) break; - sb.append("\n"); + String line; + while ((line = bReader.readLine()) != null) { + sb.append(line).append("\n"); } return sb.toString(); } catch (IOException e) { diff --git a/plugin/src/main/resources/help-messages/action.txt b/plugin/src/main/resources/help-messages/action.txt deleted file mode 100644 index eb63aa1..0000000 --- a/plugin/src/main/resources/help-messages/action.txt +++ /dev/null @@ -1,10 +0,0 @@ - -ZNPCsPlus v${version} Click to view the main help message'>[BACK] -Hover over any command for more info - - * /npc action add - * /npc action clear - * /npc action delete - * /npc action edit - * /npc action list - diff --git a/plugin/src/main/resources/help-messages/holo.txt b/plugin/src/main/resources/help-messages/holo.txt deleted file mode 100644 index 677f264..0000000 --- a/plugin/src/main/resources/help-messages/holo.txt +++ /dev/null @@ -1,11 +0,0 @@ - -ZNPCsPlus v${version} Click to view the main help message'>[BACK] -Hover over any command more info - - * /npc holo add - * /npc holo delete - * /npc holo set - * /npc holo insert - * /npc holo offset - * /npc holo info - diff --git a/plugin/src/main/resources/help-messages/property.txt b/plugin/src/main/resources/help-messages/property.txt deleted file mode 100644 index 61671d7..0000000 --- a/plugin/src/main/resources/help-messages/property.txt +++ /dev/null @@ -1,7 +0,0 @@ - -ZNPCsPlus v${version} Click to view the main help message'>[BACK] -Hover over any command more info - - * /npc property set - * /npc property remove - diff --git a/plugin/src/main/resources/help-messages/root.txt b/plugin/src/main/resources/help-messages/root.txt deleted file mode 100644 index da9cfcb..0000000 --- a/plugin/src/main/resources/help-messages/root.txt +++ /dev/null @@ -1,26 +0,0 @@ - -ZNPCsPlus v${version} -Hover over any command for more info - - * /npc create - * /npc delete - * /npc changeid - * /npc toggle - * /npc list - * /npc type - - * /npc near - * /npc center - * /npc lookatme - * /npc setlocation - * /npc setrotation - * /npc move - * /npc teleport - - * /npc skin - - * Npc property commands
Click to view full list'>/npc property help - * Npc hologram commands
Click to view full list'>/npc holo help - * Player interaction commands
Click to view full list'>/npc action help - * Npc data storage commands
Click to view full list'>/npc storage help - diff --git a/plugin/src/main/resources/help-messages/storage.txt b/plugin/src/main/resources/help-messages/storage.txt deleted file mode 100644 index 6cbe3f5..0000000 --- a/plugin/src/main/resources/help-messages/storage.txt +++ /dev/null @@ -1,8 +0,0 @@ - -ZNPCsPlus v${version} Click to view the main help message'>[BACK] -Hover over any command for more info - - * /npc storage save - * /npc storage reload - * /npc storage import - diff --git a/plugin/src/main/resources/messages/action-hover/add.txt b/plugin/src/main/resources/messages/action-hover/add.txt new file mode 100644 index 0000000..e69de29 diff --git a/plugin/src/main/resources/messages/action-hover/clear.txt b/plugin/src/main/resources/messages/action-hover/clear.txt new file mode 100644 index 0000000..e69de29 diff --git a/plugin/src/main/resources/messages/action-hover/delete.txt b/plugin/src/main/resources/messages/action-hover/delete.txt new file mode 100644 index 0000000..e69de29 diff --git a/plugin/src/main/resources/messages/action-hover/edit.txt b/plugin/src/main/resources/messages/action-hover/edit.txt new file mode 100644 index 0000000..e69de29 diff --git a/plugin/src/main/resources/messages/action-hover/list.txt b/plugin/src/main/resources/messages/action-hover/list.txt new file mode 100644 index 0000000..e69de29 diff --git a/plugin/src/main/resources/messages/action.txt b/plugin/src/main/resources/messages/action.txt new file mode 100644 index 0000000..f6e1e09 --- /dev/null +++ b/plugin/src/main/resources/messages/action.txt @@ -0,0 +1,10 @@ + +ZNPCsPlus v${version} Click to view the main help message'>[BACK] +Hover over any command for more info + + * /npc action add + * /npc action clear + * /npc action delete + * /npc action edit + * /npc action list + diff --git a/plugin/src/main/resources/messages/holo-hover/add.txt b/plugin/src/main/resources/messages/holo-hover/add.txt new file mode 100644 index 0000000..e69de29 diff --git a/plugin/src/main/resources/messages/holo-hover/delete.txt b/plugin/src/main/resources/messages/holo-hover/delete.txt new file mode 100644 index 0000000..e69de29 diff --git a/plugin/src/main/resources/messages/holo-hover/info.txt b/plugin/src/main/resources/messages/holo-hover/info.txt new file mode 100644 index 0000000..e69de29 diff --git a/plugin/src/main/resources/messages/holo-hover/insert.txt b/plugin/src/main/resources/messages/holo-hover/insert.txt new file mode 100644 index 0000000..e69de29 diff --git a/plugin/src/main/resources/messages/holo-hover/offset.txt b/plugin/src/main/resources/messages/holo-hover/offset.txt new file mode 100644 index 0000000..e69de29 diff --git a/plugin/src/main/resources/messages/holo-hover/set.txt b/plugin/src/main/resources/messages/holo-hover/set.txt new file mode 100644 index 0000000..e69de29 diff --git a/plugin/src/main/resources/messages/holo.txt b/plugin/src/main/resources/messages/holo.txt new file mode 100644 index 0000000..a0b858d --- /dev/null +++ b/plugin/src/main/resources/messages/holo.txt @@ -0,0 +1,11 @@ + +ZNPCsPlus v${version} Click to view the main help message'>[BACK] +Hover over any command more info + + * /npc holo add + * /npc holo delete + * /npc holo set + * /npc holo insert + * /npc holo offset + * /npc holo info + diff --git a/plugin/src/main/resources/messages/property-hover/remove.txt b/plugin/src/main/resources/messages/property-hover/remove.txt new file mode 100644 index 0000000..e69de29 diff --git a/plugin/src/main/resources/messages/property-hover/set.txt b/plugin/src/main/resources/messages/property-hover/set.txt new file mode 100644 index 0000000..e69de29 diff --git a/plugin/src/main/resources/messages/property.txt b/plugin/src/main/resources/messages/property.txt new file mode 100644 index 0000000..33524c6 --- /dev/null +++ b/plugin/src/main/resources/messages/property.txt @@ -0,0 +1,7 @@ + +ZNPCsPlus v${version} Click to view the main help message'>[BACK] +Hover over any command more info + + * /npc property set + * /npc property remove + diff --git a/plugin/src/main/resources/messages/root-hover/center.txt b/plugin/src/main/resources/messages/root-hover/center.txt new file mode 100644 index 0000000..e69de29 diff --git a/plugin/src/main/resources/messages/root-hover/changeid.txt b/plugin/src/main/resources/messages/root-hover/changeid.txt new file mode 100644 index 0000000..e69de29 diff --git a/plugin/src/main/resources/messages/root-hover/create.txt b/plugin/src/main/resources/messages/root-hover/create.txt new file mode 100644 index 0000000..e69de29 diff --git a/plugin/src/main/resources/messages/root-hover/delete.txt b/plugin/src/main/resources/messages/root-hover/delete.txt new file mode 100644 index 0000000..e69de29 diff --git a/plugin/src/main/resources/messages/root-hover/list.txt b/plugin/src/main/resources/messages/root-hover/list.txt new file mode 100644 index 0000000..e69de29 diff --git a/plugin/src/main/resources/messages/root-hover/lookatme.txt b/plugin/src/main/resources/messages/root-hover/lookatme.txt new file mode 100644 index 0000000..e69de29 diff --git a/plugin/src/main/resources/messages/root-hover/move.txt b/plugin/src/main/resources/messages/root-hover/move.txt new file mode 100644 index 0000000..e69de29 diff --git a/plugin/src/main/resources/messages/root-hover/near.txt b/plugin/src/main/resources/messages/root-hover/near.txt new file mode 100644 index 0000000..e69de29 diff --git a/plugin/src/main/resources/messages/root-hover/setlocation.txt b/plugin/src/main/resources/messages/root-hover/setlocation.txt new file mode 100644 index 0000000..e69de29 diff --git a/plugin/src/main/resources/messages/root-hover/setrotation.txt b/plugin/src/main/resources/messages/root-hover/setrotation.txt new file mode 100644 index 0000000..e69de29 diff --git a/plugin/src/main/resources/messages/root-hover/skin.txt b/plugin/src/main/resources/messages/root-hover/skin.txt new file mode 100644 index 0000000..e69de29 diff --git a/plugin/src/main/resources/messages/root-hover/teleport.txt b/plugin/src/main/resources/messages/root-hover/teleport.txt new file mode 100644 index 0000000..e69de29 diff --git a/plugin/src/main/resources/messages/root-hover/toggle.txt b/plugin/src/main/resources/messages/root-hover/toggle.txt new file mode 100644 index 0000000..e69de29 diff --git a/plugin/src/main/resources/messages/root-hover/type.txt b/plugin/src/main/resources/messages/root-hover/type.txt new file mode 100644 index 0000000..e69de29 diff --git a/plugin/src/main/resources/messages/root.txt b/plugin/src/main/resources/messages/root.txt new file mode 100644 index 0000000..e7680ff --- /dev/null +++ b/plugin/src/main/resources/messages/root.txt @@ -0,0 +1,26 @@ + +ZNPCsPlus v${version} +Hover over any command for more info + + * /npc create + * /npc delete + * /npc changeid + * /npc toggle + * /npc list + * /npc type + + * /npc near + * /npc center + * /npc lookatme + * /npc setlocation + * /npc setrotation + * /npc move + * /npc teleport + + * /npc skin + + * Npc property commands
Click to view full list'>/npc property help + * Npc hologram commands
Click to view full list'>/npc holo help + * Player interaction commands
Click to view full list'>/npc action help + * Npc data storage commands
Click to view full list'>/npc storage help + diff --git a/plugin/src/main/resources/messages/storage-hover/import.txt b/plugin/src/main/resources/messages/storage-hover/import.txt new file mode 100644 index 0000000..e69de29 diff --git a/plugin/src/main/resources/messages/storage-hover/reload.txt b/plugin/src/main/resources/messages/storage-hover/reload.txt new file mode 100644 index 0000000..e69de29 diff --git a/plugin/src/main/resources/messages/storage-hover/save.txt b/plugin/src/main/resources/messages/storage-hover/save.txt new file mode 100644 index 0000000..e69de29 diff --git a/plugin/src/main/resources/messages/storage.txt b/plugin/src/main/resources/messages/storage.txt new file mode 100644 index 0000000..b5721b3 --- /dev/null +++ b/plugin/src/main/resources/messages/storage.txt @@ -0,0 +1,8 @@ + +ZNPCsPlus v${version} Click to view the main help message'>[BACK] +Hover over any command for more info + + * /npc storage save + * /npc storage reload + * /npc storage import +