diff --git a/plugin/src/main/java/com/denizenscript/denizen/objects/LocationTag.java b/plugin/src/main/java/com/denizenscript/denizen/objects/LocationTag.java index ecfaa92340..c2b4a01c01 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/objects/LocationTag.java +++ b/plugin/src/main/java/com/denizenscript/denizen/objects/LocationTag.java @@ -3681,13 +3681,30 @@ else if (PolygonTag.matches(attribute.getParam())) { // @returns ElementTag(Number) // @mechanism LocationTag.lectern_page // @group world + // @deprecated Use 'LocationTag.page' // @description - // Returns the current page on display in the book on this Lectern block. + // Deprecated in favor of <@link tag LocationTag.page>. // --> tagProcessor.registerTag(ElementTag.class, "lectern_page", (attribute, object) -> { + BukkitImplDeprecations.lecternPage.warn(attribute.context); BlockState state = object.getBlockStateForTag(attribute); - if (state instanceof Lectern) { - return new ElementTag(((Lectern) state).getPage()); + if (state instanceof Lectern lectern) { + return new ElementTag(lectern.getPage()); + } + return null; + }); + + // <--[tag] + // @attribute + // @returns ElementTag(Number) + // @mechanism LocationTag.page + // @group world + // @description + // Returns the current page on display in the book on this Lectern block. + // --> + tagProcessor.registerTag(ElementTag.class, "page", (attribute, object) -> { + if (object.getBlockState() instanceof Lectern lectern) { + return new ElementTag(lectern.getPage() + 1); } return null; }); @@ -4524,6 +4541,28 @@ else if (mechanism.requireObject(EntityTag.class)) { chiseledBookshelf.setLastInteractedSlot(input.asInt() - 1); } }); + + // <--[mechanism] + // @object LocationTag + // @name page + // @input ElementTag(Number) + // @description + // Sets the page currently displayed on the book in a lectern block. + // @tags + // + // --> + tagProcessor.registerMechanism("page", false, ElementTag.class, (object, mechanism, input) -> { + if (!mechanism.requireInteger()) { + return; + } + if (object.getBlockState() instanceof Lectern lectern) { + lectern.setPage(input.asInt() - 1); + lectern.update(); + } + else { + mechanism.echoError("The 'LocationTag.page' mechanism can only be called on a lectern block."); + } + }); } public static final ObjectTagProcessor tagProcessor = new ObjectTagProcessor<>(); @@ -5123,15 +5162,17 @@ else if (state instanceof Dropper) { // @object LocationTag // @name lectern_page // @input ElementTag(Number) + // @deprecated Use LocationTag.page // @description - // Changes the page currently displayed on the book in a lectern block. + // Deprecated in favor of <@link tag LocationTag.page>. // @tags // // --> if (mechanism.matches("lectern_page") && mechanism.requireInteger()) { + BukkitImplDeprecations.lecternPage.warn(mechanism.context); BlockState state = getBlockState(); - if (state instanceof Lectern) { - ((Lectern) state).setPage(mechanism.getValue().asInt()); + if (state instanceof Lectern lectern) { + lectern.setPage(mechanism.getValue().asInt()); state.update(); } else { diff --git a/plugin/src/main/java/com/denizenscript/denizen/utilities/BukkitImplDeprecations.java b/plugin/src/main/java/com/denizenscript/denizen/utilities/BukkitImplDeprecations.java index a66e5e9d4d..ec94b3bffe 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/utilities/BukkitImplDeprecations.java +++ b/plugin/src/main/java/com/denizenscript/denizen/utilities/BukkitImplDeprecations.java @@ -324,6 +324,9 @@ public class BukkitImplDeprecations { // Added 2023/11/16, deprecate officially by 2027 public static Warning takeExperience = new FutureWarning("takeExperience", "Using the 'take' command to take experience is deprecated in favor of the 'experience' command."); + // Added 2024/02/19, deprecate officially by 2027. + public static Warning lecternPage = new FutureWarning("lecternPage", "'LocationTag.lectern_page' is deprecated in favor of 'LocationTag.page'."); + // ==================== PAST deprecations of things that are already gone but still have a warning left behind ==================== // Removed upstream 2023/10/29 without warning.