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" ..
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 !
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){
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.