This repository has been archived by the owner on Aug 4, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
PrefixCommands.java
304 lines (298 loc) · 11.7 KB
/
PrefixCommands.java
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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
package de.xghostkillerx.colorme;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.entity.Player;
public class PrefixCommands implements CommandExecutor {
ColorMe plugin;
public PrefixCommands(ColorMe instance) {
plugin = instance;
}
// Commands for prefixing
public boolean onCommand (CommandSender sender, Command command, String commandLabel, String[] args) {
String message, globalPrefix, target, senderName, prefix = "", pluginPart = "prefix", world = "default";
// Reloads the configs
if (args.length > 0 && args[0].equalsIgnoreCase("reload")) {
if (sender.hasPermission("prefixer.reload")) {
Actions.reload(sender);
return true;
}
else {
message = ColorMe.localization.getString("permission_denied");
ColorMe.message(sender, null, message, null, null, null, null);
return true;
}
}
// Stop here if Prefixer is unwanted
if (ColorMe.config.getBoolean("Prefixer") == false) {
message = ColorMe.localization.getString("part_disabled");
ColorMe.message(sender, null, message, null, null, null, null);
return true;
}
// Displays the help
if (args.length > 0 && args[0].equalsIgnoreCase("help")) {
Actions.help(sender, "prefix");
return true;
}
// Sets the global prefix
if (args.length > 1 && args[0].equalsIgnoreCase("global")) {
globalPrefix = args[1];
if (sender.hasPermission("prefixer.global")) {
// If the prefixes are the same
if (globalPrefix.equalsIgnoreCase(Actions.getGlobal("prefix"))) {
message = ColorMe.localization.getString("same_prefix_global");
ColorMe.message(sender, null, message, null, null, null, null);
return true;
}
ColorMe.config.set("global_default.prefix", globalPrefix);
plugin.saveConfig();
message = ColorMe.localization.getString("changed_prefix_global");
ColorMe.message(sender, null, message, Actions.replaceThings(globalPrefix), null, null, null);
return true;
}
else {
message = ColorMe.localization.getString("permission_denied");
ColorMe.message(sender, null, message, null, null, null, null);
return true;
}
}
// Removes a prefix
if (args.length > 1 && args[0].equalsIgnoreCase("remove")) {
world = "default";
// Removes the global prefix
if (args[1].equalsIgnoreCase("global")) {
if (sender.hasPermission("prefixer.global")) {
// Trying to remove an empty global prefix
if (!Actions.hasGlobal("prefix")) {
message = ColorMe.localization.getString("no_prefix_global");
ColorMe.message(sender, null, message, null, null, null, null);
return true;
}
// Remove global prefix
Actions.removeGlobal("prefix");
message = ColorMe.localization.getString("removed_prefix_global");
ColorMe.message(sender, null, message, null, null, null, null);
return true;
}
// Deny access
else {
message = ColorMe.localization.getString("permission_denied");
ColorMe.message(sender, null, message, null, null, null, null);
return true;
}
}
target = args[1].toLowerCase();
// Support for "me" -> this is the senderName!
if (target.equalsIgnoreCase("me")) {
target = sender.getName().toLowerCase();
// Tell console only ingame command
if (sender instanceof ConsoleCommandSender) {
message = ColorMe.localization.getString("only_ingame");
ColorMe.message(sender, null, message, null, null, null, null);
return true;
}
}
senderName = sender.getName().toLowerCase();
if (args.length > 2) {
world = args[2].toLowerCase();
}
// Check for permission or self
if (sender.hasPermission("prefixer.remove") || Actions.self(sender, target)) {
// Trying to remove a prefix from a prefix-less player
if (((!Actions.has(target, world, pluginPart) && ColorMe.players.contains(target + "." + pluginPart + "." + world)))
|| !ColorMe.players.contains(target)) {
// Self
if (target.equalsIgnoreCase(senderName)) {
message = ColorMe.localization.getString("no_prefix_self");
ColorMe.message(sender, null, message, null, world, null, null);
return true;
}
// Other
message = ColorMe.localization.getString("no_prefix_other");
ColorMe.message(sender, null, message, null, world, target, null);
return true;
}
// Remove prefix
Actions.remove(target, world, pluginPart);
if (plugin.getServer().getPlayerExact(target) != null) {
// Notify player is online
Player player = plugin.getServer().getPlayerExact(target);
message = ColorMe.localization.getString("removed_prefix_self");
ColorMe.message(null, player, message, null, world, null, null);
}
// If player is offline just notify the sender
if (!target.equalsIgnoreCase(senderName)) {
message = ColorMe.localization.getString("removed_prefix_other");
ColorMe.message(sender, null, message, null, world, target, null);
return true;
}
return true;
}
// Deny access
else {
message = ColorMe.localization.getString("permission_denied");
ColorMe.message(sender, null, message, null, null, null, null);
return true;
}
}
// Gets a prefix
if (args.length > 1 && args[0].equalsIgnoreCase("get")) {
world = "default";
// Get the global prefix if set
if (args[1].equalsIgnoreCase("global")) {
if (sender.hasPermission("prefixer.global")) {
// Trying to get an empty global prefix
if (!Actions.hasGlobal("prefix")) {
message = ColorMe.localization.getString("no_prefix_global");
ColorMe.message(sender, null, message, null, null, null, null);
return true;
}
prefix = Actions.getGlobal("prefix");
message = ColorMe.localization.getString("get_prefix_global");
ColorMe.message(sender, null, message, Actions.replaceThings(prefix), null, null, null);
return true;
}
// Deny access
else {
message = ColorMe.localization.getString("permission_denied");
ColorMe.message(sender, null, message, null, null, null, null);
return true;
}
}
// If a player name is there, too
target = args[1].toLowerCase();
if (target.equalsIgnoreCase("me")) {
target = sender.getName().toLowerCase();
// Tell console only ingame command
if (sender instanceof ConsoleCommandSender) {
message = ColorMe.localization.getString("only_ingame");
ColorMe.message(sender, null, message, null, null, null, null);
return true;
}
}
senderName = sender.getName().toLowerCase();
if (args.length > 2) {
world = args[2].toLowerCase();
}
Actions.get(target, world, pluginPart);
// Check for permission or self
if (sender.hasPermission("prefixer.get") || Actions.self(sender, target)) {
// Trying to get a prefix from a prefix-less player
if (((!Actions.has(target, world, pluginPart) && ColorMe.players.contains(target)))
|| !ColorMe.players.contains(target)) {
// Self
if (target.equalsIgnoreCase(senderName)) {
message = ColorMe.localization.getString("no_prefix_self");
ColorMe.message(sender, null, message, null, world, null, null);
return true;
}
// Other
message = ColorMe.localization.getString("no_prefix_other");
ColorMe.message(sender, null, message, null, world, target, null);
return true;
}
// Gets prefix
if (target.equalsIgnoreCase(senderName)) {
message = ColorMe.localization.getString("get_prefix_self");
ColorMe.message(sender, null, message, Actions.replaceThings(prefix), world, null, null);
return true;
}
message = ColorMe.localization.getString("get_prefix_other");
ColorMe.message(sender, null, message, Actions.replaceThings(prefix), world, target, null);
return true;
}
// Deny access
else {
message = ColorMe.localization.getString("permission_denied");
ColorMe.message(sender, null, message, null, null, null, null);
return true;
}
}
// Prefixing
if (args.length > 1) {
world = "default";
target = args[0].toLowerCase();
if (target.equalsIgnoreCase("me")) {
target = sender.getName().toLowerCase();
// Tell console only ingame command
if (sender instanceof ConsoleCommandSender) {
message = ColorMe.localization.getString("only_ingame");
ColorMe.message(sender, null, message, null, null, null, null);
return true;
}
}
prefix = args[1];
senderName = sender.getName().toLowerCase();
if (args.length > 2) {
world = args[2].toLowerCase();
}
// If the prefixes are the same
if (prefix.equalsIgnoreCase(Actions.get(target, world, pluginPart))) {
if (senderName.equalsIgnoreCase(target)) {
message = ColorMe.localization.getString("same_prefix_self");
ColorMe.message(sender, null, message, null, world, null, null);
return true;
}
message = ColorMe.localization.getString("same_prefix_other");
ColorMe.message(sender, null, message, null, world, target, null);
return true;
}
// Self prefixing
if (sender.hasPermission("prefixer.self") && Actions.self(sender, target)) {
// Without economy or costs are null
Double cost = ColorMe.config.getDouble("costs.prefix");
if (plugin.economy == null || cost == 0) {
Actions.set(senderName, prefix, world, pluginPart);
message = ColorMe.localization.getString("changed_prefix_self");
ColorMe.message(sender, null, message, Actions.replaceThings(prefix), world, null, null);
return true;
}
// With economy
else if (plugin.economy != null) {
// Charge costs :)
if (cost > 0 && plugin.economy.has(senderName, cost)) {
// Charge player unless he has the free permissions
if (!sender.hasPermission("prefixer.free")) plugin.economy.withdrawPlayer(senderName, cost);
// Set prefix an notify sender
Actions.set(senderName, prefix, world, pluginPart);
message = ColorMe.localization.getString("charged");
ColorMe.message(sender, null, message, null, null, null, cost);
message = ColorMe.localization.getString("changed_prefix_self");
ColorMe.message(sender, null, message, Actions.replaceThings(prefix), world, null, null);
return true;
}
// If player hasn't got enough money
else if (cost > 0 && plugin.economy.getBalance(senderName) < cost) {
message = ColorMe.localization.getString("not_enough_money_1");
ColorMe.message(sender, null, message, null, null, null, null);
message = ColorMe.localization.getString("not_enough_money_2");
ColorMe.message(sender, null, message, null, null, null, cost);
return true;
}
}
}
// Prefixing other
else if (sender.hasPermission("prefixer.other") && !Actions.self(sender, target)) {
// Set the new prefix
Actions.set(target, prefix, world, pluginPart);
if (plugin.getServer().getPlayerExact(target) != null) {
// Tell the affected player
Player player = plugin.getServer().getPlayerExact(target);
message = ColorMe.localization.getString("changed_prefix_self");
ColorMe.message(null, player, message, Actions.replaceThings(prefix), world, null, null);
}
message = ColorMe.localization.getString("changed_prefix_other");
ColorMe.message(sender, null, message, Actions.replaceThings(prefix), world, target, null);
return true;
}
// Permission check failed
else {
message = ColorMe.localization.getString("permission_denied");
ColorMe.message(sender, null, message, null, null, null, null);
return true;
}
}
return false;
}
}