From 17fbd42b9cda97a34fae52d73e733c4da24d3128 Mon Sep 17 00:00:00 2001 From: Ty Sayers Date: Fri, 2 Oct 2015 14:30:39 -0400 Subject: [PATCH] Fix bug where a players inventory was not properly updated after switching to SURVIVAL mode, causing CustomGear items to remain unhidden an JSON encoded. --- .../src/mineplex/core/shop/ShopBase.java | 2 +- .../game/clans/items/GearManager.java | 4 +-- .../game/clans/items/ItemListener.java | 29 +++++++++---------- .../clans/items/commands/GearCommand.java | 1 + 4 files changed, 17 insertions(+), 19 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/shop/ShopBase.java b/Plugins/Mineplex.Core/src/mineplex/core/shop/ShopBase.java index b7ea24b2e..cf8b15d93 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/shop/ShopBase.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/shop/ShopBase.java @@ -134,7 +134,7 @@ public abstract class ShopBase implements Listene if (page.matchesInventory(event.getInventory())) { - _playerPageMap.get(event.getWhoClicked().getName()).playerClicked(event); + page.playerClicked(event); if (event.getRawSlot() < page.getSize()) { diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/GearManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/GearManager.java index 08162a270..5c32e9b57 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/GearManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/GearManager.java @@ -433,7 +433,7 @@ public class GearManager extends MiniPlugin implements IPacketHandler, Runnable Packet packet = packetInfo.getPacket(); if (packet instanceof PacketPlayOutSetSlot) - { + { PacketPlayOutSetSlot slotPacket = (PacketPlayOutSetSlot) packet; slotPacket.c = maskItem(slotPacket.c); // Mask all out-going item packets } @@ -445,7 +445,7 @@ public class GearManager extends MiniPlugin implements IPacketHandler, Runnable { itemsPacket.b[i] = maskItem(itemsPacket.b[i]); // Mask all out-going item packets } - } + } } private net.minecraft.server.v1_7_R4.ItemStack maskItem(net.minecraft.server.v1_7_R4.ItemStack item) diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/ItemListener.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/ItemListener.java index 76f793c84..2e97a89a1 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/ItemListener.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/ItemListener.java @@ -5,6 +5,7 @@ import mineplex.game.clans.items.attributes.ItemAttribute; import mineplex.minecraft.game.core.damage.CustomDamageEvent; import net.minecraft.server.v1_7_R4.Material; +import org.bukkit.Bukkit; import org.bukkit.GameMode; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; @@ -44,7 +45,7 @@ public class ItemListener implements Listener _plugin = plugin; } - @EventHandler + @EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR) public void onGamemodeChange(PlayerGameModeChangeEvent event) { if (event.getNewGameMode() == GameMode.CREATIVE) // Entering creative mode @@ -54,6 +55,17 @@ public class ItemListener implements Listener else if (event.getPlayer().getGameMode() == GameMode.CREATIVE) // Exiting creative mode { GearManager.getInstance().removeCreativePlayer(event.getPlayer()); + + // Update/refresh the players inventory in 5 ticks once they're in survival mode again + final Player player = event.getPlayer(); + Bukkit.getScheduler().runTaskLater(_plugin, new Runnable() + { + @Override + public void run() + { + player.updateInventory(); + } + }, 5l); } } @@ -163,21 +175,6 @@ public class ItemListener implements Listener @EventHandler public void onPlayerInteract(PlayerInteractEvent event) { - // Prevent players from equipping armour items in hand (prevents lore-breaking bug) - ItemStack itemInHand = event.getItem(); - if (isArmour(itemInHand)) - { - Action action = event.getAction(); - boolean rightClick = action == Action.RIGHT_CLICK_AIR || action == Action.RIGHT_CLICK_BLOCK; - - if (rightClick) - { - event.setCancelled(true); - GearManager.notify(event.getPlayer(), "You must manually equip armour!"); - return; - } - } - // Activate weapon interact abilities PlayerGear playerGear = getGear(event.getPlayer()); playerGear.onInteract(event); diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/commands/GearCommand.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/commands/GearCommand.java index 51a3cffbc..d090c8ced 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/commands/GearCommand.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/commands/GearCommand.java @@ -58,6 +58,7 @@ public class GearCommand extends CommandBase } else { + caller.updateInventory(); //caller.setFoodLevel(10); //return; }