Skip to content
Open
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 @@ -82,6 +82,11 @@ private void onApolloRegister(ApolloRegisterPlayerEvent event) {
for (CommandCosmetic spec : npc.getCosmetics()) {
cosmeticExample.equipNpcCosmeticToViewer(player, npc.getUuid(), spec);
}

PlayerNpc.ActiveEmote emote = npc.getActiveEmote();
if (emote != null && npc.getViewers().contains(player.getUniqueId())) {
cosmeticExample.startNpcEmoteToViewer(player, npc.getUuid(), emote.getEmoteId(), emote.getMetadata());
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,20 +175,62 @@ public void startNpcEmoteExample(Player viewer, UUID npcUuid) {
}

@Override
public void startNpcEmoteInternal(Player viewer, UUID npcUuid, int emoteId, int metadata) {
public void startNpcEmoteInternal(UUID npcUuid, int emoteId, int metadata) {
List<ApolloPlayer> viewers = this.getApolloViewers(npcUuid);
if (viewers.isEmpty()) {
return;
}

Emote emote = Emote.builder()
.id(emoteId)
.metadata(metadata)
.build();

this.cosmeticModule.startNpcEmote(Recipients.ofEveryone(), npcUuid, emote);
this.cosmeticModule.startNpcEmote(Recipients.of(viewers), npcUuid, emote);
}

@Override
public void startNpcEmoteToViewer(Player viewer, UUID npcUuid, int emoteId, int metadata) {
Apollo.getPlayerManager().getPlayer(viewer.getUniqueId()).ifPresent(apolloPlayer -> {
Emote emote = Emote.builder()
.id(emoteId)
.metadata(metadata)
.build();

this.cosmeticModule.startNpcEmote(apolloPlayer, npcUuid, emote);
});
}

@Override
public void stopNpcEmoteExample(Player viewer, UUID npcUuid) {
this.cosmeticModule.stopNpcEmote(Recipients.ofEveryone(), npcUuid);
}

@Override
public void stopNpcEmoteInternal(UUID npcUuid) {
List<ApolloPlayer> viewers = this.getApolloViewers(npcUuid);
if (viewers.isEmpty()) {
return;
}

this.cosmeticModule.stopNpcEmote(Recipients.of(viewers), npcUuid);
}

@Override
public void stopNpcEmoteToViewer(Player viewer, UUID npcUuid) {
Apollo.getPlayerManager().getPlayer(viewer.getUniqueId()).ifPresent(apolloPlayer ->
this.cosmeticModule.stopNpcEmote(apolloPlayer, npcUuid));
}

private List<ApolloPlayer> getApolloViewers(UUID npcUuid) {
List<ApolloPlayer> viewers = new ArrayList<>();
for (Player player : this.getNpcViewers(npcUuid)) {
Apollo.getPlayerManager().getPlayer(player.getUniqueId()).ifPresent(viewers::add);
}

return viewers;
}

@Override
public void resetNpcEmotesExample() {
this.cosmeticModule.resetNpcEmotes(Recipients.ofEveryone());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
import com.lunarclient.apollo.example.module.impl.VignetteExample;
import com.lunarclient.apollo.example.module.impl.WaypointExample;
import com.lunarclient.apollo.example.nms.NpcManager;
import com.lunarclient.apollo.example.nms.PlayerNpc;
import lombok.Getter;
import lombok.Setter;
import org.bukkit.plugin.java.JavaPlugin;
Expand Down Expand Up @@ -150,6 +151,13 @@ public void onEnable() {
this.registerCommands();
this.registerModuleExamples();
this.registerListeners();

this.npcManager.addViewerListener((viewer, npc) -> {
PlayerNpc.ActiveEmote emote = npc.getActiveEmote();
if (emote != null && this.cosmeticExample != null) {
this.cosmeticExample.startNpcEmoteToViewer(viewer, npc.getUuid(), emote.getEmoteId(), emote.getMetadata());
}
});
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,12 @@ private boolean handleEmote(Player player, CosmeticExample example, String[] arg
}
}

example.startNpcEmoteInternal(player, uuid, emoteId, metadata);
example.startNpcEmoteInternal(uuid, emoteId, metadata);

int emoteMetadata = metadata;
ApolloExamplePlugin.getInstance().getNpcManager().findByUuid(uuid)
.ifPresent(npc -> npc.setActiveEmote(new PlayerNpc.ActiveEmote(emoteId, emoteMetadata)));

player.sendMessage(ChatColor.GREEN + "Started emote " + emoteId + " on NPC " + args[2]);
break;
}
Expand All @@ -238,13 +243,22 @@ private boolean handleEmote(Player player, CosmeticExample example, String[] arg
return true;
}

example.stopNpcEmoteExample(player, uuid);
example.stopNpcEmoteInternal(uuid);

ApolloExamplePlugin.getInstance().getNpcManager().findByUuid(uuid)
.ifPresent(npc -> npc.setActiveEmote(null));

player.sendMessage(ChatColor.GREEN + "Stopped emote on NPC " + args[2]);
break;
}

case "reset": {
example.resetNpcEmotesExample();

for (PlayerNpc npc : ApolloExamplePlugin.getInstance().getNpcManager().getNpcs()) {
npc.setActiveEmote(null);
}

player.sendMessage(ChatColor.GREEN + "Reset all NPC emotes");
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
*/
package com.lunarclient.apollo.example.module.impl;

import com.lunarclient.apollo.example.ApolloExamplePlugin;
import com.lunarclient.apollo.example.module.ApolloModuleExample;
import com.lunarclient.apollo.example.nms.CommandCosmetic;
import java.util.Collections;
Expand Down Expand Up @@ -54,12 +55,30 @@ public void equipNpcCosmeticToViewer(Player viewer, UUID npcUuid, CommandCosmeti

public abstract void startNpcEmoteExample(Player viewer, UUID npcUuid);

public abstract void startNpcEmoteInternal(Player viewer, UUID npcUuid, int emoteId, int metadata);
public void startNpcEmoteInternal(UUID npcUuid, int emoteId, int metadata) {
for (Player viewer : this.getNpcViewers(npcUuid)) {
this.startNpcEmoteToViewer(viewer, npcUuid, emoteId, metadata);
}
}

public abstract void startNpcEmoteToViewer(Player viewer, UUID npcUuid, int emoteId, int metadata);

public abstract void stopNpcEmoteExample(Player viewer, UUID npcUuid);

public void stopNpcEmoteInternal(UUID npcUuid) {
for (Player viewer : this.getNpcViewers(npcUuid)) {
this.stopNpcEmoteToViewer(viewer, npcUuid);
}
}

public abstract void stopNpcEmoteToViewer(Player viewer, UUID npcUuid);

public abstract void resetNpcEmotesExample();

protected List<Player> getNpcViewers(UUID npcUuid) {
return ApolloExamplePlugin.getInstance().getNpcManager().getViewers(npcUuid);
}

public abstract void displaySprayExample(Player viewer, int sprayId);

public abstract void removeSprayExample(int sprayId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
import com.google.gson.JsonObject;
import com.lunarclient.apollo.example.ApolloExamplePlugin;
import com.lunarclient.apollo.example.json.util.JsonPacketUtil;
import com.lunarclient.apollo.example.module.impl.CosmeticExample;
import com.lunarclient.apollo.example.nms.CommandCosmetic;
import com.lunarclient.apollo.example.nms.PlayerNpc;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
Expand Down Expand Up @@ -81,6 +84,26 @@ private void onRegisterChannel(PlayerRegisterChannelEvent event) {

PLAYERS_RUNNING_APOLLO.add(player.getUniqueId());
player.sendMessage("You are using LunarClient!");

this.applyNpcCosmetics(player);
}

private void applyNpcCosmetics(Player player) {
CosmeticExample cosmeticExample = this.plugin.getCosmeticExample();
if (cosmeticExample == null) {
return;
}

for (PlayerNpc npc : this.plugin.getNpcManager().getNpcs()) {
for (CommandCosmetic spec : npc.getCosmetics()) {
cosmeticExample.equipNpcCosmeticToViewer(player, npc.getUuid(), spec);
}

PlayerNpc.ActiveEmote emote = npc.getActiveEmote();
if (emote != null && npc.getViewers().contains(player.getUniqueId())) {
cosmeticExample.startNpcEmoteToViewer(player, npc.getUuid(), emote.getEmoteId(), emote.getMetadata());
}
}
}

@EventHandler
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import com.lunarclient.apollo.example.json.util.JsonPacketUtil;
import com.lunarclient.apollo.example.json.util.JsonUtil;
import com.lunarclient.apollo.example.module.impl.CosmeticExample;
import com.lunarclient.apollo.example.nms.CommandCosmetic;
import java.time.Duration;
import java.util.List;
import java.util.UUID;
Expand Down Expand Up @@ -103,6 +104,56 @@ public void equipNpcCosmeticsInternal(Player viewer, UUID npcUuid, List<Integer>
JsonPacketUtil.broadcastPacket(message);
}

@Override
public void equipNpcCosmeticInternal(Player viewer, UUID npcUuid, CommandCosmetic cosmetic) {
JsonPacketUtil.broadcastPacket(this.createEquipMessage(npcUuid, cosmetic));
}

@Override
public void equipNpcCosmeticToViewer(Player viewer, UUID npcUuid, CommandCosmetic cosmetic) {
JsonPacketUtil.sendPacket(viewer, this.createEquipMessage(npcUuid, cosmetic));
}

private JsonObject createEquipMessage(UUID npcUuid, CommandCosmetic cosmetic) {
JsonObject cosmeticObject = new JsonObject();
cosmeticObject.addProperty("id", cosmetic.getId());

CommandCosmetic.Options options = cosmetic.getOptions();
if (options instanceof CommandCosmetic.Hat) {
CommandCosmetic.Hat hat = (CommandCosmetic.Hat) options;
JsonObject hatOptions = new JsonObject();
hatOptions.addProperty("show_over_helmet", hat.isShowOverHelmet());
hatOptions.addProperty("show_over_skin_layer", hat.isShowOverSkinLayer());
hatOptions.addProperty("height_offset", hat.getHeightOffset());
cosmeticObject.add("hat_options", hatOptions);
} else if (options instanceof CommandCosmetic.Cloak) {
JsonObject cloakOptions = new JsonObject();
cloakOptions.addProperty("use_cloth_physics", ((CommandCosmetic.Cloak) options).isUseClothPhysics());
cosmeticObject.add("cloak_options", cloakOptions);
} else if (options instanceof CommandCosmetic.Pet) {
JsonObject petOptions = new JsonObject();
petOptions.addProperty("flip_shoulder", ((CommandCosmetic.Pet) options).isFlipShoulder());
cosmeticObject.add("pet_options", petOptions);
} else if (options instanceof CommandCosmetic.Body) {
CommandCosmetic.Body body = (CommandCosmetic.Body) options;
JsonObject bodyOptions = new JsonObject();
bodyOptions.addProperty("show_over_chestplate", body.isShowOverChestplate());
bodyOptions.addProperty("show_over_leggings", body.isShowOverLeggings());
bodyOptions.addProperty("show_over_boots", body.isShowOverBoots());
cosmeticObject.add("body_options", bodyOptions);
}

JsonArray cosmeticsArray = new JsonArray();
cosmeticsArray.add(cosmeticObject);

JsonObject message = new JsonObject();
message.addProperty("@type", "type.googleapis.com/lunarclient.apollo.cosmetic.v1.EquipNpcCosmeticsMessage");
message.add("npc_uuid", JsonUtil.createUuidObject(npcUuid));
message.add("cosmetics", cosmeticsArray);

return message;
}

@Override
public void unequipNpcCosmeticsExample(Player viewer, UUID npcUuid) {
List<Integer> cosmeticIds = Lists.newArrayList(434, 3654, 5095, 3, 3977);
Expand Down Expand Up @@ -154,7 +205,7 @@ public void startNpcEmoteExample(Player viewer, UUID npcUuid) {
}

@Override
public void startNpcEmoteInternal(Player viewer, UUID npcUuid, int emoteId, int metadata) {
public void startNpcEmoteToViewer(Player viewer, UUID npcUuid, int emoteId, int metadata) {
JsonObject emote = new JsonObject();
emote.addProperty("id", emoteId);
emote.addProperty("metadata", metadata);
Expand All @@ -164,7 +215,7 @@ public void startNpcEmoteInternal(Player viewer, UUID npcUuid, int emoteId, int
message.add("npc_uuid", JsonUtil.createUuidObject(npcUuid));
message.add("emote", emote);

JsonPacketUtil.broadcastPacket(message);
JsonPacketUtil.sendPacket(viewer, message);
}

@Override
Expand All @@ -176,6 +227,15 @@ public void stopNpcEmoteExample(Player viewer, UUID npcUuid) {
JsonPacketUtil.broadcastPacket(message);
}

@Override
public void stopNpcEmoteToViewer(Player viewer, UUID npcUuid) {
JsonObject message = new JsonObject();
message.addProperty("@type", "type.googleapis.com/lunarclient.apollo.cosmetic.v1.StopNpcEmoteMessage");
message.add("npc_uuid", JsonUtil.createUuidObject(npcUuid));

JsonPacketUtil.sendPacket(viewer, message);
}

@Override
public void resetNpcEmotesExample() {
JsonObject message = new JsonObject();
Expand Down
Loading
Loading