Newer
Older
ChallengesJoinEntities / src / main / java / de / fanta / challengesjoinentities / commands / AdventureCommand / AdventureTempCommand.java
@fanta fanta on 6 Aug 2023 4 KB ProgressBar and StorageBox
package de.fanta.challengesjoinentities.commands.AdventureCommand;

import de.fanta.challengesjoinentities.ChallengesJoinEntities;
import de.fanta.challengesjoinentities.ChatUtil;
import de.fanta.challengesjoinentities.adventure.AdventureMapsConfig;
import de.fanta.challengesjoinentities.adventure.CategoriesConfig;
import de.iani.cubesideutils.bukkit.commands.SubCommand;
import de.iani.cubesideutils.commands.ArgsParser;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;

import java.io.File;
import java.io.IOException;
import java.util.List;

public class AdventureTempCommand extends SubCommand {
    private final ChallengesJoinEntities plugin;

    public AdventureTempCommand(ChallengesJoinEntities plugin) {
        this.plugin = plugin;
    }

    public boolean onCommand(CommandSender sender, Command command, String alias, String commandString, ArgsParser args) {
        FileConfiguration config = AdventureMapsConfig.getConfig();
        FileConfiguration catConfig = CategoriesConfig.getConfig();

        //File adventureCategories = new File("/home/storagebox/Adventure-Maps/");
        File adventureCategories = plugin.getAdventureMapsPath().toFile();
        File[] categories = adventureCategories.listFiles();
        if (categories != null) {
            for (File mapFolder : categories) {
                ChatUtil.sendNormalMessage(sender, "- " + mapFolder.getName());
                File[] maps = mapFolder.listFiles();
                if (maps != null) {
                    for (File map : maps) {
                        if (config.getKeys(false).contains(map.getName())) {
                            try {
                                File mapConfig = new File(map, "/Challenges/serverconfig.yml");
                                YamlConfiguration serverConfig = new YamlConfiguration();
                                serverConfig.load(mapConfig);
                                config.set(map.getName() + "." + "version", serverConfig.get("serverversion"));
                                config.save(AdventureMapsConfig.getFile());

                                List<String> catList = catConfig.getStringList(mapFolder.getName() + "." + "maps");
                                if (!catList.contains(map.getName())) {
                                    catList.add(map.getName());
                                    catConfig.set(mapFolder.getName() + "." + "maps", catList);
                                    catConfig.save(CategoriesConfig.getFile());
                                }

                            } catch (IOException | InvalidConfigurationException e) {
                                throw new RuntimeException(e);
                            }

                        }
                    }
                }
            }
        }

        return true;
    }





    /*public boolean onCommand(CommandSender sender, Command command, String alias, String commandString, ArgsParser args) {

        File adventureSaves = new File("/home/minecraft/saves/");
        File[] players = adventureSaves.listFiles();
        if (players != null) {
            for (File player : players) {
                ChatUtil.sendNormalMessage(sender, "- " + player.getName());

                File[] maps = player.listFiles();
                if (maps != null) {
                    for (File map : maps) {
                        ChatUtil.sendDebugMessage(sender, " - " + map.getName());
                        try {
                            NBTFile file = new NBTFile(new File(map, "/world/level.dat"));
                            NBTCompound data = file.getCompound("Data");
                            NBTCompound dataPacks = data.getCompound("DataPacks");

                            dataPacks.getStringList("Enabled").add("update_1_20");
                            dataPacks.getStringList("Disabled").add("bundle");

                            data.getStringList("enabled_features").add("minecraft:update_1_20");
                            data.getStringList("enabled_features").add("minecraft:vanilla");


                            file.save();

                        } catch (IOException e) {
                            throw new RuntimeException(e);
                        }
                    }
                }
            }
        }
        return true;
    }*/

    @Override
    public String getRequiredPermission() {
        return "challenge.command.temp";
    }
}