Skip to content

Commit

Permalink
Start working on new mod settings implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
ItsNature committed Sep 25, 2023
1 parent a07a0dd commit 3b9e480
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 312 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -39,7 +40,7 @@ public final class ModLighting {
*
* @since 1.0.0
*/
public static final SimpleOption<Boolean> ENABLED = SimpleOption.<Boolean>builder()
public static final SimpleOption<Boolean> ENABLED = Option.<Boolean>builder()
.node("lighting", "enabled").type(TypeToken.get(Boolean.class))
.defaultValue(true)
.notifyClient()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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<ModSettings> MOD_SETTINGS = Option.<ModSettings>list()
.comment("A list of mod settings to send to the client.")
.node("settings").type(new TypeToken<List<ModSettings>>() {})
.defaultValue(new ArrayList<>(Collections.singletonList(SKYBLOCK_ADDONS_SETTING)))
.notifyClient()
.build();

ModSettingModule() {
this.registerOptions(MOD_SETTINGS);
}

@Override
public Collection<ApolloPlatform.Kind> getSupportedPlatforms() {
return Arrays.asList(ApolloPlatform.Kind.SERVER, ApolloPlatform.Kind.PROXY);
Expand All @@ -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);

}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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 <send|reset|broadcast>");
player.sendMessage("Usage: /modsettings <enable|disable>");
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 <send|reset|broadcast>");
player.sendMessage("Usage: /modsettings <enable|disable>");
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<ApolloPlayer> 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<ApolloPlayer> 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<ApolloPlayer> apolloPlayerOpt = Apollo.getPlayerManager().getPlayer(viewer.getUniqueId());
apolloPlayerOpt.ifPresent(apolloPlayer -> this.modSettingModule.getOptions().set(apolloPlayer, ModLighting.ENABLED, true));
}

}
Loading

0 comments on commit 3b9e480

Please sign in to comment.