-
-
Notifications
You must be signed in to change notification settings - Fork 85
/
SentinelPlugin.java
547 lines (528 loc) · 27.5 KB
/
SentinelPlugin.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
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
package org.mcmonkey.sentinel;
import net.citizensnpcs.api.CitizensAPI;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.api.trait.TraitInfo;
import net.citizensnpcs.api.trait.trait.Owner;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
public class SentinelPlugin extends JavaPlugin {
public static final String ColorBasic = ChatColor.YELLOW.toString();
public static final String prefixGood = ChatColor.DARK_GREEN + "[Sentinel] " + ColorBasic;
public static final String prefixBad = ChatColor.DARK_GREEN + "[Sentinel] " + ChatColor.RED;
static HashMap<String, SentinelTarget> targetOptions = new HashMap<String, SentinelTarget>();
static HashMap<EntityType, HashSet<SentinelTarget>> entityToTargets = new HashMap<EntityType, HashSet<SentinelTarget>>();
public static SentinelPlugin instance;
public int tickRate = 10;
static {
for (EntityType type: EntityType.values()) {
entityToTargets.put(type, new HashSet<SentinelTarget>());
}
}
@Override
public void onEnable() {
getLogger().info("Sentinel loading...");
instance = this;
CitizensAPI.getTraitFactory().registerTrait(TraitInfo.create(SentinelTrait.class).withName("sentinel"));
saveDefaultConfig();
if (getConfig().getInt("config version", 0) != 1) {
getLogger().warning("Outdated Sentinel config - please delete it to regenerate it!");
}
tickRate = getConfig().getInt("update rate", 10);
getLogger().info("Sentinel loaded!");
}
@Override
public void onDisable() {
getLogger().info("Sentinel unloading...");
getLogger().info("Sentinel unloaded!");
}
public SentinelTrait getSentinelFor(CommandSender sender) {
NPC npc = CitizensAPI.getDefaultNPCSelector().getSelected(sender);
if (npc == null) {
return null;
}
if (npc.hasTrait(SentinelTrait.class)) {
return npc.getTrait(SentinelTrait.class);
}
return null;
}
private long ignoreMe = 0;
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
String arg0 = args.length > 0 ? args[0].toLowerCase(): "help";
SentinelTrait sentinel = getSentinelFor(sender);
if (sentinel == null && !arg0.equals("help")) {
sender.sendMessage(prefixBad + "Must have an NPC selected!");
return true;
}
else if (arg0.equals("addtarget") && sender.hasPermission("sentinel.addtarget") && args.length > 1) {
SentinelTarget target = SentinelTarget.forName(args[1].toUpperCase());
if (target == null) {
String[] info = args[1].split(":", 2);
if (info.length > 1) {
List<String> names = null;
if (info[0].equalsIgnoreCase("player")) {
names = sentinel.playerNameTargets;
}
else if (info[0].equalsIgnoreCase("npc")) {
names = sentinel.npcNameTargets;
}
else if (info[0].equalsIgnoreCase("entityname")) {
names = sentinel.entityNameTargets;
}
else if (info[0].equalsIgnoreCase("helditem")) {
names = sentinel.heldItemTargets;
}
try {
if ("Sentinel".matches(info[1])) {
ignoreMe++;
}
}
catch (Exception e) {
names = null;
sender.sendMessage(prefixBad + "Bad regular expression!");
}
if (names != null) {
if (names.contains(info[1])) {
sender.sendMessage(prefixBad + "Already tracking that name target!");
}
else {
names.add(info[1]);
sender.sendMessage(prefixGood + "Tracking new target!");
}
return true;
}
}
sender.sendMessage(prefixBad + "Invalid target!");
StringBuilder valid = new StringBuilder();
for (SentinelTarget poss: SentinelTarget.values()) {
valid.append(poss.name()).append(", ");
}
sender.sendMessage(prefixGood + "Valid targets: " + valid.substring(0, valid.length() - 2));
sender.sendMessage(prefixGood + "Also allowed: player:NAME(REGEX), npc:NAME(REGEX), entityname:NAME(REGEX), helditem:MATERIALNAME(REGEX)");
}
else {
if (sentinel.targets.add(target)) {
sender.sendMessage(prefixGood + "Target added!");
}
else {
sender.sendMessage(prefixBad + "Target already added!");
}
}
return true;
}
else if (arg0.equals("removetarget") && sender.hasPermission("sentinel.removetarget") && args.length > 1) {
SentinelTarget target = SentinelTarget.forName(args[1].toUpperCase());
if (target == null) {
String[] info = args[1].split(":", 2);
if (info.length > 1) {
List<String> names = null;
if (info[0].equalsIgnoreCase("player")) {
names = sentinel.playerNameTargets;
}
else if (info[0].equalsIgnoreCase("npc")) {
names = sentinel.npcNameTargets;
}
else if (info[0].equalsIgnoreCase("entityname")) {
names = sentinel.entityNameTargets;
}
else if (info[0].equalsIgnoreCase("helditem")) {
names = sentinel.heldItemTargets;
}
try {
if ("Sentinel".matches(info[1])) {
ignoreMe++;
}
}
catch (Exception e) {
names = null;
sender.sendMessage(prefixBad + "Bad regular expression!");
}
if (names != null) {
if (!names.remove(info[1])) {
sender.sendMessage(prefixBad + "Not tracking that name target!");
}
else {
sender.sendMessage(prefixGood + "No longer tracking that target!");
}
return true;
}
}
sender.sendMessage(prefixBad + "Invalid target!");
sender.sendMessage(prefixGood + "See '/sentinel addtarget help' to view valid targets!");
}
else {
if (sentinel.targets.remove(target)) {
sender.sendMessage(prefixGood + "Target removed!");
}
else {
sender.sendMessage(prefixBad + "Target not added!");
}
}
return true;
}
else if (arg0.equals("addignore") && sender.hasPermission("sentinel.addignore") && args.length > 1) {
SentinelTarget target = SentinelTarget.forName(args[1].toUpperCase());
if (target == null) {
String[] info = args[1].split(":", 2);
if (info.length > 1) {
List<String> names = null;
if (info[0].equalsIgnoreCase("player")) {
names = sentinel.playerNameIgnores;
}
else if (info[0].equalsIgnoreCase("npc")) {
names = sentinel.npcNameIgnores;
}
else if (info[0].equalsIgnoreCase("entityname")) {
names = sentinel.entityNameIgnores;
}
else if (info[0].equalsIgnoreCase("helditem")) {
names = sentinel.heldItemIgnores;
}
try {
if ("Sentinel".matches(info[1])) {
ignoreMe++;
}
}
catch (Exception e) {
names = null;
sender.sendMessage(prefixBad + "Bad regular expression!");
}
if (names != null) {
if (!names.contains(info[1])) {
sender.sendMessage(prefixBad + "Already ignoring that name target!");
}
else {
names.add(info[1]);
sender.sendMessage(prefixGood + "Ignoring new target!");
}
return true;
}
}
sender.sendMessage(prefixBad + "Invalid ignore target!");
sender.sendMessage(prefixGood + "See '/sentinel addtarget help' to view valid targets!");
}
else {
if (sentinel.ignores.add(target)) {
sender.sendMessage(prefixGood + "Ignore added!");
}
else {
sender.sendMessage(prefixBad + "Ignore already added!");
}
}
return true;
}
else if (arg0.equals("removeignore") && sender.hasPermission("sentinel.removeignore") && args.length > 1) {
SentinelTarget target = SentinelTarget.forName(args[1].toUpperCase());
if (target == null) {
String[] info = args[1].split(":", 2);
if (info.length > 1) {
List<String> names = null;
if (info[0].equalsIgnoreCase("player")) {
names = sentinel.playerNameIgnores;
}
else if (info[0].equalsIgnoreCase("npc")) {
names = sentinel.npcNameIgnores;
}
else if (info[0].equalsIgnoreCase("entityname")) {
names = sentinel.entityNameIgnores;
}
else if (info[0].equalsIgnoreCase("helditem")) {
names = sentinel.heldItemIgnores;
}
try {
if ("Sentinel".matches(info[1])) {
ignoreMe++;
}
}
catch (Exception e) {
names = null;
sender.sendMessage(prefixBad + "Bad regular expression!");
}
if (names != null) {
if (!names.remove(info[1])) {
sender.sendMessage(prefixBad + "Was not ignoring that name target!");
}
else {
sender.sendMessage(prefixGood + "Not ignoring that target along longer!");
}
return true;
}
}
sender.sendMessage(prefixBad + "Invalid ignore target!");
sender.sendMessage(prefixGood + "See '/sentinel addtarget help' to view valid targets!");
}
else {
if (sentinel.ignores.remove(target)) {
sender.sendMessage(prefixGood + "Ignore removed!");
}
else {
sender.sendMessage(prefixBad + "Ignore not added!");
}
}
return true;
}
else if (arg0.equals("range") && sender.hasPermission("sentinel.range") && args.length > 1) {
try {
Double d = Double.valueOf(args[1]);
if (d > 0 && d < 200) {
sentinel.range = d;
sender.sendMessage(prefixGood + "Range set!");
}
else {
throw new NumberFormatException("Number out or range.");
}
}
catch (NumberFormatException ex) {
sender.sendMessage(prefixBad + "Invalid range number!");
}
return true;
}
else if (arg0.equals("damage") && sender.hasPermission("sentinel.damage") && args.length > 1) {
try {
Double d = Double.valueOf(args[1]);
if (d < 1000) {
sentinel.damage = d;
sender.sendMessage(prefixGood + "Damage set!");
}
else {
throw new NumberFormatException("Number out or range.");
}
}
catch (NumberFormatException ex) {
sender.sendMessage(prefixBad + "Invalid damage number!");
}
return true;
}
else if (arg0.equals("armor") && sender.hasPermission("sentinel.armor") && args.length > 1) {
try {
Double d = Double.valueOf(args[1]);
if (d <= 1) {
sentinel.armor = d;
sender.sendMessage(prefixGood + "Armor set!");
}
else {
throw new NumberFormatException("Number out or range.");
}
}
catch (NumberFormatException ex) {
sender.sendMessage(prefixBad + "Invalid armor number!");
}
return true;
}
else if (arg0.equals("health") && sender.hasPermission("sentinel.health") && args.length > 1) {
try {
Double d = Double.valueOf(args[1]);
if (d <= 200) {
sentinel.setHealth(d);
sender.sendMessage(prefixGood + "Health set!");
}
else {
throw new NumberFormatException("Number out or range.");
}
}
catch (NumberFormatException ex) {
sender.sendMessage(prefixBad + "Invalid health number!");
}
return true;
}
else if (arg0.equals("attackrate") && sender.hasPermission("sentinel.attackrate") && args.length > 1) {
try {
int d = Integer.valueOf(args[1]);
if (d >= 10 && d <= 2000) {
sentinel.attackRate = d;
sender.sendMessage(prefixGood + "Attack rate set!");
}
else {
throw new NumberFormatException("Number out or range.");
}
}
catch (NumberFormatException ex) {
sender.sendMessage(prefixBad + "Invalid rate number!");
}
return true;
}
else if (arg0.equals("healrate") && sender.hasPermission("sentinel.healrate") && args.length > 1) {
try {
int d = Integer.valueOf(args[1]);
if (d >= 0 && d <= 2000) {
sentinel.healRate = d;
sender.sendMessage(prefixGood + "Heal rate set!");
}
else {
throw new NumberFormatException("Number out or range.");
}
}
catch (NumberFormatException ex) {
sender.sendMessage(prefixBad + "Invalid rate number!");
}
return true;
}
else if (arg0.equals("invincible") && sender.hasPermission("sentinel.invincible")) {
sentinel.setInvincible(!sentinel.invincible);
if (sentinel.invincible) {
sender.sendMessage(prefixGood + "NPC now invincible!");
}
else {
sender.sendMessage(prefixGood + "NPC no longer invincible!");
}
return true;
}
else if (arg0.equals("fightback") && sender.hasPermission("sentinel.fightback")) {
sentinel.fightback = !sentinel.fightback;
if (sentinel.fightback) {
sender.sendMessage(prefixGood + "NPC now fights back!");
}
else {
sender.sendMessage(prefixGood + "NPC no longer fights back!");
}
return true;
}
else if (arg0.equals("needammo") && sender.hasPermission("sentinel.needammo")) {
sentinel.needsAmmo = !sentinel.needsAmmo;
if (sentinel.needsAmmo) {
sender.sendMessage(prefixGood + "NPC now needs ammo!");
}
else {
sender.sendMessage(prefixGood + "NPC no longer needs ammo!");
}
return true;
}
else if (arg0.equals("chaseclose") && sender.hasPermission("sentinel.chase")) {
sentinel.closeChase = !sentinel.closeChase;
if (sentinel.closeChase) {
sender.sendMessage(prefixGood + "NPC now will chase while close!");
}
else {
sender.sendMessage(prefixGood + "NPC no longer will chase while close!");
}
return true;
}
else if (arg0.equals("chaseranged") && sender.hasPermission("sentinel.chase")) {
sentinel.rangedChase = !sentinel.rangedChase;
if (sentinel.rangedChase) {
sender.sendMessage(prefixGood + "NPC now will chase while ranged!");
}
else {
sender.sendMessage(prefixGood + "NPC no longer will chase while ranged!");
}
return true;
}
else if (arg0.equals("guard") && sender.hasPermission("sentinel.guard")) {
if (args.length > 1) {
Player pl = Bukkit.getPlayer(args[1]);
sentinel.setGuarding(pl == null ? null: pl.getUniqueId());
}
else {
sentinel.setGuarding(null);
}
if (sentinel.getGuarding() == null) {
sender.sendMessage(prefixGood + "NPC now guarding its area!");
}
else {
sender.sendMessage(prefixGood + "NPC now guarding that player!");
}
return true;
}
else if (arg0.equals("targets") && sender.hasPermission("sentinel.info")) {
sender.sendMessage(prefixGood + ChatColor.RESET + sentinel.getNPC().getFullName() + ColorBasic
+ ": owned by " + ChatColor.RESET + getOwner(sentinel.getNPC()));
sender.sendMessage(prefixGood + "Targets: " + ChatColor.AQUA + getTargetString(sentinel.targets));
sender.sendMessage(prefixGood + "Player Name Targets: " + ChatColor.AQUA + getNameTargetString(sentinel.playerNameTargets));
sender.sendMessage(prefixGood + "NPC Name Targets: " + ChatColor.AQUA + getNameTargetString(sentinel.npcNameTargets));
sender.sendMessage(prefixGood + "Entity Name Targets: " + ChatColor.AQUA + getNameTargetString(sentinel.entityNameTargets));
sender.sendMessage(prefixGood + "Held Item Targets: " + ChatColor.AQUA + getNameTargetString(sentinel.heldItemTargets));
sender.sendMessage(prefixGood + "Ignored Targets: " + ChatColor.AQUA + getTargetString(sentinel.ignores));
sender.sendMessage(prefixGood + "Ignored Player Name Targets: " + ChatColor.AQUA + getNameTargetString(sentinel.playerNameIgnores));
sender.sendMessage(prefixGood + "Ignored NPC Name Targets: " + ChatColor.AQUA + getNameTargetString(sentinel.npcNameIgnores));
sender.sendMessage(prefixGood + "Ignored Entity Name Targets: " + ChatColor.AQUA + getNameTargetString(sentinel.entityNameIgnores));
sender.sendMessage(prefixGood + "Ignored Held Item Targets: " + ChatColor.AQUA + getNameTargetString(sentinel.heldItemIgnores));
return true;
}
else if (arg0.equals("info") && sender.hasPermission("sentinel.info")) {
sender.sendMessage(prefixGood + ChatColor.RESET + sentinel.getNPC().getFullName() + ColorBasic
+ ": owned by " + ChatColor.RESET + getOwner(sentinel.getNPC()) +
(sentinel.getGuarding() == null ? "": ColorBasic + ", guarding: " + ChatColor.RESET + Bukkit.getOfflinePlayer(sentinel.getGuarding()).getName()));
sender.sendMessage(prefixGood + "Damage: " + ChatColor.AQUA + sentinel.damage);
sender.sendMessage(prefixGood + "Armor: " + ChatColor.AQUA + sentinel.armor);
sender.sendMessage(prefixGood + "Health: " + ChatColor.AQUA +
(sentinel.getNPC().isSpawned() ? sentinel.getLivingEntity().getHealth() + "/": "") + sentinel.health);
sender.sendMessage(prefixGood + "Range: " + ChatColor.AQUA + sentinel.range);
sender.sendMessage(prefixGood + "Attack Rate: " + ChatColor.AQUA + sentinel.attackRate);
sender.sendMessage(prefixGood + "Heal Rate: " + ChatColor.AQUA + sentinel.healRate);
sender.sendMessage(prefixGood + "Invincibility Enabled: " + ChatColor.AQUA + sentinel.invincible);
sender.sendMessage(prefixGood + "Fightback Enabled: " + ChatColor.AQUA + sentinel.fightback);
sender.sendMessage(prefixGood + "Ranged Chasing Enabled: " + ChatColor.AQUA + sentinel.rangedChase);
sender.sendMessage(prefixGood + "Close-Quarters Chasing Enabled: " + ChatColor.AQUA + sentinel.closeChase);
return true;
}
else if (arg0.equals("stats") && sender.hasPermission("sentinel.info")) {
sender.sendMessage(prefixGood + ChatColor.RESET + sentinel.getNPC().getFullName() + ColorBasic
+ ": owned by " + ChatColor.RESET + getOwner(sentinel.getNPC()));
sender.sendMessage(prefixGood + "Arrows fired: " + ChatColor.AQUA + sentinel.stats_arrowsFired);
sender.sendMessage(prefixGood + "Potions thrown: " + ChatColor.AQUA + sentinel.stats_potionsThrown);
sender.sendMessage(prefixGood + "Fireballs launched: " + ChatColor.AQUA + sentinel.stats_fireballsFired);
sender.sendMessage(prefixGood + "Punches: " + ChatColor.AQUA + sentinel.stats_punches);
sender.sendMessage(prefixGood + "Times spawned: " + ChatColor.AQUA + sentinel.stats_timesSpawned);
sender.sendMessage(prefixGood + "Damage Given: " + ChatColor.AQUA + sentinel.stats_damageGiven);
sender.sendMessage(prefixGood + "Damage Taken: " + ChatColor.AQUA + sentinel.stats_damageTaken);
sender.sendMessage(prefixGood + "Minutes spawned: " + ChatColor.AQUA + sentinel.stats_ticksSpawned / (20.0 * 60.0));
return true;
}
else {
if (sender.hasPermission("sentinel.basic")) sender.sendMessage(prefixGood + "/sentinel help - Shows help info.");
if (sender.hasPermission("sentinel.addtarget")) sender.sendMessage(prefixGood + "/sentinel addtarget TYPE - Adds a target.");
if (sender.hasPermission("sentinel.removetarget")) sender.sendMessage(prefixGood + "/sentinel removetarget TYPE - Removes a target.");
if (sender.hasPermission("sentinel.addignore")) sender.sendMessage(prefixGood + "/sentinel addignore TYPE - Ignores a target.");
if (sender.hasPermission("sentinel.removeignore")) sender.sendMessage(prefixGood + "/sentinel removeignore TYPE - Allows targetting a target.");
if (sender.hasPermission("sentinel.range")) sender.sendMessage(prefixGood + "/sentinel range RANGE - Sets the NPC's maximum attack range.");
if (sender.hasPermission("sentinel.damage")) sender.sendMessage(prefixGood + "/sentinel damage DAMAGE - Sets the NPC's attack damage.");
if (sender.hasPermission("sentinel.armor")) sender.sendMessage(prefixGood + "/sentinel armor ARMOR - Sets the NPC's armor level.");
if (sender.hasPermission("sentinel.health")) sender.sendMessage(prefixGood + "/sentinel health HEALTH - Sets the NPC's health level.");
if (sender.hasPermission("sentinel.attackrate")) sender.sendMessage(prefixGood + "/sentinel attackrate RATE - Changes the rate at which the NPC attacks, in ticks.");
if (sender.hasPermission("sentinel.healrate")) sender.sendMessage(prefixGood + "/sentinel healrate RATE - Changes the rate at which the NPC heals, in ticks.");
if (sender.hasPermission("sentinel.guard")) sender.sendMessage(prefixGood + "/sentinel guard [PLAYERNAME] - Makes the NPC guard a specific player. Don't specify a player to stop guarding.");
if (sender.hasPermission("sentinel.invincible")) sender.sendMessage(prefixGood + "/sentinel invincible - Toggles whether the NPC is invincible.");
if (sender.hasPermission("sentinel.fightback")) sender.sendMessage(prefixGood + "/sentinel fightback - Toggles whether the NPC will fight back.");
if (sender.hasPermission("sentinel.needammo")) sender.sendMessage(prefixGood + "/sentinel needammo - Toggles whether the NPC will need ammo.");
if (sender.hasPermission("sentinel.chase")) sender.sendMessage(prefixGood + "/sentinel chaseclose - Toggles whether the NPC will chase while in 'close quarters' fights.");
if (sender.hasPermission("sentinel.chase")) sender.sendMessage(prefixGood + "/sentinel chaseranged - Toggles whether the NPC will chase while in ranged fights.");
if (sender.hasPermission("sentinel.info")) sender.sendMessage(prefixGood + "/sentinel info - Shows info on the current NPC.");
if (sender.hasPermission("sentinel.info")) sender.sendMessage(prefixGood + "/sentinel targets - Shows the targets of the current NPC.");
if (sender.hasPermission("sentinel.admin")) sender.sendMessage(prefixGood + "Be careful, you can edit other player's NPCs!");
return true;
}
}
public String getNameTargetString(List<String> strs) {
StringBuilder targets = new StringBuilder();
for (String str: strs) {
targets.append(str).append(", ");
}
return targets.length() > 0 ? targets.substring(0, targets.length() - 2): targets.toString();
}
public String getTargetString(HashSet<SentinelTarget> sentinel) {
StringBuilder targets = new StringBuilder();
for (SentinelTarget target: sentinel) {
targets.append(target.name()).append(", ");
}
return targets.length() > 0 ? targets.substring(0, targets.length() - 2): targets.toString();
}
public String getOwner(NPC npc) {
if (npc.getTrait(Owner.class).getOwnerId() == null) {
return npc.getTrait(Owner.class).getOwner();
}
OfflinePlayer player = Bukkit.getOfflinePlayer(npc.getTrait(Owner.class).getOwnerId());
if (player == null) {
return "Server/Unknown";
}
return player.getName();
}
}