Search in sources :

Example 1 with PlayerConnection

use of net.minecraft.server.v1_16_R3.PlayerConnection 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.server.v1_16_R3.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.e(customId);
        nmsEntity.a_(customUUID);
    }
    EntityTag entity = new EntityTag(nmsEntity.getBukkitEntity());
    for (Mechanism mechanism : mechanisms) {
        entity.safeAdjustDuplicate(mechanism);
    }
    nmsEntity.dead = false;
    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) -> {
        EntityPlayer nmsPlayer = ((CraftPlayer) player.getPlayerEntity()).getHandle();
        PlayerConnection conn = nmsPlayer.playerConnection;
        final EntityTrackerEntry tracker = new EntityTrackerEntry(world.getHandle(), nmsEntity, 1, true, conn::sendPacket, Collections.singleton(nmsPlayer));
        tracker.b(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.b(((CraftPlayer) player.getPlayerEntity()).getHandle());
                            wasOnline = true;
                        }
                        tracker.a();
                    } 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.a();
            }
        }
    };
    fake.triggerDestroyPacket = () -> {
        for (TrackerData tracker : trackers) {
            if (tracker.player.isOnline()) {
                tracker.tracker.a(((CraftPlayer) tracker.player.getPlayerEntity()).getHandle());
            }
        }
        trackers.clear();
    };
    return fake;
}
Also used : FakeEntity(com.denizenscript.denizen.utilities.entity.FakeEntity) EntityItemProjectileImpl(com.denizenscript.denizen.nms.v1_16.impl.entities.EntityItemProjectileImpl) CraftFakePlayerImpl(com.denizenscript.denizen.nms.v1_16.impl.entities.CraftFakePlayerImpl) PlayerTag(com.denizenscript.denizen.objects.PlayerTag) Mechanism(com.denizenscript.denizencore.objects.Mechanism) EntityTag(com.denizenscript.denizen.objects.EntityTag) CraftWorld(org.bukkit.craftbukkit.v1_16_R3.CraftWorld) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) CraftPlayer(org.bukkit.craftbukkit.v1_16_R3.entity.CraftPlayer) ItemStack(org.bukkit.inventory.ItemStack) net.minecraft.server.v1_16_R3(net.minecraft.server.v1_16_R3) CraftItemStack(org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack) ItemStack(org.bukkit.inventory.ItemStack) ItemTag(com.denizenscript.denizen.objects.ItemTag)

Example 2 with PlayerConnection

use of net.minecraft.server.v1_16_R3.PlayerConnection in project DragonsOnline by UniverseCraft.

the class PlayerNPC116R3 method spawn.

public void spawn() {
    registry.unregister(this);
    uuid = UUID.randomUUID();
    this.isDestroyed = false;
    DedicatedServer server = ((CraftServer) Bukkit.getServer()).getServer();
    WorldServer world = ((CraftWorld) location.getWorld()).getHandle();
    // displayName);
    GameProfile gameProfile = new GameProfile(uuid, "");
    gameProfile.getProperties().clear();
    gameProfile.getProperties().put("textures", new Property("textures", texture, signature));
    this.handle = new EntityPlayer(server, world, gameProfile, new PlayerInteractManager(world));
    handle.persist = true;
    handle.collides = false;
    handle.setCustomNameVisible(false);
    handle.setInvulnerable(npc.isImmortal());
    handle.playerConnection = new PlayerConnection(((CraftServer) Bukkit.getServer()).getServer(), new NetworkManager(EnumProtocolDirection.SERVERBOUND), handle);
    ((CraftWorld) location.getWorld()).addEntity(handle, CreatureSpawnEvent.SpawnReason.CUSTOM);
    handle.setLocation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
    registry.register(this);
    for (Entity e : getEntity().getNearbyEntities(SPAWN_RADIUS, SPAWN_RADIUS, SPAWN_RADIUS)) {
        if (e instanceof Player) {
            registry.updateSpawns((Player) e, true);
        }
    }
}
Also used : Entity(org.bukkit.entity.Entity) PacketPlayOutEntity(net.minecraft.server.v1_16_R3.PacketPlayOutEntity) Player(org.bukkit.entity.Player) EntityPlayer(net.minecraft.server.v1_16_R3.EntityPlayer) CraftPlayer(org.bukkit.craftbukkit.v1_16_R3.entity.CraftPlayer) GameProfile(com.mojang.authlib.GameProfile) PlayerInteractManager(net.minecraft.server.v1_16_R3.PlayerInteractManager) EntityPlayer(net.minecraft.server.v1_16_R3.EntityPlayer) DedicatedServer(net.minecraft.server.v1_16_R3.DedicatedServer) WorldServer(net.minecraft.server.v1_16_R3.WorldServer) CraftServer(org.bukkit.craftbukkit.v1_16_R3.CraftServer) NetworkManager(net.minecraft.server.v1_16_R3.NetworkManager) CraftWorld(org.bukkit.craftbukkit.v1_16_R3.CraftWorld) Property(com.mojang.authlib.properties.Property) PlayerConnection(net.minecraft.server.v1_16_R3.PlayerConnection)

Example 3 with PlayerConnection

use of net.minecraft.server.v1_16_R3.PlayerConnection in project THP-Engine by TheHollowPlanetMC.

the class FlyPacketHandler method rewrite.

@Override
public Object rewrite(Object packet, EnginePlayer EnginePlayer, boolean cacheSetting) {
    ParallelUniverse universe = EnginePlayer.getUniverse();
    if (universe == null)
        return packet;
    World world = EnginePlayer.getBukkitPlayer().getWorld();
    String worldName = world.getName();
    ParallelWorld parallelWorld = universe.getWorld(worldName);
    EntityPlayer entityPlayer = ((CraftPlayer) EnginePlayer.getBukkitPlayer()).getHandle();
    int x = NumberConversions.floor(entityPlayer.locX());
    int y = NumberConversions.floor(entityPlayer.locY());
    int z = NumberConversions.floor(entityPlayer.locZ());
    int downY = y - 1;
    downY = Math.max(0, downY);
    if (parallelWorld.hasBlockData(x, y, z) || parallelWorld.hasBlockData(x, downY, z)) {
        try {
            PlayerConnection playerConnection = entityPlayer.playerConnection;
            C.set(playerConnection, 0);
            E.set(playerConnection, 0);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    return packet;
}
Also used : ParallelWorld(thpmc.engine.api.world.parallel.ParallelWorld) ParallelUniverse(thpmc.engine.api.world.parallel.ParallelUniverse) EntityPlayer(net.minecraft.server.v1_15_R1.EntityPlayer) CraftPlayer(org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer) World(org.bukkit.World) ParallelWorld(thpmc.engine.api.world.parallel.ParallelWorld) PlayerConnection(net.minecraft.server.v1_15_R1.PlayerConnection)

Example 4 with PlayerConnection

use of net.minecraft.server.v1_16_R3.PlayerConnection in project MechanicsMain by WeaponMechanics.

the class FakeEntity_1_16_R3 method show.

public void show() {
    // Construct the packets out of the loop to save resources, they will
    // be the same for each Player.
    Packet<?> spawn = type.isAlive() ? new PacketPlayOutSpawnEntityLiving((EntityLiving) entity) : new PacketPlayOutSpawnEntity(entity, type == EntityType.FALLING_BLOCK ? Block.getCombinedId(block) : 0);
    PacketPlayOutEntityMetadata meta = new PacketPlayOutEntityMetadata(cache, entity.getDataWatcher(), true);
    PacketPlayOutEntityHeadRotation head = new PacketPlayOutEntityHeadRotation(entity, convertYaw(getYaw()));
    PacketPlayOutEntityLook look = new PacketPlayOutEntityLook(cache, convertYaw(getYaw()), convertPitch(getPitch()), false);
    PacketPlayOutEntityVelocity velocity = new PacketPlayOutEntityVelocity(cache, new Vec3D(motion.getX(), motion.getY(), motion.getZ()));
    for (Player temp : DistanceUtil.getPlayersInRange(location)) {
        PlayerConnection connection = ((CraftPlayer) temp).getHandle().playerConnection;
        if (connections.contains(connection)) {
            continue;
        }
        connection.sendPacket(spawn);
        connection.sendPacket(meta);
        connection.sendPacket(head);
        connection.sendPacket(velocity);
        connection.sendPacket(look);
        PacketPlayOutEntityEquipment equipment = getEquipmentPacket();
        if (equipment != null)
            connection.sendPacket(equipment);
        connections.add(connection);
    }
}
Also used : Player(org.bukkit.entity.Player) CraftPlayer(org.bukkit.craftbukkit.v1_16_R3.entity.CraftPlayer) PacketPlayOutEntityLook(net.minecraft.server.v1_16_R3.PacketPlayOutEntity.PacketPlayOutEntityLook)

Example 5 with PlayerConnection

use of net.minecraft.server.v1_16_R3.PlayerConnection in project HitW-plugin by Blackoutburst.

the class GameUtils method sendTitle.

public static void sendTitle(Player player, String title, String subtitle, int fadeIn, int stay, int fadeOut) {
    CraftPlayer craftplayer = (CraftPlayer) player;
    PlayerConnection connection = craftplayer.getHandle().playerConnection;
    IChatBaseComponent titleJSON = ChatSerializer.a("{'text': '" + title + "'}");
    IChatBaseComponent subtitleJSON = ChatSerializer.a("{'text': '" + subtitle + "'}");
    PacketPlayOutTitle timePacket = new PacketPlayOutTitle(fadeIn, stay, fadeOut);
    PacketPlayOutTitle titlePacket = new PacketPlayOutTitle(EnumTitleAction.TITLE, titleJSON);
    PacketPlayOutTitle subtitlePacket = new PacketPlayOutTitle(EnumTitleAction.SUBTITLE, subtitleJSON);
    connection.sendPacket(timePacket);
    connection.sendPacket(titlePacket);
    connection.sendPacket(subtitlePacket);
}
Also used : PacketPlayOutTitle(net.minecraft.server.v1_8_R3.PacketPlayOutTitle) CraftPlayer(org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer) IChatBaseComponent(net.minecraft.server.v1_8_R3.IChatBaseComponent) PlayerConnection(net.minecraft.server.v1_8_R3.PlayerConnection)

Aggregations

CraftPlayer (org.bukkit.craftbukkit.v1_16_R3.entity.CraftPlayer)5 CraftWorld (org.bukkit.craftbukkit.v1_16_R3.CraftWorld)3 CraftFakePlayerImpl (com.denizenscript.denizen.nms.v1_16.impl.entities.CraftFakePlayerImpl)2 EntityItemProjectileImpl (com.denizenscript.denizen.nms.v1_16.impl.entities.EntityItemProjectileImpl)2 EntityTag (com.denizenscript.denizen.objects.EntityTag)2 ItemTag (com.denizenscript.denizen.objects.ItemTag)2 PlayerTag (com.denizenscript.denizen.objects.PlayerTag)2 FakeEntity (com.denizenscript.denizen.utilities.entity.FakeEntity)2 Mechanism (com.denizenscript.denizencore.objects.Mechanism)2 net.minecraft.server.v1_16_R3 (net.minecraft.server.v1_16_R3)2 EntityPlayer (net.minecraft.server.v1_16_R3.EntityPlayer)2 NetworkManager (net.minecraft.server.v1_16_R3.NetworkManager)2 PacketPlayOutEntityLook (net.minecraft.server.v1_16_R3.PacketPlayOutEntity.PacketPlayOutEntityLook)2 PlayerConnection (net.minecraft.server.v1_16_R3.PlayerConnection)2 World (org.bukkit.World)2 CraftItemStack (org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack)2 Player (org.bukkit.entity.Player)2 ItemStack (org.bukkit.inventory.ItemStack)2 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)2 ParallelUniverse (thpmc.engine.api.world.parallel.ParallelUniverse)2