我正在尝试使“ /setspawn
”命令成为“ /lv setspawn
”。我将插件放在“ plugins”文件夹中,插件生成配置,然后打开配置。此时一切都正确,因此当我尝试使用“ /lv setspawn
”时,除电源线外的所有东西都将被移除。我进入配置并使用“ control + z”,“ control + s”和/reload
。现在的配置就像是一开始,我再次使用“ /lv setspawn
”并可以完美地工作(我不能放置超过2个链接)。
对不起我的英语。
我想要的是:
我想在使用/lv setspawn
时将坐标放入配置中
Video from the problem
主要代码:
package com.gmail.santiagoelheroe;
import static com.gmail.santiagoelheroe.Eventos.plugin;
import org.bukkit.*;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
public class LoginVip extends JavaPlugin {
// Comandos
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (args[0].equalsIgnoreCase("setspawn")) {
getConfig().set("Cords.World", player.getLocation().getWorld().getName());
getConfig().set("Cords.X", player.getLocation().getX());
getConfig().set("Cords.Y", player.getLocation().getY());
getConfig().set("Cords.Z", player.getLocation().getZ());
saveConfig();
sender.sendMessage(prefix + "§aSpawn placed");
return true;
}
if (args[0].equalsIgnoreCase("spawn")) {
World w = Bukkit.getServer().getWorld(getConfig().getString("Cords.World"));
double x = getConfig().getDouble("Cords.X");
double y = getConfig().getDouble("Cords.Y");
double z = getConfig().getDouble("Cords.Z");
player.teleport(new Location(w, x, y, z));
return true;
}
return true;
}
//Comandos
@Override
public void onEnable() {
PluginManager manager = this.getServer().getPluginManager();
manager.registerEvents(Eventos, this);
saveDefaultConfig();
}
配置(在插件内部)
# * Permisos: 'lv.main', 'lv.join' y 'lv.quit' Variables: %player%
Configuracion:
JoinMessage: '&b%player% &7se ha conectado'
JoinMessageActivo: true
QuitMessage: '&c%player% &7se ha desconectado'
QuitMessageActivo: true
NoPermissionsMessage: '&cNo tienes permisos para hacer esto'
Prefix: '&7[&6LV&7] '
TpSpawnOnJoin: false #To set spawn use in game /lv setspawn
Cords:
World: ''
X: ''
Y: ''
Z: ''
最佳答案
我个人讨厌默认配置,所以我从不使用它。
看看YamlConfiguration
。参见tutorial。
File fileConfig = new File(Plugin.getDataFolder().getPath(), "config.yml");
YamlConfiguration config = YamlConfiguration.loadConfiguration(fileConfig);
// Setting
Location spawn = Player.getLocation();
config.set("spawn.world", spawn.getWorld().getName());
config.set("spawn.x", spawn.getX());
config.set("spawn.y", spawn.getY());
config.set("spawn.z", spawn.getZ());
config.set("spawn.yaw", spawn.getYaw());
config.set("spawn.pitch", spawn.getPitch());
try {
config.save(fileConfig);
} catch (IOException io) {
// Unable to save data
}
// Getting
String world = config.getString("spawn.world");
double x = config.getDouble("spawn.x");
double y = config.getDouble("spawn.y");
double z = config.getDouble("spawn.z");
double yaw = config.getDouble("spawn.yaw");
double pitch = config.getDouble("spawn.pitch");
Location spawn = new Location(Server.getWorld(world), x, y, z, (float) yaw, (float) pitch);
Player.teleport(spawn);