Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New stuff related to leaves blocks: (#2014)
* New stuff related to leaves blocks: 3 new tags: is_leaves, tree_distance, and persistent 1 new mechanism: persistent 1 additional fix (possible copypasta) * Fix conflicts with upstream * fixing the result of public school (grammar) * removal of unnecessary import.... * updates to match proper denizen design * readability improvement * stability improvements * further cleanup * preferential fixes * meta fixes
- Loading branch information
1 parent
3abb4d1
commit e696128
Showing
4 changed files
with
136 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
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
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
99 changes: 99 additions & 0 deletions
99
...n/src/main/java/com/denizenscript/denizen/objects/properties/material/MaterialLeaves.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,99 @@ | ||
package com.denizenscript.denizen.objects.properties.material; | ||
|
||
import com.denizenscript.denizen.objects.MaterialTag; | ||
import com.denizenscript.denizen.utilities.debugging.Debug; | ||
import com.denizenscript.denizencore.objects.Mechanism; | ||
import com.denizenscript.denizencore.objects.ObjectTag; | ||
import com.denizenscript.denizencore.objects.core.ElementTag; | ||
import com.denizenscript.denizencore.objects.properties.Property; | ||
import com.denizenscript.denizencore.tags.Attribute; | ||
import org.bukkit.block.data.type.Leaves; | ||
|
||
public class MaterialLeaves implements Property { | ||
|
||
public static boolean describes(ObjectTag material) { | ||
return material instanceof MaterialTag | ||
&& ((MaterialTag) material).hasModernData() | ||
&& ((MaterialTag) material).getModernData().data instanceof Leaves; | ||
} | ||
|
||
public static MaterialLeaves getFrom(ObjectTag _material) { | ||
if (!describes(_material)) { | ||
return null; | ||
} | ||
else { | ||
return new MaterialLeaves((MaterialTag) _material); | ||
} | ||
} | ||
|
||
public static final String[] handledTags = new String[] { | ||
"persistent" | ||
}; | ||
|
||
public static final String[] handledMechs = new String[] { | ||
"persistent" | ||
}; | ||
|
||
|
||
private MaterialLeaves(MaterialTag _material) { | ||
material = _material; | ||
} | ||
|
||
MaterialTag material; | ||
|
||
@Override | ||
public String getAttribute(Attribute attribute) { | ||
|
||
if (attribute == null) { | ||
return null; | ||
} | ||
|
||
// <--[tag] | ||
// @attribute <MaterialTag.persistent> | ||
// @returns ElementTag(Boolean) | ||
// @group properties | ||
// @description | ||
// Returns whether this block will decay from being too far away from a tree. | ||
// --> | ||
if (attribute.startsWith("persistent")) { | ||
return new ElementTag(getLeaves().isPersistent()).getAttribute(attribute.fulfill(1)); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
public Leaves getLeaves() { | ||
return (Leaves) material.getModernData().data; | ||
} | ||
|
||
public int getDistance() { | ||
return getLeaves().getDistance(); | ||
} | ||
|
||
@Override | ||
public String getPropertyString() { | ||
return String.valueOf(getLeaves().isPersistent()); | ||
} | ||
|
||
@Override | ||
public String getPropertyId() { | ||
return "persistent"; | ||
} | ||
|
||
@Override | ||
public void adjust(Mechanism mechanism) { | ||
|
||
// <--[mechanism] | ||
// @object MaterialTag | ||
// @name persistent | ||
// @input Element(Boolean) | ||
// @description | ||
// Sets leaves blocks to ignore decay, or to obey it. | ||
// @tags | ||
// <MaterialTag.persistent> | ||
// --> | ||
if (mechanism.matches("persistent") && mechanism.requireBoolean()) { | ||
getLeaves().setPersistent(mechanism.getValue().asBoolean()); | ||
} | ||
} | ||
} |