Search in sources :

Example 6 with PlayerConnection

use of net.minecraft.server.v1_15_R1.PlayerConnection in project WLib by WizardlyBump17.

the class EntityAdapter method sendPacket.

@Override
public void sendPacket(Object... packets) {
    if (!(entity instanceof Player))
        return;
    EntityPlayer player = ((CraftPlayer) entity).getHandle();
    PlayerConnection connection = player.playerConnection;
    for (Object packet : packets) {
        if (!(packet instanceof Packet))
            continue;
        connection.sendPacket(((Packet<?>) packet));
    }
}
Also used : Packet(net.minecraft.server.v1_15_R1.Packet) Player(org.bukkit.entity.Player) CraftPlayer(org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer) EntityPlayer(net.minecraft.server.v1_15_R1.EntityPlayer) EntityPlayer(net.minecraft.server.v1_15_R1.EntityPlayer) CraftPlayer(org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer) PlayerConnection(net.minecraft.server.v1_15_R1.PlayerConnection)

Example 7 with PlayerConnection

use of net.minecraft.server.v1_15_R1.PlayerConnection in project Citizens2 by CitizensDev.

the class EntityHumanNPC method initialise.

private void initialise(MinecraftServer minecraftServer) {
    Socket socket = new EmptySocket();
    NetworkManager conn = null;
    try {
        conn = new EmptyNetworkManager(EnumProtocolDirection.CLIENTBOUND);
        playerConnection = new EmptyNetHandler(minecraftServer, conn, this);
        conn.setPacketListener(playerConnection);
        socket.close();
    } catch (IOException e) {
    // swallow
    }
    AttributeInstance range = getAttributeInstance(GenericAttributes.FOLLOW_RANGE);
    if (range == null) {
        range = getAttributeMap().b(GenericAttributes.FOLLOW_RANGE);
    }
    range.setValue(Setting.DEFAULT_PATHFINDING_RANGE.asDouble());
    controllerJump = new PlayerControllerJump(this);
    controllerLook = new PlayerControllerLook(this);
    controllerMove = new PlayerControllerMove(this);
    navigation = new PlayerNavigation(this, world);
    invulnerableTicks = 0;
    // the default (0) breaks step climbing
    NMS.setStepHeight(getBukkitEntity(), 1);
    setSkinFlags((byte) 0xFF);
    EmptyAdvancementDataPlayer.clear(this.getAdvancementData());
    NMSImpl.setAdvancement(this.getBukkitEntity(), new EmptyAdvancementDataPlayer(minecraftServer, CitizensAPI.getDataFolder().getParentFile(), this));
}
Also used : EmptyNetworkManager(net.citizensnpcs.nms.v1_15_R1.network.EmptyNetworkManager) PlayerControllerLook(net.citizensnpcs.nms.v1_15_R1.util.PlayerControllerLook) EmptySocket(net.citizensnpcs.nms.v1_15_R1.network.EmptySocket) EmptyNetHandler(net.citizensnpcs.nms.v1_15_R1.network.EmptyNetHandler) PlayerControllerMove(net.citizensnpcs.nms.v1_15_R1.util.PlayerControllerMove) PlayerNavigation(net.citizensnpcs.nms.v1_15_R1.util.PlayerNavigation) AttributeInstance(net.minecraft.server.v1_15_R1.AttributeInstance) PlayerControllerJump(net.citizensnpcs.nms.v1_15_R1.util.PlayerControllerJump) IOException(java.io.IOException) EmptyAdvancementDataPlayer(net.citizensnpcs.nms.v1_15_R1.util.EmptyAdvancementDataPlayer) EmptyNetworkManager(net.citizensnpcs.nms.v1_15_R1.network.EmptyNetworkManager) NetworkManager(net.minecraft.server.v1_15_R1.NetworkManager) Socket(java.net.Socket) EmptySocket(net.citizensnpcs.nms.v1_15_R1.network.EmptySocket)

Example 8 with PlayerConnection

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

the class FakeEntity_1_15_R1 method show.

@Override
public void show(@NotNull Player player) {
    PlayerConnection connection = ((CraftPlayer) player).getHandle().playerConnection;
    if (connections.contains(connection))
        throw new IllegalArgumentException();
    connection.sendPacket(type.isAlive() ? new PacketPlayOutSpawnEntityLiving((EntityLiving) entity) : new PacketPlayOutSpawnEntity(entity, type == EntityType.FALLING_BLOCK ? Block.getCombinedId(block) : 0));
    connection.sendPacket(new PacketPlayOutEntityMetadata(cache, entity.getDataWatcher(), true));
    connection.sendPacket(new PacketPlayOutEntityLook(cache, convertYaw(getYaw()), convertPitch(getPitch()), false));
    connection.sendPacket(new PacketPlayOutEntityVelocity(cache, new Vec3D(motion.getX(), motion.getY(), motion.getZ())));
    connection.sendPacket(new PacketPlayOutEntityHeadRotation(entity, convertYaw(getYaw())));
    PacketPlayOutEntityEquipment[] equipment = getEquipmentPacket();
    if (equipment != null) {
        for (PacketPlayOutEntityEquipment packet : equipment) {
            connection.sendPacket(packet);
        }
    }
    // Inject the player's packet connection into this listener, so we can
    // show the player position/velocity/rotation changes
    connections.add(connection);
}
Also used : PacketPlayOutEntityLook(net.minecraft.server.v1_15_R1.PacketPlayOutEntity.PacketPlayOutEntityLook)

Example 9 with PlayerConnection

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

the class FakeEntity_1_15_R1 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) {
            for (PacketPlayOutEntityEquipment packet : equipment) {
                connection.sendPacket(packet);
            }
        }
        connections.add(connection);
    }
}
Also used : Player(org.bukkit.entity.Player) CraftPlayer(org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer) PacketPlayOutEntityLook(net.minecraft.server.v1_15_R1.PacketPlayOutEntity.PacketPlayOutEntityLook)

Example 10 with PlayerConnection

use of net.minecraft.server.v1_15_R1.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_16_R3.EntityPlayer) CraftPlayer(org.bukkit.craftbukkit.v1_16_R3.entity.CraftPlayer) World(org.bukkit.World) ParallelWorld(thpmc.engine.api.world.parallel.ParallelWorld) PlayerConnection(net.minecraft.server.v1_16_R3.PlayerConnection)

Aggregations

Player (org.bukkit.entity.Player)6 EntityPlayer (net.minecraft.server.v1_16_R3.EntityPlayer)3 PlayerConnection (net.minecraft.server.v1_16_R3.PlayerConnection)3 CraftPlayer (org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer)3 CraftPlayer (org.bukkit.craftbukkit.v1_16_R3.entity.CraftPlayer)3 GameProfile (com.mojang.authlib.GameProfile)2 EntityPlayer (net.minecraft.server.v1_15_R1.EntityPlayer)2 PacketPlayOutEntityLook (net.minecraft.server.v1_15_R1.PacketPlayOutEntity.PacketPlayOutEntityLook)2 PlayerConnection (net.minecraft.server.v1_15_R1.PlayerConnection)2 PlayerConnection (net.minecraft.server.v1_8_R3.PlayerConnection)2 World (org.bukkit.World)2 CraftPlayer (org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer)2 ParallelUniverse (thpmc.engine.api.world.parallel.ParallelUniverse)2 ParallelWorld (thpmc.engine.api.world.parallel.ParallelWorld)2 Property (com.mojang.authlib.properties.Property)1 IOException (java.io.IOException)1 Socket (java.net.Socket)1 EmptyNetHandler (net.citizensnpcs.nms.v1_15_R1.network.EmptyNetHandler)1 EmptyNetworkManager (net.citizensnpcs.nms.v1_15_R1.network.EmptyNetworkManager)1 EmptySocket (net.citizensnpcs.nms.v1_15_R1.network.EmptySocket)1