/
dPlayer.java
810 lines (675 loc) · 30.3 KB
/
dPlayer.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
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
package net.aufdemrand.denizen.objects;
import net.aufdemrand.denizen.flags.FlagManager;
import net.aufdemrand.denizen.tags.Attribute;
import net.aufdemrand.denizen.tags.core.PlayerTags;
import net.aufdemrand.denizen.utilities.DenizenAPI;
import net.aufdemrand.denizen.utilities.debugging.dB;
import net.aufdemrand.denizen.utilities.depends.Depends;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.OfflinePlayer;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryType;
import java.util.ArrayList;
import java.util.List;
import java.util.HashMap;
import java.util.Map;
public class dPlayer implements dObject {
/////////////////////
// STATIC METHODS
/////////////////
static Map<String, dPlayer> players = new HashMap<String, dPlayer>();
public static dPlayer mirrorBukkitPlayer(OfflinePlayer player) {
if (player == null) return null;
if (players.containsKey(player.getName())) return players.get(player.getName());
else return new dPlayer(player);
}
/////////////////////
// OBJECT FETCHER
/////////////////
@ObjectFetcher("p")
public static dPlayer valueOf(String string) {
if (string == null) return null;
string = string.replace("p@", "");
////////
// Match player name
OfflinePlayer returnable = null;
for (OfflinePlayer player : Bukkit.getOfflinePlayers())
if (player.getName().equalsIgnoreCase(string)) {
returnable = player;
break;
}
if (returnable != null) {
if (players.containsKey(returnable.getName())) return players.get(returnable.getName());
else return new dPlayer(returnable);
}
else dB.echoError("Invalid Player! '" + string
+ "' could not be found. Has the player logged off?");
return null;
}
public static boolean matches(String arg) {
arg = arg.replace("p@", "");
OfflinePlayer returnable = null;
for (OfflinePlayer player : Bukkit.getOfflinePlayers())
if (player.getName().equalsIgnoreCase(arg)) {
returnable = player;
break;
}
if (returnable != null) return true;
return false;
}
/////////////////////
// STATIC CONSTRUCTORS
/////////////////
public dPlayer(OfflinePlayer player) {
if (player == null) return;
this.player_name = player.getName();
// Keep in a map to avoid multiple instances of a dPlayer per player.
players.put(this.player_name, this);
}
/////////////////////
// INSTANCE FIELDS/METHODS
/////////////////
String player_name = null;
public boolean isValid() {
if (player_name == null) return false;
if (getPlayerEntity() == null && getOfflinePlayer() == null) return false;
return true;
}
public Player getPlayerEntity() {
if (player_name == null) return null;
return Bukkit.getPlayer(player_name);
}
public OfflinePlayer getOfflinePlayer() {
if (player_name == null) return null;
return Bukkit.getOfflinePlayer(player_name);
}
public dEntity getDenizenEntity() {
return new dEntity(getPlayerEntity());
}
public dNPC getSelectedNPC() {
if (getPlayerEntity().hasMetadata("selected"))
return dNPC.valueOf(getPlayerEntity().getMetadata("selected").get(0).asString());
else return null;
}
public String getName() {
return player_name;
}
public dLocation getLocation() {
if (isOnline()) return new dLocation(getPlayerEntity().getLocation());
else return null;
}
public dLocation getEyeLocation() {
if (isOnline()) return new dLocation(getPlayerEntity().getEyeLocation());
else return null;
}
public World getWorld() {
if (isOnline()) return getPlayerEntity().getWorld();
else return null;
}
public boolean isOnline() {
if (player_name == null) return false;
if (Bukkit.getPlayer(player_name) != null) return true;
return false;
}
/////////////////////
// dObject Methods
/////////////////
private String prefix = "Player";
@Override
public String getPrefix() {
return prefix;
}
@Override
public dPlayer setPrefix(String prefix) {
this.prefix = prefix;
return this;
}
@Override
public String debug() {
return (prefix + "='<A>" + identify() + "<G>' ");
}
@Override
public boolean isUnique() {
return true;
}
@Override
public String getType() {
return "Player";
}
@Override
public String identify() {
return "p@" + player_name;
}
@Override
public String toString() {
return identify();
}
@Override
public String getAttribute(Attribute attribute) {
if (attribute == null) return "null";
if (player_name == null) return "null";
// <--
// <player> -> dPlayer
// Returns the dPlayer of the player.
// -->
// <--
// <player.entity> -> dEntity
// returns the dEntity object of the player
// -->
if (attribute.startsWith("entity"))
return new dEntity(getPlayerEntity())
.getAttribute(attribute.fulfill(1));
// <--
// <player.has_played_before> -> Element(boolean)
// returns true if the player has played before
// -->
if (attribute.startsWith("has_played_before"))
return new Element(String.valueOf(getOfflinePlayer().hasPlayedBefore()))
.getAttribute(attribute.fulfill(1));
// <--
// <player.is_op> -> Element(boolean)
// returns true if the player has 'op status'
// -->
if (attribute.startsWith("is_op"))
return new Element(String.valueOf(getOfflinePlayer().isOp()))
.getAttribute(attribute.fulfill(1));
// <--
// <player.first_played> -> Element(number)
// returns the 'System.currentTimeMillis()' of when the player
// first logged on. Will return '0' if player has never played.
// -->
if (attribute.startsWith("first_played"))
return new Element(String.valueOf(getOfflinePlayer().getFirstPlayed()))
.getAttribute(attribute.fulfill(1));
// <--
// <player.last_played> -> Element(number)
// returns the 'System.currentTimeMillis()' of when the player
// was last seen. Will return '0' if player has never played.
// -->
if (attribute.startsWith("last_played"))
return new Element(String.valueOf(getOfflinePlayer().getLastPlayed()))
.getAttribute(attribute.fulfill(1));
// <--
// <player.is_banned> -> Element(boolean)
// returns true if the player is banned
// -->
if (attribute.startsWith("is_banned"))
return new Element(String.valueOf(getOfflinePlayer().isBanned()))
.getAttribute(attribute.fulfill(1));
// <--
// <player.is_whitelisted> -> Element(boolean)
// returns true if the player is whitelisted
// -->
if (attribute.startsWith("is_whitelisted"))
return new Element(String.valueOf(getOfflinePlayer().isWhitelisted()))
.getAttribute(attribute.fulfill(1));
if (attribute.startsWith("name") && !isOnline())
// This can be parsed later with more detail if the player is online, so only check for offline.
return new Element(player_name).getAttribute(attribute.fulfill(1));
// <--
// <player.is_online> -> Element(boolean)
// returns true if the player is currently online
// -->
if (attribute.startsWith("is_online"))
return new Element(String.valueOf(isOnline())).getAttribute(attribute.fulfill(1));
// <--
// <player.ip> -> Element
// Returns the player's IP address.
// -->
if (attribute.startsWith("ip"))
return getPlayerEntity().getAddress().getHostName();
// <--
// <player.list> -> dList(dPlayer)
// Returns all players that have ever played on the server, online or not.
// **NOTE: This will only work if there is a player attached to the current script.
// If you need it anywhere else, use <server.list_players>**
if (attribute.startsWith("list")) {
List<String> players = new ArrayList<String>();
// <--
// <player.list.online> -> dList(dPlayer)
// Returns all online players.
// **NOTE: This will only work if there is a player attached to the current script.
// If you need it anywhere else, use <server.list_online_players>**
if (attribute.startsWith("list.online")) {
for(Player player : Bukkit.getOnlinePlayers())
players.add(player.getName());
return new dList(players).getAttribute(attribute.fulfill(2));
}
// <--
// <player.list.offline> -> dList(dPlayer)
// Returns all offline players.
// **NOTE: This will only work if there is a player attached to the current script.
// If you need it anywhere else, use <server.list_offline_players>**
else if (attribute.startsWith("list.offline")) {
for(OfflinePlayer player : Bukkit.getOfflinePlayers()) {
if (!Bukkit.getOnlinePlayers().toString().contains(player.getName()))
players.add(player.getName());
}
return new dList(players).getAttribute(attribute.fulfill(2));
}
else {
for(OfflinePlayer player : Bukkit.getOfflinePlayers())
players.add(player.getName());
return new dList(players).getAttribute(attribute.fulfill(1));
}
}
// <--
// <player.chat_history_list> -> dList
// Returns a list of the last 10 things the player has said, less
// if the player hasn't said all that much.
// -->
if (attribute.startsWith("chat_history_list"))
return new dList(PlayerTags.playerChatHistory.get(player_name))
.getAttribute(attribute.fulfill(1));
// <--
// <player.chat_history> -> Element
// returns the last thing the player said.
// -->
if (attribute.startsWith("chat_history")) {
int x = 1;
if (attribute.hasContext(1) && aH.matchesInteger(attribute.getContext(1)))
x = attribute.getIntContext(1);
return new Element(PlayerTags.playerChatHistory.get(player_name).get(x - 1))
.getAttribute(attribute.fulfill(1));
}
// <--
// <player.bed_spawn> -> dLocation
// Returns a dLocation of the player's bed spawn location, 'null' if
// it doesn't exist.
// -->
if (attribute.startsWith("bed_spawn"))
return new dLocation(getOfflinePlayer().getBedSpawnLocation())
.getAttribute(attribute.fulfill(2));
// <--
// <player.money> -> Element(number)
// returns the amount of money the player has with the registered
// Economy system.
// -->
if (attribute.startsWith("money")) {
if(Depends.economy != null) {
// <--
// <player.money.currency_singular> -> Element
// returns the 'singular currency' string, if supported by the
// registered Economy system.
// -->
if (attribute.startsWith("money.currency_singular"))
return new Element(Depends.economy.currencyNameSingular())
.getAttribute(attribute.fulfill(2));
// <--
// <player.money.currency> -> Element
// returns the 'currency' string, if supported by the
// registered Economy system.
// -->
if (attribute.startsWith("money.currency"))
return new Element(Depends.economy.currencyNamePlural())
.getAttribute(attribute.fulfill(2));
return new Element(String.valueOf(Depends.economy.getBalance(player_name)))
.getAttribute(attribute.fulfill(1));
} else {
dB.echoError("No economy loaded! Have you installed Vault and a compatible economy plugin?");
return null;
}
}
if (!isOnline()) return new Element(identify()).getAttribute(attribute);
// Player is required to be online after this point...
// <--
// <player.xp.to_next_level> -> Element(number)
// returns the amount of experience to the next level.
// -->
if (attribute.startsWith("xp.to_next_level"))
return new Element(String.valueOf(getPlayerEntity().getExpToLevel()))
.getAttribute(attribute.fulfill(2));
// <--
// <player.xp.total> -> Element(number)
// returns the total amount of experience points.
// -->
if (attribute.startsWith("xp.total"))
return new Element(String.valueOf(getPlayerEntity().getTotalExperience()))
.getAttribute(attribute.fulfill(2));
// <--
// <player.xp.level> -> Element(number)
// returns the number of levels the player has.
// -->
if (attribute.startsWith("xp.level"))
return new Element(getPlayerEntity().getLevel())
.getAttribute(attribute.fulfill(2));
// <--
// <player.xp> -> Element(number)
// returns the percentage of experience points to the next level.
// -->
if (attribute.startsWith("xp"))
return new Element(String.valueOf(getPlayerEntity().getExp() * 100))
.getAttribute(attribute.fulfill(1));
// <--
// <player.equipment.boots> -> dItem
// returns the item the player is wearing as boots, or null
// if none.
// -->
if (attribute.startsWith("equipment.boots"))
if (getPlayerEntity().getInventory().getBoots() != null)
return new dItem(getPlayerEntity().getInventory().getBoots())
.getAttribute(attribute.fulfill(2));
// <--
// <player.equipment.chestplate> -> dItem
// returns the item the player is wearing as a chestplate, or null
// if none.
// -->
if (attribute.startsWith("equipment.chestplate"))
if (getPlayerEntity().getInventory().getChestplate() != null)
return new dItem(getPlayerEntity().getInventory().getChestplate())
.getAttribute(attribute.fulfill(2));
// <--
// <player.equipment.helmet> -> dItem
// returns the item the player is wearing as a helmet, or null
// if none.
// -->
if (attribute.startsWith("equipment.helmet"))
if (getPlayerEntity().getInventory().getHelmet() != null)
return new dItem(getPlayerEntity().getInventory().getHelmet())
.getAttribute(attribute.fulfill(2));
// <--
// <player.equipment.leggings> -> dItem
// returns the item the player is wearing as leggings, or null
// if none.
// -->
if (attribute.startsWith("equipment.leggings"))
if (getPlayerEntity().getInventory().getLeggings() != null)
return new dItem(getPlayerEntity().getInventory().getLeggings())
.getAttribute(attribute.fulfill(2));
// <--
// <player.equipment> -> dInventory
// returns a dInventory containing the player's equipment
// -->
if (attribute.startsWith("equipment"))
// The only way to return correct size for dInventory
// created from equipment is to use a CRAFTING type
// that has the expected 4 slots
return new dInventory(InventoryType.CRAFTING).add(getPlayerEntity().getInventory().getArmorContents())
.getAttribute(attribute.fulfill(1));
// <--
// <player.inventory> -> dInventory
// returns a dInventory of the player's current inventory.
// -->
if (attribute.startsWith("inventory"))
return new dInventory(getPlayerEntity().getInventory())
.getAttribute(attribute.fulfill(1));
// <--
// <player.item_in_hand> -> dItem
// returns the item the player is holding, or null
// if none.
// -->
if (attribute.startsWith("item_in_hand"))
return new dItem(getPlayerEntity().getItemInHand())
.getAttribute(attribute.fulfill(1));
// <--
// <player.name.display> -> Element
// returns the 'display name' of the player, which may contain
// prefixes and suffixes/color, etc.
// -->
if (attribute.startsWith("name.display"))
return new Element(getPlayerEntity().getDisplayName())
.getAttribute(attribute.fulfill(2));
// <--
// <player.name.list> -> Element
// returns the name of the player as shown in the 'player list'.
// -->
if (attribute.startsWith("name.list"))
return new Element(getPlayerEntity().getPlayerListName())
.getAttribute(attribute.fulfill(2));
// <--
// <player.name> -> Element
// returns the name of the player.
// -->
if (attribute.startsWith("name"))
return new Element(player_name).getAttribute(attribute.fulfill(1));
// <--
// <player.compass.target> -> dLocation
// returns a dLocation of the player's 'compass target'.
// -->
if (attribute.startsWith("compass_target"))
return new dLocation(getPlayerEntity().getCompassTarget())
.getAttribute(attribute.fulfill(2));
// <--
// <player.food_level.formatted> -> Element
// returns a 'formatted' value of the player's current food level.
// May be 'starving', 'famished', 'parched, 'hungry' or 'healthy'
// -->
if (attribute.startsWith("food_level.formatted")) {
double maxHunger = getPlayerEntity().getMaxHealth();
if (attribute.hasContext(2))
maxHunger = attribute.getIntContext(2);
if ((float) getPlayerEntity().getFoodLevel() / maxHunger < .10)
return new Element("starving").getAttribute(attribute.fulfill(2));
else if ((float) getPlayerEntity().getFoodLevel() / maxHunger < .40)
return new Element("famished").getAttribute(attribute.fulfill(2));
else if ((float) getPlayerEntity().getFoodLevel() / maxHunger < .75)
return new Element("parched").getAttribute(attribute.fulfill(2));
else if ((float) getPlayerEntity().getFoodLevel() / maxHunger < 1)
return new Element("hungry").getAttribute(attribute.fulfill(2));
else return new Element("healthy").getAttribute(attribute.fulfill(2));
}
// <--
// <player.food_level> -> Element(number)
// returns the current food level of the player.
// -->
if (attribute.startsWith("food_level"))
return new Element(String.valueOf(getPlayerEntity().getFoodLevel()))
.getAttribute(attribute.fulfill(1));
// <--
// <player.has_permission[permission.node]> -> Element(boolean)
// returns true if the player has the specified node, false otherwise
// -->
if (attribute.startsWith("permission")
|| attribute.startsWith("has_permission")) {
if (Depends.permissions == null) {
dB.echoError("No permission system loaded! Have you installed Vault and a compatible permissions plugin?");
return null;
}
String permission = attribute.getContext(1);
// <--
// <player.has_permission[permission.node].global> -> Element(boolean)
// returns true if the player has the specified node, regardless of world.
// this may or may not be functional with your permissions system.
// -->
// Non-world specific permission
if (attribute.getAttribute(2).startsWith("global"))
return new Element(String.valueOf(Depends.permissions.has((World) null, player_name, permission)))
.getAttribute(attribute.fulfill(2));
// Permission in certain world
else if (attribute.getAttribute(2).startsWith("world"))
return new Element(String.valueOf(Depends.permissions.has(attribute.getContext(2), player_name, permission)))
.getAttribute(attribute.fulfill(2));
// <--
// <player.has_permission[permission.node].world> -> Element(boolean)
// returns true if the player has the specified node in regards to the
// player's current world. This may or may not be functional with your
// permissions system.
// -->
// Permission in current world
return new Element(String.valueOf(Depends.permissions.has(getPlayerEntity(), permission)))
.getAttribute(attribute.fulfill(1));
}
// <--
// <player.flag[flag_name]> -> Flag dList
// returns 'flag dList' of the player's flag_name specified.
// -->
if (attribute.startsWith("flag")) {
String flag_name;
if (attribute.hasContext(1)) flag_name = attribute.getContext(1);
else return "null";
attribute.fulfill(1);
if (attribute.startsWith("is_expired")
|| attribute.startsWith("isexpired"))
return new Element(!FlagManager.playerHasFlag(this, flag_name))
.getAttribute(attribute.fulfill(1));
if (attribute.startsWith("size") && !FlagManager.playerHasFlag(this, flag_name))
return new Element(0).getAttribute(attribute.fulfill(1));
if (FlagManager.playerHasFlag(this, flag_name))
return new dList(DenizenAPI.getCurrentInstance().flagManager()
.getPlayerFlag(getName(), flag_name))
.getAttribute(attribute);
else return "null";
}
// <--
// <player.in_group[group_name]> -> Element(boolean)
// returns true if the player has the specified group, false otherwise
// -->
if (attribute.startsWith("group")
|| attribute.startsWith("in_group")) {
if (Depends.permissions == null) {
dB.echoError("No permission system loaded! Have you installed Vault and a compatible permissions plugin?");
return "null";
}
String group = attribute.getContext(1);
// <--
// <player.in_group[group_name].global> -> Element(boolean)
// returns true if the player has the group with no regard to the
// player's current world. This may or may not be functional with your
// permissions system.
// -->
// Non-world specific permission
if (attribute.getAttribute(2).startsWith("global"))
return new Element(String.valueOf(Depends.permissions.playerInGroup((World) null, player_name, group)))
.getAttribute(attribute.fulfill(2));
// Permission in certain world
else if (attribute.getAttribute(2).startsWith("world"))
return new Element(String.valueOf(Depends.permissions.playerInGroup(attribute.getContext(2), player_name, group)))
.getAttribute(attribute.fulfill(2));
// <--
// <player.in_group[group_name].world> -> Element(boolean)
// returns true if the player has the group in regards to the
// player's current world. This may or may not be functional with your
// permissions system.
// -->
// Permission in current world
return new Element(String.valueOf(Depends.permissions.playerInGroup(getPlayerEntity(), group)))
.getAttribute(attribute.fulfill(1));
}
// <--
// <player.is_flying> -> Element(boolean)
// returns true if the player is currently flying, false otherwise
// -->
if (attribute.startsWith("is_flying"))
return new Element(String.valueOf(getPlayerEntity().isFlying()))
.getAttribute(attribute.fulfill(1));
// <--
// <player.is_sneaking> -> Element(boolean)
// returns true if the player is currently sneaking, false otherwise
// -->
if (attribute.startsWith("is_sneaking"))
return new Element(String.valueOf(getPlayerEntity().isSneaking()))
.getAttribute(attribute.fulfill(1));
// <--
// <player.is_blocking> -> Element(boolean)
// returns true if the player is currently blocking, false otherwise
// -->
if (attribute.startsWith("is_blocking"))
return new Element(String.valueOf(getPlayerEntity().isBlocking()))
.getAttribute(attribute.fulfill(1));
// <--
// <player.is_sleeping> -> Element(boolean)
// returns true if the player is currently sleeping, false otherwise
// -->
if (attribute.startsWith("is_sleeping"))
return new Element(String.valueOf(getPlayerEntity().isSleeping()))
.getAttribute(attribute.fulfill(1));
// <--
// <player.is_sprinting> -> Element(boolean)
// returns true if the player is currently sprinting, false otherwise
// -->
if (attribute.startsWith("is_sprinting"))
return new Element(String.valueOf(getPlayerEntity().isSprinting()))
.getAttribute(attribute.fulfill(1));
// <--
// <player.gamemode.id> -> Element(number)
// returns 'gamemode id' of the player. 0 = survival, 1 = creative, 2 = adventure
// -->
if (attribute.startsWith("gamemode.id"))
return new Element(String.valueOf(getPlayerEntity().getGameMode().getValue()))
.getAttribute(attribute.fulfill(1));
// <--
// <player.gamemode> -> Element
// returns the name of the gamemode the player is currently set to.
// -->
if (attribute.startsWith("gamemode"))
return new Element(String.valueOf(getPlayerEntity().getGameMode().toString()))
.getAttribute(attribute.fulfill(1));
// <--
// <player.item_on_cursor> -> dItem
// returns a dItem that the player's cursor is on, if any. This includes
// chest interfaces, inventories, and hotbars, etc.
// -->
if (attribute.startsWith("item_on_cursor"))
return new dItem(getPlayerEntity().getItemOnCursor())
.getAttribute(attribute.fulfill(1));
// <--
// <player.selected_npc> -> dNPC
// returns the dNPC that the player currently has selected with
// '/npc sel', null if no player selected.
// -->
if (attribute.startsWith("selected_npc")) {
if (getPlayerEntity().hasMetadata("selected"))
return dNPC.valueOf(getPlayerEntity().getMetadata("selected").get(0).asString())
.getAttribute(attribute.fulfill(1));
else return "null";
}
// <--
// <player.allowed_flight> -> Element(boolean)
// returns true if the player is allowed to fly, and false otherwise
// -->
if (attribute.startsWith("allowed_flight"))
return new Element(String.valueOf(getPlayerEntity().getAllowFlight()))
.getAttribute(attribute.fulfill(1));
// <--
// <player.host_name> -> Element
// returns the player's 'host name'.
// -->
if (attribute.startsWith("host_name"))
return new Element(String.valueOf(getPlayerEntity().getAddress().getHostName()))
.getAttribute(attribute.fulfill(1));
// <--
// <player.time_asleep> -> Duration
// returns a Duration of the time the player has been asleep.
// -->
if (attribute.startsWith("time_asleep"))
return new Duration(getPlayerEntity().getSleepTicks() / 20)
.getAttribute(attribute.fulfill(1));
// <--
// <player.player_time> -> Element
// returns the time, specific to the player
// -->
if (attribute.startsWith("player_time"))
return new Element(String.valueOf(getPlayerEntity().getPlayerTime()))
.getAttribute(attribute.fulfill(1));
// <--
// <player.player_time_offset> -> Element
// returns the player's 'offset' of time vs. the real time.
// -->
if (attribute.startsWith("player_time_offset"))
return new Element(String.valueOf(getPlayerEntity().getPlayerTimeOffset()))
.getAttribute(attribute.fulfill(1));
// <--
// <player.prefix> -> Element
// Returns the player's prefix.
// -->
if (attribute.startsWith("prefix"))
return new Element(prefix)
.getAttribute(attribute.fulfill(1));
if (attribute.startsWith("debug.log")) {
dB.log(debug());
return new Element(Boolean.TRUE.toString())
.getAttribute(attribute.fulfill(2));
}
if (attribute.startsWith("debug.no_color")) {
return new Element(ChatColor.stripColor(debug()))
.getAttribute(attribute.fulfill(2));
}
if (attribute.startsWith("debug")) {
return new Element(debug())
.getAttribute(attribute.fulfill(1));
}
return new dEntity(getPlayerEntity()).getAttribute(attribute.fulfill(0));
}
}