Update to 1.17 #11

Open
CrashCringle12 wants to merge 1 commit from CrashCringle12/master into master
4 changed files with 121 additions and 118 deletions

125
pom.xml
View file

@ -6,47 +6,34 @@
<groupId>com.github.TBMCPlugins</groupId> <groupId>com.github.TBMCPlugins</groupId>
<artifactId>CustomDimensions</artifactId> <artifactId>CustomDimensions</artifactId>
<version>1.6.0</version> <version>1.6.1</version>
<build> <build>
<plugins> <defaultGoal>clean package install</defaultGoal>
<plugin> <finalName>${project.name}-${project.version}</finalName>
<groupId>org.apache.maven.plugins</groupId> <sourceDirectory>${project.basedir}/src</sourceDirectory>
<artifactId>maven-compiler-plugin</artifactId> <resources>
<version>3.8.1</version> <resource>
<configuration> <targetPath>.</targetPath>
<!-- Make sure we're not using Java 9+ APIs --> <filtering>true</filtering>
<release>8</release> <directory>${project.basedir}/src/</directory>
<source>14</source> <includes>
<target>14</target> <include>plugin.yml</include>
<compilerArgs> </includes>
<arg>-Xplugin:jabel</arg> </resource>
</compilerArgs> </resources>
</configuration> <plugins>
</plugin> <plugin>
<plugin> <groupId>org.apache.maven.plugins</groupId>
<groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId>
<artifactId>maven-shade-plugin</artifactId> <version>3.1</version>
<version>3.2.4</version> <configuration>
<configuration> <source>8</source>
<relocations> <target>8</target>
<relocation> </configuration>
<pattern>org.bstats</pattern> </plugin>
<shadedPattern>buttondevteam.customdimensions.bstats</shadedPattern> </plugins>
</relocation> </build>
</relocations>
<createDependencyReducedPom>false</createDependencyReducedPom>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<repositories> <repositories>
<repository> <repository>
@ -60,48 +47,18 @@
</repositories> </repositories>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>org.spigotmc</groupId> <groupId>org.spigotmc</groupId>
<artifactId>spigot</artifactId> <artifactId>spigot-api</artifactId>
<version>1.16.4-R0.1-SNAPSHOT</version> <version>1.17-R0.1-SNAPSHOT</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.github.bsideup.jabel</groupId> <groupId>org.spigotmc</groupId>
<artifactId>jabel-javac-plugin</artifactId> <artifactId>spigot</artifactId>
<version>0.3.0</version> <version>1.17</version>
<scope>provided</scope> <scope>system</scope>
</dependency> <systemPath>${project.basedir}/utils/spigot-1.17.jar</systemPath>
<dependency> </dependency>
<groupId>org.bstats</groupId>
<artifactId>bstats-bukkit</artifactId>
<version>2.2.1</version>
<scope>compile</scope>
</dependency>
</dependencies> </dependencies>
<profiles>
<profile>
<id>intellij-idea-only</id>
<activation>
<property>
<name>idea.maven.embedder.version</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<release>14</release>
<compilerArgs>
<arg>--enable-preview</arg>
</compilerArgs>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project> </project>

View file

@ -4,13 +4,48 @@ import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.google.common.util.concurrent.Callables; import com.google.common.util.concurrent.Callables;
import com.mojang.serialization.DynamicOps;
import com.mojang.serialization.Lifecycle; import com.mojang.serialization.Lifecycle;
import net.minecraft.server.v1_16_R3.*;
import org.bstats.bukkit.Metrics; import net.minecraft.core.IRegistry;
import org.bstats.charts.SimplePie; import net.minecraft.core.IRegistryCustom;
import net.minecraft.core.RegistryMaterials;
import net.minecraft.nbt.DynamicOpsNBT;
import net.minecraft.nbt.NBTBase;
import net.minecraft.resources.MinecraftKey;
import net.minecraft.resources.RegistryReadOps;
import net.minecraft.resources.ResourceKey;
import net.minecraft.server.*;
import net.minecraft.server.dedicated.DedicatedServer;
import net.minecraft.server.level.WorldServer;
import net.minecraft.server.level.progress.WorldLoadListener;
import net.minecraft.util.datafix.DataConverterRegistry;
import net.minecraft.world.EnumDifficulty;
import net.minecraft.world.entity.ai.village.VillageSiege;
import net.minecraft.world.entity.npc.MobSpawnerCat;
import net.minecraft.world.entity.npc.MobSpawnerTrader;
import net.minecraft.world.level.EnumGamemode;
import net.minecraft.world.level.GameRules;
import net.minecraft.world.level.MobSpawner;
import net.minecraft.world.level.World;
import net.minecraft.world.level.WorldSettings;
import net.minecraft.world.level.biome.BiomeManager;
import net.minecraft.world.level.chunk.ChunkGenerator;
import net.minecraft.world.level.dimension.DimensionManager;
import net.minecraft.world.level.dimension.WorldDimension;
import net.minecraft.world.level.levelgen.GeneratorSettings;
import net.minecraft.world.level.levelgen.MobSpawnerPatrol;
import net.minecraft.world.level.levelgen.MobSpawnerPhantom;
import net.minecraft.world.level.storage.Convertable;
import net.minecraft.world.level.storage.Convertable.ConversionSession;
import net.minecraft.world.level.storage.SaveData;
import net.minecraft.world.level.storage.WorldDataServer;
import net.minecraft.world.level.storage.loot.predicates.LootItemConditionType;
import net.minecraft.server.packs.resources.IResourceManager;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.WorldType; import org.bukkit.WorldType;
import org.bukkit.craftbukkit.v1_16_R3.CraftServer; import org.bukkit.craftbukkit.v1_17_R1.CraftServer;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.world.WorldInitEvent; import org.bukkit.event.world.WorldInitEvent;
import org.bukkit.event.world.WorldLoadEvent; import org.bukkit.event.world.WorldLoadEvent;
@ -18,14 +53,14 @@ import org.bukkit.plugin.java.JavaPlugin;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.Field;
import java.util.*; import java.util.*;
import java.util.Map.Entry;
public class CustomDimensions extends JavaPlugin implements Listener { public class CustomDimensions extends JavaPlugin implements Listener {
private Metrics metrics;
@Override @Override
public void onEnable() { public void onEnable() {
metrics = new Metrics(this, 10545);
getLogger().info("Loading custom dimensions..."); getLogger().info("Loading custom dimensions...");
try { try {
load(); load();
@ -36,24 +71,28 @@ public class CustomDimensions extends JavaPlugin implements Listener {
} }
private void load() throws Exception { private void load() throws Exception {
var console = ((CraftServer) Bukkit.getServer()).getServer(); DedicatedServer console = ((CraftServer) Bukkit.getServer()).getServer();
var field = console.getClass().getSuperclass().getDeclaredField("saveData"); System.out.println("******************************************");
for (Field fie : console.getClass().getSuperclass().getDeclaredFields()) {
System.out.println(fie.getName());
}
Field field = console.getClass().getSuperclass().getDeclaredField("saveData");
field.setAccessible(true); field.setAccessible(true);
var saveData = (SaveData) field.get(console); SaveData saveData = (SaveData) field.get(console);
GeneratorSettings mainGenSettings = saveData.getGeneratorSettings(); GeneratorSettings mainGenSettings = saveData.getGeneratorSettings();
RegistryMaterials<WorldDimension> dimensionRegistry = mainGenSettings.d(); RegistryMaterials<WorldDimension> dimensionRegistry = mainGenSettings.d();
var mainWorld = Bukkit.getWorlds().get(0); org.bukkit.World mainWorld = Bukkit.getWorlds().get(0);
var convertable = Convertable.a(Bukkit.getWorldContainer().toPath()); Convertable convertable = Convertable.a(Bukkit.getWorldContainer().toPath());
if (!getConfig().contains("ignored")) { if (!getConfig().contains("ignored")) {
getConfig().set("ignored", Lists.newArrayList("single_biome")); getConfig().set("ignored", Lists.newArrayList("single_biome"));
saveConfig(); saveConfig();
} }
var ignored = getConfig().getStringList("ignored"); List<String> ignored = getConfig().getStringList("ignored");
int allCount = -3, loadedCount = 0, ignoredCount = 0; //-3: overworld, nether, end int allCount = -3, loadedCount = 0, ignoredCount = 0; //-3: overworld, nether, end
for (var dimEntry : dimensionRegistry.d()) { for (Entry<ResourceKey<WorldDimension>, WorldDimension> dimEntry : dimensionRegistry.d()) {
allCount++; allCount++;
if (ignored.contains(dimEntry.getKey().a().getKey())) { if (ignored.contains(dimEntry.getKey().a().getKey())) {
getLogger().info(dimEntry.getKey() + " is on the ignore list"); getLogger().info(dimEntry.getKey() + " is on the ignore list");
@ -68,18 +107,17 @@ public class CustomDimensions extends JavaPlugin implements Listener {
e.printStackTrace(); e.printStackTrace();
} }
} }
metrics.addCustomChart(new SimplePie("all_custom_dimensions", Callables.returning(allCount + "")));
metrics.addCustomChart(new SimplePie("loaded_custom_dimensions", Callables.returning(loadedCount + "")));
metrics.addCustomChart(new SimplePie("ignored_custom_dimensions", Callables.returning(ignoredCount + "")));
} }
private boolean loadDimension(ResourceKey<WorldDimension> dimKey, WorldDimension dimension, private boolean loadDimension(ResourceKey<WorldDimension> dimKey, WorldDimension dimension,
Convertable convertable, DedicatedServer console, org.bukkit.World mainWorld) throws IOException { Convertable convertable, DedicatedServer console, org.bukkit.World mainWorld) throws IOException {
if (dimKey == WorldDimension.OVERWORLD //The default dimensions are already loaded if (dimKey == WorldDimension.a //The default dimensions are already loaded
|| dimKey == WorldDimension.THE_NETHER || dimKey == WorldDimension.b
|| dimKey == WorldDimension.THE_END) || dimKey == WorldDimension.c
|| dimKey == WorldDimension.d)
return false; return false;
ResourceKey<World> worldKey = ResourceKey.a(IRegistry.L, dimKey.a()); ResourceKey<World> worldKey = ResourceKey.a(IRegistry.Q, dimKey.a());
DimensionManager dimensionmanager = dimension.b(); DimensionManager dimensionmanager = dimension.b();
ChunkGenerator chunkgenerator = dimension.c(); ChunkGenerator chunkgenerator = dimension.c();
String name = getConfig().getString("worldNames." + dimKey.a()); String name = getConfig().getString("worldNames." + dimKey.a());
@ -90,16 +128,16 @@ public class CustomDimensions extends JavaPlugin implements Listener {
return false; return false;
} }
getLogger().info("Loading " + name); getLogger().info("Loading " + name);
var session = convertable.new ConversionSession(name, dimKey) { //The original session isn't prepared for custom dimensions ConversionSession session = convertable.new ConversionSession(name, dimKey) { //The original session isn't prepared for custom dimensions
@Override @Override
public File a(ResourceKey<World> resourcekey) { public File a(ResourceKey<World> resourcekey) {
return new File(this.folder.toFile(), "custom"); return new File(this.c.toFile(), "custom");
} }
}; };
MinecraftServer.convertWorld(session); MinecraftServer.convertWorld(session);
//Load world settings or create default values //Load world settings or create default values
RegistryReadOps<NBTBase> registryreadops = RegistryReadOps.a(DynamicOpsNBT.a, console.dataPackResources.h(), console.customRegistry); RegistryReadOps<NBTBase> registryreadops = RegistryReadOps.a((DynamicOps<NBTBase>) DynamicOpsNBT.a, console.aC.i(), console.getCustomRegistry());
WorldDataServer worlddata = (WorldDataServer) session.a(registryreadops, console.datapackconfiguration); WorldDataServer worlddata = (WorldDataServer) session.a(registryreadops, console.datapackconfiguration);
if (worlddata == null) { if (worlddata == null) {
Properties properties = new Properties(); Properties properties = new Properties();
@ -110,35 +148,36 @@ public class CustomDimensions extends JavaPlugin implements Listener {
WorldSettings worldSettings = new WorldSettings(name, WorldSettings worldSettings = new WorldSettings(name,
EnumGamemode.getById(Bukkit.getDefaultGameMode().getValue()), EnumGamemode.getById(Bukkit.getDefaultGameMode().getValue()),
false, //Hardcore false, //Hardcore
EnumDifficulty.EASY, false, new GameRules(), console.datapackconfiguration); EnumDifficulty.a, false, new GameRules(), console.datapackconfiguration);
worlddata = new WorldDataServer(worldSettings, dimGenSettings, Lifecycle.stable()); worlddata = new WorldDataServer(worldSettings, dimGenSettings, Lifecycle.stable());
} }
worlddata.checkName(name); worlddata.checkName(name);
worlddata.a(console.getServerModName(), console.getModded().isPresent()); worlddata.a(console.getServerModName(), console.getModded().isPresent());
if (console.options.has("forceUpgrade")) { if (console.options.has("forceUpgrade")) {
net.minecraft.server.v1_16_R3.Main.convertWorld(session, DataConverterRegistry.a(), net.minecraft.server.Main.convertWorld(session, DataConverterRegistry.a(),
console.options.has("eraseCache"), () -> true, console.options.has("eraseCache"), () -> true,
worlddata.getGeneratorSettings().d().d().stream() worlddata.getGeneratorSettings().d().d().stream()
.map((entry2) -> ResourceKey.a(IRegistry.K, entry2.getKey().a())) .map((entry2) -> ResourceKey.a(IRegistry.P, entry2.getKey().a()))
.collect(ImmutableSet.toImmutableSet())); .collect(ImmutableSet.toImmutableSet()));
} }
List<MobSpawner> spawners = ImmutableList.of(new MobSpawnerPhantom(), new MobSpawnerPatrol(), new MobSpawnerCat(), new VillageSiege(), new MobSpawnerTrader(worlddata)); List<MobSpawner> spawners = ImmutableList.of(new MobSpawnerPhantom(), new MobSpawnerPatrol(), new MobSpawnerCat(), new VillageSiege(), new MobSpawnerTrader(worlddata));
ResourceKey<DimensionManager> dimManResKey = ResourceKey.a(IRegistry.K, dimKey.a());
var dimRegistry = ((RegistryMaterials<DimensionManager>) console.customRegistry.a()); ResourceKey<DimensionManager> dimManResKey = ResourceKey.a(IRegistry.P, dimKey.a());
RegistryMaterials<DimensionManager> dimRegistry = new RegistryMaterials<DimensionManager>(null, null); //((RegistryMaterials<DimensionManager>));
{ {
var key = dimRegistry.getKey(dimensionmanager); MinecraftKey key = dimRegistry.getKey(dimensionmanager);
if (key == null) { //The loaded manager is different - different dimension type if (key == null) { //The loaded manager is different - different dimension type
//Replace existing dimension manager, correctly setting the ID up (which is -1 for default worlds...) //Replace existing dimension manager, correctly setting the ID up (which is -1 for default worlds...)
dimRegistry.a(OptionalInt.empty(), dimManResKey, dimensionmanager, Lifecycle.stable()); dimRegistry.a(OptionalInt.empty(), dimManResKey, dimensionmanager, Lifecycle.stable());
} }
} }
var worldloadlistener = console.worldLoadListenerFactory.create(11); WorldLoadListener worldloadlistener = console.L.create(11);
WorldServer worldserver = new WorldServer(console, console.aA, session,
WorldServer worldserver = new WorldServer(console, console.executorService, session,
worlddata, worldKey, dimensionmanager, worldloadlistener, chunkgenerator, worlddata, worldKey, dimensionmanager, worldloadlistener, chunkgenerator,
false, //isDebugWorld false, //isDebugWorld
BiomeManager.a(worlddata.getGeneratorSettings().getSeed()), //Biome seed BiomeManager.a(worlddata.getGeneratorSettings().getSeed()), //Biome seed
@ -152,9 +191,9 @@ public class CustomDimensions extends JavaPlugin implements Listener {
} else { } else {
console.initWorld(worldserver, worlddata, worlddata, worlddata.getGeneratorSettings()); console.initWorld(worldserver, worlddata, worlddata, worlddata.getGeneratorSettings());
worldserver.setSpawnFlags(true, true); worldserver.setSpawnFlags(true, true);
console.worldServer.put(worldserver.getDimensionKey(), worldserver); console.R.put(worldserver.getDimensionKey(), worldserver);
Bukkit.getPluginManager().callEvent(new WorldInitEvent(worldserver.getWorld())); Bukkit.getPluginManager().callEvent(new WorldInitEvent(worldserver.getWorld()));
console.loadSpawn(worldserver.getChunkProvider().playerChunkMap.worldLoadListener, worldserver); console.loadSpawn(worldserver.getChunkProvider().a.z, worldserver);
Bukkit.getPluginManager().callEvent(new WorldLoadEvent(worldserver.getWorld())); Bukkit.getPluginManager().callEvent(new WorldLoadEvent(worldserver.getWorld()));
return true; return true;
} }

7
src/plugin.yml Normal file
View file

@ -0,0 +1,7 @@
name: CustomDimensions
main: buttondevteam.customdimensions.CustomDimensions
api-version: 1.14
version: 1.17
loadbefore:
- Multiverse-Core
- Hyperverse

BIN
utils/spigot-1.17.jar Normal file

Binary file not shown.