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 combusts" event in new ScriptEvent format.
- Loading branch information
Showing
3 changed files
with
97 additions
and
99 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
98 changes: 0 additions & 98 deletions
98
src/main/java/net/aufdemrand/denizen/events/core/EntityCombustSmartEvent.java
This file was deleted.
Oops, something went wrong.
96 changes: 96 additions & 0 deletions
96
src/main/java/net/aufdemrand/denizen/events/scriptevents/EntityCombustsScriptEvent.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,96 @@ | ||
package net.aufdemrand.denizen.events.scriptevents; | ||
|
||
import net.aufdemrand.denizen.objects.dEntity; | ||
import net.aufdemrand.denizen.utilities.DenizenAPI; | ||
import net.aufdemrand.denizencore.events.ScriptEvent; | ||
import net.aufdemrand.denizencore.objects.Element; | ||
import net.aufdemrand.denizencore.objects.dObject; | ||
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.EntityCombustEvent; | ||
|
||
import java.util.HashMap; | ||
|
||
public class EntityCombustsScriptEvent extends ScriptEvent implements Listener { | ||
|
||
// <--[event] | ||
// @Events | ||
// entity combusts | ||
// <entity> combusts | ||
// | ||
// @Cancellable true | ||
// | ||
// @Triggers when an entity combusts. | ||
// | ||
// @Context | ||
// <context.duration> returns how long the entity takes to combust. | ||
// <context.entity> returns the dEntity that combusted. | ||
// | ||
// --> | ||
|
||
public EntityCombustsScriptEvent() { | ||
instance = this; | ||
} | ||
public static EntityCombustsScriptEvent instance; | ||
public dEntity entity; | ||
public Element duration; | ||
public EntityCombustEvent event; | ||
|
||
@Override | ||
public boolean couldMatch(ScriptContainer scriptContainer, String s) { | ||
String lower = CoreUtilities.toLowerCase(s); | ||
return lower.contains("combusts"); | ||
} | ||
|
||
@Override | ||
public boolean matches(ScriptContainer scriptContainer, String s) { | ||
String lower = CoreUtilities.toLowerCase(s); | ||
|
||
return lower.equals("entity combusts") | ||
|| lower.equals(entity.identifyType() + " combusts") | ||
|| lower.equals(entity.identifySimple() + " combusts"); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "EntityCombusts"; | ||
} | ||
|
||
@Override | ||
public void init() { | ||
Bukkit.getServer().getPluginManager().registerEvents(this, DenizenAPI.getCurrentInstance()); | ||
} | ||
|
||
@Override | ||
public void destroy() { | ||
EntityCombustEvent.getHandlerList().unregister(this); | ||
} | ||
|
||
@Override | ||
public boolean applyDetermination(ScriptContainer container, String determination) { | ||
return super.applyDetermination(container, determination); | ||
} | ||
|
||
@Override | ||
public HashMap<String, dObject> getContext() { | ||
HashMap<String, dObject> context = super.getContext(); | ||
context.put("entity", entity); | ||
context.put("duration", duration); | ||
return context; | ||
} | ||
|
||
@EventHandler | ||
public void onEntityCombust(EntityCombustEvent event) { | ||
entity = new dEntity(event.getEntity()); | ||
duration = new Element(event.getDuration()); | ||
cancelled = event.isCancelled(); | ||
this.event = event; | ||
fire(); | ||
event.setCancelled(cancelled); | ||
} | ||
|
||
} |