diff --git a/Essentials/src/main/java/com/earth2me/essentials/Mob.java b/Essentials/src/main/java/com/earth2me/essentials/Mob.java index 11f51b41d..9a5cd48c2 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/Mob.java +++ b/Essentials/src/main/java/com/earth2me/essentials/Mob.java @@ -109,6 +109,8 @@ public enum Mob { TADPOLE("Tadpole", Enemies.FRIENDLY, "TADPOLE"), WARDEN("Warden", Enemies.ENEMY, "WARDEN"), CHEST_BOAT("ChestBoat", Enemies.NEUTRAL, "CHEST_BOAT"), + CAMEL("Camel", Enemies.FRIENDLY, "CAMEL"), + SNIFFER("Sniffer", Enemies.FRIENDLY, "SNIFFER"), ; private static final Map hashMap = new HashMap<>(); diff --git a/Essentials/src/main/java/com/earth2me/essentials/MobCompat.java b/Essentials/src/main/java/com/earth2me/essentials/MobCompat.java index 1c93301f2..e4992f547 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/MobCompat.java +++ b/Essentials/src/main/java/com/earth2me/essentials/MobCompat.java @@ -3,9 +3,11 @@ 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.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; import org.bukkit.entity.Fox; @@ -15,8 +17,10 @@ import org.bukkit.entity.MushroomCow; import org.bukkit.entity.Ocelot; import org.bukkit.entity.Panda; import org.bukkit.entity.Parrot; +import org.bukkit.entity.Player; import org.bukkit.entity.TropicalFish; import org.bukkit.entity.Villager; +import org.bukkit.inventory.ItemStack; import java.lang.reflect.Method; @@ -41,6 +45,7 @@ public final class MobCompat { public static final EntityType AXOLOTL = getEntityType("AXOLOTL"); public static final EntityType GOAT = getEntityType("GOAT"); public static final EntityType FROG = getEntityType("FROG"); + public static final EntityType CAMEL = getEntityType("CAMEL"); // Constants for mobs that have changed since earlier versions public static final EntityType CAT = getEntityType("CAT", "OCELOT"); @@ -195,6 +200,19 @@ public final class MobCompat { } } + public static void setCamelSaddle(final Entity entity, final Player target) { + if (VersionUtil.getServerBukkitVersion().isLowerThan(VersionUtil.v1_20_1_R01)) { + return; + } + + if (entity instanceof Camel) { + final Camel camel = (Camel) entity; + camel.setTamed(true); + camel.setOwner(target); + camel.getInventory().setSaddle(new ItemStack(Material.SADDLE, 1)); + } + } + public enum CatType { // These are (loosely) Mojang names for the cats SIAMESE("SIAMESE", "SIAMESE_CAT"), diff --git a/Essentials/src/main/java/com/earth2me/essentials/MobData.java b/Essentials/src/main/java/com/earth2me/essentials/MobData.java index 99a889efc..ec9608ba4 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/MobData.java +++ b/Essentials/src/main/java/com/earth2me/essentials/MobData.java @@ -209,6 +209,7 @@ public enum MobData { 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), ; final private String nickname; @@ -387,6 +388,8 @@ public enum MobData { } } else if (this.value.equals(Data.GOAT_SCREAMING)) { ((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) { @@ -446,5 +449,6 @@ public enum MobData { FISH_BODY_COLOR, FISH_PATTERN_COLOR, GOAT_SCREAMING, + CAMELSADDLE, } } diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandeditsign.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandeditsign.java index b4db03c49..e7159d279 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandeditsign.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandeditsign.java @@ -3,14 +3,22 @@ package com.earth2me.essentials.commands; import com.earth2me.essentials.User; import com.earth2me.essentials.utils.FormatUtil; import com.earth2me.essentials.utils.NumberUtil; +import com.earth2me.essentials.utils.VersionUtil; import com.google.common.collect.Lists; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Server; import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; import org.bukkit.block.Sign; +import org.bukkit.block.data.BlockData; +import org.bukkit.block.data.type.HangingSign; +import org.bukkit.block.data.type.WallHangingSign; +import org.bukkit.block.data.type.WallSign; +import org.bukkit.block.sign.Side; import org.bukkit.entity.Player; import org.bukkit.event.block.SignChangeEvent; +import org.bukkit.util.Vector; import java.util.Collections; import java.util.List; @@ -32,7 +40,7 @@ public class Commandeditsign extends EssentialsCommand { if (!(target.getState() instanceof Sign)) { throw new Exception(tl("editsignCommandTarget")); } - final Sign sign = (Sign) target.getState(); + final ModifiableSign sign = wrapSign((Sign) target.getState(), user); try { if (args[0].equalsIgnoreCase("set") && args.length > 2) { final String[] existingLines = sign.getLines(); @@ -108,8 +116,15 @@ public class Commandeditsign extends EssentialsCommand { } } - private boolean callSignEvent(final Sign sign, final Player player, final String[] lines) { - final SignChangeEvent event = new SignChangeEvent(sign.getBlock(), player, lines); + private boolean callSignEvent(final ModifiableSign sign, final Player player, final String[] lines) { + final SignChangeEvent event; + if (VersionUtil.getServerBukkitVersion().isHigherThanOrEqualTo(VersionUtil.v1_20_1_R01)) { + event = new SignChangeEvent(sign.getBlock(), player, lines, sign.isFront() ? Side.FRONT : Side.BACK); + } else { + //noinspection deprecation + event = new SignChangeEvent(sign.getBlock(), player, lines); + } + Bukkit.getServer().getPluginManager().callEvent(event); if (event.isCancelled()) { if (ess.getSettings().isDebug()) { @@ -135,7 +150,7 @@ public class Commandeditsign extends EssentialsCommand { final int line = Integer.parseInt(args[1]); final Block target = user.getTargetBlock(5); if (target.getState() instanceof Sign && line <= 4) { - final Sign sign = (Sign) target.getState(); + final ModifiableSign sign = wrapSign((Sign) target.getState(), user); return Lists.newArrayList(FormatUtil.unformatString(user, "essentials.editsign", sign.getLine(line - 1))); } return Collections.emptyList(); @@ -143,4 +158,93 @@ public class Commandeditsign extends EssentialsCommand { return Collections.emptyList(); } } + + private ModifiableSign wrapSign(final Sign sign, final User user) { + if (VersionUtil.getServerBukkitVersion().isHigherThanOrEqualTo(VersionUtil.v1_20_1_R01)) { + final Vector eyeLocLessSign = user.getBase().getEyeLocation().toVector().subtract(sign.getLocation().add(.5, .5, .5).toVector()); + final BlockData signBlockData = sign.getBlockData(); + + final BlockFace signDirection; + if (signBlockData instanceof org.bukkit.block.data.type.Sign) { + signDirection = ((org.bukkit.block.data.type.Sign) signBlockData).getRotation(); + } else if (signBlockData instanceof WallSign) { + signDirection = ((WallSign) signBlockData).getFacing(); + } else if (signBlockData instanceof HangingSign) { + signDirection = ((HangingSign) signBlockData).getRotation(); + } else if (signBlockData instanceof WallHangingSign) { + signDirection = ((WallHangingSign) signBlockData).getFacing(); + } else { + throw new IllegalStateException("Unknown block data for sign: " + signBlockData.getClass()); + } + + final Side side = eyeLocLessSign.dot(signDirection.getDirection()) > 0 ? Side.FRONT : Side.BACK; + + return new ModifiableSign(sign) { + @Override + String[] getLines() { + return sign.getSide(side).getLines(); + } + + @Override + String getLine(int line) { + return sign.getSide(side).getLine(line); + } + + @Override + void setLine(int line, String text) { + sign.getSide(side).setLine(line, text); + } + + @Override + boolean isFront() { + return side == Side.FRONT; + } + }; + } + return new ModifiableSign(sign) { + @Override + String[] getLines() { + return sign.getLines(); + } + + @Override + String getLine(int line) { + return sign.getLine(line); + } + + @Override + void setLine(int line, String text) { + sign.setLine(line, text); + } + + @Override + boolean isFront() { + return true; + } + }; + } + + private abstract static class ModifiableSign { + protected final Sign sign; + + protected ModifiableSign(final Sign sign) { + this.sign = sign; + } + + abstract String getLine(int line); + + abstract String[] getLines(); + + abstract void setLine(int line, String text); + + abstract boolean isFront(); + + Block getBlock() { + return sign.getBlock(); + } + + void update() { + sign.update(); + } + } } diff --git a/Essentials/src/main/java/com/earth2me/essentials/craftbukkit/BanLookup.java b/Essentials/src/main/java/com/earth2me/essentials/craftbukkit/BanLookup.java index 65cc2a401..dcc40d97b 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/craftbukkit/BanLookup.java +++ b/Essentials/src/main/java/com/earth2me/essentials/craftbukkit/BanLookup.java @@ -21,8 +21,9 @@ public final class BanLookup { } public static BanEntry getBanEntry(final IEssentials ess, final String name) { - final Set benteries = ess.getServer().getBanList(BanList.Type.NAME).getBanEntries(); - for (final BanEntry banEnt : benteries) { + final Set benteries = ess.getServer().getBanList(BanList.Type.NAME).getBanEntries(); + for (final Object ob : benteries) { + final BanEntry banEnt = (BanEntry) ob; if (banEnt.getTarget().equals(name)) { return banEnt; } diff --git a/Essentials/src/main/java/com/earth2me/essentials/signs/EssentialsSign.java b/Essentials/src/main/java/com/earth2me/essentials/signs/EssentialsSign.java index cb0aaaf96..c0ba2cf76 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/signs/EssentialsSign.java +++ b/Essentials/src/main/java/com/earth2me/essentials/signs/EssentialsSign.java @@ -8,6 +8,7 @@ import com.earth2me.essentials.User; import com.earth2me.essentials.utils.FormatUtil; import com.earth2me.essentials.utils.MaterialUtil; import com.earth2me.essentials.utils.NumberUtil; +import com.earth2me.essentials.utils.VersionUtil; import net.ess3.api.IEssentials; import net.ess3.api.MaxMoneyException; import net.ess3.api.events.SignBreakEvent; @@ -18,7 +19,7 @@ import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.block.Sign; -import org.bukkit.block.data.type.WallSign; +import org.bukkit.block.data.Directional; import org.bukkit.entity.Player; import org.bukkit.event.block.SignChangeEvent; import org.bukkit.inventory.ItemStack; @@ -48,7 +49,7 @@ public class EssentialsSign { final BlockFace[] directions = new BlockFace[] {BlockFace.NORTH, BlockFace.EAST, BlockFace.SOUTH, BlockFace.WEST}; for (final BlockFace blockFace : directions) { final Block signBlock = block.getRelative(blockFace); - if (MaterialUtil.isWallSign(signBlock.getType())) { + if (MaterialUtil.isWallSign(signBlock.getType()) || MaterialUtil.isWallHangingSign(signBlock.getType())) { try { if (getWallSignFacing(signBlock) == blockFace && isValidSign(new BlockSign(signBlock))) { return true; @@ -84,13 +85,14 @@ public class EssentialsSign { } private static BlockFace getWallSignFacing(final Block block) { - try { - final WallSign signData = (WallSign) block.getState().getBlockData(); - return signData.getFacing(); - } catch (final NoClassDefFoundError | NoSuchMethodError e) { + if (VersionUtil.PRE_FLATTENING) { + //noinspection deprecation final org.bukkit.material.Sign signMat = (org.bukkit.material.Sign) block.getState().getData(); return signMat.getFacing(); } + + final Directional signData = (Directional) block.getState().getBlockData(); + return signData.getFacing(); } protected final boolean onSignCreate(final SignChangeEvent event, final IEssentials ess) { diff --git a/Essentials/src/main/java/com/earth2me/essentials/utils/MaterialUtil.java b/Essentials/src/main/java/com/earth2me/essentials/utils/MaterialUtil.java index 19140876c..2c9023d5d 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/utils/MaterialUtil.java +++ b/Essentials/src/main/java/com/earth2me/essentials/utils/MaterialUtil.java @@ -27,6 +27,8 @@ public final class MaterialUtil { private static final Set POTIONS; private static final Set SIGN_POSTS; private static final Set WALL_SIGNS; + private static final Set HANGING_SIGNS; + private static final Set HANGING_WALL_SIGNS; private static final Set HELMETS; private static final Set CHESTPLATES; @@ -71,7 +73,7 @@ public final class MaterialUtil { MOB_HEADS = EnumUtil.getAllMatching(Material.class, "SKELETON_SKULL", "SKELETON_WALL_SKULL", "WITHER_SKELETON_SKULL", "WITHER_SKELETON_WALL_SKULL", "CREEPER_HEAD", "CREEPER_WALL_HEAD", "ZOMBIE_HEAD", "ZOMBIE_WALL_HEAD", "DRAGON_HEAD" - , "DRAGON_WALL_HEAD"); + , "DRAGON_WALL_HEAD", "PIGLIN_HEAD", "PIGLIN_WALL_HEAD"); PLAYER_HEADS = EnumUtil.getAllMatching(Material.class, "PLAYER_HEAD", "PLAYER_WALL_HEAD"); @@ -83,14 +85,30 @@ public final class MaterialUtil { "DARK_OAK_SIGN", "JUNGLE_SIGN", "OAK_SIGN", "SPRUCE_SIGN", "CRIMSON_SIGN", "WARPED_SIGN", - "MANGROVE_SIGN"); + "MANGROVE_SIGN", "CHERRY_SIGN", + "BAMBOO_SIGN"); WALL_SIGNS = EnumUtil.getAllMatching(Material.class, "WALL_SIGN", "ACACIA_WALL_SIGN", "BIRCH_WALL_SIGN", "DARK_OAK_WALL_SIGN", "JUNGLE_WALL_SIGN", "OAK_WALL_SIGN", "SPRUCE_WALL_SIGN", "CRIMSON_WALL_SIGN", "WARPED_WALL_SIGN", - "MANGROVE_WALL_SIGN"); + "MANGROVE_WALL_SIGN", "CHERRY_WALL_SIGN", + "BAMBOO_WALL_SIGN"); + + HANGING_SIGNS = EnumUtil.getAllMatching(Material.class, "ACACIA_HANGING_SIGN", "BIRCH_HANGING_SIGN", + "DARK_OAK_HANGING_SIGN", "JUNGLE_HANGING_SIGN", + "OAK_HANGING_SIGN", "SPRUCE_HANGING_SIGN", + "CRIMSON_HANGING_SIGN", "WARPED_HANGING_SIGN", + "MANGROVE_HANGING_SIGN", "CHERRY_HANGING_SIGN", + "BAMBOO_HANGING_SIGN"); + + HANGING_WALL_SIGNS = EnumUtil.getAllMatching(Material.class, "ACACIA_WALL_HANGING_SIGN", "BIRCH_WALL_HANGING_SIGN", + "DARK_OAK_WALL_HANGING_SIGN", "JUNGLE_WALL_HANGING_SIGN", + "OAK_WALL_HANGING_SIGN", "SPRUCE_WALL_HANGING_SIGN", + "CRIMSON_WALL_HANGING_SIGN", "WARPED_WALL_HANGING_SIGN", + "MANGROVE_WALL_HANGING_SIGN", "CHERRY_WALL_HANGING_SIGN", + "BAMBOO_WALL_HANGING_SIGN"); } private MaterialUtil() { @@ -152,12 +170,20 @@ public final class MaterialUtil { return WALL_SIGNS.contains(material); } + public static boolean isHangingSign(final Material material) { + return HANGING_SIGNS.contains(material); + } + + public static boolean isWallHangingSign(final Material material) { + return HANGING_WALL_SIGNS.contains(material); + } + public static boolean isEditableBook(final Material material) { return EDITABLE_BOOKS.contains(material); } public static boolean isSign(final Material material) { - return isSignPost(material) || isWallSign(material); + return isSignPost(material) || isWallSign(material) || isHangingSign(material) || isWallHangingSign(material); } public static boolean isSkull(final Material material) { diff --git a/Essentials/src/main/java/com/earth2me/essentials/utils/VersionUtil.java b/Essentials/src/main/java/com/earth2me/essentials/utils/VersionUtil.java index e61786346..b9299271d 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/utils/VersionUtil.java +++ b/Essentials/src/main/java/com/earth2me/essentials/utils/VersionUtil.java @@ -36,10 +36,10 @@ public final class VersionUtil { public static final BukkitVersion v1_17_1_R01 = BukkitVersion.fromString("1.17.1-R0.1-SNAPSHOT"); public static final BukkitVersion v1_18_2_R01 = BukkitVersion.fromString("1.18.2-R0.1-SNAPSHOT"); public static final BukkitVersion v1_19_R01 = BukkitVersion.fromString("1.19-R0.1-SNAPSHOT"); - public static final BukkitVersion v1_19_2_R01 = BukkitVersion.fromString("1.19.2-R0.1-SNAPSHOT"); public static final BukkitVersion v1_19_4_R01 = BukkitVersion.fromString("1.19.4-R0.1-SNAPSHOT"); + public static final BukkitVersion v1_20_1_R01 = BukkitVersion.fromString("1.20.1-R0.1-SNAPSHOT"); - private static final Set 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_1_R01, v1_18_2_R01, v1_19_4_R01); + private static final Set 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_1_R01, v1_18_2_R01, v1_19_4_R01, v1_20_1_R01); public static final boolean PRE_FLATTENING = VersionUtil.getServerBukkitVersion().isLowerThan(VersionUtil.v1_13_0_R01); diff --git a/README.md b/README.md index cbaadb5f7..2fd9c63fc 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ however, have some new requirements: * **EssentialsX requires CraftBukkit, Spigot or Paper to run.** Other server software may work, but these are not tested by the team and we may not be able to help with any issues that occur. * **EssentialsX currently 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, 1.17.1, 1.18.2, and 1.19.4.** + 1.16.5, 1.17.1, 1.18.2, 1.19.4, and 1.20.1.** * **EssentialsX currently requires Java 8 or higher.** We recommend using the latest Java version supported by your server software. * **EssentialsX requires [Vault](http://dev.bukkit.org/bukkit-plugins/vault/) to enable using chat prefix/suffixes and diff --git a/build-logic/src/main/kotlin/constants.kt b/build-logic/src/main/kotlin/constants.kt index bdc5d7441..f48deee61 100644 --- a/build-logic/src/main/kotlin/constants.kt +++ b/build-logic/src/main/kotlin/constants.kt @@ -1 +1 @@ -const val RUN_PAPER_MINECRAFT_VERSION = "1.19.4" +const val RUN_PAPER_MINECRAFT_VERSION = "1.20.1" diff --git a/build-logic/src/main/kotlin/essentials.base-conventions.gradle.kts b/build-logic/src/main/kotlin/essentials.base-conventions.gradle.kts index e7596e9c9..c0d665fcb 100644 --- a/build-logic/src/main/kotlin/essentials.base-conventions.gradle.kts +++ b/build-logic/src/main/kotlin/essentials.base-conventions.gradle.kts @@ -10,7 +10,7 @@ plugins { val baseExtension = extensions.create("essentials", project) val checkstyleVersion = "8.36.2" -val spigotVersion = "1.19.4-R0.1-SNAPSHOT" +val spigotVersion = "1.20.1-R0.1-SNAPSHOT" val junit5Version = "5.7.0" val mockitoVersion = "3.2.0"