use of io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge in project Arclight by IzzelAliz.
the class ServerWorldMixin method sendParticles.
public <T extends IParticleData> int sendParticles(final ServerPlayerEntity sender, final T t0, final double d0, final double d1, final double d2, final int i, final double d3, final double d4, final double d5, final double d6, final boolean force) {
SSpawnParticlePacket packet = new SSpawnParticlePacket((T) t0, force, d0, d1, d2, (float) d3, (float) d4, (float) d5, (float) d6, i);
int j = 0;
for (ServerPlayerEntity entity : this.players) {
if (sender == null || ((ServerPlayerEntityBridge) entity).bridge$getBukkitEntity().canSee(((ServerPlayerEntityBridge) sender).bridge$getBukkitEntity())) {
if (this.sendPacketWithinDistance(entity, force, d0, d1, d2, packet)) {
++j;
}
}
}
return j;
}
use of io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge in project Arclight by IzzelAliz.
the class ServerPlayNetHandlerMixin method processVehicleMove.
/**
* @author IzzelAliz
* @reason
*/
@Overwrite
public void processVehicleMove(final CMoveVehiclePacket packetplayinvehiclemove) {
PacketThreadUtil.checkThreadAndEnqueue(packetplayinvehiclemove, (ServerPlayNetHandler) (Object) this, this.player.getServerWorld());
if (isMoveVehiclePacketInvalid(packetplayinvehiclemove)) {
this.disconnect(new TranslationTextComponent("multiplayer.disconnect.invalid_vehicle_movement"));
} else {
Entity entity = this.player.getLowestRidingEntity();
if (entity != this.player && entity.getControllingPassenger() == this.player && entity == this.lowestRiddenEnt) {
ServerWorld worldserver = this.player.getServerWorld();
double d0 = entity.posX;
double d2 = entity.posY;
double d3 = entity.posZ;
double d4 = packetplayinvehiclemove.getX();
double d5 = packetplayinvehiclemove.getY();
double d6 = packetplayinvehiclemove.getZ();
float f = packetplayinvehiclemove.getYaw();
float f2 = packetplayinvehiclemove.getPitch();
double d7 = d4 - this.lowestRiddenX;
double d8 = d5 - this.lowestRiddenY;
double d9 = d6 - this.lowestRiddenZ;
double d10 = entity.getMotion().lengthSquared();
double d11 = d7 * d7 + d8 * d8 + d9 * d9;
this.allowedPlayerTicks += (int) (System.currentTimeMillis() / 50L - this.lastTick);
this.allowedPlayerTicks = Math.max(this.allowedPlayerTicks, 1);
this.lastTick = (int) (System.currentTimeMillis() / 50L);
++this.movePacketCounter;
int i = this.movePacketCounter - this.lastMovePacketCounter;
if (i > Math.max(this.allowedPlayerTicks, 5)) {
LOGGER.debug(this.player.getScoreboardName() + " is sending move packets too frequently (" + i + " packets since last tick)");
i = 1;
}
if (d11 > 0.0) {
--this.allowedPlayerTicks;
} else {
this.allowedPlayerTicks = 20;
}
double speed;
if (this.player.abilities.isFlying) {
speed = this.player.abilities.flySpeed * 20.0f;
} else {
speed = this.player.abilities.walkSpeed * 10.0f;
}
speed *= 2.0;
if (d11 - d10 > Math.max(100.0, Math.pow(10.0f * i * speed, 2.0)) && !this.func_217264_d()) {
LOGGER.warn("{} (vehicle of {}) moved too quickly! {},{},{}", entity.getName().getString(), this.player.getName().getString(), d7, d8, d9);
this.netManager.sendPacket(new SMoveVehiclePacket(entity));
return;
}
boolean flag = this.bridge$worldNoCollision(worldserver, entity, entity.getBoundingBox().shrink(0.0625));
d7 = d4 - this.lowestRiddenX1;
d8 = d5 - this.lowestRiddenY1 - 1.0E-6;
d9 = d6 - this.lowestRiddenZ1;
entity.move(MoverType.PLAYER, new Vec3d(d7, d8, d9));
double d12 = d8;
d7 = d4 - entity.posX;
d8 = d5 - entity.posY;
if (d8 > -0.5 || d8 < 0.5) {
d8 = 0.0;
}
d9 = d6 - entity.posZ;
d11 = d7 * d7 + d8 * d8 + d9 * d9;
boolean flag2 = false;
if (d11 > 0.0625) {
flag2 = true;
LOGGER.warn("{} moved wrongly!", entity.getName().getString());
}
entity.setPositionAndRotation(d4, d5, d6, f, f2);
this.player.setPositionAndRotation(d4, d5, d6, this.player.rotationYaw, this.player.rotationPitch);
boolean flag3 = this.bridge$worldNoCollision(worldserver, entity, entity.getBoundingBox().shrink(0.0625));
if (flag && (flag2 || !flag3)) {
entity.setPositionAndRotation(d0, d2, d3, f, f2);
this.player.setPositionAndRotation(d0, d2, d3, this.player.rotationYaw, this.player.rotationPitch);
this.netManager.sendPacket(new SMoveVehiclePacket(entity));
return;
}
Player player = this.getPlayer();
Location from = new Location(player.getWorld(), this.lastPosX, this.lastPosY, this.lastPosZ, this.lastYaw, this.lastPitch);
Location to = player.getLocation().clone();
to.setX(packetplayinvehiclemove.getX());
to.setY(packetplayinvehiclemove.getY());
to.setZ(packetplayinvehiclemove.getZ());
to.setYaw(packetplayinvehiclemove.getYaw());
to.setPitch(packetplayinvehiclemove.getPitch());
double delta = Math.pow(this.lastPosX - to.getX(), 2.0) + Math.pow(this.lastPosY - to.getY(), 2.0) + Math.pow(this.lastPosZ - to.getZ(), 2.0);
float deltaAngle = Math.abs(this.lastYaw - to.getYaw()) + Math.abs(this.lastPitch - to.getPitch());
if ((delta > 0.00390625 || deltaAngle > 10.0f) && !((ServerPlayerEntityBridge) this.player).bridge$isMovementBlocked()) {
this.lastPosX = to.getX();
this.lastPosY = to.getY();
this.lastPosZ = to.getZ();
this.lastYaw = to.getYaw();
this.lastPitch = to.getPitch();
if (from.getX() != Double.MAX_VALUE) {
Location oldTo = to.clone();
PlayerMoveEvent event = new PlayerMoveEvent(player, from, to);
this.server.getPluginManager().callEvent(event);
if (event.isCancelled()) {
this.bridge$teleport(from);
return;
}
if (!oldTo.equals(event.getTo()) && !event.isCancelled()) {
((ServerPlayerEntityBridge) this.player).bridge$getBukkitEntity().teleport(event.getTo(), PlayerTeleportEvent.TeleportCause.PLUGIN);
return;
}
if (!from.equals(this.getPlayer().getLocation()) && this.justTeleported) {
this.justTeleported = false;
return;
}
}
}
this.player.getServerWorld().getChunkProvider().updatePlayerPosition(this.player);
this.player.addMovementStat(this.player.posX - d0, this.player.posY - d2, this.player.posZ - d3);
this.vehicleFloating = (d12 >= -0.03125 && !this.minecraftServer.isFlightAllowed() && !worldserver.checkBlockCollision(entity.getBoundingBox().grow(0.0625).expand(0.0, -0.55, 0.0)));
this.lowestRiddenX1 = entity.posX;
this.lowestRiddenY1 = entity.posY;
this.lowestRiddenZ1 = entity.posZ;
}
}
}
use of io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge in project Arclight by IzzelAliz.
the class ServerPlayNetHandlerMixin method processClickWindow.
/**
* @author IzzelAliz
* @reason
*/
@Overwrite
public void processClickWindow(CClickWindowPacket packet) {
PacketThreadUtil.checkThreadAndEnqueue(packet, (ServerPlayNetHandler) (Object) this, this.player.getServerWorld());
if (((ServerPlayerEntityBridge) this.player).bridge$isMovementBlocked()) {
return;
}
this.player.markPlayerActive();
if (this.player.openContainer.windowId == packet.getWindowId() && this.player.openContainer.getCanCraft(this.player) && this.player.openContainer.canInteractWith(this.player)) {
boolean cancelled = this.player.isSpectator();
if (packet.getSlotId() < -1 && packet.getSlotId() != -999) {
return;
}
InventoryView inventory = ((ContainerBridge) this.player.openContainer).bridge$getBukkitView();
InventoryType.SlotType type = inventory.getSlotType(packet.getSlotId());
org.bukkit.event.inventory.ClickType click = org.bukkit.event.inventory.ClickType.UNKNOWN;
InventoryAction action = InventoryAction.UNKNOWN;
ItemStack itemstack = ItemStack.EMPTY;
switch(packet.getClickType()) {
case PICKUP:
{
if (packet.getUsedButton() == 0) {
click = org.bukkit.event.inventory.ClickType.LEFT;
} else if (packet.getUsedButton() == 1) {
click = org.bukkit.event.inventory.ClickType.RIGHT;
}
if (packet.getUsedButton() != 0 && packet.getUsedButton() != 1) {
break;
}
action = InventoryAction.NOTHING;
if (packet.getSlotId() == -999) {
if (!this.player.inventory.getItemStack().isEmpty()) {
action = ((packet.getUsedButton() == 0) ? InventoryAction.DROP_ALL_CURSOR : InventoryAction.DROP_ONE_CURSOR);
break;
}
break;
} else {
if (packet.getSlotId() < 0) {
action = InventoryAction.NOTHING;
break;
}
Slot slot = this.player.openContainer.getSlot(packet.getSlotId());
if (slot == null) {
break;
}
ItemStack clickedItem = slot.getStack();
ItemStack cursor = this.player.inventory.getItemStack();
if (clickedItem.isEmpty()) {
if (!cursor.isEmpty()) {
action = ((packet.getUsedButton() == 0) ? InventoryAction.PLACE_ALL : InventoryAction.PLACE_ONE);
break;
}
break;
} else {
if (!slot.canTakeStack(this.player)) {
break;
}
if (cursor.isEmpty()) {
action = ((packet.getUsedButton() == 0) ? InventoryAction.PICKUP_ALL : InventoryAction.PICKUP_HALF);
break;
}
if (slot.isItemValid(cursor)) {
if (clickedItem.isItemEqual(cursor) && ItemStack.areItemStackTagsEqual(clickedItem, cursor)) {
int toPlace = (packet.getUsedButton() == 0) ? cursor.getCount() : 1;
toPlace = Math.min(toPlace, clickedItem.getMaxStackSize() - clickedItem.getCount());
toPlace = Math.min(toPlace, slot.inventory.getInventoryStackLimit() - clickedItem.getCount());
if (toPlace == 1) {
action = InventoryAction.PLACE_ONE;
break;
}
if (toPlace == cursor.getCount()) {
action = InventoryAction.PLACE_ALL;
break;
}
if (toPlace < 0) {
action = ((toPlace != -1) ? InventoryAction.PICKUP_SOME : InventoryAction.PICKUP_ONE);
break;
}
if (toPlace != 0) {
action = InventoryAction.PLACE_SOME;
break;
}
break;
} else {
if (cursor.getCount() <= slot.getSlotStackLimit()) {
action = InventoryAction.SWAP_WITH_CURSOR;
break;
}
break;
}
} else {
if (cursor.getItem() == clickedItem.getItem() && ItemStack.areItemStackTagsEqual(cursor, clickedItem) && clickedItem.getCount() >= 0 && clickedItem.getCount() + cursor.getCount() <= cursor.getMaxStackSize()) {
action = InventoryAction.PICKUP_ALL;
break;
}
break;
}
}
}
}
case QUICK_MOVE:
{
if (packet.getUsedButton() == 0) {
click = org.bukkit.event.inventory.ClickType.SHIFT_LEFT;
} else if (packet.getUsedButton() == 1) {
click = org.bukkit.event.inventory.ClickType.SHIFT_RIGHT;
}
if (packet.getUsedButton() != 0 && packet.getUsedButton() != 1) {
break;
}
if (packet.getSlotId() < 0) {
action = InventoryAction.NOTHING;
break;
}
Slot slot = this.player.openContainer.getSlot(packet.getSlotId());
if (slot != null && slot.canTakeStack(this.player) && slot.getHasStack()) {
action = InventoryAction.MOVE_TO_OTHER_INVENTORY;
break;
}
action = InventoryAction.NOTHING;
break;
}
case SWAP:
{
if (packet.getUsedButton() < 0 || packet.getUsedButton() >= 9) {
break;
}
click = org.bukkit.event.inventory.ClickType.NUMBER_KEY;
Slot clickedSlot = this.player.openContainer.getSlot(packet.getSlotId());
if (!clickedSlot.canTakeStack(this.player)) {
action = InventoryAction.NOTHING;
break;
}
ItemStack hotbar = this.player.inventory.getStackInSlot(packet.getUsedButton());
boolean canCleanSwap = hotbar.isEmpty() || (clickedSlot.inventory == this.player.inventory && clickedSlot.isItemValid(hotbar));
if (clickedSlot.getHasStack()) {
if (canCleanSwap) {
action = InventoryAction.HOTBAR_SWAP;
break;
}
action = InventoryAction.HOTBAR_MOVE_AND_READD;
break;
} else {
if (!clickedSlot.getHasStack() && !hotbar.isEmpty() && clickedSlot.isItemValid(hotbar)) {
action = InventoryAction.HOTBAR_SWAP;
break;
}
action = InventoryAction.NOTHING;
break;
}
}
case CLONE:
{
if (packet.getUsedButton() != 2) {
click = org.bukkit.event.inventory.ClickType.UNKNOWN;
action = InventoryAction.UNKNOWN;
break;
}
click = org.bukkit.event.inventory.ClickType.MIDDLE;
if (packet.getSlotId() < 0) {
action = InventoryAction.NOTHING;
break;
}
Slot slot = this.player.openContainer.getSlot(packet.getSlotId());
if (slot != null && slot.getHasStack() && this.player.abilities.isCreativeMode && this.player.inventory.getItemStack().isEmpty()) {
action = InventoryAction.CLONE_STACK;
break;
}
action = InventoryAction.NOTHING;
break;
}
case THROW:
{
if (packet.getSlotId() < 0) {
click = org.bukkit.event.inventory.ClickType.LEFT;
if (packet.getUsedButton() == 1) {
click = org.bukkit.event.inventory.ClickType.RIGHT;
}
action = InventoryAction.NOTHING;
break;
}
if (packet.getUsedButton() == 0) {
click = org.bukkit.event.inventory.ClickType.DROP;
Slot slot = this.player.openContainer.getSlot(packet.getSlotId());
if (slot != null && slot.getHasStack() && slot.canTakeStack(this.player) && !slot.getStack().isEmpty() && slot.getStack().getItem() != Item.getItemFromBlock(Blocks.AIR)) {
action = InventoryAction.DROP_ONE_SLOT;
break;
}
action = InventoryAction.NOTHING;
break;
} else {
if (packet.getUsedButton() != 1) {
break;
}
click = org.bukkit.event.inventory.ClickType.CONTROL_DROP;
Slot slot = this.player.openContainer.getSlot(packet.getSlotId());
if (slot != null && slot.getHasStack() && slot.canTakeStack(this.player) && !slot.getStack().isEmpty() && slot.getStack().getItem() != Item.getItemFromBlock(Blocks.AIR)) {
action = InventoryAction.DROP_ALL_SLOT;
break;
}
action = InventoryAction.NOTHING;
break;
}
}
case QUICK_CRAFT:
{
itemstack = this.player.openContainer.slotClick(packet.getSlotId(), packet.getUsedButton(), packet.getClickType(), this.player);
break;
}
case PICKUP_ALL:
{
click = org.bukkit.event.inventory.ClickType.DOUBLE_CLICK;
action = InventoryAction.NOTHING;
if (packet.getSlotId() < 0 || this.player.inventory.getItemStack().isEmpty()) {
break;
}
ItemStack cursor2 = this.player.inventory.getItemStack();
action = InventoryAction.NOTHING;
if (inventory.getTopInventory().contains(CraftMagicNumbers.getMaterial(cursor2.getItem())) || inventory.getBottomInventory().contains(CraftMagicNumbers.getMaterial(cursor2.getItem()))) {
action = InventoryAction.COLLECT_TO_CURSOR;
break;
}
break;
}
}
if (packet.getClickType() != net.minecraft.inventory.container.ClickType.QUICK_CRAFT) {
InventoryClickEvent event;
if (click == org.bukkit.event.inventory.ClickType.NUMBER_KEY) {
event = new InventoryClickEvent(inventory, type, packet.getSlotId(), click, action, packet.getUsedButton());
} else {
event = new InventoryClickEvent(inventory, type, packet.getSlotId(), click, action);
}
Inventory top = inventory.getTopInventory();
if (packet.getSlotId() == 0 && top instanceof org.bukkit.inventory.CraftingInventory) {
Recipe recipe = ((org.bukkit.inventory.CraftingInventory) top).getRecipe();
if (recipe != null) {
if (click == org.bukkit.event.inventory.ClickType.NUMBER_KEY) {
event = new CraftItemEvent(recipe, inventory, type, packet.getSlotId(), click, action, packet.getUsedButton());
} else {
event = new CraftItemEvent(recipe, inventory, type, packet.getSlotId(), click, action);
}
}
}
event.setCancelled(cancelled);
Container oldContainer = this.player.openContainer;
this.server.getPluginManager().callEvent(event);
if (this.player.openContainer != oldContainer) {
return;
}
switch(event.getResult()) {
case DEFAULT:
case ALLOW:
{
itemstack = this.player.openContainer.slotClick(packet.getSlotId(), packet.getUsedButton(), packet.getClickType(), this.player);
break;
}
case DENY:
{
switch(action) {
case PICKUP_ALL:
case MOVE_TO_OTHER_INVENTORY:
case HOTBAR_MOVE_AND_READD:
case HOTBAR_SWAP:
case COLLECT_TO_CURSOR:
case UNKNOWN:
{
this.player.sendContainerToPlayer(this.player.openContainer);
break;
}
case PICKUP_SOME:
case PICKUP_HALF:
case PICKUP_ONE:
case PLACE_ALL:
case PLACE_SOME:
case PLACE_ONE:
case SWAP_WITH_CURSOR:
{
this.player.connection.sendPacket(new SSetSlotPacket(-1, -1, this.player.inventory.getItemStack()));
this.player.connection.sendPacket(new SSetSlotPacket(this.player.openContainer.windowId, packet.getSlotId(), this.player.openContainer.getSlot(packet.getSlotId()).getStack()));
break;
}
case DROP_ALL_SLOT:
case DROP_ONE_SLOT:
{
this.player.connection.sendPacket(new SSetSlotPacket(this.player.openContainer.windowId, packet.getSlotId(), this.player.openContainer.getSlot(packet.getSlotId()).getStack()));
break;
}
case DROP_ALL_CURSOR:
case DROP_ONE_CURSOR:
case CLONE_STACK:
{
this.player.connection.sendPacket(new SSetSlotPacket(-1, -1, this.player.inventory.getItemStack()));
break;
}
}
return;
}
}
if (event instanceof CraftItemEvent) {
this.player.sendContainerToPlayer(this.player.openContainer);
}
}
if (ItemStack.areItemStacksEqual(packet.getClickedItem(), itemstack)) {
this.player.connection.sendPacket(new SConfirmTransactionPacket(packet.getWindowId(), packet.getActionNumber(), true));
this.player.isChangingQuantityOnly = true;
this.player.openContainer.detectAndSendChanges();
this.player.updateHeldItem();
this.player.isChangingQuantityOnly = false;
} else {
this.pendingTransactions.put(this.player.openContainer.windowId, packet.getActionNumber());
this.player.connection.sendPacket(new SConfirmTransactionPacket(packet.getWindowId(), packet.getActionNumber(), false));
this.player.openContainer.setCanCraft(this.player, false);
NonNullList<ItemStack> nonnulllist1 = NonNullList.create();
for (int j = 0; j < this.player.openContainer.inventorySlots.size(); ++j) {
ItemStack itemstack2 = this.player.openContainer.inventorySlots.get(j).getStack();
nonnulllist1.add(itemstack2.isEmpty() ? ItemStack.EMPTY : itemstack2);
}
this.player.sendAllContents(this.player.openContainer, nonnulllist1);
}
}
}
use of io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge in project Arclight by IzzelAliz.
the class ServerPlayNetHandlerMixin method handleAnimation.
/**
* @author IzzelAliz
* @reason
*/
@Overwrite
public void handleAnimation(CAnimateHandPacket packet) {
PacketThreadUtil.checkThreadAndEnqueue(packet, (ServerPlayNetHandler) (Object) this, this.player.getServerWorld());
if (((ServerPlayerEntityBridge) this.player).bridge$isMovementBlocked()) {
return;
}
this.player.markPlayerActive();
float f1 = this.player.rotationPitch;
float f2 = this.player.rotationYaw;
double d0 = this.player.posX;
double d2 = this.player.posY + this.player.getEyeHeight();
double d3 = this.player.posZ;
Vec3d vec3d = new Vec3d(d0, d2, d3);
float f3 = MathHelper.cos(-f2 * 0.017453292f - 3.1415927f);
float f4 = MathHelper.sin(-f2 * 0.017453292f - 3.1415927f);
float f5 = -MathHelper.cos(-f1 * 0.017453292f);
float f6 = MathHelper.sin(-f1 * 0.017453292f);
float f7 = f4 * f5;
float f8 = f3 * f5;
double d4 = (this.player.interactionManager.getGameType() == GameType.CREATIVE) ? 5.0 : 4.5;
Vec3d vec3d2 = vec3d.add(f7 * d4, f6 * d4, f8 * d4);
RayTraceResult result = this.player.world.rayTraceBlocks(new RayTraceContext(vec3d, vec3d2, RayTraceContext.BlockMode.OUTLINE, RayTraceContext.FluidMode.NONE, this.player));
if (result == null || result.getType() != RayTraceResult.Type.BLOCK) {
CraftEventFactory.callPlayerInteractEvent(this.player, Action.LEFT_CLICK_AIR, this.player.inventory.getCurrentItem(), Hand.MAIN_HAND);
}
PlayerAnimationEvent event = new PlayerAnimationEvent(this.getPlayer());
this.server.getPluginManager().callEvent(event);
if (event.isCancelled()) {
return;
}
this.player.swingArm(packet.getHand());
}
use of io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge in project Arclight by IzzelAliz.
the class PlayerListMixin method moveToWorld.
public ServerPlayerEntity moveToWorld(ServerPlayerEntity playerIn, DimensionType type, boolean flag, Location location, boolean avoidSuffocation) {
if (!net.minecraftforge.common.ForgeHooks.onTravelToDimension(playerIn, type))
return playerIn;
playerIn.stopRiding();
this.players.remove(playerIn);
// this.playersByName.remove(playerIn.getScoreboardName().toLowerCase(Locale.ROOT));
playerIn.getServerWorld().removePlayer(playerIn, true);
BlockPos pos = playerIn.getBedLocation(type);
boolean flag2 = playerIn.isSpawnForced(type);
org.bukkit.World fromWorld = ((ServerPlayerEntityBridge) playerIn).bridge$getBukkitEntity().getWorld();
playerIn.queuedEndExit = false;
playerIn.copyFrom(playerIn, flag);
playerIn.setEntityId(playerIn.getEntityId());
playerIn.setPrimaryHand(playerIn.getPrimaryHand());
for (String s : playerIn.getTags()) {
playerIn.addTag(s);
}
if (location == null) {
boolean isBedSpawn = false;
CraftWorld cworld = (CraftWorld) Bukkit.getServer().getWorld(((ServerPlayerEntityBridge) playerIn).bridge$getSpawnWorld());
if (cworld != null && pos != null) {
Optional<Vec3d> optional = PlayerEntity.checkBedValidRespawnPosition(cworld.getHandle(), pos, flag2);
if (optional.isPresent()) {
Vec3d vec3d = optional.get();
isBedSpawn = true;
location = new Location(cworld, vec3d.x, vec3d.y, vec3d.z);
} else {
this.bridge$setSpawnPoint(playerIn, null, true, playerIn.dimension, false);
playerIn.connection.sendPacket(new SChangeGameStatePacket(0, 0.0f));
}
}
if (location == null) {
cworld = (CraftWorld) Bukkit.getServer().getWorlds().get(0);
pos = ((ServerPlayerEntityBridge) playerIn).bridge$getSpawnPoint(cworld.getHandle());
location = new Location(cworld, pos.getX() + 0.5f, pos.getY() + 0.1f, pos.getZ() + 0.5f);
}
Player respawnPlayer = this.cserver.getPlayer(playerIn);
PlayerRespawnEvent respawnEvent = new PlayerRespawnEvent(respawnPlayer, location, isBedSpawn);
this.cserver.getPluginManager().callEvent(respawnEvent);
if (((ServerPlayNetHandlerBridge) playerIn.connection).bridge$isDisconnected()) {
return playerIn;
}
location = respawnEvent.getRespawnLocation();
if (!flag) {
((ServerPlayerEntityBridge) playerIn).bridge$reset();
}
} else {
location.setWorld(((WorldBridge) this.server.getWorld(type)).bridge$getWorld());
}
ServerWorld serverWorld = ((CraftWorld) location.getWorld()).getHandle();
playerIn.setPositionAndRotation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
playerIn.connection.captureCurrentPosition();
while (avoidSuffocation && !serverWorld.hasNoCollisions(playerIn) && playerIn.getPosY() < 256.0) {
playerIn.setPosition(playerIn.getPosX(), playerIn.getPosY() + 1.0, playerIn.getPosZ());
}
if (fromWorld.getEnvironment() == ((WorldBridge) serverWorld).bridge$getWorld().getEnvironment()) {
playerIn.connection.sendPacket(this.bridge$respawnPacket((serverWorld.dimension.getType().getId() >= 0) ? DimensionType.THE_NETHER : DimensionType.OVERWORLD, serverWorld.getWorldInfo().getSeed(), serverWorld.getWorldInfo().getGenerator(), playerIn.interactionManager.getGameType()));
}
WorldInfo worldInfo = serverWorld.getWorldInfo();
net.minecraftforge.fml.network.NetworkHooks.sendDimensionDataPacket(playerIn.connection.netManager, playerIn);
playerIn.connection.sendPacket(this.bridge$respawnPacket(((DimensionTypeBridge) serverWorld.dimension.getType()).bridge$getType(), serverWorld.getWorldInfo().getSeed(), serverWorld.getWorldInfo().getGenerator(), playerIn.interactionManager.getGameType()));
playerIn.connection.sendPacket(new SUpdateViewDistancePacket(((ServerWorldBridge) serverWorld).bridge$spigotConfig().viewDistance));
playerIn.setWorld(serverWorld);
playerIn.interactionManager.setWorld(serverWorld);
playerIn.revive();
((ServerPlayNetHandlerBridge) playerIn.connection).bridge$teleport(new Location(((WorldBridge) serverWorld).bridge$getWorld(), playerIn.getPosX(), playerIn.getPosY(), playerIn.getPosZ(), playerIn.rotationYaw, playerIn.rotationPitch));
playerIn.setSneaking(false);
BlockPos pos1 = serverWorld.getSpawnPoint();
playerIn.connection.sendPacket(new SSpawnPositionPacket(pos1));
playerIn.connection.sendPacket(new SServerDifficultyPacket(worldInfo.getDifficulty(), worldInfo.isDifficultyLocked()));
playerIn.connection.sendPacket(new SSetExperiencePacket(playerIn.experience, playerIn.experienceTotal, playerIn.experienceLevel));
this.sendWorldInfo(playerIn, serverWorld);
this.updatePermissionLevel(playerIn);
if (!((ServerPlayNetHandlerBridge) playerIn.connection).bridge$isDisconnected()) {
serverWorld.addRespawnedPlayer(playerIn);
this.players.add(playerIn);
// this.playersByName.put(entityplayer2.getScoreboardName().toLowerCase(Locale.ROOT), entityplayer2);
this.uuidToPlayerMap.put(playerIn.getUniqueID(), playerIn);
}
playerIn.setHealth(playerIn.getHealth());
this.sendInventory(playerIn);
playerIn.sendPlayerAbilities();
for (Object o1 : playerIn.getActivePotionEffects()) {
EffectInstance mobEffect = (EffectInstance) o1;
playerIn.connection.sendPacket(new SPlayEntityEffectPacket(playerIn.getEntityId(), mobEffect));
}
playerIn.func_213846_b(((CraftWorld) fromWorld).getHandle());
if (fromWorld != location.getWorld()) {
PlayerChangedWorldEvent event = new PlayerChangedWorldEvent(((ServerPlayerEntityBridge) playerIn).bridge$getBukkitEntity(), fromWorld);
Bukkit.getPluginManager().callEvent(event);
}
if (((ServerPlayNetHandlerBridge) playerIn.connection).bridge$isDisconnected()) {
this.writePlayerData(playerIn);
}
net.minecraftforge.fml.hooks.BasicEventHooks.firePlayerRespawnEvent(playerIn, flag);
return playerIn;
}
Aggregations