diff --git a/branch-adventure/branch-adventure.iml b/branch-adventure/branch-adventure.iml new file mode 100644 index 0000000..641ad76 --- /dev/null +++ b/branch-adventure/branch-adventure.iml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/branch-adventure/pom.xml b/branch-adventure/pom.xml new file mode 100644 index 0000000..30bef17 --- /dev/null +++ b/branch-adventure/pom.xml @@ -0,0 +1,36 @@ + + + + branch + xyz.auriium + 0.1.0 + + 4.0.0 + + branch-spigot-adventure + + + ${compiler.version} + ${compiler.version} + + + + + xyz.auriium + branch-core + + + net.kyori + adventure-api + 4.8.1 + + + net.kyori + adventure-text-serializer-legacy + 4.8.1 + + + + \ No newline at end of file diff --git a/branch-adventure/src/main/java/xyz/auriium/branch/adventure/AdventureMessageBoss.java b/branch-adventure/src/main/java/xyz/auriium/branch/adventure/AdventureMessageBoss.java new file mode 100644 index 0000000..bd1c8dd --- /dev/null +++ b/branch-adventure/src/main/java/xyz/auriium/branch/adventure/AdventureMessageBoss.java @@ -0,0 +1,12 @@ +package xyz.auriium.branch.adventure; + +import net.kyori.adventure.text.Component; +import xyz.auriium.branch.interfacing.MessageWorker; +import xyz.auriium.branch.interfacing.WorkerMessageBoss; + +public class AdventureMessageBoss extends WorkerMessageBoss { + + public AdventureMessageBoss(AudienceTransmogrifier iTransmogrifier, AudienceTransmogrifier aTransmogrifier) { + super(new AdventureMessageWorker<>(iTransmogrifier), new AdventureMessageWorker<>(aTransmogrifier)); + } +} diff --git a/branch-adventure/src/main/java/xyz/auriium/branch/adventure/AdventureMessageWorker.java b/branch-adventure/src/main/java/xyz/auriium/branch/adventure/AdventureMessageWorker.java new file mode 100644 index 0000000..2716206 --- /dev/null +++ b/branch-adventure/src/main/java/xyz/auriium/branch/adventure/AdventureMessageWorker.java @@ -0,0 +1,25 @@ +package xyz.auriium.branch.adventure; + +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.TextComponent; +import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; +import xyz.auriium.branch.interfacing.MessageWorker; + +public class AdventureMessageWorker implements MessageWorker { + + private final AudienceTransmogrifier transmogrifier; + + public AdventureMessageWorker(AudienceTransmogrifier transmogrifier) { + this.transmogrifier = transmogrifier; + } + + @Override + public void sendMessage(String message, T type) { + transmogrifier.transmogrify(type).sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(message)); + } + + @Override + public void sendObject(Component message, T type) { + transmogrifier.transmogrify(type).sendMessage(message); + } +} diff --git a/branch-adventure/src/main/java/xyz/auriium/branch/adventure/AudienceTransmogrifier.java b/branch-adventure/src/main/java/xyz/auriium/branch/adventure/AudienceTransmogrifier.java new file mode 100644 index 0000000..3f89906 --- /dev/null +++ b/branch-adventure/src/main/java/xyz/auriium/branch/adventure/AudienceTransmogrifier.java @@ -0,0 +1,12 @@ +package xyz.auriium.branch.adventure; + +import net.kyori.adventure.audience.Audience; + +/** + * I am not one to be outdone with names + */ +public interface AudienceTransmogrifier { + + Audience transmogrify(A user); + +} diff --git a/core/pom.xml b/branch-core/pom.xml similarity index 75% rename from core/pom.xml rename to branch-core/pom.xml index b7479b7..8a4fb06 100644 --- a/core/pom.xml +++ b/branch-core/pom.xml @@ -25,7 +25,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> branch - me.aurium + xyz.auriium 0.1.0 4.0.0 @@ -37,6 +37,24 @@ ${compiler.version} + + + org.slf4j + slf4j-api + test + + + org.junit.jupiter + junit-jupiter-engine + test + + + org.junit.jupiter + junit-jupiter-params + test + + + @@ -51,6 +69,4 @@ - - \ No newline at end of file diff --git a/branch-core/src/main/java/module-info.java b/branch-core/src/main/java/module-info.java new file mode 100644 index 0000000..a9fa6ec --- /dev/null +++ b/branch-core/src/main/java/module-info.java @@ -0,0 +1,26 @@ +module branch.core { + exports xyz.auriium.branch; + exports xyz.auriium.branch.base; + exports xyz.auriium.branch.base.execution; + exports xyz.auriium.branch.base.execution.blocks; + exports xyz.auriium.branch.base.permissions; + exports xyz.auriium.branch.base.suggestion; + exports xyz.auriium.branch.nodes; + exports xyz.auriium.branch.nodes.argument; + exports xyz.auriium.branch.nodes.argument.model; + exports xyz.auriium.branch.nodes.argument.impl; + exports xyz.auriium.branch.nodes.argument.types; + exports xyz.auriium.branch.results; + exports xyz.auriium.branch.nodes.branching; + exports xyz.auriium.branch.nodes.description; + exports xyz.auriium.branch.nodes.single; + exports xyz.auriium.branch.nodes.single.impl; + exports xyz.auriium.branch.nodes.help; + exports xyz.auriium.branch.nodes.proxy; + exports xyz.auriium.branch.interfacing; + exports xyz.auriium.branch.interfacing.exceptional; + exports xyz.auriium.branch.interfacing.exceptional.anomalies; + exports xyz.auriium.branch.interfacing.exceptional.caption; + exports xyz.auriium.branch.interfacing.exceptional.printing; + exports xyz.auriium.branch.typeadapter; +} \ No newline at end of file diff --git a/core/src/main/java/me/aurium/branch/centralized/CentralizedManager.java b/branch-core/src/main/java/xyz/auriium/branch/CentralizedManager.java similarity index 68% rename from core/src/main/java/me/aurium/branch/centralized/CentralizedManager.java rename to branch-core/src/main/java/xyz/auriium/branch/CentralizedManager.java index cac406a..18aa04d 100644 --- a/core/src/main/java/me/aurium/branch/centralized/CentralizedManager.java +++ b/branch-core/src/main/java/xyz/auriium/branch/CentralizedManager.java @@ -19,11 +19,12 @@ * */ -package me.aurium.branch.centralized; +package xyz.auriium.branch; -import me.aurium.branch.centralized.base.NodeBase; -import me.aurium.branch.centralized.base.NodeBaseBuilder; -import me.aurium.branch.centralized.typeadapter.ManagerAdapter; +import xyz.auriium.branch.base.NodeBase; +import xyz.auriium.branch.base.NodeBaseBuilder; +import xyz.auriium.branch.typeadapter.ManagerAdapter; +import xyz.auriium.branch.nodes.CommandNode; /** * Represents the utmost base part of the command framework which has the ability to bind any injected commands to a platform @@ -35,10 +36,13 @@ public interface CentralizedManager { CentralizedManagerBinder getBinder(V platform); NodeSource getSource(); - NodeBaseBuilder newCommand(); - NodeBaseBuilder newCommand(ManagerAdapter adapter); + NodeBaseBuilder newCommandWithBuilder(); + NodeBaseBuilder newCommandWithBuilder(ManagerAdapter adapter); - void injectCommand(NodeBase base); + void newCommandWithNode(CommandNode node); + void newCommandWithNode(CommandNode node, ManagerAdapter adapter); + + void newCommand(NodeBase base); } diff --git a/core/src/main/java/me/aurium/branch/centralized/CentralizedManagerBinder.java b/branch-core/src/main/java/xyz/auriium/branch/CentralizedManagerBinder.java similarity index 96% rename from core/src/main/java/me/aurium/branch/centralized/CentralizedManagerBinder.java rename to branch-core/src/main/java/xyz/auriium/branch/CentralizedManagerBinder.java index 2c16ed7..066cbf6 100644 --- a/core/src/main/java/me/aurium/branch/centralized/CentralizedManagerBinder.java +++ b/branch-core/src/main/java/xyz/auriium/branch/CentralizedManagerBinder.java @@ -19,7 +19,7 @@ * */ -package me.aurium.branch.centralized; +package xyz.auriium.branch; /** * Represents a carrier vessel which is typically attached to the instance of a centralizedManagerBinder's platform diff --git a/branch-core/src/main/java/xyz/auriium/branch/NodeSource.java b/branch-core/src/main/java/xyz/auriium/branch/NodeSource.java new file mode 100644 index 0000000..62179b3 --- /dev/null +++ b/branch-core/src/main/java/xyz/auriium/branch/NodeSource.java @@ -0,0 +1,20 @@ +package xyz.auriium.branch; + +import xyz.auriium.branch.base.execution.ExecutionHandler; +import xyz.auriium.branch.base.permissions.Permission; +import xyz.auriium.branch.nodes.description.Description; +import xyz.auriium.branch.nodes.branching.BranchingBuilder; +import xyz.auriium.branch.nodes.single.SingleNode; +import xyz.auriium.branch.nodes.single.SingleNodeBuilder; + +public interface NodeSource { + + SingleNodeBuilder single(); + BranchingBuilder branch(); + //TODO argument + + + SingleNode singleNode(String literal, ExecutionHandler handler); + SingleNode singleNode(String literal, ExecutionHandler handler, Permission permission, Description description); + +} diff --git a/branch-core/src/main/java/xyz/auriium/branch/base/AbstractNodeBase.java b/branch-core/src/main/java/xyz/auriium/branch/base/AbstractNodeBase.java new file mode 100644 index 0000000..1897230 --- /dev/null +++ b/branch-core/src/main/java/xyz/auriium/branch/base/AbstractNodeBase.java @@ -0,0 +1,148 @@ +/* + * + * Branch + * Copyright © 2021 Aurium + * + * Branch is free software: you can redistribute it and/or modify + * It under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * Branch is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with Branch. If not, see + * and navigate to version 3 of the GNU Affero General Public License. + * + */ + +package xyz.auriium.branch.base; + +import xyz.auriium.branch.base.suggestion.Suggestion; +import xyz.auriium.branch.base.suggestion.SuggestionSearchStrategy; +import xyz.auriium.branch.typeadapter.ManagerAdapter; +import xyz.auriium.branch.base.execution.Execution; +import xyz.auriium.branch.base.execution.ExecutionSearchStrategy; +import xyz.auriium.branch.interfacing.exceptional.AnomalyHandler; +import xyz.auriium.branch.nodes.CommandNode; +import xyz.auriium.branch.results.PreProcessSearch; +import xyz.auriium.branch.results.SearcherEquality; +import xyz.auriium.branch.results.Result; + +import java.util.ArrayList; +import java.util.List; + +/** + * Represents a node base that has the ability to convert it's input sender to a sender of type C or fail with a result. + * @param the input type of nodebase + * @param the adjusted type desired by the output of the {@link ManagerAdapter} found in this nodebase + */ +public abstract class AbstractNodeBase implements NodeBase { + + private final ManagerAdapter adapter; + private final AnomalyHandler handler; + + private final CommandNode baseNode; + private final ExecutionSearchStrategy executionStrategy; + private final SuggestionSearchStrategy suggestionStrategy; + private final ContextProvider provider; + private final SearcherEquality equality; + + private final static List EMPTY = new ArrayList<>(); + + protected AbstractNodeBase(ManagerAdapter adapter, AnomalyHandler handler, CommandNode baseNode, ExecutionSearchStrategy executionStrategy, SuggestionSearchStrategy suggestionStrategy, ContextProvider provider, SearcherEquality equality) { + this.adapter = adapter; + this.handler = handler; + this.baseNode = baseNode; + this.executionStrategy = executionStrategy; + this.suggestionStrategy = suggestionStrategy; + this.provider = provider; + this.equality = equality; + } + + + /** + * Method for execution of runnable once runnable is found + * Exists in order to allow for concurrent-type nodebases + * + * @param execution the runnable + */ + abstract void submitExecution(Execution execution); + + public void execute(I input, String alias, String[] args) { + //have not aqcuired C-type (cannot use Result object or message handling-parsing) + + if (!adapter.canAdapt(input)) { + handler.communicateNotAdapted(input, adapter.failedParseResponse(input)); + + return; + } + + //have acquired C-type via parsing. + + A adaptedSender = adapter.adapt(input); + NodeContext produced = provider.produce(adaptedSender, alias, args); + + Result> preprocessResult = executionStrategy.attemptPreprocess(produced, equality, baseNode); + + if (!preprocessResult.isSuccessful()) { + handler.communicateAdapted(adaptedSender, preprocessResult.getFailure()); + + return; + } + + PreProcessSearch info = preprocessResult.getSuccess(); + + Result> executionResult = info.getFoundNode().searchExecute(produced, info); + + if (!executionResult.isSuccessful()) { + handler.communicateAdapted(adaptedSender, preprocessResult.getFailure()); + + return; + } + + submitExecution(executionResult.getSuccess()); + } + + public List suggest(I input, String alias, String[] args) { + + if (!adapter.canAdapt(input)) { + handler.communicateNotAdapted(input, adapter.failedParseResponse(input)); + + return EMPTY; + } + + //have acquired C-type via parsing. + + A adaptedSender = adapter.adapt(input); + NodeContext produced = provider.produce(adaptedSender, alias, args); + + Result> preprocessResult = executionStrategy.attemptPreprocess(produced, equality, baseNode); + + if (!preprocessResult.isSuccessful()) { + handler.communicateAdapted(adaptedSender, preprocessResult.getFailure()); + + return EMPTY; + } + + PreProcessSearch info = preprocessResult.getSuccess(); + + var searchResult = info.getFoundNode().searchSuggestion(produced, info); + + if (!searchResult.isSuccessful()) { + handler.communicateAdapted(adaptedSender, searchResult.getFailure()); + + return EMPTY; + } + + List> suggestions = searchResult.getSuccess(); + + return suggestionStrategy.order(suggestions,produced); + } + + + +} diff --git a/core/src/main/java/me/aurium/branch/execution/ContextProvider.java b/branch-core/src/main/java/xyz/auriium/branch/base/ContextProvider.java similarity index 84% rename from core/src/main/java/me/aurium/branch/execution/ContextProvider.java rename to branch-core/src/main/java/xyz/auriium/branch/base/ContextProvider.java index 4c6056d..2860f0f 100644 --- a/core/src/main/java/me/aurium/branch/execution/ContextProvider.java +++ b/branch-core/src/main/java/xyz/auriium/branch/base/ContextProvider.java @@ -19,16 +19,13 @@ * */ -package me.aurium.branch.execution; - -import me.aurium.branch.nodes.CommandNode; -import me.aurium.branch.nodes.results.SearchInfo; +package xyz.auriium.branch.base; /** * Represents something that produces specific context based on a platform */ public interface ContextProvider { - NodeContext produce(T sender, String alias, String[] strings, CommandNode baseNode, SearchInfo search); + NodeContext produce(T sender, String alias, String[] strings); } diff --git a/branch-core/src/main/java/xyz/auriium/branch/base/DelegatingEnhancedContext.java b/branch-core/src/main/java/xyz/auriium/branch/base/DelegatingEnhancedContext.java new file mode 100644 index 0000000..1bcd9aa --- /dev/null +++ b/branch-core/src/main/java/xyz/auriium/branch/base/DelegatingEnhancedContext.java @@ -0,0 +1,39 @@ +package xyz.auriium.branch.base; + +import xyz.auriium.branch.results.PostProcessSearch; + +public class DelegatingEnhancedContext implements EnhancedNodeContext { + + private final NodeContext delegate; + private final PostProcessSearch search; + + public DelegatingEnhancedContext(NodeContext delegate, PostProcessSearch search) { + this.delegate = delegate; + this.search = search; + } + + @Override + public T getSender() { + return delegate.getSender(); + } + + @Override + public String getAlias() { + return delegate.getAlias(); + } + + @Override + public String[] getArgs() { + return delegate.getArgs(); + } + + @Override + public boolean hasStringPermissible(String string) { + return delegate.hasStringPermissible(string); + } + + @Override + public PostProcessSearch getProcessedSearch() { + return search; + } +} diff --git a/branch-core/src/main/java/xyz/auriium/branch/base/DelegatingNodeBase.java b/branch-core/src/main/java/xyz/auriium/branch/base/DelegatingNodeBase.java new file mode 100644 index 0000000..4de9947 --- /dev/null +++ b/branch-core/src/main/java/xyz/auriium/branch/base/DelegatingNodeBase.java @@ -0,0 +1,33 @@ +package xyz.auriium.branch.base; + +import xyz.auriium.branch.base.suggestion.SuggestionSearchStrategy; +import xyz.auriium.branch.nodes.CommandNode; +import xyz.auriium.branch.typeadapter.ManagerAdapter; +import xyz.auriium.branch.base.execution.ExecutionSearchStrategy; +import xyz.auriium.branch.nodes.description.Description; +import xyz.auriium.branch.interfacing.exceptional.AnomalyHandler; +import xyz.auriium.branch.nodes.IdentifiableNode; +import xyz.auriium.branch.results.SearcherEquality; + +/** + * Adapting node base that delegates identifier calls to the first node in the base stack. + */ +public class DelegatingNodeBase extends RunNodeBase { + + private final IdentifiableNode baseNode; + + public DelegatingNodeBase(ManagerAdapter adapter, AnomalyHandler handler, IdentifiableNode baseNode, ExecutionSearchStrategy executionStrategy, SuggestionSearchStrategy suggestionStrategy, ContextProvider provider, SearcherEquality equality) { + super(adapter, handler, baseNode, executionStrategy, suggestionStrategy, provider, equality); + this.baseNode = baseNode; + } + + @Override + public Description getDescription() { + return baseNode.getDescription(); + } + + @Override + public String getIdentifier() { + return baseNode.getIdentifier().getLabel(); + } +} diff --git a/branch-core/src/main/java/xyz/auriium/branch/base/EnhancedNodeContext.java b/branch-core/src/main/java/xyz/auriium/branch/base/EnhancedNodeContext.java new file mode 100644 index 0000000..69be2ef --- /dev/null +++ b/branch-core/src/main/java/xyz/auriium/branch/base/EnhancedNodeContext.java @@ -0,0 +1,9 @@ +package xyz.auriium.branch.base; + +import xyz.auriium.branch.results.PostProcessSearch; + +public interface EnhancedNodeContext extends NodeContext { + + PostProcessSearch getProcessedSearch(); + +} diff --git a/branch-core/src/main/java/xyz/auriium/branch/base/NodeBase.java b/branch-core/src/main/java/xyz/auriium/branch/base/NodeBase.java new file mode 100644 index 0000000..e912ec0 --- /dev/null +++ b/branch-core/src/main/java/xyz/auriium/branch/base/NodeBase.java @@ -0,0 +1,61 @@ +/* + * + * Branch + * Copyright © 2021 Aurium + * + * Branch is free software: you can redistribute it and/or modify + * It under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * Branch is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with Branch. If not, see + * and navigate to version 3 of the GNU Affero General Public License. + * + */ + +package xyz.auriium.branch.base; + +import xyz.auriium.branch.nodes.description.Description; + +import java.util.Collections; +import java.util.List; + +/** + * Represents a single command tree as a single executable object, executable by the bound node base. + * You can **technically** simply implement this and pretend it's a normal bukkit command + * I will laugh at you, however. + * + * @param type of input object used by the manager this node base is bound to + */ +public interface NodeBase { + + /** + * Method called when node base desires execution of this object + * @param input input object of the manager (maybe not final adapted object) + * @param alias alias of the command (people like using this in interfacing) + * @param args arguments sent by input object + */ + void execute(I input, String alias, String[] args); + + /** + * Method called when node base desires suggestions to submit to the user + * @param input input object of the manager (maybe not final adapted object) + * @param alias alias of the command (people like using this in interfacing) + * @param args arguments sent by input object + */ + List suggest(I input, String alias, String[] args); + + Description getDescription(); + String getIdentifier(); + + default List getAliases() { + return Collections.emptyList(); + } + +} diff --git a/branch-core/src/main/java/xyz/auriium/branch/base/NodeBaseBuilder.java b/branch-core/src/main/java/xyz/auriium/branch/base/NodeBaseBuilder.java new file mode 100644 index 0000000..8621f72 --- /dev/null +++ b/branch-core/src/main/java/xyz/auriium/branch/base/NodeBaseBuilder.java @@ -0,0 +1,100 @@ +/* + * + * Branch + * Copyright © 2021 Aurium + * + * Branch is free software: you can redistribute it and/or modify + * It under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * Branch is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with Branch. If not, see + * and navigate to version 3 of the GNU Affero General Public License. + * + */ + +package xyz.auriium.branch.base; + +import xyz.auriium.branch.CentralizedManager; +import xyz.auriium.branch.typeadapter.ManagerAdapter; +import xyz.auriium.branch.base.execution.ExecutionSearchStrategy; +import xyz.auriium.branch.interfacing.exceptional.AnomalyHandler; +import xyz.auriium.branch.nodes.IdentifiableNode; +import xyz.auriium.branch.results.SearcherEquality; + +import java.util.*; + +/** + * Default implementation of a class that produces adaptingNodeBases + * + * @param Input type + * @param Adapted type + */ +public class NodeBaseBuilder { + + private final CentralizedManager manager; + + private final ManagerAdapter adapter; + private AnomalyHandler handler; + + private IdentifiableNode node; + private ExecutionSearchStrategy strategy; + private ContextProvider provider; + private SearcherEquality equality; + + public NodeBaseBuilder(CentralizedManager manager, ManagerAdapter adapter) { + this.manager = manager; + this.adapter = adapter; + } + + public NodeBaseBuilder(CentralizedManager manager, ManagerAdapter adapter, ExecutionSearchStrategy strategy, ContextProvider provider, AnomalyHandler handler, SearcherEquality equality) { + this.manager = manager; + this.adapter = adapter; + this.strategy = strategy; + this.provider = provider; + this.handler = handler; + this.equality = equality; + } + + public NodeBaseBuilder withNode(IdentifiableNode node) { + this.node = node; + + return this; + } + + public NodeBaseBuilder customStrategy(ExecutionSearchStrategy strategy) { + this.strategy = strategy; + + return this; + } + + public NodeBaseBuilder customProvider(ContextProvider provider) { + this.provider = provider; + + return this; + } + + public NodeBaseBuilder customInterfacing(AnomalyHandler handler) { + this.handler = handler; + + return this; + } + + + + public void finish() { + Objects.requireNonNull(node, "Node cannot be null!"); + Objects.requireNonNull(strategy, "Strategy cannot be null!"); + Objects.requireNonNull(provider, "Provider cannot be null!"); + Objects.requireNonNull(handler, "AnomalyHandler cannot be null!"); + Objects.requireNonNull(equality, "SearcherEquality cannot be null!"); + + manager.newCommand(new DelegatingNodeBase<>(adapter,handler,node,strategy,provider,equality)); + } +} diff --git a/core/src/main/java/me/aurium/branch/execution/NodeContext.java b/branch-core/src/main/java/xyz/auriium/branch/base/NodeContext.java similarity index 67% rename from core/src/main/java/me/aurium/branch/execution/NodeContext.java rename to branch-core/src/main/java/xyz/auriium/branch/base/NodeContext.java index 467e7df..6058a55 100644 --- a/core/src/main/java/me/aurium/branch/execution/NodeContext.java +++ b/branch-core/src/main/java/xyz/auriium/branch/base/NodeContext.java @@ -19,11 +19,7 @@ * */ -package me.aurium.branch.execution; - -import me.aurium.branch.interfacing.Response; -import me.aurium.branch.nodes.CommandNode; -import me.aurium.branch.nodes.results.SearchInfo; +package xyz.auriium.branch.base; /** @@ -33,23 +29,25 @@ */ public interface NodeContext { + /** + * Gets the parsed sender object used by this object + * @return the sender object + */ T getSender(); - String getAlias(); - String[] getArgs(); - CommandNode getBaseExecutedNode(); - SearchInfo getResults(); /** - * Sends an ugly string to the player using the platform's message handler. Whatever floats your boat! - * @param string string + * Returns the specific name used to execute this command + * @return alias string */ - void stringSender(String string); + String getAlias(); + String[] getArgs(); /** - * Sends a formatted response to a player coded to a key - * @param failure the response + * Gets whether the context's delegating sender has access to a permission. On some platforms, this may always be false. + * @param string the permission + * @return whether it is permissible or not. */ - void response(Response failure); + boolean hasStringPermissible(String string); } diff --git a/branch-core/src/main/java/xyz/auriium/branch/base/RunNodeBase.java b/branch-core/src/main/java/xyz/auriium/branch/base/RunNodeBase.java new file mode 100644 index 0000000..253f23f --- /dev/null +++ b/branch-core/src/main/java/xyz/auriium/branch/base/RunNodeBase.java @@ -0,0 +1,26 @@ +package xyz.auriium.branch.base; + +import xyz.auriium.branch.base.suggestion.SuggestionSearchStrategy; +import xyz.auriium.branch.typeadapter.ManagerAdapter; +import xyz.auriium.branch.base.execution.Execution; +import xyz.auriium.branch.base.execution.ExecutionSearchStrategy; +import xyz.auriium.branch.interfacing.exceptional.AnomalyHandler; +import xyz.auriium.branch.nodes.CommandNode; +import xyz.auriium.branch.results.SearcherEquality; + +/** + * Nodebase that simply runs the execution runnable + * @param input type + * @param adapted type + */ +public abstract class RunNodeBase extends AbstractNodeBase { + + protected RunNodeBase(ManagerAdapter adapter, AnomalyHandler handler, CommandNode baseNode, ExecutionSearchStrategy executionStrategy, SuggestionSearchStrategy suggestionStrategy, ContextProvider provider, SearcherEquality equality) { + super(adapter, handler, baseNode, executionStrategy, suggestionStrategy, provider, equality); + } + + @Override + void submitExecution(Execution execution) { + execution.run(); + } +} diff --git a/branch-core/src/main/java/xyz/auriium/branch/base/execution/ArgExecution.java b/branch-core/src/main/java/xyz/auriium/branch/base/execution/ArgExecution.java new file mode 100644 index 0000000..1b2cf66 --- /dev/null +++ b/branch-core/src/main/java/xyz/auriium/branch/base/execution/ArgExecution.java @@ -0,0 +1,26 @@ +package xyz.auriium.branch.base.execution; + +import xyz.auriium.branch.base.EnhancedNodeContext; +import xyz.auriium.branch.nodes.argument.ArgumentContext; +import xyz.auriium.branch.nodes.argument.ArgumentContextHandler; +import xyz.auriium.branch.nodes.argument.Arguments; + +public class ArgExecution implements Execution { + + private final ArgumentContextHandler handler; + private final EnhancedNodeContext node; + private final Arguments arguments; + + public ArgExecution(ArgumentContextHandler handler, EnhancedNodeContext node, Arguments arguments) { + this.handler = handler; + this.node = node; + this.arguments = arguments; + } + + + @Override + public void run() { + handler.handle(new ArgumentContext<>(node, arguments)); + } + +} diff --git a/branch-core/src/main/java/xyz/auriium/branch/base/execution/BasicExecution.java b/branch-core/src/main/java/xyz/auriium/branch/base/execution/BasicExecution.java new file mode 100644 index 0000000..886a602 --- /dev/null +++ b/branch-core/src/main/java/xyz/auriium/branch/base/execution/BasicExecution.java @@ -0,0 +1,20 @@ +package xyz.auriium.branch.base.execution; + +import xyz.auriium.branch.base.EnhancedNodeContext; + +public class BasicExecution implements Execution { + + private final ExecutionHandler handler; + private final EnhancedNodeContext node; + + public BasicExecution(ExecutionHandler handler, EnhancedNodeContext node) { + this.handler = handler; + this.node = node; + } + + @Override + public void run() { + handler.handle(node); + } + +} diff --git a/core/src/main/java/me/aurium/branch/execution/EmptyExecutionHandler.java b/branch-core/src/main/java/xyz/auriium/branch/base/execution/EmptyExecutionHandler.java similarity index 85% rename from core/src/main/java/me/aurium/branch/execution/EmptyExecutionHandler.java rename to branch-core/src/main/java/xyz/auriium/branch/base/execution/EmptyExecutionHandler.java index 3ba74c8..d8c7381 100644 --- a/core/src/main/java/me/aurium/branch/execution/EmptyExecutionHandler.java +++ b/branch-core/src/main/java/xyz/auriium/branch/base/execution/EmptyExecutionHandler.java @@ -19,13 +19,13 @@ * */ -package me.aurium.branch.execution; +package xyz.auriium.branch.base.execution; -import me.aurium.branch.execution.api.ExecutionHandler; +import xyz.auriium.branch.base.EnhancedNodeContext; public class EmptyExecutionHandler implements ExecutionHandler { @Override - public void handle(NodeContext adapter) { + public void handle(EnhancedNodeContext adapter) { } } diff --git a/core/src/main/java/me/aurium/branch/execution/Block.java b/branch-core/src/main/java/xyz/auriium/branch/base/execution/Execution.java similarity index 73% rename from core/src/main/java/me/aurium/branch/execution/Block.java rename to branch-core/src/main/java/xyz/auriium/branch/base/execution/Execution.java index b8048c1..35dccd0 100644 --- a/core/src/main/java/me/aurium/branch/execution/Block.java +++ b/branch-core/src/main/java/xyz/auriium/branch/base/execution/Execution.java @@ -19,16 +19,14 @@ * */ -package me.aurium.branch.execution; +package xyz.auriium.branch.base.execution; /** - * Represents an unparsed component of a command argument input structure + * Marker runnable representing the supplying of all required dependencies to an execution handler + * or significant derivative and actual execution of said handler. + * + * @param the type */ -public interface Block { - - String getIdentifier(); - - boolean equals(Object object); - boolean isVisual(); +public interface Execution extends Runnable { } diff --git a/core/src/main/java/me/aurium/branch/execution/api/ExecutionHandler.java b/branch-core/src/main/java/xyz/auriium/branch/base/execution/ExecutionHandler.java similarity index 86% rename from core/src/main/java/me/aurium/branch/execution/api/ExecutionHandler.java rename to branch-core/src/main/java/xyz/auriium/branch/base/execution/ExecutionHandler.java index e4e2a1c..73be61f 100644 --- a/core/src/main/java/me/aurium/branch/execution/api/ExecutionHandler.java +++ b/branch-core/src/main/java/xyz/auriium/branch/base/execution/ExecutionHandler.java @@ -19,9 +19,9 @@ * */ -package me.aurium.branch.execution.api; +package xyz.auriium.branch.base.execution; -import me.aurium.branch.execution.NodeContext; +import xyz.auriium.branch.base.EnhancedNodeContext; /** * Functional interface typically used in simple nodes that only need to do one action @@ -30,6 +30,6 @@ @FunctionalInterface public interface ExecutionHandler { - void handle(NodeContext context); + void handle(EnhancedNodeContext context); } diff --git a/core/src/main/java/me/aurium/branch/fallback/strategies/FallbackSearchStrategy.java b/branch-core/src/main/java/xyz/auriium/branch/base/execution/ExecutionSearchStrategy.java similarity index 68% rename from core/src/main/java/me/aurium/branch/fallback/strategies/FallbackSearchStrategy.java rename to branch-core/src/main/java/xyz/auriium/branch/base/execution/ExecutionSearchStrategy.java index 53898d0..7092d8b 100644 --- a/core/src/main/java/me/aurium/branch/fallback/strategies/FallbackSearchStrategy.java +++ b/branch-core/src/main/java/xyz/auriium/branch/base/execution/ExecutionSearchStrategy.java @@ -19,11 +19,13 @@ * */ -package me.aurium.branch.fallback.strategies; +package xyz.auriium.branch.base.execution; -import me.aurium.branch.nodes.CommandNode; -import me.aurium.branch.nodes.results.SearchInfo; -import me.aurium.branch.nodes.results.model.Result; +import xyz.auriium.branch.base.NodeContext; +import xyz.auriium.branch.nodes.CommandNode; +import xyz.auriium.branch.results.PreProcessSearch; +import xyz.auriium.branch.results.SearcherEquality; +import xyz.auriium.branch.results.Result; /** * A strategy to define @@ -32,10 +34,10 @@ * - what happens if a node is unusable * @param */ -public interface FallbackSearchStrategy { +public interface ExecutionSearchStrategy { - Result> attemptPreprocess(T sender, String alias, String[] args, CommandNode baseNode); + Result> attemptPreprocess(NodeContext context, SearcherEquality equality, CommandNode baseNode); } diff --git a/core/src/main/java/me/aurium/branch/fallback/strategies/OneBackStrategy.java b/branch-core/src/main/java/xyz/auriium/branch/base/execution/OneBackStrategy.java similarity index 72% rename from core/src/main/java/me/aurium/branch/fallback/strategies/OneBackStrategy.java rename to branch-core/src/main/java/xyz/auriium/branch/base/execution/OneBackStrategy.java index 9f0e971..cefb62f 100644 --- a/core/src/main/java/me/aurium/branch/fallback/strategies/OneBackStrategy.java +++ b/branch-core/src/main/java/xyz/auriium/branch/base/execution/OneBackStrategy.java @@ -19,17 +19,17 @@ * */ -package me.aurium.branch.fallback.strategies; +package xyz.auriium.branch.base.execution; -import me.aurium.branch.interfacing.responses.NoPermissionResponse; -import me.aurium.branch.nodes.CommandNode; -import me.aurium.branch.nodes.results.SearchInput; -import me.aurium.branch.nodes.results.SearchInfo; -import me.aurium.branch.nodes.results.model.Result; +import xyz.auriium.branch.base.NodeContext; +import xyz.auriium.branch.interfacing.exceptional.anomalies.NoPermissionAnomaly; +import xyz.auriium.branch.nodes.CommandNode; +import xyz.auriium.branch.results.InitialSearch; +import xyz.auriium.branch.results.PreProcessSearch; +import xyz.auriium.branch.results.Result; +import xyz.auriium.branch.results.SearcherEquality; /** - * - * /// FIXME: 5/7/2021 This strat is possibly broken thanks to the update that changes nodes to return execution results. * * Fallback and processing strategy that does the following actions: * @@ -51,25 +51,25 @@ * * @param */ -public class OneBackStrategy implements FallbackSearchStrategy { +public class OneBackStrategy implements ExecutionSearchStrategy { @Override - public Result> attemptPreprocess(T sender, String alias, String[] args, CommandNode baseNode) { + public Result> attemptPreprocess(NodeContext ctx, SearcherEquality equality, CommandNode baseNode) { - SearchInput input = SearchInput.of(args); - Result> toBeExecuted = baseNode.getSpecificNode(input); + InitialSearch search = InitialSearch.of(equality, ctx.getArgs()); + Result> toBeExecuted = baseNode.searchNode(search); //1. Check permissions and access (preprocessing) - while (toBeExecuted.isSuccessful() && !toBeExecuted.getSuccess().resultingNode().getPermission().attempt(sender, alias, args)) { + while (toBeExecuted.isSuccessful() && !toBeExecuted.getSuccess().getFoundNode().getPermission().attempt(ctx)) { //something is wrong with the execution (e.g. wrong args or you did something bad), pass above one. - if (toBeExecuted.getSuccess().resultingNode().equals(baseNode)) { - return Result.fail(new NoPermissionResponse(baseNode.getPermission().failureIdentifiableName())); + if (toBeExecuted.getSuccess().getFoundNode().equals(baseNode)) { + return Result.fail(new NoPermissionAnomaly(baseNode.getPermission().failureIdentifiableName())); } else { - toBeExecuted = baseNode.getSpecificNode(input.withoutTop()); //regress backwards a node + toBeExecuted = baseNode.searchNode(search = InitialSearch.withoutTop(search)); //regress backwards a node //TODO fix all of this } } @@ -77,8 +77,6 @@ public Result> attemptPreprocess(T sender, String alias, String[] } - - //TODO old code - refer to it if you need to /*SearchInput input = SearchInput.of(args); SearchResult toBeExecuted = baseNode.getSpecificNode(input); diff --git a/core/src/main/java/me/aurium/branch/fallback/strategies/PermissionLockoutStrategy.java b/branch-core/src/main/java/xyz/auriium/branch/base/execution/PermissionLockoutStrategy.java similarity index 52% rename from core/src/main/java/me/aurium/branch/fallback/strategies/PermissionLockoutStrategy.java rename to branch-core/src/main/java/xyz/auriium/branch/base/execution/PermissionLockoutStrategy.java index 0b67c80..c3298ba 100644 --- a/core/src/main/java/me/aurium/branch/fallback/strategies/PermissionLockoutStrategy.java +++ b/branch-core/src/main/java/xyz/auriium/branch/base/execution/PermissionLockoutStrategy.java @@ -19,28 +19,32 @@ * */ -package me.aurium.branch.fallback.strategies; +package xyz.auriium.branch.base.execution; -import me.aurium.branch.interfacing.responses.NoPermissionResponse; -import me.aurium.branch.nodes.CommandNode; -import me.aurium.branch.nodes.results.SearchInfo; -import me.aurium.branch.nodes.results.SearchInput; -import me.aurium.branch.nodes.results.model.Result; +import xyz.auriium.branch.base.NodeContext; +import xyz.auriium.branch.interfacing.exceptional.anomalies.NoPermissionAnomaly; +import xyz.auriium.branch.nodes.CommandNode; +import xyz.auriium.branch.results.InitialSearch; +import xyz.auriium.branch.results.PreProcessSearch; +import xyz.auriium.branch.results.Result; +import xyz.auriium.branch.results.SearcherEquality; /** * Simple fallback strategy that if the sender has no permission to execute the command they are sent a failing response. * @param */ -public class PermissionLockoutStrategy implements FallbackSearchStrategy { +public class PermissionLockoutStrategy implements ExecutionSearchStrategy { + @Override - public Result> attemptPreprocess(T sender, String alias, String[] args, CommandNode baseNode) { + public Result> attemptPreprocess(NodeContext ctx, SearcherEquality equality, CommandNode baseNode) { - SearchInput input = SearchInput.of(args); - Result> toBeExecuted = baseNode.getSpecificNode(input); + InitialSearch search = InitialSearch.of(equality, ctx.getArgs()); + Result> toBeExecuted = baseNode.searchNode(search); //peak object oriented code - if (toBeExecuted.isSuccessful() && !toBeExecuted.getSuccess().resultingNode().getPermission().attempt(sender, alias, args)) { - return Result.fail(new NoPermissionResponse(toBeExecuted.getSuccess().resultingNode().getPermission().failureIdentifiableName())); + + if (toBeExecuted.isSuccessful() && !toBeExecuted.getSuccess().getFoundNode().getPermission().attempt(ctx)) { + return Result.fail(new NoPermissionAnomaly(toBeExecuted.getSuccess().getFoundNode().getPermission().failureIdentifiableName())); } return toBeExecuted; diff --git a/branch-core/src/main/java/xyz/auriium/branch/base/execution/blocks/ArgumentBlock.java b/branch-core/src/main/java/xyz/auriium/branch/base/execution/blocks/ArgumentBlock.java new file mode 100644 index 0000000..63d3813 --- /dev/null +++ b/branch-core/src/main/java/xyz/auriium/branch/base/execution/blocks/ArgumentBlock.java @@ -0,0 +1,34 @@ +package xyz.auriium.branch.base.execution.blocks; + +public class ArgumentBlock implements Block { + + private final String label; + private final String argumentType; + private final boolean isOptional; + + public ArgumentBlock(String label, String argumentType, boolean isOptional) { + this.label = label; + this.argumentType = argumentType; + this.isOptional = isOptional; + } + + @Override + public String getLabel() { + return label; + } + + @Override + public String getType() { + return argumentType; + } + + @Override + public BracketPattern getBracketPattern() { + return isOptional ? new BracketPattern('<','>') : new BracketPattern('[',']'); + } + + @Override + public BlockType getTypeObject() { + return isOptional ? BlockType.ARGUMENT_OPTIONAL : BlockType.ARGUMENT_REQUIRED; + } +} diff --git a/branch-core/src/main/java/xyz/auriium/branch/base/execution/blocks/Block.java b/branch-core/src/main/java/xyz/auriium/branch/base/execution/blocks/Block.java new file mode 100644 index 0000000..9d635e8 --- /dev/null +++ b/branch-core/src/main/java/xyz/auriium/branch/base/execution/blocks/Block.java @@ -0,0 +1,84 @@ +/* + * + * Branch + * Copyright © 2021 Aurium + * + * Branch is free software: you can redistribute it and/or modify + * It under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * Branch is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with Branch. If not, see + * and navigate to version 3 of the GNU Affero General Public License. + * + */ + +package xyz.auriium.branch.base.execution.blocks; + +/** + * Represents a Branch-provided identification structure for the identifier of specific structures + */ +public interface Block { + + /** + * Gets the literal identifier of the block + * + * If the object is an endpoint block "join" of /kitpvp join, the identifier is "join" + * (pretty obvious) + * @return the identifier + */ + String getLabel(); + + /** + * Gets the prettified "version" of the block used to display it + * + * If the object is an endpoint block "join" of /kitpvp join, + * the prettified identifier will be "" + * + * @return the pretty string alone + */ + default String getPretty() { + return getBracketPattern().parse(getLabel()); + } + + /** + * Gets identifier and type wrapped with prettified bracketing + * + * If the object is an endpoint block "join" of /kitpvp join, the + * prettified + type string is "" + * + * @return the prettified string + */ + default String getPrettyAndType() { + return getBracketPattern().parse(String.format("%s:%s", getType(), getLabel())); + } + + /** + * Gets just the type string used for this object. Typically delegates to {@link #getTypeObject()} except + * for argument blocks, in which case + * @return the type + */ + String getType(); + + /** + * Returns a bracket pattern for use with {@link #getPretty()} + * @return returns the bracket pattern + */ + BracketPattern getBracketPattern(); + + /** + * Gets the blocktype this belongs to + * @return the blocktype + */ + BlockType getTypeObject(); + + default boolean matches(String string) { + return getLabel().equalsIgnoreCase(string); + } +} diff --git a/branch-core/src/main/java/xyz/auriium/branch/base/execution/blocks/BlockType.java b/branch-core/src/main/java/xyz/auriium/branch/base/execution/blocks/BlockType.java new file mode 100644 index 0000000..682a7fc --- /dev/null +++ b/branch-core/src/main/java/xyz/auriium/branch/base/execution/blocks/BlockType.java @@ -0,0 +1,23 @@ +package xyz.auriium.branch.base.execution.blocks; + +public enum BlockType { + + INPUT("input"), + + LITERAL_GROUP("subgroup"), //used for blocks representing a subgroup's identifier e.g. group in /command group [bar] + LITERAL_ENDPOINT("endpoint"), //used for blocks representing an endpoint command's identifier e.g. help or join in /command help or /command kitpvp join + ARGUMENT_OPTIONAL("optional"), //used for blocks representing a command's optional argument e.g. bar in /command group [bar] + ARGUMENT_REQUIRED("required"), //used for blocks representing a required argument e.g. foo in /command group [bar] + + LITERAL_CUSTOM("custom"); //for framework-user implemented blocks (why?) + + String readable; + + BlockType(String humanReadable) { + readable = humanReadable; + } + + public String getReadable() { + return readable; + } +} diff --git a/branch-core/src/main/java/xyz/auriium/branch/base/execution/blocks/BracketPattern.java b/branch-core/src/main/java/xyz/auriium/branch/base/execution/blocks/BracketPattern.java new file mode 100644 index 0000000..839962d --- /dev/null +++ b/branch-core/src/main/java/xyz/auriium/branch/base/execution/blocks/BracketPattern.java @@ -0,0 +1,32 @@ +package xyz.auriium.branch.base.execution.blocks; + +public class BracketPattern { + + private final Character startChar; + private final Character closeChar; + + public BracketPattern(Character startChar, Character closeChar) { + this.startChar = startChar; + this.closeChar = closeChar; + } + + public String parse(String input) { + StringBuilder builder = new StringBuilder(); + + if (startChar != null) { + builder.append(startChar); + } + + builder.append(input); + + if (closeChar != null) { + builder.append(closeChar); + } + + return builder.toString(); + } + + public static BracketPattern empty() { + return new BracketPattern(null, null); + } +} diff --git a/branch-core/src/main/java/xyz/auriium/branch/base/execution/blocks/EndpointBlock.java b/branch-core/src/main/java/xyz/auriium/branch/base/execution/blocks/EndpointBlock.java new file mode 100644 index 0000000..0f03b20 --- /dev/null +++ b/branch-core/src/main/java/xyz/auriium/branch/base/execution/blocks/EndpointBlock.java @@ -0,0 +1,30 @@ +package xyz.auriium.branch.base.execution.blocks; + +public class EndpointBlock implements Block { + + private final String endpointIdentifier; + + public EndpointBlock(String endpointIdentifier) { + this.endpointIdentifier = endpointIdentifier; + } + + @Override + public String getLabel() { + return endpointIdentifier; + } + + @Override + public String getType() { + return BlockType.LITERAL_ENDPOINT.getReadable(); + } + + @Override + public BracketPattern getBracketPattern() { + return BracketPattern.empty(); + } + + @Override + public BlockType getTypeObject() { + return BlockType.LITERAL_ENDPOINT; + } +} diff --git a/branch-core/src/main/java/xyz/auriium/branch/base/execution/blocks/GroupBlock.java b/branch-core/src/main/java/xyz/auriium/branch/base/execution/blocks/GroupBlock.java new file mode 100644 index 0000000..6555fba --- /dev/null +++ b/branch-core/src/main/java/xyz/auriium/branch/base/execution/blocks/GroupBlock.java @@ -0,0 +1,30 @@ +package xyz.auriium.branch.base.execution.blocks; + +public class GroupBlock implements Block { + + private final String groupName; + + public GroupBlock(String groupName) { + this.groupName = groupName; + } + + @Override + public String getLabel() { + return groupName; + } + + @Override + public String getType() { + return BlockType.LITERAL_GROUP.getReadable(); + } + + @Override + public BracketPattern getBracketPattern() { + return BracketPattern.empty(); + } + + @Override + public BlockType getTypeObject() { + return BlockType.LITERAL_GROUP; + } +} diff --git a/core/src/main/java/me/aurium/branch/fallback/permissions/EmptyPermission.java b/branch-core/src/main/java/xyz/auriium/branch/base/permissions/EmptyPermission.java similarity index 72% rename from core/src/main/java/me/aurium/branch/fallback/permissions/EmptyPermission.java rename to branch-core/src/main/java/xyz/auriium/branch/base/permissions/EmptyPermission.java index 01c9677..5dc8c91 100644 --- a/core/src/main/java/me/aurium/branch/fallback/permissions/EmptyPermission.java +++ b/branch-core/src/main/java/xyz/auriium/branch/base/permissions/EmptyPermission.java @@ -19,7 +19,9 @@ * */ -package me.aurium.branch.fallback.permissions; +package xyz.auriium.branch.base.permissions; + +import xyz.auriium.branch.base.NodeContext; /** * Represents a permission that is always true @@ -27,8 +29,12 @@ */ public class EmptyPermission implements Permission { + private static final EmptyPermission INSTANCE = new EmptyPermission<>(); + + EmptyPermission() {} + @Override - public boolean attempt(T sender, String alias, String[] args) { + public boolean attempt(NodeContext nodeContext) { return true; } @@ -36,4 +42,9 @@ public boolean attempt(T sender, String alias, String[] args) { public String failureIdentifiableName() { return "None"; } + + @SuppressWarnings("unchecked") + public static EmptyPermission instance() { + return (EmptyPermission) INSTANCE; + } } diff --git a/core/src/main/java/me/aurium/branch/fallback/permissions/Permission.java b/branch-core/src/main/java/xyz/auriium/branch/base/permissions/Permission.java similarity index 69% rename from core/src/main/java/me/aurium/branch/fallback/permissions/Permission.java rename to branch-core/src/main/java/xyz/auriium/branch/base/permissions/Permission.java index ab13801..a338e37 100644 --- a/core/src/main/java/me/aurium/branch/fallback/permissions/Permission.java +++ b/branch-core/src/main/java/xyz/auriium/branch/base/permissions/Permission.java @@ -19,9 +19,9 @@ * */ -package me.aurium.branch.fallback.permissions; +package xyz.auriium.branch.base.permissions; -import me.aurium.branch.execution.NodeContext; +import xyz.auriium.branch.base.NodeContext; /** * Represents the accessibility predicate of a command -> whether a command can be executed or not @@ -29,17 +29,13 @@ public interface Permission { /** - * Checks whether the sender has acccess or not - * @param sender sender - * @param alias alias - * @param args args - * @return true if so, false if not + * Method describing whether the permission accepts the context + * + * + * @param nodeContext ctx + * @return true if permission is had, otherwise false */ - boolean attempt(T sender, String alias, String[] args); //because fuck you - - default boolean attempt(NodeContext nodeContext) { - return attempt(nodeContext.getSender(),nodeContext.getAlias(), nodeContext.getArgs()); - } + boolean attempt(NodeContext nodeContext); /** * Represents the name shown when the permission fails. diff --git a/core/src/main/java/me/aurium/branch/fallback/permissions/PredicatePermission.java b/branch-core/src/main/java/xyz/auriium/branch/base/permissions/PredicatePermission.java similarity index 78% rename from core/src/main/java/me/aurium/branch/fallback/permissions/PredicatePermission.java rename to branch-core/src/main/java/xyz/auriium/branch/base/permissions/PredicatePermission.java index 53c55b3..44cba9a 100644 --- a/core/src/main/java/me/aurium/branch/fallback/permissions/PredicatePermission.java +++ b/branch-core/src/main/java/xyz/auriium/branch/base/permissions/PredicatePermission.java @@ -19,7 +19,9 @@ * */ -package me.aurium.branch.fallback.permissions; +package xyz.auriium.branch.base.permissions; + +import xyz.auriium.branch.base.NodeContext; import java.util.function.Predicate; @@ -30,16 +32,16 @@ public class PredicatePermission implements Permission { private final String easyName; - private final Predicate predicate; + private final Predicate> predicate; - public PredicatePermission(String easyName, Predicate predicate) { + public PredicatePermission(String easyName, Predicate> predicate) { this.easyName = easyName; this.predicate = predicate; } @Override - public boolean attempt(T sender, String alias, String[] args) { - return predicate.test(sender); + public boolean attempt(NodeContext ctx) { + return predicate.test(ctx); } @Override diff --git a/branch-core/src/main/java/xyz/auriium/branch/base/permissions/StringPermission.java b/branch-core/src/main/java/xyz/auriium/branch/base/permissions/StringPermission.java new file mode 100644 index 0000000..4b5d971 --- /dev/null +++ b/branch-core/src/main/java/xyz/auriium/branch/base/permissions/StringPermission.java @@ -0,0 +1,22 @@ +package xyz.auriium.branch.base.permissions; + +import xyz.auriium.branch.base.NodeContext; + +public class StringPermission implements Permission { + + private final String permissionNode; + + public StringPermission(String permissionNode) { + this.permissionNode = permissionNode; + } + + @Override + public boolean attempt(NodeContext nodeContext) { + return nodeContext.hasStringPermissible(permissionNode); + } + + @Override + public String failureIdentifiableName() { + return permissionNode; + } +} diff --git a/branch-core/src/main/java/xyz/auriium/branch/base/suggestion/AbstractSuggestionSearchStrategy.java b/branch-core/src/main/java/xyz/auriium/branch/base/suggestion/AbstractSuggestionSearchStrategy.java new file mode 100644 index 0000000..88006ae --- /dev/null +++ b/branch-core/src/main/java/xyz/auriium/branch/base/suggestion/AbstractSuggestionSearchStrategy.java @@ -0,0 +1,46 @@ +package xyz.auriium.branch.base.suggestion; + +import xyz.auriium.branch.base.NodeContext; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +/** + * Abstract suggestion strategy handler that + * @param + */ +public abstract class AbstractSuggestionSearchStrategy implements SuggestionSearchStrategy { + + @Override + public List order(List> suggestions, NodeContext ctx) { + String[] strings = ctx.getArgs(); + + return copyPartialMatches(strings[strings.length - 1], order(suggestions, ctx)); + } + + abstract List orderThen(List> suggestions, NodeContext ctx); + + private List copyPartialMatches(final String token, final Collection originals) throws UnsupportedOperationException, IllegalArgumentException { + + List results = new ArrayList<>(); + + for (String string : originals) { + + if (startsWithIgnoreCase(string, token)) { + results.add(string); + } + + } + + return results; + } + + private boolean startsWithIgnoreCase(final String string, final String prefix) throws IllegalArgumentException, NullPointerException { + if (string.length() < prefix.length()) { + return false; + } + return string.regionMatches(true, 0, prefix, 0, prefix.length()); + } + +} diff --git a/branch-core/src/main/java/xyz/auriium/branch/base/suggestion/CommonSuggestionSearchStrategy.java b/branch-core/src/main/java/xyz/auriium/branch/base/suggestion/CommonSuggestionSearchStrategy.java new file mode 100644 index 0000000..3cd4e14 --- /dev/null +++ b/branch-core/src/main/java/xyz/auriium/branch/base/suggestion/CommonSuggestionSearchStrategy.java @@ -0,0 +1,32 @@ +package xyz.auriium.branch.base.suggestion; + +import xyz.auriium.branch.base.NodeContext; + +import java.util.ArrayList; +import java.util.List; + +public class CommonSuggestionSearchStrategy extends AbstractSuggestionSearchStrategy { + + private final boolean hideNoPermissions; + + public CommonSuggestionSearchStrategy(boolean hideNoPermissions) { + this.hideNoPermissions = hideNoPermissions; + } + + @Override + List orderThen(List> suggestions, NodeContext ctx) { + + List strings = new ArrayList<>(); + + for (Suggestion suggestion : suggestions) { + if (hideNoPermissions) { + if (!suggestion.getPermission().attempt(ctx)) continue; + } + + + strings.add(suggestion.getIdentifier().getLabel()); + } + + return strings; + } +} diff --git a/branch-core/src/main/java/xyz/auriium/branch/base/suggestion/Suggestion.java b/branch-core/src/main/java/xyz/auriium/branch/base/suggestion/Suggestion.java new file mode 100644 index 0000000..7d1a7db --- /dev/null +++ b/branch-core/src/main/java/xyz/auriium/branch/base/suggestion/Suggestion.java @@ -0,0 +1,23 @@ +package xyz.auriium.branch.base.suggestion; + +import xyz.auriium.branch.base.execution.blocks.Block; +import xyz.auriium.branch.base.permissions.Permission; + +public class Suggestion { + + private final Permission permission; + private final Block identifier; + + public Suggestion(Permission permission, Block identifier) { + this.permission = permission; + this.identifier = identifier; + } + + public Permission getPermission() { + return permission; + } + + public Block getIdentifier() { + return identifier; + } +} diff --git a/core/src/main/java/me/aurium/branch/execution/api/SuggestionHandler.java b/branch-core/src/main/java/xyz/auriium/branch/base/suggestion/SuggestionHandler.java similarity index 84% rename from core/src/main/java/me/aurium/branch/execution/api/SuggestionHandler.java rename to branch-core/src/main/java/xyz/auriium/branch/base/suggestion/SuggestionHandler.java index cac21fc..b726429 100644 --- a/core/src/main/java/me/aurium/branch/execution/api/SuggestionHandler.java +++ b/branch-core/src/main/java/xyz/auriium/branch/base/suggestion/SuggestionHandler.java @@ -19,10 +19,9 @@ * */ -package me.aurium.branch.execution.api; +package xyz.auriium.branch.base.suggestion; -import me.aurium.branch.execution.Block; -import me.aurium.branch.execution.NodeContext; +import xyz.auriium.branch.base.NodeContext; import java.util.List; @@ -33,6 +32,6 @@ @FunctionalInterface public interface SuggestionHandler { - List handle(NodeContext context); + List handle(NodeContext context); } diff --git a/branch-core/src/main/java/xyz/auriium/branch/base/suggestion/SuggestionSearchStrategy.java b/branch-core/src/main/java/xyz/auriium/branch/base/suggestion/SuggestionSearchStrategy.java new file mode 100644 index 0000000..ea28ec7 --- /dev/null +++ b/branch-core/src/main/java/xyz/auriium/branch/base/suggestion/SuggestionSearchStrategy.java @@ -0,0 +1,16 @@ +package xyz.auriium.branch.base.suggestion; + +import xyz.auriium.branch.base.NodeContext; + +import java.util.List; + +/** + * Retrieves a single suggestion completion based on contextual arguments: likely delegates to the nodes themselves + * as well as an adapter for conversion of type + * @param input type + */ +public interface SuggestionSearchStrategy { + + List order(List> suggestions, NodeContext ctx); + +} diff --git a/core/src/main/java/me/aurium/branch/interfacing/Message.java b/branch-core/src/main/java/xyz/auriium/branch/interfacing/Message.java similarity index 96% rename from core/src/main/java/me/aurium/branch/interfacing/Message.java rename to branch-core/src/main/java/xyz/auriium/branch/interfacing/Message.java index 11653ca..18905a8 100644 --- a/core/src/main/java/me/aurium/branch/interfacing/Message.java +++ b/branch-core/src/main/java/xyz/auriium/branch/interfacing/Message.java @@ -19,7 +19,7 @@ * */ -package me.aurium.branch.interfacing; +package xyz.auriium.branch.interfacing; /** * Represents the final stage of something that occur after a response has been consumed diff --git a/branch-core/src/main/java/xyz/auriium/branch/interfacing/MessageBoss.java b/branch-core/src/main/java/xyz/auriium/branch/interfacing/MessageBoss.java new file mode 100644 index 0000000..55fa725 --- /dev/null +++ b/branch-core/src/main/java/xyz/auriium/branch/interfacing/MessageBoss.java @@ -0,0 +1,22 @@ +package xyz.auriium.branch.interfacing; + +/** + * MessageBoss represents message sending class - if a command sender fails adaptation or never even reaches adaptation + * phase it will be sent a message via type I interfacer, otherwise it will be sent a message via type A interfacer + * + * @param type I interfacer (I for initial type) handles communication with initial user + * @param type A of adapted type handles communication with converted user + * @param message object type (like Component for kyori or BreakMessage for default) + */ +public interface MessageBoss { + + void sendMessageToInitial(String message, I initialType); + void sendMessageToAdapted(String message, A adaptedType); + + void sendObjectToInitial(M message, I initialType); + void sendObjectToAdapted(M message, A adaptedType); + + + + +} diff --git a/branch-core/src/main/java/xyz/auriium/branch/interfacing/MessageWorker.java b/branch-core/src/main/java/xyz/auriium/branch/interfacing/MessageWorker.java new file mode 100644 index 0000000..e28a4d9 --- /dev/null +++ b/branch-core/src/main/java/xyz/auriium/branch/interfacing/MessageWorker.java @@ -0,0 +1,13 @@ +package xyz.auriium.branch.interfacing; + +/** + * Represents a subcomponent of a {@link xyz.auriium.branch.interfacing.MessageBoss} that only handles one type + * @param Type + * @param Message object type + */ +public interface MessageWorker { + + void sendMessage(String message, T type); + void sendObject(M message, T type); + +} diff --git a/core/src/main/java/me/aurium/branch/interfacing/ResponseAction.java b/branch-core/src/main/java/xyz/auriium/branch/interfacing/ResponseAction.java similarity index 85% rename from core/src/main/java/me/aurium/branch/interfacing/ResponseAction.java rename to branch-core/src/main/java/xyz/auriium/branch/interfacing/ResponseAction.java index b6a0e8a..02a7e1d 100644 --- a/core/src/main/java/me/aurium/branch/interfacing/ResponseAction.java +++ b/branch-core/src/main/java/xyz/auriium/branch/interfacing/ResponseAction.java @@ -19,14 +19,16 @@ * */ -package me.aurium.branch.interfacing; +package xyz.auriium.branch.interfacing; + +import xyz.auriium.branch.interfacing.exceptional.Anomaly; /** * Represents an action that is fired when a response is received * @param t * @param c */ -public interface ResponseAction { +public interface ResponseAction { Message consume(C response); diff --git a/branch-core/src/main/java/xyz/auriium/branch/interfacing/WorkerMessageBoss.java b/branch-core/src/main/java/xyz/auriium/branch/interfacing/WorkerMessageBoss.java new file mode 100644 index 0000000..0099e63 --- /dev/null +++ b/branch-core/src/main/java/xyz/auriium/branch/interfacing/WorkerMessageBoss.java @@ -0,0 +1,35 @@ +package xyz.auriium.branch.interfacing; + +/** + * MessageBoss thta delegates to two MessageWorker + */ +public class WorkerMessageBoss implements MessageBoss { + + private final MessageWorker initialWorker; + private final MessageWorker adaptedWorker; + + public WorkerMessageBoss(MessageWorker initialWorker, MessageWorker adaptedWorker) { + this.initialWorker = initialWorker; + this.adaptedWorker = adaptedWorker; + } + + @Override + public void sendMessageToInitial(String message, I initialType) { + this.initialWorker.sendMessage(message, initialType); + } + + @Override + public void sendMessageToAdapted(String message, A adaptedType) { + this.adaptedWorker.sendMessage(message, adaptedType); + } + + @Override + public void sendObjectToInitial(M message, I initialType) { + this.initialWorker.sendObject(message, initialType); + } + + @Override + public void sendObjectToAdapted(M message, A adaptedType) { + this.adaptedWorker.sendObject(message, adaptedType); + } +} diff --git a/core/src/main/java/me/aurium/branch/interfacing/Response.java b/branch-core/src/main/java/xyz/auriium/branch/interfacing/exceptional/Anomaly.java similarity index 68% rename from core/src/main/java/me/aurium/branch/interfacing/Response.java rename to branch-core/src/main/java/xyz/auriium/branch/interfacing/exceptional/Anomaly.java index ad1b88a..c120e66 100644 --- a/core/src/main/java/me/aurium/branch/interfacing/Response.java +++ b/branch-core/src/main/java/xyz/auriium/branch/interfacing/exceptional/Anomaly.java @@ -19,11 +19,16 @@ * */ -package me.aurium.branch.interfacing; +package xyz.auriium.branch.interfacing.exceptional; /** - * Marker interface for a data-carrying object that can be consumed by a responseActionhandler + * Marker interface for a data-carrying control flow object that is + * similar to an exception. Key distinction in that it + * does not interrupt control flow by existing but rather must be manually + * returned. Typically carries data, consumed by a responseActionhandler */ -public interface Response { +public interface Anomaly { + + AnomalyType type(); } diff --git a/branch-core/src/main/java/xyz/auriium/branch/interfacing/exceptional/AnomalyHandler.java b/branch-core/src/main/java/xyz/auriium/branch/interfacing/exceptional/AnomalyHandler.java new file mode 100644 index 0000000..4b8880f --- /dev/null +++ b/branch-core/src/main/java/xyz/auriium/branch/interfacing/exceptional/AnomalyHandler.java @@ -0,0 +1,26 @@ +package xyz.auriium.branch.interfacing.exceptional; + +/** + * Represents the most outer-facing interface for interacting with and handling thrown anomalies and + * sending them to the player (interfacing). + * + * Typically delegates actual message handling to a {@link xyz.auriium.branch.interfacing.MessageBoss}, + * whereas retrieval of captions to a {@link xyz.auriium.branch.interfacing.exceptional.caption.AnomalyCaptioner} + */ +public interface AnomalyHandler { + + /** + * Communicates an anomaly to the user and/or to console + * @param notAdapted the anomaly + * @param anomaly the exceptional anomaly + */ + void communicateNotAdapted(I notAdapted, Anomaly anomaly); + + /** + * Commuicates an anomaly to the adapted user + * @param adapted adapted user + * @param anomaly anomaly + */ + void communicateAdapted(A adapted, Anomaly anomaly); + +} diff --git a/branch-core/src/main/java/xyz/auriium/branch/interfacing/exceptional/AnomalyType.java b/branch-core/src/main/java/xyz/auriium/branch/interfacing/exceptional/AnomalyType.java new file mode 100644 index 0000000..a24fe75 --- /dev/null +++ b/branch-core/src/main/java/xyz/auriium/branch/interfacing/exceptional/AnomalyType.java @@ -0,0 +1,10 @@ +package xyz.auriium.branch.interfacing.exceptional; + +public enum AnomalyType { + + INVALID_SYNTAX, + INVALID_SENDER, + NO_PERMISSION, + ARGUMENT_PARSING + +} diff --git a/branch-core/src/main/java/xyz/auriium/branch/interfacing/exceptional/CommonAnomalyHandler.java b/branch-core/src/main/java/xyz/auriium/branch/interfacing/exceptional/CommonAnomalyHandler.java new file mode 100644 index 0000000..a7ed170 --- /dev/null +++ b/branch-core/src/main/java/xyz/auriium/branch/interfacing/exceptional/CommonAnomalyHandler.java @@ -0,0 +1,32 @@ +package xyz.auriium.branch.interfacing.exceptional; + +import xyz.auriium.branch.interfacing.MessageBoss; +import xyz.auriium.branch.interfacing.exceptional.caption.AnomalyCaptioner; +import xyz.auriium.branch.interfacing.exceptional.printing.AnomalyPrinter; + +public class CommonAnomalyHandler implements AnomalyHandler{ + + private final MessageBoss messageBoss; + private final AnomalyPrinter handler; + private final AnomalyCaptioner captioner; + + public CommonAnomalyHandler(MessageBoss messageBoss, AnomalyPrinter handler, AnomalyCaptioner captioner) { + this.messageBoss = messageBoss; + this.handler = handler; + this.captioner = captioner; + } + + @Override + public void communicateNotAdapted(I notAdapted, Anomaly anomaly) { + messageBoss.sendObjectToInitial(make(anomaly), notAdapted); + } + + @Override + public void communicateAdapted(A adapted, Anomaly anomaly) { + messageBoss.sendObjectToAdapted(make(anomaly), adapted); + } + + M make(Anomaly anomaly) { + return handler.makeMessage(anomaly.type(), captioner.retrieveMessage(anomaly)); + } +} diff --git a/core/src/main/java/me/aurium/branch/interfacing/responses/NoPermissionResponse.java b/branch-core/src/main/java/xyz/auriium/branch/interfacing/exceptional/anomalies/NoPermissionAnomaly.java similarity index 68% rename from core/src/main/java/me/aurium/branch/interfacing/responses/NoPermissionResponse.java rename to branch-core/src/main/java/xyz/auriium/branch/interfacing/exceptional/anomalies/NoPermissionAnomaly.java index dc50a4f..a98de67 100644 --- a/core/src/main/java/me/aurium/branch/interfacing/responses/NoPermissionResponse.java +++ b/branch-core/src/main/java/xyz/auriium/branch/interfacing/exceptional/anomalies/NoPermissionAnomaly.java @@ -19,19 +19,28 @@ * */ -package me.aurium.branch.interfacing.responses; +package xyz.auriium.branch.interfacing.exceptional.anomalies; -import me.aurium.branch.interfacing.Response; +import xyz.auriium.branch.interfacing.exceptional.Anomaly; +import xyz.auriium.branch.interfacing.exceptional.AnomalyType; -public class NoPermissionResponse implements Response { +/** + * Response fired when someone lacks a permission + */ +public class NoPermissionAnomaly implements Anomaly { private final String lackingPermission; - public NoPermissionResponse(String lackingPermission) { + public NoPermissionAnomaly(String lackingPermission) { this.lackingPermission = lackingPermission; } public String getLackingPermission() { return lackingPermission; } + + @Override + public AnomalyType type() { + return AnomalyType.NO_PERMISSION; + } } diff --git a/branch-core/src/main/java/xyz/auriium/branch/interfacing/exceptional/anomalies/TooFewInputsExternalAnomaly.java b/branch-core/src/main/java/xyz/auriium/branch/interfacing/exceptional/anomalies/TooFewInputsExternalAnomaly.java new file mode 100644 index 0000000..812906e --- /dev/null +++ b/branch-core/src/main/java/xyz/auriium/branch/interfacing/exceptional/anomalies/TooFewInputsExternalAnomaly.java @@ -0,0 +1,11 @@ +package xyz.auriium.branch.interfacing.exceptional.anomalies; + +import xyz.auriium.branch.interfacing.exceptional.Anomaly; +import xyz.auriium.branch.interfacing.exceptional.AnomalyType; + +public class TooFewInputsExternalAnomaly implements Anomaly { + @Override + public AnomalyType type() { + return AnomalyType.INVALID_SYNTAX; + } +} diff --git a/branch-core/src/main/java/xyz/auriium/branch/interfacing/exceptional/anomalies/TooFewInputsInternalAnomaly.java b/branch-core/src/main/java/xyz/auriium/branch/interfacing/exceptional/anomalies/TooFewInputsInternalAnomaly.java new file mode 100644 index 0000000..24d1087 --- /dev/null +++ b/branch-core/src/main/java/xyz/auriium/branch/interfacing/exceptional/anomalies/TooFewInputsInternalAnomaly.java @@ -0,0 +1,12 @@ +package xyz.auriium.branch.interfacing.exceptional.anomalies; + +import xyz.auriium.branch.interfacing.exceptional.Anomaly; +import xyz.auriium.branch.interfacing.exceptional.AnomalyType; + +public class TooFewInputsInternalAnomaly implements Anomaly { + + @Override + public AnomalyType type() { + return AnomalyType.INVALID_SYNTAX; + } +} diff --git a/core/src/main/java/me/aurium/branch/interfacing/responses/FailedAdaptingResponse.java b/branch-core/src/main/java/xyz/auriium/branch/interfacing/exceptional/anomalies/WrongTypeParseAnomaly.java similarity index 73% rename from core/src/main/java/me/aurium/branch/interfacing/responses/FailedAdaptingResponse.java rename to branch-core/src/main/java/xyz/auriium/branch/interfacing/exceptional/anomalies/WrongTypeParseAnomaly.java index 6bf9ddd..a998065 100644 --- a/core/src/main/java/me/aurium/branch/interfacing/responses/FailedAdaptingResponse.java +++ b/branch-core/src/main/java/xyz/auriium/branch/interfacing/exceptional/anomalies/WrongTypeParseAnomaly.java @@ -19,20 +19,22 @@ * */ -package me.aurium.branch.interfacing.responses; +package xyz.auriium.branch.interfacing.exceptional.anomalies; -import me.aurium.branch.interfacing.Response; +import xyz.auriium.branch.interfacing.exceptional.Anomaly; +import xyz.auriium.branch.interfacing.exceptional.AnomalyHandler; +import xyz.auriium.branch.interfacing.exceptional.AnomalyType; /** * Represents a response to the scenario in which a certain object was attempted to be adapted to an extending type * but it was not an instance of it (or similar scenarios, such as attempting to flatmap a certain type to another.) */ -public class FailedAdaptingResponse implements Response { +public class WrongTypeParseAnomaly implements Anomaly { private final Class expectedClass; private final Class receivedClass; - public FailedAdaptingResponse(Class expectedClass, Class receivedClass) { + public WrongTypeParseAnomaly(Class expectedClass, Class receivedClass) { this.expectedClass = expectedClass; this.receivedClass = receivedClass; } @@ -45,4 +47,8 @@ public Class getReceivedClass() { return receivedClass; } + @Override + public AnomalyType type() { + return AnomalyType.INVALID_SENDER; + } } diff --git a/branch-core/src/main/java/xyz/auriium/branch/interfacing/exceptional/caption/AnomalyCaptioner.java b/branch-core/src/main/java/xyz/auriium/branch/interfacing/exceptional/caption/AnomalyCaptioner.java new file mode 100644 index 0000000..f1afe03 --- /dev/null +++ b/branch-core/src/main/java/xyz/auriium/branch/interfacing/exceptional/caption/AnomalyCaptioner.java @@ -0,0 +1,13 @@ +package xyz.auriium.branch.interfacing.exceptional.caption; + +import xyz.auriium.branch.interfacing.exceptional.Anomaly; + +/** + * Represents something that can handle anomalies and retrieve stringly simplified messages based on them + * These messages are then distributed to a AnomalyPrinter. + */ +public interface AnomalyCaptioner { + + M retrieveMessage(Anomaly anomaly); + +} diff --git a/branch-core/src/main/java/xyz/auriium/branch/interfacing/exceptional/caption/CommonAnomalyCaptioner.java b/branch-core/src/main/java/xyz/auriium/branch/interfacing/exceptional/caption/CommonAnomalyCaptioner.java new file mode 100644 index 0000000..951cfdc --- /dev/null +++ b/branch-core/src/main/java/xyz/auriium/branch/interfacing/exceptional/caption/CommonAnomalyCaptioner.java @@ -0,0 +1,31 @@ +package xyz.auriium.branch.interfacing.exceptional.caption; + +import xyz.auriium.branch.interfacing.exceptional.Anomaly; + +import java.util.HashMap; +import java.util.Map; +import java.util.function.Function; + +public class CommonAnomalyCaptioner implements SettableCaptioner { + + private final Map, Function> records = new HashMap<>(); + + @Override + public M retrieveMessage(Anomaly anomaly) { + return retrieve(anomaly).apply(anomaly); + } + + @SuppressWarnings("unchecked") + private Function retrieve(A anomaly) { + return (Function) records.get(anomaly.getClass()); + } + + @Override + public SettableCaptioner set(Class anomalyType, Function parser) { + records.put(anomalyType, parser); + + return this; + } + + +} diff --git a/branch-core/src/main/java/xyz/auriium/branch/interfacing/exceptional/caption/SettableCaptioner.java b/branch-core/src/main/java/xyz/auriium/branch/interfacing/exceptional/caption/SettableCaptioner.java new file mode 100644 index 0000000..573a0bd --- /dev/null +++ b/branch-core/src/main/java/xyz/auriium/branch/interfacing/exceptional/caption/SettableCaptioner.java @@ -0,0 +1,11 @@ +package xyz.auriium.branch.interfacing.exceptional.caption; + +import xyz.auriium.branch.interfacing.exceptional.Anomaly; + +import java.util.function.Function; + +public interface SettableCaptioner extends AnomalyCaptioner { + + SettableCaptioner set(Class anomalyType, Function parser); + +} diff --git a/branch-core/src/main/java/xyz/auriium/branch/interfacing/exceptional/printing/AnomalyPrinter.java b/branch-core/src/main/java/xyz/auriium/branch/interfacing/exceptional/printing/AnomalyPrinter.java new file mode 100644 index 0000000..3a3c623 --- /dev/null +++ b/branch-core/src/main/java/xyz/auriium/branch/interfacing/exceptional/printing/AnomalyPrinter.java @@ -0,0 +1,13 @@ +package xyz.auriium.branch.interfacing.exceptional.printing; + +import xyz.auriium.branch.interfacing.exceptional.AnomalyType; + +/** + * Printer that converts anomaly type + message into message object + * @param message object + */ +public interface AnomalyPrinter { + + M makeMessage(AnomalyType type, M initial); + +} diff --git a/branch-core/src/main/java/xyz/auriium/branch/interfacing/exceptional/printing/SettablePrinter.java b/branch-core/src/main/java/xyz/auriium/branch/interfacing/exceptional/printing/SettablePrinter.java new file mode 100644 index 0000000..0403123 --- /dev/null +++ b/branch-core/src/main/java/xyz/auriium/branch/interfacing/exceptional/printing/SettablePrinter.java @@ -0,0 +1,31 @@ +package xyz.auriium.branch.interfacing.exceptional.printing; + +import xyz.auriium.branch.interfacing.exceptional.AnomalyType; + +import java.util.HashMap; +import java.util.Map; +import java.util.function.Function; + +public abstract class SettablePrinter implements AnomalyPrinter { + + private final Map> map = new HashMap<>(); + + @Override + public M makeMessage(AnomalyType type, M string) { + var func = map.get(type); + + if (func == null) throw new IllegalStateException("No type parser found for type: " + type.name()); + + return func.apply(string); + } + + public SettablePrinter add(AnomalyType type, Function function) { + this.map.put(type,function); + + return this; + } + + + + +} diff --git a/branch-core/src/main/java/xyz/auriium/branch/interfacing/exceptional/printing/StringlyPrinter.java b/branch-core/src/main/java/xyz/auriium/branch/interfacing/exceptional/printing/StringlyPrinter.java new file mode 100644 index 0000000..e2e42ea --- /dev/null +++ b/branch-core/src/main/java/xyz/auriium/branch/interfacing/exceptional/printing/StringlyPrinter.java @@ -0,0 +1,15 @@ +package xyz.auriium.branch.interfacing.exceptional.printing; + +import xyz.auriium.branch.interfacing.exceptional.AnomalyType; + +public class StringlyPrinter extends SettablePrinter { + + public static SettablePrinter defaults() { + return new StringlyPrinter() + .add(AnomalyType.ARGUMENT_PARSING, s -> "Error parsing argument: " + s) + .add(AnomalyType.INVALID_SENDER, s -> "Invalid sender: " + s) + .add(AnomalyType.INVALID_SYNTAX, s -> "Invalid syntax: " + s) + .add(AnomalyType.NO_PERMISSION, s -> "No permission to execute command!"); + } + +} diff --git a/branch-core/src/main/java/xyz/auriium/branch/nodes/CommandNode.java b/branch-core/src/main/java/xyz/auriium/branch/nodes/CommandNode.java new file mode 100644 index 0000000..ecda1f1 --- /dev/null +++ b/branch-core/src/main/java/xyz/auriium/branch/nodes/CommandNode.java @@ -0,0 +1,75 @@ +/* + * + * Branch + * Copyright © 2021 Aurium + * + * Branch is free software: you can redistribute it and/or modify + * It under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * Branch is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with Branch. If not, see + * and navigate to version 3 of the GNU Affero General Public License. + * + */ + +package xyz.auriium.branch.nodes; + +import xyz.auriium.branch.base.NodeContext; +import xyz.auriium.branch.base.execution.Execution; +import xyz.auriium.branch.base.suggestion.Suggestion; +import xyz.auriium.branch.nodes.description.Description; +import xyz.auriium.branch.base.permissions.Permission; +import xyz.auriium.branch.results.Result; +import xyz.auriium.branch.results.InitialSearch; +import xyz.auriium.branch.results.PreProcessSearch; + +import java.util.List; + +/** + * Base object + * @param fuck + */ +public interface CommandNode { + + //int getExpectedConsumeAmount() //used to check how much was expected as you pass through vs how much was received, among other htings. + + /** + * Suggestion-handling analogy to + * + * @return returns a result containing all suggestions + */ + Result>> searchSuggestion(NodeContext ctx, PreProcessSearch input); + + /** + * Method called first. Locates the node to execute and adds all found nodes along the path to the SearcherOutput + * + * Is not finished since some nodes still need to add blocks to the final output + * + * @return a result containing the node required and all initial blocks found. + */ + Result> searchNode(InitialSearch input); + + /** + * Method called next. Typically adds all node-specific blocks to the search + * and returns an execution. + * + * @return execution of the node + */ + Result> searchExecute(NodeContext ctx, PreProcessSearch input); + + + /** + * Gets the permission required to execute and interact with this node. Depending on the base, this may cause the node to become locked, or just completely be ignored. + * @return the permission binding + */ + Permission getPermission(); + Description getDescription(); + +} diff --git a/core/src/main/java/me/aurium/branch/nodes/single/EndpointNode.java b/branch-core/src/main/java/xyz/auriium/branch/nodes/EndpointNode.java similarity index 52% rename from core/src/main/java/me/aurium/branch/nodes/single/EndpointNode.java rename to branch-core/src/main/java/xyz/auriium/branch/nodes/EndpointNode.java index 5a08eff..7d15e98 100644 --- a/core/src/main/java/me/aurium/branch/nodes/single/EndpointNode.java +++ b/branch-core/src/main/java/xyz/auriium/branch/nodes/EndpointNode.java @@ -19,21 +19,34 @@ * */ -package me.aurium.branch.nodes.single; +package xyz.auriium.branch.nodes; -import me.aurium.branch.nodes.IdentifiableNode; -import me.aurium.branch.nodes.results.SearchInfo; -import me.aurium.branch.nodes.results.SearchInput; -import me.aurium.branch.nodes.results.model.Result; +import xyz.auriium.branch.base.NodeContext; +import xyz.auriium.branch.base.execution.blocks.EndpointBlock; +import xyz.auriium.branch.base.suggestion.Suggestion; +import xyz.auriium.branch.results.InitialSearch; +import xyz.auriium.branch.results.PreProcessSearch; +import xyz.auriium.branch.results.Result; + +import java.util.ArrayList; +import java.util.List; /** * A node that cannot point to any node other than itself (and therefore ends the branching of a node-path) */ -public abstract class EndpointNode implements IdentifiableNode { +public interface EndpointNode extends IdentifiableNode { + + @Override + EndpointBlock getIdentifier(); + + @Override + default Result>> searchSuggestion(NodeContext ctx, PreProcessSearch input) { + return Result.success(new ArrayList<>()); + } @Override - public final Result> getSpecificNode(SearchInput input) { - return Result.success(new SearchInfo<>(this,input)); + default Result> searchNode(InitialSearch input) { + return Result.success(PreProcessSearch.generate(this,input)); //new generation } } diff --git a/core/src/main/java/me/aurium/branch/nodes/IdentifiableNode.java b/branch-core/src/main/java/xyz/auriium/branch/nodes/IdentifiableNode.java similarity index 86% rename from core/src/main/java/me/aurium/branch/nodes/IdentifiableNode.java rename to branch-core/src/main/java/xyz/auriium/branch/nodes/IdentifiableNode.java index f454cab..2e236ed 100644 --- a/core/src/main/java/me/aurium/branch/nodes/IdentifiableNode.java +++ b/branch-core/src/main/java/xyz/auriium/branch/nodes/IdentifiableNode.java @@ -19,10 +19,9 @@ * */ -package me.aurium.branch.nodes; +package xyz.auriium.branch.nodes; -import me.aurium.branch.execution.Block; -import me.aurium.branch.information.description.Description; +import xyz.auriium.branch.base.execution.blocks.Block; public interface IdentifiableNode extends CommandNode { diff --git a/branch-core/src/main/java/xyz/auriium/branch/nodes/ProcessingNode.java b/branch-core/src/main/java/xyz/auriium/branch/nodes/ProcessingNode.java new file mode 100644 index 0000000..3f671be --- /dev/null +++ b/branch-core/src/main/java/xyz/auriium/branch/nodes/ProcessingNode.java @@ -0,0 +1,27 @@ +package xyz.auriium.branch.nodes; + +import xyz.auriium.branch.base.DelegatingEnhancedContext; +import xyz.auriium.branch.base.EnhancedNodeContext; +import xyz.auriium.branch.base.NodeContext; +import xyz.auriium.branch.base.execution.Execution; +import xyz.auriium.branch.results.PreProcessSearch; +import xyz.auriium.branch.results.SearchPair; +import xyz.auriium.branch.results.Result; + +public interface ProcessingNode extends EndpointNode { + + Result>searchStepOneExecute(NodeContext context, PreProcessSearch preProcessSearch); + Result> searchStepTwoExecute(EnhancedNodeContext context, O object); + + @Override + default Result> searchExecute(NodeContext ctx, PreProcessSearch input) { + + var pairResult = searchStepOneExecute(ctx, input); + + if (!pairResult.isSuccessful()) return Result.transmuteFail(pairResult); + + SearchPair searchPair = pairResult.getSuccess(); + + return searchStepTwoExecute(new DelegatingEnhancedContext<>(ctx, searchPair.getSearch()), searchPair.getObject()); + } +} diff --git a/core/src/main/java/me/aurium/branch/nodes/ResponseHandler.java b/branch-core/src/main/java/xyz/auriium/branch/nodes/ResponseHandler.java similarity index 96% rename from core/src/main/java/me/aurium/branch/nodes/ResponseHandler.java rename to branch-core/src/main/java/xyz/auriium/branch/nodes/ResponseHandler.java index 561b9f7..3e38277 100644 --- a/core/src/main/java/me/aurium/branch/nodes/ResponseHandler.java +++ b/branch-core/src/main/java/xyz/auriium/branch/nodes/ResponseHandler.java @@ -19,7 +19,7 @@ * */ -package me.aurium.branch.nodes; +package xyz.auriium.branch.nodes; public class ResponseHandler { } diff --git a/branch-core/src/main/java/xyz/auriium/branch/nodes/SimpleProcessingNode.java b/branch-core/src/main/java/xyz/auriium/branch/nodes/SimpleProcessingNode.java new file mode 100644 index 0000000..9bdf7ee --- /dev/null +++ b/branch-core/src/main/java/xyz/auriium/branch/nodes/SimpleProcessingNode.java @@ -0,0 +1,30 @@ +package xyz.auriium.branch.nodes; + +import xyz.auriium.branch.base.EnhancedNodeContext; +import xyz.auriium.branch.base.NodeContext; +import xyz.auriium.branch.base.execution.Execution; +import xyz.auriium.branch.results.PostProcessSearch; +import xyz.auriium.branch.results.PreProcessSearch; +import xyz.auriium.branch.results.SearchPair; +import xyz.auriium.branch.results.Result; + +/** + * Node that doesn't give a shit but still handles enhancedNodeContexts + * @param the type + */ +public interface SimpleProcessingNode extends ProcessingNode { + + Object returned = 0x01; + + @Override + default Result> searchStepOneExecute(NodeContext context, PreProcessSearch preProcessSearch) { + return Result.success(new SearchPair<>(PostProcessSearch.generate(preProcessSearch),returned)); + } + + @Override + default Result> searchStepTwoExecute(EnhancedNodeContext context, Object object) { + return onCommand(context); + } + + Result> onCommand(EnhancedNodeContext context); +} diff --git a/core/src/main/java/me/aurium/branch/interfacing/responses/TooManyArgsResponse.java b/branch-core/src/main/java/xyz/auriium/branch/nodes/TooManyArgsAnomaly.java similarity index 74% rename from core/src/main/java/me/aurium/branch/interfacing/responses/TooManyArgsResponse.java rename to branch-core/src/main/java/xyz/auriium/branch/nodes/TooManyArgsAnomaly.java index 12b79b8..1b3128d 100644 --- a/core/src/main/java/me/aurium/branch/interfacing/responses/TooManyArgsResponse.java +++ b/branch-core/src/main/java/xyz/auriium/branch/nodes/TooManyArgsAnomaly.java @@ -19,16 +19,17 @@ * */ -package me.aurium.branch.interfacing.responses; +package xyz.auriium.branch.nodes; -import me.aurium.branch.interfacing.Response; +import xyz.auriium.branch.interfacing.exceptional.Anomaly; +import xyz.auriium.branch.interfacing.exceptional.AnomalyType; -public class TooManyArgsResponse implements Response { +public class TooManyArgsAnomaly implements Anomaly { private final int expectedArgs; private final int suppliedArgs; - public TooManyArgsResponse(int expectedArgs, int suppliedArgs) { + public TooManyArgsAnomaly(int expectedArgs, int suppliedArgs) { this.expectedArgs = expectedArgs; this.suppliedArgs = suppliedArgs; } @@ -40,4 +41,9 @@ public int getExpectedArgs() { public int getSuppliedArgs() { return suppliedArgs; } + + @Override + public AnomalyType type() { + return AnomalyType.INVALID_SYNTAX; + } } diff --git a/branch-core/src/main/java/xyz/auriium/branch/nodes/argument/AbstractArgNode.java b/branch-core/src/main/java/xyz/auriium/branch/nodes/argument/AbstractArgNode.java new file mode 100644 index 0000000..92a8afe --- /dev/null +++ b/branch-core/src/main/java/xyz/auriium/branch/nodes/argument/AbstractArgNode.java @@ -0,0 +1,89 @@ +package xyz.auriium.branch.nodes.argument; + +import xyz.auriium.branch.base.EnhancedNodeContext; +import xyz.auriium.branch.interfacing.exceptional.anomalies.TooFewInputsExternalAnomaly; +import xyz.auriium.branch.base.NodeContext; +import xyz.auriium.branch.base.execution.ArgExecution; +import xyz.auriium.branch.base.execution.Execution; +import xyz.auriium.branch.nodes.ProcessingNode; +import xyz.auriium.branch.nodes.argument.model.ContextualBaseArgument; +import xyz.auriium.branch.results.PostProcessSearch; +import xyz.auriium.branch.results.PreProcessSearch; +import xyz.auriium.branch.results.SearchPair; +import xyz.auriium.branch.results.Result; + +import java.util.*; + +public abstract class AbstractArgNode implements ProcessingNode { + + protected abstract List> getArguments(); + protected abstract ArgumentContextHandler getContextHandler(); + + @Override + public Result> searchExecute(NodeContext ctx, PreProcessSearch input) { + + for (ContextualBaseArgument argument : getArguments()) { + + } + + return Result.success(null); + } + + @Override + public Result> searchStepOneExecute(NodeContext context, PreProcessSearch preProcessSearch) { + + Arguments argumentObject = new Arguments(); + Queue subQueue = new LinkedList<>(preProcessSearch.getRemainingStrings()); + + int argsLeft = getArguments().size(); + + for (ContextualBaseArgument argument : getArguments()) { + + if (subQueue.peek() == null) { + + if (argument.getOptional().isPresent()) { //if this is an optional argument + argumentObject.put(argument.getLabel(),argument.getOptional().get()); + + continue; + } else { + return Result.fail( + new TooFewInputsExternalAnomaly() + ); //throw + + + } + + + } + + assert argument.reservedBlockAmount() > 0 : "Cannot be negative or zero"; + + List collected = new ArrayList<>(); + + for (int v = 0; v < argument.reservedBlockAmount(); ++v) { + String blk = subQueue.peek(); + + if (blk == null) return Result.fail(null); //noInputProvidedInternal if theres not enough for the NEXT RESERVATION inside this arg + + collected.add(subQueue.remove()); + } + + Result res = argument.parse(context.getSender(), context.getAlias(), collected); + + if (!res.isSuccessful()) { + return Result.transmuteFail(res); + } + + preProcessSearch.getRemainingBlocks().add(argument.getType()); + argumentObject.put(argument.getLabel(), res.getSuccess()); + } + + + return Result.success(new SearchPair<>(PostProcessSearch.generate(preProcessSearch),argumentObject)); + } + + @Override + public Result> searchStepTwoExecute(EnhancedNodeContext context, Arguments object) { + return Result.success(new ArgExecution<>(getContextHandler(),context,object)); + } +} diff --git a/branch-core/src/main/java/xyz/auriium/branch/nodes/argument/ArgNode.java b/branch-core/src/main/java/xyz/auriium/branch/nodes/argument/ArgNode.java new file mode 100644 index 0000000..631643c --- /dev/null +++ b/branch-core/src/main/java/xyz/auriium/branch/nodes/argument/ArgNode.java @@ -0,0 +1,66 @@ +package xyz.auriium.branch.nodes.argument; + +import xyz.auriium.branch.base.execution.blocks.EndpointBlock; +import xyz.auriium.branch.base.permissions.EmptyPermission; +import xyz.auriium.branch.base.permissions.Permission; +import xyz.auriium.branch.nodes.description.Description; +import xyz.auriium.branch.nodes.description.StringDescription; +import xyz.auriium.branch.nodes.argument.model.ContextualBaseArgument; + +import java.util.List; + +/** + * Argument-consuming node. The most important part of branch (not) + * + * @param input type + */ +public class ArgNode extends AbstractArgNode { + + private final EndpointBlock identifier; + private final Permission permission; + private final Description description; + private final List> arguments; + private final ArgumentContextHandler handler; + + public ArgNode(EndpointBlock identifier, Permission permission, Description description, List> arguments, ArgumentContextHandler handler) { + this.identifier = identifier; + this.permission = permission; + this.description = description; + this.arguments = arguments; + this.handler = handler; + } + + public static ArgNode of(String identifier, Permission permission, Description description, List> arguments, ArgumentContextHandler handler) { + return new ArgNode<>(new EndpointBlock(identifier), permission, description, arguments, handler); + } + + public static ArgNode of(String identifier, List> arguments, ArgumentContextHandler handler) { + return new ArgNode<>(new EndpointBlock(identifier), EmptyPermission.instance(), new StringDescription("TODO"), arguments, handler); //TODO impl + } + + + @Override + public Permission getPermission() { + return permission; + } + + @Override + public Description getDescription() { + return description; + } + + @Override + public EndpointBlock getIdentifier() { + return identifier; + } + + @Override + protected List> getArguments() { + return arguments; + } + + @Override + protected ArgumentContextHandler getContextHandler() { + return handler; + } +} diff --git a/branch-core/src/main/java/xyz/auriium/branch/nodes/argument/ArgumentContext.java b/branch-core/src/main/java/xyz/auriium/branch/nodes/argument/ArgumentContext.java new file mode 100644 index 0000000..87cd493 --- /dev/null +++ b/branch-core/src/main/java/xyz/auriium/branch/nodes/argument/ArgumentContext.java @@ -0,0 +1,43 @@ +/* + * + * Branch + * Copyright © 2021 Aurium + * + * Branch is free software: you can redistribute it and/or modify + * It under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * Branch is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with Branch. If not, see + * and navigate to version 3 of the GNU Affero General Public License. + * + */ + +package xyz.auriium.branch.nodes.argument; + +import xyz.auriium.branch.base.NodeContext; + +public class ArgumentContext { + + private final NodeContext nodeContext; + private final Arguments arguments; + + public ArgumentContext(NodeContext nodeContext, Arguments arguments) { + this.nodeContext = nodeContext; + this.arguments = arguments; + } + + public NodeContext getNodeContext() { + return nodeContext; + } + + public Arguments getArguments() { + return arguments; + } +} diff --git a/core/src/main/java/me/aurium/branch/nodes/argument/ArgumentContextHandler.java b/branch-core/src/main/java/xyz/auriium/branch/nodes/argument/ArgumentContextHandler.java similarity index 84% rename from core/src/main/java/me/aurium/branch/nodes/argument/ArgumentContextHandler.java rename to branch-core/src/main/java/xyz/auriium/branch/nodes/argument/ArgumentContextHandler.java index f51351c..04eb14c 100644 --- a/core/src/main/java/me/aurium/branch/nodes/argument/ArgumentContextHandler.java +++ b/branch-core/src/main/java/xyz/auriium/branch/nodes/argument/ArgumentContextHandler.java @@ -19,10 +19,11 @@ * */ -package me.aurium.branch.nodes.argument; +package xyz.auriium.branch.nodes.argument; -public interface ArgumentContextHandler { +public interface ArgumentContextHandler { + + void handle(ArgumentContext argumentContext); - void handle(ArgumentContext context); } diff --git a/core/src/main/java/me/aurium/branch/interfacing/handlers/InnerMap.java b/branch-core/src/main/java/xyz/auriium/branch/nodes/argument/Arguments.java similarity index 59% rename from core/src/main/java/me/aurium/branch/interfacing/handlers/InnerMap.java rename to branch-core/src/main/java/xyz/auriium/branch/nodes/argument/Arguments.java index bd0e569..665fcc1 100644 --- a/core/src/main/java/me/aurium/branch/interfacing/handlers/InnerMap.java +++ b/branch-core/src/main/java/xyz/auriium/branch/nodes/argument/Arguments.java @@ -19,27 +19,28 @@ * */ -package me.aurium.branch.interfacing.handlers; - -import me.aurium.branch.interfacing.Response; -import me.aurium.branch.interfacing.ResponseAction; +package xyz.auriium.branch.nodes.argument; import java.util.HashMap; import java.util.Map; +import java.util.Optional; -public class InnerMap implements MessageMap { +/** + * Object for storing and returning arguments of a command + */ +public class Arguments { - private final Map,ResponseAction> map = new HashMap<>(); + private final Map map = new HashMap<>(); - @Override - public InnerMap add(Class key, ResponseAction action) { - this.map.put(key,action); + public Optional getOptional(String identifier) { + return (Optional) Optional.ofNullable(map.get(identifier)); + } - return this; + public T get(String identifier) { + return (T) map.get(identifier); } - @Override - public InterfacingHandler make() { - return new CommonInterfacingHandler<>(map); + void put(String identifier, Object object) { + this.map.put(identifier, object); } } diff --git a/branch-core/src/main/java/xyz/auriium/branch/nodes/argument/impl/DefaultingArgNode.java b/branch-core/src/main/java/xyz/auriium/branch/nodes/argument/impl/DefaultingArgNode.java new file mode 100644 index 0000000..1584a3f --- /dev/null +++ b/branch-core/src/main/java/xyz/auriium/branch/nodes/argument/impl/DefaultingArgNode.java @@ -0,0 +1,13 @@ +package xyz.auriium.branch.nodes.argument.impl; + +import xyz.auriium.branch.base.permissions.EmptyPermission; +import xyz.auriium.branch.base.permissions.Permission; + +public abstract class DefaultingArgNode extends ImplementableArgNode { + + @Override + public Permission getPermission() { + return EmptyPermission.instance(); + } + +} diff --git a/branch-core/src/main/java/xyz/auriium/branch/nodes/argument/impl/ImplementableArgNode.java b/branch-core/src/main/java/xyz/auriium/branch/nodes/argument/impl/ImplementableArgNode.java new file mode 100644 index 0000000..db8c1b5 --- /dev/null +++ b/branch-core/src/main/java/xyz/auriium/branch/nodes/argument/impl/ImplementableArgNode.java @@ -0,0 +1,19 @@ +package xyz.auriium.branch.nodes.argument.impl; + +import xyz.auriium.branch.nodes.argument.AbstractArgNode; +import xyz.auriium.branch.nodes.argument.ArgumentContext; +import xyz.auriium.branch.nodes.argument.ArgumentContextHandler; + +public abstract class ImplementableArgNode extends AbstractArgNode { + + @Override + protected ArgumentContextHandler getContextHandler() { + return this::onExecution; + } + + /** + * Method representing the execution of the node + * @param context pojo representing arguments + default context + */ + abstract void onExecution(ArgumentContext context); +} diff --git a/branch-core/src/main/java/xyz/auriium/branch/nodes/argument/model/ContextualBaseArgument.java b/branch-core/src/main/java/xyz/auriium/branch/nodes/argument/model/ContextualBaseArgument.java new file mode 100644 index 0000000..9ea678e --- /dev/null +++ b/branch-core/src/main/java/xyz/auriium/branch/nodes/argument/model/ContextualBaseArgument.java @@ -0,0 +1,61 @@ +package xyz.auriium.branch.nodes.argument.model; + +import xyz.auriium.branch.base.execution.blocks.ArgumentBlock; +import xyz.auriium.branch.results.Result; + +import java.util.List; +import java.util.Optional; + +/** + * Base-type SPI interface describing an + * argument that requires information about the node's contextual sender base + * + * Convention dictates that when writing an argument instantiation of said argument will be done + * via the use of a static #of method with a private constructor. + * + * @param input type of command node + * @param output type of argument parsing e.g. world or string + */ +public interface ContextualBaseArgument { + + /** + * Method describing the single-word "type" of this argument, like + * "StringArgument" or "IntegerArgument" + * + * @return the type + */ + ArgumentBlock getType(); + + /** + * Method describing what label this argument uses + * Label is typically defined by the user of the framework + * + * @return the label + */ + String getLabel(); + + /** + * Method describing how many blocks this argument reserves + * @return the amount of blocks this argument requires + */ + int reservedBlockAmount(); + + /** + * If this object is an optional, return a value. If it is not, will always return empty + * @return the optional describing whether this object is optional or not + */ + Optional getOptional(); + + /** + * Method describing how this object parses + * + * Always assume that {@param reserved} contains the exact amount of arguments you requested. + * It will never contain only 1 if you request 2, and will never be empty if you request 1. + * + * @return a result describing the execution success of parsing + */ + Result parse(T sender, String alias, List reserved); + + + +} diff --git a/branch-core/src/main/java/xyz/auriium/branch/nodes/argument/model/DefaultingIgnorantArgument.java b/branch-core/src/main/java/xyz/auriium/branch/nodes/argument/model/DefaultingIgnorantArgument.java new file mode 100644 index 0000000..e1035de --- /dev/null +++ b/branch-core/src/main/java/xyz/auriium/branch/nodes/argument/model/DefaultingIgnorantArgument.java @@ -0,0 +1,4 @@ +package xyz.auriium.branch.nodes.argument.model; + +public class DefaultingIgnorantArgument { +} diff --git a/branch-core/src/main/java/xyz/auriium/branch/nodes/argument/model/IgnorantBaseArgument.java b/branch-core/src/main/java/xyz/auriium/branch/nodes/argument/model/IgnorantBaseArgument.java new file mode 100644 index 0000000..618e8f4 --- /dev/null +++ b/branch-core/src/main/java/xyz/auriium/branch/nodes/argument/model/IgnorantBaseArgument.java @@ -0,0 +1,8 @@ +package xyz.auriium.branch.nodes.argument.model; + +/** + * Base argument that ignores context + * @param the type of object returned by parsing + */ +public interface IgnorantBaseArgument extends ContextualBaseArgument { +} diff --git a/branch-core/src/main/java/xyz/auriium/branch/nodes/argument/model/SingleContextualArgument.java b/branch-core/src/main/java/xyz/auriium/branch/nodes/argument/model/SingleContextualArgument.java new file mode 100644 index 0000000..8b7f341 --- /dev/null +++ b/branch-core/src/main/java/xyz/auriium/branch/nodes/argument/model/SingleContextualArgument.java @@ -0,0 +1,20 @@ +package xyz.auriium.branch.nodes.argument.model; + +import xyz.auriium.branch.results.Result; + +import java.util.List; + +public interface SingleContextualArgument extends ContextualBaseArgument { + + @Override + default int reservedBlockAmount() { + return 1; + } + + @Override + default Result parse(T sender, String alias, List reserved) { + return microParse(sender,alias,reserved.get(0)); + } + + Result microParse(T sender, String alias, String toParse); +} diff --git a/branch-core/src/main/java/xyz/auriium/branch/nodes/argument/model/SingleIgnorantArgument.java b/branch-core/src/main/java/xyz/auriium/branch/nodes/argument/model/SingleIgnorantArgument.java new file mode 100644 index 0000000..e8b17d3 --- /dev/null +++ b/branch-core/src/main/java/xyz/auriium/branch/nodes/argument/model/SingleIgnorantArgument.java @@ -0,0 +1,4 @@ +package xyz.auriium.branch.nodes.argument.model; + +public interface SingleIgnorantArgument extends SingleContextualArgument { +} diff --git a/branch-core/src/main/java/xyz/auriium/branch/nodes/argument/types/StringArgument.java b/branch-core/src/main/java/xyz/auriium/branch/nodes/argument/types/StringArgument.java new file mode 100644 index 0000000..0cce566 --- /dev/null +++ b/branch-core/src/main/java/xyz/auriium/branch/nodes/argument/types/StringArgument.java @@ -0,0 +1,53 @@ +package xyz.auriium.branch.nodes.argument.types; + +import xyz.auriium.branch.base.execution.blocks.ArgumentBlock; +import xyz.auriium.branch.nodes.argument.model.SingleIgnorantArgument; +import xyz.auriium.branch.results.Result; + +import java.util.Objects; +import java.util.Optional; + +public class StringArgument implements SingleIgnorantArgument { + + private final String label; + private final String nullableOptional; + + private final ArgumentBlock block; + + StringArgument(String label, String nullableOptional) { + this.label = label; + this.nullableOptional = nullableOptional; + + this.block = new ArgumentBlock(label, "string", nullableOptional != null); + } + + public static StringArgument of(String label) { + return new StringArgument(label, null); + } + + public static StringArgument ofOptional(String label, String optional) { + Objects.requireNonNull(optional); + + return new StringArgument(label, optional); + } + + @Override + public ArgumentBlock getType() { + return block; + } + + @Override + public String getLabel() { + return label; + } + + @Override + public Optional getOptional() { + return Optional.ofNullable(nullableOptional); + } + + @Override + public Result microParse(Object sender, String alias, String toParse) { + return Result.success(toParse); + } +} diff --git a/branch-core/src/main/java/xyz/auriium/branch/nodes/branching/BranchingBuilder.java b/branch-core/src/main/java/xyz/auriium/branch/nodes/branching/BranchingBuilder.java new file mode 100644 index 0000000..f0b5b5f --- /dev/null +++ b/branch-core/src/main/java/xyz/auriium/branch/nodes/branching/BranchingBuilder.java @@ -0,0 +1,4 @@ +package xyz.auriium.branch.nodes.branching; + +public class BranchingBuilder { +} diff --git a/branch-core/src/main/java/xyz/auriium/branch/nodes/branching/BranchingNode.java b/branch-core/src/main/java/xyz/auriium/branch/nodes/branching/BranchingNode.java new file mode 100644 index 0000000..f62f1c6 --- /dev/null +++ b/branch-core/src/main/java/xyz/auriium/branch/nodes/branching/BranchingNode.java @@ -0,0 +1,120 @@ +/* + * + * Branch + * Copyright © 2021 Aurium + * + * Branch is free software: you can redistribute it and/or modify + * It under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * Branch is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with Branch. If not, see + * and navigate to version 3 of the GNU Affero General Public License. + * + */ + +package xyz.auriium.branch.nodes.branching; + +import xyz.auriium.branch.base.suggestion.Suggestion; +import xyz.auriium.branch.nodes.description.StringDescription; +import xyz.auriium.branch.base.execution.Execution; +import xyz.auriium.branch.base.NodeContext; +import xyz.auriium.branch.nodes.description.Description; +import xyz.auriium.branch.base.execution.blocks.GroupBlock; +import xyz.auriium.branch.base.permissions.EmptyPermission; +import xyz.auriium.branch.nodes.IdentifiableNode; +import xyz.auriium.branch.base.permissions.Permission; +import xyz.auriium.branch.results.Result; +import xyz.auriium.branch.results.InitialSearch; +import xyz.auriium.branch.results.PreProcessSearch; + +import java.util.ArrayList; +import java.util.List; + +/** + * Nodes should always assume that the first block in the blockpath is theirs to consume TODO write docs + * + * TODO make ordered + * + * @param + */ +public class BranchingNode implements IdentifiableNode { + + private final GroupBlock identifier; + private final PreStoredList nodes; + private final Description description; + private final Permission permission; + + public BranchingNode(String identifier, PreStoredList nodes, Description description, Permission permission) { + this.nodes = nodes; + this.identifier = new GroupBlock(identifier); + this.description = description; + this.permission = permission; + } + + @Override + public Result>> searchSuggestion(NodeContext ctx, PreProcessSearch input) { + + List> suggestions = new ArrayList<>(); + + for (IdentifiableNode node : nodes.getContents()) { + suggestions.add(new Suggestion<>(node.getPermission(), node.getIdentifier())); + } + + return Result.success(suggestions); + + } + + @Override + public GroupBlock getIdentifier() { + return identifier; + } + + @Override + public Description getDescription() { + return description; + } + + @Override + public Permission getPermission() { + return permission; + } + + @Override + public Result> searchNode(InitialSearch input) { + + if (!input.getRemainingStrings().isEmpty()) { + String popped = input.getRemainingStrings().peek(); //reveal + + for (IdentifiableNode node : nodes.getContents()) { + if (input.getEquality().equal(identifier,popped)) { + input.getRemainingStrings().remove(); //pop string + + return node.searchNode(input); //consume + } + } + + } + + return nodes.getSideNode().searchNode(input); + } + + @Override + public Result> searchExecute(NodeContext ctx, PreProcessSearch input) { + return nodes.getSideNode().searchExecute(ctx, input); + } + + public static BranchingNode of(String identifier, PreStoredList nodes, Description description, Permission permission) { + return new BranchingNode<>(identifier, nodes, description, permission); + } + + public static BranchingNode of(String identifier, PreStoredList nodes) { + return new BranchingNode<>(identifier, nodes, new StringDescription("Default description for branching command"), EmptyPermission.instance()); + } +} diff --git a/branch-core/src/main/java/xyz/auriium/branch/nodes/branching/CommonPreStoredList.java b/branch-core/src/main/java/xyz/auriium/branch/nodes/branching/CommonPreStoredList.java new file mode 100644 index 0000000..64b8f77 --- /dev/null +++ b/branch-core/src/main/java/xyz/auriium/branch/nodes/branching/CommonPreStoredList.java @@ -0,0 +1,27 @@ +package xyz.auriium.branch.nodes.branching; + +import xyz.auriium.branch.nodes.CommandNode; +import xyz.auriium.branch.nodes.IdentifiableNode; + +import java.util.List; + +public class CommonPreStoredList implements PreStoredList { + + private final List> contents; + private final CommandNode node; + + public CommonPreStoredList(List> contents, CommandNode node) { + this.contents = contents; + this.node = node; + } + + @Override + public List> getContents() { + return contents; + } + + @Override + public CommandNode getSideNode() { + return node; + } +} diff --git a/branch-core/src/main/java/xyz/auriium/branch/nodes/branching/ExclusivePrestoredBuilder.java b/branch-core/src/main/java/xyz/auriium/branch/nodes/branching/ExclusivePrestoredBuilder.java new file mode 100644 index 0000000..73e9e72 --- /dev/null +++ b/branch-core/src/main/java/xyz/auriium/branch/nodes/branching/ExclusivePrestoredBuilder.java @@ -0,0 +1,45 @@ +package xyz.auriium.branch.nodes.branching; + +import xyz.auriium.branch.nodes.CommandNode; +import xyz.auriium.branch.nodes.IdentifiableNode; +import xyz.auriium.branch.nodes.help.HelpNode; + +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; + +public class ExclusivePrestoredBuilder { + + private final List> nodes = new ArrayList<>(); + private volatile CommandNode base; + + public static ExclusivePrestoredBuilder of() { + return new ExclusivePrestoredBuilder<>(); + } + + /** + * Sets the no-args handling node + * @param node the node + * @return a value + */ + public ExclusivePrestoredBuilder withNoArgs(CommandNode node) { + this.base = node; + + return this; + } + + /** + * Adds an node into the builder (ordered) + * @param node the node + * @return this builder + */ + public ExclusivePrestoredBuilder addNode(IdentifiableNode node) { + nodes.add(node); + + return this; + } + + public PreStoredList make() { + return new CommonPreStoredList<>(nodes, Objects.requireNonNullElse(base, HelpNode.of())); + } +} diff --git a/branch-core/src/main/java/xyz/auriium/branch/nodes/branching/InclusivePreStoredBuilder.java b/branch-core/src/main/java/xyz/auriium/branch/nodes/branching/InclusivePreStoredBuilder.java new file mode 100644 index 0000000..24800f2 --- /dev/null +++ b/branch-core/src/main/java/xyz/auriium/branch/nodes/branching/InclusivePreStoredBuilder.java @@ -0,0 +1,51 @@ +package xyz.auriium.branch.nodes.branching; + +import xyz.auriium.branch.nodes.CommandNode; +import xyz.auriium.branch.nodes.IdentifiableNode; +import xyz.auriium.branch.nodes.help.HelpNode; + +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; + +public class InclusivePreStoredBuilder { + + private final List> nodes = new ArrayList<>(); + private volatile IdentifiableNode base; + + public static InclusivePreStoredBuilder of() { + return new InclusivePreStoredBuilder<>(); + } + + /** + * Sets the no-args handling node + * @param node the node + * @return a value + */ + public InclusivePreStoredBuilder withNoArgs(IdentifiableNode node) { + this.base = node; + + return this; + } + + /** + * Adds an node into the builder (ordered) + * @param node the node + * @return this builder + */ + public InclusivePreStoredBuilder addNode(IdentifiableNode node) { + nodes.add(node); + + return this; + } + + public PreStoredList make() { + IdentifiableNode node = Objects.requireNonNullElse(base, HelpNode.of()); + List> list = new ArrayList<>(nodes); + + list.add(node); + + return new CommonPreStoredList<>(list, node); + } + +} diff --git a/branch-core/src/main/java/xyz/auriium/branch/nodes/branching/PreStoredList.java b/branch-core/src/main/java/xyz/auriium/branch/nodes/branching/PreStoredList.java new file mode 100644 index 0000000..32d2fed --- /dev/null +++ b/branch-core/src/main/java/xyz/auriium/branch/nodes/branching/PreStoredList.java @@ -0,0 +1,15 @@ +package xyz.auriium.branch.nodes.branching; + +import xyz.auriium.branch.nodes.CommandNode; +import xyz.auriium.branch.nodes.IdentifiableNode; + +import java.util.List; + + +//TODO refactor to prestoredList in order to allow user defined preferences +public interface PreStoredList { + + List> getContents(); + CommandNode getSideNode(); + +} diff --git a/core/src/main/java/me/aurium/branch/information/description/Description.java b/branch-core/src/main/java/xyz/auriium/branch/nodes/description/Description.java similarity index 89% rename from core/src/main/java/me/aurium/branch/information/description/Description.java rename to branch-core/src/main/java/xyz/auriium/branch/nodes/description/Description.java index f5904d9..551ea6f 100644 --- a/core/src/main/java/me/aurium/branch/information/description/Description.java +++ b/branch-core/src/main/java/xyz/auriium/branch/nodes/description/Description.java @@ -19,8 +19,9 @@ * */ -package me.aurium.branch.information.description; +package xyz.auriium.branch.nodes.description; +//TODO make functional interface in order to generate str public interface Description { String getTextDescription(); diff --git a/branch-core/src/main/java/xyz/auriium/branch/nodes/description/DescriptionContext.java b/branch-core/src/main/java/xyz/auriium/branch/nodes/description/DescriptionContext.java new file mode 100644 index 0000000..1695c88 --- /dev/null +++ b/branch-core/src/main/java/xyz/auriium/branch/nodes/description/DescriptionContext.java @@ -0,0 +1,10 @@ +package xyz.auriium.branch.nodes.description; + +/** + * everything a description needs (this node name, etc etc etc etc) + * + * Calls to node.getDescription should return a **STRING**, this object should not be known by the api at large and instead + * should be considered an object used in order to act as a transport for description message orders. + */ +public class DescriptionContext { +} diff --git a/branch-core/src/main/java/xyz/auriium/branch/nodes/description/GeneratingDescription.java b/branch-core/src/main/java/xyz/auriium/branch/nodes/description/GeneratingDescription.java new file mode 100644 index 0000000..6fc9427 --- /dev/null +++ b/branch-core/src/main/java/xyz/auriium/branch/nodes/description/GeneratingDescription.java @@ -0,0 +1,22 @@ +package xyz.auriium.branch.nodes.description; + +import java.util.function.Supplier; + +/** + * Represents a description that can calculate a response whenever called + * + * Potential usecase: command that updates it's description whenever a global command is on cooldown? idk + */ +public class GeneratingDescription implements Description{ + + private final Supplier generator; + + public GeneratingDescription(Supplier generator) { + this.generator = generator; + } + + @Override + public String getTextDescription() { + return generator.get(); + } +} diff --git a/branch-core/src/main/java/xyz/auriium/branch/nodes/description/LazyGeneratingDescription.java b/branch-core/src/main/java/xyz/auriium/branch/nodes/description/LazyGeneratingDescription.java new file mode 100644 index 0000000..b97c3bb --- /dev/null +++ b/branch-core/src/main/java/xyz/auriium/branch/nodes/description/LazyGeneratingDescription.java @@ -0,0 +1,28 @@ +package xyz.auriium.branch.nodes.description; + +import java.util.function.Supplier; + +/** + * Represents generator that generates it's description once whenever it is requested to. + * Functions like a lazy developer's singleton. Use this if you don't want heavy logic being called often. + * + * A potential use case of this: idk argnode + */ +public class LazyGeneratingDescription implements Description{ + + private final Supplier generator; + private volatile String generated; + + public LazyGeneratingDescription(Supplier generator) { + this.generator = generator; + } + + @Override + public String getTextDescription() { + if (generated == null) { + generated = generator.get(); + } + + return generated; + } +} diff --git a/core/src/main/java/me/aurium/branch/information/description/StringDescription.java b/branch-core/src/main/java/xyz/auriium/branch/nodes/description/StringDescription.java similarity index 73% rename from core/src/main/java/me/aurium/branch/information/description/StringDescription.java rename to branch-core/src/main/java/xyz/auriium/branch/nodes/description/StringDescription.java index ae7d769..a6a72a2 100644 --- a/core/src/main/java/me/aurium/branch/information/description/StringDescription.java +++ b/branch-core/src/main/java/xyz/auriium/branch/nodes/description/StringDescription.java @@ -1,5 +1,8 @@ -package me.aurium.branch.information.description; +package xyz.auriium.branch.nodes.description; +/** + * Immutable description returning a simple string + */ public class StringDescription implements Description { private final String textDescription; diff --git a/branch-core/src/main/java/xyz/auriium/branch/nodes/help/HelpNode.java b/branch-core/src/main/java/xyz/auriium/branch/nodes/help/HelpNode.java new file mode 100644 index 0000000..63d1411 --- /dev/null +++ b/branch-core/src/main/java/xyz/auriium/branch/nodes/help/HelpNode.java @@ -0,0 +1,93 @@ +/* + * + * Branch + * Copyright © 2021 Aurium + * + * Branch is free software: you can redistribute it and/or modify + * It under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * Branch is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with Branch. If not, see + * and navigate to version 3 of the GNU Affero General Public License. + * + */ + +package xyz.auriium.branch.nodes.help; + +import xyz.auriium.branch.nodes.description.StringDescription; +import xyz.auriium.branch.base.NodeContext; +import xyz.auriium.branch.base.execution.Execution; +import xyz.auriium.branch.base.execution.blocks.EndpointBlock; +import xyz.auriium.branch.base.permissions.EmptyPermission; +import xyz.auriium.branch.base.permissions.Permission; +import xyz.auriium.branch.nodes.description.Description; +import xyz.auriium.branch.nodes.EndpointNode; +import xyz.auriium.branch.results.PreProcessSearch; +import xyz.auriium.branch.results.Result; + +/** + * Represents a node that pregenerates help entries based on the message context + */ +public class HelpNode implements EndpointNode { + + private final EndpointBlock identifier; + private final Permission permission; + private final Description description; + + public HelpNode(String name, Permission permission, Description description) { + this.identifier = new EndpointBlock(name); + this.permission = permission; + this.description = description; + } + + @Override + public Permission getPermission() { + return permission; + } + + @Override + public EndpointBlock getIdentifier() { + return identifier; + } + + @Override + public Description getDescription() { + return description; + } + + @Override + public Result> searchExecute(NodeContext ctx, PreProcessSearch input) { + + /*List blocks = new ArrayList<>(); + String[] strong = ct.getArgs(); + + for (int i = 0; i < strong.length - 1; i++) { + blocks.add(StringBlock.of(strong[i])); + } + + Result> toBeExecuted = context.getBaseExecutedNode().getSpecificNode(SearchInput.of(blocks)); + + toBeExecuted.getSuccess().resultingNode();*/ + + return null; + } + + public static HelpNode of() { + return new HelpNode<>("help", EmptyPermission.instance(), new StringDescription("Default help command")); + } + + public static HelpNode of(String name, Permission permission, Description description) { + return new HelpNode<>(name, permission, description); + } + + public static HelpNode of(Permission permission, Description description) { + return new HelpNode<>("help", permission, description); + } +} diff --git a/core/src/main/java/me/aurium/branch/nodes/ProxyNode.java b/branch-core/src/main/java/xyz/auriium/branch/nodes/proxy/ProxyNode.java similarity index 76% rename from core/src/main/java/me/aurium/branch/nodes/ProxyNode.java rename to branch-core/src/main/java/xyz/auriium/branch/nodes/proxy/ProxyNode.java index 565307d..d96c77c 100644 --- a/core/src/main/java/me/aurium/branch/nodes/ProxyNode.java +++ b/branch-core/src/main/java/xyz/auriium/branch/nodes/proxy/ProxyNode.java @@ -1,4 +1,4 @@ -package me.aurium.branch.nodes; +package xyz.auriium.branch.nodes.proxy; /** * Represents a node that can dynamically convert a specified ProxyInterface into arguments diff --git a/branch-core/src/main/java/xyz/auriium/branch/nodes/single/AbstractSingleNode.java b/branch-core/src/main/java/xyz/auriium/branch/nodes/single/AbstractSingleNode.java new file mode 100644 index 0000000..b4cae4a --- /dev/null +++ b/branch-core/src/main/java/xyz/auriium/branch/nodes/single/AbstractSingleNode.java @@ -0,0 +1,25 @@ +package xyz.auriium.branch.nodes.single; + +import xyz.auriium.branch.base.execution.blocks.Block; +import xyz.auriium.branch.base.EnhancedNodeContext; +import xyz.auriium.branch.base.execution.BasicExecution; +import xyz.auriium.branch.base.execution.Execution; +import xyz.auriium.branch.base.execution.ExecutionHandler; +import xyz.auriium.branch.nodes.SimpleProcessingNode; +import xyz.auriium.branch.results.Result; + +import java.util.ArrayList; +import java.util.List; + +public abstract class AbstractSingleNode implements SimpleProcessingNode { + + public static List returned = new ArrayList<>(); + + @Override + public Result> onCommand(EnhancedNodeContext context) { + return Result.success(new BasicExecution<>(getHandler(), context)); + } + + protected abstract ExecutionHandler getHandler(); + +} diff --git a/branch-core/src/main/java/xyz/auriium/branch/nodes/single/SingleNode.java b/branch-core/src/main/java/xyz/auriium/branch/nodes/single/SingleNode.java new file mode 100644 index 0000000..a273e21 --- /dev/null +++ b/branch-core/src/main/java/xyz/auriium/branch/nodes/single/SingleNode.java @@ -0,0 +1,52 @@ +package xyz.auriium.branch.nodes.single; + +import xyz.auriium.branch.base.execution.ExecutionHandler; +import xyz.auriium.branch.base.execution.blocks.EndpointBlock; +import xyz.auriium.branch.base.permissions.EmptyPermission; +import xyz.auriium.branch.base.permissions.Permission; +import xyz.auriium.branch.nodes.description.Description; +import xyz.auriium.branch.nodes.description.StringDescription; + +public class SingleNode extends AbstractSingleNode { + + private final EndpointBlock identifier; + private final Permission permission; + private final Description description; + private final ExecutionHandler handler; + + public SingleNode(String identifier, Permission permission, Description description, ExecutionHandler handler) { + this.identifier = new EndpointBlock(identifier); + this.permission = permission; + this.description = description; + this.handler = handler; + } + + @Override + public Permission getPermission() { + return permission; + } + + @Override + public Description getDescription() { + return description; + } + + @Override + public EndpointBlock getIdentifier() { + return identifier; + } + + @Override + protected ExecutionHandler getHandler() { + return handler; + } + + public static SingleNode of(String id, ExecutionHandler handler, Permission permission, Description description) { + return new SingleNode<>(id, permission, description, handler); + } + + public static SingleNode of(String id, ExecutionHandler handler) { + return new SingleNode<>(id, EmptyPermission.instance(), new StringDescription("default description"), handler); + } + +} diff --git a/branch-core/src/main/java/xyz/auriium/branch/nodes/single/SingleNodeBuilder.java b/branch-core/src/main/java/xyz/auriium/branch/nodes/single/SingleNodeBuilder.java new file mode 100644 index 0000000..594ae96 --- /dev/null +++ b/branch-core/src/main/java/xyz/auriium/branch/nodes/single/SingleNodeBuilder.java @@ -0,0 +1,52 @@ +package xyz.auriium.branch.nodes.single; + +import xyz.auriium.branch.base.execution.ExecutionHandler; +import xyz.auriium.branch.base.permissions.EmptyPermission; +import xyz.auriium.branch.base.permissions.Permission; +import xyz.auriium.branch.nodes.description.Description; +import xyz.auriium.branch.nodes.description.StringDescription; + +import java.util.Objects; + +@Deprecated //TODO undeprecate when all builders are done. for now, use each node's static method +public final class SingleNodeBuilder { + + + private final String identifier; + private Permission permission; + private Description description; + private ExecutionHandler handler; + + SingleNodeBuilder(String identifier) { + this.identifier = identifier; + } + + public static SingleNodeBuilder builder(String identifier) { + return new SingleNodeBuilder<>(identifier); + } + + public SingleNodeBuilder withPermission(Permission permission) { + this.permission = permission; + return this; + } + + public SingleNodeBuilder withDescription(Description description) { + this.description = description; + return this; + } + + public SingleNodeBuilder withHandler(ExecutionHandler handler) { + this.handler = handler; + return this; + } + + public SingleNode build() { + + return new SingleNode<>( + identifier, + Objects.requireNonNullElse(permission, EmptyPermission.instance()), + Objects.requireNonNullElse(description, new StringDescription("Default description")), + handler + ); + } +} diff --git a/branch-core/src/main/java/xyz/auriium/branch/nodes/single/impl/DefaultingSingleNode.java b/branch-core/src/main/java/xyz/auriium/branch/nodes/single/impl/DefaultingSingleNode.java new file mode 100644 index 0000000..442627c --- /dev/null +++ b/branch-core/src/main/java/xyz/auriium/branch/nodes/single/impl/DefaultingSingleNode.java @@ -0,0 +1,20 @@ +package xyz.auriium.branch.nodes.single.impl; + +import xyz.auriium.branch.base.execution.blocks.EndpointBlock; +import xyz.auriium.branch.base.permissions.EmptyPermission; +import xyz.auriium.branch.base.permissions.Permission; + +public abstract class DefaultingSingleNode extends ImplementableSingleNode { + + @Override + public Permission getPermission() { + return EmptyPermission.instance(); + } + + @Override + public EndpointBlock getIdentifier() { + return new EndpointBlock(getName()); + } + + abstract String getName(); +} diff --git a/branch-core/src/main/java/xyz/auriium/branch/nodes/single/impl/ImplementableSingleNode.java b/branch-core/src/main/java/xyz/auriium/branch/nodes/single/impl/ImplementableSingleNode.java new file mode 100644 index 0000000..8ddf48e --- /dev/null +++ b/branch-core/src/main/java/xyz/auriium/branch/nodes/single/impl/ImplementableSingleNode.java @@ -0,0 +1,17 @@ +package xyz.auriium.branch.nodes.single.impl; + +import xyz.auriium.branch.base.NodeContext; +import xyz.auriium.branch.base.execution.ExecutionHandler; +import xyz.auriium.branch.nodes.single.AbstractSingleNode; + +public abstract class ImplementableSingleNode extends AbstractSingleNode { + + protected ExecutionHandler getHandler() { + return this::onExecution; + } + + abstract void onExecution(NodeContext context); + + + +} diff --git a/branch-core/src/main/java/xyz/auriium/branch/package-info.java b/branch-core/src/main/java/xyz/auriium/branch/package-info.java new file mode 100644 index 0000000..cc280a8 --- /dev/null +++ b/branch-core/src/main/java/xyz/auriium/branch/package-info.java @@ -0,0 +1,4 @@ +/** + * Main package for branch core module + */ +package xyz.auriium.branch; \ No newline at end of file diff --git a/branch-core/src/main/java/xyz/auriium/branch/results/DelegatingImmutableList.java b/branch-core/src/main/java/xyz/auriium/branch/results/DelegatingImmutableList.java new file mode 100644 index 0000000..72b70d3 --- /dev/null +++ b/branch-core/src/main/java/xyz/auriium/branch/results/DelegatingImmutableList.java @@ -0,0 +1,61 @@ +package xyz.auriium.branch.results; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +public class DelegatingImmutableList implements ImmutableList { //TODO + + private final List delegate; + + DelegatingImmutableList(List list) { + this.delegate = list; + } + + @Override + public List delegate() { + return delegate; + } + + @Override + public int size() { + return delegate.size(); + } + + @Override + public boolean isEmpty() { + return delegate.isEmpty(); + } + + @Override + public boolean contains(Object o) { + return delegate.contains(o); + } + + @Override + public Iterator iterator() { + return delegate.iterator(); + } + + @Override + public Object[] toArray() { + return delegate.toArray(); + } + + @Override + public T get(int index) { + return delegate.get(index); + } + + public List getDelegate() { + return delegate; + } + + public static DelegatingImmutableList make(List list) { + return new DelegatingImmutableList<>(List.copyOf(list)); + } + + public static DelegatingImmutableList make() { + return new DelegatingImmutableList<>(List.copyOf(new ArrayList<>())); + } +} diff --git a/core/src/main/java/me/aurium/branch/nodes/results/model/FailingResult.java b/branch-core/src/main/java/xyz/auriium/branch/results/FailingResult.java similarity index 85% rename from core/src/main/java/me/aurium/branch/nodes/results/model/FailingResult.java rename to branch-core/src/main/java/xyz/auriium/branch/results/FailingResult.java index 0a21da9..72ed593 100644 --- a/core/src/main/java/me/aurium/branch/nodes/results/model/FailingResult.java +++ b/branch-core/src/main/java/xyz/auriium/branch/results/FailingResult.java @@ -19,9 +19,9 @@ * */ -package me.aurium.branch.nodes.results.model; +package xyz.auriium.branch.results; -import me.aurium.branch.interfacing.Response; +import xyz.auriium.branch.interfacing.exceptional.Anomaly; /** * A result that has failed @@ -29,9 +29,9 @@ */ public class FailingResult implements Result { - private final Response failure; + private final Anomaly failure; - public FailingResult(Response failure) { + public FailingResult(Anomaly failure) { this.failure = failure; } @@ -46,7 +46,7 @@ public T getSuccess() { } @Override - public Response getFailure() { + public Anomaly getFailure() { return failure; } diff --git a/branch-core/src/main/java/xyz/auriium/branch/results/ImmutableList.java b/branch-core/src/main/java/xyz/auriium/branch/results/ImmutableList.java new file mode 100644 index 0000000..e957eff --- /dev/null +++ b/branch-core/src/main/java/xyz/auriium/branch/results/ImmutableList.java @@ -0,0 +1,92 @@ +package xyz.auriium.branch.results; + +import java.util.Arrays; +import java.util.Collection; +import java.util.Iterator; +import java.util.List; + +/** + * Immutable list implementation since for some strange reason the jdk never included one..... + * + * @param element + */ +public interface ImmutableList { + + /** + * Gets the delegating object (immutable) + * Delegating object should be... immutable + * + * @return returns the internal delegating object + */ + List delegate(); + + /** + * Returns the number of elements in this list. If this list contains + * more than {@code Integer.MAX_VALUE} elements, returns + * {@code Integer.MAX_VALUE}. + * + * @return the number of elements in this list + */ + int size(); + + /** + * Returns {@code true} if this list contains no elements. + * + * @return {@code true} if this list contains no elements + */ + boolean isEmpty(); + + /** + * Returns {@code true} if this list contains the specified element. + * More formally, returns {@code true} if and only if this list contains + * at least one element {@code e} such that + * {@code Objects.equals(o, e)}. + * + * @param o element whose presence in this list is to be tested + * @return {@code true} if this list contains the specified element + * @throws ClassCastException if the type of the specified element + * is incompatible with this list + * (optional) + * @throws NullPointerException if the specified element is null and this + * list does not permit null elements + * (optional) + */ + boolean contains(Object o); + + + /** + * Returns an iterator over the elements in this list in proper sequence. + * + * @return an iterator over the elements in this list in proper sequence + */ + Iterator iterator(); + + /** + * Returns an array containing all of the elements in this list in proper + * sequence (from first to last element). + * + *

The returned array will be "safe" in that no references to it are + * maintained by this list. (In other words, this method must + * allocate a new array even if this list is backed by an array). + * The caller is thus free to modify the returned array. + * + *

This method acts as bridge between array-based and collection-based + * APIs. + * + * @return an array containing all of the elements in this list in proper + * sequence + * @see Arrays#asList(Object[]) + */ + Object[] toArray(); + + + /** + * Returns the element at the specified position in this list. + * + * @param index index of the element to return + * @return the element at the specified position in this list + * @throws IndexOutOfBoundsException if the index is out of range + * ({@code index < 0 || index >= size()}) + */ + E get(int index); +} diff --git a/branch-core/src/main/java/xyz/auriium/branch/results/InitialSearch.java b/branch-core/src/main/java/xyz/auriium/branch/results/InitialSearch.java new file mode 100644 index 0000000..f695f0e --- /dev/null +++ b/branch-core/src/main/java/xyz/auriium/branch/results/InitialSearch.java @@ -0,0 +1,56 @@ +package xyz.auriium.branch.results; + +import xyz.auriium.branch.base.execution.blocks.Block; + +import java.util.*; + +/** + * TODO redux of searcher info/input that relies on a base-provided equality input in order to give + * nodes the option of how they want to compare block equality + */ +public class InitialSearch { + + + private final SearcherEquality equality; + + private final ImmutableList originalStrings; + private final Queue remainingStrings; + private final Queue originalBlocks = new LinkedList<>(); + //private final Queue> nodes = new LinkedList<>(); + + public InitialSearch(SearcherEquality equality, ImmutableList originalStrings) { + this.equality = equality; + + this.originalStrings = originalStrings; + this.remainingStrings = new LinkedList<>(originalStrings.delegate()); + } + + public ImmutableList getOriginalStrings() { + return originalStrings; + } + + public Queue getRemainingStrings() { + return remainingStrings; + } + + public Queue getOriginalBlocks() { + return originalBlocks; + } + + public SearcherEquality getEquality() { + return equality; + } + + public static InitialSearch of(SearcherEquality equality, String[] args) { + return new InitialSearch<>(equality, DelegatingImmutableList.make(Arrays.asList(args))); + + } + + public static InitialSearch withoutTop(InitialSearch search) { + List newBase = new ArrayList<>(search.getOriginalStrings().delegate()); + + newBase.remove(newBase.size() - 1); + + return new InitialSearch<>(search.getEquality(), DelegatingImmutableList.make(newBase)); + } +} diff --git a/branch-core/src/main/java/xyz/auriium/branch/results/PostProcessSearch.java b/branch-core/src/main/java/xyz/auriium/branch/results/PostProcessSearch.java new file mode 100644 index 0000000..45958d6 --- /dev/null +++ b/branch-core/src/main/java/xyz/auriium/branch/results/PostProcessSearch.java @@ -0,0 +1,55 @@ +package xyz.auriium.branch.results; + +import xyz.auriium.branch.base.execution.blocks.Block; +import xyz.auriium.branch.nodes.CommandNode; + +import java.util.List; + +public class PostProcessSearch { + + private final CommandNode foundNode; + + private final ImmutableList originalStrings; + private final List remainingStrings; + + private final List originalBlocks; + private final List allBlocks; + + PostProcessSearch(CommandNode foundNode, ImmutableList originalStrings, List remainingStrings, List originalBlocks, List allBlocks) { + this.foundNode = foundNode; + this.originalStrings = originalStrings; + this.remainingStrings = remainingStrings; + this.originalBlocks = originalBlocks; + this.allBlocks = allBlocks; + } + + public ImmutableList getOriginalStrings() { + return originalStrings; + } + + public List getRemainingStrings() { + return remainingStrings; + } + + public List getOriginalBlocks() { + return originalBlocks; + } + + public List getAllBlocks() { + return allBlocks; + } + + public CommandNode getFoundNode() { + return foundNode; + } + + public static PostProcessSearch generate(PreProcessSearch input) { + return new PostProcessSearch<>( + input.getFoundNode(), + input.getOriginalStrings(), + input.getRemainingStrings(), + input.getOriginalBlocks(), + List.copyOf(input.getRemainingBlocks()) + ); + } +} diff --git a/branch-core/src/main/java/xyz/auriium/branch/results/PreProcessSearch.java b/branch-core/src/main/java/xyz/auriium/branch/results/PreProcessSearch.java new file mode 100644 index 0000000..f04e14e --- /dev/null +++ b/branch-core/src/main/java/xyz/auriium/branch/results/PreProcessSearch.java @@ -0,0 +1,56 @@ +package xyz.auriium.branch.results; + +import xyz.auriium.branch.base.execution.blocks.Block; +import xyz.auriium.branch.nodes.CommandNode; + +import java.util.LinkedList; +import java.util.List; +import java.util.Queue; + +public class PreProcessSearch { + + private final CommandNode foundNode; + + private final ImmutableList originalStrings; + private final List remainingStrings; + + private final List originalBlocks; + private final Queue remainingBlocks; + + public PreProcessSearch(CommandNode foundNode, ImmutableList originalStrings, List remainingStrings, List originalBlocks, Queue remainingBlocks) { + this.foundNode = foundNode; + this.originalStrings = originalStrings; + this.remainingStrings = remainingStrings; + this.originalBlocks = originalBlocks; + this.remainingBlocks = remainingBlocks; + } + + public ImmutableList getOriginalStrings() { + return originalStrings; + } + + public List getRemainingStrings() { + return remainingStrings; + } + + public List getOriginalBlocks() { + return originalBlocks; + } + + public Queue getRemainingBlocks() { + return remainingBlocks; + } + + public CommandNode getFoundNode() { + return foundNode; + } + + public static PreProcessSearch generate(CommandNode node, InitialSearch input) { + return new PreProcessSearch<>( + node, + input.getOriginalStrings(), + List.copyOf(input.getRemainingStrings()), + List.copyOf(input.getOriginalBlocks()), + new LinkedList<>()); + } +} diff --git a/core/src/main/java/me/aurium/branch/nodes/results/model/Result.java b/branch-core/src/main/java/xyz/auriium/branch/results/Result.java similarity index 73% rename from core/src/main/java/me/aurium/branch/nodes/results/model/Result.java rename to branch-core/src/main/java/xyz/auriium/branch/results/Result.java index 8653301..24b0bd6 100644 --- a/core/src/main/java/me/aurium/branch/nodes/results/model/Result.java +++ b/branch-core/src/main/java/xyz/auriium/branch/results/Result.java @@ -19,9 +19,9 @@ * */ -package me.aurium.branch.nodes.results.model; +package xyz.auriium.branch.results; -import me.aurium.branch.interfacing.Response; +import xyz.auriium.branch.interfacing.exceptional.Anomaly; public interface Result { @@ -29,13 +29,17 @@ public interface Result { T getSuccess(); - Response getFailure(); + Anomaly getFailure(); - static Result success(X t) { + static SuccessfulResult success(X t) { return new SuccessfulResult<>(t); } - static Result fail(Response failure) { + static FailingResult fail(Anomaly failure) { return new FailingResult<>(failure); } + static Result transmuteFail(Result result) { + return Result.fail(result.getFailure()); + } + } diff --git a/branch-core/src/main/java/xyz/auriium/branch/results/SearchPair.java b/branch-core/src/main/java/xyz/auriium/branch/results/SearchPair.java new file mode 100644 index 0000000..c3b9174 --- /dev/null +++ b/branch-core/src/main/java/xyz/auriium/branch/results/SearchPair.java @@ -0,0 +1,20 @@ +package xyz.auriium.branch.results; + +public class SearchPair { + + private final PostProcessSearch search; + private final O object; + + public SearchPair(PostProcessSearch search, O object) { + this.search = search; + this.object = object; + } + + public PostProcessSearch getSearch() { + return search; + } + + public O getObject() { + return object; + } +} diff --git a/branch-core/src/main/java/xyz/auriium/branch/results/SearcherEquality.java b/branch-core/src/main/java/xyz/auriium/branch/results/SearcherEquality.java new file mode 100644 index 0000000..7ab9034 --- /dev/null +++ b/branch-core/src/main/java/xyz/auriium/branch/results/SearcherEquality.java @@ -0,0 +1,12 @@ +package xyz.auriium.branch.results; + +import xyz.auriium.branch.base.execution.blocks.Block; + +/** + * Represents something that compares blocks + */ +public interface SearcherEquality { + + boolean equal(Block block, String popped); + +} diff --git a/core/src/main/java/me/aurium/branch/nodes/results/model/SuccessfulResult.java b/branch-core/src/main/java/xyz/auriium/branch/results/SuccessfulResult.java similarity index 90% rename from core/src/main/java/me/aurium/branch/nodes/results/model/SuccessfulResult.java rename to branch-core/src/main/java/xyz/auriium/branch/results/SuccessfulResult.java index 25174f2..5cd3d3c 100644 --- a/core/src/main/java/me/aurium/branch/nodes/results/model/SuccessfulResult.java +++ b/branch-core/src/main/java/xyz/auriium/branch/results/SuccessfulResult.java @@ -19,9 +19,9 @@ * */ -package me.aurium.branch.nodes.results.model; +package xyz.auriium.branch.results; -import me.aurium.branch.interfacing.Response; +import xyz.auriium.branch.interfacing.exceptional.Anomaly; public class SuccessfulResult implements Result { @@ -42,7 +42,7 @@ public T getSuccess() { } @Override - public Response getFailure() { + public Anomaly getFailure() { throw new IllegalStateException("Attempted to get failure of a successful result!"); } } diff --git a/core/src/main/java/me/aurium/branch/centralized/typeadapter/CommonAdapter.java b/branch-core/src/main/java/xyz/auriium/branch/typeadapter/CommonAdapter.java similarity index 83% rename from core/src/main/java/me/aurium/branch/centralized/typeadapter/CommonAdapter.java rename to branch-core/src/main/java/xyz/auriium/branch/typeadapter/CommonAdapter.java index fb18fcd..4953510 100644 --- a/core/src/main/java/me/aurium/branch/centralized/typeadapter/CommonAdapter.java +++ b/branch-core/src/main/java/xyz/auriium/branch/typeadapter/CommonAdapter.java @@ -19,9 +19,9 @@ * */ -package me.aurium.branch.centralized.typeadapter; +package xyz.auriium.branch.typeadapter; -import me.aurium.branch.interfacing.responses.FailedAdaptingResponse; +import xyz.auriium.branch.interfacing.exceptional.anomalies.WrongTypeParseAnomaly; /** * Represents an adapter that does not convert and simply returns the same object @@ -40,7 +40,11 @@ default boolean canAdapt(T input) { } @Override - default FailedAdaptingResponse failedParseResponse(T input) { + default WrongTypeParseAnomaly failedParseResponse(T input) { throw new IllegalStateException("How did you get here (Since canAdapt is always true this should never occur?)"); } + + default String adapterType() { + return ""; + } } diff --git a/core/src/main/java/me/aurium/branch/centralized/typeadapter/ManagerAdapter.java b/branch-core/src/main/java/xyz/auriium/branch/typeadapter/ManagerAdapter.java similarity index 86% rename from core/src/main/java/me/aurium/branch/centralized/typeadapter/ManagerAdapter.java rename to branch-core/src/main/java/xyz/auriium/branch/typeadapter/ManagerAdapter.java index 56e51f9..3818b7a 100644 --- a/core/src/main/java/me/aurium/branch/centralized/typeadapter/ManagerAdapter.java +++ b/branch-core/src/main/java/xyz/auriium/branch/typeadapter/ManagerAdapter.java @@ -19,9 +19,9 @@ * */ -package me.aurium.branch.centralized.typeadapter; +package xyz.auriium.branch.typeadapter; -import me.aurium.branch.interfacing.responses.FailedAdaptingResponse; +import xyz.auriium.branch.interfacing.exceptional.anomalies.WrongTypeParseAnomaly; /** * Represents something that can convert an object of a certain type to another object @@ -35,6 +35,6 @@ public interface ManagerAdapter { OUTPUT adapt(INPUT input); boolean canAdapt(INPUT input); - FailedAdaptingResponse failedParseResponse(INPUT input); + WrongTypeParseAnomaly failedParseResponse(INPUT input); } diff --git a/branch-core/src/main/java/xyz/auriium/branch/typeadapter/ReduxAdapter.java b/branch-core/src/main/java/xyz/auriium/branch/typeadapter/ReduxAdapter.java new file mode 100644 index 0000000..4cb3b09 --- /dev/null +++ b/branch-core/src/main/java/xyz/auriium/branch/typeadapter/ReduxAdapter.java @@ -0,0 +1,16 @@ +package xyz.auriium.branch.typeadapter; + +import xyz.auriium.branch.results.Result; + +/** + * New version of adapter in accordance with new design + * @param input type + * @param output type + * + * TODO: rename to SenderParser + */ +public interface ReduxAdapter { + + Result parse(I input); + +} diff --git a/core/src/main/java/me/aurium/branch/centralized/typeadapter/StandardCommonAdapter.java b/branch-core/src/main/java/xyz/auriium/branch/typeadapter/StandardCommonAdapter.java similarity index 94% rename from core/src/main/java/me/aurium/branch/centralized/typeadapter/StandardCommonAdapter.java rename to branch-core/src/main/java/xyz/auriium/branch/typeadapter/StandardCommonAdapter.java index bee22dd..3b6cfed 100644 --- a/core/src/main/java/me/aurium/branch/centralized/typeadapter/StandardCommonAdapter.java +++ b/branch-core/src/main/java/xyz/auriium/branch/typeadapter/StandardCommonAdapter.java @@ -19,7 +19,7 @@ * */ -package me.aurium.branch.centralized.typeadapter; +package xyz.auriium.branch.typeadapter; /** * Simple implementation"" diff --git a/core-tests/src/test/java/me/aurium/branch/ExecutionTest.java b/branch-core/src/test/java/ExecutionTest.java similarity index 59% rename from core-tests/src/test/java/me/aurium/branch/ExecutionTest.java rename to branch-core/src/test/java/ExecutionTest.java index 5ebc147..0eb0f71 100644 --- a/core-tests/src/test/java/me/aurium/branch/ExecutionTest.java +++ b/branch-core/src/test/java/ExecutionTest.java @@ -19,16 +19,28 @@ * */ -package me.aurium.branch; - -import me.aurium.branch.tests.StringManager; -import org.junit.platform.commons.logging.Logger; -import org.junit.platform.commons.logging.LoggerFactory; - public class ExecutionTest { - private final static Logger logger = LoggerFactory.getLogger(ExecutionTest.class); + /*private final static Logger logger = LoggerFactory.getLogger(ExecutionTest.class); private final StringManager manager = new StringManager(); + private final NodeSource source = manager.getSource(); + + public void test1() { + + manager.newCommandWithBuilder() + .withNode(source.single() + .withHandler(context -> { + + }).build() + ).finish(); + + manager.newCommandWithNode(SingleNode.of("hi", act -> { + + },EmptyPermission.instance(), new StringDescription("cum"))); + + //oh my god i can't believe singlenode is actually working + + }*/ } diff --git a/branch-core/src/test/java/xyz/auriium/branch/tests/centralized/MockAdapter.java b/branch-core/src/test/java/xyz/auriium/branch/tests/centralized/MockAdapter.java new file mode 100644 index 0000000..c5a9a18 --- /dev/null +++ b/branch-core/src/test/java/xyz/auriium/branch/tests/centralized/MockAdapter.java @@ -0,0 +1,6 @@ +package xyz.auriium.branch.tests.centralized; + +import xyz.auriium.branch.typeadapter.CommonAdapter; + +public class MockAdapter implements CommonAdapter { +} diff --git a/branch-core/src/test/java/xyz/auriium/branch/tests/centralized/MockContext.java b/branch-core/src/test/java/xyz/auriium/branch/tests/centralized/MockContext.java new file mode 100644 index 0000000..b774f65 --- /dev/null +++ b/branch-core/src/test/java/xyz/auriium/branch/tests/centralized/MockContext.java @@ -0,0 +1,36 @@ +package xyz.auriium.branch.tests.centralized; + +import xyz.auriium.branch.base.NodeContext; + +public class MockContext implements NodeContext { + + private final MockSender sender; + private final String alias; + private final String[] args; + + public MockContext(MockSender sender, String alias, String[] args) { + this.sender = sender; + this.alias = alias; + this.args = args; + } + + @Override + public MockSender getSender() { + return sender; + } + + @Override + public String getAlias() { + return alias; + } + + @Override + public String[] getArgs() { + return args; + } + + @Override + public boolean hasStringPermissible(String string) { + return sender.hasPermission(string); + } +} diff --git a/branch-core/src/test/java/xyz/auriium/branch/tests/centralized/MockContextProducer.java b/branch-core/src/test/java/xyz/auriium/branch/tests/centralized/MockContextProducer.java new file mode 100644 index 0000000..d681487 --- /dev/null +++ b/branch-core/src/test/java/xyz/auriium/branch/tests/centralized/MockContextProducer.java @@ -0,0 +1,11 @@ +package xyz.auriium.branch.tests.centralized; + +import xyz.auriium.branch.base.ContextProvider; +import xyz.auriium.branch.base.NodeContext; + +public class MockContextProducer implements ContextProvider { + @Override + public NodeContext produce(MockSender sender, String alias, String[] strings) { + return new MockContext(sender, alias, strings); + } +} diff --git a/branch-core/src/test/java/xyz/auriium/branch/tests/centralized/MockManager.java b/branch-core/src/test/java/xyz/auriium/branch/tests/centralized/MockManager.java new file mode 100644 index 0000000..6a133e2 --- /dev/null +++ b/branch-core/src/test/java/xyz/auriium/branch/tests/centralized/MockManager.java @@ -0,0 +1,49 @@ +package xyz.auriium.branch.tests.centralized; + +import xyz.auriium.branch.CentralizedManager; +import xyz.auriium.branch.CentralizedManagerBinder; +import xyz.auriium.branch.NodeSource; +import xyz.auriium.branch.base.NodeBase; +import xyz.auriium.branch.base.NodeBaseBuilder; +import xyz.auriium.branch.typeadapter.ManagerAdapter; +import xyz.auriium.branch.nodes.CommandNode; + +public class MockManager implements CentralizedManager { + + private final static MockAdapter adapter = new MockAdapter(); + + @Override + public CentralizedManagerBinder getBinder(Void platform) { + throw new IllegalStateException("Cannot bind a mock manager to any platform (lol)"); + } + + @Override + public NodeSource getSource() { + return null; + } + + @Override + public NodeBaseBuilder newCommandWithBuilder() { + return new NodeBaseBuilder<>(this, adapter); + } + + @Override + public NodeBaseBuilder newCommandWithBuilder(ManagerAdapter adapter) { + return new NodeBaseBuilder<>(this, adapter); + } + + @Override + public void newCommandWithNode(CommandNode node) { + //TODO + } + + @Override + public void newCommandWithNode(CommandNode node, ManagerAdapter adapter) { + //TODO + } + + @Override + public void newCommand(NodeBase base) { + //TODO + } +} diff --git a/branch-core/src/test/java/xyz/auriium/branch/tests/centralized/MockSender.java b/branch-core/src/test/java/xyz/auriium/branch/tests/centralized/MockSender.java new file mode 100644 index 0000000..c7ebdcf --- /dev/null +++ b/branch-core/src/test/java/xyz/auriium/branch/tests/centralized/MockSender.java @@ -0,0 +1,22 @@ +package xyz.auriium.branch.tests.centralized; + +import java.util.Arrays; +import java.util.UUID; + +public class MockSender { + + private final UUID field = UUID.randomUUID(); + private final String[] permissions; + + public MockSender(String... permissions) { + this.permissions = permissions; + } + + public UUID getField() { + return field; + } + + public boolean hasPermission(String str) { + return Arrays.asList(permissions).contains(str); + } +} diff --git a/branch-core/src/test/java/xyz/auriium/branch/tests/execution/BlockIT.java b/branch-core/src/test/java/xyz/auriium/branch/tests/execution/BlockIT.java new file mode 100644 index 0000000..e833ee5 --- /dev/null +++ b/branch-core/src/test/java/xyz/auriium/branch/tests/execution/BlockIT.java @@ -0,0 +1,4 @@ +package xyz.auriium.branch.tests.execution; + +public class BlockIT { +} diff --git a/branch-core/src/test/java/xyz/auriium/branch/tests/fallback/permission/PermissionTest.java b/branch-core/src/test/java/xyz/auriium/branch/tests/fallback/permission/PermissionTest.java new file mode 100644 index 0000000..c5552f1 --- /dev/null +++ b/branch-core/src/test/java/xyz/auriium/branch/tests/fallback/permission/PermissionTest.java @@ -0,0 +1,45 @@ +package xyz.auriium.branch.tests.fallback.permission; + +import org.junit.jupiter.api.Test; +import xyz.auriium.branch.base.permissions.EmptyPermission; +import xyz.auriium.branch.base.permissions.StringPermission; +import xyz.auriium.branch.tests.centralized.MockContextProducer; +import xyz.auriium.branch.tests.centralized.MockSender; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class PermissionTest { + + private final MockContextProducer producer = new MockContextProducer(); + + @Test + public void whenEmptyPermission_alwaysSuccessful() { + EmptyPermission permission = EmptyPermission.instance(); + + assertTrue( + permission.attempt( + producer.produce(new MockSender(), "alias", new String[]{}) + ) + ); + + } + + @Test + public void whenStringPermission_checkValue() { + var permission = new StringPermission("permissionTest"); + + assertTrue(permission.attempt( + producer.produce(new MockSender("permissionTest"), "test", new String[]{}) + )); + + assertFalse(permission.attempt( + producer.produce(new MockSender("permissionYouDontHave"), "test", new String[]{}) + )); + + + } + + + +} diff --git a/branch-core/src/test/java/xyz/auriium/branch/tests/interfacing/MessageBossTest.java b/branch-core/src/test/java/xyz/auriium/branch/tests/interfacing/MessageBossTest.java new file mode 100644 index 0000000..b0c09f7 --- /dev/null +++ b/branch-core/src/test/java/xyz/auriium/branch/tests/interfacing/MessageBossTest.java @@ -0,0 +1,4 @@ +package xyz.auriium.branch.tests.interfacing; + +public class MessageBossTest { +} diff --git a/branch-core/src/test/java/xyz/auriium/branch/tests/node/single/SingleNodeManagedIT.java b/branch-core/src/test/java/xyz/auriium/branch/tests/node/single/SingleNodeManagedIT.java new file mode 100644 index 0000000..a9d33e8 --- /dev/null +++ b/branch-core/src/test/java/xyz/auriium/branch/tests/node/single/SingleNodeManagedIT.java @@ -0,0 +1,4 @@ +package xyz.auriium.branch.tests.node.single; + +public class SingleNodeManagedIT { +} diff --git a/branch-core/src/test/java/xyz/auriium/branch/tests/node/single/SingleNodeSearcherTest.java b/branch-core/src/test/java/xyz/auriium/branch/tests/node/single/SingleNodeSearcherTest.java new file mode 100644 index 0000000..f5051f7 --- /dev/null +++ b/branch-core/src/test/java/xyz/auriium/branch/tests/node/single/SingleNodeSearcherTest.java @@ -0,0 +1,5 @@ +package xyz.auriium.branch.tests.node.single; + +//tests not-direct features like searching +public class SingleNodeSearcherTest { +} diff --git a/branch-core/src/test/java/xyz/auriium/branch/tests/node/single/SingleNodeTest.java b/branch-core/src/test/java/xyz/auriium/branch/tests/node/single/SingleNodeTest.java new file mode 100644 index 0000000..710dd8a --- /dev/null +++ b/branch-core/src/test/java/xyz/auriium/branch/tests/node/single/SingleNodeTest.java @@ -0,0 +1,14 @@ +package xyz.auriium.branch.tests.node.single; + +import org.junit.jupiter.api.Test; + +//Tests direct implementation features of an isolated single node +public class SingleNodeTest { + + @Test + public void nodeTest() { + + + + } +} diff --git a/branch-core/src/test/java/xyz/auriium/branch/tests/node/utility/ImmutableListTest.java b/branch-core/src/test/java/xyz/auriium/branch/tests/node/utility/ImmutableListTest.java new file mode 100644 index 0000000..e809441 --- /dev/null +++ b/branch-core/src/test/java/xyz/auriium/branch/tests/node/utility/ImmutableListTest.java @@ -0,0 +1,60 @@ +package xyz.auriium.branch.tests.node.utility; + + +import org.junit.jupiter.api.Test; +import xyz.auriium.branch.results.DelegatingImmutableList; +import xyz.auriium.branch.results.ImmutableList; + +import java.util.ArrayList; +import java.util.List; + +import static org.junit.jupiter.api.Assertions.*; + +public class ImmutableListTest { + + @Test + public void whenListCreated_IsSeparate() { + List list = new ArrayList<>(); + ImmutableList immutableList = DelegatingImmutableList.make(list); + + list.add("test"); + + assertFalse(() -> immutableList.contains("test")); + assertTrue(immutableList::isEmpty); + } + + @Test + public void whenListCreated_CannotModifyDelegate() { + ImmutableList immutableList = DelegatingImmutableList.make(); + + assertThrows(UnsupportedOperationException.class, () -> { + immutableList.delegate().add("i am going to ruin this list's day"); //THROWS + }); + } + + @Test + public void whenListCreated_ImmutableSharesValues() { + List toDelegate = new ArrayList<>(); + toDelegate.add("test"); + + ImmutableList immutableList = DelegatingImmutableList.make(toDelegate); + + assertTrue(toDelegate.contains("test")); + assertTrue(immutableList.contains("test")); + + } + + @Test + public void whenImmutableListCopied_CanModifyCopy() { + List toDelegate = new ArrayList<>(); + toDelegate.add("test"); + + ImmutableList immutableList = DelegatingImmutableList.make(toDelegate); + List modifiable = new ArrayList<>(immutableList.delegate()); + + modifiable.remove("test"); + + assertTrue(modifiable.isEmpty()); + } + +} diff --git a/branch-core/src/test/java/xyz/auriium/branch/tests/node/utility/MockAnomaly.java b/branch-core/src/test/java/xyz/auriium/branch/tests/node/utility/MockAnomaly.java new file mode 100644 index 0000000..bb6da47 --- /dev/null +++ b/branch-core/src/test/java/xyz/auriium/branch/tests/node/utility/MockAnomaly.java @@ -0,0 +1,12 @@ +package xyz.auriium.branch.tests.node.utility; + +import xyz.auriium.branch.interfacing.exceptional.Anomaly; +import xyz.auriium.branch.interfacing.exceptional.AnomalyType; + +public class MockAnomaly implements Anomaly { + + @Override + public AnomalyType type() { + return AnomalyType.INVALID_SYNTAX; + } +} diff --git a/branch-core/src/test/java/xyz/auriium/branch/tests/node/utility/ResultTest.java b/branch-core/src/test/java/xyz/auriium/branch/tests/node/utility/ResultTest.java new file mode 100644 index 0000000..e2835c1 --- /dev/null +++ b/branch-core/src/test/java/xyz/auriium/branch/tests/node/utility/ResultTest.java @@ -0,0 +1,27 @@ +package xyz.auriium.branch.tests.node.utility; + +import org.junit.jupiter.api.Test; +import xyz.auriium.branch.interfacing.exceptional.AnomalyType; +import xyz.auriium.branch.results.Result; + +import static org.junit.jupiter.api.Assertions.*; + +public class ResultTest { + + @Test + public void whenResultSuppliedAnomaly_isUnsuccessfulAndHasAnomaly() { + Result result = Result.fail(new MockAnomaly()); + + assertFalse(result.isSuccessful()); + assertEquals(result.getFailure().type(), AnomalyType.INVALID_SYNTAX); + } + + @Test + public void whenResultSuppliedSuccess_isSuccessfulAndHasSuccess() { + Result result = Result.success("test"); + + assertTrue(result.isSuccessful()); + assertEquals(result.getSuccess(), "test"); + } + +} diff --git a/branch-spigot-impl/branch-spigot-impl.iml b/branch-spigot-impl/branch-spigot-impl.iml new file mode 100644 index 0000000..0a1c21a --- /dev/null +++ b/branch-spigot-impl/branch-spigot-impl.iml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/spigot-impl/pom.xml b/branch-spigot-impl/pom.xml similarity index 86% rename from spigot-impl/pom.xml rename to branch-spigot-impl/pom.xml index a4e66d9..6ab95e3 100644 --- a/spigot-impl/pom.xml +++ b/branch-spigot-impl/pom.xml @@ -25,7 +25,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> branch - me.aurium + xyz.auriium 0.1.0 4.0.0 @@ -39,14 +39,9 @@ - me.aurium + xyz.auriium branch-core - - - com.destroystokyo.paper - paper-api - 1.16.5-R0.1-SNAPSHOT - provided + 0.1.0 org.spigotmc diff --git a/spigot-impl/src/main/java/me/aurium/branch/spigot/CommandWrapper.java b/branch-spigot-impl/src/main/java/xyz/auriium/branch/spigot/CommandWrapper.java similarity index 78% rename from spigot-impl/src/main/java/me/aurium/branch/spigot/CommandWrapper.java rename to branch-spigot-impl/src/main/java/xyz/auriium/branch/spigot/CommandWrapper.java index a30ae1e..ca0de66 100644 --- a/spigot-impl/src/main/java/me/aurium/branch/spigot/CommandWrapper.java +++ b/branch-spigot-impl/src/main/java/xyz/auriium/branch/spigot/CommandWrapper.java @@ -19,12 +19,11 @@ * */ -package me.aurium.branch.spigot; +package xyz.auriium.branch.spigot; -import me.aurium.branch.centralized.base.NodeBase; +import xyz.auriium.branch.base.NodeBase; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; -import org.jetbrains.annotations.NotNull; import java.util.List; @@ -38,14 +37,14 @@ public CommandWrapper(NodeBase base) { } @Override - public boolean execute(@NotNull CommandSender commandSender, @NotNull String s, String[] strings) { + public boolean execute(CommandSender commandSender, String s, String[] strings) { base.execute(commandSender, s, strings); return true; } @Override - public @NotNull List tabComplete(@NotNull CommandSender sender, @NotNull String alias, String[] args) throws IllegalArgumentException { + public List tabComplete(CommandSender sender, String alias, String[] args) throws IllegalArgumentException { return base.suggest(sender, alias, args); } } diff --git a/spigot-impl/src/main/java/me/aurium/branch/spigot/message/FormattedMessage.java b/branch-spigot-impl/src/main/java/xyz/auriium/branch/spigot/SpigotContext.java similarity index 63% rename from spigot-impl/src/main/java/me/aurium/branch/spigot/message/FormattedMessage.java rename to branch-spigot-impl/src/main/java/xyz/auriium/branch/spigot/SpigotContext.java index fad79d9..b8f45b2 100644 --- a/spigot-impl/src/main/java/me/aurium/branch/spigot/message/FormattedMessage.java +++ b/branch-spigot-impl/src/main/java/xyz/auriium/branch/spigot/SpigotContext.java @@ -19,19 +19,24 @@ * */ -package me.aurium.branch.spigot.message; +package xyz.auriium.branch.spigot; + -import me.aurium.branch.interfacing.Message; import org.bukkit.command.CommandSender; +import xyz.auriium.branch.nodes.CommandNode; -public abstract class FormattedMessage implements Message { +public class SpigotContext extends AbstractNodeContext { - //TODO private final Formatter formatter; + private final T sender; - protected abstract void accept(C sender, String postFormatted); + protected SpigotContext(T sender, String alias, String[] args, CommandNode baseNode, SearchInfo result) { + super(sender, alias, args, baseNode, result); - @Override - public void accept(C sender) { + this.sender = sender; + } + @Override + public boolean hasStringPermissible(String string) { + return sender.hasPermission(string); } } diff --git a/spigot-impl/src/main/java/me/aurium/branch/spigot/SpigotContextProvider.java b/branch-spigot-impl/src/main/java/xyz/auriium/branch/spigot/SpigotContextProvider.java similarity index 69% rename from spigot-impl/src/main/java/me/aurium/branch/spigot/SpigotContextProvider.java rename to branch-spigot-impl/src/main/java/xyz/auriium/branch/spigot/SpigotContextProvider.java index 6080886..2091ebc 100644 --- a/spigot-impl/src/main/java/me/aurium/branch/spigot/SpigotContextProvider.java +++ b/branch-spigot-impl/src/main/java/xyz/auriium/branch/spigot/SpigotContextProvider.java @@ -19,26 +19,18 @@ * */ -package me.aurium.branch.spigot; +package xyz.auriium.branch.spigot; -import me.aurium.branch.execution.ContextProvider; -import me.aurium.branch.execution.NodeContext; -import me.aurium.branch.interfacing.handlers.InterfacingHandler; -import me.aurium.branch.nodes.CommandNode; -import me.aurium.branch.nodes.results.SearchInfo; +import xyz.auriium.branch.base.ContextProvider; +import xyz.auriium.branch.base.NodeContext; +import xyz.auriium.branch.nodes.CommandNode; import org.bukkit.command.CommandSender; public class SpigotContextProvider implements ContextProvider { - private final InterfacingHandler handler; - - public SpigotContextProvider(InterfacingHandler handler) { - this.handler = handler; - } - @Override public NodeContext produce(C sender, String alias, String[] strings, CommandNode baseNode, SearchInfo search) { - return new SpigotContext<>(sender,alias,strings,baseNode,search, handler); + return new SpigotContext<>(sender,alias,strings,baseNode,search); } } diff --git a/spigot-impl/src/main/java/me/aurium/branch/spigot/SpigotManager.java b/branch-spigot-impl/src/main/java/xyz/auriium/branch/spigot/SpigotManager.java similarity index 70% rename from spigot-impl/src/main/java/me/aurium/branch/spigot/SpigotManager.java rename to branch-spigot-impl/src/main/java/xyz/auriium/branch/spigot/SpigotManager.java index a6629e9..a103b54 100644 --- a/spigot-impl/src/main/java/me/aurium/branch/spigot/SpigotManager.java +++ b/branch-spigot-impl/src/main/java/xyz/auriium/branch/spigot/SpigotManager.java @@ -19,21 +19,19 @@ * */ -package me.aurium.branch.spigot; - -import me.aurium.branch.centralized.CentralizedManager; -import me.aurium.branch.centralized.CentralizedManagerBinder; -import me.aurium.branch.centralized.NodeSource; -import me.aurium.branch.centralized.base.NodeBase; -import me.aurium.branch.centralized.typeadapter.ManagerAdapter; -import me.aurium.branch.centralized.base.NodeBaseBuilder; -import me.aurium.branch.fallback.strategies.OneBackStrategy; -import me.aurium.branch.interfacing.handlers.InterfacingHandler; -import me.aurium.branch.interfacing.handlers.MessageMap; -import me.aurium.branch.spigot.adapter.SenderAdapter; -import me.aurium.branch.spigot.message.SpigotMessageMap; +package xyz.auriium.branch.spigot; + import org.bukkit.command.CommandSender; import org.bukkit.plugin.java.JavaPlugin; +import xyz.auriium.branch.CentralizedManager; +import xyz.auriium.branch.CentralizedManagerBinder; +import xyz.auriium.branch.NodeSource; +import xyz.auriium.branch.base.NodeBase; +import xyz.auriium.branch.base.NodeBaseBuilder; +import xyz.auriium.branch.typeadapter.ManagerAdapter; +import xyz.auriium.branch.base.execution.OneBackStrategy; +import xyz.auriium.branch.nodes.CommandNode; +import xyz.auriium.branch.spigot.adapter.SenderAdapter; import java.util.HashSet; import java.util.Set; @@ -58,7 +56,7 @@ public SpigotManager() { @Override public CentralizedManagerBinder getBinder(JavaPlugin platform) { - return new SpigotManagerBinder(platform.getName(), platform.getServer().getCommandMap(), senders); + return new SpigotManagerBinder(platform.getName(), null, senders); } @Override @@ -67,17 +65,27 @@ public NodeSource getSource() { } @Override - public NodeBaseBuilder newCommand() { + public NodeBaseBuilder newCommandWithBuilder() { return new NodeBaseBuilder<>(this, defaultAdapter, new OneBackStrategy<>(), new SpigotContextProvider<>(defaultInterfacing), defaultInterfacing); } @Override - public NodeBaseBuilder newCommand(ManagerAdapter adapter) { + public NodeBaseBuilder newCommandWithBuilder(ManagerAdapter adapter) { return new NodeBaseBuilder<>(this,adapter, new OneBackStrategy<>(), new SpigotContextProvider<>(defaultInterfacing), defaultInterfacing); } @Override - public void injectCommand(NodeBase base) { + public void newCommandWithNode(CommandNode node) { + + } + + @Override + public void newCommandWithNode(CommandNode node, ManagerAdapter adapter) { + + } + + @Override + public void newCommand(NodeBase base) { senders.add(base); } diff --git a/spigot-impl/src/main/java/me/aurium/branch/spigot/SpigotManagerBinder.java b/branch-spigot-impl/src/main/java/xyz/auriium/branch/spigot/SpigotManagerBinder.java similarity index 91% rename from spigot-impl/src/main/java/me/aurium/branch/spigot/SpigotManagerBinder.java rename to branch-spigot-impl/src/main/java/xyz/auriium/branch/spigot/SpigotManagerBinder.java index 0b69afb..3e902d1 100644 --- a/spigot-impl/src/main/java/me/aurium/branch/spigot/SpigotManagerBinder.java +++ b/branch-spigot-impl/src/main/java/xyz/auriium/branch/spigot/SpigotManagerBinder.java @@ -19,10 +19,10 @@ * */ -package me.aurium.branch.spigot; +package xyz.auriium.branch.spigot; -import me.aurium.branch.centralized.CentralizedManagerBinder; -import me.aurium.branch.centralized.base.NodeBase; +import xyz.auriium.branch.CentralizedManagerBinder; +import xyz.auriium.branch.base.NodeBase; import org.bukkit.command.CommandMap; import org.bukkit.command.CommandSender; diff --git a/spigot-impl/src/main/java/me/aurium/branch/spigot/adapter/PlayerAdapter.java b/branch-spigot-impl/src/main/java/xyz/auriium/branch/spigot/adapter/PlayerAdapter.java similarity index 79% rename from spigot-impl/src/main/java/me/aurium/branch/spigot/adapter/PlayerAdapter.java rename to branch-spigot-impl/src/main/java/xyz/auriium/branch/spigot/adapter/PlayerAdapter.java index ce98e38..c26eda9 100644 --- a/spigot-impl/src/main/java/me/aurium/branch/spigot/adapter/PlayerAdapter.java +++ b/branch-spigot-impl/src/main/java/xyz/auriium/branch/spigot/adapter/PlayerAdapter.java @@ -19,10 +19,10 @@ * */ -package me.aurium.branch.spigot.adapter; +package xyz.auriium.branch.spigot.adapter; -import me.aurium.branch.interfacing.responses.FailedAdaptingResponse; -import me.aurium.branch.centralized.typeadapter.ManagerAdapter; +import xyz.auriium.branch.interfacing.exceptional.anomalies.WrongTypeParseAnomaly; +import xyz.auriium.branch.typeadapter.ManagerAdapter; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -43,8 +43,8 @@ public boolean canAdapt(CommandSender sender) { } @Override - public FailedAdaptingResponse failedParseResponse(CommandSender sender) { - return new FailedAdaptingResponse(Player.class, CommandSender.class); + public WrongTypeParseAnomaly failedParseResponse(CommandSender sender) { + return new WrongTypeParseAnomaly(Player.class, CommandSender.class); } diff --git a/spigot-impl/src/main/java/me/aurium/branch/spigot/adapter/SenderAdapter.java b/branch-spigot-impl/src/main/java/xyz/auriium/branch/spigot/adapter/SenderAdapter.java similarity index 89% rename from spigot-impl/src/main/java/me/aurium/branch/spigot/adapter/SenderAdapter.java rename to branch-spigot-impl/src/main/java/xyz/auriium/branch/spigot/adapter/SenderAdapter.java index aeb67fd..221d38b 100644 --- a/spigot-impl/src/main/java/me/aurium/branch/spigot/adapter/SenderAdapter.java +++ b/branch-spigot-impl/src/main/java/xyz/auriium/branch/spigot/adapter/SenderAdapter.java @@ -19,9 +19,9 @@ * */ -package me.aurium.branch.spigot.adapter; +package xyz.auriium.branch.spigot.adapter; -import me.aurium.branch.centralized.typeadapter.CommonAdapter; +import xyz.auriium.branch.typeadapter.CommonAdapter; import org.bukkit.command.CommandSender; public class SenderAdapter implements CommonAdapter { diff --git a/spigot-impl/src/main/java/me/aurium/branch/spigot/permisison/SpigotPermission.java b/branch-spigot-impl/src/main/java/xyz/auriium/branch/spigot/permisison/SpigotPermission.java similarity index 57% rename from spigot-impl/src/main/java/me/aurium/branch/spigot/permisison/SpigotPermission.java rename to branch-spigot-impl/src/main/java/xyz/auriium/branch/spigot/permisison/SpigotPermission.java index e23d7b4..5a826c3 100644 --- a/spigot-impl/src/main/java/me/aurium/branch/spigot/permisison/SpigotPermission.java +++ b/branch-spigot-impl/src/main/java/xyz/auriium/branch/spigot/permisison/SpigotPermission.java @@ -1,6 +1,7 @@ -package me.aurium.branch.spigot.permisison; +package xyz.auriium.branch.spigot.permisison; -import me.aurium.branch.fallback.permissions.Permission; +import xyz.auriium.branch.base.NodeContext; +import xyz.auriium.branch.base.permissions.Permission; import org.bukkit.command.CommandSender; public class SpigotPermission implements Permission { @@ -12,8 +13,8 @@ public SpigotPermission(String permission) { } @Override - public boolean attempt(CommandSender sender, String alias, String[] args) { - return sender.hasPermission(permission); + public boolean attempt(NodeContext nodeContext) { + return nodeContext.hasStringPermissible(permission); } @Override diff --git a/branch-spigot-impl/src/test/java/me/aurium/beetle/KitpvpCommand.java b/branch-spigot-impl/src/test/java/me/aurium/beetle/KitpvpCommand.java new file mode 100644 index 0000000..6e0e7e9 --- /dev/null +++ b/branch-spigot-impl/src/test/java/me/aurium/beetle/KitpvpCommand.java @@ -0,0 +1,9 @@ +package me.aurium.beetle; + + +public class KitpvpCommand { + + + + +} diff --git a/spigot-impl/src/test/java/me/aurium/branch/spigot/ExampleBinding.java b/branch-spigot-impl/src/test/java/xyz/auriium/branch/spigot/ExampleBinding.java similarity index 96% rename from spigot-impl/src/test/java/me/aurium/branch/spigot/ExampleBinding.java rename to branch-spigot-impl/src/test/java/xyz/auriium/branch/spigot/ExampleBinding.java index 5f755a6..151e4f4 100644 --- a/spigot-impl/src/test/java/me/aurium/branch/spigot/ExampleBinding.java +++ b/branch-spigot-impl/src/test/java/xyz/auriium/branch/spigot/ExampleBinding.java @@ -19,7 +19,7 @@ * */ -package me.aurium.branch.spigot; +package xyz.auriium.branch.spigot; import org.bukkit.plugin.java.JavaPlugin; diff --git a/spigot-impl/src/test/resources/plugin.yml b/branch-spigot-impl/src/test/resources/plugin.yml similarity index 100% rename from spigot-impl/src/test/resources/plugin.yml rename to branch-spigot-impl/src/test/resources/plugin.yml diff --git a/core-tests/core-tests.iml b/core-tests/core-tests.iml deleted file mode 100644 index 78b2cc5..0000000 --- a/core-tests/core-tests.iml +++ /dev/null @@ -1,2 +0,0 @@ - - \ No newline at end of file diff --git a/core-tests/pom.xml b/core-tests/pom.xml deleted file mode 100644 index 341cfa7..0000000 --- a/core-tests/pom.xml +++ /dev/null @@ -1,75 +0,0 @@ - - - - - 4.0.0 - - - branch - me.aurium - 0.1.0 - - - branch-core-tests - 0.1.0 - - - ${compiler.version} - ${compiler.version} - - - - - branch-core - me.aurium - 0.1.0 - - - org.junit.jupiter - junit-jupiter-engine - 5.7.0 - test - - - org.slf4j - slf4j-api - 2.0.0-alpha1 - test - - - ch.qos.logback - logback-core - 1.3.0-alpha5 - test - - - ch.qos.logback - logback-classic - 1.2.3 - test - - - - - \ No newline at end of file diff --git a/core-tests/src/main/java/me/aurium/branch/tests/StringAdapter.java b/core-tests/src/main/java/me/aurium/branch/tests/StringAdapter.java deleted file mode 100644 index 3795f71..0000000 --- a/core-tests/src/main/java/me/aurium/branch/tests/StringAdapter.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * - * Branch - * Copyright © 2021 Aurium - * - * Branch is free software: you can redistribute it and/or modify - * It under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * Branch is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Branch. If not, see - * and navigate to version 3 of the GNU Affero General Public License. - * - */ - -package me.aurium.branch.tests; - -import me.aurium.branch.centralized.typeadapter.CommonAdapter; - -public class StringAdapter implements CommonAdapter { -} diff --git a/core-tests/src/main/java/me/aurium/branch/tests/StringManager.java b/core-tests/src/main/java/me/aurium/branch/tests/StringManager.java deleted file mode 100644 index 229da42..0000000 --- a/core-tests/src/main/java/me/aurium/branch/tests/StringManager.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * - * Branch - * Copyright © 2021 Aurium - * - * Branch is free software: you can redistribute it and/or modify - * It under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * Branch is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Branch. If not, see - * and navigate to version 3 of the GNU Affero General Public License. - * - */ - -package me.aurium.branch.tests; - -import me.aurium.branch.centralized.*; -import me.aurium.branch.centralized.base.NodeBase; -import me.aurium.branch.centralized.base.NodeBaseBuilder; -import me.aurium.branch.centralized.typeadapter.ManagerAdapter; - -public class StringManager implements CentralizedManager { - - private final static StringAdapter defaultAdapter = new StringAdapter(); - - @Override - public CentralizedManagerBinder getBinder(Void platform) { - throw new IllegalStateException("StringManager is for tests!"); - } - - @Override - public NodeSource getSource() { - return null; - } - - @Override - public NodeBaseBuilder newCommand() { - return new NodeBaseBuilder<>(this,defaultAdapter); - } - - @Override - public NodeBaseBuilder newCommand(ManagerAdapter adapter) { - return new NodeBaseBuilder<>(this,adapter); - } - - @Override - public void injectCommand(NodeBase base) { - throw new IllegalStateException("StringManager is for tests!"); - } -} diff --git a/core/src/main/java/me/aurium/branch/centralized/NodeSource.java b/core/src/main/java/me/aurium/branch/centralized/NodeSource.java deleted file mode 100644 index e7867be..0000000 --- a/core/src/main/java/me/aurium/branch/centralized/NodeSource.java +++ /dev/null @@ -1,14 +0,0 @@ -package me.aurium.branch.centralized; - -import me.aurium.branch.nodes.branching.ExclusiveBranchingBuilder; -import me.aurium.branch.nodes.branching.InclusiveBranchingBuilder; -import me.aurium.branch.nodes.single.SingleBuilder; - -public interface NodeSource { - - SingleBuilder single(); - InclusiveBranchingBuilder inclusiveBranching(); - ExclusiveBranchingBuilder exclusiveBranching(); - //TODO help and argument - -} diff --git a/core/src/main/java/me/aurium/branch/centralized/base/AdaptingNodeBase.java b/core/src/main/java/me/aurium/branch/centralized/base/AdaptingNodeBase.java deleted file mode 100644 index 4f0e0c9..0000000 --- a/core/src/main/java/me/aurium/branch/centralized/base/AdaptingNodeBase.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * - * Branch - * Copyright © 2021 Aurium - * - * Branch is free software: you can redistribute it and/or modify - * It under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * Branch is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Branch. If not, see - * and navigate to version 3 of the GNU Affero General Public License. - * - */ - -package me.aurium.branch.centralized.base; - -import me.aurium.branch.centralized.typeadapter.ManagerAdapter; -import me.aurium.branch.execution.api.Execution; -import me.aurium.branch.execution.ContextProvider; -import me.aurium.branch.execution.NodeContext; -import me.aurium.branch.fallback.strategies.FallbackSearchStrategy; -import me.aurium.branch.information.description.Description; -import me.aurium.branch.interfacing.handlers.InterfacingHandler; -import me.aurium.branch.nodes.CommandNode; -import me.aurium.branch.nodes.results.SearchInfo; -import me.aurium.branch.nodes.results.model.Result; - -import java.util.List; - -/** - * Represents a node base that has the ability to convert it's input sender to a sender of type C or fail with a result. - * @param the input type of nodebase - * @param the adapted adjusted type desired, based on a similar adapter. - */ -public abstract class AdaptingNodeBase implements NodeBase { - - private final ManagerAdapter adapter; - - private final CommandNode baseNode; - private final FallbackSearchStrategy strategy; - private final ContextProvider provider; - private final InterfacingHandler handler; - - public AdaptingNodeBase(ManagerAdapter adapter, CommandNode baseNode, FallbackSearchStrategy strategy, ContextProvider provider, InterfacingHandler handler) { - this.adapter = adapter; - this.baseNode = baseNode; - this.strategy = strategy; - this.provider = provider; - this.handler = handler; - } - - public void execute(T t, String alias, String[] args) { - if (!adapter.canAdapt(t)) { - handler.sendMessage(t,adapter.failedParseResponse(t)); - return; - } - - C adaptedSender = adapter.adapt(t); - - Result> result = strategy.attemptPreprocess(adaptedSender,alias,args,baseNode); - - if (!result.isSuccessful()) { - handler.sendMessage(t, result.getFailure()); - return; - } - - SearchInfo info = result.getSuccess(); - NodeContext produced = provider.produce(adaptedSender,alias,args,baseNode,info); - - Execution execution = info.resultingNode().getHandling().getExecution(produced); - - execution.run(); - } - - public List suggest(T t, String alias, String[] args) { - return null; //TODO - } - -} diff --git a/core/src/main/java/me/aurium/branch/centralized/base/DelegatingNodeBase.java b/core/src/main/java/me/aurium/branch/centralized/base/DelegatingNodeBase.java deleted file mode 100644 index cddf7e0..0000000 --- a/core/src/main/java/me/aurium/branch/centralized/base/DelegatingNodeBase.java +++ /dev/null @@ -1,35 +0,0 @@ -package me.aurium.branch.centralized.base; - -import me.aurium.branch.centralized.typeadapter.ManagerAdapter; -import me.aurium.branch.execution.ContextProvider; -import me.aurium.branch.fallback.strategies.FallbackSearchStrategy; -import me.aurium.branch.information.description.Description; -import me.aurium.branch.interfacing.handlers.InterfacingHandler; -import me.aurium.branch.nodes.CommandNode; -import me.aurium.branch.nodes.IdentifiableNode; - -/** - * Adapting node base that delegates identifier calls to the first node in the base stack. - * @param t - * @param c - */ -public class DelegatingNodeBase extends AdaptingNodeBase { - - private final IdentifiableNode baseNode; - - public DelegatingNodeBase(ManagerAdapter adapter, IdentifiableNode baseNode, FallbackSearchStrategy strategy, ContextProvider provider, InterfacingHandler handler) { - super(adapter, baseNode, strategy, provider, handler); - - this.baseNode = baseNode; - } - - @Override - public Description getDescription() { - return baseNode.getDescription(); - } - - @Override - public String getIdentifier() { - return baseNode.getIdentifier().getIdentifier(); - } -} diff --git a/core/src/main/java/me/aurium/branch/centralized/base/NodeBase.java b/core/src/main/java/me/aurium/branch/centralized/base/NodeBase.java deleted file mode 100644 index 4323616..0000000 --- a/core/src/main/java/me/aurium/branch/centralized/base/NodeBase.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * - * Branch - * Copyright © 2021 Aurium - * - * Branch is free software: you can redistribute it and/or modify - * It under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * Branch is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Branch. If not, see - * and navigate to version 3 of the GNU Affero General Public License. - * - */ - -package me.aurium.branch.centralized.base; - -import me.aurium.branch.information.description.Description; - -import java.util.Collections; -import java.util.List; - -/** - * Represents a single command tree as a command - * @param type of input sender - */ -public interface NodeBase { - - void execute(T t, String alias, String[] args); //may execute instantly or take some time - List suggest(T t, String alias, String[] args); - - Description getDescription(); - String getIdentifier(); - - default List getAliases() { - return Collections.emptyList(); - } - -} diff --git a/core/src/main/java/me/aurium/branch/centralized/base/NodeBaseBuilder.java b/core/src/main/java/me/aurium/branch/centralized/base/NodeBaseBuilder.java deleted file mode 100644 index 42154c0..0000000 --- a/core/src/main/java/me/aurium/branch/centralized/base/NodeBaseBuilder.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * - * Branch - * Copyright © 2021 Aurium - * - * Branch is free software: you can redistribute it and/or modify - * It under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * Branch is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Branch. If not, see - * and navigate to version 3 of the GNU Affero General Public License. - * - */ - -package me.aurium.branch.centralized.base; - -import me.aurium.branch.centralized.CentralizedManager; -import me.aurium.branch.centralized.typeadapter.ManagerAdapter; -import me.aurium.branch.execution.ContextProvider; -import me.aurium.branch.fallback.strategies.FallbackSearchStrategy; -import me.aurium.branch.interfacing.handlers.InterfacingHandler; -import me.aurium.branch.nodes.CommandNode; -import me.aurium.branch.nodes.IdentifiableNode; - -import java.util.Objects; - -/** - * Default implementation of a class that produces adaptingNodeBases - * - * @param Input type - * @param Adapted type - */ -public class NodeBaseBuilder { - - private final CentralizedManager manager; - private final ManagerAdapter adapter; - - private IdentifiableNode node; - private FallbackSearchStrategy strategy; - private ContextProvider provider; - private InterfacingHandler handler; - - - public NodeBaseBuilder(CentralizedManager manager, ManagerAdapter adapter) { - this.manager = manager; - this.adapter = adapter; - } - - public NodeBaseBuilder(CentralizedManager manager, ManagerAdapter adapter, FallbackSearchStrategy strategy, ContextProvider provider, InterfacingHandler handler) { - this.manager = manager; - this.adapter = adapter; - this.strategy = strategy; - this.provider = provider; - this.handler = handler; - } - - public NodeBaseBuilder setNode(IdentifiableNode node) { - this.node = node; - - return this; - } - - public NodeBaseBuilder setStrategy(FallbackSearchStrategy strategy) { - this.strategy = strategy; - - return this; - } - - public NodeBaseBuilder setProvider(ContextProvider provider) { - this.provider = provider; - - return this; - } - - public NodeBaseBuilder setHandler(InterfacingHandler handler) { - this.handler = handler; - - return this; - } - - public void inject() { - Objects.requireNonNull(node); - Objects.requireNonNull(strategy); - Objects.requireNonNull(provider); - Objects.requireNonNull(handler); - - manager.injectCommand(new DelegatingNodeBase<>(adapter,node,strategy,provider,handler)); - } -} diff --git a/core/src/main/java/me/aurium/branch/execution/AbstractNodeContext.java b/core/src/main/java/me/aurium/branch/execution/AbstractNodeContext.java deleted file mode 100644 index 71bc2a6..0000000 --- a/core/src/main/java/me/aurium/branch/execution/AbstractNodeContext.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * - * Branch - * Copyright © 2021 Aurium - * - * Branch is free software: you can redistribute it and/or modify - * It under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * Branch is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Branch. If not, see - * and navigate to version 3 of the GNU Affero General Public License. - * - */ - -package me.aurium.branch.execution; - - -import me.aurium.branch.nodes.CommandNode; -import me.aurium.branch.nodes.results.SearchInfo; - -/** - * Abstract implementation of a node context - * @param type - */ -public abstract class AbstractNodeContext implements NodeContext { - - private final T sender; - private final String alias; - private final String[] args; - - private final CommandNode baseNode; - private final SearchInfo searchInfo; - - protected AbstractNodeContext(T sender, String alias, String[] args, CommandNode baseNode, SearchInfo result) { - this.sender = sender; - this.alias = alias; - this.args = args; - - this.searchInfo = result; - this.baseNode = baseNode; - } - - @Override - public T getSender() { - return sender; - } - - @Override - public String getAlias() { - return alias; - } - - @Override - public String[] getArgs() { - return args; - } - - @Override - public CommandNode getBaseExecutedNode() { - return baseNode; - } - - @Override - public SearchInfo getResults() { - return searchInfo; - } - -} diff --git a/core/src/main/java/me/aurium/branch/execution/EmptySuggestionHandler.java b/core/src/main/java/me/aurium/branch/execution/EmptySuggestionHandler.java deleted file mode 100644 index f819a89..0000000 --- a/core/src/main/java/me/aurium/branch/execution/EmptySuggestionHandler.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * - * Branch - * Copyright © 2021 Aurium - * - * Branch is free software: you can redistribute it and/or modify - * It under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * Branch is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Branch. If not, see - * and navigate to version 3 of the GNU Affero General Public License. - * - */ - -package me.aurium.branch.execution; - -import me.aurium.branch.execution.api.SuggestionHandler; - -import java.util.ArrayList; -import java.util.List; - -public class EmptySuggestionHandler implements SuggestionHandler { - - private static final List empty = new ArrayList<>(); - - @Override - public List handle(NodeContext adapter) { - return empty; - } -} diff --git a/core/src/main/java/me/aurium/branch/execution/StringBlock.java b/core/src/main/java/me/aurium/branch/execution/StringBlock.java deleted file mode 100644 index 6bcb746..0000000 --- a/core/src/main/java/me/aurium/branch/execution/StringBlock.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * - * Branch - * Copyright © 2021 Aurium - * - * Branch is free software: you can redistribute it and/or modify - * It under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * Branch is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Branch. If not, see - * and navigate to version 3 of the GNU Affero General Public License. - * - */ - -package me.aurium.branch.execution; - -/** - * Represents a block that contains a string - */ -public class StringBlock implements Block { - - private final String identifier; - - public StringBlock(String identifier) { - this.identifier = identifier; - } - - @Override - public String getIdentifier() { - return identifier; - } - - public static Block of(String string) { - if (string.contains(" ")) throw new IllegalStateException("Identifier cannot have spaces!"); - - return new StringBlock(string); - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - StringBlock that = (StringBlock) o; - return identifier.equalsIgnoreCase(that.identifier); - } - - @Override - public boolean isVisual() { - return true; - } - - @Override - public int hashCode() { - return identifier.hashCode(); - } -} diff --git a/core/src/main/java/me/aurium/branch/execution/api/BranchHandler.java b/core/src/main/java/me/aurium/branch/execution/api/BranchHandler.java deleted file mode 100644 index ac450b6..0000000 --- a/core/src/main/java/me/aurium/branch/execution/api/BranchHandler.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * - * Branch - * Copyright © 2021 Aurium - * - * Branch is free software: you can redistribute it and/or modify - * It under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * Branch is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Branch. If not, see - * and navigate to version 3 of the GNU Affero General Public License. - * - */ - -package me.aurium.branch.execution.api; - -import me.aurium.branch.execution.NodeContext; -import me.aurium.branch.nodes.results.model.Result; - -import java.util.List; - -/** - * Represents the actable behavior of a node once the node has been found - e.g. after the node's search logic is complete - * @param sender - */ -public interface BranchHandler { - - Execution getExecution(NodeContext context); - List getSuggestions(NodeContext context); - -} diff --git a/core/src/main/java/me/aurium/branch/execution/api/Execution.java b/core/src/main/java/me/aurium/branch/execution/api/Execution.java deleted file mode 100644 index 5ec4c5f..0000000 --- a/core/src/main/java/me/aurium/branch/execution/api/Execution.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * - * Branch - * Copyright © 2021 Aurium - * - * Branch is free software: you can redistribute it and/or modify - * It under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * Branch is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Branch. If not, see - * and navigate to version 3 of the GNU Affero General Public License. - * - */ - -package me.aurium.branch.execution.api; - -import me.aurium.branch.execution.NodeContext; - -/** - * Standin class for something more sophisticated - basically allows the controlled execution of the node to be submitted as a runnable - * @param the type - */ -public class Execution implements Runnable { - - private final ExecutionHandler handler; - private final NodeContext node; - - public Execution(ExecutionHandler handler, NodeContext node) { - this.handler = handler; - this.node = node; - } - - @Override - public void run() { - handler.handle(node); - } -} diff --git a/core/src/main/java/me/aurium/branch/information/help/HelpEntry.java b/core/src/main/java/me/aurium/branch/information/help/HelpEntry.java deleted file mode 100644 index 65cf9c9..0000000 --- a/core/src/main/java/me/aurium/branch/information/help/HelpEntry.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * - * Branch - * Copyright © 2021 Aurium - * - * Branch is free software: you can redistribute it and/or modify - * It under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * Branch is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Branch. If not, see - * and navigate to version 3 of the GNU Affero General Public License. - * - */ - -package me.aurium.branch.information.help; - -public interface HelpEntry { -} diff --git a/core/src/main/java/me/aurium/branch/information/help/Shit.java b/core/src/main/java/me/aurium/branch/information/help/Shit.java deleted file mode 100644 index 4ad9f20..0000000 --- a/core/src/main/java/me/aurium/branch/information/help/Shit.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * - * Branch - * Copyright © 2021 Aurium - * - * Branch is free software: you can redistribute it and/or modify - * It under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * Branch is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Branch. If not, see - * and navigate to version 3 of the GNU Affero General Public License. - * - */ - -package me.aurium.branch.information.help; - -public class Shit { - - //commandnodes or maybe their branchhandlers all need to return a Description -} diff --git a/core/src/main/java/me/aurium/branch/interfacing/handlers/CommonInterfacingHandler.java b/core/src/main/java/me/aurium/branch/interfacing/handlers/CommonInterfacingHandler.java deleted file mode 100644 index f7cfc0c..0000000 --- a/core/src/main/java/me/aurium/branch/interfacing/handlers/CommonInterfacingHandler.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * - * Branch - * Copyright © 2021 Aurium - * - * Branch is free software: you can redistribute it and/or modify - * It under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * Branch is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Branch. If not, see - * and navigate to version 3 of the GNU Affero General Public License. - * - */ - -package me.aurium.branch.interfacing.handlers; - -import me.aurium.branch.interfacing.Message; -import me.aurium.branch.interfacing.Response; -import me.aurium.branch.interfacing.ResponseAction; - -import java.util.Map; - -public class CommonInterfacingHandler implements InterfacingHandler { - - private final Map, ResponseAction> map; - - CommonInterfacingHandler(Map, ResponseAction> map) { - this.map = map; - } - - @Override - public void sendMessage(T recipent, Message message) { - message.accept(recipent); - } - - @Override - public void sendMessage(T recipent, Response response) { - getMessage(response).accept(recipent); - } - - @SuppressWarnings("unchecked") - private ResponseAction get(Class clazz) { - ResponseAction action = (ResponseAction) map.get(clazz); - - if (action == null) throw new IllegalStateException("A response was requested but internal map had no binding!"); - - return action; - } - - @SuppressWarnings("unchecked") - private Message getMessage(C response) { - return get((Class) response.getClass()).consume(response); - } -} diff --git a/core/src/main/java/me/aurium/branch/interfacing/handlers/DelegatingDefaultMap.java b/core/src/main/java/me/aurium/branch/interfacing/handlers/DelegatingDefaultMap.java deleted file mode 100644 index 6316231..0000000 --- a/core/src/main/java/me/aurium/branch/interfacing/handlers/DelegatingDefaultMap.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * - * Branch - * Copyright © 2021 Aurium - * - * Branch is free software: you can redistribute it and/or modify - * It under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * Branch is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Branch. If not, see - * and navigate to version 3 of the GNU Affero General Public License. - * - */ - -package me.aurium.branch.interfacing.handlers; - -import me.aurium.branch.interfacing.Response; -import me.aurium.branch.interfacing.ResponseAction; - -public abstract class DelegatingDefaultMap implements MessageMap { - - private final InnerMap delegate = defaultMap(); - protected abstract InnerMap defaultMap(); - - @Override - public DelegatingDefaultMap add(Class key, ResponseAction action) { - delegate.add(key,action); - - return this; - } - - @Override - public InterfacingHandler make() { - return delegate.make(); - } -} diff --git a/core/src/main/java/me/aurium/branch/interfacing/handlers/InterfacingHandler.java b/core/src/main/java/me/aurium/branch/interfacing/handlers/InterfacingHandler.java deleted file mode 100644 index b65c93f..0000000 --- a/core/src/main/java/me/aurium/branch/interfacing/handlers/InterfacingHandler.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * - * Branch - * Copyright © 2021 Aurium - * - * Branch is free software: you can redistribute it and/or modify - * It under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * Branch is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Branch. If not, see - * and navigate to version 3 of the GNU Affero General Public License. - * - */ - -package me.aurium.branch.interfacing.handlers; - -import me.aurium.branch.interfacing.Message; -import me.aurium.branch.interfacing.Response; - -/** - * Represents a centralized source for message providing as well as context creation. I am aware i spelled recipient wrong. - * @param the type - */ -public interface InterfacingHandler { - - void sendMessage(T recipent, Message message); - void sendMessage(T recipent, Response response); - -} diff --git a/core/src/main/java/me/aurium/branch/interfacing/handlers/MessageMap.java b/core/src/main/java/me/aurium/branch/interfacing/handlers/MessageMap.java deleted file mode 100644 index 481f808..0000000 --- a/core/src/main/java/me/aurium/branch/interfacing/handlers/MessageMap.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * - * Branch - * Copyright © 2021 Aurium - * - * Branch is free software: you can redistribute it and/or modify - * It under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * Branch is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Branch. If not, see - * and navigate to version 3 of the GNU Affero General Public License. - * - */ - -package me.aurium.branch.interfacing.handlers; - -import me.aurium.branch.interfacing.Message; -import me.aurium.branch.interfacing.Response; -import me.aurium.branch.interfacing.ResponseAction; - -public interface MessageMap { - - MessageMap add(Class key, ResponseAction action); - - InterfacingHandler make(); - -} diff --git a/core/src/main/java/me/aurium/branch/interfacing/responses/NoIntegratedArgsResponse.java b/core/src/main/java/me/aurium/branch/interfacing/responses/NoIntegratedArgsResponse.java deleted file mode 100644 index fe37378..0000000 --- a/core/src/main/java/me/aurium/branch/interfacing/responses/NoIntegratedArgsResponse.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * - * Branch - * Copyright © 2021 Aurium - * - * Branch is free software: you can redistribute it and/or modify - * It under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * Branch is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Branch. If not, see - * and navigate to version 3 of the GNU Affero General Public License. - * - */ - -package me.aurium.branch.interfacing.responses; - -import me.aurium.branch.execution.NodeContext; -import me.aurium.branch.interfacing.Response; - -import java.util.ArrayList; -import java.util.List; - -//This can probably be improved - -/** - * Represents a response to the scenario in which not enough arguments were supplied to execute a splittable - * node, so all alternative commands are suggested. This needs work, however, as it cannot list all alternative commands - * and their arguments just yet. (logic for this must be some kind of greedy queue consumer with potentially dangerous loops) - */ -public class NoIntegratedArgsResponse implements Response { - - private final List alternativeCommands; - - public NoIntegratedArgsResponse(List alternativeCommands) { - this.alternativeCommands = alternativeCommands; - } - - public List getAlternativeCommands() { - return alternativeCommands; - } - -} diff --git a/core/src/main/java/me/aurium/branch/nodes/Builder.java b/core/src/main/java/me/aurium/branch/nodes/Builder.java deleted file mode 100644 index 92f4a21..0000000 --- a/core/src/main/java/me/aurium/branch/nodes/Builder.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * - * Branch - * Copyright © 2021 Aurium - * - * Branch is free software: you can redistribute it and/or modify - * It under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * Branch is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Branch. If not, see - * and navigate to version 3 of the GNU Affero General Public License. - * - */ - -package me.aurium.branch.nodes; - - -public interface Builder{ - - CommandNode build(); - -} diff --git a/core/src/main/java/me/aurium/branch/nodes/CommandNode.java b/core/src/main/java/me/aurium/branch/nodes/CommandNode.java deleted file mode 100644 index f02b322..0000000 --- a/core/src/main/java/me/aurium/branch/nodes/CommandNode.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * - * Branch - * Copyright © 2021 Aurium - * - * Branch is free software: you can redistribute it and/or modify - * It under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * Branch is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Branch. If not, see - * and navigate to version 3 of the GNU Affero General Public License. - * - */ - -package me.aurium.branch.nodes; - -import me.aurium.branch.execution.api.BranchHandler; -import me.aurium.branch.information.description.Description; -import me.aurium.branch.nodes.results.SearchInput; -import me.aurium.branch.nodes.results.SearchInfo; -import me.aurium.branch.fallback.permissions.Permission; -import me.aurium.branch.nodes.results.model.Result; - -/** - * Base object - * @param fuck - */ -public interface CommandNode { - - //int getExpectedConsumeAmount() //used to check how much was expected as you pass through vs how much was received, among other htings. - - Result> getSpecificNode(SearchInput path); - BranchHandler getHandling(); - - - /** - * Gets the permission required to execute and interact with this node. Depending on the base, this may cause the node to become locked, or just completely be ignored. - * @return the permission binding - */ - Permission getPermission(); - Description getDescription(); - -} diff --git a/core/src/main/java/me/aurium/branch/nodes/argument/ArgNode.java b/core/src/main/java/me/aurium/branch/nodes/argument/ArgNode.java deleted file mode 100644 index 24b2cdd..0000000 --- a/core/src/main/java/me/aurium/branch/nodes/argument/ArgNode.java +++ /dev/null @@ -1,74 +0,0 @@ -package me.aurium.branch.nodes.argument; - -import me.aurium.branch.execution.Block; -import me.aurium.branch.execution.NodeContext; -import me.aurium.branch.execution.api.BranchHandler; -import me.aurium.branch.execution.api.Execution; -import me.aurium.branch.fallback.permissions.Permission; -import me.aurium.branch.information.description.Description; -import me.aurium.branch.nodes.argument.types.Argument; -import me.aurium.branch.nodes.results.model.Result; -import me.aurium.branch.nodes.single.EndpointNode; - -import java.util.ArrayDeque; -import java.util.Deque; -import java.util.List; - -public class ArgNode extends EndpointNode { - - private final Block identifier; - private final Permission permission; - private final Description description; - private final List> arguments; - - public ArgNode(Block identifier, Permission permission, Description description, List> arguments) { - this.identifier = identifier; - this.permission = permission; - this.description = description; - this.arguments = arguments; - } - - @Override - public BranchHandler getHandling() { - return null; - } - - @Override - public Permission getPermission() { - return permission; - } - - @Override - public Description getDescription() { - return description; - } - - @Override - public Block getIdentifier() { - return identifier; - } - - public static final class ArgHandler implements BranchHandler { - - private final List> arguments; - - public ArgHandler(List> arguments) { - this.arguments = arguments; - } - - @Override - public Execution getExecution(NodeContext context) { - - Deque subdeque = new ArrayDeque<>(context.getResults().reducedPath()); - - - - return null; - } - - @Override - public List getSuggestions(NodeContext context) { - return null; - } - } -} diff --git a/core/src/main/java/me/aurium/branch/nodes/argument/ArgumentContext.java b/core/src/main/java/me/aurium/branch/nodes/argument/ArgumentContext.java deleted file mode 100644 index a44e3db..0000000 --- a/core/src/main/java/me/aurium/branch/nodes/argument/ArgumentContext.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * - * Branch - * Copyright © 2021 Aurium - * - * Branch is free software: you can redistribute it and/or modify - * It under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * Branch is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Branch. If not, see - * and navigate to version 3 of the GNU Affero General Public License. - * - */ - -package me.aurium.branch.nodes.argument; - -import me.aurium.branch.execution.NodeContext; - -public interface ArgumentContext extends NodeContext { - - Arguments getArgumentContainer(); - -} diff --git a/core/src/main/java/me/aurium/branch/nodes/argument/ArgumentConverter.java b/core/src/main/java/me/aurium/branch/nodes/argument/ArgumentConverter.java deleted file mode 100644 index 0c944e6..0000000 --- a/core/src/main/java/me/aurium/branch/nodes/argument/ArgumentConverter.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * - * Branch - * Copyright © 2021 Aurium - * - * Branch is free software: you can redistribute it and/or modify - * It under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * Branch is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Branch. If not, see - * and navigate to version 3 of the GNU Affero General Public License. - * - */ - -package me.aurium.branch.nodes.argument; - -public interface ArgumentConverter { -} diff --git a/core/src/main/java/me/aurium/branch/nodes/argument/ArgumentNode.java b/core/src/main/java/me/aurium/branch/nodes/argument/ArgumentNode.java deleted file mode 100644 index 290b736..0000000 --- a/core/src/main/java/me/aurium/branch/nodes/argument/ArgumentNode.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * - * Branch - * Copyright © 2021 Aurium - * - * Branch is free software: you can redistribute it and/or modify - * It under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * Branch is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Branch. If not, see - * and navigate to version 3 of the GNU Affero General Public License. - * - */ - -package me.aurium.branch.nodes.argument; - -//kinda like a branching node except it throws forward and not to the sides - -//one of these days ill actually finish this class LMFAO -/* -public class ArgumentNode implements IdentifiableNode { - - private final Block identifier; - private final List> sequentialValueNodes; //the nodes in order from here on out - private final SingleNode noArgs; - - private final Permission permission; - - public ArgumentNode(Block identifier, List> sequentialValueNodes, SingleNode noArgs, Permission permission) { - this.identifier = identifier; - this.sequentialValueNodes = sequentialValueNodes; - this.noArgs = noArgs; - this.permission = permission; - } - - - // - These two methods can remain unimplemented because this node will never be used for contexthandlers and suggestionhandlers - - // - The actual contextHandler and Suggestionhandler are provided by the getSpecificNode method returning an anonymous basenode - - // - This is because the contexthandler and suggestion handler here always depend on the blockpath, and in order to respect - - // - the node map object model, we must do this. - - - @Override - public SearchResult getSpecificNode(SearchInput input) { - return new SearchResult<>(this, input); - } - - */ -/*if (path.isEmpty()) return Optional.of(noArgs); - - return Optional.of(this);*//* - - - */ -/* This was pointless, see below note - - //we can either do this shit, or we can return **THIS** no matter what and let the context handler be variable, since the context handler delegates - //to another adapter anyways - - int position = path.length() - 1; //wow real throwback to LEAF framework huh - int size = sequentialValueNodes.size(); - - //check the length - if (position == size) return Optional.of(sequentialValueNodes.get(size - 1)); - - return Optional.of(sequentialValueNodes.get(position)); - *//* - - - @Override - public ExecutionResult getExecutionHandler() { - return new ExecutionResult<>((context) -> { - Deque executed = context.executedPath(); - }); - } - - @Override - public SuggestionHandler getSuggestionHandler() { - return (context) -> { - return null; - }; - } - - @Override - public Permission getPermission() { - return permission; - } - - @Override - public Block getIdentifier() { - return identifier; - } -} -*/ diff --git a/core/src/main/java/me/aurium/branch/nodes/argument/Arguments.java b/core/src/main/java/me/aurium/branch/nodes/argument/Arguments.java deleted file mode 100644 index 47d9327..0000000 --- a/core/src/main/java/me/aurium/branch/nodes/argument/Arguments.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * - * Branch - * Copyright © 2021 Aurium - * - * Branch is free software: you can redistribute it and/or modify - * It under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * Branch is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Branch. If not, see - * and navigate to version 3 of the GNU Affero General Public License. - * - */ - -package me.aurium.branch.nodes.argument; - -public class Arguments { -} diff --git a/core/src/main/java/me/aurium/branch/nodes/argument/types/Argument.java b/core/src/main/java/me/aurium/branch/nodes/argument/types/Argument.java deleted file mode 100644 index 9665d8b..0000000 --- a/core/src/main/java/me/aurium/branch/nodes/argument/types/Argument.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * - * Branch - * Copyright © 2021 Aurium - * - * Branch is free software: you can redistribute it and/or modify - * It under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * Branch is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Branch. If not, see - * and navigate to version 3 of the GNU Affero General Public License. - * - */ - -package me.aurium.branch.nodes.argument.types; - -import me.aurium.branch.execution.Block; -import me.aurium.branch.execution.NodeContext; - -import java.util.List; -import java.util.Optional; - -/** - * Represents a kind of parser that converts blocks into a typed argument. - * @param - * - * TODO: maybe let arguments consume more than one Block. - */ -public interface Argument { - - /** - * What the argument identifies as - * @return what it identifies as - */ - String getLabel(); - - /** - * Gets the bounds of the object - * @param context the context used to calculate - * @return - */ - List getBounds(NodeContext context); - - boolean check(Block toParse); - T parse(Block block); - - Optional getDefault(); - -} diff --git a/core/src/main/java/me/aurium/branch/nodes/argument/types/UncalculatingArgument.java b/core/src/main/java/me/aurium/branch/nodes/argument/types/UncalculatingArgument.java deleted file mode 100644 index 8ea5b75..0000000 --- a/core/src/main/java/me/aurium/branch/nodes/argument/types/UncalculatingArgument.java +++ /dev/null @@ -1,4 +0,0 @@ -package me.aurium.branch.nodes.argument.types; - -public interface UncalculatingArgument { -} diff --git a/core/src/main/java/me/aurium/branch/nodes/branching/BranchingNode.java b/core/src/main/java/me/aurium/branch/nodes/branching/BranchingNode.java deleted file mode 100644 index c9cde4b..0000000 --- a/core/src/main/java/me/aurium/branch/nodes/branching/BranchingNode.java +++ /dev/null @@ -1,134 +0,0 @@ -/* - * - * Branch - * Copyright © 2021 Aurium - * - * Branch is free software: you can redistribute it and/or modify - * It under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * Branch is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Branch. If not, see - * and navigate to version 3 of the GNU Affero General Public License. - * - */ - -package me.aurium.branch.nodes.branching; - -import me.aurium.branch.execution.Block; -import me.aurium.branch.execution.api.BranchHandler; -import me.aurium.branch.execution.api.Execution; -import me.aurium.branch.execution.NodeContext; -import me.aurium.branch.information.description.Description; -import me.aurium.branch.interfacing.responses.NoIntegratedArgsResponse; -import me.aurium.branch.nodes.IdentifiableNode; -import me.aurium.branch.fallback.permissions.Permission; -import me.aurium.branch.nodes.results.model.Result; -import me.aurium.branch.nodes.results.SearchInfo; -import me.aurium.branch.nodes.results.SearchInput; - -import java.util.ArrayList; -import java.util.List; - -/** - * Nodes should always assume that the first block in the blockpath is theirs to consume - * - * @param - */ -public class BranchingNode implements IdentifiableNode { - - private final PrestoredSet nodes; - private final Block path; - private final BranchHandler handler; - private final Description description; - - private final Permission permission; - - public BranchingNode(PrestoredSet nodes, Block path, Description description, Permission permission) { - this.nodes = nodes; - this.path = path; - this.description = description; - this.permission = permission; - - this.handler = new BranchingHandler<>(nodes); - } - - @Override - public Block getIdentifier() { - return path; - } - - @Override - public Description getDescription() { - return description; - } - - //args[] = join aMatch - //let's say this is the base - @Override - public Result> getSpecificNode(SearchInput input) { - //if there is something left, the first thing in the queue is our argument - //if there is nothing left no args time - - if (!input.getReducablePath().isEmpty()) { - Block block = input.getReducablePath().getFirst(); //reveal - - for (IdentifiableNode node : nodes.getContents()) { - if (node.getIdentifier().equals(block)) { - return node.getSpecificNode(input); //consume - } - } - - } - - return Result.success(new SearchInfo<>(this,input)); - } - - @Override - public BranchHandler getHandling() { - return handler; - } - - @Override - public Permission getPermission() { - return permission; - } - - public static final class BranchingHandler implements BranchHandler { - - private final PrestoredSet nodeShit; - - public BranchingHandler(PrestoredSet nodeShit) { - this.nodeShit = nodeShit; - } - - - @Override - public Execution getExecution(NodeContext context) { - return nodeShit.getSideNode().getHandling().getExecution(context); - } - - @Override - public List getSuggestions(NodeContext context) { - - List strings = new ArrayList<>(); - - for (IdentifiableNode node : nodeShit.getContents()) { - if (node.getPermission().attempt(context) && node.getIdentifier().isVisual()) { - strings.add(node.getIdentifier().getIdentifier()); - } - } - - return strings; - } - - } - - -} diff --git a/core/src/main/java/me/aurium/branch/nodes/branching/ExclusiveBranchingBuilder.java b/core/src/main/java/me/aurium/branch/nodes/branching/ExclusiveBranchingBuilder.java deleted file mode 100644 index 5f4cb7a..0000000 --- a/core/src/main/java/me/aurium/branch/nodes/branching/ExclusiveBranchingBuilder.java +++ /dev/null @@ -1,80 +0,0 @@ -package me.aurium.branch.nodes.branching; - -import me.aurium.branch.execution.Block; -import me.aurium.branch.execution.StringBlock; -import me.aurium.branch.fallback.permissions.EmptyPermission; -import me.aurium.branch.fallback.permissions.Permission; -import me.aurium.branch.information.description.Description; -import me.aurium.branch.information.description.StringDescription; -import me.aurium.branch.nodes.single.HelpNode; -import me.aurium.branch.nodes.Builder; -import me.aurium.branch.nodes.CommandNode; -import me.aurium.branch.nodes.IdentifiableNode; - -import java.util.HashSet; -import java.util.Objects; -import java.util.Set; - -public class ExclusiveBranchingBuilder implements Builder { - - private final Set> commands; - - private Block block; - private CommandNode noArgs; - private Permission permission; - private Description description; - - public ExclusiveBranchingBuilder() { - this.commands = new HashSet<>(); - this.permission = new EmptyPermission<>(); - this.noArgs = new HelpNode<>(); - } - - public ExclusiveBranchingBuilder withIdentifier(Block block) { - this.block = block; - - return this; - } - - public ExclusiveBranchingBuilder withIdentifier(String string) { - this.block = StringBlock.of(string); - - return this; - } - - public ExclusiveBranchingBuilder withPermission(Permission permission) { - this.permission = permission; - - return this; - } - - public ExclusiveBranchingBuilder withDescription(Description description) { - this.description = description; - - return this; - } - - public ExclusiveBranchingBuilder withNode(IdentifiableNode node) { - commands.add(node); - - return this; - } - - public ExclusiveBranchingBuilder withNoArgs(CommandNode node) { - this.noArgs = node; - - return this; - } - - public CommandNode build() { - - Objects.requireNonNull(block); - Objects.requireNonNull(permission); - Objects.requireNonNull(noArgs); - - Description returned = Objects.requireNonNullElse(description,new StringDescription("Default description for subcommand " + block.getIdentifier())); - - return new BranchingNode<>(new ExclusivePrestoredSet<>(noArgs,commands),block, returned, permission); - } - -} diff --git a/core/src/main/java/me/aurium/branch/nodes/branching/ExclusivePrestoredSet.java b/core/src/main/java/me/aurium/branch/nodes/branching/ExclusivePrestoredSet.java deleted file mode 100644 index 89ac489..0000000 --- a/core/src/main/java/me/aurium/branch/nodes/branching/ExclusivePrestoredSet.java +++ /dev/null @@ -1,27 +0,0 @@ -package me.aurium.branch.nodes.branching; - -import me.aurium.branch.nodes.CommandNode; -import me.aurium.branch.nodes.IdentifiableNode; - -import java.util.Set; - -public class ExclusivePrestoredSet implements PrestoredSet { - - private final CommandNode commandNode; - private final Set> otherNodes; - - public ExclusivePrestoredSet(CommandNode commandNode, Set> otherNodes) { - this.commandNode = commandNode; - this.otherNodes = otherNodes; - } - - @Override - public Set> getContents() { - return otherNodes; - } - - @Override - public CommandNode getSideNode() { - return commandNode; - } -} diff --git a/core/src/main/java/me/aurium/branch/nodes/branching/InclusiveBranchingBuilder.java b/core/src/main/java/me/aurium/branch/nodes/branching/InclusiveBranchingBuilder.java deleted file mode 100644 index 4700a4f..0000000 --- a/core/src/main/java/me/aurium/branch/nodes/branching/InclusiveBranchingBuilder.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * - * Branch - * Copyright © 2021 Aurium - * - * Branch is free software: you can redistribute it and/or modify - * It under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * Branch is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Branch. If not, see - * and navigate to version 3 of the GNU Affero General Public License. - * - */ - -package me.aurium.branch.nodes.branching; - -import me.aurium.branch.execution.Block; -import me.aurium.branch.execution.StringBlock; -import me.aurium.branch.fallback.permissions.Permission; -import me.aurium.branch.fallback.permissions.EmptyPermission; -import me.aurium.branch.information.description.Description; -import me.aurium.branch.information.description.StringDescription; -import me.aurium.branch.nodes.single.EndpointNode; -import me.aurium.branch.nodes.single.HelpNode; -import me.aurium.branch.nodes.Builder; -import me.aurium.branch.nodes.CommandNode; -import me.aurium.branch.nodes.IdentifiableNode; - -import java.util.HashSet; -import java.util.Objects; -import java.util.Set; - -public class InclusiveBranchingBuilder implements Builder { - - private final Set> commands; - - private Block block; - private EndpointNode noArgs; - private Permission permission; - private Description description; - - public InclusiveBranchingBuilder() { - this.commands = new HashSet<>(); - this.permission = new EmptyPermission<>(); - this.noArgs = new HelpNode<>(); - } - - public InclusiveBranchingBuilder withIdentifier(Block block) { - this.block = block; - - return this; - } - - public InclusiveBranchingBuilder withIdentifier(String string) { - this.block = StringBlock.of(string); - - return this; - } - - public InclusiveBranchingBuilder withPermission(Permission permission) { - this.permission = permission; - - return this; - } - - public InclusiveBranchingBuilder withNode(IdentifiableNode node) { - commands.add(node); - - return this; - } - - public InclusiveBranchingBuilder withNoArgs(EndpointNode node) { - this.noArgs = node; - - return this; - } - - public InclusiveBranchingBuilder withDescription(Description description) { - this.description = description; - - return this; - } - - public CommandNode build() { - - Objects.requireNonNull(block); - Objects.requireNonNull(permission); - Objects.requireNonNull(noArgs); - - Description returned = Objects.requireNonNullElse(description,new StringDescription("Default description for subcommand " + block.getIdentifier())); - - return new BranchingNode<>(new InclusivePrestoredSet<>(noArgs,commands),block, returned, permission); - } - -} \ No newline at end of file diff --git a/core/src/main/java/me/aurium/branch/nodes/branching/InclusivePrestoredSet.java b/core/src/main/java/me/aurium/branch/nodes/branching/InclusivePrestoredSet.java deleted file mode 100644 index cadde13..0000000 --- a/core/src/main/java/me/aurium/branch/nodes/branching/InclusivePrestoredSet.java +++ /dev/null @@ -1,31 +0,0 @@ -package me.aurium.branch.nodes.branching; - -import me.aurium.branch.nodes.IdentifiableNode; - -import java.util.HashSet; -import java.util.Set; - -public class InclusivePrestoredSet implements PrestoredSet { - - private final IdentifiableNode alreadyStored; - private final Set> otherThingsInTheSet; - - public InclusivePrestoredSet(IdentifiableNode alreadyStored, Set> otherThingsInTheSet) { - this.alreadyStored = alreadyStored; - this.otherThingsInTheSet = otherThingsInTheSet; - } - - @Override - public Set> getContents() { - Set> pas = new HashSet<>(otherThingsInTheSet); - - pas.add(alreadyStored); - - return Set.copyOf(pas); - } - - @Override - public IdentifiableNode getSideNode() { - return alreadyStored; - } -} diff --git a/core/src/main/java/me/aurium/branch/nodes/branching/PrestoredSet.java b/core/src/main/java/me/aurium/branch/nodes/branching/PrestoredSet.java deleted file mode 100644 index bc164f2..0000000 --- a/core/src/main/java/me/aurium/branch/nodes/branching/PrestoredSet.java +++ /dev/null @@ -1,13 +0,0 @@ -package me.aurium.branch.nodes.branching; - -import me.aurium.branch.nodes.CommandNode; -import me.aurium.branch.nodes.IdentifiableNode; - -import java.util.Set; - -public interface PrestoredSet { - - Set> getContents(); - CommandNode getSideNode(); - -} diff --git a/core/src/main/java/me/aurium/branch/nodes/results/SearchInfo.java b/core/src/main/java/me/aurium/branch/nodes/results/SearchInfo.java deleted file mode 100644 index abd6061..0000000 --- a/core/src/main/java/me/aurium/branch/nodes/results/SearchInfo.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * - * Branch - * Copyright © 2021 Aurium - * - * Branch is free software: you can redistribute it and/or modify - * It under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * Branch is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Branch. If not, see - * and navigate to version 3 of the GNU Affero General Public License. - * - */ - -package me.aurium.branch.nodes.results; - -import me.aurium.branch.execution.Block; -import me.aurium.branch.nodes.CommandNode; - -import java.util.List; - -public class SearchInfo { - - private final CommandNode calculatedNode; - - private final List initialPath; - private final List reducedPath; - - public SearchInfo(CommandNode calculatedNode, SearchInput input) { - this.calculatedNode = calculatedNode; - - this.initialPath = List.copyOf(input.getInitialPath()); - this.reducedPath = List.copyOf(input.getReducablePath()); - - } - - public CommandNode resultingNode() { - return calculatedNode; - } - - public List initialPath() { - return initialPath; - } - - public List reducedPath() { - return reducedPath; - } - - public boolean hasMoreArguments() { - return initialPath.isEmpty(); - } -} diff --git a/core/src/main/java/me/aurium/branch/nodes/results/SearchInput.java b/core/src/main/java/me/aurium/branch/nodes/results/SearchInput.java deleted file mode 100644 index d44ea2d..0000000 --- a/core/src/main/java/me/aurium/branch/nodes/results/SearchInput.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * - * Branch - * Copyright © 2021 Aurium - * - * Branch is free software: you can redistribute it and/or modify - * It under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * Branch is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Branch. If not, see - * and navigate to version 3 of the GNU Affero General Public License. - * - */ - -package me.aurium.branch.nodes.results; - -import me.aurium.branch.execution.Block; -import me.aurium.branch.execution.StringBlock; - -import java.util.ArrayDeque; -import java.util.ArrayList; -import java.util.Deque; -import java.util.List; - -public class SearchInput { - - private final List initialPath; //TODO make list or something - i don't care but it must be immutable - private final Deque reducablePath; - - public SearchInput(List initialPath, Deque reducablePath) { - this.initialPath = initialPath; - this.reducablePath = reducablePath; - } - - public List getInitialPath() { - return List.copyOf(initialPath); - } - public Deque getReducablePath() { - return reducablePath; - } - - public SearchInput withoutTop() { - List newBase = new ArrayList<>(initialPath); - - newBase.remove(newBase.size() - 1); - - return new SearchInput(newBase, new ArrayDeque<>(newBase)); - } - - public static SearchInput of(String[] args) { - List blocks = new ArrayList<>(); - - for (String string : args) { - blocks.add(StringBlock.of(string)); - } - - return new SearchInput(blocks, new ArrayDeque<>(blocks)); - } -} diff --git a/core/src/main/java/me/aurium/branch/nodes/single/HelpNode.java b/core/src/main/java/me/aurium/branch/nodes/single/HelpNode.java deleted file mode 100644 index 0b402b0..0000000 --- a/core/src/main/java/me/aurium/branch/nodes/single/HelpNode.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * - * Branch - * Copyright © 2021 Aurium - * - * Branch is free software: you can redistribute it and/or modify - * It under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * Branch is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Branch. If not, see - * and navigate to version 3 of the GNU Affero General Public License. - * - */ - -package me.aurium.branch.nodes.single; - -import me.aurium.branch.execution.Block; -import me.aurium.branch.execution.api.BranchHandler; -import me.aurium.branch.fallback.permissions.Permission; -import me.aurium.branch.information.description.Description; -import me.aurium.branch.nodes.single.EndpointNode; - -/** - * Represents a node that pregenerates help entries based on the message context - */ -public class HelpNode extends EndpointNode { - - @Override - public BranchHandler getHandling() { - return null; - } - - @Override - public Permission getPermission() { - return null; - } - - @Override - public Block getIdentifier() { - return null; - } - - @Override - public Description getDescription() { - return null; - } -} diff --git a/core/src/main/java/me/aurium/branch/nodes/single/SingleBuilder.java b/core/src/main/java/me/aurium/branch/nodes/single/SingleBuilder.java deleted file mode 100644 index 1f8af5b..0000000 --- a/core/src/main/java/me/aurium/branch/nodes/single/SingleBuilder.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * - * Branch - * Copyright © 2021 Aurium - * - * Branch is free software: you can redistribute it and/or modify - * It under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * Branch is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Branch. If not, see - * and navigate to version 3 of the GNU Affero General Public License. - * - */ - -package me.aurium.branch.nodes.single; - -import me.aurium.branch.execution.Block; -import me.aurium.branch.execution.StringBlock; -import me.aurium.branch.execution.api.ExecutionHandler; -import me.aurium.branch.information.description.Description; -import me.aurium.branch.information.description.StringDescription; -import me.aurium.branch.nodes.Builder; -import me.aurium.branch.nodes.CommandNode; -import me.aurium.branch.fallback.permissions.Permission; -import me.aurium.branch.fallback.permissions.EmptyPermission; - -import java.util.Objects; - -public class SingleBuilder implements Builder { - - private Block block; - private ExecutionHandler contextHandler; - private Permission permission = new EmptyPermission<>(); - private Description description; - - public void withIdentifier(Block identifier) { - this.block = identifier; - } - - public void withIdentifier(String string) { - this.block = StringBlock.of(string); - } - - public void withHandler(ExecutionHandler handler) { - this.contextHandler = handler; - } - - public void withPermission(Permission permission) { - this.permission = permission; - } - - public void withDescription(Description description) { - this.description = description; - } - - public CommandNode build() { - Objects.requireNonNull(block); - Objects.requireNonNull(contextHandler); - - Description returned = Objects.requireNonNullElse(description,new StringDescription("Default description for subcommand " + block.getIdentifier())); - - return new SingleNode<>(block, contextHandler, permission, returned); - } - -} diff --git a/core/src/main/java/me/aurium/branch/nodes/single/SingleNode.java b/core/src/main/java/me/aurium/branch/nodes/single/SingleNode.java deleted file mode 100644 index 67ff1be..0000000 --- a/core/src/main/java/me/aurium/branch/nodes/single/SingleNode.java +++ /dev/null @@ -1,106 +0,0 @@ -/* - * - * Branch - * Copyright © 2021 Aurium - * - * Branch is free software: you can redistribute it and/or modify - * It under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * Branch is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Branch. If not, see - * and navigate to version 3 of the GNU Affero General Public License. - * - */ - -package me.aurium.branch.nodes.single; - -import me.aurium.branch.execution.Block; -import me.aurium.branch.execution.api.BranchHandler; -import me.aurium.branch.execution.api.ExecutionHandler; -import me.aurium.branch.execution.api.Execution; -import me.aurium.branch.execution.NodeContext; -import me.aurium.branch.information.description.Description; -import me.aurium.branch.nodes.results.SearchInfo; -import me.aurium.branch.fallback.permissions.Permission; -import me.aurium.branch.nodes.results.model.Result; - -import java.util.ArrayList; -import java.util.List; - -/** - * Represents a node that can do one action and takes no arguments and has no tabcompletion - * @param the type of executor - */ -public class SingleNode extends EndpointNode { - - private final Block identifier; - private final Permission permission; - private final SingleHandler handler; - private final Description description; - - public SingleNode(Block identifier, ExecutionHandler executionHandler, Permission permission, Description description) { - this.identifier = identifier; - - this.handler = new SingleHandler<>(executionHandler); - this.permission = permission; - this.description = description; - } - - @Override - public Block getIdentifier() { - return identifier; - } - - @Override - public Description getDescription() { - return description; - } - - @Override - public BranchHandler getHandling() { - return handler; - } - - @Override - public Permission getPermission() { - return permission; - } - - public static class SingleHandler implements BranchHandler { - - private final ExecutionHandler handler; - - public SingleHandler(ExecutionHandler handler) { - this.handler = handler; - } - - @Override - public Execution getExecution(NodeContext context) { - SearchInfo info = context.getResults(); - - /*if (info.hasMoreArguments()) { - return Result.fail( - new TooManyArgsResponse(0,info.reducedPath().size()) //TODO move this to search details - ); - }*/ - - return new Execution<>(handler,context); - } - - @Override - public List getSuggestions(NodeContext context) { - return new ArrayList<>(); - } - - } - - - -} diff --git a/docs/.nojekyll b/docs/.nojekyll deleted file mode 100644 index e69de29..0000000 diff --git a/docs/README.md b/docs/README.md deleted file mode 100644 index a4d69e6..0000000 --- a/docs/README.md +++ /dev/null @@ -1,35 +0,0 @@ -# Branch - -An opinionated command framework based around the concept of an argument handling node - -Has support for both builder format and annotation format - -Built for use with Beetle but can be used independently - -## How can I ask for support? - -DM **Aesthetik#9784** on discord! - -## Contributing - -Make pull requests that arent bad and I accept them. It's about that simple! - -## Repositories - -``` - - - me.aurium - branch-core - 0.1.0 - - -``` -``` - - - aurium - https://repo.repsy.io/mvn/elytraforce/default - - -``` diff --git a/docs/_coverpage.md b/docs/_coverpage.md deleted file mode 100644 index fa401c7..0000000 --- a/docs/_coverpage.md +++ /dev/null @@ -1,13 +0,0 @@ -![logo](media/branch.png) - -# branch framework 1.0 - -> A powerful Java command framework - -- Versatile and object oriented -- Many implementations, including ones for Spigot and Velocity -- Annotations, or builder format -- Easy for beginners, flexible enough for experienced devs - -[GitHub](https://github.com/docsifyjs/docsify/) -[Get Started](#docsify) \ No newline at end of file diff --git a/docs/_sidebar.md b/docs/_sidebar.md deleted file mode 100644 index 98fcd8b..0000000 --- a/docs/_sidebar.md +++ /dev/null @@ -1,32 +0,0 @@ -- Branch Framework - - - [Introduction](README.md) - -- Getting Started - - - [Key Concepts](info/concepts.md) - - [Basic Example](info/example.md) - -- Nodes - - - [What is a node?](info/nodes.md) - - [The Argument Node](info/argumentnode.md) - - Other Nodes - - [The Single Node](info/singlenode.md) - - [The Branching Node](info/branchingnode.md) - - [The Help Node](info/helpnode.md) - - [Implementing your own](info/implementingnode.md) - -- Central - - - Core Management - - [The Centralized Manager](info/centralizedmanager.md) - - [Type Adapters](info/typeadapter.md) - - [Node Bases](info/nodebase.md) - - [Fallback Strategies](info/fallback.md) - - Messaging and Responses - - [Response Handling](info/responses.md) - - [Descriptions and Help](info/descriptions.md) - - - diff --git a/docs/index.html b/docs/index.html deleted file mode 100644 index de14ede..0000000 --- a/docs/index.html +++ /dev/null @@ -1,27 +0,0 @@ - - - - - Branch Framework - - - - - - - -

- - - - - diff --git a/docs/media/branch.png b/docs/media/branch.png deleted file mode 100644 index f97d1f0..0000000 Binary files a/docs/media/branch.png and /dev/null differ diff --git a/pom.xml b/pom.xml index 31d7368..e8187e8 100644 --- a/pom.xml +++ b/pom.xml @@ -25,20 +25,24 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 + + xyz.auriium + insect + 0.3.0 + + branch pom 0.1.0 - - me.aurium - insect - 0.2.1 - + + scm:git:https://github.com/Auriium/Branch.git + - core - core-tests - spigot-impl + branch-core + branch-spigot-impl + branch-adventure @@ -49,18 +53,35 @@ + xyz.auriium branch-core - me.aurium - ${project.version} + 0.1.0 + + + org.junit.jupiter + junit-jupiter-engine + 5.7.0 + test + + + org.slf4j + slf4j-api + 1.7.32 + test + + + org.junit.jupiter + junit-jupiter-params + 5.7.0 + test - jfrog - a0phrw82hnl4g-artifactory-primary-0-releases - https://aurium.jfrog.io/artifactory/aurium-libs-release-local + central-repo + https://repo.auriium.xyz/releases diff --git a/readme.md b/readme.md index 9ec4aaa..d03732a 100644 --- a/readme.md +++ b/readme.md @@ -6,6 +6,17 @@ Has support for both builder format and annotation format Built for use with Beetle but can be used independently +TODO something something Branch Base lets you write subcommands as if they were individual commands, no complex array/iterator or hard thinking required + +TODO yada yada Branch Base also lets you write commands the way YOU want to, +with formats for all adherents of 3 popular command styles: + +builder with functional interface, +light builder + manually implement any logic-handling node +interface + annotation + +yada yada additionally branch is lightweight where you tell it to be. There is no separate executorservice instantiated purely for a command handling framework. + # How can I ask for support? DM **Aesthetik#9784** on discord! diff --git a/spigot-impl/src/main/java/me/aurium/branch/spigot/SpigotContext.java b/spigot-impl/src/main/java/me/aurium/branch/spigot/SpigotContext.java deleted file mode 100644 index b1eb1c2..0000000 --- a/spigot-impl/src/main/java/me/aurium/branch/spigot/SpigotContext.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * - * Branch - * Copyright © 2021 Aurium - * - * Branch is free software: you can redistribute it and/or modify - * It under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * Branch is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Branch. If not, see - * and navigate to version 3 of the GNU Affero General Public License. - * - */ - -package me.aurium.branch.spigot; - - -import me.aurium.branch.execution.AbstractNodeContext; -import me.aurium.branch.interfacing.handlers.InterfacingHandler; -import me.aurium.branch.interfacing.Response; -import me.aurium.branch.nodes.CommandNode; -import me.aurium.branch.nodes.results.SearchInfo; -import org.bukkit.ChatColor; -import org.bukkit.command.CommandSender; - -public class SpigotContext extends AbstractNodeContext { - - private final T sender; - private final InterfacingHandler handler; - - protected SpigotContext(T sender, String alias, String[] args, CommandNode baseNode, SearchInfo result, InterfacingHandler handler) { - super(sender, alias, args, baseNode, result); - - this.sender = sender; - this.handler = handler; - } - - @Override - public void stringSender(String string) { - this.sender.sendMessage(ChatColor.translateAlternateColorCodes('&',string)); - } - - @Override - public void response(Response failure) { - handler.sendMessage(sender,failure); - } -} diff --git a/spigot-impl/src/main/java/me/aurium/branch/spigot/message/SpigotMessageMap.java b/spigot-impl/src/main/java/me/aurium/branch/spigot/message/SpigotMessageMap.java deleted file mode 100644 index bff08f2..0000000 --- a/spigot-impl/src/main/java/me/aurium/branch/spigot/message/SpigotMessageMap.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * - * Branch - * Copyright © 2021 Aurium - * - * Branch is free software: you can redistribute it and/or modify - * It under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * Branch is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Branch. If not, see - * and navigate to version 3 of the GNU Affero General Public License. - * - */ - -package me.aurium.branch.spigot.message; - -import me.aurium.branch.interfacing.Response; -import me.aurium.branch.interfacing.ResponseAction; -import me.aurium.branch.interfacing.handlers.DelegatingDefaultMap; -import me.aurium.branch.interfacing.handlers.InnerMap; -import me.aurium.branch.interfacing.responses.FailedAdaptingResponse; -import org.bukkit.command.CommandSender; - -/** - * Spigot message defaults - * @param - */ -public class SpigotMessageMap extends DelegatingDefaultMap { - - @Override - public SpigotMessageMap add(Class key, ResponseAction action) { - return (SpigotMessageMap) super.add(key, action); - } - - @Override - protected InnerMap defaultMap() { - InnerMap map = new InnerMap<>(); - - map.add(FailedAdaptingResponse.class, response -> new TextMessage<>( - "Expected class: " + response.getExpectedClass().getName() + "Got class: " + response.getReceivedClass() - )); - - return map; - } -} diff --git a/spigot-impl/src/main/java/me/aurium/branch/spigot/message/TextMessage.java b/spigot-impl/src/main/java/me/aurium/branch/spigot/message/TextMessage.java deleted file mode 100644 index 846e202..0000000 --- a/spigot-impl/src/main/java/me/aurium/branch/spigot/message/TextMessage.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * - * Branch - * Copyright © 2021 Aurium - * - * Branch is free software: you can redistribute it and/or modify - * It under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * Branch is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Branch. If not, see - * and navigate to version 3 of the GNU Affero General Public License. - * - */ - -package me.aurium.branch.spigot.message; - -import me.aurium.branch.interfacing.Message; -import org.bukkit.ChatColor; -import org.bukkit.command.CommandSender; - -public class TextMessage implements Message { - - private final String[] coloredStringToSend; - - public TextMessage(String... coloredStringToSend) { - this.coloredStringToSend = coloredStringToSend; - } - - @Override - public void accept(C sender) { - - for (String string : coloredStringToSend) { - sender.sendMessage(ChatColor.translateAlternateColorCodes('&',string)); - } - - } -}