mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-20 23:46:57 +01:00
#1003: Fix cancellation of TradeSelectEvent
By: pop4959 <pop4959@gmail.com>
This commit is contained in:
parent
f46c4e64ea
commit
2fb7e5202f
1 changed files with 50 additions and 44 deletions
|
@ -344,15 +344,21 @@
|
|||
this.connection.send(new PacketPlayOutTabComplete(packetplayintabcomplete.getId(), suggestions));
|
||||
});
|
||||
}
|
||||
@@ -715,6 +929,7 @@
|
||||
@@ -715,6 +929,13 @@
|
||||
|
||||
if (container instanceof ContainerMerchant) {
|
||||
ContainerMerchant containermerchant = (ContainerMerchant) container;
|
||||
+ CraftEventFactory.callTradeSelectEvent(this.player, i, containermerchant); // CraftBukkit
|
||||
+ // CraftBukkit start
|
||||
+ final org.bukkit.event.inventory.TradeSelectEvent tradeSelectEvent = CraftEventFactory.callTradeSelectEvent(this.player, i, containermerchant);
|
||||
+ if (tradeSelectEvent.isCancelled()) {
|
||||
+ this.player.getBukkitEntity().updateInventory();
|
||||
+ return;
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
|
||||
containermerchant.setSelectionHint(i);
|
||||
containermerchant.tryMoveItems(i);
|
||||
@@ -724,6 +939,13 @@
|
||||
@@ -724,6 +945,13 @@
|
||||
|
||||
@Override
|
||||
public void handleEditBook(PacketPlayInBEdit packetplayinbedit) {
|
||||
|
@ -366,7 +372,7 @@
|
|||
int i = packetplayinbedit.getSlot();
|
||||
|
||||
if (PlayerInventory.isHotbarSlot(i) || i == 40) {
|
||||
@@ -732,7 +954,7 @@
|
||||
@@ -732,7 +960,7 @@
|
||||
|
||||
Objects.requireNonNull(list);
|
||||
optional.ifPresent(list::add);
|
||||
|
@ -375,7 +381,7 @@
|
|||
|
||||
Objects.requireNonNull(list);
|
||||
stream.forEach(list::add);
|
||||
@@ -748,7 +970,7 @@
|
||||
@@ -748,7 +976,7 @@
|
||||
ItemStack itemstack = this.player.getInventory().getItem(i);
|
||||
|
||||
if (itemstack.is(Items.WRITABLE_BOOK)) {
|
||||
|
@ -384,7 +390,7 @@
|
|||
}
|
||||
}
|
||||
|
||||
@@ -773,16 +995,16 @@
|
||||
@@ -773,16 +1001,16 @@
|
||||
|
||||
this.updateBookPages(list, (s) -> {
|
||||
return IChatBaseComponent.ChatSerializer.toJson(new ChatComponentText(s));
|
||||
|
@ -405,7 +411,7 @@
|
|||
return NBTTagString.valueOf((String) unaryoperator.apply(itextfilter_a.getFiltered()));
|
||||
});
|
||||
|
||||
@@ -810,6 +1032,7 @@
|
||||
@@ -810,6 +1038,7 @@
|
||||
}
|
||||
|
||||
itemstack.addTagElement("pages", nbttaglist);
|
||||
|
@ -413,7 +419,7 @@
|
|||
}
|
||||
|
||||
@Override
|
||||
@@ -846,7 +1069,7 @@
|
||||
@@ -846,7 +1075,7 @@
|
||||
} else {
|
||||
WorldServer worldserver = this.player.getLevel();
|
||||
|
||||
|
@ -422,7 +428,7 @@
|
|||
if (this.tickCount == 0) {
|
||||
this.resetPosition();
|
||||
}
|
||||
@@ -856,7 +1079,7 @@
|
||||
@@ -856,7 +1085,7 @@
|
||||
this.awaitingTeleportTime = this.tickCount;
|
||||
this.teleport(this.awaitingPositionFromClient.x, this.awaitingPositionFromClient.y, this.awaitingPositionFromClient.z, this.player.getYRot(), this.player.getXRot());
|
||||
}
|
||||
|
@ -431,7 +437,7 @@
|
|||
} else {
|
||||
this.awaitingTeleportTime = this.tickCount;
|
||||
double d0 = clampHorizontal(packetplayinflying.getX(this.player.getX()));
|
||||
@@ -868,7 +1091,15 @@
|
||||
@@ -868,7 +1097,15 @@
|
||||
if (this.player.isPassenger()) {
|
||||
this.player.absMoveTo(this.player.getX(), this.player.getY(), this.player.getZ(), f, f1);
|
||||
this.player.getLevel().getChunkSource().move(this.player);
|
||||
|
@ -447,7 +453,7 @@
|
|||
double d3 = this.player.getX();
|
||||
double d4 = this.player.getY();
|
||||
double d5 = this.player.getZ();
|
||||
@@ -888,15 +1119,33 @@
|
||||
@@ -888,15 +1125,33 @@
|
||||
++this.receivedMovePacketCount;
|
||||
int i = this.receivedMovePacketCount - this.knownMovePacketCount;
|
||||
|
||||
|
@ -483,7 +489,7 @@
|
|||
PlayerConnection.LOGGER.warn("{} moved too quickly! {},{},{}", this.player.getName().getString(), d7, d8, d9);
|
||||
this.teleport(this.player.getX(), this.player.getY(), this.player.getZ(), this.player.getYRot(), this.player.getXRot());
|
||||
return;
|
||||
@@ -915,6 +1164,7 @@
|
||||
@@ -915,6 +1170,7 @@
|
||||
}
|
||||
|
||||
this.player.move(EnumMoveType.PLAYER, new Vec3D(d7, d8, d9));
|
||||
|
@ -491,7 +497,7 @@
|
|||
double d12 = d8;
|
||||
|
||||
d7 = d0 - this.player.getX();
|
||||
@@ -936,7 +1186,71 @@
|
||||
@@ -936,7 +1192,71 @@
|
||||
if (!this.player.noPhysics && !this.player.isSleeping() && (flag1 && worldserver.noCollision(this.player, axisalignedbb) || this.isPlayerCollidingWithAnythingNew(worldserver, axisalignedbb))) {
|
||||
this.teleport(d3, d4, d5, f, f1);
|
||||
} else {
|
||||
|
@ -564,7 +570,7 @@
|
|||
this.player.getLevel().getChunkSource().move(this.player);
|
||||
this.player.doCheckFallDamage(this.player.getY() - d6, packetplayinflying.isOnGround());
|
||||
this.player.setOnGround(packetplayinflying.isOnGround());
|
||||
@@ -974,19 +1288,80 @@
|
||||
@@ -974,19 +1294,80 @@
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -590,9 +596,8 @@
|
|||
public void teleport(double d0, double d1, double d2, float f, float f1, Set<PacketPlayOutPosition.EnumPlayerTeleportFlags> set) {
|
||||
- this.teleport(d0, d1, d2, f, f1, set, false);
|
||||
+ this.teleport(d0, d1, d2, f, f1, set, PlayerTeleportEvent.TeleportCause.UNKNOWN);
|
||||
}
|
||||
|
||||
- public void teleport(double d0, double d1, double d2, float f, float f1, Set<PacketPlayOutPosition.EnumPlayerTeleportFlags> set, boolean flag) {
|
||||
+ }
|
||||
+
|
||||
+ public void teleport(double d0, double d1, double d2, float f, float f1, Set<PacketPlayOutPosition.EnumPlayerTeleportFlags> set, PlayerTeleportEvent.TeleportCause cause) {
|
||||
+ this.teleport(d0, d1, d2, f, f1, set, false, cause);
|
||||
+ }
|
||||
|
@ -629,8 +634,9 @@
|
|||
+
|
||||
+ this.internalTeleport(d0, d1, d2, f, f1, set, flag);
|
||||
+ return event.isCancelled(); // CraftBukkit - Return event status
|
||||
+ }
|
||||
+
|
||||
}
|
||||
|
||||
- public void teleport(double d0, double d1, double d2, float f, float f1, Set<PacketPlayOutPosition.EnumPlayerTeleportFlags> set, boolean flag) {
|
||||
+ public void teleport(Location dest) {
|
||||
+ internalTeleport(dest.getX(), dest.getY(), dest.getZ(), dest.getYaw(), dest.getPitch(), Collections.<PacketPlayOutPosition.EnumPlayerTeleportFlags>emptySet(), true);
|
||||
+ }
|
||||
|
@ -649,7 +655,7 @@
|
|||
double d3 = set.contains(PacketPlayOutPosition.EnumPlayerTeleportFlags.X) ? this.player.getX() : 0.0D;
|
||||
double d4 = set.contains(PacketPlayOutPosition.EnumPlayerTeleportFlags.Y) ? this.player.getY() : 0.0D;
|
||||
double d5 = set.contains(PacketPlayOutPosition.EnumPlayerTeleportFlags.Z) ? this.player.getZ() : 0.0D;
|
||||
@@ -998,6 +1373,14 @@
|
||||
@@ -998,6 +1379,14 @@
|
||||
this.awaitingTeleport = 0;
|
||||
}
|
||||
|
||||
|
@ -664,7 +670,7 @@
|
|||
this.awaitingTeleportTime = this.tickCount;
|
||||
this.player.absMoveTo(d0, d1, d2, f, f1);
|
||||
this.player.connection.send(new PacketPlayOutPosition(d0 - d3, d1 - d4, d2 - d5, f - f2, f1 - f3, set, this.awaitingTeleport, flag));
|
||||
@@ -1006,6 +1389,7 @@
|
||||
@@ -1006,6 +1395,7 @@
|
||||
@Override
|
||||
public void handlePlayerAction(PacketPlayInBlockDig packetplayinblockdig) {
|
||||
PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinblockdig, this, this.player.getLevel());
|
||||
|
@ -672,7 +678,7 @@
|
|||
BlockPosition blockposition = packetplayinblockdig.getPos();
|
||||
|
||||
this.player.resetLastActionTime();
|
||||
@@ -1016,14 +1400,46 @@
|
||||
@@ -1016,14 +1406,46 @@
|
||||
if (!this.player.isSpectator()) {
|
||||
ItemStack itemstack = this.player.getItemInHand(EnumHand.OFF_HAND);
|
||||
|
||||
|
@ -721,7 +727,7 @@
|
|||
this.player.drop(false);
|
||||
}
|
||||
|
||||
@@ -1060,6 +1476,7 @@
|
||||
@@ -1060,6 +1482,7 @@
|
||||
@Override
|
||||
public void handleUseItemOn(PacketPlayInUseItem packetplayinuseitem) {
|
||||
PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinuseitem, this, this.player.getLevel());
|
||||
|
@ -729,7 +735,7 @@
|
|||
WorldServer worldserver = this.player.getLevel();
|
||||
EnumHand enumhand = packetplayinuseitem.getHand();
|
||||
ItemStack itemstack = this.player.getItemInHand(enumhand);
|
||||
@@ -1072,6 +1489,14 @@
|
||||
@@ -1072,6 +1495,14 @@
|
||||
|
||||
if (blockposition.getY() < i) {
|
||||
if (this.awaitingPositionFromClient == null && this.player.distanceToSqr((double) blockposition.getX() + 0.5D, (double) blockposition.getY() + 0.5D, (double) blockposition.getZ() + 0.5D) < 64.0D && worldserver.mayInteract(this.player, blockposition)) {
|
||||
|
@ -744,7 +750,7 @@
|
|||
EnumInteractionResult enuminteractionresult = this.player.gameMode.useItemOn(this.player, worldserver, itemstack, enumhand, movingobjectpositionblock);
|
||||
|
||||
if (enumdirection == EnumDirection.UP && !enuminteractionresult.consumesAction() && blockposition.getY() >= i - 1 && wasBlockPlacementAttempt(this.player, itemstack)) {
|
||||
@@ -1095,12 +1520,51 @@
|
||||
@@ -1095,12 +1526,51 @@
|
||||
@Override
|
||||
public void handleUseItem(PacketPlayInBlockPlace packetplayinblockplace) {
|
||||
PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinblockplace, this, this.player.getLevel());
|
||||
|
@ -796,7 +802,7 @@
|
|||
EnumInteractionResult enuminteractionresult = this.player.gameMode.useItem(this.player, worldserver, itemstack, enumhand);
|
||||
|
||||
if (enuminteractionresult.shouldSwing()) {
|
||||
@@ -1121,7 +1585,7 @@
|
||||
@@ -1121,7 +1591,7 @@
|
||||
Entity entity = packetplayinspectate.getEntity(worldserver);
|
||||
|
||||
if (entity != null) {
|
||||
|
@ -805,7 +811,7 @@
|
|||
return;
|
||||
}
|
||||
}
|
||||
@@ -1136,6 +1600,7 @@
|
||||
@@ -1136,6 +1606,7 @@
|
||||
PlayerConnection.LOGGER.info("Disconnecting {} due to resource pack rejection", this.player.getName());
|
||||
this.disconnect(new ChatMessage("multiplayer.requiredTexturePrompt.disconnect"));
|
||||
}
|
||||
|
@ -813,7 +819,7 @@
|
|||
|
||||
}
|
||||
|
||||
@@ -1155,11 +1620,26 @@
|
||||
@@ -1155,11 +1626,26 @@
|
||||
|
||||
@Override
|
||||
public void onDisconnect(IChatBaseComponent ichatbasecomponent) {
|
||||
|
@ -841,7 +847,7 @@
|
|||
this.player.getTextFilter().leave();
|
||||
if (this.isSingleplayerOwner()) {
|
||||
PlayerConnection.LOGGER.info("Stopping singleplayer server as player logged out");
|
||||
@@ -1174,6 +1654,15 @@
|
||||
@@ -1174,6 +1660,15 @@
|
||||
}
|
||||
|
||||
public void send(Packet<?> packet, @Nullable GenericFutureListener<? extends Future<? super Void>> genericfuturelistener) {
|
||||
|
@ -857,7 +863,7 @@
|
|||
try {
|
||||
this.connection.send(packet, genericfuturelistener);
|
||||
} catch (Throwable throwable) {
|
||||
@@ -1190,7 +1679,16 @@
|
||||
@@ -1190,7 +1685,16 @@
|
||||
@Override
|
||||
public void handleSetCarriedItem(PacketPlayInHeldItemSlot packetplayinhelditemslot) {
|
||||
PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinhelditemslot, this, this.player.getLevel());
|
||||
|
@ -874,7 +880,7 @@
|
|||
if (this.player.getInventory().selected != packetplayinhelditemslot.getSlot() && this.player.getUsedItemHand() == EnumHand.MAIN_HAND) {
|
||||
this.player.stopUsingItem();
|
||||
}
|
||||
@@ -1199,11 +1697,18 @@
|
||||
@@ -1199,11 +1703,18 @@
|
||||
this.player.resetLastActionTime();
|
||||
} else {
|
||||
PlayerConnection.LOGGER.warn("{} tried to set an invalid carried item", this.player.getName().getString());
|
||||
|
@ -893,7 +899,7 @@
|
|||
String s = StringUtils.normalizeSpace(packetplayinchat.getMessage());
|
||||
|
||||
for (int i = 0; i < s.length(); ++i) {
|
||||
@@ -1217,20 +1722,42 @@
|
||||
@@ -1217,20 +1728,42 @@
|
||||
PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinchat, this, this.player.getLevel());
|
||||
this.handleChat(ITextFilter.a.passThrough(s));
|
||||
} else {
|
||||
|
@ -940,7 +946,7 @@
|
|||
} else {
|
||||
String s1 = itextfilter_a.getFiltered();
|
||||
ChatMessage chatmessage = s1.isEmpty() ? null : new ChatMessage("chat.type.text", new Object[]{this.player.getDisplayName(), s1});
|
||||
@@ -1241,28 +1768,198 @@
|
||||
@@ -1241,28 +1774,198 @@
|
||||
}, ChatMessageType.CHAT, this.player.getUUID());
|
||||
}
|
||||
|
||||
|
@ -1143,7 +1149,7 @@
|
|||
this.player.resetLastActionTime();
|
||||
IJumpable ijumpable;
|
||||
|
||||
@@ -1320,6 +2017,7 @@
|
||||
@@ -1320,6 +2023,7 @@
|
||||
@Override
|
||||
public void handleInteract(PacketPlayInUseEntity packetplayinuseentity) {
|
||||
PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinuseentity, this, this.player.getLevel());
|
||||
|
@ -1151,7 +1157,7 @@
|
|||
WorldServer worldserver = this.player.getLevel();
|
||||
final Entity entity = packetplayinuseentity.getTarget(worldserver);
|
||||
|
||||
@@ -1334,10 +2032,44 @@
|
||||
@@ -1334,10 +2038,44 @@
|
||||
|
||||
if (this.player.distanceToSqr(entity) < 36.0D) {
|
||||
packetplayinuseentity.dispatch(new PacketPlayInUseEntity.c() {
|
||||
|
@ -1197,7 +1203,7 @@
|
|||
if (enuminteractionresult.consumesAction()) {
|
||||
CriterionTriggers.PLAYER_INTERACTED_WITH_ENTITY.trigger(PlayerConnection.this.player, itemstack, entity);
|
||||
if (enuminteractionresult.shouldSwing()) {
|
||||
@@ -1349,20 +2081,27 @@
|
||||
@@ -1349,20 +2087,27 @@
|
||||
|
||||
@Override
|
||||
public void onInteraction(EnumHand enumhand) {
|
||||
|
@ -1228,7 +1234,7 @@
|
|||
} else {
|
||||
PlayerConnection.this.disconnect(new ChatMessage("multiplayer.disconnect.invalid_entity_attacked"));
|
||||
PlayerConnection.LOGGER.warn("Player {} tried to attack an invalid entity", PlayerConnection.this.player.getName().getString());
|
||||
@@ -1407,21 +2146,304 @@
|
||||
@@ -1407,21 +2152,304 @@
|
||||
@Override
|
||||
public void handleContainerClose(PacketPlayInCloseWindow packetplayinclosewindow) {
|
||||
PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinclosewindow, this, this.player.getLevel());
|
||||
|
@ -1536,7 +1542,7 @@
|
|||
ObjectIterator objectiterator = Int2ObjectMaps.fastIterable(packetplayinwindowclick.getChangedSlots()).iterator();
|
||||
|
||||
while (objectiterator.hasNext()) {
|
||||
@@ -1456,6 +2478,7 @@
|
||||
@@ -1456,6 +2484,7 @@
|
||||
@Override
|
||||
public void handleContainerButtonClick(PacketPlayInEnchantItem packetplayinenchantitem) {
|
||||
PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinenchantitem, this, this.player.getLevel());
|
||||
|
@ -1544,7 +1550,7 @@
|
|||
this.player.resetLastActionTime();
|
||||
if (this.player.containerMenu.containerId == packetplayinenchantitem.getContainerId() && !this.player.isSpectator()) {
|
||||
this.player.containerMenu.clickMenuButton(this.player, packetplayinenchantitem.getButtonId());
|
||||
@@ -1483,6 +2506,43 @@
|
||||
@@ -1483,6 +2512,43 @@
|
||||
|
||||
boolean flag1 = packetplayinsetcreativeslot.getSlotNum() >= 1 && packetplayinsetcreativeslot.getSlotNum() <= 45;
|
||||
boolean flag2 = itemstack.isEmpty() || itemstack.getDamageValue() >= 0 && itemstack.getCount() <= 64 && !itemstack.isEmpty();
|
||||
|
@ -1588,7 +1594,7 @@
|
|||
|
||||
if (flag1 && flag2) {
|
||||
this.player.inventoryMenu.getSlot(packetplayinsetcreativeslot.getSlotNum()).set(itemstack);
|
||||
@@ -1505,6 +2565,7 @@
|
||||
@@ -1505,6 +2571,7 @@
|
||||
}
|
||||
|
||||
private void updateSignText(PacketPlayInUpdateSign packetplayinupdatesign, List<ITextFilter.a> list) {
|
||||
|
@ -1596,7 +1602,7 @@
|
|||
this.player.resetLastActionTime();
|
||||
WorldServer worldserver = this.player.getLevel();
|
||||
BlockPosition blockposition = packetplayinupdatesign.getPos();
|
||||
@@ -1521,18 +2582,37 @@
|
||||
@@ -1521,18 +2588,37 @@
|
||||
|
||||
if (!tileentitysign.isEditable() || !this.player.getUUID().equals(tileentitysign.getPlayerWhoMayEdit())) {
|
||||
PlayerConnection.LOGGER.warn("Player {} just tried to change non-editable sign", this.player.getName().getString());
|
||||
|
@ -1636,7 +1642,7 @@
|
|||
|
||||
tileentitysign.setChanged();
|
||||
worldserver.sendBlockUpdated(blockposition, iblockdata, iblockdata, 3);
|
||||
@@ -1542,6 +2622,7 @@
|
||||
@@ -1542,6 +2628,7 @@
|
||||
|
||||
@Override
|
||||
public void handleKeepAlive(PacketPlayInKeepAlive packetplayinkeepalive) {
|
||||
|
@ -1644,7 +1650,7 @@
|
|||
if (this.keepAlivePending && packetplayinkeepalive.getId() == this.keepAliveChallenge) {
|
||||
int i = (int) (SystemUtils.getMillis() - this.keepAliveTime);
|
||||
|
||||
@@ -1556,7 +2637,17 @@
|
||||
@@ -1556,7 +2643,17 @@
|
||||
@Override
|
||||
public void handlePlayerAbilities(PacketPlayInAbilities packetplayinabilities) {
|
||||
PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinabilities, this, this.player.getLevel());
|
||||
|
@ -1663,7 +1669,7 @@
|
|||
}
|
||||
|
||||
@Override
|
||||
@@ -1565,8 +2656,50 @@
|
||||
@@ -1565,8 +2662,50 @@
|
||||
this.player.updateOptions(packetplayinsettings);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue