Skip to content

Commit

Permalink
add Left/Right click handler in custom inventories (menus)
Browse files Browse the repository at this point in the history
  • Loading branch information
HoverEpic committed Jan 31, 2017
1 parent faf0b1a commit 00d85d8
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 52 deletions.
124 changes: 73 additions & 51 deletions src/main/java/dev/wolveringer/bungeeutil/item/ItemStack.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,85 +5,107 @@

public abstract class ItemStack extends Item {

public static class Click {
private Player player;
private int slot;
private Inventory inventory;
private int mode;
private boolean cancel = true;
private Item item;
private boolean sync;
public enum ClickType
{
RIGHT,
LEFT;
}

public static class Click{
private Player player;
private int slot;
private Inventory inventory;
private ClickType clickType = null;
private int mode;
private boolean cancel = true;
private Item item;
private boolean sync;

public Click(Player p, int slot, Inventory inv,Item ci, int mode,boolean sync) {
this.player = p;
this.slot = slot;
this.inventory = inv;
this.mode = mode;
this.item = ci;
this.sync = sync;
}
this.player = p;
this.slot = slot;
this.inventory = inv;
this.mode = mode;
this.item = ci;
this.sync = sync;
}

public Click(Player p, int slot, Inventory inv, Item ci, int mode, ClickType clickType, boolean sync){
this.player = p;
this.slot = slot;
this.inventory = inv;
this.mode = mode;
this.clickType = clickType;
this.item = ci;
this.sync = sync;
}

public Inventory getInventory() {
return this.inventory;
}
return this.inventory;
}

public Item getItem() {
return this.item;
}
return this.item;
}

public int getMode() {
return this.mode;
}

return this.mode;
}

public ClickType getClickType()
{
return this.clickType;
}

public Player getPlayer() {
return this.player;
}
return this.player;
}

public int getSlot() {
return this.slot;
}
return this.slot;
}

@Deprecated
@Deprecated
public boolean isCancelled() {
return this.cancel;
}
return this.cancel;
}

public boolean isSyncHandle() {
return this.sync;
}
return this.sync;
}

@Deprecated
@Deprecated
public void setCancelled(boolean b) {
this.cancel = b;
}
}
this.cancel = b;
}
}

public static enum InteractType {
RIGHT_CLICK,
LEFT_CLICK;
}
RIGHT_CLICK,
LEFT_CLICK;
}

@SuppressWarnings("deprecation")
@SuppressWarnings("deprecation")
public ItemStack(int type, int amount, short damage) {
super(type, amount, damage);
}
super(type, amount, damage);
}

public ItemStack(Item stack) throws IllegalArgumentException {
super(stack);
}
super(stack);
}

public ItemStack(Material type) {
super(type);
}
super(type);
}

public ItemStack(Material type, int amount) {
super(type, amount);
}
super(type, amount);
}

public ItemStack(Material type, int amount, short damage) {
super(type, amount, damage);
}
public abstract void click(Click click);
super(type, amount, damage);
}
public abstract void click(Click click);

public void onInteract(Player player,InteractType type){}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,8 @@ else if(button == 2){
player.updateInventory();
if (player.getInventoryView().isClickable()){
boolean sync = ((CraftItemMeta)is.getItemMeta()).isClickSync() || Configuration.isSyncInventoryClickActive();
handleItemClick(player,is,new Click(player, pl.getSlot(), player.getInventoryView(), pl.getItem(), pl.getMode(), sync),sync,false);
ClickType clickType = button == 0 ? ClickType.LEFT : ClickType.RIGHT;
handleItemClick(player,is,new Click(player, pl.getSlot(), player.getInventoryView(), pl.getItem(), pl.getMode(), clickType, sync),sync,false);
}
Profiler.packet_handle.stop("handleWindowClick");
e.setCancelled(true);
Expand Down

0 comments on commit 00d85d8

Please sign in to comment.