forked from espidev/ProtectionStones
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArgAdminHelp.java
More file actions
216 lines (183 loc) · 9.18 KB
/
ArgAdminHelp.java
File metadata and controls
216 lines (183 loc) · 9.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
/*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package dev.espi.protectionstones.commands;
import dev.espi.protectionstones.ProtectionStones;
import net.md_5.bungee.api.chat.BaseComponent;
import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.HoverEvent;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
public class ArgAdminHelp {
// Provided helper method to generate a dot string.
private static String getDots(int num) {
StringBuilder str = new StringBuilder(" " + ChatColor.DARK_GRAY);
for (int i = 0; i < num; i++) {
str.append(".");
}
return str.toString();
}
/**
* Sends a help message to the sender with a right-aligned clickable tag.
* This version allows you to manually supply the exact number of dots.
*
* @param p The CommandSender.
* @param text The left-side command text (short form).
* @param info The detailed info for hover (contains full command usage).
* @param clickCommand The command to run or suggest (should be unformatted).
* @param run If true the tag will execute the command; if false it will suggest it.
* @param manualDots The manual number of dots (filler) to add before the tag.
*/
private static void send(CommandSender p, String text, String info, String clickCommand, boolean run, int manualDots) {
// Create the main text component from legacy text.
BaseComponent[] mainComponents = TextComponent.fromLegacyText(text);
TextComponent mainText = new TextComponent("");
for (BaseComponent component : mainComponents) {
mainText.addExtra(component);
}
// Determine the tag label.
String tagLabel = run ? "[Run]" : "[Prep]";
// Use the provided manual dot count.
String dotsString = getDots(manualDots);
// Create a dots component.
BaseComponent[] dotsComponents = TextComponent.fromLegacyText(dotsString);
TextComponent dotsText = new TextComponent("");
for (BaseComponent component : dotsComponents) {
dotsText.addExtra(component);
}
// Create the clickable tag component.
BaseComponent[] tagComponents = TextComponent.fromLegacyText(tagLabel);
TextComponent clickableComponent = new TextComponent("");
for (BaseComponent component : tagComponents) {
clickableComponent.addExtra(component);
}
// Create the hover event from the info text.
BaseComponent[] hoverComponents = TextComponent.fromLegacyText(info);
HoverEvent hoverEvent = new HoverEvent(HoverEvent.Action.SHOW_TEXT, hoverComponents);
// Set the same hover event on all parts.
mainText.setHoverEvent(hoverEvent);
dotsText.setHoverEvent(hoverEvent);
clickableComponent.setHoverEvent(hoverEvent);
// Setup the click event on the [Run/Prep] tag.
if (run) {
clickableComponent.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, ChatColor.stripColor(clickCommand)));
} else {
clickableComponent.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, ChatColor.stripColor(clickCommand)));
}
// Append the dots and clickable tag to the main text.
mainText.addExtra(dotsText);
mainText.addExtra(clickableComponent);
// Send the assembled message.
p.spigot().sendMessage(mainText);
}
static boolean argumentAdminHelp(CommandSender p, String[] args) {
String baseCommand = ProtectionStones.getInstance().getConfigOptions().base_command;
String bc = "/" + baseCommand;
String tx = ChatColor.AQUA + "> " + ChatColor.GRAY + bc;
// Display header as before.
p.sendMessage(ChatColor.DARK_GRAY + "" + ChatColor.STRIKETHROUGH + "===============" +
ChatColor.RESET + " PS Admin Help " +
ChatColor.DARK_GRAY + ChatColor.STRIKETHROUGH + "===============\n");
// Now you can manually supply each dot count.
send(p,
tx + " admin version",
"Show the version number of the plugin.\n\n" + bc + " admin version",
baseCommand + " admin version",
true, 61);
send(p,
tx + " admin hide",
"Hide all of the protection stone blocks in the world you are in.\n\n" + bc + " admin hide",
bc + " admin hide",
true, 70);
send(p,
tx + " admin unhide",
"Unhide all of the protection stone blocks in the world you are in.\n\n" + bc + " admin unhide",
bc + " admin unhide",
true, 64);
send(p,
tx + " admin cleanup remove",
"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" +
bc + " admin cleanup remove [days] [-t typealias (optional)] [world (console)]",
bc + " admin cleanup remove",
false, 39);
send(p,
tx + " admin cleanup disown",
"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" +
bc + " admin cleanup disown",
bc + " admin cleanup disown",
false, 41);
send(p,
tx + " admin flag",
"Set a flag for all protection stone regions in a world.\n\n" +
bc + " admin flag [world] [flagname] [value|null|default]",
bc + " admin flag [world] [flagname] [value|null|default]",
false, 69);
send(p,
tx + " admin lastlogon",
"Get the last time a player logged on.\n\n" + bc + " admin lastlogon [player]",
bc + " admin lastlogon",
false, 56);
send(p,
tx + " admin lastlogons",
"List all of the last logons of each player.\n\n" + bc + " admin lastlogons",
bc + " admin lastlogons",
true, 55);
send(p,
tx + " admin stats",
"Show some statistics of the plugin.\n\n" + bc + " admin stats [player (optional)]",
bc + " admin stats",
true, 68);
send(p,
tx + " admin recreate",
"Recreate all PS regions using radius set in config.\n\n" + bc + " admin recreate",
bc + " admin recreate",
true, 58);
send(p,
tx + " admin debug",
"Toggle debug mode.\n\n" + bc + " admin debug",
bc + " admin debug",
false, 64);
send(p,
tx + " admin settaxautopayers",
"Add a tax autopayer for every region on the server that does not have one.\n\n" + bc + " admin settaxautopayers",
bc + " admin settaxautopayers",
false, 34);
send(p,
tx + " admin forcemerge",
"Merge overlapping PS regions together if they have the same owners, members and flags.\n\n" +
bc + " admin forcemerge [world]",
bc + " admin forcemerge [world]",
true, 52);
send(p,
tx + " admin changeblock",
"Change all of the PS blocks and regions in a world to a different block. Both blocks must be configured in config.\n\n" +
bc + " admin changeblock [world] [oldtypealias] [newtypealias]",
bc + " admin changeblock [world] [oldtypealias] [newtypealias]",
false, 49);
send(p,
tx + " admin changeregiontype",
"Change the internal type of all PS regions of a certain type. Useful for error correction.\n\n" +
bc + " admin changeregiontype [world] [oldtype] [newtype]",
bc + " admin changeregiontype [world] [oldtype] [newtype]",
false, 34);
send(p,
tx + " admin fixregions",
"Use this command to recalculate block types for PS regions in a world.\n\n" + bc + " admin fixregions",
bc + " admin fixregions",
true, 56);
p.sendMessage(ChatColor.DARK_GRAY + "" + ChatColor.STRIKETHROUGH + "=============================================");
return true;
}
}