java - Bukkit. Color support in chat (&) ? and Username onplayerjoin does not work? -
i have 2 problems.
problem 1
i want colors essentials have in chat dont know how tried this:
@eventhandler public void onplayerchat(asyncplayerchatevent chatevent){ chatevent.getmessage().replaceall("&", "§"); (string word : chatevent.getmessage().split(" ")){ if(sysmng.getconfig().getstringlist("badwords").contains(word)){ if (!chatevent.getplayer().haspermission("bypassbadwords")){ chatevent.setcancelled(true); chatevent.getplayer().sendmessage(chatcolor.red + "dont use dirty or swear words!"); } } } }
this line: chatevent.getmessage().replaceall("&", "§"); not work. how can color support in chat?
problem 1 update ok soo did:
public void onplayerchat(asyncplayerchatevent chatevent){ (string word : chatevent.getmessage().split(" ")){ word.replaceall("&", "§"); if(sysmng.getconfig().getstringlist("badwords").contains(word)){ if (!chatevent.getplayer().haspermission("bypassbadwords")){ chatevent.setcancelled(true); chatevent.getplayer().sendmessage(chatcolor.red + "dont use dirty or swear words!"); } } } }
but still not work. how can fix soo in chat colors work? know strings dont need tell me that. game developer know these simple stuff.
2 problem fixed
and problem want onplayerjoin event announce when server owner join if name match , did work not doing wrong? console name cannot null. wrong? here event:
@eventhandler public void onplayerjoin(playerjoinevent joinevent){ player getplayer = joinevent.getplayer(); getplayer.sendmessage(chatcolor.aqua + "hey " + getplayer.getname() + "! welcome ultimate prison server!"); // spawning player in spawn location if(sysmng.getspawnsdata().getconfigurationsection("spawn") == null){ getplayer.sendmessage(chatcolor.red + "spawn not set!. report problem owner instantly!"); } world w = bukkit.getserver().getworld(sysmng.getspawnsdata().getstring("spawn.world")); double x = sysmng.getspawnsdata().getdouble("spawn.x"); double y = sysmng.getspawnsdata().getdouble("spawn.y"); double z = sysmng.getspawnsdata().getdouble("spawn.z"); getplayer.teleport(new location(w, x, y, z)); // ---------------------------------------------------------------- if(getplayer.getname() == "herobrine112211"){ bukkit.getserver().broadcastmessage(chatcolor.white + "[" + chatcolor.gold + "broadcast" + chatcolor.white + "] " + chatcolor.gold + "server creator herobrine112211 has joined game!!!!!!!!!!"); } }
the line if(getplayer.getname() == "herobrine112211"){ problem think. did try changing exact same name still same error. how can fix it?
problem 2 fix
if(getplayer.getname().equalsignorecase("herobrine112211")){
i know should 1 question dont want post 2 questions better in 1.
thanks. here reading answers if need more tell me.
problem 1 "thomas"
like this?
@eventhandler public void onplayerchat(asyncplayerchatevent chatevent){ (string word : chatevent.getmessage().split(" ")){ word = word.replaceall("&", "§"); if(sysmng.getconfig().getstringlist("badwords").contains(word)){ if (!chatevent.getplayer().haspermission("bypassbadwords")){ chatevent.setcancelled(true); chatevent.getplayer().sendmessage(chatcolor.red + "dont use dirty or swear words!"); } } } }
still not work.
strings immutable. can't change them inplace. calling replaceall()
returns new string. if want replace old word new word, need do:
word = word.replaceall("&", "§");
Comments
Post a Comment