Skip to content
Permalink
Browse files

Add lockable block functions

  • Loading branch information
PseudoKnight committed Dec 27, 2019
1 parent f1f9cd9 commit ea07e0fe1fc3a93bb732945e331d3ab875fa3160
@@ -12,4 +12,13 @@
MCLocation getLocation();

void update();

boolean isLockable();

boolean isLocked();

String getLock();

void setLock(String key);

}
@@ -7,6 +7,7 @@
import com.laytonsmith.abstraction.bukkit.BukkitMCLocation;
import com.laytonsmith.abstraction.bukkit.BukkitMCMetadatable;
import org.bukkit.block.BlockState;
import org.bukkit.block.Lockable;

public class BukkitMCBlockState extends BukkitMCMetadatable implements MCBlockState {

@@ -41,4 +42,37 @@ public MCLocation getLocation() {
public void update() {
bs.update();
}

@Override
public boolean isLockable() {
return bs instanceof Lockable;
}

@Override
public boolean isLocked() {
if(bs instanceof Lockable) {
return ((Lockable) bs).isLocked();
} else {
throw new ClassCastException("Block is not a Lockable.");
}
}

@Override
public String getLock() {
if(bs instanceof Lockable) {
return ((Lockable) bs).getLock();
} else {
throw new ClassCastException("Block is not a Lockable.");
}
}

@Override
public void setLock(String key) {
if(bs instanceof Lockable) {
((Lockable) bs).setLock(key);
bs.update();
} else {
throw new ClassCastException("Block is not a Lockable.");
}
}
}
@@ -10,6 +10,7 @@
import com.laytonsmith.abstraction.StaticLayer;
import com.laytonsmith.abstraction.blocks.MCBlock;
import com.laytonsmith.abstraction.blocks.MCBlockData;
import com.laytonsmith.abstraction.blocks.MCBlockState;
import com.laytonsmith.abstraction.blocks.MCCommandBlock;
import com.laytonsmith.abstraction.blocks.MCMaterial;
import com.laytonsmith.abstraction.blocks.MCSign;
@@ -38,6 +39,7 @@
import com.laytonsmith.core.constructs.CNull;
import com.laytonsmith.core.constructs.CString;
import com.laytonsmith.core.constructs.CVoid;
import com.laytonsmith.core.constructs.Construct;
import com.laytonsmith.core.constructs.Target;
import com.laytonsmith.core.environments.CommandHelperEnvironment;
import com.laytonsmith.core.exceptions.CRE.CREBadEntityException;
@@ -2229,6 +2231,218 @@ public Mixed exec(Target t, com.laytonsmith.core.environments.Environment enviro
}
}

@api
public static class is_block_lockable extends AbstractFunction {

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

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

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

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

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

@Override
public String docs() {
return "boolean {locationArray} Returns whether or not the block is lockable."
+ " ---- Locks prevent players from accessing the block's interface unless they are holding an item"
+ " key with the same display name as the lock.";
}

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

@Override
public Mixed exec(Target t, com.laytonsmith.core.environments.Environment environment, Mixed... args)
throws ConfigRuntimeException {
MCLocation loc = ObjectGenerator.GetGenerator().location(args[0], null, t);
return CBoolean.get(loc.getBlock().getState().isLockable());
}
}

@api
public static class is_block_locked extends AbstractFunction {

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

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

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

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

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

@Override
public String docs() {
return "boolean {locationArray} Returns whether or not the block is locked if its lockable."
+ " ---- Locks prevent players from accessing the block's interface unless they are holding an item"
+ " key with the same display name as the lock."
+ " Throws IllegalArgumentException if used on a block that isn't lockable.";
}

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

@Override
public Mixed exec(Target t, com.laytonsmith.core.environments.Environment environment, Mixed... args)
throws ConfigRuntimeException {
MCLocation loc = ObjectGenerator.GetGenerator().location(args[0], null, t);
MCBlockState block = loc.getBlock().getState();
if(!block.isLockable()) {
throw new CREIllegalArgumentException("Block is not lockable.", t);
}
return CBoolean.get(block.isLocked());
}
}

@api
public static class get_block_lock extends AbstractFunction {

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

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

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

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

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

@Override
public String docs() {
return "string {locationArray} Returns the string lock for this block if its lockable."
+ " ---- Locks prevent players from accessing the block's interface unless they are holding an item"
+ " key with the same display name as the lock."
+ " Throws IllegalArgumentException if used on a block that isn't lockable.";
}

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

@Override
public Mixed exec(Target t, com.laytonsmith.core.environments.Environment environment, Mixed... args)
throws ConfigRuntimeException {
MCLocation loc = ObjectGenerator.GetGenerator().location(args[0], null, t);
MCBlockState block = loc.getBlock().getState();
if(!block.isLockable()) {
throw new CREIllegalArgumentException("Block is not lockable.", t);
}
return new CString(block.getLock(), t);
}
}

@api
public static class set_block_lock extends AbstractFunction {

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

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

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

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

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

@Override
public String docs() {
return "void {locationArray, string} Sets the string lock for this block if its lockable."
+ " Set an empty string or null to remove lock."
+ " ---- Locks prevent players from accessing the block's interface unless they are holding an item"
+ " key with the same display name as the lock."
+ " Throws IllegalArgumentException if used on a block that isn't lockable.";
}

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

@Override
public Mixed exec(Target t, com.laytonsmith.core.environments.Environment environment, Mixed... args)
throws ConfigRuntimeException {
MCLocation loc = ObjectGenerator.GetGenerator().location(args[0], null, t);
MCBlockState block = loc.getBlock().getState();
if(!block.isLockable()) {
throw new CREIllegalArgumentException("Block is not lockable.", t);
}
block.setLock(Construct.nval(args[1]));
return CVoid.VOID;
}
}

@api
public static class get_block_command extends AbstractFunction {

0 comments on commit ea07e0f

Please sign in to comment.
You can’t perform that action at this time.