mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-03 14:38:53 +00:00
Plugin message dispatch logic (#275)
This commit is contained in:
1 parent
3c1d46bf46
commit
ed58779ae7
2 files changed
+65
-76
No files matched your search
@@ -13,7 +13,6 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||
import org.bukkit.metadata.MetadataValue;
|
||||
import org.bukkit.permissions.PermissionAttachmentInfo;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Map;
|
||||
@@ -26,6 +25,14 @@ import java.util.stream.Collectors;
|
||||
*/
|
||||
public class BukkitPlayer extends OnlineUser {
|
||||
|
||||
/**
|
||||
* Number of ticks to wait before {@link #sendPluginMessage(String, byte[]) sending a plugin message}.
|
||||
* </p>
|
||||
* This is needed because it is not possible to have players dispatch plugin messages in certain circumstance,
|
||||
* such as on the tick that they join the server.
|
||||
*/
|
||||
private static final long PLUGIN_MESSAGE_DISPATCH_DELAY = 3L;
|
||||
|
||||
// Instance of the implementing plugin
|
||||
private final BukkitHuskHomes plugin;
|
||||
|
||||
@@ -142,9 +149,13 @@ public class BukkitPlayer extends OnlineUser {
|
||||
|
||||
/**
|
||||
* Send a Bukkit plugin message
|
||||
*
|
||||
* @implNote This is dispatched after {@link #PLUGIN_MESSAGE_DISPATCH_DELAY a delay} to ensure that the player
|
||||
* is ready to send receive messages
|
||||
*/
|
||||
public void sendPluginMessage(@NotNull Plugin source, @NotNull String channel, final byte[] message) {
|
||||
player.sendPluginMessage(source, channel, message);
|
||||
public void sendPluginMessage(@NotNull String channel, final byte[] message) {
|
||||
Bukkit.getScheduler().runTaskLater(plugin,
|
||||
() -> player.sendPluginMessage(plugin, channel, message), PLUGIN_MESSAGE_DISPATCH_DELAY);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user