Skip to content

Commit

Permalink
feat: see portal info with /portal info (name)
Browse files Browse the repository at this point in the history
  • Loading branch information
sekwah41 committed Nov 18, 2024
1 parent 0044008 commit e7b0d5e
Show file tree
Hide file tree
Showing 18 changed files with 120 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ private void registerPortalCommand(CommandRegister commandRegister) {
new ListPortalsSubCommand());
this.portalCommand.registerSubCommand("show",
new ShowPortalSubCommand());
this.portalCommand.registerSubCommand("info",
new InfoPortalSubCommand());

commandRegister.registerCommand("portal", this.portalCommand);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,19 +194,4 @@ protected void filterAndProcessTags(List<DataTag> dataTags) {
return o1.NAME.compareTo(o2.NAME);
});
}

protected void printTags(CommandSenderContainer sender,
List<DataTag> dataTags) {
for (DataTag tag : dataTags) {
if (tag.VALUES.length == 1) {
sender.sendMessage(" \u00A7a" + tag.NAME + "\u00A77:\u00A7e"
+ tag.VALUES[0]);
} else {
for (int i = 0; i < tag.VALUES.length; i++) {
sender.sendMessage(" \u00A7a" + tag.NAME + "\u00A77[" + i
+ "]:\u00A7e" + tag.VALUES[i]);
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public void onCommand(CommandSenderContainer sender, String[] args) {

if (!destinationTags.isEmpty()) {
this.filterAndProcessTags(destinationTags);
this.printTags(sender, destinationTags);
TagReader.printArgs(sender, destinationTags);
}
sender.sendMessage("");
Destination destination = destinationServices.createDesti(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public void onCommand(CommandSenderContainer sender, String[] args) {

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

Expand All @@ -93,7 +93,7 @@ public void onCommand(CommandSenderContainer sender, String[] args) {
sender.sendMessage(Lang.translate("messageprefix.positive")
+ Lang.translate("command.create.complete"));
sender.sendMessage(Lang.translate("command.create.tags"));
this.printTags(sender, portal.getArgs());
TagReader.printArgs(sender, portal.getArgs());
} else {
sender.sendMessage(Lang.translate("messageprefix.negative")
+ Lang.translate("command.create.error"));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
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 InfoPortalSubCommand 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.translate("messageprefix.negative")
+ Lang.translateInsertVariables("command.portal.info.notfound", portalName));
return;
}
sender.sendMessage(Lang.translate("messageprefix.positive")
+ Lang.translateInsertVariables("command.portal.info.complete", portalName));
TagReader.printArgs(sender, portal.getArgs());
} else {
sender.sendMessage(Lang.translate("command.portal.info.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.list.help");
}

@Override
public String getDetailedHelpText() {
return Lang.translate("command.portal.list.help");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.sekwah.advancedportals.core.connector.containers;

public enum GameMode {
SURVIVAL,
CREATIVE,
ADVENTURE,
SPECTATOR
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,6 @@ void sendFakeBlockWithData(BlockLocation blockPos, String material,
void playSound(String sound, float volume, float pitch);

ServerContainer getServer();

GameMode getGameMode();
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ public String inPortalRegionGetName(BlockLocation loc, int extraBlocks) {
return null;
}

public AdvancedPortal getPortal(String portalName) {
return portalCache.get(portalName);
}

public enum PortalActivationResult {
NOT_IN_PORTAL,
PORTAL_TELEPORTED,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.sekwah.advancedportals.core.util.Lang;
import com.sekwah.advancedportals.core.warphandler.ActivationData;
import com.sekwah.advancedportals.core.warphandler.Tag;

import javax.annotation.Nullable;

public class CommandTag implements Tag.Activation, Tag.Split, Tag.Creation {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
import com.sekwah.advancedportals.core.warphandler.ActivationData;
import com.sekwah.advancedportals.core.warphandler.Tag;

import java.util.Random;
import javax.annotation.Nullable;
import java.util.Random;

public class CooldownTag implements Tag.Activation, Tag.Creation {
@Inject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
import com.sekwah.advancedportals.core.util.Lang;
import com.sekwah.advancedportals.core.warphandler.ActivationData;
import com.sekwah.advancedportals.core.warphandler.Tag;
import java.util.List;

import javax.annotation.Nullable;
import java.util.List;

public class DestiTag implements Tag.Activation, Tag.AutoComplete, Tag.Split {
public static String TAG_NAME = "destination";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
import com.sekwah.advancedportals.core.registry.TagTarget;
import com.sekwah.advancedportals.core.util.Lang;
import com.sekwah.advancedportals.core.warphandler.Tag;
import java.util.List;

import javax.annotation.Nullable;
import java.util.List;

/**
* The name of the destination or portal.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.sekwah.advancedportals.core.util.Lang;
import com.sekwah.advancedportals.core.warphandler.ActivationData;
import com.sekwah.advancedportals.core.warphandler.Tag;

import javax.annotation.Nullable;
import javax.inject.Inject;

Expand All @@ -25,7 +26,7 @@ public class PermissionTag implements Tag.Activation {

private final String[] aliases = new String[] {"perm"};

private final TagType[] tagTypes = new TagType[] {TagType.PORTAL};
private final TagType[] tagTypes = new TagType[] {TagType.PORTAL, TagType.DESTINATION};

@Override
public TagType[] getTagTypes() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.sekwah.advancedportals.core.tags;

import com.sekwah.advancedportals.core.connector.containers.GameMode;
import com.sekwah.advancedportals.core.connector.containers.PlayerContainer;
import com.sekwah.advancedportals.core.registry.TagTarget;
import com.sekwah.advancedportals.core.repository.ConfigRepository;
Expand Down Expand Up @@ -55,6 +56,9 @@ public String description() {
@Override
public boolean preActivated(TagTarget target, PlayerContainer player,
ActivationData activeData, String[] argData) {
if(player.getGameMode() == GameMode.CREATIVE) {
return true;
}
return !Objects.equals(argData[0], "true") || activeData.getTriggerType() == TriggerType.PORTAL;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
import com.sekwah.advancedportals.core.connector.containers.ServerContainer;
import com.sekwah.advancedportals.core.util.Lang;
import com.sekwah.advancedportals.core.warphandler.Tag;
import java.util.List;

import javax.annotation.Nullable;
import java.util.List;

public class TriggerBlockTag implements Tag.AutoComplete, Tag.Split {
@Inject
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.sekwah.advancedportals.core.util;

import com.sekwah.advancedportals.core.connector.containers.CommandSenderContainer;
import com.sekwah.advancedportals.core.serializeddata.DataTag;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

public class TagReader {
public static boolean isClosedString(String[] args) {
Expand Down Expand Up @@ -94,4 +96,21 @@ public static String getTag(String arg) {
}
return null;
}



public static void printArgs(CommandSenderContainer sender,
List<DataTag> dataTags) {
for (DataTag tag : dataTags) {
if (tag.VALUES.length == 1) {
sender.sendMessage(" \u00A7a" + tag.NAME + "\u00A77:\u00A7e"
+ tag.VALUES[0]);
} else {
for (int i = 0; i < tag.VALUES.length; i++) {
sender.sendMessage(" \u00A7a" + tag.NAME + "\u00A77[" + i
+ "]:\u00A7e" + tag.VALUES[i]);
}
}
}
}
}
4 changes: 4 additions & 0 deletions lang/src/main/resources/lang/en_GB.lang
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ value needs spaces use the format tag:"value with spaces"
command.createdesti.complete= The destination has been successfully
created.

command.portal.info.complete= Portal information for &e%1$s&a:
command.portal.info.notfound= No portal by the name &e%1$s &cwas found.


command.create.tags=&aTags&7:

command.playeronly= Sorry but that command can only be run by a player.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.google.inject.Inject;
import com.sekwah.advancedportals.core.AdvancedPortalsCore;
import com.sekwah.advancedportals.core.connector.containers.GameMode;
import com.sekwah.advancedportals.core.connector.containers.PlayerContainer;
import com.sekwah.advancedportals.core.connector.containers.ServerContainer;
import com.sekwah.advancedportals.core.serializeddata.BlockLocation;
Expand Down Expand Up @@ -105,6 +106,15 @@ public boolean sendPacket(String channel, byte[] bytes) {
return true;
}

@Override
public GameMode getGameMode() {
try {
return GameMode.valueOf(this.player.getGameMode().name());
} catch (IllegalArgumentException e) {
return GameMode.SURVIVAL;
}
}

public Player getPlayer() {
return this.player;
}
Expand Down

0 comments on commit e7b0d5e

Please sign in to comment.