net.minecraft.server.network.ServerPlayerEntity Java Examples

The following examples show how to use net.minecraft.server.network.ServerPlayerEntity. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PlayerCommand.java    From fabric-carpet with MIT License 7 votes vote down vote up
private static int shadow(CommandContext<ServerCommandSource> context)
{
    ServerPlayerEntity player = getPlayer(context);
    if (player instanceof EntityPlayerMPFake)
    {
        Messenger.m(context.getSource(), "r Cannot shadow fake players");
        return 0;
    }
    ServerPlayerEntity sendingPlayer = null;
    try
    {
        sendingPlayer = context.getSource().getPlayer();
    }
    catch (CommandSyntaxException ignored) { }

    if (sendingPlayer!=player && cantManipulate(context)) return 0;
    EntityPlayerMPFake.createShadow(player.server, player);
    return 1;
}
 
Example #2
Source File: AnimalMateGoalMixin.java    From carpet-extra with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Inject(
    method = "breed",
    at = @At(
        value = "INVOKE",
        target = "Lnet/minecraft/world/World;spawnEntity(Lnet/minecraft/entity/Entity;)Z",
        ordinal = 1
    ),
    cancellable = true
)
protected void onSpawnExperience(CallbackInfo ci) {
    ServerPlayerEntity serverPlayerEntity_1 = this.animal.getLovingPlayer();
    if (serverPlayerEntity_1 == null) {
        serverPlayerEntity_1 = this.mate.getLovingPlayer();
    }
    if(serverPlayerEntity_1 == null && CarpetExtraSettings.dispensersFeedAnimals) {
        ci.cancel();
    }
}
 
Example #3
Source File: CarpetScriptHost.java    From fabric-carpet with MIT License 6 votes vote down vote up
public CarpetScriptHost retrieveForExecution(ServerCommandSource source)
{
    CarpetScriptHost host = this;
    if (perUser)
    {
        try
        {
            ServerPlayerEntity player = source.getPlayer();
            host = (CarpetScriptHost) retrieveForExecution(player.getName().getString());
        }
        catch (CommandSyntaxException e)
        {
            host = (CarpetScriptHost)  retrieveForExecution((String) null);
        }
    }
    if (host.errorSnooper == null) host.setChatErrorSnooper(source);
    return host;
}
 
Example #4
Source File: ServerPlayerEntity_scarpetEventMixin.java    From fabric-carpet with MIT License 6 votes vote down vote up
@Redirect(method = "consumeItem", at = @At(
        value = "INVOKE",
        target = "Lnet/minecraft/entity/player/PlayerEntity;consumeItem()V"
))
private void finishedUsingItem(PlayerEntity playerEntity)
{
    if (PLAYER_FINISHED_USING_ITEM.isNeeded())
    {
        Hand hand = getActiveHand();
        ItemStack stack = getActiveItem().copy();
        // do vanilla
        super.consumeItem();
        PLAYER_FINISHED_USING_ITEM.onItemAction((ServerPlayerEntity) (Object)this, hand, stack);
    }
    else
    {
        // do vanilla
        super.consumeItem();
    }
}
 
Example #5
Source File: ShapeDispatcher.java    From fabric-carpet with MIT License 6 votes vote down vote up
@Override
public Consumer<ServerPlayerEntity> alternative()
{
    ParticleEffect particle = replacementParticle();
    double density = Math.max(2.0, from.distanceTo(to) /50) / (a+0.1);
    return p ->
    {
        if (p.dimension == shapeDimension) drawParticleLine(
                Collections.singletonList(p),
                particle,
                relativiseRender(p.getServerWorld(), from, 0),
                relativiseRender(p.getServerWorld(), to, 0),
                density
        );
    };
}
 
Example #6
Source File: ShapeDispatcher.java    From fabric-carpet with MIT License 6 votes vote down vote up
public static int particleMesh(List<ServerPlayerEntity> playerList, ParticleEffect particle, double density,
                               Vec3d from, Vec3d to)
{
    double x1 = from.x;
    double y1 = from.y;
    double z1 = from.z;
    double x2 = to.x;
    double y2 = to.y;
    double z2 = to.z;
    return
    drawParticleLine(playerList, particle, new Vec3d(x1, y1, z1), new Vec3d(x1, y2, z1), density)+
    drawParticleLine(playerList, particle, new Vec3d(x1, y2, z1), new Vec3d(x2, y2, z1), density)+
    drawParticleLine(playerList, particle, new Vec3d(x2, y2, z1), new Vec3d(x2, y1, z1), density)+
    drawParticleLine(playerList, particle, new Vec3d(x2, y1, z1), new Vec3d(x1, y1, z1), density)+

    drawParticleLine(playerList, particle, new Vec3d(x1, y1, z2), new Vec3d(x1, y2, z2), density)+
    drawParticleLine(playerList, particle, new Vec3d(x1, y2, z2), new Vec3d(x2, y2, z2), density)+
    drawParticleLine(playerList, particle, new Vec3d(x2, y2, z2), new Vec3d(x2, y1, z2), density)+
    drawParticleLine(playerList, particle, new Vec3d(x2, y1, z2), new Vec3d(x1, y1, z2), density)+

    drawParticleLine(playerList, particle, new Vec3d(x1, y1, z1), new Vec3d(x1, y1, z2), density)+
    drawParticleLine(playerList, particle, new Vec3d(x1, y2, z1), new Vec3d(x1, y2, z2), density)+
    drawParticleLine(playerList, particle, new Vec3d(x2, y2, z1), new Vec3d(x2, y2, z2), density)+
    drawParticleLine(playerList, particle, new Vec3d(x2, y1, z1), new Vec3d(x2, y1, z2), density);
}
 
Example #7
Source File: CarpetEventServer.java    From fabric-carpet with MIT License 6 votes vote down vote up
@Override
public void onBlockHit(ServerPlayerEntity player, Hand enumhand, BlockHitResult hitRes)
{
    handler.call( () ->
    {
        BlockPos blockpos = hitRes.getBlockPos();
        Direction enumfacing = hitRes.getSide();
        Vec3d vec3d = hitRes.getPos().subtract(blockpos.getX(), blockpos.getY(), blockpos.getZ());
        return Arrays.asList(
                ((c, t) -> new EntityValue(player)),
                ((c, t) -> new StringValue(enumhand == Hand.MAIN_HAND ? "mainhand" : "offhand")),
                ((c, t) -> new BlockValue(null, player.getServerWorld(), blockpos)),
                ((c, t) -> new StringValue(enumfacing.getName())),
                ((c, t) -> ListValue.of(
                        new NumericValue(vec3d.x),
                        new NumericValue(vec3d.y),
                        new NumericValue(vec3d.z)
                ))
        );
    }, player::getCommandSource);
}
 
Example #8
Source File: ShapeDispatcher.java    From fabric-carpet with MIT License 6 votes vote down vote up
@Override
public Consumer<ServerPlayerEntity> alternative()
{
    ParticleEffect particle = replacementParticle();
    double density = Math.max(2.0, from.distanceTo(to) /50) / (a+0.1);
    return p ->
    {
        if (p.dimension == shapeDimension)
        {
            particleMesh(
                    Collections.singletonList(p),
                    particle,
                    density,
                    relativiseRender(p.getServerWorld(), from, 0),
                    relativiseRender(p.getServerWorld(), to, 0)
            );
        }
    };
}
 
Example #9
Source File: EntityValue.java    From fabric-carpet with MIT License 6 votes vote down vote up
private static void updatePosition(Entity e, double x, double y, double z, float yaw, float pitch)
{
    if (
            !Double.isFinite(x) || Double.isNaN(x) ||
            !Double.isFinite(y) || Double.isNaN(y) ||
            !Double.isFinite(z) || Double.isNaN(z) ||
            !Float.isFinite(yaw) || Float.isNaN(yaw) ||
            !Float.isFinite(pitch) || Float.isNaN(pitch)
    )
        return;
    if (e instanceof ServerPlayerEntity)
    {
        // this forces position but doesn't angles for some reason. Need both in the API in the future.
        EnumSet<PlayerPositionLookS2CPacket.Flag> set  = EnumSet.noneOf(PlayerPositionLookS2CPacket.Flag.class);
        set.add(PlayerPositionLookS2CPacket.Flag.X_ROT);
        set.add(PlayerPositionLookS2CPacket.Flag.Y_ROT);
        ((ServerPlayerEntity)e).networkHandler.teleportRequest(x, y, z, yaw, pitch, set );
    }
    else
    {
        e.refreshPositionAndAngles(x, y, z, yaw, pitch);
        ((ServerWorld) e.getEntityWorld()).getChunkManager().sendToNearbyPlayers(e, new EntityPositionS2CPacket(e));
    }

}
 
Example #10
Source File: PathfindingVisualizer.java    From fabric-carpet with MIT License 6 votes vote down vote up
public static void slowPath(Entity entity, Vec3d target, float miliseconds, boolean successful)
{
    if (!LoggerRegistry.__pathfinding) return;
    LoggerRegistry.getLogger("pathfinding").log( (option, player)->
    {
        if (!(player instanceof ServerPlayerEntity))
            return null;
        int minDuration = Integer.parseInt(option);
        if (miliseconds < minDuration)
            return null;
        if (player.squaredDistanceTo(entity) > 1000 && player.squaredDistanceTo(target) > 1000)
            return null;
        if (minDuration < 1)
            minDuration = 1;

        String accent = successful ? "happy_villager" : "angry_villager";
        String color = (miliseconds/minDuration < 2)? "dust 1 1 0 1" : ((miliseconds/minDuration < 4)?"dust 1 0.5 0 1":"dust 1 0 0 1");
        ParticleDisplay.drawParticleLine((ServerPlayerEntity) player, entity.getPos(), target, color, accent, 5, 0.5);
        return null;
    });
}
 
Example #11
Source File: EntityPlayerMPFake.java    From fabric-carpet with MIT License 6 votes vote down vote up
public static EntityPlayerMPFake createShadow(MinecraftServer server, ServerPlayerEntity player)
{
    player.getServer().getPlayerManager().remove(player);
    player.networkHandler.disconnect(new TranslatableText("multiplayer.disconnect.duplicate_login"));
    ServerWorld worldIn = server.getWorld(player.dimension);
    ServerPlayerInteractionManager interactionManagerIn = new ServerPlayerInteractionManager(worldIn);
    GameProfile gameprofile = player.getGameProfile();
    EntityPlayerMPFake playerShadow = new EntityPlayerMPFake(server, worldIn, gameprofile, interactionManagerIn, true);
    server.getPlayerManager().onPlayerConnect(new NetworkManagerFake(NetworkSide.SERVERBOUND), playerShadow);

    playerShadow.setHealth(player.getHealth());
    playerShadow.networkHandler.requestTeleport(player.getX(), player.getY(), player.getZ(), player.yaw, player.pitch);
    interactionManagerIn.setGameMode(player.interactionManager.getGameMode());
    ((ServerPlayerEntityInterface) playerShadow).getActionPack().copyFrom(((ServerPlayerEntityInterface) player).getActionPack());
    playerShadow.stepHeight = 0.6F;
    playerShadow.dataTracker.set(PLAYER_MODEL_PARTS, player.getDataTracker().get(PLAYER_MODEL_PARTS));


    server.getPlayerManager().sendToDimension(new EntitySetHeadYawS2CPacket(playerShadow, (byte) (player.headYaw * 256 / 360)), playerShadow.dimension);
    server.getPlayerManager().sendToAll(new PlayerListS2CPacket(PlayerListS2CPacket.Action.ADD_PLAYER, playerShadow));
    player.getServerWorld().getChunkManager().updateCameraPosition(playerShadow);
    return playerShadow;
}
 
Example #12
Source File: ServerWorld_fakePlayersMixin.java    From fabric-carpet with MIT License 6 votes vote down vote up
@Redirect( method = "removePlayer", at  = @At(
        value = "INVOKE",
        target = "Lnet/minecraft/server/world/ServerWorld;removeEntity(Lnet/minecraft/entity/Entity;)V"
))
private void crashRemovePlayer(ServerWorld serverWorld, Entity entity_1, ServerPlayerEntity serverPlayerEntity_1)
{
    if ( !(ticking && serverPlayerEntity_1 instanceof EntityPlayerMPFake) )
        serverWorld.removeEntity(entity_1);
    else
        getServer().send(new ServerTask(getServer().getTicks(), () ->
        {
            serverWorld.removeEntity(serverPlayerEntity_1);
            serverPlayerEntity_1.onTeleportationDone();
        }));

}
 
Example #13
Source File: MixinPlayerChat_SayCommand.java    From Galaxy with GNU Affero General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("UnresolvedMixinReference")
@Inject(
    method = "method_13563",
    at = @At(
        value = "INVOKE",
        target = "Lnet/minecraft/server/PlayerManager;broadcastChatMessage(Lnet/minecraft/text/Text;Lnet/minecraft/network/MessageType;Ljava/util/UUID;)V",
        ordinal = 0
    ),
    locals = LocalCapture.CAPTURE_FAILSOFT
)
private static void onCommand(CommandContext<ServerCommandSource> context, CallbackInfoReturnable<Integer> cir, Text text, TranslatableText translatableText, Entity entity) {
    if (!(entity instanceof ServerPlayerEntity)) return;

    Main main = Main.Companion.getMain();
    ServerPlayerEntity player = (ServerPlayerEntity) entity;

    if (main == null || !main.getEventManager().emit(new PlayerChatEvent(player, translatableText)).getCancel()) {
        player.server.getPlayerManager().broadcastChatMessage(translatableText, MessageType.CHAT, entity.getUuid());
    } else {
        cir.setReturnValue(0);
        cir.cancel();
        player.server.sendSystemMessage(translatableText.append(" (Canceled)"), entity.getUuid());
    }
}
 
Example #14
Source File: TickCommand.java    From fabric-carpet with MIT License 6 votes vote down vote up
private static int setWarp(ServerCommandSource source, int advance, String tail_command)
{
    ServerPlayerEntity player = null;
    try
    {
        player = source.getPlayer();
    }
    catch (CommandSyntaxException ignored)
    {
    }
    BaseText message = TickSpeed.tickrate_advance(player, advance, tail_command, source);
    if (message != null)
    {
        source.sendFeedback(message, false);
    }
    return 1;
}
 
Example #15
Source File: CarpetEventServer.java    From fabric-carpet with MIT License 6 votes vote down vote up
@Override
public void onDimensionChange(ServerPlayerEntity player, Vec3d from, Vec3d to, DimensionType fromDim, DimensionType dimTo)
{
    // eligibility already checked in mixin
    Value fromValue = ListValue.fromTriple(from.x, from.y, from.z);
    Value toValue = (to == null)?Value.NULL:ListValue.fromTriple(to.x, to.y, to.z);
    Value fromDimStr = new StringValue(NBTSerializableValue.nameFromRegistryId(Registry.DIMENSION_TYPE.getId(fromDim)));
    Value toDimStr = new StringValue(NBTSerializableValue.nameFromRegistryId(Registry.DIMENSION_TYPE.getId(dimTo)));

    handler.call( () -> Arrays.asList(
            ((c, t) -> new EntityValue(player)),
            ((c, t) -> fromValue),
            ((c, t) -> fromDimStr),
            ((c, t) -> toValue),
            ((c, t) -> toDimStr)
    ), player::getCommandSource);
}
 
Example #16
Source File: ServerWorld_onePlayerSleepingMixin.java    From fabric-carpet with MIT License 6 votes vote down vote up
@Inject(method = "updatePlayersSleeping", cancellable = true, at = @At("HEAD"))
private void updateOnePlayerSleeping(CallbackInfo ci)
{
    if(CarpetSettings.onePlayerSleeping)
    {
        allPlayersSleeping = false;
        for (ServerPlayerEntity p : players)
            if (!p.isSpectator() && p.isSleeping())
            {
                allPlayersSleeping = true;
                ci.cancel();
                return;
            }
        ci.cancel();
    }
}
 
Example #17
Source File: CarpetEventServer.java    From fabric-carpet with MIT License 5 votes vote down vote up
@Override
public void onBlockAction(ServerPlayerEntity player, BlockPos blockpos, Direction facing)
{
    handler.call( () ->
    {
        return Arrays.asList(
                ((c, t) -> new EntityValue(player)),
                ((c, t) -> new BlockValue(null, player.getServerWorld(), blockpos)),
                ((c, t) -> new StringValue(facing.getName()))
        );
    }, player::getCommandSource);
}
 
Example #18
Source File: CarpetEventServer.java    From fabric-carpet with MIT License 5 votes vote down vote up
@Override
public void onMountControls(ServerPlayerEntity player, float strafeSpeed, float forwardSpeed, boolean jumping, boolean sneaking)
{
    handler.call( () -> Arrays.asList(
            ((c, t) -> new EntityValue(player)),
            ((c, t) -> new NumericValue(forwardSpeed)),
            ((c, t) -> new NumericValue(strafeSpeed)),
            ((c, t) -> new NumericValue(jumping)),
            ((c, t) -> new NumericValue(sneaking))
    ), player::getCommandSource);
}
 
Example #19
Source File: BlockItem_scarpetEventMixin.java    From fabric-carpet with MIT License 5 votes vote down vote up
@Inject(method = "place(Lnet/minecraft/item/ItemPlacementContext;)Lnet/minecraft/util/ActionResult;", at = @At(
        value = "INVOKE",
        target = "Lnet/minecraft/block/Block;onPlaced(Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;Lnet/minecraft/entity/LivingEntity;Lnet/minecraft/item/ItemStack;)V",
        shift = At.Shift.AFTER
))
private void afterPlacement(ItemPlacementContext context, CallbackInfoReturnable<ActionResult> cir)
{
    if (context.getPlayer() instanceof ServerPlayerEntity && PLAYER_PLACES_BLOCK.isNeeded())
        PLAYER_PLACES_BLOCK.onBlockPlaced((ServerPlayerEntity) context.getPlayer(), context.getBlockPos(), context.getHand(), context.getStack());
}
 
Example #20
Source File: CarpetEventServer.java    From fabric-carpet with MIT License 5 votes vote down vote up
@Override
public void onItemAction(ServerPlayerEntity player, Hand enumhand, ItemStack itemstack)
{
    // this.getStackInHand(this.getActiveHand()), this.activeItemStack)
    handler.call( () ->
    {
        return Arrays.asList(
                ((c, t) -> new EntityValue(player)),
                ((c, t) -> ListValue.fromItemStack(itemstack)),
                ((c, t) -> new StringValue(enumhand == Hand.MAIN_HAND ? "mainhand" : "offhand"))
        );
    }, player::getCommandSource);
}
 
Example #21
Source File: CarpetEventServer.java    From fabric-carpet with MIT License 5 votes vote down vote up
@Override
public void onItemAction(ServerPlayerEntity player, Hand enumhand, ItemStack itemstack)
{
    // this.getStackInHand(this.getActiveHand()), this.activeItemStack)
    handler.call( () ->
    {
        return Arrays.asList(
                ((c, t) -> new EntityValue(player)),
                ((c, t) -> ListValue.fromItemStack(itemstack)),
                ((c, t) -> new StringValue(enumhand == Hand.MAIN_HAND ? "mainhand" : "offhand"))
        );
    }, player::getCommandSource);
}
 
Example #22
Source File: CarpetEventServer.java    From fabric-carpet with MIT License 5 votes vote down vote up
@Override
public void onRecipeSelected(ServerPlayerEntity player, Identifier recipe, boolean fullStack)
{
    handler.call( () ->
    {
        return Arrays.asList(
                ((c, t) -> new EntityValue(player)),
                ((c, t) -> new StringValue(NBTSerializableValue.nameFromRegistryId(recipe))),
                ((c, t) -> new NumericValue(fullStack))
        );
    }, player::getCommandSource);
}
 
Example #23
Source File: CarpetEventServer.java    From fabric-carpet with MIT License 5 votes vote down vote up
@Override
public void onPlayerMessage(ServerPlayerEntity player, String message)
{
    handler.call( () -> Arrays.asList(
            ((c, t) -> new EntityValue(player)),
            ((c, t) -> new StringValue(message))
    ), player::getCommandSource);
}
 
Example #24
Source File: CarpetEventServer.java    From fabric-carpet with MIT License 5 votes vote down vote up
@Override
public void onPlayerStatistic(ServerPlayerEntity player, Stat<?> stat, int amount)
{
    Identifier id = getStatId(stat);
    if (skippedStats.contains(id)) return;
    handler.call( () -> Arrays.asList(
            ((c, t) -> new EntityValue(player)),
            ((c, t) -> new StringValue(NBTSerializableValue.nameFromRegistryId(Registry.STAT_TYPE.getId(stat.getType())))),
            ((c, t) -> new StringValue(NBTSerializableValue.nameFromRegistryId(id))),
            ((c, t) -> new NumericValue(amount))
    ), player::getCommandSource);
}
 
Example #25
Source File: CameraModeCommand.java    From fabric-carpet with MIT License 5 votes vote down vote up
private static int cameraMode(ServerCommandSource source, ServerPlayerEntity player)
{
    if (!(iCanHasPermissions(source, player))) return 0;
    player.setGameMode(GameMode.SPECTATOR);
    player.addVelocity(0,0.1,0);
    player.networkHandler.sendPacket(new EntityVelocityUpdateS2CPacket(player));
    player.addStatusEffect(new StatusEffectInstance(StatusEffects.NIGHT_VISION, 999999, 0, false, false));
    player.addStatusEffect(new StatusEffectInstance(StatusEffects.CONDUIT_POWER, 999999, 0, false, false));
    return 1;
}
 
Example #26
Source File: ParticleDisplay.java    From fabric-carpet with MIT License 5 votes vote down vote up
public static void drawParticleLine(ServerPlayerEntity player, Vec3d from, Vec3d to, String main, String accent, int count, double spread)
{
    ParticleEffect accentParticle = getEffect(accent);
    ParticleEffect mainParticle = getEffect(main);

    if (accentParticle != null) ((ServerWorld)player.world).spawnParticles(
            player,
            accentParticle,
            true,
            to.x, to.y, to.z, count,
            spread, spread, spread, 0.0);

    double lineLengthSq = from.squaredDistanceTo(to);
    if (lineLengthSq == 0) return;

    Vec3d incvec = to.subtract(from).normalize();//    multiply(50/sqrt(lineLengthSq));
    int pcount = 0;
    for (Vec3d delta = new Vec3d(0.0,0.0,0.0);
         delta.lengthSquared()<lineLengthSq;
         delta = delta.add(incvec.multiply(player.world.random.nextFloat())))
    {
        ((ServerWorld)player.world).spawnParticles(
                player,
                mainParticle,
                true,
                delta.x+from.x, delta.y+from.y, delta.z+from.z, 1,
                0.0, 0.0, 0.0, 0.0);
    }
}
 
Example #27
Source File: EntityPlayerActionPack.java    From fabric-carpet with MIT License 5 votes vote down vote up
@Override
boolean execute(ServerPlayerEntity player, Action action)
{
    if (action.limit == 1)
    {
        if (player.onGround) player.jump();
    }
    else
    {
        player.setJumping(true);
    }
    return false;
}
 
Example #28
Source File: PlayerCommand.java    From fabric-carpet with MIT License 5 votes vote down vote up
private static int manipulate(CommandContext<ServerCommandSource> context, Consumer<EntityPlayerActionPack> action)
{
    if (cantManipulate(context)) return 0;
    ServerPlayerEntity player = getPlayer(context);
    action.accept(((ServerPlayerEntityInterface) player).getActionPack());
    return 1;
}
 
Example #29
Source File: EntityPlayerActionPack.java    From fabric-carpet with MIT License 5 votes vote down vote up
@Override
boolean execute(ServerPlayerEntity player, Action action)
{
    player.updateLastActionTime();
    player.dropSelectedItem(false);
    return false;
}
 
Example #30
Source File: PingCommand.java    From carpet-extra with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static void register(CommandDispatcher<ServerCommandSource> dispatcher)
{
    LiteralArgumentBuilder<ServerCommandSource> command = literal("ping").
            requires( (player) -> CarpetExtraSettings.commandPing).
                    executes( c ->
                    {
                        ServerPlayerEntity playerEntity = c.getSource().getPlayer();
                        int ping = playerEntity.pingMilliseconds;
                        playerEntity.sendMessage(new LiteralText("Your ping is: " + ping + " ms"));
                        return 1;
                    });
    
    dispatcher.register(command);
}