Getting player selection

Discussion in 'Plugin Development' started by Shzylo, Aug 11, 2013.

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

    Shzylo

    I have make a region selector for a minigame I am working on with a tutorial by sothatsit (link) and I am trying to get to see if both points are set in another class, this always sends me the message "Both points are not set"

    Code:java
    1. ExtremePaintball plugin;
    2. Player p;
    3. Selection selection;
    4.  
    5. public CmdCreateArena(ExtremePaintball instance) {
    6. this.plugin = instance;
    7. }
    8.  
    9. @Override
    10. public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    11. if (sender instanceof Player) {
    12. p = (Player) sender;
    13. selection = new Selection(p.getName());
    14. if (!selection.areBothPointsSet()) {
    15. p.sendMessage("Both points aren't set.");
    16. } else
    17. p.sendMessage("Yay");
    18. } else
    19. sender.sendMessage(plugin.ERR_NOT_PLAYER);
    20. return false;
    21. }


    I think it is caused by: selection = new Selection(p.getName()); but I am not sure
     
  2. Offline

    chasechocolate

    It's because you are re-instantiating it each time a player runs the command, which will probably make .areBothPointsSet() return false.
     
  3. Offline

    Shzylo

    I was thinking that but I wasn't exactly sure, do you know of a better method to doing this? (If you need more code I will post it).
     
Thread Status:
Not open for further replies.

Share This Page