diff --git a/api/src/main/java/com/lunarclient/apollo/ApolloPlatform.java b/api/src/main/java/com/lunarclient/apollo/ApolloPlatform.java index 4cf1e2dd..a7820b41 100644 --- a/api/src/main/java/com/lunarclient/apollo/ApolloPlatform.java +++ b/api/src/main/java/com/lunarclient/apollo/ApolloPlatform.java @@ -76,6 +76,14 @@ public interface ApolloPlatform { */ ApolloStats getStats(); + /** + * Returns the platform plugin class. + * + * @return the platform plugin class + * @since 1.0.9 + */ + Object getPlugin(); + /** * Represents the kind of server a platform is. * diff --git a/api/src/main/java/com/lunarclient/apollo/common/icon/AdvancedResourceLocationIcon.java b/api/src/main/java/com/lunarclient/apollo/common/icon/AdvancedResourceLocationIcon.java index de8113f3..f7141081 100644 --- a/api/src/main/java/com/lunarclient/apollo/common/icon/AdvancedResourceLocationIcon.java +++ b/api/src/main/java/com/lunarclient/apollo/common/icon/AdvancedResourceLocationIcon.java @@ -25,6 +25,7 @@ import lombok.Builder; import lombok.Getter; +import org.jetbrains.annotations.Range; /** * Represents an advanced resource location icon. @@ -51,22 +52,24 @@ public final class AdvancedResourceLocationIcon extends Icon { /** * Returns the icon width {@link Float}. * - *

Size of the image width (in pixels).

+ *

Size of the image width (in pixels). Must be equal to or greater + * than 0.

* * @return the icon width * @since 1.0.0 */ - float width; + @Range(from = 0, to = Integer.MAX_VALUE) float width; /** * Returns the icon height {@link Float}. * - *

Size of the image height (in pixels).

+ *

Size of the image height (in pixels). Must be equal to or greater + * than 0.

* * @return the icon height * @since 1.0.0 */ - float height; + @Range(from = 0, to = Integer.MAX_VALUE) float height; /** * Returns the icon min u {@link Float}. @@ -76,7 +79,7 @@ public final class AdvancedResourceLocationIcon extends Icon { * @return the icon min u * @since 1.0.0 */ - float minU; + @Range(from = 0, to = 1) float minU; /** * Returns the icon max u {@link Float}. @@ -86,7 +89,7 @@ public final class AdvancedResourceLocationIcon extends Icon { * @return the icon max u * @since 1.0.0 */ - float maxU; + @Range(from = 0, to = 1) float maxU; /** * Returns the icon min v {@link Float}. @@ -96,7 +99,7 @@ public final class AdvancedResourceLocationIcon extends Icon { * @return the icon min v * @since 1.0.0 */ - float minV; + @Range(from = 0, to = 1) float minV; /** * Returns the icon max v {@link Float}. @@ -106,6 +109,6 @@ public final class AdvancedResourceLocationIcon extends Icon { * @return the icon max v * @since 1.0.0 */ - float maxV; + @Range(from = 0, to = 1) float maxV; } diff --git a/api/src/main/java/com/lunarclient/apollo/common/icon/SimpleResourceLocationIcon.java b/api/src/main/java/com/lunarclient/apollo/common/icon/SimpleResourceLocationIcon.java index 29834050..88ef87b3 100644 --- a/api/src/main/java/com/lunarclient/apollo/common/icon/SimpleResourceLocationIcon.java +++ b/api/src/main/java/com/lunarclient/apollo/common/icon/SimpleResourceLocationIcon.java @@ -25,6 +25,7 @@ import lombok.Builder; import lombok.Getter; +import org.jetbrains.annotations.Range; /** * Represents a simple resource location icon. @@ -48,11 +49,12 @@ public final class SimpleResourceLocationIcon extends Icon { /** * Returns the icon {@link Integer} size. * - *

Size of the image height and width (in pixels).

+ *

Size of the image height and width (in pixels). Must be equal to or + * greater than 0.

* * @return the icon size * @since 1.0.0 */ - int size; + @Range(from = 0, to = Integer.MAX_VALUE) int size; } diff --git a/api/src/main/java/com/lunarclient/apollo/mods/Mods.java b/api/src/main/java/com/lunarclient/apollo/mods/Mods.java index 2ca4bd0a..9435c2f9 100644 --- a/api/src/main/java/com/lunarclient/apollo/mods/Mods.java +++ b/api/src/main/java/com/lunarclient/apollo/mods/Mods.java @@ -84,6 +84,7 @@ import com.lunarclient.apollo.mods.impl.ModServerAddress; import com.lunarclient.apollo.mods.impl.ModShinyPots; import com.lunarclient.apollo.mods.impl.ModShulkerPreview; +import com.lunarclient.apollo.mods.impl.ModSkyblock; import com.lunarclient.apollo.mods.impl.ModSnaplook; import com.lunarclient.apollo.mods.impl.ModSoundChanger; import com.lunarclient.apollo.mods.impl.ModStopwatch; @@ -190,7 +191,8 @@ public final class Mods { ModWaila.class, ModNeu.class, ModHurtCam.class, - ModDamageTint.class + ModDamageTint.class, + ModSkyblock.class ); private Mods() { diff --git a/api/src/main/java/com/lunarclient/apollo/mods/impl/ModBlockOutline.java b/api/src/main/java/com/lunarclient/apollo/mods/impl/ModBlockOutline.java index 051ee745..ad8c8dea 100644 --- a/api/src/main/java/com/lunarclient/apollo/mods/impl/ModBlockOutline.java +++ b/api/src/main/java/com/lunarclient/apollo/mods/impl/ModBlockOutline.java @@ -50,8 +50,8 @@ public final class ModBlockOutline { * * @since 1.0.0 */ - public static final SimpleOption BLOCK_OUTLINE_COLOR = SimpleOption.builder() - .node("block-outline", "block-outline-color").type(TypeToken.get(Color.class)) + public static final SimpleOption BLOCK_OUTLINE = SimpleOption.builder() + .node("block-outline", "block-outline").type(TypeToken.get(Boolean.class)) .notifyClient() .build(); @@ -60,19 +60,75 @@ public final class ModBlockOutline { * * @since 1.0.0 */ - public static final SimpleOption BLOCK_OVERLAY_COLOR = SimpleOption.builder() - .node("block-outline", "block-overlay-color").type(TypeToken.get(Color.class)) + public static final NumberOption BLOCK_OUTLINE_WIDTH = NumberOption.number() + .node("block-outline", "block-outline-width").type(TypeToken.get(Float.class)) + .min(1.0F).max(10.0F) .notifyClient() .build(); /** - * No documentation available. + * Primary block outline color. * * @since 1.0.0 */ - public static final NumberOption BLOCK_OUTLINE_WIDTH = NumberOption.number() - .node("block-outline", "block-outline-width").type(TypeToken.get(Float.class)) - .min(1.0F).max(10.0F) + public static final SimpleOption BLOCK_OUTLINE_COLOR = SimpleOption.builder() + .comment("Primary block outline color") + .node("block-outline", "block-outline-color").type(TypeToken.get(Color.class)) + .notifyClient() + .build(); + + /** + * Secondary block outline color. + * + * @since 1.0.9 + */ + public static final SimpleOption BLOCK_OUTLINE_COLOR_END = SimpleOption.builder() + .comment("Secondary block outline color") + .node("block-outline", "block-outline-color-end").type(TypeToken.get(Color.class)) + .notifyClient() + .build(); + + /** + * If the transparency should also blend between both outline colors. + * + * @since 1.0.9 + */ + public static final SimpleOption BLOCK_OUTLINE_INTERPOLATE_ALPHA = SimpleOption.builder() + .comment("If the transparency should also blend between both outline colors") + .node("block-outline", "block-outline-interpolate-alpha").type(TypeToken.get(Boolean.class)) + .notifyClient() + .build(); + + /** + * If the exact block bounding box should be used, this comes at a slight performance cost. + * + * @since 1.0.9 + */ + public static final SimpleOption BLOCK_OUTLINE_ACCURATE = SimpleOption.builder() + .comment("If the exact block bounding box should be used, this comes at a slight performance cost") + .node("block-outline", "block-outline-accurate").type(TypeToken.get(Boolean.class)) + .notifyClient() + .build(); + + /** + * If the outline colors should travel through the block. + * + * @since 1.0.9 + */ + public static final SimpleOption BLOCK_OUTLINE_TRAVERSAL = SimpleOption.builder() + .comment("If the outline colors should travel through the block") + .node("block-outline", "block-outline-traversal").type(TypeToken.get(Boolean.class)) + .notifyClient() + .build(); + + /** + * No documentation available. + * + * @since 1.0.9 + */ + public static final NumberOption BLOCK_OUTLINE_TRAVERSAL_SPEED = NumberOption.number() + .node("block-outline", "block-outline-traversal-speed").type(TypeToken.get(Float.class)) + .min(0.15F).max(5.0F) .notifyClient() .build(); @@ -87,12 +143,112 @@ public final class ModBlockOutline { .build(); /** - * No documentation available. + * Primary block overlay color. * * @since 1.0.0 */ - public static final SimpleOption BLOCK_OUTLINE = SimpleOption.builder() - .node("block-outline", "block-outline").type(TypeToken.get(Boolean.class)) + public static final SimpleOption BLOCK_OVERLAY_COLOR = SimpleOption.builder() + .comment("Primary block overlay color") + .node("block-outline", "block-overlay-color").type(TypeToken.get(Color.class)) + .notifyClient() + .build(); + + /** + * Secondary block overlay color. + * + * @since 1.0.9 + */ + public static final SimpleOption BLOCK_OVERLAY_COLOR_END = SimpleOption.builder() + .comment("Secondary block overlay color") + .node("block-outline", "block-overlay-color-end").type(TypeToken.get(Color.class)) + .notifyClient() + .build(); + + /** + * If the transparency should also blend between both overlay colors. + * + * @since 1.0.9 + */ + public static final SimpleOption BLOCK_OVERLAY_INTERPOLATE_ALPHA = SimpleOption.builder() + .comment("If the transparency should also blend between both overlay colors") + .node("block-outline", "block-overlay-interpolate-alpha").type(TypeToken.get(Boolean.class)) + .notifyClient() + .build(); + + /** + * If the exact block bounding box should be used, this comes at a slight performance cost. + * + * @since 1.0.9 + */ + public static final SimpleOption BLOCK_OVERLAY_ACCURATE = SimpleOption.builder() + .comment("If the exact block bounding box should be used, this comes at a slight performance cost") + .node("block-outline", "block-overlay-accurate").type(TypeToken.get(Boolean.class)) + .notifyClient() + .build(); + + /** + * If the overlay colors should travel through the block. + * + * @since 1.0.9 + */ + public static final SimpleOption BLOCK_OVERLAY_TRAVERSAL = SimpleOption.builder() + .comment("If the overlay colors should travel through the block") + .node("block-outline", "block-overlay-traversal").type(TypeToken.get(Boolean.class)) + .notifyClient() + .build(); + + /** + * No documentation available. + * + * @since 1.0.9 + */ + public static final NumberOption BLOCK_OVERLAY_TRAVERSAL_SPEED = NumberOption.number() + .node("block-outline", "block-overlay-traversal-speed").type(TypeToken.get(Float.class)) + .min(0.15F).max(5.0F) + .notifyClient() + .build(); + + /** + * If only a single side of the block should have outlines. + * + * @since 1.0.9 + */ + public static final SimpleOption BLOCK_OUTLINE_SIDE = SimpleOption.builder() + .comment("If only a single side of the block should have outlines") + .node("block-outline", "block-outline-side").type(TypeToken.get(Boolean.class)) + .notifyClient() + .build(); + + /** + * If using hide foliage, should outlines still show on foliage. + * + * @since 1.0.9 + */ + public static final SimpleOption BLOCK_OUTLINE_SHOW_HIDDEN_FOLIAGE = SimpleOption.builder() + .comment("If using hide foliage, should outlines still show on foliage") + .node("block-outline", "block-outline-show-hidden-foliage").type(TypeToken.get(Boolean.class)) + .notifyClient() + .build(); + + /** + * If blocks that connect together should share an outline. + * + * @since 1.0.9 + */ + public static final SimpleOption BLOCK_OUTLINE_MULTI_BLOCK = SimpleOption.builder() + .comment("If blocks that connect together should share an outline") + .node("block-outline", "block-outline-multi-block").type(TypeToken.get(Boolean.class)) + .notifyClient() + .build(); + + /** + * If outlines should be visible in spectator mode. + * + * @since 1.0.9 + */ + public static final SimpleOption SHOW_IN_SPECTATOR = SimpleOption.builder() + .comment("If outlines should be visible in spectator mode") + .node("block-outline", "show-in-spectator").type(TypeToken.get(Boolean.class)) .notifyClient() .build(); diff --git a/api/src/main/java/com/lunarclient/apollo/mods/impl/ModClock.java b/api/src/main/java/com/lunarclient/apollo/mods/impl/ModClock.java index a90a1ee7..ad864367 100644 --- a/api/src/main/java/com/lunarclient/apollo/mods/impl/ModClock.java +++ b/api/src/main/java/com/lunarclient/apollo/mods/impl/ModClock.java @@ -56,16 +56,6 @@ public final class ModClock { .notifyClient() .build(); - /** - * No documentation available. - * - * @since 1.0.0 - */ - public static final SimpleOption MILITARY_TIME = SimpleOption.builder() - .node("clock", "military-time").type(TypeToken.get(Boolean.class)) - .notifyClient() - .build(); - /** * No documentation available. * @@ -180,6 +170,16 @@ public final class ModClock { .notifyClient() .build(); + /** + * No documentation available. + * + * @since 1.0.0 + */ + public static final SimpleOption MILITARY_TIME = SimpleOption.builder() + .node("clock", "military-time").type(TypeToken.get(Boolean.class)) + .notifyClient() + .build(); + private ModClock() { } diff --git a/api/src/main/java/com/lunarclient/apollo/mods/impl/ModCps.java b/api/src/main/java/com/lunarclient/apollo/mods/impl/ModCps.java index db7ba2a6..25ac423d 100644 --- a/api/src/main/java/com/lunarclient/apollo/mods/impl/ModCps.java +++ b/api/src/main/java/com/lunarclient/apollo/mods/impl/ModCps.java @@ -56,36 +56,6 @@ public final class ModCps { .notifyClient() .build(); - /** - * No documentation available. - * - * @since 1.0.0 - */ - public static final SimpleOption RIGHT_CLICK = SimpleOption.builder() - .node("cps", "right-click").type(TypeToken.get(Boolean.class)) - .notifyClient() - .build(); - - /** - * No documentation available. - * - * @since 1.0.0 - */ - public static final SimpleOption SHOW_CPSTEXT = SimpleOption.builder() - .node("cps", "show-c-p-s-text").type(TypeToken.get(Boolean.class)) - .notifyClient() - .build(); - - /** - * No documentation available. - * - * @since 1.0.0 - */ - public static final SimpleOption LINE_COLOR = SimpleOption.builder() - .node("cps", "line-color").type(TypeToken.get(Color.class)) - .notifyClient() - .build(); - /** * No documentation available. * @@ -200,6 +170,36 @@ public final class ModCps { .notifyClient() .build(); + /** + * No documentation available. + * + * @since 1.0.0 + */ + public static final SimpleOption RIGHT_CLICK = SimpleOption.builder() + .node("cps", "right-click").type(TypeToken.get(Boolean.class)) + .notifyClient() + .build(); + + /** + * No documentation available. + * + * @since 1.0.0 + */ + public static final SimpleOption SHOW_CPSTEXT = SimpleOption.builder() + .node("cps", "show-c-p-s-text").type(TypeToken.get(Boolean.class)) + .notifyClient() + .build(); + + /** + * No documentation available. + * + * @since 1.0.0 + */ + public static final SimpleOption LINE_COLOR = SimpleOption.builder() + .node("cps", "line-color").type(TypeToken.get(Color.class)) + .notifyClient() + .build(); + private ModCps() { } diff --git a/api/src/main/java/com/lunarclient/apollo/mods/impl/ModDayCounter.java b/api/src/main/java/com/lunarclient/apollo/mods/impl/ModDayCounter.java index ff47befc..2103bffa 100644 --- a/api/src/main/java/com/lunarclient/apollo/mods/impl/ModDayCounter.java +++ b/api/src/main/java/com/lunarclient/apollo/mods/impl/ModDayCounter.java @@ -56,16 +56,6 @@ public final class ModDayCounter { .notifyClient() .build(); - /** - * No documentation available. - * - * @since 1.0.0 - */ - public static final SimpleOption USE_WORLD_TYPE = SimpleOption.builder() - .node("day-counter", "use-world-type").type(TypeToken.get(Boolean.class)) - .notifyClient() - .build(); - /** * No documentation available. * @@ -180,6 +170,16 @@ public final class ModDayCounter { .notifyClient() .build(); + /** + * No documentation available. + * + * @since 1.0.0 + */ + public static final SimpleOption USE_WORLD_TYPE = SimpleOption.builder() + .node("day-counter", "use-world-type").type(TypeToken.get(Boolean.class)) + .notifyClient() + .build(); + private ModDayCounter() { } diff --git a/api/src/main/java/com/lunarclient/apollo/mods/impl/ModMomentum.java b/api/src/main/java/com/lunarclient/apollo/mods/impl/ModMomentum.java index a2cef7eb..7bb08a9c 100644 --- a/api/src/main/java/com/lunarclient/apollo/mods/impl/ModMomentum.java +++ b/api/src/main/java/com/lunarclient/apollo/mods/impl/ModMomentum.java @@ -56,40 +56,6 @@ public final class ModMomentum { .notifyClient() .build(); - /** - * If enabled then Y velocity is not used in the final speed. - * - * @since 1.0.0 - */ - public static final SimpleOption USE_GROUND_SPEED = SimpleOption.builder() - .comment("If enabled then Y velocity is not used in the final speed.") - .node("momentum", "use-ground-speed").type(TypeToken.get(Boolean.class)) - .notifyClient() - .build(); - - /** - * If this is disabled then instant velocity is used. - * - * @since 1.0.0 - */ - public static final SimpleOption USE_AVERAGE_VELOCITY = SimpleOption.builder() - .comment("If this is disabled then instant velocity is used") - .node("momentum", "use-average-velocity").type(TypeToken.get(Boolean.class)) - .notifyClient() - .build(); - - /** - * Determines how many times a second velocity is calculated. Lower values will show a smoother velocity. - * - * @since 1.0.0 - */ - public static final NumberOption AVERAGING_PERIOD = NumberOption.number() - .comment("Determines how many times a second velocity is calculated. Lower values will show a smoother velocity") - .node("momentum", "averaging-period").type(TypeToken.get(Integer.class)) - .min(1).max(50) - .notifyClient() - .build(); - /** * No documentation available. * @@ -204,6 +170,40 @@ public final class ModMomentum { .notifyClient() .build(); + /** + * If enabled then Y velocity is not used in the final speed. + * + * @since 1.0.0 + */ + public static final SimpleOption USE_GROUND_SPEED = SimpleOption.builder() + .comment("If enabled then Y velocity is not used in the final speed.") + .node("momentum", "use-ground-speed").type(TypeToken.get(Boolean.class)) + .notifyClient() + .build(); + + /** + * If this is disabled then instant velocity is used. + * + * @since 1.0.0 + */ + public static final SimpleOption USE_AVERAGE_VELOCITY = SimpleOption.builder() + .comment("If this is disabled then instant velocity is used") + .node("momentum", "use-average-velocity").type(TypeToken.get(Boolean.class)) + .notifyClient() + .build(); + + /** + * Determines how many times a second velocity is calculated. Lower values will show a smoother velocity. + * + * @since 1.0.0 + */ + public static final NumberOption AVERAGING_PERIOD = NumberOption.number() + .comment("Determines how many times a second velocity is calculated. Lower values will show a smoother velocity") + .node("momentum", "averaging-period").type(TypeToken.get(Integer.class)) + .min(1).max(50) + .notifyClient() + .build(); + private ModMomentum() { } diff --git a/api/src/main/java/com/lunarclient/apollo/mods/impl/ModPackDisplay.java b/api/src/main/java/com/lunarclient/apollo/mods/impl/ModPackDisplay.java index 68668cd3..a968bc7f 100644 --- a/api/src/main/java/com/lunarclient/apollo/mods/impl/ModPackDisplay.java +++ b/api/src/main/java/com/lunarclient/apollo/mods/impl/ModPackDisplay.java @@ -56,26 +56,6 @@ public final class ModPackDisplay { .notifyClient() .build(); - /** - * No documentation available. - * - * @since 1.0.0 - */ - public static final SimpleOption PACK_ICON = SimpleOption.builder() - .node("pack-display", "pack-icon").type(TypeToken.get(Boolean.class)) - .notifyClient() - .build(); - - /** - * No documentation available. - * - * @since 1.0.0 - */ - public static final SimpleOption PACK_DESCRIPTION = SimpleOption.builder() - .node("pack-display", "pack-description").type(TypeToken.get(Boolean.class)) - .notifyClient() - .build(); - /** * No documentation available. * @@ -190,6 +170,26 @@ public final class ModPackDisplay { .notifyClient() .build(); + /** + * No documentation available. + * + * @since 1.0.0 + */ + public static final SimpleOption PACK_ICON = SimpleOption.builder() + .node("pack-display", "pack-icon").type(TypeToken.get(Boolean.class)) + .notifyClient() + .build(); + + /** + * No documentation available. + * + * @since 1.0.0 + */ + public static final SimpleOption PACK_DESCRIPTION = SimpleOption.builder() + .node("pack-display", "pack-description").type(TypeToken.get(Boolean.class)) + .notifyClient() + .build(); + private ModPackDisplay() { } diff --git a/api/src/main/java/com/lunarclient/apollo/mods/impl/ModPing.java b/api/src/main/java/com/lunarclient/apollo/mods/impl/ModPing.java index 589543a2..5436def5 100644 --- a/api/src/main/java/com/lunarclient/apollo/mods/impl/ModPing.java +++ b/api/src/main/java/com/lunarclient/apollo/mods/impl/ModPing.java @@ -56,18 +56,6 @@ public final class ModPing { .notifyClient() .build(); - /** - * Faster updates may impact performance. - * - * @since 1.0.0 - */ - public static final NumberOption UPDATE_INTERVAL_SEC = NumberOption.number() - .comment("Faster updates may impact performance") - .node("ping", "update-interval-sec").type(TypeToken.get(Integer.class)) - .min(1).max(30) - .notifyClient() - .build(); - /** * No documentation available. * @@ -182,6 +170,18 @@ public final class ModPing { .notifyClient() .build(); + /** + * Faster updates may impact performance. + * + * @since 1.0.0 + */ + public static final NumberOption UPDATE_INTERVAL_SEC = NumberOption.number() + .comment("Faster updates may impact performance") + .node("ping", "update-interval-sec").type(TypeToken.get(Integer.class)) + .min(1).max(30) + .notifyClient() + .build(); + private ModPing() { } diff --git a/api/src/main/java/com/lunarclient/apollo/mods/impl/ModServerAddress.java b/api/src/main/java/com/lunarclient/apollo/mods/impl/ModServerAddress.java index 142b8fce..0bb3ce97 100644 --- a/api/src/main/java/com/lunarclient/apollo/mods/impl/ModServerAddress.java +++ b/api/src/main/java/com/lunarclient/apollo/mods/impl/ModServerAddress.java @@ -56,16 +56,6 @@ public final class ModServerAddress { .notifyClient() .build(); - /** - * No documentation available. - * - * @since 1.0.0 - */ - public static final SimpleOption SERVER_ICON = SimpleOption.builder() - .node("server-address", "server-icon").type(TypeToken.get(Boolean.class)) - .notifyClient() - .build(); - /** * No documentation available. * @@ -180,6 +170,16 @@ public final class ModServerAddress { .notifyClient() .build(); + /** + * No documentation available. + * + * @since 1.0.0 + */ + public static final SimpleOption SERVER_ICON = SimpleOption.builder() + .node("server-address", "server-icon").type(TypeToken.get(Boolean.class)) + .notifyClient() + .build(); + private ModServerAddress() { } diff --git a/api/src/main/java/com/lunarclient/apollo/mods/impl/ModSkyblock.java b/api/src/main/java/com/lunarclient/apollo/mods/impl/ModSkyblock.java new file mode 100644 index 00000000..ee6e24d8 --- /dev/null +++ b/api/src/main/java/com/lunarclient/apollo/mods/impl/ModSkyblock.java @@ -0,0 +1,221 @@ +/* + * This file is part of Apollo, licensed under the MIT License. + * + * Copyright (c) 2023 Moonsworth + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package com.lunarclient.apollo.mods.impl; + +import com.lunarclient.apollo.option.NumberOption; +import com.lunarclient.apollo.option.SimpleOption; +import io.leangen.geantyref.TypeToken; + +/** + * Various features to help in Hypixel Skyblock. + * + * @since 1.0.9 + */ +public final class ModSkyblock { + + /** + * No documentation available. + * + * @since 1.0.9 + */ + public static final SimpleOption ENABLED = SimpleOption.builder() + .node("skyblock", "enabled").type(TypeToken.get(Boolean.class)) + .notifyClient() + .build(); + + /** + * No documentation available. + * + * @since 1.0.9 + */ + public static final NumberOption SKYBLOCK_ALERT_SCALE = NumberOption.number() + .node("skyblock", "skyblock-alert-scale").type(TypeToken.get(Float.class)) + .min(0.2F).max(2.5F) + .notifyClient() + .build(); + + /** + * No documentation available. + * + * @since 1.0.9 + */ + public static final SimpleOption SKYBLOCK_HIDE_HUNGER = SimpleOption.builder() + .node("skyblock", "skyblock-hide-hunger").type(TypeToken.get(Boolean.class)) + .notifyClient() + .build(); + + /** + * No documentation available. + * + * @since 1.0.9 + */ + public static final SimpleOption SKYBLOCK_HIDE_ARMOR = SimpleOption.builder() + .node("skyblock", "skyblock-hide-armor").type(TypeToken.get(Boolean.class)) + .notifyClient() + .build(); + + /** + * No documentation available. + * + * @since 1.0.9 + */ + public static final SimpleOption HIDE_MIDAS_STAFF = SimpleOption.builder() + .node("skyblock", "hide-midas-staff").type(TypeToken.get(Boolean.class)) + .notifyClient() + .build(); + + /** + * No documentation available. + * + * @since 1.0.9 + */ + public static final SimpleOption HIDE_FALLING_BLOCKS = SimpleOption.builder() + .node("skyblock", "hide-falling-blocks").type(TypeToken.get(Boolean.class)) + .notifyClient() + .build(); + + /** + * Automatically copies rare drops and pet drops to the clipboard. + * + * @since 1.0.9 + */ + public static final SimpleOption AUTO_COPY_RARE_DROPS = SimpleOption.builder() + .comment("Automatically copies rare drops and pet drops to the clipboard.") + .node("skyblock", "auto-copy-rare-drops").type(TypeToken.get(Boolean.class)) + .notifyClient() + .build(); + + /** + * Changes crop hitboxes with their 1.12+ variant. Only enabled on Hypixel or singleplayer. + * + * @since 1.0.9 + */ + public static final SimpleOption TALLER_CROPS = SimpleOption.builder() + .comment("Changes crop hitboxes with their 1.12+ variant. Only enabled on Hypixel or singleplayer.") + .node("skyblock", "taller-crops").type(TypeToken.get(Boolean.class)) + .notifyClient() + .build(); + + /** + * Fixes your fishing bobber sinking in lava. + * + * @since 1.0.9 + */ + public static final SimpleOption FIX_LAVA_BOBBER = SimpleOption.builder() + .comment("Fixes your fishing bobber sinking in lava.") + .node("skyblock", "fix-lava-bobber").type(TypeToken.get(Boolean.class)) + .notifyClient() + .build(); + + /** + * Changes the texture of lava to water in the Crimson Isles and Kuudra. + * + * @since 1.0.9 + */ + public static final SimpleOption REPLACE_LAVA_WITH_WATER_CRIMSON = SimpleOption.builder() + .comment("Changes the texture of lava to water in the Crimson Isles and Kuudra.") + .node("skyblock", "replace-lava-with-water-crimson").type(TypeToken.get(Boolean.class)) + .notifyClient() + .build(); + + /** + * Changes the texture of lava to water everywhere in SkyBlock. + * + * @since 1.0.9 + */ + public static final SimpleOption REPLACE_LAVA_WITH_WATER_EVERYWHERE = SimpleOption.builder() + .comment("Changes the texture of lava to water everywhere in SkyBlock.") + .node("skyblock", "replace-lava-with-water-everywhere").type(TypeToken.get(Boolean.class)) + .notifyClient() + .build(); + + /** + * Provides a chat message on boss kill that tells you how long it took to kill!. + * + * @since 1.0.9 + */ + public static final SimpleOption SLAYER_BOSS_TIMER = SimpleOption.builder() + .comment("Provides a chat message on boss kill that tells you how long it took to kill!") + .node("skyblock", "slayer-boss-timer").type(TypeToken.get(Boolean.class)) + .notifyClient() + .build(); + + /** + * No documentation available. + * + * @since 1.0.9 + */ + public static final SimpleOption SLAYER_MINI_BOSS_ALERT = SimpleOption.builder() + .node("skyblock", "slayer-mini-boss-alert").type(TypeToken.get(Boolean.class)) + .notifyClient() + .build(); + + /** + * Used in Stillgore of the Rift, this feature tells you where to go to refresh the duration of inactive Effigies. + * + * @since 1.0.9 + */ + public static final SimpleOption INACTIVE_EFFIGY_WAYPOINTS = SimpleOption.builder() + .comment("Used in Stillgore of the Rift, this feature tells you where to go to refresh the duration of inactive Effigies.") + .node("skyblock", "inactive-effigy-waypoints").type(TypeToken.get(Boolean.class)) + .notifyClient() + .build(); + + /** + * Highlights a boss when it can be 1 tapped using steak stake. + * + * @since 1.0.9 + */ + public static final SimpleOption VAMPIRE_STEAK_DISPLAY = SimpleOption.builder() + .comment("Highlights a boss when it can be 1 tapped using steak stake.") + .node("skyblock", "vampire-steak-display").type(TypeToken.get(Boolean.class)) + .notifyClient() + .build(); + + /** + * Highlights blood ichors present during T5 Bloodfiends. + * + * @since 1.0.9 + */ + public static final SimpleOption VAMPIRE_ICHOR_DISPLAY = SimpleOption.builder() + .comment("Highlights blood ichors present during T5 Bloodfiends") + .node("skyblock", "vampire-ichor-display").type(TypeToken.get(Boolean.class)) + .notifyClient() + .build(); + + /** + * Shows the positions where you can trap the gray blazes. + * + * @since 1.0.9 + */ + public static final SimpleOption GRAVITY_WELL_WAYPOINTS = SimpleOption.builder() + .comment("Shows the positions where you can trap the gray blazes.") + .node("skyblock", "gravity-well-waypoints").type(TypeToken.get(Boolean.class)) + .notifyClient() + .build(); + + private ModSkyblock() { + } + +} diff --git a/api/src/main/java/com/lunarclient/apollo/mods/impl/ModStopwatch.java b/api/src/main/java/com/lunarclient/apollo/mods/impl/ModStopwatch.java index 281a425d..08bda120 100644 --- a/api/src/main/java/com/lunarclient/apollo/mods/impl/ModStopwatch.java +++ b/api/src/main/java/com/lunarclient/apollo/mods/impl/ModStopwatch.java @@ -56,16 +56,6 @@ public final class ModStopwatch { .notifyClient() .build(); - /** - * No documentation available. - * - * @since 1.0.0 - */ - public static final SimpleOption RESET_EVERY_START = SimpleOption.builder() - .node("stopwatch", "reset-every-start").type(TypeToken.get(Boolean.class)) - .notifyClient() - .build(); - /** * No documentation available. * @@ -180,6 +170,16 @@ public final class ModStopwatch { .notifyClient() .build(); + /** + * No documentation available. + * + * @since 1.0.0 + */ + public static final SimpleOption RESET_EVERY_START = SimpleOption.builder() + .node("stopwatch", "reset-every-start").type(TypeToken.get(Boolean.class)) + .notifyClient() + .build(); + private ModStopwatch() { } diff --git a/api/src/main/java/com/lunarclient/apollo/mods/impl/ModZoom.java b/api/src/main/java/com/lunarclient/apollo/mods/impl/ModZoom.java index 15705d70..f4df769c 100644 --- a/api/src/main/java/com/lunarclient/apollo/mods/impl/ModZoom.java +++ b/api/src/main/java/com/lunarclient/apollo/mods/impl/ModZoom.java @@ -100,6 +100,18 @@ public final class ModZoom { .notifyClient() .build(); + /** + * Change the camera sensitivity when zoomed in. + * + * @since 1.0.9 + */ + public static final NumberOption CAMERA_SENSITIVITY = NumberOption.number() + .comment("Change the camera sensitivity when zoomed in.") + .node("zoom", "camera-sensitivity").type(TypeToken.get(Float.class)) + .min(0.1F).max(2.0F) + .notifyClient() + .build(); + private ModZoom() { } diff --git a/api/src/main/java/com/lunarclient/apollo/module/border/Border.java b/api/src/main/java/com/lunarclient/apollo/module/border/Border.java index b7b7ddea..2a02070e 100644 --- a/api/src/main/java/com/lunarclient/apollo/module/border/Border.java +++ b/api/src/main/java/com/lunarclient/apollo/module/border/Border.java @@ -27,6 +27,7 @@ import java.awt.Color; import lombok.Builder; import lombok.Getter; +import org.jetbrains.annotations.Range; /** * Represents a border which can be shown on the client. @@ -102,9 +103,11 @@ public final class Border { /** * Returns the border {@link Integer} duration represented in ticks (1 tick = 50 milliseconds). * + *

The value must be equal to or greater than 0.

+ * * @return the border duration * @since 1.0.0 */ - int durationTicks; + @Range(from = 0, to = Integer.MAX_VALUE) int durationTicks; } diff --git a/api/src/main/java/com/lunarclient/apollo/module/staffmod/StaffModModule.java b/api/src/main/java/com/lunarclient/apollo/module/staffmod/StaffModModule.java index b0b644ed..5a8a348d 100644 --- a/api/src/main/java/com/lunarclient/apollo/module/staffmod/StaffModModule.java +++ b/api/src/main/java/com/lunarclient/apollo/module/staffmod/StaffModModule.java @@ -71,4 +71,5 @@ public abstract class StaffModModule extends ApolloModule { * @since 1.0.0 */ public abstract void disableAllStaffMods(Recipients recipients); + } diff --git a/api/src/main/java/com/lunarclient/apollo/module/team/TeamMember.java b/api/src/main/java/com/lunarclient/apollo/module/team/TeamMember.java index c5b718d8..7cf3befb 100644 --- a/api/src/main/java/com/lunarclient/apollo/module/team/TeamMember.java +++ b/api/src/main/java/com/lunarclient/apollo/module/team/TeamMember.java @@ -79,4 +79,5 @@ public final class TeamMember { * @since 1.0.0 */ ApolloLocation location; + } diff --git a/api/src/main/java/com/lunarclient/apollo/module/title/Title.java b/api/src/main/java/com/lunarclient/apollo/module/title/Title.java index a0cf1e87..ec207dfe 100644 --- a/api/src/main/java/com/lunarclient/apollo/module/title/Title.java +++ b/api/src/main/java/com/lunarclient/apollo/module/title/Title.java @@ -27,6 +27,7 @@ import lombok.Builder; import lombok.Getter; import net.kyori.adventure.text.Component; +import org.jetbrains.annotations.Range; /** * Represents a title which can be shown on the client. @@ -56,10 +57,12 @@ public final class Title { /** * Returns the title {@link Float} scale. * + *

The value must be equal to or greater than 0.

+ * * @return the title scale * @since 1.0.0 */ - float scale; + @Range(from = 0, to = Integer.MAX_VALUE) float scale; /** * Returns the title {@link Duration} display time. @@ -90,22 +93,24 @@ public final class Title { * *

If the provided interpolation scale is greater than {@link Title#scale}, * the title will expand. However, if the {@link Title#scale} is greater than - * the interpolation scale, the title will shrink.

+ * the interpolation scale, the title will shrink. The value must be equal + * to or greater than 0.

* * @return the title interpolation scale * @since 1.0.7 */ - float interpolationScale; + @Range(from = 0, to = Integer.MAX_VALUE) float interpolationScale; /** * Returns the title {@link Float} interpolation rate. * *

The rate that the title will expand or shrink every tick (50ms) - * between {@link Title#scale} and {@link Title#interpolationScale}.

+ * between {@link Title#scale} and {@link Title#interpolationScale}. The + * value must be equal to or greater than 0.

* * @return the title interpolation rate * @since 1.0.7 */ - float interpolationRate; + @Range(from = 0, to = Integer.MAX_VALUE) float interpolationRate; } diff --git a/api/src/main/java/com/lunarclient/apollo/module/tntcountdown/TntCountdownModule.java b/api/src/main/java/com/lunarclient/apollo/module/tntcountdown/TntCountdownModule.java index f2507fea..0d179df8 100644 --- a/api/src/main/java/com/lunarclient/apollo/module/tntcountdown/TntCountdownModule.java +++ b/api/src/main/java/com/lunarclient/apollo/module/tntcountdown/TntCountdownModule.java @@ -29,6 +29,7 @@ import com.lunarclient.apollo.option.NumberOption; import io.leangen.geantyref.TypeToken; import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.Range; /** * Represents the tnt countdown module. @@ -64,10 +65,12 @@ public boolean isClientNotify() { /** * Set the amount of ticks before the specified TNT explodes. * + *

The given ticks must be equal to or greater than 0.

+ * * @param entity the TNT entity * @param ticks the ticks until explosion * @since 1.0.0 */ - public abstract void setTntCountdown(ApolloEntity entity, int ticks); + public abstract void setTntCountdown(ApolloEntity entity, @Range(from = 0, to = Integer.MAX_VALUE) int ticks); } diff --git a/api/src/main/java/com/lunarclient/apollo/module/transfer/PingResponse.java b/api/src/main/java/com/lunarclient/apollo/module/transfer/PingResponse.java index dde15d2f..9a88b242 100644 --- a/api/src/main/java/com/lunarclient/apollo/module/transfer/PingResponse.java +++ b/api/src/main/java/com/lunarclient/apollo/module/transfer/PingResponse.java @@ -28,6 +28,7 @@ import lombok.Builder; import lombok.Getter; import lombok.experimental.SuperBuilder; +import org.jetbrains.annotations.Range; /** * Represents the server ping response. @@ -77,7 +78,7 @@ public static class PingData { * @return the ping * @since 1.0.0 */ - int pingMillis; + @Range(from = 0, to = Integer.MAX_VALUE) int pingMillis; /** * Represents the ping data state. diff --git a/api/src/main/java/com/lunarclient/apollo/module/vignette/Vignette.java b/api/src/main/java/com/lunarclient/apollo/module/vignette/Vignette.java index 15fea327..bc9937e3 100644 --- a/api/src/main/java/com/lunarclient/apollo/module/vignette/Vignette.java +++ b/api/src/main/java/com/lunarclient/apollo/module/vignette/Vignette.java @@ -25,6 +25,7 @@ import lombok.Builder; import lombok.Getter; +import org.jetbrains.annotations.Range; /** * Represents a vignette which can be shown on the client. @@ -48,11 +49,11 @@ public final class Vignette { /** * Returns the vignette {@link Float} opacity. * - *

Set to 0 to hide the vignette.

+ *

Set to 0 to hide the vignette. This value must be between 0 and 1.

* * @return the opacity * @since 1.0.0 */ - float opacity; + @Range(from = 0, to = 1) float opacity; } diff --git a/api/src/main/java/com/lunarclient/apollo/player/ApolloPlayer.java b/api/src/main/java/com/lunarclient/apollo/player/ApolloPlayer.java index 03760c82..8d009643 100644 --- a/api/src/main/java/com/lunarclient/apollo/player/ApolloPlayer.java +++ b/api/src/main/java/com/lunarclient/apollo/player/ApolloPlayer.java @@ -97,4 +97,12 @@ default boolean hasPermission(Options options, Option option) { */ boolean hasPermission(String permissionNode); + /** + * Returns the player object associated with the platform. + * + * @return the associated player object + * @since 1.0.9 + */ + Object getPlayer(); + } diff --git a/api/src/main/java/com/lunarclient/apollo/roundtrip/ApolloRequest.java b/api/src/main/java/com/lunarclient/apollo/roundtrip/ApolloRequest.java index 9da64c1b..a163cf72 100644 --- a/api/src/main/java/com/lunarclient/apollo/roundtrip/ApolloRequest.java +++ b/api/src/main/java/com/lunarclient/apollo/roundtrip/ApolloRequest.java @@ -25,6 +25,7 @@ import java.util.UUID; import lombok.Getter; +import org.jetbrains.annotations.Range; /** * Represents an Apollo Request. @@ -54,7 +55,7 @@ public class ApolloRequest { * * @since 1.0.0 */ - private final long sentTime; + private final @Range(from = 0, to = Long.MAX_VALUE) long sentTime; /** * Constructs a new {@link ApolloRequest}. diff --git a/api/src/main/java/com/lunarclient/apollo/stats/ApolloStats.java b/api/src/main/java/com/lunarclient/apollo/stats/ApolloStats.java index d3d613b0..eeb03f59 100644 --- a/api/src/main/java/com/lunarclient/apollo/stats/ApolloStats.java +++ b/api/src/main/java/com/lunarclient/apollo/stats/ApolloStats.java @@ -25,6 +25,7 @@ import java.util.List; import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.Range; /** * Represents Apollo tracked stats. @@ -88,6 +89,6 @@ public interface ApolloStats { * @return the servers total players * @since 1.0.0 */ - int getTotalPlayers(); + @Range(from = 0, to = Integer.MAX_VALUE) int getTotalPlayers(); } diff --git a/bukkit-example/src/main/java/com/lunarclient/apollo/example/ApolloExamplePlugin.java b/bukkit-example/src/main/java/com/lunarclient/apollo/example/ApolloExamplePlugin.java index 0b049fdd..d9d1f140 100644 --- a/bukkit-example/src/main/java/com/lunarclient/apollo/example/ApolloExamplePlugin.java +++ b/bukkit-example/src/main/java/com/lunarclient/apollo/example/ApolloExamplePlugin.java @@ -23,6 +23,7 @@ */ package com.lunarclient.apollo.example; +import com.lunarclient.apollo.event.EventBus; import com.lunarclient.apollo.example.commands.BeamCommand; import com.lunarclient.apollo.example.commands.BorderCommand; import com.lunarclient.apollo.example.commands.ChatCommand; @@ -45,6 +46,7 @@ import com.lunarclient.apollo.example.commands.TransferCommand; import com.lunarclient.apollo.example.commands.VignetteCommand; import com.lunarclient.apollo.example.commands.WaypointCommand; +import com.lunarclient.apollo.example.listeners.PlayerListener; import com.lunarclient.apollo.example.modules.BeamExample; import com.lunarclient.apollo.example.modules.BorderExample; import com.lunarclient.apollo.example.modules.ChatExample; @@ -105,6 +107,7 @@ public void onEnable() { this.registerModuleExamples(); this.registerCommands(); + this.registerListeners(); } @Override @@ -162,4 +165,8 @@ private void registerCommands() { this.getCommand("waypoint").setExecutor(new WaypointCommand()); } + private void registerListeners() { + EventBus.getBus().register(new PlayerListener()); + } + } diff --git a/bukkit-example/src/main/java/com/lunarclient/apollo/example/listeners/PlayerListener.java b/bukkit-example/src/main/java/com/lunarclient/apollo/example/listeners/PlayerListener.java new file mode 100644 index 00000000..ebb0b7c1 --- /dev/null +++ b/bukkit-example/src/main/java/com/lunarclient/apollo/example/listeners/PlayerListener.java @@ -0,0 +1,54 @@ +/* + * This file is part of Apollo, licensed under the MIT License. + * + * Copyright (c) 2023 Moonsworth + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package com.lunarclient.apollo.example.listeners; + +import com.lunarclient.apollo.event.ApolloListener; +import com.lunarclient.apollo.event.Listen; +import com.lunarclient.apollo.event.player.ApolloRegisterPlayerEvent; +import com.lunarclient.apollo.example.ApolloExamplePlugin; +import com.lunarclient.apollo.example.modules.TeamExample; +import com.lunarclient.apollo.player.ApolloPlayer; +import org.bukkit.entity.Player; + +public class PlayerListener implements ApolloListener { + + private final ApolloExamplePlugin plugin = ApolloExamplePlugin.getPlugin(); + private final TeamExample.Team defaultTeam = this.plugin.getTeamExample().createTeam(); + + @Listen + private void onApolloRegister(ApolloRegisterPlayerEvent event) { + ApolloPlayer apolloPlayer = event.getPlayer(); + Player player = (Player) apolloPlayer.getPlayer(); + + // Default team view markers + this.defaultTeam.addMember(player); + + this.plugin.getBeamExample().displayBeamExample(player); + this.plugin.getBorderExample().displayBorderExample(player); + this.plugin.getCooldownExample().displayCooldownExample(player); + this.plugin.getNametagExample().overrideNametagExample(player); + this.plugin.getWaypointExample().displayWaypointExample(player); + } + +} diff --git a/bukkit-example/src/main/java/com/lunarclient/apollo/example/modules/HologramExample.java b/bukkit-example/src/main/java/com/lunarclient/apollo/example/modules/HologramExample.java index 7e44c10a..e58a15da 100644 --- a/bukkit-example/src/main/java/com/lunarclient/apollo/example/modules/HologramExample.java +++ b/bukkit-example/src/main/java/com/lunarclient/apollo/example/modules/HologramExample.java @@ -45,7 +45,7 @@ public void displayHologramExample() { .id("welcome-hologram") .location(ApolloLocation.builder() .world("world") - .z(5) + .x(5) .y(105) .z(0) .build()) diff --git a/bukkit-example/src/main/resources/plugin.yml b/bukkit-example/src/main/resources/plugin.yml index 54fa3ef5..827fb7ce 100644 --- a/bukkit-example/src/main/resources/plugin.yml +++ b/bukkit-example/src/main/resources/plugin.yml @@ -1,6 +1,6 @@ name: Apollo-Example main: com.lunarclient.apollo.example.ApolloExamplePlugin -version: 1.0.8 +version: 1.0.9 author: Moonsworth depend: [ Apollo-Bukkit ] api-version: 1.13 diff --git a/bukkit/src/main/java/com/lunarclient/apollo/ApolloBukkitPlatform.java b/bukkit/src/main/java/com/lunarclient/apollo/ApolloBukkitPlatform.java index 105c8209..4eea21c6 100644 --- a/bukkit/src/main/java/com/lunarclient/apollo/ApolloBukkitPlatform.java +++ b/bukkit/src/main/java/com/lunarclient/apollo/ApolloBukkitPlatform.java @@ -23,7 +23,8 @@ */ package com.lunarclient.apollo; -import com.lunarclient.apollo.command.ApolloCommand; +import com.lunarclient.apollo.command.impl.ApolloCommand; +import com.lunarclient.apollo.command.impl.LunarClientCommand; import com.lunarclient.apollo.listener.ApolloPlayerListener; import com.lunarclient.apollo.listener.ApolloWorldListener; import com.lunarclient.apollo.loader.PlatformPlugin; @@ -74,8 +75,6 @@ import com.lunarclient.apollo.option.Options; import com.lunarclient.apollo.option.OptionsImpl; import com.lunarclient.apollo.stats.ApolloStats; -import com.lunarclient.apollo.stats.ApolloStatsManager; -import com.lunarclient.apollo.version.ApolloVersionManager; import com.lunarclient.apollo.wrapper.BukkitApolloStats; import java.util.logging.Level; import java.util.logging.Logger; @@ -133,9 +132,6 @@ public void onEnable() { .addModule(VignetteModule.class, new VignetteModuleImpl()) .addModule(WaypointModule.class, new WaypointModuleImpl()); - ApolloStatsManager statsManager = new ApolloStatsManager(); - ApolloVersionManager versionManager = new ApolloVersionManager(); - try { ApolloManager.setConfigPath(this.plugin.getDataFolder().toPath()); ApolloManager.loadConfiguration(); @@ -151,10 +147,11 @@ public void onEnable() { (channel, player, bytes) -> ApolloManager.getNetworkManager().receivePacket(player.getUniqueId(), bytes) ); - this.getPlugin().getCommand("apollo").setExecutor(new ApolloCommand()); + this.plugin.getCommand("apollo").setExecutor(new ApolloCommand()); + this.plugin.getCommand("lunarclient").setExecutor(new LunarClientCommand()); - statsManager.enable(); - versionManager.checkForUpdates(); + ApolloManager.getStatsManager().enable(); + ApolloManager.getVersionManager().checkForUpdates(); if (Bukkit.getPluginManager().getPlugin("LunarClient-API") != null) { this.getPlatformLogger().log(Level.WARNING, "Please remove the legacy API to prevent compatibility issues with Apollo!"); diff --git a/bukkit/src/main/java/com/lunarclient/apollo/command/BukkitApolloCommand.java b/bukkit/src/main/java/com/lunarclient/apollo/command/BukkitApolloCommand.java new file mode 100644 index 00000000..2ba91829 --- /dev/null +++ b/bukkit/src/main/java/com/lunarclient/apollo/command/BukkitApolloCommand.java @@ -0,0 +1,73 @@ +/* + * This file is part of Apollo, licensed under the MIT License. + * + * Copyright (c) 2023 Moonsworth + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package com.lunarclient.apollo.command; + +import java.util.function.BiConsumer; +import java.util.function.Consumer; +import lombok.NonNull; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; + +/** + * Provides common command functions for Bukkit. + * + * @param the sender type + * @since 1.0.9 + */ +public abstract class BukkitApolloCommand extends AbstractApolloCommand { + + /** + * Returns a new instance of a Bukkit command. + * + * @param textConsumer the consumer for sending messages to the sender + * @since 1.0.9 + */ + public BukkitApolloCommand(BiConsumer textConsumer) { + super(textConsumer); + } + + /** + * Handles a player argument; if the provided player doesn't exist, a not found message + * is sent to the sender. Otherwise, the player is passed to the provided player consumer. + * + * @param sender the command sender + * @param argument the argument passed from the command execution + * @param playerConsumer a consumer used for processing a desired action if the player is found + * @since 1.0.9 + */ + protected void handlePlayerArgument(@NonNull T sender, @NonNull String argument, @NonNull Consumer playerConsumer) { + Player player = Bukkit.getPlayer(argument); + + if (player == null) { + this.textConsumer.accept(sender, Component.text("Player '", NamedTextColor.RED) + .append(Component.text(argument, NamedTextColor.RED)) + .append(Component.text("' not found!", NamedTextColor.RED))); + return; + } + + playerConsumer.accept(player); + } +} diff --git a/bukkit/src/main/java/com/lunarclient/apollo/command/ApolloCommand.java b/bukkit/src/main/java/com/lunarclient/apollo/command/impl/ApolloCommand.java similarity index 72% rename from bukkit/src/main/java/com/lunarclient/apollo/command/ApolloCommand.java rename to bukkit/src/main/java/com/lunarclient/apollo/command/impl/ApolloCommand.java index 2f64f07a..1285bf79 100644 --- a/bukkit/src/main/java/com/lunarclient/apollo/command/ApolloCommand.java +++ b/bukkit/src/main/java/com/lunarclient/apollo/command/impl/ApolloCommand.java @@ -21,8 +21,10 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package com.lunarclient.apollo.command; +package com.lunarclient.apollo.command.impl; +import com.lunarclient.apollo.ApolloManager; +import com.lunarclient.apollo.command.BukkitApolloCommand; import com.lunarclient.apollo.common.ApolloComponent; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; @@ -33,7 +35,7 @@ * * @since 1.0.5 */ -public final class ApolloCommand extends AbstractApolloCommand implements CommandExecutor { +public final class ApolloCommand extends BukkitApolloCommand implements CommandExecutor { /** * Returns a new instance of this command. @@ -45,11 +47,16 @@ public ApolloCommand() { } @Override - public boolean onCommand(CommandSender commandSender, Command command, String label, String[] args) { + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { if(args.length < 1) { - this.getCurrentVersion(commandSender); + this.getCurrentVersion(sender); } else if(args[0].equalsIgnoreCase("reload")) { - this.reloadConfiguration(commandSender); + this.reloadConfiguration(sender); + } else if(args[0].equalsIgnoreCase("update")) { + ApolloManager.getVersionManager().forceUpdate( + "bukkit", + message -> this.textConsumer.accept(sender, message) + ); } return true; diff --git a/bukkit/src/main/java/com/lunarclient/apollo/command/impl/LunarClientCommand.java b/bukkit/src/main/java/com/lunarclient/apollo/command/impl/LunarClientCommand.java new file mode 100644 index 00000000..eabd32bc --- /dev/null +++ b/bukkit/src/main/java/com/lunarclient/apollo/command/impl/LunarClientCommand.java @@ -0,0 +1,78 @@ +/* + * This file is part of Apollo, licensed under the MIT License. + * + * Copyright (c) 2023 Moonsworth + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package com.lunarclient.apollo.command.impl; + +import com.lunarclient.apollo.Apollo; +import com.lunarclient.apollo.command.BukkitApolloCommand; +import com.lunarclient.apollo.common.ApolloComponent; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; + +/** + * The general Lunar Client command. + * + * @since 1.0.9 + */ +public final class LunarClientCommand extends BukkitApolloCommand implements CommandExecutor { + + /** + * Returns a new instance of this command. + * + * @since 1.0.9 + */ + public LunarClientCommand() { + super((sender, component) -> sender.sendMessage(ApolloComponent.toLegacy(component))); + + this.setUsage("/lunarclient "); + } + + @Override + public boolean onCommand(CommandSender commandSender, Command command, String label, String[] args) { + if(args.length != 1) { + this.sendCommandUsage(commandSender); + return true; + } + + this.handlePlayerArgument(commandSender, args[0], player -> { + Component message = Component.text("Player ", NamedTextColor.GRAY) + .append(Component.text(player.getName(), NamedTextColor.AQUA)) + .append(Component.text(" is ", NamedTextColor.GRAY)); + + if (Apollo.getPlayerManager().hasSupport(player.getUniqueId())) { + message = message.append(Component.text("using ", NamedTextColor.GREEN)); + } else { + message = message.append(Component.text("not using ", NamedTextColor.RED)); + } + + message = message.append(Component.text("Lunar Client!", NamedTextColor.GRAY)); + this.textConsumer.accept(commandSender, message); + }); + + return true; + } + +} diff --git a/bukkit/src/main/java/com/lunarclient/apollo/module/tntcountdown/TntCountdownModuleImpl.java b/bukkit/src/main/java/com/lunarclient/apollo/module/tntcountdown/TntCountdownModuleImpl.java index 4a927173..73fca4c1 100644 --- a/bukkit/src/main/java/com/lunarclient/apollo/module/tntcountdown/TntCountdownModuleImpl.java +++ b/bukkit/src/main/java/com/lunarclient/apollo/module/tntcountdown/TntCountdownModuleImpl.java @@ -41,6 +41,8 @@ import org.bukkit.event.Listener; import org.bukkit.event.entity.EntitySpawnEvent; +import static com.lunarclient.apollo.util.Ranges.checkPositive; + /** * Provides the tnt countdown module. * @@ -65,6 +67,8 @@ protected void onEnable() { @Override public void setTntCountdown(ApolloEntity entity, int ticks) { + checkPositive(ticks, "TntCountdown#ticks"); + TNTPrimed target = null; if (TntCountdownModuleImpl.entityGetter != null) { try { diff --git a/bukkit/src/main/java/com/lunarclient/apollo/wrapper/BukkitApolloPlayer.java b/bukkit/src/main/java/com/lunarclient/apollo/wrapper/BukkitApolloPlayer.java index 83cf17ad..986447ac 100644 --- a/bukkit/src/main/java/com/lunarclient/apollo/wrapper/BukkitApolloPlayer.java +++ b/bukkit/src/main/java/com/lunarclient/apollo/wrapper/BukkitApolloPlayer.java @@ -32,7 +32,8 @@ import com.lunarclient.apollo.world.ApolloWorld; import java.util.Optional; import java.util.UUID; -import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.RequiredArgsConstructor; import org.bukkit.Location; import org.bukkit.World; import org.bukkit.entity.Player; @@ -42,7 +43,8 @@ * * @since 1.0.0 */ -@AllArgsConstructor +@Getter +@RequiredArgsConstructor public final class BukkitApolloPlayer extends AbstractApolloPlayer { private final Player player; diff --git a/bukkit/src/platform-loader/resources/plugin.yml b/bukkit/src/platform-loader/resources/plugin.yml index f1ac68cd..e5631a73 100644 --- a/bukkit/src/platform-loader/resources/plugin.yml +++ b/bukkit/src/platform-loader/resources/plugin.yml @@ -1,6 +1,6 @@ name: Apollo-Bukkit main: com.lunarclient.apollo.loader.BukkitPlatformLoader -version: 1.0.8 +version: 1.0.9 author: Moonsworth api-version: 1.13 soft-depend: [LunarClient-API] @@ -8,5 +8,10 @@ soft-depend: [LunarClient-API] commands: apollo: description: The main Apollo command. - usage: /apollo + usage: /apollo permission: apollo.command + lunarclient: + aliases: [lc] + description: The command to check whether the player is using Lunar Client. + usage: /lunarclient + permission: apollo.lunarclient diff --git a/bungee/src/main/java/com/lunarclient/apollo/ApolloBungeePlatform.java b/bungee/src/main/java/com/lunarclient/apollo/ApolloBungeePlatform.java index 458dceeb..be795313 100644 --- a/bungee/src/main/java/com/lunarclient/apollo/ApolloBungeePlatform.java +++ b/bungee/src/main/java/com/lunarclient/apollo/ApolloBungeePlatform.java @@ -23,7 +23,8 @@ */ package com.lunarclient.apollo; -import com.lunarclient.apollo.command.ApolloCommand; +import com.lunarclient.apollo.command.impl.ApolloCommand; +import com.lunarclient.apollo.command.impl.LunarClientCommand; import com.lunarclient.apollo.listener.ApolloPlayerListener; import com.lunarclient.apollo.loader.PlatformPlugin; import com.lunarclient.apollo.module.ApolloModuleManagerImpl; @@ -67,8 +68,6 @@ import com.lunarclient.apollo.option.Options; import com.lunarclient.apollo.option.OptionsImpl; import com.lunarclient.apollo.stats.ApolloStats; -import com.lunarclient.apollo.stats.ApolloStatsManager; -import com.lunarclient.apollo.version.ApolloVersionManager; import com.lunarclient.apollo.wrapper.BungeeApolloStats; import java.util.logging.Level; import java.util.logging.Logger; @@ -76,6 +75,7 @@ import lombok.RequiredArgsConstructor; import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.plugin.Plugin; +import net.md_5.bungee.api.plugin.PluginManager; /** * The Bungee platform plugin. @@ -119,9 +119,6 @@ public void onEnable() { .addModule(VignetteModule.class, new VignetteModuleImpl()) .addModule(WaypointModule.class, new WaypointModuleImpl()); - ApolloStatsManager statsManager = new ApolloStatsManager(); - ApolloVersionManager versionManager = new ApolloVersionManager(); - try { ApolloManager.setConfigPath(this.plugin.getDataFolder().toPath()); ApolloManager.loadConfiguration(); @@ -133,11 +130,14 @@ public void onEnable() { ProxyServer server = this.plugin.getProxy(); server.registerChannel(ApolloManager.PLUGIN_MESSAGE_CHANNEL); - server.getPluginManager().registerListener(this.plugin, new ApolloPlayerListener()); - server.getPluginManager().registerCommand(this.plugin, ApolloCommand.create()); - statsManager.enable(); - versionManager.checkForUpdates(); + PluginManager pluginManager = server.getPluginManager(); + pluginManager.registerListener(this.plugin, new ApolloPlayerListener()); + pluginManager.registerCommand(this.plugin, ApolloCommand.create()); + pluginManager.registerCommand(this.plugin, LunarClientCommand.create()); + + ApolloManager.getStatsManager().enable(); + ApolloManager.getVersionManager().checkForUpdates(); } @Override diff --git a/bungee/src/main/java/com/lunarclient/apollo/command/BungeeApolloCommand.java b/bungee/src/main/java/com/lunarclient/apollo/command/BungeeApolloCommand.java new file mode 100644 index 00000000..8b01e4e5 --- /dev/null +++ b/bungee/src/main/java/com/lunarclient/apollo/command/BungeeApolloCommand.java @@ -0,0 +1,73 @@ +/* + * This file is part of Apollo, licensed under the MIT License. + * + * Copyright (c) 2023 Moonsworth + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package com.lunarclient.apollo.command; + +import java.util.function.BiConsumer; +import java.util.function.Consumer; +import lombok.NonNull; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; +import net.md_5.bungee.api.ProxyServer; +import net.md_5.bungee.api.connection.ProxiedPlayer; + +/** + * Provides common command functions for Bungee. + * + * @param the sender type + * @since 1.0.9 + */ +public abstract class BungeeApolloCommand extends AbstractApolloCommand { + + /** + * Returns a new instance of a Bungee command. + * + * @param textConsumer the consumer for sending messages to the sender + * @since 1.0.9 + */ + public BungeeApolloCommand(BiConsumer textConsumer) { + super(textConsumer); + } + + /** + * Handles a player argument; if the provided player doesn't exist, a not found message + * is sent to the sender. Otherwise, the player is passed to the provided player consumer. + * + * @param sender the command sender + * @param argument the argument passed from the command execution + * @param playerConsumer a consumer used for processing a desired action if the player is found + * @since 1.0.9 + */ + protected void handlePlayerArgument(@NonNull T sender, @NonNull String argument, @NonNull Consumer playerConsumer) { + ProxiedPlayer player = ProxyServer.getInstance().getPlayer(argument); + + if (player == null) { + this.textConsumer.accept(sender, Component.text("Player '", NamedTextColor.RED) + .append(Component.text(argument, NamedTextColor.RED)) + .append(Component.text("' not found!", NamedTextColor.RED))); + return; + } + + playerConsumer.accept(player); + } +} diff --git a/bungee/src/main/java/com/lunarclient/apollo/command/ApolloCommand.java b/bungee/src/main/java/com/lunarclient/apollo/command/impl/ApolloCommand.java similarity index 83% rename from bungee/src/main/java/com/lunarclient/apollo/command/ApolloCommand.java rename to bungee/src/main/java/com/lunarclient/apollo/command/impl/ApolloCommand.java index f329af6a..57e56622 100644 --- a/bungee/src/main/java/com/lunarclient/apollo/command/ApolloCommand.java +++ b/bungee/src/main/java/com/lunarclient/apollo/command/impl/ApolloCommand.java @@ -21,8 +21,10 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package com.lunarclient.apollo.command; +package com.lunarclient.apollo.command.impl; +import com.lunarclient.apollo.ApolloManager; +import com.lunarclient.apollo.command.BungeeApolloCommand; import com.lunarclient.apollo.common.ApolloComponent; import net.md_5.bungee.api.CommandSender; import net.md_5.bungee.api.plugin.Command; @@ -32,7 +34,7 @@ * * @since 1.0.5 */ -public final class ApolloCommand extends AbstractApolloCommand { +public final class ApolloCommand extends BungeeApolloCommand { /** * Returns a new instance of this command. @@ -60,6 +62,11 @@ void execute(CommandSender sender, String[] args) { this.getCurrentVersion(sender); } else if(args[0].equalsIgnoreCase("reload")) { this.reloadConfiguration(sender); + } else if(args[0].equalsIgnoreCase("update")) { + ApolloManager.getVersionManager().forceUpdate( + "bungee", + message -> this.textConsumer.accept(sender, message) + ); } } diff --git a/bungee/src/main/java/com/lunarclient/apollo/command/impl/LunarClientCommand.java b/bungee/src/main/java/com/lunarclient/apollo/command/impl/LunarClientCommand.java new file mode 100644 index 00000000..ca455e49 --- /dev/null +++ b/bungee/src/main/java/com/lunarclient/apollo/command/impl/LunarClientCommand.java @@ -0,0 +1,86 @@ +/* + * This file is part of Apollo, licensed under the MIT License. + * + * Copyright (c) 2023 Moonsworth + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package com.lunarclient.apollo.command.impl; + +import com.lunarclient.apollo.Apollo; +import com.lunarclient.apollo.command.BungeeApolloCommand; +import com.lunarclient.apollo.common.ApolloComponent; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; +import net.md_5.bungee.api.CommandSender; +import net.md_5.bungee.api.plugin.Command; + +/** + * The general Lunar Client command. + * + * @since 1.0.9 + */ +public final class LunarClientCommand extends BungeeApolloCommand { + + /** + * Returns a new instance of this command. + * + * @return a new command + * @since 1.0.9 + */ + public static Command create() { + return new Command("lunarclient", "apollo.lunarclient") { + private final LunarClientCommand command = new LunarClientCommand(); + + @Override + public void execute(CommandSender sender, String[] args) { + this.command.execute(sender, args); + } + }; + } + + LunarClientCommand() { + super((sender, component) -> sender.sendMessage(ApolloComponent.toLegacy(component))); + + this.setUsage("/lunarclient "); + } + + void execute(CommandSender sender, String[] args) { + if(args.length != 1) { + this.sendCommandUsage(sender); + return; + } + + this.handlePlayerArgument(sender, args[0], player -> { + Component message = Component.text("Player ", NamedTextColor.GRAY) + .append(Component.text(player.getName(), NamedTextColor.AQUA)) + .append(Component.text(" is ", NamedTextColor.GRAY)); + + if (Apollo.getPlayerManager().hasSupport(player.getUniqueId())) { + message = message.append(Component.text("using ", NamedTextColor.GREEN)); + } else { + message = message.append(Component.text("not using ", NamedTextColor.RED)); + } + + message = message.append(Component.text("Lunar Client!", NamedTextColor.GRAY)); + this.textConsumer.accept(sender, message); + }); + } + +} diff --git a/bungee/src/main/java/com/lunarclient/apollo/wrapper/BungeeApolloPlayer.java b/bungee/src/main/java/com/lunarclient/apollo/wrapper/BungeeApolloPlayer.java index 37ecd3d8..9862cea1 100644 --- a/bungee/src/main/java/com/lunarclient/apollo/wrapper/BungeeApolloPlayer.java +++ b/bungee/src/main/java/com/lunarclient/apollo/wrapper/BungeeApolloPlayer.java @@ -27,6 +27,7 @@ import com.lunarclient.apollo.player.AbstractApolloPlayer; import com.lunarclient.apollo.player.ApolloPlayer; import java.util.UUID; +import lombok.Getter; import lombok.RequiredArgsConstructor; import net.md_5.bungee.api.connection.ProxiedPlayer; @@ -35,6 +36,7 @@ * * @since 1.0.0 */ +@Getter @RequiredArgsConstructor public final class BungeeApolloPlayer extends AbstractApolloPlayer { diff --git a/bungee/src/platform-loader/resources/plugin.yml b/bungee/src/platform-loader/resources/plugin.yml index fd8ccbb9..e39fed33 100644 --- a/bungee/src/platform-loader/resources/plugin.yml +++ b/bungee/src/platform-loader/resources/plugin.yml @@ -1,4 +1,4 @@ name: Apollo-Bungee main: com.lunarclient.apollo.loader.BungeePlatformLoader -version: 1.0.8 +version: 1.0.9 author: Moonsworth diff --git a/common/src/main/java/com/lunarclient/apollo/ApolloManager.java b/common/src/main/java/com/lunarclient/apollo/ApolloManager.java index 24da8169..4085d740 100644 --- a/common/src/main/java/com/lunarclient/apollo/ApolloManager.java +++ b/common/src/main/java/com/lunarclient/apollo/ApolloManager.java @@ -33,7 +33,9 @@ import com.lunarclient.apollo.option.config.CommonSerializers; import com.lunarclient.apollo.player.ApolloPlayerManagerImpl; import com.lunarclient.apollo.roundtrip.ApolloRoundtripManager; +import com.lunarclient.apollo.stats.ApolloStatsManager; import com.lunarclient.apollo.util.ConfigTarget; +import com.lunarclient.apollo.version.ApolloVersionManager; import com.lunarclient.apollo.world.ApolloWorldManagerImpl; import java.nio.file.Path; import java.util.Arrays; @@ -70,6 +72,8 @@ public final class ApolloManager { @Getter private static ApolloRoundtripManager roundtripManager; @Getter private static ApolloHttpManager httpManager; @Getter private static ApolloNetworkManager networkManager; + @Getter private static ApolloVersionManager versionManager; + @Getter private static ApolloStatsManager statsManager; @Getter private static Path configPath; @@ -97,6 +101,8 @@ public static void bootstrap(ApolloPlatform platform) { ApolloManager.roundtripManager = new ApolloRoundtripManager(); ApolloManager.httpManager = new ApolloHttpManager(); ApolloManager.networkManager = new ApolloNetworkManager(); + ApolloManager.versionManager = new ApolloVersionManager(); + ApolloManager.statsManager = new ApolloStatsManager(); new CommonSerializers(); diff --git a/common/src/main/java/com/lunarclient/apollo/api/ApolloHttpManager.java b/common/src/main/java/com/lunarclient/apollo/api/ApolloHttpManager.java index 6ea8065a..1e222279 100644 --- a/common/src/main/java/com/lunarclient/apollo/api/ApolloHttpManager.java +++ b/common/src/main/java/com/lunarclient/apollo/api/ApolloHttpManager.java @@ -25,15 +25,20 @@ import com.lunarclient.apollo.Apollo; import com.lunarclient.apollo.ApolloManager; +import com.lunarclient.apollo.api.request.DownloadFileRequest; +import com.lunarclient.apollo.api.response.DownloadFileResponse; import com.lunarclient.apollo.async.Future; import com.lunarclient.apollo.async.future.UncertainFuture; import java.io.BufferedReader; import java.io.IOException; +import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.lang.reflect.Type; import java.net.HttpURLConnection; import java.net.URL; +import java.nio.file.Files; +import java.nio.file.StandardCopyOption; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.logging.Level; @@ -142,6 +147,32 @@ public Future request(ApiRequest request) { return future; } + /** + * Asynchronously downloads a file and returns a {@link Future} for the API response. + * + * @param request The download file request to be sent. + * @return A {@link Future} representing the result of the API request. + * @since 1.0.9 + */ + public Future download(DownloadFileRequest request) { + UncertainFuture future = new UncertainFuture<>(); + String url = request.getUrl(); + + this.requestExecutor.submit(() -> { + try { + InputStream in = new URL(url).openStream(); + Files.copy(in, request.getTarget(), StandardCopyOption.REPLACE_EXISTING); + + future.handleSuccess(new DownloadFileResponse()); + } catch (Throwable t) { + future.handleFailure(new Throwable(String.format("Failed to download file %s", url))); + t.printStackTrace(); + } + }); + + return future; + } + /** * Handles an error that occurred while sending an API request. * diff --git a/common/src/main/java/com/lunarclient/apollo/api/request/DownloadFileRequest.java b/common/src/main/java/com/lunarclient/apollo/api/request/DownloadFileRequest.java new file mode 100644 index 00000000..d527d652 --- /dev/null +++ b/common/src/main/java/com/lunarclient/apollo/api/request/DownloadFileRequest.java @@ -0,0 +1,74 @@ +/* + * This file is part of Apollo, licensed under the MIT License. + * + * Copyright (c) 2023 Moonsworth + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package com.lunarclient.apollo.api.request; + +import com.lunarclient.apollo.api.ApiRequest; +import com.lunarclient.apollo.api.ApiRequestType; +import com.lunarclient.apollo.api.ApiServiceType; +import com.lunarclient.apollo.api.response.DownloadFileResponse; +import java.nio.file.Path; +import lombok.Builder; +import lombok.Getter; +import lombok.ToString; + +/** + * Represents the apollo download request. + * + * @since 1.0.9 + */ +@ToString +@Getter +@Builder(toBuilder = true) +public final class DownloadFileRequest implements ApiRequest { + + /** + * The url to download the file from. + * + * @since 1.0.9 + */ + private final String url; + + /** + * The target path to download the file to. + * + * @since 1.0.9 + */ + private final Path target; + + @Override + public ApiServiceType getService() { + return null; + } + + @Override + public ApiRequestType getType() { + return null; + } + + @Override + public String getRoute() { + return null; + } + +} diff --git a/common/src/main/java/com/lunarclient/apollo/api/response/DownloadFileResponse.java b/common/src/main/java/com/lunarclient/apollo/api/response/DownloadFileResponse.java new file mode 100644 index 00000000..b8f010db --- /dev/null +++ b/common/src/main/java/com/lunarclient/apollo/api/response/DownloadFileResponse.java @@ -0,0 +1,35 @@ +/* + * This file is part of Apollo, licensed under the MIT License. + * + * Copyright (c) 2023 Moonsworth + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package com.lunarclient.apollo.api.response; + +import com.lunarclient.apollo.api.ApiResponse; + +/** + * Represents the download response. + * + * @since 1.0.9 + */ +public final class DownloadFileResponse implements ApiResponse { + +} diff --git a/common/src/main/java/com/lunarclient/apollo/api/response/VersionResponse.java b/common/src/main/java/com/lunarclient/apollo/api/response/VersionResponse.java index 262aae00..76b488d2 100644 --- a/common/src/main/java/com/lunarclient/apollo/api/response/VersionResponse.java +++ b/common/src/main/java/com/lunarclient/apollo/api/response/VersionResponse.java @@ -42,4 +42,47 @@ public final class VersionResponse implements ApiResponse { */ String version; + /** + * Returns the apollo {@link Assets}. + * + * @return the apollo assets + * @since 1.0.9 + */ + Assets assets; + + /** + * Represents the apollo assets. + * + * @since 1.0.9 + */ + @Getter + public static final class Assets { + + /** + * Returns the latest version of apollo {@link String} Bukkit download URL. + * + * @return the apollo bukkit download url + * @since 1.0.9 + */ + String bukkit; + + /** + * Returns the latest version of apollo {@link String} Bungee download URL. + * + * @return the apollo bungee download url + * @since 1.0.9 + */ + String bungee; + + /** + * Returns the latest version of apollo {@link String} Velocity download URL. + * + * @return the apollo velocity download url + * @since 1.0.9 + */ + String velocity; + + + } + } diff --git a/common/src/main/java/com/lunarclient/apollo/command/AbstractApolloCommand.java b/common/src/main/java/com/lunarclient/apollo/command/AbstractApolloCommand.java index 559685e7..9769bf6d 100644 --- a/common/src/main/java/com/lunarclient/apollo/command/AbstractApolloCommand.java +++ b/common/src/main/java/com/lunarclient/apollo/command/AbstractApolloCommand.java @@ -30,6 +30,7 @@ import java.util.logging.Level; import lombok.NonNull; import lombok.RequiredArgsConstructor; +import lombok.Setter; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; @@ -39,10 +40,13 @@ * @param the sender type * @since 1.0.5 */ +@Setter @RequiredArgsConstructor public abstract class AbstractApolloCommand { - private final BiConsumer textConsumer; + protected final BiConsumer textConsumer; + + protected String usage; /** * Sends the current version message to the sender. @@ -85,4 +89,15 @@ protected void reloadConfiguration(@NonNull T sender) { )); } + /** + * Sends the command usage to the sender. + * + * @param sender the command sender + * @since 1.0.9 + */ + protected void sendCommandUsage(@NonNull T sender) { + this.textConsumer.accept(sender, Component.text("Usage: ", NamedTextColor.RED) + .append(Component.text(this.usage, NamedTextColor.RED))); + } + } diff --git a/common/src/main/java/com/lunarclient/apollo/module/border/BorderModuleImpl.java b/common/src/main/java/com/lunarclient/apollo/module/border/BorderModuleImpl.java index 8129ad7e..07d31e53 100644 --- a/common/src/main/java/com/lunarclient/apollo/module/border/BorderModuleImpl.java +++ b/common/src/main/java/com/lunarclient/apollo/module/border/BorderModuleImpl.java @@ -31,6 +31,8 @@ import com.lunarclient.apollo.recipients.Recipients; import lombok.NonNull; +import static com.lunarclient.apollo.util.Ranges.checkPositive; + /** * Provides the border module. * @@ -48,7 +50,7 @@ public void displayBorder(@NonNull Recipients recipients, @NonNull Border border .setCanShrinkOrExpand(border.isCanShrinkOrExpand()) .setColor(NetworkTypes.toProtobuf(border.getColor())) .setBounds(NetworkTypes.toProtobuf(border.getBounds())) - .setDurationTicks(border.getDurationTicks()) + .setDurationTicks(checkPositive(border.getDurationTicks(), "Border#durationTicks")) .build(); recipients.forEach(player -> ((AbstractApolloPlayer) player).sendPacket(message)); diff --git a/common/src/main/java/com/lunarclient/apollo/module/title/TitleModuleImpl.java b/common/src/main/java/com/lunarclient/apollo/module/title/TitleModuleImpl.java index 9875bd79..d9f2d7fb 100644 --- a/common/src/main/java/com/lunarclient/apollo/module/title/TitleModuleImpl.java +++ b/common/src/main/java/com/lunarclient/apollo/module/title/TitleModuleImpl.java @@ -32,6 +32,8 @@ import com.lunarclient.apollo.title.v1.TitleType; import lombok.NonNull; +import static com.lunarclient.apollo.util.Ranges.checkPositive; + /** * Provides the title module. * @@ -44,12 +46,12 @@ public void displayTitle(@NonNull Recipients recipients, @NonNull Title title) { DisplayTitleMessage message = DisplayTitleMessage.newBuilder() .setTitleType(TitleType.forNumber(title.getType().ordinal() + 1)) .setAdventureJsonMessage(ApolloComponent.toJson(title.getMessage())) - .setScale(title.getScale()) + .setScale(checkPositive(title.getScale(), "Title#scale")) .setFadeInTime(NetworkTypes.toProtobuf(title.getFadeInTime())) .setDisplayTime(NetworkTypes.toProtobuf(title.getDisplayTime())) .setFadeOutTime(NetworkTypes.toProtobuf(title.getFadeOutTime())) - .setInterpolationScale(title.getInterpolationScale()) - .setInterpolationRate(title.getInterpolationRate()) + .setInterpolationScale(checkPositive(title.getInterpolationScale(), "Title#interpolationScale")) + .setInterpolationRate(checkPositive(title.getInterpolationRate(), "Title#interpolationRate")) .build(); recipients.forEach(player -> ((AbstractApolloPlayer) player).sendPacket(message)); diff --git a/common/src/main/java/com/lunarclient/apollo/module/vignette/VignetteModuleImpl.java b/common/src/main/java/com/lunarclient/apollo/module/vignette/VignetteModuleImpl.java index a83201c5..1d43ef4b 100644 --- a/common/src/main/java/com/lunarclient/apollo/module/vignette/VignetteModuleImpl.java +++ b/common/src/main/java/com/lunarclient/apollo/module/vignette/VignetteModuleImpl.java @@ -29,6 +29,8 @@ import com.lunarclient.apollo.vignette.v1.ResetVignetteMessage; import lombok.NonNull; +import static com.lunarclient.apollo.util.Ranges.checkRange; + /** * Provides the vignette module. * @@ -40,7 +42,7 @@ public final class VignetteModuleImpl extends VignetteModule { public void displayVignette(@NonNull Recipients recipients, @NonNull Vignette vignette) { DisplayVignetteMessage message = DisplayVignetteMessage.newBuilder() .setResourceLocation(vignette.getResourceLocation()) - .setOpacity(vignette.getOpacity()) + .setOpacity(checkRange(vignette.getOpacity(), 0, 1, "Vignette#opacity")) .build(); recipients.forEach(player -> ((AbstractApolloPlayer) player).sendPacket(message)); diff --git a/common/src/main/java/com/lunarclient/apollo/network/NetworkTypes.java b/common/src/main/java/com/lunarclient/apollo/network/NetworkTypes.java index efa5a0a2..4987d74e 100644 --- a/common/src/main/java/com/lunarclient/apollo/network/NetworkTypes.java +++ b/common/src/main/java/com/lunarclient/apollo/network/NetworkTypes.java @@ -41,6 +41,9 @@ import java.time.Duration; import java.util.UUID; +import static com.lunarclient.apollo.util.Ranges.checkPositive; +import static com.lunarclient.apollo.util.Ranges.checkRange; + /** * Utility class for converting objects to and from their * corresponding Protocol Buffers representations. @@ -424,19 +427,19 @@ public static com.lunarclient.apollo.common.v1.Icon toProtobuf(Icon icon) { builder.setSimpleResourceLocation(com.lunarclient.apollo.common.v1.SimpleResourceLocationIcon.newBuilder() .setResourceLocation(simple.getResourceLocation()) - .setSize(simple.getSize()) + .setSize(checkPositive(simple.getSize(), "SimpleResourceLocationIcon#size")) .build()); } else if (icon instanceof AdvancedResourceLocationIcon) { AdvancedResourceLocationIcon advanced = (AdvancedResourceLocationIcon) icon; builder.setAdvancedResourceLocation(com.lunarclient.apollo.common.v1.AdvancedResourceLocationIcon.newBuilder() .setResourceLocation(advanced.getResourceLocation()) - .setWidth(advanced.getWidth()) - .setHeight(advanced.getHeight()) - .setMinU(advanced.getMinU()) - .setMaxU(advanced.getMaxU()) - .setMinV(advanced.getMinV()) - .setMaxV(advanced.getMaxV()) + .setWidth(checkPositive(advanced.getWidth(), "AdvancedResourceLocationIcon#width")) + .setHeight(checkPositive(advanced.getHeight(), "AdvancedResourceLocationIcon#height")) + .setMinU(checkRange(advanced.getMinU(), 0, 1, "AdvancedResourceLocationIcon#minU")) + .setMaxU(checkRange(advanced.getMaxU(), 0, 1, "AdvancedResourceLocationIcon#maxU")) + .setMinV(checkRange(advanced.getMinV(), 0, 1, "AdvancedResourceLocationIcon#minV")) + .setMaxV(checkRange(advanced.getMaxV(), 0, 1, "AdvancedResourceLocationIcon#maxV")) .build()); } diff --git a/common/src/main/java/com/lunarclient/apollo/util/Ranges.java b/common/src/main/java/com/lunarclient/apollo/util/Ranges.java new file mode 100644 index 00000000..1d7af1a2 --- /dev/null +++ b/common/src/main/java/com/lunarclient/apollo/util/Ranges.java @@ -0,0 +1,83 @@ +/* + * This file is part of Apollo, licensed under the MIT License. + * + * Copyright (c) 2023 Moonsworth + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package com.lunarclient.apollo.util; + +/** + * Represents a utility class for validating ranges. + * + * @since 1.0.9 + */ +public final class Ranges { + + /** + * Returns the value if it is within the range, otherwise throws an + * {@link IllegalArgumentException}. + * + * @param value the value to check + * @param min the minimum value + * @param max the maximum value + * @param name the name of the value + * @return the value + * @throws IllegalArgumentException if the value is not within the range + * @since 1.0.9 + */ + public static float checkRange(float value, float min, float max, String name) { + if(value < min && value >= max) throw new IllegalArgumentException(name + " must be between " + min + " and " + max); + return value; + } + + /** + * Returns the value if it is positive, otherwise throws an + * {@link IllegalArgumentException}. + * + * @param value the value to check + * @param name the name of the value + * @return the value + * @throws IllegalArgumentException if the value is not positive + * @since 1.0.9 + */ + public static int checkPositive(int value, String name) { + if(value < 0) throw new IllegalArgumentException(name + " must be positive"); + return value; + } + + /** + * Returns the value if it is positive, otherwise throws an + * {@link IllegalArgumentException}. + * + * @param value the value to check + * @param name the name of the value + * @return the value + * @throws IllegalArgumentException if the value is not positive + * @since 1.0.9 + */ + public static float checkPositive(float value, String name) { + if(value < 0) throw new IllegalArgumentException(name + " must be positive"); + return value; + } + + private Ranges() { + } + +} diff --git a/common/src/main/java/com/lunarclient/apollo/version/ApolloVersion.java b/common/src/main/java/com/lunarclient/apollo/version/ApolloVersion.java index 5fe23423..b25d80c8 100644 --- a/common/src/main/java/com/lunarclient/apollo/version/ApolloVersion.java +++ b/common/src/main/java/com/lunarclient/apollo/version/ApolloVersion.java @@ -73,12 +73,12 @@ public ApolloVersion(String version) { * @since 1.0.0 */ public boolean isUpdateAvailable(ApolloVersion version) { - if (this.major > version.getMajor()) { + if (version.getMajor() > this.major) { return true; - } else if (this.minor > version.getMinor()) { + } else if (version.getMinor() > this.minor) { return true; } - return this.patch > version.getPatch(); + return version.getPatch() > this.patch; } } diff --git a/common/src/main/java/com/lunarclient/apollo/version/ApolloVersionManager.java b/common/src/main/java/com/lunarclient/apollo/version/ApolloVersionManager.java index 626040fe..c01c3847 100644 --- a/common/src/main/java/com/lunarclient/apollo/version/ApolloVersionManager.java +++ b/common/src/main/java/com/lunarclient/apollo/version/ApolloVersionManager.java @@ -26,10 +26,21 @@ import com.lunarclient.apollo.Apollo; import com.lunarclient.apollo.ApolloManager; import com.lunarclient.apollo.ApolloPlatform; +import com.lunarclient.apollo.api.request.DownloadFileRequest; import com.lunarclient.apollo.api.request.VersionRequest; +import com.lunarclient.apollo.api.response.VersionResponse; import com.lunarclient.apollo.option.Option; import com.lunarclient.apollo.option.SimpleOption; import io.leangen.geantyref.TypeToken; +import java.io.File; +import java.net.URISyntaxException; +import java.net.URL; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.function.Consumer; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; /** * Manages Apollo versioning. @@ -43,8 +54,8 @@ public final class ApolloVersionManager { .node("send-updater-message").type(TypeToken.get(Boolean.class)) .defaultValue(true).build(); - private static final String DOWNLOAD_URL = "https://lunarclient.dev/apollo/downloads"; - public static final String UPDATE_MESSAGE = "[Apollo] You’re running an outdated version, update to the latest version here: " + DOWNLOAD_URL; + public static final String UPDATE_MESSAGE = "[Apollo] You're running an outdated version of Apollo. " + + "Use \"/apollo update\" to update to the latest version!"; /** * Returns whether the server needs to update Apollo. @@ -53,6 +64,9 @@ public final class ApolloVersionManager { */ public static boolean NEEDS_UPDATE; + private VersionResponse.Assets assets; + private AtomicBoolean updated = new AtomicBoolean(false); + /** * Constructs the {@link ApolloVersionManager}. * @@ -68,23 +82,130 @@ public ApolloVersionManager() { * @since 1.0.0 */ public void checkForUpdates() { - ApolloPlatform platform = Apollo.getPlatform(); - - if (!platform.getOptions().get(ApolloVersionManager.SEND_UPDATE_MESSAGE)) { - return; - } - ApolloManager.getHttpManager().request(VersionRequest.builder().build()) .onSuccess(response -> { + this.assets = response.getAssets(); + + ApolloPlatform platform = Apollo.getPlatform(); ApolloVersion currentVersion = new ApolloVersion(platform.getApolloVersion()); ApolloVersion latestVersion = new ApolloVersion(response.getVersion()); if (currentVersion.isUpdateAvailable(latestVersion)) { ApolloVersionManager.NEEDS_UPDATE = true; - platform.getPlatformLogger().warning(UPDATE_MESSAGE); + + if (platform.getOptions().get(ApolloVersionManager.SEND_UPDATE_MESSAGE)) { + platform.getPlatformLogger().warning(UPDATE_MESSAGE); + } } }) .onFailure(Throwable::printStackTrace); } + /** + * Runs a force update. + * + * @param platform the platform to run the update on + * @param message the message to send to the command sender + * @since 1.0.9 + */ + public void forceUpdate(String platform, Consumer message) { + if (this.updated.get()) { + message.accept(Component.text( + "Apollo is already updated, please restart your server!", + NamedTextColor.RED) + ); + return; + } + + if (!ApolloVersionManager.NEEDS_UPDATE) { + message.accept(Component.text( + "This server is already running the latest version of Apollo.", + NamedTextColor.RED) + ); + return; + } + + if (this.assets == null) { + message.accept(Component.text( + "Unable to find assets to update from.", + NamedTextColor.RED) + ); + return; + } + + String platformUrl = this.getPlatformUrl(platform); + if (platformUrl == null) { + message.accept(Component.text( + "Unable to find platform url.", + NamedTextColor.RED) + ); + return; + } + + // Find the current running Apollo jar + URL url = Apollo.getPlatform().getPlugin() + .getClass() + .getProtectionDomain() + .getCodeSource() + .getLocation(); + + File file; + try { + file = new File(url.toURI()); + } catch (URISyntaxException e) { + e.printStackTrace(); + return; + } + + // Find name of the new Apollo jar + String[] urlArgs = platformUrl.split("/"); + String fileName = urlArgs[urlArgs.length - 1]; + + // Create a path for the downloaded Apollo jar + Path updatedJarPath = Paths.get(file.getParent() + File.separator + fileName); + + DownloadFileRequest request = DownloadFileRequest.builder() + .url(platformUrl) + .target(updatedJarPath) + .build(); + + ApolloManager.getHttpManager().download(request) + .onSuccess(response -> { + message.accept(Component.text( + "Successfully updated Apollo, please restart your server!", + NamedTextColor.RED) + ); + + // Delete old Apollo jar + file.deleteOnExit(); + this.updated.set(true); + }) + .onFailure(throwable -> { + message.accept(Component.text( + "Failed to update Apollo, please check your console for more information!", + NamedTextColor.RED) + ); + + throwable.printStackTrace(); + }); + } + + private String getPlatformUrl(String platform) { + switch (platform.toLowerCase()) { + case "bukkit": { + return this.assets.getBukkit(); + } + + case "bungee": { + return this.assets.getBungee(); + } + + case "velocity": { + return this.assets.getVelocity(); + } + } + + return null; + } + } diff --git a/deploy.sh b/deploy.sh index 28a14161..664beb25 100755 --- a/deploy.sh +++ b/deploy.sh @@ -1,5 +1,5 @@ # Deploy apollo to the test server set -e ./gradlew clean build -scp bukkit/build/libs/apollo-bukkit-1.0.8.jar ubuntu@build.moonsworth.com:/home/ubuntu/apollo/plugins/ -scp bukkit-example/build/libs/apollo-bukkit-example-1.0.8.jar ubuntu@build.moonsworth.com:/home/ubuntu/apollo/plugins/ +scp bukkit/build/libs/apollo-bukkit-1.0.9.jar ubuntu@build.moonsworth.com:/home/ubuntu/apollo/plugins/ +scp bukkit-example/build/libs/apollo-bukkit-example-1.0.9.jar ubuntu@build.moonsworth.com:/home/ubuntu/apollo/plugins/ diff --git a/docs/developers/mods/_meta.json b/docs/developers/mods/_meta.json index 9d046839..0c3bd216 100644 --- a/docs/developers/mods/_meta.json +++ b/docs/developers/mods/_meta.json @@ -60,6 +60,7 @@ "serveraddress": "ServerAddress", "shinypots": "ShinyPots", "shulkerpreview": "ShulkerPreview", + "skyblock": "Skyblock", "snaplook": "Snaplook", "soundchanger": "SoundChanger", "stopwatch": "Stopwatch", diff --git a/docs/developers/mods/blockoutline.mdx b/docs/developers/mods/blockoutline.mdx index 80d53942..1bf45b47 100644 --- a/docs/developers/mods/blockoutline.mdx +++ b/docs/developers/mods/blockoutline.mdx @@ -21,25 +21,62 @@ public void toggleBlockOutlineExample(Player viewer, boolean value) { - Type: `Boolean` - Default: `false` +- __`BLOCK_OUTLINE`__ + - Config Key: `block-outline` + - Values + - Type: `Boolean` + - Default: `true` + +- __`BLOCK_OUTLINE_WIDTH`__ + - Config Key: `block-outline-width` + - Values + - Type: `Float` + - Default: `2.0F` + - Minimum: `1.0F` + - Maximum: `10.0F` + - __`BLOCK_OUTLINE_COLOR`__ + - Primary block outline color - Config Key: `block-outline-color` - Values - Type: `String` - Default: `#66000000` -- __`BLOCK_OVERLAY_COLOR`__ - - Config Key: `block-overlay-color` +- __`BLOCK_OUTLINE_COLOR_END`__ + - Secondary block outline color + - Config Key: `block-outline-color-end` - Values - Type: `String` - Default: `#66000000` -- __`BLOCK_OUTLINE_WIDTH`__ - - Config Key: `block-outline-width` +- __`BLOCK_OUTLINE_INTERPOLATE_ALPHA`__ + - If the transparency should also blend between both outline colors + - Config Key: `block-outline-interpolate-alpha` + - Values + - Type: `Boolean` + - Default: `false` + +- __`BLOCK_OUTLINE_ACCURATE`__ + - If the exact block bounding box should be used, this comes at a slight performance cost + - Config Key: `block-outline-accurate` + - Values + - Type: `Boolean` + - Default: `true` + +- __`BLOCK_OUTLINE_TRAVERSAL`__ + - If the outline colors should travel through the block + - Config Key: `block-outline-traversal` + - Values + - Type: `Boolean` + - Default: `false` + +- __`BLOCK_OUTLINE_TRAVERSAL_SPEED`__ + - Config Key: `block-outline-traversal-speed` - Values - Type: `Float` - - Default: `2.0F` - - Minimum: `1.0F` - - Maximum: `10.0F` + - Default: `1.0F` + - Minimum: `0.15F` + - Maximum: `5.0F` - __`BLOCK_OVERLAY`__ - Config Key: `block-overlay` @@ -47,9 +84,74 @@ public void toggleBlockOutlineExample(Player viewer, boolean value) { - Type: `Boolean` - Default: `false` -- __`BLOCK_OUTLINE`__ - - Config Key: `block-outline` +- __`BLOCK_OVERLAY_COLOR`__ + - Primary block overlay color + - Config Key: `block-overlay-color` + - Values + - Type: `String` + - Default: `#1A000000` + +- __`BLOCK_OVERLAY_COLOR_END`__ + - Secondary block overlay color + - Config Key: `block-overlay-color-end` + - Values + - Type: `String` + - Default: `#1A000000` + +- __`BLOCK_OVERLAY_INTERPOLATE_ALPHA`__ + - If the transparency should also blend between both overlay colors + - Config Key: `block-overlay-interpolate-alpha` + - Values + - Type: `Boolean` + - Default: `false` + +- __`BLOCK_OVERLAY_ACCURATE`__ + - If the exact block bounding box should be used, this comes at a slight performance cost + - Config Key: `block-overlay-accurate` - Values - Type: `Boolean` - Default: `true` +- __`BLOCK_OVERLAY_TRAVERSAL`__ + - If the overlay colors should travel through the block + - Config Key: `block-overlay-traversal` + - Values + - Type: `Boolean` + - Default: `false` + +- __`BLOCK_OVERLAY_TRAVERSAL_SPEED`__ + - Config Key: `block-overlay-traversal-speed` + - Values + - Type: `Float` + - Default: `1.0F` + - Minimum: `0.15F` + - Maximum: `5.0F` + +- __`BLOCK_OUTLINE_SIDE`__ + - If only a single side of the block should have outlines + - Config Key: `block-outline-side` + - Values + - Type: `Boolean` + - Default: `false` + +- __`BLOCK_OUTLINE_SHOW_HIDDEN_FOLIAGE`__ + - If using hide foliage, should outlines still show on foliage + - Config Key: `block-outline-show-hidden-foliage` + - Values + - Type: `Boolean` + - Default: `true` + +- __`BLOCK_OUTLINE_MULTI_BLOCK`__ + - If blocks that connect together should share an outline + - Config Key: `block-outline-multi-block` + - Values + - Type: `Boolean` + - Default: `true` + +- __`SHOW_IN_SPECTATOR`__ + - If outlines should be visible in spectator mode + - Config Key: `show-in-spectator` + - Values + - Type: `Boolean` + - Default: `false` + diff --git a/docs/developers/mods/clock.mdx b/docs/developers/mods/clock.mdx index 53c0179f..1564eaeb 100644 --- a/docs/developers/mods/clock.mdx +++ b/docs/developers/mods/clock.mdx @@ -29,12 +29,6 @@ public void toggleClockExample(Player viewer, boolean value) { - Minimum: `0.5F` - Maximum: `1.5F` -- __`MILITARY_TIME`__ - - Config Key: `military-time` - - Values - - Type: `Boolean` - - Default: `false` - - __`TEXT_SHADOW`__ - Config Key: `text-shadow` - Values @@ -108,3 +102,9 @@ public void toggleClockExample(Player viewer, boolean value) { - Type: `String` - Default: `#9F000000` +- __`MILITARY_TIME`__ + - Config Key: `military-time` + - Values + - Type: `Boolean` + - Default: `false` + diff --git a/docs/developers/mods/cps.mdx b/docs/developers/mods/cps.mdx index e637768c..aa3a2807 100644 --- a/docs/developers/mods/cps.mdx +++ b/docs/developers/mods/cps.mdx @@ -29,24 +29,6 @@ public void toggleCPSExample(Player viewer, boolean value) { - Minimum: `0.5F` - Maximum: `1.5F` -- __`RIGHT_CLICK`__ - - Config Key: `right-click` - - Values - - Type: `Boolean` - - Default: `false` - -- __`SHOW_CPSTEXT`__ - - Config Key: `show-c-p-s-text` - - Values - - Type: `Boolean` - - Default: `true` - -- __`LINE_COLOR`__ - - Config Key: `line-color` - - Values - - Type: `String` - - Default: `#FF202020` - - __`TEXT_SHADOW`__ - Config Key: `text-shadow` - Values @@ -120,3 +102,21 @@ public void toggleCPSExample(Player viewer, boolean value) { - Type: `String` - Default: `#9F000000` +- __`RIGHT_CLICK`__ + - Config Key: `right-click` + - Values + - Type: `Boolean` + - Default: `false` + +- __`SHOW_CPSTEXT`__ + - Config Key: `show-c-p-s-text` + - Values + - Type: `Boolean` + - Default: `true` + +- __`LINE_COLOR`__ + - Config Key: `line-color` + - Values + - Type: `String` + - Default: `#FF202020` + diff --git a/docs/developers/mods/daycounter.mdx b/docs/developers/mods/daycounter.mdx index 164235af..a73ed42a 100644 --- a/docs/developers/mods/daycounter.mdx +++ b/docs/developers/mods/daycounter.mdx @@ -29,12 +29,6 @@ public void toggleDayCounterExample(Player viewer, boolean value) { - Minimum: `0.5F` - Maximum: `1.5F` -- __`USE_WORLD_TYPE`__ - - Config Key: `use-world-type` - - Values - - Type: `Boolean` - - Default: `false` - - __`TEXT_SHADOW`__ - Config Key: `text-shadow` - Values @@ -108,3 +102,9 @@ public void toggleDayCounterExample(Player viewer, boolean value) { - Type: `String` - Default: `#9F000000` +- __`USE_WORLD_TYPE`__ + - Config Key: `use-world-type` + - Values + - Type: `Boolean` + - Default: `false` + diff --git a/docs/developers/mods/momentum.mdx b/docs/developers/mods/momentum.mdx index 7efe8c2a..e75150a1 100644 --- a/docs/developers/mods/momentum.mdx +++ b/docs/developers/mods/momentum.mdx @@ -29,29 +29,6 @@ public void toggleMomentumModExample(Player viewer, boolean value) { - Minimum: `0.5F` - Maximum: `1.5F` -- __`USE_GROUND_SPEED`__ - - If enabled then Y velocity is not used in the final speed. - - Config Key: `use-ground-speed` - - Values - - Type: `Boolean` - - Default: `false` - -- __`USE_AVERAGE_VELOCITY`__ - - If this is disabled then instant velocity is used - - Config Key: `use-average-velocity` - - Values - - Type: `Boolean` - - Default: `false` - -- __`AVERAGING_PERIOD`__ - - Determines how many times a second velocity is calculated. Lower values will show a smoother velocity - - Config Key: `averaging-period` - - Values - - Type: `Integer` - - Default: `8` - - Minimum: `1` - - Maximum: `50` - - __`TEXT_SHADOW`__ - Config Key: `text-shadow` - Values @@ -125,3 +102,26 @@ public void toggleMomentumModExample(Player viewer, boolean value) { - Type: `String` - Default: `#9F000000` +- __`USE_GROUND_SPEED`__ + - If enabled then Y velocity is not used in the final speed. + - Config Key: `use-ground-speed` + - Values + - Type: `Boolean` + - Default: `false` + +- __`USE_AVERAGE_VELOCITY`__ + - If this is disabled then instant velocity is used + - Config Key: `use-average-velocity` + - Values + - Type: `Boolean` + - Default: `false` + +- __`AVERAGING_PERIOD`__ + - Determines how many times a second velocity is calculated. Lower values will show a smoother velocity + - Config Key: `averaging-period` + - Values + - Type: `Integer` + - Default: `8` + - Minimum: `1` + - Maximum: `50` + diff --git a/docs/developers/mods/packdisplay.mdx b/docs/developers/mods/packdisplay.mdx index 56b1aaf3..6e8569fd 100644 --- a/docs/developers/mods/packdisplay.mdx +++ b/docs/developers/mods/packdisplay.mdx @@ -29,18 +29,6 @@ public void togglePackDisplayExample(Player viewer, boolean value) { - Minimum: `0.5F` - Maximum: `1.5F` -- __`PACK_ICON`__ - - Config Key: `pack-icon` - - Values - - Type: `Boolean` - - Default: `true` - -- __`PACK_DESCRIPTION`__ - - Config Key: `pack-description` - - Values - - Type: `Boolean` - - Default: `false` - - __`TEXT_SHADOW`__ - Config Key: `text-shadow` - Values @@ -114,3 +102,15 @@ public void togglePackDisplayExample(Player viewer, boolean value) { - Type: `String` - Default: `#9F000000` +- __`PACK_ICON`__ + - Config Key: `pack-icon` + - Values + - Type: `Boolean` + - Default: `true` + +- __`PACK_DESCRIPTION`__ + - Config Key: `pack-description` + - Values + - Type: `Boolean` + - Default: `false` + diff --git a/docs/developers/mods/ping.mdx b/docs/developers/mods/ping.mdx index 4d732478..571d303b 100644 --- a/docs/developers/mods/ping.mdx +++ b/docs/developers/mods/ping.mdx @@ -29,15 +29,6 @@ public void togglePingExample(Player viewer, boolean value) { - Minimum: `0.5F` - Maximum: `1.5F` -- __`UPDATE_INTERVAL_SEC`__ - - Faster updates may impact performance - - Config Key: `update-interval-sec` - - Values - - Type: `Integer` - - Default: `15` - - Minimum: `1` - - Maximum: `30` - - __`TEXT_SHADOW`__ - Config Key: `text-shadow` - Values @@ -111,3 +102,12 @@ public void togglePingExample(Player viewer, boolean value) { - Type: `String` - Default: `#9F000000` +- __`UPDATE_INTERVAL_SEC`__ + - Faster updates may impact performance + - Config Key: `update-interval-sec` + - Values + - Type: `Integer` + - Default: `15` + - Minimum: `1` + - Maximum: `30` + diff --git a/docs/developers/mods/serveraddress.mdx b/docs/developers/mods/serveraddress.mdx index 6ebf09aa..a47ac851 100644 --- a/docs/developers/mods/serveraddress.mdx +++ b/docs/developers/mods/serveraddress.mdx @@ -29,12 +29,6 @@ public void toggleServerAddressExample(Player viewer, boolean value) { - Minimum: `0.5F` - Maximum: `1.5F` -- __`SERVER_ICON`__ - - Config Key: `server-icon` - - Values - - Type: `Boolean` - - Default: `true` - - __`TEXT_SHADOW`__ - Config Key: `text-shadow` - Values @@ -108,3 +102,9 @@ public void toggleServerAddressExample(Player viewer, boolean value) { - Type: `String` - Default: `#9F000000` +- __`SERVER_ICON`__ + - Config Key: `server-icon` + - Values + - Type: `Boolean` + - Default: `true` + diff --git a/docs/developers/mods/skyblock.mdx b/docs/developers/mods/skyblock.mdx new file mode 100644 index 00000000..54daa243 --- /dev/null +++ b/docs/developers/mods/skyblock.mdx @@ -0,0 +1,131 @@ +# Hypixel Skyblock + +Various features to help in Hypixel Skyblock. + +## Integration + +### How to toggle the mod + +```java +public void toggleHypixelSkyblockExample(Player viewer, boolean value) { + Optional apolloPlayerOpt = Apollo.getPlayerManager().getPlayer(viewer.getUniqueId()); + apolloPlayerOpt.ifPresent(apolloPlayer -> this.modSettingModule.getOptions().set(apolloPlayer, ModSkyblock.ENABLED, value)); +} +``` + +## Available options + +- __`ENABLED`__ + - Config Key: `enabled` + - Values + - Type: `Boolean` + - Default: `false` + +- __`SKYBLOCK_ALERT_SCALE`__ + - Config Key: `skyblock-alert-scale` + - Values + - Type: `Float` + - Default: `1.0F` + - Minimum: `0.2F` + - Maximum: `2.5F` + +- __`SKYBLOCK_HIDE_HUNGER`__ + - Config Key: `skyblock-hide-hunger` + - Values + - Type: `Boolean` + - Default: `true` + +- __`SKYBLOCK_HIDE_ARMOR`__ + - Config Key: `skyblock-hide-armor` + - Values + - Type: `Boolean` + - Default: `true` + +- __`HIDE_MIDAS_STAFF`__ + - Config Key: `hide-midas-staff` + - Values + - Type: `Boolean` + - Default: `false` + +- __`HIDE_FALLING_BLOCKS`__ + - Config Key: `hide-falling-blocks` + - Values + - Type: `Boolean` + - Default: `false` + +- __`AUTO_COPY_RARE_DROPS`__ + - Automatically copies rare drops and pet drops to the clipboard. + - Config Key: `auto-copy-rare-drops` + - Values + - Type: `Boolean` + - Default: `false` + +- __`TALLER_CROPS`__ + - Changes crop hitboxes with their 1.12+ variant. Only enabled on Hypixel or singleplayer. + - Config Key: `taller-crops` + - Values + - Type: `Boolean` + - Default: `false` + +- __`FIX_LAVA_BOBBER`__ + - Fixes your fishing bobber sinking in lava. + - Config Key: `fix-lava-bobber` + - Values + - Type: `Boolean` + - Default: `false` + +- __`REPLACE_LAVA_WITH_WATER_CRIMSON`__ + - Changes the texture of lava to water in the Crimson Isles and Kuudra. + - Config Key: `replace-lava-with-water-crimson` + - Values + - Type: `Boolean` + - Default: `false` + +- __`REPLACE_LAVA_WITH_WATER_EVERYWHERE`__ + - Changes the texture of lava to water everywhere in SkyBlock. + - Config Key: `replace-lava-with-water-everywhere` + - Values + - Type: `Boolean` + - Default: `false` + +- __`SLAYER_BOSS_TIMER`__ + - Provides a chat message on boss kill that tells you how long it took to kill! + - Config Key: `slayer-boss-timer` + - Values + - Type: `Boolean` + - Default: `false` + +- __`SLAYER_MINI_BOSS_ALERT`__ + - Config Key: `slayer-mini-boss-alert` + - Values + - Type: `Boolean` + - Default: `false` + +- __`INACTIVE_EFFIGY_WAYPOINTS`__ + - Used in Stillgore of the Rift, this feature tells you where to go to refresh the duration of inactive Effigies. + - Config Key: `inactive-effigy-waypoints` + - Values + - Type: `Boolean` + - Default: `false` + +- __`VAMPIRE_STEAK_DISPLAY`__ + - Highlights a boss when it can be 1 tapped using steak stake. + - Config Key: `vampire-steak-display` + - Values + - Type: `Boolean` + - Default: `false` + +- __`VAMPIRE_ICHOR_DISPLAY`__ + - Highlights blood ichors present during T5 Bloodfiends + - Config Key: `vampire-ichor-display` + - Values + - Type: `Boolean` + - Default: `false` + +- __`GRAVITY_WELL_WAYPOINTS`__ + - Shows the positions where you can trap the gray blazes. + - Config Key: `gravity-well-waypoints` + - Values + - Type: `Boolean` + - Default: `false` + diff --git a/docs/developers/mods/stopwatch.mdx b/docs/developers/mods/stopwatch.mdx index 0270b2b6..db4e4c72 100644 --- a/docs/developers/mods/stopwatch.mdx +++ b/docs/developers/mods/stopwatch.mdx @@ -29,12 +29,6 @@ public void toggleStopwatchExample(Player viewer, boolean value) { - Minimum: `0.5F` - Maximum: `1.5F` -- __`RESET_EVERY_START`__ - - Config Key: `reset-every-start` - - Values - - Type: `Boolean` - - Default: `true` - - __`TEXT_SHADOW`__ - Config Key: `text-shadow` - Values @@ -108,3 +102,9 @@ public void toggleStopwatchExample(Player viewer, boolean value) { - Type: `String` - Default: `#9F000000` +- __`RESET_EVERY_START`__ + - Config Key: `reset-every-start` + - Values + - Type: `Boolean` + - Default: `true` + diff --git a/docs/developers/mods/zoom.mdx b/docs/developers/mods/zoom.mdx index 8a20dc9d..28ef70a8 100644 --- a/docs/developers/mods/zoom.mdx +++ b/docs/developers/mods/zoom.mdx @@ -58,3 +58,12 @@ public void toggleZoomExample(Player viewer, boolean value) { - Minimum: `2` - Maximum: `10` +- __`CAMERA_SENSITIVITY`__ + - Change the camera sensitivity when zoomed in. + - Config Key: `camera-sensitivity` + - Values + - Type: `Float` + - Default: `1.0F` + - Minimum: `0.1F` + - Maximum: `2.0F` + diff --git a/docs/developers/modules/hologram.mdx b/docs/developers/modules/hologram.mdx index aa35af62..7aa64d6b 100644 --- a/docs/developers/modules/hologram.mdx +++ b/docs/developers/modules/hologram.mdx @@ -20,7 +20,7 @@ public void displayHologramExample() { .id("welcome-hologram") .location(ApolloLocation.builder() .world("world") - .z(5) + .x(5) .y(105) .z(0) .build()) @@ -55,7 +55,7 @@ public void displayHologramExample() { ```java .location(ApolloLocation.builder() .world("world") - .z(5) + .x(5) .y(100) .z(0) .build() diff --git a/docs/server-owners/commands.mdx b/docs/server-owners/commands.mdx index a9f750e4..68977aa2 100644 --- a/docs/server-owners/commands.mdx +++ b/docs/server-owners/commands.mdx @@ -12,3 +12,14 @@ Apollo comes with some built-in commands to make your life easier. * `/apollo reload` * Description: Reload The Apollo Configuration Files. * Permission: `apollo.command` + + +* `/apollo update` + * Description: Forcefully updates Apollo to the latest version. + * Permission: `apollo.command` + + +* `/lunarclient ` + * Description: The command to check whether the player is using Lunar Client. + * Aliases: `lc` + * Permission: `apollo.lunarclient` diff --git a/gradle.properties b/gradle.properties index bb4ffab9..f818001d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ group=com.lunarclient -version=1.0.8 +version=1.0.9 description=The API for interacting with Lunar Client players. org.gradle.parallel=true diff --git a/velocity/src/main/java/com/lunarclient/apollo/ApolloVelocityPlatform.java b/velocity/src/main/java/com/lunarclient/apollo/ApolloVelocityPlatform.java index 588e7a75..411ce783 100644 --- a/velocity/src/main/java/com/lunarclient/apollo/ApolloVelocityPlatform.java +++ b/velocity/src/main/java/com/lunarclient/apollo/ApolloVelocityPlatform.java @@ -24,7 +24,8 @@ package com.lunarclient.apollo; import com.google.inject.Inject; -import com.lunarclient.apollo.command.ApolloCommand; +import com.lunarclient.apollo.command.impl.ApolloCommand; +import com.lunarclient.apollo.command.impl.LunarClientCommand; import com.lunarclient.apollo.listener.ApolloPlayerListener; import com.lunarclient.apollo.module.ApolloModuleManagerImpl; import com.lunarclient.apollo.module.beam.BeamModule; @@ -67,9 +68,8 @@ import com.lunarclient.apollo.option.Options; import com.lunarclient.apollo.option.OptionsImpl; import com.lunarclient.apollo.stats.ApolloStats; -import com.lunarclient.apollo.stats.ApolloStatsManager; -import com.lunarclient.apollo.version.ApolloVersionManager; import com.lunarclient.apollo.wrapper.VelocityApolloStats; +import com.velocitypowered.api.command.CommandManager; import com.velocitypowered.api.event.Subscribe; import com.velocitypowered.api.event.proxy.ProxyInitializeEvent; import com.velocitypowered.api.event.proxy.ProxyShutdownEvent; @@ -92,7 +92,7 @@ @Plugin( id = "apollo", name = "Apollo-Velocity", - version = "1.0.8", + version = "1.0.9", url = "https://moonsworth.com", description = "Implementation of Apollo for Velocity", authors = {"Moonsworth"} @@ -143,6 +143,11 @@ public ApolloStats getStats() { return this.stats; } + @Override + public Object getPlugin() { + return getInstance(); + } + /** * Handles initialization of the proxy. * @@ -177,9 +182,6 @@ public void onProxyInitialization(ProxyInitializeEvent event) { .addModule(VignetteModule.class, new VignetteModuleImpl()) .addModule(WaypointModule.class, new WaypointModuleImpl()); - ApolloStatsManager statsManager = new ApolloStatsManager(); - ApolloVersionManager versionManager = new ApolloVersionManager(); - try { ApolloManager.setConfigPath(this.dataDirectory); ApolloManager.loadConfiguration(); @@ -192,10 +194,12 @@ public void onProxyInitialization(ProxyInitializeEvent event) { this.server.getEventManager().register(this, new ApolloPlayerListener()); this.server.getChannelRegistrar().register(ApolloVelocityPlatform.PLUGIN_CHANNEL); - this.server.getCommandManager().register(ApolloCommand.create()); + CommandManager commandManager = this.server.getCommandManager(); + commandManager.register(ApolloCommand.create()); + commandManager.register(LunarClientCommand.create()); - statsManager.enable(); - versionManager.checkForUpdates(); + ApolloManager.getStatsManager().enable(); + ApolloManager.getVersionManager().checkForUpdates(); } /** diff --git a/velocity/src/main/java/com/lunarclient/apollo/command/VelocityApolloCommand.java b/velocity/src/main/java/com/lunarclient/apollo/command/VelocityApolloCommand.java new file mode 100644 index 00000000..14f01273 --- /dev/null +++ b/velocity/src/main/java/com/lunarclient/apollo/command/VelocityApolloCommand.java @@ -0,0 +1,74 @@ +/* + * This file is part of Apollo, licensed under the MIT License. + * + * Copyright (c) 2023 Moonsworth + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package com.lunarclient.apollo.command; + +import com.lunarclient.apollo.ApolloVelocityPlatform; +import com.velocitypowered.api.proxy.Player; +import java.util.Optional; +import java.util.function.BiConsumer; +import java.util.function.Consumer; +import lombok.NonNull; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; + +/** + * Provides common command functions for Velocity. + * + * @param the sender type + * @since 1.0.9 + */ +public abstract class VelocityApolloCommand extends AbstractApolloCommand { + + /** + * Returns a new instance of a Velocity command. + * + * @param textConsumer the consumer for sending messages to the sender + * @since 1.0.9 + */ + public VelocityApolloCommand(BiConsumer textConsumer) { + super(textConsumer); + } + + /** + * Handles a player argument; if the provided player doesn't exist, a not found message + * is sent to the sender. Otherwise, the player is passed to the provided player consumer. + * + * @param sender the command sender + * @param argument the argument passed from the command execution + * @param playerConsumer a consumer used for processing a desired action if the player is found + * @since 1.0.9 + */ + protected void handlePlayerArgument(@NonNull T sender, @NonNull String argument, @NonNull Consumer playerConsumer) { + Optional playerOpt = ApolloVelocityPlatform.getInstance().getServer().getPlayer(argument); + + if (!playerOpt.isPresent()) { + this.textConsumer.accept(sender, Component.text("Player '", NamedTextColor.RED) + .append(Component.text(argument, NamedTextColor.RED)) + .append(Component.text("' not found!", NamedTextColor.RED))); + return; + } + + playerConsumer.accept(playerOpt.get()); + } +} diff --git a/velocity/src/main/java/com/lunarclient/apollo/command/ApolloCommand.java b/velocity/src/main/java/com/lunarclient/apollo/command/impl/ApolloCommand.java similarity index 80% rename from velocity/src/main/java/com/lunarclient/apollo/command/ApolloCommand.java rename to velocity/src/main/java/com/lunarclient/apollo/command/impl/ApolloCommand.java index 279ca1bc..efb797a0 100644 --- a/velocity/src/main/java/com/lunarclient/apollo/command/ApolloCommand.java +++ b/velocity/src/main/java/com/lunarclient/apollo/command/impl/ApolloCommand.java @@ -21,8 +21,10 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package com.lunarclient.apollo.command; +package com.lunarclient.apollo.command.impl; +import com.lunarclient.apollo.ApolloManager; +import com.lunarclient.apollo.command.VelocityApolloCommand; import com.mojang.brigadier.Command; import com.mojang.brigadier.builder.LiteralArgumentBuilder; import com.velocitypowered.api.command.BrigadierCommand; @@ -36,7 +38,7 @@ * @since 1.0.5 */ @Getter -public final class ApolloCommand extends AbstractApolloCommand { +public final class ApolloCommand extends VelocityApolloCommand { /** * Returns a new instance of this command. @@ -54,6 +56,10 @@ public static BrigadierCommand create() { .executes(command.getReloadCommand()) .build() ) + .then(LiteralArgumentBuilder.literal("update") + .executes(command.getUpdateCommand()) + .build() + ) .build() ); } @@ -70,6 +76,15 @@ public static BrigadierCommand create() { return Command.SINGLE_SUCCESS; }; + private final Command updateCommand = context -> { + ApolloManager.getVersionManager().forceUpdate( + "velocity", + message -> this.textConsumer.accept(context.getSource(), message) + ); + + return Command.SINGLE_SUCCESS; + }; + ApolloCommand() { super(Audience::sendMessage); } diff --git a/velocity/src/main/java/com/lunarclient/apollo/command/impl/LunarClientCommand.java b/velocity/src/main/java/com/lunarclient/apollo/command/impl/LunarClientCommand.java new file mode 100644 index 00000000..d7b1e84f --- /dev/null +++ b/velocity/src/main/java/com/lunarclient/apollo/command/impl/LunarClientCommand.java @@ -0,0 +1,98 @@ +/* + * This file is part of Apollo, licensed under the MIT License. + * + * Copyright (c) 2023 Moonsworth + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package com.lunarclient.apollo.command.impl; + +import com.lunarclient.apollo.Apollo; +import com.lunarclient.apollo.command.VelocityApolloCommand; +import com.mojang.brigadier.Command; +import com.mojang.brigadier.arguments.StringArgumentType; +import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import com.mojang.brigadier.builder.RequiredArgumentBuilder; +import com.velocitypowered.api.command.BrigadierCommand; +import com.velocitypowered.api.command.CommandSource; +import lombok.Getter; +import net.kyori.adventure.audience.Audience; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; + +/** + * The general Lunar Client command. + * + * @since 1.0.9 + */ +@Getter +public final class LunarClientCommand extends VelocityApolloCommand { + + /** + * Returns a new instance of this command. + * + * @return a new command + * @since 1.0.9 + */ + public static BrigadierCommand create() { + LunarClientCommand command = new LunarClientCommand(); + + return new BrigadierCommand(LiteralArgumentBuilder.literal("lunarclient") + .executes(source -> { + command.sendCommandUsage(source.getSource()); + return Command.SINGLE_SUCCESS; + }) + .requires(source -> source.hasPermission("apollo.lunarclient")) + .then(RequiredArgumentBuilder.argument("player", StringArgumentType.word()) + .executes(command.getPlayerCommand()) + .build() + ) + .build() + ); + } + + private final Command playerCommand = context -> { + String argument = context.getArgument("player", String.class); + CommandSource source = context.getSource(); + + this.handlePlayerArgument(source, argument, player -> { + Component message = Component.text("Player ", NamedTextColor.GRAY) + .append(Component.text(player.getUsername(), NamedTextColor.AQUA)) + .append(Component.text(" is ", NamedTextColor.GRAY)); + + if (Apollo.getPlayerManager().hasSupport(player.getUniqueId())) { + message = message.append(Component.text("using ", NamedTextColor.GREEN)); + } else { + message = message.append(Component.text("not using ", NamedTextColor.RED)); + } + + message = message.append(Component.text("Lunar Client!", NamedTextColor.GRAY)); + this.textConsumer.accept(source, message); + }); + + return Command.SINGLE_SUCCESS; + }; + + LunarClientCommand() { + super(Audience::sendMessage); + + this.setUsage("/lunarclient "); + } + +} diff --git a/velocity/src/main/java/com/lunarclient/apollo/wrapper/VelocityApolloPlayer.java b/velocity/src/main/java/com/lunarclient/apollo/wrapper/VelocityApolloPlayer.java index 5b7318f2..c7aa4a17 100644 --- a/velocity/src/main/java/com/lunarclient/apollo/wrapper/VelocityApolloPlayer.java +++ b/velocity/src/main/java/com/lunarclient/apollo/wrapper/VelocityApolloPlayer.java @@ -28,6 +28,7 @@ import com.lunarclient.apollo.player.ApolloPlayer; import com.velocitypowered.api.proxy.Player; import java.util.UUID; +import lombok.Getter; import lombok.RequiredArgsConstructor; /** @@ -35,6 +36,7 @@ * * @since 1.0.0 */ +@Getter @RequiredArgsConstructor public final class VelocityApolloPlayer extends AbstractApolloPlayer {