-
-
Notifications
You must be signed in to change notification settings - Fork 42
/
BossShopCommand.java
109 lines (86 loc) · 3.53 KB
/
BossShopCommand.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
package com.denizenscript.depenizen.bukkit.commands.bossshop;
import com.denizenscript.depenizen.bukkit.bridges.BossShopBridge;
import net.aufdemrand.denizen.BukkitScriptEntryData;
import net.aufdemrand.denizen.objects.dPlayer;
import net.aufdemrand.denizencore.exceptions.InvalidArgumentsException;
import net.aufdemrand.denizencore.objects.Element;
import net.aufdemrand.denizencore.objects.aH;
import net.aufdemrand.denizencore.scripts.ScriptEntry;
import net.aufdemrand.denizencore.scripts.commands.AbstractCommand;
import org.black_ixx.bossshop.BossShop;
import org.black_ixx.bossshop.core.BSShop;
import net.aufdemrand.denizencore.utilities.debugging.dB;
public class BossShopCommand extends AbstractCommand {
// <--[command]
// @Name bossshop
// @Syntax bossshop [<shop name>] (target:<player>)
// @Group Depenizen
// @Plugin DepenizenBukkit, BossShop
// @Required 1
// @Short Opens a BossShop inventory for a player.
// @Description
// Use to open up a BossShop inventory for either
// the player attached to the queue or specified target.
// Useful for rewarding players using the BossShop plugin.
// Shops are made with the BossShop system.
//
// @Tags
// <in@inventory.is_bossshop>
// @Usage
// Use to open a bossshop inventory for the player in the queue as a Player.
// - bossshop "MyShop"
// @Usage
// Use to open a bossshop inventory for the target.
// - bossshop "MyShop" target:<player>
// -->
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
for (aH.Argument arg : aH.interpret(scriptEntry.getArguments())) {
if (!scriptEntry.hasObject("target")
&& arg.matchesPrefix("target")) {
scriptEntry.addObject("target", arg.asType(dPlayer.class));
}
else if (!scriptEntry.hasObject("shop")) {
scriptEntry.addObject("shop", arg.asElement());
}
else {
arg.reportUnhandled();
}
}
if (!scriptEntry.hasObject("shop")) {
throw new InvalidArgumentsException("Shop not specified!");
}
if (!scriptEntry.hasObject("target")) {
if (((BukkitScriptEntryData) scriptEntry.entryData).hasPlayer()) {
scriptEntry.addObject("target", ((BukkitScriptEntryData) scriptEntry.entryData).getPlayer());
}
else {
throw new InvalidArgumentsException("This command does not have a player attached!");
}
}
}
@Override
public void execute(ScriptEntry scriptEntry) {
dPlayer target = scriptEntry.getdObject("target");
Element dshop = scriptEntry.getdObject("shop");
// Report to dB
dB.report(scriptEntry, getName(),
(target != null ? target.debug() : "")
+ (dshop != null ? dshop.debug() : ""));
if (target == null) {
dB.echoError(scriptEntry.getResidingQueue(), "Target not found!");
return;
}
if (dshop == null) {
dB.echoError(scriptEntry.getResidingQueue(), "Shop not Specified!");
return;
}
BossShop bs = (BossShop) BossShopBridge.instance.plugin;
BSShop shop = bs.getAPI().getShop(dshop.asString());
if (shop == null) {
dB.echoError(scriptEntry.getResidingQueue(), "Shop not found!");
return;
}
bs.getAPI().openShop(target.getPlayerEntity(), shop);
}
}