Created
February 7, 2020 23:07
-
-
Save NahuLD/5d10f65fa7faede301a20cdbde31232b to your computer and use it in GitHub Desktop.
Useful plugin message provider for Bukkit!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.google.common.io.ByteArrayDataOutput; | |
import com.google.common.io.ByteStreams; | |
import org.bukkit.Bukkit; | |
import org.bukkit.plugin.Plugin; | |
public class MessageProvider { | |
@SuppressWarnings("UnstableApiUsage") | |
private ByteArrayDataOutput output = ByteStreams.newDataOutput(); | |
public MessageProvider() { | |
this(null, null); | |
} | |
public MessageProvider(String subChannel, String argument) { | |
if (subChannel == null || argument == null) | |
return; | |
output.writeUTF(subChannel); | |
output.writeUTF(argument); | |
} | |
public MessageProvider and(String argument) { | |
output.writeUTF(argument); | |
return this; | |
} | |
public MessageProvider and(short size) { | |
output.write(size); | |
return this; | |
} | |
public MessageProvider and(boolean argument) { | |
output.writeBoolean(argument); | |
return this; | |
} | |
public MessageProvider and(double argument) { | |
output.writeDouble(argument); | |
return this; | |
} | |
public MessageProvider and(float argument) { | |
output.writeFloat(argument); | |
return this; | |
} | |
public MessageProvider and(long argument) { | |
output.writeLong(argument); | |
return this; | |
} | |
public MessageProvider with(MessageProvider provider) { | |
byte[] array = provider.build(); | |
output.writeShort(array.length); | |
output.write(array); | |
return this; | |
} | |
public void send(Plugin plugin) { | |
Bukkit.getServer().sendPluginMessage(plugin, "BungeeCord", output.toByteArray()); | |
} | |
private byte[] build() { | |
return output.toByteArray(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment