java - Problems with accessing HashMaps from other classes -
i writing plugin using spigot (pretty bukkit) i'm having problems accessing hashmap 1 class in another. here hashmap , getter:
private map<string, integer> compplayers = new hashmap<string, integer>(); public map<string, integer> getcompplayers(){ return compplayers; }
i able see if hashmap contains keys within class such here:
if(args[0].equalsignorecase("join")){ if(compplayers.containskey(p.getname())){ p.sendmessage(chatcolor.red + "you part of competition"); return false; }
yet in listener class, can't seem access properly. here's section of code in listener class:
public class competitionlistener implements listener { private pluginmain plugin; public competitionlistener(pluginmain plugin){ this.plugin = plugin; } @eventhandler public void onblockplace(blockbreakevent e){ player p = (player) e.getplayer(); p.sendmessage("blockbreakevent"); if(plugin.getcommands().getcompplayers().containskey(p.getname())){ p.sendmessage(chatcolor.yellow + "you scored point!"); plugin.getcommands().getcompplayers().put(p.getname(), plugin.getcommands().getcompplayers().get(p.getname() + 1)); } } }
pluginmain class extends javaplugin , getcommands() getter commands class within it.
though able access these methods listener class without errors, line checking if player name in hashmap doesn't work , returns false. event work.
you never register events in listener
class.
in listener
class's constructor, add following:
plugin.getserver().getpluginmanager().registerevents(this, plugin);
Comments
Post a Comment