Skip to content

Commit

Permalink
refactor: 👽 refactor uuid fields
Browse files Browse the repository at this point in the history
  • Loading branch information
RichardDorian committed Aug 30, 2022
1 parent 1083e9e commit 3b9167e
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 13 deletions.
16 changes: 11 additions & 5 deletions src/Player.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { parseUUID, UUID } from '@minecraft-js/uuid';
import {
LunarClientMod,
LunarClientPluginChannel,
Expand All @@ -24,7 +25,7 @@ export class LunarClientPlayer {
*/
public isConnected: boolean;
/** UUID for this player */
public uuid: string;
public uuid: UUID;
/**
* Plugin channel used to establish the
* connection, defaults to
Expand Down Expand Up @@ -86,7 +87,7 @@ export class LunarClientPlayer {
if (this.options?.channelAlreadyRegistered) this.isConnected = true;
else this.isConnected = false;

this.uuid = options?.playerUUID ?? '';
this.uuid = options?.playerUUID ?? null;
this.channel = this.options?.pluginChannel || LunarClientPluginChannel.NEW;

this.waypoints = [];
Expand Down Expand Up @@ -200,8 +201,13 @@ export class LunarClientPlayer {
* @param teammate Teammate UUID or teammate object
* @returns Whether or not this operation was successful
*/
public removeTeammate(teammate: string | TeammatePlayer): boolean {
teammate = typeof teammate === 'string' ? teammate : teammate.uuid;
public removeTeammate(teammate: string | UUID | TeammatePlayer): boolean {
teammate =
typeof teammate === 'string'
? parseUUID(teammate)
: teammate instanceof UUID
? teammate
: teammate.uuid;

if (!this.teammates.find((t) => t.uuid === teammate)) return false;
this.teammates = this.teammates.filter((t) => t.uuid !== teammate);
Expand Down Expand Up @@ -458,5 +464,5 @@ export interface LunarClientPlayerOptions {
* packet for the leader field
* @see [TeammatesPacket](./protocol/client/TeammatesPacket.ts)
*/
playerUUID?: string;
playerUUID?: UUID;
}
4 changes: 3 additions & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { UUID } from '@minecraft-js/uuid';

/**
* Plugin channels Lunar Client uses
* to establish the connection between
Expand Down Expand Up @@ -219,7 +221,7 @@ export interface Waypoint {

export interface TeammatePlayer {
/** UUID of the player */
uuid: string;
uuid: UUID;
/** X fallback value when the player is out of render distance */
x?: number;
/** Y fallback value when the player is out of render distance */
Expand Down
3 changes: 2 additions & 1 deletion src/protocol/server/VoiceChannelPacket.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { UUID } from '@minecraft-js/uuid';
import { Packet } from '../Packet';

export class VoiceChannelPacket extends Packet<VoiceChannel> {
Expand Down Expand Up @@ -33,7 +34,7 @@ export class VoiceChannelPacket extends Packet<VoiceChannel> {
*/
interface VoiceChannel {
/** UUID of the channel */
uuid: string;
uuid: UUID;
/** Name of the channel */
name: string;
players: { [key: string]: string };
Expand Down
3 changes: 2 additions & 1 deletion src/protocol/server/VoiceChannelRemovePacket.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { UUID } from '@minecraft-js/uuid';
import { Packet } from '../Packet';

export class VoiceChannelRemovePacket extends Packet<VoiceChannelRemove> {
Expand Down Expand Up @@ -26,5 +27,5 @@ export class VoiceChannelRemovePacket extends Packet<VoiceChannelRemove> {
*/
interface VoiceChannelRemove {
/** UUID of the channel */
uuid: string;
uuid: UUID;
}
5 changes: 3 additions & 2 deletions src/protocol/server/VoiceChannelUpdatePacket.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { UUID } from '@minecraft-js/uuid';
import { VoiceChannelUpdateStatus } from '../../constants';
import deprecatePacket from '../../util/deprecatePacket';
import { Packet } from '../Packet';
Expand Down Expand Up @@ -41,9 +42,9 @@ interface VoiceChannelUpdate {
/** Status of the channel */
status: VoiceChannelUpdateStatus;
/** UUID of the channel */
channelUuid: string;
channelUuid: UUID;
/** UUID of the player */
uuid: string;
uuid: UUID;
/** Name of the player */
name: string;
}
5 changes: 3 additions & 2 deletions src/protocol/server/VoicePacket.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { UUID } from '@minecraft-js/uuid';
import deprecatePacket from '../../util/deprecatePacket';
import { Packet } from '../Packet';

Expand All @@ -17,7 +18,7 @@ class _VoicePacket extends Packet<Voice> {

public read(): Voice {
const uuidsLength = this.buf.readVarInt();
const uuids: string[] = [];
const uuids: UUID[] = [];
for (let i = 0; i < uuidsLength; i++) uuids.push(this.buf.readUUID());

this.data = {
Expand All @@ -38,7 +39,7 @@ export const VoicePacket = deprecatePacket(_VoicePacket);
*/
interface Voice {
/** The UUID of all the senders */
uuids: string[];
uuids: UUID[];
/** The "smashed" bytes of all the voice */
data: number[];
}
3 changes: 2 additions & 1 deletion src/protocol/shared/EmoteBroadcastPacket.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { UUID } from '@minecraft-js/uuid';
import deprecatePacket from '../../util/deprecatePacket';
import { Packet } from '../Packet';

Expand Down Expand Up @@ -32,7 +33,7 @@ export const EmoteBroadcastPacket = deprecatePacket(_EmoteBroadcastPacket);
*/
interface EmoteBroadcast {
/** User doing the emote */
uuid: string;
uuid: UUID;
/** Emote they are doing */
emoteId: number;
}

0 comments on commit 3b9167e

Please sign in to comment.