Fix ghost items with /recipe

This commit is contained in:
KHobbits 2014-02-09 21:51:18 +00:00
parent 5e6ce8aecb
commit 9bc8f287a4

View File

@ -650,6 +650,7 @@ public class EssentialsPlayerListener implements Listener
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onInventoryClickEvent(final InventoryClickEvent event) public void onInventoryClickEvent(final InventoryClickEvent event)
{ {
Player refreshPlayer = null;
final Inventory top = event.getView().getTopInventory(); final Inventory top = event.getView().getTopInventory();
final InventoryType type = top.getType(); final InventoryType type = top.getType();
@ -665,7 +666,7 @@ public class EssentialsPlayerListener implements Listener
|| !invOwner.isOnline())) || !invOwner.isOnline()))
{ {
event.setCancelled(true); event.setCancelled(true);
user.updateInventory(); refreshPlayer = user.getBase();
} }
} }
} }
@ -675,6 +676,7 @@ public class EssentialsPlayerListener implements Listener
if (user.isEnderSee() && (!user.isAuthorized("essentials.enderchest.modify"))) if (user.isEnderSee() && (!user.isAuthorized("essentials.enderchest.modify")))
{ {
event.setCancelled(true); event.setCancelled(true);
refreshPlayer = user.getBase();
} }
} }
else if (type == InventoryType.WORKBENCH) else if (type == InventoryType.WORKBENCH)
@ -683,6 +685,7 @@ public class EssentialsPlayerListener implements Listener
if (user.isRecipeSee()) if (user.isRecipeSee())
{ {
event.setCancelled(true); event.setCancelled(true);
refreshPlayer = user.getBase();
} }
} }
else if (type == InventoryType.CHEST && top.getSize() == 9) else if (type == InventoryType.CHEST && top.getSize() == 9)
@ -692,26 +695,41 @@ public class EssentialsPlayerListener implements Listener
if (invHolder != null && invHolder instanceof HumanEntity && user.isInvSee()) if (invHolder != null && invHolder instanceof HumanEntity && user.isInvSee())
{ {
event.setCancelled(true); event.setCancelled(true);
refreshPlayer = user.getBase();
} }
} }
if (refreshPlayer != null)
{
final Player player = refreshPlayer;
ess.scheduleSyncDelayedTask(new Runnable()
{
@Override
public void run()
{
player.updateInventory();
}
}, 1);
}
} }
@EventHandler(priority = EventPriority.MONITOR) @EventHandler(priority = EventPriority.MONITOR)
public void onInventoryCloseEvent(final InventoryCloseEvent event) public void onInventoryCloseEvent(final InventoryCloseEvent event)
{ {
Player refreshPlayer = null;
final Inventory top = event.getView().getTopInventory(); final Inventory top = event.getView().getTopInventory();
final InventoryType type = top.getType(); final InventoryType type = top.getType();
if (type == InventoryType.PLAYER) if (type == InventoryType.PLAYER)
{ {
final User user = ess.getUser((Player)event.getPlayer()); final User user = ess.getUser((Player)event.getPlayer());
user.setInvSee(false); user.setInvSee(false);
user.updateInventory(); refreshPlayer = user.getBase();
} }
else if (type == InventoryType.ENDER_CHEST) else if (type == InventoryType.ENDER_CHEST)
{ {
final User user = ess.getUser((Player)event.getPlayer()); final User user = ess.getUser((Player)event.getPlayer());
user.setEnderSee(false); user.setEnderSee(false);
user.updateInventory(); refreshPlayer = user.getBase();
} }
else if (type == InventoryType.WORKBENCH) else if (type == InventoryType.WORKBENCH)
{ {
@ -720,7 +738,7 @@ public class EssentialsPlayerListener implements Listener
{ {
user.setRecipeSee(false); user.setRecipeSee(false);
event.getView().getTopInventory().clear(); event.getView().getTopInventory().clear();
user.updateInventory(); refreshPlayer = user.getBase();
} }
} }
else if (type == InventoryType.CHEST && top.getSize() == 9) else if (type == InventoryType.CHEST && top.getSize() == 9)
@ -730,9 +748,22 @@ public class EssentialsPlayerListener implements Listener
{ {
final User user = ess.getUser((Player)event.getPlayer()); final User user = ess.getUser((Player)event.getPlayer());
user.setInvSee(false); user.setInvSee(false);
user.updateInventory(); refreshPlayer = user.getBase();
} }
} }
if (refreshPlayer != null)
{
final Player player = refreshPlayer;
ess.scheduleSyncDelayedTask(new Runnable()
{
@Override
public void run()
{
player.updateInventory();
}
}, 1);
}
} }
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)