Code cleanup

This commit is contained in:
Daniel Saukel 2019-02-23 23:54:49 +01:00
parent dc75a14b6a
commit a526822c6e
11 changed files with 33 additions and 112 deletions

View File

@ -46,8 +46,8 @@ public class ImportCommand extends DCommand {
@Override
public void onExecute(String[] args, CommandSender sender) {
final File target = new File(DungeonsXL.MAPS, args[1]);
final File source = new File(Bukkit.getWorldContainer(), args[1]);
File target = new File(DungeonsXL.MAPS, args[1]);
File source = new File(Bukkit.getWorldContainer(), args[1]);
if (!source.exists()) {
MessageUtil.sendMessage(sender, DMessage.ERROR_NO_SUCH_MAP.getMessage(args[1]));

View File

@ -26,7 +26,6 @@ import java.util.UUID;
import java.util.concurrent.CopyOnWriteArrayList;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitTask;
/**
* DGlobalPlayer instance manager.
@ -38,10 +37,6 @@ public class DPlayerCache {
private DungeonsXL plugin;
private MainConfig config;
private BukkitTask secureModeTask;
private BukkitTask updateTask;
private BukkitTask lazyUpdateTask;
private CopyOnWriteArrayList<DGlobalPlayer> dGlobalPlayers = new CopyOnWriteArrayList<>();
public DPlayerCache(DungeonsXL plugin) {
@ -52,10 +47,10 @@ public class DPlayerCache {
config = plugin.getMainConfig();
if (config.isSecureModeEnabled()) {
startSecureModeTask(config.getSecureModeCheckInterval());
new SecureModeTask(plugin).runTaskTimer(plugin, config.getSecureModeCheckInterval(), config.getSecureModeCheckInterval());
}
startUpdateTask(2L);
startLazyUpdateTask(20L);
new UpdateTask(plugin).runTaskTimer(plugin, 2L, 2L);
new LazyUpdateTask(plugin).runTaskTimer(plugin, 20L, 20L);
Bukkit.getPluginManager().registerEvents(new DPlayerListener(plugin), plugin);
}
@ -187,53 +182,4 @@ public class DPlayerCache {
return true;
}
/* Tasks */
/**
* @return the secureModeTask
*/
public BukkitTask getSecureModeTask() {
return secureModeTask;
}
/**
* start a new SecureModeTask
*
* @param period the period in ticks
*/
public void startSecureModeTask(long period) {
secureModeTask = new SecureModeTask(plugin).runTaskTimer(plugin, period, period);
}
/**
* @return the updateTask
*/
public BukkitTask getUpdateTask() {
return updateTask;
}
/**
* start a new LazyUpdateTask
*
* @param period the period in ticks
*/
public void startUpdateTask(long period) {
updateTask = new UpdateTask(plugin).runTaskTimer(plugin, period, period);
}
/**
* @return the lazyUpdateTask
*/
public BukkitTask getLazyUpdateTask() {
return lazyUpdateTask;
}
/**
* start a new LazyUpdateTask
*
* @param period the period in ticks
*/
public void startLazyUpdateTask(long period) {
lazyUpdateTask = new LazyUpdateTask(plugin).runTaskTimer(plugin, period, period);
}
}

View File

@ -488,7 +488,7 @@ public class DPlayerListener implements Listener {
}
// Because some plugins set another respawn point, DXL teleports a few ticks later.
new RespawnTask(plugin, player, respawn).runTaskLater(plugin, 10);
new RespawnTask(plugin, player, respawn).runTaskLater(plugin, 10L);
// Don't forget Doge!
if (gamePlayer.getWolf() != null) {

View File

@ -40,7 +40,7 @@ public class SecureModeTask extends BukkitRunnable {
dGlobalPlayer = new DGlobalPlayer(plugin, player);
}
if (!(dGlobalPlayer instanceof DGamePlayer || dGlobalPlayer instanceof DEditPlayer)) {
if (!(dGlobalPlayer instanceof DInstancePlayer)) {
if (player.getWorld().getName().startsWith("DXL_Game_") | player.getWorld().getName().startsWith("DXL_Edit_") && !DPermission.hasPermission(player, DPermission.INSECURE)) {
player.teleport(Bukkit.getWorlds().get(0).getSpawnLocation());
}

View File

@ -38,27 +38,26 @@ public class MobSpawnTask extends BukkitRunnable {
if (sign.getInterval() <= 0) {
World world = sign.getSign().getWorld();
DGameWorld gameWorld = DGameWorld.getByWorld(world);
if (gameWorld != null) {
LivingEntity entity = sign.spawn();
if (entity != null) {
new DMob(entity, sign.getGameWorld(), sign.getMob());
}
if (sign.getAmount() != -1) {
if (sign.getAmount() > 1) {
sign.setAmount(sign.getAmount() - 1);
} else {
sign.killTask();
}
}
sign.setInterval(sign.getMaxInterval());
} else {
if (gameWorld == null) {
sign.killTask();
return;
}
LivingEntity entity = sign.spawn();
if (entity != null) {
new DMob(entity, sign.getGameWorld(), sign.getMob());
}
if (sign.getAmount() != -1) {
if (sign.getAmount() > 1) {
sign.setAmount(sign.getAmount() - 1);
} else {
sign.killTask();
}
}
sign.setInterval(sign.getMaxInterval());
}
sign.setInterval(sign.getInterval() - 1);

View File

@ -45,7 +45,7 @@ public class TriggerListener implements Listener {
}
}
}
}.runTaskLater(plugin, 1);
}.runTaskLater(plugin, 1L);
}
}

View File

@ -129,10 +129,9 @@ public class DEditWorld extends DInstanceWorld {
*
* @param save whether this world should be saved
*/
public void delete(final boolean save) {
public void delete(boolean save) {
EditWorldUnloadEvent event = new EditWorldUnloadEvent(this, true);
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()) {
return;
}

View File

@ -274,14 +274,14 @@ public class DResourceWorld {
* @return the automatically created DEditWorld instance
*/
public DEditWorld generate() {
final String name = worlds.generateName(false);
String name = worlds.generateName(false);
int id = worlds.generateId();
final File folder = new File(Bukkit.getWorldContainer(), name);
final WorldCreator creator = new WorldCreator(name);
File folder = new File(Bukkit.getWorldContainer(), name);
WorldCreator creator = new WorldCreator(name);
creator.type(WorldType.FLAT);
creator.generateStructures(false);
final DEditWorld editWorld = new DEditWorld(plugin, this, folder, id);
DEditWorld editWorld = new DEditWorld(plugin, this, folder, id);
EditWorldGenerateEvent event = new EditWorldGenerateEvent(editWorld);
Bukkit.getPluginManager().callEvent(event);

View File

@ -43,8 +43,6 @@ public class DWorldCache {
public static final File RAW = new File(DungeonsXL.MAPS, ".raw");
private BukkitTask worldUnloadTask;
private Set<DResourceWorld> resources = new HashSet<>();
private Set<DInstanceWorld> instances = new HashSet<>();
@ -65,7 +63,7 @@ public class DWorldCache {
createRaw();
}
startWorldUnloadTask(1200L);
new WorldUnloadTask(plugin).runTaskTimer(plugin, 20L, 20L);//1200L
Bukkit.getPluginManager().registerEvents(new DWorldListener(plugin), plugin);
if (LWCUtil.isLWCLoaded()) {
new LWCIntegration(plugin);
@ -317,23 +315,6 @@ public class DWorldCache {
FileUtil.removeDir(worldFolder);
}
/* Tasks */
/**
* @return the worldUnloadTask
*/
public BukkitTask getWorldUnloadTask() {
return worldUnloadTask;
}
/**
* start a new WorldUnloadTask
*
* @param period the period in ticks
*/
public void startWorldUnloadTask(long period) {
worldUnloadTask = new WorldUnloadTask(plugin).runTaskTimer(plugin, period, period);
}
/* Util */
/**
* Removes files that are not needed from a world
@ -341,8 +322,7 @@ public class DWorldCache {
* @param dir the directory to purge
*/
public static void deleteUnusedFiles(File dir) {
File[] files = dir.listFiles();
for (File file : files) {
for (File file : dir.listFiles()) {
if (file.getName().equalsIgnoreCase("uid.dat") || file.getName().contains(".id_")) {
file.delete();
}

View File

@ -18,7 +18,6 @@ package de.erethon.dungeonsxl.world;
import de.erethon.caliburn.CaliburnAPI;
import de.erethon.caliburn.item.ExItem;
import de.erethon.commons.compatibility.CompatibilityHandler;
import de.erethon.commons.misc.EnumUtil;
import de.erethon.commons.misc.NumberUtil;
import de.erethon.dungeonsxl.DungeonsXL;
@ -50,7 +49,6 @@ public class WorldConfig extends GameRuleProvider {
private DungeonsXL plugin;
private CaliburnAPI caliburn;
private CompatibilityHandler compat = CompatibilityHandler.getInstance();
private File file;

View File

@ -34,7 +34,6 @@ public class WorldUnloadTask extends BukkitRunnable {
@Override
public void run() {
Set<DInstanceWorld> instances = plugin.getDWorldCache().getInstances();
System.out.println(instances);
for (DInstanceWorld instance : instances.toArray(new DInstanceWorld[instances.size()])) {
if (instance.exists()) {
if (instance.getWorld().getPlayers().isEmpty()) {