Showing SignGUI to user raises error
hoch98 opened this issue · 0 comments
I'm creating a SkyblockCore plugin, which has a function that allows a player (with an island) to invite other players to their island. I'm trying to create a button in a GUI that triggers a SignGUI (which required ProtocolLib), where you can input the name of the player you want to invite to your island! But instead, it showed a "CancelledPacketHandleException"
Full Error:
Unhandled exception occured in onPacketReceiving(PacketEvent) for IronHavenSB net.minecraft.server.v1_16_R3.CancelledPacketHandleException: null [10:15:09] [Netty Server IO #1/ERROR]: Parameters: net.minecraft.server.v1_16_R3.PacketPlayInUpdateSign@13984347[ a=BlockPosition{x=-1, y=76, z=2} b={4MC,,,} ]
API Methods:
VaultAPI
WorldEdit
SpigotAPI
ProtocolLib
I thought it was going to show the SignGUI to a player, where they can type an online player's name, then show a GUI to the player inputted.
InviteIsland class:
`public class InviteIsland {
public InviteIsland(Player p, Main plugin) {
plugin.signMenuFactory
.newMenu(Lists.newArrayList("", "", "", ""))
.reopenIfFail()
.response((player, lines) -> {
if (lines[0] != null) {
if (Bukkit.getPlayer(lines[0]) == null) {
p.sendMessage(ChatColor.RED+"[Iron Haven] >> This player is not online!");
} else {
new InviteGUI(Bukkit.getPlayer(lines[0]), p, plugin);
}
return true;
}
return false; // failure. becaues reopenIfFail was called, menu will reopen when closed.
})
.open(p);
}
}`
InviteGUI class:
`public class InviteGUI {
public static Player invitor;
public InviteGUI(Player victim, Player Invitor, Main plugin) {
invitor = Invitor;
Inventory coopGUI = Bukkit.getServer().createInventory(Invitor, 9, "Accept Island Invite");
// Info Item
ItemStack info = new ItemStack(Material.WITHER_SKELETON_SKULL);
ItemMeta infoMeta = info.getItemMeta();
ArrayList<String> infoLore = new ArrayList<String>();
infoLore.add(ChatColor.GREEN+Invitor.getName()+" has invited you to join their coop!");
infoMeta.setLore(infoLore);
infoMeta.setDisplayName("§6§lInfo");
info.setItemMeta(infoMeta);
coopGUI.setItem(4, info);
// Accept Item
ItemStack acceptItem = new ItemStack(Material.GREEN_CONCRETE);
ItemMeta acceptItemMeta = acceptItem.getItemMeta();
ArrayList<String> acceptItemLore = new ArrayList<String>();
acceptItemLore.add(ChatColor.GREEN+"Accept coop invitation!");
acceptItemMeta.setLore(acceptItemLore);
acceptItemMeta.setDisplayName("§a§lAccept");
acceptItem.setItemMeta(acceptItemMeta);
coopGUI.setItem(2, acceptItem);
// Decline Item
ItemStack declineItem = new ItemStack(Material.RED_CONCRETE);
ItemMeta declineItemMeta = declineItem.getItemMeta();
ArrayList<String> declineItemLore = new ArrayList<String>();
declineItemLore.add(ChatColor.RED+"Decline coop invitation!");
declineItemMeta.setLore(declineItemLore);
declineItemMeta.setDisplayName("§c§lDecline");
declineItem.setItemMeta(declineItemMeta);
coopGUI.setItem(6, declineItem);
//Here opens the inventory
victim.openInventory(coopGUI);
}
}`
Here is my code when a player presses "Accept" or "Decline":
`e.setCancelled(true);
if ((e.getCurrentItem() == null) || (e.getCurrentItem().getType().equals(Material.AIR))) {
return;
}
if (e.getSlot() == 3 && (e.getCurrentItem().getItemMeta().getDisplayName().equalsIgnoreCase("§a§lAccept"))){
new JoinIsland(p, InviteGUI.invitor);
} else if (e.getSlot() == 5 && (e.getCurrentItem().getItemMeta().getDisplayName().equalsIgnoreCase("§c§lDecline"))){
p.sendMessage(ChatColor.RED+"[Iron Haven] >> You declined the coop invitation!");
}`
But the code doesn't even get to opening the GUI for the victim before showing the error.
I followed this tutorial on SignMenus
Also, IDK why github messed up a few of the code lines, but you should be able to piece them together