Skip to content

Commit

Permalink
Add functions and item meta for waxed signs
Browse files Browse the repository at this point in the history
  • Loading branch information
PseudoKnight committed Aug 16, 2023
1 parent 9fdd0dc commit ad09174
Show file tree
Hide file tree
Showing 5 changed files with 140 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/main/java/com/laytonsmith/abstraction/blocks/MCSign.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

public interface MCSign extends MCBlockState, MCSignText {

boolean isWaxed();

void setWaxed(boolean waxed);

/**
* Gets the back text for this sign block.
* Using the methods directly on the sign object will apply to the front text for backwards compatibility.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,25 @@ public void setDyeColor(MCDyeColor color) {
s.setColor(BukkitMCDyeColor.getConvertor().getConcreteEnum(color));
}

@Override
public boolean isWaxed() {
try {
return s.isWaxed();
} catch(NoSuchMethodError ex) {
// probably before 1.20.1
return false;
}
}

@Override
public void setWaxed(boolean waxed) {
try {
s.setWaxed(waxed);
} catch(NoSuchMethodError ignore) {
// probably before 1.20.1
}
}

@Override
public MCSignText getBackText() {
try {
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/laytonsmith/core/ObjectGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,7 @@ public Construct itemMeta(MCItemStack is, Target t) {
}
ma.set("inventory", box, t);
} else if(bs instanceof MCSign sign) {
ma.set("waxed", CBoolean.get(sign.isWaxed()), t);
CArray lines = new CArray(t);
for(String line : sign.getLines()) {
lines.push(new CString(line, t), t);
Expand Down Expand Up @@ -1069,6 +1070,9 @@ public MCItemMeta itemMeta(Mixed c, MCMaterial mat, Target t) throws ConfigRunti
}
}
} else if(bs instanceof MCSign sign) {
if(ma.containsKey("waxed")) {
sign.setWaxed(ArgumentValidation.getBooleanObject(ma.get("waxed", t), t));
}
if(ma.containsKey("signtext")) {
Mixed possibleLines = ma.get("signtext", t);
if(possibleLines.isInstanceOf(CArray.TYPE)) {
Expand Down
112 changes: 112 additions & 0 deletions src/main/java/com/laytonsmith/core/functions/Environment.java
Original file line number Diff line number Diff line change
Expand Up @@ -813,6 +813,118 @@ public Mixed exec(Target t, com.laytonsmith.core.environments.Environment enviro
}
}

@api(environments = {CommandHelperEnvironment.class})
public static class is_sign_waxed extends AbstractFunction {

@Override
public String getName() {
return "is_sign_waxed";
}

@Override
public Integer[] numArgs() {
return new Integer[]{1};
}

@Override
public String docs() {
return "boolean {locationArray} Returns whether a sign is waxed and uneditable. (MC 1.20.1+)";
}

@Override
public Class<? extends CREThrowable>[] thrown() {
return new Class[]{CREFormatException.class, CREInvalidWorldException.class};
}

@Override
public boolean isRestricted() {
return true;
}

@Override
public MSVersion since() {
return MSVersion.V3_3_5;
}

@Override
public Boolean runAsync() {
return false;
}

@Override
public Mixed exec(Target t, com.laytonsmith.core.environments.Environment environment, Mixed... args) throws ConfigRuntimeException {
MCCommandSender sender = environment.getEnv(CommandHelperEnvironment.class).GetCommandSender();
MCWorld w = null;
if(sender instanceof MCPlayer) {
w = ((MCPlayer) sender).getWorld();
}
MCBlock b = ObjectGenerator.GetGenerator().location(args[0], w, t).getBlock();
if(!b.isSign()) {
throw new CRERangeException("The block at the specified location is not a sign", t);
}
MCSign sign = b.getSign();
return CBoolean.get(sign.isWaxed());
}
}

@api(environments = {CommandHelperEnvironment.class})
public static class set_sign_waxed extends AbstractFunction {

@Override
public String getName() {
return "set_sign_waxed";
}

@Override
public Integer[] numArgs() {
return new Integer[]{2};
}

@Override
public String docs() {
return "void {locationArray, boolean} Sets a sign to be waxed or not. (MC 1.20.1+)"
+ " If a sign is waxed, it is not editable by players.";
}

@Override
public Class<? extends CREThrowable>[] thrown() {
return new Class[]{CRERangeException.class, CREFormatException.class, CREInvalidWorldException.class,
CRECastException.class};
}

@Override
public boolean isRestricted() {
return true;
}

@Override
public MSVersion since() {
return MSVersion.V3_3_5;
}

@Override
public Boolean runAsync() {
return false;
}

@Override
public Mixed exec(Target t, com.laytonsmith.core.environments.Environment environment, Mixed... args) throws ConfigRuntimeException {
MCCommandSender sender = environment.getEnv(CommandHelperEnvironment.class).GetCommandSender();
MCWorld w = null;
if(sender instanceof MCPlayer) {
w = ((MCPlayer) sender).getWorld();
}
MCBlock b = ObjectGenerator.GetGenerator().location(args[0], w, t).getBlock();
if(!b.isSign()) {
throw new CRERangeException("The block at the specified location is not a sign", t);
}
MCSign sign = b.getSign();
sign.setWaxed(ArgumentValidation.getBooleanObject(args[1], t));
sign.update();
return CVoid.VOID;
}
}

@api(environments = {CommandHelperEnvironment.class})
public static class set_skull_owner extends AbstractFunction {

Expand Down
1 change: 1 addition & 0 deletions src/main/resources/functionDocs/get_itemmeta
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ Below are the available fields in the item meta array. Fields can be null when t
* '''backtext''' : (array) An array of 4 strings, one for each line of text on the back. (MC 1.20+)
* '''backcolor''' : (string) The dye color for the text on the back. (default: 'BLACK') (MC 1.20+)
* '''backglowing''' : (boolean) Whether the sign has glowing text on the back. (MC 1.20+)
* '''waxed''' : (boolean) Whether the sign is waxed. (MC 1.20.1+)
|-
| Spawners
|
Expand Down

0 comments on commit ad09174

Please sign in to comment.