Reputation: 33
I'm trying to make "/setspawn
" command "/lv setspawn
". I put the plugin inside "plugins" folder, the plugin generates the config and I'll open the config. Everything at this moment is right, so when I try to use "/lv setspawn
" everything except cords get removed. I go to config and use "control+z" "control+s" and /reload
. Now config is like at the first moment, I use again "/lv setspawn
" and works perfectly (I can't put more than 2 links).
I'm sorry for my english.
What I want:
I want the coordinates are put inside the config when I use /lv setspawn
Main code :
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();
}
Config (inside the plugin)
# * 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: ''
Upvotes: 0
Views: 2408
Reputation:
Personally, I hate the default config so I never use it.
Take a look at YamlConfiguration
. See a 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);
Upvotes: 1