Search in sources :

Example 6 with ServerPlayer

use of net.minecraft.server.level.ServerPlayer in project Denizen-For-Bukkit by DenizenScript.

the class PlayerHelperImpl method deTrackEntity.

@Override
public void deTrackEntity(Player player, Entity entity) {
    ServerPlayer nmsPlayer = ((CraftPlayer) player).getHandle();
    ServerLevel world = (ServerLevel) nmsPlayer.level;
    ChunkMap.TrackedEntity tracker = world.getChunkProvider().chunkMap.G.get(entity.getEntityId());
    if (tracker == null) {
        return;
    }
    sendEntityDestroy(player, entity);
    tracker.removePlayer(nmsPlayer);
}
Also used : ServerLevel(net.minecraft.server.level.ServerLevel) ChunkMap(net.minecraft.server.level.ChunkMap) ServerPlayer(net.minecraft.server.level.ServerPlayer) CraftPlayer(org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer)

Example 7 with ServerPlayer

use of net.minecraft.server.level.ServerPlayer in project Denizen-For-Bukkit by DenizenScript.

the class EntityHelperImpl method sendShowPacket.

@Override
public void sendShowPacket(Player pl, Entity entity) {
    if (entity instanceof Player) {
        pl.showPlayer(Denizen.getInstance(), (Player) entity);
        return;
    }
    CraftPlayer craftPlayer = (CraftPlayer) pl;
    ServerPlayer entityPlayer = craftPlayer.getHandle();
    if (entityPlayer.connection != null && !craftPlayer.equals(entity)) {
        ChunkMap tracker = ((ServerLevel) craftPlayer.getHandle().level).getChunkProvider().chunkMap;
        net.minecraft.world.entity.Entity other = ((CraftEntity) entity).getHandle();
        ChunkMap.TrackedEntity entry = tracker.G.get(other.getId());
        if (entry != null) {
            entry.removePlayer(entityPlayer);
            entry.updatePlayer(entityPlayer);
        }
    }
}
Also used : ServerPlayer(net.minecraft.server.level.ServerPlayer) ChunkMap(net.minecraft.server.level.ChunkMap) ServerPlayer(net.minecraft.server.level.ServerPlayer) org.bukkit.craftbukkit.v1_17_R1.entity(org.bukkit.craftbukkit.v1_17_R1.entity) org.bukkit.entity(org.bukkit.entity) net.minecraft.world.entity(net.minecraft.world.entity)

Example 8 with ServerPlayer

use of net.minecraft.server.level.ServerPlayer in project Denizen-For-Bukkit by DenizenScript.

the class EntityHelperImpl method sendHidePacket.

/*
        Hide Entity
     */
@Override
public void sendHidePacket(Player pl, Entity entity) {
    if (entity instanceof Player) {
        pl.hidePlayer(Denizen.getInstance(), (Player) entity);
        return;
    }
    CraftPlayer craftPlayer = (CraftPlayer) pl;
    ServerPlayer entityPlayer = craftPlayer.getHandle();
    if (entityPlayer.connection != null && !craftPlayer.equals(entity)) {
        ChunkMap tracker = ((ServerLevel) craftPlayer.getHandle().level).getChunkProvider().chunkMap;
        net.minecraft.world.entity.Entity other = ((CraftEntity) entity).getHandle();
        ChunkMap.TrackedEntity entry = tracker.G.get(other.getId());
        if (entry != null) {
            entry.removePlayer(entityPlayer);
        }
        if (Denizen.supportsPaper) {
            // Workaround for Paper issue
            entityPlayer.connection.send(new ClientboundRemoveEntitiesPacket(other.getId()));
        }
    }
}
Also used : ServerPlayer(net.minecraft.server.level.ServerPlayer) ChunkMap(net.minecraft.server.level.ChunkMap) ClientboundRemoveEntitiesPacket(net.minecraft.network.protocol.game.ClientboundRemoveEntitiesPacket) ServerPlayer(net.minecraft.server.level.ServerPlayer) org.bukkit.craftbukkit.v1_17_R1.entity(org.bukkit.craftbukkit.v1_17_R1.entity) org.bukkit.entity(org.bukkit.entity) net.minecraft.world.entity(net.minecraft.world.entity)

Example 9 with ServerPlayer

use of net.minecraft.server.level.ServerPlayer in project Denizen-For-Bukkit by DenizenScript.

the class PlayerHelperImpl method sendEntitySpawn.

@Override
public FakeEntity sendEntitySpawn(List<PlayerTag> players, DenizenEntityType entityType, LocationTag location, ArrayList<Mechanism> mechanisms, int customId, UUID customUUID, boolean autoTrack) {
    CraftWorld world = ((CraftWorld) location.getWorld());
    net.minecraft.world.entity.Entity nmsEntity;
    if (entityType.isCustom()) {
        if (entityType.customEntityType == CustomEntityType.ITEM_PROJECTILE) {
            org.bukkit.inventory.ItemStack itemStack = new ItemStack(Material.STONE);
            for (Mechanism mechanism : mechanisms) {
                if (mechanism.matches("item") && mechanism.requireObject(ItemTag.class)) {
                    itemStack = mechanism.valueAsType(ItemTag.class).getItemStack();
                }
            }
            nmsEntity = new EntityItemProjectileImpl(world.getHandle(), location, CraftItemStack.asNMSCopy(itemStack));
        } else if (entityType.customEntityType == CustomEntityType.FAKE_PLAYER) {
            String name = null;
            String skin = null;
            for (Mechanism mechanism : new ArrayList<>(mechanisms)) {
                if (mechanism.matches("name")) {
                    name = mechanism.getValue().asString();
                    mechanisms.remove(mechanism);
                } else if (mechanism.matches("skin")) {
                    skin = mechanism.getValue().asString();
                    mechanisms.remove(mechanism);
                }
                if (name != null && skin != null) {
                    break;
                }
            }
            nmsEntity = ((CraftFakePlayerImpl) CustomEntityHelperImpl.spawnFakePlayer(location, name, skin, false)).getHandle();
        } else {
            throw new IllegalArgumentException("entityType");
        }
    } else {
        nmsEntity = world.createEntity(location, entityType.getBukkitEntityType().getEntityClass());
    }
    if (customUUID != null) {
        nmsEntity.setId(customId);
        nmsEntity.setUUID(customUUID);
    }
    EntityTag entity = new EntityTag(nmsEntity.getBukkitEntity());
    entity.isFake = true;
    entity.isFakeValid = true;
    for (Mechanism mechanism : mechanisms) {
        entity.safeAdjustDuplicate(mechanism);
    }
    nmsEntity.unsetRemoved();
    FakeEntity fake = new FakeEntity(players, location, entity.getBukkitEntity().getEntityId());
    fake.entity = new EntityTag(entity.getBukkitEntity());
    fake.entity.isFake = true;
    fake.entity.isFakeValid = true;
    List<TrackerData> trackers = new ArrayList<>();
    fake.triggerSpawnPacket = (player) -> {
        ServerPlayer nmsPlayer = ((CraftPlayer) player.getPlayerEntity()).getHandle();
        ServerGamePacketListenerImpl conn = nmsPlayer.connection;
        final ServerEntity tracker = new ServerEntity(world.getHandle(), nmsEntity, 1, true, conn::send, Collections.singleton(nmsPlayer.connection));
        tracker.addPairing(nmsPlayer);
        final TrackerData data = new TrackerData();
        data.player = player;
        data.tracker = tracker;
        trackers.add(data);
        if (autoTrack) {
            new BukkitRunnable() {

                boolean wasOnline = true;

                @Override
                public void run() {
                    if (!fake.entity.isFakeValid) {
                        cancel();
                        return;
                    }
                    if (player.isOnline()) {
                        if (!wasOnline) {
                            tracker.addPairing(((CraftPlayer) player.getPlayerEntity()).getHandle());
                            wasOnline = true;
                        }
                        tracker.sendChanges();
                    } else if (wasOnline) {
                        wasOnline = false;
                    }
                }
            }.runTaskTimer(Denizen.getInstance(), 1, 1);
        }
    };
    for (PlayerTag player : players) {
        fake.triggerSpawnPacket.accept(player);
    }
    fake.triggerUpdatePacket = () -> {
        for (TrackerData tracker : trackers) {
            if (tracker.player.isOnline()) {
                tracker.tracker.sendChanges();
            }
        }
    };
    fake.triggerDestroyPacket = () -> {
        for (TrackerData tracker : trackers) {
            if (tracker.player.isOnline()) {
                tracker.tracker.removePairing(((CraftPlayer) tracker.player.getPlayerEntity()).getHandle());
            }
        }
        trackers.clear();
    };
    return fake;
}
Also used : FakeEntity(com.denizenscript.denizen.utilities.entity.FakeEntity) EntityItemProjectileImpl(com.denizenscript.denizen.nms.v1_18.impl.entities.EntityItemProjectileImpl) CraftFakePlayerImpl(com.denizenscript.denizen.nms.v1_18.impl.entities.CraftFakePlayerImpl) PlayerTag(com.denizenscript.denizen.objects.PlayerTag) Mechanism(com.denizenscript.denizencore.objects.Mechanism) ServerEntity(net.minecraft.server.level.ServerEntity) EntityTag(com.denizenscript.denizen.objects.EntityTag) CraftWorld(org.bukkit.craftbukkit.v1_18_R1.CraftWorld) ServerGamePacketListenerImpl(net.minecraft.server.network.ServerGamePacketListenerImpl) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) CraftPlayer(org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer) ItemStack(org.bukkit.inventory.ItemStack) ServerPlayer(net.minecraft.server.level.ServerPlayer) CraftItemStack(org.bukkit.craftbukkit.v1_18_R1.inventory.CraftItemStack) ItemStack(org.bukkit.inventory.ItemStack) ItemTag(com.denizenscript.denizen.objects.ItemTag)

Example 10 with ServerPlayer

use of net.minecraft.server.level.ServerPlayer in project Denizen-For-Bukkit by DenizenScript.

the class ProfileEditorImpl method updatePlayer.

@Override
protected void updatePlayer(Player player, final boolean isSkinChanging) {
    final ServerPlayer entityPlayer = ((CraftPlayer) player).getHandle();
    final UUID uuid = player.getUniqueId();
    ClientboundRemoveEntitiesPacket destroyPacket = new ClientboundRemoveEntitiesPacket(entityPlayer.getId());
    for (Player p : Bukkit.getServer().getOnlinePlayers()) {
        if (!p.getUniqueId().equals(uuid)) {
            PacketHelperImpl.send(p, destroyPacket);
        }
    }
    new BukkitRunnable() {

        @Override
        public void run() {
            ClientboundPlayerInfoPacket playerInfo = new ClientboundPlayerInfoPacket(ClientboundPlayerInfoPacket.Action.ADD_PLAYER, entityPlayer);
            ClientboundAddPlayerPacket spawnPacket = new ClientboundAddPlayerPacket(entityPlayer);
            for (Player player : Bukkit.getServer().getOnlinePlayers()) {
                PacketHelperImpl.send(player, playerInfo);
                if (!player.getUniqueId().equals(uuid)) {
                    PacketHelperImpl.send(player, spawnPacket);
                } else {
                    if (isSkinChanging) {
                        ((CraftServer) Bukkit.getServer()).getHandle().respawn(entityPlayer, (ServerLevel) entityPlayer.level, true, player.getLocation(), false);
                    }
                    player.updateInventory();
                }
            }
        }
    }.runTaskLater(NMSHandler.getJavaPlugin(), 5);
}
Also used : ServerLevel(net.minecraft.server.level.ServerLevel) ClientboundRemoveEntitiesPacket(net.minecraft.network.protocol.game.ClientboundRemoveEntitiesPacket) Player(org.bukkit.entity.Player) ServerPlayer(net.minecraft.server.level.ServerPlayer) CraftPlayer(org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer) ServerPlayer(net.minecraft.server.level.ServerPlayer) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) CraftPlayer(org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer) ClientboundAddPlayerPacket(net.minecraft.network.protocol.game.ClientboundAddPlayerPacket) UUID(java.util.UUID) CraftServer(org.bukkit.craftbukkit.v1_18_R1.CraftServer) ClientboundPlayerInfoPacket(net.minecraft.network.protocol.game.ClientboundPlayerInfoPacket)

Aggregations

ServerPlayer (net.minecraft.server.level.ServerPlayer)71 TamableAnimal (net.minecraft.world.entity.TamableAnimal)12 Behavior (de.Keyle.MyPet.api.skill.skills.Behavior)11 ServerLevel (net.minecraft.server.level.ServerLevel)11 ArmorStand (net.minecraft.world.entity.decoration.ArmorStand)11 ItemStack (net.minecraft.world.item.ItemStack)10 CraftPlayer (org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer)10 Player (org.bukkit.entity.Player)10 MyPet (de.Keyle.MyPet.api.entity.MyPet)8 EntityMyPet (de.Keyle.MyPet.compat.v1_17_R1.entity.EntityMyPet)8 CraftPlayer (org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer)8 Player (net.minecraft.world.entity.player.Player)7 EntityMyPet (de.Keyle.MyPet.compat.v1_18_R1.entity.EntityMyPet)6 ArrayList (java.util.ArrayList)6 ClientboundRemoveEntitiesPacket (net.minecraft.network.protocol.game.ClientboundRemoveEntitiesPacket)6 ChunkMap (net.minecraft.server.level.ChunkMap)6 ServerGamePacketListenerImpl (net.minecraft.server.network.ServerGamePacketListenerImpl)6 LivingEntity (net.minecraft.world.entity.LivingEntity)6 ItemEntity (net.minecraft.world.entity.item.ItemEntity)6 PlayerEntityTagMessage (com.wuest.prefab.proxy.messages.PlayerEntityTagMessage)5