geforkt von Mirrors/Paper
More Teleport API
Dieser Commit ist enthalten in:
Ursprung
4be7165c83
Commit
8cc67f527e
@ -48,7 +48,7 @@
|
||||
import net.minecraft.world.level.GameRules;
|
||||
import net.minecraft.world.level.GameType;
|
||||
import net.minecraft.world.level.Level;
|
||||
@@ -192,12 +196,73 @@
|
||||
@@ -192,11 +196,72 @@
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.phys.AABB;
|
||||
import net.minecraft.world.phys.BlockHitResult;
|
||||
@ -59,7 +59,7 @@
|
||||
import net.minecraft.world.phys.shapes.VoxelShape;
|
||||
+import org.bukkit.NamespacedKey;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
+
|
||||
+// CraftBukkit start
|
||||
+import io.papermc.paper.adventure.ChatProcessor; // Paper
|
||||
+import io.papermc.paper.adventure.PaperAdventure; // Paper
|
||||
@ -118,10 +118,9 @@
|
||||
+import org.bukkit.inventory.InventoryView;
|
||||
+import org.bukkit.inventory.SmithingInventory;
|
||||
+// CraftBukkit end
|
||||
+
|
||||
|
||||
public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl implements ServerGamePacketListener, ServerPlayerConnection, TickablePacketListener {
|
||||
|
||||
static final Logger LOGGER = LogUtils.getLogger();
|
||||
@@ -212,7 +277,9 @@
|
||||
private int tickCount;
|
||||
private int ackBlockChangesUpTo = -1;
|
||||
@ -891,7 +890,7 @@
|
||||
|
||||
return true;
|
||||
} else {
|
||||
@@ -1147,23 +1614,91 @@
|
||||
@@ -1147,23 +1614,98 @@
|
||||
}
|
||||
|
||||
public void teleport(double x, double y, double z, float yaw, float pitch) {
|
||||
@ -921,11 +920,18 @@
|
||||
+ return true; // CraftBukkit - Return event status
|
||||
+ }
|
||||
+
|
||||
+ PlayerTeleportEvent event = new PlayerTeleportEvent(player, from.clone(), to.clone(), cause);
|
||||
+ // Paper start - Teleport API
|
||||
+ final Set<io.papermc.paper.entity.TeleportFlag.Relative> relativeFlags = java.util.EnumSet.noneOf(io.papermc.paper.entity.TeleportFlag.Relative.class);
|
||||
+ for (final Relative relativeArgument : set) {
|
||||
+ final io.papermc.paper.entity.TeleportFlag.Relative flag = org.bukkit.craftbukkit.entity.CraftPlayer.deltaRelativeToAPI(relativeArgument);
|
||||
+ if (flag != null) relativeFlags.add(flag);
|
||||
+ }
|
||||
+ PlayerTeleportEvent event = new PlayerTeleportEvent(player, from.clone(), to.clone(), cause, java.util.Set.copyOf(relativeFlags));
|
||||
+ // Paper end - Teleport API
|
||||
+ this.cserver.getPluginManager().callEvent(event);
|
||||
+
|
||||
+ if (event.isCancelled() || !to.equals(event.getTo())) {
|
||||
+ set = Collections.emptySet(); // Can't relative teleport
|
||||
+ // set = Collections.emptySet(); // Can't relative teleport // Paper - Teleport API; Now you can!
|
||||
+ to = event.isCancelled() ? event.getFrom() : event.getTo();
|
||||
+ positionmoverotation = new PositionMoveRotation(CraftLocation.toVec3D(to), Vec3.ZERO, to.getYaw(), to.getPitch());
|
||||
+ }
|
||||
@ -986,7 +992,7 @@
|
||||
if (this.player.hasClientLoaded()) {
|
||||
BlockPos blockposition = packet.getPos();
|
||||
|
||||
@@ -1175,14 +1710,46 @@
|
||||
@@ -1175,14 +1717,46 @@
|
||||
if (!this.player.isSpectator()) {
|
||||
ItemStack itemstack = this.player.getItemInHand(InteractionHand.OFF_HAND);
|
||||
|
||||
@ -1035,7 +1041,7 @@
|
||||
this.player.drop(false);
|
||||
}
|
||||
|
||||
@@ -1199,6 +1766,12 @@
|
||||
@@ -1199,6 +1773,12 @@
|
||||
case START_DESTROY_BLOCK:
|
||||
case ABORT_DESTROY_BLOCK:
|
||||
case STOP_DESTROY_BLOCK:
|
||||
@ -1048,7 +1054,7 @@
|
||||
this.player.gameMode.handleBlockBreakAction(blockposition, packetplayinblockdig_enumplayerdigtype, packet.getDirection(), this.player.level().getMaxY(), packet.getSequence());
|
||||
this.player.connection.ackBlockChangesUpTo(packet.getSequence());
|
||||
return;
|
||||
@@ -1218,9 +1791,31 @@
|
||||
@@ -1218,9 +1798,31 @@
|
||||
}
|
||||
}
|
||||
|
||||
@ -1080,7 +1086,7 @@
|
||||
if (this.player.hasClientLoaded()) {
|
||||
this.player.connection.ackBlockChangesUpTo(packet.getSequence());
|
||||
ServerLevel worldserver = this.player.serverLevel();
|
||||
@@ -1230,6 +1825,11 @@
|
||||
@@ -1230,6 +1832,11 @@
|
||||
if (itemstack.isItemEnabled(worldserver.enabledFeatures())) {
|
||||
BlockHitResult movingobjectpositionblock = packet.getHitResult();
|
||||
Vec3 vec3d = movingobjectpositionblock.getLocation();
|
||||
@ -1092,7 +1098,7 @@
|
||||
BlockPos blockposition = movingobjectpositionblock.getBlockPos();
|
||||
|
||||
if (this.player.canInteractWithBlock(blockposition, 1.0D)) {
|
||||
@@ -1243,7 +1843,8 @@
|
||||
@@ -1243,7 +1850,8 @@
|
||||
int i = this.player.level().getMaxY();
|
||||
|
||||
if (blockposition.getY() <= i) {
|
||||
@ -1102,7 +1108,7 @@
|
||||
InteractionResult enuminteractionresult = this.player.gameMode.useItemOn(this.player, worldserver, itemstack, enumhand, movingobjectpositionblock);
|
||||
|
||||
if (enuminteractionresult.consumesAction()) {
|
||||
@@ -1257,7 +1858,7 @@
|
||||
@@ -1257,7 +1865,7 @@
|
||||
} else if (enuminteractionresult instanceof InteractionResult.Success) {
|
||||
InteractionResult.Success enuminteractionresult_d = (InteractionResult.Success) enuminteractionresult;
|
||||
|
||||
@ -1111,7 +1117,7 @@
|
||||
this.player.swing(enumhand, true);
|
||||
}
|
||||
}
|
||||
@@ -1281,6 +1882,8 @@
|
||||
@@ -1281,6 +1889,8 @@
|
||||
@Override
|
||||
public void handleUseItem(ServerboundUseItemPacket packet) {
|
||||
PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel());
|
||||
@ -1120,7 +1126,7 @@
|
||||
if (this.player.hasClientLoaded()) {
|
||||
this.ackBlockChangesUpTo(packet.getSequence());
|
||||
ServerLevel worldserver = this.player.serverLevel();
|
||||
@@ -1294,8 +1897,49 @@
|
||||
@@ -1294,8 +1904,49 @@
|
||||
|
||||
if (f1 != this.player.getXRot() || f != this.player.getYRot()) {
|
||||
this.player.absRotateTo(f, f1);
|
||||
@ -1170,7 +1176,7 @@
|
||||
InteractionResult enuminteractionresult = this.player.gameMode.useItem(this.player, worldserver, itemstack, enumhand);
|
||||
|
||||
if (enuminteractionresult instanceof InteractionResult.Success) {
|
||||
@@ -1321,7 +1965,7 @@
|
||||
@@ -1321,7 +1972,7 @@
|
||||
Entity entity = packet.getEntity(worldserver);
|
||||
|
||||
if (entity != null) {
|
||||
@ -1179,7 +1185,7 @@
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -1342,17 +1986,46 @@
|
||||
@@ -1342,17 +1993,46 @@
|
||||
|
||||
@Override
|
||||
public void onDisconnect(DisconnectionDetails info) {
|
||||
@ -1230,7 +1236,7 @@
|
||||
this.player.getTextFilter().leave();
|
||||
}
|
||||
|
||||
@@ -1367,7 +2040,17 @@
|
||||
@@ -1367,7 +2047,17 @@
|
||||
@Override
|
||||
public void handleSetCarriedItem(ServerboundSetCarriedItemPacket packet) {
|
||||
PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel());
|
||||
@ -1248,7 +1254,7 @@
|
||||
if (this.player.getInventory().selected != packet.getSlot() && this.player.getUsedItemHand() == InteractionHand.MAIN_HAND) {
|
||||
this.player.stopUsingItem();
|
||||
}
|
||||
@@ -1376,11 +2059,18 @@
|
||||
@@ -1376,11 +2066,18 @@
|
||||
this.player.resetLastActionTime();
|
||||
} else {
|
||||
ServerGamePacketListenerImpl.LOGGER.warn("{} tried to set an invalid carried item", this.player.getName().getString());
|
||||
@ -1267,7 +1273,7 @@
|
||||
Optional<LastSeenMessages> optional = this.unpackAndApplyLastSeen(packet.lastSeenMessages());
|
||||
|
||||
if (!optional.isEmpty()) {
|
||||
@@ -1394,27 +2084,44 @@
|
||||
@@ -1394,27 +2091,44 @@
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1319,7 +1325,7 @@
|
||||
ParseResults<CommandSourceStack> parseresults = this.parseCommand(command);
|
||||
|
||||
if (this.server.enforceSecureProfile() && SignableCommand.hasSignableArguments(parseresults)) {
|
||||
@@ -1431,19 +2138,37 @@
|
||||
@@ -1431,19 +2145,37 @@
|
||||
|
||||
if (!optional.isEmpty()) {
|
||||
this.tryHandleChat(packet.command(), () -> {
|
||||
@ -1361,7 +1367,7 @@
|
||||
} catch (SignedMessageChain.DecodeException signedmessagechain_a) {
|
||||
this.handleMessageDecodeFailure(signedmessagechain_a);
|
||||
return;
|
||||
@@ -1451,10 +2176,10 @@
|
||||
@@ -1451,10 +2183,10 @@
|
||||
|
||||
CommandSigningContext.SignedArguments commandsigningcontext_a = new CommandSigningContext.SignedArguments(map);
|
||||
|
||||
@ -1374,7 +1380,7 @@
|
||||
}
|
||||
|
||||
private void handleMessageDecodeFailure(SignedMessageChain.DecodeException exception) {
|
||||
@@ -1530,14 +2255,20 @@
|
||||
@@ -1530,14 +2262,20 @@
|
||||
return com_mojang_brigadier_commanddispatcher.parse(command, this.player.createCommandSourceStack());
|
||||
}
|
||||
|
||||
@ -1400,7 +1406,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1549,7 +2280,7 @@
|
||||
@@ -1549,7 +2287,7 @@
|
||||
|
||||
if (optional.isEmpty()) {
|
||||
ServerGamePacketListenerImpl.LOGGER.warn("Failed to validate message acknowledgements from {}", this.player.getName().getString());
|
||||
@ -1409,7 +1415,7 @@
|
||||
}
|
||||
|
||||
return optional;
|
||||
@@ -1566,6 +2297,127 @@
|
||||
@@ -1566,6 +2304,127 @@
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -1537,7 +1543,7 @@
|
||||
private PlayerChatMessage getSignedMessage(ServerboundChatPacket packet, LastSeenMessages lastSeenMessages) throws SignedMessageChain.DecodeException {
|
||||
SignedMessageBody signedmessagebody = new SignedMessageBody(packet.message(), packet.timeStamp(), packet.salt(), lastSeenMessages);
|
||||
|
||||
@@ -1573,15 +2425,44 @@
|
||||
@@ -1573,15 +2432,44 @@
|
||||
}
|
||||
|
||||
private void broadcastChatMessage(PlayerChatMessage message) {
|
||||
@ -1588,7 +1594,7 @@
|
||||
|
||||
}
|
||||
|
||||
@@ -1592,7 +2473,7 @@
|
||||
@@ -1592,7 +2480,7 @@
|
||||
synchronized (this.lastSeenMessages) {
|
||||
if (!this.lastSeenMessages.applyOffset(packet.offset())) {
|
||||
ServerGamePacketListenerImpl.LOGGER.warn("Failed to validate message acknowledgements from {}", this.player.getName().getString());
|
||||
@ -1597,7 +1603,7 @@
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1601,7 +2482,40 @@
|
||||
@@ -1601,7 +2489,40 @@
|
||||
@Override
|
||||
public void handleAnimate(ServerboundSwingPacket packet) {
|
||||
PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel());
|
||||
@ -1638,7 +1644,7 @@
|
||||
this.player.swing(packet.getHand());
|
||||
}
|
||||
|
||||
@@ -1609,6 +2523,29 @@
|
||||
@@ -1609,6 +2530,29 @@
|
||||
public void handlePlayerCommand(ServerboundPlayerCommandPacket packet) {
|
||||
PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel());
|
||||
if (this.player.hasClientLoaded()) {
|
||||
@ -1668,7 +1674,7 @@
|
||||
this.player.resetLastActionTime();
|
||||
Entity entity;
|
||||
PlayerRideableJumping ijumpable;
|
||||
@@ -1616,6 +2553,11 @@
|
||||
@@ -1616,6 +2560,11 @@
|
||||
switch (packet.getAction()) {
|
||||
case PRESS_SHIFT_KEY:
|
||||
this.player.setShiftKeyDown(true);
|
||||
@ -1680,7 +1686,7 @@
|
||||
break;
|
||||
case RELEASE_SHIFT_KEY:
|
||||
this.player.setShiftKeyDown(false);
|
||||
@@ -1684,13 +2626,19 @@
|
||||
@@ -1684,13 +2633,19 @@
|
||||
}
|
||||
|
||||
if (i > 4096) {
|
||||
@ -1701,7 +1707,7 @@
|
||||
this.send(new ClientboundPlayerChatPacket(message.link().sender(), message.link().index(), message.signature(), message.signedBody().pack(this.messageSignatureCache), message.unsignedContent(), message.filterMask(), params));
|
||||
this.addPendingMessage(message);
|
||||
}
|
||||
@@ -1703,6 +2651,18 @@
|
||||
@@ -1703,6 +2658,18 @@
|
||||
return this.connection.getRemoteAddress();
|
||||
}
|
||||
|
||||
@ -1720,7 +1726,7 @@
|
||||
public void switchToConfig() {
|
||||
this.waitingForSwitchToConfig = true;
|
||||
this.removePlayerFromWorld();
|
||||
@@ -1718,9 +2678,17 @@
|
||||
@@ -1718,9 +2685,17 @@
|
||||
@Override
|
||||
public void handleInteract(ServerboundInteractPacket packet) {
|
||||
PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel());
|
||||
@ -1738,7 +1744,7 @@
|
||||
|
||||
this.player.resetLastActionTime();
|
||||
this.player.setShiftKeyDown(packet.isUsingSecondaryAction());
|
||||
@@ -1733,20 +2701,58 @@
|
||||
@@ -1733,20 +2708,58 @@
|
||||
|
||||
if (this.player.canInteractWithEntity(axisalignedbb, 3.0D)) {
|
||||
packet.dispatch(new ServerboundInteractPacket.Handler() {
|
||||
@ -1801,7 +1807,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1755,19 +2761,20 @@
|
||||
@@ -1755,19 +2768,20 @@
|
||||
|
||||
@Override
|
||||
public void onInteraction(InteractionHand hand) {
|
||||
@ -1825,7 +1831,7 @@
|
||||
label23:
|
||||
{
|
||||
if (entity instanceof AbstractArrow) {
|
||||
@@ -1785,17 +2792,41 @@
|
||||
@@ -1785,17 +2799,41 @@
|
||||
}
|
||||
|
||||
ServerGamePacketListenerImpl.this.player.attack(entity);
|
||||
@ -1868,7 +1874,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1809,7 +2840,7 @@
|
||||
@@ -1809,7 +2847,7 @@
|
||||
case PERFORM_RESPAWN:
|
||||
if (this.player.wonGame) {
|
||||
this.player.wonGame = false;
|
||||
@ -1877,7 +1883,7 @@
|
||||
this.resetPosition();
|
||||
CriteriaTriggers.CHANGED_DIMENSION.trigger(this.player, Level.END, Level.OVERWORLD);
|
||||
} else {
|
||||
@@ -1817,11 +2848,11 @@
|
||||
@@ -1817,11 +2855,11 @@
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1892,7 +1898,7 @@
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -1833,16 +2864,27 @@
|
||||
@@ -1833,16 +2871,27 @@
|
||||
|
||||
@Override
|
||||
public void handleContainerClose(ServerboundContainerClosePacket packet) {
|
||||
@ -1922,7 +1928,7 @@
|
||||
this.player.containerMenu.sendAllDataToRemote();
|
||||
} else if (!this.player.containerMenu.stillValid(this.player)) {
|
||||
ServerGamePacketListenerImpl.LOGGER.debug("Player {} interacted with invalid menu {}", this.player, this.player.containerMenu);
|
||||
@@ -1855,7 +2897,284 @@
|
||||
@@ -1855,7 +2904,284 @@
|
||||
boolean flag = packet.getStateId() != this.player.containerMenu.getStateId();
|
||||
|
||||
this.player.containerMenu.suppressRemoteUpdates();
|
||||
@ -2208,7 +2214,7 @@
|
||||
ObjectIterator objectiterator = Int2ObjectMaps.fastIterable(packet.getChangedSlots()).iterator();
|
||||
|
||||
while (objectiterator.hasNext()) {
|
||||
@@ -1879,6 +3198,14 @@
|
||||
@@ -1879,6 +3205,14 @@
|
||||
|
||||
@Override
|
||||
public void handlePlaceRecipe(ServerboundPlaceRecipePacket packet) {
|
||||
@ -2223,7 +2229,7 @@
|
||||
PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel());
|
||||
this.player.resetLastActionTime();
|
||||
if (!this.player.isSpectator() && this.player.containerMenu.containerId == packet.containerId()) {
|
||||
@@ -1900,9 +3227,43 @@
|
||||
@@ -1900,9 +3234,43 @@
|
||||
ServerGamePacketListenerImpl.LOGGER.debug("Player {} tried to place impossible recipe {}", this.player, recipeholder.id().location());
|
||||
return;
|
||||
}
|
||||
@ -2268,7 +2274,7 @@
|
||||
if (containerrecipebook_a == RecipeBookMenu.PostPlaceAction.PLACE_GHOST_RECIPE) {
|
||||
this.player.connection.send(new ClientboundPlaceGhostRecipePacket(this.player.containerMenu.containerId, craftingmanager_d.display().display()));
|
||||
}
|
||||
@@ -1917,6 +3278,7 @@
|
||||
@@ -1917,6 +3285,7 @@
|
||||
@Override
|
||||
public void handleContainerButtonClick(ServerboundContainerButtonClickPacket packet) {
|
||||
PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel());
|
||||
@ -2276,7 +2282,7 @@
|
||||
this.player.resetLastActionTime();
|
||||
if (this.player.containerMenu.containerId == packet.containerId() && !this.player.isSpectator()) {
|
||||
if (!this.player.containerMenu.stillValid(this.player)) {
|
||||
@@ -1945,6 +3307,43 @@
|
||||
@@ -1945,6 +3314,43 @@
|
||||
|
||||
boolean flag1 = packet.slotNum() >= 1 && packet.slotNum() <= 45;
|
||||
boolean flag2 = itemstack.isEmpty() || itemstack.getCount() <= itemstack.getMaxStackSize();
|
||||
@ -2320,7 +2326,7 @@
|
||||
|
||||
if (flag1 && flag2) {
|
||||
this.player.inventoryMenu.getSlot(packet.slotNum()).setByPlayer(itemstack);
|
||||
@@ -1964,7 +3363,19 @@
|
||||
@@ -1964,7 +3370,19 @@
|
||||
|
||||
@Override
|
||||
public void handleSignUpdate(ServerboundSignUpdatePacket packet) {
|
||||
@ -2341,7 +2347,7 @@
|
||||
|
||||
this.filterTextPacket(list).thenAcceptAsync((list1) -> {
|
||||
this.updateSignText(packet, list1);
|
||||
@@ -1972,6 +3383,7 @@
|
||||
@@ -1972,6 +3390,7 @@
|
||||
}
|
||||
|
||||
private void updateSignText(ServerboundSignUpdatePacket packet, List<FilteredText> signText) {
|
||||
@ -2349,7 +2355,7 @@
|
||||
this.player.resetLastActionTime();
|
||||
ServerLevel worldserver = this.player.serverLevel();
|
||||
BlockPos blockposition = packet.getPos();
|
||||
@@ -1993,15 +3405,33 @@
|
||||
@@ -1993,15 +3412,33 @@
|
||||
@Override
|
||||
public void handlePlayerAbilities(ServerboundPlayerAbilitiesPacket packet) {
|
||||
PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel());
|
||||
@ -2384,7 +2390,7 @@
|
||||
if (this.player.isModelPartShown(PlayerModelPart.HAT) != flag) {
|
||||
this.server.getPlayerList().broadcastAll(new ClientboundPlayerInfoUpdatePacket(ClientboundPlayerInfoUpdatePacket.Action.UPDATE_HAT, this.player));
|
||||
}
|
||||
@@ -2012,7 +3442,7 @@
|
||||
@@ -2012,7 +3449,7 @@
|
||||
public void handleChangeDifficulty(ServerboundChangeDifficultyPacket packet) {
|
||||
PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel());
|
||||
if (this.player.hasPermissions(2) || this.isSingleplayerOwner()) {
|
||||
@ -2393,7 +2399,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2033,7 +3463,7 @@
|
||||
@@ -2033,7 +3470,7 @@
|
||||
|
||||
if (!Objects.equals(profilepublickey_a, profilepublickey_a1)) {
|
||||
if (profilepublickey_a != null && profilepublickey_a1.expiresAt().isBefore(profilepublickey_a.expiresAt())) {
|
||||
@ -2402,7 +2408,7 @@
|
||||
} else {
|
||||
try {
|
||||
SignatureValidator signaturevalidator = this.server.getProfileKeySignatureValidator();
|
||||
@@ -2046,7 +3476,7 @@
|
||||
@@ -2046,7 +3483,7 @@
|
||||
this.resetPlayerChatState(remotechatsession_a.validate(this.player.getGameProfile(), signaturevalidator));
|
||||
} catch (ProfilePublicKey.ValidationException profilepublickey_b) {
|
||||
ServerGamePacketListenerImpl.LOGGER.error("Failed to validate profile key: {}", profilepublickey_b.getMessage());
|
||||
@ -2411,7 +2417,7 @@
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2058,7 +3488,7 @@
|
||||
@@ -2058,7 +3495,7 @@
|
||||
if (!this.waitingForSwitchToConfig) {
|
||||
throw new IllegalStateException("Client acknowledged config, but none was requested");
|
||||
} else {
|
||||
@ -2420,7 +2426,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2083,8 +3513,10 @@
|
||||
@@ -2083,8 +3520,10 @@
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -222,15 +222,36 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
|
||||
|
||||
@Override
|
||||
public boolean teleport(Location location, TeleportCause cause) {
|
||||
// Paper start - Teleport passenger API
|
||||
return teleport(location, cause, new io.papermc.paper.entity.TeleportFlag[0]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean teleport(Location location, TeleportCause cause, io.papermc.paper.entity.TeleportFlag... flags) {
|
||||
// Paper end
|
||||
Preconditions.checkArgument(location != null, "location cannot be null");
|
||||
location.checkFinite();
|
||||
// Paper start - Teleport passenger API
|
||||
Set<io.papermc.paper.entity.TeleportFlag> flagSet = Set.of(flags);
|
||||
boolean dismount = !flagSet.contains(io.papermc.paper.entity.TeleportFlag.EntityState.RETAIN_VEHICLE);
|
||||
boolean ignorePassengers = flagSet.contains(io.papermc.paper.entity.TeleportFlag.EntityState.RETAIN_PASSENGERS);
|
||||
// Don't allow teleporting between worlds while keeping passengers
|
||||
if (flagSet.contains(io.papermc.paper.entity.TeleportFlag.EntityState.RETAIN_PASSENGERS) && this.entity.isVehicle() && location.getWorld() != this.getWorld()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.entity.isVehicle() || this.entity.isRemoved()) {
|
||||
// Don't allow to teleport between worlds if remaining on vehicle
|
||||
if (!dismount && this.entity.isPassenger() && location.getWorld() != this.getWorld()) {
|
||||
return false;
|
||||
}
|
||||
// Paper end
|
||||
|
||||
if ((!ignorePassengers && this.entity.isVehicle()) || this.entity.isRemoved()) { // Paper - Teleport passenger API
|
||||
return false;
|
||||
}
|
||||
|
||||
// If this entity is riding another entity, we must dismount before teleporting.
|
||||
this.entity.stopRiding();
|
||||
if (dismount) this.entity.stopRiding(); // Paper - Teleport passenger API
|
||||
|
||||
// Let the server handle cross world teleports
|
||||
if (location.getWorld() != null && !location.getWorld().equals(this.getWorld())) {
|
||||
@ -971,6 +992,39 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
|
||||
return CraftEntity.perm;
|
||||
}
|
||||
|
||||
// Paper start - more teleport API / async chunk API
|
||||
@Override
|
||||
public java.util.concurrent.CompletableFuture<Boolean> teleportAsync(final Location location, final TeleportCause cause, final io.papermc.paper.entity.TeleportFlag... teleportFlags) {
|
||||
Preconditions.checkArgument(location != null, "location");
|
||||
location.checkFinite();
|
||||
Location locationClone = location.clone(); // clone so we don't need to worry about mutations after this call.
|
||||
|
||||
net.minecraft.server.level.ServerLevel world = ((CraftWorld)locationClone.getWorld()).getHandle();
|
||||
java.util.concurrent.CompletableFuture<Boolean> ret = new java.util.concurrent.CompletableFuture<>();
|
||||
|
||||
world.loadChunksForMoveAsync(getHandle().getBoundingBoxAt(locationClone.getX(), locationClone.getY(), locationClone.getZ()),
|
||||
this instanceof CraftPlayer ? ca.spottedleaf.concurrentutil.util.Priority.HIGHER : ca.spottedleaf.concurrentutil.util.Priority.NORMAL, (list) -> {
|
||||
net.minecraft.server.MinecraftServer.getServer().scheduleOnMain(() -> {
|
||||
final net.minecraft.server.level.ServerChunkCache chunkCache = world.getChunkSource();
|
||||
for (final net.minecraft.world.level.chunk.ChunkAccess chunk : list) {
|
||||
chunkCache.addTicketAtLevel(net.minecraft.server.level.TicketType.POST_TELEPORT, chunk.getPos(), 33, CraftEntity.this.getEntityId());
|
||||
}
|
||||
try {
|
||||
ret.complete(CraftEntity.this.teleport(locationClone, cause, teleportFlags) ? Boolean.TRUE : Boolean.FALSE);
|
||||
} catch (Throwable throwable) {
|
||||
if (throwable instanceof ThreadDeath) {
|
||||
throw (ThreadDeath)throwable;
|
||||
}
|
||||
net.minecraft.server.MinecraftServer.LOGGER.error("Failed to teleport entity " + CraftEntity.this, throwable);
|
||||
ret.completeExceptionally(throwable);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
return ret;
|
||||
}
|
||||
// Paper end - more teleport API / async chunk API
|
||||
|
||||
// Spigot start
|
||||
private final org.bukkit.entity.Entity.Spigot spigot = new org.bukkit.entity.Entity.Spigot()
|
||||
{
|
||||
|
@ -1293,13 +1293,94 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
||||
|
||||
@Override
|
||||
public void setRotation(float yaw, float pitch) {
|
||||
throw new UnsupportedOperationException("Cannot set rotation of players. Consider teleporting instead.");
|
||||
// Paper start - Teleport API
|
||||
if (this.getHandle().connection == null) return;
|
||||
this.getHandle().forceSetRotation(yaw, pitch);
|
||||
// Paper end - Teleportation API
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean teleport(Location location, PlayerTeleportEvent.TeleportCause cause) {
|
||||
// Paper start - Teleport API
|
||||
return this.teleport(location, cause, new io.papermc.paper.entity.TeleportFlag[0]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void lookAt(@NotNull org.bukkit.entity.Entity entity, @NotNull io.papermc.paper.entity.LookAnchor playerAnchor, @NotNull io.papermc.paper.entity.LookAnchor entityAnchor) {
|
||||
this.getHandle().lookAt(toNmsAnchor(playerAnchor), ((CraftEntity) entity).getHandle(), toNmsAnchor(entityAnchor));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void lookAt(double x, double y, double z, @NotNull io.papermc.paper.entity.LookAnchor playerAnchor) {
|
||||
this.getHandle().lookAt(toNmsAnchor(playerAnchor), new net.minecraft.world.phys.Vec3(x, y, z));
|
||||
}
|
||||
|
||||
public static net.minecraft.commands.arguments.EntityAnchorArgument.Anchor toNmsAnchor(io.papermc.paper.entity.LookAnchor nmsAnchor) {
|
||||
return switch (nmsAnchor) {
|
||||
case EYES -> net.minecraft.commands.arguments.EntityAnchorArgument.Anchor.EYES;
|
||||
case FEET -> net.minecraft.commands.arguments.EntityAnchorArgument.Anchor.FEET;
|
||||
};
|
||||
}
|
||||
|
||||
public static io.papermc.paper.entity.LookAnchor toApiAnchor(net.minecraft.commands.arguments.EntityAnchorArgument.Anchor playerAnchor) {
|
||||
return switch (playerAnchor) {
|
||||
case EYES -> io.papermc.paper.entity.LookAnchor.EYES;
|
||||
case FEET -> io.papermc.paper.entity.LookAnchor.FEET;
|
||||
};
|
||||
}
|
||||
|
||||
public static net.minecraft.world.entity.Relative deltaRelativeToNMS(io.papermc.paper.entity.TeleportFlag.Relative apiFlag) {
|
||||
return switch (apiFlag) {
|
||||
case VELOCITY_X -> net.minecraft.world.entity.Relative.DELTA_X;
|
||||
case VELOCITY_Y -> net.minecraft.world.entity.Relative.DELTA_Y;
|
||||
case VELOCITY_Z -> net.minecraft.world.entity.Relative.DELTA_Z;
|
||||
case VELOCITY_ROTATION -> net.minecraft.world.entity.Relative.ROTATE_DELTA;
|
||||
};
|
||||
}
|
||||
|
||||
public static @org.jetbrains.annotations.Nullable io.papermc.paper.entity.TeleportFlag.Relative deltaRelativeToAPI(net.minecraft.world.entity.Relative nmsFlag) {
|
||||
return switch (nmsFlag) {
|
||||
case DELTA_X -> io.papermc.paper.entity.TeleportFlag.Relative.VELOCITY_X;
|
||||
case DELTA_Y -> io.papermc.paper.entity.TeleportFlag.Relative.VELOCITY_Y;
|
||||
case DELTA_Z -> io.papermc.paper.entity.TeleportFlag.Relative.VELOCITY_Z;
|
||||
case ROTATE_DELTA -> io.papermc.paper.entity.TeleportFlag.Relative.VELOCITY_ROTATION;
|
||||
default -> null;
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean teleport(Location location, org.bukkit.event.player.PlayerTeleportEvent.TeleportCause cause, io.papermc.paper.entity.TeleportFlag... flags) {
|
||||
Set<io.papermc.paper.entity.TeleportFlag.Relative> relativeArguments;
|
||||
Set<io.papermc.paper.entity.TeleportFlag> allFlags;
|
||||
if (flags.length == 0) {
|
||||
relativeArguments = Set.of();
|
||||
allFlags = Set.of();
|
||||
} else {
|
||||
relativeArguments = java.util.EnumSet.noneOf(io.papermc.paper.entity.TeleportFlag.Relative.class);
|
||||
allFlags = new HashSet<>();
|
||||
for (io.papermc.paper.entity.TeleportFlag flag : flags) {
|
||||
if (flag instanceof final io.papermc.paper.entity.TeleportFlag.Relative relativeTeleportFlag) {
|
||||
relativeArguments.add(relativeTeleportFlag);
|
||||
}
|
||||
allFlags.add(flag);
|
||||
}
|
||||
}
|
||||
boolean dismount = !allFlags.contains(io.papermc.paper.entity.TeleportFlag.EntityState.RETAIN_VEHICLE);
|
||||
boolean ignorePassengers = allFlags.contains(io.papermc.paper.entity.TeleportFlag.EntityState.RETAIN_PASSENGERS);
|
||||
// Paper end - Teleport API
|
||||
Preconditions.checkArgument(location != null, "location");
|
||||
Preconditions.checkArgument(location.getWorld() != null, "location.world");
|
||||
// Paper start - Teleport passenger API
|
||||
// Don't allow teleporting between worlds while keeping passengers
|
||||
if (ignorePassengers && entity.isVehicle() && location.getWorld() != this.getWorld()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Don't allow to teleport between worlds if remaining on vehicle
|
||||
if (!dismount && entity.isPassenger() && location.getWorld() != this.getWorld()) {
|
||||
return false;
|
||||
}
|
||||
// Paper end
|
||||
location.checkFinite();
|
||||
|
||||
ServerPlayer entity = this.getHandle();
|
||||
@ -1312,7 +1393,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (entity.isVehicle()) {
|
||||
if (entity.isVehicle() && !ignorePassengers) { // Paper - Teleport API
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -1321,7 +1402,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
||||
// To = Players new Location if Teleport is Successful
|
||||
Location to = location;
|
||||
// Create & Call the Teleport Event.
|
||||
PlayerTeleportEvent event = new PlayerTeleportEvent(this, from, to, cause);
|
||||
PlayerTeleportEvent event = new PlayerTeleportEvent(this, from, to, cause, Set.copyOf(relativeArguments)); // Paper - Teleport API
|
||||
this.server.getPluginManager().callEvent(event);
|
||||
|
||||
// Return False to inform the Plugin that the Teleport was unsuccessful/cancelled.
|
||||
@ -1330,7 +1411,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
||||
}
|
||||
|
||||
// If this player is riding another entity, we must dismount before teleporting.
|
||||
entity.stopRiding();
|
||||
if (dismount) entity.stopRiding(); // Paper - Teleport API
|
||||
|
||||
// SPIGOT-5509: Wakeup, similar to riding
|
||||
if (this.isSleeping()) {
|
||||
@ -1346,13 +1427,21 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
||||
ServerLevel toWorld = ((CraftWorld) to.getWorld()).getHandle();
|
||||
|
||||
// Close any foreign inventory
|
||||
if (this.getHandle().containerMenu != this.getHandle().inventoryMenu) {
|
||||
if (this.getHandle().containerMenu != this.getHandle().inventoryMenu && !allFlags.contains(io.papermc.paper.entity.TeleportFlag.EntityState.RETAIN_OPEN_INVENTORY)) { // Paper
|
||||
this.getHandle().closeContainer(org.bukkit.event.inventory.InventoryCloseEvent.Reason.TELEPORT); // Paper - Inventory close reason
|
||||
}
|
||||
|
||||
// Check if the fromWorld and toWorld are the same.
|
||||
if (fromWorld == toWorld) {
|
||||
entity.connection.teleport(to);
|
||||
// Paper start - Teleport API
|
||||
final Set<net.minecraft.world.entity.Relative> nms = java.util.EnumSet.noneOf(net.minecraft.world.entity.Relative.class);
|
||||
for (final io.papermc.paper.entity.TeleportFlag.Relative bukkit : relativeArguments) {
|
||||
nms.add(deltaRelativeToNMS(bukkit));
|
||||
}
|
||||
entity.connection.internalTeleport(new net.minecraft.world.entity.PositionMoveRotation(
|
||||
io.papermc.paper.util.MCUtil.toVec3(to), net.minecraft.world.phys.Vec3.ZERO, to.getYaw(), to.getPitch()
|
||||
), nms);
|
||||
// Paper end - Teleport API
|
||||
} else {
|
||||
entity.portalProcess = null; // SPIGOT-7785: there is no need to carry this over as it contains the old world/location and we might run into trouble if there is a portal in the same spot in both worlds
|
||||
// The respawn reason should never be used if the passed location is non null.
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren