Search in sources :

Example 1 with PlayerConnection

use of org.spongepowered.api.network.PlayerConnection in project SpongeCommon by SpongePowered.

the class SpongeMessageHandler method handleRequest.

public static void handleRequest(MessageTrackerDataRequest message, RemoteConnection connection, Platform.Type side) {
    if (!(connection instanceof PlayerConnection)) {
        return;
    }
    Player player = ((PlayerConnection) connection).getPlayer();
    if (!player.hasPermission("sponge.debug.block-tracking")) {
        return;
    }
    EntityPlayerMP sender = (EntityPlayerMP) player;
    BlockPos pos = new BlockPos(message.x, message.y, message.z);
    if (!sender.world.isBlockLoaded(pos)) {
        return;
    }
    String ownerName;
    String notifierName;
    Optional<User> owner = Optional.empty();
    Optional<User> notifier = Optional.empty();
    if (message.type == 0) {
        // block
        IMixinChunk spongeChunk = (IMixinChunk) sender.world.getChunkFromBlockCoords(pos);
        owner = spongeChunk.getBlockOwner(pos);
        notifier = spongeChunk.getBlockNotifier(pos);
    } else if (message.type == 1) {
        // entity
        Entity entity = sender.world.getEntityByID(message.entityId);
        if (entity != null) {
            IMixinEntity spongeEntity = (IMixinEntity) entity;
            owner = spongeEntity.getCreatorUser();
            notifier = spongeEntity.getNotifierUser();
        }
    }
    ownerName = owner.map(User::getName).orElse("");
    notifierName = notifier.map(User::getName).orElse("");
    channel.sendTo(player, new MessageTrackerDataResponse(ownerName, notifierName));
}
Also used : Entity(net.minecraft.entity.Entity) IMixinEntity(org.spongepowered.common.interfaces.entity.IMixinEntity) Player(org.spongepowered.api.entity.living.player.Player) User(org.spongepowered.api.entity.living.player.User) IMixinChunk(org.spongepowered.common.interfaces.IMixinChunk) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) BlockPos(net.minecraft.util.math.BlockPos) IMixinEntity(org.spongepowered.common.interfaces.entity.IMixinEntity) PlayerConnection(org.spongepowered.api.network.PlayerConnection)

Aggregations

Entity (net.minecraft.entity.Entity)1 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)1 BlockPos (net.minecraft.util.math.BlockPos)1 Player (org.spongepowered.api.entity.living.player.Player)1 User (org.spongepowered.api.entity.living.player.User)1 PlayerConnection (org.spongepowered.api.network.PlayerConnection)1 IMixinChunk (org.spongepowered.common.interfaces.IMixinChunk)1 IMixinEntity (org.spongepowered.common.interfaces.entity.IMixinEntity)1