diff --git a/build.gradle b/build.gradle index 3f88707..3acc204 100644 --- a/build.gradle +++ b/build.gradle @@ -45,6 +45,8 @@ dependencies { implementation "net.md-5:bungeecord-api:1.15-SNAPSHOT" implementation "io.netty:netty-all:4.0.4.Final" + + //compile fileTree(dir: 'libs', include: ['*.jar']) } task copyPlugin { diff --git a/src/main/java/com/sekwah/advancedportals/bukkit/AdvancedPortalsCommand.java b/src/main/java/com/sekwah/advancedportals/bukkit/AdvancedPortalsCommand.java index a735aab..255e547 100644 --- a/src/main/java/com/sekwah/advancedportals/bukkit/AdvancedPortalsCommand.java +++ b/src/main/java/com/sekwah/advancedportals/bukkit/AdvancedPortalsCommand.java @@ -10,6 +10,8 @@ import org.bukkit.DyeColor; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.World; +import org.bukkit.block.Block; +import org.bukkit.block.EndGateway; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; @@ -64,24 +66,63 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter { if (args.length > 0) { switch (args[0].toLowerCase()) { case "warp": - if (args.length == 2 && player.hasPermission("advancedportals.portal.warp")) { - for (AdvancedPortal portal : Portal.portals) { - if (args[1].equalsIgnoreCase(portal.getName())) { + if (args.length == 2 && (player.hasPermission("advancedportals.warp.*") || player.hasPermission("advancedportals.warp." + args[1]))) { + AdvancedPortal portal = Portal.getPortal(args[1]); - if (portal.inPortal.contains(player.getUniqueId())) - return true; - WarpEvent warpEvent = new WarpEvent(player, portal); - plugin.getServer().getPluginManager().callEvent(warpEvent); + if(portal == null) { + sender.sendMessage(PluginMessages.customPrefixFail + + " Could not find a portal with that name"); + } + else { + if (portal.inPortal.contains(player.getUniqueId())) + return true; + WarpEvent warpEvent = new WarpEvent(player, portal); + plugin.getServer().getPluginManager().callEvent(warpEvent); - if (!warpEvent.isCancelled()) - Portal.activate(player, portal); - break; + if (!warpEvent.isCancelled()) { + Portal.activate(player, portal); } } } else if (args.length == 1 && player.hasPermission("advancedportals.portal.warp")) { sendMenu(player, "Help Menu: Warp", "\u00A76/" + command + " warp \u00A7a- teleport to warp name"); } + else { + sender.sendMessage(PluginMessages.customPrefixFail + + " You do not have permission"); + } + break; + case "disablebeacon": + boolean DISABLE_BEACON = config.getConfig().getBoolean("DisableGatewayBeam", true); + if (player.hasPermission("advancedportals.build") && DISABLE_BEACON) { + if(args.length == 1) { + sender.sendMessage(PluginMessages.customPrefixFail + + " You need to specify a portal to replace the blocks."); + } + else { + AdvancedPortal portal = Portal.getPortal(args[1]); + + if(portal == null) { + sender.sendMessage(PluginMessages.customPrefixFail + + " Could not find a portal with that name"); + } + else { + sender.sendMessage(PluginMessages.customPrefix + + " Replacing any found beacon blocks."); + disableBeacons(portal); + } + } + } + else { + if(DISABLE_BEACON) { + + } + else { + + } + sender.sendMessage(PluginMessages.customPrefixFail + " You do not have permission " + + "to do that." + " Needed: \u00A7eadvancedportals.build"); + } break; case "wand": case "selector": @@ -338,6 +379,12 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter { portalArgs = extraData.toArray(portalArgs); player.sendMessage(Portal.create(pos1, pos2, portalName, destination, materialSet, serverName, portalArgs)); + if(materialSet.contains(Material.END_GATEWAY)) { + AdvancedPortal portal = Portal.getPortal(portalName); + if(portal != null) { + disableBeacons(portal); + } + } } else { ConfigAccessor Config = new ConfigAccessor(plugin, "config.yml"); player.sendMessage("\u00A7ctriggerBlock: \u00A7edefault(" @@ -629,6 +676,29 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter { return true; } + private void disableBeacons(AdvancedPortal portal) { + Location loc1 = portal.getPos1(); + Location loc2 = portal.getPos2(); + + Location scanner = loc1.clone(); + + for (int x = loc2.getBlockX(); x <= loc1.getBlockX(); x++) { + scanner.setZ(x); + for (int y = loc2.getBlockY(); y <= loc1.getBlockY(); y++) { + scanner.setZ(y); + for (int z = loc2.getBlockZ(); z <= loc1.getBlockZ(); z++) { + scanner.setZ(z); + Block block = scanner.getBlock(); + if(block.getType() == Material.END_GATEWAY) { + EndGateway tileState = (EndGateway) block.getState(); + tileState.setAge(Long.MIN_VALUE); + tileState.update(); + } + } + } + } + } + private boolean startsWithPortalArg(String portalArg, String arg) { return arg.toLowerCase().startsWith(portalArg) && arg.length() > portalArg.length(); } @@ -780,7 +850,7 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter { if (sender.hasPermission("advancedportals.createportal")) { if (args.length == 1 || (args.length == 2 && args[0].toLowerCase().equals("help"))) { autoComplete.addAll(Arrays.asList("create", "list", "portalblock", "select", "unselect", "command", - "selector", "show", "gatewayblock", "endportalblock", "variables", "wand", "remove", "rename", + "selector", "show", "gatewayblock", "endportalblock", "variables", "wand", "disablebeacon", "remove", "rename", "help", "bukkitpage", "helppage", "warp")); } else if (args[0].toLowerCase().equals("create")) { @@ -863,7 +933,7 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter { } } } - if (args.length == 2 && args[0].equalsIgnoreCase("warp")) { + if (args.length == 2 && (args[0].equalsIgnoreCase("warp"))) { for (AdvancedPortal portal : Portal.portals) { String perm = portal.getArg("permission"); if (perm == null || sender.hasPermission(perm)) { @@ -871,6 +941,12 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter { } } } + else if (args.length == 2 && (args[0].equalsIgnoreCase("remove") + || args[0].equalsIgnoreCase("disablebeacon"))) { + for (AdvancedPortal portal : Portal.portals) { + autoComplete.add(portal.getName()); + } + } String triggerBlock = "triggerblock:"; if (args[args.length - 1].toLowerCase().startsWith(triggerBlock)) { String currentArg = args[args.length - 1]; diff --git a/src/main/java/com/sekwah/advancedportals/bukkit/compat/CraftBukkit.java b/src/main/java/com/sekwah/advancedportals/bukkit/compat/CraftBukkit.java index 428ab94..2188215 100644 --- a/src/main/java/com/sekwah/advancedportals/bukkit/compat/CraftBukkit.java +++ b/src/main/java/com/sekwah/advancedportals/bukkit/compat/CraftBukkit.java @@ -87,25 +87,4 @@ public class CraftBukkit { e.printStackTrace(); } } - - - /** - * Blocks the beacon from showing - * @param block - */ - /*public void setGatewayAgeHigh(Block block) { - if(block.getWorld().getEnvironment() != World.Environment.THE_END && - this.endGatewayClass.isAssignableFrom(block.getState().getClass())) { - try { - Object tileEntity = this.getTileEntityMethod.invoke(this.getWorldHandleMethod.invoke(block.getWorld()), - this.blockPositionConstructor.newInstance(block.getX(), block.getY(), block.getZ())); - if(this.tileEntityEndGatewayClass.isAssignableFrom(tileEntity.getClass())) { - getEntityTimeoutField.set(tileEntity, Integer.MAX_VALUE); - } - } catch (IllegalAccessException| InvocationTargetException | InstantiationException e) { - this.plugin.getLogger().warning("Error setting gateway time"); - e.printStackTrace(); - } - } - }*/ } diff --git a/src/main/java/com/sekwah/advancedportals/bukkit/config/ConfigHelper.java b/src/main/java/com/sekwah/advancedportals/bukkit/config/ConfigHelper.java index 87a3de7..aa41029 100644 --- a/src/main/java/com/sekwah/advancedportals/bukkit/config/ConfigHelper.java +++ b/src/main/java/com/sekwah/advancedportals/bukkit/config/ConfigHelper.java @@ -6,10 +6,11 @@ public class ConfigHelper { public static String CONFIG_VERSION = "ConfigVersion"; + public static String DISABLE_GATEWAY_BEAM = "DisableGatewayBeam"; + private FileConfiguration config; public ConfigHelper(FileConfiguration config) { - this.config = config; } @@ -21,6 +22,8 @@ public class ConfigHelper { // Added in 0.5.4 if(configVersion == null || configVersion.equals("0.5.3")) { config.set(ConfigHelper.CONFIG_VERSION, "0.5.4"); + + config.set(ConfigHelper.CONFIG_VERSION, true); } } } diff --git a/src/main/java/com/sekwah/advancedportals/bukkit/listeners/PortalPlacer.java b/src/main/java/com/sekwah/advancedportals/bukkit/listeners/PortalPlacer.java index 55c2e94..a4793da 100644 --- a/src/main/java/com/sekwah/advancedportals/bukkit/listeners/PortalPlacer.java +++ b/src/main/java/com/sekwah/advancedportals/bukkit/listeners/PortalPlacer.java @@ -5,17 +5,20 @@ import com.sekwah.advancedportals.bukkit.config.ConfigAccessor; import com.sekwah.advancedportals.bukkit.portals.Portal; import org.bukkit.Material; import org.bukkit.block.Block; +import org.bukkit.block.BlockState; +import org.bukkit.block.EndGateway; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.block.BlockPhysicsEvent; import org.bukkit.event.block.BlockPlaceEvent; +import org.bukkit.event.world.ChunkLoadEvent; public class PortalPlacer implements Listener { @SuppressWarnings("unused") private final AdvancedPortalsPlugin plugin; - //private final boolean DISABLE_GATEWAY_BEAM; + private final boolean DISABLE_GATEWAY_BEAM; public PortalPlacer(AdvancedPortalsPlugin plugin) { this.plugin = plugin; @@ -23,7 +26,7 @@ public class PortalPlacer implements Listener { ConfigAccessor config = new ConfigAccessor(plugin, "config.yml"); boolean portalPlace = config.getConfig().getBoolean("CanBuildPortalBlock"); - //this.DISABLE_GATEWAY_BEAM = config.getConfig().getBoolean("DisableGatewayBeam", true); + this.DISABLE_GATEWAY_BEAM = config.getConfig().getBoolean("DisableGatewayBeam", true); if (portalPlace) { @@ -46,18 +49,37 @@ public class PortalPlacer implements Listener { event.getBlockPlaced().setType(Material.END_PORTAL); } else if (name.equals("\u00A78Gateway Block Placer")){ - event.getBlockPlaced().setType(Material.END_GATEWAY); - /*if(this.DISABLE_GATEWAY_BEAM) { - Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, () -> { - this.plugin.compat.setGatewayAgeHigh(event.getBlock()); - }, 1); - }*/ + Block block = event.getBlockPlaced(); + block.setType(Material.END_GATEWAY); + if(this.DISABLE_GATEWAY_BEAM) { + EndGateway tileState = (EndGateway) block.getState(); + tileState.setAge(Long.MIN_VALUE); + tileState.update(); + } } } } + @EventHandler + public void onChunkLoad(ChunkLoadEvent event) { + if(!this.DISABLE_GATEWAY_BEAM) { + return; + } + BlockState[] tileEntities = event.getChunk().getTileEntities(); + for(BlockState block : tileEntities) { + if(block.getType() == Material.END_GATEWAY) { + if(Portal.inPortalRegion(block.getLocation(), 5)) { + EndGateway tileState = (EndGateway) block; + tileState.setAge(Long.MIN_VALUE); + tileState.update(); + } + } + + } + } + @EventHandler(priority = EventPriority.HIGHEST) public void onBlockPhysics(BlockPhysicsEvent event) { Block block = event.getBlock(); diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index e6f4ac6..476a020 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -70,9 +70,11 @@ BlockSpectatorMode: false PortalCooldown: 5 # How long after trying to enter a portal until the player can try to enter another. 0 or lower to deactivate. ThrowbackAmount: 0.7 # How fast to throw them back, 0 or lower to disable throwback -# Experimental, works but not all the time (Entities don't seem to be provided in the event sometimes or something is wrong) -# We have no plans to further this but if anyone has any tips feel free to contact us here https://discord.gg/25QZVVn -DisableGatewayBeam: false +# Only disables the gateway block places with "/portal gatewayblock" for now +# If you want to replace already made portals just use "/portal disablebeacon" and it will run through all the blocks in the area +# Reloading the world or chunks that portals are in will also trigger the beacons to be disabled (this is for efficiency reasons) +# However these wont trigger in the spawn chunks as they are loaded before any pluigns are. +DisableGatewayBeam: true # Enable or disable special command portals # diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 3282242..4d5a3ac 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -55,5 +55,5 @@ permissions: description: Gives access to all desti commands default: op advancedportals.warp.*: - description: Access to all warps (not really used tbh) + description: Access to all warps default: op