-
-
Notifications
You must be signed in to change notification settings - Fork 103
/
PlayerJumpScriptEvent.java
97 lines (84 loc) · 3.06 KB
/
PlayerJumpScriptEvent.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
package com.denizenscript.denizen.events.player;
import com.denizenscript.denizen.objects.EntityTag;
import com.denizenscript.denizen.objects.LocationTag;
import com.denizenscript.denizen.utilities.implementation.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 org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerMoveEvent;
public class PlayerJumpScriptEvent extends BukkitScriptEvent implements Listener {
// <--[event]
// @Events
// player jumps
//
// @Regex ^on player jumps$
//
// @Group Player
//
// @Location true
//
// @Triggers when a player jumps.
//
// @Warning On Spigot servers, this event and its data are inaccurate and unreliable. This event works more stably on Paper servers.
//
// @Context
// <context.location> returns the location the player jumped from.
//
// @Player Always.
//
// -->
public PlayerJumpScriptEvent() {
instance = this;
}
public static PlayerJumpScriptEvent instance;
public LocationTag location;
public PlayerTag player;
@Override
public boolean couldMatch(ScriptPath path) {
return path.eventLower.startsWith("player jumps");
}
@Override
public boolean matches(ScriptPath path) {
if (!runInCheck(path, location)) {
return false;
}
return super.matches(path);
}
@Override
public String getName() {
return "PlayerJumps";
}
@Override
public ScriptEntryData getScriptEntryData() {
return new BukkitScriptEntryData(player, null);
}
@Override
public ObjectTag getContext(String name) {
if (name.equals("location")) {
return location;
}
return super.getContext(name);
}
public static class PlayerJumpsSpigotScriptEventImpl extends PlayerJumpScriptEvent {
@EventHandler
public void onPlayerJumps(PlayerMoveEvent event) {
if (EntityTag.isNPC(event.getPlayer())) {
return;
}
// Check that the block level changed (Upward)
if (event.getTo().getBlockY() > event.getFrom().getBlockY()
// and also that the player has a high velocity (jump instead of walking up stairs)
&& Math.abs(event.getPlayer().getVelocity().getY()) > 0.1
// and that the player isn't in any form of fast moving vehicle
&& event.getPlayer().getVehicle() == null) {
// Not perfect checking, but close enough until Bukkit adds a proper event
location = new LocationTag(event.getFrom());
player = new PlayerTag(event.getPlayer());
fire(event);
}
}
}
}