2015-05-19 18:09:22 +02:00
|
|
|
package com.intellectualcrafters.plot.util.bukkit;
|
|
|
|
|
2015-07-03 11:30:26 +02:00
|
|
|
import java.lang.reflect.Constructor;
|
|
|
|
import java.lang.reflect.Field;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Iterator;
|
2015-05-19 18:09:22 +02:00
|
|
|
|
2015-07-05 17:44:10 +02:00
|
|
|
import org.bukkit.World;
|
|
|
|
import org.bukkit.generator.BlockPopulator;
|
|
|
|
import org.bukkit.generator.ChunkGenerator;
|
|
|
|
|
|
|
|
import com.intellectualcrafters.plot.PS;
|
|
|
|
import com.intellectualcrafters.plot.generator.AugmentedPopulator;
|
|
|
|
import com.intellectualcrafters.plot.util.SetupUtils;
|
|
|
|
|
2015-05-19 18:09:22 +02:00
|
|
|
public class SetGenCB {
|
|
|
|
public static void setGenerator(World world) throws Exception {
|
|
|
|
SetupUtils.manager.updateGenerators();
|
2015-07-03 14:15:20 +02:00
|
|
|
PS.get().removePlotWorldAbs(world.getName());
|
2015-05-19 18:09:22 +02:00
|
|
|
ChunkGenerator gen = world.getGenerator();
|
|
|
|
if (gen == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
String name = gen.getClass().getCanonicalName();
|
|
|
|
boolean set = false;
|
|
|
|
for (ChunkGenerator newGen : SetupUtils.generators.values()) {
|
|
|
|
if (newGen.getClass().getCanonicalName().equals(name)) {
|
|
|
|
// set generator
|
|
|
|
Field generator = world.getClass().getDeclaredField("generator");
|
|
|
|
Field populators = world.getClass().getDeclaredField("populators");
|
|
|
|
generator.setAccessible(true);
|
|
|
|
populators.setAccessible(true);
|
|
|
|
// Set populators (just in case)
|
|
|
|
populators.set(world, new ArrayList<>());
|
|
|
|
// Set generator
|
|
|
|
Constructor<? extends ChunkGenerator> constructor = newGen.getClass().getConstructor(String.class);
|
|
|
|
ChunkGenerator newNewGen = constructor.newInstance(world.getName());
|
|
|
|
generator.set(world, newNewGen);
|
|
|
|
populators.set(world, newNewGen.getDefaultPopulators(world));
|
|
|
|
// end
|
|
|
|
set = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!set) {
|
|
|
|
Iterator<BlockPopulator> iter = world.getPopulators().iterator();
|
|
|
|
while (iter.hasNext()) {
|
|
|
|
if (iter.next() instanceof AugmentedPopulator) {
|
|
|
|
iter.remove();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-07-03 14:15:20 +02:00
|
|
|
PS.get().loadWorld(world.getName(), null);
|
2015-05-19 18:09:22 +02:00
|
|
|
}
|
|
|
|
}
|