[SOLVED] Clear inventory & setLocation

Hi guys!

I already ask a question on this forum and I got a lot of good answers so I try get some help again :slightly_smiling:

I’m trying to do my own HungerGame plugin and I’m looking for a way to clean the inventory (in the case someone successfully dropped an item, what shouldn’t be possible because I should have cancelled the event :slightly_smiling: ) and a way to spawn the players on a circle shape (if I’m not writing clearly, say it… I’m French).

My issue is that player.getInventory().clear(); isn’t working well. I might do something wrong so I tried to find an answer but I didn’t.

To come back on my spawn issue, I would use a circle equation with a for loop but I don’t understand how the player.setLocation(); works… Is there a way to do setLocation(x, y, z); ?

EDIT : The source code can be found here!

setLocation takes a Location object from the SpongeAPI.
It represents an Extent and a position in that extent.
Try this:

player.setLocation(player.getLocation().setPosition(position));

position represents a Vector3d or Vector3i, you can create them by doing new Vector3d(x, y, z)

Thanks to reply so fast!

I was thinking setPosition() would set the direction the players was looking to :slightly_smiling:
I try this now.

Out of the topic: I developed timers using Thread… I read it can be a bad idea using the API.

There’s a method setRotation which will set the direction the player is looking

You may be interested in the Scheduler API in Sponge, https://docs.spongepowered.org/en/plugin/scheduler.html

Hi. Thank you for your reply :slightly_smiling:

On your advice, I used this: player.setLocation(player.getLocation().setPosition(position)); and it works… But after the players spawn, they get back to their previous location. Does it come from the fact I use Thread? I didn’t use Scheduler API yet.
You can find the code on the Git Repository linked to the first post (I can add a GitHub Repository if needed), I think it’s more handy to do like this, and let you post the wrong code :wink:

EDIT : And I still didn’t fix the player.getInventory().clear(); issue.

Hi.
With the 3.0.0 version of the SpongeAPI, I successfully cleaned the player’s inventory! But the spawn is still cancelled… Does it link with the fact I use Thread (according to you)? :slightly_smiling:
EDIT: I finally use the scheduler way to run the task but, maybe because I’m very tired, I don’t find anyway to do it a specific amount of times… I mean I don’t want it to be run all seconds. It should stop to be call when the countdown is finish.
EDIT 2: I create a new topic about this issue. This one isn’t about it :smile:

1 Like