Metadata Strange Issue

Discussion in 'Plugin Development' started by spy85, Nov 24, 2013.

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

    spy85

    SOLVED!
    Simple programming mistake of not actually making sure the metadata got set to the player.

    I am new to meta data but have come by a very strange problem in which to me makes completely no sense. I have a meta data assigned as "cash" and "mobkills" as you can see.

    Code:java
    1. //Player Statistics
    2. public void registerPlayerStats(Player player){
    3. player.setMetadata("cash", new FixedMetadataValue(plugin, 200));
    4. player.setMetadata("mobkills", new FixedMetadataValue(plugin, 0));
    5. }
    6. public void unRegisterPlayerStats(Player player){
    7.  
    8. }
    9. public Object getPlayerKills(Player player){
    10. return getMetadata(player, "mobkills");
    11. }
    12. public Object getPlayerCash(Player player){
    13. return getMetadata(player, "cash");
    14. }


    Here is the method being used to get meta data for the kills and cash getters:
    Code:java
    1. //Metadata
    2. public Object getMetadata(Player player, String key){
    3. List<MetadataValue> values = player.getMetadata(key);
    4. for(MetadataValue val : values){
    5. if(val.getOwningPlugin().getDescription().getName().equals(plugin.getDescription().getName())){
    6. return val.value();
    7. }
    8. }
    9. return player.getMetadata(key);
    10. }


    There are two commands, one is /killstats in which displays the personal players mob kills from the meta data. The other is /cash in which displays their cash from the meta data. The /cash outputs as desired and correctly, but the /killstats outputs as [WWZ] Kills : [] while /cash outputs as [WWZ] $Cash$ : $250

    Code:java
    1. public boolean onCommand(CommandSender sender, Command cmd, String alias, String[] args) {
    2. //CASH
    3. if(cmd.getName().equalsIgnoreCase("cash")){
    4. if(sender instanceof Player){
    5.  
    6. Player player = (Player)sender;
    7. player.sendMessage(chatPrefix + ChatColor.GREEN+" $Cash$ : "+ChatColor.RED+
    8. inGameVariables.getPlayerCash(player));
    9.  
    10. }else{
    11. sender.sendMessage(chatPrefix + ChatColor.RED+"You must be a player to use this command.");
    12. }
    13. return true;
    14. }
    15.  
    16. //KILL_STATS (personal)
    17. if(cmd.getName().equalsIgnoreCase("killstats")){
    18. if(sender instanceof Player){
    19.  
    20. Player player = (Player)sender;
    21. player.sendMessage(chatPrefix + ChatColor.GREEN+" Kills : "+ChatColor.RED+
    22. inGameVariables.getPlayerKills(player));
    23.  
    24. }else{
    25. sender.sendMessage(chatPrefix + ChatColor.RED+"You must be a player to use this command.");
    26. }
    27. return true;
    28. }
    29. return false;
    30. }


    Any idea why? Thanks for the help!
     
  2. Offline

    jboy44

    spy85
    Did you try killing a mob or a player? I'm sure it wont say anything unless you've actually killed something first.
     
  3. Offline

    spy85

    Currently the way it is setup, is it is only a integer value of 0 that should display when /killstats is sent. It is in no way linked with the actual kills yet.
     
  4. Offline

    spy85

    I figured it out it was a very simple programming mistake.
     
Thread Status:
Not open for further replies.

Share This Page