updated warp permissions to allow ops through and also fixed a problem with the portal placer when vanilla portals are broken

This commit is contained in:
sekwah41 2015-03-27 22:44:04 +00:00
parent 5a2bd1796d
commit 80da8833ef
5 changed files with 72 additions and 62 deletions

View File

@ -33,15 +33,13 @@ public class FlowStopper implements Listener {
// when checking positions check the block and the to block
Block blockTo = event.getToBlock();
Block block = event.getBlock();
AdvancedPortal[] portals = Portal.Portals;
int portalId = 0;
for(Object portal : portals){
if(Portal.Portals[portalId].worldName.equals(block.getWorld().getName())){
if((Portal.Portals[portalId].pos1.getX() + 3D) >= block.getX() && (Portal.Portals[portalId].pos1.getY() + 3D) >= block.getY() && (Portal.Portals[portalId].pos1.getZ() + 3D) >= block.getZ()){
for(AdvancedPortal portal : Portal.Portals){
if(portal.worldName.equals(block.getWorld().getName())){
if((Portal.Portals[portalId].pos2.getX() - 3D) <= block.getX() && (Portal.Portals[portalId].pos2.getY() - 3D) <= block.getY() && (Portal.Portals[portalId].pos2.getZ() - 3D) <= block.getZ()){
if((portal.pos1.getX() + 3D) >= block.getX() && (portal.pos1.getY() + 3D) >= block.getY() && (portal.pos1.getZ() + 3D) >= block.getZ()){
if((portal.pos2.getX() - 3D) <= block.getX() && (portal.pos2.getY() - 3D) <= block.getY() && (portal.pos2.getZ() - 3D) <= block.getZ()){
event.setCancelled(true);
@ -50,11 +48,11 @@ public class FlowStopper implements Listener {
}
if(Portal.Portals[portalId].worldName.equals(blockTo.getWorld().getName())){
if(portal.worldName.equals(blockTo.getWorld().getName())){
if((Portal.Portals[portalId].pos1.getX() + 3D) >= blockTo.getX() && (Portal.Portals[portalId].pos1.getY() + 3D) >= blockTo.getY() && (Portal.Portals[portalId].pos1.getZ() + 3D) >= blockTo.getZ()){
if((portal.pos1.getX() + 3D) >= blockTo.getX() && (portal.pos1.getY() + 3D) >= blockTo.getY() && (portal.pos1.getZ() + 3D) >= blockTo.getZ()){
if((Portal.Portals[portalId].pos2.getX() - 3D) <= blockTo.getX() && (Portal.Portals[portalId].pos2.getY() - 3D) <= blockTo.getY() && (Portal.Portals[portalId].pos2.getZ() - 3D) <= blockTo.getZ()){
if((portal.pos2.getX() - 3D) <= blockTo.getX() && (portal.pos2.getY() - 3D) <= blockTo.getY() && (portal.pos2.getZ() - 3D) <= blockTo.getZ()){
event.setCancelled(true);
@ -62,7 +60,6 @@ public class FlowStopper implements Listener {
}
}
portalId++;
}
}

View File

@ -86,13 +86,12 @@ public class Listeners implements Listener {
//System.out.println(loc.getBlock().getType()); // for debugging, remove or comment out when not needed
eyeloc.setY(eyeloc.getY() + player.getEyeHeight());
AdvancedPortal[] portals = Portal.Portals;
int portalId = 0;
for(AdvancedPortal portal : portals){
if(Portal.Portals[portalId].worldName.equals(loc.getWorld().getName())){
if(Portal.Portals[portalId].trigger.equals(loc.getBlock().getType())
|| Portal.Portals[portalId].trigger.equals(eyeloc.getBlock().getType())){
if((Portal.Portals[portalId].pos1.getX() + 1D) >= loc.getX() && (Portal.Portals[portalId].pos1.getY() + 1D) >= loc.getY() && (Portal.Portals[portalId].pos1.getZ() + 1D) >= loc.getZ()){
if(Portal.Portals[portalId].pos2.getX() <= loc.getX() && Portal.Portals[portalId].pos2.getY() <= loc.getY() && Portal.Portals[portalId].pos2.getZ() <= loc.getZ()){
if(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() + 1D) >= loc.getY() && (portal.pos1.getZ() + 1D) >= loc.getZ()){
if(portal.pos2.getX() <= loc.getX() && portal.pos2.getY() <= loc.getY() && portal.pos2.getZ() <= loc.getZ()){
WarpEvent warpEvent = new WarpEvent(player, portal.portalName);
@ -103,13 +102,13 @@ public class Listeners implements Listener {
if(PortalMessagesDisplay == 1 && warped){
ConfigAccessor config = new ConfigAccessor(plugin, "Portals.yml");
player.sendMessage("");
player.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] You have been warped to \u00A7e" + config.getConfig().getString(Portal.Portals[portalId].portalName + ".destination").replaceAll("_", " ") + "\u00A7.");
player.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] You have been warped to \u00A7e" + config.getConfig().getString(portal.portalName + ".destination").replaceAll("_", " ") + "\u00A7.");
player.sendMessage("");
}
else if(PortalMessagesDisplay == 2 && warped){
ConfigAccessor config = new ConfigAccessor(plugin, "Portals.yml");
plugin.nmsAccess.sendActionBarMessage("{text:\"\u00A7aYou have been warped to \u00A7e" + config.getConfig().getString(Portal.Portals[portalId].portalName + ".destination").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:\"\u00A7aYou have been warped to \u00A7e" + config.getConfig().getString(portal.portalName + ".destination").replaceAll("_", " ") + "\u00A7a.\"}", player);
/**plugin.nmsAccess.sendActionBarMessage("[{text:\"You have warped to \",color:green},{text:\"" + config.getConfig().getString(portal.portalName + ".destination").replaceAll("_", " ")
+ "\",color:yellow},{\"text\":\".\",color:green}]", player);*/
}
@ -123,7 +122,7 @@ public class Listeners implements Listener {
}
if(Portal.Portals[portalId].trigger.equals(Material.PORTAL)){
if(portal.trigger.equals(Material.PORTAL)){
final Player finalplayer = event.getPlayer();
if(player.getGameMode().equals(GameMode.CREATIVE)){
player.setMetadata("HasWarped", new FixedMetadataValue(plugin, true));
@ -140,7 +139,6 @@ public class Listeners implements Listener {
}
}
portalId++;
}
}
@ -161,13 +159,12 @@ public class Listeners implements Listener {
Location loc = player.getLocation();
Object[] portals = Portal.Portals;
int portalId = 0;
for(Object portal : portals){
if(Portal.Portals[portalId].worldName.equals(player.getWorld().getName())){
for(AdvancedPortal portal : Portal.Portals){
if(portal.worldName.equals(player.getWorld().getName())){
if((Portal.Portals[portalId].pos1.getX() + 1D) >= loc.getX() && (Portal.Portals[portalId].pos1.getY() + 1D) >= loc.getY() && (Portal.Portals[portalId].pos1.getZ() + 1D) >= loc.getZ()){
if((portal.pos1.getX() + 1D) >= loc.getX() && (portal.pos1.getY() + 1D) >= loc.getY() && (portal.pos1.getZ() + 1D) >= loc.getZ()){
if((Portal.Portals[portalId].pos2.getX()) <= loc.getX() && (Portal.Portals[portalId].pos2.getY()) <= loc.getY() && (Portal.Portals[portalId].pos2.getZ()) <= loc.getZ()){
if((portal.pos2.getX()) <= loc.getX() && (portal.pos2.getY()) <= loc.getY() && (portal.pos2.getZ()) <= loc.getZ()){
event.setCancelled(true);
@ -175,7 +172,6 @@ public class Listeners implements Listener {
}
}
portalId++;
}
}
@ -184,24 +180,22 @@ public class Listeners implements Listener {
@SuppressWarnings("deprecation")
@EventHandler
public void oniteminteract(PlayerInteractEvent event) {
public void onItemInteract(PlayerInteractEvent event) {
// will detect if the player is using an axe so the points of a portal can be set
// also any other detections such as sign interaction or basic block protection
Player player = event.getPlayer();
if(player.hasMetadata("selectingPortal") && (event.getAction() == Action.LEFT_CLICK_BLOCK || event.getAction() == Action.RIGHT_CLICK_BLOCK)){
Block block = event.getClickedBlock();
Object[] portals = Portal.Portals;
int portalId = 0;
for(Object portal : portals){
if(Portal.Portals[portalId].worldName.equals(block.getWorld().getName())){
for(AdvancedPortal portal : Portal.Portals){
if(portal.worldName.equals(block.getWorld().getName())){
if((Portal.Portals[portalId].pos1.getX() + 3D) >= block.getX() && (Portal.Portals[portalId].pos1.getY() + 3D) >= block.getY() && (Portal.Portals[portalId].pos1.getZ() + 3D) >= block.getZ()){
if((portal.pos1.getX() + 3D) >= block.getX() && (portal.pos1.getY() + 3D) >= block.getY() && (portal.pos1.getZ() + 3D) >= block.getZ()){
if((Portal.Portals[portalId].pos2.getX() - 3D) <= block.getX() && (Portal.Portals[portalId].pos2.getY() - 3D) <= block.getY() && (Portal.Portals[portalId].pos2.getZ() - 3D) <= block.getZ()){
player.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] You have selected: \u00A7e" + Portal.Portals[portalId].portalName);
if((portal.pos2.getX() - 3D) <= block.getX() && (portal.pos2.getY() - 3D) <= block.getY() && (portal.pos2.getZ() - 3D) <= block.getZ()){
player.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] You have selected: \u00A7e" + portal.portalName);
player.removeMetadata("selectingPortal", plugin);
player.setMetadata("selectedPortal", new FixedMetadataValue(plugin, Portal.Portals[portalId].portalName)); // adds the name to the metadata of the character
player.setMetadata("selectedPortal", new FixedMetadataValue(plugin, portal.portalName)); // adds the name to the metadata of the character
event.setCancelled(true);
player.removeMetadata("selectingPortal", plugin);
return;
@ -210,7 +204,6 @@ public class Listeners implements Listener {
}
}
portalId++;
}
player.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] No portal was selected - if you would like to stop selecting please type \u00A7e/portal select \u00A7cagain!");
event.setCancelled(true);

View File

@ -1,6 +1,9 @@
package com.sekwah.advancedportals;
import com.sekwah.advancedportals.portals.AdvancedPortal;
import com.sekwah.advancedportals.portals.Portal;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
@ -11,8 +14,10 @@ public class PortalPlacer implements Listener {
@SuppressWarnings("unused")
private final AdvancedPortalsPlugin plugin;
// The needed config values will be stored so they are easier to access later
// an example is in the interact event in this if statement if((!UseOnlyServerAxe || event.getItem().getItemMeta().getDisplayName().equals("§eP...
private final double PortalProtectionRadius;
// The needed config values will be stored so they are easier to access later
// an example is in the interact event in this if statement if((!UseOnlyServerAxe || event.getItem().getItemMeta().getDisplayName().equals("<EFBFBD>eP...
private boolean PortalPlace = true;
public PortalPlacer(AdvancedPortalsPlugin plugin) {
@ -20,6 +25,8 @@ public class PortalPlacer implements Listener {
ConfigAccessor config = new ConfigAccessor(plugin, "Config.yml");
this.PortalPlace = config.getConfig().getBoolean("CanBuildPortalBlock");
this.PortalProtectionRadius = config.getConfig().getDouble("PortalProtectionRadius");
if(PortalPlace){
plugin.getServer().getPluginManager().registerEvents(this, plugin);
@ -28,11 +35,27 @@ public class PortalPlacer implements Listener {
@EventHandler(priority = EventPriority.HIGHEST)
public void onBlockPhysics(BlockPhysicsEvent event) {
Material material = event.getBlock().getType();
Block block = event.getBlock();
Material material = block.getType();
if (material == Material.PORTAL)
{
event.getChangedType();
event.setCancelled(true);
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;
}
}
}
}
//event.getChangedType();
//event.setCancelled(true);
}
}

View File

@ -1,5 +1,6 @@
package com.sekwah.advancedportals;
import com.sekwah.advancedportals.portals.AdvancedPortal;
import com.sekwah.advancedportals.portals.Portal;
import org.bukkit.block.Block;
import org.bukkit.event.EventHandler;
@ -42,16 +43,15 @@ public class PortalProtect implements Listener {
if(!event.getPlayer().hasPermission("advancedportals.build")){
Block block = event.getBlock();
Object[] portals = Portal.Portals;
int portalId = 0;
for(Object portal : portals){
if(Portal.Portals[portalId].worldName.equals(block.getWorld().getName())){
for(AdvancedPortal portal : Portal.Portals){
if(portal.worldName.equals(block.getWorld().getName())){
if((Portal.Portals[portalId].pos1.getX() + PortalProtectionRadius) >= block.getX() && (Portal.Portals[portalId].pos1.getY() + PortalProtectionRadius) >= block.getY() && (Portal.Portals[portalId].pos1.getZ() + PortalProtectionRadius) >= block.getZ()){
if((portal.pos1.getX() + PortalProtectionRadius) >= block.getX() && (portal.pos1.getY() + PortalProtectionRadius) >= block.getY() && (portal.pos1.getZ() + PortalProtectionRadius) >= block.getZ()){
if((Portal.Portals[portalId].pos2.getX() - PortalProtectionRadius) <= block.getX() && (Portal.Portals[portalId].pos2.getY() - PortalProtectionRadius) <= block.getY() && (Portal.Portals[portalId].pos2.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;
}
}
@ -68,16 +68,15 @@ public class PortalProtect implements Listener {
if(!event.getPlayer().hasPermission("advancedportals.build")){
Block block = event.getBlock();
Object[] portals = Portal.Portals;
for(int portalId = 0; portalId < portals.length; portalId++){
if(Portal.Portals[portalId].worldName.equals(block.getWorld().getName())){
for(AdvancedPortal portal : Portal.Portals){
if(portal.worldName.equals(block.getWorld().getName())){
if((Portal.Portals[portalId].pos1.getX() + PortalProtectionRadius) >= block.getX() && (Portal.Portals[portalId].pos1.getY() + PortalProtectionRadius) >= block.getY() && (Portal.Portals[portalId].pos1.getZ() + PortalProtectionRadius) >= block.getZ()){
if((portal.pos1.getX() + PortalProtectionRadius) >= block.getX() && (portal.pos1.getY() + PortalProtectionRadius) >= block.getY() && (portal.pos1.getZ() + PortalProtectionRadius) >= block.getZ()){
if((Portal.Portals[portalId].pos2.getX() - PortalProtectionRadius) <= block.getX() && (Portal.Portals[portalId].pos2.getY() - PortalProtectionRadius) <= block.getY() && (Portal.Portals[portalId].pos2.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;
}
}
@ -92,13 +91,12 @@ public class PortalProtect implements Listener {
for (int i = 0; i < blockList.size(); i++) {
Block block = blockList.get(i);
Object[] portals = Portal.Portals;
int portalId = 0;
for(Object portal : portals){ // change for format for(int i = 0; i < portals.length; i++){
if(Portal.Portals[portalId].worldName.equals(block.getWorld().getName())){
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.Portals[portalId].pos1.getX() + PortalProtectionRadius) >= block.getX() && (Portal.Portals[portalId].pos1.getY() + PortalProtectionRadius) >= block.getY() && (Portal.Portals[portalId].pos1.getZ() + PortalProtectionRadius) >= block.getZ()){
if((portal.pos1.getX() + PortalProtectionRadius) >= block.getX() && (portal.pos1.getY() + PortalProtectionRadius) >= block.getY() && (portal.pos1.getZ() + PortalProtectionRadius) >= block.getZ()){
if((Portal.Portals[portalId].pos2.getX() - PortalProtectionRadius) <= block.getX() && (Portal.Portals[portalId].pos2.getY() - PortalProtectionRadius) <= block.getY() && (Portal.Portals[portalId].pos2.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--;
@ -107,7 +105,6 @@ public class PortalProtect implements Listener {
}
}
portalId++;
}
}
}

View File

@ -345,7 +345,7 @@ public class Portal {
String destiName = config.getConfig().getString(portalName + ".destination");
if(configDesti.getConfig().getString(destiName + ".world") != null){
String permission = config.getConfig().getString(portalName + ".portalArgs.permission");
if(permission != null && player.hasPermission(permission)){
if(permission != null && player.hasPermission(permission) || player.isOp()){
boolean warped = Destination.warp(player, destiName);
return warped;
}