Updated to 1.16

Solves #200

Also removed the compat file so this should be far more forwards compatible
This commit is contained in:
Sekwah 2020-06-26 00:42:39 +01:00
parent 4012e9bc01
commit 1c413c82e5
8 changed files with 112 additions and 147 deletions

View File

@ -41,7 +41,8 @@ repositories {
// includeLibs just says to include the library in the final jar // includeLibs just says to include the library in the final jar
dependencies { dependencies {
implementation "org.bukkit:bukkit:1.15.1-R0.1-SNAPSHOT" //implementation "org.bukkit:bukkit:1.16.1-R0.1-SNAPSHOT"
implementation "org.spigotmc:spigot-api:1.16.1-R0.1-SNAPSHOT"
implementation "net.md-5:bungeecord-api:1.15-SNAPSHOT" implementation "net.md-5:bungeecord-api:1.15-SNAPSHOT"
implementation "io.netty:netty-all:4.0.4.Final" implementation "io.netty:netty-all:4.0.4.Final"

View File

@ -6,6 +6,9 @@ import com.sekwah.advancedportals.bukkit.config.ConfigAccessor;
import com.sekwah.advancedportals.bukkit.listeners.Listeners; import com.sekwah.advancedportals.bukkit.listeners.Listeners;
import com.sekwah.advancedportals.bukkit.portals.AdvancedPortal; import com.sekwah.advancedportals.bukkit.portals.AdvancedPortal;
import com.sekwah.advancedportals.bukkit.portals.Portal; import com.sekwah.advancedportals.bukkit.portals.Portal;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.ChatMessageType;
import net.md_5.bungee.api.chat.*;
import org.bukkit.DyeColor; import org.bukkit.DyeColor;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
@ -23,6 +26,7 @@ import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.material.Wool; import org.bukkit.material.Wool;
import org.bukkit.metadata.FixedMetadataValue; import org.bukkit.metadata.FixedMetadataValue;
import javax.xml.soap.Text;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -462,21 +466,31 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
player.sendMessage(PluginMessages.customPrefixFail + " You had no portal selected!"); player.sendMessage(PluginMessages.customPrefixFail + " You had no portal selected!");
} }
case "gui": case "gui":
// /portal gui remove testarg
if (args.length > 1) { if (args.length > 1) {
if (args[1].toLowerCase().equals("remove") && args.length > 2) { if (args[1].toLowerCase().equals("remove") && args.length > 2) {
sender.sendMessage(""); sender.sendMessage("");
sender.sendMessage(PluginMessages.customPrefixFail sender.sendMessage(PluginMessages.customPrefixFail
+ " Are you sure you would like to remove the portal \u00A7e" + args[2] + " Are you sure you would like to remove the portal \u00A7e" + args[2]
+ "\u00A7c?"); + "\u00A7c?");
TextComponent removeMessage = new TextComponent();
TextComponent yes = new TextComponent("[Yes]");
yes.setColor(ChatColor.YELLOW);
yes.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/portal remove " + args[2]));
yes.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("Confirm removing this portal").create()));
TextComponent no = new TextComponent("[No]");
no.setColor(ChatColor.YELLOW);
no.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/portal edit " + args[2]));
no.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("Cancel removing this portal").create()));
removeMessage.addExtra(" ");
removeMessage.addExtra(yes);
removeMessage.addExtra(" ");
removeMessage.addExtra(no);
sender.sendMessage(""); sender.sendMessage("");
plugin.compat.sendRawMessage( sender.spigot().sendMessage(removeMessage);
"{\"text\":\" \",\"extra\":[{\"text\":\"\u00A7e[Yes]\",\"hoverEvent\":{\"action\":\"show_text\","
+ "\"value\":\"Confirm removing this portal\"},\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/portal remove "
+ args[2] + "\"}}, "
+ "{\"text\":\" \"},{\"text\":\"\u00A7e[No]\",\"hoverEvent\":{\"action\":\"show_text\",\"value\":\"Cancel removing this portal\"}"
+ ",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/portal edit "
+ args[2] + "\"}}]}",
player);
sender.sendMessage(""); sender.sendMessage("");
} }
} }
@ -551,11 +565,11 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
// TODO add the command autocompletes, add, remove and show // TODO add the command autocompletes, add, remove and show
if (args[1].toLowerCase().equals("add")) { if (args[1].toLowerCase().equals("add")) {
if (args.length > 2) { if (args.length > 2) {
String portalCommand = args[2]; StringBuilder portalCommand = new StringBuilder(args[2]);
for (int i = 3; i < args.length; i++) { for (int i = 3; i < args.length; i++) {
portalCommand += args[i]; portalCommand.append(args[i]);
} }
if (Portal.addCommand(portalName, portalCommand)) { if (Portal.addCommand(portalName, portalCommand.toString())) {
sender.sendMessage( sender.sendMessage(
PluginMessages.customPrefixFail + " Command added to portal!"); PluginMessages.customPrefixFail + " Command added to portal!");
} else { } else {
@ -826,15 +840,65 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
sender.sendMessage(""); sender.sendMessage("");
Player player = (Player) sender; Player player = (Player) sender;
/*TextComponent editMessage = new TextComponent();
editMessage.setColor(ChatColor.GREEN);*/
/* TextComponent yes = new TextComponent("Functions");
yes.setColor(ChatColor.YELLOW);
yes.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/portal remove " + args[2]));
yes.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("Confirm removing this portal").create()));
TextComponent no = new TextComponent("[No]");
no.setColor(ChatColor.YELLOW);
no.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/portal edit " + args[2]));
no.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("Cancel removing this portal").create()));
plugin.compat.sendRawMessage("{\"text\":\"\u00A7aFunctions\u00A7e: \"," removeMessage.addExtra(" ");
removeMessage.addExtra(no);
removeMessage.addExtra(" ");
removeMessage.addExtra(yes);*/
TextComponent removeButton = new TextComponent("Remove");
removeButton.setColor(ChatColor.YELLOW);
removeButton.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT,
new ComponentBuilder("Remove the selected portal").create()));
removeButton.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND,
"/portal gui remove " + portalName));
TextComponent showButton = new TextComponent("Show");
showButton.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT,
new ComponentBuilder("Show the selected portal").create()));
showButton.setColor(ChatColor.YELLOW);
showButton.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/portal show " + portalName));
TextComponent renameButton = new TextComponent("Rename");
renameButton.setColor(ChatColor.YELLOW);
renameButton.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT,
new ComponentBuilder("Change the name of the portal").create()));
renameButton.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/portal rename "));
TextComponent activateButton = new TextComponent("Activate");
activateButton.setColor(ChatColor.YELLOW);
activateButton.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT,
new ComponentBuilder("Trigger it as if you've just walked into it (Minus failing knockback)").create()));
activateButton.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/portal warp " + portalName));
BaseComponent[] editMessage = new ComponentBuilder("Functions").color(ChatColor.GREEN)
.append(": ").color(ChatColor.YELLOW)
.append(removeButton).append(" ")
.append(showButton).append(" ")
.append(renameButton).append(" ")
.append(activateButton).append(" ")
.create();
sender.spigot().sendMessage(editMessage);
/*player.spigot().sendMessage(TextComponent.fromLegacyText("{\"text\":\"\u00A7aFunctions\u00A7e: \","
+ "\"extra\":[{\"text\":\"\u00A7eRemove\",\"hoverEvent\":{\"action\":\"show_text\",\"value\":\"Remove the selected portal\"},\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/portal gui remove " + "\"extra\":[{\"text\":\"\u00A7eRemove\",\"hoverEvent\":{\"action\":\"show_text\",\"value\":\"Remove the selected portal\"},\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/portal gui remove "
+ portalName + "\"}}" + portalName + "\"}}"
+ ",{\"text\":\" \"},{\"text\":\"\u00A7eShow\",\"hoverEvent\":{\"action\":\"show_text\",\"value\":\"Show the selected portal\"},\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/portal show " + ",{\"text\":\" \"},{\"text\":\"\u00A7eShow\",\"hoverEvent\":{\"action\":\"show_text\",\"value\":\"Show the selected portal\"},\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/portal show "
+ portalName + "\"}}" + portalName + "\"}}"
+ ",{\"text\":\" \"},{\"text\":\"\u00A7eRename\",\"hoverEvent\":{\"action\":\"show_text\",\"value\":\"Change the name of the portal\"},\"clickEvent\":{\"action\":\"suggest_command\",\"value\":\"/portal rename \"}}" + ",{\"text\":\" \"},{\"text\":\"\u00A7eRename\",\"hoverEvent\":{\"action\":\"show_text\",\"value\":\"Change the name of the portal\"},\"clickEvent\":{\"action\":\"suggest_command\",\"value\":\"/portal rename \"}}"
+ ",{\"text\":\" \"},{\"text\":\"\u00A7eTeleport\",\"hoverEvent\":{\"action\":\"show_text\",\"value\":\"Teleport to the set destination\n(If there is one)\"},\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/desti warp " + ",{\"text\":\" \"},{\"text\":\"\u00A7eTeleport\",\"hoverEvent\":{\"action\":\"show_text\",\"value\":\"Teleport to the set destination\n(If there is one)\"},\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/desti warp "
+ destination + "\"}}]}", player); + destination + "\"}}]}"));*/
sender.sendMessage(""); sender.sendMessage("");

View File

@ -1,6 +1,5 @@
package com.sekwah.advancedportals.bukkit; package com.sekwah.advancedportals.bukkit;
import com.sekwah.advancedportals.bukkit.compat.CraftBukkit;
import com.sekwah.advancedportals.bukkit.config.ConfigAccessor; import com.sekwah.advancedportals.bukkit.config.ConfigAccessor;
import com.sekwah.advancedportals.bukkit.config.ConfigHelper; import com.sekwah.advancedportals.bukkit.config.ConfigHelper;
import com.sekwah.advancedportals.bukkit.destinations.Destination; import com.sekwah.advancedportals.bukkit.destinations.Destination;
@ -14,7 +13,7 @@ import org.bukkit.plugin.java.JavaPlugin;
public class AdvancedPortalsPlugin extends JavaPlugin { public class AdvancedPortalsPlugin extends JavaPlugin {
public CraftBukkit compat = null; //public CraftBukkit compat = null;
private Settings settings; private Settings settings;
public String channelName = "mc:advancedportals"; public String channelName = "mc:advancedportals";
@ -29,11 +28,11 @@ public class AdvancedPortalsPlugin extends JavaPlugin {
saveDefaultConfig(); saveDefaultConfig();
Metrics metrics = new Metrics(this); /*Metrics metrics = */
new Metrics(this);
try {
this.compat = new CraftBukkit(this, version); //this.compat = new CraftBukkit(this, version);
ConfigAccessor config = new ConfigAccessor(this, "config.yml"); ConfigAccessor config = new ConfigAccessor(this, "config.yml");
@ -73,19 +72,6 @@ public class AdvancedPortalsPlugin extends JavaPlugin {
this.getServer().getConsoleSender().sendMessage("\u00A7aAdvanced portals have been successfully enabled!"); this.getServer().getConsoleSender().sendMessage("\u00A7aAdvanced portals have been successfully enabled!");
} catch (ClassNotFoundException e) {
e.printStackTrace();
this.getLogger().warning("This version of craftbukkit is not yet supported, please notify sekwah and tell him about this version v:" + version);
this.getLogger().warning("Along with the above stacktrace");
this.setEnabled(false);
} catch (IllegalArgumentException |
NoSuchFieldException | SecurityException | NoSuchMethodException e) {
e.printStackTrace();
this.getLogger().warning("Something went wrong, please notify sekwah and tell him about this version v:" + version);
this.getLogger().warning("Along with the above stacktrace");
this.setEnabled(false);
}
for (Player player: for (Player player:
this.getServer().getOnlinePlayers()) { this.getServer().getOnlinePlayers()) {
player.removeMetadata("hasWarped", this); player.removeMetadata("hasWarped", this);

View File

@ -1,90 +0,0 @@
package com.sekwah.advancedportals.bukkit.compat;
import com.sekwah.advancedportals.bukkit.AdvancedPortalsPlugin;
import com.sekwah.advancedportals.bukkit.reflection.ReflectionHelper;
import org.bukkit.entity.Player;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
public class CraftBukkit {
private final AdvancedPortalsPlugin plugin;
// Data for chat bar and json message
private Method chatMessageTypeMethod;
private Method serializeMessage;
private Constructor<?> chatPacketConstructor;
private Method playerGetHandle;
private Field playerConnection;
private Method sendPacket;
public CraftBukkit(AdvancedPortalsPlugin plugin, String bukkitImpl) throws ClassNotFoundException, NoSuchFieldException, NoSuchMethodException {
this.plugin = plugin;
try {
String craftBukkitPackage = "org.bukkit.craftbukkit." + bukkitImpl + ".";
String minecraftPackage = "net.minecraft.server." + bukkitImpl + ".";
this.plugin.getLogger().info("Bukkit version detected " + bukkitImpl);
Class<?> chatBaseComponent = Class.forName(minecraftPackage + "IChatBaseComponent"); // string to packet methods
Class<?> chatSerialClass = ReflectionHelper.findClass(chatBaseComponent, "ChatSerializer");
Class<?> chatMessageTypeClass = Class.forName(minecraftPackage + "ChatMessageType");
this.chatMessageTypeMethod = chatMessageTypeClass.getMethod("a", byte.class);
this.chatPacketConstructor = Class.forName(minecraftPackage + "PacketPlayOutChat").getConstructor(chatBaseComponent, chatMessageTypeClass);
this.serializeMessage = chatSerialClass.getMethod("a", String.class);
this.playerGetHandle = Class.forName(craftBukkitPackage + "entity.CraftPlayer").getMethod("getHandle");
this.playerConnection = Class.forName(minecraftPackage + "EntityPlayer").getField("playerConnection"); // get player connection
Class<?> packet = Class.forName(minecraftPackage + "Packet");
this.sendPacket = playerConnection.getType().getMethod("sendPacket", packet);
} catch (Exception e) {
e.printStackTrace();
plugin.getLogger().warning("Attempting to use backup porekit locations");
// Fall back on your Porekit
Class<?> textBaseComponent = Class.forName("net.minecraft.util.text.ITextComponent"); // string to packet methods
this.serializeMessage = ReflectionHelper.findClass(textBaseComponent, "Serializer").getMethod("func_150699_a", String.class); // md: jsonToComponent
this.chatPacketConstructor = Class.forName("net.minecraft.network.play.server.SPacketChat").getConstructor(textBaseComponent, byte.class);
this.playerGetHandle = Class.forName("blue.lapis.pore.impl.entity.PorePlayer").getMethod("getHandle");
this.playerConnection = Class.forName("net.minecraft.entity.player.EntityPlayerMP").getField("field_71135_a"); // get player connection fd: connection
Class<?> packet = Class.forName("net.minecraft.network.Packet");
this.sendPacket = playerConnection.getType().getMethod("func_147359_a", packet); //md: sendPacket
}
}
public void sendRawMessage(String rawMessage, Player player) {
this.sendMessage(rawMessage,player, (byte) 1);
}
public void sendActionBarMessage(String rawMessage, Player player) {
this.sendMessage("{\"text\":\"" + rawMessage + "\"}",player, (byte) 2);
}
public void sendMessage(String rawMessage, Player player, byte msgType) {
try {
Object comp = this.serializeMessage.invoke(null, rawMessage);
Object packet = this.chatPacketConstructor.newInstance(comp, this.chatMessageTypeMethod.invoke(null,msgType)); // convert bytes into packet
Object handle = this.playerGetHandle.invoke(player);
Object playerConnection = this.playerConnection.get(handle); // get players connection
sendPacket.invoke(playerConnection, packet); // send packet
} catch (IllegalAccessException | InvocationTargetException | InstantiationException e) {
this.plugin.getLogger().warning("Error creating raw message, something must be wrong with reflection");
e.printStackTrace();
}
}
}

View File

@ -4,6 +4,8 @@ import com.sekwah.advancedportals.bukkit.AdvancedPortalsPlugin;
import com.sekwah.advancedportals.bukkit.config.ConfigAccessor; import com.sekwah.advancedportals.bukkit.config.ConfigAccessor;
import com.sekwah.advancedportals.bukkit.PluginMessages; import com.sekwah.advancedportals.bukkit.PluginMessages;
import com.sekwah.advancedportals.bukkit.effects.WarpEffects; import com.sekwah.advancedportals.bukkit.effects.WarpEffects;
import net.md_5.bungee.api.ChatMessageType;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Chunk; import org.bukkit.Chunk;
import org.bukkit.Location; import org.bukkit.Location;
@ -150,7 +152,7 @@ public class Destination {
player.sendMessage(PluginMessages.customPrefixFail + "\u00A7a You have been warped to \u00A7e" + name.replaceAll("_", " ") + "\u00A7a."); player.sendMessage(PluginMessages.customPrefixFail + "\u00A7a You have been warped to \u00A7e" + name.replaceAll("_", " ") + "\u00A7a.");
player.sendMessage(""); player.sendMessage("");
} else if (PORTAL_MESSAGE_DISPLAY == 2 && !hideActionbar) { } else if (PORTAL_MESSAGE_DISPLAY == 2 && !hideActionbar) {
plugin.compat.sendActionBarMessage("\u00A7aYou have warped to \u00A7e" + name.replaceAll("_", " ") + "\u00A7a.", player); player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText("\u00A7aYou have warped to \u00A7e" + name.replaceAll("_", " ") + "\u00A7a."));
} }
return true; return true;

View File

@ -9,6 +9,8 @@ import com.sekwah.advancedportals.bukkit.api.portaldata.PortalArg;
import com.sekwah.advancedportals.bukkit.destinations.Destination; import com.sekwah.advancedportals.bukkit.destinations.Destination;
import com.sekwah.advancedportals.bukkit.effects.WarpEffects; import com.sekwah.advancedportals.bukkit.effects.WarpEffects;
import com.sekwah.advancedportals.bungee.BungeeMessages; import com.sekwah.advancedportals.bungee.BungeeMessages;
import net.md_5.bungee.api.ChatMessageType;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.*; import org.bukkit.*;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -581,8 +583,8 @@ public class Portal {
if (warped) { if (warped) {
if (hasMessage) { if (hasMessage) {
plugin.compat.sendActionBarMessage(portal.getArg("message").replaceAll("&(?=[0-9a-fk-or])", "\u00A7"), player.spigot().sendMessage(ChatMessageType.ACTION_BAR,
player); TextComponent.fromLegacyText(portal.getArg("message").replaceAll("&(?=[0-9a-fk-or])", "\u00A7")));
} }
} }

View File

@ -1,4 +1,4 @@
main: com.sekwah.advancedportals.bungee.AdvancedPortalsPlugin main: com.sekwah.advancedportals.bungee.AdvancedPortalsPlugin
name: AdvancedPortals name: AdvancedPortals
version: 0.5.4 version: 0.5.5
author: sekwah41 author: sekwah41

View File

@ -1,6 +1,6 @@
main: com.sekwah.advancedportals.bukkit.AdvancedPortalsPlugin main: com.sekwah.advancedportals.bukkit.AdvancedPortalsPlugin
name: AdvancedPortals name: AdvancedPortals
version: 0.5.4 version: 0.5.5
author: sekwah41 author: sekwah41
description: An advanced portals plugin for bukkit. description: An advanced portals plugin for bukkit.
api-version: 1.13 api-version: 1.13