Fix UI for PlayWire changes

Fix memory leak in Menu

(cherry picked from commit 770c899)
This commit is contained in:
TadahTech 2016-09-30 00:48:53 -04:00 committed by Shaun Bennett
parent 36c26c0b2c
commit 2a81f2b317
2 changed files with 58 additions and 51 deletions

View File

@ -20,11 +20,11 @@ public class PlayWireButton implements GuiItem
.setTitle(C.cGreen + C.Bold + "Watch an Ad!") .setTitle(C.cGreen + C.Bold + "Watch an Ad!")
.addLore( .addLore(
C.cWhite + "You have already redeemed your", C.cWhite + "You have already redeemed your",
C.cWhite + "250 Shards for watching the Ad!", C.cWhite + "100 Shards for watching the Ad!",
" ", " ",
C.cWhite + "You can watch it again, but you won't earn any shards!", C.cWhite + "You can watch it again, but you won't earn any shards!",
" ", " ",
C.cWhite + "You can watch the Ad once every 12 hours.", C.cWhite + "You can watch the Ad once every hour.",
" ", " ",
C.cWhite + "Ads help us keep Mineplex awesome", C.cWhite + "Ads help us keep Mineplex awesome",
C.cRedB + "Be sure to have your AdBlocker disabled!", C.cRedB + "Be sure to have your AdBlocker disabled!",
@ -36,10 +36,10 @@ public class PlayWireButton implements GuiItem
private static final ItemStack ENABLED_ICON = new ItemBuilder(Material.TRIPWIRE_HOOK) private static final ItemStack ENABLED_ICON = new ItemBuilder(Material.TRIPWIRE_HOOK)
.setTitle(C.cGreen + C.Bold + "Watch an Ad!") .setTitle(C.cGreen + C.Bold + "Watch an Ad!")
.addLore( .addLore(
C.cYellow + "Earn a 250 Shard Reward", C.cYellow + "Earn a 100 Shard Reward",
C.cWhite + "by checking out our partner's Advertisement", C.cWhite + "by checking out our partner's Advertisement",
" ", " ",
C.cWhite + "You can watch the Ad once every 12 hours.", C.cWhite + "You can watch the Ad once every hour.",
" ", " ",
C.cWhite + "Ads help us keep Mineplex awesome", C.cWhite + "Ads help us keep Mineplex awesome",
C.cRedB + "Be sure to have your AdBlocker disabled!", C.cRedB + "Be sure to have your AdBlocker disabled!",

View File

@ -6,6 +6,7 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryCloseEvent; import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.event.player.PlayerQuitEvent;
/** /**
* Listener for the Menu system * Listener for the Menu system
@ -13,64 +14,70 @@ import org.bukkit.event.inventory.InventoryCloseEvent;
public class MenuListener implements Listener public class MenuListener implements Listener
{ {
@EventHandler @EventHandler
public void onClick(InventoryClickEvent event) public void onClick(InventoryClickEvent event)
{ {
String name = event.getInventory().getName(); String name = event.getInventory().getName();
Player player = (Player) event.getWhoClicked(); Player player = (Player) event.getWhoClicked();
Menu gui = Menu.get(player.getUniqueId()); Menu gui = Menu.get(player.getUniqueId());
if (gui == null) if (gui == null)
{ {
return; return;
} }
if (!gui.getName().equalsIgnoreCase(name)) if (!gui.getName().equalsIgnoreCase(name))
{ {
return; return;
} }
Button button = gui.getButton(event.getRawSlot()); Button button = gui.getButton(event.getRawSlot());
event.setCancelled(true); event.setCancelled(true);
event.setResult(Event.Result.DENY); event.setResult(Event.Result.DENY);
if (button == null) if (button == null)
{ {
return; return;
} }
if(button.useItemClick()) if(button.useItemClick())
{ {
button.onClick(player, event.getClick(), event.getCurrentItem()); button.onClick(player, event.getClick(), event.getCurrentItem());
return; return;
} }
button.onClick(player, event.getClick()); button.onClick(player, event.getClick());
} }
@EventHandler @EventHandler
public void onClose(InventoryCloseEvent event) public void onClose(InventoryCloseEvent event)
{ {
String name = event.getInventory().getName(); String name = event.getInventory().getName();
Player player = (Player) event.getPlayer(); Player player = (Player) event.getPlayer();
Menu gui = Menu.get(player.getUniqueId()); Menu gui = Menu.get(player.getUniqueId());
if (gui == null) if (gui == null)
{ {
return; return;
} }
if (!gui.getName().equalsIgnoreCase(name)) if (!gui.getName().equalsIgnoreCase(name))
{ {
return; return;
} }
if(gui.isUseClose()) if(gui.isUseClose())
{ {
gui.onClose(player); gui.onClose(player);
gui.setUseClose(false); gui.setUseClose(false);
} }
} }
@EventHandler
public void onQuit(PlayerQuitEvent event)
{
Menu.remove(event.getPlayer().getUniqueId());
}
} }