mirror of
https://github.com/sekwah41/Advanced-Portals.git
synced 2025-03-02 11:21:11 +01:00
feat: add disable beacon sub command
This commit is contained in:
parent
a2f6574224
commit
57e27a87a1
@ -173,6 +173,8 @@ public class AdvancedPortalsCore {
|
||||
new ShowPortalSubCommand());
|
||||
this.portalCommand.registerSubCommand("info",
|
||||
new InfoPortalSubCommand());
|
||||
this.portalCommand.registerSubCommand("disablebeacon",
|
||||
new DisableBeaconSubCommand());
|
||||
|
||||
commandRegister.registerCommand("portal", this.portalCommand);
|
||||
}
|
||||
|
@ -141,6 +141,7 @@ public class CoreListeners {
|
||||
return true;
|
||||
} else if (itemInHandName.equals("\u00A78Gateway Block Placer")) {
|
||||
world.setBlock(blockPos, "END_GATEWAY");
|
||||
world.disableBeacon(blockPos);
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
|
@ -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");
|
||||
}
|
||||
}
|
@ -199,15 +199,11 @@ public class ShowPortalSubCommand
|
||||
int maxY = Math.max(pos1.getPosY(), pos2.getPosY());
|
||||
int maxZ = Math.max(pos1.getPosZ(), pos2.getPosZ());
|
||||
|
||||
var size = pos1.getSize(pos2);
|
||||
|
||||
var world = player.getWorld();
|
||||
|
||||
int widthX = maxX - minX + 1;
|
||||
int widthY = maxY - minY + 1;
|
||||
int widthZ = maxZ - minZ + 1;
|
||||
|
||||
int totalBlocks = widthX * widthY * widthZ;
|
||||
|
||||
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++) {
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -49,4 +49,6 @@ public interface ConfigRepository {
|
||||
boolean getWarpEffectEnabled();
|
||||
|
||||
boolean getEnableProxySupport();
|
||||
|
||||
boolean getDisableGatewayBeam();
|
||||
}
|
||||
|
@ -105,6 +105,11 @@ public class ConfigRepositoryImpl implements ConfigRepository {
|
||||
return this.config.enableProxySupport;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getDisableGatewayBeam() {
|
||||
return this.config.disableGatewayBeam;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadConfig(DataStorage dataStorage) {
|
||||
this.dataStorage = dataStorage;
|
||||
|
@ -75,4 +75,20 @@ public class BlockLocation {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -39,4 +39,6 @@ public class Config {
|
||||
public boolean enableProxySupport = false;
|
||||
|
||||
public WarpEffectConfig warpEffect = new WarpEffectConfig();
|
||||
|
||||
public boolean disableGatewayBeam = true;
|
||||
}
|
||||
|
@ -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:
|
||||
|
||||
|
@ -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 {
|
||||
|
@ -5,7 +5,10 @@ import com.sekwah.advancedportals.core.CoreListeners;
|
||||
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.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,
|
||||
@ -143,4 +147,26 @@ public class Listeners implements Listener {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,15 +2,29 @@ package com.sekwah.advancedportals.spigot.connector.container;
|
||||
|
||||
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 class SpigotWorldContainer implements WorldContainer {
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user