Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-12-27 00:22:51 +01:00
Changes on plugin channel rewriting
Dieser Commit ist enthalten in:
Ursprung
7335c8ea98
Commit
c47d5dcba6
@ -3,6 +3,7 @@ package us.myles.ViaVersion.protocols.protocolsnapshotto1_12_2.packets;
|
|||||||
import com.github.steveice10.opennbt.tag.builtin.*;
|
import com.github.steveice10.opennbt.tag.builtin.*;
|
||||||
import com.google.common.base.Joiner;
|
import com.google.common.base.Joiner;
|
||||||
import com.google.common.base.Optional;
|
import com.google.common.base.Optional;
|
||||||
|
import com.google.common.io.BaseEncoding;
|
||||||
import us.myles.ViaVersion.api.PacketWrapper;
|
import us.myles.ViaVersion.api.PacketWrapper;
|
||||||
import us.myles.ViaVersion.api.minecraft.item.Item;
|
import us.myles.ViaVersion.api.minecraft.item.Item;
|
||||||
import us.myles.ViaVersion.api.protocol.Protocol;
|
import us.myles.ViaVersion.api.protocol.Protocol;
|
||||||
@ -133,7 +134,7 @@ public class InventoryPackets {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
String originalChannel = channel;
|
String originalChannel = channel;
|
||||||
channel = getNewPluginChannelId(channel).orNull();
|
channel = getNewPluginChannelId(channel);
|
||||||
if (channel == null) {
|
if (channel == null) {
|
||||||
System.out.println("Plugin message cancelled " + originalChannel); // TODO remove this debug
|
System.out.println("Plugin message cancelled " + originalChannel); // TODO remove this debug
|
||||||
wrapper.cancel();
|
wrapper.cancel();
|
||||||
@ -142,7 +143,8 @@ public class InventoryPackets {
|
|||||||
String[] channels = new String(wrapper.read(Type.REMAINING_BYTES), StandardCharsets.UTF_8).split("\0");
|
String[] channels = new String(wrapper.read(Type.REMAINING_BYTES), StandardCharsets.UTF_8).split("\0");
|
||||||
List<String> rewrittenChannels = new ArrayList<>();
|
List<String> rewrittenChannels = new ArrayList<>();
|
||||||
for (int i = 0; i < channels.length; i++) {
|
for (int i = 0; i < channels.length; i++) {
|
||||||
String rewritten = getNewPluginChannelId(channels[i]).orNull();
|
String rewritten = getNewPluginChannelId(channels[i]);
|
||||||
|
System.out.println(channels[i] + " -> " + rewritten);
|
||||||
if (rewritten != null)
|
if (rewritten != null)
|
||||||
rewrittenChannels.add(rewritten);
|
rewrittenChannels.add(rewritten);
|
||||||
else
|
else
|
||||||
@ -213,7 +215,8 @@ public class InventoryPackets {
|
|||||||
public void handle(PacketWrapper wrapper) throws Exception {
|
public void handle(PacketWrapper wrapper) throws Exception {
|
||||||
String channel = wrapper.get(Type.STRING, 0);
|
String channel = wrapper.get(Type.STRING, 0);
|
||||||
String originalChannel = channel;
|
String originalChannel = channel;
|
||||||
channel = getOldPluginChannelId(channel).orNull();
|
channel = getOldPluginChannelId(channel);
|
||||||
|
System.out.println(originalChannel + " -> " + channel);
|
||||||
if (channel == null) {
|
if (channel == null) {
|
||||||
System.out.println("Plugin message cancelled " + originalChannel); // TODO remove this debug
|
System.out.println("Plugin message cancelled " + originalChannel); // TODO remove this debug
|
||||||
wrapper.cancel();
|
wrapper.cancel();
|
||||||
@ -222,7 +225,8 @@ public class InventoryPackets {
|
|||||||
String[] channels = new String(wrapper.read(Type.REMAINING_BYTES), StandardCharsets.UTF_8).split("\0");
|
String[] channels = new String(wrapper.read(Type.REMAINING_BYTES), StandardCharsets.UTF_8).split("\0");
|
||||||
List<String> rewrittenChannels = new ArrayList<>();
|
List<String> rewrittenChannels = new ArrayList<>();
|
||||||
for (int i = 0; i < channels.length; i++) {
|
for (int i = 0; i < channels.length; i++) {
|
||||||
String rewritten = getOldPluginChannelId(channels[i]).orNull();
|
String rewritten = getOldPluginChannelId(channels[i]);
|
||||||
|
System.out.println(channels[i] + " -> " + rewritten);
|
||||||
if (rewritten != null)
|
if (rewritten != null)
|
||||||
rewrittenChannels.add(rewritten);
|
rewrittenChannels.add(rewritten);
|
||||||
else
|
else
|
||||||
@ -480,34 +484,47 @@ public class InventoryPackets {
|
|||||||
|| id == 443; // elytra
|
|| id == 443; // elytra
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Optional<String> getNewPluginChannelId(String old) {
|
public static String getNewPluginChannelId(String old) {
|
||||||
if (old.equalsIgnoreCase("MC|TrList"))
|
switch (old) {
|
||||||
return Optional.of("minecraft:trader_list");
|
case "MC|TrList":
|
||||||
if (old.equalsIgnoreCase("MC|Brand"))
|
return "minecraft:trader_list";
|
||||||
return Optional.of("minecraft:brand");
|
case "MC|Brand":
|
||||||
if (old.equalsIgnoreCase("MC|BOpen"))
|
return "minecraft:brand";
|
||||||
return Optional.of("minecraft:book_open");
|
case "MC|BOpen":
|
||||||
if (old.equalsIgnoreCase("MC|DebugPath"))
|
return "minecraft:book_open";
|
||||||
return Optional.of("minecraft:debug/paths");
|
case "MC|DebugPath":
|
||||||
if (old.equalsIgnoreCase("MC|DebugNeighborsUpdate"))
|
return "minecraft:debug/paths";
|
||||||
return Optional.of("minecraft:debug/neighbors_update");
|
case "MC|DebugNeighborsUpdate":
|
||||||
if (old.equalsIgnoreCase("REGISTER"))
|
return "minecraft:debug/neighbors_update";
|
||||||
return Optional.of("minecraft:register");
|
case "REGISTER":
|
||||||
if (old.equalsIgnoreCase("UNREGISTER"))
|
return "minecraft:register";
|
||||||
return Optional.of("minecraft:unregister");
|
case "UNREGISTER":
|
||||||
return Optional.absent();
|
return "minecraft:unregister";
|
||||||
|
case "BungeeCord":
|
||||||
|
return "bungeecord:main";
|
||||||
|
default:
|
||||||
|
return old.matches("[0-9a-z_-]+:[0-9a-z_/.-]+") // Identifier regex
|
||||||
|
? old
|
||||||
|
: "viaversion:legacy/" + BaseEncoding.base32().lowerCase().withPadChar('-').encode(
|
||||||
|
old.getBytes(StandardCharsets.UTF_8));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Optional<String> getOldPluginChannelId(String newId) {
|
public static String getOldPluginChannelId(String newId) {
|
||||||
switch (newId) {
|
switch (newId) {
|
||||||
case "minecraft:register":
|
case "minecraft:register":
|
||||||
return Optional.of("REGISTER");
|
return "REGISTER";
|
||||||
case "minecraft:unregister":
|
case "minecraft:unregister":
|
||||||
return Optional.of("UNREGISTER");
|
return "UNREGISTER";
|
||||||
case "minecraft:brand":
|
case "minecraft:brand":
|
||||||
return Optional.of("MC|Brand");
|
return "MC|Brand";
|
||||||
|
case "bungeecord:main":
|
||||||
|
return "BungeeCord";
|
||||||
default:
|
default:
|
||||||
return Optional.absent();
|
return newId.startsWith("viaversion:legacy/")
|
||||||
|
? new String(BaseEncoding.base32().lowerCase().withPadChar('-').decode(
|
||||||
|
newId.substring(18)), StandardCharsets.UTF_8)
|
||||||
|
: newId;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren