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