2020-04-16 04:52:39 +02:00
|
|
|
/*
|
|
|
|
* _____ _ _ _____ _
|
|
|
|
* | __ \| | | | / ____| | |
|
|
|
|
* | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
|
|
|
|
* | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
|
|
|
|
* | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
|
|
|
|
* |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
|
|
|
|
* | |
|
|
|
|
* |_|
|
|
|
|
* PlotSquared plot management system for Minecraft
|
|
|
|
* Copyright (C) 2020 IntellectualSites
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2020-08-15 14:59:29 +02:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2020-04-16 04:52:39 +02:00
|
|
|
*/
|
2020-04-11 02:19:18 +02:00
|
|
|
package com.plotsquared.bukkit.util;
|
2015-05-19 18:09:22 +02:00
|
|
|
|
2020-04-11 02:19:18 +02:00
|
|
|
import com.plotsquared.bukkit.generator.BukkitAugmentedGenerator;
|
2020-04-15 21:26:54 +02:00
|
|
|
import com.plotsquared.core.PlotSquared;
|
|
|
|
import com.plotsquared.core.generator.GeneratorWrapper;
|
|
|
|
import com.plotsquared.core.util.SetupUtils;
|
2016-02-14 02:01:18 +01:00
|
|
|
import org.bukkit.World;
|
|
|
|
import org.bukkit.generator.ChunkGenerator;
|
|
|
|
|
|
|
|
import java.lang.reflect.Field;
|
|
|
|
import java.util.ArrayList;
|
2015-07-05 17:44:10 +02:00
|
|
|
|
2015-09-13 06:04:31 +02:00
|
|
|
public class SetGenCB {
|
2016-02-14 02:01:18 +01:00
|
|
|
|
2016-03-23 02:41:37 +01:00
|
|
|
public static void setGenerator(World world) throws Exception {
|
2020-12-05 18:41:25 +01:00
|
|
|
PlotSquared.platform().setupUtils().updateGenerators();
|
2018-11-14 14:19:56 +01:00
|
|
|
PlotSquared.get().removePlotAreas(world.getName());
|
2016-03-23 02:41:37 +01:00
|
|
|
ChunkGenerator gen = world.getGenerator();
|
2015-09-13 06:04:31 +02:00
|
|
|
if (gen == null) {
|
|
|
|
return;
|
|
|
|
}
|
2016-03-23 02:41:37 +01:00
|
|
|
String name = gen.getClass().getCanonicalName();
|
2015-05-19 18:09:22 +02:00
|
|
|
boolean set = false;
|
2016-03-23 02:41:37 +01:00
|
|
|
for (GeneratorWrapper<?> wrapper : SetupUtils.generators.values()) {
|
2016-02-10 19:59:51 +01:00
|
|
|
ChunkGenerator newGen = (ChunkGenerator) wrapper.getPlatformGenerator();
|
|
|
|
if (newGen == null) {
|
|
|
|
newGen = (ChunkGenerator) wrapper;
|
|
|
|
}
|
2015-09-13 06:04:31 +02:00
|
|
|
if (newGen.getClass().getCanonicalName().equals(name)) {
|
2015-05-19 18:09:22 +02:00
|
|
|
// set generator
|
2016-03-23 02:41:37 +01:00
|
|
|
Field generator = world.getClass().getDeclaredField("generator");
|
|
|
|
Field populators = world.getClass().getDeclaredField("populators");
|
2015-05-19 18:09:22 +02:00
|
|
|
generator.setAccessible(true);
|
|
|
|
populators.setAccessible(true);
|
|
|
|
// Set populators (just in case)
|
|
|
|
populators.set(world, new ArrayList<>());
|
|
|
|
// Set generator
|
2016-02-10 19:59:51 +01:00
|
|
|
generator.set(world, newGen);
|
|
|
|
populators.set(world, newGen.getDefaultPopulators(world));
|
2015-05-19 18:09:22 +02:00
|
|
|
// end
|
|
|
|
set = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2015-09-13 06:04:31 +02:00
|
|
|
if (!set) {
|
2019-02-13 18:05:28 +01:00
|
|
|
world.getPopulators()
|
|
|
|
.removeIf(blockPopulator -> blockPopulator instanceof BukkitAugmentedGenerator);
|
2015-05-19 18:09:22 +02:00
|
|
|
}
|
2018-11-14 15:44:07 +01:00
|
|
|
PlotSquared.get()
|
2020-07-07 12:56:43 +02:00
|
|
|
.loadWorld(world.getName(), PlotSquared.platform().getGenerator(world.getName(), null));
|
2015-05-19 18:09:22 +02:00
|
|
|
}
|
|
|
|
}
|