Skip to content

Instantly share code, notes, and snippets.

@Bastian
Created July 20, 2014 12:16
Show Gist options
  • Select an option

  • Save Bastian/95953846d59c28e8fc72 to your computer and use it in GitHub Desktop.

Select an option

Save Bastian/95953846d59c28e8fc72 to your computer and use it in GitHub Desktop.
package de.oppermann.bastian.lib.miscellaneous;
import java.util.UUID;
import net.minecraft.server.v1_7_R4.Packet;
import org.bukkit.Bukkit;
import org.bukkit.craftbukkit.v1_7_R4.entity.CraftPlayer;
import org.bukkit.entity.Player;
public class CraftBukkitUtil {
private CraftBukkitUtil() { }
/**
* Sends a packet to every online player.
*
* @param packet The packet to send.
*/
public static void sendGlobalPacket(Packet packet) {
for (Player player : Bukkit.getOnlinePlayers()) {
sendPacket(packet, player);
}
}
/**
* Sends a packet to every online player.
*
* @param packet The packet to send.
* @param besides If the packet should not be send to the player with this uuid.
*/
public static void sendGlobalPacket(Packet packet, UUID besides) {
for (Player player : Bukkit.getOnlinePlayers()) {
if (player.getUniqueId() == besides) {
continue;
}
sendPacket(packet, player);
}
}
/**
* Sends a packet to a specific player.
*
* @param packet The packet to send.
* @param player The player.
*/
public static void sendPacket(Packet packet, Player player) {
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment