为什么我的配置文件没有修改我的服务器 motd?
why isn't my config file modifying my servers motd?
所以正如标题所说,我需要我的配置文件来修改我的服务器 motd,我觉得我已经以正确的方式完成了所有事情,但显然有些地方不对劲,所以让我向您展示我正在使用的东西
me.zavage.motd.Main
package me.zavage.motd;
import org.bukkit.plugin.java.JavaPlugin;
public class Main extends JavaPlugin {
@Override
public void onEnable() {
saveDefaultConfig();
}
}
me.zavage.motd.listeners.PingListener
package me.zavage.motd.listeners;
import java.io.File;
import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.server.ServerListPingEvent;
import me.zavage.motd.Main;
import me.zavage.motd.utils.Utils;
public class PingListener implements Listener {
private Main plugin;
@EventHandler
public void onPing(ServerListPingEvent e) {
e.setMaxPlayers(plugin.getConfig().getInt("maxplayers"));
e.setMotd(Utils.chat(plugin.getConfig().getString("motd" + "\n" + (Utils.chat(plugin.getConfig().getString("motd_line_2"))))));
try {
e.setServerIcon(Bukkit.loadServerIcon(new File(plugin.getConfig().getString("server_icon_path"))));
} catch (Exception e1) {
e1.printStackTrace();
}
}
}
然后我们有 config.yml
#can only be a NUMBER with NO DECIMALS!
maxplayers: ''
motd: ''
#next line on motd
motd_line_2:
#create a folder inside the first page of your server files, call it "icon" and drop you server icon in there
#server icon MUST be 64 x 64 pixels
# #NameOfIcon#
#path example "C:\Users\user\Desktop\minecraft test server\icon\icon.png
server_icon_path: ''
如果您显示的代码与您正在使用的所有内容一致,则几乎没有问题。
- 您没有注册监听器
package me.zavage.motd;
import org.bukkit.plugin.java.JavaPlugin;
public class Main extends JavaPlugin {
@Override
public void onEnable() {
saveDefaultConfig();
getServer().getPluginManager().registerEvents(new PingListener(this), this);
}
}
- 你没有在监听器中设置插件变量,也没有构造函数
public class PingListener implements Listener {
private Main plugin;
public PingListener(Main plugin) {
this.plugin = plugin;
}
}
- 最后,您正在搜索
motd\n motd_line_2
消息。您必须在 ServerListPingEvent
侦听器中使用它:
e.setMaxPlayers(plugin.getConfig().getInt("maxplayers"));
e.setMotd(Utils.chat(plugin.getConfig().getString("motd") + "\n" + plugin.getConfig().getString("motd_line_2")));
try {
e.setServerIcon(Bukkit.loadServerIcon(new File(plugin.getConfig().getString("server_icon_path"))));
} catch (Exception exc) {
exc.printStackTrace();
}
所以正如标题所说,我需要我的配置文件来修改我的服务器 motd,我觉得我已经以正确的方式完成了所有事情,但显然有些地方不对劲,所以让我向您展示我正在使用的东西
me.zavage.motd.Main
package me.zavage.motd;
import org.bukkit.plugin.java.JavaPlugin;
public class Main extends JavaPlugin {
@Override
public void onEnable() {
saveDefaultConfig();
}
}
me.zavage.motd.listeners.PingListener
package me.zavage.motd.listeners;
import java.io.File;
import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.server.ServerListPingEvent;
import me.zavage.motd.Main;
import me.zavage.motd.utils.Utils;
public class PingListener implements Listener {
private Main plugin;
@EventHandler
public void onPing(ServerListPingEvent e) {
e.setMaxPlayers(plugin.getConfig().getInt("maxplayers"));
e.setMotd(Utils.chat(plugin.getConfig().getString("motd" + "\n" + (Utils.chat(plugin.getConfig().getString("motd_line_2"))))));
try {
e.setServerIcon(Bukkit.loadServerIcon(new File(plugin.getConfig().getString("server_icon_path"))));
} catch (Exception e1) {
e1.printStackTrace();
}
}
}
然后我们有 config.yml
#can only be a NUMBER with NO DECIMALS!
maxplayers: ''
motd: ''
#next line on motd
motd_line_2:
#create a folder inside the first page of your server files, call it "icon" and drop you server icon in there
#server icon MUST be 64 x 64 pixels
# #NameOfIcon#
#path example "C:\Users\user\Desktop\minecraft test server\icon\icon.png
server_icon_path: ''
如果您显示的代码与您正在使用的所有内容一致,则几乎没有问题。
- 您没有注册监听器
package me.zavage.motd;
import org.bukkit.plugin.java.JavaPlugin;
public class Main extends JavaPlugin {
@Override
public void onEnable() {
saveDefaultConfig();
getServer().getPluginManager().registerEvents(new PingListener(this), this);
}
}
- 你没有在监听器中设置插件变量,也没有构造函数
public class PingListener implements Listener {
private Main plugin;
public PingListener(Main plugin) {
this.plugin = plugin;
}
}
- 最后,您正在搜索
motd\n motd_line_2
消息。您必须在ServerListPingEvent
侦听器中使用它:
e.setMaxPlayers(plugin.getConfig().getInt("maxplayers"));
e.setMotd(Utils.chat(plugin.getConfig().getString("motd") + "\n" + plugin.getConfig().getString("motd_line_2")));
try {
e.setServerIcon(Bukkit.loadServerIcon(new File(plugin.getConfig().getString("server_icon_path"))));
} catch (Exception exc) {
exc.printStackTrace();
}