用自定义变量替换球员名称

时间:2016-06-17 13:56:17

标签: bukkit

所以,当我试图让玩家安装了特定的mod并试图加入时,玩家会受到踢,但是因为我有一个配置和一个自定义变量,用'玩家'取代了玩家。工作时,当玩家加入控制台日志时“错误:找不到播放器”。

这是我的代码:

getConfig().options().copyDefaults(true);
    getConfig().addDefault("CommandOnJoin", "kick 'player' &c&lZakMC &8» &6That mod is not allowed on this server.");
    saveConfig();
    getServer().getPluginManager().registerEvents(this, this);
    instance = this;
    getServer().getMessenger().registerIncomingPluginChannel(this, "WDL|INIT", this);
    getServer().getMessenger().registerOutgoingPluginChannel(this, "WDL|CONTROL");


    PluginDescriptionFile pdfFile = getDescription();
    Logger logger = Logger.getLogger("Minecraft");

    logger.info(pdfFile.getName() +  " has been found and enabled. (Version " + pdfFile.getVersion() +" )");
}

public void onDisable(){

    getServer().getMessenger().unregisterIncomingPluginChannel(this, "WDL|INIT");
    getServer().getMessenger().unregisterOutgoingPluginChannel(this, "WDL|CONTROL");

    PluginDescriptionFile pdfFile = getDescription();
    Logger logger = Logger.getLogger("Minecraft");

    logger.info(pdfFile.getName() +  " has been found and disabled. (Version " + pdfFile.getVersion() +" )");
 }

  public void onPluginMessageReceived(String channel, Player player, byte[] data){

    if ((channel.equals("WDL|INIT"))) 
      Bukkit.dispatchCommand(Bukkit.getConsoleSender(), getConfig().getString(ChatColor.translateAlternateColorCodes('&', "CommandOnJoin").replace("'player'", player.getName())));
  }

1 个答案:

答案 0 :(得分:0)

你需要做

Bukkit.dispatchCommand(Bukkit.getConsoleSender(), ChatColor.translateAlternateColorCodes('&', getConfig().getString("CommandOnJoin").replace("'player'", player.getName())));

而不是

Bukkit.dispatchCommand(Bukkit.getConsoleSender(), getConfig().getString(ChatColor.translateAlternateColorCodes('&', "CommandOnJoin").replace("'player'", player.getName())));

由于您的代码会在配置中查找已翻译的字符串,但无法找到。