#InventoryOpenEvent help!
1 messages · Page 1 of 1 (latest)
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 ❤️
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
Add the chest to a set called open chests
Actually before this, check if this set contains the chest
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
iam not home ..
Are you looking to see if a player is near a chest?
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] .
@past stag
Do you know which chest is the middle chest?
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?
So the first player to open any of the centre chests?
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
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
What is ultragamechest?
its the center chest
Can i see the class?
Can you screenshot it?
yes
there as an api
to get the chest by location
would that help?
get Chest by location?
not sure if its correct
If holder is null or not a chest
Return
Check if! (holder instanceof Chest)
@past stag
Also add (ignoreCancelled=true) to the @chilly ginkgotHandler
Check that it's not null
xd?
Actually not necessary
Right so define a boolean outside the method called firstCenterChestOpened
Make the default value false
Make it private
alr
Do ctrl + alt + L
done
Next iterate the centre chests
Before this, do Chest chest = holder
Cast the holder
ok so there is 2 method to get the center
Map<Location, UltraGameChest> invs = center.getInvs();
first is this
and second one is
centre.GetChests for loop
alright
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
No
Not type
Location.getBlock.equals(chest.getBlock);
If that's true, a centre chest was opened
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