#prevent pdc item from being put in container

1 messages · Page 1 of 1 (latest)

frail brook
#

ive asked so many people, cant figure it otu

#

ive tried so many things dude

#

does anyone have a solution

#

the issue is the item being stopped part

#

wehn i put it in another container it bugs out and stays there

#

or does some other weird sht

dawn zinc
#

cancel the movement between comtainers

dawn zinc
#

add a tag to the item like immovable or smth the. on inventoryxhange event and the 9 thousand other ones check if the item has the PDC value, if it does, can le if it doesn't, leave jt

frail brook
#

so

#

im currently using the inventory click event and inventory drag event

dawn zinc
#

replace the item I. cursor with air

frail brook
#

then that will delete the item ?

frail brook
#

they all are supper buggy

#

like it stops me from moving it in my inventory but sometimes doesnt etc etc

#

Ive asked so many people and even some pretty talented devs couldnt help

#

Older solutions dont work anymore and I don’t know what to do

dawn zinc
#
    @EventHandler 
     public void onInventoryClick(final InventoryClickEvent e) { 
         if (!cancelGUIClicks) return; 
         try { 
             if (!(e.getClickedInventory()).getHolder().toString().toLowerCase().contains("com.bedless.spawnerplus.gui.utils.spinventoryholder")) 
                 return; 
             if (!e.getInventory().getViewers().contains(e.getWhoClicked())) return; 
             e.setCancelled(true); 
             if (!notifyEvents) return; 
             SpawnerPlusEventManager.callGUIClickEvent((Player) e.getWhoClicked(), e.getCurrentItem(), e.getClickedInventory()); 
         } catch (NullPointerException ex) { 
             //Do Nothing, Ignore 
         } 
     } 
  
     @EventHandler 
     public void onInventoryClick(final InventoryDragEvent e) { 
         if (!cancelGUIDrags) return; 
         try { 
             if (!(e.getInventory().getHolder().toString().toLowerCase().contains("com.bedless.spawnerplus.gui.utils.spinventoryholder"))) 
                 return; 
             if (!e.getInventory().getViewers().contains(e.getWhoClicked())) return; 
             e.getCursor().setType(Material.AIR); 
             e.setCancelled(true); 
         } catch (NullPointerException ex) { 
             //Do Nothing, Ignore 
         } 
     }
#

my canceling works fine

frail brook
#

kk lemme try

#

this looks identical to mine but we'll see 😭

frail brook
#
    @EventHandler
    public void onInventoryClick(final InventoryClickEvent e) {
        try {
            if (!isSoulItem(e.getCurrentItem())) return;
            if (!e.getInventory().getViewers().contains(e.getWhoClicked())) return;
            e.setCancelled(true);
        } catch (NullPointerException ex) {
            //Do Nothing, Ignore
        }
    }

    @EventHandler
    public void onInventoryClick(final InventoryDragEvent e) {
        try {
            if (!isSoulItem(e.getCursor())) return;
            if (!e.getInventory().getViewers().contains(e.getWhoClicked())) return;
            e.getCursor().setType(Material.AIR);
            e.setCancelled(true);
        } catch (NullPointerException ex) {
            //Do Nothing, Ignore
        }
    }```
#

this is my implementation

#

do u see anything worng

#

with it

dawn zinc
#

there's more events, I just gave you a few

frail brook
#

yeah but it should allow me to move it in my inventory

#

isnt that what the if (!e.getInventory().getViewers().contains(e.getWhoClicked())) return; is?

#

its not getting emitted

dawn zinc
#

just check the docs what other events get triggered by an item moving and can cancel them using the method I gave you

dawn zinc
frail brook
#

ohh

#

icic

#

alright but

#

how did u go about fixing the number keys?

frail brook
# dawn zinc that checks if the player is viewing the given inventory

okay okay, i have fixed everything but the number keys

when i use them i can still put it in the other container

    @EventHandler
    public void onClick(InventoryClickEvent event) {
        ItemStack currentItem = event.getCurrentItem();
        if (currentItem == null) return;

        ItemStack cursor = event.getCursor();
        if (cursor == null) return;

        Inventory clickedInventory = event.getClickedInventory();
        if (clickedInventory == null ) return;

        Player player = (Player) event.getWhoClicked();

        if (event.getClick().isShiftClick()) {
            if (clickedInventory == player.getInventory()) {

                if (currentItem != null && (isSoulItem(currentItem))) {
                    event.setCancelled(true);
                }
            }
        }

        if (clickedInventory != player.getInventory()) {
            ItemStack onCursor = event.getCursor();

            if ((isSoulItem(onCursor))){
                event.setCancelled(true);
            }
        }
    }

    @EventHandler
    public void onInventoryDrag(InventoryDragEvent event) {
        ItemStack dragged = event.getOldCursor();

        if (isSoulItem(dragged)) {
            int inventorySize = event.getInventory().getSize();

            for (int i : event.getRawSlots()) {
                if (i < inventorySize) {
                    event.setCancelled(true);
                    break;
                }
            }
        }
    }```
#

this is my code

#

i still acnt figure out how to prevent number keys

#

everything works besides that

dawn zinc
#

gimme a few min making my coffee, the ill take a look at it

frail brook
#

alr no worries!

dawn zinc
#

reconstructed ur code

frail brook
#

okay

dawn zinc
#

Imma sit in a call while trying to figure this out if you wanna join me xD

frail brook
#

kk

#

i will gimme sec

dawn zinc
#

What inventory are you checking fore

#

found it already

frail brook
#

gtg to the bathroom for a sec

#

i cant join the vc rn

#

my mom needs me to walk my pet

dawn zinc
#

Foudn the Issue

frail brook
#

OH

#

what

dawn zinc
#

Why are you checking for a cetrain click type

frail brook
#

so if its shiftclick i can prevent that

dawn zinc
#

There are so many diff types of clicks

#

you are only preveting shiftlick

#

why not prevent all

frail brook
#

true

#

yeah but even when i dont do that

#

it still doesnt prevent number key

#

the reason being

#

is because

#

number keying items

#

returns air

#

on botrh current item

#

and cursor

frail brook
dawn zinc
#

theres a few for intellij

frail brook
#

or are u using their website

#

i gotta walk my pet

dawn zinc
#

Good thing

#

ive blocked hotkeys

#

but that include blocking any action with the item xD

#

You can move the item whie in the player Inventory

#

but not while in a chest

frail brook
#

i think thats fine lol

#

but its not preferred

dawn zinc
#

imma work on fixing it tho xD

frail brook
#

okay thanks dude

#

ur a lifesaver

#

its been a year im not kiding

dawn zinc
#

The way im doing it, is im checking the Inventory Holder, if the inventory has been registered by a Player, i ignore im going to ignore the cancel, if its a inventory registered by an external source or a blokc like a chest, im going to suppres the moving

frail brook
#

maybe check if the movement is in the player inventory

#

instead of checking the invetnory the plaer is in

dawn zinc
#

?paste

dim lindenBOT
dawn zinc
#

@frail brook

frail brook
#

im in hte vc

#

nice

#

thanks

#

1sec

#

thanks for doing that, message me if u find a way to allow the player to move it in their inv while viewing a container

#

number keys still allow u to move it in another container

#

wait nvm

#

wait yeah

#

it does

#

F

#

sad

frail brook
dawn zinc
#

you already have it

#

when you're in the player inventory, you can move the item

frail brook
dawn zinc
#

What

#

it didn't work for me

#

I found issue

frail brook
#

you found it?

#

what is it

#

on the inventorymoveitem event it never triggers in my experience

#

maybe thats it?

#

and yes i removed the if(event.getInventory().getHolder().toString().toLowerCase().contains("craftplayer{name=")) return;

dawn zinc
#

Copy the marked try catch statment

frail brook
#

it was buggy when i had it

#

but ok

dawn zinc
#

copy the marked code blocl

frail brook
#

it still didnt work when i did that too

dawn zinc
#

and replace e. getInventory

#

with e. get clicked inventory

frail brook
#

OHH

#

damn

dawn zinc
#

in one of them

frail brook
#

i didnt see that

dawn zinc
#

so you loop through both inventories

frail brook
#

kk

dawn zinc
#

that issue with removing the if you removed, wouldn't allow moving the item at all, not even in the players inv, when there not in a container

frail brook
#

now with changing it to getClickedInventory

#

it literally doesnt allow me to move anything at all even if it isnt soulitem

#

and i can still move it with numberkeys

dawn zinc
#

yep

#

idk what you broke.
.

frail brook
#

heres my code

#
    @EventHandler
    public void onClick(InventoryClickEvent event) {
        ItemStack currentItem = event.getCurrentItem();
        if (currentItem == null) return;

        ItemStack cursor = event.getCursor();
        if (cursor == null) return;

        Inventory clickedInventory = event.getClickedInventory();
        if (clickedInventory == null ) return;


        if(event.getInventory().getHolder().toString().toLowerCase().contains("craftplayer{name=")) return;
        try {
            for (ItemStack item : event.getClickedInventory()) {
                if (isSoulItem(item)) event.setCancelled(true);
            }
        } catch (NullPointerException ex) {

        }
        if (currentItem != null && (isSoulItem(currentItem))) {
            event.setCancelled(true);
        }
        ItemStack onCursor = event.getCursor();
        if ((isSoulItem(onCursor))){
            event.setCancelled(true);
        }
    }

    @EventHandler
    public void onInventoryDrag(InventoryDragEvent event) {
        ItemStack dragged = event.getOldCursor();
        if (isSoulItem(dragged)) {
            int inventorySize = event.getInventory().getSize();
            for (int i : event.getRawSlots()) {
                if (i < inventorySize) {
                    event.setCancelled(true);
                    break;
                }
            }
        }
    }

    @EventHandler
    public void onItemInventoryChangeEvent(InventoryMoveItemEvent event){
        if(isSoulItem(event.getItem())) {
            Bukkit.getConsoleSender().sendMessage("triggered inventory change event | is item");
            event.setCancelled(true);
            return;
        }

        Bukkit.getConsoleSender().sendMessage("triggered inventory change event | no item");
    }```
dawn zinc
#

well I know the issue

frail brook
#

when u use number keys it returns air

#

on

#

cursor

dawn zinc
#

it's because we're checking if an soul item is in the players inventory and if so were canceling

frail brook
#

AND currentitem?

dawn zinc
#

yes

frail brook
#

since we cant even detect what their doing if they use number keys

dawn zinc
#

we can

#

great idea

#

make an if statment

#

check if e.getClickType() == InventoryClick.HOTBAR_SWAP

#

it should be smth like tgat

frail brook
#

yeah ive tried that but u acnt even detect what ur hotbar swapping

#

so that would remove hotbar swapping

dawn zinc
#

you have to check the wiki, what click type get

frail brook
#

fore verything

dawn zinc
#

that would disable hot keys in the inventory

#

check the docs what click type gets triggered by a hotkey

frail brook
#

its hotbarswap

#

u were right

dawn zinc
#

put that around that if statement around the try and catch statments

#

so it will block hot key, if there is an soul item in the invebtory

frail brook
#

im kinda tryna not do that though

#

because the player will always have a soul item and i use the hotkey thing alot

#

wait

#

wahts that one api

#

protocol lib

#

doesnt it like make spigot better or smt

dawn zinc
#

it gives you packets

frail brook
#

oh

dawn zinc
#

if you add the if statement, it will only block the hot keys while you are viewing another inventory

#

you can move it without a problem if you are in ur own inv

frail brook
#

do u think if i payed you or someone else some money, you or they could fix my problem and figure out a way to not do that?

dawn zinc
#

I'd probably go about editing the source code of spigot if I'd have to fix it, but that would be rather unconventional

dawn zinc
frail brook
#

i might pay someone like $5 to do it because it seems simple

#

this has been an ongoing problem for way too long

dawn zinc
#

I think I found a fix

frail brook
#

what

#

ok

#

i hate dynamically typed languages because im used to static ones 💀

dawn zinc
#

but I'm not home rn

frail brook
#

explain it to me

#

i could write it

dawn zinc
#

I'll take a look when I'm home

frail brook
#

alr

#

what time is it for u btw

dawn zinc
#

9:25 AM

frail brook
#

alr

dawn zinc
#

my fix sdidnt work

#

rip

#

ur gna have to work wiht what you have