Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@

import com.lunarclient.apollo.module.ApolloModule;
import com.lunarclient.apollo.module.ModuleDefinition;
import com.lunarclient.apollo.option.Option;
import com.lunarclient.apollo.option.SimpleOption;
import com.lunarclient.apollo.recipients.Recipients;
import io.leangen.geantyref.TypeToken;
import java.awt.Color;
import java.util.UUID;
import org.jetbrains.annotations.ApiStatus;
Expand All @@ -39,6 +42,22 @@
@ModuleDefinition(id = "colored_fire", name = "Colored Fire")
public abstract class ColoredFireModule extends ApolloModule {

/**
* Whether fire colors should persist when a player unloads from the tracker.
*
* @since 1.2.7
*/
public static final SimpleOption<Boolean> PERSIST_COLORS_ON_UNLOAD = Option.<Boolean>builder()
.comment("Set to 'true' to keep fire colors when players unload from the tracker, otherwise 'false'.")
.node("persist-colors-on-unload").type(TypeToken.get(Boolean.class))
.defaultValue(false).notifyClient().build();

ColoredFireModule() {
this.registerOptions(
ColoredFireModule.PERSIST_COLORS_ON_UNLOAD
);
}

@Override
public boolean isClientNotify() {
return true;
Expand Down
1 change: 1 addition & 0 deletions docs/developers/lightweight/json/packet-util.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ private static final Table<String, String, Object> CONFIG_MODULE_PROPERTIES = Ha
static {
// Module Options the client needs to be notified about. These properties are sent with the enable module packet.
// While using the Apollo plugin this would be equivalent to modifying the config.yml
CONFIG_MODULE_PROPERTIES.put("colored_fire", "persist-colors-on-unload", false);
CONFIG_MODULE_PROPERTIES.put("combat", "disable-miss-penalty", false);
CONFIG_MODULE_PROPERTIES.put("packet_enrichment", "player-attack.send-packet", false);
CONFIG_MODULE_PROPERTIES.put("packet_enrichment", "player-chat-open.send-packet", false);
Expand Down
1 change: 1 addition & 0 deletions docs/developers/lightweight/protobuf/packet-util.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ private static final Table<String, String, Value> CONFIG_MODULE_PROPERTIES = Has
static {
// Module Options the client needs to be notified about. These properties are sent with the enable module packet.
// While using the Apollo plugin this would be equivalent to modifying the config.yml
CONFIG_MODULE_PROPERTIES.put("colored_fire", "persist-colors-on-unload", Value.newBuilder().setBoolValue(false).build());
CONFIG_MODULE_PROPERTIES.put("combat", "disable-miss-penalty", Value.newBuilder().setBoolValue(false).build());
CONFIG_MODULE_PROPERTIES.put("packet_enrichment", "player-attack.send-packet", Value.newBuilder().setBoolValue(false).build());
CONFIG_MODULE_PROPERTIES.put("packet_enrichment", "player-chat-open.send-packet", Value.newBuilder().setBoolValue(false).build());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@
import com.lunarclient.apollo.example.module.impl.CooldownExample;
import com.lunarclient.apollo.example.module.impl.CosmeticExample;
import com.lunarclient.apollo.example.module.impl.ServerLinkExample;
import com.lunarclient.apollo.example.nms.CommandCosmetic;
import com.lunarclient.apollo.example.nms.NpcManager;
import com.lunarclient.apollo.example.nms.PlayerNpc;
import com.lunarclient.apollo.player.ApolloPlayer;
import java.util.Optional;
import org.bukkit.entity.Player;

public class ApolloPlayerApiListener implements ApolloListener {
Expand Down Expand Up @@ -79,8 +79,11 @@ private void onApolloRegister(ApolloRegisterPlayerEvent event) {
CosmeticExample cosmeticExample = this.example.getCosmeticExample();
NpcManager npcManager = this.example.getNpcManager();

Optional<PlayerNpc> npc = npcManager.findByName("Apollo");
npc.ifPresent(playerNpc -> cosmeticExample.equipNpcCosmeticsExample(player, playerNpc.getUuid()));
for (PlayerNpc npc : npcManager.getNpcs()) {
for (CommandCosmetic spec : npc.getCosmetics()) {
cosmeticExample.equipNpcCosmeticToViewer(player, npc.getUuid(), spec);
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,14 @@
import com.lunarclient.apollo.Apollo;
import com.lunarclient.apollo.common.location.ApolloBlockLocation;
import com.lunarclient.apollo.example.module.impl.CosmeticExample;
import com.lunarclient.apollo.example.nms.CommandCosmetic;
import com.lunarclient.apollo.module.cosmetic.Cosmetic;
import com.lunarclient.apollo.module.cosmetic.CosmeticModule;
import com.lunarclient.apollo.module.cosmetic.Spray;
import com.lunarclient.apollo.module.cosmetic.options.BodyOptions;
import com.lunarclient.apollo.module.cosmetic.options.CloakOptions;
import com.lunarclient.apollo.module.cosmetic.options.CosmeticOptions;
import com.lunarclient.apollo.module.cosmetic.options.HatOptions;
import com.lunarclient.apollo.module.cosmetic.options.PetOptions;
import com.lunarclient.apollo.module.packetenrichment.raytrace.Direction;
import com.lunarclient.apollo.player.ApolloPlayer;
Expand Down Expand Up @@ -87,6 +91,54 @@ public void equipNpcCosmeticsInternal(Player viewer, UUID npcUuid, List<Integer>
this.cosmeticModule.equipNpcCosmetics(Recipients.ofEveryone(), npcUuid, cosmetics);
}

@Override
public void equipNpcCosmeticInternal(Player viewer, UUID npcUuid, CommandCosmetic spec) {
this.cosmeticModule.equipNpcCosmetics(Recipients.ofEveryone(), npcUuid, Lists.newArrayList(this.toApiCosmetic(spec)));
}

@Override
public void equipNpcCosmeticToViewer(Player viewer, UUID npcUuid, CommandCosmetic spec) {
Apollo.getPlayerManager().getPlayer(viewer.getUniqueId()).ifPresent(apolloPlayer ->
this.cosmeticModule.equipNpcCosmetics(apolloPlayer, npcUuid, Lists.newArrayList(this.toApiCosmetic(spec))));
}

private Cosmetic toApiCosmetic(CommandCosmetic spec) {
return Cosmetic.builder()
.id(spec.getId())
.options(this.toApiOptions(spec.getOptions()))
.build();
}

private CosmeticOptions toApiOptions(CommandCosmetic.Options options) {
if (options instanceof CommandCosmetic.Hat) {
CommandCosmetic.Hat hat = (CommandCosmetic.Hat) options;
return HatOptions.builder()
.showOverHelmet(hat.isShowOverHelmet())
.showOverSkinLayer(hat.isShowOverSkinLayer())
.heightOffset(hat.getHeightOffset())
.build();
} else if (options instanceof CommandCosmetic.Cloak) {
CommandCosmetic.Cloak cloak = (CommandCosmetic.Cloak) options;
return CloakOptions.builder()
.useClothPhysics(cloak.isUseClothPhysics())
.build();
} else if (options instanceof CommandCosmetic.Pet) {
CommandCosmetic.Pet pet = (CommandCosmetic.Pet) options;
return PetOptions.builder()
.flipShoulder(pet.isFlipShoulder())
.build();
} else if (options instanceof CommandCosmetic.Body) {
CommandCosmetic.Body body = (CommandCosmetic.Body) options;
return BodyOptions.builder()
.showOverChestplate(body.isShowOverChestplate())
.showOverLeggings(body.isShowOverLeggings())
.showOverBoots(body.isShowOverBoots())
.build();
}

return null;
}

@Override
public void unequipNpcCosmeticsExample(Player viewer, UUID npcUuid) {
Optional<ApolloPlayer> apolloPlayerOpt = Apollo.getPlayerManager().getPlayer(viewer.getUniqueId());
Expand Down
1 change: 1 addition & 0 deletions example/bukkit/api/src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ folia-supported: true
commands:
npc:
description: "NPCs!"
aliases: [apollonpc]
apollodebug:
description: "Apollo Debug!"
modstatus:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public void onEnable() {
@Override
public void onDisable() {
if (this.npcManager != null) {
this.npcManager.removeAll();
this.npcManager.despawnAll();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,17 @@

import com.lunarclient.apollo.example.ApolloExamplePlugin;
import com.lunarclient.apollo.example.module.impl.CosmeticExample;
import com.lunarclient.apollo.example.nms.CommandCosmetic;
import com.lunarclient.apollo.example.nms.PlayerNpc;
import com.lunarclient.apollo.example.util.CommandUtil;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.UUID;
import java.util.stream.Collectors;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
Expand Down Expand Up @@ -82,21 +88,31 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command

switch (args[0].toLowerCase()) {
case "equip": {
if (args.length >= 3 && this.isCosmeticType(args[2])) {
this.handleTypedEquip(player, example, uuid, npcName, args);
break;
}

List<Integer> cosmeticIds = this.parseCosmeticIds(args);
example.equipNpcCosmeticsInternal(player, uuid, cosmeticIds);
this.persistEquipped(uuid, cosmeticIds.stream()
.map(id -> CommandCosmetic.builder().id(id).build())
.collect(Collectors.toList()));
player.sendMessage(ChatColor.GREEN + "Equipped cosmetics " + cosmeticIds + " on NPC " + npcName);
break;
}

case "unequip": {
List<Integer> cosmeticIds = this.parseCosmeticIds(args);
example.unequipNpcCosmeticsInternal(player, uuid, cosmeticIds);
this.persistUnequipped(uuid, cosmeticIds);
player.sendMessage(ChatColor.GREEN + "Unequipped cosmetics " + cosmeticIds + " from NPC " + npcName);
break;
}

case "reset": {
example.resetNpcCosmeticsExample(player, uuid);
this.persistReset(uuid);
player.sendMessage(ChatColor.GREEN + "Reset all cosmetics on NPC " + npcName);
break;
}
Expand Down Expand Up @@ -170,6 +186,125 @@ private boolean handleSpray(Player player, CosmeticExample example, String[] arg
return true;
}

private boolean isCosmeticType(String type) {
String lower = type.toLowerCase();
return "hat".equals(lower) || "cloak".equals(lower) || "pet".equals(lower) || "body".equals(lower);
}

private void handleTypedEquip(Player player, CosmeticExample example, UUID uuid, String npcName, String[] args) {
if (args.length < 4) {
this.sendUsage(player);
return;
}

int cosmeticId;
try {
cosmeticId = Integer.parseInt(args[3]);
} catch (NumberFormatException ex) {
player.sendMessage(ChatColor.RED + "Cosmetic id must be an integer.");
return;
}

Map<String, String> options = this.parseOptions(args, 4);
String type = args[2].toLowerCase();

CommandCosmetic.Options optionsSpec;
switch (type) {
case "hat": {
optionsSpec = CommandCosmetic.Hat.builder()
.showOverHelmet(CommandUtil.parseBoolean(options.get("showoverhelmet"), true))
.showOverSkinLayer(CommandUtil.parseBoolean(options.get("showoverskinlayer"), true))
.heightOffset(CommandUtil.parseFloat(options.get("heightoffset"), 0f))
.build();
break;
}
case "cloak": {
optionsSpec = CommandCosmetic.Cloak.builder()
.useClothPhysics(CommandUtil.parseBoolean(options.get("useclothphysics"), false))
.build();
break;
}
case "pet": {
optionsSpec = CommandCosmetic.Pet.builder()
.flipShoulder(CommandUtil.parseBoolean(options.get("flipshoulder"), false))
.build();
break;
}
case "body": {
optionsSpec = CommandCosmetic.Body.builder()
.showOverChestplate(CommandUtil.parseBoolean(options.get("showoverchestplate"), true))
.showOverLeggings(CommandUtil.parseBoolean(options.get("showoverleggings"), true))
.showOverBoots(CommandUtil.parseBoolean(options.get("showoverboots"), true))
.build();
break;
}
default: {
this.sendUsage(player);
return;
}
}

CommandCosmetic spec = CommandCosmetic.builder()
.id(cosmeticId)
.options(optionsSpec)
.build();

example.equipNpcCosmeticInternal(player, uuid, spec);
this.persistEquipped(uuid, Collections.singletonList(spec));
player.sendMessage(ChatColor.GREEN + "Equipped " + type + " cosmetic " + cosmeticId + " on NPC " + npcName);
}

private void persistEquipped(UUID npcUuid, List<CommandCosmetic> equipped) {
Optional<PlayerNpc> npcOpt = ApolloExamplePlugin.getInstance().getNpcManager().findByUuid(npcUuid);
if (!npcOpt.isPresent()) {
return;
}

List<CommandCosmetic> cosmetics = npcOpt.get().getCosmetics();
for (CommandCosmetic cosmetic : equipped) {
cosmetics.removeIf(existing -> existing.getId() == cosmetic.getId());
cosmetics.add(cosmetic);
}

ApolloExamplePlugin.getInstance().getNpcManager().save();
}

private void persistUnequipped(UUID npcUuid, List<Integer> cosmeticIds) {
Optional<PlayerNpc> npcOpt = ApolloExamplePlugin.getInstance().getNpcManager().findByUuid(npcUuid);
if (!npcOpt.isPresent()) {
return;
}

npcOpt.get().getCosmetics().removeIf(cosmetic -> cosmeticIds.contains(cosmetic.getId()));
ApolloExamplePlugin.getInstance().getNpcManager().save();
}

private void persistReset(UUID npcUuid) {
Optional<PlayerNpc> npcOpt = ApolloExamplePlugin.getInstance().getNpcManager().findByUuid(npcUuid);
if (!npcOpt.isPresent()) {
return;
}

npcOpt.get().getCosmetics().clear();
ApolloExamplePlugin.getInstance().getNpcManager().save();
}

private Map<String, String> parseOptions(String[] args, int startIndex) {
Map<String, String> options = new HashMap<>();
for (int i = startIndex; i < args.length; i++) {
String token = args[i];
int index = token.indexOf('=');

if (index <= 0 || index == token.length() - 1) {
continue;
}

options.put(token.substring(0, index).toLowerCase(), token.substring(index + 1));
}

return options;
}

private List<Integer> parseCosmeticIds(String[] args) {
List<Integer> ids = new ArrayList<>();
for (int i = 2; i < args.length; i++) {
Expand All @@ -184,8 +319,26 @@ private List<Integer> parseCosmeticIds(String[] args) {
private void sendUsage(Player player) {
player.sendMessage("Usage:");
player.sendMessage(" - /cosmetic equip <npc_name> [cosmeticIds]");
player.sendMessage(ChatColor.ITALIC + " /cosmetic equip Apollo 434 3654 3977");
player.sendMessage("");
player.sendMessage(" - /cosmetic equip <npc_name> hat <id>");
player.sendMessage(ChatColor.ITALIC + " /cosmetic equip Apollo hat 434 showOverHelmet=true showOverSkinLayer=true heightOffset=0.0");
player.sendMessage("");
player.sendMessage(" - /cosmetic equip <npc_name> cloak <id>");
player.sendMessage(ChatColor.ITALIC + " /cosmetic equip Apollo cloak 3 useClothPhysics=true");
player.sendMessage("");
player.sendMessage(" - /cosmetic equip <npc_name> pet <id>");
player.sendMessage(ChatColor.ITALIC + " /cosmetic equip Apollo pet 5095 flipShoulder=true");
player.sendMessage("");
player.sendMessage(" - /cosmetic equip <npc_name> body <id>");
player.sendMessage(ChatColor.ITALIC + " /cosmetic equip Apollo body 3977 showOverChestplate=true showOverLeggings=true showOverBoots=true");
player.sendMessage("");
player.sendMessage(" - /cosmetic unequip <npc_name> [cosmeticIds]");
player.sendMessage(ChatColor.ITALIC + " /cosmetic unequip Apollo 434 3654");
player.sendMessage("");
player.sendMessage(" - /cosmetic reset <npc_name>");
player.sendMessage(ChatColor.ITALIC + " /cosmetic reset Apollo");
player.sendMessage("");
this.sendSprayUsage(player);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,17 +86,6 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
break;
}

case "reset": {
if (npcManager.getNpcs().isEmpty()) {
player.sendMessage(ChatColor.YELLOW + "There are no NPCs to remove.");
break;
}

npcManager.removeAll();
player.sendMessage(ChatColor.GREEN + "Removed all tracked NPCs.");
break;
}

default: {
this.sendUsage(player);
break;
Expand All @@ -109,7 +98,6 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
private void sendUsage(Player player) {
player.sendMessage("Usage: /npc spawn <name>");
player.sendMessage("Usage: /npc remove <name>");
player.sendMessage("Usage: /npc reset");
}

}
Loading
Loading