Added support for LabyMod EmoteAPI.

This commit is contained in:
Jitse Boonstra
2020-04-12 17:01:18 +02:00
parent 8e661b024e
commit 33a8615aad
18 changed files with 198 additions and 21 deletions
@@ -101,7 +101,7 @@ public interface NPC {
* @return Object instance.
*/
NPC toggleState(NPCState state);
/**
* Get state of NPC.
*
@@ -120,14 +120,14 @@ public interface NPC {
NPC setItem(NPCSlot slot, ItemStack item);
NPC setText(List<String> text);
/**
* Get the text of an NPC
*
* @return List<String> text
*/
List<String> getText();
/**
* Get a NPC's item.
*
@@ -135,4 +135,14 @@ public interface NPC {
* @return ItemStack item.
*/
ItemStack getItem(NPCSlot slot);
/**
* LABYMOD ONLY
* Let the NPC play an emote.
* (https://docs.labymod.net/pages/server/emote_api/)
*
* @param receiver The player who should see the emote.
* @param emoteId The emote id (see link).
*/
void forceLabyModEmote(Player receiver, int emoteId);
}
@@ -4,6 +4,8 @@
package net.jitse.npclib.internal;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.mojang.authlib.GameProfile;
import com.mojang.authlib.properties.Property;
import net.jitse.npclib.NPCLib;
@@ -14,6 +16,7 @@ import net.jitse.npclib.api.skin.Skin;
import net.jitse.npclib.api.state.NPCSlot;
import net.jitse.npclib.api.state.NPCState;
import net.jitse.npclib.hologram.Hologram;
import net.labymod.utilities.LMCUtils;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
@@ -25,10 +28,7 @@ import java.util.*;
public abstract class NPCBase implements NPC, NPCPacketHandler {
protected final UUID uuid = UUID.randomUUID();
protected final int entityId = Integer.MAX_VALUE - NPCManager.getAllNPCs().size();
protected final String name = uuid.toString().replace("-", "").substring(0, 10);
protected final GameProfile gameProfile = new GameProfile(uuid, name);
protected final Set<UUID> hasTeamRegistered = new HashSet<>();
protected final Set<NPCState> activeStates = EnumSet.noneOf(NPCState.class);
@@ -36,6 +36,11 @@ public abstract class NPCBase implements NPC, NPCPacketHandler {
private final Set<UUID> autoHidden = new HashSet<>();
protected double cosFOV = Math.cos(Math.toRadians(60));
// 12/4/20, JMB: Changed the UUID in order to enable LabyMod Emotes:
// This gives a format similar to: 528086a2-4f5f-2ec2-0000-000000000000
protected UUID uuid = new UUID(new Random().nextLong(), 0);
protected String name = uuid.toString().replace("-", "").substring(0, 10);
protected GameProfile gameProfile = new GameProfile(uuid, name);
protected NPCLib instance;
protected List<String> text;
@@ -86,6 +91,16 @@ public abstract class NPCBase implements NPC, NPCPacketHandler {
}
}
@Override
public void forceLabyModEmote(Player receiver, int emoteId) {
JsonArray array = new JsonArray();
JsonObject forcedEmote = new JsonObject();
forcedEmote.addProperty("uuid", uuid.toString());
forcedEmote.addProperty("emote_id", emoteId);
array.add(forcedEmote);
LMCUtils.sendLMCMessage(receiver, "emote_api", array.getAsJsonObject());
}
public void disableFOV() {
this.cosFOV = 0; // Or equals Math.cos(1/2 * Math.PI).
}