Skip to content
Merged
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* This file is part of Apollo, licensed under the MIT License.
*
* Copyright (c) 2026 Moonsworth
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.lunarclient.apollo.common.icon;

import lombok.Builder;
import lombok.Getter;

/**
* Represents a resource location icon.
*
* @since 1.2.5
*/
@Getter
@Builder
public final class ResourceLocationIcon extends Icon {

/**
* Returns the icon {@link String} resource location.
*
* <p>Represents a path to an icon that will appear for the player.</p>
*
* @return the icon resource location
* @since 1.2.5
*/
String resourceLocation;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* This file is part of Apollo, licensed under the MIT License.
*
* Copyright (c) 2026 Moonsworth
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.lunarclient.apollo.module.serverlink;

import lombok.Builder;
import lombok.Getter;
import net.kyori.adventure.text.Component;

/**
* Represents a link entry displayed in the Server Links menu.
*
* @since 1.2.5
*/
@Getter
@Builder
public final class ServerLink {

/**
* Returns the server link {@link String} id.
*
* @return the server link id
* @since 1.2.5
*/
String id;

/**
* Returns the server link {@link Component} display name.
*
* @return the server link display name
* @since 1.2.5
*/
Component displayName;

/**
* Returns the server link {@link String} url.
*
* @return the server link url
* @since 1.2.5
*/
String url;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
/*
* This file is part of Apollo, licensed under the MIT License.
*
* Copyright (c) 2026 Moonsworth
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.lunarclient.apollo.module.serverlink;

import com.lunarclient.apollo.common.icon.ResourceLocationIcon;
import com.lunarclient.apollo.module.ApolloModule;
import com.lunarclient.apollo.module.ModuleDefinition;
import com.lunarclient.apollo.recipients.Recipients;
import java.util.List;
import org.jetbrains.annotations.ApiStatus;

/**
* Represents the server links module.
*
* <p>This module provides support for the Server Links feature introduced in
* Minecraft 1.21.0, with compatibility extending down to version 1.7.</p>
*
* @since 1.2.5
*/
@ApiStatus.NonExtendable
@ModuleDefinition(id = "server_link", name = "Server Link")
public abstract class ServerLinkModule extends ApolloModule {

/**
* Overrides the server link menu title image for the {@link Recipients}.
*
* <p>The provided {@link ResourceLocationIcon} will be displayed in place of the default
* menu title.</p>
*
* <p>The resource location must reference a valid client-side asset using the standard
* namespace format:</p>
*
* <pre>
* minecraft:textures/item/apple.png
* lunar:logo/logo-100x100.png
* </pre>
*
* <p>For optimal results, a square image (e.g. 128x128) is recommended.</p>
*
* @param recipients the recipients that are receiving the packet
* @param icon the resource location icon
* @since 1.2.5
*/
public abstract void overrideServerLinkResource(Recipients recipients, ResourceLocationIcon icon);

/**
* Resets the server link menu title image for the {@link Recipients}.
*
* <p>Reverts back to displaying the default menu title.</p>
*
* @param recipients the recipients that are receiving the packet
* @since 1.2.5
*/
public abstract void resetServerLinkResource(Recipients recipients);

/**
* Adds or updates the {@link ServerLink} for the {@link Recipients}.
*
* @param recipients the recipients that are receiving the packet
* @param serverLink the server link
* @since 1.2.5
*/
public abstract void addServerLink(Recipients recipients, ServerLink serverLink);

/**
* Adds or updates the {@link ServerLink}s for the {@link Recipients}.
*
* @param recipients the recipients that are receiving the packet
* @param serverLinks the server links
* @since 1.2.5
*/
public abstract void addServerLink(Recipients recipients, List<ServerLink> serverLinks);

/**
* Removes the {@link ServerLink} from the {@link Recipients}.
*
* @param recipients the recipients that are receiving the packet
* @param serverLinkId the server link id
* @since 1.2.5
*/
public abstract void removeServerLink(Recipients recipients, String serverLinkId);

/**
* Removes the {@link ServerLink} from the {@link Recipients}.
*
* @param recipients the recipients that are receiving the packet
* @param serverLink the server link
* @since 1.2.5
*/
public abstract void removeServerLink(Recipients recipients, ServerLink serverLink);

/**
* Removes the {@link ServerLink}s from the {@link Recipients}.
*
* @param recipients the recipients that are receiving the packet
* @param serverLinkIds the server link ids
* @since 1.2.5
*/
public abstract void removeServerLink(Recipients recipients, List<String> serverLinkIds);

/**
* Resets all {@link ServerLink}s for the {@link Recipients}.
*
* @param recipients the recipients that are receiving the packet
* @since 1.2.5
*/
public abstract void resetServerLinks(Recipients recipients);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
/*
* This file is part of Apollo, licensed under the MIT License.
*
* Copyright (c) 2026 Moonsworth
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.lunarclient.apollo.module.serverlink;

import com.lunarclient.apollo.common.ApolloComponent;
import com.lunarclient.apollo.common.icon.ResourceLocationIcon;
import com.lunarclient.apollo.network.NetworkTypes;
import com.lunarclient.apollo.player.AbstractApolloPlayer;
import com.lunarclient.apollo.recipients.Recipients;
import com.lunarclient.apollo.serverlink.v1.AddServerLinkMessage;
import com.lunarclient.apollo.serverlink.v1.OverrideServerLinkResourceMessage;
import com.lunarclient.apollo.serverlink.v1.RemoveServerLinkMessage;
import com.lunarclient.apollo.serverlink.v1.ResetServerLinkResourceMessage;
import com.lunarclient.apollo.serverlink.v1.ResetServerLinksMessage;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import lombok.NonNull;

/**
* Provides the server link module.
*
* @since 1.2.5
*/
public final class ServerLinkModuleImpl extends ServerLinkModule {

@Override
public void overrideServerLinkResource(@NonNull Recipients recipients, @NonNull ResourceLocationIcon icon) {
OverrideServerLinkResourceMessage message = OverrideServerLinkResourceMessage.newBuilder()
.setIcon(NetworkTypes.toProtobuf(icon))
.build();

recipients.forEach(player -> ((AbstractApolloPlayer) player).sendPacket(message));
}

@Override
public void resetServerLinkResource(@NonNull Recipients recipients) {
ResetServerLinkResourceMessage message = ResetServerLinkResourceMessage.getDefaultInstance();
recipients.forEach(player -> ((AbstractApolloPlayer) player).sendPacket(message));
}

@Override
public void addServerLink(@NonNull Recipients recipients, @NonNull ServerLink serverLink) {
this.addServerLink(recipients, Collections.singletonList(serverLink));
}

@Override
public void addServerLink(@NonNull Recipients recipients, @NonNull List<ServerLink> serverLinks) {
List<com.lunarclient.apollo.serverlink.v1.ServerLink> serverLinksProto = serverLinks.stream()
.map(this::toProtobuf)
.collect(Collectors.toList());

AddServerLinkMessage message = AddServerLinkMessage.newBuilder()
.addAllServerLinks(serverLinksProto)
.build();

recipients.forEach(player -> ((AbstractApolloPlayer) player).sendPacket(message));
}

@Override
public void removeServerLink(@NonNull Recipients recipients, @NonNull String serverLinkId) {
this.removeServerLink(recipients, Collections.singletonList(serverLinkId));
}

@Override
public void removeServerLink(@NonNull Recipients recipients, @NonNull ServerLink serverLink) {
this.removeServerLink(recipients, Collections.singletonList(serverLink.getId()));
}

@Override
public void removeServerLink(@NonNull Recipients recipients, @NonNull List<String> serverLinkIds) {
RemoveServerLinkMessage message = RemoveServerLinkMessage.newBuilder()
.addAllServerLinkIds(serverLinkIds)
.build();

recipients.forEach(player -> ((AbstractApolloPlayer) player).sendPacket(message));
}

@Override
public void resetServerLinks(@NonNull Recipients recipients) {
ResetServerLinksMessage message = ResetServerLinksMessage.getDefaultInstance();
recipients.forEach(player -> ((AbstractApolloPlayer) player).sendPacket(message));
}

private com.lunarclient.apollo.serverlink.v1.ServerLink toProtobuf(ServerLink serverLink) {
return com.lunarclient.apollo.serverlink.v1.ServerLink.newBuilder()
.setId(serverLink.getId())
.setDisplayNameAdventureJsonLines(ApolloComponent.toJson(serverLink.getDisplayName()))
.setUrl(serverLink.getUrl())
.build();
}

}
Loading
Loading