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;
}
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;
})));
}
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);
}
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()));
}
}
}
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));
}
Aggregations