use of net.minecraft.network.play.server.SPacketPlayerAbilities in project SpongeCommon by SpongePowered.
the class MixinPlayerList method initializeConnectionToPlayer.
public void initializeConnectionToPlayer(NetworkManager netManager, EntityPlayerMP playerIn, @Nullable NetHandlerPlayServer handler) {
GameProfile gameprofile = playerIn.getGameProfile();
PlayerProfileCache playerprofilecache = this.mcServer.getPlayerProfileCache();
GameProfile gameprofile1 = playerprofilecache.getProfileByUUID(gameprofile.getId());
String s = gameprofile1 == null ? gameprofile.getName() : gameprofile1.getName();
playerprofilecache.addEntry(gameprofile);
// Sponge start - save changes to offline User before reading player data
SpongeUser user = (SpongeUser) ((IMixinEntityPlayerMP) playerIn).getUserObject();
if (SpongeUser.dirtyUsers.contains(user)) {
user.save();
}
// Sponge end
NBTTagCompound nbttagcompound = this.readPlayerDataFromFile(playerIn);
WorldServer worldServer = this.mcServer.getWorld(playerIn.dimension);
int actualDimensionId = ((IMixinWorldServer) worldServer).getDimensionId();
BlockPos spawnPos = null;
// Join data
Optional<Instant> firstJoined = SpongePlayerDataHandler.getFirstJoined(playerIn.getUniqueID());
Instant lastJoined = Instant.now();
SpongePlayerDataHandler.setPlayerInfo(playerIn.getUniqueID(), firstJoined.orElse(lastJoined), lastJoined);
if (actualDimensionId != playerIn.dimension) {
SpongeImpl.getLogger().warn("Player [{}] has attempted to login to unloaded world [{}]. This is not safe so we have moved them to " + "the default world's spawn point.", playerIn.getName(), playerIn.dimension);
if (!firstJoined.isPresent()) {
spawnPos = SpongeImplHooks.getRandomizedSpawnPoint(worldServer);
} else {
spawnPos = worldServer.getSpawnPoint();
}
playerIn.dimension = actualDimensionId;
playerIn.setPosition(spawnPos.getX(), spawnPos.getY(), spawnPos.getZ());
}
// Sponge start - fire login event
@Nullable String kickReason = allowUserToConnect(netManager.getRemoteAddress(), gameprofile);
Text disconnectMessage;
if (kickReason != null) {
disconnectMessage = SpongeTexts.fromLegacy(kickReason);
} else {
disconnectMessage = Text.of("You are not allowed to log in to this server.");
}
Player player = (Player) playerIn;
Transform<World> fromTransform = player.getTransform().setExtent((World) worldServer);
Sponge.getCauseStackManager().pushCause(player);
ClientConnectionEvent.Login loginEvent = SpongeEventFactory.createClientConnectionEventLogin(Sponge.getCauseStackManager().getCurrentCause(), fromTransform, fromTransform, (RemoteConnection) netManager, new MessageEvent.MessageFormatter(disconnectMessage), (org.spongepowered.api.profile.GameProfile) gameprofile, player, false);
if (kickReason != null) {
loginEvent.setCancelled(true);
}
if (SpongeImpl.postEvent(loginEvent)) {
Sponge.getCauseStackManager().popCause();
disconnectClient(netManager, loginEvent.isMessageCancelled() ? Optional.empty() : Optional.of(loginEvent.getMessage()), gameprofile);
return;
}
Sponge.getCauseStackManager().popCause();
// Sponge end
worldServer = (WorldServer) loginEvent.getToTransform().getExtent();
double x = loginEvent.getToTransform().getPosition().getX();
double y = loginEvent.getToTransform().getPosition().getY();
double z = loginEvent.getToTransform().getPosition().getZ();
float pitch = (float) loginEvent.getToTransform().getPitch();
float yaw = (float) loginEvent.getToTransform().getYaw();
playerIn.dimension = ((IMixinWorldServer) worldServer).getDimensionId();
playerIn.setWorld(worldServer);
playerIn.interactionManager.setWorld((WorldServer) playerIn.world);
playerIn.setPositionAndRotation(x, y, z, yaw, pitch);
// make sure the chunk is loaded for login
worldServer.getChunkProvider().loadChunk(loginEvent.getToTransform().getLocation().getChunkPosition().getX(), loginEvent.getToTransform().getLocation().getChunkPosition().getZ());
// Sponge end
String s1 = "local";
if (netManager.getRemoteAddress() != null) {
s1 = netManager.getRemoteAddress().toString();
}
final WorldInfo worldinfo = worldServer.getWorldInfo();
final BlockPos spawnBlockPos = worldServer.getSpawnPoint();
this.setPlayerGameTypeBasedOnOther(playerIn, null, worldServer);
// Sponge start
if (handler == null) {
// Create the handler here (so the player's gets set)
handler = new NetHandlerPlayServer(this.mcServer, netManager, playerIn);
}
playerIn.connection = handler;
// Sponge end
// Support vanilla clients logging into custom dimensions
final int dimensionId = WorldManager.getClientDimensionId(playerIn, worldServer);
// Send dimension registration
WorldManager.sendDimensionRegistration(playerIn, worldServer.provider);
handler.sendPacket(new SPacketJoinGame(playerIn.getEntityId(), playerIn.interactionManager.getGameType(), worldinfo.isHardcoreModeEnabled(), dimensionId, worldServer.getDifficulty(), this.getMaxPlayers(), worldinfo.getTerrainType(), worldServer.getGameRules().getBoolean("reducedDebugInfo")));
handler.sendPacket(new SPacketCustomPayload("MC|Brand", (new PacketBuffer(Unpooled.buffer())).writeString(this.getServerInstance().getServerModName())));
handler.sendPacket(new SPacketServerDifficulty(worldinfo.getDifficulty(), worldinfo.isDifficultyLocked()));
handler.sendPacket(new SPacketSpawnPosition(spawnBlockPos));
handler.sendPacket(new SPacketPlayerAbilities(playerIn.capabilities));
handler.sendPacket(new SPacketHeldItemChange(playerIn.inventory.currentItem));
this.updatePermissionLevel(playerIn);
playerIn.getStatFile().markAllDirty();
playerIn.getRecipeBook().init(playerIn);
this.mcServer.refreshStatusNextTick();
handler.setPlayerLocation(x, y, z, yaw, pitch);
this.playerLoggedIn(playerIn);
// Sponge start - add world name to message
LOGGER.info(playerIn.getName() + "[" + s1 + "] logged in with entity id " + playerIn.getEntityId() + " in " + worldServer.getWorldInfo().getWorldName() + "(" + ((IMixinWorldServer) worldServer).getDimensionId() + ") at (" + playerIn.posX + ", " + playerIn.posY + ", " + playerIn.posZ + ")");
// Sponge end
this.updateTimeAndWeatherForPlayer(playerIn, worldServer);
// Sponge Start - Use the server's ResourcePack object
Optional<ResourcePack> pack = ((Server) this.mcServer).getDefaultResourcePack();
if (pack.isPresent()) {
((Player) playerIn).sendResourcePack(pack.get());
}
// Sponge End
// Sponge Start
//
// This sends the objective/score creation packets
// to the player, without attempting to remove them from their
// previous scoreboard (which is set in a field initializer).
// This allows #getWorldScoreboard to function
// as normal, without causing issues when it is initialized on the client.
((IMixinEntityPlayerMP) playerIn).initScoreboard();
for (PotionEffect potioneffect : playerIn.getActivePotionEffects()) {
handler.sendPacket(new SPacketEntityEffect(playerIn.getEntityId(), potioneffect));
}
if (nbttagcompound != null) {
if (nbttagcompound.hasKey("RootVehicle", 10)) {
NBTTagCompound nbttagcompound1 = nbttagcompound.getCompoundTag("RootVehicle");
Entity entity2 = AnvilChunkLoader.readWorldEntity(nbttagcompound1.getCompoundTag("Entity"), worldServer, true);
if (entity2 != null) {
UUID uuid = nbttagcompound1.getUniqueId("Attach");
if (entity2.getUniqueID().equals(uuid)) {
playerIn.startRiding(entity2, true);
} else {
for (Entity entity : entity2.getRecursivePassengers()) {
if (entity.getUniqueID().equals(uuid)) {
playerIn.startRiding(entity, true);
break;
}
}
}
if (!playerIn.isRiding()) {
LOGGER.warn("Couldn\'t reattach entity to player");
worldServer.removeEntityDangerously(entity2);
for (Entity entity3 : entity2.getRecursivePassengers()) {
worldServer.removeEntityDangerously(entity3);
}
}
}
} else if (nbttagcompound.hasKey("Riding", 10)) {
Entity entity1 = AnvilChunkLoader.readWorldEntity(nbttagcompound.getCompoundTag("Riding"), worldServer, true);
if (entity1 != null) {
playerIn.startRiding(entity1, true);
}
}
}
playerIn.addSelfToInternalCraftingInventory();
TextComponentTranslation chatcomponenttranslation;
if (!playerIn.getName().equalsIgnoreCase(s)) {
chatcomponenttranslation = new TextComponentTranslation("multiplayer.player.joined.renamed", playerIn.getDisplayName(), s);
} else {
chatcomponenttranslation = new TextComponentTranslation("multiplayer.player.joined", playerIn.getDisplayName());
}
chatcomponenttranslation.getStyle().setColor(TextFormatting.YELLOW);
// Fire PlayerJoinEvent
Text originalMessage = SpongeTexts.toText(chatcomponenttranslation);
MessageChannel originalChannel = player.getMessageChannel();
Sponge.getCauseStackManager().pushCause(player);
final ClientConnectionEvent.Join event = SpongeEventFactory.createClientConnectionEventJoin(Sponge.getCauseStackManager().getCurrentCause(), originalChannel, Optional.of(originalChannel), new MessageEvent.MessageFormatter(originalMessage), player, false);
SpongeImpl.postEvent(event);
Sponge.getCauseStackManager().popCause();
// Send to the channel
if (!event.isMessageCancelled()) {
event.getChannel().ifPresent(channel -> channel.send(player, event.getMessage()));
}
// Sponge end
}
use of net.minecraft.network.play.server.SPacketPlayerAbilities in project MorePlanets by SteveKunG.
the class TeleportUtil method teleportPlayerInternational.
private static EntityPlayer teleportPlayerInternational(EntityPlayerMP player, MinecraftServer server, int sourceDim, int targetDim, double xCoord, double yCoord, double zCoord, float yaw, float pitch) {
WorldServer sourceWorld = server.getWorld(sourceDim);
WorldServer targetWorld = server.getWorld(targetDim);
PlayerList playerList = server.getPlayerList();
player.dimension = targetDim;
player.connection.sendPacket(new SPacketRespawn(player.dimension, targetWorld.getDifficulty(), targetWorld.getWorldInfo().getTerrainType(), player.interactionManager.getGameType()));
playerList.updatePermissionLevel(player);
sourceWorld.removeEntityDangerously(player);
player.isDead = false;
// world transfer
player.setLocationAndAngles(xCoord, yCoord, zCoord, yaw, pitch);
player.connection.setPlayerLocation(xCoord, yCoord, zCoord, yaw, pitch);
targetWorld.spawnEntity(player);
targetWorld.updateEntityWithOptionalForce(player, false);
player.setWorld(targetWorld);
playerList.preparePlayer(player, sourceWorld);
player.connection.setPlayerLocation(xCoord, yCoord, zCoord, yaw, pitch);
player.interactionManager.setWorld(targetWorld);
player.connection.sendPacket(new SPacketPlayerAbilities(player.capabilities));
playerList.updateTimeAndWeatherForPlayer(player, targetWorld);
playerList.syncPlayerInventory(player);
for (PotionEffect potion : player.getActivePotionEffects()) {
player.connection.sendPacket(new SPacketEntityEffect(player.getEntityId(), potion));
}
player.connection.sendPacket(new SPacketSetExperience(player.experience, player.experienceTotal, player.experienceLevel));
FMLCommonHandler.instance().firePlayerChangedDimensionEvent(player, sourceDim, targetDim);
player.setLocationAndAngles(xCoord, yCoord, zCoord, yaw, pitch);
return player;
}
use of net.minecraft.network.play.server.SPacketPlayerAbilities in project Minestuck by mraof.
the class Teleport method teleportEntity.
public static boolean teleportEntity(Entity entity, int destinationDimension, ITeleporter teleporter, double x, double y, double z) {
if (destinationDimension == entity.dimension)
return localTeleport(entity, teleporter, x, y, z);
if (entity.world.isRemote)
throw new IllegalArgumentException("Shouldn't do teleporting with a clientside entity.");
if (!ForgeHooks.onTravelToDimension(entity, destinationDimension))
return false;
MinecraftServer mcServer = entity.getServer();
int prevDimension = entity.dimension;
WorldServer worldFrom = mcServer.getWorld(prevDimension);
WorldServer worldDest = mcServer.getWorld(destinationDimension);
if (entity instanceof EntityPlayerMP) {
PlayerList playerList = mcServer.getPlayerList();
EntityPlayerMP player = (EntityPlayerMP) entity;
try {
setPortalInvincibilityWithReflection(player);
} catch (Exception e) {
Debug.warn("Failed to set portal invincibility through reflection. Portal problems might occur. Problem: " + e.getMessage());
}
player.dimension = destinationDimension;
SPacketRespawn respawnPacket = new SPacketRespawn(player.dimension, player.world.getDifficulty(), worldDest.getWorldInfo().getTerrainType(), player.interactionManager.getGameType());
player.connection.sendPacket(respawnPacket);
playerList.updatePermissionLevel(player);
worldFrom.removeEntityDangerously(player);
player.isDead = false;
player.setPosition(x, y, z);
if (teleporter != null)
teleporter.makeDestination(player, worldFrom, worldDest);
worldDest.spawnEntity(player);
worldDest.updateEntityWithOptionalForce(entity, false);
player.setWorld(worldDest);
playerList.preparePlayer(player, worldFrom);
player.connection.setPlayerLocation(player.posX, player.posY, player.posZ, player.rotationYaw, player.rotationPitch);
player.interactionManager.setWorld(worldDest);
player.connection.sendPacket(new SPacketPlayerAbilities(player.capabilities));
playerList.updateTimeAndWeatherForPlayer(player, worldDest);
playerList.syncPlayerInventory(player);
Iterator<?> iterator = player.getActivePotionEffects().iterator();
while (iterator.hasNext()) {
PotionEffect potioneffect = (PotionEffect) iterator.next();
player.connection.sendPacket(new SPacketEntityEffect(player.getEntityId(), potioneffect));
}
FMLCommonHandler.instance().firePlayerChangedDimensionEvent(player, prevDimension, destinationDimension);
return true;
} else if (!entity.isDead) {
Entity newEntity = EntityList.newEntity(entity.getClass(), worldDest);
if (newEntity == null)
return false;
NBTTagCompound nbt = new NBTTagCompound();
entity.dimension = destinationDimension;
entity.writeToNBT(nbt);
if (teleporter != null)
teleporter.makeDestination(entity, worldFrom, worldDest);
worldDest.updateEntityWithOptionalForce(entity, false);
nbt.removeTag("Dimension");
newEntity.readFromNBT(nbt);
newEntity.timeUntilPortal = entity.timeUntilPortal;
newEntity.setPosition(x, y, z);
boolean flag = newEntity.forceSpawn;
newEntity.forceSpawn = true;
worldDest.spawnEntity(newEntity);
newEntity.forceSpawn = flag;
worldDest.updateEntityWithOptionalForce(newEntity, false);
entity.world.removeEntity(entity);
entity.isDead = true;
worldFrom.resetUpdateEntityTick();
worldDest.resetUpdateEntityTick();
return true;
}
return false;
}
Aggregations