From 4670a84bd9db26b4fd013f723f2089ae570ec9ae Mon Sep 17 00:00:00 2001 From: md_5 Date: Mon, 24 Jul 2017 17:41:08 +1000 Subject: [PATCH] SPIGOT-3432: Add playNote support for new sounds --- nms-patches/PlayerConnection.patch | 47 ++++++++++++------- .../craftbukkit/entity/CraftPlayer.java | 30 ++++++++++++ .../permissions/CraftDefaultPermissions.java | 2 + 3 files changed, 62 insertions(+), 17 deletions(-) diff --git a/nms-patches/PlayerConnection.patch b/nms-patches/PlayerConnection.patch index 1fb2584143..6914c9c8dc 100644 --- a/nms-patches/PlayerConnection.patch +++ b/nms-patches/PlayerConnection.patch @@ -1159,7 +1159,7 @@ + + InventoryView inventory = this.player.activeContainer.getBukkitView(); + SlotType type = CraftInventoryView.getSlotType(inventory, packetplayinwindowclick.b()); -+ + + InventoryClickEvent event; + ClickType click = ClickType.UNKNOWN; + InventoryAction action = InventoryAction.UNKNOWN; @@ -1412,7 +1412,7 @@ + } + return; + } - ++ + if (event instanceof CraftItemEvent) { + // Need to update the inventory on crafting to + // correctly support custom recipes @@ -1423,7 +1423,20 @@ if (ItemStack.matches(packetplayinwindowclick.e(), itemstack)) { this.player.playerConnection.sendPacket(new PacketPlayOutTransaction(packetplayinwindowclick.a(), packetplayinwindowclick.d(), true)); this.player.f = true; -@@ -958,6 +1974,7 @@ +@@ -886,6 +1902,12 @@ + public void a(PacketPlayInAutoRecipe packetplayinautorecipe) { + PlayerConnectionUtils.ensureMainThread(packetplayinautorecipe, this, this.player.x()); + this.player.resetIdleTimer(); ++ // CraftBukkit start ++ if (!player.getBukkitEntity().hasPermission("minecraft.autocraft")) { ++ player.getBukkitEntity().updateInventory(); ++ return; ++ } ++ // CraftBukkit end + if (this.player.activeContainer.windowId == packetplayinautorecipe.a() && this.player.activeContainer.c(this.player)) { + this.player.playerConnection.sendPacket(new PacketPlayOutTransaction(packetplayinautorecipe.a(), packetplayinautorecipe.b(), true)); + Iterator iterator; +@@ -958,6 +1980,7 @@ public void a(PacketPlayInEnchantItem packetplayinenchantitem) { PlayerConnectionUtils.ensureMainThread(packetplayinenchantitem, this, this.player.x()); @@ -1431,7 +1444,7 @@ this.player.resetIdleTimer(); if (this.player.activeContainer.windowId == packetplayinenchantitem.a() && this.player.activeContainer.c(this.player) && !this.player.isSpectator()) { this.player.activeContainer.a(this.player, packetplayinenchantitem.b()); -@@ -991,7 +2008,45 @@ +@@ -991,7 +2014,45 @@ } boolean flag1 = packetplayinsetcreativeslot.a() >= 1 && packetplayinsetcreativeslot.a() <= 45; @@ -1478,7 +1491,7 @@ if (flag1 && flag2) { if (itemstack.isEmpty()) { -@@ -1015,6 +2070,7 @@ +@@ -1015,6 +2076,7 @@ public void a(PacketPlayInTransaction packetplayintransaction) { PlayerConnectionUtils.ensureMainThread(packetplayintransaction, this, this.player.x()); @@ -1486,7 +1499,7 @@ Short oshort = (Short) this.k.get(this.player.activeContainer.windowId); if (oshort != null && packetplayintransaction.b() == oshort.shortValue() && this.player.activeContainer.windowId == packetplayintransaction.a() && !this.player.activeContainer.c(this.player) && !this.player.isSpectator()) { -@@ -1025,6 +2081,7 @@ +@@ -1025,6 +2087,7 @@ public void a(PacketPlayInUpdateSign packetplayinupdatesign) { PlayerConnectionUtils.ensureMainThread(packetplayinupdatesign, this, this.player.x()); @@ -1494,7 +1507,7 @@ this.player.resetIdleTimer(); WorldServer worldserver = this.minecraftServer.getWorldServer(this.player.dimension); BlockPosition blockposition = packetplayinupdatesign.a(); -@@ -1041,14 +2098,30 @@ +@@ -1041,14 +2104,30 @@ if (!tileentitysign.a() || tileentitysign.e() != this.player) { this.minecraftServer.warning("Player " + this.player.getName() + " just tried to change non-editable sign"); @@ -1526,7 +1539,7 @@ tileentitysign.update(); worldserver.notify(blockposition, iblockdata, iblockdata, 3); -@@ -1071,11 +2144,27 @@ +@@ -1071,11 +2150,27 @@ public void a(PacketPlayInAbilities packetplayinabilities) { PlayerConnectionUtils.ensureMainThread(packetplayinabilities, this, this.player.x()); @@ -1555,7 +1568,7 @@ ArrayList arraylist = Lists.newArrayList(); Iterator iterator = this.minecraftServer.tabCompleteCommand(this.player, packetplayintabcomplete.a(), packetplayintabcomplete.b(), packetplayintabcomplete.c()).iterator(); -@@ -1101,6 +2190,13 @@ +@@ -1101,6 +2196,13 @@ ItemStack itemstack1; if ("MC|BEdit".equals(s)) { @@ -1569,7 +1582,7 @@ packetdataserializer = packetplayincustompayload.b(); try { -@@ -1119,15 +2215,25 @@ +@@ -1119,15 +2221,25 @@ } if (itemstack.getItem() == Items.WRITABLE_BOOK && itemstack.getItem() == itemstack1.getItem()) { @@ -1595,7 +1608,7 @@ packetdataserializer = packetplayincustompayload.b(); try { -@@ -1161,10 +2267,11 @@ +@@ -1161,10 +2273,11 @@ } itemstack2.a("pages", (NBTBase) nbttaglist); @@ -1608,7 +1621,7 @@ } } else if ("MC|TrSel".equals(s)) { try { -@@ -1176,6 +2283,7 @@ +@@ -1176,6 +2289,7 @@ } } catch (Exception exception2) { PlayerConnection.LOGGER.error("Couldn\'t select trade", exception2); @@ -1616,7 +1629,7 @@ } } else { TileEntity tileentity; -@@ -1225,6 +2333,7 @@ +@@ -1225,6 +2339,7 @@ } } catch (Exception exception3) { PlayerConnection.LOGGER.error("Couldn\'t set command block", exception3); @@ -1624,7 +1637,7 @@ } } else if ("MC|AutoCmd".equals(s)) { if (!this.minecraftServer.getEnableCommandBlock()) { -@@ -1292,6 +2401,7 @@ +@@ -1292,6 +2407,7 @@ } } catch (Exception exception4) { PlayerConnection.LOGGER.error("Couldn\'t set command block", exception4); @@ -1632,7 +1645,7 @@ } } else { int k; -@@ -1315,6 +2425,7 @@ +@@ -1315,6 +2431,7 @@ } } catch (Exception exception5) { PlayerConnection.LOGGER.error("Couldn\'t set beacon", exception5); @@ -1640,7 +1653,7 @@ } } } else if ("MC|ItemName".equals(s)) { -@@ -1401,6 +2512,7 @@ +@@ -1401,6 +2518,7 @@ } } catch (Exception exception6) { PlayerConnection.LOGGER.error("Couldn\'t set structure block", exception6); @@ -1648,7 +1661,7 @@ } } else if ("MC|PickItem".equals(s)) { packetdataserializer = packetplayincustompayload.b(); -@@ -1413,11 +2525,49 @@ +@@ -1413,11 +2531,49 @@ this.player.playerConnection.sendPacket(new PacketPlayOutHeldItemSlot(this.player.inventory.itemInHandIndex)); } catch (Exception exception7) { PlayerConnection.LOGGER.error("Couldn\'t pick item", exception7); diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java index 4764e70a99..b400b53558 100644 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java @@ -265,6 +265,21 @@ public class CraftPlayer extends CraftHumanEntity implements Player { case 4: instrumentName = "bass"; break; + case 5: + instrumentName = "flute"; + break; + case 6: + instrumentName = "bell"; + break; + case 7: + instrumentName = "guitar"; + break; + case 8: + instrumentName = "chime"; + break; + case 9: + instrumentName = "xylophone"; + break; } float f = (float) Math.pow(2.0D, (note - 12.0D) / 12.0D); @@ -292,6 +307,21 @@ public class CraftPlayer extends CraftHumanEntity implements Player { case 4: instrumentName = "bass"; break; + case 5: + instrumentName = "flute"; + break; + case 6: + instrumentName = "bell"; + break; + case 7: + instrumentName = "guitar"; + break; + case 8: + instrumentName = "chime"; + break; + case 9: + instrumentName = "xylophone"; + break; } float f = (float) Math.pow(2.0D, (note.getId() - 12.0D) / 12.0D); getHandle().playerConnection.sendPacket(new PacketPlayOutNamedSoundEffect(CraftSound.getSoundEffect("block.note." + instrumentName), net.minecraft.server.SoundCategory.MUSIC, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), 3.0f, f)); diff --git a/src/main/java/org/bukkit/craftbukkit/util/permissions/CraftDefaultPermissions.java b/src/main/java/org/bukkit/craftbukkit/util/permissions/CraftDefaultPermissions.java index 84826ee037..8a5249c5d0 100644 --- a/src/main/java/org/bukkit/craftbukkit/util/permissions/CraftDefaultPermissions.java +++ b/src/main/java/org/bukkit/craftbukkit/util/permissions/CraftDefaultPermissions.java @@ -1,6 +1,7 @@ package org.bukkit.craftbukkit.util.permissions; import org.bukkit.permissions.Permission; +import org.bukkit.permissions.PermissionDefault; import org.bukkit.util.permissions.DefaultPermissions; public final class CraftDefaultPermissions { @@ -11,6 +12,7 @@ public final class CraftDefaultPermissions { public static void registerCorePermissions() { Permission parent = DefaultPermissions.registerPermission(ROOT, "Gives the user the ability to use all vanilla utilities and commands"); CommandPermissions.registerPermissions(parent); + DefaultPermissions.registerPermission(ROOT + ".autocraft", "Gives the user the ability to use autocraft functionality", PermissionDefault.OP, parent); parent.recalculatePermissibles(); } }