Search in sources :

Example 51 with PlayerTag

use of com.denizenscript.denizen.objects.PlayerTag in project Denizen-For-Bukkit by DenizenScript.

the class DenizenNetworkManagerImpl method processDisguiseForPacket.

public boolean processDisguiseForPacket(Packet<?> packet, GenericFutureListener<? extends Future<? super Void>> genericfuturelistener) {
    if (DisguiseCommand.disguises.isEmpty() || antiDuplicate) {
        return false;
    }
    try {
        if (packet instanceof PacketPlayOutEntityMetadata) {
            PacketPlayOutEntityMetadata metadataPacket = (PacketPlayOutEntityMetadata) packet;
            int eid = ENTITY_METADATA_EID.getInt(metadataPacket);
            Entity ent = player.world.getEntity(eid);
            if (ent == null) {
                return false;
            }
            HashMap<UUID, DisguiseCommand.TrackedDisguise> playerMap = DisguiseCommand.disguises.get(ent.getUniqueID());
            if (playerMap == null) {
                return false;
            }
            DisguiseCommand.TrackedDisguise disguise = playerMap.get(player.getUniqueID());
            if (disguise == null) {
                disguise = playerMap.get(null);
                if (disguise == null) {
                    return false;
                }
            }
            if (ent.getId() == player.getId()) {
                if (!disguise.shouldFake) {
                    return false;
                }
                List<DataWatcher.Item<?>> data = (List<DataWatcher.Item<?>>) ENTITY_METADATA_LIST.get(metadataPacket);
                for (DataWatcher.Item item : data) {
                    DataWatcherObject<?> watcherObject = item.a();
                    int watcherId = watcherObject.a();
                    if (watcherId == 0) {
                        // Entity flags
                        PacketPlayOutEntityMetadata altPacket = new PacketPlayOutEntityMetadata();
                        copyPacket(metadataPacket, altPacket);
                        data = new ArrayList<>(data);
                        ENTITY_METADATA_LIST.set(altPacket, data);
                        data.remove(item);
                        byte flags = (byte) item.b();
                        // Invisible flag
                        flags |= 0x20;
                        data.add(new DataWatcher.Item(watcherObject, flags));
                        PacketPlayOutEntityMetadata updatedPacket = getModifiedMetadataFor(altPacket);
                        oldManager.sendPacket(updatedPacket == null ? altPacket : updatedPacket, genericfuturelistener);
                        return true;
                    }
                }
            } else {
                PacketPlayOutEntityMetadata altPacket = new PacketPlayOutEntityMetadata(ent.getId(), ((CraftEntity) disguise.toOthers.entity.entity).getHandle().getDataWatcher(), true);
                oldManager.sendPacket(altPacket, genericfuturelistener);
                return true;
            }
            return false;
        }
        int ider = -1;
        if (packet instanceof PacketPlayOutNamedEntitySpawn) {
            ider = ENTITY_ID_NAMEDENTSPAWN.getInt(packet);
        } else if (packet instanceof PacketPlayOutSpawnEntity) {
            ider = ENTITY_ID_SPAWNENT.getInt(packet);
        } else if (packet instanceof PacketPlayOutSpawnEntityLiving) {
            ider = ENTITY_ID_SPAWNENTLIVING.getInt(packet);
        }
        if (ider != -1) {
            Entity e = player.getWorld().getEntity(ider);
            if (e == null) {
                return false;
            }
            HashMap<UUID, DisguiseCommand.TrackedDisguise> playerMap = DisguiseCommand.disguises.get(e.getUniqueID());
            if (playerMap == null) {
                return false;
            }
            DisguiseCommand.TrackedDisguise disguise = playerMap.get(player.getUniqueID());
            if (disguise == null) {
                disguise = playerMap.get(null);
                if (disguise == null) {
                    return false;
                }
            }
            antiDuplicate = true;
            disguise.sendTo(Collections.singletonList(new PlayerTag(player.getBukkitEntity())));
            antiDuplicate = false;
            return true;
        }
    } catch (Throwable ex) {
        antiDuplicate = false;
        Debug.echoError(ex);
    }
    return false;
}
Also used : CraftEntity(org.bukkit.craftbukkit.v1_16_R3.entity.CraftEntity) PacketOutSpawnEntity(com.denizenscript.denizen.nms.interfaces.packets.PacketOutSpawnEntity) DisguiseCommand(com.denizenscript.denizen.scripts.commands.player.DisguiseCommand) PlayerTag(com.denizenscript.denizen.objects.PlayerTag) CraftEntity(org.bukkit.craftbukkit.v1_16_R3.entity.CraftEntity)

Example 52 with PlayerTag

use of com.denizenscript.denizen.objects.PlayerTag 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 53 with PlayerTag

use of com.denizenscript.denizen.objects.PlayerTag in project Denizen-For-Bukkit by DenizenScript.

the class DenizenNetworkManagerImpl method processDisguiseForPacket.

public boolean processDisguiseForPacket(Packet<?> packet, GenericFutureListener<? extends Future<? super Void>> genericfuturelistener) {
    if (DisguiseCommand.disguises.isEmpty() || antiDuplicate) {
        return false;
    }
    try {
        if (packet instanceof ClientboundSetEntityDataPacket) {
            ClientboundSetEntityDataPacket metadataPacket = (ClientboundSetEntityDataPacket) packet;
            int eid = metadataPacket.getId();
            Entity ent = player.level.getEntity(eid);
            if (ent == null) {
                return false;
            }
            HashMap<UUID, DisguiseCommand.TrackedDisguise> playerMap = DisguiseCommand.disguises.get(ent.getUUID());
            if (playerMap == null) {
                return false;
            }
            DisguiseCommand.TrackedDisguise disguise = playerMap.get(player.getUUID());
            if (disguise == null) {
                disguise = playerMap.get(null);
                if (disguise == null) {
                    return false;
                }
            }
            if (ent.getId() == player.getId()) {
                if (!disguise.shouldFake) {
                    return false;
                }
                List<SynchedEntityData.DataItem<?>> data = metadataPacket.getUnpackedData();
                for (SynchedEntityData.DataItem item : data) {
                    EntityDataAccessor<?> watcherObject = item.getAccessor();
                    int watcherId = watcherObject.getId();
                    if (watcherId == 0) {
                        // Entity flags
                        ClientboundSetEntityDataPacket altPacket = new ClientboundSetEntityDataPacket(copyPacket(metadataPacket));
                        data = new ArrayList<>(data);
                        ENTITY_METADATA_LIST.set(altPacket, data);
                        data.remove(item);
                        byte flags = (byte) item.getValue();
                        // Invisible flag
                        flags |= 0x20;
                        data.add(new SynchedEntityData.DataItem(watcherObject, flags));
                        ClientboundSetEntityDataPacket updatedPacket = getModifiedMetadataFor(altPacket);
                        oldManager.send(updatedPacket == null ? altPacket : updatedPacket, genericfuturelistener);
                        return true;
                    }
                }
            } else {
                ClientboundSetEntityDataPacket altPacket = new ClientboundSetEntityDataPacket(ent.getId(), ((CraftEntity) disguise.toOthers.entity.entity).getHandle().getEntityData(), true);
                oldManager.send(altPacket, genericfuturelistener);
                return true;
            }
            return false;
        }
        int ider = -1;
        if (packet instanceof ClientboundAddPlayerPacket) {
            ider = ((ClientboundAddPlayerPacket) packet).getEntityId();
        } else if (packet instanceof ClientboundAddEntityPacket) {
            ider = ((ClientboundAddEntityPacket) packet).getId();
        } else if (packet instanceof ClientboundAddMobPacket) {
            ider = ((ClientboundAddMobPacket) packet).getId();
        }
        if (ider != -1) {
            Entity e = player.getLevel().getEntity(ider);
            if (e == null) {
                return false;
            }
            HashMap<UUID, DisguiseCommand.TrackedDisguise> playerMap = DisguiseCommand.disguises.get(e.getUUID());
            if (playerMap == null) {
                return false;
            }
            DisguiseCommand.TrackedDisguise disguise = playerMap.get(player.getUUID());
            if (disguise == null) {
                disguise = playerMap.get(null);
                if (disguise == null) {
                    return false;
                }
            }
            antiDuplicate = true;
            disguise.sendTo(Collections.singletonList(new PlayerTag(player.getBukkitEntity())));
            antiDuplicate = false;
            return true;
        }
    } catch (Throwable ex) {
        antiDuplicate = false;
        Debug.echoError(ex);
    }
    return false;
}
Also used : CraftEntity(org.bukkit.craftbukkit.v1_17_R1.entity.CraftEntity) Entity(net.minecraft.world.entity.Entity) DisguiseCommand(com.denizenscript.denizen.scripts.commands.player.DisguiseCommand) SynchedEntityData(net.minecraft.network.syncher.SynchedEntityData) PlayerTag(com.denizenscript.denizen.objects.PlayerTag) CraftEntity(org.bukkit.craftbukkit.v1_17_R1.entity.CraftEntity)

Example 54 with PlayerTag

use of com.denizenscript.denizen.objects.PlayerTag in project Denizen-For-Bukkit by DenizenScript.

the class StatisticCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) {
    ElementTag action = scriptEntry.getElement("action");
    ListTag players = scriptEntry.getObjectTag("players");
    ElementTag statistic = scriptEntry.getElement("statistic");
    ElementTag amount = scriptEntry.getElement("amount");
    MaterialTag material = scriptEntry.getObjectTag("material");
    EntityTag entity = scriptEntry.getObjectTag("entity");
    if (scriptEntry.dbCallShouldDebug()) {
        Debug.report(scriptEntry, getName(), action, statistic, amount, players, material, entity);
    }
    Action act = Action.valueOf(action.asString().toUpperCase());
    Statistic stat = Statistic.valueOf(statistic.asString().toUpperCase());
    int amt = amount.asInt();
    switch(stat.getType()) {
        case BLOCK:
        case ITEM:
            Material mat = material.getMaterial();
            switch(act) {
                case ADD:
                    for (PlayerTag player : players.filter(PlayerTag.class, scriptEntry)) {
                        player.incrementStatistic(stat, mat, amt);
                    }
                    break;
                case TAKE:
                    for (PlayerTag player : players.filter(PlayerTag.class, scriptEntry)) {
                        player.decrementStatistic(stat, mat, amt);
                    }
                    break;
                case SET:
                    for (PlayerTag player : players.filter(PlayerTag.class, scriptEntry)) {
                        player.setStatistic(stat, mat, amt);
                    }
                    break;
            }
            break;
        case ENTITY:
            EntityType ent = entity.getBukkitEntityType();
            switch(act) {
                case ADD:
                    for (PlayerTag player : players.filter(PlayerTag.class, scriptEntry)) {
                        player.incrementStatistic(stat, ent, amt);
                    }
                    break;
                case TAKE:
                    for (PlayerTag player : players.filter(PlayerTag.class, scriptEntry)) {
                        player.decrementStatistic(stat, ent, amt);
                    }
                    break;
                case SET:
                    for (PlayerTag player : players.filter(PlayerTag.class, scriptEntry)) {
                        player.setStatistic(stat, ent, amt);
                    }
                    break;
            }
            break;
        case UNTYPED:
            switch(act) {
                case ADD:
                    for (PlayerTag player : players.filter(PlayerTag.class, scriptEntry)) {
                        player.incrementStatistic(stat, amt);
                    }
                    break;
                case TAKE:
                    for (PlayerTag player : players.filter(PlayerTag.class, scriptEntry)) {
                        player.decrementStatistic(stat, amt);
                    }
                    break;
                case SET:
                    for (PlayerTag player : players.filter(PlayerTag.class, scriptEntry)) {
                        player.setStatistic(stat, amt);
                    }
                    break;
            }
            break;
    }
}
Also used : MaterialTag(com.denizenscript.denizen.objects.MaterialTag) EntityType(org.bukkit.entity.EntityType) Statistic(org.bukkit.Statistic) PlayerTag(com.denizenscript.denizen.objects.PlayerTag) EntityTag(com.denizenscript.denizen.objects.EntityTag) Material(org.bukkit.Material) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) ListTag(com.denizenscript.denizencore.objects.core.ListTag)

Example 55 with PlayerTag

use of com.denizenscript.denizen.objects.PlayerTag in project Denizen-For-Bukkit by DenizenScript.

the class AnnounceCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) {
    if (scriptEntry.getResidingQueue().procedural) {
        Debug.echoError("'Announce' should not be used in a procedure script. Consider the 'debug' command instead.");
    }
    ElementTag text = scriptEntry.getElement("text");
    AnnounceType type = (AnnounceType) scriptEntry.getObject("type");
    FormatScriptContainer format = (FormatScriptContainer) scriptEntry.getObject("format");
    ElementTag flag = scriptEntry.getElement("flag");
    if (scriptEntry.dbCallShouldDebug()) {
        Debug.report(scriptEntry, getName(), db("message", text), (format != null ? db("format", format.getName()) : ""), db("type", type.name()), flag);
    }
    String message = format != null ? format.getFormattedText(text.asString(), scriptEntry) : text.asString();
    // Use Bukkit to broadcast the message to everybody in the server.
    switch(type) {
        case ALL:
            Denizen.getInstance().getServer().spigot().broadcast(FormattedTextHelper.parse(message, ChatColor.WHITE));
            break;
        case TO_OPS:
            for (Player player : Bukkit.getOnlinePlayers()) {
                if (player.isOp()) {
                    player.spigot().sendMessage(FormattedTextHelper.parse(message, ChatColor.WHITE));
                }
            }
            break;
        case TO_PERMISSION:
            for (Player player : Bukkit.getOnlinePlayers()) {
                if (player.hasPermission(flag.asString())) {
                    player.spigot().sendMessage(FormattedTextHelper.parse(message, ChatColor.WHITE));
                }
            }
        case TO_FLAGGED:
            for (Player player : Bukkit.getOnlinePlayers()) {
                if (new PlayerTag(player).getFlagTracker().hasFlag(flag.asString())) {
                    player.spigot().sendMessage(FormattedTextHelper.parse(message, ChatColor.WHITE));
                }
            }
            break;
        case TO_CONSOLE:
            Bukkit.getServer().getConsoleSender().spigot().sendMessage(FormattedTextHelper.parse(message, ChatColor.WHITE));
            break;
    }
}
Also used : Player(org.bukkit.entity.Player) PlayerTag(com.denizenscript.denizen.objects.PlayerTag) FormatScriptContainer(com.denizenscript.denizen.scripts.containers.core.FormatScriptContainer) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag)

Aggregations

PlayerTag (com.denizenscript.denizen.objects.PlayerTag)81 ElementTag (com.denizenscript.denizencore.objects.core.ElementTag)41 Player (org.bukkit.entity.Player)26 List (java.util.List)23 NPCTag (com.denizenscript.denizen.objects.NPCTag)22 EntityTag (com.denizenscript.denizen.objects.EntityTag)16 DurationTag (com.denizenscript.denizencore.objects.core.DurationTag)15 ListTag (com.denizenscript.denizencore.objects.core.ListTag)15 LocationTag (com.denizenscript.denizen.objects.LocationTag)14 ItemTag (com.denizenscript.denizen.objects.ItemTag)12 InvalidArgumentsException (com.denizenscript.denizencore.exceptions.InvalidArgumentsException)11 EventHandler (org.bukkit.event.EventHandler)11 BukkitTagContext (com.denizenscript.denizen.tags.BukkitTagContext)8 ScriptTag (com.denizenscript.denizencore.objects.core.ScriptTag)8 ScriptEntry (com.denizenscript.denizencore.scripts.ScriptEntry)8 MaterialTag (com.denizenscript.denizen.objects.MaterialTag)7 BukkitScriptEntryData (com.denizenscript.denizen.utilities.implementation.BukkitScriptEntryData)7 ObjectTag (com.denizenscript.denizencore.objects.ObjectTag)7 FakeEntity (com.denizenscript.denizen.utilities.entity.FakeEntity)6 Argument (com.denizenscript.denizencore.objects.Argument)6