Skip to content

Commit

Permalink
feat: adding debug command
Browse files Browse the repository at this point in the history
  • Loading branch information
sekwah41 committed Nov 18, 2024
1 parent a658e7d commit f002c8e
Show file tree
Hide file tree
Showing 22 changed files with 492 additions and 42 deletions.
2 changes: 2 additions & 0 deletions core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ dependencies {
includeLibs group: 'com.google.inject', name: 'guice', version:'5.0.1'
implementation group: 'com.google.inject', name: 'guice', version:'5.0.1'
implementation group: 'com.google.guava', name: 'guava', version: '30.1.1-jre'
implementation group: 'io.netty', name: 'netty-buffer', version: '4.1.53.Final'
implementation group: 'io.netty', name: 'netty-codec', version: '4.1.53.Final'
}

jar {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.google.inject.Injector;
import com.sekwah.advancedportals.core.commands.CommandWithSubCommands;
import com.sekwah.advancedportals.core.commands.subcommands.desti.CreateDestiSubCommand;
import com.sekwah.advancedportals.core.commands.subcommands.desti.ListDestiSubCommand;
import com.sekwah.advancedportals.core.commands.subcommands.desti.RemoveDestiSubCommand;
import com.sekwah.advancedportals.core.commands.subcommands.portal.*;
import com.sekwah.advancedportals.core.connector.commands.CommandRegister;
Expand Down Expand Up @@ -99,7 +100,8 @@ private void registerPortalCommand(CommandRegister commandRegister) {
this.portalCommand.registerSubCommand("endgatewayblock", new EndGatewayBlockSubCommand());
this.portalCommand.registerSubCommand("create", new CreatePortalSubCommand());
this.portalCommand.registerSubCommand("remove", new RemovePortalSubCommand());
this.portalCommand.registerSubCommand("list", new ListSubCommand());
this.portalCommand.registerSubCommand("list", new ListPortalsSubCommand());
this.portalCommand.registerSubCommand("debug", new DebugPortalsSubCommand());

commandRegister.registerCommand("portal", this.portalCommand);
}
Expand All @@ -108,6 +110,7 @@ private void registerDestinationCommand(CommandRegister commandRegister) {
this.destiCommand = new CommandWithSubCommands(this);
this.destiCommand.registerSubCommand("create", new CreateDestiSubCommand());
this.destiCommand.registerSubCommand("remove", new RemoveDestiSubCommand());
this.destiCommand.registerSubCommand("list", new ListDestiSubCommand());

commandRegister.registerCommand("destination", this.destiCommand);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public void onCommand(CommandSenderContainer sender, String commandExecuted, Str
if(this.subCommandRegistry.isArgRegistered(subCommand)) {
sender.sendMessage("");
var helpTitle = Lang.centeredTitle(Lang.translateInsertVariables("command.help.subcommandheader",
command, helpPage, pages));
command, subCommand));
sender.sendMessage(helpTitle);
sender.sendMessage("\u00A77" + this.getSubCommand(subCommand).getDetailedHelpText());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public void onCommand(CommandSenderContainer sender, String[] args) {
if(args.length > 1) {
PlayerContainer player = sender.getPlayerContainer();
if(player == null) {
sender.sendMessage(Lang.translate("messageprefix.negative") + Lang.translate("command.createdesti.console"));
sender.sendMessage(Lang.translate("messageprefix.negative") + Lang.translate("command.create.destination.console"));
return;
}
ArrayList<DataTag> destinationTags = TagReader.getTagsFromArgs(args);
Expand All @@ -48,7 +48,7 @@ public void onCommand(CommandSenderContainer sender, String[] args) {
sender.sendMessage(Lang.translate("messageprefix.negative") + Lang.translate("command.error.noname"));
return;
}
sender.sendMessage(Lang.centeredTitle(Lang.translate("command.createdesti.prep")));
sender.sendMessage(Lang.centeredTitle(Lang.translate("command.create.destination.prep")));
sender.sendMessage("");
sender.sendMessage(Lang.translate("command.create.tags"));

Expand All @@ -59,11 +59,11 @@ public void onCommand(CommandSenderContainer sender, String[] args) {
sender.sendMessage("");
Destination destination = destinationServices.createDesti(player, player.getLoc(), destinationTags);
if(destination != null) {
sender.sendMessage(Lang.translate("messageprefix.positive") + Lang.translate("command.createdesti.complete"));
sender.sendMessage(Lang.translate("messageprefix.positive") + Lang.translate("command.create.destination.complete"));
}
else {
sender.sendMessage("");
sender.sendMessage(Lang.translate("messageprefix.negative") + Lang.translate("command.createdesti.error"));
sender.sendMessage(Lang.translate("messageprefix.negative") + Lang.translate("command.create.destination.error"));
}
}
else {
Expand All @@ -85,11 +85,11 @@ protected List<Tag> getRelatedTags() {

@Override
public String getBasicHelpText() {
return Lang.translate("command.createdesti.help");
return Lang.translate("command.create.destination.help");
}

@Override
public String getDetailedHelpText() {
return Lang.translate("command.createdesti.detailedhelp");
return Lang.translate("command.create.destination.detailedhelp");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.sekwah.advancedportals.core.commands.subcommands.desti;

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.DestinationServices;
import com.sekwah.advancedportals.core.services.PortalServices;
import com.sekwah.advancedportals.core.util.Lang;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class ListDestiSubCommand implements SubCommand {

@Inject
DestinationServices portalServices;

@Override
public void onCommand(CommandSenderContainer sender, String[] args) {
sender.sendMessage(Lang.translate("messageprefix.positive") + Lang.translate("command.destination.list")
+ " " + portalServices.getDestinations().stream().sorted().collect(Collectors.joining(", ")));
}

@Override
public boolean hasPermission(CommandSenderContainer sender) {
return true;
}

@Override
public List<String> onTabComplete(CommandSenderContainer sender, String[] args) {
return null;
}

@Override
public String getBasicHelpText() {
return Lang.translate("command.destination.list.help");
}

@Override
public String getDetailedHelpText() {
return Lang.translate("command.destination.list.help");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.sekwah.advancedportals.core.commands.subcommands.reusable.CreateTaggedSubCommand;
import com.sekwah.advancedportals.core.connector.containers.CommandSenderContainer;
import com.sekwah.advancedportals.core.connector.containers.PlayerContainer;
import com.sekwah.advancedportals.core.destination.Destination;
import com.sekwah.advancedportals.core.registry.TagRegistry;
import com.sekwah.advancedportals.core.serializeddata.DataTag;
import com.sekwah.advancedportals.core.permissions.PortalPermissions;
Expand Down Expand Up @@ -40,7 +41,28 @@ public void onCommand(CommandSenderContainer sender, String[] args) {
// Find the tag with the "name" NAME
DataTag nameTag = portalTags.stream().findFirst().filter(tag -> tag.NAME.equals("name")).orElse(null);

AdvancedPortal portal = portalServices.createPortal(nameTag == null ? null : nameTag.VALUES[0], player, portalTags);
// If the tag is null, check if arg[1] has a : to check it's not a tag.
if(nameTag == null && !args[1].contains(":")) {
nameTag = new DataTag("name", args[1]);
portalTags.add(nameTag);
}

if (nameTag == null) {
sender.sendMessage(Lang.translate("messageprefix.negative") + Lang.translate("command.error.noname"));
return;
}

sender.sendMessage(Lang.centeredTitle(Lang.translate("command.create.portal.prep")));
sender.sendMessage("");
sender.sendMessage(Lang.translate("command.create.tags"));

if(!portalTags.isEmpty()) {
this.filterAndProcessTags(portalTags);
this.printTags(sender, portalTags);
}
sender.sendMessage("");

AdvancedPortal portal = portalServices.createPortal(player, portalTags);
if(portal != null) {
sender.sendMessage(Lang.translate("messageprefix.positive") + Lang.translate("command.create.complete"));
sender.sendMessage(Lang.translate("command.create.tags"));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
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.connector.containers.PlayerContainer;
import com.sekwah.advancedportals.core.serializeddata.BlockLocation;
import com.sekwah.advancedportals.core.serializeddata.PlayerTempData;
import com.sekwah.advancedportals.core.services.PortalTempDataServices;
import com.sekwah.advancedportals.core.util.Debug;
import com.sekwah.advancedportals.core.util.FriendlyDataOutput;
import com.sekwah.advancedportals.core.util.Lang;

import java.awt.*;
import java.util.List;

public class DebugPortalsSubCommand implements SubCommand {

@Inject
PortalTempDataServices tempDataServices;

@Override
public void onCommand(CommandSenderContainer sender, String[] args) {
sender.sendMessage("Debug");
if(sender.getPlayerContainer() != null) {
PlayerContainer playerContainer = sender.getPlayerContainer();
PlayerTempData tempData = tempDataServices.getPlayerTempData(playerContainer);
if(tempData.getPos1() != null) {
Debug.addMarker(sender.getPlayerContainer(), tempData.getPos1(), "Pos1", new Color(0, 255, 0), 1000 * 10);
}
if(tempData.getPos2() != null) {
Debug.addMarker(sender.getPlayerContainer(), tempData.getPos2(), "Pos2", new Color(255, 0, 0), 1000 * 10);
}

if (tempData.getPos1() != null && tempData.getPos2() != null) {
int minX = Math.min(tempData.getPos1().posX, tempData.getPos2().posX);
int minY = Math.min(tempData.getPos1().posY, tempData.getPos2().posY);
int minZ = Math.min(tempData.getPos1().posZ, tempData.getPos2().posZ);

int maxX = Math.max(tempData.getPos1().posX, tempData.getPos2().posX);
int maxY = Math.max(tempData.getPos1().posY, tempData.getPos2().posY);
int maxZ = Math.max(tempData.getPos1().posZ, tempData.getPos2().posZ);

for (int x = minX; x <= maxX; x++) {
for (int y = minY; y <= maxY; y++) {
for (int z = minZ; z <= maxZ; z++) {
if ((x == minX || x == maxX) && (y == minY || y == maxY || z == minZ || z == maxZ) ||
(y == minY || y == maxY) && (x == minX || x == maxX || z == minZ || z == maxZ) ||
(z == minZ || z == maxZ) && (x == minX || x == maxX || y == minY || y == maxY)) {

var pos = new BlockLocation(tempData.getPos1().worldName, x, y, z);
if (pos.equals(tempData.getPos1()) || pos.equals(tempData.getPos2()))
continue;
Debug.addMarker(sender.getPlayerContainer(), pos, "", new Color(255, 0, 0, 100), 1000 * 10);
}
}
}
}
}
/*int minX = Math.min(tempData.getPos1().posX, tempData.getPos2().posX);
int minY = Math.min(tempData.getPos1().posY, tempData.getPos2().posY);
int minZ = Math.min(tempData.getPos1().posZ, tempData.getPos2().posZ);
int maxX = Math.max(tempData.getPos1().posX, tempData.getPos2().posX);
int maxY = Math.max(tempData.getPos1().posY, tempData.getPos2().posY);
int maxZ = Math.max(tempData.getPos1().posZ, tempData.getPos2().posZ);
FriendlyDataOutput out = new FriendlyDataOutput();
out.writeUtf("minecraft:overworld");
// Bounding Box
out.writeInt(minX);
out.writeInt(minY);
out.writeInt(minZ);
out.writeInt(maxX);
out.writeInt(maxY);
out.writeInt(maxZ);
// Count
out.writeInt(0);
playerContainer.sendPacket("minecraft:debug/structures", out.toByteArray());*/
}
}

@Override
public boolean hasPermission(CommandSenderContainer sender) {
return true;
}

@Override
public List<String> onTabComplete(CommandSenderContainer sender, String[] args) {
return null;
}

@Override
public String getBasicHelpText() {
return Lang.translate("command.portal.list.debug");
}

@Override
public String getDetailedHelpText() {
return Lang.translate("command.portal.list.debug");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
import java.util.Map;
import java.util.stream.Collectors;

public class ListSubCommand implements SubCommand {
public class ListPortalsSubCommand implements SubCommand {

@Inject
PortalServices portalServices;

@Override
public void onCommand(CommandSenderContainer sender, String[] args) {
sender.sendMessage(Lang.translate("messageprefix.positive") + Lang.translate("command.list")
sender.sendMessage(Lang.translate("messageprefix.positive") + Lang.translate("command.portal.list")
+ " " + portalServices.getPortals().asList().stream().map(Map.Entry::getKey).sorted().collect(Collectors.joining(", ")));
}

Expand All @@ -33,11 +33,11 @@ public List<String> onTabComplete(CommandSenderContainer sender, String[] args)

@Override
public String getBasicHelpText() {
return Lang.translate("command.list.help");
return Lang.translate("command.portal.list.help");
}

@Override
public String getDetailedHelpText() {
return Lang.translate("command.list.help");
return Lang.translate("command.portal.list.help");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public interface PlayerContainer {

PlayerLocation getLoc();

BlockLocation getBlockLoc();

double getEyeHeight();

void teleport(PlayerLocation location);
Expand All @@ -41,4 +43,6 @@ public interface PlayerContainer {
void sendFakeBlockWithData(BlockLocation blockPos, String material, byte data);

void giveItem(String material, String itemName, String... itemDescription);

boolean sendPacket(String channel, byte[] bytes);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import com.google.inject.Inject;
import com.sekwah.advancedportals.core.connector.containers.PlayerContainer;
import com.sekwah.advancedportals.core.registry.TagTarget;
import com.sekwah.advancedportals.core.serializeddata.BlockLocation;
import com.sekwah.advancedportals.core.serializeddata.DataTag;
import com.sekwah.advancedportals.core.serializeddata.WorldLocation;
import com.sekwah.advancedportals.core.registry.TagRegistry;
import com.sekwah.advancedportals.core.warphandler.ActivationData;
import com.sekwah.advancedportals.core.warphandler.Tag;
Expand All @@ -23,27 +23,27 @@ public class AdvancedPortal implements TagTarget {
transient TagRegistry tagRegistry;

@SerializedName("max")
private WorldLocation maxLoc;
private BlockLocation maxLoc;

@SerializedName("min")
private WorldLocation minLoc;
private BlockLocation minLoc;

@SerializedName("t")
private String[] triggerBlocks = {"PORTAL"};

@SerializedName("a")
private HashMap<String, String[]> args = new HashMap<>();

public AdvancedPortal(WorldLocation maxLoc, WorldLocation minLoc) {
public AdvancedPortal(BlockLocation maxLoc, BlockLocation minLoc) {
this.maxLoc = maxLoc;
this.minLoc = minLoc;
}

public WorldLocation getMaxLoc() {
public BlockLocation getMaxLoc() {
return this.maxLoc;
}

public WorldLocation getMinLoc() {
public BlockLocation getMinLoc() {
return this.minLoc;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.sekwah.advancedportals.core.registry;

import com.google.inject.Inject;
import com.google.inject.Singleton;
import com.sekwah.advancedportals.core.AdvancedPortalsCore;
import com.sekwah.advancedportals.core.warphandler.Tag;

Expand All @@ -25,6 +26,9 @@ public class TagRegistry {
private final Map<String, Tag.Creation> creationTags = new HashMap<>();
private final Map<String, Tag.TagStatus> statusTags = new HashMap<>();

@Inject
private AdvancedPortalsCore pluginCore;

/**
* Portals to trigger when a portal is activated
*
Expand Down Expand Up @@ -58,6 +62,7 @@ public Tag.TagStatus getTagStatusHandler(String arg) {
* @return if the tag has been registered or if it already exists.
*/
public boolean registerTag(Tag tag) {
pluginCore.getModule().getInjector().injectMembers(tag);

String tagName = tag.getName();

Expand Down
Loading

0 comments on commit f002c8e

Please sign in to comment.