set up system for command hovers
This commit is contained in:
		
							parent
							
								
									93c6a42124
								
							
						
					
					
						commit
						5ef94c09a4
					
				
					 42 changed files with 87 additions and 71 deletions
				
			
		|  | @ -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<CommandContext> 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); | ||||
|     } | ||||
| 
 | ||||
|  |  | |||
|  | @ -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) { | ||||
|  |  | |||
|  | @ -1,10 +0,0 @@ | |||
| 
 | ||||
| <gold>ZNPCsPlus <yellow>v${version} <red><click:run_command:/npc><hover:show_text:'<red>Click to view the main help message'>[BACK]</hover></click></red> | ||||
| <gray>Hover over any command for more info | ||||
| 
 | ||||
|  <gold>* <yellow>/npc action add <type> <id> <args> | ||||
|  <gold>* <yellow>/npc action clear <id> | ||||
|  <gold>* <yellow>/npc action delete <id> <index> | ||||
|  <gold>* <yellow>/npc action edit <id> <index> <type> <args> | ||||
|  <gold>* <yellow>/npc action list <id> | ||||
| 
 | ||||
|  | @ -1,11 +0,0 @@ | |||
| 
 | ||||
| <gold>ZNPCsPlus <yellow>v${version} <red><click:run_command:/npc><hover:show_text:'<red>Click to view the main help message'>[BACK]</hover></click></red> | ||||
| <gray>Hover over any command more info | ||||
| 
 | ||||
|  <gold>* <yellow>/npc holo add <id> <text> | ||||
|  <gold>* <yellow>/npc holo delete <id> <line> | ||||
|  <gold>* <yellow>/npc holo set <id> <line> <text> | ||||
|  <gold>* <yellow>/npc holo insert <id> <line> <text> | ||||
|  <gold>* <yellow>/npc holo offset <id> <amount> | ||||
|  <gold>* <yellow>/npc holo info <id> | ||||
| 
 | ||||
|  | @ -1,7 +0,0 @@ | |||
| 
 | ||||
| <gold>ZNPCsPlus <yellow>v${version} <red><click:run_command:/npc><hover:show_text:'<red>Click to view the main help message'>[BACK]</hover></click></red> | ||||
| <gray>Hover over any command more info | ||||
| 
 | ||||
|  <gold>* <yellow>/npc property set <id> <property> <value> | ||||
|  <gold>* <yellow>/npc property remove <id> <property> | ||||
| 
 | ||||
|  | @ -1,26 +0,0 @@ | |||
| 
 | ||||
| <gold>ZNPCsPlus <yellow>v${version} | ||||
| <gray>Hover over any command for more info | ||||
| 
 | ||||
|  <gold>* <yellow>/npc create <id> <type> | ||||
|  <gold>* <yellow>/npc delete <id> | ||||
|  <gold>* <yellow>/npc changeid <old> <new> | ||||
|  <gold>* <yellow>/npc toggle <id> | ||||
|  <gold>* <yellow>/npc list | ||||
|  <gold>* <yellow>/npc type <id> <type> | ||||
| 
 | ||||
|  <gold>* <yellow>/npc near <distance> | ||||
|  <gold>* <yellow>/npc center <id> | ||||
|  <gold>* <yellow>/npc lookatme <id> | ||||
|  <gold>* <yellow>/npc setlocation <id> <x> <y> <z> | ||||
|  <gold>* <yellow>/npc setrotation <id> <yaw> <pitch> | ||||
|  <gold>* <yellow>/npc move <id> | ||||
|  <gold>* <yellow>/npc teleport <id> | ||||
| 
 | ||||
|  <gold>* <yellow>/npc skin <id> <type> <args> | ||||
| 
 | ||||
|  <gold>* <yellow><click:run_command:/npc property><hover:show_text:'<gray>Npc property commands<br>Click to view full list'>/npc property help</hover></click> | ||||
|  <gold>* <yellow><click:run_command:/npc holo><hover:show_text:'<gray>Npc hologram commands<br>Click to view full list'>/npc holo help</hover></click> | ||||
|  <gold>* <yellow><click:run_command:/npc action><hover:show_text:'<gray>Player interaction commands<br>Click to view full list'>/npc action help</hover></click> | ||||
|  <gold>* <yellow><click:run_command:/npc storage><hover:show_text:'<gray>Npc data storage commands<br>Click to view full list'>/npc storage help</hover></click> | ||||
| 
 | ||||
|  | @ -1,8 +0,0 @@ | |||
| 
 | ||||
| <gold>ZNPCsPlus <yellow>v${version} <red><click:run_command:/npc><hover:show_text:'<red>Click to view the main help message'>[BACK]</hover></click></red> | ||||
| <gray>Hover over any command for more info | ||||
| 
 | ||||
|  <gold>* <yellow>/npc storage save | ||||
|  <gold>* <yellow>/npc storage reload | ||||
|  <gold>* <yellow>/npc storage import <importer> | ||||
| 
 | ||||
							
								
								
									
										0
									
								
								plugin/src/main/resources/messages/action-hover/add.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								plugin/src/main/resources/messages/action-hover/add.txt
									
									
									
									
									
										Normal file
									
								
							
							
								
								
									
										0
									
								
								plugin/src/main/resources/messages/action-hover/edit.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								plugin/src/main/resources/messages/action-hover/edit.txt
									
									
									
									
									
										Normal file
									
								
							
							
								
								
									
										0
									
								
								plugin/src/main/resources/messages/action-hover/list.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								plugin/src/main/resources/messages/action-hover/list.txt
									
									
									
									
									
										Normal file
									
								
							
							
								
								
									
										10
									
								
								plugin/src/main/resources/messages/action.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								plugin/src/main/resources/messages/action.txt
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,10 @@ | |||
| 
 | ||||
| <gold>ZNPCsPlus <yellow>v${version} <red><click:run_command:/npc><hover:show_text:'<red>Click to view the main help message'>[BACK]</hover></click></red> | ||||
| <gray>Hover over any command for more info | ||||
| 
 | ||||
|  <hover:show_text:'{@action-hover/add}'><gold>* <yellow>/npc action add <type> <id> <args></hover> | ||||
|  <hover:show_text:'{@action-hover/clear}'><gold>* <yellow>/npc action clear <id></hover> | ||||
|  <hover:show_text:'{@action-hover/delete}'><gold>* <yellow>/npc action delete <id> <index></hover> | ||||
|  <hover:show_text:'{@action-hover/edit}'><gold>* <yellow>/npc action edit <id> <index> <type> <args></hover> | ||||
|  <hover:show_text:'{@action-hover/list}'><gold>* <yellow>/npc action list <id></hover> | ||||
| 
 | ||||
							
								
								
									
										0
									
								
								plugin/src/main/resources/messages/holo-hover/add.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								plugin/src/main/resources/messages/holo-hover/add.txt
									
									
									
									
									
										Normal file
									
								
							
							
								
								
									
										0
									
								
								plugin/src/main/resources/messages/holo-hover/delete.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								plugin/src/main/resources/messages/holo-hover/delete.txt
									
									
									
									
									
										Normal file
									
								
							
							
								
								
									
										0
									
								
								plugin/src/main/resources/messages/holo-hover/info.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								plugin/src/main/resources/messages/holo-hover/info.txt
									
									
									
									
									
										Normal file
									
								
							
							
								
								
									
										0
									
								
								plugin/src/main/resources/messages/holo-hover/insert.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								plugin/src/main/resources/messages/holo-hover/insert.txt
									
									
									
									
									
										Normal file
									
								
							
							
								
								
									
										0
									
								
								plugin/src/main/resources/messages/holo-hover/offset.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								plugin/src/main/resources/messages/holo-hover/offset.txt
									
									
									
									
									
										Normal file
									
								
							
							
								
								
									
										0
									
								
								plugin/src/main/resources/messages/holo-hover/set.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								plugin/src/main/resources/messages/holo-hover/set.txt
									
									
									
									
									
										Normal file
									
								
							
							
								
								
									
										11
									
								
								plugin/src/main/resources/messages/holo.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								plugin/src/main/resources/messages/holo.txt
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,11 @@ | |||
| 
 | ||||
| <gold>ZNPCsPlus <yellow>v${version} <red><click:run_command:/npc><hover:show_text:'<red>Click to view the main help message'>[BACK]</hover></click></red> | ||||
| <gray>Hover over any command more info | ||||
| 
 | ||||
|  <hover:show_text:'{@holo-hover/add}'><gold>* <yellow>/npc holo add <id> <text></hover> | ||||
|  <hover:show_text:'{@holo-hover/delete}'><gold>* <yellow>/npc holo delete <id> <line></hover> | ||||
|  <hover:show_text:'{@holo-hover/set}'><gold>* <yellow>/npc holo set <id> <line> <text></hover> | ||||
|  <hover:show_text:'{@holo-hover/insert}'><gold>* <yellow>/npc holo insert <id> <line> <text></hover> | ||||
|  <hover:show_text:'{@holo-hover/offset}'><gold>* <yellow>/npc holo offset <id> <amount></hover> | ||||
|  <hover:show_text:'{@holo-hover/info}'><gold>* <yellow>/npc holo info <id></hover> | ||||
| 
 | ||||
							
								
								
									
										7
									
								
								plugin/src/main/resources/messages/property.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								plugin/src/main/resources/messages/property.txt
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,7 @@ | |||
| 
 | ||||
| <gold>ZNPCsPlus <yellow>v${version} <red><click:run_command:/npc><hover:show_text:'<red>Click to view the main help message'>[BACK]</hover></click></red> | ||||
| <gray>Hover over any command more info | ||||
| 
 | ||||
|  <hover:show_text:'{@property-hover/set}'><gold>* <yellow>/npc property set <id> <property> <value></hover> | ||||
|  <hover:show_text:'{@property-hover/remove}'><gold>* <yellow>/npc property remove <id> <property></hover> | ||||
| 
 | ||||
							
								
								
									
										0
									
								
								plugin/src/main/resources/messages/root-hover/center.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								plugin/src/main/resources/messages/root-hover/center.txt
									
									
									
									
									
										Normal file
									
								
							
							
								
								
									
										0
									
								
								plugin/src/main/resources/messages/root-hover/create.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								plugin/src/main/resources/messages/root-hover/create.txt
									
									
									
									
									
										Normal file
									
								
							
							
								
								
									
										0
									
								
								plugin/src/main/resources/messages/root-hover/delete.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								plugin/src/main/resources/messages/root-hover/delete.txt
									
									
									
									
									
										Normal file
									
								
							
							
								
								
									
										0
									
								
								plugin/src/main/resources/messages/root-hover/list.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								plugin/src/main/resources/messages/root-hover/list.txt
									
									
									
									
									
										Normal file
									
								
							
							
								
								
									
										0
									
								
								plugin/src/main/resources/messages/root-hover/move.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								plugin/src/main/resources/messages/root-hover/move.txt
									
									
									
									
									
										Normal file
									
								
							
							
								
								
									
										0
									
								
								plugin/src/main/resources/messages/root-hover/near.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								plugin/src/main/resources/messages/root-hover/near.txt
									
									
									
									
									
										Normal file
									
								
							
							
								
								
									
										0
									
								
								plugin/src/main/resources/messages/root-hover/skin.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								plugin/src/main/resources/messages/root-hover/skin.txt
									
									
									
									
									
										Normal file
									
								
							
							
								
								
									
										0
									
								
								plugin/src/main/resources/messages/root-hover/toggle.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								plugin/src/main/resources/messages/root-hover/toggle.txt
									
									
									
									
									
										Normal file
									
								
							
							
								
								
									
										0
									
								
								plugin/src/main/resources/messages/root-hover/type.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								plugin/src/main/resources/messages/root-hover/type.txt
									
									
									
									
									
										Normal file
									
								
							
							
								
								
									
										26
									
								
								plugin/src/main/resources/messages/root.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								plugin/src/main/resources/messages/root.txt
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,26 @@ | |||
| 
 | ||||
| <gold>ZNPCsPlus <yellow>v${version} | ||||
| <gray>Hover over any command for more info | ||||
| 
 | ||||
|  <hover:show_text:'{@root-hover/create}'><gold>* <yellow>/npc create <id> <type></hover> | ||||
|  <hover:show_text:'{@root-hover/delete}'><gold>* <yellow>/npc delete <id></hover> | ||||
|  <hover:show_text:'{@root-hover/changeid}'><gold>* <yellow>/npc changeid <old> <new></hover> | ||||
|  <hover:show_text:'{@root-hover/toggle}'><gold>* <yellow>/npc toggle <id></hover> | ||||
|  <hover:show_text:'{@root-hover/list}'><gold>* <yellow>/npc list</hover> | ||||
|  <hover:show_text:'{@root-hover/type}'><gold>* <yellow>/npc type <id> <type></hover> | ||||
| 
 | ||||
|  <hover:show_text:'{@root-hover/near}'><gold>* <yellow>/npc near <distance></hover> | ||||
|  <hover:show_text:'{@root-hover/center}'><gold>* <yellow>/npc center <id></hover> | ||||
|  <hover:show_text:'{@root-hover/lookatme}'><gold>* <yellow>/npc lookatme <id></hover> | ||||
|  <hover:show_text:'{@root-hover/setlocation}'><gold>* <yellow>/npc setlocation <id> <x> <y> <z></hover> | ||||
|  <hover:show_text:'{@root-hover/setrotation}'><gold>* <yellow>/npc setrotation <id> <yaw> <pitch></hover> | ||||
|  <hover:show_text:'{@root-hover/move}'><gold>* <yellow>/npc move <id></hover> | ||||
|  <hover:show_text:'{@root-hover/teleport}'><gold>* <yellow>/npc teleport <id></hover> | ||||
| 
 | ||||
|  <hover:show_text:'{@root-hover/skin}'><gold>* <yellow>/npc skin <id> <type> <args></hover> | ||||
| 
 | ||||
|  <gold>* <yellow><click:run_command:/npc property><hover:show_text:'<gray>Npc property commands<br>Click to view full list'>/npc property help</hover></click> | ||||
|  <gold>* <yellow><click:run_command:/npc holo><hover:show_text:'<gray>Npc hologram commands<br>Click to view full list'>/npc holo help</hover></click> | ||||
|  <gold>* <yellow><click:run_command:/npc action><hover:show_text:'<gray>Player interaction commands<br>Click to view full list'>/npc action help</hover></click> | ||||
|  <gold>* <yellow><click:run_command:/npc storage><hover:show_text:'<gray>Npc data storage commands<br>Click to view full list'>/npc storage help</hover></click> | ||||
| 
 | ||||
							
								
								
									
										8
									
								
								plugin/src/main/resources/messages/storage.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								plugin/src/main/resources/messages/storage.txt
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,8 @@ | |||
| 
 | ||||
| <gold>ZNPCsPlus <yellow>v${version} <red><click:run_command:/npc><hover:show_text:'<red>Click to view the main help message'>[BACK]</hover></click></red> | ||||
| <gray>Hover over any command for more info | ||||
| 
 | ||||
|  <hover:show_text:'{@storage-hover/save}'><gold>* <yellow>/npc storage save</hover> | ||||
|  <hover:show_text:'{@storage-hover/reload}'><gold>* <yellow>/npc storage reload</hover> | ||||
|  <hover:show_text:'{@storage-hover/import}'><gold>* <yellow>/npc storage import <importer></hover> | ||||
| 
 | ||||
		Loading…
	
		Reference in a new issue