13
0
geforkt von Mirrors/Paper

SPIGOT-6078: Add SmithItemEvent and expand SmithingInventory API

By: Julian van den Berkmortel <julianvdberkmortel@outlook.com>
Dieser Commit ist enthalten in:
CraftBukkit/Spigot 2021-04-18 18:03:23 +10:00
Ursprung 9d052543d0
Commit 8cbaba0a8a
4 geänderte Dateien mit 122 neuen und 56 gelöschten Zeilen

Datei anzeigen

@ -1,6 +1,6 @@
--- a/net/minecraft/server/network/PlayerConnection.java --- a/net/minecraft/server/network/PlayerConnection.java
+++ b/net/minecraft/server/network/PlayerConnection.java +++ b/net/minecraft/server/network/PlayerConnection.java
@@ -158,6 +158,59 @@ @@ -158,6 +158,61 @@
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
@ -36,6 +36,7 @@
+import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.event.inventory.InventoryClickEvent;
+import org.bukkit.event.inventory.InventoryCreativeEvent; +import org.bukkit.event.inventory.InventoryCreativeEvent;
+import org.bukkit.event.inventory.InventoryType.SlotType; +import org.bukkit.event.inventory.InventoryType.SlotType;
+import org.bukkit.event.inventory.SmithItemEvent;
+import org.bukkit.event.player.AsyncPlayerChatEvent; +import org.bukkit.event.player.AsyncPlayerChatEvent;
+import org.bukkit.event.player.PlayerAnimationEvent; +import org.bukkit.event.player.PlayerAnimationEvent;
+import org.bukkit.event.player.PlayerChatEvent; +import org.bukkit.event.player.PlayerChatEvent;
@ -54,13 +55,14 @@
+import org.bukkit.inventory.CraftingInventory; +import org.bukkit.inventory.CraftingInventory;
+import org.bukkit.inventory.EquipmentSlot; +import org.bukkit.inventory.EquipmentSlot;
+import org.bukkit.inventory.InventoryView; +import org.bukkit.inventory.InventoryView;
+import org.bukkit.inventory.SmithingInventory;
+import org.bukkit.util.NumberConversions; +import org.bukkit.util.NumberConversions;
+// CraftBukkit end +// CraftBukkit end
+ +
public class PlayerConnection implements PacketListenerPlayIn { public class PlayerConnection implements PacketListenerPlayIn {
private static final Logger LOGGER = LogManager.getLogger(); private static final Logger LOGGER = LogManager.getLogger();
@@ -168,7 +221,10 @@ @@ -168,7 +223,10 @@
private long lastKeepAlive; private long lastKeepAlive;
private boolean awaitingKeepAlive; private boolean awaitingKeepAlive;
private long h; private long h;
@ -72,7 +74,7 @@
private int j; private int j;
private final Int2ShortMap k = new Int2ShortOpenHashMap(); private final Int2ShortMap k = new Int2ShortOpenHashMap();
private double l; private double l;
@@ -206,8 +262,33 @@ @@ -206,8 +264,33 @@
itextfilter.a(); itextfilter.a();
} }
@ -106,7 +108,7 @@
public void tick() { public void tick() {
this.syncPosition(); this.syncPosition();
this.player.lastX = this.player.locX(); this.player.lastX = this.player.locX();
@@ -255,7 +336,7 @@ @@ -255,7 +338,7 @@
this.minecraftServer.getMethodProfiler().enter("keepAlive"); this.minecraftServer.getMethodProfiler().enter("keepAlive");
long i = SystemUtils.getMonotonicMillis(); long i = SystemUtils.getMonotonicMillis();
@ -115,7 +117,7 @@
if (this.awaitingKeepAlive) { if (this.awaitingKeepAlive) {
this.disconnect(new ChatMessage("disconnect.timeout")); this.disconnect(new ChatMessage("disconnect.timeout"));
} else { } else {
@@ -267,15 +348,21 @@ @@ -267,15 +350,21 @@
} }
this.minecraftServer.getMethodProfiler().exit(); this.minecraftServer.getMethodProfiler().exit();
@ -137,7 +139,7 @@
this.disconnect(new ChatMessage("multiplayer.disconnect.idling")); this.disconnect(new ChatMessage("multiplayer.disconnect.idling"));
} }
@@ -299,16 +386,46 @@ @@ -299,16 +388,46 @@
return this.minecraftServer.a(this.player.getProfile()); return this.minecraftServer.a(this.player.getProfile());
} }
@ -185,7 +187,7 @@
} }
private <T> void a(T t0, Consumer<T> consumer, BiFunction<ITextFilter, T, CompletableFuture<Optional<T>>> bifunction) { private <T> void a(T t0, Consumer<T> consumer, BiFunction<ITextFilter, T, CompletableFuture<Optional<T>>> bifunction) {
@@ -324,7 +441,7 @@ @@ -324,7 +443,7 @@
ITextFilter itextfilter = this.player.Q(); ITextFilter itextfilter = this.player.Q();
if (itextfilter != null) { if (itextfilter != null) {
@ -194,7 +196,7 @@
optional.ifPresent(consumer1); optional.ifPresent(consumer1);
}, iasynctaskhandler); }, iasynctaskhandler);
} else { } else {
@@ -381,7 +498,34 @@ @@ -381,7 +500,34 @@
double d9 = entity.getMot().g(); double d9 = entity.getMot().g();
double d10 = d6 * d6 + d7 * d7 + d8 * d8; double d10 = d6 * d6 + d7 * d7 + d8 * d8;
@ -230,7 +232,7 @@
PlayerConnection.LOGGER.warn("{} (vehicle of {}) moved too quickly! {},{},{}", entity.getDisplayName().getString(), this.player.getDisplayName().getString(), d6, d7, d8); PlayerConnection.LOGGER.warn("{} (vehicle of {}) moved too quickly! {},{},{}", entity.getDisplayName().getString(), this.player.getDisplayName().getString(), d6, d7, d8);
this.networkManager.sendPacket(new PacketPlayOutVehicleMove(entity)); this.networkManager.sendPacket(new PacketPlayOutVehicleMove(entity));
return; return;
@@ -411,14 +555,72 @@ @@ -411,14 +557,72 @@
} }
entity.setLocation(d3, d4, d5, f, f1); entity.setLocation(d3, d4, d5, f, f1);
@ -303,7 +305,7 @@
this.player.getWorldServer().getChunkProvider().movePlayer(this.player); this.player.getWorldServer().getChunkProvider().movePlayer(this.player);
this.player.checkMovement(this.player.locX() - d0, this.player.locY() - d1, this.player.locZ() - d2); this.player.checkMovement(this.player.locX() - d0, this.player.locY() - d1, this.player.locZ() - d2);
this.D = d11 >= -0.03125D && !this.minecraftServer.getAllowFlight() && this.a(entity); this.D = d11 >= -0.03125D && !this.minecraftServer.getAllowFlight() && this.a(entity);
@@ -437,7 +639,7 @@ @@ -437,7 +641,7 @@
@Override @Override
public void a(PacketPlayInTeleportAccept packetplayinteleportaccept) { public void a(PacketPlayInTeleportAccept packetplayinteleportaccept) {
PlayerConnectionUtils.ensureMainThread(packetplayinteleportaccept, this, this.player.getWorldServer()); PlayerConnectionUtils.ensureMainThread(packetplayinteleportaccept, this, this.player.getWorldServer());
@ -312,7 +314,7 @@
this.player.setLocation(this.teleportPos.x, this.teleportPos.y, this.teleportPos.z, this.player.yaw, this.player.pitch); this.player.setLocation(this.teleportPos.x, this.teleportPos.y, this.teleportPos.z, this.player.yaw, this.player.pitch);
this.o = this.teleportPos.x; this.o = this.teleportPos.x;
this.p = this.teleportPos.y; this.p = this.teleportPos.y;
@@ -447,6 +649,7 @@ @@ -447,6 +651,7 @@
} }
this.teleportPos = null; this.teleportPos = null;
@ -320,7 +322,7 @@
} }
} }
@@ -454,7 +657,7 @@ @@ -454,7 +659,7 @@
@Override @Override
public void a(PacketPlayInRecipeDisplayed packetplayinrecipedisplayed) { public void a(PacketPlayInRecipeDisplayed packetplayinrecipedisplayed) {
PlayerConnectionUtils.ensureMainThread(packetplayinrecipedisplayed, this, this.player.getWorldServer()); PlayerConnectionUtils.ensureMainThread(packetplayinrecipedisplayed, this, this.player.getWorldServer());
@ -329,7 +331,7 @@
RecipeBookServer recipebookserver = this.player.getRecipeBook(); RecipeBookServer recipebookserver = this.player.getRecipeBook();
optional.ifPresent(recipebookserver::e); optional.ifPresent(recipebookserver::e);
@@ -483,6 +686,12 @@ @@ -483,6 +688,12 @@
@Override @Override
public void a(PacketPlayInTabComplete packetplayintabcomplete) { public void a(PacketPlayInTabComplete packetplayintabcomplete) {
PlayerConnectionUtils.ensureMainThread(packetplayintabcomplete, this, this.player.getWorldServer()); PlayerConnectionUtils.ensureMainThread(packetplayintabcomplete, this, this.player.getWorldServer());
@ -342,7 +344,7 @@
StringReader stringreader = new StringReader(packetplayintabcomplete.c()); StringReader stringreader = new StringReader(packetplayintabcomplete.c());
if (stringreader.canRead() && stringreader.peek() == '/') { if (stringreader.canRead() && stringreader.peek() == '/') {
@@ -492,6 +701,7 @@ @@ -492,6 +703,7 @@
ParseResults<CommandListenerWrapper> parseresults = this.minecraftServer.getCommandDispatcher().a().parse(stringreader, this.player.getCommandListener()); ParseResults<CommandListenerWrapper> parseresults = this.minecraftServer.getCommandDispatcher().a().parse(stringreader, this.player.getCommandListener());
this.minecraftServer.getCommandDispatcher().a().getCompletionSuggestions(parseresults).thenAccept((suggestions) -> { this.minecraftServer.getCommandDispatcher().a().getCompletionSuggestions(parseresults).thenAccept((suggestions) -> {
@ -350,7 +352,7 @@
this.networkManager.sendPacket(new PacketPlayOutTabComplete(packetplayintabcomplete.b(), suggestions)); this.networkManager.sendPacket(new PacketPlayOutTabComplete(packetplayintabcomplete.b(), suggestions));
}); });
} }
@@ -720,6 +930,7 @@ @@ -720,6 +932,7 @@
if (container instanceof ContainerMerchant) { if (container instanceof ContainerMerchant) {
ContainerMerchant containermerchant = (ContainerMerchant) container; ContainerMerchant containermerchant = (ContainerMerchant) container;
@ -358,7 +360,7 @@
containermerchant.d(i); containermerchant.d(i);
containermerchant.g(i); containermerchant.g(i);
@@ -729,6 +940,13 @@ @@ -729,6 +942,13 @@
@Override @Override
public void a(PacketPlayInBEdit packetplayinbedit) { public void a(PacketPlayInBEdit packetplayinbedit) {
@ -372,7 +374,7 @@
ItemStack itemstack = packetplayinbedit.b(); ItemStack itemstack = packetplayinbedit.b();
if (itemstack.getItem() == Items.WRITABLE_BOOK) { if (itemstack.getItem() == Items.WRITABLE_BOOK) {
@@ -744,13 +962,15 @@ @@ -744,13 +964,15 @@
NBTTagList nbttaglist = nbttagcompound.getList("pages", 8); NBTTagList nbttaglist = nbttagcompound.getList("pages", 8);
@ -391,7 +393,7 @@
if (PlayerInventory.d(i) || i == 40) { if (PlayerInventory.d(i) || i == 40) {
this.a((List) list, flag ? (list1) -> { this.a((List) list, flag ? (list1) -> {
this.a((String) list1.get(0), list1.subList(1, list1.size()), i); this.a((String) list1.get(0), list1.subList(1, list1.size()), i);
@@ -769,7 +989,9 @@ @@ -769,7 +991,9 @@
NBTTagList nbttaglist = new NBTTagList(); NBTTagList nbttaglist = new NBTTagList();
list.stream().map(NBTTagString::a).forEach(nbttaglist::add); list.stream().map(NBTTagString::a).forEach(nbttaglist::add);
@ -401,7 +403,7 @@
} }
} }
@@ -798,7 +1020,7 @@ @@ -798,7 +1022,7 @@
} }
itemstack1.a("pages", (NBTBase) nbttaglist); itemstack1.a("pages", (NBTBase) nbttaglist);
@ -410,7 +412,7 @@
} }
} }
@@ -836,7 +1058,7 @@ @@ -836,7 +1060,7 @@
} else { } else {
WorldServer worldserver = this.player.getWorldServer(); WorldServer worldserver = this.player.getWorldServer();
@ -419,7 +421,7 @@
if (this.e == 0) { if (this.e == 0) {
this.syncPosition(); this.syncPosition();
} }
@@ -846,13 +1068,21 @@ @@ -846,13 +1070,21 @@
this.A = this.e; this.A = this.e;
this.a(this.teleportPos.x, this.teleportPos.y, this.teleportPos.z, this.player.yaw, this.player.pitch); this.a(this.teleportPos.x, this.teleportPos.y, this.teleportPos.z, this.player.yaw, this.player.pitch);
} }
@ -442,7 +444,7 @@
double d0 = this.player.locX(); double d0 = this.player.locX();
double d1 = this.player.locY(); double d1 = this.player.locY();
double d2 = this.player.locZ(); double d2 = this.player.locZ();
@@ -877,15 +1107,33 @@ @@ -877,15 +1109,33 @@
++this.receivedMovePackets; ++this.receivedMovePackets;
int i = this.receivedMovePackets - this.processedMovePackets; int i = this.receivedMovePackets - this.processedMovePackets;
@ -478,7 +480,7 @@
PlayerConnection.LOGGER.warn("{} moved too quickly! {},{},{}", this.player.getDisplayName().getString(), d7, d8, d9); PlayerConnection.LOGGER.warn("{} moved too quickly! {},{},{}", this.player.getDisplayName().getString(), d7, d8, d9);
this.a(this.player.locX(), this.player.locY(), this.player.locZ(), this.player.yaw, this.player.pitch); this.a(this.player.locX(), this.player.locY(), this.player.locZ(), this.player.yaw, this.player.pitch);
return; return;
@@ -904,6 +1152,7 @@ @@ -904,6 +1154,7 @@
} }
this.player.move(EnumMoveType.PLAYER, new Vec3D(d7, d8, d9)); this.player.move(EnumMoveType.PLAYER, new Vec3D(d7, d8, d9));
@ -486,7 +488,7 @@
double d12 = d8; double d12 = d8;
d7 = d4 - this.player.locX(); d7 = d4 - this.player.locX();
@@ -925,10 +1174,74 @@ @@ -925,10 +1176,74 @@
if (!this.player.noclip && !this.player.isSleeping() && (flag1 && worldserver.getCubes(this.player, axisalignedbb) || this.a((IWorldReader) worldserver, axisalignedbb))) { if (!this.player.noclip && !this.player.isSleeping() && (flag1 && worldserver.getCubes(this.player, axisalignedbb) || this.a((IWorldReader) worldserver, axisalignedbb))) {
this.a(d0, d1, d2, f, f1); this.a(d0, d1, d2, f, f1);
} else { } else {
@ -563,7 +565,7 @@
if (flag) { if (flag) {
this.player.fallDistance = 0.0F; this.player.fallDistance = 0.0F;
} }
@@ -957,10 +1270,66 @@ @@ -957,10 +1272,66 @@
} }
public void a(double d0, double d1, double d2, float f, float f1) { public void a(double d0, double d1, double d2, float f, float f1) {
@ -631,7 +633,7 @@
double d3 = set.contains(PacketPlayOutPosition.EnumPlayerTeleportFlags.X) ? this.player.locX() : 0.0D; double d3 = set.contains(PacketPlayOutPosition.EnumPlayerTeleportFlags.X) ? this.player.locX() : 0.0D;
double d4 = set.contains(PacketPlayOutPosition.EnumPlayerTeleportFlags.Y) ? this.player.locY() : 0.0D; double d4 = set.contains(PacketPlayOutPosition.EnumPlayerTeleportFlags.Y) ? this.player.locY() : 0.0D;
double d5 = set.contains(PacketPlayOutPosition.EnumPlayerTeleportFlags.Z) ? this.player.locZ() : 0.0D; double d5 = set.contains(PacketPlayOutPosition.EnumPlayerTeleportFlags.Z) ? this.player.locZ() : 0.0D;
@@ -972,6 +1341,14 @@ @@ -972,6 +1343,14 @@
this.teleportAwait = 0; this.teleportAwait = 0;
} }
@ -646,7 +648,7 @@
this.A = this.e; this.A = this.e;
this.player.setLocation(d0, d1, d2, f, f1); this.player.setLocation(d0, d1, d2, f, f1);
this.player.playerConnection.sendPacket(new PacketPlayOutPosition(d0 - d3, d1 - d4, d2 - d5, f - f2, f1 - f3, set, this.teleportAwait)); this.player.playerConnection.sendPacket(new PacketPlayOutPosition(d0 - d3, d1 - d4, d2 - d5, f - f2, f1 - f3, set, this.teleportAwait));
@@ -980,6 +1357,7 @@ @@ -980,6 +1359,7 @@
@Override @Override
public void a(PacketPlayInBlockDig packetplayinblockdig) { public void a(PacketPlayInBlockDig packetplayinblockdig) {
PlayerConnectionUtils.ensureMainThread(packetplayinblockdig, this, this.player.getWorldServer()); PlayerConnectionUtils.ensureMainThread(packetplayinblockdig, this, this.player.getWorldServer());
@ -654,7 +656,7 @@
BlockPosition blockposition = packetplayinblockdig.b(); BlockPosition blockposition = packetplayinblockdig.b();
this.player.resetIdleTimer(); this.player.resetIdleTimer();
@@ -990,14 +1368,46 @@ @@ -990,14 +1370,46 @@
if (!this.player.isSpectator()) { if (!this.player.isSpectator()) {
ItemStack itemstack = this.player.b(EnumHand.OFF_HAND); ItemStack itemstack = this.player.b(EnumHand.OFF_HAND);
@ -703,7 +705,7 @@
this.player.dropItem(false); this.player.dropItem(false);
} }
@@ -1034,6 +1444,7 @@ @@ -1034,6 +1446,7 @@
@Override @Override
public void a(PacketPlayInUseItem packetplayinuseitem) { public void a(PacketPlayInUseItem packetplayinuseitem) {
PlayerConnectionUtils.ensureMainThread(packetplayinuseitem, this, this.player.getWorldServer()); PlayerConnectionUtils.ensureMainThread(packetplayinuseitem, this, this.player.getWorldServer());
@ -711,7 +713,7 @@
WorldServer worldserver = this.player.getWorldServer(); WorldServer worldserver = this.player.getWorldServer();
EnumHand enumhand = packetplayinuseitem.b(); EnumHand enumhand = packetplayinuseitem.b();
ItemStack itemstack = this.player.b(enumhand); ItemStack itemstack = this.player.b(enumhand);
@@ -1044,6 +1455,14 @@ @@ -1044,6 +1457,14 @@
this.player.resetIdleTimer(); this.player.resetIdleTimer();
if (blockposition.getY() < this.minecraftServer.getMaxBuildHeight()) { if (blockposition.getY() < this.minecraftServer.getMaxBuildHeight()) {
if (this.teleportPos == null && this.player.h((double) blockposition.getX() + 0.5D, (double) blockposition.getY() + 0.5D, (double) blockposition.getZ() + 0.5D) < 64.0D && worldserver.a((EntityHuman) this.player, blockposition)) { if (this.teleportPos == null && this.player.h((double) blockposition.getX() + 0.5D, (double) blockposition.getY() + 0.5D, (double) blockposition.getZ() + 0.5D) < 64.0D && worldserver.a((EntityHuman) this.player, blockposition)) {
@ -726,7 +728,7 @@
EnumInteractionResult enuminteractionresult = this.player.playerInteractManager.a(this.player, worldserver, itemstack, enumhand, movingobjectpositionblock); EnumInteractionResult enuminteractionresult = this.player.playerInteractManager.a(this.player, worldserver, itemstack, enumhand, movingobjectpositionblock);
if (enumdirection == EnumDirection.UP && !enuminteractionresult.a() && blockposition.getY() >= this.minecraftServer.getMaxBuildHeight() - 1 && a(this.player, itemstack)) { if (enumdirection == EnumDirection.UP && !enuminteractionresult.a() && blockposition.getY() >= this.minecraftServer.getMaxBuildHeight() - 1 && a(this.player, itemstack)) {
@@ -1067,12 +1486,51 @@ @@ -1067,12 +1488,51 @@
@Override @Override
public void a(PacketPlayInBlockPlace packetplayinblockplace) { public void a(PacketPlayInBlockPlace packetplayinblockplace) {
PlayerConnectionUtils.ensureMainThread(packetplayinblockplace, this, this.player.getWorldServer()); PlayerConnectionUtils.ensureMainThread(packetplayinblockplace, this, this.player.getWorldServer());
@ -778,7 +780,7 @@
EnumInteractionResult enuminteractionresult = this.player.playerInteractManager.a(this.player, worldserver, itemstack, enumhand); EnumInteractionResult enuminteractionresult = this.player.playerInteractManager.a(this.player, worldserver, itemstack, enumhand);
if (enuminteractionresult.b()) { if (enuminteractionresult.b()) {
@@ -1093,7 +1551,7 @@ @@ -1093,7 +1553,7 @@
Entity entity = packetplayinspectate.a(worldserver); Entity entity = packetplayinspectate.a(worldserver);
if (entity != null) { if (entity != null) {
@ -787,7 +789,7 @@
return; return;
} }
} }
@@ -1102,7 +1560,12 @@ @@ -1102,7 +1562,12 @@
} }
@Override @Override
@ -801,7 +803,7 @@
@Override @Override
public void a(PacketPlayInBoatMove packetplayinboatmove) { public void a(PacketPlayInBoatMove packetplayinboatmove) {
@@ -1117,11 +1580,26 @@ @@ -1117,11 +1582,26 @@
@Override @Override
public void a(IChatBaseComponent ichatbasecomponent) { public void a(IChatBaseComponent ichatbasecomponent) {
@ -829,7 +831,7 @@
ITextFilter itextfilter = this.player.Q(); ITextFilter itextfilter = this.player.Q();
if (itextfilter != null) { if (itextfilter != null) {
@@ -1153,6 +1631,15 @@ @@ -1153,6 +1633,15 @@
} }
} }
@ -845,7 +847,7 @@
try { try {
this.networkManager.sendPacket(packet, genericfuturelistener); this.networkManager.sendPacket(packet, genericfuturelistener);
} catch (Throwable throwable) { } catch (Throwable throwable) {
@@ -1169,7 +1656,16 @@ @@ -1169,7 +1658,16 @@
@Override @Override
public void a(PacketPlayInHeldItemSlot packetplayinhelditemslot) { public void a(PacketPlayInHeldItemSlot packetplayinhelditemslot) {
PlayerConnectionUtils.ensureMainThread(packetplayinhelditemslot, this, this.player.getWorldServer()); PlayerConnectionUtils.ensureMainThread(packetplayinhelditemslot, this, this.player.getWorldServer());
@ -862,7 +864,7 @@
if (this.player.inventory.itemInHandIndex != packetplayinhelditemslot.b() && this.player.getRaisedHand() == EnumHand.MAIN_HAND) { if (this.player.inventory.itemInHandIndex != packetplayinhelditemslot.b() && this.player.getRaisedHand() == EnumHand.MAIN_HAND) {
this.player.clearActiveItem(); this.player.clearActiveItem();
} }
@@ -1178,65 +1674,286 @@ @@ -1178,65 +1676,286 @@
this.player.resetIdleTimer(); this.player.resetIdleTimer();
} else { } else {
PlayerConnection.LOGGER.warn("{} tried to set an invalid carried item", this.player.getDisplayName().getString()); PlayerConnection.LOGGER.warn("{} tried to set an invalid carried item", this.player.getDisplayName().getString());
@ -1158,7 +1160,7 @@
this.player.resetIdleTimer(); this.player.resetIdleTimer();
IJumpable ijumpable; IJumpable ijumpable;
@@ -1294,6 +2011,7 @@ @@ -1294,6 +2013,7 @@
@Override @Override
public void a(PacketPlayInUseEntity packetplayinuseentity) { public void a(PacketPlayInUseEntity packetplayinuseentity) {
PlayerConnectionUtils.ensureMainThread(packetplayinuseentity, this, this.player.getWorldServer()); PlayerConnectionUtils.ensureMainThread(packetplayinuseentity, this, this.player.getWorldServer());
@ -1166,7 +1168,7 @@
WorldServer worldserver = this.player.getWorldServer(); WorldServer worldserver = this.player.getWorldServer();
Entity entity = packetplayinuseentity.a((World) worldserver); Entity entity = packetplayinuseentity.a((World) worldserver);
@@ -1307,18 +2025,72 @@ @@ -1307,18 +2027,72 @@
ItemStack itemstack = enumhand != null ? this.player.b(enumhand).cloneItemStack() : ItemStack.b; ItemStack itemstack = enumhand != null ? this.player.b(enumhand).cloneItemStack() : ItemStack.b;
Optional<EnumInteractionResult> optional = Optional.empty(); Optional<EnumInteractionResult> optional = Optional.empty();
@ -1240,7 +1242,7 @@
} }
if (optional.isPresent() && ((EnumInteractionResult) optional.get()).a()) { if (optional.isPresent() && ((EnumInteractionResult) optional.get()).a()) {
@@ -1365,15 +2137,21 @@ @@ -1365,15 +2139,21 @@
@Override @Override
public void a(PacketPlayInCloseWindow packetplayinclosewindow) { public void a(PacketPlayInCloseWindow packetplayinclosewindow) {
PlayerConnectionUtils.ensureMainThread(packetplayinclosewindow, this, this.player.getWorldServer()); PlayerConnectionUtils.ensureMainThread(packetplayinclosewindow, this, this.player.getWorldServer());
@ -1264,7 +1266,7 @@
NonNullList<ItemStack> nonnulllist = NonNullList.a(); NonNullList<ItemStack> nonnulllist = NonNullList.a();
for (int i = 0; i < this.player.activeContainer.slots.size(); ++i) { for (int i = 0; i < this.player.activeContainer.slots.size(); ++i) {
@@ -1382,8 +2160,274 @@ @@ -1382,8 +2162,285 @@
this.player.a(this.player.activeContainer, nonnulllist); this.player.a(this.player.activeContainer, nonnulllist);
} else { } else {
@ -1467,13 +1469,24 @@
+ } + }
+ } + }
+ +
+ if (packetplayinwindowclick.c() == 2 && top instanceof SmithingInventory) {
+ org.bukkit.inventory.ItemStack result = ((SmithingInventory) top).getResult();
+ if (result != null) {
+ if (click == ClickType.NUMBER_KEY) {
+ event = new SmithItemEvent(inventory, type, packetplayinwindowclick.c(), click, action, packetplayinwindowclick.d());
+ } else {
+ event = new SmithItemEvent(inventory, type, packetplayinwindowclick.c(), click, action);
+ }
+ }
+ }
+
+ event.setCancelled(cancelled); + event.setCancelled(cancelled);
+ Container oldContainer = this.player.activeContainer; // SPIGOT-1224 + Container oldContainer = this.player.activeContainer; // SPIGOT-1224
+ server.getPluginManager().callEvent(event); + server.getPluginManager().callEvent(event);
+ if (this.player.activeContainer != oldContainer) { + if (this.player.activeContainer != oldContainer) {
+ return; + return;
+ } + }
+
+ switch (event.getResult()) { + switch (event.getResult()) {
+ case ALLOW: + case ALLOW:
+ case DEFAULT: + case DEFAULT:
@ -1482,7 +1495,7 @@
+ case DENY: + case DENY:
+ /* Needs enum constructor in InventoryAction + /* Needs enum constructor in InventoryAction
+ if (action.modifiesOtherSlots()) { + if (action.modifiesOtherSlots()) {
+
+ } else { + } else {
+ if (action.modifiesCursor()) { + if (action.modifiesCursor()) {
+ this.player.playerConnection.sendPacket(new Packet103SetSlot(-1, -1, this.player.inventory.getCarried())); + this.player.playerConnection.sendPacket(new Packet103SetSlot(-1, -1, this.player.inventory.getCarried()));
@ -1530,7 +1543,7 @@
+ return; + return;
+ } + }
+ +
+ if (event instanceof CraftItemEvent) { + if (event instanceof CraftItemEvent || event instanceof SmithItemEvent) {
+ // Need to update the inventory on crafting to + // Need to update the inventory on crafting to
+ // correctly support custom recipes + // correctly support custom recipes
+ player.updateInventory(player.activeContainer); + player.updateInventory(player.activeContainer);
@ -1540,7 +1553,7 @@
if (ItemStack.matches(packetplayinwindowclick.f(), itemstack)) { if (ItemStack.matches(packetplayinwindowclick.f(), itemstack)) {
this.player.playerConnection.sendPacket(new PacketPlayOutTransaction(packetplayinwindowclick.b(), packetplayinwindowclick.e(), true)); this.player.playerConnection.sendPacket(new PacketPlayOutTransaction(packetplayinwindowclick.b(), packetplayinwindowclick.e(), true));
this.player.e = true; this.player.e = true;
@@ -1423,6 +2467,7 @@ @@ -1423,6 +2480,7 @@
@Override @Override
public void a(PacketPlayInEnchantItem packetplayinenchantitem) { public void a(PacketPlayInEnchantItem packetplayinenchantitem) {
PlayerConnectionUtils.ensureMainThread(packetplayinenchantitem, this, this.player.getWorldServer()); PlayerConnectionUtils.ensureMainThread(packetplayinenchantitem, this, this.player.getWorldServer());
@ -1548,7 +1561,7 @@
this.player.resetIdleTimer(); this.player.resetIdleTimer();
if (this.player.activeContainer.windowId == packetplayinenchantitem.b() && this.player.activeContainer.c(this.player) && !this.player.isSpectator()) { if (this.player.activeContainer.windowId == packetplayinenchantitem.b() && this.player.activeContainer.c(this.player) && !this.player.isSpectator()) {
this.player.activeContainer.a((EntityHuman) this.player, packetplayinenchantitem.c()); this.player.activeContainer.a((EntityHuman) this.player, packetplayinenchantitem.c());
@@ -1455,6 +2500,43 @@ @@ -1455,6 +2513,43 @@
boolean flag1 = packetplayinsetcreativeslot.b() >= 1 && packetplayinsetcreativeslot.b() <= 45; boolean flag1 = packetplayinsetcreativeslot.b() >= 1 && packetplayinsetcreativeslot.b() <= 45;
boolean flag2 = itemstack.isEmpty() || itemstack.getDamage() >= 0 && itemstack.getCount() <= 64 && !itemstack.isEmpty(); boolean flag2 = itemstack.isEmpty() || itemstack.getDamage() >= 0 && itemstack.getCount() <= 64 && !itemstack.isEmpty();
@ -1592,7 +1605,7 @@
if (flag1 && flag2) { if (flag1 && flag2) {
if (itemstack.isEmpty()) { if (itemstack.isEmpty()) {
@@ -1476,6 +2558,7 @@ @@ -1476,6 +2571,7 @@
@Override @Override
public void a(PacketPlayInTransaction packetplayintransaction) { public void a(PacketPlayInTransaction packetplayintransaction) {
PlayerConnectionUtils.ensureMainThread(packetplayintransaction, this, this.player.getWorldServer()); PlayerConnectionUtils.ensureMainThread(packetplayintransaction, this, this.player.getWorldServer());
@ -1600,7 +1613,7 @@
int i = this.player.activeContainer.windowId; int i = this.player.activeContainer.windowId;
if (i == packetplayintransaction.b() && this.k.getOrDefault(i, (short) (packetplayintransaction.c() + 1)) == packetplayintransaction.c() && !this.player.activeContainer.c(this.player) && !this.player.isSpectator()) { if (i == packetplayintransaction.b() && this.k.getOrDefault(i, (short) (packetplayintransaction.c() + 1)) == packetplayintransaction.c() && !this.player.activeContainer.c(this.player) && !this.player.isSpectator()) {
@@ -1494,6 +2577,7 @@ @@ -1494,6 +2590,7 @@
} }
private void a(PacketPlayInUpdateSign packetplayinupdatesign, List<String> list) { private void a(PacketPlayInUpdateSign packetplayinupdatesign, List<String> list) {
@ -1608,7 +1621,7 @@
this.player.resetIdleTimer(); this.player.resetIdleTimer();
WorldServer worldserver = this.player.getWorldServer(); WorldServer worldserver = this.player.getWorldServer();
BlockPosition blockposition = packetplayinupdatesign.b(); BlockPosition blockposition = packetplayinupdatesign.b();
@@ -1510,12 +2594,28 @@ @@ -1510,12 +2607,28 @@
if (!tileentitysign.d() || tileentitysign.f() != this.player) { if (!tileentitysign.d() || tileentitysign.f() != this.player) {
PlayerConnection.LOGGER.warn("Player {} just tried to change non-editable sign", this.player.getDisplayName().getString()); PlayerConnection.LOGGER.warn("Player {} just tried to change non-editable sign", this.player.getDisplayName().getString());
@ -1638,7 +1651,7 @@
tileentitysign.update(); tileentitysign.update();
worldserver.notify(blockposition, iblockdata, iblockdata, 3); worldserver.notify(blockposition, iblockdata, iblockdata, 3);
@@ -1525,6 +2625,7 @@ @@ -1525,6 +2638,7 @@
@Override @Override
public void a(PacketPlayInKeepAlive packetplayinkeepalive) { public void a(PacketPlayInKeepAlive packetplayinkeepalive) {
@ -1646,7 +1659,7 @@
if (this.awaitingKeepAlive && packetplayinkeepalive.b() == this.h) { if (this.awaitingKeepAlive && packetplayinkeepalive.b() == this.h) {
int i = (int) (SystemUtils.getMonotonicMillis() - this.lastKeepAlive); int i = (int) (SystemUtils.getMonotonicMillis() - this.lastKeepAlive);
@@ -1539,7 +2640,17 @@ @@ -1539,7 +2653,17 @@
@Override @Override
public void a(PacketPlayInAbilities packetplayinabilities) { public void a(PacketPlayInAbilities packetplayinabilities) {
PlayerConnectionUtils.ensureMainThread(packetplayinabilities, this, this.player.getWorldServer()); PlayerConnectionUtils.ensureMainThread(packetplayinabilities, this, this.player.getWorldServer());
@ -1665,7 +1678,7 @@
} }
@Override @Override
@@ -1548,8 +2659,50 @@ @@ -1548,8 +2672,50 @@
this.player.a(packetplayinsettings); this.player.a(packetplayinsettings);
} }

Datei anzeigen

@ -1,6 +1,37 @@
--- a/net/minecraft/world/inventory/ContainerAnvilAbstract.java --- a/net/minecraft/world/inventory/ContainerAnvilAbstract.java
+++ b/net/minecraft/world/inventory/ContainerAnvilAbstract.java +++ b/net/minecraft/world/inventory/ContainerAnvilAbstract.java
@@ -85,6 +85,7 @@ @@ -11,13 +11,7 @@
public abstract class ContainerAnvilAbstract extends Container {
protected final InventoryCraftResult resultInventory = new InventoryCraftResult();
- protected final IInventory repairInventory = new InventorySubcontainer(2) {
- @Override
- public void update() {
- super.update();
- ContainerAnvilAbstract.this.a((IInventory) this);
- }
- };
+ protected final IInventory repairInventory; // CraftBukkit - instantiate repairInventory in the constructor
protected final ContainerAccess containerAccess;
protected final EntityHuman player;
@@ -31,6 +25,15 @@
super(containers, i);
this.containerAccess = containeraccess;
this.player = playerinventory.player;
+ // CraftBukkit start
+ this.repairInventory = new InventoryCrafting(this, 1, 2, player) {
+ @Override
+ public void update() {
+ super.update();
+ ContainerAnvilAbstract.this.a((IInventory) this);
+ }
+ };
+ // CraftBukkit end
this.a(new Slot(this.repairInventory, 0, 27, 47));
this.a(new Slot(this.repairInventory, 1, 76, 47));
this.a(new Slot(this.resultInventory, 2, 134, 47) {
@@ -85,6 +88,7 @@
@Override @Override
public boolean canUse(EntityHuman entityhuman) { public boolean canUse(EntityHuman entityhuman) {

Datei anzeigen

@ -18,7 +18,7 @@
public ContainerSmithing(int i, PlayerInventory playerinventory) { public ContainerSmithing(int i, PlayerInventory playerinventory) {
this(i, playerinventory, ContainerAccess.a); this(i, playerinventory, ContainerAccess.a);
@@ -63,13 +68,13 @@ @@ -63,13 +68,16 @@
List<RecipeSmithing> list = this.g.getCraftingManager().b(Recipes.SMITHING, this.repairInventory, this.g); List<RecipeSmithing> list = this.g.getCraftingManager().b(Recipes.SMITHING, this.repairInventory, this.g);
if (list.isEmpty()) { if (list.isEmpty()) {
@ -30,11 +30,14 @@
this.resultInventory.a((IRecipe) this.h); this.resultInventory.a((IRecipe) this.h);
- this.resultInventory.setItem(0, itemstack); - this.resultInventory.setItem(0, itemstack);
+ org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareSmithingEvent(getBukkitView(), itemstack); // CraftBukkit + // CraftBukkit start
+ this.repairInventory.setCurrentRecipe(this.h);
+ org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareSmithingEvent(getBukkitView(), itemstack);
+ // CraftBukkit end
} }
} }
@@ -85,4 +90,18 @@ @@ -85,4 +93,18 @@
public boolean a(ItemStack itemstack, Slot slot) { public boolean a(ItemStack itemstack, Slot slot) {
return slot.inventory != this.resultInventory && super.a(itemstack, slot); return slot.inventory != this.resultInventory && super.a(itemstack, slot);
} }

Datei anzeigen

@ -1,7 +1,10 @@
package org.bukkit.craftbukkit.inventory; package org.bukkit.craftbukkit.inventory;
import net.minecraft.world.IInventory; import net.minecraft.world.IInventory;
import net.minecraft.world.item.crafting.IRecipe;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.Recipe;
import org.bukkit.inventory.SmithingInventory; import org.bukkit.inventory.SmithingInventory;
public class CraftInventorySmithing extends CraftResultInventory implements SmithingInventory { public class CraftInventorySmithing extends CraftResultInventory implements SmithingInventory {
@ -17,4 +20,20 @@ public class CraftInventorySmithing extends CraftResultInventory implements Smit
public Location getLocation() { public Location getLocation() {
return location; return location;
} }
@Override
public ItemStack getResult() {
return getItem(2);
}
@Override
public void setResult(ItemStack item) {
setItem(2, item);
}
@Override
public Recipe getRecipe() {
IRecipe recipe = getInventory().getCurrentRecipe();
return (recipe == null) ? null : recipe.toBukkitRecipe();
}
} }