Skip to content

Commit

Permalink
version 2.9.14-snapshot-1
Browse files Browse the repository at this point in the history
added message to optifine and forge clients
  • Loading branch information
EriolEandur committed Sep 17, 2024
1 parent e43a07d commit fd7679e
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ public void onEnable() {
// pluginManager.registerEvents(new AfkListener(), this);

Bukkit.getMessenger().registerIncomingPluginChannel(this, "mcme-modpack-marker:hello", new RpPluginMessageListener());
Bukkit.getMessenger().registerIncomingPluginChannel(this, "minecraft:brand", new TestPluginMessageListener());
Bukkit.getMessenger().registerIncomingPluginChannel(this, "l:fmlhs", new TestPluginMessageListener());
Bukkit.getMessenger().registerIncomingPluginChannel(this, "wdl:init", new TestPluginMessageListener());

ProtocolManager manager = ProtocolLibrary.getProtocolManager();
manager.addPacketListener(new ViewDistanceListener(this));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public void onPlayerPreLogin(AsyncPlayerPreLoginEvent event) {
@EventHandler
public void onPlayerConnect(PlayerConnectEvent event) {
Player player = event.getPlayer();
/*Logger.getGlobal().info("PlayerConnectEvent: "+player.getName()+" "+ event.getReason().name());
Logger.getGlobal().info("PlayerConnectEvent: "+player.getName()+" "+ event.getReason().name());
int version = player.getProtocolVersion();
String snapshot = "";
if(version > 0x40000000) {
Expand All @@ -76,7 +76,7 @@ public void onPlayerConnect(PlayerConnectEvent event) {
Logger.getGlobal().info("Protocol Version: "+snapshot + version);
Logger.getGlobal().info("Sodium client: "+RpManager.isSodiumClient(player));
Logger.getGlobal().info("Incomming plugin channels:");
Bukkit.getMessenger().getIncomingChannels().forEach(channel->Logger.getGlobal().info(channel));*/
Bukkit.getMessenger().getIncomingChannels().forEach(channel->Logger.getGlobal().info(channel));
if(event.getReason().equals(PlayerConnectEvent.ConnectReason.JOIN_PROXY)) {
new BukkitRunnable() {
int counter = 11;
Expand All @@ -97,13 +97,28 @@ public void run() {
//}
}
if (RpManager.hasPlayerDataLoaded(player)
&& player.getClientBrandName() !=null
&& player.getClientBrandName().contains("fabric")
&& !data.getClient().equals("sodium")) {
new FancyMessage(MessageType.INFO, PluginData.getMessageUtil())
.addSimple("If you are using "+ChatColor.GREEN+ChatColor.BOLD+"Sodium "+ChatColor.AQUA+"mod you might experience"+ ChatColor.GREEN+" texture errors"+ChatColor.AQUA+" as your server RP is not set to Sodium variant. ")
.addClickable("Click here to fix this or do command "+ChatColor.GREEN+ChatColor.BOLD+"/rp client sodium.","/rp client sodium").setRunDirect()
.send(player);
&& player.getClientBrandName() !=null) {
if(player.getClientBrandName().contains("fabric")
&& !data.getClient().equals("sodium")) {
new FancyMessage(MessageType.INFO, PluginData.getMessageUtil())
.addSimple("If you are using " + ChatColor.GREEN + ChatColor.BOLD + "Sodium "
+ ChatColor.AQUA + "you might experience" + ChatColor.GREEN + " texture errors"
+ ChatColor.AQUA + " as your server RP is not set to Sodium variant. ")
.addClickable("Click here to fix this or do command "
+ ChatColor.GREEN + ChatColor.BOLD + "/rp client sodium.",
"/rp client sodium").setRunDirect()
.send(player);
} else if(player.getClientBrandName().contains("forge")
|| player.getClientBrandName().contains("optifine")) {
new FancyMessage(MessageType.INFO, PluginData.getMessageUtil())
.addSimple("If you are using " + ChatColor.GREEN + ChatColor.BOLD + "Optifine "
+ ChatColor.AQUA + "you need to" + ChatColor.GREEN +ChatColor.BOLD+ " disable mip-mapping"
+ ChatColor.AQUA + ". Also please notice that "
+ ChatColor.GREEN+ChatColor.BOLD+"Optifine Shaders do not work"
+ ChatColor.AQUA + "with our resource packs.")
.addClickable("Click here to get a " + ChatColor.GREEN + ChatColor.BOLD + "Guide to Shaders on MCME.", "/helper shaders").setRunDirect()
.send(player);
}
}
cancel();
} else counter --;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,46 @@
import org.bukkit.plugin.messaging.PluginMessageListener;
import org.jetbrains.annotations.NotNull;

import java.io.ByteArrayInputStream;
import java.io.DataInputStream;
import java.io.IOException;
import java.util.Arrays;
import java.util.logging.Logger;

public class RpPluginMessageListener implements PluginMessageListener {

@Override
public void onPluginMessageReceived(@NotNull String s, @NotNull Player player, byte[] bytes) {
public void onPluginMessageReceived(@NotNull String channel, @NotNull Player player, byte[] bytes) {
//Logger.getGlobal().info("Sodium client detected: "+player.getName());

Logger.getGlobal().info("Received message from player " + player.getName() + " on channel "
+ channel + " with data " + Arrays.toString(bytes));
try (var dataStream = new DataInputStream(new ByteArrayInputStream(bytes))) {
int stringLength = readVarInt(dataStream);
String jsonString = new String(dataStream.readNBytes(stringLength));
Logger.getGlobal().info("data = " + jsonString);
} catch (IOException e) {
Logger.getGlobal().warning("Received invalid MCME Modpack marker data from player " + player.getName() + " (" + player.getUniqueId() + "): " + Arrays.toString(bytes));
}

RpManager.addSodiumClient(player,"unknown");
}

private int readVarInt(DataInputStream dataStream) throws IOException {
// This will break for strings over 127 characters long.
int accumulator = 0;
for (int index = 0; true; index++) {
if (index >= 4) {
throw new IllegalArgumentException("VarInt too long. Reached index " + index);
}

int nextByte = dataStream.readUnsignedByte();
accumulator <<= 8;
accumulator |= nextByte & 0x7f;
if ((nextByte & 0x80) == 0) break;
}

return accumulator;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.mcmiddleearth.architect.serverResoucePack;

import org.bukkit.entity.Player;
import org.bukkit.plugin.messaging.PluginMessageListener;
import org.jetbrains.annotations.NotNull;

import java.io.ByteArrayInputStream;
import java.io.DataInputStream;
import java.io.IOException;
import java.util.Arrays;
import java.util.logging.Logger;

public class TestPluginMessageListener implements PluginMessageListener {

@Override
public void onPluginMessageReceived(@NotNull String channel, @NotNull Player player, byte[] bytes) {
//Logger.getGlobal().info("Sodium client detected: "+player.getName());

Logger.getGlobal().info("Received message from player " + player.getName() + " on channel "
+ channel + " with data " + Arrays.toString(bytes));
try (var dataStream = new DataInputStream(new ByteArrayInputStream(bytes))) {
int stringLength = readVarInt(dataStream);
String jsonString = new String(dataStream.readNBytes(stringLength));
Logger.getGlobal().info("data = " + jsonString);
} catch (IOException e) {
Logger.getGlobal().warning("Received invalid MCME Modpack marker data from player " + player.getName() + " (" + player.getUniqueId() + "): " + Arrays.toString(bytes));
}

}

private int readVarInt(DataInputStream dataStream) throws IOException {
// This will break for strings over 127 characters long.
int accumulator = 0;
for (int index = 0; true; index++) {
if (index >= 4) {
throw new IllegalArgumentException("VarInt too long. Reached index " + index);
}

int nextByte = dataStream.readUnsignedByte();
accumulator <<= 8;
accumulator |= nextByte & 0x7f;
if ((nextByte & 0x80) == 0) break;
}

return accumulator;
}

}

0 comments on commit fd7679e

Please sign in to comment.