use of com.denizenscript.denizen.objects.MaterialTag in project Denizen-For-Bukkit by DenizenScript.
the class SchematicCommand method schematicTags.
public void schematicTags(ReplaceableTagEvent event) {
if (!event.matches("schematic")) {
return;
}
Attribute attribute = event.getAttributes();
String id = attribute.hasParam() ? attribute.getParam().toUpperCase() : null;
attribute = attribute.fulfill(1);
// -->
if (attribute.startsWith("list")) {
event.setReplaced(new ListTag(schematics.keySet()).getAttribute(attribute.fulfill(1)));
}
if (id == null) {
return;
}
if (!schematics.containsKey(id)) {
// Meta below
if (attribute.startsWith("exists")) {
event.setReplaced(new ElementTag(false).getAttribute(attribute.fulfill(1)));
return;
}
Debug.echoError(attribute.getScriptEntry(), "Schematic file " + id + " is not loaded.");
return;
}
CuboidBlockSet set = schematics.get(id);
// -->
if (attribute.startsWith("exists")) {
event.setReplaced(new ElementTag(true).getAttribute(attribute.fulfill(1)));
return;
}
// -->
if (attribute.startsWith("height")) {
event.setReplaced(new ElementTag(set.y_length).getAttribute(attribute.fulfill(1)));
return;
}
// -->
if (attribute.startsWith("length")) {
event.setReplaced(new ElementTag(set.z_height).getAttribute(attribute.fulfill(1)));
return;
}
// -->
if (attribute.startsWith("width")) {
event.setReplaced(new ElementTag(set.x_width).getAttribute(attribute.fulfill(1)));
return;
}
// -->
if (attribute.startsWith("block")) {
if (attribute.hasParam() && LocationTag.matches(attribute.getParam())) {
LocationTag location = attribute.paramAsType(LocationTag.class);
FullBlockData block = set.blockAt(location.getX(), location.getY(), location.getZ());
event.setReplaced(new MaterialTag(block.data).getAttribute(attribute.fulfill(1)));
return;
}
}
// -->
if (attribute.startsWith("origin")) {
event.setReplaced(new LocationTag(null, set.center_x, set.center_y, set.center_z).getAttribute(attribute.fulfill(1)));
return;
}
// -->
if (attribute.startsWith("blocks")) {
event.setReplaced(new ElementTag(set.blocks.length).getAttribute(attribute.fulfill(1)));
return;
}
// -->
if (attribute.startsWith("cuboid") && attribute.hasParam()) {
LocationTag origin = attribute.paramAsType(LocationTag.class);
event.setReplaced(set.getCuboid(origin).getAttribute(attribute.fulfill(1)));
return;
}
}
use of com.denizenscript.denizen.objects.MaterialTag in project Denizen-For-Bukkit by DenizenScript.
the class SwitchCommand method switchBlock.
// Break off this portion of the code from execute() so it can be used in both execute and the delayed runnable
public void switchBlock(ScriptEntry scriptEntry, Location interactLocation, SwitchState switchState, boolean physics) {
Block block = interactLocation.getBlock();
BlockData data1 = block.getBlockData();
MaterialTag materialTag = new MaterialTag(data1);
MaterialSwitchable switchable = MaterialSwitchable.getFrom(materialTag);
if (switchable == null) {
Debug.echoError("Cannot switch block of type '" + materialTag.getMaterial().name() + "'");
return;
}
if (materialTag.getMaterial() == Material.BELL) {
NMSHandler.getBlockHelper().ringBell((Bell) block.getState());
return;
}
boolean currentState = switchable.getState();
if ((switchState.equals(SwitchState.ON) && !currentState) || (switchState.equals(SwitchState.OFF) && currentState) || switchState.equals(SwitchState.TOGGLE)) {
switchable.setState(!currentState);
if (physics) {
block.setBlockData(switchable.material.getModernData());
} else {
ModifyBlockCommand.setBlock(block.getLocation(), materialTag, false, null);
}
if (data1 instanceof Bisected && !(data1 instanceof TrapDoor)) {
// TrapDoor implements Bisected, but is not actually bisected???
Location other = interactLocation.clone();
if (((Bisected) data1).getHalf() == Bisected.Half.TOP) {
other = other.add(0, -1, 0);
} else {
other = other.add(0, 1, 0);
}
BlockData data2 = other.getBlock().getBlockData();
if (data2.getMaterial() == data1.getMaterial()) {
MaterialSwitchable switchable2 = MaterialSwitchable.getFrom(new MaterialTag(data2));
switchable2.setState(!currentState);
other.getBlock().setBlockData(switchable2.material.getModernData());
if (physics) {
AdjustBlockCommand.applyPhysicsAt(other);
}
}
}
if (physics) {
AdjustBlockCommand.applyPhysicsAt(interactLocation);
}
if (scriptEntry.dbCallShouldDebug()) {
Debug.echoDebug(scriptEntry, "Switched " + block.getType().toString() + "! Current state now: " + (switchState(block) ? "ON" : "OFF"));
}
}
}
use of com.denizenscript.denizen.objects.MaterialTag in project Denizen-For-Bukkit by DenizenScript.
the class DenizenPacketListenerImpl method a.
@Override
public void a(PacketPlayInUpdateSign packet) {
if (fakeSignExpected != null && packet.b().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(getPlayer().getLocation());
LocationTag loc = evt.location.clone();
loc.setY(0);
evt.event = new SignChangeEvent(loc.getBlock(), getPlayer(), packet.c());
evt.fire(evt.event);
}
super.a(packet);
}
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().getTileEntity(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 BlockFadesScriptEvent method onBlockFades.
@EventHandler
public void onBlockFades(BlockFadeEvent event) {
location = new LocationTag(event.getBlock().getLocation());
material = new MaterialTag(event.getBlock());
this.event = event;
fire(event);
}
Aggregations