Skip to content

Commit

Permalink
feat: add disable beacon sub command
Browse files Browse the repository at this point in the history
  • Loading branch information
sekwah41 committed Nov 13, 2024
1 parent 56eda7d commit aa89601
Show file tree
Hide file tree
Showing 13 changed files with 171 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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<String> 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");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
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 {
void setBlock(BlockLocation location, String material);

String getBlock(BlockLocation location);

void disableBeacon(BlockLocation location);

BlockAxis getBlockAxis(BlockLocation location);

void setBlockAxis(BlockLocation location, BlockAxis axis);

void disableBeacon(AdvancedPortal portal);
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,6 @@ public interface ConfigRepository {
boolean getWarpEffectEnabled();

boolean getEnableProxySupport();

boolean getDisableGatewayBeam();
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,6 @@ public class Config {
public boolean enableProxySupport = false;

public WarpEffectConfig warpEffect = new WarpEffectConfig();

public boolean disableGatewayBeam = true;
}
5 changes: 5 additions & 0 deletions lang/src/main/resources/lang/en_GB.lang
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,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:

Expand Down
4 changes: 2 additions & 2 deletions spigot/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,22 @@
import com.sekwah.advancedportals.core.services.PortalServices;
import com.sekwah.advancedportals.spigot.connector.container.SpigotEntityContainer;
import com.sekwah.advancedportals.spigot.connector.container.SpigotPlayerContainer;
import com.sekwah.advancedportals.spigot.connector.container.SpigotWorldContainer;
import com.sekwah.advancedportals.spigot.utils.ContainerHelpers;
import java.util.List;
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;
import org.bukkit.event.Listener;
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,
Expand Down Expand Up @@ -203,4 +208,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();
}
}

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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();
}
}
}
}
}
}

0 comments on commit aa89601

Please sign in to comment.