Skip to content

Commit

Permalink
More work
Browse files Browse the repository at this point in the history
  • Loading branch information
Obydux committed Jul 31, 2024
1 parent 50f079c commit d8452a7
Show file tree
Hide file tree
Showing 11 changed files with 128 additions and 88 deletions.
35 changes: 19 additions & 16 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,35 +1,38 @@
plugins {
`java-library`
`maven-publish`
id("java")
id("maven-publish")
id("io.github.goooler.shadow") version "8.1.8"
}

repositories {
mavenLocal()
mavenCentral()
maven("https://jitpack.io/")
maven("https://hub.spigotmc.org/nexus/content/repositories/snapshots/")
maven("https://repo.papermc.io/repository/maven-public/")
maven("https://repo.codemc.io/repository/maven-releases/")
}

dependencies {
api("com.github.steveice10:opennbt:1.6")
api("io.netty:netty-all:4.1.109.Final")
compileOnly("org.spigotmc:spigot-api:1.20.6-R0.1-SNAPSHOT")
implementation("com.github.GeyserMC:OpenNBT:master-SNAPSHOT")
implementation("io.netty:netty-all:4.1.112.Final")
compileOnly("io.papermc.paper:paper-api:1.20.6-R0.1-SNAPSHOT")
}

java.sourceCompatibility = JavaVersion.VERSION_17
java.targetCompatibility = JavaVersion.VERSION_17

publishing {
publications.create<MavenPublication>("maven") {
from(components["java"])
}
tasks.withType<JavaCompile> {
options.encoding = "UTF-8"
options.release.set(21)
}

tasks.withType<JavaCompile>() {
tasks.withType<Javadoc> {
options.encoding = "UTF-8"
}

tasks.withType<Javadoc>() {
options.encoding = "UTF-8"
publishing.publications.create<MavenPublication>("maven") {
artifact(tasks["shadowJar"])
}

tasks.shadowJar {
minimize()
archiveFileName.set("${project.name}.jar")
relocate("com.github.GeyserMC", "dev._2lstudios.exploitfixer.shaded.com.github.GeyserMC")
}
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Gradle properties
org.gradle.daemon=true
org.gradle.configureondemand=true
org.gradle.parallel=true
org.gradle.parallel=true
org.gradle.caching=true
8 changes: 4 additions & 4 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
# https://docs.gradle.org/current/userguide/platforms.html#sub::toml-dependencies-format

[versions]
com-github-steveice10-opennbt = "1.5"
dev--v2lstudios-hamsterapi = "0.2.3"
io-netty-netty-all = "4.1.94.Final"
org-spigotmc-spigot-api = "1.19-R0.1-SNAPSHOT"
com-github-steveice10-opennbt = "1.6"
dev--v2lstudios-hamsterapi = "0.2.4"
io-netty-netty-all = "4.1.112.Final"
org-spigotmc-spigot-api = "1.20.6-R0.1-SNAPSHOT"

[libraries]
com-github-steveice10-opennbt = { module = "com.github.steveice10:opennbt", version.ref = "com-github-steveice10-opennbt" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public void onEnable() {
private void downloadHamsterAPI() throws IOException, UnknownDependencyException, InvalidPluginException, InvalidDescriptionException {
PluginDownloader pm = new PluginDownloader();
File file = pm.downloadPlugin(
"https://github.com/2lstudios-mc/HamsterAPI/releases/download/0.2.3/HamsterAPI.jar",
"https://github.com/2lstudios-mc/HamsterAPI/releases/download/0.2.4/HamsterAPI.jar",
getDataFolder().getParentFile().getAbsolutePath());
Plugin plugin = pm.loadPlugin(file, this);
pm.enablePlugin(plugin);
Expand Down
12 changes: 7 additions & 5 deletions src/main/java/dev/_2lstudios/hamsterapi/HamsterAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,22 @@ public static synchronized HamsterAPI getInstance() {
}

public static String getVersion(Server server) {
final String packageName = server.getClass().getPackage().getName();
return packageName.substring(packageName.lastIndexOf('.') + 1);
String packageName = server.getClass().getPackage().getName();
String[] packageSplit = packageName.split("\\.");
String version = packageSplit.length > 3 ? packageSplit[3] : null;
return version;
}

private void initialize() {
final Server server = getServer();
final Properties properties = getProperties();
final String bukkitVersion = getVersion(server).replaceAll("[^0-9]", "");
final String bukkitVersion = getVersion(server);
final int compressionThreshold = (int) properties.getOrDefault("network_compression_threshold", 256);

setInstance(this);

this.reflection = new Reflection(server.getClass().getPackage().getName().split("\\.")[3]);
this.bufferIO = new BufferIO(this.reflection, bukkitVersion, compressionThreshold);
this.reflection = new Reflection(bukkitVersion);
this.bufferIO = new BufferIO(this.reflection, bukkitVersion == null ? null : bukkitVersion.replaceAll("[^0-9]", ""), compressionThreshold);
this.hamsterPlayerManager = new HamsterPlayerManager();
this.bungeeMessenger = new BungeeMessenger(this);
}
Expand Down
10 changes: 6 additions & 4 deletions src/main/java/dev/_2lstudios/hamsterapi/Version.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,13 @@ public Version(String versionText) {

public static Version getCurrentVersion() {
if (currentVersion == null) {
String version = HamsterAPI.getVersion(Bukkit.getServer());
currentVersion = new Version(
HamsterAPI.getVersion(Bukkit.getServer())
.split("v")[1]
.split("_R")[0]
.replace("_", ".")
version == null ? "1.20.6" :
version
.split("v")[1]
.split("_R")[0]
.replace("_", ".")
);
}
return currentVersion;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,25 +44,35 @@ public Player getPlayer() {

public void sendActionbarPacketOld(final String text) throws IllegalAccessException, IllegalArgumentException,
InvocationTargetException, InstantiationException, NoSuchMethodException, SecurityException {
final Reflection reflection = hamsterAPI.getReflection();
final Object chatAction = toChatBaseComponent.invoke(null, "{ \"text\":\"" + text + "\" }");
final Object packet = reflection.getPacketPlayOutChat().getConstructor(iChatBaseComponentClass, byte.class)
.newInstance(chatAction, (byte) 2);
try {
final Reflection reflection = hamsterAPI.getReflection();
final Object chatAction = toChatBaseComponent.invoke(null, "{ \"text\":\"" + text + "\" }");
final Object packet = reflection.getPacketPlayOutChat().getConstructor(iChatBaseComponentClass, byte.class)
.newInstance(chatAction, (byte) 2);

sendPacket(packet);
sendPacket(packet);
} catch (final Exception e) {
hamsterAPI.getLogger().info("Failed to send action bar packet to player " + player.getName() + "!");
e.printStackTrace();
}
}

public void sendActionbarPacketNew(final String text) throws IllegalAccessException, IllegalArgumentException,
InvocationTargetException, InstantiationException, NoSuchMethodException, SecurityException {
final Reflection reflection = hamsterAPI.getReflection();
final Object chatAction = toChatBaseComponent.invoke(null, "{ \"text\":\"" + text + "\" }");
final Class<?> chatMessageTypeClass = reflection.getChatMessageType();
final Object[] enumConstants = chatMessageTypeClass.getEnumConstants();
final Object packet = reflection.getPacketPlayOutChat()
.getConstructor(iChatBaseComponentClass, chatMessageTypeClass, UUID.class)
.newInstance(chatAction, enumConstants[2], player.getUniqueId());

sendPacket(packet);
try {
final Reflection reflection = hamsterAPI.getReflection();
final Object chatAction = toChatBaseComponent.invoke(null, "{ \"text\":\"" + text + "\" }");
final Class<?> chatMessageTypeClass = reflection.getChatMessageType();
final Object[] enumConstants = chatMessageTypeClass.getEnumConstants();
final Object packet = reflection.getPacketPlayOutChat()
.getConstructor(iChatBaseComponentClass, chatMessageTypeClass, UUID.class)
.newInstance(chatAction, enumConstants[2], player.getUniqueId());

sendPacket(packet);
} catch (final Exception e) {
hamsterAPI.getLogger().info("Failed to send action bar packet to player " + player.getName() + "!");
e.printStackTrace();
}
}

// Sends an ActionBar to the HamsterPlayer
Expand All @@ -81,45 +91,57 @@ public void sendActionbar(final String text) {
public void sendTitlePacketOld(final String title, final String subtitle, final int fadeInTime, final int showTime,
final int fadeOutTime) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException,
NoSuchMethodException, SecurityException, InstantiationException, NoSuchFieldException {
final Reflection reflection = hamsterAPI.getReflection();
try {
final Reflection reflection = hamsterAPI.getReflection();

final Object chatTitle = toChatBaseComponent.invoke(null, "{ \"text\":\"" + title + "\" }");
final Object chatSubTitle = toChatBaseComponent.invoke(null, "{ \"text\":\"" + subtitle + "\" }");
final Class<?> enumTitleActionClass = reflection.getPacketPlayOutTitle().getDeclaredClasses()[0];
final Constructor<?> titleConstructor = reflection.getPacketPlayOutTitle().getConstructor(enumTitleActionClass,
iChatBaseComponentClass, int.class, int.class, int.class);
final Object titlePacket = titleConstructor.newInstance(
enumTitleActionClass.getDeclaredField("TITLE").get(null), chatTitle, fadeInTime, showTime, fadeOutTime);
final Object subtitlePacket = titleConstructor.newInstance(
enumTitleActionClass.getDeclaredField("SUBTITLE").get(null), chatSubTitle, fadeInTime, showTime,
fadeOutTime);

sendPacket(titlePacket);
sendPacket(subtitlePacket);
final Object chatTitle = toChatBaseComponent.invoke(null, "{ \"text\":\"" + title + "\" }");
final Object chatSubTitle = toChatBaseComponent.invoke(null, "{ \"text\":\"" + subtitle + "\" }");
final Class<?> enumTitleActionClass = reflection.getPacketPlayOutTitle().getDeclaredClasses()[0];
final Constructor<?> titleConstructor = reflection.getPacketPlayOutTitle().getConstructor(
enumTitleActionClass,
iChatBaseComponentClass, int.class, int.class, int.class);
final Object titlePacket = titleConstructor.newInstance(
enumTitleActionClass.getDeclaredField("TITLE").get(null), chatTitle, fadeInTime, showTime,
fadeOutTime);
final Object subtitlePacket = titleConstructor.newInstance(
enumTitleActionClass.getDeclaredField("SUBTITLE").get(null), chatSubTitle, fadeInTime, showTime,
fadeOutTime);

sendPacket(titlePacket);
sendPacket(subtitlePacket);
} catch (final Exception e) {
hamsterAPI.getLogger().info("Failed to send title packet to player " + player.getName() + "!");
e.printStackTrace();
}
}

public void sendTitlePacketNew(final String title, final String subtitle, final int fadeInTime, final int showTime,
final int fadeOutTime) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException,
NoSuchMethodException, SecurityException, InstantiationException, NoSuchFieldException {
final Reflection reflection = hamsterAPI.getReflection();
try {
final Reflection reflection = hamsterAPI.getReflection();

final Constructor<?> timingTitleConstructor = reflection.getClientboundSetTitlesAnimationPacket()
.getConstructor(int.class, int.class, int.class);
final Object timingPacket = timingTitleConstructor.newInstance(fadeInTime, showTime, fadeOutTime);
final Constructor<?> timingTitleConstructor = reflection.getClientboundSetTitlesAnimationPacket()
.getConstructor(int.class, int.class, int.class);
final Object timingPacket = timingTitleConstructor.newInstance(fadeInTime, showTime, fadeOutTime);

final Object chatTitle = toChatBaseComponent.invoke(null, "{ \"text\":\"" + title + "\" }");
final Constructor<?> titleConstructor = reflection.getClientboundSetTitleTextPacket()
.getConstructor(iChatBaseComponentClass);
final Object titlePacket = titleConstructor.newInstance(chatTitle);
final Object chatTitle = toChatBaseComponent.invoke(null, "{ \"text\":\"" + title + "\" }");
final Constructor<?> titleConstructor = reflection.getClientboundSetTitleTextPacket()
.getConstructor(iChatBaseComponentClass);
final Object titlePacket = titleConstructor.newInstance(chatTitle);

final Object chatSubTitle = toChatBaseComponent.invoke(null, "{ \"text\":\"" + subtitle + "\" }");
final Constructor<?> subTitleConstructor = reflection.getClientboundSetSubtitleTextPacket()
.getConstructor(iChatBaseComponentClass);
final Object subTitlePacket = subTitleConstructor.newInstance(chatSubTitle);
final Object chatSubTitle = toChatBaseComponent.invoke(null, "{ \"text\":\"" + subtitle + "\" }");
final Constructor<?> subTitleConstructor = reflection.getClientboundSetSubtitleTextPacket()
.getConstructor(iChatBaseComponentClass);
final Object subTitlePacket = subTitleConstructor.newInstance(chatSubTitle);

sendPacket(timingPacket);
sendPacket(titlePacket);
sendPacket(subTitlePacket);
sendPacket(timingPacket);
sendPacket(titlePacket);
sendPacket(subTitlePacket);
} catch (final Exception e) {
hamsterAPI.getLogger().info("Failed to send title packet to player " + player.getName() + "!");
e.printStackTrace();
}
}

// Sends a Title to the HamsterPlayer
Expand All @@ -132,6 +154,7 @@ public void sendTitle(final String title, final String subtitle, final int fadeI
sendTitlePacketOld(title, subtitle, fadeInTime, showTime, fadeOutTime);
} catch (final Exception e2) {
hamsterAPI.getLogger().info("Failed to send title packet to player " + player.getName() + "!");
e2.printStackTrace();
}
}
}
Expand Down Expand Up @@ -222,13 +245,15 @@ public void setup()

this.iChatBaseComponentClass = reflection.getIChatBaseComponent();


this.sendPacketMethod = this.playerConnection.getClass().getMethod(
Version.getCurrentVersion().isMinor("1.18") ? "sendPacket" : "a"
, reflection.getPacket());
Version.getCurrentVersion().isMinor("1.18") ? "sendPacket" : "a", reflection.getPacket());
Debug.info("Getting sendPacket method from playerConnection field (" + this.player.getName() + ")");

this.toChatBaseComponent = iChatBaseComponentClass.getDeclaredClasses()[0].getMethod("a", String.class);
try {
this.toChatBaseComponent = iChatBaseComponentClass.getDeclaredClasses()[0].getMethod("a", String.class);
} catch (NoSuchMethodException ex) {
// Unable to get chat component method
Debug.crit("Failed to get toChatBaseComponent method. Kick messagges and other won't show up.");
}
this.setup = true;
}
}
Expand All @@ -255,7 +280,8 @@ public void inject() throws IllegalAccessException, InvocationTargetException, N
pipeline.addAfter("splitter", HamsterHandler.HAMSTER_DECODER, hamsterDecoderHandler);
Debug.info("Added HAMSTER_DECODER in pipeline after spliter (" + this.player.getName() + ")");
} else {
Debug.crit("No ChannelHandler was found on the pipeline to inject HAMSTER_DECODER (" + this.player.getName() + ")");
Debug.crit("No ChannelHandler was found on the pipeline to inject HAMSTER_DECODER ("
+ this.player.getName() + ")");
throw new IllegalAccessException(
"No ChannelHandler was found on the pipeline to inject " + HamsterHandler.HAMSTER_DECODER);
}
Expand All @@ -264,7 +290,8 @@ public void inject() throws IllegalAccessException, InvocationTargetException, N
pipeline.addAfter("decoder", HamsterHandler.HAMSTER_CHANNEL, hamsterChannelHandler);
Debug.info("Added HAMSTER_CHANNEL in pipeline after decoder (" + this.player.getName() + ")");
} else {
Debug.crit("No ChannelHandler was found on the pipeline to inject HAMSTER_CHANNEL (" + this.player.getName() + ")");
Debug.crit("No ChannelHandler was found on the pipeline to inject HAMSTER_CHANNEL ("
+ this.player.getName() + ")");
throw new IllegalAccessException(
"No ChannelHandler was found on the pipeline to inject " + hamsterChannelHandler);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public BufferIO(final Reflection reflection, final String bukkitVersion, final i
this.enumProtocolClass = reflection.getEnumProtocol();
this.enumProtocolDirectionClass = reflection.getEnumProtocolDirection();
this.inflater = new Inflater();
this.bukkitVersion = Integer.parseInt(bukkitVersion);
this.bukkitVersion = bukkitVersion == null ? 1206 : Integer.parseInt(bukkitVersion);
this.compressionThreshold = compressionThreshold;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ public Object getField(final Object object, final Class<?> fieldType) throws Ill
private Class<?> getMinecraftClass(String key) {
final int lastDot = key.lastIndexOf(".");
final String lastKey = key.substring(lastDot > 0 ? lastDot + 1 : 0, key.length());
// 1.8
final Class<?> legacyClass = getClass("net.minecraft.server." + this.version + "." + lastKey);
// 1.17
final Class<?> newClass = getClass("net.minecraft." + key);

return legacyClass != null ? legacyClass : newClass;
Expand All @@ -92,10 +94,14 @@ private Class<?> getMinecraftClass(String key) {
private Class<?> getCraftBukkitClass(String key) {
final int lastDot = key.lastIndexOf(".");
final String lastKey = key.substring(lastDot > 0 ? lastDot + 1 : 0, key.length());
// 1.8
final Class<?> legacyClass = getClass("org.bukkit.craftbukkit." + this.version + "." + lastKey);
// 1.17
final Class<?> newClass = getClass("org.bukkit.craftbukkit." + this.version + "." + key);
// 1.20.6
final Class<?> newestClass = getClass("org.bukkit.craftbukkit." + key);

return legacyClass != null ? legacyClass : newClass;
return legacyClass != null ? legacyClass : newClass != null ? newClass : newestClass;
}

public Class<?> getItemStack() {
Expand Down
6 changes: 3 additions & 3 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# ExploitFixer by LinsaFTW
# ExploitFixer by LinsaFTW & Obydux
# Please help by donating, we require funds to continue with the development.
# https://paypal.me/LinsaFTW
# https://paypal.me/Obydux
#
# INSTALL THE PLUGIN ON ALL BUKKIT SERVERS!
#
Expand All @@ -11,7 +11,7 @@
locale: "en"

# Web link used on the messages
web: "discord.gg/gF36AT3"
web: "discord.gg/MC2BzcE3vx"

# Shows notifications to console and players with permissions.
notifications:
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: ExploitFixer
description: "Advanced anti-exploit plugin for Spigot/Paper servers."
authors: [2LS, Obydux]
version: '2.3.0'
version: '3.0.0'
main: dev._2lstudios.exploitfixer.ExploitFixer
api-version: '1.13'
folia-supported: true
Expand Down

0 comments on commit d8452a7

Please sign in to comment.