Forum
Tipps
News
Menu-Icon

Minecraft Java Bukkit Config Probleme

Hey Leute, ich bin wieder mal am Programmieren eines Bukkit Plugins, jedoch habe ich momentan ein kleines Problem.
und zwar hatte ich die Idee zu einem Prison Plugin. Und zwar gibt es Polizei und Räuber und ich habe den Command /prison eingebaut, welcher noch einige Argumente mitliefert, bei denen eigentlich eine Config eingerichtet werden soll. Mein Problem ist das wenn ich zum Beispiel /prison prison-set ausführe zwar die prison.yml erstellt wird aber die Koordinaten die eigentlich in ihr stehen sollten nicht eingetragen wurden. Meinen Code habe ich hier Unten. Falls die Frage aufkommen sollte, ja ich habe den Command und alles in der main registriert und in der Console gibt es keine Fehler . Ich hoffe mir kann wer helfen




package Main;

import java.io.File;
import java.io.IOException;

import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;

public class commands implements Listener, CommandExecutor {

   public boolean onCommand(CommandSender sender, Command cmd, String cmdlabel, String[] args) {
      if (cmd.getName().equalsIgnoreCase("Prison")) {
         Player p = (Player) sender;
         if (args.length == 0) {
            if (p.hasPermission("Prison.op")) {
               p.sendMessage("§8§l====Prison Spieler Commands====");
               p.sendMessage("/prison help    (Liste alle Commands auf)");
               p.sendMessage("/prison join    (Betrete ein Spiel)");
               p.sendMessage("/prison leave    (Verlasse ein Spiel)");
               p.sendMessage("§8§l====Prison Setup Commands====");
               p.sendMessage("/prison prison-set    (Setzte das Gefängnis)");
               p.sendMessage("/prison spawn-set    (Setze den Spawn)");
               p.sendMessage("/prison start-set    (Setze die Wartelobby)");
               p.sendMessage("§8§l====Prison Reset Command====");
               p.sendMessage(
                     "/prison reset    (Resete alle Spawns in den Dateien prison.yml, spawn.yml, start.yml)");
            } else {
               p.sendMessage("§8§l====Prison Spieler Commands====");
               p.sendMessage("/prison help    (Liste alle Commands auf)");
               p.sendMessage("/prison join    (Betrete ein Spiel)");
               p.sendMessage("/prison leave    (Verlasse ein Spiel)");
            }
         } else {
            if ((args[0].equalsIgnoreCase("help"))) {
               if (p.hasPermission("Prison.op")) {
                  p.sendMessage("§8§l====Prison Spieler Commands====");
                  p.sendMessage("/prison help    (Liste alle Commands auf)");
                  p.sendMessage("/prison join    (Betrete ein Spiel)");
                  p.sendMessage("/prison leave    (Verlasse ein Spiel)");
                  p.sendMessage("§8§l====Prison Setup Commands====");
                  p.sendMessage("/prison prison-set    (Setzte das Gefängnis)");
                  p.sendMessage("/prison spawn-set    (Setze den Spawn)");
                  p.sendMessage("/prison start-set    (Setze die Wartelobby)");
                  p.sendMessage("§8§l====Prison Reset Command====");
                  p.sendMessage(
                        "/prison reset    (Resete alle Spawns in den Dateien prison.yml, spawn.yml, start.yml)");
               } else {
                  p.sendMessage("§8§l====Prison Spieler Commands====");
                  p.sendMessage("/prison help    (Liste alle Commands auf)");
                  p.sendMessage("/prison join    (Betrete ein Spiel)");
                  p.sendMessage("/prison leave    (Verlasse ein Spiel)");
               }

            } else {
               if ((args[0].equalsIgnoreCase("prison-set"))) {
                  if (p.hasPermission("prison.*")) {
                     File ordner = new File("plugins//Prisons");
                     File file = new File("plugins//Prisons//prisons.yml");
                     if (!ordner.exists()) {
                        ordner.mkdir();
                     }
                     if (!file.exists()) {
                        try {
                           file.createNewFile();
                        } catch (IOException i) {
                           p.sendMessage("§cprisons.yml konnte nicht erstellt werden !");
                        }
                     }
                     YamlConfiguration cfg = YamlConfiguration.loadConfiguration((File) file);
                     Location locMin = p.getLocation();

                     double x = locMin.getX();
                     double y = locMin.getY();
                     double z = locMin.getZ();

                     float yaw = locMin.getYaw();
                     float pitch = locMin.getPitch();

                     String world = locMin.getWorld().getName();

                     cfg.set("X", (int) x);
                     cfg.set("Y", (int) y);
                     cfg.set("Z", (int) z);
                     cfg.set("Yaw", (int) yaw);
                     cfg.set("Pitch", (int) pitch);
                     cfg.set("Welt", (String) world);
                  } else {
                     p.sendMessage("§cKeine Berechtigung!");
                  }

               } else {
                  if ((args[0].equalsIgnoreCase("reset"))) {
                     if (p.hasPermission("prison.*")) {
                        File ordner = new File("plugins//Prisons");
                        File file = new File("plugins//Prisons//prisons.yml");
                        if (!ordner.exists()) {
                           ordner.mkdir();
                        }
                        if (file.exists()) {
                           try {
                              file.delete();
                              file.createNewFile();
                           } catch (IOException i) {
                              p.sendMessage("§cDie Datei Prison.yml wurde nicht zurückgesetzt!");

                           }
                        }
                        File ordner1 = new File("plugins//Prisons");
                        File file1 = new File("plugins//Prisons//spawn.yml");
                        if (!ordner1.exists()) {
                           ordner1.mkdir();
                        }
                        if (file1.exists()) {
                           try {
                              file1.delete();
                              file1.createNewFile();
                           } catch (IOException i) {
                              p.sendMessage("§cDie Datei spawn.yml wurde nicht zurückgesetzt!");
                           }
                        }
                        File ordner2 = new File("plugins//Prisons");
                        File file2 = new File("plugins//Prisons//start.yml");
                        if (!ordner2.exists()) {
                           ordner2.mkdir();
                        }
                        if (file2.exists()) {
                           try {
                              file2.delete();
                              file2.createNewFile();
                           } catch (IOException i) {
                              p.sendMessage("§cDie Datei start.yml wurde nicht zurückgesetzt!");
                           }
                        }
                     } else {
                        p.sendMessage("§cKeine Berechtigung!");
                     }

                  } else {
                     if ((args[0].equalsIgnoreCase("join"))) {
                        File ordner = new File("plugins//Prisons");
                        File file = new File("plugins//Prisons//start.yml");
                        if (!ordner.exists()) {
                           ordner.mkdir();
                        }
                        if (file.exists()) {
                           p.sendMessage("§aEin Adminestrator muss zu erst das Setup ausführen!");
                        }
                        YamlConfiguration cfg = YamlConfiguration.loadConfiguration((File) file);

                        Location loc = p.getLocation();

                        loc.setX((double) cfg.getDouble("X"));
                        loc.setZ((double) cfg.getDouble("Z"));

                        loc.setY((double) cfg.getDouble("Y"));
                        loc.setWorld((World) cfg.get("Welt"));
                        loc.setYaw(cfg.getInt("Yaw"));
                        loc.setPitch(cfg.getInt("Pitch"));

                        p.teleport(loc);

                     } else {

                        if ((args[0].equalsIgnoreCase("leave"))) {
                           File ordner = new File("plugins//Prisons");
                           File file = new File("plugins//Prisons//spawn.yml");
                           if (!ordner.exists()) {
                              ordner.mkdir();
                           }
                           if (!file.exists()) {
                              p.sendMessage("§aEin Adminestrator muss zu erst das Setup ausführen!");
                           }
                           YamlConfiguration cfg = YamlConfiguration.loadConfiguration((File) file);

                           Location loc = p.getLocation();

                           loc.setX((double) cfg.getDouble("X"));
                           loc.setZ((double) cfg.getDouble("Z"));

                           loc.setY((double) cfg.getDouble("Y"));
                           loc.setWorld((World) cfg.get("Welt"));
                           loc.setYaw(cfg.getInt("Yaw"));
                           loc.setPitch(cfg.getInt("Pitch"));

                           p.teleport(loc);

                        } else {

                           if ((args[0].equalsIgnoreCase("spawn-set"))) {
                              if (p.hasPermission("prison.*")) {
                                 File ordner = new File("plugins//Prisons");
                                 File file = new File("plugins//Prisons//spawn.yml");
                                 if (!ordner.exists()) {
                                    ordner.mkdir();
                                 }
                                 if (!file.exists()) {
                                    try {
                                       file.createNewFile();
                                    } catch (IOException i) {
                                       p.sendMessage("§cspawn.yml konnte nicht erstellt werden !");
                                    }
                                 }
                                 YamlConfiguration cfg = YamlConfiguration.loadConfiguration((File) file);
                                 Location locMin = p.getLocation();

                                 double x = locMin.getX();
                                 double y = locMin.getY();
                                 double z = locMin.getZ();

                                 float yaw = locMin.getYaw();
                                 float pitch = locMin.getPitch();

                                 String world = locMin.getWorld().getName();
                                 World welt = Bukkit.getWorld((String) world);

                                 cfg.set("X", (int) x);
                                 cfg.set("Y", (int) y);
                                 cfg.set("Z", (int) z);
                                 cfg.set("Yaw", (int) yaw);
                                 cfg.set("Pitch", (int) pitch);
                                 cfg.set("Welt", (String) world);
                              } else {
                                 p.sendMessage("§cKeine Berechtigung!");
                              }

                           } else {
                              if ((args[0].equalsIgnoreCase("start-set"))) {
                                 if (p.hasPermission("prison.*")) {
                                    File ordner = new File("plugins//Prisons");
                                    File file = new File("plugins//Prisons//start.yml");
                                    if (!ordner.exists()) {
                                       ordner.mkdir();
                                    }
                                    if (!file.exists()) {
                                       try {
                                          file.createNewFile();
                                       } catch (IOException i) {
                                          p.sendMessage("§cstart.yml konnte nicht erstellt werden !");
                                       }
                                    }
                                    YamlConfiguration cfg = YamlConfiguration
                                          .loadConfiguration((File) file);
                                    Location locMin = p.getLocation();

                                    double x = locMin.getX();
                                    double y = locMin.getY();
                                    double z = locMin.getZ();

                                    float yaw = locMin.getYaw();
                                    float pitch = locMin.getPitch();

                                    String world = locMin.getWorld().getName();
                                    World welt = Bukkit.getWorld((String) world);

                                    cfg.set("X", (int) x);
                                    cfg.set("Y", (int) y);
                                    cfg.set("Z", (int) z);
                                    cfg.set("Yaw", (int) yaw);
                                    cfg.set("Pitch", (int) pitch);
                                    cfg.set("Welt", (String) world);
                                 } else {
                                    p.sendMessage("§cKeine Berechtigung!");
                                 }

                              }
                           }
                        }

                     }

                  }
               }
            }
         }
      }

      return false;

   }

}
 







Antworten zu Minecraft Java Bukkit Config Probleme:

Hat dir diese Antwort geholfen?

Danke ButtonHilfreiche Antwort Button

Hi,

der YMLConfigurator erbt von der FileConfiguration-Klasse und dort existiert eine save Methode, ich gehe mal davon aus, dass dir diese fehlt:

Zitat
    /**
     * Saves this {@link FileConfiguration} to the specified location.
     * <p>
     * If the file does not exist, it will be created. If already exists, it
     * will be overwritten. If it cannot be overwritten or created, an
     * exception will be thrown.
     * <p>
     * This method will save using the system default encoding, or possibly
     * using UTF8.
     *
     * @param file File to save to.
     * @throws IOException Thrown when the given file cannot be written to for
     *     any reason.
     * @throws IllegalArgumentException Thrown when file is null.
     */
    public void save(File file) throws IOException {
        Validate.notNull(file, "File cannot be null");

        Files.createParentDirs(file);

        String data = saveToString();

        Writer writer = new OutputStreamWriter(new FileOutputStream(file), UTF8_OVERRIDE && !UTF_BIG ? Charsets.UTF_8 : Charset.defaultCharset());

        try {
            writer.write(data);
        } finally {
            writer.close();
        }
}



« Batch: zufälligen Ordner öffnenProgrammieren Grundlagen von 0 aufbauend. »
 

Schnelle Hilfe: Hier nach ähnlichen Fragen und passenden Tipps suchen!

Fremdwörter? Erklärungen im Lexikon!
Ipconfig
Ipconfig (Internet Protocol Configuration) ist ein Konsolenbefehl, mit dem man unter Microsoft Windows die aktuelle Konfiguration des installierten IP-Stacks auf einem Ne...

Quellcode
Ein Quellcode, auch als Quelltext bekannt, bezeichnet den unkompilierten Programm-Code einer Software. Quell- oder Programm-Code ist der auch für Menschen lesbare Co...

Unicode
Unicode ist ein international anerkannter Standard, der als universeller Zeichencode ("Universal Code") dient und durch das Unicode-Konsortium entwickelt und verwaltet wi...