Started updating listeners and users of the regions to use the new code in the portal class

This commit is contained in:
Alastair 2016-08-01 03:01:16 +00:00
parent 3e1ff45fd3
commit ce9a679bbc
2 changed files with 57 additions and 48 deletions

View File

@ -23,7 +23,7 @@ public class PortalProtect implements Listener {
// an example is in the interact event in this if statement if((!UseOnlyServerAxe || event.getItem().getItemMeta().getDisplayName().equals("<EFBFBD>eP...
private boolean PortalProtect = true;
private double PortalProtectionRadius = 5D;
private int PortalProtectionRadius = 5;
public PortalProtect(AdvancedPortalsPlugin plugin) {
this.plugin = plugin;
@ -31,7 +31,7 @@ public class PortalProtect implements Listener {
ConfigAccessor config = new ConfigAccessor(plugin, "config.yml");
this.PortalProtect = config.getConfig().getBoolean("PortalProtection");
this.PortalProtectionRadius = config.getConfig().getDouble("PortalProtectionRadius");
this.PortalProtectionRadius = config.getConfig().getInt("PortalProtectionRadius");
if (PortalProtect) {
plugin.getServer().getPluginManager().registerEvents(this, plugin);
@ -49,19 +49,9 @@ public class PortalProtect implements Listener {
if (!event.getPlayer().hasPermission("advancedportals.build")) {
Block block = event.getBlock();
for (AdvancedPortal portal : Portal.Portals) {
if (portal.worldName.equals(block.getWorld().getName())) {
if ((portal.pos1.getX() + PortalProtectionRadius) >= block.getX() && (portal.pos1.getY() + PortalProtectionRadius) >= block.getY() && (portal.pos1.getZ() + PortalProtectionRadius) >= block.getZ()) {
if ((portal.pos2.getX() - PortalProtectionRadius) <= block.getX() && (portal.pos2.getY() - PortalProtectionRadius) <= block.getY() && (portal.pos2.getZ() - PortalProtectionRadius) <= block.getZ()) {
event.setCancelled(true);
break;
}
}
}
AdvancedPortal inPortal = Portal.locationInPortal(block.getLocation(), PortalProtectionRadius);
if(inPortal != null){
event.setCancelled(true);
}
}
}
@ -77,19 +67,9 @@ public class PortalProtect implements Listener {
if (!event.getPlayer().hasPermission("advancedportals.build")) {
Block block = event.getBlock();
for (AdvancedPortal portal : Portal.Portals) {
if (portal.worldName.equals(block.getWorld().getName())) {
if ((portal.pos1.getX() + PortalProtectionRadius) >= block.getX() && (portal.pos1.getY() + PortalProtectionRadius) >= block.getY() && (portal.pos1.getZ() + PortalProtectionRadius) >= block.getZ()) {
if ((portal.pos2.getX() - PortalProtectionRadius) <= block.getX() && (portal.pos2.getY() - PortalProtectionRadius) <= block.getY() && (portal.pos2.getZ() - PortalProtectionRadius) <= block.getZ()) {
event.setCancelled(true);
break;
}
}
}
AdvancedPortal inPortal = Portal.locationInPortal(block.getLocation(), PortalProtectionRadius);
if(inPortal != null){
event.setCancelled(true);
}
}
}
@ -104,21 +84,11 @@ public class PortalProtect implements Listener {
List<Block> blockList = event.blockList();
for (int i = 0; i < blockList.size(); i++) {
Block block = blockList.get(i);
Object[] portals = Portal.Portals;
for (AdvancedPortal portal : Portal.Portals) { // change for format for(int i = 0; i < portals.length; i++){
if (portal.worldName.equals(block.getWorld().getName())) {
if ((portal.pos1.getX() + PortalProtectionRadius) >= block.getX() && (portal.pos1.getY() + PortalProtectionRadius) >= block.getY() && (portal.pos1.getZ() + PortalProtectionRadius) >= block.getZ()) {
if ((portal.pos2.getX() - PortalProtectionRadius) <= block.getX() && (portal.pos2.getY() - PortalProtectionRadius) <= block.getY() && (portal.pos2.getZ() - PortalProtectionRadius) <= block.getZ()) {
blockList.remove(i);
i--;
}
}
}
AdvancedPortal inPortal = Portal.locationInPortal(block.getLocation(), PortalProtectionRadius);
if(inPortal != null){
blockList.remove(i);
i--;
}
}
}

View File

@ -381,7 +381,7 @@ public class Portal {
command = command.substring(1);
plugin.getLogger().log(Level.INFO, "Portal command: " + command);
try{
plugin.getServer().dispatchCommand(Bukkit.getConsoleSender(), command);
plugin.getServer().dispatchCommand(Bukkit.getConsoleSender(), command);
}
catch(Exception e){
plugin.getLogger().warning("Error while executing: " + command);
@ -486,8 +486,39 @@ public class Portal {
}
}
public static AdvancedPortal locationInPortal(Location loc){
return locationInPortal(loc, 0);
}
public AdvancedPortal playerInPortal(Player player, Location loc){
/**
* Only returns the first portal found. May have issues with additional area but overlapping should not occour at 0.
* @param loc
* @param additionalArea
* @return
*/
public static AdvancedPortal locationInPortal(Location loc, int additionalArea){
for (AdvancedPortal portal : Portal.Portals) {
if (loc.getWorld() != null && portal.worldName.equals(loc.getWorld().getName())) {
if ((portal.pos1.getX() + 1D + additionalArea) >= loc.getX() && (portal.pos1.getY() + additionalArea) >= loc.getY() && (portal.pos1.getZ() + 1D + additionalArea) >= loc.getZ()) {
if (portal.pos2.getX() - additionalArea <= loc.getX() && portal.pos2.getY() - additionalArea <= loc.getY() && portal.pos2.getZ() - additionalArea <= loc.getZ()) {
return portal;
}
}
}
}
return null;
}
/**
* Only returns the first portal found. May have issues with additional area but overlapping should not occour at 0.
* @param player
* @param loc
* @param additionalArea
* @return
*/
public static AdvancedPortal playerInPortal(Player player, Location loc, int additionalArea){
if(loc == null){
loc = player.getLocation();
@ -499,8 +530,8 @@ public class Portal {
if (loc.getWorld() != null && portal.worldName.equals(loc.getWorld().getName())) {
if (portal.trigger.equals(loc.getBlock().getType())
|| portal.trigger.equals(eyeLoc.getBlock().getType())) {
if ((portal.pos1.getX() + 1D) >= loc.getX() && (portal.pos1.getY()) >= loc.getY() && (portal.pos1.getZ() + 1D) >= loc.getZ()) {
if (portal.pos2.getX() <= loc.getX() && portal.pos2.getY() <= loc.getY() && portal.pos2.getZ() <= loc.getZ()) {
if ((portal.pos1.getX() + 1D + additionalArea) >= loc.getX() && (portal.pos1.getY() + additionalArea) >= loc.getY() && (portal.pos1.getZ() + 1D + additionalArea) >= loc.getZ()) {
if (portal.pos2.getX() - additionalArea <= loc.getX() && portal.pos2.getY() - additionalArea <= loc.getY() && portal.pos2.getZ() - additionalArea <= loc.getZ()) {
return portal;
}
}
@ -511,7 +542,15 @@ public class Portal {
return null;
}
public AdvancedPortal playerInPortal(Player player){
return playerInPortal(player, null);
public static AdvancedPortal playerInPortal(Player player){
return playerInPortal(player, null, 0);
}
public static AdvancedPortal playerInPortal(Player player, Location loc){
return playerInPortal(player, loc, 0);
}
public static AdvancedPortal playerInPortal(Player player, int additionalArea){
return playerInPortal(player, null, additionalArea);
}
}