Added additional checks for plot expiry system

This commit is contained in:
boy0001 2015-02-04 15:40:39 +11:00
parent 2ba9590238
commit 466d570ea2
6 changed files with 91 additions and 21 deletions

View File

@ -808,6 +808,7 @@ public class PlotMain extends JavaPlugin implements Listener {
options.put("debug", true); options.put("debug", true);
options.put("clear.auto.enabled", false); options.put("clear.auto.enabled", false);
options.put("clear.auto.days", 365); options.put("clear.auto.days", 365);
options.put("clear.check-disk", Settings.AUTO_CLEAR_CHECK_DISK);
options.put("clear.on.ban", false); options.put("clear.on.ban", false);
options.put("max_plots", Settings.MAX_PLOTS); options.put("max_plots", Settings.MAX_PLOTS);
options.put("schematics.save_path", Settings.SCHEMATIC_SAVE_PATH); options.put("schematics.save_path", Settings.SCHEMATIC_SAVE_PATH);
@ -841,6 +842,7 @@ public class PlotMain extends JavaPlugin implements Listener {
+ "inding"); + "inding");
Settings.METRICS = config.getBoolean("metrics"); Settings.METRICS = config.getBoolean("metrics");
Settings.AUTO_CLEAR_DAYS = config.getInt("clear.auto.days"); Settings.AUTO_CLEAR_DAYS = config.getInt("clear.auto.days");
Settings.AUTO_CLEAR_CHECK_DISK = config.getBoolean("clear.check-disk");
Settings.MAX_AUTO_SIZE = config.getInt("claim.max-auto-area"); Settings.MAX_AUTO_SIZE = config.getInt("claim.max-auto-area");
Settings.AUTO_CLEAR = config.getBoolean("clear.auto.enabled"); Settings.AUTO_CLEAR = config.getBoolean("clear.auto.enabled");
Settings.TITLES = config.getBoolean("titles"); Settings.TITLES = config.getBoolean("titles");

View File

@ -21,11 +21,16 @@
package com.intellectualcrafters.plot.commands; package com.intellectualcrafters.plot.commands;
import java.sql.Timestamp;
import java.util.Arrays; import java.util.Arrays;
import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Map.Entry;
import java.util.UUID;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -42,7 +47,7 @@ public class DebugExec extends SubCommand {
@Override @Override
public boolean execute(final Player player, final String... args) { public boolean execute(final Player player, final String... args) {
List<String> allowed_params = Arrays.asList(new String[]{"stop-expire","start-expire", "show-expired", "update-expired"}); List<String> allowed_params = Arrays.asList(new String[]{"stop-expire","start-expire", "show-expired", "update-expired", "seen"});
if (args.length > 0) { if (args.length > 0) {
String arg = args[0].toLowerCase(); String arg = args[0].toLowerCase();
switch (arg) { switch (arg) {
@ -80,12 +85,34 @@ public class DebugExec extends SubCommand {
return PlayerFunctions.sendMessage(null, "Invalid world: "+args[1]); return PlayerFunctions.sendMessage(null, "Invalid world: "+args[1]);
} }
PlayerFunctions.sendMessage(null, "Expired plots (" + ExpireManager.expiredPlots.get(args[1]).size() + "):"); PlayerFunctions.sendMessage(null, "Expired plots (" + ExpireManager.expiredPlots.get(args[1]).size() + "):");
for (Plot plot : ExpireManager.expiredPlots.get(args[1])) { for (Entry<Plot, Long> entry : ExpireManager.expiredPlots.get(args[1]).entrySet()) {
PlayerFunctions.sendMessage(null, " - " + plot.world + ";" + plot.id.x + ";" + plot.id.y + ";" + UUIDHandler.getName(plot.owner)); Plot plot = entry.getKey();
Long stamp = entry.getValue();
PlayerFunctions.sendMessage(null, " - " + plot.world + ";" + plot.id.x + ";" + plot.id.y + ";" + UUIDHandler.getName(plot.owner) +" : " + stamp);
} }
return true; return true;
} }
return PlayerFunctions.sendMessage(null, "Use /plot debugexec show-expired <world>"); return PlayerFunctions.sendMessage(null, "Use /plot debugexec show-expired <world>");
case "seen":
if (args.length != 1) {
return PlayerFunctions.sendMessage(null, "Use /plot debugexec seen <player>");
}
UUID uuid = UUIDHandler.getUUID(args[1]);
if (uuid == null) {
return PlayerFunctions.sendMessage(null, "player not found: " + args[1]);
}
OfflinePlayer op = UUIDHandler.uuidWrapper.getOfflinePlayer(uuid);
if (op == null || !op.hasPlayedBefore()) {
return PlayerFunctions.sendMessage(null, "player hasn't connected before: " + args[1]);
}
Timestamp stamp = new Timestamp(op.getLastPlayed());
Date date = new Date(stamp.getTime());
PlayerFunctions.sendMessage(null, "PLAYER: " + args[1]);
PlayerFunctions.sendMessage(null, "UUID: " + uuid);
PlayerFunctions.sendMessage(null, "Object: " + date.toGMTString());
PlayerFunctions.sendMessage(null, "GMT: " + date.toGMTString());
PlayerFunctions.sendMessage(null, "Local: " + date.toLocaleString());
return true;
} }
} }
PlayerFunctions.sendMessage(player, "Possible sub commands: /plot debugexec <" + StringUtils.join(allowed_params, "|") + ">"); PlayerFunctions.sendMessage(player, "Possible sub commands: /plot debugexec <" + StringUtils.join(allowed_params, "|") + ">");

View File

@ -52,7 +52,7 @@ import com.intellectualcrafters.plot.util.PlayerFunctions;
import com.intellectualcrafters.plot.util.TaskManager; import com.intellectualcrafters.plot.util.TaskManager;
import com.intellectualcrafters.plot.util.UUIDHandler; import com.intellectualcrafters.plot.util.UUIDHandler;
@SuppressWarnings({"unused", "deprecated", "javadoc"}) public class Trim extends SubCommand { public class Trim extends SubCommand {
public static boolean TASK = false; public static boolean TASK = false;
private static int TASK_ID = 0; private static int TASK_ID = 0;

View File

@ -123,6 +123,7 @@ public class Settings {
* Days until a plot gets cleared * Days until a plot gets cleared
*/ */
public static int AUTO_CLEAR_DAYS = 360; public static int AUTO_CLEAR_DAYS = 360;
public static boolean AUTO_CLEAR_CHECK_DISK = true;
public static int MIN_BLOCKS_CHANGED = -1; public static int MIN_BLOCKS_CHANGED = -1;

View File

@ -84,7 +84,7 @@ public class PlotMeConverter {
if (!plotMeFile.exists()) { if (!plotMeFile.exists()) {
return; return;
} }
sendMessage("Conversion has started"); sendMessage("PlotMe conversion has started. To disable this, please set 'plotme-convert.enabled' in the 'settings.yml'");
sendMessage("Connecting to PlotMe DB"); sendMessage("Connecting to PlotMe DB");
final FileConfiguration plotConfig = YamlConfiguration.loadConfiguration(plotMeFile); final FileConfiguration plotConfig = YamlConfiguration.loadConfiguration(plotMeFile);
int count = 0; int count = 0;

View File

@ -1,7 +1,9 @@
package com.intellectualcrafters.plot.util; package com.intellectualcrafters.plot.util;
import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
import java.util.UUID; import java.util.UUID;
@ -23,7 +25,7 @@ import com.intellectualcrafters.plot.object.PlotManager;
public class ExpireManager { public class ExpireManager {
private static long timestamp = 0; private static long timestamp = 0;
public static ConcurrentHashMap<String, ArrayList<Plot>> expiredPlots = new ConcurrentHashMap<>(); public static ConcurrentHashMap<String, HashMap<Plot, Long>> expiredPlots = new ConcurrentHashMap<>();
public static ConcurrentHashMap<String, Boolean> updatingPlots = new ConcurrentHashMap<>(); public static ConcurrentHashMap<String, Boolean> updatingPlots = new ConcurrentHashMap<>();
public static int task; public static int task;
@ -35,7 +37,7 @@ public class ExpireManager {
TaskManager.runTask(new Runnable() { TaskManager.runTask(new Runnable() {
@Override @Override
public void run() { public void run() {
ArrayList<Plot> plots = getOldPlots(world); HashMap<Plot, Long> plots = getOldPlots(world);
PlotMain.sendConsoleSenderMessage("&cFound " + plots.size() + " expired plots!"); PlotMain.sendConsoleSenderMessage("&cFound " + plots.size() + " expired plots!");
expiredPlots.put(world, plots); expiredPlots.put(world, plots);
updatingPlots.put(world, false); updatingPlots.put(world, false);
@ -52,28 +54,31 @@ public class ExpireManager {
@Override @Override
public void run() { public void run() {
for (String world : PlotMain.getPlotWorldsString()) { for (String world : PlotMain.getPlotWorldsString()) {
if (!ExpireManager.updatingPlots.contains(world)) { if (!ExpireManager.updatingPlots.containsKey(world)) {
ExpireManager.updatingPlots.put(world, false); ExpireManager.updatingPlots.put(world, false);
} }
Boolean updating = ExpireManager.updatingPlots.get(world); Boolean updating = ExpireManager.updatingPlots.get(world);
if (updating) { if (updating) {
return; return;
} }
ArrayList<Plot> plots = expiredPlots.get(world); if (!expiredPlots.containsKey(world)) {
updateExpired(world);
return;
}
Set<Plot> plots = expiredPlots.get(world).keySet();
if (plots == null || plots.size() == 0) { if (plots == null || plots.size() == 0) {
updateExpired(world); updateExpired(world);
return; return;
} }
Plot plot = plots.get(0); Plot plot = plots.iterator().next();
if (plot.owner != null) { if (plot.owner != null) {
if (UUIDHandler.uuidWrapper.getPlayer(plot.owner) != null) { if (UUIDHandler.uuidWrapper.getPlayer(plot.owner) != null) {
expiredPlots.get(world).remove(0); expiredPlots.get(world).remove(plot);
return; return;
} }
} }
if (!isExpired(plot.owner)) { if (!isExpired(plot.owner)) {
expiredPlots.get(world).remove(0); expiredPlots.get(world).remove(plot);
return; return;
} }
final PlotDeleteEvent event = new PlotDeleteEvent(world, plot.id); final PlotDeleteEvent event = new PlotDeleteEvent(world, plot.id);
@ -96,7 +101,7 @@ public class ExpireManager {
PlotHelper.removeSign(worldobj, plot); PlotHelper.removeSign(worldobj, plot);
DBFunc.delete(world, plot); DBFunc.delete(world, plot);
PlotMain.removePlot(world, plot.id, true); PlotMain.removePlot(world, plot.id, true);
expiredPlots.get(world).remove(0); expiredPlots.get(world).remove(plot);
PlotMain.sendConsoleSenderMessage("&cDeleted expired plot: " + plot.id); PlotMain.sendConsoleSenderMessage("&cDeleted expired plot: " + plot.id);
PlotMain.sendConsoleSenderMessage("&3 - World: "+plot.world); PlotMain.sendConsoleSenderMessage("&3 - World: "+plot.world);
if (plot.hasOwner()) { if (plot.hasOwner()) {
@ -127,15 +132,15 @@ public class ExpireManager {
return false; return false;
} }
public static ArrayList<Plot> getOldPlots(String world) { public static HashMap<Plot, Long> getOldPlots(String world) {
final Collection<Plot> plots = PlotMain.getPlots(world).values(); final Collection<Plot> plots = PlotMain.getPlots(world).values();
final ArrayList<Plot> toRemove = new ArrayList<>(); final HashMap<Plot, Long> toRemove = new HashMap<>();
Set<UUID> remove = new HashSet<>(); HashMap<UUID, Long> remove = new HashMap<>();
Set<UUID> keep = new HashSet<>(); Set<UUID> keep = new HashSet<>();
for (Plot plot : plots) { for (Plot plot : plots) {
UUID uuid = plot.owner; UUID uuid = plot.owner;
if (uuid == null || remove.contains(uuid)) { if (uuid == null || remove.containsKey(uuid)) {
toRemove.add(plot); toRemove.put(plot, remove.get(uuid));
continue; continue;
} }
if (keep.contains(uuid)) { if (keep.contains(uuid)) {
@ -153,8 +158,43 @@ public class ExpireManager {
long last = op.getLastPlayed(); long last = op.getLastPlayed();
long compared = System.currentTimeMillis() - last; long compared = System.currentTimeMillis() - last;
if (compared >= 86400000 * Settings.AUTO_CLEAR_DAYS) { if (compared >= 86400000 * Settings.AUTO_CLEAR_DAYS) {
toRemove.add(plot); if (Settings.AUTO_CLEAR_CHECK_DISK) {
remove.add(uuid); String worldname = Bukkit.getWorlds().get(0).getName();
String foldername;
String filename = null;
if (PlotMain.checkVersion()) {
foldername = "playerdata";
filename = uuid.toString() + ".dat";
}
else {
foldername = "players";
String playername = UUIDHandler.getName(uuid);
if (playername != null) {
filename = playername + ".dat";
}
}
if (filename != null) {
File playerFile = new File(worldname + File.separator + foldername + File.separator + filename);
if (!playerFile.exists()) {
PlotMain.sendConsoleSenderMessage("Could not find file: " + filename);
}
else {
try {
last = playerFile.lastModified();
compared = System.currentTimeMillis() - last;
if (compared < 86400000 * Settings.AUTO_CLEAR_DAYS) {
keep.add(uuid);
continue;
}
}
catch (Exception e) {
PlotMain.sendConsoleSenderMessage("Please disable disk checking in old plot auto clearing; Could not read file: " + filename);
}
}
}
}
toRemove.put(plot, last);
remove.put(uuid, last);
} }
keep.add(uuid); keep.add(uuid);
} }