diff --git a/pom.xml b/pom.xml index 943512a..b639489 100644 --- a/pom.xml +++ b/pom.xml @@ -107,7 +107,7 @@ com.viaversion viaversion-api - 4.5.2-SNAPSHOT + 4.7.1-SNAPSHOT provided diff --git a/src/main/java/de/fanta/challengesjoinentities/ChallengesJoinEntities.java b/src/main/java/de/fanta/challengesjoinentities/ChallengesJoinEntities.java index a4d4ace..edfe56b 100644 --- a/src/main/java/de/fanta/challengesjoinentities/ChallengesJoinEntities.java +++ b/src/main/java/de/fanta/challengesjoinentities/ChallengesJoinEntities.java @@ -29,7 +29,6 @@ import de.fanta.challengesjoinentities.listeners.EntityListener; import de.fanta.challengesjoinentities.listeners.PlayerListener; import de.fanta.challengesjoinentities.schedular.BukkitScheduler; -import de.fanta.challengesjoinentities.schedular.FoliaScheduler; import de.fanta.challengesjoinentities.schedular.Scheduler; import de.fanta.challengesjoinentities.utils.Statistics; import de.iani.cubesidestats.api.CubesideStatisticsAPI; @@ -51,6 +50,7 @@ import org.bukkit.plugin.java.JavaPlugin; import org.jetbrains.annotations.Nullable; +import java.nio.file.Path; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; @@ -88,6 +88,12 @@ private Scheduler scheduler; + private Path challengeSavePath; + private Path adventureSavePath; + private Path aventureMapsPath; + private Path serverJarsPath; + private Path serverFolderPath; + public ChallengesJoinEntities() { this.entityData = new HashMap<>(); @@ -116,14 +122,17 @@ signManager.init(); } - try { + /*try { Class.forName("io.papermc.paper.threadedregions.scheduler.ScheduledTask"); getLogger().log(Level.INFO, "Folia found. Use Folia Scheduler"); scheduler = new FoliaScheduler(this); } catch (Throwable ignored) { getLogger().log(Level.INFO, "Bukkit found. Use Bukkit Scheduler"); scheduler = new BukkitScheduler(this); - } + }*/ + getLogger().log(Level.INFO, "Bukkit found. Use Bukkit Scheduler"); + scheduler = new BukkitScheduler(this); + this.globalDataHelper = new ChallengesGlobalDataHelper(this); this.config = new Config(this); @@ -145,7 +154,7 @@ challengesrouter.addCommandMapping(new ChallengeLoadCommand(this), "load"); challengesrouter.addCommandMapping(new ChallengesStatsCommand(plugin.getStatistics()), "stats"); challengesrouter.addCommandMapping(new ChallengeSetStatsCommand(plugin), "setstats"); - challengesrouter.addCommandMapping(new ChallengeClearSavesCommand(), "clearoldsaves"); + challengesrouter.addCommandMapping(new ChallengeClearSavesCommand(plugin), "clearoldsaves"); CommandRouter adventurerouter = new CommandRouter(getCommand("adventure")); adventurerouter.addCommandMapping(new AdventureLoadCommand(this), "load"); @@ -156,7 +165,7 @@ adventurerouter.addCommandMapping(new ChallengesRemovePlayerServer(this), "removeplayerfromserver"); adventurerouter.addCommandMapping(new AdventureConvertMapCommand(this), "convertmap"); adventurerouter.addCommandMapping(new AdventureLoadMapIconsCommand(this), "loadmapicons"); - adventurerouter.addCommandMapping(new AdventureClearSavesCommand(), "clearoldsaves"); + adventurerouter.addCommandMapping(new AdventureClearSavesCommand(plugin), "clearoldsaves"); adventurerouter.addCommandMapping(new AdventureTempCommand(this), "temp"); adventurerouter.addCommandMapping(new AdventureStartEventServerCommand(this), "starteventserver"); @@ -236,6 +245,7 @@ public void addPiglin(UUID piglinUUID, String serverName, String gpLocationName, String serverDisplayName, boolean saveToConfig) { addPiglin(piglinUUID, serverName, null, gpLocationName, serverDisplayName, saveToConfig); } + public void addPiglin(UUID piglinUUID, String serverName, @Nullable Integer mapVersion, String gpLocationName, String serverDisplayName, boolean saveToConfig) { JoinEntityData entityData = new JoinEntityData(serverName, mapVersion, piglinUUID, gpLocationName, serverDisplayName, JoinEntityData.ServerStatus.OFFLINE, JoinEntityData.EventStatus.NORMAL, 0, 0); this.entityData.put(serverName, entityData); @@ -428,4 +438,44 @@ public Scheduler getScheduler() { return scheduler; } + + public Path getChallengeSavePath() { + return challengeSavePath; + } + + public void setChallengeSavePath(Path challengeSavePath) { + this.challengeSavePath = challengeSavePath; + } + + public Path getAdventureSavePath() { + return adventureSavePath; + } + + public void setAdventureSavePath(Path adventureSavePath) { + this.adventureSavePath = adventureSavePath; + } + + public Path getAdventureMapsPath() { + return aventureMapsPath; + } + + public void setAventureMapsPath(Path aventureMapsPath) { + this.aventureMapsPath = aventureMapsPath; + } + + public Path getServerJarsPath() { + return serverJarsPath; + } + + public void setServerJarsPath(Path serverJarsPath) { + this.serverJarsPath = serverJarsPath; + } + + public Path getServerFolderPath() { + return serverFolderPath; + } + + public void setServerFolderPath(Path serverFolderPath) { + this.serverFolderPath = serverFolderPath; + } } diff --git a/src/main/java/de/fanta/challengesjoinentities/Config.java b/src/main/java/de/fanta/challengesjoinentities/Config.java index 2e793aa..1dea37f 100644 --- a/src/main/java/de/fanta/challengesjoinentities/Config.java +++ b/src/main/java/de/fanta/challengesjoinentities/Config.java @@ -6,6 +6,7 @@ import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.FileConfiguration; +import java.io.File; import java.util.HashSet; import java.util.Optional; import java.util.Set; @@ -41,6 +42,15 @@ } } + ConfigurationSection filaPathSection = config.getConfigurationSection("fileLocations"); + if (filaPathSection != null) { + plugin.setChallengeSavePath(new File(filaPathSection.getString("challengeSaves")).toPath()); + plugin.setAdventureSavePath(new File(filaPathSection.getString("adventureSaves")).toPath()); + plugin.setAventureMapsPath(new File(filaPathSection.getString("adventureMaps")).toPath()); + plugin.setServerJarsPath(new File(filaPathSection.getString("serverJars")).toPath()); + plugin.setServerFolderPath(new File(filaPathSection.getString("serverFolder")).toPath()); + } + ConfigurationSection challengeServerSection = config.getConfigurationSection("challenge"); if (challengeServerSection != null) { for (String serverName : challengeServerSection.getKeys(false)) { diff --git a/src/main/java/de/fanta/challengesjoinentities/Server.java b/src/main/java/de/fanta/challengesjoinentities/Server.java index 05c9f63..5b13d8d 100644 --- a/src/main/java/de/fanta/challengesjoinentities/Server.java +++ b/src/main/java/de/fanta/challengesjoinentities/Server.java @@ -12,9 +12,12 @@ import java.io.File; import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.StandardCopyOption; import java.util.HashMap; import java.util.Map; import java.util.UUID; +import java.util.concurrent.atomic.AtomicReference; public class Server { public static HashMap serverPlayers = new HashMap<>(); @@ -76,30 +79,17 @@ this.serverVersion = serverVersion; } - public void loadSaved(Player p, String slot) { - this.online = true; - serverPlayers.put(this, p.getUniqueId()); - UUID uuid = p.getUniqueId(); - File dir; - dir = new File("/home/minecraft/Server/" + this.serverType.getDir() + "/" + uuid + "/" + slot); - - if (!dir.isDirectory()) { - ChatUtil.sendErrorMessage(p, "Du hast noch keine Map gespeichert!"); - this.online = false; - serverPlayers.remove(this); - return; - } - - - load(p, this.serverType.getDir(), uuid + "/" + slot, getMapVersion(new File(dir + "/Challenges/serverconfig.yml"))); //TODO LOAD VERSION FROM ADVENTURE CONFIG - - } - public void loadSaved(Player p, UUID playerID, String slot) { this.online = true; serverPlayers.put(this, p.getUniqueId()); File dir; - dir = new File("/home/minecraft/" + this.serverType.getDir() + "/" + playerID + "/" + slot); + //dir = new File("/home/minecraft/" + this.serverType.getDir() + "/" + playerID + "/" + slot); + if (serverType == ServerType.CHALLENGES) { + dir = new File(plugin.getChallengeSavePath().toFile(), "/" + playerID + "/" + slot); + } else { + dir = new File(plugin.getAdventureSavePath().toFile(), "/" + playerID + "/" + slot); + } + String path = playerID + "/" + slot; @@ -118,7 +108,8 @@ if (playerVersion >= mapProtocolVersion) { this.online = true; serverPlayers.put(this, player.getUniqueId()); - File dir = new File("/home/minecraft/Adventure-Maps", category + "/" + map); + //File dir = new File("/home/storagebox/Adventure-Maps", category + "/" + map); + File dir = new File(plugin.getAdventureMapsPath().toFile(), category + "/" + map); if (!dir.isDirectory()) { ChatUtil.sendErrorMessage(player, "Map " + map + " nicht gefunden!"); this.online = false; @@ -134,18 +125,44 @@ public void load(Player p, String serverTypeDir, String targetDir, String ServerVersion) { plugin.getScheduler().runAsync(() -> { - File serverFolder = new File("/home/minecraft/Server/" + this.dir); + //File serverFolder = new File("/home/minecraft/Server/" + this.dir); + File serverFolder = new File(plugin.getServerFolderPath().toFile(), this.dir); File configs = new File(serverFolder, "/plugins/Challenges"); File end = new File(serverFolder, "/world_the_end"); File nether = new File(serverFolder, "/world_nether"); File world = new File(serverFolder, "/world"); File mlgworld = new File(serverFolder, "/mlg_challenge"); File serverJar = new File(serverFolder, "/paper.jar"); - File saveServerJar = new File("/home/minecraft/ServerJars/" + ServerVersion + "/paper.jar"); - File saveend = new File("/home/minecraft/" + serverTypeDir + "/" + targetDir + "/world_the_end"); - File savenether = new File("/home/minecraft/" + serverTypeDir + "/" + targetDir + "/world_nether"); - File saveworld = new File("/home/minecraft/" + serverTypeDir + "/" + targetDir + "/world"); - File saveconfigs = new File("/home/minecraft/" + serverTypeDir + "/" + targetDir + "/Challenges"); + //File saveServerJar = new File("/home/minecraft/ServerJars/" + ServerVersion + "/paper.jar"); + File saveServerJar = new File(plugin.getServerJarsPath().toFile(), ServerVersion + "/paper.jar"); + File saveend; + File savenether; + File saveworld; + File saveconfigs; + + + if (!serverTypeDir.equals("Adventure-Maps")) { + /*saveend = new File("/home/minecraft/" + serverTypeDir + "/" + targetDir + "/world_the_end"); + savenether = new File("/home/minecraft/" + serverTypeDir + "/" + targetDir + "/world_nether"); + saveworld = new File("/home/minecraft/" + serverTypeDir + "/" + targetDir + "/world"); + saveconfigs = new File("/home/minecraft/" + serverTypeDir + "/" + targetDir + "/Challenges");*/ + + saveend = new File(plugin.getChallengeSavePath().toFile(), targetDir + "/world_the_end"); + savenether = new File(plugin.getChallengeSavePath().toFile(), targetDir + "/world_nether"); + saveworld = new File(plugin.getChallengeSavePath().toFile(), targetDir + "/world"); + saveconfigs = new File(plugin.getChallengeSavePath().toFile(), targetDir + "/Challenges"); + } else { + /*saveend = new File("/home/storagebox/" + serverTypeDir + "/" + targetDir + "/world_the_end"); + savenether = new File("/home/storagebox/" + serverTypeDir + "/" + targetDir + "/world_nether"); + saveworld = new File("/home/storagebox/" + serverTypeDir + "/" + targetDir + "/world"); + saveconfigs = new File("/home/storagebox/" + serverTypeDir + "/" + targetDir + "/Challenges");*/ + + saveend = new File(plugin.getAdventureSavePath().toFile(), targetDir + "/world_the_end"); + savenether = new File(plugin.getAdventureSavePath().toFile(), targetDir + "/world_nether"); + saveworld = new File(plugin.getAdventureSavePath().toFile(), targetDir + "/world"); + saveconfigs = new File(plugin.getAdventureSavePath().toFile(), targetDir + "/Challenges"); + } + ChatUtil.sendNormalMessage(p, "Versuche Map zu laden!"); try { if (world.isDirectory()) { @@ -162,13 +179,22 @@ if (configs.isDirectory()) { FileUtils.deleteDirectory(configs); } - FileUtils.copyFile(saveServerJar, serverJar); - FileUtils.copyDirectory(saveconfigs, configs); - FileUtils.copyDirectory(saveworld, world); - FileUtils.copyDirectory(savenether, nether); - FileUtils.copyDirectory(saveend, end); - File serverConfigFile = new File("/home/minecraft/Server/" + this.dir + "/plugins/Challenges/serverconfig.yml"); + HashMap copyMap = new HashMap<>(); + copyMap.put(saveServerJar, serverJar); + copyMap.put(saveconfigs, configs); + copyMap.put(saveworld, world); + copyMap.put(savenether, nether); + copyMap.put(saveend, end); + moveFolderWithProgress(copyMap, p); + //FileUtils.copyFile(saveServerJar, serverJar); + //FileUtils.copyDirectory(saveconfigs, configs); + //FileUtils.copyDirectory(saveworld, world); + //FileUtils.copyDirectory(savenether, nether); + //FileUtils.copyDirectory(saveend, end); + + //File serverConfigFile = new File("/home/minecraft/Server/" + this.dir + "/plugins/Challenges/serverconfig.yml"); + File serverConfigFile = new File(plugin.getServerFolderPath().toFile(), this.dir + "/plugins/Challenges/serverconfig.yml"); YamlConfiguration serverConfig = new YamlConfiguration(); serverConfig.load(serverConfigFile); @@ -195,15 +221,66 @@ }); } + public static void moveFolderWithProgress(HashMap copyMap, Player player) throws IOException { + final long[] totalBytes = {0}; + final long[] copiedBytes = {0}; + AtomicReference progress = new AtomicReference<>(0.0); + + for (File sourceFolder : copyMap.keySet()) { + Files.walk(sourceFolder.toPath()).forEach(source -> { + if (!Files.isDirectory(source)) { + totalBytes[0] += source.toFile().length(); + } + }); + } + + for (File sourceFolder : copyMap.keySet()) { + Files.walk(sourceFolder.toPath()).forEach(source -> { + try { + File target = new File(copyMap.get(sourceFolder).toPath().resolve(sourceFolder.toPath().relativize(source)).toString()); + if (Files.isDirectory(source)) { + target.mkdir(); + } else { + Files.copy(source, target.toPath(), StandardCopyOption.REPLACE_EXISTING); + copiedBytes[0] += source.toFile().length(); + progress.set((double) copiedBytes[0] / totalBytes[0] * 100); + player.sendActionBar(ChatUtil.GREEN + "Kopiere Welt: " + getProgressBar(progress.get())); + } + } catch (IOException e) { + e.printStackTrace(); + } + }); + } + } + + public static String getProgressBar(double value) { + int progress = (int) (value / 100 * 40); + + StringBuilder progressBar = new StringBuilder(); + progressBar.append(ChatUtil.RED + "["); + for (int i = 0; i < 40; i++) { + if (i < progress) { + progressBar.append(ChatUtil.PINK + "|"); + } else { + progressBar.append(ChatUtil.GREEN + "|"); + } + } + progressBar.append(ChatUtil.RED + "] " + ChatUtil.PINK + String.format("%.2f", value) + "%"); + + return progressBar.toString(); + } + public void start(Player player) { ProcessBuilder processBuilder = new ProcessBuilder(); boolean eventServer = false; if (this.serverType == ServerType.ADVENTURE && plugin.getEventServerPlayerList().contains(player.getUniqueId())) { - processBuilder.command("screen", "-AmdS", player.getName(), "./event.sh").directory(new File("/home/minecraft/Server/" + this.dir)); + //processBuilder.command("screen", "-AmdS", player.getName(), "./event.sh").directory(new File("/home/minecraft/Server/" + this.dir)); + processBuilder.command("screen", "-AmdS", player.getName(), "./event.sh").directory(new File(plugin.getServerFolderPath().toFile(), this.dir)); plugin.getEventServerPlayerList().remove(player.getUniqueId()); eventServer = true; } else { - processBuilder.command("screen", "-AmdS", player.getName(), "./start.sh").directory(new File("/home/minecraft/Server/" + this.dir)); + //processBuilder.command("screen", "-AmdS", player.getName(), "./start.sh").directory(new File("/home/minecraft/Server/" + this.dir)); + processBuilder.command("screen", "-AmdS", player.getName(), "./start.sh").directory(new File(plugin.getServerFolderPath().toFile(), this.dir)); } try { @@ -243,8 +320,9 @@ e.printStackTrace(); } String configServerVersion = serverConfiguration.getString("serverversion"); - File serverversionfolder = new File("/home/minecraft/ServerJars/" + configServerVersion); + //File serverversionfolder = new File("/home/minecraft/ServerJars/" + configServerVersion); if (configServerVersion != null) { + File serverversionfolder = new File(plugin.getServerJarsPath().toFile(), configServerVersion); if (serverversionfolder.isDirectory()) { serverVersion = configServerVersion; } else { diff --git a/src/main/java/de/fanta/challengesjoinentities/commands/AdventureCommand/AdventureClearSavesCommand.java b/src/main/java/de/fanta/challengesjoinentities/commands/AdventureCommand/AdventureClearSavesCommand.java index 2af099c..2d01fe8 100644 --- a/src/main/java/de/fanta/challengesjoinentities/commands/AdventureCommand/AdventureClearSavesCommand.java +++ b/src/main/java/de/fanta/challengesjoinentities/commands/AdventureCommand/AdventureClearSavesCommand.java @@ -1,5 +1,6 @@ package de.fanta.challengesjoinentities.commands.AdventureCommand; +import de.fanta.challengesjoinentities.ChallengesJoinEntities; import de.fanta.challengesjoinentities.ChatUtil; import de.iani.cubesideutils.StringUtil; import de.iani.cubesideutils.bukkit.commands.SubCommand; @@ -20,7 +21,10 @@ public class AdventureClearSavesCommand extends SubCommand { - public AdventureClearSavesCommand() { + private final ChallengesJoinEntities plugin; + + public AdventureClearSavesCommand(ChallengesJoinEntities plugin) { + this.plugin = plugin; } public boolean onCommand(CommandSender sender, Command command, String alias, String commandString, ArgsParser args) { @@ -29,37 +33,40 @@ return true; } - File adventureSaveFolder = new File("/home/minecraft/Adventure-saves"); //DELETE OLD AdventureMaps - if (adventureSaveFolder.isDirectory()) { - File[] playerFolders; - playerFolders = adventureSaveFolder.listFiles(); - if (playerFolders != null) { - int deletecounter = 0; - long starttime = System.currentTimeMillis(); - for (File playerFolder : playerFolders) { - File[] saveFolders; - saveFolders = playerFolder.listFiles(); - if (saveFolders != null) { - try { - for (File map : saveFolders) { - BasicFileAttributes attr = Files.readAttributes(map.toPath(), BasicFileAttributes.class); - FileTime fileTime = attr.creationTime(); - if (10368000000L + fileTime.toMillis() <= System.currentTimeMillis()) { //120 Tage - FileUtils.deleteDirectory(map); - deletecounter++; + ChatUtil.sendNormalMessage(p, "Gespeicherte Adventure-Maps die älter als 120 Tage sind werden gelöscht. Dies kann einige Minuten dauern."); + plugin.getScheduler().runAsync(() -> { + File adventureSaveFolder = plugin.getAdventureSavePath().toFile(); //DELETE OLD AdventureMaps + if (adventureSaveFolder.isDirectory()) { + File[] playerFolders; + playerFolders = adventureSaveFolder.listFiles(); + if (playerFolders != null) { + int deletecounter = 0; + long starttime = System.currentTimeMillis(); + for (File playerFolder : playerFolders) { + File[] saveFolders; + saveFolders = playerFolder.listFiles(); + if (saveFolders != null) { + try { + for (File map : saveFolders) { + BasicFileAttributes attr = Files.readAttributes(map.toPath(), BasicFileAttributes.class); + FileTime fileTime = attr.creationTime(); + if (10368000000L + fileTime.toMillis() <= System.currentTimeMillis()) { //120 Tage + FileUtils.deleteDirectory(map); + deletecounter++; + } } + if (Objects.requireNonNull(playerFolder.listFiles()).length == 0) { + FileUtils.deleteDirectory(playerFolder); + } + } catch (IOException ex) { + Bukkit.getLogger().log(Level.SEVERE, "Fehler beim löschen einer Map", ex); } - if (Objects.requireNonNull(playerFolder.listFiles()).length == 0) { - FileUtils.deleteDirectory(playerFolder); - } - } catch (IOException ex) { - Bukkit.getLogger().log(Level.SEVERE, "Fehler beim löschen einer Map", ex); } } + ChatUtil.sendNormalMessage(p, "Es wurden: " + deletecounter + " maps in " + StringUtil.formatTimespan(System.currentTimeMillis() - starttime) + " gelöscht"); } - ChatUtil.sendNormalMessage(p, "Es wurden: " + deletecounter + " maps in " + StringUtil.formatTimespan(System.currentTimeMillis() - starttime) + " gelöscht"); } - } + }); return true; } diff --git a/src/main/java/de/fanta/challengesjoinentities/commands/AdventureCommand/AdventureConvertMapCommand.java b/src/main/java/de/fanta/challengesjoinentities/commands/AdventureCommand/AdventureConvertMapCommand.java index 5f70342..cd578ac 100644 --- a/src/main/java/de/fanta/challengesjoinentities/commands/AdventureCommand/AdventureConvertMapCommand.java +++ b/src/main/java/de/fanta/challengesjoinentities/commands/AdventureCommand/AdventureConvertMapCommand.java @@ -188,7 +188,7 @@ ChatUtil.sendNormalMessage(player, "Konvertierung fertig."); - File destFolder = new File("/home/minecraft/Adventure-Maps/test/" + newFolderName); + File destFolder = new File(plugin.getAdventureMapsPath().toFile(), "test/" + newFolderName); try { FileUtils.moveDirectory(newFolderFile, destFolder); diff --git a/src/main/java/de/fanta/challengesjoinentities/commands/AdventureCommand/AdventureLoadMapIconsCommand.java b/src/main/java/de/fanta/challengesjoinentities/commands/AdventureCommand/AdventureLoadMapIconsCommand.java index b50c70a..113ebfd 100644 --- a/src/main/java/de/fanta/challengesjoinentities/commands/AdventureCommand/AdventureLoadMapIconsCommand.java +++ b/src/main/java/de/fanta/challengesjoinentities/commands/AdventureCommand/AdventureLoadMapIconsCommand.java @@ -23,7 +23,8 @@ } public boolean onCommand(CommandSender sender, Command command, String alias, String commandString, ArgsParser args) { - File adventureCategories = new File("/home/minecraft/Adventure-Maps/"); + //File adventureCategories = new File("/home/storagebox/Adventure-Maps/"); + File adventureCategories = plugin.getAdventureMapsPath().toFile(); File[] categories = adventureCategories.listFiles(); if (categories != null) { for (File mapFolder : categories) { diff --git a/src/main/java/de/fanta/challengesjoinentities/commands/AdventureCommand/AdventureTempCommand.java b/src/main/java/de/fanta/challengesjoinentities/commands/AdventureCommand/AdventureTempCommand.java index 0109fa1..68e372c 100644 --- a/src/main/java/de/fanta/challengesjoinentities/commands/AdventureCommand/AdventureTempCommand.java +++ b/src/main/java/de/fanta/challengesjoinentities/commands/AdventureCommand/AdventureTempCommand.java @@ -27,7 +27,8 @@ FileConfiguration config = AdventureMapsConfig.getConfig(); FileConfiguration catConfig = CategoriesConfig.getConfig(); - File adventureCategories = new File("/home/minecraft/Adventure-Maps/"); + //File adventureCategories = new File("/home/storagebox/Adventure-Maps/"); + File adventureCategories = plugin.getAdventureMapsPath().toFile(); File[] categories = adventureCategories.listFiles(); if (categories != null) { for (File mapFolder : categories) { diff --git a/src/main/java/de/fanta/challengesjoinentities/commands/AdventureCommand/AdventureTestMapCommand.java b/src/main/java/de/fanta/challengesjoinentities/commands/AdventureCommand/AdventureTestMapCommand.java index 3d8ae3f..9102bd2 100644 --- a/src/main/java/de/fanta/challengesjoinentities/commands/AdventureCommand/AdventureTestMapCommand.java +++ b/src/main/java/de/fanta/challengesjoinentities/commands/AdventureCommand/AdventureTestMapCommand.java @@ -9,6 +9,11 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +import java.io.File; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; + public class AdventureTestMapCommand extends SubCommand { private final ChallengesJoinEntities plugin; @@ -34,17 +39,74 @@ ChatUtil.sendErrorMessage(p, "Du kannst nur einen Server starten!"); } } else { - ChatUtil.sendWarningMessage(p, "/ladventure testmap "); + ChatUtil.sendWarningMessage(p, "/adventure testmap "); } } else { - ChatUtil.sendWarningMessage(p, "/ladventure testmap "); + ChatUtil.sendWarningMessage(p, "/adventure testmap "); } } else { - ChatUtil.sendWarningMessage(p, "/ladventure testmap "); + ChatUtil.sendWarningMessage(p, "/adventure testmap "); } } else { ChatUtil.sendErrorMessage(p, "Keine Rechte!"); } return true; } + + @Override + public Collection onTabComplete(CommandSender sender, Command command, String alias, ArgsParser args) { + int i = args.remaining(); + Collection completions = new ArrayList<>(); + if (i == 1) { + //File adventureCategories = new File("/home/storagebox/Adventure-Maps/"); + File adventureCategories = plugin.getAdventureMapsPath().toFile(); + File[] files = adventureCategories.listFiles(); + if (files != null) { + for (File file : files) { + if (file.isDirectory()) { + completions.add(file.getName()); + } + } + return completions; + } + } + + String category = args.hasNext() ? args.getNext() : null; + + if (category != null && i == 2) { + //File adventureMaps = new File("/home/storagebox/Adventure-Maps/" + category + "/"); + File adventureMaps = new File(plugin.getAdventureMapsPath().toFile(), category + "/"); + File[] files = adventureMaps.listFiles(); + if (files != null) { + for (File file : files) { + if (file.isDirectory()) { + completions.add(file.getName()); + } + } + return completions; + } + } + + if (category != null && i == 3) { + //File serverJars = new File("/home/minecraft/ServerJars"); + File serverJars = plugin.getServerJarsPath().toFile(); + File[] files = serverJars.listFiles(); + if (files != null) { + for (File file : files) { + if (file.isDirectory()) { + completions.add(file.getName()); + } + } + return completions; + } + } + + + return Collections.emptyList(); + } + + @Override + public String getRequiredPermission() { + return "challenges.starttestmap"; + } } diff --git a/src/main/java/de/fanta/challengesjoinentities/commands/ChallengesCommand/ChallengeClearSavesCommand.java b/src/main/java/de/fanta/challengesjoinentities/commands/ChallengesCommand/ChallengeClearSavesCommand.java index a232a40..eb6e497 100644 --- a/src/main/java/de/fanta/challengesjoinentities/commands/ChallengesCommand/ChallengeClearSavesCommand.java +++ b/src/main/java/de/fanta/challengesjoinentities/commands/ChallengesCommand/ChallengeClearSavesCommand.java @@ -1,5 +1,6 @@ package de.fanta.challengesjoinentities.commands.AdventureCommand; +import de.fanta.challengesjoinentities.ChallengesJoinEntities; import de.fanta.challengesjoinentities.ChatUtil; import de.iani.cubesideutils.StringUtil; import de.iani.cubesideutils.bukkit.commands.SubCommand; @@ -20,7 +21,10 @@ public class ChallengeClearSavesCommand extends SubCommand { - public ChallengeClearSavesCommand() { + private final ChallengesJoinEntities plugin; + + public ChallengeClearSavesCommand(ChallengesJoinEntities plugin) { + this.plugin = plugin; } public boolean onCommand(CommandSender sender, Command command, String alias, String commandString, ArgsParser args) { @@ -29,37 +33,40 @@ return true; } - File challengeSaveFolder = new File("/home/minecraft/saves"); //DELETE OLD ChallengeMaps - if (challengeSaveFolder.isDirectory()) { - File[] playerFolders; - playerFolders = challengeSaveFolder.listFiles(); - if (playerFolders != null) { - int deletecounter = 0; - long starttime = System.currentTimeMillis(); - for (File playerFolder : playerFolders) { - File[] saveFolders; - saveFolders = playerFolder.listFiles(); - if (saveFolders != null) { - try { - for (File map : saveFolders) { - BasicFileAttributes attr = Files.readAttributes(map.toPath(), BasicFileAttributes.class); - FileTime fileTime = attr.creationTime(); - if (10368000000L + fileTime.toMillis() <= System.currentTimeMillis()) { //120 Tage - FileUtils.deleteDirectory(map); - deletecounter++; + ChatUtil.sendNormalMessage(p, "Gespeicherte Challenges die älter als 120 Tage sind werden gelöscht. Dies kann einige Minuten dauern."); + plugin.getScheduler().runAsync(() -> { + File challengeSaveFolder = plugin.getChallengeSavePath().toFile(); //DELETE OLD ChallengeMaps + if (challengeSaveFolder.isDirectory()) { + File[] playerFolders; + playerFolders = challengeSaveFolder.listFiles(); + if (playerFolders != null) { + int deletecounter = 0; + long starttime = System.currentTimeMillis(); + for (File playerFolder : playerFolders) { + File[] saveFolders; + saveFolders = playerFolder.listFiles(); + if (saveFolders != null) { + try { + for (File map : saveFolders) { + BasicFileAttributes attr = Files.readAttributes(map.toPath(), BasicFileAttributes.class); + FileTime fileTime = attr.creationTime(); + if (10368000000L + fileTime.toMillis() <= System.currentTimeMillis()) { //120 Tage + FileUtils.deleteDirectory(map); + deletecounter++; + } } + if (Objects.requireNonNull(playerFolder.listFiles()).length == 0) { + FileUtils.deleteDirectory(playerFolder); + } + } catch (IOException ex) { + Bukkit.getLogger().log(Level.SEVERE, "Fehler beim löschen einer Map", ex); } - if (Objects.requireNonNull(playerFolder.listFiles()).length == 0) { - FileUtils.deleteDirectory(playerFolder); - } - } catch (IOException ex) { - Bukkit.getLogger().log(Level.SEVERE, "Fehler beim löschen einer Map", ex); } } + ChatUtil.sendNormalMessage(p, "Es wurden: " + deletecounter + " maps in " + StringUtil.formatTimespan(System.currentTimeMillis() - starttime) + " gelöscht"); } - ChatUtil.sendNormalMessage(p, "Es wurden: " + deletecounter + " maps in " + StringUtil.formatTimespan(System.currentTimeMillis() - starttime) + " gelöscht"); } - } + }); return true; } diff --git a/src/main/java/de/fanta/challengesjoinentities/loadgui/AdventureLoadGUI.java b/src/main/java/de/fanta/challengesjoinentities/loadgui/AdventureLoadGUI.java index e55c6d5..2fa050d 100644 --- a/src/main/java/de/fanta/challengesjoinentities/loadgui/AdventureLoadGUI.java +++ b/src/main/java/de/fanta/challengesjoinentities/loadgui/AdventureLoadGUI.java @@ -48,10 +48,15 @@ protected void rebuildInventory() { Player player = getPlayer(); UUID savePlayerID = savePlayerList.get(player.getUniqueId()); - File adventureSave1 = new File("/home/minecraft/Adventure-saves/" + savePlayerID + "/1"); + /*File adventureSave1 = new File("/home/minecraft/Adventure-saves/" + savePlayerID + "/1"); File adventureSave2 = new File("/home/minecraft/Adventure-saves/" + savePlayerID + "/2"); File adventureSave3 = new File("/home/minecraft/Adventure-saves/" + savePlayerID + "/3"); - File adventureSaveAuto = new File("/home/minecraft/Adventure-saves/" + savePlayerID + "/autosave"); + File adventureSaveAuto = new File("/home/minecraft/Adventure-saves/" + savePlayerID + "/autosave");*/ + + File adventureSave1 = new File(plugin.getAdventureSavePath().toFile(), savePlayerID + "/1"); + File adventureSave2 = new File(plugin.getAdventureSavePath().toFile(), savePlayerID + "/2"); + File adventureSave3 = new File(plugin.getAdventureSavePath().toFile(), savePlayerID + "/3"); + File adventureSaveAuto = new File(plugin.getAdventureSavePath().toFile(), savePlayerID + "/autosave"); for (int i = 0; i < WINDOW_SIZE; i++) { ItemStack item; @@ -80,10 +85,15 @@ Player p = getPlayer(); UUID savePlayerID = savePlayerList.get(p.getUniqueId()); - File adventureSave1 = new File("/home/minecraft/Adventure-saves/" + savePlayerID + "/1"); + /*File adventureSave1 = new File("/home/minecraft/Adventure-saves/" + savePlayerID + "/1"); File adventureSave2 = new File("/home/minecraft/Adventure-saves/" + savePlayerID + "/2"); File adventureSave3 = new File("/home/minecraft/Adventure-saves/" + savePlayerID + "/3"); - File adventureSaveAuto = new File("/home/minecraft/Adventure-saves/" + savePlayerID + "/autosave"); + File adventureSaveAuto = new File("/home/minecraft/Adventure-saves/" + savePlayerID + "/autosave");*/ + + File adventureSave1 = new File(plugin.getAdventureSavePath().toFile(), savePlayerID + "/1"); + File adventureSave2 = new File(plugin.getAdventureSavePath().toFile(), savePlayerID + "/2"); + File adventureSave3 = new File(plugin.getAdventureSavePath().toFile(), savePlayerID + "/3"); + File adventureSaveAuto = new File(plugin.getAdventureSavePath().toFile(), savePlayerID + "/autosave"); int slot = event.getSlot(); diff --git a/src/main/java/de/fanta/challengesjoinentities/loadgui/ChallengeLoadGUI.java b/src/main/java/de/fanta/challengesjoinentities/loadgui/ChallengeLoadGUI.java index 122d82c..a18ad20 100644 --- a/src/main/java/de/fanta/challengesjoinentities/loadgui/ChallengeLoadGUI.java +++ b/src/main/java/de/fanta/challengesjoinentities/loadgui/ChallengeLoadGUI.java @@ -42,10 +42,15 @@ protected void rebuildInventory() { Player p = getPlayer(); UUID savePlayerID = savePlayerList.get(p.getUniqueId()); - File challengeSave1 = new File("/home/minecraft/saves/" + savePlayerID + "/1"); + /*File challengeSave1 = new File("/home/minecraft/saves/" + savePlayerID + "/1"); File challengeSave2 = new File("/home/minecraft/saves/" + savePlayerID + "/2"); File challengeSave3 = new File("/home/minecraft/saves/" + savePlayerID + "/3"); - File challengeSaveAuto = new File("/home/minecraft/saves/" + savePlayerID + "/autosave"); + File challengeSaveAuto = new File("/home/minecraft/saves/" + savePlayerID + "/autosave");*/ + + File challengeSave1 = new File(plugin.getChallengeSavePath().toFile(), savePlayerID + "/1"); + File challengeSave2 = new File(plugin.getChallengeSavePath().toFile(), savePlayerID + "/2"); + File challengeSave3 = new File(plugin.getChallengeSavePath().toFile(), savePlayerID + "/3"); + File challengeSaveAuto = new File(plugin.getChallengeSavePath().toFile(), savePlayerID + "/autosave"); for (int i = 0; i < WINDOW_SIZE; i++) { ItemStack item; @@ -117,10 +122,15 @@ Player p = getPlayer(); UUID savePlayerID = savePlayerList.get(p.getUniqueId()); - File challengeSave1 = new File("/home/minecraft/saves/" + savePlayerID + "/1"); + /*File challengeSave1 = new File("/home/minecraft/saves/" + savePlayerID + "/1"); File challengeSave2 = new File("/home/minecraft/saves/" + savePlayerID + "/2"); File challengeSave3 = new File("/home/minecraft/saves/" + savePlayerID + "/3"); - File challengeSaveAuto = new File("/home/minecraft/saves/" + savePlayerID + "/autosave"); + File challengeSaveAuto = new File("/home/minecraft/saves/" + savePlayerID + "/autosave");*/ + + File challengeSave1 = new File(plugin.getChallengeSavePath().toFile(), savePlayerID + "/1"); + File challengeSave2 = new File(plugin.getChallengeSavePath().toFile(), savePlayerID + "/2"); + File challengeSave3 = new File(plugin.getChallengeSavePath().toFile(), savePlayerID + "/3"); + File challengeSaveAuto = new File(plugin.getChallengeSavePath().toFile(), savePlayerID + "/autosave"); int slot = event.getSlot(); diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index de54dde..a7d7d0e 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -1 +1,7 @@ piglins: +fileLocations: + adventureMaps: "/home/storagebox/Adventure-Maps/" + adventureSaves: "/home/storagebox/Adventure-saves/" + challengeSaves: "/home/storagebox/Challenge-saves" + serverJars: "/home/minecraft/ServerJars/" + serverFolder: "/home/minecraft/Server/"