mirror of
https://github.com/sekwah41/Advanced-Portals.git
synced 2024-11-29 05:55:19 +01:00
feat: add show desti command
This commit is contained in:
parent
008573305e
commit
6629151fc6
@ -3,15 +3,15 @@ package com.sekwah.advancedportals.core;
|
||||
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;
|
||||
@ -19,19 +19,26 @@ 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;
|
||||
|
||||
@ -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;
|
||||
|
||||
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;
|
||||
|
||||
this.module = new AdvancedPortalsModule(this);
|
||||
|
||||
// Provide any items that need to be provided.
|
||||
//this.module.addInstanceBinding(DataCollector.class, this.infoLogger);
|
||||
|
||||
// Don't do much crazy setup here, keep it to onEnable as that will be once the implementation is set up.
|
||||
}
|
||||
|
||||
/**
|
||||
@ -76,6 +97,7 @@ public class AdvancedPortalsCore {
|
||||
this.registerCommands();
|
||||
this.registerTags();
|
||||
|
||||
this.destinationServices.loadDestinations();
|
||||
this.infoLogger.log(Lang.translate("logger.pluginenable"));
|
||||
}
|
||||
|
||||
@ -97,7 +119,7 @@ public class AdvancedPortalsCore {
|
||||
|
||||
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());
|
||||
@ -115,6 +137,8 @@ public class AdvancedPortalsCore {
|
||||
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);
|
||||
}
|
||||
@ -151,4 +175,12 @@ public class AdvancedPortalsCore {
|
||||
public GameScheduler getGameScheduler() {
|
||||
return gameScheduler;
|
||||
}
|
||||
|
||||
public int[] getMcVersion() {
|
||||
return mcVersion;
|
||||
}
|
||||
|
||||
public ServerContainer getServerContainer() {
|
||||
return serverContainer;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -4,11 +4,9 @@ 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 {
|
||||
@ -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
|
||||
|
@ -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");
|
||||
}
|
||||
}
|
@ -3,16 +3,12 @@ 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.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 {
|
||||
|
||||
@ -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 {
|
||||
@ -46,7 +42,7 @@ public class RemoveDestiSubCommand implements SubCommand {
|
||||
if(args.length > 2) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
List<String> destiNames = destinationServices.getDestinations();
|
||||
List<String> destiNames = destinationServices.getDestinationNames();
|
||||
Collections.sort(destiNames);
|
||||
return destiNames;
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
@ -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;
|
||||
|
@ -12,7 +12,7 @@ import com.sekwah.advancedportals.core.util.Lang;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ReloadSubCommand implements SubCommand {
|
||||
public class ReloadPortalSubCommand implements SubCommand {
|
||||
|
||||
@Inject
|
||||
private AdvancedPortalsCore portalsCore;
|
@ -1,17 +1,15 @@
|
||||
package com.sekwah.advancedportals.core.commands.subcommands.portal;
|
||||
|
||||
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.serializeddata.BlockLocation;
|
||||
import com.sekwah.advancedportals.core.serializeddata.PlayerTempData;
|
||||
import com.sekwah.advancedportals.core.connector.containers.ServerContainer;
|
||||
import com.sekwah.advancedportals.core.services.PortalTempDataServices;
|
||||
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;
|
||||
|
||||
/**
|
||||
@ -25,45 +23,26 @@ public class ShowPortalSubCommand implements SubCommand, SubCommand.SubCommandOn
|
||||
@Inject
|
||||
GameScheduler gameScheduler;
|
||||
|
||||
@Inject
|
||||
AdvancedPortalsCore core;
|
||||
|
||||
@Inject
|
||||
ServerContainer serverContainer;
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
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.isPortalVisible()) {
|
||||
sender.sendMessage(Lang.translate("messageprefix.negative") + Lang.translate("command.portal.show.disabled"));
|
||||
} else {
|
||||
sender.sendMessage(Lang.translate("messageprefix.positive") + Lang.translate("command.portal.show.enabled"));
|
||||
}
|
||||
tempData.setPortalVisible(!tempData.isPortalVisible());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -89,7 +68,51 @@ public class ShowPortalSubCommand implements SubCommand, SubCommand.SubCommandOn
|
||||
@Override
|
||||
public void registered() {
|
||||
gameScheduler.intervalTickEvent("show_portal", () -> {
|
||||
System.out.println("check visibility");
|
||||
for(PlayerContainer player : serverContainer.getPlayers()) {
|
||||
var tempData = tempDataServices.getPlayerTempData(player);
|
||||
if(!tempData.isDestiVisible()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
/*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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}, 1, 20);
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,15 @@
|
||||
package com.sekwah.advancedportals.core.connector.containers;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public interface ServerContainer {
|
||||
|
||||
WorldContainer getWorld(String name);
|
||||
|
||||
PlayerContainer getPlayer(String name);
|
||||
|
||||
PlayerContainer getPlayer(UUID name);
|
||||
|
||||
PlayerContainer[] getPlayers();
|
||||
|
||||
}
|
||||
|
@ -113,4 +113,12 @@ public class Destination implements TagTarget {
|
||||
}
|
||||
return tagList;
|
||||
}
|
||||
|
||||
public PlayerLocation getLoc() {
|
||||
return loc;
|
||||
}
|
||||
|
||||
public void setLoc(PlayerLocation loc) {
|
||||
this.loc = loc;
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package com.sekwah.advancedportals.core.module;
|
||||
|
||||
import com.google.inject.*;
|
||||
import com.sekwah.advancedportals.core.AdvancedPortalsCore;
|
||||
import com.sekwah.advancedportals.core.connector.containers.ServerContainer;
|
||||
import com.sekwah.advancedportals.core.registry.TagRegistry;
|
||||
import com.sekwah.advancedportals.core.serializeddata.config.Config;
|
||||
import com.sekwah.advancedportals.core.serializeddata.config.ConfigProvider;
|
||||
@ -45,6 +46,7 @@ public class AdvancedPortalsModule extends AbstractModule {
|
||||
bind(AdvancedPortalsCore.class).toInstance(advancedPortalsCore);
|
||||
bind(InfoLogger.class).toInstance(advancedPortalsCore.getInfoLogger());
|
||||
bind(DataStorage.class).toInstance(advancedPortalsCore.getDataStorage());
|
||||
bind(ServerContainer.class).toInstance(advancedPortalsCore.getServerContainer());
|
||||
|
||||
// Providers
|
||||
bind(Config.class).toProvider(ConfigProvider.class);
|
||||
|
@ -13,4 +13,6 @@ public interface ConfigRepository {
|
||||
String getSelectorMaterial();
|
||||
|
||||
void loadConfig(DataStorage dataStorage);
|
||||
|
||||
int getVisibleRange();
|
||||
}
|
||||
|
@ -5,5 +5,5 @@ import com.sekwah.advancedportals.core.destination.Destination;
|
||||
import java.io.IOException;
|
||||
|
||||
public interface IDestinationRepository extends IJsonRepository<Destination> {
|
||||
void addDestination(String name, Destination desti) throws IOException;
|
||||
|
||||
}
|
||||
|
@ -1,8 +1,5 @@
|
||||
package com.sekwah.advancedportals.core.repository;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.gson.Gson;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface IJsonRepository<T> {
|
||||
@ -17,5 +14,7 @@ public interface IJsonRepository<T> {
|
||||
|
||||
T get(String name);
|
||||
|
||||
List<String> listAll();
|
||||
List<String> getAllNames();
|
||||
|
||||
List<T> getAll();
|
||||
}
|
||||
|
@ -43,6 +43,10 @@ public class ConfigRepositoryImpl implements ConfigRepository {
|
||||
return this.config.selectorMaterial;
|
||||
}
|
||||
|
||||
public int getVisibleRange() {
|
||||
return this.config.visibleRange;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadConfig(DataStorage dataStorage) {
|
||||
this.config = dataStorage.loadJson(Config.class, "config.json");
|
||||
|
@ -11,6 +11,7 @@ import javax.inject.Singleton;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Singleton
|
||||
@ -23,14 +24,9 @@ public class DestinationRepositoryImpl implements IDestinationRepository {
|
||||
@Inject
|
||||
InfoLogger infoLogger;
|
||||
|
||||
public void addDestination(String name, Destination destination) {
|
||||
infoLogger.log("Adding destination: " + fileLocation + name + ".json");
|
||||
dataStorage.storeJson(destination, fileLocation + name + ".json");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean save(String name, Destination destination) {
|
||||
return false;
|
||||
return dataStorage.storeJson(destination, fileLocation + name + ".json");
|
||||
}
|
||||
|
||||
public boolean containsKey(String name) {
|
||||
@ -52,7 +48,18 @@ public class DestinationRepositoryImpl implements IDestinationRepository {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> listAll() {
|
||||
public List<String> getAllNames() {
|
||||
return dataStorage.listAllFiles(fileLocation, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Destination> getAll() {
|
||||
List<Destination> destinations = new ArrayList<>();
|
||||
List<String> allFiles = dataStorage.listAllFiles(fileLocation, false);
|
||||
for (String fileName : allFiles) {
|
||||
Destination destination = dataStorage.loadJson(Destination.class, fileLocation + fileName);
|
||||
destinations.add(destination);
|
||||
}
|
||||
return destinations;
|
||||
}
|
||||
}
|
||||
|
@ -49,7 +49,12 @@ public class PortalRepositoryImpl implements IPortalRepository {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> listAll() {
|
||||
public List<String> getAllNames() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<WorldLocation> getAll() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -35,4 +35,15 @@ public class BlockLocation {
|
||||
public boolean equals(BlockLocation location) {
|
||||
return location.posX == this.posX && location.posY == this.posY && location.posZ == this.posZ && location.worldName.equals(this.worldName);
|
||||
}
|
||||
|
||||
public double distanceTo(BlockLocation pos) {
|
||||
return Math.sqrt(this.distanceToSq(pos));
|
||||
}
|
||||
|
||||
public double distanceToSq(BlockLocation pos) {
|
||||
double dx = this.posX - pos.posX;
|
||||
double dy = this.posY - pos.posY;
|
||||
double dz = this.posZ - pos.posZ;
|
||||
return dx * dx + dy * dy + dz * dz;
|
||||
}
|
||||
}
|
||||
|
@ -66,7 +66,13 @@ public class DataStorage {
|
||||
return null;
|
||||
}
|
||||
BufferedReader bufReader = new BufferedReader(new InputStreamReader(jsonResource));
|
||||
return gson.fromJson(bufReader, dataHolder);
|
||||
T data = gson.fromJson(bufReader, dataHolder);
|
||||
try {
|
||||
bufReader.close();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
public boolean storeJson(Object dataHolder, String location) {
|
||||
@ -222,6 +228,12 @@ public class DataStorage {
|
||||
}
|
||||
|
||||
public boolean deleteFile(String fileLocation) {
|
||||
return new File(dataFolder, fileLocation).delete();
|
||||
try {
|
||||
Files.delete(Paths.get(dataFolder.getAbsolutePath(), fileLocation));
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -19,6 +19,16 @@ public class PlayerTempData {
|
||||
*/
|
||||
private BlockLocation pos2;
|
||||
|
||||
/**
|
||||
* If to show portals near the player
|
||||
*/
|
||||
private boolean portalVisible;
|
||||
|
||||
/**
|
||||
* If to show destination blocks near the player
|
||||
*/
|
||||
private boolean destiVisible;
|
||||
|
||||
/**
|
||||
* Used for things like join cooldowns
|
||||
* TODO either store a hashmap of cool-downs on a portal, or a hashmap of cool-downs for portals on a player
|
||||
@ -59,4 +69,20 @@ public class PlayerTempData {
|
||||
public void setSelectedPortal(String selectedPortal) {
|
||||
this.selectedPortal = selectedPortal;
|
||||
}
|
||||
|
||||
public boolean isPortalVisible() {
|
||||
return portalVisible;
|
||||
}
|
||||
|
||||
public void setPortalVisible(boolean showPortals) {
|
||||
this.portalVisible = showPortals;
|
||||
}
|
||||
|
||||
public boolean isDestiVisible() {
|
||||
return destiVisible;
|
||||
}
|
||||
|
||||
public void setDestiVisible(boolean destiVisible) {
|
||||
this.destiVisible = destiVisible;
|
||||
}
|
||||
}
|
||||
|
@ -22,4 +22,19 @@ public class WorldLocation {
|
||||
this.posY = posY;
|
||||
this.posZ = posZ;
|
||||
}
|
||||
|
||||
public double distanceTo(WorldLocation pos) {
|
||||
return Math.sqrt(this.distanceToSq(pos));
|
||||
}
|
||||
|
||||
public double distanceToSq(WorldLocation pos) {
|
||||
double dx = this.posX - pos.posX;
|
||||
double dy = this.posY - pos.posY;
|
||||
double dz = this.posZ - pos.posZ;
|
||||
return dx * dx + dy * dy + dz * dz;
|
||||
}
|
||||
|
||||
public BlockLocation toBlockPos() {
|
||||
return new BlockLocation(this.worldName, (int) Math.floor(this.posX), (int) Math.floor(this.posY), (int) Math.floor(this.posZ));
|
||||
}
|
||||
}
|
||||
|
@ -27,4 +27,6 @@ public class Config {
|
||||
|
||||
public String translationFile = "en_GB";
|
||||
|
||||
public int visibleRange = 50;
|
||||
|
||||
}
|
||||
|
@ -1,37 +1,29 @@
|
||||
package com.sekwah.advancedportals.core.services;
|
||||
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.google.inject.Inject;
|
||||
import com.sekwah.advancedportals.core.connector.containers.PlayerContainer;
|
||||
import com.sekwah.advancedportals.core.portal.AdvancedPortal;
|
||||
import com.sekwah.advancedportals.core.serializeddata.DataStorage;
|
||||
import com.sekwah.advancedportals.core.serializeddata.DataTag;
|
||||
import com.sekwah.advancedportals.core.serializeddata.PlayerLocation;
|
||||
import com.sekwah.advancedportals.core.destination.Destination;
|
||||
import com.sekwah.advancedportals.core.repository.IDestinationRepository;
|
||||
import com.sekwah.advancedportals.core.util.Lang;
|
||||
import com.sekwah.advancedportals.core.util.Response;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Handles logic for all destination, this is a transient layer so it should
|
||||
* not store any information.
|
||||
*/
|
||||
@Singleton
|
||||
public class DestinationServices {
|
||||
|
||||
@Inject
|
||||
private IDestinationRepository destinationRepository;
|
||||
|
||||
private final Map<String, Destination> destinationCache = new HashMap<>();
|
||||
|
||||
public Response.Creation create(String name, Destination destination) {
|
||||
if (!destinationRepository.containsKey(name)) {
|
||||
destinationRepository.save(name, destination);
|
||||
@ -47,8 +39,20 @@ public class DestinationServices {
|
||||
return false;
|
||||
}
|
||||
|
||||
public List<String> getDestinations() {
|
||||
return destinationRepository.listAll();
|
||||
public List<String> getDestinationNames() {
|
||||
return destinationRepository.getAllNames();
|
||||
}
|
||||
|
||||
public List<Destination> getDestinations() {
|
||||
return new ArrayList<>(destinationCache.values());
|
||||
}
|
||||
|
||||
public void loadDestinations() {
|
||||
List<String> destinationNames = destinationRepository.getAllNames();
|
||||
for (String name : destinationNames) {
|
||||
Destination destination = destinationRepository.get(name);
|
||||
destinationCache.put(name, destination);
|
||||
}
|
||||
}
|
||||
|
||||
public Destination createDesti(PlayerContainer player, PlayerLocation playerLocation, ArrayList<DataTag> tags) {
|
||||
@ -58,25 +62,24 @@ public class DestinationServices {
|
||||
String name = nameTag == null ? null : nameTag.VALUES[0];
|
||||
|
||||
// If the name is null, send an error saying that the name is required.
|
||||
if(nameTag == null) {
|
||||
if (nameTag == null) {
|
||||
player.sendMessage(Lang.translate("messageprefix.negative") + Lang.translate("desti.error.noname"));
|
||||
return null;
|
||||
}
|
||||
|
||||
if(name == null || name.equals("")) {
|
||||
if (name == null || name.equals("")) {
|
||||
player.sendMessage(Lang.translate("messageprefix.negative") + Lang.translate("command.error.noname"));
|
||||
return null;
|
||||
}
|
||||
else if(this.destinationRepository.containsKey(name)) {
|
||||
} else if (this.destinationRepository.containsKey(name)) {
|
||||
player.sendMessage(Lang.translate("messageprefix.negative") + Lang.translateInsertVariables("command.error.nametaken", name));
|
||||
return null;
|
||||
}
|
||||
|
||||
Destination desti = new Destination(playerLocation);
|
||||
for(DataTag portalTag : tags) {
|
||||
for (DataTag portalTag : tags) {
|
||||
desti.setArgValues(portalTag);
|
||||
}
|
||||
for(DataTag destiTag : tags) {
|
||||
for (DataTag destiTag : tags) {
|
||||
// TODO sort tag handle registry
|
||||
/*TagHandler.Creation<Destination> creation = AdvancedPortalsCore.getDestinationTagRegistry().getCreationHandler(destiTag.NAME);
|
||||
if(creation != null) {
|
||||
@ -84,32 +87,21 @@ public class DestinationServices {
|
||||
}*/
|
||||
}
|
||||
try {
|
||||
this.destinationRepository.addDestination(name, desti);
|
||||
if(this.destinationRepository.save(name, desti)) {
|
||||
this.destinationCache.put(name, desti);
|
||||
} else {
|
||||
player.sendMessage(Lang.translate("messageprefix.negative") + Lang.translate("desti.error.save"));
|
||||
return null;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
player.sendMessage(Lang.translate("messageprefix.negative") + Lang.translate("desti.error.save"));
|
||||
}
|
||||
this.saveDestinations();
|
||||
return desti;
|
||||
}
|
||||
|
||||
//TODO Change to repository
|
||||
|
||||
public void loadDestinations() {
|
||||
Type type = new TypeToken<HashMap<String, Destination>>() {
|
||||
}.getType();
|
||||
//this.destiHashMap = this.portalsCore.getDataStorage().loadJson(type, "destinations.json");
|
||||
this.saveDestinations();
|
||||
}
|
||||
|
||||
public void saveDestinations() {
|
||||
/*if (this.destiHashMap == null) {
|
||||
this.destiHashMap = new HashMap<>();
|
||||
}
|
||||
this.portalsCore.getDataStorage().storeJson(this.destiHashMap, "destinations.json");*/
|
||||
}
|
||||
|
||||
public boolean removeDesti(String name, PlayerContainer playerContainer) {
|
||||
public boolean removeDestination(String name, PlayerContainer playerContainer) {
|
||||
this.destinationCache.remove(name);
|
||||
if(this.destinationRepository.containsKey(name)) {
|
||||
this.destinationRepository.delete(name);
|
||||
return true;
|
||||
|
@ -1,10 +0,0 @@
|
||||
package com.sekwah.advancedportals.core.services;
|
||||
|
||||
public class Response {
|
||||
|
||||
public enum Creation {
|
||||
SUCCESS,
|
||||
NAME_IN_USE,
|
||||
}
|
||||
|
||||
}
|
@ -53,6 +53,6 @@ public class DestiTag implements Tag.Activation, Tag.AutoComplete {
|
||||
|
||||
@Override
|
||||
public List<String> autoComplete(String argData) {
|
||||
return destinationServices.getDestinations();
|
||||
return destinationServices.getDestinationNames();
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,13 @@
|
||||
package com.sekwah.advancedportals.core.util;
|
||||
|
||||
/**
|
||||
* Need to make more of the plugin use this rather than just returning true or false.
|
||||
*/
|
||||
public class Response {
|
||||
|
||||
public enum Creation {
|
||||
SUCCESS,
|
||||
NAME_IN_USE,
|
||||
}
|
||||
|
||||
}
|
@ -84,9 +84,22 @@ command.portal.remove.complete= The portal has been successfully removed.
|
||||
|
||||
command.portal.show.help=Shows nearby portals
|
||||
command.portal.show.detailedhelp=Shows nearby portals. Relies on debug markers so may not work on certain versions of minecraft (1.16+ atm only).
|
||||
command.portal.show.enabled= Portal markers are now enabled.
|
||||
command.portal.show.disabled= Portal markers are now disabled.
|
||||
command.portal.show.unsupported= Portal markers are not supported on this version of minecraft. (1.16+ atm only)
|
||||
|
||||
command.destination.remove.error= There was a problem removing the destination.
|
||||
|
||||
command.destination.show.help=Shows nearby destinations
|
||||
command.destination.show.detailedhelp=Shows nearby destinations. Relies on debug markers so may not work on certain versions of minecraft (1.16+ atm only).
|
||||
command.destination.show.enabled= Destination markers are now enabled.
|
||||
command.destination.show.disabled= Destination markers are now disabled.
|
||||
command.destination.show.unsupported= Destination markers are not supported on this version of minecraft. (1.16+ atm only)
|
||||
|
||||
command.destination.reload.help=Reloads the destination data from the repository.
|
||||
command.destination.reload.detailedhelp=This command will reload all destination data from the repository, updating the cache with the latest data.
|
||||
command.destination.reload= Destinations reloaded.
|
||||
|
||||
command.portal.list.help=Lists portals
|
||||
command.portal.list=&7 Portals&a:
|
||||
|
||||
|
@ -0,0 +1,54 @@
|
||||
package com.sekwah.advancedportals.spigot.connector.container;
|
||||
|
||||
import com.sekwah.advancedportals.core.connector.containers.PlayerContainer;
|
||||
import com.sekwah.advancedportals.core.connector.containers.ServerContainer;
|
||||
import com.sekwah.advancedportals.core.connector.containers.WorldContainer;
|
||||
import org.bukkit.Server;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class SpigotServerContainer implements ServerContainer {
|
||||
|
||||
private final Server server;
|
||||
|
||||
public SpigotServerContainer(Server server) {
|
||||
this.server = server;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WorldContainer getWorld(String name) {
|
||||
var world = server.getWorld(name);
|
||||
if(world != null) {
|
||||
return new SpigotWorldContainer(world);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayerContainer getPlayer(String name) {
|
||||
var player = server.getPlayer(name);
|
||||
if(player != null) {
|
||||
return new SpigotPlayerContainer(player);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayerContainer getPlayer(UUID name) {
|
||||
var player = server.getPlayer(name);
|
||||
if(player != null) {
|
||||
return new SpigotPlayerContainer(player);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayerContainer[] getPlayers() {
|
||||
return server.getOnlinePlayers().stream()
|
||||
.map(SpigotPlayerContainer::new)
|
||||
.toArray(PlayerContainer[]::new);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user