java - Issue with arrays -
i have issue array while developing bukkit plugin. why doesn't work? supposed check whether player has placed block. keeps on saying "diamonds!!" ingame.
@eventhandler public void onplaceofdiamond(blockplaceevent e){ player player = e.getplayer(); string storage[] = new string[100]; int = 0; if(e.getblock().gettype() == material.diamond_block){ if(arrays.aslist(storage).contains(player.getname())){ player.sendmessage(chatcolor.blue + "you on list"); }else{ player.sendmessage(chatcolor.blue + "diamonds!!"); storage[i] = player.getname(); i++; } } }
it's because creating new storage
array every time player places block:
@eventhandler public void onplaceofdiamond(blockplaceevent e){ player player = e.getplayer(); string storage[] = new string[100];
so you'll never have complete list of players. fix this, should declare array
outside of method:
string storage[] = new string[100]; @eventhandler public void onplaceofdiamond(blockplaceevent e) { player player = e.getplayer(); int = 0; if(e.getblock().gettype() == material.diamond_block){ if(arrays.aslist(storage).contains(player.getname())){ player.sendmessage(chatcolor.blue + "you on list"); } else{ player.sendmessage(chatcolor.blue + "diamonds!!"); storage[i] = player.getname(); i++; } } }
Comments
Post a Comment