Help With accessing player outside event

Discussion in 'Plugin Development' started by lrdemolition, Aug 15, 2014.

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

    lrdemolition

    so...
    i have a player interact event and inside it a cast for the player name.
    i need to access the players name from a method outside of the event.
    here is the basics of my code:



    public void sclick (PlayerInteractEvent event){
    Player p = (Player) event.getPlayer();
    blue.add(p.getName());
    teamclear();
    }

    private void teamclear() {
    blue.remove(p);

    }




    i try to declare p public but it cant, its only valid modifier is final.
    please answer and thank you
     
  2. Offline

    Gater12

    lrdemolition
    Make teamclear require a Player parameter.
     
  3. Offline

    lrdemolition

    private void teamclear(p) {
    blue.remove(p);

    }


    like that?
    Gater12
     
  4. Offline

    Gater12

  5. Offline

    lrdemolition

    thanks, so i would probably cast a string to p and use the string?
    Gater12
     
  6. Offline

    AoH_Ruthless

    lrdemolition
    You can't cast a string to a player ... remove the player's name, which is what is stored. That's like trying to cast a cat to a dog.
     
  7. Offline

    lrdemolition

    AoH_Ruthless
    you can by:
    String pi = (String) e.getPlayer().getName();

    but i'm having trouble accessing the string from outside the event(i need the method to use the player name to remove it from a list)
     
  8. Offline

    AoH_Ruthless

    lrdemolition
    You can, but that's useless casting and bad practice because getName() already returns a string...

    You need a global list of players for your team so you can easily add/remove players.
    I think you should start by actually learning Java.
     
  9. Offline

    lrdemolition

    AoH_Ruthless
    which is what i am doing. (i'm 13)
    and i think i have 4 public arraylists at the top of my events class(is that global?)
     
  10. Offline

    AoH_Ruthless

    lrdemolition
    Yes, that is a global variable, known as a field. Fields are generally better as private with getters as accessors, but yes.
     
  11. Offline

    lrdemolition

Thread Status:
Not open for further replies.

Share This Page