diff --git a/paper/src/main/java/com/denizenscript/denizen/paper/properties/PaperPlayerExtensions.java b/paper/src/main/java/com/denizenscript/denizen/paper/properties/PaperPlayerExtensions.java index be56152901..d0d3806724 100644 --- a/paper/src/main/java/com/denizenscript/denizen/paper/properties/PaperPlayerExtensions.java +++ b/paper/src/main/java/com/denizenscript/denizen/paper/properties/PaperPlayerExtensions.java @@ -79,6 +79,19 @@ public static void register() { return map; }); + // <--[tag] + // @attribute + // @returns ElementTag(Number) + // @mechanism PlayerTag.view_distance + // @group paper + // @Plugin Paper + // @description + // Returns this player's view distance, or the view distance of the world they're in if unset. + // --> + PlayerTag.registerOnlineOnlyTag(ElementTag.class, "view_distance", (attribute, object) -> { + return new ElementTag(object.getPlayerEntity().getViewDistance()); + }); + // <--[mechanism] // @object PlayerTag // @name affects_monster_spawning @@ -136,6 +149,32 @@ public static void register() { } }); + // <--[mechanism] + // @object PlayerTag + // @name view_distance + // @input ElementTag(Number) + // @Plugin Paper + // @group paper + // @description + // Sets this player's view distance. Input must be a number between 2 and 32. + // This will be reset when a player rejoins. Provide no input to unset. + // @tags + // + // --> + PlayerTag.registerOnlineOnlyMechanism("view_distance", (object, mechanism) -> { + if (!mechanism.hasValue()) { + object.getPlayerEntity().setViewDistance(-1); + } + else if (mechanism.requireInteger()) { + int distance = mechanism.getValue().asInt(); + if (distance < 2 || distance > 32) { + mechanism.echoError("Invalid view distance '" + distance + "': must be between 2 and 32."); + return; + } + object.getPlayerEntity().setViewDistance(distance); + } + }); + if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_19)) { // <--[tag]