mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-25 22:56:45 +01:00
Fix compatibility with old type 2 plotworld cluster data
This commit is contained in:
parent
11064ec814
commit
411a74eefa
@ -14,6 +14,7 @@ import java.net.URLConnection;
|
||||
import java.nio.file.Files;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
@ -21,6 +22,7 @@ import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
@ -617,7 +619,22 @@ public class PS {
|
||||
*/
|
||||
public void addPlotArea(final PlotArea plotarea) {
|
||||
HashMap<PlotId, Plot> plots = plots_tmp.remove(plotarea.toString());
|
||||
if (plots != null) {
|
||||
if (plots == null) {
|
||||
if (plotarea.TYPE == 2) {
|
||||
plots = plots_tmp.get(plotarea.worldname);
|
||||
if (plots != null) {
|
||||
Iterator<Entry<PlotId, Plot>> iter = plots.entrySet().iterator();
|
||||
while (iter.hasNext()) {
|
||||
Entry<PlotId, Plot> next = iter.next();
|
||||
PlotId id = next.getKey();
|
||||
if (plotarea.contains(id)) {
|
||||
next.getValue().setArea(plotarea);
|
||||
iter.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (Entry<PlotId, Plot> entry : plots.entrySet()) {
|
||||
Plot plot = entry.getValue();
|
||||
plot.setArea(plotarea);
|
||||
@ -625,7 +642,21 @@ public class PS {
|
||||
}
|
||||
if (Settings.ENABLE_CLUSTERS) {
|
||||
Set<PlotCluster> clusters = clusters_tmp.remove(plotarea.toString());
|
||||
if (clusters != null) {
|
||||
if (clusters == null) {
|
||||
if (plotarea.TYPE == 2) {
|
||||
clusters = clusters_tmp.get(plotarea.worldname);
|
||||
if (clusters != null) {
|
||||
Iterator<PlotCluster> iter = clusters.iterator();
|
||||
while (iter.hasNext()) {
|
||||
PlotCluster next = iter.next();
|
||||
if (next.intersects(plotarea.getMin(), plotarea.getMax())) {
|
||||
next.setArea(plotarea);
|
||||
iter.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (PlotCluster cluster : clusters) {
|
||||
cluster.setArea(plotarea);
|
||||
}
|
||||
@ -1442,17 +1473,21 @@ public class PS {
|
||||
if (clusters == null) {
|
||||
throw new IllegalArgumentException("No cluster exists for world: " + world);
|
||||
}
|
||||
ArrayDeque<PlotArea> toLoad = new ArrayDeque<>();
|
||||
for (PlotCluster cluster : clusters) {
|
||||
PlotId pos1 = cluster.getP1(); // Cluster pos1
|
||||
PlotId pos2 = cluster.getP2(); // Cluster pos2
|
||||
String name = cluster.getName(); // Cluster name
|
||||
String fullId = name + "-" + pos1 + "-" + pos2;
|
||||
worldSection.createSection("areas." + fullId);
|
||||
DBFunc.replaceWorld(world, world + ";" + name, pos1, pos2); // NPE
|
||||
|
||||
log(C.PREFIX.s() + "&3 - " + name + "-" + pos1 + "-" + pos2);
|
||||
GeneratorWrapper<?> areaGen = IMP.getGenerator(world, gen_string);
|
||||
if (areaGen == null) {
|
||||
throw new IllegalArgumentException("Invalid Generator: " + gen_string);
|
||||
}
|
||||
PlotArea pa = areaGen.getPlotGenerator().getNewPlotArea(world, name, pos1, pos2);
|
||||
pa.setCompatibility("3.2.X");
|
||||
pa.saveConfiguration(worldSection);
|
||||
pa.loadDefaultConfiguration(worldSection);
|
||||
try {
|
||||
@ -1463,9 +1498,13 @@ public class PS {
|
||||
log(C.PREFIX.s() + "&c | &9generator: &7" + baseGenerator + ">" + areaGen);
|
||||
log(C.PREFIX.s() + "&c | &9plotworld: &7" + pa);
|
||||
log(C.PREFIX.s() + "&c | &9manager: &7" + pa);
|
||||
log(C.PREFIX.s() + "&cNote: &7Area created for cluster:" + name + " (invalid or old configuration?)");
|
||||
areaGen.getPlotGenerator().initialize(pa);
|
||||
areaGen.augment(pa);
|
||||
addPlotArea(pa);
|
||||
toLoad.add(pa);
|
||||
}
|
||||
for (PlotArea area : toLoad) {
|
||||
addPlotArea(area);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ import com.intellectualcrafters.plot.util.TaskManager;
|
||||
import com.plotsquared.general.commands.CommandDeclaration;
|
||||
|
||||
@CommandDeclaration(command = "clear", description = "Clear a plot", permission = "plots.clear", category = CommandCategory.APPEARANCE,
|
||||
usage = "/plot clear [id]")
|
||||
usage = "/plot clear [id]", aliases = "reset")
|
||||
public class Clear extends SubCommand {
|
||||
|
||||
@Override
|
||||
|
@ -352,4 +352,6 @@ public interface AbstractDB {
|
||||
boolean deleteTables();
|
||||
|
||||
void close();
|
||||
|
||||
void replaceWorld(String oldWorld, String newWorld, PlotId min, PlotId max);
|
||||
}
|
||||
|
@ -474,6 +474,10 @@ public class DBFunc {
|
||||
dbManager.setPosition(cluster, position);
|
||||
}
|
||||
|
||||
public static void replaceWorld(String oldWorld, String newWorld, PlotId min, PlotId max) {
|
||||
dbManager.replaceWorld(oldWorld, newWorld, min, max);
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace all occurrences of a uuid in the database with another one
|
||||
* @param old
|
||||
|
@ -3030,6 +3030,62 @@ public class SQLManager implements AbstractDB {
|
||||
commit();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void replaceWorld(final String oldWorld, final String newWorld, final PlotId min, final PlotId max) {
|
||||
addGlobalTask(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (min == null) {
|
||||
try (PreparedStatement stmt = connection.prepareStatement("UPDATE `" + prefix + "plot` SET `world` = ? WHERE `world` = ?")) {
|
||||
stmt.setString(1, newWorld);
|
||||
stmt.setString(2, oldWorld);
|
||||
stmt.executeUpdate();
|
||||
stmt.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
try (PreparedStatement stmt = connection.prepareStatement("UPDATE `" + prefix + "cluster` SET `world` = ? WHERE `world` = ?")) {
|
||||
stmt.setString(1, newWorld);
|
||||
stmt.setString(2, oldWorld);
|
||||
stmt.executeUpdate();
|
||||
stmt.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
try (PreparedStatement stmt = connection.prepareStatement("UPDATE `"
|
||||
+ prefix
|
||||
+ "plot` SET `world` = ? WHERE `world` = ? AND `plot_id_x` BETWEEN ? AND ? AND `plot_id_z` BETWEEN ? AND ?")) {
|
||||
stmt.setString(1, newWorld);
|
||||
stmt.setString(2, oldWorld);
|
||||
stmt.setInt(3, min.x);
|
||||
stmt.setInt(4, max.x);
|
||||
stmt.setInt(5, min.y);
|
||||
stmt.setInt(6, max.y);
|
||||
stmt.executeUpdate();
|
||||
stmt.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
try (PreparedStatement stmt = connection.prepareStatement("UPDATE `"
|
||||
+ prefix
|
||||
+ "cluster` SET `world` = ? WHERE `world` = ? AND `pos1_x` <= ? AND `pos1_z` <= ? AND `pos2_x` >= ? AND `pos2_z` >= ?")) {
|
||||
stmt.setString(1, newWorld);
|
||||
stmt.setString(2, oldWorld);
|
||||
stmt.setInt(3, max.x);
|
||||
stmt.setInt(4, max.y);
|
||||
stmt.setInt(5, min.x);
|
||||
stmt.setInt(6, min.y);
|
||||
stmt.executeUpdate();
|
||||
stmt.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void replaceUUID(final UUID old, final UUID now) {
|
||||
addGlobalTask(new Runnable() {
|
||||
|
@ -20,6 +20,18 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.intellectualcrafters.plot.object;
|
||||
|
||||
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.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import com.intellectualcrafters.configuration.ConfigurationSection;
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
@ -38,18 +50,6 @@ import com.intellectualcrafters.plot.util.StringMan;
|
||||
import com.intellectualcrafters.plot.util.WorldUtil;
|
||||
import com.intellectualcrafters.plot.util.area.QuadMap;
|
||||
|
||||
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.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* @author Jesse Boyd
|
||||
*/
|
||||
@ -91,11 +91,6 @@ public abstract class PlotArea {
|
||||
public PlotGamemode GAMEMODE = PlotGamemode.CREATIVE;
|
||||
int hash;
|
||||
private RegionWrapper region;
|
||||
/**
|
||||
* Please ignore
|
||||
*/
|
||||
@Deprecated
|
||||
private int compatibility_id;
|
||||
private ConcurrentHashMap<String, Object> meta;
|
||||
private QuadMap<PlotCluster> clusters;
|
||||
|
||||
@ -188,16 +183,6 @@ public abstract class PlotArea {
|
||||
return clusters == null ? new HashSet<PlotCluster>() : clusters.getAll();
|
||||
}
|
||||
|
||||
public void setCompatibility(String version) {
|
||||
switch (version) {
|
||||
case "3.2.X":
|
||||
compatibility_id = 1;
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException("Not valid version");
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isCompatible(PlotArea plotarea) {
|
||||
final ConfigurationSection section = PS.get().config.getConfigurationSection("worlds");
|
||||
for (final ConfigurationNode setting : plotarea.getSettingNodes()) {
|
||||
@ -367,7 +352,7 @@ public abstract class PlotArea {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return compatibility_id == 1 || id == null ? worldname : worldname + ";" + id;
|
||||
return id == null ? worldname : worldname + ";" + id;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -430,6 +415,10 @@ public abstract class PlotArea {
|
||||
public boolean contains(int x, int z) {
|
||||
return TYPE != 2 || getRegionAbs().isIn(x, z);
|
||||
}
|
||||
|
||||
public boolean contains(PlotId id) {
|
||||
return min == null || (id.x >= min.x && id.x <= max.x && id.y >= min.y && id.y <= max.y);
|
||||
}
|
||||
|
||||
public boolean contains(Location loc) {
|
||||
return StringMan.isEqual(loc.getWorld(), worldname) && (getRegionAbs() == null || region.isIn(loc.getX(), loc.getZ()));
|
||||
|
Loading…
Reference in New Issue
Block a user