[SPIGOT-4840] Cartography Table inventory not returned for InventoryClickEvent.getClickedInventory on result slot Created: 02/May/19  Updated: 05/May/19  Resolved: 04/May/19

Status: Resolved
Project: Spigot
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Minor
Reporter: Christopher Borchert Assignee: Unassigned
Resolution: Fixed Votes: 0
Labels: 1.14, bug, event, spigot

Version: This server is running CraftBukkit version git-Spigot-1eece4f-d5c2e3c (MC: 1.14) (Implementing API version 1.14-R0.1-SNAPSHOT)
Guidelines Read: Yes

 Description   

I'm writing on a map plugin, to deny copyright protected maps. The maps have a lore and if the lore is on the map, it couldn't be copied.

 

This works fine with the Player-Crafting Inventory and the Workbench Inventory. On click onto the map in the Result slot, I can cancel the event. But this doesn't works with the Cartography Table.

If I check every Slot of the Cartography Table and first put the filled map in and then the empty map, the event will be canceled. If I put first an empty map in and then the filled map, the event wouldn't be canceled and I can click on the Result Slot and get the maps copied.

 

if(e.getClickedInventory().getItem(0) != null) {
	if(e.getClickedInventory().getItem(0).hasItemMeta()) {
		ItemMeta iMeta = e.getClickedInventory().getItem(0).getItemMeta();
		if(iMeta.hasLore()) {
			List<String> iLore = e.getClickedInventory().getItem(0).getItemMeta().getLore();
			String str = ChatColor.stripColor(String.valueOf(iLore));
			String original = "Original";
			String copy = "Copy";
							
			if(str.contains(original) || str.contains(copy)) {
				e.setCancelled(true);
				p.closeInventory();
				p.sendMessage("Can not be copied");
				return;
			}
		}
	}
}


 Comments   
Comment by Christopher Borchert [ 05/May/19 ]

Thanks, works fine now. 

Comment by md_5 [ 04/May/19 ]

Bug fixed in identifying inventory / slots.

The following now works:

        if ( e.getClickedInventory() instanceof CartographyInventory && e.getSlot() == 2 )
        {
            e.getWhoClicked().sendMessage( "Cannot remove maps from cartography table" );
            e.setCancelled( true );
        } 
Comment by Christopher Borchert [ 04/May/19 ]

Can you open the ticket again or should I have to open a new ticket again for the given problem, that the Cartography table not reacting on the InventoryClickEvent?

Comment by Christopher Borchert [ 04/May/19 ]

Thanks for your answer. Okay, I tried it.

Clicked on the first Inputslot (Slot 0) = Message Output 0
Clicked on the second Inputslot (Slot 1) = Message Output 1
Clicked in the Resultslot (As you sayed Slot 9) = No Output in Chat.

And thats exactly what I mean. The Resultslot of the CARTOGRAPHY TABLE reacting not on the InventoryClickEvent.

Comment by md_5 [ 04/May/19 ]

A simple getServer().broadcastMessage( e.getSlot() + "" ); reveals the slots as 0, 1, 9 from left to right.

Comment by Christopher Borchert [ 03/May/19 ]

I know, but I found no other documentation of wihch slot has which number at the moment.

Comment by md_5 [ 03/May/19 ]

That wiki is not Spigot documentation....

Comment by Christopher Borchert [ 03/May/19 ]

Here is the link again:
https://wiki.vg/index.php?title=Pre-release_protocol&oldid=14723#Cartography_Table

 

Okay, if a palyer wants top copy a map witch has a lore of "Original" or "Copy", I want prevent him to copy this map. And with this code, I want to check, if in the Crafting/Workbench/Cartography Inventory is placed a filled map with this lore and an empty map and by clicking on the result slot, the event should be cancelled.

 

In the CRAFTING inventory and thw workbench inventory, it works fine, but with the CRAFTING inventory, it would be ignored and the player gets the copy.

Comment by md_5 [ 03/May/19 ]

Your documentation link is dead.

I'm also confused as to what the actual bug is vs your code potentially just not being correct.

Comment by Christopher Borchert [ 02/May/19 ]

Like in the documentation it should be slot 2, but I've tested it several times and it must be slot 0. Maybe this is the problem?

 

Generated at Tue Apr 22 04:20:16 UTC 2025 using Jira 10.3.5#10030005-sha1:190c783f2bd6c69cd5accdb70f97e48812a78d14.