package cat.freya.khs.command.map; import cat.freya.khs.Main; import cat.freya.khs.command.util.ICommand; import cat.freya.khs.configuration.Config; import cat.freya.khs.configuration.Localization; import cat.freya.khs.configuration.Map; import cat.freya.khs.configuration.Maps; import cat.freya.khs.game.util.Status; import org.bukkit.World; import org.bukkit.entity.Player; import org.bukkit.scheduler.BukkitRunnable; import org.jetbrains.annotations.NotNull; import java.util.List; import java.util.stream.Collectors; public class Save implements ICommand { public static boolean runningBackup = false; public void execute(Player sender, String[] args) { if (!Config.mapSaveEnabled) { sender.sendMessage(Config.errorPrefix + Localization.message("MAPSAVE_DISABLED")); return; } if (Main.getInstance().getGame().getStatus() != Status.STANDBY) { sender.sendMessage(Config.errorPrefix + Localization.message("GAME_INPROGRESS")); return; } Map map = Maps.getMap(args[0]); if(map == null) { sender.sendMessage(Config.errorPrefix + Localization.message("INVALID_MAP")); return; } if (map.getSpawn().isNotSetup()) { sender.sendMessage(Config.errorPrefix + Localization.message("ERROR_GAME_SPAWN")); return; } if (map.isBoundsNotSetup()) { sender.sendMessage(Config.errorPrefix + Localization.message("ERROR_MAP_BOUNDS")); return; } sender.sendMessage(Config.messagePrefix + Localization.message("MAPSAVE_START")); sender.sendMessage(Config.warningPrefix + Localization.message("MAPSAVE_WARNING")); World world = map.getSpawn().load(); if (world == null) { sender.sendMessage(Config.warningPrefix + Localization.message("MAPSAVE_FAIL_WORLD")); return; } world.save(); BukkitRunnable runnable = new BukkitRunnable() { public void run() { sender.sendMessage( map.getWorldLoader().save() ); runningBackup = false; } }; runnable.runTaskAsynchronously(Main.getInstance()); runningBackup = true; } public String getLabel() { return "save"; } public String getUsage() { return ""; } public String getDescription() { return "Saves the map to its own separate playable map"; } public List autoComplete(@NotNull String parameter, @NotNull String typed) { if(parameter.equals("map")) { return Maps.getAllMaps().stream().map(Map::getName).collect(Collectors.toList()); } return null; } }