mirror of
https://github.com/zDevelopers/ImageOnMap.git
synced 2024-11-10 20:40:16 +01:00
Improved the GUI API.
* BUG: Fixed players unable to shift-click an item from the player inventory to the GUI. * NEW: Added a direct access to the InventoryAction in the methods. * OPT: Code style, avoiding too many nested blocs. * OPT: Raw types in the class attributes (meh @IamBlueSlime).
This commit is contained in:
parent
9084d28401
commit
c738359d2e
@ -40,7 +40,12 @@ public abstract class AbstractGui {
|
|||||||
|
|
||||||
public void onClose(Player player) {}
|
public void onClose(Player player) {}
|
||||||
|
|
||||||
public void onClick(Player player, ItemStack stack, String action, ClickType clickType, InventoryClickEvent event)
|
public void onClick(Player player, ItemStack stack, String action, ClickType clickType, InventoryAction invAction, InventoryClickEvent event)
|
||||||
|
{
|
||||||
|
this.onClick(player, stack, action, clickType, invAction);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onClick(Player player, ItemStack stack, String action, ClickType clickType, InventoryAction invAction)
|
||||||
{
|
{
|
||||||
this.onClick(player, stack, action, clickType);
|
this.onClick(player, stack, action, clickType);
|
||||||
}
|
}
|
||||||
@ -53,7 +58,12 @@ public abstract class AbstractGui {
|
|||||||
public void onClick(Player player, ItemStack stack, String action) {}
|
public void onClick(Player player, ItemStack stack, String action) {}
|
||||||
|
|
||||||
|
|
||||||
public void onItemDeposit(Player player, ItemStack stack, ClickType clickType, InventoryClickEvent event)
|
public void onItemDeposit(Player player, ItemStack stack, ClickType clickType, InventoryAction invAction, InventoryClickEvent event)
|
||||||
|
{
|
||||||
|
onItemDeposit(player, stack, clickType, invAction);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onItemDeposit(Player player, ItemStack stack, ClickType clickType, InventoryAction invAction)
|
||||||
{
|
{
|
||||||
onItemDeposit(player, stack, clickType);
|
onItemDeposit(player, stack, clickType);
|
||||||
}
|
}
|
||||||
|
@ -46,17 +46,30 @@ public class GuiListener implements Listener {
|
|||||||
Player player = (Player) event.getWhoClicked();
|
Player player = (Player) event.getWhoClicked();
|
||||||
AbstractGui gui = GuiManager.getPlayerGui(player);
|
AbstractGui gui = GuiManager.getPlayerGui(player);
|
||||||
|
|
||||||
if (gui != null)
|
if(gui == null)
|
||||||
{
|
return;
|
||||||
|
|
||||||
if (event.getInventory() instanceof PlayerInventory)
|
if (event.getInventory() instanceof PlayerInventory)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if(event.getRawSlot() == event.getSlot()) // Chest inventory, not player one
|
|
||||||
|
/* *** Click from player inventory (with shift) *** */
|
||||||
|
|
||||||
|
if(event.getRawSlot() != event.getSlot())
|
||||||
{
|
{
|
||||||
|
if(event.isShiftClick())
|
||||||
|
{
|
||||||
|
gui.onItemDeposit(player, event.getCurrentItem(), event.getClick(), event.getAction(), event);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* *** Click on the “chest” *** */
|
||||||
|
|
||||||
if(event.getCursor() != null && event.getCursor().getType() != Material.AIR)
|
if(event.getCursor() != null && event.getCursor().getType() != Material.AIR)
|
||||||
{
|
{
|
||||||
gui.onItemDeposit(player, event.getCursor(), event.getClick(), event);
|
gui.onItemDeposit(player, event.getCursor(), event.getClick(), event.getAction(), event);
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
else
|
||||||
@ -64,14 +77,12 @@ public class GuiListener implements Listener {
|
|||||||
String action = gui.getAction(event.getSlot());
|
String action = gui.getAction(event.getSlot());
|
||||||
|
|
||||||
if (action != null)
|
if (action != null)
|
||||||
gui.onClick(player, event.getCurrentItem(), action, event.getClick(), event);
|
gui.onClick(player, event.getCurrentItem(), action, event.getClick(), event.getAction(), event);
|
||||||
}
|
}
|
||||||
|
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onInventoryDrag(InventoryDragEvent event)
|
public void onInventoryDrag(InventoryDragEvent event)
|
||||||
|
@ -31,7 +31,8 @@ import java.util.concurrent.*;
|
|||||||
* Changes by Amaury Carrade to use statics (beh, code style, these things).
|
* Changes by Amaury Carrade to use statics (beh, code style, these things).
|
||||||
*/
|
*/
|
||||||
public class GuiManager {
|
public class GuiManager {
|
||||||
protected static ConcurrentHashMap<UUID, AbstractGui> currentGUIs;
|
|
||||||
|
protected static Map<UUID, AbstractGui> currentGUIs;
|
||||||
|
|
||||||
public static void init(ImageOnMap plugin)
|
public static void init(ImageOnMap plugin)
|
||||||
{
|
{
|
||||||
@ -72,7 +73,7 @@ public class GuiManager {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ConcurrentHashMap<UUID, AbstractGui> getPlayersGui()
|
public static Map<UUID, AbstractGui> getPlayersGui()
|
||||||
{
|
{
|
||||||
return currentGUIs;
|
return currentGUIs;
|
||||||
}
|
}
|
||||||
|
@ -189,7 +189,7 @@ public class MapListGui extends AbstractGui {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onItemDeposit(Player player, ItemStack stack, ClickType clickType, InventoryClickEvent ev) {
|
public void onItemDeposit(Player player, ItemStack stack, ClickType clickType, InventoryAction invAction, InventoryClickEvent ev) {
|
||||||
ev.setCancelled(true);
|
ev.setCancelled(true);
|
||||||
|
|
||||||
if (stack.getType() == Material.MAP && MapManager.managesMap(stack))
|
if (stack.getType() == Material.MAP && MapManager.managesMap(stack))
|
||||||
|
Loading…
Reference in New Issue
Block a user