|
16 | 16 | package dev.espi.protectionstones.commands; |
17 | 17 |
|
18 | 18 | import dev.espi.protectionstones.ProtectionStones; |
19 | | -import net.md_5.bungee.api.chat.ComponentBuilder; |
| 19 | +import net.md_5.bungee.api.chat.BaseComponent; |
| 20 | +import net.md_5.bungee.api.chat.ClickEvent; |
20 | 21 | import net.md_5.bungee.api.chat.HoverEvent; |
21 | 22 | import net.md_5.bungee.api.chat.TextComponent; |
22 | 23 | import org.bukkit.ChatColor; |
23 | 24 | import org.bukkit.command.CommandSender; |
24 | 25 |
|
25 | 26 | public class ArgAdminHelp { |
26 | 27 |
|
27 | | - private static void send(CommandSender p, String text, String info) { |
28 | | - TextComponent tc = new TextComponent(text); |
29 | | - tc.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(info).create())); |
30 | | - p.spigot().sendMessage(tc); |
| 28 | + private static void send(CommandSender p, String text, String info, String clickCommand, boolean run) { |
| 29 | + // Create the main text component from legacy text. |
| 30 | + BaseComponent[] mainComponents = TextComponent.fromLegacyText(text); |
| 31 | + TextComponent mainText = new TextComponent(""); |
| 32 | + for (BaseComponent component : mainComponents) { |
| 33 | + mainText.addExtra(component); |
| 34 | + } |
| 35 | + |
| 36 | + // Create the hover event from the info text, add click event after |
| 37 | + BaseComponent[] hoverComponents = TextComponent.fromLegacyText(info); |
| 38 | + mainText.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, hoverComponents)); |
| 39 | + //toggle for running on mouse click, currently disabled |
| 40 | + if (run) { |
| 41 | + mainText.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, ChatColor.stripColor(clickCommand))); |
| 42 | + } else { |
| 43 | + mainText.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, ChatColor.stripColor(clickCommand))); |
| 44 | + } |
| 45 | + |
| 46 | + // Send the assembled message. |
| 47 | + p.spigot().sendMessage(mainText); |
31 | 48 | } |
32 | 49 |
|
33 | 50 | static boolean argumentAdminHelp(CommandSender p, String[] args) { |
34 | | - String bc = "/" + ProtectionStones.getInstance().getConfigOptions().base_command; |
35 | | - |
36 | | - p.sendMessage(ChatColor.DARK_GRAY + "" + ChatColor.STRIKETHROUGH + "=====" + ChatColor.RESET + " PS Admin Help " + ChatColor.DARK_GRAY + ChatColor.STRIKETHROUGH + "=====\n" + ChatColor.AQUA + "> " + ChatColor.GRAY + "/ps admin help"); |
37 | | - send(p, ChatColor.AQUA + "> " + ChatColor.GRAY + bc + " admin version", "Show the version number of the plugin."); |
38 | | - send(p, ChatColor.AQUA + "> " + ChatColor.GRAY + bc + " admin hide", "Hide all of the protection stone blocks in the world you are in."); |
39 | | - send(p, ChatColor.AQUA + "> " + ChatColor.GRAY + bc + " admin unhide", "Unhide all of the protection stone blocks in the world you are in."); |
40 | | - send(p, ChatColor.AQUA + "> " + ChatColor.GRAY + bc + " admin cleanup remove [days] [-t typealias (optional)] [world (console)]", "Remove inactive players that haven't joined within the last [days] days from protected regions in the world you are in (or specified). Then, remove any regions with no owners left."); |
41 | | - send(p, ChatColor.AQUA + "> " + ChatColor.GRAY + bc + " admin cleanup disown [days] [-t typealias (optional)] [world (console)]", "Remove inactive players that haven't joined within the last [days] days from protected regions in the world you are in (or specified)."); |
42 | | - send(p, ArgAdmin.getFlagHelp(), "Set a flag for all protection stone regions in a world."); |
43 | | - send(p, ChatColor.AQUA + "> " + ChatColor.GRAY + bc + " admin lastlogon [player]", "Get the last time a player logged on."); |
44 | | - send(p, ChatColor.AQUA + "> " + ChatColor.GRAY + bc + " admin lastlogons", "List all of the last logons of each player."); |
45 | | - send(p, ChatColor.AQUA + "> " + ChatColor.GRAY + bc + " admin stats [player (optional)]", "Show some statistics of the plugin."); |
46 | | - send(p, ChatColor.AQUA + "> " + ChatColor.GRAY + bc + " admin recreate", "Recreate all PS regions using radius set in config."); |
47 | | - send(p, ChatColor.AQUA + "> " + ChatColor.GRAY + bc + " admin debug", "Toggles debug mode."); |
48 | | - send(p, ChatColor.AQUA + "> " + ChatColor.GRAY + bc + " admin settaxautopayers", "Add a tax autopayer for every region on the server that does not have one."); |
49 | | - send(p, ArgAdmin.getForceMergeHelp(), "Merge overlapping PS regions together if they have the same owners, members and flags."); |
50 | | - send(p, ArgAdmin.getChangeBlockHelp(), "Change all of the PS blocks and regions in a world to a different block. Both blocks must be configured in config."); |
51 | | - send(p, ArgAdmin.getChangeRegionTypeHelp(), "Change the internal type of all PS regions of a certain type. Useful for error correction."); |
52 | | - send(p, ChatColor.AQUA + "> " + ChatColor.GRAY + bc + " admin fixregions", "Use this command to recalculate block types for PS regions in a world."); |
| 51 | + String baseCommand = ProtectionStones.getInstance().getConfigOptions().base_command; |
| 52 | + String bc = "/" + baseCommand; |
| 53 | + String tx = ChatColor.AQUA + "> " + ChatColor.GRAY + "/" + bc; |
| 54 | + |
| 55 | + p.sendMessage(ChatColor.DARK_GRAY + "" + ChatColor.STRIKETHROUGH + "===============" + |
| 56 | + ChatColor.RESET + " PS Admin Help " + |
| 57 | + ChatColor.DARK_GRAY + ChatColor.STRIKETHROUGH + "===============\n"); |
| 58 | + |
| 59 | + send(p, |
| 60 | + tx + " admin version", |
| 61 | + "Show the version number of the plugin.\n\n" + bc + " admin version", |
| 62 | + baseCommand + " admin version", |
| 63 | + false); |
| 64 | + |
| 65 | + send(p, |
| 66 | + tx + " admin hide", |
| 67 | + "Hide all of the protection stone blocks in the world you are in.\n\n" + bc + " admin hide", |
| 68 | + bc + " admin hide", |
| 69 | + false); |
| 70 | + |
| 71 | + send(p, |
| 72 | + tx + " admin unhide", |
| 73 | + "Unhide all of the protection stone blocks in the world you are in.\n\n" + bc + " admin unhide", |
| 74 | + bc + " admin unhide", |
| 75 | + false); |
| 76 | + |
| 77 | + send(p, |
| 78 | + tx + " admin cleanup remove", |
| 79 | + "Remove inactive players that haven't joined within the last [days] days from protected regions in the world you are in (or specified). Then, remove any regions with no owners left.\n\n" + |
| 80 | + bc + " admin cleanup remove [days] [-t typealias (optional)] [world (console)]", |
| 81 | + bc + " admin cleanup remove", |
| 82 | + false); |
| 83 | + |
| 84 | + send(p, |
| 85 | + tx + " admin cleanup disown", |
| 86 | + "Remove inactive players that haven't joined within the last [days] days from protected regions in the world you are in (or specified).\n\n" + |
| 87 | + bc + " admin cleanup disown", |
| 88 | + bc + " admin cleanup disown", |
| 89 | + false); |
| 90 | + |
| 91 | + send(p, |
| 92 | + tx + " admin flag", |
| 93 | + "Set a flag for all protection stone regions in a world.\n\n" + |
| 94 | + bc + " admin flag [world] [flagname] [value|null|default]", |
| 95 | + bc + " admin flag [world] [flagname] [value|null|default]", |
| 96 | + false); |
| 97 | + |
| 98 | + send(p, |
| 99 | + tx + " admin lastlogon", |
| 100 | + "Get the last time a player logged on.\n\n" + bc + " admin lastlogon [player]", |
| 101 | + bc + " admin lastlogon", |
| 102 | + false); |
| 103 | + |
| 104 | + send(p, |
| 105 | + tx + " admin lastlogons", |
| 106 | + "List all of the last logons of each player.\n\n" + bc + " admin lastlogons", |
| 107 | + bc + " admin lastlogons", |
| 108 | + false); |
| 109 | + |
| 110 | + send(p, |
| 111 | + tx + " admin stats", |
| 112 | + "Show some statistics of the plugin.\n\n" + bc + " admin stats [player (optional)]", |
| 113 | + bc + " admin stats", |
| 114 | + false); |
| 115 | + |
| 116 | + send(p, |
| 117 | + tx + " admin recreate", |
| 118 | + "Recreate all PS regions using radius set in config.\n\n" + bc + " admin recreate", |
| 119 | + bc + " admin recreate", |
| 120 | + false); |
| 121 | + |
| 122 | + send(p, |
| 123 | + tx + " admin debug", |
| 124 | + "Toggle debug mode.\n\n" + bc + " admin debug", |
| 125 | + bc + " admin debug", |
| 126 | + false); |
| 127 | + |
| 128 | + send(p, |
| 129 | + tx + " admin settaxautopayers", |
| 130 | + "Add a tax autopayer for every region on the server that does not have one.\n\n" + bc + " admin settaxautopayers", |
| 131 | + bc + " admin settaxautopayers", |
| 132 | + false); |
| 133 | + |
| 134 | + send(p, |
| 135 | + tx + " admin forcemerge", |
| 136 | + "Merge overlapping PS regions together if they have the same owners, members and flags.\n\n" + |
| 137 | + bc + " admin forcemerge [world]", |
| 138 | + bc + " admin forcemerge [world]", |
| 139 | + false); |
| 140 | + |
| 141 | + send(p, |
| 142 | + tx + " admin changeblock", |
| 143 | + "Change all of the PS blocks and regions in a world to a different block. Both blocks must be configured in config.\n\n" + |
| 144 | + bc + " admin changeblock [world] [oldtypealias] [newtypealias]", |
| 145 | + bc + " admin changeblock [world] [oldtypealias] [newtypealias]", |
| 146 | + false); |
| 147 | + |
| 148 | + send(p, |
| 149 | + tx + " admin changeregiontype", |
| 150 | + "Change the internal type of all PS regions of a certain type. Useful for error correction.\n\n" + |
| 151 | + bc + " admin changeregiontype [world] [oldtype] [newtype]", |
| 152 | + bc + " admin changeregiontype [world] [oldtype] [newtype]", |
| 153 | + false); |
| 154 | + |
| 155 | + send(p, |
| 156 | + tx + " admin fixregions", |
| 157 | + "Use this command to recalculate block types for PS regions in a world.\n\n" + bc + " admin fixregions", |
| 158 | + bc + " admin fixregions", |
| 159 | + false); |
| 160 | + //add footer since it was missing |
| 161 | + p.sendMessage(ChatColor.DARK_GRAY + "" + ChatColor.STRIKETHROUGH + "============================================="); |
53 | 162 |
|
54 | 163 | return true; |
55 | 164 | } |
|
0 commit comments