From 3c1a4d728bccfdd54179a0a204b11aad984a2b1c Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Fri, 10 Aug 2018 21:01:07 +0200 Subject: [PATCH] Remove unsafe performance tweaks --- pom.xml | 2 +- .../de/erethon/dungeonsxl/DungeonsXL.java | 1 - .../announcer/AnnouncerStartGameTask.java | 2 +- .../dungeonsxl/command/CreateCommand.java | 2 +- .../dungeonsxl/command/EditCommand.java | 2 +- .../dungeonsxl/command/EnterCommand.java | 2 +- .../dungeonsxl/command/ImportCommand.java | 12 +-- .../dungeonsxl/command/PlayCommand.java | 2 +- .../dungeonsxl/command/SaveCommand.java | 2 +- .../dungeonsxl/command/TestCommand.java | 2 +- .../erethon/dungeonsxl/config/DMessage.java | 1 - .../erethon/dungeonsxl/config/MainConfig.java | 28 ------ .../de/erethon/dungeonsxl/global/DPortal.java | 2 +- .../player/CreateDInstancePlayerTask.java | 97 ------------------- .../dungeonsxl/player/DEditPlayer.java | 9 +- .../dungeonsxl/player/DGamePlayer.java | 20 +--- .../dungeonsxl/player/DGlobalPlayer.java | 2 +- .../dungeonsxl/world/BackupResourceTask.java | 41 -------- .../erethon/dungeonsxl/world/DEditWorld.java | 55 +++-------- .../erethon/dungeonsxl/world/DGameWorld.java | 20 +--- .../dungeonsxl/world/DResourceWorld.java | 77 ++++----------- .../erethon/dungeonsxl/world/DWorldCache.java | 2 +- 22 files changed, 53 insertions(+), 330 deletions(-) delete mode 100644 src/main/java/de/erethon/dungeonsxl/player/CreateDInstancePlayerTask.java delete mode 100644 src/main/java/de/erethon/dungeonsxl/world/BackupResourceTask.java diff --git a/pom.xml b/pom.xml index 10096610..d79db900 100644 --- a/pom.xml +++ b/pom.xml @@ -2,7 +2,7 @@ 4.0.0 de.erethon dungeonsxl - 0.16.1-SNAPSHOT + 0.16.1 jar DungeonsXL https://dre2n.github.io diff --git a/src/main/java/de/erethon/dungeonsxl/DungeonsXL.java b/src/main/java/de/erethon/dungeonsxl/DungeonsXL.java index 7f4e2770..ca90f6f0 100644 --- a/src/main/java/de/erethon/dungeonsxl/DungeonsXL.java +++ b/src/main/java/de/erethon/dungeonsxl/DungeonsXL.java @@ -132,7 +132,6 @@ public class DungeonsXL extends DREPlugin { @Override public void onDisable() { - mainConfig.setTweaksEnabled(false); // Save saveData(); messageConfig.save(); diff --git a/src/main/java/de/erethon/dungeonsxl/announcer/AnnouncerStartGameTask.java b/src/main/java/de/erethon/dungeonsxl/announcer/AnnouncerStartGameTask.java index b89f2573..94350d64 100644 --- a/src/main/java/de/erethon/dungeonsxl/announcer/AnnouncerStartGameTask.java +++ b/src/main/java/de/erethon/dungeonsxl/announcer/AnnouncerStartGameTask.java @@ -101,7 +101,7 @@ public class AnnouncerStartGameTask extends BukkitRunnable { } for (Player player : game.getPlayers()) { - DGamePlayer.create(player, game.getWorld()); + new DGamePlayer(player, game.getWorld()); } announcer.endStartTask(); diff --git a/src/main/java/de/erethon/dungeonsxl/command/CreateCommand.java b/src/main/java/de/erethon/dungeonsxl/command/CreateCommand.java index 9ea09cc9..48a60b8e 100644 --- a/src/main/java/de/erethon/dungeonsxl/command/CreateCommand.java +++ b/src/main/java/de/erethon/dungeonsxl/command/CreateCommand.java @@ -97,7 +97,7 @@ public class CreateCommand extends DRECommand { MessageUtil.log(plugin, DMessage.LOG_WORLD_GENERATION_FINISHED.getMessage()); // Tp Player - DEditPlayer.create(player, editWorld); + new DEditPlayer(player, editWorld); } } diff --git a/src/main/java/de/erethon/dungeonsxl/command/EditCommand.java b/src/main/java/de/erethon/dungeonsxl/command/EditCommand.java index 53cd3c84..ec079319 100644 --- a/src/main/java/de/erethon/dungeonsxl/command/EditCommand.java +++ b/src/main/java/de/erethon/dungeonsxl/command/EditCommand.java @@ -86,7 +86,7 @@ public class EditCommand extends DRECommand { return; } - DEditPlayer.create(player, editWorld); + new DEditPlayer(player, editWorld); } } diff --git a/src/main/java/de/erethon/dungeonsxl/command/EnterCommand.java b/src/main/java/de/erethon/dungeonsxl/command/EnterCommand.java index 5c0aff9c..0ad6ecab 100644 --- a/src/main/java/de/erethon/dungeonsxl/command/EnterCommand.java +++ b/src/main/java/de/erethon/dungeonsxl/command/EnterCommand.java @@ -86,7 +86,7 @@ public class EnterCommand extends DRECommand { joining.sendMessage(DMessage.CMD_ENTER_SUCCESS.getMessage(joining.getName(), target.getName())); for (Player player : joining.getPlayers().getOnlinePlayers()) { - DGamePlayer.create(player, game.getWorld(), game.getType()); + new DGamePlayer(player, game.getWorld(), game.getType()); } } diff --git a/src/main/java/de/erethon/dungeonsxl/command/ImportCommand.java b/src/main/java/de/erethon/dungeonsxl/command/ImportCommand.java index e71df57f..008011e9 100644 --- a/src/main/java/de/erethon/dungeonsxl/command/ImportCommand.java +++ b/src/main/java/de/erethon/dungeonsxl/command/ImportCommand.java @@ -70,17 +70,7 @@ public class ImportCommand extends DRECommand { MessageUtil.log(plugin, DMessage.LOG_NEW_MAP.getMessage()); MessageUtil.log(plugin, DMessage.LOG_IMPORT_WORLD.getMessage()); - if (!plugin.getMainConfig().areTweaksEnabled()) { - FileUtil.copyDir(source, target, "playerdata", "stats"); - - } else { - new BukkitRunnable() { - @Override - public void run() { - FileUtil.copyDir(source, target, "playerdata", "stats"); - } - }.runTaskAsynchronously(plugin); - } + FileUtil.copyDir(source, target, "playerdata", "stats"); DResourceWorld resource = new DResourceWorld(plugin.getDWorlds(), args[1]); if (world.getEnvironment() != Environment.NORMAL) { diff --git a/src/main/java/de/erethon/dungeonsxl/command/PlayCommand.java b/src/main/java/de/erethon/dungeonsxl/command/PlayCommand.java index 1a4b93cb..d8665ce8 100644 --- a/src/main/java/de/erethon/dungeonsxl/command/PlayCommand.java +++ b/src/main/java/de/erethon/dungeonsxl/command/PlayCommand.java @@ -97,7 +97,7 @@ public class PlayCommand extends DRECommand { } new Game(dGroup, gameWorld); for (Player groupPlayer : dGroup.getPlayers().getOnlinePlayers()) { - DGamePlayer.create(groupPlayer, dGroup.getGameWorld()); + new DGamePlayer(groupPlayer, dGroup.getGameWorld()); } } diff --git a/src/main/java/de/erethon/dungeonsxl/command/SaveCommand.java b/src/main/java/de/erethon/dungeonsxl/command/SaveCommand.java index e9f7796d..22d55752 100644 --- a/src/main/java/de/erethon/dungeonsxl/command/SaveCommand.java +++ b/src/main/java/de/erethon/dungeonsxl/command/SaveCommand.java @@ -50,7 +50,7 @@ public class SaveCommand extends DRECommand { if (editWorld != null) { BackupMode backupMode = mainConfig.getBackupMode(); if (backupMode == BackupMode.ON_SAVE || backupMode == BackupMode.ON_DISABLE_AND_SAVE) { - editWorld.getResource().backup(mainConfig.areTweaksEnabled()); + editWorld.getResource().backup(); } editWorld.save(); diff --git a/src/main/java/de/erethon/dungeonsxl/command/TestCommand.java b/src/main/java/de/erethon/dungeonsxl/command/TestCommand.java index beec9bb0..3f2dd6d5 100644 --- a/src/main/java/de/erethon/dungeonsxl/command/TestCommand.java +++ b/src/main/java/de/erethon/dungeonsxl/command/TestCommand.java @@ -92,7 +92,7 @@ public class TestCommand extends DRECommand { return; } Game game = new Game(new DGroup(player, dungeon), GameTypeDefault.TEST, instance); - DGamePlayer.create(player, game.getWorld(), GameTypeDefault.TEST); + new DGamePlayer(player, game.getWorld(), GameTypeDefault.TEST); } } diff --git a/src/main/java/de/erethon/dungeonsxl/config/DMessage.java b/src/main/java/de/erethon/dungeonsxl/config/DMessage.java index c44ba9e9..4263932c 100644 --- a/src/main/java/de/erethon/dungeonsxl/config/DMessage.java +++ b/src/main/java/de/erethon/dungeonsxl/config/DMessage.java @@ -159,7 +159,6 @@ public enum DMessage implements Message { GROUP_KICKED_PLAYER("Group_KickedPlayer", "&4&v1&6 kicked the player &4&v2&6 from the group &4&v3&6."), GROUP_PLAYER_JOINED("Group_PlayerJoined", "&6Player &4&v1&6 has joined the group!"), GROUP_WAVE_FINISHED("Group_WaveFinished", "&6Your group finished wave no. &4&v1&6. The next one is going to start in &4&v2&6 seconds."), - LOG_DISABLED_TWEAKS("Log_DisabledTweaks", "&4Disabled performance tweaks because there is no support for this server software."), LOG_ERROR_DUNGEON_SETUP("Log_Error_DungeonSetup", "&4The setup of dungeon &6&v1&4 is incorrect. See https://github.com/DRE2N/DungeonsXL/wiki/dungeon-configuration for reference."), LOG_ERROR_MOB_ENCHANTMENT("Log_Error_MobEnchantment", "&4An error occurred while loading mob.yml: Enchantment &6&v1&4 doesn't exist!"), LOG_ERROR_MOBTYPE("Log_Error_MobType", "&4Error at loading mob.yml: Mob &6&v1&4 doesn't exist!"), diff --git a/src/main/java/de/erethon/dungeonsxl/config/MainConfig.java b/src/main/java/de/erethon/dungeonsxl/config/MainConfig.java index 6fb570b4..a880f354 100644 --- a/src/main/java/de/erethon/dungeonsxl/config/MainConfig.java +++ b/src/main/java/de/erethon/dungeonsxl/config/MainConfig.java @@ -94,7 +94,6 @@ public class MainConfig extends DREConfig { /* Performance */ private int maxInstances = 10; - private boolean tweaksEnabled = false; /* Secure Mode */ private boolean secureModeEnabled = false; @@ -346,20 +345,6 @@ public class MainConfig extends DREConfig { this.maxInstances = maxInstances; } - /** - * @return if the performance tweaks are enabled - */ - public boolean areTweaksEnabled() { - return tweaksEnabled; - } - - /** - * @param enabled if the performance tweaks are enabled - */ - public void setTweaksEnabled(boolean enabled) { - tweaksEnabled = enabled; - } - /** * @return if the secure mode is enabled */ @@ -526,10 +511,6 @@ public class MainConfig extends DREConfig { config.set("maxInstances", maxInstances); } - if (!config.contains("tweaksEnabled")) { - config.set("tweaksEnabled", tweaksEnabled); - } - if (!config.contains("secureMode.enabled")) { config.set("secureMode.enabled", secureModeEnabled); } @@ -659,15 +640,6 @@ public class MainConfig extends DREConfig { maxInstances = config.getInt("maxInstances"); } - if (config.contains("tweaksEnabled")) { - if (Internals.isAtLeast(Internals.v1_9_R1)) { - tweaksEnabled = config.getBoolean("tweaksEnabled"); - } else { - tweaksEnabled = false; - MessageUtil.log(DMessage.LOG_DISABLED_TWEAKS.getMessage()); - } - } - if (config.contains("secureMode.enabled")) { secureModeEnabled = config.getBoolean("secureMode.enabled"); } diff --git a/src/main/java/de/erethon/dungeonsxl/global/DPortal.java b/src/main/java/de/erethon/dungeonsxl/global/DPortal.java index 3792f43d..38663bf1 100644 --- a/src/main/java/de/erethon/dungeonsxl/global/DPortal.java +++ b/src/main/java/de/erethon/dungeonsxl/global/DPortal.java @@ -240,7 +240,7 @@ public class DPortal extends GlobalProtection { dGroup.setGameWorld(target); } - DGamePlayer.create(player, target); + new DGamePlayer(player, target); } @Override diff --git a/src/main/java/de/erethon/dungeonsxl/player/CreateDInstancePlayerTask.java b/src/main/java/de/erethon/dungeonsxl/player/CreateDInstancePlayerTask.java deleted file mode 100644 index 53b8b440..00000000 --- a/src/main/java/de/erethon/dungeonsxl/player/CreateDInstancePlayerTask.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright (C) 2012-2018 Frank Baumann - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package de.erethon.dungeonsxl.player; - -import de.erethon.commons.chat.MessageUtil; -import de.erethon.dungeonsxl.game.GameType; -import de.erethon.dungeonsxl.world.DEditWorld; -import de.erethon.dungeonsxl.world.DGameWorld; -import de.erethon.dungeonsxl.world.DInstanceWorld; -import java.util.UUID; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.entity.Player; -import org.bukkit.scheduler.BukkitRunnable; - -/** - * @author Daniel Saukel - */ -public class CreateDInstancePlayerTask extends BukkitRunnable { - - public static final String BAR = "\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588"; - - private UUID player; - private DInstanceWorld instance; - private GameType ready; - - private int i = 12; - - public CreateDInstancePlayerTask(Player player, DInstanceWorld instance) { - this.player = player.getUniqueId(); - this.instance = instance; - } - - public CreateDInstancePlayerTask(Player player, DInstanceWorld instance, GameType ready) { - this.player = player.getUniqueId(); - this.instance = instance; - this.ready = ready; - } - - @Override - public void run() { - Player player = Bukkit.getPlayer(this.player); - if (player == null || !player.isOnline()) { - cancel(); - return; - } - - if (instance.exists()) { - if (instance instanceof DGameWorld) { - DGamePlayer gamePlayer = new DGamePlayer(player, (DGameWorld) instance); - if (ready != null) { - gamePlayer.ready(ready); - } - - } else if (instance instanceof DEditWorld) { - new DEditPlayer(player, (DEditWorld) instance); - } - - cancel(); - return; - } - - StringBuilder bar = new StringBuilder(BAR); - int pos = i; - if (bar.length() - pos < 0) { - pos = bar.length(); - } - bar.insert(bar.length() - pos, ChatColor.GREEN.toString()); - - pos = i - 2; - if (pos > 0) { - bar.insert(bar.length() - pos, ChatColor.DARK_RED.toString()); - } - - MessageUtil.sendActionBarMessage(player, ChatColor.DARK_RED + bar.toString()); - - i--; - if (i == 0) { - i = 12; - } - } - -} diff --git a/src/main/java/de/erethon/dungeonsxl/player/DEditPlayer.java b/src/main/java/de/erethon/dungeonsxl/player/DEditPlayer.java index 0dd5edf5..4b8e85ba 100644 --- a/src/main/java/de/erethon/dungeonsxl/player/DEditPlayer.java +++ b/src/main/java/de/erethon/dungeonsxl/player/DEditPlayer.java @@ -43,7 +43,7 @@ public class DEditPlayer extends DInstancePlayer { private String[] linesCopy; private DEditWorld editWorld; - public DEditPlayer(final Player player, DEditWorld world) { + public DEditPlayer(Player player, DEditWorld world) { super(player, world.getWorld()); editWorld = world; @@ -72,13 +72,6 @@ public class DEditPlayer extends DInstancePlayer { } } - /** - * @param player the represented Player - * @param editWorld the player's EditWorld - */ - public static void create(Player player, DEditWorld editWorld) { - new CreateDInstancePlayerTask(player, editWorld).runTaskTimer(DungeonsXL.getInstance(), 0L, 5L); - } /* Getters and setters */ /** diff --git a/src/main/java/de/erethon/dungeonsxl/player/DGamePlayer.java b/src/main/java/de/erethon/dungeonsxl/player/DGamePlayer.java index 003dbe30..97600315 100644 --- a/src/main/java/de/erethon/dungeonsxl/player/DGamePlayer.java +++ b/src/main/java/de/erethon/dungeonsxl/player/DGamePlayer.java @@ -111,21 +111,11 @@ public class DGamePlayer extends DInstancePlayer { } } - /** - * @param player the represented Player - * @param gameWorld the player's GameWorld - */ - public static void create(Player player, DGameWorld gameWorld) { - create(player, gameWorld, null); - } - - /** - * @param player the represented Player - * @param gameWorld the player's GameWorld - * @param ready Any GameType if the player will be ready from the beginning null if the player will not be ready from the beginning - */ - public static void create(Player player, DGameWorld gameWorld, GameType ready) { - new CreateDInstancePlayerTask(player, gameWorld, ready).runTaskTimer(DungeonsXL.getInstance(), 0L, 5L); + public DGamePlayer(Player player, DGameWorld world, GameType ready) { + this(player, world); + if (ready != null) { + ready(ready); + } } /* Getters and setters */ diff --git a/src/main/java/de/erethon/dungeonsxl/player/DGlobalPlayer.java b/src/main/java/de/erethon/dungeonsxl/player/DGlobalPlayer.java index 10c6c605..b1526665 100644 --- a/src/main/java/de/erethon/dungeonsxl/player/DGlobalPlayer.java +++ b/src/main/java/de/erethon/dungeonsxl/player/DGlobalPlayer.java @@ -399,7 +399,7 @@ public class DGlobalPlayer implements PlayerWrapper { DGameWorld gameWorld = dungeon.getMap().instantiateAsGameWorld(true); dGroup.setGameWorld(gameWorld); new Game(dGroup, gameWorld).setTutorial(true); - DGamePlayer.create(player, gameWorld); + new DGamePlayer(player, gameWorld); } } diff --git a/src/main/java/de/erethon/dungeonsxl/world/BackupResourceTask.java b/src/main/java/de/erethon/dungeonsxl/world/BackupResourceTask.java deleted file mode 100644 index ea2bf3aa..00000000 --- a/src/main/java/de/erethon/dungeonsxl/world/BackupResourceTask.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (C) 2012-2018 Frank Baumann - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package de.erethon.dungeonsxl.world; - -import de.erethon.commons.misc.FileUtil; -import de.erethon.dungeonsxl.DungeonsXL; -import java.io.File; -import org.bukkit.scheduler.BukkitRunnable; - -/** - * @author Daniel Saukel - */ -public class BackupResourceTask extends BukkitRunnable { - - private DResourceWorld resource; - - public BackupResourceTask(DResourceWorld resource) { - this.resource = resource; - } - - @Override - public void run() { - File target = new File(DungeonsXL.BACKUPS, resource.getName() + "-" + System.currentTimeMillis()); - FileUtil.copyDir(resource.getFolder(), target); - } - -} diff --git a/src/main/java/de/erethon/dungeonsxl/world/DEditWorld.java b/src/main/java/de/erethon/dungeonsxl/world/DEditWorld.java index 4984e0e7..1eac48d6 100644 --- a/src/main/java/de/erethon/dungeonsxl/world/DEditWorld.java +++ b/src/main/java/de/erethon/dungeonsxl/world/DEditWorld.java @@ -27,7 +27,6 @@ import org.bukkit.Bukkit; import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.block.Sign; -import org.bukkit.scheduler.BukkitRunnable; /** * A raw resource world instance to edit the dungeon map. There is never more than one DEditWorld per DResourceWorld. @@ -116,19 +115,8 @@ public class DEditWorld extends DInstanceWorld { getWorld().save(); - if (!plugin.getMainConfig().areTweaksEnabled()) { - FileUtil.copyDir(getFolder(), getResource().getFolder(), DungeonsXL.EXCLUDED_FILES); - DWorldCache.deleteUnusedFiles(getResource().getFolder()); - - } else { - new BukkitRunnable() { - @Override - public void run() { - FileUtil.copyDir(getFolder(), getResource().getFolder(), DungeonsXL.EXCLUDED_FILES); - DWorldCache.deleteUnusedFiles(getResource().getFolder()); - } - }.runTaskAsynchronously(plugin); - } + FileUtil.copyDir(getFolder(), getResource().getFolder(), DungeonsXL.EXCLUDED_FILES); + DWorldCache.deleteUnusedFiles(getResource().getFolder()); getResource().getSignData().serializeSigns(signs); } @@ -153,36 +141,17 @@ public class DEditWorld extends DInstanceWorld { kickAllPlayers(); - if (!plugin.getMainConfig().areTweaksEnabled()) { - if (save) { - Bukkit.unloadWorld(getWorld(), true); - } - FileUtil.copyDir(getFolder(), getResource().getFolder(), DungeonsXL.EXCLUDED_FILES); - DWorldCache.deleteUnusedFiles(getResource().getFolder()); - if (!save) { - Bukkit.unloadWorld(getWorld(), true); - } - FileUtil.removeDir(getFolder()); - worlds.removeInstance(this); - - } else { - final DEditWorld editWorld = this; - new BukkitRunnable() { - @Override - public void run() { - if (save) { - Bukkit.unloadWorld(getWorld(), true); - } - FileUtil.copyDir(getFolder(), getResource().getFolder(), DungeonsXL.EXCLUDED_FILES); - DWorldCache.deleteUnusedFiles(getResource().getFolder()); - if (!save) { - Bukkit.unloadWorld(getWorld(), true); - } - FileUtil.removeDir(getFolder()); - worlds.removeInstance(editWorld); - } - }.runTaskAsynchronously(plugin); + if (save) { + Bukkit.unloadWorld(getWorld(), true); } + FileUtil.copyDir(getFolder(), getResource().getFolder(), DungeonsXL.EXCLUDED_FILES); + DWorldCache.deleteUnusedFiles(getResource().getFolder()); + if (!save) { + Bukkit.unloadWorld(getWorld(), true); + } + + FileUtil.removeDir(getFolder()); + worlds.removeInstance(this); } /* Statics */ diff --git a/src/main/java/de/erethon/dungeonsxl/world/DGameWorld.java b/src/main/java/de/erethon/dungeonsxl/world/DGameWorld.java index 50b2bc8c..c66b0156 100644 --- a/src/main/java/de/erethon/dungeonsxl/world/DGameWorld.java +++ b/src/main/java/de/erethon/dungeonsxl/world/DGameWorld.java @@ -69,7 +69,6 @@ import org.bukkit.entity.Player; import org.bukkit.entity.Spider; import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.inventory.ItemStack; -import org.bukkit.scheduler.BukkitRunnable; /** * A playable resource instance. There may be any amount of DGameWorlds per DResourceWorld. @@ -488,22 +487,9 @@ public class DGameWorld extends DInstanceWorld { kickAllPlayers(); - if (!plugin.getMainConfig().areTweaksEnabled()) { - Bukkit.unloadWorld(getWorld(), false); - FileUtil.removeDir(getFolder()); - worlds.removeInstance(this); - - } else { - final DGameWorld gameWorld = this; - new BukkitRunnable() { - @Override - public void run() { - Bukkit.unloadWorld(getWorld(), false); - FileUtil.removeDir(getFolder()); - worlds.removeInstance(gameWorld); - } - }.runTaskAsynchronously(plugin); - } + Bukkit.unloadWorld(getWorld(), false); + FileUtil.removeDir(getFolder()); + worlds.removeInstance(this); } /** diff --git a/src/main/java/de/erethon/dungeonsxl/world/DResourceWorld.java b/src/main/java/de/erethon/dungeonsxl/world/DResourceWorld.java index db3f0aa0..7626c2fb 100644 --- a/src/main/java/de/erethon/dungeonsxl/world/DResourceWorld.java +++ b/src/main/java/de/erethon/dungeonsxl/world/DResourceWorld.java @@ -30,7 +30,6 @@ import org.bukkit.World; import org.bukkit.World.Environment; import org.bukkit.WorldCreator; import org.bukkit.WorldType; -import org.bukkit.scheduler.BukkitRunnable; /** * This class represents unloaded worlds. @@ -187,16 +186,10 @@ public class DResourceWorld { /* Actions */ /** * Creates a backup of the resource - * - * @param async whether the task shall be performed asyncronously */ - public void backup(boolean async) { - BackupResourceTask task = new BackupResourceTask(this); - if (async) { - task.runTaskAsynchronously(plugin); - } else { - task.run(); - } + public void backup() { + File target = new File(DungeonsXL.BACKUPS, getName() + "-" + System.currentTimeMillis()); + FileUtil.copyDir(folder, target); } /** @@ -206,56 +199,34 @@ public class DResourceWorld { public DInstanceWorld instantiate(final boolean game) { int id = worlds.generateId(); String name = worlds.generateName(game, id); - File tempIF = new File(Bukkit.getWorldContainer(), name); - while (tempIF.exists()) { + + File instanceFolder = new File(Bukkit.getWorldContainer(), name); + while (instanceFolder.exists()) { World world = Bukkit.getWorld(name); boolean removed = false; if (world != null && world.getPlayers().isEmpty()) { Bukkit.unloadWorld(name, false); } if (world == null || world.getPlayers().isEmpty()) { - removed = tempIF.delete(); + removed = instanceFolder.delete(); } if (!removed) { MessageUtil.log(plugin, "&6Warning: An unrecognized junk instance (&4" + name + "&6) has been found, but could not be deleted."); id++; name = worlds.generateName(game, id); - tempIF = new File(Bukkit.getWorldContainer(), name); + instanceFolder = new File(Bukkit.getWorldContainer(), name); } } - final File instanceFolder = tempIF; // Because Java SUCKS - final DInstanceWorld instance = game ? new DGameWorld(this, instanceFolder, id) : new DEditWorld(this, instanceFolder, id); + DInstanceWorld instance = game ? new DGameWorld(this, instanceFolder, id) : new DEditWorld(this, instanceFolder, id); - if (!plugin.getMainConfig().areTweaksEnabled()) { - FileUtil.copyDir(folder, instanceFolder, DungeonsXL.EXCLUDED_FILES); - instance.world = Bukkit.createWorld(WorldCreator.name(name).environment(getWorldEnvironment())); - - if (game) { - signData.deserializeSigns((DGameWorld) instance); - } else { - signData.deserializeSigns((DEditWorld) instance); - } + FileUtil.copyDir(folder, instanceFolder, DungeonsXL.EXCLUDED_FILES); + instance.world = Bukkit.createWorld(WorldCreator.name(name).environment(getWorldEnvironment())); + if (game) { + signData.deserializeSigns((DGameWorld) instance); } else { - new BukkitRunnable() { - @Override - public void run() { - FileUtil.copyDir(folder, instanceFolder, DungeonsXL.EXCLUDED_FILES); - instance.world = WorldLoader.createWorld(WorldCreator.name(instanceFolder.getName()).environment(getWorldEnvironment())); - - new BukkitRunnable() { - @Override - public void run() { - if (game) { - signData.deserializeSigns((DGameWorld) instance); - } else { - signData.deserializeSigns((DEditWorld) instance); - } - } - }.runTask(plugin); - } - }.runTaskAsynchronously(plugin); + signData.deserializeSigns((DEditWorld) instance); } return instance; @@ -312,21 +283,13 @@ public class DResourceWorld { return null; } - if (!plugin.getMainConfig().areTweaksEnabled()) { - editWorld.world = creator.createWorld(); - editWorld.generateIdFile(); - - } else { - new BukkitRunnable() { - @Override - public void run() { - FileUtil.copyDir(DWorldCache.RAW, folder, DungeonsXL.EXCLUDED_FILES); - editWorld.generateIdFile(); - editWorld.world = WorldLoader.createWorld(creator); - editWorld.generateIdFile(); - } - }.runTaskAsynchronously(plugin); + if (!DWorldCache.RAW.exists()) { + worlds.createRaw(); } + FileUtil.copyDir(DWorldCache.RAW, folder, DungeonsXL.EXCLUDED_FILES); + editWorld.generateIdFile(); + editWorld.world = WorldLoader.createWorld(creator); + editWorld.generateIdFile(); return editWorld; } diff --git a/src/main/java/de/erethon/dungeonsxl/world/DWorldCache.java b/src/main/java/de/erethon/dungeonsxl/world/DWorldCache.java index f817c0d2..264c0c52 100644 --- a/src/main/java/de/erethon/dungeonsxl/world/DWorldCache.java +++ b/src/main/java/de/erethon/dungeonsxl/world/DWorldCache.java @@ -251,7 +251,7 @@ public class DWorldCache { HashSet instances = new HashSet<>(this.instances); for (DInstanceWorld instance : instances) { if (backupMode == BackupMode.ON_DISABLE | backupMode == BackupMode.ON_DISABLE_AND_SAVE && instance instanceof DEditWorld) { - instance.getResource().backup(mainConfig.areTweaksEnabled()); + instance.getResource().backup(); } instance.delete();