-
-
Notifications
You must be signed in to change notification settings - Fork 106
/
PlayerUsesPortalScriptEvent.java
105 lines (91 loc) · 3.21 KB
/
PlayerUsesPortalScriptEvent.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
package net.aufdemrand.denizen.events.player;
import net.aufdemrand.denizen.BukkitScriptEntryData;
import net.aufdemrand.denizen.objects.dEntity;
import net.aufdemrand.denizen.objects.dLocation;
import net.aufdemrand.denizen.utilities.DenizenAPI;
import net.aufdemrand.denizencore.events.ScriptEvent;
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.Bukkit;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerPortalEvent;
import java.util.HashMap;
public class PlayerUsesPortalScriptEvent extends ScriptEvent implements Listener {
// <--[event]
// @Events
// player uses portal
//
// @Cancellable false
//
// @Triggers when a player enters a portal.
//
// @Context
// <context.from> returns the location teleported from.
// <context.to> returns the location teleported to.
//
// @Determine
// dLocation to change the destination.
// -->
public PlayerUsesPortalScriptEvent() {
instance = this;
}
public static PlayerUsesPortalScriptEvent instance;
public dEntity entity;
public dLocation to;
public dLocation from;
public PlayerPortalEvent event;
@Override
public boolean couldMatch(ScriptContainer scriptContainer, String s) {
return CoreUtilities.toLowerCase(s).contains("player uses portal");
}
@Override
public boolean matches(ScriptContainer scriptContainer, String s) {
return true;
}
@Override
public String getName() {
return "PlayerUsesPortal";
}
@Override
public void init() {
Bukkit.getServer().getPluginManager().registerEvents(this, DenizenAPI.getCurrentInstance());
}
@Override
public void destroy() {
PlayerPortalEvent.getHandlerList().unregister(this);
}
@Override
public boolean applyDetermination(ScriptContainer container, String determination) {
if (dLocation.matches(determination)) {
to = dLocation.valueOf(determination);
return true;
}
return super.applyDetermination(container, determination);
}
@Override
public ScriptEntryData getScriptEntryData() {
return new BukkitScriptEntryData(entity.isPlayer() ? dEntity.getPlayerFrom(event.getPlayer()): null, null);
}
@Override
public HashMap<String, dObject> getContext() {
HashMap<String, dObject> context = super.getContext();
context.put("entity", entity);
context.put("to", to);
context.put("from", from);
return context;
}
@EventHandler
public void onEntityEntersPortal(PlayerPortalEvent event) {
entity = new dEntity(event.getPlayer());
to = new dLocation(event.getTo());
from = new dLocation(event.getFrom());
cancelled = event.isCancelled();
this.event = event;
fire();
event.setCancelled(cancelled);
event.setTo(to);
}
}