mirror of
https://github.com/Aust1n46/VentureChat.git
synced 2025-07-07 10:54:01 +00:00
Update to 1.17.
Refactor away NMS reflection and replace with ProtocolLib reflection.
This commit is contained in:
parent
00032823cc
commit
77eea94fad
@ -6,19 +6,15 @@ import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.SimpleCommandMap;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
@ -28,7 +24,6 @@ import org.bukkit.scheduler.BukkitScheduler;
|
||||
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.utility.MinecraftReflection;
|
||||
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import mineverse.Aust1n46.chat.alias.Alias;
|
||||
@ -52,7 +47,6 @@ import mineverse.Aust1n46.chat.listeners.SignListener;
|
||||
import mineverse.Aust1n46.chat.localization.Localization;
|
||||
import mineverse.Aust1n46.chat.localization.LocalizedMessage;
|
||||
import mineverse.Aust1n46.chat.utilities.Format;
|
||||
import mineverse.Aust1n46.chat.versions.VersionHandler;
|
||||
import net.milkbowl.vault.chat.Chat;
|
||||
import net.milkbowl.vault.permission.Permission;
|
||||
|
||||
@ -83,12 +77,6 @@ public class MineverseChat extends JavaPlugin implements PluginMessageListener {
|
||||
private static Permission permission = null;
|
||||
private static Chat chat = null;
|
||||
|
||||
// NMS
|
||||
private static Field posField;
|
||||
private static Class<?> chatMessageType;
|
||||
private static Field commandMap;
|
||||
private static Field knownCommands;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
ccInfo = new ChatChannelInfo();
|
||||
@ -153,7 +141,6 @@ public class MineverseChat extends JavaPlugin implements PluginMessageListener {
|
||||
|
||||
registerListeners();
|
||||
Bukkit.getConsoleSender().sendMessage(Format.FormatStringAll("&8[&eVentureChat&8]&e - Registering Listeners"));
|
||||
loadNMS();
|
||||
Bukkit.getConsoleSender().sendMessage(Format.FormatStringAll("&8[&eVentureChat&8]&e - Attaching to Executors"));
|
||||
|
||||
Bukkit.getConsoleSender().sendMessage(Format.FormatStringAll("&8[&eVentureChat&8]&e - Establishing BungeeCord"));
|
||||
@ -240,18 +227,6 @@ public class MineverseChat extends JavaPlugin implements PluginMessageListener {
|
||||
}
|
||||
}, 0L, 60L); // three second interval
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private void loadCommandMap() {
|
||||
try {
|
||||
commandMap = Bukkit.getServer().getClass().getDeclaredField("commandMap");
|
||||
commandMap.setAccessible(true);
|
||||
knownCommands = SimpleCommandMap.class.getDeclaredField("knownCommands");
|
||||
knownCommands.setAccessible(true);
|
||||
}
|
||||
catch(Exception e) {
|
||||
}
|
||||
}
|
||||
|
||||
private void registerListeners() {
|
||||
PluginManager pluginManager = getServer().getPluginManager();
|
||||
@ -263,43 +238,6 @@ public class MineverseChat extends JavaPlugin implements PluginMessageListener {
|
||||
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketListener());
|
||||
}
|
||||
|
||||
private void loadNMS() {
|
||||
try {
|
||||
posField = MinecraftReflection.getMinecraftClass("PacketPlayOutChat").getDeclaredField("b");
|
||||
posField.setAccessible(true);
|
||||
|
||||
|
||||
//MineverseChat.messageMethod = MinecraftReflection.getMinecraftClass("ChatBaseComponent").getDeclaredMethod("getString");
|
||||
//MineverseChat.messageMethod.setAccessible(true);
|
||||
}
|
||||
catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if(!VersionHandler.is1_7_10() && !VersionHandler.is1_8() && !VersionHandler.is1_9() && !VersionHandler.is1_10() && !VersionHandler.is1_11()) {
|
||||
try {
|
||||
chatMessageType = getNMSClass("ChatMessageType");
|
||||
}
|
||||
catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Class<?> getNMSClass(String name) {
|
||||
try {
|
||||
return Class.forName("net.minecraft.server." + getVersion() + "." + name);
|
||||
}
|
||||
catch(ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private String getVersion() {
|
||||
return Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3];
|
||||
}
|
||||
|
||||
|
||||
private boolean setupPermissions() {
|
||||
RegisteredServiceProvider<Permission> permissionProvider = getServer().getServicesManager().getRegistration(net.milkbowl.vault.permission.Permission.class);
|
||||
if(permissionProvider != null) {
|
||||
@ -320,23 +258,6 @@ public class MineverseChat extends JavaPlugin implements PluginMessageListener {
|
||||
return getPlugin(MineverseChat.class);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static void unregister(String name) {
|
||||
try {
|
||||
((Map<String, Command>) knownCommands.get((SimpleCommandMap) commandMap.get(Bukkit.getServer()))).remove(name);
|
||||
}
|
||||
catch(Exception e) {
|
||||
}
|
||||
}
|
||||
|
||||
public static Field getPosField() {
|
||||
return posField;
|
||||
}
|
||||
|
||||
public static Class<?> getChatMessageType() {
|
||||
return chatMessageType;
|
||||
}
|
||||
|
||||
public static Chat getVaultChat() {
|
||||
return chat;
|
||||
}
|
||||
|
@ -76,7 +76,7 @@ public class VentureChatGui implements VentureCommand {
|
||||
Inventory inv = Bukkit.createInventory(null, this.getSlots(), "VentureChat: " + target.getName() + " GUI");
|
||||
ItemStack close = null;
|
||||
ItemStack skull = null;
|
||||
if(VersionHandler.is1_7_10()) {
|
||||
if(VersionHandler.is1_7()) {
|
||||
close = new ItemStack(Material.BEDROCK);
|
||||
}
|
||||
else {
|
||||
@ -135,7 +135,7 @@ public class VentureChatGui implements VentureCommand {
|
||||
Inventory inv = Bukkit.createInventory(null, this.getSlots(), "VentureChat: Discord_Message GUI");
|
||||
ItemStack close = null;
|
||||
ItemStack skull = null;
|
||||
if(VersionHandler.is1_7_10()) {
|
||||
if(VersionHandler.is1_7()) {
|
||||
close = new ItemStack(Material.BEDROCK);
|
||||
}
|
||||
else {
|
||||
|
@ -236,7 +236,7 @@ public class CommandListener implements CommandExecutor, Listener {
|
||||
SkullMeta skullMeta = (SkullMeta) skull.getItemMeta();
|
||||
ChatChannel channel = ChatChannel.getChannel(ChatColor.stripColor(skullMeta.getLore().get(0)).replace("Channel: ", ""));
|
||||
int hash = Integer.parseInt(ChatColor.stripColor(skullMeta.getLore().get(1).replace("Hash: ", "")));
|
||||
if(VersionHandler.is1_7_10()) {
|
||||
if(VersionHandler.is1_7()) {
|
||||
if(item.getType() == Material.BEDROCK) {
|
||||
mcp.getPlayer().closeInventory();
|
||||
}
|
||||
|
@ -7,8 +7,6 @@ import mineverse.Aust1n46.chat.api.MineverseChatPlayer;
|
||||
import mineverse.Aust1n46.chat.utilities.Format;
|
||||
import mineverse.Aust1n46.chat.versions.VersionHandler;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.events.ListenerPriority;
|
||||
import com.comphenix.protocol.events.PacketAdapter;
|
||||
@ -41,24 +39,22 @@ public class PacketListener extends PacketAdapter {
|
||||
return;
|
||||
}
|
||||
|
||||
Field posField = MineverseChat.getPosField();
|
||||
if(posField == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
if(VersionHandler.is1_7_2() || VersionHandler.is1_7_10() || VersionHandler.is1_7_9()) {
|
||||
if(!(((boolean) posField.get(packet.getHandle())))) {
|
||||
if(VersionHandler.is1_7()) {
|
||||
packet.getBooleans().getField(0).setAccessible(true);
|
||||
if(!((boolean) packet.getBooleans().getField(0).get(packet.getHandle()))) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if(VersionHandler.is1_8() || VersionHandler.is1_9() || VersionHandler.is1_10() || VersionHandler.is1_11()){
|
||||
if(((Byte) posField.get(packet.getHandle())).intValue() > 1) {
|
||||
else if(VersionHandler.is1_8() || VersionHandler.is1_9() || VersionHandler.is1_10() || VersionHandler.is1_11()) {
|
||||
packet.getBytes().getField(0).setAccessible(true);
|
||||
if(((Byte) packet.getBytes().getField(0).get(packet.getHandle())).intValue() > 1) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(((Object) posField.get(packet.getHandle())) == MineverseChat.getChatMessageType().getEnumConstants()[2]) {
|
||||
packet.getChatTypes().getField(0).setAccessible(true);
|
||||
if(packet.getChatTypes().getField(0).get(packet.getHandle()) == packet.getChatTypes().getField(0).getType().getEnumConstants()[2]) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -492,8 +492,8 @@ public class Format {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static String toColoredText(Object o, Class<?> c) {
|
||||
if (VersionHandler.is1_7_10()) {
|
||||
return "This method is not currently supported in 1.7";
|
||||
if (VersionHandler.is1_7()) {
|
||||
return "\"extra\":[{\"text\":\"Hover to see original message is not currently supported in 1.7\",\"color\":\"red\"}]";
|
||||
}
|
||||
List<Object> finalList = new ArrayList<>();
|
||||
StringBuilder stringbuilder = new StringBuilder();
|
||||
@ -521,7 +521,7 @@ public class Format {
|
||||
stringbuilder.append(jsonObject.toJSONString() + ",");
|
||||
}
|
||||
catch(Exception e) {
|
||||
return "Something went wrong. Could not access color.";
|
||||
return "\"extra\":[{\"text\":\"Something went wrong. Could not access color.\",\"color\":\"red\"}]";
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
@ -541,7 +541,7 @@ public class Format {
|
||||
try {
|
||||
splitComponents(finalList, o, c);
|
||||
for (Object component : finalList) {
|
||||
if (VersionHandler.is1_7_10()) {
|
||||
if (VersionHandler.is1_7()) {
|
||||
stringbuilder.append((String) component.getClass().getMethod("e").invoke(component));
|
||||
} else {
|
||||
stringbuilder.append((String) component.getClass().getMethod("getText").invoke(component));
|
||||
@ -915,7 +915,7 @@ public class Format {
|
||||
}
|
||||
|
||||
private static Sound getDefaultMessageSound() {
|
||||
if(VersionHandler.is1_8() || VersionHandler.is1_7_10() || VersionHandler.is1_7_2() || VersionHandler.is1_7_9()) {
|
||||
if(VersionHandler.is1_7() || VersionHandler.is1_8()) {
|
||||
return Sound.valueOf(DEFAULT_LEGACY_MESSAGE_SOUND);
|
||||
}
|
||||
else {
|
||||
|
@ -5,45 +5,9 @@ import org.bukkit.Bukkit;
|
||||
//This class contains methods for determining what version of Minecraft the server is running.
|
||||
public class VersionHandler {
|
||||
|
||||
public static boolean is1_2_5() {
|
||||
return Bukkit.getVersion().contains("1.2.5");
|
||||
}
|
||||
|
||||
public static boolean is1_3_2() {
|
||||
return Bukkit.getVersion().contains("1.3.2");
|
||||
}
|
||||
|
||||
public static boolean is1_4_7() {
|
||||
return Bukkit.getVersion().contains("1.4.7");
|
||||
}
|
||||
|
||||
public static boolean is1_5_2() {
|
||||
return Bukkit.getVersion().contains("1.5.2");
|
||||
}
|
||||
|
||||
public static boolean is1_6_2() {
|
||||
return Bukkit.getVersion().contains("1.6.2");
|
||||
}
|
||||
|
||||
public static boolean is1_6_4() {
|
||||
return Bukkit.getVersion().contains("1.6.4");
|
||||
}
|
||||
|
||||
public static boolean is1_7() {
|
||||
return Bukkit.getVersion().contains("1.7");
|
||||
}
|
||||
|
||||
public static boolean is1_7_2() {
|
||||
return Bukkit.getVersion().contains("1.7") && Bukkit.getServer().getClass().getPackage().getName().contains("R1");
|
||||
}
|
||||
|
||||
public static boolean is1_7_9() {
|
||||
return Bukkit.getVersion().contains("1.7") && Bukkit.getServer().getClass().getPackage().getName().contains("R3");
|
||||
}
|
||||
|
||||
public static boolean is1_7_10() {
|
||||
return Bukkit.getVersion().contains("1.7") && Bukkit.getServer().getClass().getPackage().getName().contains("R4");
|
||||
}
|
||||
|
||||
public static boolean is1_8() {
|
||||
return Bukkit.getVersion().contains("1.8");
|
||||
@ -85,11 +49,7 @@ public class VersionHandler {
|
||||
return Bukkit.getVersion().contains("1.16");
|
||||
}
|
||||
|
||||
public static boolean isCauldron() {
|
||||
return false;
|
||||
public static boolean is1_17() {
|
||||
return Bukkit.getVersion().contains("1.17");
|
||||
}
|
||||
|
||||
public static boolean matchesVersion(String s) {
|
||||
return Bukkit.getVersion().contains(s) || Bukkit.getServer().getClass().getPackage().getName().contains(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user