@Johannes_C25
loadConfig() ist ne Methode 
Code:
public boolean loadConfig() {
this.config = getConfig();
this.config.options().copyDefaults(true);
saveConfig();
if (!new File(getDataFolder() + "src/config.yml").exists());
saveDefaultConfig();
return true;
}
Listener:
Code:
Main plugin;
public ZoneListener(Main instance) {
plugin = instance;
}
static int zone_ID;
@Event Handler
public void onPlayerInteract(PlayerInteractEvent event) {
final Player player = event.getPlayer();
if (ModSettings.createOn.contains(player) && ModSettings.step1.contains(player)) {
if (event.getAction() == Action.LEFT_CLICK_BLOCK && player.getItemInHand().getType() == Material.STICK) {
try {
plugin.l1 = event.getClickedBlock().getLocation();
player.sendMessage("");
player.sendMessage(ChatColor.DARK_GREEN + "Position 1: " + Throws.showBlockCoords(plugin.l1));
event.setCancelled(true);
int loc1_x = plugin.l1.getBlockX();
int loc1_y = plugin.l1.getBlockY();
int loc1_z = plugin.l1.getBlockZ();
plugin.loadArenas();
plugin.saveFile.load(plugin.f);
plugin.saveFile.set(ModSettings.zoneName + ".L1.X", loc1_x);
plugin.saveFile.set(ModSettings.zoneName + ".L1.Y", loc1_y);
plugin.saveFile.set(ModSettings.zoneName + ".L1.Z", loc1_z);
plugin.saveFile.save(plugin.f);
ModSettings.step1.remove(player);
ModSettings.step2.add(player);
} catch (Exception e) {
Throws.errorOccuredWhileCreatePoint(player);
e.printStackTrace();
}
}
}
if (ModSettings.createOn.contains(player) && ModSettings.step2.contains(player)) {
if (event.getAction() == Action.RIGHT_CLICK_BLOCK && player.getItemInHand().getType() == Material.STICK) {
try {
plugin.l2 = event.getClickedBlock().getLocation();
player.sendMessage(ChatColor.DARK_GREEN + "Position 2: " + Throws.showBlockCoords(plugin.l2));
event.setCancelled(true);
int loc2_x = plugin.l2.getBlockX();
int loc2_y = plugin.l2.getBlockY();
int loc2_z = plugin.l2.getBlockZ();
plugin.loadArenas();
plugin.saveFile.load(plugin.f);
plugin.saveFile.set(ModSettings.zoneName + ".L2.X", loc2_x);
plugin.saveFile.set(ModSettings.zoneName + ".L2.Y", loc2_y);
plugin.saveFile.set(ModSettings.zoneName + ".L2.Z", loc2_z);
plugin.saveFile.save(plugin.f);
plugin.pz.createZone(player, plugin.l1, plugin.l2);
ModSettings.step2.remove(player);
ModSettings.step3.add(player);
} catch (Exception e) {
Throws.errorOccuredWhileCreatePoint(player);
e.printStackTrace();
}
}
}
if (ModSettings.createOn.contains(player) && ModSettings.step3.contains(player)) {
if (event.getAction() == Action.LEFT_CLICK_BLOCK && player.getItemInHand().getType() == Material.STICK) {
try {
plugin.l3 = event.getClickedBlock().getLocation();
player.sendMessage(ChatColor.DARK_GREEN + "Spawnpoint 1: " + Throws.showBlockCoords(plugin.l3));
event.setCancelled(true);
int spawn1_x = plugin.l2.getBlockX();
int spawn1_y = plugin.l2.getBlockY();
int spawn1_z = plugin.l2.getBlockZ();
plugin.loadArenas();
plugin.saveFile.load(plugin.f);
plugin.saveFile.set(ModSettings.zoneName + ".Spawn1.X", spawn1_x);
plugin.saveFile.set(ModSettings.zoneName + ".Spawn1.Y", spawn1_y);
plugin.saveFile.set(ModSettings.zoneName + ".Spawn1.Z", spawn1_z);
plugin.saveFile.save(plugin.f);
ModSettings.step3.remove(player);
ModSettings.step4.add(player);
} catch(Exception e) {
Throws.errorOccuredWhileCreatePoint(player);
}
}
}
if (ModSettings.createOn.contains(player) && ModSettings.step4.contains(player)) {
if (event.getAction() == Action.RIGHT_CLICK_BLOCK && player.getItemInHand().getType() == Material.STICK) {
try {
plugin.l4 = event.getClickedBlock().getLocation();
player.sendMessage(ChatColor.DARK_GREEN + "Spawnpoint 2: " + Throws.showBlockCoords(plugin.l4));
event.setCancelled(true);
int spawn2_x = plugin.l2.getBlockX();
int spawn2_y = plugin.l2.getBlockY();
int spawn2_z = plugin.l2.getBlockZ();
plugin.loadArenas();
plugin.saveFile.load(plugin.f);
plugin.saveFile.set(ModSettings.zoneName + ".Spawn2.X", spawn2_x);
plugin.saveFile.set(ModSettings.zoneName + ".Spawn2.Y", spawn2_y);
plugin.saveFile.set(ModSettings.zoneName + ".Spawn2.Z", spawn2_z);
plugin.saveFile.save(plugin.f);
ModSettings.step4.remove(player);
ModSettings.step5.add(player);
} catch (Exception e) {
Throws.errorOccuredWhileCreateZone(player);
}
}
}
if (ModSettings.createOn.contains(player) && ModSettings.step5.contains(player)) {
if (event.getAction() == Action.LEFT_CLICK_BLOCK && player.getItemInHand().getType() == Material.STICK) {
try {
plugin.l5 = event.getClickedBlock().getLocation();
player.sendMessage(ChatColor.DARK_GREEN + "Deathposition: " + Throws.showBlockCoords(plugin.l5));
player.sendMessage("");
int death_x = plugin.l2.getBlockX();
int death_y = plugin.l2.getBlockY();
int death_z = plugin.l2.getBlockZ();
zone_ID = player.getTicksLived() + 500 / 2;
plugin.loadArenas();
plugin.saveFile.load(plugin.f);
plugin.saveFile.set(ModSettings.zoneName + ".Death.X", death_x);
plugin.saveFile.set(ModSettings.zoneName + ".Death.Y", death_y);
plugin.saveFile.set(ModSettings.zoneName + ".Death.Z", death_z);
plugin.saveFile.set(ModSettings.zoneName + ".Zone_ID", zone_ID);
plugin.saveFile.save(plugin.f);
player.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { public void run() { player.sendMessage(ChatColor.GREEN + "Congratulation! You successfully created the arena " + ChatColor.GOLD + ModSettings.zoneName); }}, 60L);
event.setCancelled(true);
ModSettings.switchStatus(player);
ModSettings.step5.remove(player);
} catch (Exception e) {
Throws.errorOccuredWhileCreateZone(player);
}
}
}
}
Commandklasse:
Code:
Main plugin;
Command cmd;
Player player;
Player ask;
String[] args;
ChatColor gray = ChatColor.GRAY;
ChatColor blue = ChatColor.BLUE;
ChatColor gold = ChatColor.GOLD;
ChatColor aqua = ChatColor.AQUA;
ChatColor green = ChatColor.GREEN;
ChatColor darkgreen = ChatColor.DARK_GREEN;
ChatColor red = ChatColor.RED;
public CommandPvP(Command cmd, Player player, String[] args) {
this.cmd = cmd;
this.player = player;
this.args = args;
}
public boolean run() {
if (args[0].equalsIgnoreCase("join")) {
if (args.length == 2) {
ModSettings.zoneName = args[1];
try {
plugin.loadArenas();
plugin.saveFile.load(plugin.f);
} catch (IOException | InvalidConfigurationException | NullPointerException e) {
e.printStackTrace();
}
// if (!plugin.saveFile.contains(ModSettings.zoneName)) {
//
// player.sendMessage(red + "This arena doesn't exists!");
//
// return false;
// }
// World world = player.getWorld();
// int x = plugin.saveFile.getInt(ModSettings.zoneName + ".Spawn1.X");
// int y = plugin.saveFile.getInt(ModSettings.zoneName + ".Spawn1.Y");
// int z = plugin.saveFile.getInt(ModSettings.zoneName + ".Spawn1.Z");
//
// Location spawnLoc = new Location(world, x, y, z);
//
// player.teleport(spawnLoc);
player.sendMessage(green + "You have been ported to the arena " + gold + args[1]);
return true;
} else {
Throws.ArgumentsException(player);
}
}
Und alle Exceptions sind NullPointerException's welche auftreten, sobald irgendwas mit der Datei gemacht wird.