Solved Settings I have saved return null when called

Discussion in 'Plugin Development' started by Pacothegint, Dec 8, 2014.

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

    Pacothegint

    In my plugin when a player joins I get their name, rank, and the prefix of that rank.
    Code:java
    1. public void onEnity(PlayerJoinEvent event){
    2. Player p = event.getPlayer();
    3. String name = p.getName();
    4. Profile profile = new Profile(p.getUniqueId(), f, yml);
    5. String rank = plugin.permission.getPrimaryGroup(p);
    6. String prefix = plugin.chat.getPlayerPrefix(p);
    7. profile.setName(name);
    8. profile.setRank(rank);
    9. profile.setPrefix(prefix);
    10.  
    11. }

    Now when I try to call that data I get null

    Code:java
    1. public void onSignchange(SignChangeEvent event){
    2. Player placer = event.getPlayer();
    3. String playername = event.getLine(0);
    4. placer.sendMessage(playername);
    5. Player target = Bukkit.getPlayerExact(playername);
    6. placer.sendMessage("getting target");
    7. Profile profile = new Profile(target.getUniqueId(), f, yml);
    8. String rank = profile.getRank();
    9. placer.sendMessage(rank);
    10. String prefix = profile.getPrefix();
    11. placer.sendMessage(prefix);
    12. event.setLine(0, prefix+rank);
    13. event.setLine(1, playername);
    14.  
    15. }

    On the debug messages I have all i get is a blank line
    Any ideas?
     
  2. Offline

    Europia79

    Pacothegint

    It looks like you're just saving the data to all local variables of type Player, String, & Profile.

    If the data doesn't need to be persisted between resets, then I would just map the player's name to all their data: In this case, i'm assuming type Profile holds all the information about the player that you want to retrieve later.

    If you want to persist the data beyond a server reset, then map the player's UUID to all their data.
     
  3. Offline

    Pacothegint

    Europia79
    It saves all the data under a player UUID
    as
    UUID
    -name
    -rank
    -prefix
    But it is when I try to call that data it returns null
    I should add. This is in a yml file
     
  4. Offline

    Europia79

    Pacothegint

    I looked more closely at the code: I'm not seeing anything you should save. For example, the rank & prefix could change, so I wouldn't save those. Just keep using getPrimaryGroup(p) and getPlayerPrefix(p)... then you'll always get the most up-to-date values.

    Code:java
    1.  
    2. /**
    3.  * What are you trying to accomplish here ?
    4.  */
    5. public void onSignchange(SignChangeEvent event){
    6. Player placer = event.getPlayer();
    7. String playername = event.getLine(0);
    8. String rank = plugin.permission.getPrimaryGroup(p);
    9. String prefix = plugin.chat.getPlayerPrefix(p);
    10. event.setLine(0, prefix+rank);
    11. event.setLine(1, playername);
    12. }


    This is the jist of what I mean... But what are you trying to do here ?
     
  5. Offline

    Pacothegint

    Europia79
    well I just redid it and it works now.
     
Thread Status:
Not open for further replies.

Share This Page