Last active
August 29, 2015 14:07
-
-
Save Goblom/f3a74829f0fedbde83af to your computer and use it in GitHub Desktop.
This file contains 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
package net.theemeraldisle.core.utils; | |
import net.minecraft.server.v1_7_R4.ChatSerializer; | |
import net.minecraft.server.v1_7_R4.IChatBaseComponent; | |
import net.minecraft.server.v1_7_R4.PacketPlayOutChat; | |
import org.bukkit.Bukkit; | |
import org.bukkit.ChatColor; | |
import org.bukkit.craftbukkit.v1_7_R4.entity.CraftPlayer; | |
import org.bukkit.entity.Player; | |
import org.json.simple.JSONObject; | |
/** | |
* | |
* @author Goblom | |
*/ | |
public class TitleUtil { | |
private static final int MIN_VERSION = 47; | |
public static void send(Player player, String msg) { | |
msg = color(msg); | |
JSONObject json = new JSONObject(); | |
json.put("text", msg); | |
IChatBaseComponent chat = ChatSerializer.a(json.toJSONString()); | |
PacketPlayOutChat bar = new PacketPlayOutChat(chat, 2); | |
if (isViable(player)) { | |
((CraftPlayer) player).getHandle().playerConnection.sendPacket(bar); | |
} | |
} | |
public static void send(String msg) { | |
for (Player player : Bukkit.getOnlinePlayers()) { | |
send(player, msg); | |
} | |
} | |
private static String color(String ms) { | |
return ChatColor.translateAlternateColorCodes('&', ms); | |
} | |
private static int getVersion(Player player) { | |
CraftPlayer cP = (CraftPlayer) player; | |
return cP.getHandle().playerConnection.networkManager.getVersion(); | |
} | |
private static boolean isViable(Player player) { | |
return getVersion(player) >= MIN_VERSION; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment