-
-
Notifications
You must be signed in to change notification settings - Fork 44
/
mcMMOPlayerLevelDownScriptEvent.java
130 lines (115 loc) · 4.25 KB
/
mcMMOPlayerLevelDownScriptEvent.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
package com.denizenscript.depenizen.bukkit.events.mcmmo;
import com.gmail.nossr50.events.experience.McMMOPlayerLevelDownEvent;
import net.aufdemrand.denizen.BukkitScriptEntryData;
import net.aufdemrand.denizen.events.BukkitScriptEvent;
import net.aufdemrand.denizen.objects.dEntity;
import net.aufdemrand.denizen.objects.dPlayer;
import net.aufdemrand.denizencore.objects.Element;
import net.aufdemrand.denizencore.objects.aH;
import net.aufdemrand.denizencore.objects.dObject;
import net.aufdemrand.denizencore.scripts.ScriptEntryData;
import net.aufdemrand.denizencore.scripts.containers.ScriptContainer;
import net.aufdemrand.denizencore.utilities.CoreUtilities;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
public class mcMMOPlayerLevelDownScriptEvent extends BukkitScriptEvent implements Listener {
// <--[event]
// @Events
// mcmmo player levels down skill (in <area>)
// mcmmo player levels down <skill> (in <area>)
//
// @Regex ^on mcmmo player levels down [^\s]+( in ((notable (cuboid|ellipsoid))|([^\s]+)))?$
//
// @Cancellable true
//
// @Triggers when a player loses levels for an mcMMO skill.
//
// @Context
// <context.skill> returns the name of the skill that lost levels. (Based on the mcMMO language file).
// <context.levels_lost> returns the number of levels lost.
// <context.old_level> returns the old level of the skill.
// <context.new_level> returns the new level of the skill.
// <context.cause> returns the cause of the level loss.
// Will be one of: 'PVP', 'PVE', 'VAMPIRISM', 'SHARED_PVP', 'SHARED_PVE', 'COMMAND', 'UNKNOWN'.
//
// @Determine
// Element(Number) to set the number of levels to gain.
//
// @Plugin Depenizen, mcMMO
// -->
public mcMMOPlayerLevelDownScriptEvent() {
instance = this;
}
public static mcMMOPlayerLevelDownScriptEvent instance;
public McMMOPlayerLevelDownEvent event;
public dPlayer player;
public Element skill;
public int new_level;
public int levels_lost;
public Element cause;
@Override
public boolean couldMatch(ScriptContainer scriptContainer, String s) {
return CoreUtilities.toLowerCase(s).startsWith("mcmmo player levels down");
}
@Override
public boolean matches(ScriptPath path) {
String eSkill = path.eventArgLowerAt(4);
if (!eSkill.equals("skill") && !eSkill.equals(CoreUtilities.toLowerCase(skill.asString()))) {
return false;
}
if (!runInCheck(path, player.getLocation())) {
return false;
}
return true;
}
@Override
public String getName() {
return "mcMMOPlayerLevelsDown";
}
@Override
public boolean applyDetermination(ScriptContainer container, String determination) {
String lower = CoreUtilities.toLowerCase(determination);
if (aH.matchesInteger(lower)) {
levels_lost = aH.getIntegerFrom(lower);
return true;
}
return super.applyDetermination(container, determination);
}
@Override
public ScriptEntryData getScriptEntryData() {
return new BukkitScriptEntryData(player, null);
}
@Override
public dObject getContext(String name) {
if (name.equals("skill")) {
return skill;
}
else if (name.equals("new_level")) {
return new Element(new_level);
}
else if (name.equals("old_level")) {
return new Element(new_level + levels_lost);
}
else if (name.equals("levels_lost")) {
return new Element(levels_lost);
}
else if (name.equals("cause")) {
return cause;
}
return super.getContext(name);
}
@EventHandler
public void onmcMMOPlayerLevelDown(McMMOPlayerLevelDownEvent event) {
if (dEntity.isNPC(event.getPlayer())) {
return;
}
player = dPlayer.mirrorBukkitPlayer(event.getPlayer());
levels_lost = event.getLevelsLost();
new_level = event.getSkillLevel();
cause = new Element(event.getXpGainReason().toString());
skill = new Element(event.getSkill().getName());
this.event = event;
fire(event);
event.setLevelsLost(levels_lost);
}
}