From 7bcd88fd1da1371bf28a3128d20f2c567965c316 Mon Sep 17 00:00:00 2001 From: Alastair Hawkes Date: Wed, 11 May 2016 11:42:54 +0100 Subject: [PATCH] Added support for 1.9.4 --- .../AdvancedPortalsPlugin.java | 98 ++++++++++--------- .../compat/bukkit/v1_9_R2.java | 27 +++++ 2 files changed, 77 insertions(+), 48 deletions(-) create mode 100644 src/com/sekwah/advancedportals/compat/bukkit/v1_9_R2.java diff --git a/src/com/sekwah/advancedportals/AdvancedPortalsPlugin.java b/src/com/sekwah/advancedportals/AdvancedPortalsPlugin.java index 072bfe88..08d79392 100644 --- a/src/com/sekwah/advancedportals/AdvancedPortalsPlugin.java +++ b/src/com/sekwah/advancedportals/AdvancedPortalsPlugin.java @@ -4,17 +4,16 @@ import com.sekwah.advancedportals.DataCollector.DataCollector; import com.sekwah.advancedportals.compat.bukkit.NMS; import com.sekwah.advancedportals.destinations.Destination; import com.sekwah.advancedportals.effects.WarpEffects; -import com.sekwah.advancedportals.listeners.*; +import com.sekwah.advancedportals.listeners.BungeeListener; +import com.sekwah.advancedportals.listeners.FlowStopper; +import com.sekwah.advancedportals.listeners.PortalPlacer; +import com.sekwah.advancedportals.listeners.PortalProtect; import com.sekwah.advancedportals.metrics.Metrics; import com.sekwah.advancedportals.portals.Portal; -import org.bukkit.Chunk; -import org.bukkit.entity.Entity; import org.bukkit.plugin.java.JavaPlugin; import java.io.IOException; import java.lang.reflect.InvocationTargetException; -import java.util.HashMap; -import java.util.Map; public class AdvancedPortalsPlugin extends JavaPlugin { @@ -43,12 +42,56 @@ public class AdvancedPortalsPlugin extends JavaPlugin { Class nmsClass = Class.forName("com.sekwah.advancedportals.compat.bukkit." + version); if (NMS.class.isAssignableFrom(nmsClass)) { this.nmsAccess = (NMS) nmsClass.getConstructor().newInstance(); + + + ConfigAccessor portalConfig = new ConfigAccessor(this, "portals.yml"); + portalConfig.saveDefaultConfig(); + + ConfigAccessor destinationConfig = new ConfigAccessor(this, "destinations.yml"); + destinationConfig.saveDefaultConfig(); + + new Assets(this); + + // Opens a channel that messages bungeeCord + this.getServer().getMessenger().registerOutgoingPluginChannel(this, "BungeeCord"); + + // Loads the portal and destination editors + new Portal(this); + new Destination(this); + + new DataCollector(this); + + // These register the commands + new AdvancedPortalsCommand(this); + new DestinationCommand(this); + new WarpCommand(this); + + new WarpEffects(this); + + + // These register the listeners + new Listeners(this); + + new FlowStopper(this); + new PortalProtect(this); + new PortalPlacer(this); + + Selection.LoadData(this); + + DataCollector.setupMetrics(); + + this.getServer().getMessenger().registerOutgoingPluginChannel(this, "BungeeCord"); + this.getServer().getMessenger().registerIncomingPluginChannel(this, "BungeeCord", new BungeeListener(this)); + + this.getServer().getConsoleSender().sendMessage("\u00A7aAdvanced portals have been successfully enabled!"); + + } else { - System.out.println("Something went wrong, please notify the author and tell them this version v:" + version); + this.getLogger().warning("Something went wrong, please notify the author and tell them this version v:" + version); this.setEnabled(false); } } catch (ClassNotFoundException e) { - System.out.println("This version of craftbukkit is not yet supported, please notify the author and give version v:" + version); + this.getLogger().warning("This version of craftbukkit is not yet supported, please notify the author and give version v:" + version); this.setEnabled(false); } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) { @@ -67,47 +110,6 @@ public class AdvancedPortalsPlugin extends JavaPlugin { this.customPrefixFail = config.getConfig().getString("CustomPrefixFail").replaceAll("&", "\u00A7"); } - ConfigAccessor portalConfig = new ConfigAccessor(this, "portals.yml"); - portalConfig.saveDefaultConfig(); - - ConfigAccessor destinationConfig = new ConfigAccessor(this, "destinations.yml"); - destinationConfig.saveDefaultConfig(); - - new Assets(this); - - // Opens a channel that messages bungeeCord - this.getServer().getMessenger().registerOutgoingPluginChannel(this, "BungeeCord"); - - // Loads the portal and destination editors - new Portal(this); - new Destination(this); - - new DataCollector(this); - - // These register the commands - new AdvancedPortalsCommand(this); - new DestinationCommand(this); - new WarpCommand(this); - - new WarpEffects(this); - - - // These register the listeners - new Listeners(this); - - new FlowStopper(this); - new PortalProtect(this); - new PortalPlacer(this); - - Selection.LoadData(this); - - DataCollector.setupMetrics(); - - this.getServer().getMessenger().registerOutgoingPluginChannel(this, "BungeeCord"); - this.getServer().getMessenger().registerIncomingPluginChannel(this, "BungeeCord", new BungeeListener(this)); - - this.getServer().getConsoleSender().sendMessage("\u00A7aAdvanced portals have been successfully enabled!"); - } diff --git a/src/com/sekwah/advancedportals/compat/bukkit/v1_9_R2.java b/src/com/sekwah/advancedportals/compat/bukkit/v1_9_R2.java new file mode 100644 index 00000000..2e4b573c --- /dev/null +++ b/src/com/sekwah/advancedportals/compat/bukkit/v1_9_R2.java @@ -0,0 +1,27 @@ +package com.sekwah.advancedportals.compat.bukkit; + +import net.minecraft.server.v1_9_R2.IChatBaseComponent; +import net.minecraft.server.v1_9_R2.PacketPlayOutChat; +import org.bukkit.craftbukkit.v1_9_R2.entity.CraftPlayer; +import org.bukkit.entity.Player; + + +public class v1_9_R2 implements NMS { + + @Override + public void sendRawMessage(String rawMessage, Player player) { + IChatBaseComponent comp = IChatBaseComponent.ChatSerializer.a(rawMessage); + // "json message", position(0: chat (chat box), 1: system message (chat box), 2: above action bar) + PacketPlayOutChat packet = new PacketPlayOutChat(comp, (byte) 1); + ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet); + } + + + @Override + public void sendActionBarMessage(String rawMessage, Player player) { + IChatBaseComponent comp = IChatBaseComponent.ChatSerializer.a(rawMessage); + // "json message", position(0: chat (chat box), 1: system message (chat box), 2: above action bar) + PacketPlayOutChat packet = new PacketPlayOutChat(comp, (byte) 2); + ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet); + } +}