diff --git a/src/com/sekwah/advancedportals/AdvancedPortalsCommand.java b/src/com/sekwah/advancedportals/AdvancedPortalsCommand.java index 8153b3a1..2f7c4054 100644 --- a/src/com/sekwah/advancedportals/AdvancedPortalsCommand.java +++ b/src/com/sekwah/advancedportals/AdvancedPortalsCommand.java @@ -1,6 +1,7 @@ package com.sekwah.advancedportals; import com.sekwah.advancedportals.portals.Portal; +import com.sekwah.advancedportals.portals.PortalArg; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.World; @@ -14,10 +15,7 @@ import org.bukkit.inventory.PlayerInventory; import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.metadata.FixedMetadataValue; -import java.util.Arrays; -import java.util.Collections; -import java.util.LinkedList; -import java.util.List; +import java.util.*; public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter { @@ -61,7 +59,7 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter { else if(args[0].toLowerCase().equals("portal") || args[0].toLowerCase().equals("portalblock")){ PlayerInventory inventory = player.getInventory(); - ItemStack portalBlock = new ItemStack(Material.PORTAL); + ItemStack portalBlock = new ItemStack(Material.PORTAL, 1); inventory.addItem(portalBlock); @@ -75,10 +73,15 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter { boolean hasTriggerBlock = false; boolean hasDestination = false; boolean isBungeePortal = false; + boolean needsPermission = false; String destination = null; String portalName = null; String triggerBlock = null; String serverName = null; + String permission = null; + + ArrayList extraData = new ArrayList(); + for(int i = 1; i < args.length; i++){ if(args[i].toLowerCase().startsWith("name:") && args[i].length() > 5){ hasName = true; @@ -107,7 +110,13 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter { else if(args[i].toLowerCase().startsWith("bungee:") && args[i].length() > 7){ // not completely implemented isBungeePortal = true; serverName = args[i].toLowerCase().replaceFirst("bungee:", ""); + //extraData.add(new PortalArgs("bungee", serverName)); } + else if(args[i].toLowerCase().startsWith("permission:") && args[i].length() > 11){ // not completely implemented + needsPermission = true; + permission = args[i].toLowerCase().replaceFirst("permission:", ""); + extraData.add(new PortalArg("permission", permission)); + } } if(!hasName){ player.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] You must include a name for the portal that you are creating in the variables!"); @@ -140,12 +149,21 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter { player.sendMessage("\u00A7abungee: \u00A7e" + serverName); } + if(needsPermission){ + player.sendMessage("\u00A7apermission: \u00A7e" + permission); + } + else{ + player.sendMessage("\u00A7apermission: \u00A7e(none needed)"); + } + Material triggerBlockMat = Material.getMaterial(0); if(hasTriggerBlock){ triggerBlockMat = Material.getMaterial(triggerBlock.toUpperCase()); if(triggerBlockMat != null){ player.sendMessage("\u00A7atriggerBlock: \u00A7e" + triggerBlock.toUpperCase()); - player.sendMessage(Portal.create(pos1, pos2, portalName, destination, triggerBlockMat, serverName)); + PortalArg[] portalArgs = new PortalArg[extraData.size()]; + portalArgs = extraData.toArray(portalArgs); + player.sendMessage(Portal.create(pos1, pos2, portalName, destination, triggerBlockMat, serverName, portalArgs)); } else{ hasTriggerBlock = false; @@ -153,13 +171,17 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter { player.sendMessage("\u00A7ctriggerBlock: \u00A7edefault(" + Config.getConfig().getString("DefaultPortalTriggerBlock") + ")"); player.sendMessage("\u00A7cThe block " + triggerBlock.toUpperCase() + " is not a valid block name in minecraft so the trigger block has been set to the default!"); - player.sendMessage(Portal.create(pos1, pos2, portalName, destination, serverName)); + PortalArg[] portalArgs = new PortalArg[extraData.size()]; + portalArgs = extraData.toArray(portalArgs); + player.sendMessage(Portal.create(pos1, pos2, portalName, destination, serverName, portalArgs)); } } else{ ConfigAccessor Config = new ConfigAccessor(plugin, "Config.yml"); player.sendMessage("\u00A7atriggerBlock: \u00A7edefault(" + Config.getConfig().getString("DefaultPortalTriggerBlock") + ")"); - player.sendMessage(Portal.create(pos1, pos2, portalName, destination, serverName)); + PortalArg[] portalArgs = new PortalArg[extraData.size()]; + portalArgs = extraData.toArray(portalArgs); + player.sendMessage(Portal.create(pos1, pos2, portalName, destination, serverName, portalArgs)); } } else{ @@ -432,6 +454,7 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter { boolean hasTriggerBlock = false; boolean hasDestination = false; boolean isBungeePortal = false; + boolean needsPermission = false; for(int i = 1; i < args.length; i++){ if(args[i].toLowerCase().startsWith("name:") && args[i].length() > 5){ @@ -449,6 +472,9 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter { else if(args[i].toLowerCase().startsWith("bungee:") && args[i].length() > 7){ isBungeePortal = true; } + else if(args[i].toLowerCase().startsWith("permission:") && args[i].length() > 11){ + needsPermission = true; + } } @@ -456,6 +482,7 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter { if(!hasTriggerBlock){autoComplete.add("triggerblock:");} if(!hasDestination){autoComplete.add("destination:");autoComplete.add("desti:");} if(!isBungeePortal){autoComplete.add("bungee:");} + if(!isBungeePortal){autoComplete.add("permission:");} } } Collections.sort(autoComplete); diff --git a/src/com/sekwah/advancedportals/AdvancedPortalsPlugin.java b/src/com/sekwah/advancedportals/AdvancedPortalsPlugin.java index 97936f73..46c23dd1 100644 --- a/src/com/sekwah/advancedportals/AdvancedPortalsPlugin.java +++ b/src/com/sekwah/advancedportals/AdvancedPortalsPlugin.java @@ -43,7 +43,7 @@ public class AdvancedPortalsPlugin extends JavaPlugin { this.setEnabled(false); } } catch (ClassNotFoundException e) { - System.out.println("This version of craftbukkit is not yet supported, please notify the author and give them this version v:" + version); + System.out.println("This version of craftbukkit is not yet supported, please notify the author and give version v:" + version); this.setEnabled(false); } catch (InstantiationException e) { e.printStackTrace(); diff --git a/src/com/sekwah/advancedportals/DestinationCommand.java b/src/com/sekwah/advancedportals/DestinationCommand.java index 7685aed6..fd06bf94 100644 --- a/src/com/sekwah/advancedportals/DestinationCommand.java +++ b/src/com/sekwah/advancedportals/DestinationCommand.java @@ -59,13 +59,13 @@ public class DestinationCommand implements CommandExecutor, TabCompleter { else if(args[0].toLowerCase().equals("remove")) { ConfigAccessor portalConfig = new ConfigAccessor(plugin, "Destinations.yml"); if(args.length > 1){ - String posX = portalConfig.getConfig().getString(args[1] + ".pos1.X"); + String posX = portalConfig.getConfig().getString(args[1] + ".pos.X"); if(posX != null){ Destination.remove(args[1]); - sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] The portal \u00A7e" + args[1] + "\u00A7c has been removed!"); + sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] The destination \u00A7e" + args[1] + "\u00A7c has been removed!"); } else{ - sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] No portal by that name exists."); + sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] No destination by that name exists."); } } else{ @@ -74,7 +74,7 @@ public class DestinationCommand implements CommandExecutor, TabCompleter { } else if(args[0].toLowerCase().equals("goto") || args[0].toLowerCase().equals("warp")) { if(args.length > 1){ - System.out.println(args[1]); + //System.out.println(args[1]); ConfigAccessor configDesti = new ConfigAccessor(plugin, "Destinations.yml"); if(configDesti.getConfig().getString(args[1] + ".world") != null){ Destination.warp(sender, args[1]); @@ -84,7 +84,7 @@ public class DestinationCommand implements CommandExecutor, TabCompleter { sender.sendMessage(""); } else if(PortalMessagesDisplay == 2){ - ConfigAccessor config = new ConfigAccessor(plugin, "Portals.yml"); + ConfigAccessor config = new ConfigAccessor(plugin, "Destinations.yml"); plugin.nmsAccess.sendActionBarMessage("{text:\"\u00A7aYou have warped to \u00A7e" + args[1].replaceAll("_", " ") + "\u00A7a.\"}", (Player) sender); /**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);*/ diff --git a/src/com/sekwah/advancedportals/FlowStopper.java b/src/com/sekwah/advancedportals/FlowStopper.java index c439e731..99b0f551 100644 --- a/src/com/sekwah/advancedportals/FlowStopper.java +++ b/src/com/sekwah/advancedportals/FlowStopper.java @@ -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++; } } diff --git a/src/com/sekwah/advancedportals/Listeners.java b/src/com/sekwah/advancedportals/Listeners.java index 83cf5b09..41acf89e 100644 --- a/src/com/sekwah/advancedportals/Listeners.java +++ b/src/com/sekwah/advancedportals/Listeners.java @@ -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 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 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); diff --git a/src/com/sekwah/advancedportals/PortalPlacer.java b/src/com/sekwah/advancedportals/PortalPlacer.java index 76992413..3d447190 100644 --- a/src/com/sekwah/advancedportals/PortalPlacer.java +++ b/src/com/sekwah/advancedportals/PortalPlacer.java @@ -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("�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); } } diff --git a/src/com/sekwah/advancedportals/PortalProtect.java b/src/com/sekwah/advancedportals/PortalProtect.java index 701359ae..b2213076 100644 --- a/src/com/sekwah/advancedportals/PortalProtect.java +++ b/src/com/sekwah/advancedportals/PortalProtect.java @@ -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,14 @@ 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.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.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; } } @@ -68,16 +67,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 +90,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 +104,6 @@ public class PortalProtect implements Listener { } } - portalId++; } } } diff --git a/src/com/sekwah/advancedportals/compat/v1_8_R2.java b/src/com/sekwah/advancedportals/compat/v1_8_R2.java new file mode 100644 index 00000000..a65f95b0 --- /dev/null +++ b/src/com/sekwah/advancedportals/compat/v1_8_R2.java @@ -0,0 +1,27 @@ +package com.sekwah.advancedportals.compat; + +import net.minecraft.server.v1_8_R2.IChatBaseComponent; +import net.minecraft.server.v1_8_R2.PacketPlayOutChat; +import org.bukkit.craftbukkit.v1_8_R2.entity.CraftPlayer; +import org.bukkit.entity.Player; + + +public class v1_8_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); + } +} diff --git a/src/com/sekwah/advancedportals/portals/Portal.java b/src/com/sekwah/advancedportals/portals/Portal.java index 19dc14fe..9c51ba36 100644 --- a/src/com/sekwah/advancedportals/portals/Portal.java +++ b/src/com/sekwah/advancedportals/portals/Portal.java @@ -72,7 +72,6 @@ public class Portal { } Portals[portalId].trigger = blockType; - System.out.println("Test: " + portal.toString()); Portals[portalId].portalName = portal.toString(); Portals[portalId].worldName = config.getConfig().getString(portal.toString() + ".world"); World world = Bukkit.getWorld(config.getConfig().getString(portal.toString() + ".world")); @@ -89,11 +88,11 @@ public class Portal { } - public static String create(Location pos1, Location pos2 , String name, String destination, Material triggerBlock) { - return create(pos1, pos2, name, destination, triggerBlock, null); + public static String create(Location pos1, Location pos2 , String name, String destination, Material triggerBlock, PortalArg... extraData) { + return create(pos1, pos2, name, destination, triggerBlock, null, extraData); } - public static String create(Location pos1, Location pos2 , String name, String destination, Material triggerBlock, String serverName) { + public static String create(Location pos1, Location pos2, String name, String destination, Material triggerBlock, String serverName, PortalArg... portalArgs) { if(!pos1.getWorld().equals(pos2.getWorld())){ plugin.getLogger().log(Level.WARNING, "pos1 and pos2 must be in the same world!"); @@ -158,6 +157,10 @@ public class Portal { config.getConfig().set(name + ".pos2.X", LowX); config.getConfig().set(name + ".pos2.Y", LowY); config.getConfig().set(name + ".pos2.Z", LowZ); + + for(PortalArg arg: portalArgs){ + config.getConfig().set(name + ".portalArgs." + arg.argName, arg.value); + } config.saveConfig(); @@ -215,8 +218,8 @@ public class Portal { return triggerBlock.toString(); } - public static String create(Location pos1, Location pos2, String name, String destination) { - return create(pos1, pos2, name, destination,(String) null); + public static String create(Location pos1, Location pos2, String portalName, String name, String destination, PortalArg... extraData) { + return create(pos1, pos2, name, destination,(String) null); } @SuppressWarnings("deprecation") @@ -340,8 +343,15 @@ public class Portal { ConfigAccessor configDesti = new ConfigAccessor(plugin, "Destinations.yml"); String destiName = config.getConfig().getString(portalName + ".destination"); if(configDesti.getConfig().getString(destiName + ".world") != null){ - boolean warped = Destination.warp(player, destiName); - return warped; + String permission = config.getConfig().getString(portalName + ".portalArgs.permission"); + if(permission == null || (permission != null && player.hasPermission(permission)) || player.isOp()){ + boolean warped = Destination.warp(player, destiName); + return warped; + } + else{ + player.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] You do not have permission to use this portal!"); + return false; + } } else{ player.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] The destination you are currently attempting to warp to doesnt exist!"); diff --git a/src/com/sekwah/advancedportals/portals/PortalArg.java b/src/com/sekwah/advancedportals/portals/PortalArg.java new file mode 100644 index 00000000..5738c044 --- /dev/null +++ b/src/com/sekwah/advancedportals/portals/PortalArg.java @@ -0,0 +1,16 @@ +package com.sekwah.advancedportals.portals; + +public class PortalArg { + + public final String argName; + public final String value; + //public final int type; + + public PortalArg(String argName, String value/*, int type*/){ + this.argName = argName; + this.value = value; + // may be used if values need to be 100% not string + //this.type = type; + } + +} diff --git a/src/plugin.yml b/src/plugin.yml index ed10eaf4..f322ba9c 100644 --- a/src/plugin.yml +++ b/src/plugin.yml @@ -1,6 +1,6 @@ main: com.sekwah.advancedportals.AdvancedPortalsPlugin name: AdvancedPortals -version: 0.0.4 +version: 0.0.6 author: SEKWAH41 description: An advanced portals plugin for bukkit. commands: @@ -20,10 +20,14 @@ permissions: description: Gives access to all portal commands children: advancedportals.createportal: true + advancedportals.portal: true advancedportals.build: true advancedportals.createportal: description: Allows you to create portals default: op + advancedportals.portal: + description: Allows use of portal commands + default: op advancedportals.build: description: Allows you to build in the portal regions default: op