Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rewrote "on block burns" event in new ScriptEvent format.
Removed from BukkitWorldScriptHelper.
- Loading branch information
Showing
3 changed files
with
97 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
96 changes: 96 additions & 0 deletions
96
src/main/java/net/aufdemrand/denizen/events/scriptevents/BlockBurnsScriptEvent.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.dLocation; | ||
import net.aufdemrand.denizen.objects.dMaterial; | ||
import net.aufdemrand.denizen.utilities.DenizenAPI; | ||
import net.aufdemrand.denizencore.events.ScriptEvent; | ||
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.block.BlockBurnEvent; | ||
|
||
import java.util.HashMap; | ||
|
||
public class BlockBurnsScriptEvent extends ScriptEvent implements Listener { | ||
|
||
// <--[event] | ||
// @Events | ||
// block burns | ||
// <block> burns | ||
// | ||
// @Cancellable true | ||
// | ||
// @Triggers when a block is destroyed by fire. | ||
// | ||
// @Context | ||
// <context.location> returns the dLocation the block was burned at. | ||
// <context.material> returns the dMaterial of the block that was burned. | ||
// | ||
// --> | ||
|
||
public BlockBurnsScriptEvent() { | ||
instance = this; | ||
} | ||
public static BlockBurnsScriptEvent instance; | ||
public dLocation location; | ||
public dMaterial material; | ||
public BlockBurnEvent event; | ||
|
||
@Override | ||
public boolean couldMatch(ScriptContainer scriptContainer, String s) { | ||
String lower = CoreUtilities.toLowerCase(s); | ||
String mat = CoreUtilities.getXthArg(0, lower); | ||
return lower.contains("block burns") | ||
|| (lower.equals(mat + " burns") && dMaterial.matches(mat)); | ||
} | ||
|
||
@Override | ||
public boolean matches(ScriptContainer scriptContainer, String s) { | ||
String lower = CoreUtilities.toLowerCase(s); | ||
String mat = CoreUtilities.getXthArg(0, lower); | ||
return mat.equals("block") | ||
|| (material.identifySimpleNoIdentifier().toLowerCase().equals(mat)); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "BlockBurns"; | ||
} | ||
|
||
@Override | ||
public void init() { | ||
Bukkit.getServer().getPluginManager().registerEvents(this, DenizenAPI.getCurrentInstance()); | ||
} | ||
|
||
@Override | ||
public void destroy() { | ||
BlockBurnEvent.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("location", location); | ||
context.put("material", material); | ||
return context; | ||
} | ||
|
||
@EventHandler | ||
public void onBlockBurns(BlockBurnEvent event) { | ||
location = new dLocation(event.getBlock().getLocation()); | ||
material = dMaterial.getMaterialFrom(event.getBlock().getType(), event.getBlock().getData()); | ||
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