mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-17 11:24:56 -04:00
DefaultPluginChannels: use identifier instead of String
This commit is contained in:
parent
a69bb91f64
commit
cd6afe325c
@ -13,26 +13,29 @@
|
|||||||
|
|
||||||
package de.bixilon.minosoft.protocol.modding.channels;
|
package de.bixilon.minosoft.protocol.modding.channels;
|
||||||
|
|
||||||
|
import de.bixilon.minosoft.game.datatypes.Identifier;
|
||||||
|
import de.bixilon.minosoft.protocol.protocol.ProtocolVersion;
|
||||||
|
|
||||||
public enum DefaultPluginChannels {
|
public enum DefaultPluginChannels {
|
||||||
MC_BRAND("MC|Brand");
|
MC_BRAND(new Identifier("MC|Brand", "minecraft:brand"));
|
||||||
|
|
||||||
|
|
||||||
final String name;
|
final Identifier identifier;
|
||||||
|
|
||||||
DefaultPluginChannels(String name) {
|
DefaultPluginChannels(Identifier identifier) {
|
||||||
this.name = name;
|
this.identifier = identifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static DefaultPluginChannels byName(String name) {
|
public static DefaultPluginChannels byName(String name, ProtocolVersion version) {
|
||||||
for (DefaultPluginChannels d : values()) {
|
for (DefaultPluginChannels d : values()) {
|
||||||
if (d.getName().equals(name)) {
|
if (d.getIdentifier().get(version).equals(name)) {
|
||||||
return d;
|
return d;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public Identifier getIdentifier() {
|
||||||
return name;
|
return identifier;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -74,7 +74,7 @@ public class PluginChannelHandler {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// check if channel was registered or if it is a default channel
|
// check if channel was registered or if it is a default channel
|
||||||
if (!registeredClientChannels.contains(name) && DefaultPluginChannels.byName(name) == null) {
|
if (!registeredClientChannels.contains(name) && DefaultPluginChannels.byName(name, connection.getVersion()) == null) {
|
||||||
Log.debug(String.format("Server tried to send data into unregistered plugin channel (name=\"%s\", messageLength=%d, string=\"%s\")", name, data.length, new String(data)));
|
Log.debug(String.format("Server tried to send data into unregistered plugin channel (name=\"%s\", messageLength=%d, string=\"%s\")", name, data.length, new String(data)));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -97,7 +97,7 @@ public class PluginChannelHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void registerServerChannel(String name) {
|
public void registerServerChannel(String name) {
|
||||||
if (DefaultPluginChannels.byName(name) != null) {
|
if (DefaultPluginChannels.byName(name, connection.getVersion()) != null) {
|
||||||
// channel is a default channel, can not register
|
// channel is a default channel, can not register
|
||||||
throw new IllegalArgumentException(String.format("Can not register default Minecraft plugin channel (name=%s)", name));
|
throw new IllegalArgumentException(String.format("Can not register default Minecraft plugin channel (name=%s)", name));
|
||||||
}
|
}
|
||||||
@ -106,7 +106,7 @@ public class PluginChannelHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void unregisterServerChannel(String name) {
|
public void unregisterServerChannel(String name) {
|
||||||
if (DefaultPluginChannels.byName(name) != null) {
|
if (DefaultPluginChannels.byName(name, connection.getVersion()) != null) {
|
||||||
// channel is a default channel, can not unregister
|
// channel is a default channel, can not unregister
|
||||||
throw new IllegalArgumentException(String.format("Can not unregister default Minecraft plugin channel (name=%s)", name));
|
throw new IllegalArgumentException(String.format("Can not unregister default Minecraft plugin channel (name=%s)", name));
|
||||||
}
|
}
|
||||||
|
@ -195,7 +195,7 @@ public class Connection {
|
|||||||
|
|
||||||
public void registerDefaultChannels() {
|
public void registerDefaultChannels() {
|
||||||
// MC|Brand
|
// MC|Brand
|
||||||
getPluginChannelHandler().registerClientHandler(DefaultPluginChannels.MC_BRAND.getName(), (handler, buffer) -> {
|
getPluginChannelHandler().registerClientHandler(DefaultPluginChannels.MC_BRAND.getIdentifier().get(version), (handler, buffer) -> {
|
||||||
String serverVersion;
|
String serverVersion;
|
||||||
String clientVersion = (Minosoft.getConfig().getBoolean(GameConfiguration.NETWORK_FAKE_CLIENT_BRAND) ? "vanilla" : "Minosoft");
|
String clientVersion = (Minosoft.getConfig().getBoolean(GameConfiguration.NETWORK_FAKE_CLIENT_BRAND) ? "vanilla" : "Minosoft");
|
||||||
OutByteBuffer toSend = new OutByteBuffer(getVersion());
|
OutByteBuffer toSend = new OutByteBuffer(getVersion());
|
||||||
@ -210,7 +210,7 @@ public class Connection {
|
|||||||
}
|
}
|
||||||
Log.info(String.format("Server is running \"%s\", connected with %s", serverVersion, getVersion().getName()));
|
Log.info(String.format("Server is running \"%s\", connected with %s", serverVersion, getVersion().getName()));
|
||||||
|
|
||||||
getPluginChannelHandler().sendRawData(DefaultPluginChannels.MC_BRAND.getName(), toSend);
|
getPluginChannelHandler().sendRawData(DefaultPluginChannels.MC_BRAND.getIdentifier().get(version), toSend);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,13 +19,13 @@ import de.bixilon.minosoft.protocol.protocol.OutPacketBuffer;
|
|||||||
import de.bixilon.minosoft.protocol.protocol.Packets;
|
import de.bixilon.minosoft.protocol.protocol.Packets;
|
||||||
import de.bixilon.minosoft.protocol.protocol.ProtocolVersion;
|
import de.bixilon.minosoft.protocol.protocol.ProtocolVersion;
|
||||||
|
|
||||||
public class PacketConfirmTransaction implements ServerboundPacket {
|
public class PacketConfirmTransactionSending implements ServerboundPacket {
|
||||||
|
|
||||||
final byte windowId;
|
final byte windowId;
|
||||||
final short actionNumber;
|
final short actionNumber;
|
||||||
final boolean accepted;
|
final boolean accepted;
|
||||||
|
|
||||||
public PacketConfirmTransaction(byte windowId, short actionNumber, boolean accepted) {
|
public PacketConfirmTransactionSending(byte windowId, short actionNumber, boolean accepted) {
|
||||||
this.windowId = windowId;
|
this.windowId = windowId;
|
||||||
this.actionNumber = actionNumber;
|
this.actionNumber = actionNumber;
|
||||||
this.accepted = accepted;
|
this.accepted = accepted;
|
Loading…
x
Reference in New Issue
Block a user