Fix json relocation issue. Make plot areas dump their default flags and add progress output for flag conversion.

This commit is contained in:
Alexander Söderberg 2020-04-11 17:58:08 +02:00
parent 546b857b9d
commit 7931390ae4
6 changed files with 47 additions and 3 deletions

View file

@ -6,6 +6,12 @@
<artifactId>PlotSquared-Bukkit</artifactId>
<version>latest</version>
<dependencies>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20190722</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.github.intellectualsites.plotsquared</groupId>
<artifactId>Core</artifactId>

View file

@ -4,7 +4,6 @@ repositories {
def textVersion = "3.0.2"
dependencies {
compile group: 'org.json', name: 'json', version: '20190722'
implementation("org.yaml:snakeyaml:1.25")
implementation("com.google.code.gson:gson:2.8.6") {
because("Minecraft uses GSON 2.8.0")

View file

@ -1675,13 +1675,26 @@ import java.util.concurrent.atomic.AtomicInteger;
//
try (final PreparedStatement preparedStatement =
this.connection.prepareStatement("INSERT INTO `" + SQLManager.this.prefix + "plot_flags`(`plot_id`, `flag`, `value`) VALUES(?, ?, ?)")) {
long timeStarted = System.currentTimeMillis();
int flagsProcessed = 0;
int plotsProcessed = 0;
int totalFlags = 0;
for (final Map<String, String> flags : flagMap.values()) {
totalFlags += flags.size();
}
for (final Map.Entry<Integer, Map<String, String>> plotFlagEntry : flagMap.entrySet()) {
for (final Map.Entry<String, String> flagEntry : plotFlagEntry.getValue().entrySet()) {
preparedStatement.setInt(1, plotFlagEntry.getKey());
preparedStatement.setString(2, flagEntry.getKey());
preparedStatement.setString(3, flagEntry.getValue());
preparedStatement.addBatch();
flagsProcessed += 1;
}
plotsProcessed += 1;
try {
preparedStatement.executeBatch();
} catch (final Exception e) {
@ -1689,6 +1702,12 @@ import java.util.concurrent.atomic.AtomicInteger;
e.printStackTrace();
continue;
}
if (System.currentTimeMillis() - timeStarted >= 1000L || plotsProcessed >= flagMap.size()) {
timeStarted = System.currentTimeMillis();
PlotSquared.log(Captions.PREFIX.getTranslated() + "... Flag conversion in progress. " + String.format("%.1f", ((float) flagsProcessed / totalFlags) * 100) + "% Done");
}
PlotSquared.debug(Captions.PREFIX.getTranslated() + "- Finished converting flags for plot with entry ID: " + plotFlagEntry.getKey());
}
} catch (final Exception e) {

View file

@ -48,7 +48,7 @@ public abstract class BlockTypeListFlag<F extends ListFlag<BlockTypeWrapper, F>>
@Override public F parse(@NotNull String input) throws FlagParseException {
final List<BlockTypeWrapper> parsedBlocks = new ArrayList<>();
final String[] split = input.split(",(?![^\\(\\[]*[\\]\\)])");
final String[] split = input.replaceAll("\\s+", "").split(",(?![^\\(\\[]*[\\]\\)])");
if (split.length == 0) {
return this.flagOf(parsedBlocks);
}

View file

@ -27,6 +27,7 @@ package com.github.intellectualsites.plotsquared.plot.object;
import com.github.intellectualsites.plotsquared.configuration.ConfigurationSection;
import com.github.intellectualsites.plotsquared.plot.PlotSquared;
import com.github.intellectualsites.plotsquared.plot.config.CaptionUtility;
import com.github.intellectualsites.plotsquared.plot.config.Captions;
import com.github.intellectualsites.plotsquared.plot.config.Configuration;
import com.github.intellectualsites.plotsquared.plot.config.ConfigurationNode;
@ -337,6 +338,22 @@ public abstract class PlotArea {
}
}
this.getFlagContainer().addAll(parseFlags(flags));
StringBuilder flagBuilder = new StringBuilder();
Collection<PlotFlag<?, ?>> flagCollection = this.getFlagContainer().getFlagMap().values();
if (flagCollection.isEmpty()) {
flagBuilder.append(Captions.NONE.getTranslated());
} else {
String prefix = " ";
for (final PlotFlag<?, ?> flag : flagCollection) {
Object value = flag.toString();
flagBuilder.append(prefix).append(CaptionUtility.format(null, Captions.PLOT_FLAG_LIST.getTranslated(),
flag.getName(), CaptionUtility.formatRaw(null, value.toString(), "")));
prefix = ", ";
}
}
PlotSquared.log(Captions.PREFIX + "&3 - default flags: &7" + flagBuilder.toString());
this.spawnEggs = config.getBoolean("event.spawn.egg");
this.spawnCustom = config.getBoolean("event.spawn.custom");
this.spawnBreeding = config.getBoolean("event.spawn.breeding");
@ -1027,7 +1044,7 @@ public abstract class PlotArea {
flags.add(flagInstance.parse(split[1]));
} catch (final FlagParseException e) {
PlotSquared.log(Captions.PREFIX.getTranslated() +
String.format("§2Failed to parse default flag with key §6'%s'§c and value: §6'%s'§c."
String.format("§cFailed to parse default flag with key §6'%s'§c and value: §6'%s'§c."
+ " Reason: %s. This flag will not be added as a default flag.",
e.getFlag().getName(), e.getValue(), e.getErrorMessage()));
}

View file

@ -78,6 +78,8 @@ subprojects {
}
dependencies {
compile group: 'org.json', name: 'json', version: '20190722'
implementation("com.sk89q.worldedit:worldedit-core:7.0.0") {
exclude(module: "bukkit-classloader-check")
exclude(module: "mockito-core")
@ -117,6 +119,7 @@ subprojects {
shadowJar {
dependencies {
include(dependency("org.json:json:20190722"))
include(dependency("net.kyori:text-api:3.0.2"))
}
relocate("io.papermc.lib", "com.github.intellectualsites.plotsquared.bukkit.paperlib")