Skip to content
Merged
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
2 changes: 1 addition & 1 deletion api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ setupPlatforms()

setupPlatformDependency("bukkit", "bukkitJar")
setupPlatformDependency("bungee", "bungeeJar")
setupPlatformDependency("velocity", "velocityJar")
setupPlatformDependency("velocity", "velocityJar", 17)
setupPlatformDependency("folia", "foliaJar", 21)

val main by sourceSets
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import com.diffplug.gradle.spotless.FormatExtension
import org.gradle.jvm.toolchain.JavaLanguageVersion
import org.gradle.jvm.toolchain.JavaToolchainService
import java.nio.charset.StandardCharsets
import java.nio.file.Files
import java.util.regex.Pattern
Expand Down Expand Up @@ -83,6 +85,11 @@ checkstyle {

tasks {
javadoc {
val javaToolchains = project.extensions.getByType(JavaToolchainService::class.java)
javadocTool.set(javaToolchains.javadocToolFor {
languageVersion.set(JavaLanguageVersion.of(21))
})

val minimalOptions: MinimalJavadocOptions = options
options.encoding("UTF-8")

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

import com.lunarclient.apollo.command.impl.ApolloCommand;
import com.lunarclient.apollo.command.impl.LunarClientCommand;
import com.lunarclient.apollo.listener.ApolloMetadataListener;
import com.lunarclient.apollo.listener.ApolloPlayerListener;
import com.lunarclient.apollo.listener.ApolloWorldListener;
import com.lunarclient.apollo.loader.PlatformPlugin;
import com.lunarclient.apollo.metadata.BukkitMetadataManager;
import com.lunarclient.apollo.module.ApolloModuleManagerImpl;
import com.lunarclient.apollo.module.autotexthotkey.AutoTextHotkeyModule;
import com.lunarclient.apollo.module.beam.BeamModule;
Expand Down Expand Up @@ -119,7 +121,9 @@ public void onEnable() {
this.stats = new BukkitApolloStats();

ApolloManager.bootstrap(this);
ApolloManager.setMetadataManager(new BukkitMetadataManager());

new ApolloMetadataListener(this.plugin);
new ApolloPlayerListener(this.plugin);
new ApolloWorldListener(this.plugin);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/*
* This file is part of Apollo, licensed under the MIT License.
*
* Copyright (c) 2023 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.listener;

import com.google.common.io.ByteArrayDataInput;
import com.google.common.io.ByteStreams;
import com.lunarclient.apollo.ApolloManager;
import com.lunarclient.apollo.metadata.BukkitMetadataManager;
import com.lunarclient.apollo.util.ByteBufUtil;
import java.io.ByteArrayInputStream;
import java.io.DataInputStream;
import java.io.IOException;
import java.util.Map;
import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerResourcePackStatusEvent;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.plugin.messaging.Messenger;
import org.bukkit.plugin.messaging.PluginMessageListener;

/**
* Handles Apollo metadata listeners.
*
* @since 1.1.9
*/
public final class ApolloMetadataListener implements Listener {

private final JavaPlugin plugin;

/**
* Constructs the {@link ApolloMetadataListener}.
*
* @param plugin the plugin
* @since 1.1.9
*/
public ApolloMetadataListener(JavaPlugin plugin) {
this.plugin = plugin;

this.registerBrandListener();
Bukkit.getPluginManager().registerEvents(this, plugin);
}

@EventHandler
private void onResourcePackStatus(PlayerResourcePackStatusEvent event) {
String status = event.getStatus().name();
BukkitMetadataManager manager = (BukkitMetadataManager) ApolloManager.getMetadataManager();
Map<String, Integer> statuses = manager.getResourcePackStatuses();

statuses.put(status, statuses.getOrDefault(status, 0) + 1);
}

private void registerBrandListener() {
Messenger messenger = this.plugin.getServer().getMessenger();

try {
PluginMessageListener listener = (channel, player, bytes) -> {
try (DataInputStream in = new DataInputStream(new ByteArrayInputStream(bytes))) {
this.collectBrand(in.readUTF());
} catch (IOException ignored) {
}
};

messenger.registerIncomingPluginChannel(this.plugin, "MC|Brand", listener);
} catch (IllegalArgumentException ignored) {
}

messenger.registerIncomingPluginChannel(this.plugin, "minecraft:brand", (channel, player, bytes) -> {
ByteArrayDataInput in = ByteStreams.newDataInput(bytes);
this.collectBrand(ByteBufUtil.readString(in));
});
}

private void collectBrand(String brand) {
BukkitMetadataManager manager = (BukkitMetadataManager) ApolloManager.getMetadataManager();
manager.getClientBrands().add(brand);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* This file is part of Apollo, licensed under the MIT License.
*
* Copyright (c) 2023 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.metadata;

import com.lunarclient.apollo.stats.metadata.PlatformMetadata;
import java.util.Map;
import java.util.Set;
import lombok.Builder;
import lombok.ToString;

/**
* Represents the bukkit metadata implementation.
*
* @since 1.1.9
*/
@ToString
@Builder(toBuilder = true)
public class BukkitMetadata extends PlatformMetadata {

/**
* Tracks client brands sent by the players.
*
* <p>A {@link Set} of {@link String} client brands.</p>
*
* @since 1.1.9
*/
private final Set<String> clientBrands;

/**
* Tracks the total number of resource pack status events received.
*
* <p>Represents a {@link Map} of {@link String} status enum name as a key
* and {@link Integer} count of how many times that status has been reported.</p>
*
* @since 1.1.9
*/
private final Map<String, Integer> resourcePackStatuses;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* This file is part of Apollo, licensed under the MIT License.
*
* Copyright (c) 2023 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.metadata;

import com.lunarclient.apollo.stats.metadata.ApolloMetadataManager;
import com.lunarclient.apollo.stats.metadata.PlatformMetadata;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import lombok.Getter;

/**
* The Bukkit implementation of {@link ApolloMetadataManager}.
*
* @since 1.1.9
*/
@Getter
public class BukkitMetadataManager implements ApolloMetadataManager {

private final Set<String> clientBrands = new HashSet<>();
private final Map<String, Integer> resourcePackStatuses = new HashMap<>();

@Override
public PlatformMetadata extract() {
return BukkitMetadata.builder()
.clientBrands(new HashSet<>(this.clientBrands))
.resourcePackStatuses(new HashMap<>(this.resourcePackStatuses))
.build();
}

@Override
public void clear() {
this.clientBrands.clear();
this.resourcePackStatuses.clear();
}

}
83 changes: 83 additions & 0 deletions bukkit/src/main/java/com/lunarclient/apollo/util/ByteBufUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
* This file is part of Apollo, licensed under the MIT License.
*
* Copyright (c) 2023 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.util;

import com.google.common.io.ByteArrayDataInput;
import java.nio.charset.StandardCharsets;

/**
* Represents a util for reading byte buffs.
*
* @since 1.1.9
*/
public final class ByteBufUtil {

/**
* Reads an int from the given input stream.
*
* @param in in the {@link ByteArrayDataInput} to read from
* @return the read int
* @throws IllegalArgumentException if the value length is invalid or too large
* @since 1.1.9
*/
public static int readVarInt(ByteArrayDataInput in) {
int i = 0;
int j = 0;

while (true) {
byte b = in.readByte();
i |= (b & 0x7F) << j++ * 7;

if (j > 5) {
throw new RuntimeException("VarInt too big");
}

if ((b & 0x80) != 128) {
break;
}
}

return i;
}

/**
* Reads a UTF-8 encoded string from the given input stream.
*
* @param in the {@link ByteArrayDataInput} to read from
* @return the decoded string
* @throws IllegalArgumentException if the value length is invalid or too large
* @since 1.1.9
*/
public static String readString(ByteArrayDataInput in) {
int length = ByteBufUtil.readVarInt(in);
byte[] bytes = new byte[length];
in.readFully(bytes);

return new String(bytes, StandardCharsets.UTF_8);
}

private ByteBufUtil() {
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@

import com.lunarclient.apollo.command.impl.ApolloCommand;
import com.lunarclient.apollo.command.impl.LunarClientCommand;
import com.lunarclient.apollo.listener.ApolloMetadataListener;
import com.lunarclient.apollo.listener.ApolloPlayerListener;
import com.lunarclient.apollo.loader.PlatformPlugin;
import com.lunarclient.apollo.metadata.BungeeMetadataManager;
import com.lunarclient.apollo.module.ApolloModuleManagerImpl;
import com.lunarclient.apollo.module.autotexthotkey.AutoTextHotkeyModule;
import com.lunarclient.apollo.module.beam.BeamModule;
Expand Down Expand Up @@ -107,6 +109,7 @@ public void onEnable() {
this.stats = new BungeeApolloStats();

ApolloManager.bootstrap(this);
ApolloManager.setMetadataManager(new BungeeMetadataManager());

((ApolloModuleManagerImpl) Apollo.getModuleManager())
.addModule(AutoTextHotkeyModule.class)
Expand Down Expand Up @@ -146,6 +149,7 @@ public void onEnable() {
server.registerChannel(ApolloManager.PLUGIN_MESSAGE_CHANNEL);

PluginManager pluginManager = server.getPluginManager();
pluginManager.registerListener(this.plugin, new ApolloMetadataListener(this.plugin));
pluginManager.registerListener(this.plugin, new ApolloPlayerListener());
pluginManager.registerCommand(this.plugin, ApolloCommand.create());
pluginManager.registerCommand(this.plugin, LunarClientCommand.create());
Expand Down
Loading