Skip to content
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.unstable,waterlogged,count Property Modernization #2665

Open
wants to merge 7 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,54 +2,42 @@

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.Candle;
import org.bukkit.block.data.type.RespawnAnchor;
import org.bukkit.block.data.type.SeaPickle;
import org.bukkit.block.data.type.TurtleEgg;

public class MaterialCount implements Property {

public static boolean describes(ObjectTag material) {
if (!(material instanceof MaterialTag)) {
return false;
}
MaterialTag mat = (MaterialTag) material;
if (!mat.hasModernData()) {
return false;
}
BlockData data = mat.getModernData();
public class MaterialCount extends MaterialProperty<ElementTag> {

// <--[property]
// @object MaterialTag
// @name count
// @input ElementTag(Number)
// @description
// Controls the amount of pickles in a Sea Pickle material, eggs in a Turtle Egg material, charges in a Respawn Anchor material, or candles in a Candle material.
// See also:
// <@link tag MaterialTag.count>
// <@link tag MaterialTag.count_min>
// <@link tag MaterialTag.count_max>
// -->

public static boolean describes(MaterialTag material) {
BlockData data = material.getModernData();
return data instanceof SeaPickle
|| data instanceof TurtleEgg
|| data instanceof RespawnAnchor
|| data instanceof Candle;
}

public static MaterialCount getFrom(ObjectTag _material) {
if (!describes(_material)) {
return null;
}
else {
return new MaterialCount((MaterialTag) _material);
}
}

public static final String[] handledMechs = new String[] {
"count", "pickle_count"
};

public MaterialCount(MaterialTag _material) {
material = _material;
}

MaterialTag material;

public static void register() {

autoRegister("count", MaterialCount.class, ElementTag.class, true, "pickle_count");

// <--[tag]
// @attribute <MaterialTag.count>
// @returns ElementTag(Number)
Expand Down Expand Up @@ -168,47 +156,36 @@ else if (isCandle()) {
}

@Override
public String getPropertyString() {
return String.valueOf(getCurrent());
public ElementTag getPropertyValue() {
return new ElementTag(getCurrent());
}

@Override
public String getPropertyId() {
return "count";
public void setPropertyValue(ElementTag elementTag, Mechanism mechanism) {
if (!mechanism.requireInteger()) {
return;
}
int count = elementTag.asInt();
if (count < getMin() || count > getMax()) {
mechanism.echoError("Material count mechanism value '" + count + "' is not valid. Must be between " + getMin() + " and " + getMax() + ".");
return;
}
if (isSeaPickle()) {
getSeaPickle().setPickles(count);
}
else if (isTurtleEgg()) {
getTurtleEgg().setEggs(count);
}
else if (isRespawnAnchor()) {
getRespawnAnchor().setCharges(count);
}
else if (isCandle()) {
getCandle().setCandles(count);
}
}

@Override
public void adjust(Mechanism mechanism) {

// <--[mechanism]
// @object MaterialTag
// @name count
// @input ElementTag(Number)
// @description
// Sets the amount of pickles in a Sea Pickle material, eggs in a Turtle Egg material, charges in a Respawn Anchor material, or candles in a Candle material.
// @tags
// <MaterialTag.count>
// <MaterialTag.count_min>
// <MaterialTag.count_max>
// -->
if ((mechanism.matches("count") || (mechanism.matches("pickle_count"))) && mechanism.requireInteger()) {
int count = mechanism.getValue().asInt();
if (count < getMin() || count > getMax()) {
mechanism.echoError("Material count mechanism value '" + count + "' is not valid. Must be between " + getMin() + " and " + getMax() + ".");
return;
}
if (isSeaPickle()) {
getSeaPickle().setPickles(count);
}
else if (isTurtleEgg()) {
getTurtleEgg().setEggs(count);
}
else if (isRespawnAnchor()) {
getRespawnAnchor().setCharges(count);
}
else if (isCandle()) {
getCandle().setCandles(count);
}
}
public String getPropertyId() {
return "count";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,52 +2,46 @@

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.TNT;

public class MaterialUnstable implements Property {
public class MaterialUnstable extends MaterialProperty<ElementTag> {

public static boolean describes(ObjectTag material) {
return material instanceof MaterialTag
&& ((MaterialTag) material).hasModernData()
&& ((MaterialTag) material).getModernData() instanceof TNT;
}
// <--[property]
// @object MaterialTag
// @name unstable
// @input ElementTag(Boolean)
// @description
// Controls whether this TNT block is unstable (explodes when punched).
// -->

public static MaterialUnstable getFrom(ObjectTag _material) {
if (!describes(_material)) {
return null;
}
else {
return new MaterialUnstable((MaterialTag) _material);
}
public static boolean describes(MaterialTag material) {
BlockData data = material.getModernData();
return data instanceof TNT;
}

public static final String[] handledMechs = new String[] {
"unstable"
};
MaterialTag material;

public MaterialUnstable(MaterialTag _material) {
material = _material;
@Override
public String getPropertyId() {
return "unstable";
}

MaterialTag material;
@Override
public ElementTag getPropertyValue() {
return new ElementTag(isUnstable());
}

public static void register() {
@Override
public void setPropertyValue(ElementTag value, Mechanism mechanism) {
if (mechanism.requireBoolean()) {
getTNT().setUnstable(value.asBoolean());
}
}

// <--[tag]
// @attribute <MaterialTag.unstable>
// @returns ElementTag(Boolean)
// @mechanism MaterialTag.unstable
// @group properties
// @description
// Returns whether this TNT block is unstable (explodes when punched).
// -->
PropertyParser.registerStaticTag(MaterialUnstable.class, ElementTag.class, "unstable", (attribute, material) -> {
return new ElementTag(material.isUnstable());
});
public static void register() {
autoRegister("unstable", MaterialUnstable.class, ElementTag.class, true);
}

public TNT getTNT() {
Expand All @@ -57,31 +51,4 @@ public TNT getTNT() {
public boolean isUnstable() {
return getTNT().isUnstable();
}

@Override
public String getPropertyString() {
return String.valueOf(isUnstable());
}

@Override
public String getPropertyId() {
return "unstable";
}

@Override
public void adjust(Mechanism mechanism) {

// <--[mechanism]
// @object MaterialTag
// @name unstable
// @input ElementTag(Boolean)
// @description
// Sets whether this TNT block is unstable (explodes when punched).
// @tags
// <MaterialTag.unstable>
// -->
if (mechanism.matches("unstable") && mechanism.requireBoolean()) {
getTNT().setUnstable(mechanism.getValue().asBoolean());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,86 +2,45 @@

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.Waterlogged;

public class MaterialWaterlogged implements Property {
public class MaterialWaterlogged extends MaterialProperty<ElementTag> {

public static boolean describes(ObjectTag material) {
return material instanceof MaterialTag
&& ((MaterialTag) material).hasModernData()
&& ((MaterialTag) material).getModernData() instanceof Waterlogged;
}

public static MaterialWaterlogged getFrom(ObjectTag _material) {
if (!describes(_material)) {
return null;
}
else {
return new MaterialWaterlogged((MaterialTag) _material);
}
}

public static final String[] handledMechs = new String[] {
"waterlogged"
};
// <--[property]
// @object MaterialTag
// @name waterlogged
// @input ElementTag(Boolean)
// @description
// Controls whether this block is waterlogged.
// -->

public MaterialWaterlogged(MaterialTag _material) {
material = _material;
public static boolean describes(MaterialTag material) {
BlockData data = material.getModernData();
return data instanceof Waterlogged;
}

MaterialTag material;

public static void register() {

// <--[tag]
// @attribute <MaterialTag.waterlogged>
// @returns ElementTag(Boolean)
// @mechanism MaterialTag.waterlogged
// @group properties
// @description
// Returns whether this block is waterlogged or not.
// -->
PropertyParser.registerStaticTag(MaterialWaterlogged.class, ElementTag.class, "waterlogged", (attribute, material) -> {
return new ElementTag(material.isWaterlogged());
});
}

public Waterlogged getWaterlogged() {
return (Waterlogged) material.getModernData();
}

public boolean isWaterlogged() {
return getWaterlogged().isWaterlogged();
}

@Override
public String getPropertyString() {
return String.valueOf(isWaterlogged());
}

@Override
public String getPropertyId() {
return "waterlogged";
}

@Override
public void adjust(Mechanism mechanism) {
public ElementTag getPropertyValue() {
return new ElementTag(((Waterlogged) material.getModernData()).isWaterlogged());
}

// <--[mechanism]
// @object MaterialTag
// @name waterlogged
// @input ElementTag(Boolean)
// @description
// Sets this block to be waterlogged, or not.
// @tags
// <MaterialTag.waterlogged>
// -->
if (mechanism.matches("waterlogged") && mechanism.requireBoolean()) {
getWaterlogged().setWaterlogged(mechanism.getValue().asBoolean());
@Override
public void setPropertyValue(ElementTag value, Mechanism mechanism) {
if (mechanism.requireBoolean()) {
((Waterlogged) material.getModernData()).setWaterlogged(value.asBoolean());
}
}

public static void register() {
autoRegister("waterlogged", MaterialWaterlogged.class, ElementTag.class, true);
}
}