Solved solved

Discussion in 'Plugin Development' started by Uniclaw, Nov 1, 2012.

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

    Uniclaw

    Hi!

    i have a HashMap "String(Player-Name), Integer", wich represents points for a player - for countingup i use this method:
    Code:
    public void countUp(Player p){
    if(phr.containsKey(p.getName())){
    phr.put(p.getName(), phr.get(p.getName())+ 1);
    }else{
    phr.put(p.getName(), 1);
    }
    }
    I call this method in events like BlockBreakEvent, and its sure called - i have added a console-output, and all works fine. But: if i would check the value with:
    Code:
    String.valueOf(plugin.kills.get(p.getName()))
    its give me every time "0" .. :(
     
  2. Offline

    fireblast709

    full code please
     
  3. Offline

    stelar7

    you put them into prh and read them from kills...
     
  4. Offline

    fireblast709

    (how did I miss that...?)
     
  5. Offline

    Uniclaw

    Ups, sorry - wrong code, i mean:
    Code:
    String.valueOf(plugin.prh.get(p.getName()))
    
     
  6. Offline

    fireblast709

    if this still gives the '0', full code please :3
     
  7. Offline

    stelar7

    so a System.out.print(plugin.prh.get(p.getName())) on a player that has had countUp 3 times == 0?
     
  8. Offline

    Uniclaw

    Okay:
    main:
    Code:
     
    package au.bk.phr;
     
    import java.io.File;
    import java.util.HashMap;
    import java.util.Iterator;
    import java.util.Set;
     
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class rk extends JavaPlugin {
     
     
     
    public void onDisable(){
     
    }
    public void onEnable(){
    saveConfig();
    this.getServer().getPluginManager().registerEvents(new Logger_L(this), this);
    getCommand("phr").setExecutor(new ce_phr(this));
    }
     
     
     
    public String colorize(String string){
    return string.replaceAll("&([a-f0-9])", "\u00A7$1");
    }
     
    public void countUp(Player p){
    if(phr.containsKey(p.getName())){
    phr.put(p.getName(), phr.get(p.getName())+ 1);
    }else{
    phr.put(p.getName(), 1);
    }
    }
     
    public void saveMyConfig(){
            if(! new File(getDataFolder(), "config.yml").exists()){
                this.saveDefaultConfig();
            }
    }
     
    public FileConfiguration config;
    public HashMap<String, Integer> phr = new HashMap<String, Integer>();}
     
    Listener(The interesting method):
    [code]
    @EventHandler
    public void break(BlockBreakEvent e){
    if(e.getBlock.getTypeId == 1){
    plugin.countUp(e.getPlayer);
    }}
    And the command executor:
    Code:
    public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String args[]) {
            if(sender instanceof Player) {
          Player p = (Player)sender;
          if (cmd.getName().equalsIgnoreCase("phr")) {
          if (p.hasPermission("phr.*")) {
          if(plugin.phr.containsKey(p.getName())){
          p.sendMessage(ChatColor.GREEN + plugin.colorize(plugin.getConfig().getString("messages.phr")
                  .replace("%points", String.valueOf(plugin.phr.get(p.getName())))));
          }else{
          p.sendMessage(ChatColor.GREEN + plugin.colorize(plugin.getConfig().getString("messages.phr")
                  .replace("%points", "0")));
          }
    


    stelar7 Yes :( !
     
  9. Offline

    pzxc

    Code:
    if(e.getBlock.getTypeId == 1){

    should be:
    Code:
    if(e.getBlock().getTypeId() == 1){

    or better yet (because it's more readable):
    Code:
    if(e.getBlock().getType() == Material.STONE){
     
  10. Offline

    Uniclaw

    No, thats not the Problem - it sas that the method is called. In the console th countUp is succesfully (ex: i make /phr : 0 i break a stone: in the cnosole i see the number 1. i re-type /phr : 0...)

    EDIT: Solved!

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 29, 2016
Thread Status:
Not open for further replies.

Share This Page