-
-
Notifications
You must be signed in to change notification settings - Fork 107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MaterialTag.half,faces,distance Property Modernization #2660
base: dev
Are you sure you want to change the base?
Changes from all commits
a110aff
b4c1b7e
7ffc2e3
9f2c151
c0dc92b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,55 +2,61 @@ | |
|
||
import com.denizenscript.denizen.objects.MaterialTag; | ||
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.objects.properties.PropertyParser; | ||
import org.bukkit.block.data.BlockData; | ||
import org.bukkit.block.data.type.Leaves; | ||
import org.bukkit.block.data.type.Scaffolding; | ||
|
||
public class MaterialDistance implements Property { | ||
|
||
public static boolean describes(Object material) { | ||
return material instanceof MaterialTag | ||
&& ((MaterialTag) material).hasModernData() | ||
&& (((MaterialTag) material).getModernData() instanceof Scaffolding | ||
|| ((MaterialTag) material).getModernData() instanceof Leaves); | ||
public class MaterialDistance extends MaterialProperty<ElementTag> { | ||
|
||
// <--[property] | ||
// @object MaterialTag | ||
// @name distance | ||
// @input ElementTag(Number) | ||
// @description | ||
// Controls the horizontal distance between a scaffolding block and the nearest scaffolding block placed above a 'bottom' scaffold, | ||
// or between a leaves block and the nearest log (a distance of 7 will cause a leaf to decay if 'persistent' is also false, less than 7 will prevent decay). | ||
// --> | ||
|
||
public static boolean describes(MaterialTag material) { | ||
BlockData data = material.getModernData(); | ||
return data instanceof Scaffolding | ||
|| data instanceof Leaves; | ||
} | ||
|
||
public static MaterialDistance getFrom(ObjectTag _material) { | ||
if (!describes(_material)) { | ||
return null; | ||
} | ||
else { | ||
return new MaterialDistance((MaterialTag) _material); | ||
} | ||
} | ||
MaterialTag material; | ||
|
||
public static final String[] handledMechs = new String[] { | ||
"distance" | ||
}; | ||
@Override | ||
public String getPropertyId() { | ||
return "distance"; | ||
} | ||
|
||
public MaterialDistance(MaterialTag _material) { | ||
material = _material; | ||
@Override | ||
public ElementTag getPropertyValue() { | ||
return new ElementTag(getDistance()); | ||
} | ||
|
||
MaterialTag material; | ||
@Override | ||
public void setPropertyValue(ElementTag value, Mechanism mechanism) { | ||
if (!mechanism.requireInteger()) { | ||
return; | ||
} | ||
int distance = value.asInt(); | ||
if (isScaffolding()) { | ||
if (distance >= 0 && distance <= getScaffolding().getMaximumDistance()) { | ||
getScaffolding().setDistance(distance); | ||
} | ||
else { | ||
mechanism.echoError("Distance must be between 0 and " + getScaffolding().getMaximumDistance()); | ||
} | ||
} | ||
else if (isLeaves()) { | ||
getLeaves().setDistance(distance); | ||
} | ||
} | ||
|
||
public static void register() { | ||
|
||
// <--[tag] | ||
// @attribute <MaterialTag.distance> | ||
// @returns ElementTag(Number) | ||
// @mechanism MaterialTag.distance | ||
// @group properties | ||
// @description | ||
// Returns the horizontal distance between a scaffolding block and the nearest scaffolding block placed above a 'bottom' scaffold, | ||
// or between a leaves block and the nearest log (a distance of 7 will cause a leaf to decay if 'persistent' is also false, less than 7 will prevent decay). | ||
// --> | ||
PropertyParser.registerStaticTag(MaterialDistance.class, ElementTag.class, "distance", (attribute, material) -> { | ||
return new ElementTag(material.getDistance()); | ||
}); | ||
autoRegister("distance", MaterialDistance.class, ElementTag.class, true); | ||
} | ||
|
||
public int getDistance() { | ||
|
@@ -79,41 +85,16 @@ public boolean isLeaves() { | |
return material.getModernData() instanceof Leaves; | ||
} | ||
|
||
@Override | ||
public String getPropertyString() { | ||
return String.valueOf(getDistance()); | ||
} | ||
|
||
@Override | ||
public String getPropertyId() { | ||
return "distance"; | ||
public static MaterialDistance getFrom(MaterialTag _material) { | ||
if (!describes(_material)) { | ||
return null; | ||
} | ||
else { | ||
return new MaterialDistance(_material); | ||
} | ||
Comment on lines
+88
to
+94
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's shouldn't be any need to keep |
||
} | ||
|
||
@Override | ||
public void adjust(Mechanism mechanism) { | ||
|
||
// <--[mechanism] | ||
// @object MaterialTag | ||
// @name distance | ||
// @input ElementTag(Number) | ||
// @description | ||
// Sets the horizontal distance between a scaffolding block and the nearest scaffolding block placed above a 'bottom' scaffold, or between a leaves block and the nearest log. | ||
// @tags | ||
// <MaterialTag.distance> | ||
// --> | ||
if (mechanism.matches("distance") && mechanism.requireInteger()) { | ||
int distance = mechanism.getValue().asInt(); | ||
if (isScaffolding()) { | ||
if (distance >= 0 && distance <= getScaffolding().getMaximumDistance()) { | ||
getScaffolding().setDistance(distance); | ||
} | ||
else { | ||
mechanism.echoError("Distance must be between 0 and " + getScaffolding().getMaximumDistance()); | ||
} | ||
} | ||
else if (isLeaves()) { | ||
getLeaves().setDistance(distance); | ||
} | ||
} | ||
public MaterialDistance(MaterialTag _material) { | ||
material = _material; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should remove the old field and use the built-in
object
field.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And with that, should use the
MaterialProperty
methods (e.g.getBlockData()
instead ofmaterial.getModernData()
)