#InventoryOpenEvent help!

1 messages · Page 1 of 1 (latest)

past stag
#

Hello , iam trying a very simple thing , but really hard to do :
1- check for specfic chest to open .
2- check for only first player that opned the chest.

#

this is my code for now .

#

not working ..

#

i didnt find a good way , to check for the specfic chest that being open

#

so i figured that i can check the location , and if player is far from it , then it will not work

#

if player near the location of chest

#

it should work

#

but the code still not working ..

#

i will go out now , if you know a fix or something that can help please mention me here ❤️

lunar gorge
#

You wanna check if a specific chest is being opened?

#

@past stag

#

Listen to inventory open event

#

Get the inventory

#

Get the holder

#

If the holder is not null, check if it is Chest

#

If it is chest, cast the holder to Chest

lunar gorge
lunar gorge
#

If it contains it, that means the chest was already opened, if it doesn't it means that the chest is being opened for the first time

past stag
#

iam not home ..

past stag
lunar gorge
#

Are you looking to see if a player is near a chest?

past stag
#

no , that was a semi fix

#

i want to check if he open a center chest [if the first player only do that , then continue the code and reward him with the code i set] .

lunar gorge
#

@past stag

past stag
#

yes

#

iam trying to add this :

lunar gorge
#

Do you know which chest is the middle chest?

past stag
#

only event part stuck at

#

yes there is a way to get locations

#

for the middle chest

#

(Location chest : game.getCenter().getChests()

#

its a list of locations

#

and i also can do

#

this one

#

i think this is better?

lunar gorge
#

So the first player to open any of the centre chests?

past stag
#

yes

#

only the first player

#

i just want to know the best way of making it , and without breaking other guis / plugins

#

bcz this event triggered when i open any gui

lunar gorge
#

Every time a chest is opened, see if it's one of the centre ones

#

If it is, then a player opened a centre chest

#

And then stop checking

#

For players opening centre chests

#

Since you only need to do it once

past stag
#

here where i am get stuck xd

#

iam only stuck at the checking part

lunar gorge
#

What is ultragamechest?

past stag
#

its the center chest

lunar gorge
#

Can i see the class?

past stag
#

its from UltraSkywars plugin

#

its open source

lunar gorge
#

Can you screenshot it?

past stag
#

yes

#

there as an api

#

to get the chest by location

#

would that help?

#

get Chest by location?

lunar gorge
#

Gonna give you steps

#

Delete the whole method

past stag
#

not sure if its correct

past stag
#

Done

lunar gorge
#

Get the player, inventory and inventory holder

#

And store those

#

In variables

past stag
#

done

lunar gorge
#

If holder is null or not a chest

#

Return

#

Check if! (holder instanceof Chest)

#

@past stag

#

Also add (ignoreCancelled=true) to the @chilly ginkgotHandler

past stag
#

right?

lunar gorge
#

Check that it's not null

past stag
lunar gorge
lunar gorge
past stag
#

changed it

#

ok

#

continue please .

lunar gorge
#

Right so define a boolean outside the method called firstCenterChestOpened

#

Make the default value false

past stag
lunar gorge
#

Make it private

past stag
#

alr

lunar gorge
#

Check if(first Chest Open) then return

#

Make that the first line of listener

past stag
#

full code :

lunar gorge
#

Do ctrl + alt + L

past stag
#

done

lunar gorge
#

Next iterate the centre chests

lunar gorge
#

Cast the holder

past stag
lunar gorge
#

Get the centre chests and iterate

#

Actually no

#

Let me look at what u sent above

past stag
#

ok so there is 2 method to get the center

#

Map<Location, UltraGameChest> invs = center.getInvs();

#

first is this

#

and second one is

lunar gorge
#

centre.GetChests for loop

past stag
#

alright

lunar gorge
#

Then check if each location.getBlock.equals(chest.getBlock)

#

If it is, that means a centre chest was opened

#

So set firstChestOpened to true and reward ur player

past stag
#

oh i got it

#

oh my god iam so stupid

#

like so right?

lunar gorge
#

Not type

#

Location.getBlock.equals(chest.getBlock);

#

If that's true, a centre chest was opened

past stag
#

alr let me test

#

last test , and i go study .. i have an exam i didn't study

#

omg i found it thanks!

#

you are a life saver

#

the problem was i wasn't checking if the chest is center

#

now its works fine , i will add the quest code

#

Thank you for helping , i still have 1 challenge to do , its also related to inventory that player open xd