Skip to content

Commit

Permalink
Rewrote "on entity combusts" event in new ScriptEvent format.
Browse files Browse the repository at this point in the history
  • Loading branch information
Talamar1 committed Jun 11, 2015
1 parent 345d8bc commit 7dd9187
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 99 deletions.
2 changes: 1 addition & 1 deletion src/main/java/net/aufdemrand/denizen/Denizen.java
Expand Up @@ -569,7 +569,6 @@ public void onEnable() {
// Register all the 'Core' SmartEvents.
OldEventManager.registerSmartEvent(new CommandSmartEvent());
OldEventManager.registerSmartEvent(new CuboidEnterExitSmartEvent());
OldEventManager.registerSmartEvent(new EntityCombustSmartEvent());
OldEventManager.registerSmartEvent(new EntityDamageSmartEvent());
OldEventManager.registerSmartEvent(new EntityDeathSmartEvent());
OldEventManager.registerSmartEvent(new EntityInteractSmartEvent());
Expand All @@ -595,6 +594,7 @@ public void onEnable() {
ScriptEvent.registerScriptEvent(new ChatScriptEvent());
ScriptEvent.registerScriptEvent(new ChunkLoadScriptEvent());
ScriptEvent.registerScriptEvent(new ChunkUnloadScriptEvent());
ScriptEvent.registerScriptEvent(new EntityCombustsScriptEvent());
ScriptEvent.registerScriptEvent(new EntityDespawnScriptEvent());
ScriptEvent.registerScriptEvent(new EntityTeleportScriptEvent());
ScriptEvent.registerScriptEvent(new LiquidSpreadScriptEvent());
Expand Down

This file was deleted.

@@ -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);
}

}

0 comments on commit 7dd9187

Please sign in to comment.