Fixing hotbar

This commit is contained in:
William Burns 2015-12-29 15:19:09 +00:00
parent 08b5e7b4db
commit f1c7424939

View File

@ -1,11 +1,19 @@
package nautilus.game.arcade.game.games.gladiators.hotbar;
import org.bukkit.Material;
import org.bukkit.entity.Item;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryAction;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.player.PlayerDropItemEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.PlayerInventory;
import mineplex.core.common.util.C;
import mineplex.core.itemstack.ItemBuilder;
/**
* Created by William (WilliamTiger).
@ -29,12 +37,25 @@ public class HotbarPageListener implements Listener
if (e.getCurrentItem() == null)
return;
if (e.getAction().equals(InventoryAction.HOTBAR_SWAP) || e.getAction().equals(InventoryAction.HOTBAR_MOVE_AND_READD)){
e.setCancelled(true);
return;
}
if (e.getClick().isShiftClick())
{
e.setCancelled(true);
return;
}
System.out.println(e.getClickedInventory().getName() + " : " + e.getInventory().getName());
// if ((e.getSlot() > 8 && e.getSlot() < 18))
// {
// e.setCancelled(false);
// return;
// }
if (e.getCurrentItem().getType().equals(Material.REDSTONE_BLOCK))
{
e.setCancelled(true);
@ -42,11 +63,21 @@ public class HotbarPageListener implements Listener
return;
}
if (e.getClickedInventory() instanceof PlayerInventory || e.getInventory() instanceof PlayerInventory){
e.setCancelled(true);
return;
}
if (e.getCurrentItem().getType().equals(Material.EMERALD_BLOCK))
{
if (e.getAction().equals(InventoryAction.SWAP_WITH_CURSOR)){
e.setCancelled(true);
return;
}
e.setCancelled(true);
e.getWhoClicked().closeInventory();
_editor.saveLayout(((Player)e.getWhoClicked()), e.getClickedInventory());
_editor.saveLayout(((Player) e.getWhoClicked()), e.getClickedInventory());
return;
}
@ -56,15 +87,57 @@ public class HotbarPageListener implements Listener
return;
}
if (e.getAction().equals(InventoryAction.PLACE_ALL)
|| e.getAction().equals(InventoryAction.PLACE_ONE)
|| e.getAction().equals(InventoryAction.PLACE_SOME))
{
if (!(e.getAction().equals(InventoryAction.PICKUP_ONE) || e.getAction().equals(InventoryAction.PLACE_ONE))){
if (!(e.getSlot() > 8 && e.getSlot() < 18))
{
e.setCancelled(true);
return;
}
return;
}
// if (e.getAction().equals(InventoryAction.PLACE_ALL)
// || e.getAction().equals(InventoryAction.PLACE_ONE)
// || e.getAction().equals(InventoryAction.PLACE_SOME))
// {
// if (!(e.getSlot() > 8 && e.getSlot() < 18))
// {
// e.setCancelled(true);
// return;
// }
// }
}
@EventHandler(priority = EventPriority.MONITOR)
public void onDrop(PlayerDropItemEvent e){
if (e.getPlayer().getOpenInventory() == null)
return;
if (e.getPlayer().getOpenInventory().getTopInventory() == null)
return;
if (!e.getPlayer().getOpenInventory().getTopInventory().getName().equals("Hotbar Editor"))
return;
if (!e.isCancelled())
return;
e.setCancelled(false);
Item i = e.getItemDrop();
Inventory inv = e.getPlayer().getOpenInventory().getTopInventory();
if (i.getItemStack().getType().equals(Material.EMERALD_BLOCK))
inv.setItem(30, new ItemBuilder(Material.EMERALD_BLOCK).setTitle(C.cGreen + C.Bold + "Save").setLore(C.cGray + "Click to save layout.").build());
else if (i.getItemStack().getType().equals(Material.REDSTONE_BLOCK))
inv.setItem(32, new ItemBuilder(Material.REDSTONE_BLOCK).setTitle(C.cRed + C.Bold + "Cancel").setLore(C.cGray + "Click to cancel layout.").build());
else
inv.addItem(i.getItemStack());
e.getPlayer().updateInventory();
e.getPlayer().setItemOnCursor(null);
i.remove();
}
}