-
-
Notifications
You must be signed in to change notification settings - Fork 165
Expand file tree
/
Copy pathCommandItems.java
More file actions
655 lines (526 loc) · 30.2 KB
/
Copy pathCommandItems.java
File metadata and controls
655 lines (526 loc) · 30.2 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
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
package com.sk89q.craftbook.mechanics.items;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.sk89q.craftbook.AbstractCraftBookMechanic;
import com.sk89q.craftbook.CraftBookPlayer;
import com.sk89q.craftbook.bukkit.CraftBookPlugin;
import com.sk89q.craftbook.bukkit.util.CraftBookBukkitUtil;
import com.sk89q.craftbook.mechanics.items.CommandItemAction.ActionRunStage;
import com.sk89q.craftbook.mechanics.items.CommandItemDefinition.CommandType;
import com.sk89q.craftbook.util.EventUtil;
import com.sk89q.craftbook.util.ItemSyntax;
import com.sk89q.craftbook.util.ItemUtil;
import com.sk89q.craftbook.util.LoadPriority;
import com.sk89q.craftbook.util.ParsingUtil;
import com.sk89q.craftbook.util.ProtectionUtil;
import com.sk89q.craftbook.util.Tuple2;
import com.sk89q.util.yaml.YAMLFormat;
import com.sk89q.util.yaml.YAMLProcessor;
import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.block.Action;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityEvent;
import org.bukkit.event.entity.EntityPickupItemEvent;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.entity.ProjectileHitEvent;
import org.bukkit.event.entity.ProjectileLaunchEvent;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.event.player.PlayerDropItemEvent;
import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerItemBreakEvent;
import org.bukkit.event.player.PlayerItemConsumeEvent;
import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import org.bukkit.permissions.PermissionAttachment;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.UUID;
public class CommandItems extends AbstractCraftBookMechanic {
public static CommandItems INSTANCE;
private YAMLProcessor config;
private Set<CommandItemDefinition> definitions;
private Map<Tuple2<String, String>, Integer> cooldownPeriods;
private Map<UUID, List<ItemStack>> deathPersistItems = Maps.newHashMap();
private boolean doChat = false;
public CommandItemDefinition getDefinitionByName(String name) {
for(CommandItemDefinition def : definitions)
if(def.name.equalsIgnoreCase(name))
return def;
return null;
}
@Override
public void disable () {
for (Entry<UUID, List<ItemStack>> deathPersistEntry : deathPersistItems.entrySet()) {
Map<String, List<String>> items = (Map<String, List<String>>) CraftBookPlugin.inst().getPersistentStorage().get("command-items.death-items");
List<String> its = items.get(deathPersistEntry.getKey().toString());
if (its == null) its = new ArrayList<>();
for (ItemStack stack : deathPersistEntry.getValue()) {
its.add(ItemSyntax.getStringFromItem(stack));
}
items.put(deathPersistEntry.getKey().toString(), its);
CraftBookPlugin.inst().getPersistentStorage().set("command-items.death-items", items);
}
definitions = null;
cooldownPeriods = null;
config = null;
INSTANCE = null;
}
@Override
public boolean enable() {
INSTANCE = this;
definitions = new HashSet<>();
cooldownPeriods = new HashMap<>();
CraftBookPlugin.inst().createDefaultConfiguration(new File(CraftBookPlugin.inst().getDataFolder(), "command-items.yml"), "command-items.yml");
config = new YAMLProcessor(new File(CraftBookPlugin.inst().getDataFolder(), "command-items.yml"), false, YAMLFormat.EXTENDED);
try {
config.load();
} catch (IOException e) {
CraftBookPlugin.logger().severe("Corrupt CommandItems command-items.yml File! Make sure that the correct syntax has been used, and that there are no tabs!");
CraftBookBukkitUtil.printStacktrace(e);
return false;
}
int amount = 0;
for(String key : config.getKeys("command-items")) {
CommandItemDefinition comdef = CommandItemDefinition.load(config, "command-items." + key);
if(addDefinition(comdef)) {
CraftBookPlugin.logDebugMessage("Added CommandItem: " + key, "command-items.initialize");
amount++;
} else
CraftBookPlugin.logger().warning("Failed to add CommandItem: " + key);
}
if(amount == 0) return false;
config.save();
CraftBookPlugin.logger().info("Successfully added " + amount + " CommandItems!");
if(definitions.size() > 0) {
Bukkit.getScheduler().runTaskTimer(CraftBookPlugin.inst(), () -> {
Iterator<Entry<Tuple2<String, String>, Integer>> iterator = cooldownPeriods.entrySet().iterator();
while(iterator.hasNext()) {
Entry<Tuple2<String, String>, Integer> entry = iterator.next();
if(entry.getValue() > 1)
cooldownPeriods.put(entry.getKey(), entry.getValue() - 1);
else
iterator.remove();
}
}, 0, 20);
Bukkit.getScheduler().runTaskTimer(CraftBookPlugin.inst(), () -> {
for(Player player : Bukkit.getOnlinePlayers()) {
if(player.getInventory().getItemInMainHand().getType() != Material.AIR)
performCommandItems(player.getInventory().getItemInMainHand(), player, null);
if(player.getInventory().getItemInOffHand().getType() != Material.AIR)
performCommandItems(player.getInventory().getItemInOffHand(), player, null);
for(ItemStack stack : player.getInventory().getArmorContents())
if(stack != null && stack.getType() != Material.AIR)
performCommandItems(stack, player, null);
}
}, 10, 10);
}
if(!CraftBookPlugin.inst().getPersistentStorage().has("command-items.death-items")) {
CraftBookPlugin.inst().getPersistentStorage().set("command-items.death-items", new HashMap<String, List<String>>());
} else {
Map<String, List<String>> items = (Map<String, List<String>>) CraftBookPlugin.inst().getPersistentStorage().get("command-items.death-items");
for (Entry<String, List<String>> entry : items.entrySet()) {
UUID uuid = UUID.fromString(entry.getKey());
List<ItemStack> its = Lists.newArrayList();
for (String item : entry.getValue()) {
its.add(ItemSyntax.getItem(item));
}
deathPersistItems.put(uuid, its);
}
items.clear();
CraftBookPlugin.inst().getPersistentStorage().set("command-items.death-items", items);
}
doChat = definitions.stream().anyMatch(def -> def.clickType == ClickType.PLAYER_CHAT);
return true;
}
public boolean addDefinition(CommandItemDefinition def) {
return definitions.add(def);
}
public void save() {
config.addNode("command-items");
for(CommandItemDefinition def : definitions) {
config.addNode("command-items." + def.name);
def.save(config, "command-items." + def.name);
}
config.save();
disable();
enable();
}
@EventHandler(priority=EventPriority.HIGH)
public void onPlayerInteract(final PlayerInteractEvent event) {
if(event.getItem() == null)
return;
if(event.getAction() == Action.PHYSICAL)
return;
performCommandItems(event.getItem(), event.getPlayer(), event);
}
@EventHandler(priority=EventPriority.HIGH)
public void onPlayerHitEntity(final PlayerInteractEntityEvent event) {
if(event.getPlayer().getInventory().getItemInMainHand().getType() == Material.AIR)
return;
performCommandItems(event.getPlayer().getInventory().getItemInMainHand(), event.getPlayer(), event);
}
@EventHandler(priority=EventPriority.HIGH)
public void onEntityDamageEntity(final EntityDamageByEntityEvent event) {
Player p;
if(event.getDamager() instanceof Projectile) {
if(!(((Projectile) event.getDamager()).getShooter() instanceof Player))
return;
p = (Player) ((Projectile) event.getDamager()).getShooter();
} else {
if(!(event.getDamager() instanceof Player))
return;
p = (Player) event.getDamager();
}
if(p.getItemInHand() == null)
return;
performCommandItems(p.getItemInHand(), p, event);
}
@EventHandler(priority=EventPriority.HIGH)
public void onBlockBreak(final BlockBreakEvent event) {
if(event.getPlayer().getItemInHand() == null)
return;
performCommandItems(event.getPlayer().getItemInHand(), event.getPlayer(), event);
}
@EventHandler(priority=EventPriority.HIGH)
public void onProjectileLaunch(final ProjectileLaunchEvent event) {
if(!(event.getEntity().getShooter() instanceof Player))
return;
if(((Player) event.getEntity().getShooter()).getItemInHand() == null)
return;
final ItemStack item = ((Player) event.getEntity().getShooter()).getItemInHand();
final Player shooter = (Player) event.getEntity().getShooter();
Bukkit.getScheduler().runTaskLater(CraftBookPlugin.inst(), () -> performCommandItems(item, shooter, event), 5L);
}
@EventHandler(priority=EventPriority.HIGH)
public void onProjectileHit(final ProjectileHitEvent event) {
if(!(event.getEntity().getShooter() instanceof Player))
return;
if(((Player) event.getEntity().getShooter()).getItemInHand() == null)
return;
final ItemStack item = ((Player) event.getEntity().getShooter()).getItemInHand();
final Player shooter = (Player) event.getEntity().getShooter();
Bukkit.getScheduler().runTaskLater(CraftBookPlugin.inst(), () -> performCommandItems(item, shooter, event), 5L);
}
@EventHandler(priority=EventPriority.HIGH)
public void onBlockPlace(final BlockPlaceEvent event) {
if(event.getItemInHand() == null)
return;
performCommandItems(event.getItemInHand(), event.getPlayer(), event);
}
@EventHandler(priority=EventPriority.HIGH)
public void onItemConsume(final PlayerItemConsumeEvent event) {
if(event.getItem() == null)
return;
performCommandItems(event.getItem(), event.getPlayer(), event);
}
@EventHandler(priority=EventPriority.HIGH)
public void onItemDrop(final PlayerDropItemEvent event) {
if(event.getItemDrop() == null || !ItemUtil.isStackValid(event.getItemDrop().getItemStack()))
return;
performCommandItems(event.getItemDrop().getItemStack(), event.getPlayer(), event);
}
@EventHandler(priority=EventPriority.HIGH)
public void onItemBreak(final PlayerItemBreakEvent event) {
if(event.getBrokenItem() == null)
return;
performCommandItems(event.getBrokenItem(), event.getPlayer(), event);
}
@EventHandler(priority=EventPriority.HIGH)
public void onItemPickup(final EntityPickupItemEvent event) {
if (event.getItem() == null)
return;
if (event.getEntity() instanceof Player) {
performCommandItems(event.getItem().getItemStack(), (Player) event.getEntity(), event);
}
}
@EventHandler(priority=EventPriority.HIGH)
public void onPlayerDeath(PlayerDeathEvent event) {
if (!EventUtil.passesFilter(event))
return;
Iterator<ItemStack> stackIt = event.getDrops().iterator();
while(stackIt.hasNext()) {
final ItemStack stack = stackIt.next();
performCommandItems(stack, event.getEntity(), event);
for(CommandItemDefinition def : definitions) {
if(ItemUtil.areItemsIdentical(stack, def.getItem()) && def.keepOnDeath) {
List<ItemStack> items = deathPersistItems.get(event.getEntity().getUniqueId());
if (items == null) items = Lists.newArrayList();
items.add(stack);
deathPersistItems.put(event.getEntity().getUniqueId(), items);
stackIt.remove();
break;
}
}
}
}
@EventHandler(priority = EventPriority.HIGH)
public void onPlayerItemClick(InventoryClickEvent event) {
if(event.getCurrentItem() == null || !(event.getWhoClicked() instanceof Player))
return;
performCommandItems(event.getCurrentItem(), (Player) event.getWhoClicked(), event);
}
@EventHandler(priority = EventPriority.HIGH)
public void onPlayerChat(AsyncPlayerChatEvent event) {
if(!doChat || event.getPlayer().getItemInHand() == null)
return;
Bukkit.getScheduler().runTask(CraftBookPlugin.inst(),
() -> performCommandItems(event.getPlayer().getItemInHand(), event.getPlayer(), event));
}
@EventHandler(priority = EventPriority.HIGH)
public void onPlayerRespawn(PlayerRespawnEvent event) {
if(!deathPersistItems.containsKey(event.getPlayer().getUniqueId())) {
return;
}
List<ItemStack> its = deathPersistItems.get(event.getPlayer().getUniqueId());
for(ItemStack it : its) {
event.getPlayer().getInventory().addItem(it);
}
deathPersistItems.remove(event.getPlayer().getUniqueId());
}
public void performCommandItems(ItemStack item, final Player player, final Event event) {
if (event != null && !EventUtil.passesFilter(event))
return;
CraftBookPlayer lplayer = CraftBookPlugin.inst().wrapPlayer(player);
for(CommandItemDefinition def : definitions) {
current: {
if(ItemUtil.areItemsIdentical(def.stack, item)) {
final CommandItemDefinition comdef = def;
if(!comdef.clickType.doesPassType(event)) break current;
if(!comdef.requireSneaking.doesPass(lplayer.isSneaking())) break current;
if(!lplayer.hasPermission("craftbook.mech.commanditems") || comdef.permNode != null && !comdef.permNode.isEmpty() && !lplayer.hasPermission(comdef.permNode)) {
if(CraftBookPlugin.inst().getConfiguration().showPermissionMessages)
lplayer.printError("mech.use-permission");
break current;
}
if(event instanceof Cancellable && comdef.cancelAction)
((Cancellable) event).setCancelled(true);
if(cooldownPeriods.containsKey(new Tuple2<>(lplayer.getName(), comdef.name))) {
if(def.clickType != ClickType.PASSIVE && !def.cooldownMessage.isEmpty())
lplayer.printError(lplayer.translate(def.cooldownMessage).replace("%time%", String.valueOf(cooldownPeriods.get(
new Tuple2<>(lplayer.getName(), comdef.name)))));
break current;
}
for (CommandItemAction action : comdef.actions) {
if (action.stage == ActionRunStage.BEFORE) {
if (!action.runAction(comdef, event, player)) {
break current;
}
}
}
if (!player.hasPermission("craftbook.mech.commanditems.bypassconsumables") && !player.getGameMode().equals(GameMode.CREATIVE)) {
for (ItemStack stack : def.consumables) {
boolean found = false;
int amount = 0;
for (ItemStack tStack : player.getInventory().getContents()) {
if (ItemUtil.areItemsIdentical(stack, tStack)) {
amount += tStack.getAmount();
if (amount >= stack.getAmount()) {
found = true;
break;
}
}
}
if (!found) {
if (!def.missingConsumableMessage.isEmpty()) {
lplayer.printError(lplayer.translate(def.missingConsumableMessage).replace("%item%", stack.getAmount() + " " + stack.getType().name()));
}
break current;
}
}
for (ItemStack stack : def.consumables) {
boolean found = false;
int amount = stack.getAmount();
for (int i = 0; i < player.getInventory().getContents().length; i++) {
ItemStack tStack = player.getInventory().getContents()[i];
if (ItemUtil.areItemsIdentical(stack, tStack)) {
ItemStack toRemove = tStack.clone();
if (toRemove.getAmount() > amount) {
toRemove.setAmount(toRemove.getAmount() - amount);
player.getInventory().setItem(i, toRemove);
amount = 0;
} else {
amount -= toRemove.getAmount();
player.getInventory().setItem(i, null);
}
if (amount <= 0) {
found = true;
break;
}
}
}
if (!found) {
lplayer.printError("mech.command-items.out-of-sync");
break current;
}
}
if (def.consumeSelf) {
if (event instanceof PlayerInteractEvent && ((PlayerInteractEvent) event).getHand() == EquipmentSlot.OFF_HAND
|| event instanceof BlockPlaceEvent && ((BlockPlaceEvent) event).getHand() == EquipmentSlot.OFF_HAND) {
if (player.getInventory().getItemInOffHand().getAmount() > 1) {
player.getInventory().getItemInOffHand().setAmount(player.getInventory().getItemInOffHand().getAmount() - 1);
} else {
player.getInventory().setItemInOffHand(null);
}
} else if (event instanceof EntityPickupItemEvent) {
((EntityPickupItemEvent) event).getItem().remove();
((EntityPickupItemEvent) event).setCancelled(true);
} else {
if (player.getInventory().getItemInMainHand().getAmount() > 1) {
player.getInventory().getItemInMainHand().setAmount(player.getInventory().getItemInMainHand().getAmount() - 1);
} else {
player.getInventory().setItemInMainHand(null);
}
}
}
player.updateInventory();
}
for(String command : comdef.commands)
doCommand(command, event, comdef, player);
for(CommandItemAction action : comdef.actions)
if(action.stage == ActionRunStage.AFTER)
action.runAction(comdef, event, player);
if(comdef.cooldown > 0 && !lplayer.hasPermission("craftbook.mech.commanditems.bypasscooldown"))
cooldownPeriods.put(new Tuple2<>(lplayer.getName(), comdef.name), comdef.cooldown);
if(comdef.delayedCommands.length > 0)
Bukkit.getScheduler().runTaskLater(CraftBookPlugin.inst(), () -> {
for(String command : comdef.delayedCommands)
doCommand(command, event, comdef, player);
}, comdef.delay);
}
}
}
}
public static void doCommand(String command, Event event, CommandItemDefinition comdef, Player player) {
if(command == null || command.trim().isEmpty())
return;
command = parseLine(command, event, player);
if(comdef.type == CommandType.CONSOLE)
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command);
else if (comdef.type == CommandType.PLAYER) {
if (comdef.fakeCommand) {
ProtectionUtil.canSendCommand(player, command);
} else {
Bukkit.dispatchCommand(player, command);
}
} else if (comdef.type == CommandType.SUPERUSER) {
PermissionAttachment att = player.addAttachment(CraftBookPlugin.inst());
att.setPermission("*", true);
boolean wasOp = player.isOp();
if(!wasOp)
player.setOp(true);
try {
if (comdef.fakeCommand) {
ProtectionUtil.canSendCommand(player, command);
} else {
Bukkit.dispatchCommand(player, command);
}
} finally {
att.remove();
if(!wasOp)
player.setOp(false);
}
}
}
static String parseLine(String command, Event event, Player player) {
if(command == null) return null;
if(event instanceof EntityDamageByEntityEvent) {
command = StringUtils.replace(command, "@d.x", String.valueOf(((EntityDamageByEntityEvent) event).getEntity().getLocation().getX()));
command = StringUtils.replace(command, "@d.y", String.valueOf(((EntityDamageByEntityEvent) event).getEntity().getLocation().getY()));
command = StringUtils.replace(command, "@d.z", String.valueOf(((EntityDamageByEntityEvent) event).getEntity().getLocation().getZ()));
command = StringUtils.replace(command, "@d.bx", String.valueOf(((EntityDamageByEntityEvent) event).getEntity().getLocation().getBlockX()));
command = StringUtils.replace(command, "@d.by", String.valueOf(((EntityDamageByEntityEvent) event).getEntity().getLocation().getBlockY()));
command = StringUtils.replace(command, "@d.bz", String.valueOf(((EntityDamageByEntityEvent) event).getEntity().getLocation().getBlockZ()));
command = StringUtils.replace(command, "@d.w", ((EntityDamageByEntityEvent) event).getEntity().getLocation().getWorld().getName());
command = StringUtils.replace(command, "@d.l", ((EntityDamageByEntityEvent) event).getEntity().getLocation().toString());
command = StringUtils.replace(command, "@d.u", ((EntityDamageByEntityEvent) event).getEntity().getUniqueId().toString());
if(((EntityDamageByEntityEvent) event).getEntity() instanceof Player) {
command = StringUtils.replace(command, "@d.i", CraftBookPlugin.inst().getUUIDMappings().getCBID(((EntityDamageByEntityEvent) event).getEntity().getUniqueId()));
command = StringUtils.replace(command, "@d", ((EntityDamageByEntityEvent) event).getEntity().getName());
} else
command = StringUtils.replace(command, "@d", ((EntityDamageByEntityEvent) event).getEntity().getType().name());
}
if(event instanceof PlayerInteractEntityEvent) {
command = StringUtils.replace(command, "@d.x", String.valueOf(((PlayerInteractEntityEvent) event).getRightClicked().getLocation().getX()));
command = StringUtils.replace(command, "@d.y", String.valueOf(((PlayerInteractEntityEvent) event).getRightClicked().getLocation().getY()));
command = StringUtils.replace(command, "@d.z", String.valueOf(((PlayerInteractEntityEvent) event).getRightClicked().getLocation().getZ()));
command = StringUtils.replace(command, "@d.bx", String.valueOf(((PlayerInteractEntityEvent) event).getRightClicked().getLocation().getBlockX()));
command = StringUtils.replace(command, "@d.by", String.valueOf(((PlayerInteractEntityEvent) event).getRightClicked().getLocation().getBlockY()));
command = StringUtils.replace(command, "@d.bz", String.valueOf(((PlayerInteractEntityEvent) event).getRightClicked().getLocation().getBlockZ()));
command = StringUtils.replace(command, "@d.w", ((PlayerInteractEntityEvent) event).getRightClicked().getLocation().getWorld().getName());
command = StringUtils.replace(command, "@d.l", ((PlayerInteractEntityEvent) event).getRightClicked().getLocation().toString());
command = StringUtils.replace(command, "@d.u", ((PlayerInteractEntityEvent) event).getRightClicked().getUniqueId().toString());
if(((PlayerInteractEntityEvent) event).getRightClicked() instanceof Player) {
command = StringUtils.replace(command, "@d.i", CraftBookPlugin.inst().getUUIDMappings().getCBID(((PlayerInteractEntityEvent) event).getRightClicked().getUniqueId()));
command = StringUtils.replace(command, "@d", ((PlayerInteractEntityEvent) event).getRightClicked().getName());
} else
command = StringUtils.replace(command, "@d", ((PlayerInteractEntityEvent) event).getRightClicked().getType().name());
}
if(event instanceof BlockEvent) {
command = StringUtils.replace(command, "@b.x", String.valueOf(((BlockEvent) event).getBlock().getX()));
command = StringUtils.replace(command, "@b.y", String.valueOf(((BlockEvent) event).getBlock().getY()));
command = StringUtils.replace(command, "@b.z", String.valueOf(((BlockEvent) event).getBlock().getZ()));
command = StringUtils.replace(command, "@b.w", ((BlockEvent) event).getBlock().getLocation().getWorld().getName());
command = StringUtils.replace(command, "@b.l", ((BlockEvent) event).getBlock().getLocation().toString());
command = StringUtils.replace(command, "@b.d", String.valueOf(((BlockEvent) event).getBlock().getData()));
command = StringUtils.replace(command, "@b.t", ((BlockEvent) event).getBlock().getType().getKey().toString());
command = StringUtils.replace(command, "@b", ((BlockEvent) event).getBlock().getType().name());
}
if(event instanceof PlayerInteractEvent && ((PlayerInteractEvent) event).getClickedBlock() != null) {
command = StringUtils.replace(command, "@b.x", String.valueOf(((PlayerInteractEvent) event).getClickedBlock().getX()));
command = StringUtils.replace(command, "@b.y", String.valueOf(((PlayerInteractEvent) event).getClickedBlock().getY()));
command = StringUtils.replace(command, "@b.z", String.valueOf(((PlayerInteractEvent) event).getClickedBlock().getZ()));
command = StringUtils.replace(command, "@b.w", ((PlayerInteractEvent) event).getClickedBlock().getWorld().getName());
command = StringUtils.replace(command, "@b.l", ((PlayerInteractEvent) event).getClickedBlock().getLocation().toString());
command = StringUtils.replace(command, "@b.d", String.valueOf(((PlayerInteractEvent) event).getClickedBlock().getData()));
command = StringUtils.replace(command, "@b.t", ((PlayerInteractEvent) event).getClickedBlock().getType().getKey().toString());
command = StringUtils.replace(command, "@b", ((PlayerInteractEvent) event).getClickedBlock().getType().name());
}
if(event instanceof EntityEvent && ((EntityEvent) event).getEntityType() != null && command.contains("@e")) {
command = StringUtils.replace(command, "@e.x", String.valueOf(((EntityEvent) event).getEntity().getLocation().getX()));
command = StringUtils.replace(command, "@e.y", String.valueOf(((EntityEvent) event).getEntity().getLocation().getY()));
command = StringUtils.replace(command, "@e.z", String.valueOf(((EntityEvent) event).getEntity().getLocation().getZ()));
command = StringUtils.replace(command, "@e.bx", String.valueOf(((EntityEvent) event).getEntity().getLocation().getBlockX()));
command = StringUtils.replace(command, "@e.by", String.valueOf(((EntityEvent) event).getEntity().getLocation().getBlockY()));
command = StringUtils.replace(command, "@e.bz", String.valueOf(((EntityEvent) event).getEntity().getLocation().getBlockZ()));
command = StringUtils.replace(command, "@e.w", ((EntityEvent) event).getEntity().getLocation().getWorld().getName());
command = StringUtils.replace(command, "@e.l", ((EntityEvent) event).getEntity().getLocation().toString());
command = StringUtils.replace(command, "@e.u", ((EntityEvent) event).getEntity().getUniqueId().toString());
command = StringUtils.replace(command, "@e", ((EntityEvent) event).getEntityType().getName());
}
if(event instanceof AsyncPlayerChatEvent && command.contains("@m"))
command = StringUtils.replace(command, "@m", ((AsyncPlayerChatEvent) event).getMessage());
command = ParsingUtil.parsePlayerTags(command, player);
command = ParsingUtil.parseVariables(command, null);
return command;
}
@Override
public void loadConfiguration (YAMLProcessor config, String path) {
}
@Override
public LoadPriority getLoadPriority() {
return LoadPriority.EARLY;
}
}