Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
315be97
commit 08c479a
Showing
2 changed files
with
88 additions
and
0 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
87 changes: 87 additions & 0 deletions
87
...in/src/main/java/com/denizenscript/denizen/events/block/LiquidLevelChangeScriptEvent.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,87 @@ | ||
package com.denizenscript.denizen.events.block; | ||
|
||
import com.denizenscript.denizen.events.BukkitScriptEvent; | ||
import com.denizenscript.denizen.objects.LocationTag; | ||
import com.denizenscript.denizen.objects.MaterialTag; | ||
import com.denizenscript.denizencore.objects.ObjectTag; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.Listener; | ||
import org.bukkit.event.block.FluidLevelChangeEvent; | ||
|
||
public class LiquidLevelChangeScriptEvent extends BukkitScriptEvent implements Listener { | ||
|
||
// <--[event] | ||
// @Events | ||
// liquid|lava|water level changes | ||
// | ||
// @Group Block | ||
// | ||
// @Location true | ||
// | ||
// @Cancellable true | ||
// | ||
// @Triggers when a liquid block's level changes. Note that 'liquid spreads' is fired when a liquid first spreads, and 'level changes' is usually fired when it goes down. | ||
// | ||
// @Context | ||
// <context.location> returns the LocationTag the liquid block that has its level changing. | ||
// <context.old_material> returns the original MaterialTag data. | ||
// <context.new_material> returns the new MaterialTag data. Sometimes can be a different material (such as air). | ||
// | ||
// --> | ||
|
||
public LiquidLevelChangeScriptEvent() { | ||
instance = this; | ||
registerCouldMatcher("liquid|lava|water level changes"); | ||
} | ||
|
||
public static LiquidLevelChangeScriptEvent instance; | ||
public LocationTag location; | ||
public MaterialTag old_material; | ||
public FluidLevelChangeEvent event; | ||
|
||
@Override | ||
public boolean couldMatch(ScriptPath path) { | ||
if (!super.couldMatch(path)) { | ||
return false; | ||
} | ||
if (path.eventLower.startsWith("block")) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean matches(ScriptPath path) { | ||
String mat = path.eventArgLowerAt(0); | ||
if (!mat.equals("liquid") && !tryMaterial(old_material, mat)) { | ||
return false; | ||
} | ||
if (!runInCheck(path, location)) { | ||
return false; | ||
} | ||
return super.matches(path); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "LiquidLevelChange"; | ||
} | ||
|
||
@Override | ||
public ObjectTag getContext(String name) { | ||
switch (name) { | ||
case "location": return location; | ||
case "old_material": return old_material; | ||
case "new_material": return new MaterialTag(event.getNewData()); | ||
} | ||
return super.getContext(name); | ||
} | ||
|
||
@EventHandler | ||
public void onLiquidLevelChange(FluidLevelChangeEvent event) { | ||
location = new LocationTag(event.getBlock().getLocation()); | ||
old_material = new MaterialTag(event.getBlock()); | ||
this.event = event; | ||
fire(event); | ||
} | ||
} |