mirror of
https://github.com/EssentialsX/Essentials.git
synced 2025-02-21 23:01:28 +01:00
Update mobs and NMS usage to 1.17
Co-authored-by: MD <1917406+mdcfe@users.noreply.github.com>
This commit is contained in:
parent
9bd35a2cd2
commit
e1441c1d33
@ -102,6 +102,9 @@ public enum Mob {
|
||||
STRIDER("Strider", Enemies.FRIENDLY, "STRIDER"),
|
||||
ZOGLIN("Zoglin", Enemies.ENEMY, "ZOGLIN"),
|
||||
PIGLIN_BRUTE("PiglinBrute", Enemies.ADULT_ENEMY, "PIGLIN_BRUTE"),
|
||||
AXOLOTL("Axolotl", Enemies.FRIENDLY, "AXOLOTL"),
|
||||
GOAT("Goat", Enemies.NEUTRAL, "GOAT"),
|
||||
GLOW_SQUID("GlowSquid", Enemies.FRIENDLY, "GLOW_SQUID"),
|
||||
;
|
||||
|
||||
public static final Logger logger = Logger.getLogger("Essentials");
|
||||
|
@ -3,6 +3,7 @@ package com.earth2me.essentials;
|
||||
import com.earth2me.essentials.utils.EnumUtil;
|
||||
import com.earth2me.essentials.utils.VersionUtil;
|
||||
import net.ess3.nms.refl.ReflUtil;
|
||||
import org.bukkit.entity.Axolotl;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Fox;
|
||||
@ -34,6 +35,8 @@ public final class MobCompat {
|
||||
public static final EntityType STRAY = getEntityType("STRAY");
|
||||
public static final EntityType FOX = getEntityType("FOX");
|
||||
public static final EntityType PHANTOM = getEntityType("PHANTOM");
|
||||
public static final EntityType AXOLOTL = getEntityType("AXOLOTL");
|
||||
public static final EntityType GOAT = getEntityType("GOAT");
|
||||
|
||||
// Constants for mobs that have changed since earlier versions
|
||||
public static final EntityType CAT = getEntityType("CAT", "OCELOT");
|
||||
@ -152,6 +155,15 @@ public final class MobCompat {
|
||||
}
|
||||
}
|
||||
|
||||
public static void setAxolotlVariant(final Entity entity, final String variant) {
|
||||
if (VersionUtil.getServerBukkitVersion().isLowerThan(VersionUtil.v1_17_R01)) {
|
||||
return;
|
||||
}
|
||||
if (entity instanceof Axolotl) {
|
||||
((Axolotl) entity).setVariant(Axolotl.Variant.valueOf(variant));
|
||||
}
|
||||
}
|
||||
|
||||
public enum CatType {
|
||||
// These are (loosely) Mojang names for the cats
|
||||
SIAMESE("SIAMESE", "SIAMESE_CAT"),
|
||||
|
@ -3,13 +3,17 @@ package com.earth2me.essentials;
|
||||
import com.earth2me.essentials.craftbukkit.InventoryWorkaround;
|
||||
import com.earth2me.essentials.utils.EnumUtil;
|
||||
import com.earth2me.essentials.utils.StringUtil;
|
||||
import com.earth2me.essentials.utils.VersionUtil;
|
||||
import org.bukkit.DyeColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Ageable;
|
||||
import org.bukkit.entity.Axolotl;
|
||||
import org.bukkit.entity.ChestedHorse;
|
||||
import org.bukkit.entity.Creeper;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.ExperienceOrb;
|
||||
import org.bukkit.entity.Goat;
|
||||
import org.bukkit.entity.Horse;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Phantom;
|
||||
@ -185,6 +189,8 @@ public enum MobData {
|
||||
RAID_LEADER("leader", MobCompat.RAIDER, Data.RAID_LEADER, true),
|
||||
TROPICAL_FISH_BODY_COLOR("fish_body_color", Arrays.stream(DyeColor.values()).map(color -> color.name().toLowerCase(Locale.ENGLISH) + "body").collect(Collectors.toList()), MobCompat.TROPICAL_FISH, Data.FISH_BODY_COLOR, true),
|
||||
TROPICAL_FISH_PATTERN_COLOR("fish_pattern_color", Arrays.stream(DyeColor.values()).map(color -> color.name().toLowerCase(Locale.ENGLISH) + "pattern").collect(Collectors.toList()), MobCompat.TROPICAL_FISH, Data.FISH_PATTERN_COLOR, true),
|
||||
COLORABLE_AXOLOTL("", Arrays.stream(Axolotl.Variant.values()).map(color -> color.name().toLowerCase(Locale.ENGLISH)).collect(Collectors.toList()), MobCompat.AXOLOTL, Data.COLORABLE, true),
|
||||
SCREAMING_GOAT("screaming", MobCompat.GOAT, Data.GOAT_SCREAMING, true),
|
||||
;
|
||||
|
||||
public static final Logger logger = Logger.getLogger("Essentials");
|
||||
@ -270,6 +276,12 @@ public enum MobData {
|
||||
((Ageable) spawned).setAdult();
|
||||
} else if (this.value.equals(Data.BABY)) {
|
||||
((Ageable) spawned).setBaby();
|
||||
} else if (this.value.equals(Data.CHEST)) {
|
||||
if (VersionUtil.getServerBukkitVersion().isHigherThanOrEqualTo(VersionUtil.v1_11_R01)) {
|
||||
((ChestedHorse) spawned).setCarryingChest(true);
|
||||
} else {
|
||||
((Horse) spawned).setCarryingChest(true);
|
||||
}
|
||||
} else if (this.value.equals(Data.ADULTZOMBIE)) {
|
||||
((Zombie) spawned).setBaby(false);
|
||||
} else if (this.value.equals(Data.BABYZOMBIE)) {
|
||||
@ -356,6 +368,8 @@ public enum MobData {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if (this.value.equals(Data.GOAT_SCREAMING)) {
|
||||
((Goat) spawned).setScreaming(true);
|
||||
} else if (this.value instanceof String) {
|
||||
final String[] split = ((String) this.value).split(":");
|
||||
switch (split[0]) {
|
||||
@ -383,6 +397,10 @@ public enum MobData {
|
||||
case "fox":
|
||||
MobCompat.setFoxType(spawned, split[1]);
|
||||
break;
|
||||
case "axolotl": {
|
||||
MobCompat.setAxolotlVariant(spawned, split[1]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
logger.warning("Unknown mob data type: " + this.toString());
|
||||
@ -406,5 +424,6 @@ public enum MobData {
|
||||
RAID_LEADER,
|
||||
FISH_BODY_COLOR,
|
||||
FISH_PATTERN_COLOR,
|
||||
GOAT_SCREAMING,
|
||||
}
|
||||
}
|
||||
|
@ -32,8 +32,9 @@ public final class VersionUtil {
|
||||
public static final BukkitVersion v1_15_2_R01 = BukkitVersion.fromString("1.15.2-R0.1-SNAPSHOT");
|
||||
public static final BukkitVersion v1_16_1_R01 = BukkitVersion.fromString("1.16.1-R0.1-SNAPSHOT");
|
||||
public static final BukkitVersion v1_16_5_R01 = BukkitVersion.fromString("1.16.5-R0.1-SNAPSHOT");
|
||||
public static final BukkitVersion v1_17_R01 = BukkitVersion.fromString("1.17-R0.1-SNAPSHOT");
|
||||
|
||||
private static final Set<BukkitVersion> supportedVersions = ImmutableSet.of(v1_8_8_R01, v1_9_4_R01, v1_10_2_R01, v1_11_2_R01, v1_12_2_R01, v1_13_2_R01, v1_14_4_R01, v1_15_2_R01, v1_16_5_R01);
|
||||
private static final Set<BukkitVersion> supportedVersions = ImmutableSet.of(v1_8_8_R01, v1_9_4_R01, v1_10_2_R01, v1_11_2_R01, v1_12_2_R01, v1_13_2_R01, v1_14_4_R01, v1_15_2_R01, v1_16_5_R01, v1_17_R01);
|
||||
|
||||
private static final Map<String, SupportStatus> unsupportedServerClasses;
|
||||
|
||||
@ -65,7 +66,11 @@ public final class VersionUtil {
|
||||
builder.put("net.fabricmc.loader.launch.knot.KnotServer", SupportStatus.UNSTABLE);
|
||||
|
||||
// Misc translation layers that do not add NMS will be caught by this
|
||||
builder.put("!net.minecraft.server." + ReflUtil.getNMSVersion() + ".MinecraftServer", SupportStatus.NMS_CLEANROOM);
|
||||
if (ReflUtil.getNmsVersionObject().isHigherThanOrEqualTo(ReflUtil.V1_17_R1)) {
|
||||
builder.put("!net.minecraft.server.MinecraftServer", SupportStatus.NMS_CLEANROOM);
|
||||
} else {
|
||||
builder.put("!net.minecraft.server." + ReflUtil.getNMSVersion() + ".MinecraftServer", SupportStatus.NMS_CLEANROOM);
|
||||
}
|
||||
|
||||
unsupportedServerClasses = builder.build();
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ EssentialsX is almost a completely drop-in replacement for Essentials. However,
|
||||
|
||||
* **EssentialsX requires Java 8 or higher.** On older versions, the plugin may not work properly.
|
||||
|
||||
* **EssentialsX supports Minecraft versions 1.8.8, 1.9.4, 1.10.2, 1.11.2, 1.12.2, 1.13.2, 1.14.4, 1.15.2, and 1.16.5.**
|
||||
* **EssentialsX supports Minecraft versions 1.8.8, 1.9.4, 1.10.2, 1.11.2, 1.12.2, 1.13.2, 1.14.4, 1.15.2, 1.16.5, and 1.17**
|
||||
|
||||
|
||||
Support
|
||||
|
@ -10,7 +10,7 @@ plugins {
|
||||
val baseExtension = extensions.create<EssentialsBaseExtension>("essentials", project)
|
||||
|
||||
val checkstyleVersion = "8.36.2"
|
||||
val spigotVersion = "1.16.5-R0.1-SNAPSHOT"
|
||||
val spigotVersion = "1.17-R0.1-SNAPSHOT"
|
||||
val junit5Version = "5.7.0"
|
||||
val mockitoVersion = "3.2.0"
|
||||
|
||||
|
@ -19,6 +19,7 @@ public final class ReflUtil {
|
||||
public static final NMSVersion V1_12_R1 = NMSVersion.fromString("v1_12_R1");
|
||||
public static final NMSVersion V1_9_R1 = NMSVersion.fromString("v1_9_R1");
|
||||
public static final NMSVersion V1_11_R1 = NMSVersion.fromString("v1_11_R1");
|
||||
public static final NMSVersion V1_17_R1 = NMSVersion.fromString("v1_17_R1");
|
||||
private static final Map<String, Class<?>> classCache = new HashMap<>();
|
||||
private static final Table<Class<?>, String, Method> methodCache = HashBasedTable.create();
|
||||
private static final Table<Class<?>, MethodParams, Method> methodParamCache = HashBasedTable.create();
|
||||
@ -46,17 +47,26 @@ public final class ReflUtil {
|
||||
|
||||
public static NMSVersion getNmsVersionObject() {
|
||||
if (nmsVersionObject == null) {
|
||||
nmsVersionObject = NMSVersion.fromString(getNMSVersion());
|
||||
try {
|
||||
nmsVersionObject = NMSVersion.fromString(getNMSVersion());
|
||||
} catch (final IllegalArgumentException e) {
|
||||
try {
|
||||
Class.forName("org.bukkit.craftbukkit.CraftServer");
|
||||
nmsVersionObject = new NMSVersion(99, 99, 99); // Mojang Dev Mappings
|
||||
} catch (final ClassNotFoundException ignored) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
return nmsVersionObject;
|
||||
}
|
||||
|
||||
public static Class<?> getNMSClass(final String className) {
|
||||
return getClassCached("net.minecraft.server." + getNMSVersion() + "." + className);
|
||||
return getClassCached("net.minecraft.server" + (ReflUtil.getNmsVersionObject().isLowerThan(ReflUtil.V1_17_R1) ? "." + getNMSVersion() : "") + "." + className);
|
||||
}
|
||||
|
||||
public static Class<?> getOBCClass(final String className) {
|
||||
return getClassCached("org.bukkit.craftbukkit." + getNMSVersion() + "." + className);
|
||||
return getClassCached("org.bukkit.craftbukkit" + (getNmsVersionObject().getMajor() == 99 ? "" : ("." + getNMSVersion())) + "." + className);
|
||||
}
|
||||
|
||||
public static Class<?> getClassCached(final String className) {
|
||||
|
Loading…
Reference in New Issue
Block a user