diff --git a/core/src/main/java/com/sekwah/advancedportals/core/AdvancedPortalsCore.java b/core/src/main/java/com/sekwah/advancedportals/core/AdvancedPortalsCore.java index 70e8638c..ad470c64 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/AdvancedPortalsCore.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/AdvancedPortalsCore.java @@ -173,6 +173,8 @@ private void registerPortalCommand(CommandRegister commandRegister) { new ShowPortalSubCommand()); this.portalCommand.registerSubCommand("info", new InfoPortalSubCommand()); + this.portalCommand.registerSubCommand("disablebeacon", + new DisableBeaconSubCommand()); commandRegister.registerCommand("portal", this.portalCommand); } diff --git a/core/src/main/java/com/sekwah/advancedportals/core/CoreListeners.java b/core/src/main/java/com/sekwah/advancedportals/core/CoreListeners.java index 0a55ad34..b21b059a 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/CoreListeners.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/CoreListeners.java @@ -141,6 +141,7 @@ public boolean blockPlace(PlayerContainer player, BlockLocation blockPos, return true; } else if (itemInHandName.equals("\u00A78Gateway Block Placer")) { world.setBlock(blockPos, "END_GATEWAY"); + world.disableBeacon(blockPos); return true; } return true; diff --git a/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/DisableBeaconSubCommand.java b/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/DisableBeaconSubCommand.java new file mode 100644 index 00000000..b0074181 --- /dev/null +++ b/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/DisableBeaconSubCommand.java @@ -0,0 +1,55 @@ +package com.sekwah.advancedportals.core.commands.subcommands.portal; + +import com.google.inject.Inject; +import com.sekwah.advancedportals.core.commands.SubCommand; +import com.sekwah.advancedportals.core.connector.containers.CommandSenderContainer; +import com.sekwah.advancedportals.core.services.PortalServices; +import com.sekwah.advancedportals.core.util.Lang; +import com.sekwah.advancedportals.core.util.TagReader; + +import java.util.List; + +public class DisableBeaconSubCommand implements SubCommand { + @Inject + PortalServices portalServices; + + @Override + public void onCommand(CommandSenderContainer sender, String[] args) { + if (args.length > 1) { + var portalName = args[1]; + var portal = portalServices.getPortal(portalName); + if(portal == null) { + sender.sendMessage(Lang.getNegativePrefix() + + Lang.translateInsertVariables("command.portal.disablebeacon.notfound", portalName)); + return; + } + sender.sendMessage(Lang.getPositivePrefix() + + Lang.translateInsertVariables("command.portal.disablebeacon.complete", portalName)); + sender.getPlayerContainer().getWorld().disableBeacon(portal); + } else { + sender.sendMessage(Lang.getNegativePrefix() + + Lang.translate("command.portal.disablebeacon.noname")); + } + } + + @Override + public boolean hasPermission(CommandSenderContainer sender) { + return true; + } + + @Override + public List onTabComplete(CommandSenderContainer sender, + String[] args) { + return portalServices.getPortalNames(); + } + + @Override + public String getBasicHelpText() { + return Lang.translate("command.portal.disablebeacon.help"); + } + + @Override + public String getDetailedHelpText() { + return Lang.translate("command.portal.disablebeacon.help"); + } +} diff --git a/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/ShowPortalSubCommand.java b/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/ShowPortalSubCommand.java index 0e7c6c3f..0bf296c9 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/ShowPortalSubCommand.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/ShowPortalSubCommand.java @@ -199,15 +199,11 @@ private void debugVisuals(PlayerContainer player, BlockLocation pos1, int maxY = Math.max(pos1.getPosY(), pos2.getPosY()); int maxZ = Math.max(pos1.getPosZ(), pos2.getPosZ()); - var world = player.getWorld(); - - int widthX = maxX - minX + 1; - int widthY = maxY - minY + 1; - int widthZ = maxZ - minZ + 1; + var size = pos1.getSize(pos2); - int totalBlocks = widthX * widthY * widthZ; + var world = player.getWorld(); - if (totalBlocks <= config.getMaxTriggerVisualisationSize()) { + if (size <= config.getMaxTriggerVisualisationSize()) { for (int x = minX; x <= maxX; x++) { for (int y = minY; y <= maxY; y++) { for (int z = minZ; z <= maxZ; z++) { diff --git a/core/src/main/java/com/sekwah/advancedportals/core/connector/containers/WorldContainer.java b/core/src/main/java/com/sekwah/advancedportals/core/connector/containers/WorldContainer.java index 186142a5..4416e2c8 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/connector/containers/WorldContainer.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/connector/containers/WorldContainer.java @@ -1,6 +1,7 @@ package com.sekwah.advancedportals.core.connector.containers; import com.sekwah.advancedportals.core.data.BlockAxis; +import com.sekwah.advancedportals.core.portal.AdvancedPortal; import com.sekwah.advancedportals.core.serializeddata.BlockLocation; public interface WorldContainer { @@ -8,7 +9,11 @@ public interface WorldContainer { String getBlock(BlockLocation location); + void disableBeacon(BlockLocation location); + BlockAxis getBlockAxis(BlockLocation location); void setBlockAxis(BlockLocation location, BlockAxis axis); + + void disableBeacon(AdvancedPortal portal); } diff --git a/core/src/main/java/com/sekwah/advancedportals/core/repository/ConfigRepository.java b/core/src/main/java/com/sekwah/advancedportals/core/repository/ConfigRepository.java index 3dc6b3a6..f5af8ef7 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/repository/ConfigRepository.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/repository/ConfigRepository.java @@ -49,4 +49,6 @@ public interface ConfigRepository { boolean getWarpEffectEnabled(); boolean getEnableProxySupport(); + + boolean getDisableGatewayBeam(); } diff --git a/core/src/main/java/com/sekwah/advancedportals/core/repository/impl/ConfigRepositoryImpl.java b/core/src/main/java/com/sekwah/advancedportals/core/repository/impl/ConfigRepositoryImpl.java index eb096cf3..8bbf8dc3 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/repository/impl/ConfigRepositoryImpl.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/repository/impl/ConfigRepositoryImpl.java @@ -105,6 +105,11 @@ public boolean getEnableProxySupport() { return this.config.enableProxySupport; } + @Override + public boolean getDisableGatewayBeam() { + return this.config.disableGatewayBeam; + } + @Override public void loadConfig(DataStorage dataStorage) { this.dataStorage = dataStorage; diff --git a/core/src/main/java/com/sekwah/advancedportals/core/serializeddata/BlockLocation.java b/core/src/main/java/com/sekwah/advancedportals/core/serializeddata/BlockLocation.java index c49f5fe2..05be2ea1 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/serializeddata/BlockLocation.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/serializeddata/BlockLocation.java @@ -75,4 +75,20 @@ public BlockLocation addY(int offsetY) { return new BlockLocation(this.worldName, this.posX, (this.posY + offsetY), this.posZ); } + + public int getSize(BlockLocation pos2) { + int minX = Math.min(this.getPosX(), pos2.getPosX()); + int minY = Math.min(this.getPosY(), pos2.getPosY()); + int minZ = Math.min(this.getPosZ(), pos2.getPosZ()); + + int maxX = Math.max(this.getPosX(), pos2.getPosX()); + int maxY = Math.max(this.getPosY(), pos2.getPosY()); + int maxZ = Math.max(this.getPosZ(), pos2.getPosZ()); + + int widthX = maxX - minX + 1; + int widthY = maxY - minY + 1; + int widthZ = maxZ - minZ + 1; + + return widthX * widthY * widthZ; + } } diff --git a/core/src/main/java/com/sekwah/advancedportals/core/serializeddata/config/Config.java b/core/src/main/java/com/sekwah/advancedportals/core/serializeddata/config/Config.java index d4d253b7..a65a2140 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/serializeddata/config/Config.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/serializeddata/config/Config.java @@ -39,4 +39,6 @@ public class Config { public boolean enableProxySupport = false; public WarpEffectConfig warpEffect = new WarpEffectConfig(); + + public boolean disableGatewayBeam = true; } diff --git a/lang/src/main/resources/lang/en_GB.lang b/lang/src/main/resources/lang/en_GB.lang index 6755aac0..35c536ae 100644 --- a/lang/src/main/resources/lang/en_GB.lang +++ b/lang/src/main/resources/lang/en_GB.lang @@ -117,6 +117,11 @@ command.destination.reload= Destinations reloaded. command.portal.list.help=Lists portals command.portal.list=&7 Portals&a: +command.portal.disablebeacon.help=Disables the gateway beacon effect for a portal +command.portal.disablebeacon.noname= You must specify a name +command.portal.disablebeacon.complete= The beacon effect has been disabled for the portal. +command.portal.disablebeacon.notfound= No portal by the name &e%1$s &cwas found. + command.destination.list.help=Lists destinations command.destination.list=&7 Destinations&a: diff --git a/spigot/build.gradle b/spigot/build.gradle index 3aa1eac4..e8f3d868 100644 --- a/spigot/build.gradle +++ b/spigot/build.gradle @@ -18,12 +18,12 @@ dependencies { // For spigot api // We are using an older version to try and ensure that we are not using anything new older versions cant use. - implementation "org.spigotmc:spigot-api:1.13-R0.1-SNAPSHOT" + implementation "org.spigotmc:spigot-api:1.13.2-R0.1-SNAPSHOT" implementation "net.md-5:bungeecord-api:1.16-R0.4" implementation "com.mojang:authlib:3.5.41" implementation "com.google.inject:guice:5.0.1" // Be careful to only use what you need to from paper, otherwise it will become incompatible with spigot. - //compileOnly 'com.destroystokyo.paper:paper-api:1.16.5-R0.1-SNAPSHOT' + // compileOnly 'com.destroystokyo.paper:paper-api:1.16.5-R0.1-SNAPSHOT' } jar { diff --git a/spigot/src/main/java/com/sekwah/advancedportals/spigot/Listeners.java b/spigot/src/main/java/com/sekwah/advancedportals/spigot/Listeners.java index e8439742..2582a016 100644 --- a/spigot/src/main/java/com/sekwah/advancedportals/spigot/Listeners.java +++ b/spigot/src/main/java/com/sekwah/advancedportals/spigot/Listeners.java @@ -5,7 +5,10 @@ import com.sekwah.advancedportals.core.data.PortalLocation; import com.sekwah.advancedportals.coreconnector.container.PlayerContainer; import org.bukkit.Location; +import org.bukkit.Material; import org.bukkit.block.Block; +import org.bukkit.block.BlockState; +import org.bukkit.block.EndGateway; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -13,6 +16,7 @@ import org.bukkit.event.block.*; import org.bukkit.event.entity.*; import org.bukkit.event.player.*; +import org.bukkit.event.world.ChunkLoadEvent; /** * Some of these will be passed to the core listener to handle the events, @@ -143,4 +147,26 @@ public void onExplosion(EntityExplodeEvent event) { } } } + + + @EventHandler + public void onChunkLoad(ChunkLoadEvent event) { + if(!configRepository.getDisableGatewayBeam()) { + return; + } + SpigotWorldContainer world = new SpigotWorldContainer(event.getWorld()); + BlockState[] tileEntities = event.getChunk().getTileEntities(); + for(BlockState block : tileEntities) { + if(block.getType() == Material.END_GATEWAY) { + var loc = block.getLocation(); + if(portalServices.inPortalRegion(new BlockLocation(loc.getWorld().getName(), + loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()), 2)) { + EndGateway tileState = (EndGateway) block; + tileState.setAge(Long.MIN_VALUE); + tileState.update(); + } + } + + } + } } diff --git a/spigot/src/main/java/com/sekwah/advancedportals/spigot/connector/container/SpigotWorldContainer.java b/spigot/src/main/java/com/sekwah/advancedportals/spigot/connector/container/SpigotWorldContainer.java index 6b5cd855..32272a3a 100644 --- a/spigot/src/main/java/com/sekwah/advancedportals/spigot/connector/container/SpigotWorldContainer.java +++ b/spigot/src/main/java/com/sekwah/advancedportals/spigot/connector/container/SpigotWorldContainer.java @@ -2,15 +2,29 @@ import com.sekwah.advancedportals.core.connector.containers.WorldContainer; import com.sekwah.advancedportals.core.data.BlockAxis; +import com.sekwah.advancedportals.core.portal.AdvancedPortal; import com.sekwah.advancedportals.core.serializeddata.BlockLocation; import org.bukkit.Axis; import org.bukkit.Material; import org.bukkit.World; +import org.bukkit.block.Block; +import org.bukkit.block.EndGateway; import org.bukkit.block.data.Orientable; public class SpigotWorldContainer implements WorldContainer { private final World world; + // Should only be false for 1.13 and 1.13.2, though just to avoid possible crashes + private static boolean endGatewaySetAgeExists; + + static { + try { + endGatewaySetAgeExists = EndGateway.class.getMethod("setAge", long.class) != null; + } catch (NoSuchMethodException e) { + endGatewaySetAgeExists = false; + } + } + public SpigotWorldContainer(World world) { this.world = world; } @@ -57,4 +71,36 @@ public void setBlockAxis(BlockLocation location, BlockAxis axis) { block.setBlockData(rotatable); } } + + @Override + public void disableBeacon(BlockLocation location) { + if(!endGatewaySetAgeExists) return; + var block = this.world.getBlockAt(location.getPosX(), location.getPosY(), + location.getPosZ()); + var blockType = block.getType(); + if(blockType == Material.END_GATEWAY && block.getState() instanceof EndGateway endGateway) { + endGateway.setAge(Long.MIN_VALUE); + endGateway.update(); + } + } + + @Override + public void disableBeacon(AdvancedPortal portal) { + if(!endGatewaySetAgeExists) return; + BlockLocation maxLoc = portal.getMaxLoc(); + BlockLocation minLoc = portal.getMinLoc(); + + for (int x = minLoc.getPosX(); x <= maxLoc.getPosX(); x++) { + for (int y = minLoc.getPosY(); y <= maxLoc.getPosY(); y++) { + for (int z = minLoc.getPosZ(); z <= maxLoc.getPosZ(); z++) { + Block block = world.getBlockAt(x, y, z); + if(block.getType() == Material.END_GATEWAY) { + EndGateway tileState = (EndGateway) block.getState(); + tileState.setAge(Long.MIN_VALUE); + tileState.update(); + } + } + } + } + } }