Getting Player From Inside Listener

Discussion in 'Plugin Development' started by McStormify, Apr 2, 2013.

Thread Status:
Not open for further replies.
  1. Offline


    I'm working on a plugin to disable drops for specific players. I have an ArrayList<String> containing player names who use the /disabledrops command.

    Here is my event handler. The problem is getting the current user's name. How would I do this?

    1. @EventHandler
    2. public void itemSpawn(ItemSpawnEvent event) {
    3. String playerName = "???";
    5. if (this.plugin.disableDrops.contains(playerName)) {
    6. event.getEntity().remove();
    7. }
    8. }

    Thanks! :D
  2. Offline


    ItemSpawnEvent won't let you get the player, since the item could be spawned from a dispenser, or dropper. If you want to disable player dropping items, use PlayerDropItemEvent:
    1. Player player = event.getPlayer();
    2. String playerName = player.getName();
    McStormify likes this.
  3. Offline


    Haha, I figured this out myself just as this was posted! Thanks for the help regardless :)
  4. Offline


    McStormify I have been looking for how to do this much love guys :)
Thread Status:
Not open for further replies.

Share This Page