Skip to content

Commit

Permalink
add from/to switches on block grows event
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Jan 7, 2020
1 parent e06f899 commit d4f1ffd
Showing 1 changed file with 14 additions and 2 deletions.
@@ -1,8 +1,11 @@
package com.denizenscript.denizen.events.block;

import com.denizenscript.denizen.nms.NMSHandler;
import com.denizenscript.denizen.nms.NMSVersion;
import com.denizenscript.denizen.objects.LocationTag;
import com.denizenscript.denizen.objects.MaterialTag;
import com.denizenscript.denizen.events.BukkitScriptEvent;
import com.denizenscript.denizen.objects.properties.material.MaterialAge;
import com.denizenscript.denizencore.objects.ObjectTag;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
Expand All @@ -20,13 +23,15 @@ public class BlockGrowsScriptEvent extends BukkitScriptEvent implements Listener
// @Group Block
//
// @Switch in:<area> to only process the event if it occurred within a specified area.
// @Switch from:<age> to only process the event if the material started at a specific age.
// @Switch to:<age> to only process the event if the material ended at a specific age.
//
// @Cancellable true
//
// @Triggers when a block grows naturally in the world, EG, when wheat, sugar canes, cacti, watermelons or pumpkins grow.
// @Context
// <context.location> returns the LocationTag of the block that grew.
// <context.material> returns the MaterialTag of the block that grew.
// <context.location> returns the LocationTag of the block that grew (still at original material state when event fires).
// <context.material> returns the MaterialTag of the block's newly grown state.
//
// -->

Expand Down Expand Up @@ -60,6 +65,13 @@ public boolean matches(ScriptPath path) {
if (!tryMaterial(material, path.eventArgLowerAt(0))) {
return false;
}
if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_13) && MaterialAge.describes(material)) {
int oldState = MaterialAge.getFrom(new MaterialTag(location.getBlockState())).getCurrent();
int newState = MaterialAge.getFrom(material).getCurrent();
if (!path.checkSwitch("from", String.valueOf(oldState)) || !path.checkSwitch("to", String.valueOf(newState))) {
return false;
}
}
return super.matches(path);
}

Expand Down

0 comments on commit d4f1ffd

Please sign in to comment.