Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Converted "on pig zapped" event to new ScriptEvent format.
- Loading branch information
Showing
3 changed files
with
94 additions
and
33 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
93 changes: 93 additions & 0 deletions
93
src/main/java/net/aufdemrand/denizen/events/entity/PigZappedScriptEvent.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,93 @@ | ||
package net.aufdemrand.denizen.events.entity; | ||
|
||
import net.aufdemrand.denizen.events.BukkitScriptEvent; | ||
import net.aufdemrand.denizen.objects.dEntity; | ||
import net.aufdemrand.denizen.utilities.DenizenAPI; | ||
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.PigZapEvent; | ||
|
||
import java.util.HashMap; | ||
|
||
public class PigZappedScriptEvent extends BukkitScriptEvent implements Listener { | ||
|
||
// <--[event] | ||
// @Events | ||
// pig zapped | ||
// | ||
// @Cancellable true | ||
// | ||
// @Triggers when a pig is zapped by lightning and turned into a pig zombie. | ||
// | ||
// @Context | ||
// <context.pig> returns the dEntity of the pig. | ||
// <context.pig_zombie> returns the dEntity of the pig zombie. | ||
// <context.lightning> returns the dEntity of the lightning. | ||
// | ||
// --> | ||
|
||
public PigZappedScriptEvent() { | ||
instance = this; | ||
} | ||
public static PigZappedScriptEvent instance; | ||
public dEntity pig; | ||
public dEntity pig_zombie; | ||
private dEntity lightning; | ||
public PigZapEvent event; | ||
|
||
@Override | ||
public boolean couldMatch(ScriptContainer scriptContainer, String s) { | ||
String lower = CoreUtilities.toLowerCase(s); | ||
return (lower.equals("pig zapped")); | ||
} | ||
|
||
@Override | ||
public boolean matches(ScriptContainer scriptContainer, String s) { | ||
return true; | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "PigZapped"; | ||
} | ||
|
||
@Override | ||
public void init() { | ||
Bukkit.getServer().getPluginManager().registerEvents(this, DenizenAPI.getCurrentInstance()); | ||
} | ||
|
||
@Override | ||
public void destroy() { | ||
PigZapEvent.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("pig", pig); | ||
context.put("pig_zombie", pig_zombie); | ||
context.put("lightning", lightning); | ||
return context; | ||
} | ||
|
||
@EventHandler | ||
public void onPigZapped(PigZapEvent event) { | ||
pig = new dEntity(event.getEntity()); | ||
pig_zombie= new dEntity(event.getPigZombie()); | ||
lightning = new dEntity(event.getLightning()); | ||
cancelled = event.isCancelled(); | ||
this.event = event; | ||
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