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 738f638
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 2 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
@@ -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
@@ -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);
}
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 @@ -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 738f638

Please sign in to comment.