Penguin
December 28, 2015, 5:38pm
1
Hi !
I’m a newbie on Sponge and I’d like to develop a plugin that will use a lock system. For the algorithm I thought about, I would need to browse the inventory of the player to get a few informations, but doing so requires getting a Player object from the event, is there a way to do this?
Thank you !
You need to get the event cause. There is 2 examples over here
Like in other events you can query the cause for certain types.
To see if a player caused the death, you do:
@Listener
public void onEntityDeath(DestructEntityEvent.Death event) {
Optional<Player> optPlayer = event.getCause().first(Player.class);
if (optPlayer.isPresent()) {
Player player = optPlayer.get();
// The player caused the entity to die
} else {
// The entity died from a non-player cause
}
}
You can also use the new event filtering
@Listener
p…
On a related note the inventory api isn’t ready so you’re going to hit a brick wall until it’s been implemented.
Penguin
December 28, 2015, 7:43pm
4
Thanks a lot for your quick answer, I will try this and let you know
Penguin
December 28, 2015, 9:59pm
5
It works, thank you very much !