mirror of
https://github.com/zDevelopers/ImageOnMap.git
synced 2025-01-05 23:37:43 +01:00
Fixed & enhanced GUI API (blame @IamBlueSlime for bugs).
* NEW: Added another onClick signature with the full event as the last parameter. * NEW: Added a new method triggered when an item is dropped in the inventory GUI (`onItemDeposit`), with various signatures. * BUG: Click triggered on click on a slot with the same raw number on the player inventory (out of the GUI). * BUG: Fixed items ate by the GUI when dragged on it by cancelling all drags on managed inventories.
This commit is contained in:
parent
26d28787be
commit
0a79eee89b
@ -28,7 +28,7 @@ import java.util.*;
|
||||
|
||||
|
||||
/**
|
||||
* @author IamBlueSlime
|
||||
* @author IamBlueSlime, Amaury Carrade
|
||||
*/
|
||||
public abstract class AbstractGui {
|
||||
protected TreeMap<Integer, String> actions = new TreeMap<>();
|
||||
@ -40,6 +40,11 @@ public abstract class AbstractGui {
|
||||
|
||||
public void onClose(Player player) {}
|
||||
|
||||
public void onClick(Player player, ItemStack stack, String action, ClickType clickType, InventoryClickEvent event)
|
||||
{
|
||||
this.onClick(player, stack, action, clickType);
|
||||
}
|
||||
|
||||
public void onClick(Player player, ItemStack stack, String action, ClickType clickType)
|
||||
{
|
||||
this.onClick(player, stack, action);
|
||||
@ -47,7 +52,22 @@ public abstract class AbstractGui {
|
||||
|
||||
public void onClick(Player player, ItemStack stack, String action) {}
|
||||
|
||||
public void setSlotData(Inventory inv, String name, Material material, int slot, String[] description, String action) {
|
||||
|
||||
public void onItemDeposit(Player player, ItemStack stack, ClickType clickType, InventoryClickEvent event)
|
||||
{
|
||||
onItemDeposit(player, stack, clickType);
|
||||
}
|
||||
|
||||
public void onItemDeposit(Player player, ItemStack stack, ClickType clickType)
|
||||
{
|
||||
onItemDeposit(player, stack);
|
||||
}
|
||||
|
||||
public void onItemDeposit(Player player, ItemStack stack) {}
|
||||
|
||||
|
||||
public void setSlotData(Inventory inv, String name, Material material, int slot, String[] description, String action)
|
||||
{
|
||||
this.setSlotData(inv, name, new ItemStack(material, 1), slot, description, action);
|
||||
}
|
||||
|
||||
|
@ -19,6 +19,7 @@
|
||||
package fr.moribus.imageonmap.gui.core;
|
||||
|
||||
import fr.moribus.imageonmap.*;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.entity.*;
|
||||
import org.bukkit.event.*;
|
||||
import org.bukkit.event.inventory.*;
|
||||
@ -26,7 +27,7 @@ import org.bukkit.inventory.*;
|
||||
|
||||
|
||||
/**
|
||||
* @author IamBlueSlime
|
||||
* @author IamBlueSlime, Amaury Carrade
|
||||
*
|
||||
* Changes by Amaury Carrade to use statics (beh, code style, these things).
|
||||
*/
|
||||
@ -40,24 +41,50 @@ public class GuiListener implements Listener {
|
||||
@EventHandler
|
||||
public void onInventoryClick(InventoryClickEvent event)
|
||||
{
|
||||
if (event.getWhoClicked() instanceof Player) {
|
||||
if (event.getWhoClicked() instanceof Player)
|
||||
{
|
||||
Player player = (Player) event.getWhoClicked();
|
||||
AbstractGui gui = GuiManager.getPlayerGui(player);
|
||||
|
||||
if (gui != null) {
|
||||
if (gui != null)
|
||||
{
|
||||
if (event.getInventory() instanceof PlayerInventory)
|
||||
return;
|
||||
|
||||
String action = gui.getAction(event.getSlot());
|
||||
if(event.getRawSlot() == event.getSlot()) // Chest inventory, not player one
|
||||
{
|
||||
|
||||
if (action != null)
|
||||
gui.onClick(player, event.getCurrentItem(), action, event.getClick());
|
||||
if(event.getCursor() != null && event.getCursor().getType() != Material.AIR)
|
||||
{
|
||||
gui.onItemDeposit(player, event.getCursor(), event.getClick(), event);
|
||||
}
|
||||
|
||||
event.setCancelled(true);
|
||||
else
|
||||
{
|
||||
String action = gui.getAction(event.getSlot());
|
||||
|
||||
if (action != null)
|
||||
gui.onClick(player, event.getCurrentItem(), action, event.getClick(), event);
|
||||
}
|
||||
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onInventoryDrag(InventoryDragEvent event)
|
||||
{
|
||||
Player player = (Player) event.getWhoClicked();
|
||||
AbstractGui gui = GuiManager.getPlayerGui(player);
|
||||
|
||||
if (gui != null)
|
||||
{
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onInventoryClose(InventoryCloseEvent event)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user