Dynamically switch between legacy and standard material.

This commit is contained in:
Ben Woo 2021-05-01 23:50:51 +08:00
parent 5a4ef27611
commit ef34f88c6a
3 changed files with 50 additions and 5 deletions

14
pom.xml
View File

@ -34,6 +34,10 @@
<id>minebench-repo</id>
<url>https://repo.minebench.de/</url>
</repository>
<repository>
<id>papermc</id>
<url>https://papermc.io/repo/repository/maven-public/</url>
</repository>
</repositories>
<pluginRepositories>
@ -253,6 +257,10 @@
<pattern>de.themoep.idconverter</pattern>
<shadedPattern>com.onarandombox.idconverter</shadedPattern>
</relocation>
<relocation>
<pattern>io.papermc.lib</pattern>
<shadedPattern>com.onarandombox.paperlib</shadedPattern>
</relocation>
</relocations>
</configuration>
</execution>
@ -339,6 +347,12 @@
<artifactId>mappings</artifactId>
<version>1.2-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>io.papermc</groupId>
<artifactId>paperlib</artifactId>
<version>1.0.6</version>
<scope>compile</scope>
</dependency>
<!-- Start of Test Dependencies -->
<dependency>

View File

@ -1,6 +1,7 @@
package com.onarandombox.MultiverseCore.utils;
import com.dumptruckman.minecraft.util.Logging;
import io.papermc.lib.PaperLib;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Ghast;
import org.bukkit.entity.Monster;
@ -124,4 +125,12 @@ public class CompatibilityLayer {
|| entity instanceof Slime
|| (phantomClass != null && phantomClass.isInstance(entity)));
}
/**
*
* @return True if using legacy material ids, else false.
*/
public static boolean isUsingLegacyMaterials() {
return TestingMode.isDisabled() && PaperLib.getMinecraftVersion() < 13;
}
}

View File

@ -32,11 +32,33 @@ public class MaterialConverter {
*/
@Nullable
public static Material convertTypeString(@Nullable String value) {
IdMappings.Mapping mapping = IdMappings.getById(value != null ? value : "");
if (mapping != null) {
return Material.matchMaterial(mapping.getFlatteningType());
} else {
return Material.matchMaterial(value != null ? value : "");
String targetValue = value != null ? value : "";
IdMappings.Mapping idMapping = IdMappings.getById(targetValue);
if (idMapping != null) {
return getMappedType(idMapping);
}
IdMappings.Mapping flattenMapping = IdMappings.getByFlatteningType(targetValue);
if (flattenMapping != null) {
return getMappedType(flattenMapping);
}
IdMappings.Mapping legacyMapping = IdMappings.getByLegacyType(targetValue);
if (legacyMapping != null) {
return getMappedType(legacyMapping);
}
return Material.matchMaterial(targetValue);
}
/**
* Gets flattened or legacy material type based on what the server supports.
*
* @param mapping Dynamic material mapping provided by {@link IdMappings}.
* @return Material of the mapping.
*/
public static Material getMappedType(IdMappings.Mapping mapping) {
return CompatibilityLayer.isUsingLegacyMaterials()
? Material.matchMaterial(mapping.getLegacyType())
: Material.matchMaterial(mapping.getFlatteningType());
}
}