mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-26 15:16:45 +01:00
fix titles
This commit is contained in:
parent
eb5ae0ec3c
commit
450e34265e
@ -1,6 +1,7 @@
|
|||||||
package com.intellectualcrafters.plot.titles;
|
package com.intellectualcrafters.plot.titles;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -222,53 +223,52 @@ public class DefaultTitleManager {
|
|||||||
*
|
*
|
||||||
* @param player
|
* @param player
|
||||||
* Player
|
* Player
|
||||||
|
* @throws InvocationTargetException
|
||||||
|
* @throws IllegalArgumentException
|
||||||
|
* @throws IllegalAccessException
|
||||||
*/
|
*/
|
||||||
public void send(Player player) {
|
public void send(Player player) throws Exception {
|
||||||
if (packetTitle != null) {
|
if (packetTitle != null) {
|
||||||
// First reset previous settings
|
// First reset previous settings
|
||||||
resetTitle(player);
|
resetTitle(player);
|
||||||
try {
|
// Send timings first
|
||||||
// Send timings first
|
Object handle = getHandle(player);
|
||||||
Object handle = getHandle(player);
|
Object connection = getField(handle.getClass(), "playerConnection").get(handle);
|
||||||
Object connection = getField(handle.getClass(), "playerConnection").get(handle);
|
Object[] actions = packetActions.getEnumConstants();
|
||||||
Object[] actions = packetActions.getEnumConstants();
|
Method sendPacket = getMethod(connection.getClass(), "sendPacket");
|
||||||
Method sendPacket = getMethod(connection.getClass(), "sendPacket");
|
Object packet =
|
||||||
Object packet =
|
packetTitle.getConstructor(packetActions, chatBaseComponent, Integer.TYPE, Integer.TYPE, Integer.TYPE).newInstance(actions[2], null, fadeInTime
|
||||||
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));
|
||||||
* (ticks ? 1 : 20), stayTime * (ticks ? 1 : 20), fadeOutTime * (ticks ? 1 : 20));
|
// Send if set
|
||||||
// Send if set
|
if (fadeInTime != -1 && fadeOutTime != -1 && stayTime != -1)
|
||||||
if (fadeInTime != -1 && fadeOutTime != -1 && stayTime != -1)
|
sendPacket.invoke(connection, packet);
|
||||||
sendPacket.invoke(connection, packet);
|
|
||||||
|
// Send title
|
||||||
// Send title
|
Object serialized =
|
||||||
Object serialized =
|
getMethod(nmsChatSerializer, "a", String.class).invoke(null, "{text:\""
|
||||||
getMethod(nmsChatSerializer, "a", String.class).invoke(null, "{text:\""
|
+ ChatColor.translateAlternateColorCodes('&', title) + "\",color:"
|
||||||
+ ChatColor.translateAlternateColorCodes('&', title) + "\",color:"
|
+ titleColor.name().toLowerCase() + "}");
|
||||||
+ titleColor.name().toLowerCase() + "}");
|
packet =
|
||||||
packet =
|
packetTitle.getConstructor(packetActions, chatBaseComponent).newInstance(actions[0], serialized);
|
||||||
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);
|
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
|
* Broadcast the title to all players
|
||||||
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public void broadcast() {
|
public void broadcast() throws Exception {
|
||||||
for (Player p : Bukkit.getOnlinePlayers()) {
|
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||||
send(p);
|
send(p);
|
||||||
}
|
}
|
||||||
|
@ -221,58 +221,54 @@ public class HackTitleManager {
|
|||||||
* @param player
|
* @param player
|
||||||
* Player
|
* Player
|
||||||
*/
|
*/
|
||||||
public void send(Player player) {
|
public void send(Player player) throws Exception {
|
||||||
if (getProtocolVersion(player) >= 47 && isSpigot()
|
if (getProtocolVersion(player) >= 47 && isSpigot()
|
||||||
&& packetTitle != null) {
|
&& packetTitle != null) {
|
||||||
// First reset previous settings
|
// First reset previous settings
|
||||||
resetTitle(player);
|
resetTitle(player);
|
||||||
try {
|
// Send timings first
|
||||||
// Send timings first
|
Object handle = getHandle(player);
|
||||||
Object handle = getHandle(player);
|
Object connection = getField(handle.getClass(),
|
||||||
Object connection = getField(handle.getClass(),
|
"playerConnection").get(handle);
|
||||||
"playerConnection").get(handle);
|
Object[] actions = packetActions.getEnumConstants();
|
||||||
Object[] actions = packetActions.getEnumConstants();
|
Method sendPacket = getMethod(connection.getClass(),
|
||||||
Method sendPacket = getMethod(connection.getClass(),
|
"sendPacket");
|
||||||
"sendPacket");
|
Object packet = packetTitle.getConstructor(packetActions,
|
||||||
Object packet = packetTitle.getConstructor(packetActions,
|
Integer.TYPE, Integer.TYPE, Integer.TYPE).newInstance(
|
||||||
Integer.TYPE, Integer.TYPE, Integer.TYPE).newInstance(
|
actions[2], fadeInTime * (ticks ? 1 : 20),
|
||||||
actions[2], fadeInTime * (ticks ? 1 : 20),
|
stayTime * (ticks ? 1 : 20),
|
||||||
stayTime * (ticks ? 1 : 20),
|
fadeOutTime * (ticks ? 1 : 20));
|
||||||
fadeOutTime * (ticks ? 1 : 20));
|
// Send if set
|
||||||
// Send if set
|
if (fadeInTime != -1 && fadeOutTime != -1 && stayTime != -1)
|
||||||
if (fadeInTime != -1 && fadeOutTime != -1 && stayTime != -1)
|
sendPacket.invoke(connection, packet);
|
||||||
sendPacket.invoke(connection, packet);
|
|
||||||
|
|
||||||
// Send title
|
// Send title
|
||||||
Object serialized = getMethod(nmsChatSerializer, "a",
|
Object serialized = getMethod(nmsChatSerializer, "a",
|
||||||
String.class).invoke(
|
String.class).invoke(
|
||||||
null,
|
null,
|
||||||
"{text:\""
|
"{text:\""
|
||||||
+ ChatColor.translateAlternateColorCodes('&',
|
+ ChatColor.translateAlternateColorCodes('&',
|
||||||
title) + "\",color:"
|
title) + "\",color:"
|
||||||
+ titleColor.name().toLowerCase() + "}");
|
+ 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,
|
packet = packetTitle.getConstructor(packetActions,
|
||||||
getNMSClass("IChatBaseComponent")).newInstance(
|
getNMSClass("IChatBaseComponent")).newInstance(
|
||||||
actions[0], serialized);
|
actions[1], serialized);
|
||||||
sendPacket.invoke(connection, packet);
|
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
|
* Broadcast the title to all players
|
||||||
*/
|
*/
|
||||||
public void broadcast() {
|
public void broadcast() throws Exception {
|
||||||
for (Player p : Bukkit.getOnlinePlayers()) {
|
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||||
send(p);
|
send(p);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user