Search in sources :

Example 1 with ServerPlayer

use of net.minecraft.server.level.ServerPlayer in project MinecraftForge by MinecraftForge.

the class TextComponentHelper method isVanillaClient.

private static boolean isVanillaClient(CommandSource sender) {
    if (sender instanceof ServerPlayer) {
        ServerPlayer playerMP = (ServerPlayer) sender;
        ServerGamePacketListenerImpl channel = playerMP.connection;
        return NetworkHooks.getConnectionType(() -> channel.connection) == ConnectionType.VANILLA;
    }
    return false;
}
Also used : ServerPlayer(net.minecraft.server.level.ServerPlayer) ServerGamePacketListenerImpl(net.minecraft.server.network.ServerGamePacketListenerImpl)

Example 2 with ServerPlayer

use of net.minecraft.server.level.ServerPlayer in project MinecraftForge by MinecraftForge.

the class FakePlayerTest method registerCommands.

@SubscribeEvent
public void registerCommands(RegisterCommandsEvent event) {
    event.getDispatcher().register(Commands.literal("fakeplayer").then(Commands.literal("attack").then(Commands.argument("target", EntityArgument.entity()).executes(context -> {
        FakePlayerFactory.getMinecraft(context.getSource().getLevel()).attack(EntityArgument.getEntity(context, "target"));
        return 1;
    }))).then(Commands.literal("opencontainer").executes(context -> {
        ServerPlayer fakePlayer = FakePlayerFactory.getMinecraft(context.getSource().getLevel());
        InteractionHand hand = InteractionHand.MAIN_HAND;
        ItemStack stack = Items.WRITABLE_BOOK.getDefaultInstance();
        fakePlayer.setItemInHand(hand, stack);
        fakePlayer.openItemGui(stack, hand);
        return 1;
    })));
}
Also used : ServerPlayer(net.minecraft.server.level.ServerPlayer) InteractionHand(net.minecraft.world.InteractionHand) ItemStack(net.minecraft.world.item.ItemStack) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 3 with ServerPlayer

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

the class AdvancementHelperImpl method update.

@Override
public void update(Player player) {
    ServerPlayer nmsPlayer = ((CraftPlayer) player).getHandle();
    nmsPlayer.connection.send(new ClientboundUpdateAdvancementsPacket(true, Collections.emptySet(), Collections.emptySet(), Collections.emptyMap()));
    PlayerAdvancements data = nmsPlayer.getAdvancements();
    // save progress
    data.save();
    // clear progress
    data.reload(DedicatedServer.getServer().getAdvancements());
    // load progress and update client
    data.flushDirty(nmsPlayer);
}
Also used : ClientboundUpdateAdvancementsPacket(net.minecraft.network.protocol.game.ClientboundUpdateAdvancementsPacket) PlayerAdvancements(net.minecraft.server.PlayerAdvancements) ServerPlayer(net.minecraft.server.level.ServerPlayer) CraftPlayer(org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer)

Example 4 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).getChunkSource().chunkMap;
        net.minecraft.world.entity.Entity other = ((CraftEntity) entity).getHandle();
        ChunkMap.TrackedEntity entry = tracker.entityMap.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.entity(org.bukkit.entity) org.bukkit.craftbukkit.v1_18_R1.entity(org.bukkit.craftbukkit.v1_18_R1.entity) net.minecraft.world.entity(net.minecraft.world.entity)

Example 5 with ServerPlayer

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

the class DenizenNetworkManagerImpl method setNetworkManager.

public static void setNetworkManager(Player player) {
    ServerPlayer entityPlayer = ((CraftPlayer) player).getHandle();
    ServerGamePacketListenerImpl playerConnection = entityPlayer.connection;
    setNetworkManager(playerConnection, new DenizenNetworkManagerImpl(entityPlayer, playerConnection.connection));
}
Also used : ServerPlayer(net.minecraft.server.level.ServerPlayer) CraftPlayer(org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer) ServerGamePacketListenerImpl(net.minecraft.server.network.ServerGamePacketListenerImpl)

Aggregations

ServerPlayer (net.minecraft.server.level.ServerPlayer)34 TamableAnimal (net.minecraft.world.entity.TamableAnimal)12 Behavior (de.Keyle.MyPet.api.skill.skills.Behavior)11 ArmorStand (net.minecraft.world.entity.decoration.ArmorStand)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 EntityMyPet (de.Keyle.MyPet.compat.v1_18_R1.entity.EntityMyPet)6 ChunkMap (net.minecraft.server.level.ChunkMap)6 ServerLevel (net.minecraft.server.level.ServerLevel)6 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)6 InvocationTargetException (java.lang.reflect.InvocationTargetException)5 ServerGamePacketListenerImpl (net.minecraft.server.network.ServerGamePacketListenerImpl)5 Ranged (de.Keyle.MyPet.api.skill.skills.Ranged)4 Method (java.lang.reflect.Method)4 ItemStack (net.minecraft.world.item.ItemStack)4 ClientboundRemoveEntitiesPacket (net.minecraft.network.protocol.game.ClientboundRemoveEntitiesPacket)3 InteractionHand (net.minecraft.world.InteractionHand)3