Skip to content

Commit

Permalink
chore: run pre-commit
Browse files Browse the repository at this point in the history
  • Loading branch information
sekwah41 committed Jun 16, 2024
1 parent c51cd8d commit 04136e2
Show file tree
Hide file tree
Showing 79 changed files with 1,339 additions and 1,034 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ repos:
rev: v2.13.0
hooks:
- id: pretty-format-java
args: [--autofix]
args: [--autofix, --aosp, --google-java-formatter-version=1.16.0]
- id: pretty-format-yaml
args: [--autofix]
- id: pretty-format-toml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
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.module.AdvancedPortalsModule;
import com.sekwah.advancedportals.core.registry.TagRegistry;
import com.sekwah.advancedportals.core.repository.ConfigRepository;
import com.sekwah.advancedportals.core.repository.IPlayerDataRepository;
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.services.PortalServices;
import com.sekwah.advancedportals.core.services.PlayerDataServices;
import com.sekwah.advancedportals.core.services.PortalServices;
import com.sekwah.advancedportals.core.tags.activation.*;
import com.sekwah.advancedportals.core.util.GameScheduler;
import com.sekwah.advancedportals.core.util.InfoLogger;
Expand All @@ -26,7 +26,6 @@

public class AdvancedPortalsCore {


public static final String version = "1.0.0";

private final InfoLogger infoLogger;
Expand All @@ -35,44 +34,40 @@ public class AdvancedPortalsCore {
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
* 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;

private static AdvancedPortalsCore instance;

@Inject
private CommandRegister commandRegister;
@Inject private CommandRegister commandRegister;

private CommandWithSubCommands portalCommand;
private CommandWithSubCommands destiCommand;

@Inject
private ConfigRepository configRepository;
@Inject private ConfigRepository configRepository;

@Inject
private TagRegistry tagRegistry;
@Inject private TagRegistry tagRegistry;

@Inject
private PortalServices portalServices;
@Inject private PortalServices portalServices;

@Inject
private DestinationServices destinationServices;
@Inject private DestinationServices destinationServices;

@Inject
private PlayerDataServices playerDataRepository;
@Inject private PlayerDataServices playerDataRepository;

@Inject
private GameScheduler gameScheduler;
@Inject private GameScheduler gameScheduler;

// TEMP REMOVE THIS THIS IS JUST FOR DEV
@Inject
private IPlayerDataRepository tempDataRepository;
@Inject private IPlayerDataRepository tempDataRepository;

public AdvancedPortalsCore(String mcVersion, File dataStorageLoc, InfoLogger infoLogger, ServerContainer serverContainer) {
public AdvancedPortalsCore(
String mcVersion,
File dataStorageLoc,
InfoLogger infoLogger,
ServerContainer serverContainer) {
instance = this;
this.serverContainer = serverContainer;
this.dataStorage = new DataStorage(dataStorageLoc);
Expand All @@ -81,31 +76,34 @@ public AdvancedPortalsCore(String mcVersion, File dataStorageLoc, InfoLogger inf
int[] mcVersionTemp;
infoLogger.info("Loading Advanced Portals Core v" + version + " for MC: " + mcVersion);
try {
mcVersionTemp = Arrays.stream(mcVersion.split("\\.")).mapToInt(Integer::parseInt).toArray();
mcVersionTemp =
Arrays.stream(mcVersion.split("\\.")).mapToInt(Integer::parseInt).toArray();
} catch (NumberFormatException e) {
infoLogger.info("Failed to parse MC version: " + mcVersion);
e.printStackTrace();
mcVersionTemp = new int[]{0, 0, 0};
mcVersionTemp = new int[] {0, 0, 0};
}
if(mcVersionTemp.length == 2) {
mcVersionTemp = new int[]{mcVersionTemp[0], mcVersionTemp[1], 0};
if (mcVersionTemp.length == 2) {
mcVersionTemp = new int[] {mcVersionTemp[0], mcVersionTemp[1], 0};
}
this.mcVersion = mcVersionTemp;

this.module = new AdvancedPortalsModule(this);
}

/**
* For some platforms we could do this on construction but this just allows for a bit more control
* For some platforms we could do this on construction but this just allows for a bit more
* control
*/
public void onEnable() {
// Force values to get injected, either because the initial ones were created too early or to ensure they are not null.
// Force values to get injected, either because the initial ones were created too early or
// to ensure they are not null.
// Do it here to give implementations a chance to interact with the module.
Injector injector = module.getInjector();
injector.injectMembers(this);
injector.injectMembers(Lang.instance);

//AdvancedPortalsModule module = new AdvancedPortalsModule(this);
// AdvancedPortalsModule module = new AdvancedPortalsModule(this);
this.dataStorage.copyDefaultFile("lang/en_GB.lang", false);
this.loadPortalConfig();
Lang.loadLanguage(configRepository.getTranslation());
Expand All @@ -126,9 +124,7 @@ private void registerTags() {
this.tagRegistry.registerTag(new PermissionTag());
}

/**
*
*/
/** */
public void registerCommands() {
this.registerPortalCommand(commandRegister);
this.registerDestinationCommand(commandRegister);
Expand Down Expand Up @@ -172,16 +168,16 @@ public boolean registerDestiCommand(String arg, SubCommand subCommand, String...
}

/**
* Loads the portal config into the memory and saves from the memory to check in case certain things have changed
* (basically if values are missing or whatever)
* Loads the portal config into the memory and saves from the memory to check in case certain
* things have changed (basically if values are missing or whatever)
*/
public void loadPortalConfig() {
this.configRepository.loadConfig(this.dataStorage);
this.configRepository.storeConfig();
}

public void onDisable() {
for(var playerContainer : this.serverContainer.getPlayers()) {
for (var playerContainer : this.serverContainer.getPlayers()) {
playerDataRepository.playerLeave(playerContainer);
}
this.infoLogger.info(Lang.translate("logger.plugindisable"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,19 @@
/**
* Already know spigot's auto complete possibilities
*
* Sponge https://docs.spongepowered.org/stable/en/plugin/commands/arguments.html#custom-command-elements
* <p>Sponge
* https://docs.spongepowered.org/stable/en/plugin/commands/arguments.html#custom-command-elements
*/
public interface CommandTemplate {

void onCommand(CommandSenderContainer sender, String commandExecuted, String[] args);

/**
* Fired when someone asks for a tab complete action.
*
* @param sender whoever triggered the command e.g. command block, server or player
* @param args arguments for the command
* @return a lot of strings that are possible completions
*/
List<String> onTabComplete(CommandSenderContainer sender, String[] args);

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,14 @@ public interface SubCommand {
/**
* @param sender
* @param args arguments including the subcommand that has been specified.
* @return if the command has worked (if false it will just display a message from the command suggesting to check help)
* @return if the command has worked (if false it will just display a message from the command
* suggesting to check help)
*/
void onCommand(CommandSenderContainer sender, String[] args);

boolean hasPermission(CommandSenderContainer sender);

/**
*
*
* @param sender
* @param args arguments including the subcommand that has been specified.
* @return tab completion for the subcommand
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
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.permissions.PortalPermissions;
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.services.DestinationServices;
import com.sekwah.advancedportals.core.util.Lang;
import com.sekwah.advancedportals.core.util.TagReader;
Expand All @@ -19,56 +19,68 @@

public class CreateDestiSubCommand extends CreateTaggedSubCommand {

@Inject
TagRegistry tagRegistry;
@Inject TagRegistry tagRegistry;

@Inject
DestinationServices destinationServices;
@Inject DestinationServices destinationServices;

@Override
public void onCommand(CommandSenderContainer sender, String[] args) {
if(args.length > 1) {
if (args.length > 1) {
PlayerContainer player = sender.getPlayerContainer();
if(player == null) {
sender.sendMessage(Lang.translate("messageprefix.negative") + Lang.translate("command.create.destination.console"));
if (player == null) {
sender.sendMessage(
Lang.translate("messageprefix.negative")
+ Lang.translate("command.create.destination.console"));
return;
}

ArrayList<DataTag> destinationTags = TagReader.getTagsFromArgs(args);

// Find the tag with the "name" NAME
DataTag nameTag = destinationTags.stream().filter(tag -> tag.NAME.equals("name")).findFirst().orElse(null);
DataTag nameTag =
destinationTags.stream()
.filter(tag -> tag.NAME.equals("name"))
.findFirst()
.orElse(null);

// If the tag is null, check if arg[1] has a : to check it's not a tag.
if(nameTag == null && !args[1].contains(":")) {
if (nameTag == null && !args[1].contains(":")) {
nameTag = new DataTag("name", args[1]);
destinationTags.add(nameTag);
}

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

if(!destinationTags.isEmpty()) {
if (!destinationTags.isEmpty()) {
this.filterAndProcessTags(destinationTags);
this.printTags(sender, destinationTags);
}
sender.sendMessage("");
Destination destination = destinationServices.createDesti(player, player.getLoc(), destinationTags);
if(destination != null) {
sender.sendMessage(Lang.translate("messageprefix.positive") + Lang.translate("command.create.destination.complete"));
}
else {
Destination destination =
destinationServices.createDesti(player, player.getLoc(), destinationTags);
if (destination != null) {
sender.sendMessage(
Lang.translate("messageprefix.positive")
+ Lang.translate("command.create.destination.complete"));
} else {
sender.sendMessage("");
sender.sendMessage(Lang.translate("messageprefix.negative") + Lang.translate("command.create.destination.error"));
sender.sendMessage(
Lang.translate("messageprefix.negative")
+ Lang.translate("command.create.destination.error"));
}
}
else {
sender.sendMessage(Lang.translate("messageprefix.negative") + Lang.translate("command.error.noname"));
} else {
sender.sendMessage(
Lang.translate("messageprefix.negative")
+ Lang.translate("command.error.noname"));
}
}

Expand All @@ -81,7 +93,9 @@ public boolean hasPermission(CommandSenderContainer sender) {
protected List<Tag> getRelatedTags() {
var tags = tagRegistry.getTags();
// Filter tags that support Destination
return tags.stream().filter(tag -> Arrays.asList(tag.getTagTypes()).contains(Tag.TagType.DESTINATION)).toList();
return tags.stream()
.filter(tag -> Arrays.asList(tag.getTagTypes()).contains(Tag.TagType.DESTINATION))
.toList();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,17 @@

public class ListDestiSubCommand implements SubCommand {

@Inject
DestinationServices portalServices;
@Inject DestinationServices portalServices;

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

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,21 @@

public class RemoveDestiSubCommand implements SubCommand {


@Inject
DestinationServices destinationServices;
@Inject DestinationServices destinationServices;

@Override
public void onCommand(CommandSenderContainer sender, String[] args) {
if(args.length > 1) {
if(destinationServices.removeDestination(args[1], sender.getPlayerContainer())) {
sender.sendMessage(Lang.translate("messageprefix.positive") + Lang.translate("command.destination.remove.complete"));
}
else {
sender.sendMessage(Lang.translate("messageprefix.negative")
+ Lang.translate("command.destination.remove.error"));
if (args.length > 1) {
if (destinationServices.removeDestination(args[1], sender.getPlayerContainer())) {
sender.sendMessage(
Lang.translate("messageprefix.positive")
+ Lang.translate("command.destination.remove.complete"));
} else {
sender.sendMessage(
Lang.translate("messageprefix.negative")
+ Lang.translate("command.destination.remove.error"));
}
}
else {
} else {
sender.sendMessage(Lang.translate("command.destination.noname"));
}
}
Expand All @@ -39,7 +38,7 @@ public boolean hasPermission(CommandSenderContainer sender) {

@Override
public List<String> onTabComplete(CommandSenderContainer sender, String[] args) {
if(args.length > 2) {
if (args.length > 2) {
return Collections.emptyList();
}
List<String> destiNames = destinationServices.getDestinationNames();
Expand Down
Loading

0 comments on commit 04136e2

Please sign in to comment.