Add Util class for sending titles to players

This commit is contained in:
Shaun Bennett 2014-09-05 19:46:11 -05:00
parent 8ad137c218
commit eb27c1dfbe
3 changed files with 90 additions and 1 deletions

View File

@ -10,6 +10,7 @@ import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.craftbukkit.v1_7_R4.entity.CraftEntity;
import org.bukkit.craftbukkit.v1_7_R4.entity.CraftPlayer;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
@ -396,6 +397,11 @@ public class UtilPlayer
return (((CraftEntity)player).getHandle().getDataWatcher().getByte(0) & 1 << 4) != 0;
}
public static boolean is1_8(Player player)
{
return ((CraftPlayer)player).getHandle().playerConnection.networkManager.getVersion() >= 47;
}
/*
public void setListName(Player player, CoreClient client)

View File

@ -0,0 +1,82 @@
package mineplex.core.common.util;
import org.bukkit.craftbukkit.v1_7_R4.entity.CraftPlayer;
import org.bukkit.entity.Player;
import net.minecraft.server.v1_7_R4.ChatMessage;
import org.spigotmc.ProtocolInjector.PacketTitle;
import org.spigotmc.ProtocolInjector.PacketTitle.Action;
/**
* Created by Shaun on 9/5/2014.
*/
public class UtilTitle
{
/**
* Show Title text for a player with their current set timings.
*
* Default timings are 20, 60, 20 (in ticks)
*/
public static void showTitle(String text, Player... players)
{
ChatMessage message = new ChatMessage(text);
PacketTitle packet = new PacketTitle(Action.TITLE, message);
sendPacket(packet, players);
}
/**
* Set the current subtitle for a player.
*
* This stays unless reset or cleared, and doesn't appear unless a title is showing
*/
public static void setSubtitle(String text, Player... players)
{
ChatMessage message = new ChatMessage(text);
PacketTitle packet = new PacketTitle(Action.SUBTITLE, message);
sendPacket(packet, players);
}
/**
* Set timings for a player.
*
* Remember these are in ticks
*/
public static void setTimings(int fadeInTicks, int stayTicks, int fadeOutTicks, Player... players)
{
PacketTitle packet = new PacketTitle(Action.TIMES, fadeInTicks, stayTicks, fadeOutTicks);
sendPacket(packet, players);
}
/**
* Clear the title that is currently being displayed, has no affect on timings or subtitle.
*/
public static void clear(Player... players)
{
PacketTitle packet = new PacketTitle(Action.CLEAR);
sendPacket(packet, players);
}
/**
* Reset subtitle and timings for a player.
*
* This will set the subtitle to nothing and timings back to default (20, 60, 20)
*/
public static void reset(Player... players)
{
PacketTitle packet = new PacketTitle(Action.RESET);
sendPacket(packet, players);
}
private static void sendPacket(PacketTitle packet, Player... players)
{
for (Player player : players)
{
if (UtilPlayer.is1_8(player))
{
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
}
}
}
}

View File

@ -5,6 +5,7 @@ import java.util.List;
import mineplex.core.common.DummyEntity;
import mineplex.core.common.util.NautHashMap;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.packethandler.PacketVerifier;
import mineplex.core.packethandler.PlayerPacketEvent;
import net.minecraft.server.v1_7_R4.DataWatcher;
@ -58,7 +59,7 @@ public class CustomTagFix extends MiniPlugin
Player owner = event.getPlayer();
PacketVerifier verifier = event.getVerifier();
if (((CraftPlayer)owner).getHandle().playerConnection.networkManager.getVersion() >= 47)
if (UtilPlayer.is1_8(event.getPlayer()))
{
if (packet instanceof PacketPlayOutSpawnEntityLiving)
{