use of com.denizenscript.denizen.objects.MaterialTag in project Denizen-For-Bukkit by DenizenScript.
the class MaterialSwitchable method describes.
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();
return data instanceof Powerable || data instanceof Openable || data instanceof Dispenser || data instanceof DaylightDetector || data instanceof Piston || data instanceof Lightable || data instanceof EndPortalFrame || data instanceof Hopper;
}
use of com.denizenscript.denizen.objects.MaterialTag in project Denizen-For-Bukkit by DenizenScript.
the class PacketHelperImpl method showSignEditor.
@Override
public boolean showSignEditor(Player player, Location location) {
if (location == null) {
LocationTag fakeSign = new LocationTag(player.getLocation());
fakeSign.setY(0);
FakeBlock.showFakeBlockTo(Collections.singletonList(new PlayerTag(player)), fakeSign, new MaterialTag(org.bukkit.Material.OAK_WALL_SIGN), new DurationTag(1), true);
BlockPos pos = new BlockPos(fakeSign.getX(), 0, fakeSign.getZ());
((DenizenNetworkManagerImpl) ((CraftPlayer) player).getHandle().connection.connection).packetListener.fakeSignExpected = pos;
send(player, new ClientboundOpenSignEditorPacket(pos));
return true;
}
BlockEntity tileEntity = ((CraftWorld) location.getWorld()).getHandle().getBlockEntity(new BlockPos(location.getBlockX(), location.getBlockY(), location.getBlockZ()), true);
if (tileEntity instanceof SignBlockEntity) {
SignBlockEntity sign = (SignBlockEntity) tileEntity;
// Prevent client crashing by sending current state of the sign
send(player, sign.getUpdatePacket());
sign.isEditable = true;
sign.setAllowedPlayerEditor(player.getUniqueId());
send(player, new ClientboundOpenSignEditorPacket(sign.getBlockPos()));
return true;
} else {
return false;
}
}
use of com.denizenscript.denizen.objects.MaterialTag in project Denizen-For-Bukkit by DenizenScript.
the class DenizenPacketListenerImpl method handleSignUpdate.
@Override
public void handleSignUpdate(ServerboundSignUpdatePacket packet) {
if (fakeSignExpected != null && packet.getPos().equals(fakeSignExpected)) {
fakeSignExpected = null;
PlayerChangesSignScriptEvent evt = (PlayerChangesSignScriptEvent) PlayerChangesSignScriptEvent.instance.clone();
evt.cancelled = false;
evt.material = new MaterialTag(org.bukkit.Material.OAK_WALL_SIGN);
evt.location = new LocationTag(player.getBukkitEntity().getLocation());
LocationTag loc = evt.location.clone();
loc.setY(0);
evt.event = new SignChangeEvent(loc.getBlock(), player.getBukkitEntity(), packet.getLines());
evt.fire(evt.event);
}
super.handleSignUpdate(packet);
}
use of com.denizenscript.denizen.objects.MaterialTag in project Denizen-For-Bukkit by DenizenScript.
the class SignCommand method execute.
@Override
public void execute(final ScriptEntry scriptEntry) {
String direction = scriptEntry.hasObject("direction") ? ((ElementTag) scriptEntry.getObject("direction")).asString() : null;
ElementTag typeElement = scriptEntry.getElement("type");
ListTag text = scriptEntry.getObjectTag("text");
LocationTag location = scriptEntry.getObjectTag("location");
MaterialTag material = scriptEntry.getObjectTag("material");
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), typeElement, location, db("direction", direction), material, text);
}
Type type = Type.valueOf(typeElement.asString().toUpperCase());
Block sign = location.getBlock();
if (type != Type.AUTOMATIC || !isAnySign(sign.getType())) {
if (type == Type.WALL_SIGN) {
BlockFace bf;
if (direction != null) {
bf = Utilities.chooseSignRotation(direction);
} else {
bf = Utilities.chooseSignRotation(sign);
}
setWallSign(sign, bf, material);
} else {
sign.setType(material == null ? Material.OAK_SIGN : material.getMaterial(), false);
if (direction != null) {
Utilities.setSignRotation(sign.getState(), direction);
}
}
} else if (!isAnySign(sign.getType())) {
if (sign.getRelative(BlockFace.DOWN).getType().isSolid()) {
sign.setType(material == null ? Material.OAK_SIGN : material.getMaterial(), false);
} else {
BlockFace bf = Utilities.chooseSignRotation(sign);
setWallSign(sign, bf, material);
}
}
BlockState signState = sign.getState();
Utilities.setSignLines((Sign) signState, text.toArray(new String[4]));
}
use of com.denizenscript.denizen.objects.MaterialTag in project Denizen-For-Bukkit by DenizenScript.
the class AdjustBlockCommand method execute.
@Override
public void execute(ScriptEntry scriptEntry) {
ElementTag mechanismName = scriptEntry.getElement("mechanism");
ObjectTag value = scriptEntry.getObjectTag("mechanism_value");
ElementTag noPhysics = scriptEntry.getElement("no_physics");
List<LocationTag> locations = (List<LocationTag>) scriptEntry.getObject("locations");
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), db("locations", locations), mechanismName, noPhysics, value);
}
boolean doPhysics = noPhysics == null || !noPhysics.asBoolean();
for (LocationTag location : locations) {
Block block = location.getBlock();
BlockData data = block.getBlockData();
MaterialTag specialMaterial = new MaterialTag(data);
Mechanism mechanism = new Mechanism(mechanismName.asString(), value, scriptEntry.getContext());
specialMaterial.safeAdjust(mechanism);
if (doPhysics) {
block.setBlockData(data, false);
applyPhysicsAt(location);
} else {
ModifyBlockCommand.setBlock(block.getLocation(), specialMaterial, false, null);
}
}
}
Aggregations