Search in sources :

Example 31 with MaterialTag

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;
}
Also used : MaterialTag(com.denizenscript.denizen.objects.MaterialTag) Lightable(org.bukkit.block.data.Lightable) Powerable(org.bukkit.block.data.Powerable) BlockData(org.bukkit.block.data.BlockData) Openable(org.bukkit.block.data.Openable)

Example 32 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().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;
    }
}
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_18.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 33 with MaterialTag

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);
}
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 34 with MaterialTag

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]));
}
Also used : LocationTag(com.denizenscript.denizen.objects.LocationTag) MaterialTag(com.denizenscript.denizen.objects.MaterialTag) BlockState(org.bukkit.block.BlockState) BlockFace(org.bukkit.block.BlockFace) Block(org.bukkit.block.Block) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) ListTag(com.denizenscript.denizencore.objects.core.ListTag)

Example 35 with MaterialTag

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);
        }
    }
}
Also used : LocationTag(com.denizenscript.denizen.objects.LocationTag) MaterialTag(com.denizenscript.denizen.objects.MaterialTag) Block(org.bukkit.block.Block) List(java.util.List) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) BlockData(org.bukkit.block.data.BlockData)

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