mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2025-06-25 02:04:44 +02:00
Add configuration conversion and fix BukkitLegacyMappings
This commit is contained in:
@ -52,6 +52,11 @@ public interface IPlotMain extends ILogger {
|
||||
*/
|
||||
void disable();
|
||||
|
||||
/**
|
||||
* Completely shut down the plugin
|
||||
*/
|
||||
void shutdown();
|
||||
|
||||
/**
|
||||
* Get the version of the PlotSquared being used.
|
||||
*
|
||||
|
@ -119,7 +119,13 @@ import java.util.zip.ZipInputStream;
|
||||
}
|
||||
}
|
||||
TaskManager.IMP = this.IMP.getTaskManager();
|
||||
setupConfigs();
|
||||
|
||||
// World Util. Has to be done before config files are loaded
|
||||
WorldUtil.IMP = this.IMP.initWorldUtil();
|
||||
|
||||
if (!setupConfigs()) {
|
||||
return;
|
||||
}
|
||||
this.translationFile = MainUtil.getFile(this.IMP.getDirectory(),
|
||||
Settings.Paths.TRANSLATIONS + File.separator + IMP.getPluginName()
|
||||
+ ".use_THIS.yml");
|
||||
@ -176,8 +182,6 @@ import java.util.zip.ZipInputStream;
|
||||
InventoryUtil.manager = this.IMP.initInventoryUtil();
|
||||
// create setup util class
|
||||
SetupUtils.manager = this.IMP.initSetupUtils();
|
||||
// World Util
|
||||
WorldUtil.IMP = this.IMP.initWorldUtil();
|
||||
// Set block
|
||||
GlobalBlockQueue.IMP = new GlobalBlockQueue(IMP.initBlockQueue(), 1);
|
||||
GlobalBlockQueue.IMP.runTask();
|
||||
@ -1543,11 +1547,13 @@ import java.util.zip.ZipInputStream;
|
||||
try {
|
||||
// Validate that all data in the db is correct
|
||||
final HashSet<Plot> plots = new HashSet<>();
|
||||
foreachPlotRaw(new RunnableVal<Plot>() {
|
||||
@Override public void run(Plot value) {
|
||||
plots.add(value);
|
||||
}
|
||||
});
|
||||
try {
|
||||
foreachPlotRaw(new RunnableVal<Plot>() {
|
||||
@Override public void run(Plot value) {
|
||||
plots.add(value);
|
||||
}
|
||||
});
|
||||
} catch (final Exception ignored) {}
|
||||
DBFunc.validatePlots(plots);
|
||||
|
||||
// Close the connection
|
||||
@ -1661,7 +1667,7 @@ import java.util.zip.ZipInputStream;
|
||||
* - Storage: storage.yml<br>
|
||||
* - Translation: PlotSquared.use_THIS.yml, style.yml<br>
|
||||
*/
|
||||
public void setupConfigs() {
|
||||
public boolean setupConfigs() {
|
||||
File folder = new File(this.IMP.getDirectory(), "config");
|
||||
if (!folder.exists() && !folder.mkdirs()) {
|
||||
PlotSquared.log(C.PREFIX
|
||||
@ -1674,6 +1680,34 @@ import java.util.zip.ZipInputStream;
|
||||
"Could not create the worlds file, please create \"worlds.yml\" manually.");
|
||||
}
|
||||
this.worlds = YamlConfiguration.loadConfiguration(this.worldsFile);
|
||||
|
||||
if (this.worlds.contains("worlds")) {
|
||||
if (!this.worlds.contains("configuration_version") || !this.worlds
|
||||
.getString("configuration_version").equalsIgnoreCase(LegacyConverter.CONFIGURATION_VERSION)) {
|
||||
// Conversion needed
|
||||
log(C.LEGACY_CONFIG_FOUND.s());
|
||||
try {
|
||||
com.google.common.io.Files
|
||||
.copy(this.worldsFile, new File(folder, "worlds.yml.old"));
|
||||
log(C.LEGACY_CONFIG_BACKUP.s());
|
||||
final ConfigurationSection worlds = this.worlds.getConfigurationSection("worlds");
|
||||
final LegacyConverter converter = new LegacyConverter(worlds);
|
||||
converter.convert();
|
||||
this.worlds.set("configuration_version", LegacyConverter.CONFIGURATION_VERSION);
|
||||
this.worlds.set("worlds", worlds); // Redundant, but hey... ¯\_(ツ)_/¯
|
||||
this.worlds.save(this.worldsFile);
|
||||
log(C.LEGACY_CONFIG_DONE.s());
|
||||
} catch (final Exception e) {
|
||||
log(C.LEGACY_CONFIG_CONVERSION_FAILED.s());
|
||||
e.printStackTrace();
|
||||
}
|
||||
// Disable plugin
|
||||
this.IMP.shutdown();
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
this.worlds.set("configuration_version", LegacyConverter.CONFIGURATION_VERSION);
|
||||
}
|
||||
} catch (IOException ignored) {
|
||||
PlotSquared.log("Failed to save settings.yml");
|
||||
}
|
||||
@ -1734,6 +1768,7 @@ import java.util.zip.ZipInputStream;
|
||||
PlotSquared.log("Configuration file saving failed");
|
||||
e.printStackTrace();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -247,7 +247,7 @@ import java.util.Map.Entry;
|
||||
|
||||
boolean valid = false;
|
||||
try {
|
||||
step.isValid(args[0]);
|
||||
valid = step.isValid(args[0]);
|
||||
} catch (final Configuration.UnsafeBlockException e) {
|
||||
C.NOT_ALLOWED_BLOCK.send(player, e.getUnsafeBlock().toString());
|
||||
}
|
||||
|
@ -851,6 +851,21 @@ public enum C {
|
||||
* Custom
|
||||
*/
|
||||
|
||||
/**
|
||||
* Legacy Configuration Conversion
|
||||
*/
|
||||
LEGACY_CONFIG_FOUND("A legacy configuration file was detected. Conversion will be attempted.",
|
||||
"LegacyConfig"), LEGACY_CONFIG_BACKUP(
|
||||
"A copy of worlds.yml $1have been saved in the file worlds.yml.old$1.",
|
||||
"LegacyConfig"), LEGACY_CONFIG_REPLACED("> %s has been replaced with %s",
|
||||
"LegacyConfig"), LEGACY_CONFIG_DONE(
|
||||
"The conversion has finished. PlotSquared will now be disabled and the new configuration file will"
|
||||
+ " be used at next startup. Please review the new worlds.yml file. "
|
||||
+ "Please note that schematics will not be converted, as we are now using WorldEdit to handle schematics. "
|
||||
+ "You need to re-generate the schematics.",
|
||||
"LegacyConfig"), LEGACY_CONFIG_CONVERSION_FAILED(
|
||||
"Failed to convert the legacy configuration file. See stack trace for information.", "LegacyConfig"),
|
||||
|
||||
CUSTOM_STRING("-", "-");
|
||||
|
||||
public static final HashMap<String, String> replacements = new HashMap<>();
|
||||
@ -1048,5 +1063,4 @@ public enum C {
|
||||
} else {
|
||||
caller.sendMessage(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
}}
|
||||
|
@ -1,11 +1,16 @@
|
||||
package com.github.intellectualsites.plotsquared.plot.util;
|
||||
|
||||
import com.github.intellectualsites.plotsquared.configuration.ConfigurationSection;
|
||||
import com.github.intellectualsites.plotsquared.plot.PlotSquared;
|
||||
import com.github.intellectualsites.plotsquared.plot.config.C;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.BlockBucket;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.PlotBlock;
|
||||
import lombok.NonNull;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Converts legacy configurations into the new (BlockBucket) format
|
||||
@ -13,6 +18,8 @@ import java.util.*;
|
||||
@SuppressWarnings("unused")
|
||||
public final class LegacyConverter {
|
||||
|
||||
public static final String CONFIGURATION_VERSION = "post_flattening";
|
||||
|
||||
private enum ConfigurationType {
|
||||
BLOCK, BLOCK_LIST
|
||||
}
|
||||
@ -40,7 +47,7 @@ public final class LegacyConverter {
|
||||
}
|
||||
|
||||
private void setString(@NonNull final ConfigurationSection section, @NonNull final String string, @NonNull final BlockBucket blocks) {
|
||||
if (!this.configuration.contains(string)) {
|
||||
if (!section.contains(string)) {
|
||||
throw new IllegalArgumentException(String.format("No such key: %s", string));
|
||||
}
|
||||
section.set(string, blocks.toString());
|
||||
@ -85,6 +92,7 @@ public final class LegacyConverter {
|
||||
@NonNull final String block) {
|
||||
final BlockBucket bucket = this.blockToBucket(block);
|
||||
this.setString(section, key, bucket);
|
||||
PlotSquared.log(C.LEGACY_CONFIG_REPLACED.f(block, bucket.toString()));
|
||||
}
|
||||
|
||||
private void convertBlockList(@NonNull final ConfigurationSection section, @NonNull final String key,
|
||||
@ -92,6 +100,18 @@ public final class LegacyConverter {
|
||||
final PlotBlock[] blocks = this.splitBlockList(blockList);
|
||||
final BlockBucket bucket = this.blockListToBucket(blocks);
|
||||
this.setString(section, key, bucket);
|
||||
PlotSquared.log(C.LEGACY_CONFIG_REPLACED.f(plotBlockArrayString(blocks), bucket.toString()));
|
||||
}
|
||||
|
||||
private String plotBlockArrayString(@NonNull final PlotBlock[] blocks) {
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
for (int i = 0; i < blocks.length; i++) {
|
||||
builder.append(blocks[i].toString());
|
||||
if ((i + 1) < blocks.length) {
|
||||
builder.append(",");
|
||||
}
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
public void convert() {
|
||||
|
@ -6,8 +6,6 @@ public abstract class LegacyMappings {
|
||||
|
||||
public abstract PlotBlock fromAny(final String string);
|
||||
|
||||
public abstract PlotBlock fromLegacyToString(final int id);
|
||||
|
||||
public abstract PlotBlock fromLegacyToString(final int id, final int data);
|
||||
|
||||
public abstract PlotBlock fromLegacyToString(final String id);
|
||||
|
Reference in New Issue
Block a user