Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
124 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
122 changes: 122 additions & 0 deletions
122
src/main/java/net/aufdemrand/denizen/events/entity/EntityGlideScriptEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
package net.aufdemrand.denizen.events.entity; | ||
|
||
import net.aufdemrand.denizen.BukkitScriptEntryData; | ||
import net.aufdemrand.denizen.events.BukkitScriptEvent; | ||
import net.aufdemrand.denizen.objects.dEntity; | ||
import net.aufdemrand.denizen.utilities.DenizenAPI; | ||
import net.aufdemrand.denizencore.objects.Element; | ||
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.entity.EntityToggleGlideEvent; | ||
|
||
public class EntityGlideScriptEvent extends BukkitScriptEvent implements Listener { | ||
|
||
// <--[event] | ||
// @Events | ||
// entity toggles gliding (in <area>) | ||
// entity starts gliding (in <area>) | ||
// entity stops gliding (in <area>) | ||
// | ||
// @Regex ^on player (toggles|starts|stops) gliding( in ((notable (cuboid|ellipsoid))|([^\s]+)))?$ | ||
// | ||
// @Cancellable true | ||
// | ||
// @Triggers when an entity starts or stops gliding. | ||
// | ||
// @Context | ||
// <context.entity> returns the dEntity of this event. | ||
// <context.state> returns an Element(Boolean) with a value of "true" if the entity is now gliding and "false" otherwise. | ||
// | ||
// @Player when the entity is a player. | ||
// | ||
// @NPC when the entity is an NPC. | ||
// | ||
// --> | ||
|
||
public EntityGlideScriptEvent() { | ||
instance = this; | ||
} | ||
|
||
public static EntityGlideScriptEvent instance; | ||
public dEntity entity; | ||
public Boolean state; | ||
|
||
@Override | ||
public boolean couldMatch(ScriptContainer scriptContainer, String s) { | ||
return CoreUtilities.getXthArg(2, CoreUtilities.toLowerCase(s)).equals("gliding"); | ||
} | ||
|
||
@Override | ||
public boolean matches(ScriptContainer scriptContainer, String s) { | ||
String lower = CoreUtilities.toLowerCase(s); | ||
|
||
if (!tryEntity(entity, CoreUtilities.getXthArg(0, lower))) { | ||
return false; | ||
} | ||
|
||
String cmd = CoreUtilities.getXthArg(1, lower); | ||
if (cmd.equals("starts") && !state) { | ||
return false; | ||
} | ||
if (cmd.equals("stops") && state) { | ||
return false; | ||
} | ||
|
||
if (!runInCheck(scriptContainer, s, lower, entity.getLocation())) { | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "EntityGlide"; | ||
} | ||
|
||
@Override | ||
public void init() { | ||
Bukkit.getServer().getPluginManager().registerEvents(this, DenizenAPI.getCurrentInstance()); | ||
} | ||
|
||
@Override | ||
public void destroy() { | ||
EntityToggleGlideEvent.getHandlerList().unregister(this); | ||
} | ||
|
||
@Override | ||
public boolean applyDetermination(ScriptContainer container, String determination) { | ||
return super.applyDetermination(container, determination); | ||
} | ||
|
||
@Override | ||
public ScriptEntryData getScriptEntryData() { | ||
return new BukkitScriptEntryData(entity.isPlayer() ? entity.getDenizenPlayer() : null, | ||
entity.isCitizensNPC() ? entity.getDenizenNPC() : null); | ||
} | ||
|
||
@Override | ||
public dObject getContext(String name) { | ||
if (name.equals("entity")) { | ||
return entity; | ||
} | ||
else if (name.equals("state")) { | ||
return new Element(state); | ||
} | ||
return super.getContext(name); | ||
} | ||
|
||
@EventHandler | ||
public void onEntityToggleGlide(EntityToggleGlideEvent event) { | ||
entity = new dEntity(event.getEntity()); | ||
state = event.isGliding(); | ||
cancelled = event.isCancelled(); | ||
fire(); | ||
event.setCancelled(cancelled); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters