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 falls" event in new ScriptEvent format.
- Loading branch information
Showing
3 changed files
with
89 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/BlockFallsSmartEvent.java
This file was deleted.
Oops, something went wrong.
88 changes: 88 additions & 0 deletions
88
src/main/java/net/aufdemrand/denizen/events/scriptevents/BlockFallsScriptEvent.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,88 @@ | ||
package net.aufdemrand.denizen.events.scriptevents; | ||
|
||
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.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.EntityChangeBlockEvent; | ||
|
||
import java.util.HashMap; | ||
|
||
public class BlockFallsScriptEvent extends ScriptEvent implements Listener { | ||
|
||
// <--[event] | ||
// @Events | ||
// block falls | ||
// <material> falls | ||
// | ||
// @Cancellable true | ||
// | ||
// @Triggers when a block falls. | ||
// | ||
// @Context | ||
// <context.location> returns the location of the block. | ||
// | ||
// --> | ||
|
||
public BlockFallsScriptEvent() { | ||
instance = this; | ||
} | ||
public static BlockFallsScriptEvent instance; | ||
public dLocation location; | ||
public EntityChangeBlockEvent event; | ||
|
||
@Override | ||
public boolean couldMatch(ScriptContainer scriptContainer, String s) { | ||
String lower = CoreUtilities.toLowerCase(s); | ||
return lower.contains("falls"); | ||
} | ||
|
||
@Override | ||
public boolean matches(ScriptContainer scriptContainer, String s) { | ||
String lower = CoreUtilities.toLowerCase(s); | ||
return lower.equals("block falls") | ||
|| lower.equals(event.getBlock().getType().name().toLowerCase() + " falls"); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "BlockFalls"; | ||
} | ||
|
||
@Override | ||
public void init() { | ||
Bukkit.getServer().getPluginManager().registerEvents(this, DenizenAPI.getCurrentInstance()); | ||
} | ||
|
||
@Override | ||
public void destroy() { | ||
EntityChangeBlockEvent.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); | ||
return context; | ||
} | ||
|
||
@EventHandler | ||
public void onBlockPhysics(EntityChangeBlockEvent event) { | ||
location = new dLocation(event.getBlock().getLocation()); | ||
cancelled = event.isCancelled(); | ||
this.event = event; | ||
fire(); | ||
event.setCancelled(cancelled); | ||
} | ||
} |