Search in sources :

Example 21 with MaterialTag

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;
    }
}
Also used : LocationTag(com.denizenscript.denizen.objects.LocationTag) MaterialTag(com.denizenscript.denizen.objects.MaterialTag) Attribute(com.denizenscript.denizencore.tags.Attribute) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) ListTag(com.denizenscript.denizencore.objects.core.ListTag)

Example 22 with MaterialTag

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"));
        }
    }
}
Also used : MaterialTag(com.denizenscript.denizen.objects.MaterialTag) TrapDoor(org.bukkit.block.data.type.TrapDoor) Block(org.bukkit.block.Block) BlockData(org.bukkit.block.data.BlockData) MaterialSwitchable(com.denizenscript.denizen.objects.properties.material.MaterialSwitchable) Bisected(org.bukkit.block.data.Bisected) Location(org.bukkit.Location)

Example 23 with MaterialTag

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);
}
Also used : MaterialTag(com.denizenscript.denizen.objects.MaterialTag) LocationTag(com.denizenscript.denizen.objects.LocationTag) PlayerChangesSignScriptEvent(com.denizenscript.denizen.events.player.PlayerChangesSignScriptEvent) SignChangeEvent(org.bukkit.event.block.SignChangeEvent)

Example 24 with MaterialTag

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;
    }
}
Also used : LocationTag(com.denizenscript.denizen.objects.LocationTag) MaterialTag(com.denizenscript.denizen.objects.MaterialTag) SignBlockEntity(net.minecraft.world.level.block.entity.SignBlockEntity) PlayerTag(com.denizenscript.denizen.objects.PlayerTag) BlockPos(net.minecraft.core.BlockPos) DenizenNetworkManagerImpl(com.denizenscript.denizen.nms.v1_17.impl.network.handlers.DenizenNetworkManagerImpl) DurationTag(com.denizenscript.denizencore.objects.core.DurationTag) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity) SignBlockEntity(net.minecraft.world.level.block.entity.SignBlockEntity)

Example 25 with MaterialTag

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);
}
Also used : LocationTag(com.denizenscript.denizen.objects.LocationTag) MaterialTag(com.denizenscript.denizen.objects.MaterialTag) EventHandler(org.bukkit.event.EventHandler)

Aggregations

MaterialTag (com.denizenscript.denizen.objects.MaterialTag)51 LocationTag (com.denizenscript.denizen.objects.LocationTag)33 EventHandler (org.bukkit.event.EventHandler)21 ElementTag (com.denizenscript.denizencore.objects.core.ElementTag)9 EntityTag (com.denizenscript.denizen.objects.EntityTag)8 Material (org.bukkit.Material)8 PlayerTag (com.denizenscript.denizen.objects.PlayerTag)7 BlockData (org.bukkit.block.data.BlockData)7 DurationTag (com.denizenscript.denizencore.objects.core.DurationTag)6 ListTag (com.denizenscript.denizencore.objects.core.ListTag)6 ItemStack (org.bukkit.inventory.ItemStack)6 List (java.util.List)4 Block (org.bukkit.block.Block)4 PlayerChangesSignScriptEvent (com.denizenscript.denizen.events.player.PlayerChangesSignScriptEvent)3 ItemTag (com.denizenscript.denizen.objects.ItemTag)3 SignChangeEvent (org.bukkit.event.block.SignChangeEvent)3 InvalidArgumentsException (com.denizenscript.denizencore.exceptions.InvalidArgumentsException)2 ScriptEntry (com.denizenscript.denizencore.scripts.ScriptEntry)2 HashSet (java.util.HashSet)2 BlockPos (net.minecraft.core.BlockPos)2