mirror of
https://github.com/EssentialsX/Essentials.git
synced 2025-04-06 13:30:43 +08:00
Support boat variants on older versions
New versions will need to use the specific entity, as we cannot swap the entity type after it has been spawned
This commit is contained in:
parent
2b209a4a2f
commit
fe6b04ed84
@ -5,7 +5,9 @@ import com.earth2me.essentials.utils.RegistryUtil;
|
||||
import com.earth2me.essentials.utils.VersionUtil;
|
||||
import net.ess3.nms.refl.ReflUtil;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.TreeSpecies;
|
||||
import org.bukkit.entity.Axolotl;
|
||||
import org.bukkit.entity.Boat;
|
||||
import org.bukkit.entity.Camel;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
@ -194,6 +196,25 @@ public final class MobCompat {
|
||||
}
|
||||
}
|
||||
|
||||
public static void setBoatVariant(final Entity entity, final BoatVariant variant) {
|
||||
if (VersionUtil.getServerBukkitVersion().isHigherThanOrEqualTo(VersionUtil.v1_21_3_R01) || VersionUtil.getServerBukkitVersion().isLowerThan(VersionUtil.v1_9_R01)) {
|
||||
return;
|
||||
}
|
||||
final Boat boat;
|
||||
if (entity instanceof Boat) {
|
||||
boat = (Boat) entity;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
if (VersionUtil.getServerBukkitVersion().isLowerThan(VersionUtil.v1_19_R01)) {
|
||||
//noinspection deprecation
|
||||
boat.setWoodType(TreeSpecies.valueOf(variant.getTreeSpecies()));
|
||||
} else {
|
||||
//noinspection deprecation
|
||||
boat.setBoatType(Boat.Type.valueOf(variant.getBoatType()));
|
||||
}
|
||||
}
|
||||
|
||||
public static void setCamelSaddle(final Entity entity, final Player target) {
|
||||
if (VersionUtil.getServerBukkitVersion().isLowerThan(VersionUtil.v1_20_1_R01)) {
|
||||
return;
|
||||
@ -292,4 +313,35 @@ public final class MobCompat {
|
||||
return RegistryUtil.valueOf(Villager.Profession.class, newProfession, oldProfession);
|
||||
}
|
||||
}
|
||||
|
||||
public enum BoatVariant {
|
||||
// Mappings for TreeSpecies names
|
||||
ACACIA("ACACIA", "ACACIA"),
|
||||
BIRCH("BIRCH", "BIRCH"),
|
||||
DARKOAK("DARK_OAK", "DARK_OAK"),
|
||||
GENERIC("GENERIC", "OAK"),
|
||||
JUNGLE("JUNGLE", "JUNGLE"),
|
||||
REDWOOD("REDWOOD", "SPRUCE"),
|
||||
// Mappings for Boat.Type names (falling back to GENERIC where undefined)
|
||||
OAK("GENERIC", "OAK"),
|
||||
SPRUCE("REDWOOD", "SPRUCE"),
|
||||
MANGROVE("GENERIC", "MANGROVE"),
|
||||
;
|
||||
|
||||
private final String treeSpecies;
|
||||
private final String boatType;
|
||||
|
||||
BoatVariant(final String treeSpecies, final String boatType) {
|
||||
this.treeSpecies = treeSpecies;
|
||||
this.boatType = boatType;
|
||||
}
|
||||
|
||||
public String getTreeSpecies() {
|
||||
return treeSpecies;
|
||||
}
|
||||
|
||||
public String getBoatType() {
|
||||
return boatType;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ import net.ess3.api.TranslatableException;
|
||||
import org.bukkit.DyeColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Ageable;
|
||||
import org.bukkit.entity.Boat;
|
||||
import org.bukkit.entity.ChestedHorse;
|
||||
import org.bukkit.entity.Creeper;
|
||||
import org.bukkit.entity.Entity;
|
||||
@ -198,6 +199,15 @@ public enum MobData {
|
||||
TEMPERATE_FROG("temperate", MobCompat.FROG, "frog:TEMPERATE", true),
|
||||
WARM_FROG("warm", MobCompat.FROG, "frog:WARM", true),
|
||||
COLD_FROG("cold", MobCompat.FROG, "frog:COLD", true),
|
||||
ACACIA_BOAT("acacia", Boat.class, MobCompat.BoatVariant.ACACIA, true),
|
||||
BIRCH_BOAT("birch", Boat.class, MobCompat.BoatVariant.BIRCH, true),
|
||||
DARK_OAK_BOAT("darkoak", Boat.class, MobCompat.BoatVariant.DARKOAK, true),
|
||||
GENERIC_BOAT("generic", Boat.class, MobCompat.BoatVariant.GENERIC, true),
|
||||
JUNGLE_BOAT("jungle", Boat.class, MobCompat.BoatVariant.JUNGLE, true),
|
||||
REDWOOD_BOAT("redwood", Boat.class, MobCompat.BoatVariant.REDWOOD, true),
|
||||
MANGROVE_BOAT("mangrove", Boat.class, MobCompat.BoatVariant.MANGROVE, true),
|
||||
OAK_BOAT("oak", Boat.class, MobCompat.BoatVariant.OAK, true),
|
||||
SPRUCE_BOAT("spruce", Boat.class, MobCompat.BoatVariant.SPRUCE, true),
|
||||
SADDLE_CAMEL("saddle", MobCompat.CAMEL, Data.CAMELSADDLE, true),
|
||||
PALE_WOLF("pale", EntityType.WOLF, "wolf:PALE", true),
|
||||
SPOTTED_WOLF("spotted", EntityType.WOLF, "wolf:PALE", true),
|
||||
@ -391,6 +401,8 @@ public enum MobData {
|
||||
((Goat) spawned).setScreaming(true);
|
||||
} else if (this.value.equals(Data.CAMELSADDLE)) {
|
||||
MobCompat.setCamelSaddle(spawned, target);
|
||||
} else if (this.value instanceof MobCompat.BoatVariant) {
|
||||
MobCompat.setBoatVariant(spawned, (MobCompat.BoatVariant) this.value);
|
||||
} else if (this.value instanceof String) {
|
||||
final String[] split = ((String) this.value).split(":");
|
||||
switch (split[0]) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user