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
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,19 @@ 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-R0.1-SNAPSHOT";

try {

minecraftVersion = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3]; // Gets the server version
minecraftVersion = Bukkit.getBukkitVersion();


} catch (ArrayIndexOutOfBoundsException exception) {
Expand All @@ -31,7 +34,7 @@ public class Compatibility {

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

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

final String versionPackage = getVersionPackage(minecraftVersion);

Expand All @@ -53,14 +56,14 @@ public class Compatibility {

private static String getVersionPackage(String minecraftVersion) {

return Compatibility.class.getPackage().getName() + "." + minecraftVersion;
return Compatibility.class.getPackage().getName();

}

private static <T> Class<? extends T> getCompatibleClass(Class<T> clazz, String minecraftVersion, String versionPackage) {

try {
final Class<?> compatibleClass = Class.forName(versionPackage + "." + clazz.getSimpleName() + "_" + minecraftVersion);
final Class<?> compatibleClass = Class.forName(versionPackage + "." + clazz.getSimpleName());
if (compatibleClass.getSuperclass() != clazz && !Arrays.asList(compatibleClass.getInterfaces()).contains(clazz)) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,32 @@

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelPromise;
import net.minecraft.network.chat.Component;
import net.minecraft.network.protocol.game.ClientboundPlayerChatPacket;
import net.minecraft.util.Crypt.SaltSignaturePair;

public interface CompatiblePacketListener {
import java.util.Optional;

/**
* @return the packet that should be read
*/
Object readPacket(ChannelHandlerContext channelHandlerContext, Object packet) throws Exception;
public class CompatiblePacketListener {

/**
* @return the packet that should be written
*/
Object writePacket(ChannelHandlerContext channelHandlerContext, Object packet, ChannelPromise promise) throws Exception;
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 Optional<Component> unsignedContent = clientboundPlayerChatPacket.unsignedContent();

// recreate a new packet
return new ClientboundPlayerChatPacket(
unsignedContent.orElse(clientboundPlayerChatPacket.signedContent()), // use unsigned content if available, this is the signed content field
unsignedContent, // unsigned content field
clientboundPlayerChatPacket.typeId(),
clientboundPlayerChatPacket.sender(),
clientboundPlayerChatPacket.timeStamp(),
new SaltSignaturePair(0, new byte[0])); // salt signature field
}

return packet;

}

}
Original file line number Diff line number Diff line change
@@ -1,10 +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 interface CompatiblePlayer {
public class CompatiblePlayer {

Channel getChannel(Player player);
public Channel getChannel(Player player) {

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

}

}

This file was deleted.

This file was deleted.

2 changes: 1 addition & 1 deletion 1.19/src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: NoEncryption
version: '${project.version}'
version: '${project.parent.version}'
main: me.doclic.noencryption.NoEncryption
api-version: 1.19
authors: [ Doclic ]
Expand Down