#prevent pdc item from being put in container
1 messages · Page 1 of 1 (latest)
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
cancel the movement between comtainers
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
yea but every time i try it always becomes buggy
so
im currently using the inventory click event and inventory drag event
replace the item I. cursor with air
then that will delete the item ?
ive tried that in like 82000 different ways but none of them work
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
@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
ok ok kinda works but i cant move it in my inventory and i can still move it to another container with my number keys
@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
there's more events, I just gave you a few
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
just check the docs what other events get triggered by an item moving and can cancel them using the method I gave you
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
gimme a few min making my coffee, the ill take a look at it
alr no worries!
reconstructed ur code
okay
Imma sit in a call while trying to figure this out if you wanna join me xD
gtg to the bathroom for a sec
i cant join the vc rn
my mom needs me to walk my pet
Why are you checking for a cetrain click type
so if its shiftclick i can prevent that
There are so many diff types of clicks
you are only preveting shiftlick
why not prevent all
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
theres a few for intellij
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
imma work on fixing it tho xD
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
maybe check if the movement is in the player inventory
instead of checking the invetnory the plaer is in
?paste
Im giving you the patch, that blocks all item movement, if the player is viewing another inv that isnt theres
https://paste.md-5.net/fokayiraxo.cs
@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
can u send me this version
yeah but i can still move it into a non player inventory with number keys
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;
Copy the marked try catch statment
no
leave that
copy the marked code blocl
it still didnt work when i did that too
in one of them
i didnt see that
so you loop through both inventories
kk
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
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
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");
}```
well I know the issue
it's because we're checking if an soul item is in the players inventory and if so were canceling
AND currentitem?
yes
true but what else can we do
since we cant even detect what their doing if they use number keys
we can
great idea
make an if statment
check if e.getClickType() == InventoryClick.HOTBAR_SWAP
it should be smth like tgat
yeah ive tried that but u acnt even detect what ur hotbar swapping
so that would remove hotbar swapping
you have to check the wiki, what click type get
fore verything
that would disable hot keys in the inventory
check the docs what click type gets triggered by a hotkey
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
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
it gives you packets
oh
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
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?
I'd probably go about editing the source code of spigot if I'd have to fix it, but that would be rather unconventional
You could try, but developers usually do commissions
i might pay someone like $5 to do it because it seems simple
this has been an ongoing problem for way too long
I think I found a fix
but I'm not home rn
I'll take a look when I'm home
9:25 AM
alr