diff --git a/api/src/main/java/com/lunarclient/apollo/mods/impl/ModLighting.java b/api/src/main/java/com/lunarclient/apollo/mods/impl/ModLighting.java index 352bfd0b..a75e9408 100644 --- a/api/src/main/java/com/lunarclient/apollo/mods/impl/ModLighting.java +++ b/api/src/main/java/com/lunarclient/apollo/mods/impl/ModLighting.java @@ -24,6 +24,7 @@ package com.lunarclient.apollo.mods.impl; import com.lunarclient.apollo.option.NumberOption; +import com.lunarclient.apollo.option.Option; import com.lunarclient.apollo.option.SimpleOption; import io.leangen.geantyref.TypeToken; @@ -39,7 +40,7 @@ public final class ModLighting { * * @since 1.0.0 */ - public static final SimpleOption ENABLED = SimpleOption.builder() + public static final SimpleOption ENABLED = Option.builder() .node("lighting", "enabled").type(TypeToken.get(Boolean.class)) .defaultValue(true) .notifyClient() diff --git a/api/src/main/java/com/lunarclient/apollo/module/modsetting/ModSettingModule.java b/api/src/main/java/com/lunarclient/apollo/module/modsetting/ModSettingModule.java index dcaceecd..0894197d 100644 --- a/api/src/main/java/com/lunarclient/apollo/module/modsetting/ModSettingModule.java +++ b/api/src/main/java/com/lunarclient/apollo/module/modsetting/ModSettingModule.java @@ -26,16 +26,9 @@ import com.lunarclient.apollo.ApolloPlatform; import com.lunarclient.apollo.module.ApolloModule; import com.lunarclient.apollo.module.ModuleDefinition; -import com.lunarclient.apollo.option.ListOption; -import com.lunarclient.apollo.option.Option; -import com.lunarclient.apollo.player.ApolloPlayer; -import io.leangen.geantyref.TypeToken; -import java.util.ArrayList; +import org.jetbrains.annotations.ApiStatus; import java.util.Arrays; import java.util.Collection; -import java.util.Collections; -import java.util.List; -import org.jetbrains.annotations.ApiStatus; /** * Represents the mod settings module. @@ -46,28 +39,6 @@ @ModuleDefinition(id = "mod_setting", name = "Mod Setting") public abstract class ModSettingModule extends ApolloModule { - private static final ModSettings SKYBLOCK_ADDONS_SETTING = ModSettings.builder() - .target("skyblockAddons") - .enable(false) - .properties(null) - .build(); - - /** - * A list of mod settings. - * - * @since 1.0.0 - */ - public static final ListOption MOD_SETTINGS = Option.list() - .comment("A list of mod settings to send to the client.") - .node("settings").type(new TypeToken>() {}) - .defaultValue(new ArrayList<>(Collections.singletonList(SKYBLOCK_ADDONS_SETTING))) - .notifyClient() - .build(); - - ModSettingModule() { - this.registerOptions(MOD_SETTINGS); - } - @Override public Collection getSupportedPlatforms() { return Arrays.asList(ApolloPlatform.Kind.SERVER, ApolloPlatform.Kind.PROXY); @@ -78,29 +49,4 @@ public boolean isClientNotify() { return true; } - /** - * Sends the {@link ModsSettings} to the {@link ApolloPlayer}. - * - * @param viewer the player who is receiving the packet - * @param settings the settings - * @since 1.0.0 - */ - public abstract void sendSettings(ApolloPlayer viewer, ModsSettings settings); - - /** - * Resets all {@link ModsSettings}s for the {@link ApolloPlayer}. - * - * @param viewer the player who is receiving the packet - * @since 1.0.0 - */ - public abstract void resetSettings(ApolloPlayer viewer); - - /** - * Sends the {@link ModsSettings} to all {@link ApolloPlayer}s. - * - * @param settings the settings - * @since 1.0.0 - */ - public abstract void broadcastSettings(ModsSettings settings); - } diff --git a/api/src/main/java/com/lunarclient/apollo/module/modsetting/ModSettings.java b/api/src/main/java/com/lunarclient/apollo/module/modsetting/ModSettings.java deleted file mode 100644 index ec55568e..00000000 --- a/api/src/main/java/com/lunarclient/apollo/module/modsetting/ModSettings.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * 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.module.modsetting; - -import java.util.Map; -import lombok.Builder; -import lombok.Getter; - -/** - * Represents a mods settings. - * - * @since 1.0.0 - */ -@Getter -@Builder -public final class ModSettings { - - /** - * Returns the configurable {@link String} target. - * - * @return the configurable target - * @since 1.0.0 - */ - String target; - - /** - * Returns the configurable {@link Boolean} enabled state. - * - * @return the enabled state - * @since 1.0.0 - */ - boolean enable; - - /** - * Returns the configurable properties {@link Map} that contains {@link String} - * option id as key and {@link Object} forced value as value. - * - * @return the properties map - * @since 1.0.0 - */ - Map properties; - -} diff --git a/api/src/main/java/com/lunarclient/apollo/module/modsetting/ModsSettings.java b/api/src/main/java/com/lunarclient/apollo/module/modsetting/ModsSettings.java deleted file mode 100644 index fffd25f7..00000000 --- a/api/src/main/java/com/lunarclient/apollo/module/modsetting/ModsSettings.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * 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.module.modsetting; - -import java.util.Set; -import lombok.Builder; -import lombok.Getter; - -/** - * Represents configurable settings. - * - * @since 1.0.0 - */ -@Getter -@Builder -public final class ModsSettings { - - /** - * Returns a {@link Set} of {@link ModSettings}s. - * - * @return the configurable set - * @since 1.0.0 - */ - Set settings; - -} diff --git a/bukkit-example/src/main/java/com/lunarclient/apollo/example/commands/ModSettingsCommand.java b/bukkit-example/src/main/java/com/lunarclient/apollo/example/commands/ModSettingsCommand.java index faafe282..7af6c47f 100644 --- a/bukkit-example/src/main/java/com/lunarclient/apollo/example/commands/ModSettingsCommand.java +++ b/bukkit-example/src/main/java/com/lunarclient/apollo/example/commands/ModSettingsCommand.java @@ -45,31 +45,25 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command Player player = (Player) sender; if (args.length != 1) { - player.sendMessage("Usage: /modsettings "); + player.sendMessage("Usage: /modsettings "); return true; } switch (args[0].toLowerCase()) { - case "send": { - this.modSettingsExample.sendSettingsExample(player); - player.sendMessage("Sending settings...."); + case "enable": { + this.modSettingsExample.enableLightningModExample(player); + player.sendMessage("Enabling lightning mod...."); break; } - case "reset": { - this.modSettingsExample.resetSettingsExample(player); - player.sendMessage("Resetting settings...."); - break; - } - - case "broadcast": { - this.modSettingsExample.broadcastSettingsExample(); - player.sendMessage("Broadcasting settings...."); + case "disable": { + this.modSettingsExample.disableLightningModExample(player); + player.sendMessage("Disabling lightning mod...."); break; } default: { - player.sendMessage("Usage: /modsettings "); + player.sendMessage("Usage: /modsettings "); break; } } diff --git a/bukkit-example/src/main/java/com/lunarclient/apollo/example/modules/ModSettingsExample.java b/bukkit-example/src/main/java/com/lunarclient/apollo/example/modules/ModSettingsExample.java index bf9e786d..56bd7ede 100644 --- a/bukkit-example/src/main/java/com/lunarclient/apollo/example/modules/ModSettingsExample.java +++ b/bukkit-example/src/main/java/com/lunarclient/apollo/example/modules/ModSettingsExample.java @@ -23,11 +23,9 @@ */ package com.lunarclient.apollo.example.modules; -import com.google.common.collect.Sets; import com.lunarclient.apollo.Apollo; +import com.lunarclient.apollo.mods.impl.ModLighting; import com.lunarclient.apollo.module.modsetting.ModSettingModule; -import com.lunarclient.apollo.module.modsetting.ModSettings; -import com.lunarclient.apollo.module.modsetting.ModsSettings; import com.lunarclient.apollo.player.ApolloPlayer; import java.util.Optional; import org.bukkit.entity.Player; @@ -36,31 +34,14 @@ public class ModSettingsExample { private final ModSettingModule modSettingModule = Apollo.getModuleManager().getModule(ModSettingModule.class); - private final ModsSettings settings = ModsSettings.builder() - .settings(Sets.newHashSet( - // Disables the SkyBlock Addons mod - ModSettings.builder() - .target("skyblockAddons") // The Mod ID you want to change - .enable(false) // If the mod can be enabled - .properties(null) - .build() - )) - .build(); - - public void sendSettingsExample(Player viewer) { - Optional apolloPlayerOpt = Apollo.getPlayerManager().getPlayer(viewer.getUniqueId()); - - // Sending the updated mod settings, "settings", built in the example above to the player. - apolloPlayerOpt.ifPresent(apolloPlayer -> this.modSettingModule.sendSettings(apolloPlayer, this.settings)); - } - - public void resetSettingsExample(Player viewer) { + public void disableLightningModExample(Player viewer) { Optional apolloPlayerOpt = Apollo.getPlayerManager().getPlayer(viewer.getUniqueId()); - apolloPlayerOpt.ifPresent(this.modSettingModule::resetSettings); + apolloPlayerOpt.ifPresent(apolloPlayer -> this.modSettingModule.getOptions().set(apolloPlayer, ModLighting.ENABLED, false)); } - public void broadcastSettingsExample() { - this.modSettingModule.broadcastSettings(this.settings); + public void enableLightningModExample(Player viewer) { + Optional apolloPlayerOpt = Apollo.getPlayerManager().getPlayer(viewer.getUniqueId()); + apolloPlayerOpt.ifPresent(apolloPlayer -> this.modSettingModule.getOptions().set(apolloPlayer, ModLighting.ENABLED, true)); } } diff --git a/common/src/main/java/com/lunarclient/apollo/module/modsetting/ModSettingModuleImpl.java b/common/src/main/java/com/lunarclient/apollo/module/modsetting/ModSettingModuleImpl.java index 32aacfe1..53874b63 100644 --- a/common/src/main/java/com/lunarclient/apollo/module/modsetting/ModSettingModuleImpl.java +++ b/common/src/main/java/com/lunarclient/apollo/module/modsetting/ModSettingModuleImpl.java @@ -23,116 +23,11 @@ */ package com.lunarclient.apollo.module.modsetting; -import com.google.protobuf.Value; -import com.lunarclient.apollo.Apollo; -import com.lunarclient.apollo.configurable.v1.ConfigurableSettings; -import com.lunarclient.apollo.configurable.v1.OverrideConfigurableSettingsMessage; -import com.lunarclient.apollo.option.config.Serializer; -import com.lunarclient.apollo.player.AbstractApolloPlayer; -import com.lunarclient.apollo.player.ApolloPlayer; -import java.lang.reflect.Type; -import java.util.AbstractMap; -import java.util.Map; -import java.util.Set; -import java.util.stream.Collectors; -import lombok.NonNull; -import org.checkerframework.checker.nullness.qual.Nullable; -import org.spongepowered.configurate.ConfigurationNode; -import org.spongepowered.configurate.serialize.SerializationException; -import org.spongepowered.configurate.serialize.TypeSerializer; - /** * Provides the mod settings module. * * @since 1.0.0 */ -public final class ModSettingModuleImpl extends ModSettingModule implements Serializer { - - /** - * Creates a new instance of {@link ModSettingModuleImpl}. - * - * @since 1.0.0 - */ - public ModSettingModuleImpl() { - super(); - this.serializer(ModSettings.class, new ModSettingSerializer()); - } - - @Override - public void sendSettings(@NonNull ApolloPlayer viewer, @NonNull ModsSettings settings) { - ((AbstractApolloPlayer) viewer).sendPacket(this.toProtobuf(settings)); - } - - @Override - public void resetSettings(@NonNull ApolloPlayer viewer) { - ((AbstractApolloPlayer) viewer).sendPacket(OverrideConfigurableSettingsMessage.getDefaultInstance()); - } - - @Override - public void broadcastSettings(@NonNull ModsSettings settings) { - OverrideConfigurableSettingsMessage message = this.toProtobuf(settings); - - for (ApolloPlayer player : Apollo.getPlayerManager().getPlayers()) { - ((AbstractApolloPlayer) player).sendPacket(message); - } - } - - private OverrideConfigurableSettingsMessage toProtobuf(ModsSettings settings) { - Set configurableSettings = settings.getSettings().stream() - .map(configurable -> { - ConfigurableSettings.Builder builder = ConfigurableSettings.newBuilder() - .setLunarClientMod(configurable.getTarget()) - .setEnable(configurable.isEnable()); - - Map properties = configurable.getProperties(); - - if(properties != null) { - Map protoProperties = properties.entrySet().stream() - .collect(Collectors.toMap( - Map.Entry::getKey, - entry -> (Value) entry.getValue() - )); - - builder.putAllProperties(protoProperties); - } - - return builder.build(); - }) - .collect(Collectors.toSet()); - - return OverrideConfigurableSettingsMessage.newBuilder() - .addAllConfigurableSettings(configurableSettings) - .build(); - } - - private static final class ModSettingSerializer implements TypeSerializer { - @Override - public ModSettings deserialize(Type type, ConfigurationNode node) throws SerializationException { - return ModSettings.builder() - .target(node.node("target").getString()) - .enable(node.node("enable").getBoolean()) - .properties(node.node("properties").childrenMap().entrySet().stream() - .filter(entry -> entry.getKey() instanceof String && !entry.getValue().virtual()) - .map(entry -> new AbstractMap.SimpleEntry<>((String) entry.getKey(), entry.getValue().raw())) - .collect(Collectors.toMap( - AbstractMap.SimpleEntry::getKey, - AbstractMap.SimpleEntry::getValue - ))) - .build(); - } - - @Override - public void serialize(Type type, @Nullable ModSettings settings, ConfigurationNode node) throws SerializationException { - if(settings == null) { - node.raw(null); - return; - } - - node.node("target").set(String.class, settings.getTarget()); - node.node("enable").set(settings.isEnable()); - node.node("properties").set(settings.getProperties()); - } - - } +public final class ModSettingModuleImpl extends ModSettingModule { }