Package wtf.choco.veinminer.network
Interface PluginMessage<T extends PluginMessageListener>
- Type Parameters:
T- the type of listener that will handle this message
- All Known Implementing Classes:
PluginMessageClientboundHandshakeResponse,PluginMessageClientboundSetConfig,PluginMessageClientboundSetPattern,PluginMessageClientboundSyncRegisteredPatterns,PluginMessageClientboundVeinMineResults,PluginMessageServerboundHandshake,PluginMessageServerboundRequestVeinMine,PluginMessageServerboundSelectPattern,PluginMessageServerboundToggleVeinMiner
public interface PluginMessage<T extends PluginMessageListener>
Represents a message sent between client and server.
By convention, a PluginMessage implementation should have a constructor that accepts a
PluginMessageByteBuffer from which data may be read into final fields. An example
implementation may look something like the following:
public final class PluginMessageServerboundExample implements PluginMessage<ServerboundPluginMessageListener> {
private final String stringValue;
private final int intValue;
// This is intended for when the message needs to be constructed to be sent to the client/server
public PluginMessageServerboundExample(String stringValue, int intValue) {
this.stringValue = stringValue;
this.intValue = intValue;
}
// This is intended for reading from the byte buffer. Used on construction of this message.
public PluginMessageServerboundExample(PluginMessageByteBuffer buffer) {
this(buffer.readString(), buffer.readVarInt());
}
public String getStringValue() {
return stringValue;
}
public int getIntValue() {
return intValue;
}
@Override
public void write(PluginMessageByteBuffer buffer) {
buffer.writeString(stringValue);
buffer.writeVarInt(intValue);
}
@Override
public void handle(ServerboundPluginMessageListener listener) {
// Handle here. Conventionally, the listener should have a method to handle this message in specific... like so:
listener.handleExample(this);
}
}
-
Method Summary
Modifier and TypeMethodDescriptionvoidHandle this message.voidwrite(@NotNull PluginMessageByteBuffer buffer) Write this plugin message to the providedPluginMessageByteBuffer.
-
Method Details
-
write
Write this plugin message to the providedPluginMessageByteBuffer.- Parameters:
buffer- the buffer to which data should be written
-
handle
Handle this message.- Parameters:
listener- the plugin message listener
-