Last active
July 18, 2019 20:21
-
-
Save WouterG/ab86eb91e941be13fc4e3400ddef00dd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import net.menoni.rd.RuntimeDebugger; | |
import net.menoni.rd.model.Debugger; | |
import org.bukkit.command.CommandSender; | |
import org.bukkit.entity.HumanEntity; | |
import org.bukkit.event.EventHandler; | |
import org.bukkit.event.Listener; | |
import org.bukkit.event.inventory.InventoryClickEvent; | |
import org.bukkit.inventory.ItemStack; | |
public class CheckInventoryClickEvents implements Listener, Debugger, Debugger.Stoppable { | |
@Override | |
public void debug(RuntimeDebugger plugin, CommandSender cs) { | |
} | |
@Override | |
public void stop() { | |
} | |
@EventHandler | |
public void onInventoryClick(InventoryClickEvent clickEvent) { | |
HumanEntity p = clickEvent.getWhoClicked(); | |
msg(p, "[ click event ]", 0); | |
printItemStack(p, clickEvent.getCurrentItem(), "currentItem"); | |
printItemStack(p, clickEvent.getCursor(), "cursor"); | |
msg(p, "click: %s", 0, clickEvent.getClick().name()); | |
msg(p, "action: %s", 0, clickEvent.getAction().name()); | |
msg(p, "slotType: %s", 0, clickEvent.getSlotType().name()); | |
msg(p, "result: %s", 0, clickEvent.getResult().name()); | |
String name = ""; | |
if (clickEvent.getClickedInventory() == clickEvent.getView().getTopInventory()) { | |
name = "topView"; | |
} else if (clickEvent.getClickedInventory() == clickEvent.getView().getBottomInventory()) { | |
name = "bottomView"; | |
} else { | |
name = clickEvent.getClickedInventory().toString(); | |
} | |
msg(p, "inventory type: %s", 0, name); | |
} | |
private void printItemStack(CommandSender p, ItemStack is, String name) { | |
if (is == null) { | |
msg(p, "%s: item: null", 0, name); | |
return; | |
} | |
msg(p, "%s: item: {", 0, name); | |
msg(p, "type: %s", 1, is.getType()); | |
if (is.hasItemMeta()) { | |
msg(p, "name: %s", 1, is.getItemMeta().getDisplayName()); | |
} | |
msg(p, "}", 0); | |
} | |
private void msg(CommandSender p, String msg, int pad, Object... args) { | |
if (args != null && args.length > 0) { | |
msg = String.format(msg, args); | |
} | |
for (int i = 0; i < pad; i++) { | |
msg = " " + msg; | |
} | |
p.sendMessage(msg); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment