Added support for 1.12 and a new file for testing.

This commit is contained in:
Alastair 2017-05-19 06:09:57 +01:00
parent bbcd423987
commit 8ae2473b9a
8 changed files with 74 additions and 47 deletions

View File

@ -16,7 +16,7 @@
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
</repositories>
<version>0.0.25-snapshot</version>
<version>0.0.26-snapshot</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
@ -29,7 +29,7 @@
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>1.10.2-R0.1-SNAPSHOT</version>
<version>1.12-pre2-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<!--<dependency>

View File

@ -426,7 +426,7 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
case "list" :
String message = PluginMessages.customPrefix + " \u00A77Portals \u00A7c:\u00A7a";
LinkedList<String> portals = new LinkedList<>();
for (AdvancedPortal portal : Portal.Portals) {
for (AdvancedPortal portal : Portal.portals) {
portals.add(portal.portalName);
}
Collections.sort(portals);

View File

@ -33,11 +33,9 @@ public class ConfigAccessor {
fileConfiguration = YamlConfiguration.loadConfiguration(configFile);
// Look for defaults in the jar
InputStream defConfigStream = plugin.getResource(fileName);
if (defConfigStream != null) {
YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(defConfigStream);
fileConfiguration.setDefaults(defConfig);
}
YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(new File(this.getClass()
.getClassLoader().getResource(fileName).getPath()));
fileConfiguration.setDefaults(defConfig);
}
public FileConfiguration getConfig() {

View File

@ -50,7 +50,7 @@ public class DataCollector {
Graph TotalWarps = metrics.createGraph("Portal Trigger Blocks");
/**List<Material> MaterialList = new ArrayList<Material>();
for(AdvancedPortal portal : Portal.Portals){
for(AdvancedPortal portal : Portal.portals){
MaterialList.add(portal.trigger);
}*/

View File

@ -7,6 +7,7 @@ import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Arrays;
/**
* Created by on 02/08/2016.
@ -19,6 +20,9 @@ import java.lang.reflect.Method;
public class CraftBukkit {
private final AdvancedPortalsPlugin plugin;
private Method chatMessageTypeMethod;
private Method serializeMessage;
private Constructor<?> chatPacketConstructor;
@ -26,6 +30,8 @@ public class CraftBukkit {
private Field playerConnection;
private Method sendPacket;
private boolean useEnumType = true;
// Classes so it doesnt keep fetching them.
@ -41,17 +47,26 @@ public class CraftBukkit {
Class<?> chatBaseComponent = Class.forName(minecraftPackage + "IChatBaseComponent"); // string to packet methods
Class<?> chatSerialClass = this.findClass(chatBaseComponent, "ChatSerializer");
if(chatSerialClass == null){
plugin.getLogger().info("Old version detected, changing chat method");
this.serializeMessage = chatBaseComponent.getMethod("a", String.class);
Class<?> chatMessageTypeClass = Class.forName(minecraftPackage + "ChatMessageType");
if(chatMessageTypeClass != null){
useEnumType = true;
this.chatMessageTypeMethod = chatMessageTypeClass.getMethod("a", byte.class);
this.chatPacketConstructor = Class.forName(minecraftPackage + "PacketPlayOutChat").getConstructor(chatBaseComponent, chatMessageTypeClass);
}
else{
this.chatPacketConstructor = Class.forName(minecraftPackage + "PacketPlayOutChat").getConstructor(chatBaseComponent, byte.class);
}
if(chatSerialClass != null){
this.serializeMessage = chatSerialClass.getMethod("a", String.class);
}
else{
plugin.getLogger().info("Old version detected, changing chat method");
this.serializeMessage = chatBaseComponent.getMethod("a", String.class);
}
this.chatPacketConstructor = Class.forName(minecraftPackage + "PacketPlayOutChat").getConstructor(chatBaseComponent, byte.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");
@ -82,7 +97,13 @@ public class CraftBukkit {
public void sendMessage(String rawMessage, Player player, byte msgType) {
try {
Object comp = this.serializeMessage.invoke(null,rawMessage); // convert string into bytes
Object packet = this.chatPacketConstructor.newInstance(comp, msgType); // convert bytes into packet
Object packet;
if(useEnumType){
packet = this.chatPacketConstructor.newInstance(comp, this.chatMessageTypeMethod.invoke(null,msgType)); // convert bytes into packet
}
else{
packet = this.chatPacketConstructor.newInstance(comp, msgType); // convert bytes into packet
}
Object handle = this.playerGetHandle.invoke(player);
Object playerConnection = this.playerConnection.get(handle); // get players connection

View File

@ -150,7 +150,7 @@ public class Destination {
player.sendMessage("");
} else if (PortalMessagesDisplay == 2) {
plugin.compat.sendActionBarMessage("{\"text\":\"\u00A7aYou have warped to \u00A7e" + name.replaceAll("_", " ") + "\u00A7a.\"}", player);
/**plugin.nmsAccess.sendActionBarMessage("[{text:\"You have warped to \",color:green},{text:\"" + config.getConfig().getString(Portal.Portals[portalId].portalName + ".destination").replaceAll("_", " ")
/**plugin.nmsAccess.sendActionBarMessage("[{text:\"You have warped to \",color:green},{text:\"" + config.getConfig().getString(Portal.portals[portalId].portalName + ".destination").replaceAll("_", " ")
+ "\",color:yellow},{\"text\":\".\",color:green}]", player);*/
}

View File

@ -77,7 +77,7 @@ public class Listeners implements Listener {
//Location fromloc = event.getFrom();
Location loc = event.getTo();
Location eyeLoc = new Location(loc.getWorld(), loc.getX(), loc.getY() + player.getEyeHeight(), loc.getZ());
for (AdvancedPortal portal : Portal.Portals) {
for (AdvancedPortal portal : Portal.portals) {
if (Portal.locationInPortalTrigger(portal, loc) || Portal.locationInPortalTrigger(portal, eyeLoc)) {
if (portal.trigger.equals(Material.PORTAL)) {
if (player.getGameMode().equals(GameMode.CREATIVE)) {
@ -164,7 +164,7 @@ public class Listeners implements Listener {
Player player = event.getPlayer();
if (player.hasMetadata("selectingPortal") && (event.getAction() == Action.LEFT_CLICK_BLOCK || event.getAction() == Action.RIGHT_CLICK_BLOCK)) {
for (AdvancedPortal portal : Portal.Portals) {
for (AdvancedPortal portal : Portal.portals) {
if (Portal.locationInPortal(portal, event.getClickedBlock().getLocation(), 0)) {
player.sendMessage(PluginMessages.customPrefix + "\u00A7a You have selected: \u00A7e" + portal.portalName);
player.setMetadata("selectedPortal", new FixedMetadataValue(plugin, portal.portalName)); // adds the name to the metadata of the character

View File

@ -23,16 +23,16 @@ public class Portal {
public static HashMap<Player, Long> cooldown = new HashMap<Player, Long>();
// Config values
public static boolean portalsActive = false;
public static AdvancedPortal[] Portals = new AdvancedPortal[0];
public static AdvancedPortal[] portals = new AdvancedPortal[0];
private static AdvancedPortalsPlugin plugin;
public static ConfigAccessor portalData = new ConfigAccessor(plugin, "portals.yml");
private static boolean ShowBungeeMessage;
private static boolean showBungeeMessage;
private static int cooldelay;
private static double throwback;
public Portal(AdvancedPortalsPlugin plugin) {
ConfigAccessor config = new ConfigAccessor(plugin, "config.yml");
ShowBungeeMessage = config.getConfig().getBoolean("ShowBungeeWarpMessage");
showBungeeMessage = config.getConfig().getBoolean("ShowBungeeWarpMessage");
cooldelay = config.getConfig().getInt("PortalCooldown", 5);
throwback = config.getConfig().getDouble("ThrowbackAmount", 0.7);
@ -52,10 +52,10 @@ public class Portal {
portalData = new ConfigAccessor(plugin, "portals.yml");
Set<String> PortalSet = portalData.getConfig().getKeys(false);
if (PortalSet.size() > 0) {
Portals = new AdvancedPortal[PortalSet.toArray().length];
portals = new AdvancedPortal[PortalSet.toArray().length];
/*for(int i = 0; i <= PortalSet.toArray().length - 1; i++){
Portals[i] = new AdvancedPortal();
portals[i] = new AdvancedPortal();
}*/
int portalId = 0;
@ -93,21 +93,29 @@ public class Portal {
String worldName = portalData.getConfig().getString(portal.toString() + ".world");
if(worldName != null) {
World world = Bukkit.getWorld(worldName);
Location pos1 = new Location(world, portalData.getConfig().getInt(portal.toString() + ".pos1.X"), portalData.getConfig().getInt(portal.toString() + ".pos1.Y"), portalData.getConfig().getInt(portal.toString() + ".pos1.Z"));
Location pos2 = new Location(world, portalData.getConfig().getInt(portal.toString() + ".pos2.X"), portalData.getConfig().getInt(portal.toString() + ".pos2.Y"), portalData.getConfig().getInt(portal.toString() + ".pos2.Z"));
World world = Bukkit.getWorld(worldName);
Location pos1 = new Location(world, portalData.getConfig().getInt(portal.toString() + ".pos1.X"), portalData.getConfig().getInt(portal.toString() + ".pos1.Y"), portalData.getConfig().getInt(portal.toString() + ".pos1.Z"));
Location pos2 = new Location(world, portalData.getConfig().getInt(portal.toString() + ".pos2.X"), portalData.getConfig().getInt(portal.toString() + ".pos2.Y"), portalData.getConfig().getInt(portal.toString() + ".pos2.Z"));
PortalArg[] portalArgs = new PortalArg[extraData.size()];
extraData.toArray(portalArgs);
PortalArg[] portalArgs = new PortalArg[extraData.size()];
extraData.toArray(portalArgs);
portals[portalId] = new AdvancedPortal(portal.toString(), blockType, pos1, pos2, worldName, portalArgs);
Portals[portalId] = new AdvancedPortal(portal.toString(), blockType, pos1, pos2, worldName, portalArgs);
portals[portalId].bungee = portalConfigSection.getString("bungee");
Portals[portalId].bungee = portalConfigSection.getString("bungee");
portals[portalId].destiation = portalConfigSection.getString("destination");
Portals[portalId].destiation = portalConfigSection.getString("destination");
portalId++;
}
else{
AdvancedPortal[] tempPortals = portals;
portalId++;
portals = new AdvancedPortal[portals.length - 1];
System.arraycopy(portal, 0, portals, 0, portalId);
}
}
portalsActive = true;
} else {
@ -161,7 +169,7 @@ public class Portal {
Location checkpos2 = new Location(pos2.getWorld(), LowX, LowY, LowZ);
if (checkPortalOverlap(checkpos1, checkpos2)) {
plugin.getLogger().log(Level.WARNING, "Portals must not overlap!");
plugin.getLogger().log(Level.WARNING, "portals must not overlap!");
return "\u00A7cPortal creation error, portals must not overlap!";
}
@ -197,37 +205,37 @@ public class Portal {
if (portalsActive) {
int portalId = 0;
for (@SuppressWarnings("unused") Object portal : Portal.Portals) {
if (Portals[portalId].worldName.equals(pos2.getWorld().getName())) { // checks that the cubes arnt overlapping by seeing if all 4 corners are not in side another
if (checkOverLapPortal(pos1, pos2, Portals[portalId].pos1.getBlockX(), Portals[portalId].pos1.getBlockY(), Portals[portalId].pos1.getBlockZ())) {
for (@SuppressWarnings("unused") Object portal : Portal.portals) {
if (portals[portalId].worldName.equals(pos2.getWorld().getName())) { // checks that the cubes arnt overlapping by seeing if all 4 corners are not in side another
if (checkOverLapPortal(pos1, pos2, portals[portalId].pos1.getBlockX(), portals[portalId].pos1.getBlockY(), portals[portalId].pos1.getBlockZ())) {
return true;
}
if (checkOverLapPortal(pos1, pos2, Portals[portalId].pos1.getBlockX(), Portals[portalId].pos1.getBlockY(), Portals[portalId].pos2.getBlockZ())) {
if (checkOverLapPortal(pos1, pos2, portals[portalId].pos1.getBlockX(), portals[portalId].pos1.getBlockY(), portals[portalId].pos2.getBlockZ())) {
return true;
}
if (checkOverLapPortal(pos1, pos2, Portals[portalId].pos1.getBlockX(), Portals[portalId].pos2.getBlockY(), Portals[portalId].pos1.getBlockZ())) {
if (checkOverLapPortal(pos1, pos2, portals[portalId].pos1.getBlockX(), portals[portalId].pos2.getBlockY(), portals[portalId].pos1.getBlockZ())) {
return true;
}
if (checkOverLapPortal(pos1, pos2, Portals[portalId].pos2.getBlockX(), Portals[portalId].pos1.getBlockY(), Portals[portalId].pos1.getBlockZ())) {
if (checkOverLapPortal(pos1, pos2, portals[portalId].pos2.getBlockX(), portals[portalId].pos1.getBlockY(), portals[portalId].pos1.getBlockZ())) {
return true;
}
if (checkOverLapPortal(pos1, pos2, Portals[portalId].pos2.getBlockX(), Portals[portalId].pos2.getBlockY(), Portals[portalId].pos2.getBlockZ())) {
if (checkOverLapPortal(pos1, pos2, portals[portalId].pos2.getBlockX(), portals[portalId].pos2.getBlockY(), portals[portalId].pos2.getBlockZ())) {
return true;
}
if (checkOverLapPortal(pos1, pos2, Portals[portalId].pos2.getBlockX(), Portals[portalId].pos1.getBlockY(), Portals[portalId].pos2.getBlockZ())) {
if (checkOverLapPortal(pos1, pos2, portals[portalId].pos2.getBlockX(), portals[portalId].pos1.getBlockY(), portals[portalId].pos2.getBlockZ())) {
return true;
}
if (checkOverLapPortal(pos1, pos2, Portals[portalId].pos1.getBlockX(), Portals[portalId].pos2.getBlockY(), Portals[portalId].pos2.getBlockZ())) {
if (checkOverLapPortal(pos1, pos2, portals[portalId].pos1.getBlockX(), portals[portalId].pos2.getBlockY(), portals[portalId].pos2.getBlockZ())) {
return true;
}
if (checkOverLapPortal(pos1, pos2, Portals[portalId].pos2.getBlockX(), Portals[portalId].pos2.getBlockY(), Portals[portalId].pos1.getBlockZ())) {
if (checkOverLapPortal(pos1, pos2, portals[portalId].pos2.getBlockX(), portals[portalId].pos2.getBlockY(), portals[portalId].pos1.getBlockZ())) {
return true;
}
}
@ -349,7 +357,7 @@ public class Portal {
}
public static boolean activate(Player player, String portalName) {
for (AdvancedPortal portal : Portal.Portals) {
for (AdvancedPortal portal : Portal.portals) {
if (portal.portalName.equals(portalName)) return activate(player, portal);
}
plugin.getLogger().log(Level.SEVERE, "Portal not found by name of: " + portalName);
@ -388,7 +396,7 @@ public class Portal {
//plugin.getLogger().info(portal.portalName + ":" + portal.destiation);
boolean warped = false;
if (portal.bungee != null) {
if (ShowBungeeMessage) {
if (showBungeeMessage) {
player.sendMessage(PluginMessages.customPrefix + "\u00A7a Attempting to warp to \u00A7e" + portal.bungee + "\u00A7a.");
}
ByteArrayDataOutput out = ByteStreams.newDataOutput();
@ -502,7 +510,7 @@ public class Portal {
}
public static boolean inPortalTriggerRegion(Location loc) {
for (AdvancedPortal portal : Portal.Portals)
for (AdvancedPortal portal : Portal.portals)
if (Portal.locationInPortalTrigger(portal, loc))
return true;
return false;
@ -515,7 +523,7 @@ public class Portal {
}
public static boolean inPortalRegion(Location loc, int additionalArea) {
for (AdvancedPortal portal : Portal.Portals)
for (AdvancedPortal portal : Portal.portals)
if (Portal.locationInPortal(portal, loc, additionalArea))
return true;
return false;