My Config does not get saved.

Discussion in 'Plugin Development' started by VNGC, Mar 23, 2020.

Thread Status:
Not open for further replies.
  1. Offline

    VNGC

    Hey, i am trying to set a config.yml in my Plugin, but it seems that it doesnt work. the Folder with the Config doesnt creates. is there something new since 1.8, or am i completely wrong with my code?

    my main:

    Code:
    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);
            }
        }
    
    }
    

    The Class where i am trying to save the Config:

    Code:
    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;
        }
    
    }
    

    thank you for help!
     
  2. Offline

    timtower Moderator Moderator

    @VNGC Do you get any errors? Are you sure that the code is running?
     
  3. Offline

    VNGC

    Thats weird... i dont have panel-control on the lobby, as im only the Dev, i only have the FTP access. i moved the plugin on one of the other bungee-servers, there it works perfectly... uhm... is it possible that PermissionsEx is the fault?



    edit: it gets saved in another folder called "Updater". why?


    Code:
    # This configuration file affects all plugins using the Updater system (version 2+ - http://forums.bukkit.org/threads/96681/ )
    # If you wish to use your API key, read http://wiki.bukkit.org/ServerMods_API and place it below.
    # Some updating systems will not adhere to the disabled value, but these may be turned off in their plugin's configuration.
    api-key: PUT_API_KEY_HERE
    disable: false
    
     
  4. Offline

    timtower Moderator Moderator

    Locked
    Bungeecord requies offline mode.
    Offline mode is not supported by Bukkit.
     
Thread Status:
Not open for further replies.

Share This Page