2016-12-07 1 views
1

나는 Bukkit의 config API에 대해 매우 익숙하다. 질문 : 플레이어를 나타내는 % player %와 같은 것을 포함하는 YAML 파일의 문자열을 설정하는 방법 (예 : 누군가가 구성 할 수있는 발신자 이름). config.yml에서 sender.getDisplayName()을 % player %로 파싱하는 방법은 무엇입니까?bukkit - config.yml에서 변수를 사용하는 방법은 무엇입니까?

내 코드는 바로 지금입니다 :

String message = core.getConfig().getString("message"); //Get the message from the config file 
      message = message.replace("%player%", player.getDisplayName()); //Replace %player% with the player's name. 
      ChatColor.translateAlternateColorCodes('&', message); 
      Bukkit.broadcastMessage(message); 

내 config.yml은 다음과 같습니다

message: &6%player% just launched the cow party! 

오류는 다음과 같습니다

http://pastebin.com/8AdA5Xe1 (너무 오래)

+0

에 사용 문자열을 변경해야

, 더 나은 귀하의 질문에 설명 : 당신의 오류에 대해서는

Kerooker

+0

그 밖의 무엇을해야합니까? config.yaml 문자열의 % player %가 sender.getDisplayName() 인 것을 코드에 알리고 싶습니다. @Kerooker – MucaP

+0

퀘스트를 작성한 방식 on, 나는 당신이 원하는 것을 이해할 수 없다. – Kerooker

답변

1

당신이 원하는 무엇 할일은 config.yml 파일에서 문자열을 얻는 것입니다. % player %를 플레이어의 이름 또는 표시 이름과 함께 배치하십시오.

이와 비슷한 기능이 있습니다. 당신은 물론 당신의 유효한 플레이어 player를 교체해야

player.sendMessage(ChatColor.translateAlternateColorCodes('&', getConfig().getString("path.to.message").replace("%player%", player.getName())); 

:

String message = getConfig().getString("path.to.string"); //Get the message from the config file 
message = message.replace("%player%", player.getName()); //Replace %player% with the player's name. 
ChatColor.translateAlternateColorCodes('&', message); //Translate colors to color codes 
player.sendMessage(message); //Send the message 

당신은이 한 줄을 사용할 수 있습니다.

당신은 방법을 대체 메시지 따옴표 (")를 넣어, 그래서

message: &6%player% just launched the cow party! 

message: "&6%player% just launched the cow party!" 
+1

나는 로직을 단계적으로 자르고, 다른 사람들을 읽고 이해하고 미래에 유지하는 것을 더 쉽게 해준다. 원하는 경우 내가 작성한 소식을 수정할 수 있습니다. – Tschallacka

+1

의견을 보내 주셔서 감사합니다. – bramhaag

+0

고마워요! 나는 그것을 테스트 할 것이고 대답으로 받아 들일 것입니다. 감사합니다. – MucaP

관련 문제