Solved My Config doesnt get Saved in Hub Server

Discussion in 'Spigot Plugin Development' started by RealRivex, Mar 24, 2020.

  1. Hello,
    i tried to save a config, and it works on my game-Server. but on my Hub-Bungeecord-Server it doesnt work. the folder simply doesnt create and idk why.
    the thing is there is nothing in console.
    pls help.
    my config class:

    Code (Text):
    package lobby.commands;

    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.entity.Player;

    import lobby.main.Main;

    public class setspawn implements CommandExecutor {

        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            if (sender instanceof Player) {
                Player player = (Player) sender;
                if (player.hasPermission("Lobby.spawn")) {
                    if (args.length == 0) {
                        FileConfiguration config = Main.getPlugin().getConfig();
                        config.set("Spawn.World", player.getWorld().getName());
                        config.set("Spawn.X", player.getLocation().getX());
                        config.set("Spawn.Y", player.getLocation().getY());
                        config.set("Spawn.Z", player.getLocation().getZ());
                        config.set("Spawn.Yaw", player.getLocation().getYaw());
                        config.set("Spawn.Pitch", player.getLocation().getPitch());
                        Main.getPlugin().saveConfig();
                        player.sendMessage("§aDu hast den §6Spawnpoint §aauf diese Position gesetzt!");
                    }
                } else
                    player.sendMessage("Du hast keine Rechte!");

            }

            return false;
        }

    }
     

    my main:

    Code (Text):
    package lobby.main;

    import org.bukkit.Bukkit;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.scoreboard.Scoreboard;

    import lobby.commands.aliases;
    import lobby.commands.build;
    import lobby.commands.setspawn;
    import lobby.listeners.chat;
    import lobby.listeners.compass;
    import lobby.listeners.join;
    import lobby.listeners.soup;
    import lobby.listeners.voidtp;

    public class Main extends JavaPlugin implements Listener {
        private static Main plugin;

        static Scoreboard sb;

        @Override
        public void onEnable() {
            plugin = this;
            sb = Bukkit.getScoreboardManager().getNewScoreboard();

            sb.registerNewTeam("a").setPrefix("§bDev §8| §b");
            sb.registerNewTeam("b").setPrefix("§6VIP §8| §6");
            sb.registerNewTeam("z").setPrefix("§7Normi §8| §7");
            sb.registerNewTeam("c").setPrefix("§4Admin §8| §4");
            sb.registerNewTeam("d").setPrefix("§5Mod §8| §5");

            // Listeners:
            PluginManager pm = Bukkit.getPluginManager();
            pm.registerEvents(new soup(), this);
            pm.registerEvents(new compass(), this);
            pm.registerEvents(new join(), this);
            pm.registerEvents(new voidtp(), this);
            pm.registerEvents(new chat(), this);
            pm.registerEvents(this, this);
            pm.registerEvents(new aliases(), this);
            for (Player all : Bukkit.getOnlinePlayers()) {
                setPrefix(all);
            }
            // Commands;
            getCommand("build").setExecutor(new build());
            getCommand("setspawn").setExecutor(new setspawn());
        }

        public static Main getPlugin() {
            return plugin;
        }

        @EventHandler
        public void onJoin(PlayerJoinEvent event) {
            Player player = (Player) event.getPlayer();
            setPrefix(player);
            for (Player all : Bukkit.getOnlinePlayers()) {
                setPrefix(all);
            }
        }

        @SuppressWarnings("deprecation")
        public static void setPrefix(Player player) {
            String team = " ";

            if (player.getName().equalsIgnoreCase("VNGC")) {
                team = "a";
            } else if (player.getName().equalsIgnoreCase("jarException")) {
                team = "a";
            } else if (player.getName().equalsIgnoreCase("D4rkLama")) {
                team = "c";
            } else if (player.getName().equalsIgnoreCase("Konrad_2")) {
                team = "b";
            } else if (player.getName().equalsIgnoreCase("EinfachLee")) {
                team = "b";
            } else
                team = "z";

            sb.getTeam(team).addPlayer(player);

            for (Player all : Bukkit.getOnlinePlayers()) {
                all.setScoreboard(sb);
            }
        }

    }
     
    plugin.yml:

    Code (Text):
    name: Lobby
    version: 1.0
    main: lobby.main.Main
    description:
    author: VNGC
    commands:
      warp:
      damager:
      build:
      setspawn:
     
     
  2. Try to add this on top of your onEnable method:

    Code (Text):
    if(!this.getDataFolder().exists()) {
        this.getDataFolder().mkdirs();
    }
     
  3. worked, thank you! but why does it work in my other world without checking the folder, but here not?
     
  4. Probably the data folder was already created on the other server. But as you can't assure that the folder will be there every time your plugin gets enabled, it's a good practice to check and create the folder manually every time.

    Glad I helped :)
     
  5. well, on the other server it still get creates, as well if i delete the folder. so i dont think thats the issue. but it worked with your help, so im good :)