我的config.yml文件有问题。当我开始
插件,它自动生成默认的config.yml
文件。这是默认的预设:
#This Plugin was made by Yuki
#Version 0.0.1
Spawn:
World:
X:
Y:
Z:
Yaw:
Pitch:
我创建了一个注释(/setspawn(,它将数据输入到
config.yml中。这部分工作得很好,只是有一个小问题,
每次config.yml都会被完全擦除
config.yml插入数据后:
Spawn:
World: world
X: -155.45080613398784
Y: 82.0
Z: -57.60431500946787
Yaw: -27.600231
Pitch: 29.550203
我用以下行插入数据:
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if(sender instanceof Player) {
Player player = (Player) sender;
if(sender.hasPermission("cc.command.setSpawn")) {
FileConfiguration config = Main.getPlugin().getConfig();
config.set("Spawn.World", player.getWorld().getName());
config.set("Spawn.X", player.getLocation().getX());
config.set("Spawn.Y", player.getLocation().getY());
config.set("Spawn.Z", player.getLocation().getZ());
config.set("Spawn.Yaw", player.getLocation().getYaw());
config.set("Spawn.Pitch", player.getLocation().getPitch());
Main.getPlugin().saveConfig();
player.sendMessage("Der Spawn wurde gesetzt!");
}
}
return false;
}
主要类别:
public class Main extends JavaPlugin {
private static Main plugin;
public void onEnable() {
plugin = this;
this.saveDefaultConfig();
System.out.println(" 33[1;36m"+"["+" 33[1;35m"+"CC"+" 33[1;36m"+"]"+" 33[0;35m"+"Crystal Cake is online"+" 33[0m");
//commands
getCommand("heal").setExecutor(new HealAndFood());
getCommand("setspawn").setExecutor(new SetSpawnCommand());
//Listeners
Bukkit.getPluginManager().registerEvents(new JoinLeaveListener(), this);
Bukkit.getPluginManager().registerEvents(new KillListener(), this);
}
public void onDisable() {
System.out.println(" 33[1;36m"+"["+" 33[1;35m"+"CC"+" 33[1;36m"+"]"+" 33[0;35m"+"Crystal Cake is offline"+" 33[0m");
}
public static Main getPlugin() {
return plugin;
}
}
请包含onEnable((代码。
我猜其中有一些东西在启动插件时与saveDefaultConfig()
等效。:(
编辑:我已经把你的代码复制到我的另一个插件中。我没有问题。启动服务器后,配置将保持原样。日志中有消息吗?