From 450e34265eb20bf19d4122e76c9f1092a0036c24 Mon Sep 17 00:00:00 2001 From: boy0001 Date: Tue, 3 Feb 2015 12:47:10 +1100 Subject: [PATCH] fix titles --- .../plot/titles/DefaultTitleManager.java | 70 +++++++-------- .../plot/titles/HackTitleManager.java | 86 +++++++++---------- 2 files changed, 76 insertions(+), 80 deletions(-) diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/titles/DefaultTitleManager.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/titles/DefaultTitleManager.java index 796f40211..3d69cd0e1 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/titles/DefaultTitleManager.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/titles/DefaultTitleManager.java @@ -1,6 +1,7 @@ package com.intellectualcrafters.plot.titles; import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.HashMap; import java.util.Map; @@ -222,53 +223,52 @@ public class DefaultTitleManager { * * @param player * Player + * @throws InvocationTargetException + * @throws IllegalArgumentException + * @throws IllegalAccessException */ - public void send(Player player) { + public void send(Player player) throws Exception { if (packetTitle != null) { // First reset previous settings resetTitle(player); - try { - // Send timings first - Object handle = getHandle(player); - Object connection = getField(handle.getClass(), "playerConnection").get(handle); - Object[] actions = packetActions.getEnumConstants(); - Method sendPacket = getMethod(connection.getClass(), "sendPacket"); - Object packet = - packetTitle.getConstructor(packetActions, chatBaseComponent, Integer.TYPE, Integer.TYPE, Integer.TYPE).newInstance(actions[2], null, fadeInTime - * (ticks ? 1 : 20), stayTime * (ticks ? 1 : 20), fadeOutTime * (ticks ? 1 : 20)); - // Send if set - if (fadeInTime != -1 && fadeOutTime != -1 && stayTime != -1) - sendPacket.invoke(connection, packet); - - // Send title - Object serialized = - getMethod(nmsChatSerializer, "a", String.class).invoke(null, "{text:\"" - + ChatColor.translateAlternateColorCodes('&', title) + "\",color:" - + titleColor.name().toLowerCase() + "}"); - packet = - packetTitle.getConstructor(packetActions, chatBaseComponent).newInstance(actions[0], serialized); + // Send timings first + Object handle = getHandle(player); + Object connection = getField(handle.getClass(), "playerConnection").get(handle); + Object[] actions = packetActions.getEnumConstants(); + Method sendPacket = getMethod(connection.getClass(), "sendPacket"); + Object packet = + packetTitle.getConstructor(packetActions, chatBaseComponent, Integer.TYPE, Integer.TYPE, Integer.TYPE).newInstance(actions[2], null, fadeInTime + * (ticks ? 1 : 20), stayTime * (ticks ? 1 : 20), fadeOutTime * (ticks ? 1 : 20)); + // Send if set + if (fadeInTime != -1 && fadeOutTime != -1 && stayTime != -1) + sendPacket.invoke(connection, packet); + + // Send title + Object serialized = + getMethod(nmsChatSerializer, "a", String.class).invoke(null, "{text:\"" + + ChatColor.translateAlternateColorCodes('&', title) + "\",color:" + + titleColor.name().toLowerCase() + "}"); + packet = + packetTitle.getConstructor(packetActions, chatBaseComponent).newInstance(actions[0], serialized); + sendPacket.invoke(connection, packet); + if (subtitle != "") { + // Send subtitle if present + serialized = + getMethod(nmsChatSerializer, "a", String.class).invoke(null, "{text:\"" + + ChatColor.translateAlternateColorCodes('&', subtitle) + "\",color:" + + subtitleColor.name().toLowerCase() + "}"); + packet = + packetTitle.getConstructor(packetActions, chatBaseComponent).newInstance(actions[1], serialized); sendPacket.invoke(connection, packet); - if (subtitle != "") { - // Send subtitle if present - serialized = - getMethod(nmsChatSerializer, "a", String.class).invoke(null, "{text:\"" - + ChatColor.translateAlternateColorCodes('&', subtitle) + "\",color:" - + subtitleColor.name().toLowerCase() + "}"); - packet = - packetTitle.getConstructor(packetActions, chatBaseComponent).newInstance(actions[1], serialized); - sendPacket.invoke(connection, packet); - } - } - catch (Exception e) { - e.printStackTrace(); } } } /** * Broadcast the title to all players + * @throws Exception */ - public void broadcast() { + public void broadcast() throws Exception { for (Player p : Bukkit.getOnlinePlayers()) { send(p); } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/titles/HackTitleManager.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/titles/HackTitleManager.java index 84e39fe5c..a5ce7042b 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/titles/HackTitleManager.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/titles/HackTitleManager.java @@ -221,58 +221,54 @@ public class HackTitleManager { * @param player * Player */ - public void send(Player player) { + public void send(Player player) throws Exception { if (getProtocolVersion(player) >= 47 && isSpigot() && packetTitle != null) { // First reset previous settings resetTitle(player); - try { - // Send timings first - Object handle = getHandle(player); - Object connection = getField(handle.getClass(), - "playerConnection").get(handle); - Object[] actions = packetActions.getEnumConstants(); - Method sendPacket = getMethod(connection.getClass(), - "sendPacket"); - Object packet = packetTitle.getConstructor(packetActions, - Integer.TYPE, Integer.TYPE, Integer.TYPE).newInstance( - actions[2], fadeInTime * (ticks ? 1 : 20), - stayTime * (ticks ? 1 : 20), - fadeOutTime * (ticks ? 1 : 20)); - // Send if set - if (fadeInTime != -1 && fadeOutTime != -1 && stayTime != -1) - sendPacket.invoke(connection, packet); + // Send timings first + Object handle = getHandle(player); + Object connection = getField(handle.getClass(), + "playerConnection").get(handle); + Object[] actions = packetActions.getEnumConstants(); + Method sendPacket = getMethod(connection.getClass(), + "sendPacket"); + Object packet = packetTitle.getConstructor(packetActions, + Integer.TYPE, Integer.TYPE, Integer.TYPE).newInstance( + actions[2], fadeInTime * (ticks ? 1 : 20), + stayTime * (ticks ? 1 : 20), + fadeOutTime * (ticks ? 1 : 20)); + // Send if set + if (fadeInTime != -1 && fadeOutTime != -1 && stayTime != -1) + sendPacket.invoke(connection, packet); - // Send title - Object serialized = getMethod(nmsChatSerializer, "a", - String.class).invoke( - null, - "{text:\"" - + ChatColor.translateAlternateColorCodes('&', - title) + "\",color:" - + titleColor.name().toLowerCase() + "}"); + // Send title + Object serialized = getMethod(nmsChatSerializer, "a", + String.class).invoke( + null, + "{text:\"" + + ChatColor.translateAlternateColorCodes('&', + title) + "\",color:" + + titleColor.name().toLowerCase() + "}"); + packet = packetTitle.getConstructor(packetActions, + getNMSClass("IChatBaseComponent")).newInstance( + actions[0], serialized); + sendPacket.invoke(connection, packet); + if (subtitle != "") { + // Send subtitle if present + serialized = getMethod(nmsChatSerializer, "a", String.class) + .invoke(null, + "{text:\"" + + ChatColor + .translateAlternateColorCodes( + '&', subtitle) + + "\",color:" + + subtitleColor.name() + .toLowerCase() + "}"); packet = packetTitle.getConstructor(packetActions, getNMSClass("IChatBaseComponent")).newInstance( - actions[0], serialized); + actions[1], serialized); sendPacket.invoke(connection, packet); - if (subtitle != "") { - // Send subtitle if present - serialized = getMethod(nmsChatSerializer, "a", String.class) - .invoke(null, - "{text:\"" - + ChatColor - .translateAlternateColorCodes( - '&', subtitle) - + "\",color:" - + subtitleColor.name() - .toLowerCase() + "}"); - packet = packetTitle.getConstructor(packetActions, - getNMSClass("IChatBaseComponent")).newInstance( - actions[1], serialized); - sendPacket.invoke(connection, packet); - } - } catch (Exception e) { - e.printStackTrace(); } } } @@ -280,7 +276,7 @@ public class HackTitleManager { /** * Broadcast the title to all players */ - public void broadcast() { + public void broadcast() throws Exception { for (Player p : Bukkit.getOnlinePlayers()) { send(p); }