/
AreaShopExpiresScriptEvent.java
84 lines (73 loc) · 2.52 KB
/
AreaShopExpiresScriptEvent.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
package com.denizenscript.depenizen.bukkit.events.areashop;
import me.wiefferink.areashop.events.notify.UnrentedRegionEvent;
import com.denizenscript.denizen.BukkitScriptEntryData;
import com.denizenscript.denizen.events.BukkitScriptEvent;
import com.denizenscript.denizen.objects.PlayerTag;
import com.denizenscript.denizencore.objects.ObjectTag;
import com.denizenscript.denizencore.scripts.ScriptEntryData;
import com.denizenscript.denizencore.scripts.containers.ScriptContainer;
import com.denizenscript.denizencore.utilities.CoreUtilities;
import com.denizenscript.depenizen.bukkit.objects.areashop.AreaShopTag;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
public class AreaShopExpiresScriptEvent extends BukkitScriptEvent implements Listener {
// <--[event]
// @Events
// areashop shop expires
// areashop <shop> expires
//
// @Regex ^on areashop [^\s]+ expires$
//
// @Triggers when an AreaShop's rent expires.
//
// @Context
// <context.shop> Returns the AreaShop that's expiring.
//
// @Plugin Depenizen, AreaShop
//
// -->
public AreaShopExpiresScriptEvent() {
instance = this;
}
public static AreaShopExpiresScriptEvent instance;
public UnrentedRegionEvent event;
public AreaShopTag areaShop;
@Override
public boolean couldMatch(ScriptContainer scriptContainer, String s) {
String lower = CoreUtilities.toLowerCase(s);
return s.startsWith("areashop") && CoreUtilities.xthArgEquals(2, lower, "expires");
}
@Override
public boolean matches(ScriptPath path) {
String shopName = path.eventArgLowerAt(2).replace("areashop@", "");
if (shopName.equals("shop")) {
return true;
}
AreaShopTag shop = AreaShopTag.valueOf(shopName);
return shop != null && shop.equals(areaShop);
}
@Override
public String getName() {
return "AreaShopExpires";
}
@Override
public ScriptEntryData getScriptEntryData() {
return new BukkitScriptEntryData(new PlayerTag(event.getOldRenter()), null);
}
@Override
public ObjectTag getContext(String name) {
if (name.equals("shop")) {
return areaShop;
}
return super.getContext(name);
}
@EventHandler
public void onAreaShopExpires(UnrentedRegionEvent event) {
if (event.getRefundedMoney() > 0) {
return;
}
areaShop = new AreaShopTag(event.getRegion());
this.event = event;
fire(event);
}
}