Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rewrote "on entity enters portal" event in new ScriptEvent format.
Removed from BukkitWorldScriptHelper.
- Loading branch information
Showing
3 changed files
with
106 additions
and
32 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
105 changes: 105 additions & 0 deletions
105
src/main/java/net/aufdemrand/denizen/events/scriptevents/EntityEntersPortalScriptEvent.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,105 @@ | ||
package net.aufdemrand.denizen.events.scriptevents; | ||
|
||
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.entity.EntityPortalEnterEvent; | ||
|
||
import java.util.Arrays; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
|
||
public class EntityEntersPortalScriptEvent extends ScriptEvent implements Listener { | ||
|
||
// <--[event] | ||
// @Events | ||
// entity enters portal | ||
// <entity> enters portal | ||
// | ||
// @Cancellable false | ||
// | ||
// @Triggers when an entity enters a portal. | ||
// | ||
// @Context | ||
// <context.entity> returns the dEntity. | ||
// <context.location> returns the dLocation of the portal block touched by the entity. | ||
// | ||
// --> | ||
|
||
public EntityEntersPortalScriptEvent() { | ||
instance = this; | ||
} | ||
public static EntityEntersPortalScriptEvent instance; | ||
public dEntity entity; | ||
public dLocation location; | ||
public EntityPortalEnterEvent event; | ||
|
||
@Override | ||
public boolean couldMatch(ScriptContainer scriptContainer, String s) { | ||
String lower = CoreUtilities.toLowerCase(s); | ||
String entOne = CoreUtilities.getXthArg(0, lower); | ||
List<String> types = Arrays.asList("entity", "player", "npc"); | ||
return (types.contains(entOne) || dEntity.matches(entOne)) | ||
&& lower.contains("enters portal"); | ||
} | ||
|
||
@Override | ||
public boolean matches(ScriptContainer scriptContainer, String s) { | ||
String lower = CoreUtilities.toLowerCase(s); | ||
String target = CoreUtilities.getXthArg(0,lower); | ||
List<String> types = Arrays.asList("entity", "player", "npc"); | ||
return types.contains(target) || entity.matchesEntity(target); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "EntityEntersPortal"; | ||
} | ||
|
||
@Override | ||
public void init() { | ||
Bukkit.getServer().getPluginManager().registerEvents(this, DenizenAPI.getCurrentInstance()); | ||
} | ||
|
||
@Override | ||
public void destroy() { | ||
EntityPortalEnterEvent.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() ? dEntity.getPlayerFrom(event.getEntity()): null, | ||
entity.isCitizensNPC() ? dEntity.getNPCFrom(event.getEntity()): null); | ||
} | ||
|
||
@Override | ||
public HashMap<String, dObject> getContext() { | ||
HashMap<String, dObject> context = super.getContext(); | ||
context.put("entity", entity); | ||
context.put("location", location); | ||
return context; | ||
} | ||
|
||
@EventHandler | ||
public void onEntityEntersPortal(EntityPortalEnterEvent event) { | ||
entity = new dEntity(event.getEntity()); | ||
location = new dLocation(event.getLocation()); | ||
this.event = event; | ||
fire(); | ||
} | ||
} |
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