Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add "player steers entity" event http://one.denizenscript.com/haste/3…
…6123 For example, http://one.denizenscript.com/haste/36123 http://one.denizenscript.com/haste/36123 http://one.denizenscript.com/haste/36123 http://one.denizenscript.com/haste/36123
- Loading branch information
Showing
3 changed files
with
149 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
107 changes: 107 additions & 0 deletions
107
plugin/src/main/java/net/aufdemrand/denizen/events/player/PlayerSteersEntityScriptEvent.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,107 @@ | ||
package net.aufdemrand.denizen.events.player; | ||
|
||
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.dObject; | ||
import net.aufdemrand.denizencore.scripts.ScriptEntryData; | ||
import net.aufdemrand.denizencore.scripts.containers.ScriptContainer; | ||
import net.aufdemrand.denizencore.utilities.CoreUtilities; | ||
|
||
public class PlayerSteersEntityScriptEvent extends BukkitScriptEvent { | ||
|
||
// <--[event] | ||
// @Events | ||
// player steers entity (in <area>) | ||
// player steers <entity> (in <area>) | ||
// | ||
// @Regex ^on player steers [^\s]+( in ((notable (cuboid|ellipsoid))|([^\s]+)))?$ | ||
// | ||
// @Cancellable true | ||
// | ||
// @Triggers when a player attempts to steer an entity. | ||
// | ||
// @Context | ||
// <context.entity> returns the dEntity being steered by the player. | ||
// <context.sideways> returns an Element(Decimal) where a positive number signifies leftward movement. | ||
// <context.forward> returns an Element(Decimal) where a positive number signifies forward movement. | ||
// <context.jump> returns an Element(Boolean) that signifies whether the player is attempting to jump with the entity. | ||
// <context.dismount> returns an Element(Boolean) that signifies whether the player is attempting to dismount. | ||
// | ||
// --> | ||
|
||
public PlayerSteersEntityScriptEvent() { | ||
instance = this; | ||
} | ||
|
||
public static PlayerSteersEntityScriptEvent instance; | ||
public boolean enabled; | ||
public dEntity entity; | ||
public dPlayer player; | ||
public Element sideways; | ||
public Element forward; | ||
public Element jump; | ||
public Element dismount; | ||
|
||
@Override | ||
public boolean couldMatch(ScriptContainer scriptContainer, String s) { | ||
return CoreUtilities.getXthArg(1, CoreUtilities.toLowerCase(s)).startsWith("steers"); | ||
} | ||
|
||
@Override | ||
public boolean matches(ScriptContainer scriptContainer, String s) { | ||
String lower = CoreUtilities.toLowerCase(s); | ||
String entityName = CoreUtilities.getXthArg(2, lower); | ||
if (!tryEntity(entity, entityName)) { | ||
return false; | ||
} | ||
return runInCheck(scriptContainer, s, lower, entity.getLocation()); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "PlayerSteersEntity"; | ||
} | ||
|
||
@Override | ||
public void init() { | ||
enabled = true; | ||
} | ||
|
||
@Override | ||
public void destroy() { | ||
enabled = false; | ||
} | ||
|
||
@Override | ||
public boolean applyDetermination(ScriptContainer container, String determination) { | ||
return super.applyDetermination(container, determination); | ||
} | ||
|
||
@Override | ||
public ScriptEntryData getScriptEntryData() { | ||
return new BukkitScriptEntryData(player, entity.isCitizensNPC() ? entity.getDenizenNPC() : null); | ||
} | ||
|
||
@Override | ||
public dObject getContext(String name) { | ||
if (name.equals("entity")) { | ||
return entity; | ||
} | ||
else if (name.equals("sideways")) { | ||
return sideways; | ||
} | ||
else if (name.equals("forward")) { | ||
return forward; | ||
} | ||
else if (name.equals("jump")) { | ||
return jump; | ||
} | ||
else if (name.equals("dismount")) { | ||
return dismount; | ||
} | ||
return super.getContext(name); | ||
} | ||
} |
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