Updated expiremanager + PlotMe converter

- ExpireManager should be more stable
- the PlotMe converter can convert merged plots (I'm not sure when the
official PlotMe will get around to adding this, but the converter works)
This commit is contained in:
boy0001 2015-05-29 18:41:33 +10:00
parent 80db0136e2
commit 981f745c3b
5 changed files with 110 additions and 61 deletions

View File

@ -11,6 +11,8 @@ import java.util.HashMap;
import java.util.Map.Entry;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.configuration.file.FileConfiguration;
import com.intellectualcrafters.plot.PlotSquared;
@ -89,6 +91,15 @@ public class ClassicPlotMeConnector extends APlotMeConnector {
plots.put(id2, merge1);
}
public static String getWorld(final String world) {
for (final World newworld : Bukkit.getWorlds()) {
if (newworld.getName().equalsIgnoreCase(world)) {
return newworld.getName();
}
}
return world;
}
@Override
public HashMap<String, HashMap<PlotId, Plot>> getPlotMePlots(Connection connection) throws SQLException {
ResultSet r;
@ -108,6 +119,9 @@ public class ClassicPlotMeConnector extends APlotMeConnector {
if (!plots.containsKey(world)) {
int plot = PlotSquared.config.getInt("worlds." + world + ".plot.size");
int path = PlotSquared.config.getInt("worlds." + world + ".road.width");
if (plot == 0 && path == 0) {
}
plotWidth.put(world, plot);
roadWidth.put(world, path);
plots.put(world, new HashMap<PlotId, Plot>());

View File

@ -116,24 +116,24 @@ public class LikePlotMeConverter {
for (final String world : plotConfig.getConfigurationSection("worlds").getKeys(false)) {
sendMessage("Copying config for: " + world);
try {
final String plotMeWorldName = world.toLowerCase();
final Integer pathwidth = plotConfig.getInt("worlds." + plotMeWorldName + ".PathWidth"); //
PlotSquared.config.set("worlds." + world + ".road.width", pathwidth);
final Integer plotsize = plotConfig.getInt("worlds." + plotMeWorldName + ".PlotSize"); //
PlotSquared.config.set("worlds." + world + ".plot.size", plotsize);
final String wallblock = plotConfig.getString("worlds." + plotMeWorldName + ".WallBlockId"); //
PlotSquared.config.set("worlds." + world + ".wall.block", wallblock);
final String floor = plotConfig.getString("worlds." + plotMeWorldName + ".PlotFloorBlockId"); //
PlotSquared.config.set("worlds." + world + ".plot.floor", Arrays.asList(floor));
final String filling = plotConfig.getString("worlds." + plotMeWorldName + ".PlotFillingBlockId"); //
PlotSquared.config.set("worlds." + world + ".plot.filling", Arrays.asList(filling));
final String road = plotConfig.getString("worlds." + plotMeWorldName + ".RoadMainBlockId");
PlotSquared.config.set("worlds." + world + ".road.block", road);
Integer height = plotConfig.getInt("worlds." + plotMeWorldName + ".RoadHeight"); //
String actualWorldName = getWorld(world);
final Integer pathwidth = plotConfig.getInt("worlds." + world + ".PathWidth"); //
PlotSquared.config.set("worlds." + actualWorldName + ".road.width", pathwidth);
final Integer plotsize = plotConfig.getInt("worlds." + world + ".PlotSize"); //
PlotSquared.config.set("worlds." + actualWorldName + ".plot.size", plotsize);
final String wallblock = plotConfig.getString("worlds." + world + ".WallBlockId"); //
PlotSquared.config.set("worlds." + actualWorldName + ".wall.block", wallblock);
final String floor = plotConfig.getString("worlds." + world + ".PlotFloorBlockId"); //
PlotSquared.config.set("worlds." + actualWorldName + ".plot.floor", Arrays.asList(floor));
final String filling = plotConfig.getString("worlds." + world + ".PlotFillingBlockId"); //
PlotSquared.config.set("worlds." + actualWorldName + ".plot.filling", Arrays.asList(filling));
final String road = plotConfig.getString("worlds." + world + ".RoadMainBlockId");
PlotSquared.config.set("worlds." + actualWorldName + ".road.block", road);
Integer height = plotConfig.getInt("worlds." + world + ".RoadHeight"); //
if (height == null) {
height = 64;
}
PlotSquared.config.set("worlds." + world + ".road.height", height);
PlotSquared.config.set("worlds." + actualWorldName + ".road.height", height);
PlotSquared.config.save(PlotSquared.configFile);
} catch (final Exception e) {
sendMessage("&c-- &lFailed to save configuration for world '" + world + "'\nThis will need to be done using the setup command, or manually");
@ -156,6 +156,7 @@ public class LikePlotMeConverter {
final YamlConfiguration PLOTME_DG_YML = YamlConfiguration.loadConfiguration(PLOTME_DG_FILE);
try {
for (final String world : plots.keySet()) {
String actualWorldName = getWorld(world);
final String plotMeWorldName = world.toLowerCase();
Integer pathwidth = PLOTME_DG_YML.getInt("worlds." + plotMeWorldName + ".PathWidth"); //
if (pathwidth == null) {
@ -194,9 +195,9 @@ public class LikePlotMeConverter {
height = 64;
}
}
PlotSquared.config.set("worlds." + world + ".road.height", height);
PlotSquared.config.set("worlds." + world + ".plot.height", height);
PlotSquared.config.set("worlds." + world + ".wall.height", height);
PlotSquared.config.set("worlds." + actualWorldName + ".road.height", height);
PlotSquared.config.set("worlds." + actualWorldName + ".plot.height", height);
PlotSquared.config.set("worlds." + actualWorldName + ".wall.height", height);
PlotSquared.config.save(PlotSquared.configFile);
}
} catch (final Exception e) {

View File

@ -94,6 +94,7 @@ import com.intellectualcrafters.plot.object.PlotWorld;
import com.intellectualcrafters.plot.object.StringWrapper;
import com.intellectualcrafters.plot.util.ChunkManager;
import com.intellectualcrafters.plot.util.EventUtil;
import com.intellectualcrafters.plot.util.ExpireManager;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.TaskManager;
@ -269,6 +270,7 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
final StringWrapper name = new StringWrapper(username);
final UUID uuid = pp.getUUID();
UUIDHandler.add(name, uuid);
ExpireManager.dates.put(uuid, System.currentTimeMillis());
if (PlotSquared.worldEdit != null) {
if (Permissions.hasPermission(pp, "plots.worldedit.bypass")) {
WEManager.bypass.add(pp.getName());
@ -1068,6 +1070,7 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
@EventHandler(priority= EventPriority.MONITOR)
public void onLeave(final PlayerQuitEvent event) {
PlotPlayer pp = BukkitUtil.getPlayer(event.getPlayer());
ExpireManager.dates.put(pp.getUUID(), System.currentTimeMillis());
EventUtil.unregisterPlayer(pp);
if (PlotSquared.worldEdit != null) {
WEManager.bypass.remove(pp.getName());

View File

@ -1,10 +1,12 @@
package com.intellectualcrafters.plot.util;
import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
@ -17,7 +19,6 @@ import com.intellectualcrafters.plot.PlotSquared;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.events.PlotDeleteEvent;
import com.intellectualcrafters.plot.flag.Flag;
import com.intellectualcrafters.plot.flag.FlagManager;
import com.intellectualcrafters.plot.object.OfflinePlotPlayer;
@ -29,9 +30,10 @@ import com.intellectualcrafters.plot.object.PlotWorld;
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
public class ExpireManager {
public static ConcurrentHashMap<String, HashMap<Plot, Long>> expiredPlots = new ConcurrentHashMap<>();
public static ConcurrentHashMap<String, List<Plot>> expiredPlots = new ConcurrentHashMap<>();
public static ConcurrentHashMap<String, Boolean> updatingPlots = new ConcurrentHashMap<>();
public static ConcurrentHashMap<String, Long> timestamp = new ConcurrentHashMap<>();
public static ConcurrentHashMap<UUID, Long> dates = new ConcurrentHashMap<>();
public static int task;
public static long getTimeStamp(final String world) {
@ -48,13 +50,47 @@ public class ExpireManager {
final long now = System.currentTimeMillis();
if (now > getTimeStamp(world)) {
timestamp.put(world, now + 86400000l);
// TaskManager.index.increment();
// final ArrayList<Plot> plots = new ArrayList<>(PlotSquared.getPlots(world).values());
// int value = TaskManager.index.intValue();
// int id = TaskManager.runTaskRepeat(new Runnable() {
// @Override
// public void run() {
// long start = System.currentTimeMillis();
// while (System.currentTimeMillis() - start < 15) {
// Plot plot = plots.remove(0);
// final Flag keepFlag = FlagManager.getPlotFlag(plot, "keep");
// if (keepFlag != null && (Boolean) keepFlag.getValue()) {
// continue;
// }
//
//
// final HashMap<Plot, Long> toRemove = new HashMap<>();
// final HashMap<UUID, Long> remove = new HashMap<>();
// final Set<UUID> keep = new HashSet<>();
// Iterator<Plot> iter = plots.iterator();
// }
// }
// }, 1);
//
// TaskManager.tasks.put(value, id);
TaskManager.runTaskAsync(new Runnable() {
@Override
public void run() {
final HashMap<Plot, Long> plots = getOldPlots(world);
PlotSquared.log("&cFound " + plots.size() + " expired plots for " + world + "!");
expiredPlots.put(world, plots);
updatingPlots.put(world, false);
try {
final List<Plot> plots = getOldPlots(world);
PlotSquared.log("&cFound " + plots.size() + " expired plots for " + world + "!");
expiredPlots.put(world, plots);
updatingPlots.put(world, false);
}
catch (Exception e) {
e.printStackTrace();
}
}
});
return true;
@ -80,7 +116,7 @@ public class ExpireManager {
updateExpired(world);
return;
}
final Set<Plot> plots = expiredPlots.get(world).keySet();
final List<Plot> plots = expiredPlots.get(world);
if ((plots == null) || (plots.size() == 0)) {
if (updateExpired(world)) {
return;
@ -138,13 +174,26 @@ public class ExpireManager {
}
final String name = UUIDHandler.getName(uuid);
if (name != null) {
final OfflinePlayer op = Bukkit.getOfflinePlayer(name);
if (op.hasPlayedBefore()) {
final long last = op.getLastPlayed();
final long compared = System.currentTimeMillis() - last;
if (compared >= (86400000l * Settings.AUTO_CLEAR_DAYS)) {
return true;
long last;
if (dates.contains(uuid)) {
last = dates.get(uuid);
}
else {
final OfflinePlayer op = Bukkit.getOfflinePlayer(name);
if (op.hasPlayedBefore()) {
last = op.getLastPlayed();
dates.put(uuid, last);
}
else {
return false;
}
}
if (last == 0) {
return false;
}
final long compared = System.currentTimeMillis() - last;
if (compared >= (86400000l * Settings.AUTO_CLEAR_DAYS)) {
return true;
}
}
return false;
@ -159,11 +208,9 @@ public class ExpireManager {
return true;
}
public static HashMap<Plot, Long> getOldPlots(final String world) {
public static List<Plot> getOldPlots(final String world) {
final Collection<Plot> plots = PlotSquared.getPlots(world).values();
final HashMap<Plot, Long> toRemove = new HashMap<>();
final HashMap<UUID, Long> remove = new HashMap<>();
final Set<UUID> keep = new HashSet<>();
final List<Plot> toRemove = new ArrayList<>();
Iterator<Plot> iter = plots.iterator();
while (iter.hasNext()) {
Plot plot = iter.next();
@ -172,31 +219,15 @@ public class ExpireManager {
continue;
}
final UUID uuid = plot.owner;
if ((uuid == null) || remove.containsKey(uuid)) {
Long stamp;
if (uuid == null) {
stamp = 0l;
} else {
stamp = remove.get(uuid);
}
toRemove.put(plot, stamp);
continue;
}
if (keep.contains(uuid)) {
if (uuid == null) {
toRemove.add(plot);
continue;
}
final PlotPlayer player = UUIDHandler.getPlayer(uuid);
if (player != null) {
keep.add(uuid);
continue;
}
final OfflinePlotPlayer op = UUIDHandler.uuidWrapper.getOfflinePlayer(uuid);
if ((op == null) || (op.getLastPlayed() == 0)) {
continue;
}
long last = op.getLastPlayed();
long compared = System.currentTimeMillis() - last;
if (compared >= (86400000l * Settings.AUTO_CLEAR_DAYS)) {
if (isExpired(plot)) {
if (Settings.AUTO_CLEAR_CHECK_DISK) {
final String worldname = Bukkit.getWorlds().get(0).getName();
String foldername;
@ -204,6 +235,7 @@ public class ExpireManager {
if (BukkitMain.checkVersion(1, 7, 5)) {
foldername = "playerdata";
try {
final OfflinePlotPlayer op = UUIDHandler.uuidWrapper.getOfflinePlayer(uuid);
filename = op.getUUID() + ".dat";
} catch (final Throwable e) {
filename = uuid.toString() + ".dat";
@ -221,10 +253,9 @@ public class ExpireManager {
PlotSquared.log("Could not find file: " + filename);
} else {
try {
last = playerFile.lastModified();
compared = System.currentTimeMillis() - last;
long last = playerFile.lastModified();
long compared = System.currentTimeMillis() - last;
if (compared < (86400000l * Settings.AUTO_CLEAR_DAYS)) {
keep.add(uuid);
continue;
}
} catch (final Exception e) {
@ -233,11 +264,8 @@ public class ExpireManager {
}
}
}
toRemove.put(plot, last);
remove.put(uuid, last);
continue;
toRemove.add(plot);
}
keep.add(uuid);
}
return toRemove;
}

View File

@ -20,6 +20,7 @@ import com.intellectualcrafters.plot.object.OfflinePlotPlayer;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.StringWrapper;
import com.intellectualcrafters.plot.util.ExpireManager;
import com.intellectualcrafters.plot.uuid.DefaultUUIDWrapper;
import com.intellectualcrafters.plot.uuid.OfflineUUIDWrapper;
import com.intellectualcrafters.plot.uuid.UUIDWrapper;
@ -130,6 +131,7 @@ public class UUIDHandler {
final UUID uuid = UUID.fromString(s);
if (check || all.contains(uuid)) {
OfflinePlayer op = Bukkit.getOfflinePlayer(uuid);
ExpireManager.dates.put(uuid, op.getLastPlayed());
add(new StringWrapper(op.getName()), uuid);
}
} catch (final Exception e) {
@ -183,6 +185,7 @@ public class UUIDHandler {
for (UUID uuid : uuids) {
try {
final OfflinePlotPlayer player = wrapper.getOfflinePlayer(uuid);
ExpireManager.dates.put(uuid, player.getLastPlayed());
uuid = UUIDHandler.uuidWrapper.getUUID(player);
final StringWrapper name = new StringWrapper(player.getName());
add(name, uuid);