Skip to content

Commit

Permalink
feat: add show desti command
Browse files Browse the repository at this point in the history
  • Loading branch information
sekwah41 committed Nov 18, 2024
1 parent 0085733 commit 6629151
Show file tree
Hide file tree
Showing 30 changed files with 489 additions and 140 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,42 @@
import com.google.inject.Inject;
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.desti.*;
import com.sekwah.advancedportals.core.commands.subcommands.portal.*;
import com.sekwah.advancedportals.core.connector.commands.CommandRegister;
import com.sekwah.advancedportals.core.connector.containers.ServerContainer;
import com.sekwah.advancedportals.core.registry.TagRegistry;
import com.sekwah.advancedportals.core.serializeddata.DataStorage;
import com.sekwah.advancedportals.core.module.AdvancedPortalsModule;
import com.sekwah.advancedportals.core.repository.ConfigRepository;
import com.sekwah.advancedportals.core.services.DestinationServices;
import com.sekwah.advancedportals.core.tags.activation.DestiTag;
import com.sekwah.advancedportals.core.tags.activation.NameTag;
import com.sekwah.advancedportals.core.util.GameScheduler;
import com.sekwah.advancedportals.core.util.InfoLogger;
import com.sekwah.advancedportals.core.util.Lang;

import java.io.File;
import java.util.Arrays;

public class AdvancedPortalsCore {


public static final String version = "1.0.0";

public static final String lastTranslationUpdate = "1.0.0";

private final InfoLogger infoLogger;
private final DataStorage dataStorage;

private final AdvancedPortalsModule module;

/**
* Use this to enable or alter certain features for different versions.
* If there is an issue parsing it for any reason it will be set to 0.0.0
*/
private final int[] mcVersion;

private final ServerContainer serverContainer;

@Inject
private CommandRegister commandRegister;

Expand All @@ -44,18 +51,32 @@ public class AdvancedPortalsCore {
@Inject
private TagRegistry tagRegistry;

@Inject
private DestinationServices destinationServices;

@Inject
private GameScheduler gameScheduler;

public AdvancedPortalsCore(File dataStorageLoc, InfoLogger infoLogger) {
public AdvancedPortalsCore(String mcVersion, File dataStorageLoc, InfoLogger infoLogger, ServerContainer serverContainer) {
this.serverContainer = serverContainer;
this.dataStorage = new DataStorage(dataStorageLoc);
this.infoLogger = infoLogger;
this.module = new AdvancedPortalsModule(this);

// Provide any items that need to be provided.
//this.module.addInstanceBinding(DataCollector.class, this.infoLogger);
int[] mcVersionTemp;
infoLogger.log("Loading Advanced Portals Core v" + version + " for MC: " + mcVersion);
try {
mcVersionTemp = Arrays.stream(mcVersion.split("\\.")).mapToInt(Integer::parseInt).toArray();
} catch (NumberFormatException e) {
infoLogger.log("Failed to parse MC version: " + mcVersion);
e.printStackTrace();
mcVersionTemp = new int[]{0, 0, 0};
}
if(mcVersionTemp.length == 2) {
mcVersionTemp = new int[]{mcVersionTemp[0], mcVersionTemp[1], 0};
}
this.mcVersion = mcVersionTemp;

// Don't do much crazy setup here, keep it to onEnable as that will be once the implementation is set up.
this.module = new AdvancedPortalsModule(this);
}

/**
Expand All @@ -76,6 +97,7 @@ public void onEnable() {
this.registerCommands();
this.registerTags();

this.destinationServices.loadDestinations();
this.infoLogger.log(Lang.translate("logger.pluginenable"));
}

Expand All @@ -97,7 +119,7 @@ private void registerPortalCommand(CommandRegister commandRegister) {

this.portalCommand.registerSubCommand("version", new VersionSubCommand());
this.portalCommand.registerSubCommand("langupdate", new LangUpdateSubCommand());
this.portalCommand.registerSubCommand("reload", new ReloadSubCommand());
this.portalCommand.registerSubCommand("reload", new ReloadPortalSubCommand());
this.portalCommand.registerSubCommand("selector", new SelectorSubCommand(), "wand");
this.portalCommand.registerSubCommand("portalblock", new PortalBlockSubCommand());
this.portalCommand.registerSubCommand("endportalblock", new EndPortalBlockSubCommand());
Expand All @@ -115,6 +137,8 @@ private void registerDestinationCommand(CommandRegister commandRegister) {
this.destiCommand.registerSubCommand("create", new CreateDestiSubCommand());
this.destiCommand.registerSubCommand("remove", new RemoveDestiSubCommand());
this.destiCommand.registerSubCommand("list", new ListDestiSubCommand());
this.destiCommand.registerSubCommand("show", new ShowDestiSubCommand());
this.destiCommand.registerSubCommand("reload", new ReloadDestiSubCommand());

commandRegister.registerCommand("destination", this.destiCommand);
}
Expand Down Expand Up @@ -151,4 +175,12 @@ public TagRegistry getTagRegistry() {
public GameScheduler getGameScheduler() {
return gameScheduler;
}

public int[] getMcVersion() {
return mcVersion;
}

public ServerContainer getServerContainer() {
return serverContainer;
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
package com.sekwah.advancedportals.core.commands.subcommands.reusable;
package com.sekwah.advancedportals.core.commands.subcommands.common;

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.permissions.PortalPermissions;
import com.sekwah.advancedportals.core.portal.AdvancedPortal;
import com.sekwah.advancedportals.core.registry.TagRegistry;
import com.sekwah.advancedportals.core.serializeddata.DataTag;
import com.sekwah.advancedportals.core.services.PortalServices;
import com.sekwah.advancedportals.core.util.InfoLogger;
import com.sekwah.advancedportals.core.util.Lang;
import com.sekwah.advancedportals.core.util.TagReader;
import com.sekwah.advancedportals.core.warphandler.Tag;

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

import com.google.inject.Inject;
import com.sekwah.advancedportals.core.commands.subcommands.reusable.CreateTaggedSubCommand;
import com.sekwah.advancedportals.core.commands.subcommands.common.CreateTaggedSubCommand;
import com.sekwah.advancedportals.core.connector.containers.CommandSenderContainer;
import com.sekwah.advancedportals.core.connector.containers.PlayerContainer;
import com.sekwah.advancedportals.core.destination.Destination;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@
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 {
Expand All @@ -19,7 +17,7 @@ public class ListDestiSubCommand implements SubCommand {
@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(", ")));
+ " " + portalServices.getDestinationNames().stream().sorted().collect(Collectors.joining(", ")));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.sekwah.advancedportals.core.commands.subcommands.desti;

import com.google.inject.Inject;
import com.sekwah.advancedportals.core.AdvancedPortalsCore;
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.connector.containers.ServerContainer;
import com.sekwah.advancedportals.core.services.DestinationServices;
import com.sekwah.advancedportals.core.services.PortalTempDataServices;
import com.sekwah.advancedportals.core.util.GameScheduler;
import com.sekwah.advancedportals.core.util.Lang;

import java.util.List;

/**
* This will be different from the old show command and I believe it is 1.16+ till the latest version as of writing this.
*/
public class ReloadDestiSubCommand implements SubCommand {

@Inject
DestinationServices destinationServices;

@Override
public void onCommand(CommandSenderContainer sender, String[] args) {
sender.sendMessage(Lang.translate("messageprefix.positive") + Lang.translate("command.destination.reload"));
}

@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.reload.help");
}

@Override
public String getDetailedHelpText() {
return Lang.translate("command.destination.reload.detailedhelp");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,12 @@
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.destination.Destination;
import com.sekwah.advancedportals.core.permissions.PortalPermissions;
import com.sekwah.advancedportals.core.portal.AdvancedPortal;
import com.sekwah.advancedportals.core.services.DestinationServices;
import com.sekwah.advancedportals.core.util.Lang;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

public class RemoveDestiSubCommand implements SubCommand {

Expand All @@ -23,7 +19,7 @@ public class RemoveDestiSubCommand implements SubCommand {
@Override
public void onCommand(CommandSenderContainer sender, String[] args) {
if(args.length > 1) {
if(destinationServices.removeDesti(args[1], sender.getPlayerContainer())) {
if(destinationServices.removeDestination(args[1], sender.getPlayerContainer())) {
sender.sendMessage(Lang.translate("messageprefix.positive") + Lang.translate("command.portal.remove.complete"));
}
else {
Expand All @@ -46,7 +42,7 @@ public List<String> onTabComplete(CommandSenderContainer sender, String[] args)
if(args.length > 2) {
return Collections.emptyList();
}
List<String> destiNames = destinationServices.getDestinations();
List<String> destiNames = destinationServices.getDestinationNames();
Collections.sort(destiNames);
return destiNames;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
package com.sekwah.advancedportals.core.commands.subcommands.desti;

import com.google.inject.Inject;
import com.sekwah.advancedportals.core.AdvancedPortalsCore;
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.connector.containers.ServerContainer;
import com.sekwah.advancedportals.core.destination.Destination;
import com.sekwah.advancedportals.core.repository.ConfigRepository;
import com.sekwah.advancedportals.core.services.DestinationServices;
import com.sekwah.advancedportals.core.services.PortalTempDataServices;
import com.sekwah.advancedportals.core.tags.activation.NameTag;
import com.sekwah.advancedportals.core.util.Debug;
import com.sekwah.advancedportals.core.util.GameScheduler;
import com.sekwah.advancedportals.core.util.Lang;

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

/**
* This will be different from the old show command and I believe it is 1.16+ till the latest version as of writing this.
*/
public class ShowDestiSubCommand implements SubCommand, SubCommand.SubCommandOnInit {

@Inject
PortalTempDataServices tempDataServices;

@Inject
GameScheduler gameScheduler;

@Inject
AdvancedPortalsCore core;

@Inject
DestinationServices destinationServices;

@Inject
ServerContainer serverContainer;

@Inject
ConfigRepository config;

@Override
public void onCommand(CommandSenderContainer sender, String[] args) {
if(core.getMcVersion()[1] < 16) {
sender.sendMessage(Lang.translate("messageprefix.negative") + Lang.translate("command.portal.show.unsupported"));
return;
}

var tempData = tempDataServices.getPlayerTempData(sender.getPlayerContainer());
if(tempData.isDestiVisible()) {
sender.sendMessage(Lang.translate("messageprefix.negative") + Lang.translate("command.destination.show.disabled"));
} else {
sender.sendMessage(Lang.translate("messageprefix.positive") + Lang.translate("command.destination.show.enabled"));
}
tempData.setDestiVisible(!tempData.isDestiVisible());
}

@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.show.help");
}

@Override
public String getDetailedHelpText() {
return Lang.translate("command.destination.show.detailedhelp");
}

@Override
public void registered() {
gameScheduler.intervalTickEvent("show_portal", () -> {
for(PlayerContainer player : serverContainer.getPlayers()) {
var tempData = tempDataServices.getPlayerTempData(player);
if(!tempData.isDestiVisible()) {
return;
}

for (Destination destination : destinationServices.getDestinations()) {
var pos = destination.getLoc();
if(pos.distanceTo(player.getLoc()) < config.getVisibleRange()) {
Debug.addMarker(player, pos.toBlockPos(), destination.getArgValues("name")[0], new Color(100, 100, 100, 100), 1000);
}
}
//Debug.addMarker(player, pos, "", new Color(255, 0, 0, 100), 1000 * 10);

}
}, 1, 20);
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
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.commands.subcommands.reusable.CreateTaggedSubCommand;
import com.sekwah.advancedportals.core.commands.subcommands.common.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;
import com.sekwah.advancedportals.core.portal.AdvancedPortal;
import com.sekwah.advancedportals.core.services.PortalServices;
import com.sekwah.advancedportals.core.util.InfoLogger;
import com.sekwah.advancedportals.core.util.Lang;
import com.sekwah.advancedportals.core.util.TagReader;
import com.sekwah.advancedportals.core.warphandler.Tag;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import java.util.List;

public class ReloadSubCommand implements SubCommand {
public class ReloadPortalSubCommand implements SubCommand {

@Inject
private AdvancedPortalsCore portalsCore;
Expand Down
Loading

0 comments on commit 6629151

Please sign in to comment.