mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-29 16:46:45 +01:00
Set the generators on loaded worlds
- uses reflection to access private fields of CBS internals - sets the generator correctly (verified) - sets the populators correctly (verified) - should also work for augmented world types (needs verification)
This commit is contained in:
parent
bb4f8fceec
commit
e7733e749d
@ -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.11.7</version>
|
<version>2.11.8</version>
|
||||||
<name>PlotSquared</name>
|
<name>PlotSquared</name>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
<build>
|
<build>
|
||||||
|
@ -2,6 +2,7 @@ package com.intellectualcrafters.plot;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import net.milkbowl.vault.economy.Economy;
|
import net.milkbowl.vault.economy.Economy;
|
||||||
@ -123,6 +124,7 @@ import com.intellectualcrafters.plot.util.bukkit.SendChunk;
|
|||||||
import com.intellectualcrafters.plot.util.bukkit.SetBlockFast;
|
import com.intellectualcrafters.plot.util.bukkit.SetBlockFast;
|
||||||
import com.intellectualcrafters.plot.util.bukkit.SetBlockFast_1_8;
|
import com.intellectualcrafters.plot.util.bukkit.SetBlockFast_1_8;
|
||||||
import com.intellectualcrafters.plot.util.bukkit.SetBlockSlow;
|
import com.intellectualcrafters.plot.util.bukkit.SetBlockSlow;
|
||||||
|
import com.intellectualcrafters.plot.util.bukkit.SetGenCB;
|
||||||
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
|
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
|
||||||
import com.intellectualcrafters.plot.uuid.DefaultUUIDWrapper;
|
import com.intellectualcrafters.plot.uuid.DefaultUUIDWrapper;
|
||||||
import com.intellectualcrafters.plot.uuid.LowerOfflineUUIDWrapper;
|
import com.intellectualcrafters.plot.uuid.LowerOfflineUUIDWrapper;
|
||||||
@ -172,7 +174,12 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
|
|||||||
if (worlds.size() > 0) {
|
if (worlds.size() > 0) {
|
||||||
UUIDHandler.cacheAll(worlds.get(0).getName());
|
UUIDHandler.cacheAll(worlds.get(0).getName());
|
||||||
for (World world : worlds) {
|
for (World world : worlds) {
|
||||||
Bukkit.getServer().unloadWorld(world, false);
|
try {
|
||||||
|
SetGenCB.setGenerator(world);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log("Failed to reload world: " + world.getName());
|
||||||
|
Bukkit.getServer().unloadWorld(world, false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -498,6 +498,7 @@ public class PlotSquared {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public PlotSquared(final IPlotMain imp_class) {
|
public PlotSquared(final IPlotMain imp_class) {
|
||||||
|
SetupUtils.generators = new HashMap<>();
|
||||||
THIS = this;
|
THIS = this;
|
||||||
IMP = imp_class;
|
IMP = imp_class;
|
||||||
try {
|
try {
|
||||||
|
@ -0,0 +1,55 @@
|
|||||||
|
package com.intellectualcrafters.plot.util.bukkit;
|
||||||
|
|
||||||
|
import java.lang.reflect.Constructor;
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Iterator;
|
||||||
|
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.generator.BlockPopulator;
|
||||||
|
import org.bukkit.generator.ChunkGenerator;
|
||||||
|
|
||||||
|
import com.intellectualcrafters.plot.PlotSquared;
|
||||||
|
import com.intellectualcrafters.plot.generator.AugmentedPopulator;
|
||||||
|
import com.intellectualcrafters.plot.util.SetupUtils;
|
||||||
|
|
||||||
|
public class SetGenCB {
|
||||||
|
public static void setGenerator(World world) throws Exception {
|
||||||
|
SetupUtils.manager.updateGenerators();
|
||||||
|
PlotSquared.removePlotWorld(world.getName());
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
PlotSquared.loadWorld(world.getName(), null);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user