我试图制作" /setspawn
"命令" /lv setspawn
"。我把插件放在"插件"文件夹,插件生成配置,我打开配置。此刻的一切都是正确的,所以当我尝试使用" /lv setspawn
"除了绳索以外的一切都被删除我去配置并使用" control + z " " 控制 + 取值"和/reload
。现在配置就像在第一时间,我再次使用" /lv setspawn
"并且完美地工作(我不能放置超过2个链接)。
对不起我的英语。
我想要什么:
我希望在使用/lv setspawn
主要代码:
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: ''
答案 0 :(得分:1)
就个人而言,我讨厌默认配置,所以我从不使用它。
看看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);