Fixed template creation

This commit is contained in:
boy0001 2015-04-02 14:52:14 +11:00
parent b0384f4074
commit 93e6a2d87c
4 changed files with 32 additions and 1 deletions

View File

@ -8,7 +8,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties> </properties>
<artifactId>PlotSquared</artifactId> <artifactId>PlotSquared</artifactId>
<version>2.9.2</version> <version>2.9.3</version>
<name>PlotSquared</name> <name>PlotSquared</name>
<packaging>jar</packaging> <packaging>jar</packaging>
<build> <build>

View File

@ -178,6 +178,10 @@ public class Template extends SubCommand {
public static byte[] getBytes(PlotWorld plotworld) { public static byte[] getBytes(PlotWorld plotworld) {
ConfigurationSection section = PlotSquared.config.getConfigurationSection("worlds." + plotworld.worldname); ConfigurationSection section = PlotSquared.config.getConfigurationSection("worlds." + plotworld.worldname);
YamlConfiguration config = new YamlConfiguration(); YamlConfiguration config = new YamlConfiguration();
String generator = SetupUtils.manager.getGenerator(plotworld);
if (generator != null) {
config.set("generator.plugin", generator);
}
for (String key : section.getKeys(true)) { for (String key : section.getKeys(true)) {
config.set(key, section.get(key)); config.set(key, section.get(key));
} }

View File

@ -4,6 +4,7 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
import com.intellectualcrafters.plot.object.PlotGenerator; import com.intellectualcrafters.plot.object.PlotGenerator;
import com.intellectualcrafters.plot.object.PlotWorld;
import com.intellectualcrafters.plot.object.SetupObject; import com.intellectualcrafters.plot.object.SetupObject;
public abstract class SetupUtils { public abstract class SetupUtils {
@ -15,5 +16,7 @@ public abstract class SetupUtils {
public abstract void updateGenerators(); public abstract void updateGenerators();
public abstract String getGenerator(PlotWorld plotworld);
public abstract String setupWorld(final SetupObject object); public abstract String setupWorld(final SetupObject object);
} }

View File

@ -1,11 +1,14 @@
package com.intellectualcrafters.plot.util.bukkit; package com.intellectualcrafters.plot.util.bukkit;
import java.io.IOException; import java.io.IOException;
import java.util.List;
import java.util.Map.Entry;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.World.Environment; import org.bukkit.World.Environment;
import org.bukkit.WorldCreator; import org.bukkit.WorldCreator;
import org.bukkit.generator.BlockPopulator;
import org.bukkit.generator.ChunkGenerator; import org.bukkit.generator.ChunkGenerator;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
@ -13,6 +16,7 @@ import com.intellectualcrafters.plot.PlotSquared;
import com.intellectualcrafters.plot.config.ConfigurationNode; import com.intellectualcrafters.plot.config.ConfigurationNode;
import com.intellectualcrafters.plot.generator.SquarePlotManager; import com.intellectualcrafters.plot.generator.SquarePlotManager;
import com.intellectualcrafters.plot.object.PlotGenerator; import com.intellectualcrafters.plot.object.PlotGenerator;
import com.intellectualcrafters.plot.object.PlotWorld;
import com.intellectualcrafters.plot.object.SetupObject; import com.intellectualcrafters.plot.object.SetupObject;
import com.intellectualcrafters.plot.util.SetupUtils; import com.intellectualcrafters.plot.util.SetupUtils;
@ -85,4 +89,24 @@ public class BukkitSetupUtils extends SetupUtils {
return object.world; return object.world;
} }
@Override
public String getGenerator(PlotWorld plotworld) {
if (SetupUtils.generators.size() == 0) {
updateGenerators();
}
World world = Bukkit.getWorld(plotworld.worldname);
if (world == null) {
return null;
}
ChunkGenerator generator = world.getGenerator();
if (!(generator instanceof PlotGenerator)) {
return null;
}
for (Entry<String, PlotGenerator> entry : generators.entrySet()) {
if (entry.getValue().getClass().getName().equals(generator.getClass().getName())) {
return entry.getKey();
}
}
return null;
}
} }