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
121 changes: 121 additions & 0 deletions 1.19.1/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<artifactId>NoEncryption-1.19.1</artifactId>
<version>2.0</version>
<packaging>jar</packaging>

<name>NoEncryption-1.19.1</name>

<description>Makes every player message a system message</description>

<parent>
<groupId>me.doclic</groupId>
<artifactId>NoEncryption</artifactId>
<version>2.0</version>
</parent>

<properties>
<java.version>1.17</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>16</source>
<target>16</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>net.md-5</groupId>
<artifactId>specialsource-maven-plugin</artifactId>
<version>1.2.2</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>remap</goal>
</goals>
<id>remap-obf</id>
<configuration>
<srgIn>org.spigotmc:minecraft-server:1.19.1-R0.1-SNAPSHOT:txt:maps-mojang</srgIn>
<reverse>true</reverse>
<remappedDependencies>org.spigotmc:spigot:1.19.1-R0.1-SNAPSHOT:jar:remapped-mojang</remappedDependencies>
<remappedArtifactAttached>true</remappedArtifactAttached>
<remappedClassifierName>remapped-obf</remappedClassifierName>
</configuration>
</execution>
<execution>
<phase>package</phase>
<goals>
<goal>remap</goal>
</goals>
<id>remap-spigot</id>
<configuration>
<inputFile>${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar</inputFile>
<srgIn>org.spigotmc:minecraft-server:1.19.1-R0.1-SNAPSHOT:csrg:maps-spigot</srgIn>
<remappedDependencies>org.spigotmc:spigot:1.19.1-R0.1-SNAPSHOT:jar:remapped-obf</remappedDependencies>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>

<repositories>
<repository>
<id>papermc</id>
<url>https://repo.papermc.io/repository/maven-public/</url>
</repository>
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
</repositories>

<dependencies>
<dependency>
<groupId>io.papermc.paper</groupId>
<artifactId>paper-api</artifactId>
<version>1.19.1-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot</artifactId>
<version>1.19.1-R0.1-SNAPSHOT</version>
<scope>provided</scope>
<classifier>remapped-mojang</classifier>
</dependency>
</dependencies>
</project>
30 changes: 30 additions & 0 deletions 1.19.1/src/main/java/me/doclic/noencryption/NoEncryption.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package me.doclic.noencryption;

import me.doclic.noencryption.compatibility.Compatibility;
import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;

public final class NoEncryption extends JavaPlugin {

@Override
public void onEnable() {

if (Compatibility.SERVER_COMPATIBLE) {

Bukkit.getPluginManager().registerEvents(new PlayerListener(), this);

getLogger().info("Compatibility successful!");

getLogger().info("If you used /reload to update NoEncryption, your players need to");
getLogger().info("disconnect and join back");

} else {

getLogger().severe("Failed to setup NoEncryption's compatibility!");
getLogger().severe("Your server version (" + Compatibility.SERVER_VERSION + ") is not compatible with this plugin!");

Bukkit.getPluginManager().disablePlugin(this);
}

}
}
54 changes: 54 additions & 0 deletions 1.19.1/src/main/java/me/doclic/noencryption/PlayerListener.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package me.doclic.noencryption;

import io.netty.channel.Channel;
import io.netty.channel.ChannelDuplexHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.ChannelPromise;
import me.doclic.noencryption.compatibility.Compatibility;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;

public class PlayerListener implements Listener {

@EventHandler(priority = EventPriority.LOWEST)
public void onPlayerJoin (PlayerJoinEvent e) {

final Player player = e.getPlayer();
final ChannelPipeline pipeline = Compatibility.COMPATIBLE_PLAYER.getChannel(player).pipeline();
pipeline.addBefore("packet_handler", player.getUniqueId().toString(), new ChannelDuplexHandler() {

@Override
public void channelRead(ChannelHandlerContext channelHandlerContext, Object packet) throws Exception {

Object newPacket = Compatibility.COMPATIBLE_PACKET_LISTENER.readPacket(channelHandlerContext, packet);
super.channelRead(channelHandlerContext, newPacket);

}

@Override
public void write(ChannelHandlerContext channelHandlerContext, Object packet, ChannelPromise promise) throws Exception {

Object newPacket = Compatibility.COMPATIBLE_PACKET_LISTENER.writePacket(channelHandlerContext, packet, promise);
super.write(channelHandlerContext, newPacket, promise);

}

});

}

@EventHandler(priority = EventPriority.LOWEST)
public void onPlayerQuit (PlayerQuitEvent e) {

final Player player = e.getPlayer();
final Channel channel = Compatibility.COMPATIBLE_PLAYER.getChannel(player);
channel.eventLoop().submit(() -> channel.pipeline().remove(player.getUniqueId().toString()));

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package me.doclic.noencryption.compatibility;

import org.bukkit.Bukkit;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.Arrays;

public class Compatibility {

public static final CompatiblePlayer COMPATIBLE_PLAYER;
public static final CompatiblePacketListener COMPATIBLE_PACKET_LISTENER;

public static final String PLUGIN_COMPATIBLE_VERSION;
public static final boolean SERVER_COMPATIBLE;
public static final String SERVER_VERSION;

static {

String minecraftVersion;

PLUGIN_COMPATIBLE_VERSION = "1.19.1-R0.1-SNAPSHOT";

try {

minecraftVersion = Bukkit.getBukkitVersion();


} catch (ArrayIndexOutOfBoundsException exception) {
minecraftVersion = null;
}

SERVER_VERSION = minecraftVersion;

Bukkit.getLogger().info("Your server is running version " + minecraftVersion);

if (minecraftVersion != null && minecraftVersion.equals(PLUGIN_COMPATIBLE_VERSION)) {

final String versionPackage = getVersionPackage(minecraftVersion);

COMPATIBLE_PLAYER = instantiate(CompatiblePlayer.class);
COMPATIBLE_PACKET_LISTENER = instantiate(CompatiblePacketListener.class);

SERVER_COMPATIBLE = true;

} else {

COMPATIBLE_PLAYER = null;
COMPATIBLE_PACKET_LISTENER = null;

SERVER_COMPATIBLE = false;

}

}

private static String getVersionPackage(String minecraftVersion) {

return Compatibility.class.getPackage().getName();

}

private static <T> T instantiate(Class<T> clazz) {

if (clazz == null) return null;

try {
final Constructor<T> constructor = clazz.getConstructor();
return constructor.newInstance();
} catch (NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
return null;
}

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package me.doclic.noencryption.compatibility;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelPromise;
import net.minecraft.network.chat.*;
import net.minecraft.network.protocol.game.ClientboundPlayerChatHeaderPacket;
import net.minecraft.network.protocol.game.ClientboundPlayerChatPacket;
import net.minecraft.network.protocol.game.ClientboundSystemChatPacket;
import org.bukkit.craftbukkit.v1_19_R1.util.CraftChatMessage;

import java.util.Optional;
import java.util.UUID;

public class CompatiblePacketListener {

public Object readPacket(ChannelHandlerContext channelHandlerContext, Object packet) throws Exception { return packet; }

public Object writePacket(ChannelHandlerContext channelHandlerContext, Object packet, ChannelPromise promise) throws Exception {
if (packet instanceof final ClientboundPlayerChatPacket clientboundPlayerChatPacket) {
final PlayerChatMessage message = clientboundPlayerChatPacket.message();
final Optional<Component> unsignedContent = message.unsignedContent();
final ChatMessageContent signedContent = message.signedContent();
final SignedMessageBody signedBody = message.signedBody();
final ChatType.BoundNetwork chatType = clientboundPlayerChatPacket.chatType();

// recreate a new packet
return new ClientboundPlayerChatPacket(
new PlayerChatMessage(
new SignedMessageHeader(
new MessageSignature(new byte[0]),
new UUID(0, 0)),
new MessageSignature(new byte[0]),
new SignedMessageBody(
new ChatMessageContent(
signedContent.plain(),
signedContent.decorated()),
signedBody.timeStamp(),
0,
signedBody.lastSeen()),
unsignedContent,
new FilterMask(0)
),
chatType);
} else if (packet instanceof final ClientboundSystemChatPacket clientboundSystemChatPacket) {
if (clientboundSystemChatPacket.content() == null) {
return clientboundSystemChatPacket;
} else {
// recreate a new packet
return new ClientboundSystemChatPacket(
CraftChatMessage.fromJSONOrNull(clientboundSystemChatPacket.content()),
clientboundSystemChatPacket.overlay());
}
} else if (packet instanceof final ClientboundPlayerChatHeaderPacket clientboundPlayerChatHeaderPacket) {
// recreate a new packet
return new ClientboundPlayerChatHeaderPacket(
new SignedMessageHeader(
new MessageSignature(new byte[0]),
new UUID(0, 0)),
new MessageSignature(new byte[0]),
clientboundPlayerChatHeaderPacket.bodyDigest()
);
}

return packet;

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package me.doclic.noencryption.compatibility;

import io.netty.channel.Channel;
import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer;
import org.bukkit.entity.Player;

public class CompatiblePlayer {

public Channel getChannel(Player player) {

return ((CraftPlayer) player).getHandle().connection.connection.channel;

}

}
6 changes: 6 additions & 0 deletions 1.19.1/src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
name: NoEncryption
version: '${project.parent.version}'
main: me.doclic.noencryption.NoEncryption
api-version: 1.19
authors: [ Doclic ]
description: Strips signatures from player messages
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

<modules>
<module>1.19</module>
<module>1.19.1</module>
</modules>

<build>
Expand Down