diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml new file mode 100644 index 0000000..ffa0eb4 --- /dev/null +++ b/.github/workflows/maven.yml @@ -0,0 +1,24 @@ +# This workflow will build a Java project with Maven +# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven + +name: Java CI with Maven + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: Set up JDK 16 + uses: actions/setup-java@v1 + with: + java-version: 16 + - name: Build with Maven + run: mvn -B package --file pom.xml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..85e7c1d --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/.idea/ diff --git a/.idea/.gitignore b/.idea/.gitignore deleted file mode 100644 index 26d3352..0000000 --- a/.idea/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -# Default ignored files -/shelf/ -/workspace.xml diff --git a/.idea/compiler.xml b/.idea/compiler.xml deleted file mode 100644 index b67d6a5..0000000 --- a/.idea/compiler.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml deleted file mode 100644 index 8dcf5b9..0000000 --- a/.idea/encodings.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml deleted file mode 100644 index 5a6f4b1..0000000 --- a/.idea/jarRepositories.xml +++ /dev/null @@ -1,30 +0,0 @@ - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index 5f3e0f8..0000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - \ No newline at end of file diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml deleted file mode 100644 index e96534f..0000000 --- a/.idea/uiDesigner.xml +++ /dev/null @@ -1,124 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/branch.iml b/core-tests/core-tests.iml similarity index 100% rename from branch.iml rename to core-tests/core-tests.iml diff --git a/core-tests/pom.xml b/core-tests/pom.xml new file mode 100644 index 0000000..341cfa7 --- /dev/null +++ b/core-tests/pom.xml @@ -0,0 +1,75 @@ + + + + + 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 new file mode 100644 index 0000000..3795f71 --- /dev/null +++ b/core-tests/src/main/java/me/aurium/branch/tests/StringAdapter.java @@ -0,0 +1,27 @@ +/* + * + * 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 new file mode 100644 index 0000000..229da42 --- /dev/null +++ b/core-tests/src/main/java/me/aurium/branch/tests/StringManager.java @@ -0,0 +1,57 @@ +/* + * + * 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-tests/src/test/java/me/aurium/branch/ExecutionTest.java b/core-tests/src/test/java/me/aurium/branch/ExecutionTest.java new file mode 100644 index 0000000..5ebc147 --- /dev/null +++ b/core-tests/src/test/java/me/aurium/branch/ExecutionTest.java @@ -0,0 +1,34 @@ +/* + * + * 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; + +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 StringManager manager = new StringManager(); + +} diff --git a/core/pom.xml b/core/pom.xml index cede4cf..b7479b7 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -1,4 +1,25 @@ + + @@ -9,19 +30,27 @@ 4.0.0 - core + branch-core ${compiler.version} ${compiler.version} - - - me.aurium - beetle-core - ${core.version} - - + + + + org.apache.maven.plugins + maven-surefire-plugin + 3.0.0-M5 + + false + + + + + + + \ No newline at end of file diff --git a/core/src/main/java/me/aurium/beetle/branch/AlreadyStoredHashSet.java b/core/src/main/java/me/aurium/beetle/branch/AlreadyStoredHashSet.java deleted file mode 100644 index e6f8771..0000000 --- a/core/src/main/java/me/aurium/beetle/branch/AlreadyStoredHashSet.java +++ /dev/null @@ -1,53 +0,0 @@ -package me.aurium.beetle.branch; - -import java.util.HashSet; -import java.util.Set; - -/** - * Represents a set that already has an element in it - */ -public class AlreadyStoredHashSet { - - private T alreadyStored; - private final Set otherThingsInTheSet; - - //fuck code in the constructor rules - //i don't care - public AlreadyStoredHashSet(T alreadyStored) { - this.alreadyStored = alreadyStored; - this.otherThingsInTheSet = new HashSet<>(); - } - - public AlreadyStoredHashSet(Set set) { - this.otherThingsInTheSet = set; - } - - public AlreadyStoredHashSet() { - this.otherThingsInTheSet = new HashSet<>(); - } - - /** - * Returns an immutable collection of T (plus already stored variable if it is present) - * @return an immutable collection of T - */ - public Set getContents() { - if (alreadyStored == null) { - return Set.copyOf(otherThingsInTheSet); - } else { - Set set = new HashSet<>(otherThingsInTheSet); - - set.add(alreadyStored); - - return Set.copyOf(set); - } - } - - /** - * get already store thing - * @return already stored thing or null - */ - public T getAlreadyStored() { - return alreadyStored; - } - -} diff --git a/core/src/main/java/me/aurium/beetle/branch/CommandBase.java b/core/src/main/java/me/aurium/beetle/branch/CommandBase.java deleted file mode 100644 index f72961e..0000000 --- a/core/src/main/java/me/aurium/beetle/branch/CommandBase.java +++ /dev/null @@ -1,8 +0,0 @@ -package me.aurium.beetle.branch; - -public interface CommandBase { - - ContextHandler getHandler(Context context); - void handle(Context context); - -} diff --git a/core/src/main/java/me/aurium/beetle/branch/CommandNode.java b/core/src/main/java/me/aurium/beetle/branch/CommandNode.java deleted file mode 100644 index 0266dfe..0000000 --- a/core/src/main/java/me/aurium/beetle/branch/CommandNode.java +++ /dev/null @@ -1,13 +0,0 @@ -package me.aurium.beetle.branch; - -import me.aurium.beetle.api.nodes.Node; - -public interface CommandNode extends Node> { - - /** - * Represents the context handler to be used if there are no args or args are incorrect - * @return said contexthandler... - */ - ContextHandler getContextHandler(); - -} diff --git a/core/src/main/java/me/aurium/beetle/branch/Context.java b/core/src/main/java/me/aurium/beetle/branch/Context.java deleted file mode 100644 index 3d3ccf6..0000000 --- a/core/src/main/java/me/aurium/beetle/branch/Context.java +++ /dev/null @@ -1,13 +0,0 @@ -package me.aurium.beetle.branch; - -/** - * The context of a command - * @param the type of command source - */ -public interface Context { - - T getSender(); - String getAlias(); - String[] getArgs(); - -} diff --git a/core/src/main/java/me/aurium/beetle/branch/ContextHandler.java b/core/src/main/java/me/aurium/beetle/branch/ContextHandler.java deleted file mode 100644 index 25d2701..0000000 --- a/core/src/main/java/me/aurium/beetle/branch/ContextHandler.java +++ /dev/null @@ -1,8 +0,0 @@ -package me.aurium.beetle.branch; - -@FunctionalInterface -public interface ContextHandler { - - void consume(Context consumed); - -} diff --git a/core/src/main/java/me/aurium/beetle/branch/bases/CommandableBase.java b/core/src/main/java/me/aurium/beetle/branch/bases/CommandableBase.java deleted file mode 100644 index ba9eb32..0000000 --- a/core/src/main/java/me/aurium/beetle/branch/bases/CommandableBase.java +++ /dev/null @@ -1,50 +0,0 @@ -package me.aurium.beetle.branch.bases; - -import me.aurium.beetle.api.command.AbstractCommand; -import me.aurium.beetle.branch.CommandBase; -import me.aurium.beetle.branch.CommandNode; -import me.aurium.beetle.branch.Context; -import me.aurium.beetle.branch.ContextHandler; -import me.aurium.beetle.branch.impl.CommonContext; - -public class CommandableBase implements CommandBase, AbstractCommand { - - private final String name; - private final String permission; - private final CommandNode node; - - public CommandableBase(String name, String permission, CommandNode node) { - this.name = name; - this.permission = permission; - this.node = node; - } - - @Override - public ContextHandler getHandler(Context context) { - return null; - } - - @Override - public void handle(Context context) { - - } - - @Override - public String getName() { - return null; - } - - @Override - public String getPermission() { - return null; - } - - @Override - public boolean execute(T t, String alias, String[] strings) { - Context context = new CommonContext<>(t,alias,strings); - - handle(context); - - return true; - } -} diff --git a/core/src/main/java/me/aurium/beetle/branch/bases/SimpleBase.java b/core/src/main/java/me/aurium/beetle/branch/bases/SimpleBase.java deleted file mode 100644 index 2e63830..0000000 --- a/core/src/main/java/me/aurium/beetle/branch/bases/SimpleBase.java +++ /dev/null @@ -1,37 +0,0 @@ -package me.aurium.beetle.branch.bases; - -import me.aurium.beetle.api.nodes.impl.StringBlockPath; -import me.aurium.beetle.api.nodes.path.BlockPath; -import me.aurium.beetle.branch.CommandBase; -import me.aurium.beetle.branch.CommandNode; -import me.aurium.beetle.branch.Context; -import me.aurium.beetle.branch.ContextHandler; - -import java.util.Optional; - -/// FIXME: 3/10/21 I've discovered that a nodemap cannot be built with both it's parent and contents being set up correctly -public class SimpleBase implements CommandBase { - - private final CommandNode baseNode; - - public SimpleBase(CommandNode baseNode) { - this.baseNode = baseNode; - } - - @Override - public ContextHandler getHandler(Context context) { - BlockPath correctPath = StringBlockPath.of(context.getArgs()); - Optional> node = baseNode.getSpecificNode(correctPath); - - if (node.isPresent()) { - return node.get().getContextHandler(); - } else { - return baseNode.getContextHandler(); - } - } - - @Override - public void handle(Context context) { - getHandler(context).consume(context); - } -} diff --git a/core/src/main/java/me/aurium/beetle/branch/impl/CommonContext.java b/core/src/main/java/me/aurium/beetle/branch/impl/CommonContext.java deleted file mode 100644 index ad88be8..0000000 --- a/core/src/main/java/me/aurium/beetle/branch/impl/CommonContext.java +++ /dev/null @@ -1,31 +0,0 @@ -package me.aurium.beetle.branch.impl; - -import me.aurium.beetle.branch.Context; - -public class CommonContext implements Context { - - private final T sender; - private final String alias; - private final String[] args; - - public CommonContext(T sender, String alias, String[] args) { - this.sender = sender; - this.alias = alias; - this.args = args; - } - - @Override - public T getSender() { - return sender; - } - - @Override - public String getAlias() { - return alias; - } - - @Override - public String[] getArgs() { - return args; - } -} diff --git a/core/src/main/java/me/aurium/beetle/branch/nodes/BranchingCommandNode.java b/core/src/main/java/me/aurium/beetle/branch/nodes/BranchingCommandNode.java deleted file mode 100644 index c0a5dbd..0000000 --- a/core/src/main/java/me/aurium/beetle/branch/nodes/BranchingCommandNode.java +++ /dev/null @@ -1,65 +0,0 @@ -package me.aurium.beetle.branch.nodes; - -import me.aurium.beetle.api.nodes.path.Block; -import me.aurium.beetle.api.nodes.path.BlockPath; -import me.aurium.beetle.branch.AlreadyStoredHashSet; -import me.aurium.beetle.branch.CommandNode; -import me.aurium.beetle.branch.ContextHandler; - -import java.util.Collection; -import java.util.Optional; - -public class BranchingCommandNode implements CommandNode { - - private final AlreadyStoredHashSet> nodes; - private final CommandNode root; - private final CommandNode parent; - private final Block path; - - public BranchingCommandNode(AlreadyStoredHashSet> nodes, CommandNode root, CommandNode parent, Block path, ContextHandler handler) { - this.nodes = nodes; - this.root = root; - this.parent = parent; - this.path = path; - } - - @Override - public BlockPath getAbsolutePath() { - return parent.getAbsolutePath().resolve(path); - } - - @Override - public Block getShortPath() { - return path; - } - - @Override - public CommandNode getRoot() { - return root; - } - - @Override - public CommandNode getParent() { - return parent; - } - - @Override - public Optional> getSpecificNode(BlockPath blockPath) { - for (CommandNode node : this.getLinkedNodes()) { - if (blockPath.startsWith(node.getShortPath())) { - return node.getSpecificNode(blockPath); - } - } - return Optional.empty(); - } - - @Override - public Collection> getLinkedNodes() { - return nodes.getContents(); - } - - @Override - public ContextHandler getContextHandler() { - return nodes.getAlreadyStored().getContextHandler(); - } -} diff --git a/core/src/main/java/me/aurium/beetle/branch/nodes/SingleCommandNode.java b/core/src/main/java/me/aurium/beetle/branch/nodes/SingleCommandNode.java deleted file mode 100644 index bda8afb..0000000 --- a/core/src/main/java/me/aurium/beetle/branch/nodes/SingleCommandNode.java +++ /dev/null @@ -1,60 +0,0 @@ -package me.aurium.beetle.branch.nodes; - -import me.aurium.beetle.api.nodes.path.Block; -import me.aurium.beetle.api.nodes.path.BlockPath; -import me.aurium.beetle.branch.CommandNode; -import me.aurium.beetle.branch.ContextHandler; - -import java.util.Collection; -import java.util.Collections; -import java.util.Optional; - -public class SingleCommandNode implements CommandNode { - - private final CommandNode root; - private final CommandNode parent; - private final Block identifier; - private final ContextHandler handler; - - public SingleCommandNode(CommandNode root, CommandNode parent, Block identifier, ContextHandler contextHandler) { - this.root = root; - this.parent = parent; - this.identifier = identifier; - this.handler = contextHandler; - } - - @Override - public BlockPath getAbsolutePath() { - return parent.getAbsolutePath().resolve(identifier); - } - - @Override - public Block getShortPath() { - return identifier; - } - - @Override - public CommandNode getRoot() { - return root; - } - - @Override - public CommandNode getParent() { - return parent; - } - - @Override - public Optional> getSpecificNode(BlockPath blockPath) { - return Optional.of(this); - } - - @Override - public Collection> getLinkedNodes() { - return Collections.emptySet(); - } - - @Override - public ContextHandler getContextHandler() { - return handler; - } -} diff --git a/core/src/main/java/me/aurium/beetle/branch/nodes/ValueNode.java b/core/src/main/java/me/aurium/beetle/branch/nodes/ValueNode.java deleted file mode 100644 index db460b9..0000000 --- a/core/src/main/java/me/aurium/beetle/branch/nodes/ValueNode.java +++ /dev/null @@ -1,4 +0,0 @@ -package me.aurium.beetle.branch.nodes; - -public class ValueNode { -} diff --git a/core/src/main/java/me/aurium/beetle/branch/nodes/ValueSelectorNode.java b/core/src/main/java/me/aurium/beetle/branch/nodes/ValueSelectorNode.java deleted file mode 100644 index 8b5cf78..0000000 --- a/core/src/main/java/me/aurium/beetle/branch/nodes/ValueSelectorNode.java +++ /dev/null @@ -1,4 +0,0 @@ -package me.aurium.beetle.branch.nodes; - -public class ValueSelectorNode { -} diff --git a/core/src/main/java/me/aurium/branch/centralized/CentralizedManager.java b/core/src/main/java/me/aurium/branch/centralized/CentralizedManager.java new file mode 100644 index 0000000..cac406a --- /dev/null +++ b/core/src/main/java/me/aurium/branch/centralized/CentralizedManager.java @@ -0,0 +1,44 @@ +/* + * + * 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; + +import me.aurium.branch.centralized.base.NodeBase; +import me.aurium.branch.centralized.base.NodeBaseBuilder; +import me.aurium.branch.centralized.typeadapter.ManagerAdapter; + +/** + * Represents the utmost base part of the command framework which has the ability to bind any injected commands to a platform + * @param the input type, does not need to be of same type as the node bases it utilizes + * @param the platform + */ +public interface CentralizedManager { + + CentralizedManagerBinder getBinder(V platform); + NodeSource getSource(); + + NodeBaseBuilder newCommand(); + NodeBaseBuilder newCommand(ManagerAdapter adapter); + + void injectCommand(NodeBase base); + + +} diff --git a/core/src/main/java/me/aurium/branch/centralized/CentralizedManagerBinder.java b/core/src/main/java/me/aurium/branch/centralized/CentralizedManagerBinder.java new file mode 100644 index 0000000..2c16ed7 --- /dev/null +++ b/core/src/main/java/me/aurium/branch/centralized/CentralizedManagerBinder.java @@ -0,0 +1,34 @@ +/* + * + * 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; + +/** + * Represents a carrier vessel which is typically attached to the instance of a centralizedManagerBinder's platform + */ +public interface CentralizedManagerBinder { + + /** + * Register all commands to the platform + */ + void bind(); + +} diff --git a/core/src/main/java/me/aurium/branch/centralized/NodeSource.java b/core/src/main/java/me/aurium/branch/centralized/NodeSource.java new file mode 100644 index 0000000..e7867be --- /dev/null +++ b/core/src/main/java/me/aurium/branch/centralized/NodeSource.java @@ -0,0 +1,14 @@ +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 new file mode 100644 index 0000000..4f0e0c9 --- /dev/null +++ b/core/src/main/java/me/aurium/branch/centralized/base/AdaptingNodeBase.java @@ -0,0 +1,86 @@ +/* + * + * 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 new file mode 100644 index 0000000..cddf7e0 --- /dev/null +++ b/core/src/main/java/me/aurium/branch/centralized/base/DelegatingNodeBase.java @@ -0,0 +1,35 @@ +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 new file mode 100644 index 0000000..4323616 --- /dev/null +++ b/core/src/main/java/me/aurium/branch/centralized/base/NodeBase.java @@ -0,0 +1,45 @@ +/* + * + * 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 new file mode 100644 index 0000000..42154c0 --- /dev/null +++ b/core/src/main/java/me/aurium/branch/centralized/base/NodeBaseBuilder.java @@ -0,0 +1,96 @@ +/* + * + * 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/centralized/typeadapter/CommonAdapter.java b/core/src/main/java/me/aurium/branch/centralized/typeadapter/CommonAdapter.java new file mode 100644 index 0000000..fb18fcd --- /dev/null +++ b/core/src/main/java/me/aurium/branch/centralized/typeadapter/CommonAdapter.java @@ -0,0 +1,46 @@ +/* + * + * 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.typeadapter; + +import me.aurium.branch.interfacing.responses.FailedAdaptingResponse; + +/** + * Represents an adapter that does not convert and simply returns the same object + * @param the object type + */ +public interface CommonAdapter extends ManagerAdapter { + + @Override + default T adapt(T input) { + return input; + } + + @Override + default boolean canAdapt(T input) { + return true; + } + + @Override + default FailedAdaptingResponse failedParseResponse(T input) { + throw new IllegalStateException("How did you get here (Since canAdapt is always true this should never occur?)"); + } +} diff --git a/core/src/main/java/me/aurium/branch/centralized/typeadapter/ManagerAdapter.java b/core/src/main/java/me/aurium/branch/centralized/typeadapter/ManagerAdapter.java new file mode 100644 index 0000000..56e51f9 --- /dev/null +++ b/core/src/main/java/me/aurium/branch/centralized/typeadapter/ManagerAdapter.java @@ -0,0 +1,40 @@ +/* + * + * 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.typeadapter; + +import me.aurium.branch.interfacing.responses.FailedAdaptingResponse; + +/** + * Represents something that can convert an object of a certain type to another object + * It is used to enable the use of nodes of a unique type on a centralized manager of a separate type. + * + * @param Input object type + * @param Output object type + */ +public interface ManagerAdapter { + + OUTPUT adapt(INPUT input); + boolean canAdapt(INPUT input); + + FailedAdaptingResponse failedParseResponse(INPUT input); + +} diff --git a/core/src/main/java/me/aurium/branch/centralized/typeadapter/StandardCommonAdapter.java b/core/src/main/java/me/aurium/branch/centralized/typeadapter/StandardCommonAdapter.java new file mode 100644 index 0000000..bee22dd --- /dev/null +++ b/core/src/main/java/me/aurium/branch/centralized/typeadapter/StandardCommonAdapter.java @@ -0,0 +1,28 @@ +/* + * + * 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.typeadapter; + +/** + * Simple implementation"" + */ +public class StandardCommonAdapter implements CommonAdapter { +} diff --git a/core/src/main/java/me/aurium/branch/execution/AbstractNodeContext.java b/core/src/main/java/me/aurium/branch/execution/AbstractNodeContext.java new file mode 100644 index 0000000..71bc2a6 --- /dev/null +++ b/core/src/main/java/me/aurium/branch/execution/AbstractNodeContext.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 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/Block.java b/core/src/main/java/me/aurium/branch/execution/Block.java new file mode 100644 index 0000000..b8048c1 --- /dev/null +++ b/core/src/main/java/me/aurium/branch/execution/Block.java @@ -0,0 +1,34 @@ +/* + * + * 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 an unparsed component of a command argument input structure + */ +public interface Block { + + String getIdentifier(); + + boolean equals(Object object); + boolean isVisual(); + +} diff --git a/core/src/main/java/me/aurium/branch/execution/ContextProvider.java b/core/src/main/java/me/aurium/branch/execution/ContextProvider.java new file mode 100644 index 0000000..4c6056d --- /dev/null +++ b/core/src/main/java/me/aurium/branch/execution/ContextProvider.java @@ -0,0 +1,34 @@ +/* + * + * 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; + +/** + * 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); + +} diff --git a/core/src/main/java/me/aurium/branch/execution/EmptyExecutionHandler.java b/core/src/main/java/me/aurium/branch/execution/EmptyExecutionHandler.java new file mode 100644 index 0000000..3ba74c8 --- /dev/null +++ b/core/src/main/java/me/aurium/branch/execution/EmptyExecutionHandler.java @@ -0,0 +1,31 @@ +/* + * + * 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.ExecutionHandler; + +public class EmptyExecutionHandler implements ExecutionHandler { + @Override + public void handle(NodeContext adapter) { + + } +} diff --git a/core/src/main/java/me/aurium/branch/execution/EmptySuggestionHandler.java b/core/src/main/java/me/aurium/branch/execution/EmptySuggestionHandler.java new file mode 100644 index 0000000..f819a89 --- /dev/null +++ b/core/src/main/java/me/aurium/branch/execution/EmptySuggestionHandler.java @@ -0,0 +1,37 @@ +/* + * + * 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/NodeContext.java b/core/src/main/java/me/aurium/branch/execution/NodeContext.java new file mode 100644 index 0000000..467e7df --- /dev/null +++ b/core/src/main/java/me/aurium/branch/execution/NodeContext.java @@ -0,0 +1,55 @@ +/* + * + * 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.interfacing.Response; +import me.aurium.branch.nodes.CommandNode; +import me.aurium.branch.nodes.results.SearchInfo; + + +/** + * Represents the in-context of an executed command -> Basically, all the important information gleaned from the execution of a command + * such as the sender, arguments as string, and all nodes involved. + * @param the sender + */ +public interface NodeContext { + + 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 + */ + void stringSender(String string); + + /** + * Sends a formatted response to a player coded to a key + * @param failure the response + */ + void response(Response failure); + + +} diff --git a/core/src/main/java/me/aurium/branch/execution/StringBlock.java b/core/src/main/java/me/aurium/branch/execution/StringBlock.java new file mode 100644 index 0000000..6bcb746 --- /dev/null +++ b/core/src/main/java/me/aurium/branch/execution/StringBlock.java @@ -0,0 +1,63 @@ +/* + * + * 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 new file mode 100644 index 0000000..ac450b6 --- /dev/null +++ b/core/src/main/java/me/aurium/branch/execution/api/BranchHandler.java @@ -0,0 +1,38 @@ +/* + * + * 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 new file mode 100644 index 0000000..5ec4c5f --- /dev/null +++ b/core/src/main/java/me/aurium/branch/execution/api/Execution.java @@ -0,0 +1,44 @@ +/* + * + * 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/execution/api/ExecutionHandler.java b/core/src/main/java/me/aurium/branch/execution/api/ExecutionHandler.java new file mode 100644 index 0000000..e4e2a1c --- /dev/null +++ b/core/src/main/java/me/aurium/branch/execution/api/ExecutionHandler.java @@ -0,0 +1,35 @@ +/* + * + * 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; + +/** + * Functional interface typically used in simple nodes that only need to do one action + * @param + */ +@FunctionalInterface +public interface ExecutionHandler { + + void handle(NodeContext context); + +} diff --git a/core/src/main/java/me/aurium/branch/execution/api/SuggestionHandler.java b/core/src/main/java/me/aurium/branch/execution/api/SuggestionHandler.java new file mode 100644 index 0000000..cac21fc --- /dev/null +++ b/core/src/main/java/me/aurium/branch/execution/api/SuggestionHandler.java @@ -0,0 +1,38 @@ +/* + * + * 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.Block; +import me.aurium.branch.execution.NodeContext; + +import java.util.List; + +/** + * Simple functional interface that returns a string + * @param sender + */ +@FunctionalInterface +public interface SuggestionHandler { + + List handle(NodeContext context); + +} diff --git a/core/src/main/java/me/aurium/branch/fallback/permissions/EmptyPermission.java b/core/src/main/java/me/aurium/branch/fallback/permissions/EmptyPermission.java new file mode 100644 index 0000000..01c9677 --- /dev/null +++ b/core/src/main/java/me/aurium/branch/fallback/permissions/EmptyPermission.java @@ -0,0 +1,39 @@ +/* + * + * 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.fallback.permissions; + +/** + * Represents a permission that is always true + * @param sender + */ +public class EmptyPermission implements Permission { + + @Override + public boolean attempt(T sender, String alias, String[] args) { + return true; + } + + @Override + public String failureIdentifiableName() { + return "None"; + } +} diff --git a/core/src/main/java/me/aurium/branch/fallback/permissions/Permission.java b/core/src/main/java/me/aurium/branch/fallback/permissions/Permission.java new file mode 100644 index 0000000..ab13801 --- /dev/null +++ b/core/src/main/java/me/aurium/branch/fallback/permissions/Permission.java @@ -0,0 +1,50 @@ +/* + * + * 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.fallback.permissions; + +import me.aurium.branch.execution.NodeContext; + +/** + * Represents the accessibility predicate of a command -> whether a command can be executed or not + */ +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 + */ + boolean attempt(T sender, String alias, String[] args); //because fuck you + + default boolean attempt(NodeContext nodeContext) { + return attempt(nodeContext.getSender(),nodeContext.getAlias(), nodeContext.getArgs()); + } + + /** + * Represents the name shown when the permission fails. + * @return the name shown if the permission fails, injected into a Result. + */ + String failureIdentifiableName(); + +} diff --git a/core/src/main/java/me/aurium/branch/fallback/permissions/PredicatePermission.java b/core/src/main/java/me/aurium/branch/fallback/permissions/PredicatePermission.java new file mode 100644 index 0000000..53c55b3 --- /dev/null +++ b/core/src/main/java/me/aurium/branch/fallback/permissions/PredicatePermission.java @@ -0,0 +1,49 @@ +/* + * + * 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.fallback.permissions; + +import java.util.function.Predicate; + +/** + * Permission that delegates to a predicate + * @param t + */ +public class PredicatePermission implements Permission { + + private final String easyName; + private final 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); + } + + @Override + public String failureIdentifiableName() { + return easyName; + } +} diff --git a/core/src/main/java/me/aurium/branch/fallback/strategies/FallbackSearchStrategy.java b/core/src/main/java/me/aurium/branch/fallback/strategies/FallbackSearchStrategy.java new file mode 100644 index 0000000..53898d0 --- /dev/null +++ b/core/src/main/java/me/aurium/branch/fallback/strategies/FallbackSearchStrategy.java @@ -0,0 +1,41 @@ +/* + * + * 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.fallback.strategies; + +import me.aurium.branch.nodes.CommandNode; +import me.aurium.branch.nodes.results.SearchInfo; +import me.aurium.branch.nodes.results.model.Result; + +/** + * A strategy to define + * - what happens if the user has no permission to execute a node + * - what happens if a node is inaccessible + * - what happens if a node is unusable + * @param + */ +public interface FallbackSearchStrategy { + + + Result> attemptPreprocess(T sender, String alias, String[] args, CommandNode baseNode); + + +} diff --git a/core/src/main/java/me/aurium/branch/fallback/strategies/OneBackStrategy.java b/core/src/main/java/me/aurium/branch/fallback/strategies/OneBackStrategy.java new file mode 100644 index 0000000..9f0e971 --- /dev/null +++ b/core/src/main/java/me/aurium/branch/fallback/strategies/OneBackStrategy.java @@ -0,0 +1,111 @@ +/* + * + * 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.fallback.strategies; + +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; + +/** + * + * /// 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: + * + * Attempts to get a node via arguments search. It then checks if the user has permission to access the node. + * If they do not, it falls back a single node and checks again. This repeats until the user has permission or + * until the search reaches the base node, in which case a response is fired as a failure. + * + * In practice: + * + * Node tree looks like + * + * /kitpvp moderation ban + * /kitpvp moderation kick + * + * User has permissions for kitpvp.moderation but not kitpvp.moderation.ban and tries to execute kitpvp moderation ban + * + * Searcher sees no permissions for ban command and so it falls back to the no-args of /kitpvp moderation which is + * then executed. + * + * @param + */ +public class OneBackStrategy implements FallbackSearchStrategy { + + @Override + public Result> attemptPreprocess(T sender, String alias, String[] args, CommandNode baseNode) { + + SearchInput input = SearchInput.of(args); + Result> toBeExecuted = baseNode.getSpecificNode(input); + + + //1. Check permissions and access (preprocessing) + + while (toBeExecuted.isSuccessful() && !toBeExecuted.getSuccess().resultingNode().getPermission().attempt(sender, alias, args)) { + //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())); + + } else { + toBeExecuted = baseNode.getSpecificNode(input.withoutTop()); //regress backwards a node + } + } + + return toBeExecuted; + } + + + + //TODO old code - refer to it if you need to + /*SearchInput input = SearchInput.of(args); + + SearchResult toBeExecuted = baseNode.getSpecificNode(input); + + Context failed = producer.produce(sender,alias,args); + + //1. Check permissions and access (preprocessing) + + while (!toBeExecuted.resultingNode().getPermission().attempt(sender, alias, args) || toBeExecuted.resultingNode().getExecutionHandler().getExecution().isEmpty()) { + //something is wrong with the execution (e.g. wrong args or you did something bad), pass above one. + + if (toBeExecuted.resultingNode().equals(baseNode)) { + + fallback.handle(failed); + + return Optional.empty(); + + } else { + toBeExecuted = baseNode.getSpecificNode(input.withoutTop()); //regress backwards a node + } + } + + return Optional.of(toBeExecuted); + + //execute and process + + NodeContext produced = producer.produce(sender,alias,args,toBeExecuted.resultingNode(), baseNode, toBeExecuted.reducedPath(), toBeExecuted.initialPath(), fallback); + + toBeExecuted.resultingNode().getExecutionHandler().getExecution().get().handle(produced);*/ +} diff --git a/core/src/main/java/me/aurium/branch/fallback/strategies/PermissionLockoutStrategy.java b/core/src/main/java/me/aurium/branch/fallback/strategies/PermissionLockoutStrategy.java new file mode 100644 index 0000000..0b67c80 --- /dev/null +++ b/core/src/main/java/me/aurium/branch/fallback/strategies/PermissionLockoutStrategy.java @@ -0,0 +1,48 @@ +/* + * + * 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.fallback.strategies; + +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; + +/** + * 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 { + @Override + public Result> attemptPreprocess(T sender, String alias, String[] args, CommandNode baseNode) { + + SearchInput input = SearchInput.of(args); + Result> toBeExecuted = baseNode.getSpecificNode(input); + + //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())); + } + + return toBeExecuted; + } +} diff --git a/core/src/main/java/me/aurium/branch/information/description/Description.java b/core/src/main/java/me/aurium/branch/information/description/Description.java new file mode 100644 index 0000000..f5904d9 --- /dev/null +++ b/core/src/main/java/me/aurium/branch/information/description/Description.java @@ -0,0 +1,28 @@ +/* + * + * 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.description; + +public interface Description { + + String getTextDescription(); + +} diff --git a/core/src/main/java/me/aurium/branch/information/description/StringDescription.java b/core/src/main/java/me/aurium/branch/information/description/StringDescription.java new file mode 100644 index 0000000..ae7d769 --- /dev/null +++ b/core/src/main/java/me/aurium/branch/information/description/StringDescription.java @@ -0,0 +1,14 @@ +package me.aurium.branch.information.description; + +public class StringDescription implements Description { + + private final String textDescription; + + public StringDescription(String textDescription) { + this.textDescription = textDescription; + } + + public String getTextDescription() { + return textDescription; + } +} 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 new file mode 100644 index 0000000..65cf9c9 --- /dev/null +++ b/core/src/main/java/me/aurium/branch/information/help/HelpEntry.java @@ -0,0 +1,25 @@ +/* + * + * 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 new file mode 100644 index 0000000..4ad9f20 --- /dev/null +++ b/core/src/main/java/me/aurium/branch/information/help/Shit.java @@ -0,0 +1,27 @@ +/* + * + * 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/Message.java b/core/src/main/java/me/aurium/branch/interfacing/Message.java new file mode 100644 index 0000000..11653ca --- /dev/null +++ b/core/src/main/java/me/aurium/branch/interfacing/Message.java @@ -0,0 +1,32 @@ +/* + * + * 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; + +/** + * Represents the final stage of something that occur after a response has been consumed + * @param t + */ +public interface Message { + + void accept(C sender); + +} diff --git a/core/src/main/java/me/aurium/branch/interfacing/Response.java b/core/src/main/java/me/aurium/branch/interfacing/Response.java new file mode 100644 index 0000000..ad1b88a --- /dev/null +++ b/core/src/main/java/me/aurium/branch/interfacing/Response.java @@ -0,0 +1,29 @@ +/* + * + * 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; + +/** + * Marker interface for a data-carrying object that can be consumed by a responseActionhandler + */ +public interface Response { + +} diff --git a/core/src/main/java/me/aurium/branch/interfacing/ResponseAction.java b/core/src/main/java/me/aurium/branch/interfacing/ResponseAction.java new file mode 100644 index 0000000..b6a0e8a --- /dev/null +++ b/core/src/main/java/me/aurium/branch/interfacing/ResponseAction.java @@ -0,0 +1,33 @@ +/* + * + * 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; + +/** + * Represents an action that is fired when a response is received + * @param t + * @param c + */ +public interface ResponseAction { + + Message consume(C response); + +} 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 new file mode 100644 index 0000000..f7cfc0c --- /dev/null +++ b/core/src/main/java/me/aurium/branch/interfacing/handlers/CommonInterfacingHandler.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 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 new file mode 100644 index 0000000..6316231 --- /dev/null +++ b/core/src/main/java/me/aurium/branch/interfacing/handlers/DelegatingDefaultMap.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 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/InnerMap.java b/core/src/main/java/me/aurium/branch/interfacing/handlers/InnerMap.java new file mode 100644 index 0000000..bd0e569 --- /dev/null +++ b/core/src/main/java/me/aurium/branch/interfacing/handlers/InnerMap.java @@ -0,0 +1,45 @@ +/* + * + * 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; + +import java.util.HashMap; +import java.util.Map; + +public class InnerMap implements MessageMap { + + private final Map,ResponseAction> map = new HashMap<>(); + + @Override + public InnerMap add(Class key, ResponseAction action) { + this.map.put(key,action); + + return this; + } + + @Override + public InterfacingHandler make() { + return new CommonInterfacingHandler<>(map); + } +} 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 new file mode 100644 index 0000000..b65c93f --- /dev/null +++ b/core/src/main/java/me/aurium/branch/interfacing/handlers/InterfacingHandler.java @@ -0,0 +1,36 @@ +/* + * + * 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 new file mode 100644 index 0000000..481f808 --- /dev/null +++ b/core/src/main/java/me/aurium/branch/interfacing/handlers/MessageMap.java @@ -0,0 +1,34 @@ +/* + * + * 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/FailedAdaptingResponse.java b/core/src/main/java/me/aurium/branch/interfacing/responses/FailedAdaptingResponse.java new file mode 100644 index 0000000..6bf9ddd --- /dev/null +++ b/core/src/main/java/me/aurium/branch/interfacing/responses/FailedAdaptingResponse.java @@ -0,0 +1,48 @@ +/* + * + * 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.interfacing.Response; + +/** + * 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 { + + private final Class expectedClass; + private final Class receivedClass; + + public FailedAdaptingResponse(Class expectedClass, Class receivedClass) { + this.expectedClass = expectedClass; + this.receivedClass = receivedClass; + } + + public Class getExpectedClass() { + return expectedClass; + } + + public Class getReceivedClass() { + return receivedClass; + } + +} 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 new file mode 100644 index 0000000..fe37378 --- /dev/null +++ b/core/src/main/java/me/aurium/branch/interfacing/responses/NoIntegratedArgsResponse.java @@ -0,0 +1,49 @@ +/* + * + * 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/interfacing/responses/NoPermissionResponse.java b/core/src/main/java/me/aurium/branch/interfacing/responses/NoPermissionResponse.java new file mode 100644 index 0000000..dc50a4f --- /dev/null +++ b/core/src/main/java/me/aurium/branch/interfacing/responses/NoPermissionResponse.java @@ -0,0 +1,37 @@ +/* + * + * 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.interfacing.Response; + +public class NoPermissionResponse implements Response { + + private final String lackingPermission; + + public NoPermissionResponse(String lackingPermission) { + this.lackingPermission = lackingPermission; + } + + public String getLackingPermission() { + return lackingPermission; + } +} diff --git a/core/src/main/java/me/aurium/branch/interfacing/responses/TooManyArgsResponse.java b/core/src/main/java/me/aurium/branch/interfacing/responses/TooManyArgsResponse.java new file mode 100644 index 0000000..12b79b8 --- /dev/null +++ b/core/src/main/java/me/aurium/branch/interfacing/responses/TooManyArgsResponse.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 me.aurium.branch.interfacing.responses; + +import me.aurium.branch.interfacing.Response; + +public class TooManyArgsResponse implements Response { + + private final int expectedArgs; + private final int suppliedArgs; + + public TooManyArgsResponse(int expectedArgs, int suppliedArgs) { + this.expectedArgs = expectedArgs; + this.suppliedArgs = suppliedArgs; + } + + public int getExpectedArgs() { + return expectedArgs; + } + + public int getSuppliedArgs() { + return suppliedArgs; + } +} diff --git a/core/src/main/java/me/aurium/branch/nodes/Builder.java b/core/src/main/java/me/aurium/branch/nodes/Builder.java new file mode 100644 index 0000000..92f4a21 --- /dev/null +++ b/core/src/main/java/me/aurium/branch/nodes/Builder.java @@ -0,0 +1,29 @@ +/* + * + * 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 new file mode 100644 index 0000000..f02b322 --- /dev/null +++ b/core/src/main/java/me/aurium/branch/nodes/CommandNode.java @@ -0,0 +1,50 @@ +/* + * + * 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/IdentifiableNode.java b/core/src/main/java/me/aurium/branch/nodes/IdentifiableNode.java new file mode 100644 index 0000000..f454cab --- /dev/null +++ b/core/src/main/java/me/aurium/branch/nodes/IdentifiableNode.java @@ -0,0 +1,32 @@ +/* + * + * 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.Block; +import me.aurium.branch.information.description.Description; + +public interface IdentifiableNode extends CommandNode { + + Block getIdentifier(); + + +} diff --git a/core/src/main/java/me/aurium/branch/nodes/ProxyNode.java b/core/src/main/java/me/aurium/branch/nodes/ProxyNode.java new file mode 100644 index 0000000..565307d --- /dev/null +++ b/core/src/main/java/me/aurium/branch/nodes/ProxyNode.java @@ -0,0 +1,7 @@ +package me.aurium.branch.nodes; + +/** + * Represents a node that can dynamically convert a specified ProxyInterface into arguments + */ +public class ProxyNode { +} diff --git a/core/src/main/java/me/aurium/branch/nodes/ResponseHandler.java b/core/src/main/java/me/aurium/branch/nodes/ResponseHandler.java new file mode 100644 index 0000000..561b9f7 --- /dev/null +++ b/core/src/main/java/me/aurium/branch/nodes/ResponseHandler.java @@ -0,0 +1,25 @@ +/* + * + * 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 class ResponseHandler { +} 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 new file mode 100644 index 0000000..24b2cdd --- /dev/null +++ b/core/src/main/java/me/aurium/branch/nodes/argument/ArgNode.java @@ -0,0 +1,74 @@ +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 new file mode 100644 index 0000000..a44e3db --- /dev/null +++ b/core/src/main/java/me/aurium/branch/nodes/argument/ArgumentContext.java @@ -0,0 +1,30 @@ +/* + * + * 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/ArgumentContextHandler.java b/core/src/main/java/me/aurium/branch/nodes/argument/ArgumentContextHandler.java new file mode 100644 index 0000000..f51351c --- /dev/null +++ b/core/src/main/java/me/aurium/branch/nodes/argument/ArgumentContextHandler.java @@ -0,0 +1,28 @@ +/* + * + * 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 ArgumentContextHandler { + + void handle(ArgumentContext context); + +} 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 new file mode 100644 index 0000000..0c944e6 --- /dev/null +++ b/core/src/main/java/me/aurium/branch/nodes/argument/ArgumentConverter.java @@ -0,0 +1,25 @@ +/* + * + * 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 new file mode 100644 index 0000000..290b736 --- /dev/null +++ b/core/src/main/java/me/aurium/branch/nodes/argument/ArgumentNode.java @@ -0,0 +1,101 @@ +/* + * + * 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 new file mode 100644 index 0000000..47d9327 --- /dev/null +++ b/core/src/main/java/me/aurium/branch/nodes/argument/Arguments.java @@ -0,0 +1,25 @@ +/* + * + * 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 new file mode 100644 index 0000000..9665d8b --- /dev/null +++ b/core/src/main/java/me/aurium/branch/nodes/argument/types/Argument.java @@ -0,0 +1,56 @@ +/* + * + * 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 new file mode 100644 index 0000000..8ea5b75 --- /dev/null +++ b/core/src/main/java/me/aurium/branch/nodes/argument/types/UncalculatingArgument.java @@ -0,0 +1,4 @@ +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 new file mode 100644 index 0000000..c9cde4b --- /dev/null +++ b/core/src/main/java/me/aurium/branch/nodes/branching/BranchingNode.java @@ -0,0 +1,134 @@ +/* + * + * 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 new file mode 100644 index 0000000..5f4cb7a --- /dev/null +++ b/core/src/main/java/me/aurium/branch/nodes/branching/ExclusiveBranchingBuilder.java @@ -0,0 +1,80 @@ +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 new file mode 100644 index 0000000..89ac489 --- /dev/null +++ b/core/src/main/java/me/aurium/branch/nodes/branching/ExclusivePrestoredSet.java @@ -0,0 +1,27 @@ +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 new file mode 100644 index 0000000..4700a4f --- /dev/null +++ b/core/src/main/java/me/aurium/branch/nodes/branching/InclusiveBranchingBuilder.java @@ -0,0 +1,102 @@ +/* + * + * 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 new file mode 100644 index 0000000..cadde13 --- /dev/null +++ b/core/src/main/java/me/aurium/branch/nodes/branching/InclusivePrestoredSet.java @@ -0,0 +1,31 @@ +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 new file mode 100644 index 0000000..bc164f2 --- /dev/null +++ b/core/src/main/java/me/aurium/branch/nodes/branching/PrestoredSet.java @@ -0,0 +1,13 @@ +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 new file mode 100644 index 0000000..abd6061 --- /dev/null +++ b/core/src/main/java/me/aurium/branch/nodes/results/SearchInfo.java @@ -0,0 +1,59 @@ +/* + * + * 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 new file mode 100644 index 0000000..d44ea2d --- /dev/null +++ b/core/src/main/java/me/aurium/branch/nodes/results/SearchInput.java @@ -0,0 +1,66 @@ +/* + * + * 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/results/model/FailingResult.java b/core/src/main/java/me/aurium/branch/nodes/results/model/FailingResult.java new file mode 100644 index 0000000..0a21da9 --- /dev/null +++ b/core/src/main/java/me/aurium/branch/nodes/results/model/FailingResult.java @@ -0,0 +1,53 @@ +/* + * + * 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.model; + +import me.aurium.branch.interfacing.Response; + +/** + * A result that has failed + * @param the response + */ +public class FailingResult implements Result { + + private final Response failure; + + public FailingResult(Response failure) { + this.failure = failure; + } + + @Override + public boolean isSuccessful() { + return false; + } + + @Override + public T getSuccess() { + throw new IllegalStateException("Attempted to get success of a failing result! (e.g. was not checked)"); + } + + @Override + public Response getFailure() { + return failure; + } + +} diff --git a/core/src/main/java/me/aurium/branch/nodes/results/model/Result.java b/core/src/main/java/me/aurium/branch/nodes/results/model/Result.java new file mode 100644 index 0000000..8653301 --- /dev/null +++ b/core/src/main/java/me/aurium/branch/nodes/results/model/Result.java @@ -0,0 +1,41 @@ +/* + * + * 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.model; + +import me.aurium.branch.interfacing.Response; + +public interface Result { + + boolean isSuccessful(); + + T getSuccess(); + + Response getFailure(); + + static Result success(X t) { + return new SuccessfulResult<>(t); + } + static Result fail(Response failure) { + return new FailingResult<>(failure); + } + +} diff --git a/core/src/main/java/me/aurium/branch/nodes/results/model/SuccessfulResult.java b/core/src/main/java/me/aurium/branch/nodes/results/model/SuccessfulResult.java new file mode 100644 index 0000000..25174f2 --- /dev/null +++ b/core/src/main/java/me/aurium/branch/nodes/results/model/SuccessfulResult.java @@ -0,0 +1,48 @@ +/* + * + * 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.model; + +import me.aurium.branch.interfacing.Response; + +public class SuccessfulResult implements Result { + + private final T sucessful; + + public SuccessfulResult(T sucessful) { + this.sucessful = sucessful; + } + + @Override + public boolean isSuccessful() { + return true; + } + + @Override + public T getSuccess() { + return sucessful; + } + + @Override + public Response getFailure() { + throw new IllegalStateException("Attempted to get failure of a successful result!"); + } +} diff --git a/core/src/main/java/me/aurium/branch/nodes/single/EndpointNode.java b/core/src/main/java/me/aurium/branch/nodes/single/EndpointNode.java new file mode 100644 index 0000000..5a08eff --- /dev/null +++ b/core/src/main/java/me/aurium/branch/nodes/single/EndpointNode.java @@ -0,0 +1,39 @@ +/* + * + * 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.nodes.IdentifiableNode; +import me.aurium.branch.nodes.results.SearchInfo; +import me.aurium.branch.nodes.results.SearchInput; +import me.aurium.branch.nodes.results.model.Result; + +/** + * 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 { + + @Override + public final Result> getSpecificNode(SearchInput input) { + return Result.success(new SearchInfo<>(this,input)); + } + +} 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 new file mode 100644 index 0000000..0b402b0 --- /dev/null +++ b/core/src/main/java/me/aurium/branch/nodes/single/HelpNode.java @@ -0,0 +1,54 @@ +/* + * + * 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 new file mode 100644 index 0000000..1f8af5b --- /dev/null +++ b/core/src/main/java/me/aurium/branch/nodes/single/SingleBuilder.java @@ -0,0 +1,72 @@ +/* + * + * 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 new file mode 100644 index 0000000..67ff1be --- /dev/null +++ b/core/src/main/java/me/aurium/branch/nodes/single/SingleNode.java @@ -0,0 +1,106 @@ +/* + * + * 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 new file mode 100644 index 0000000..e69de29 diff --git a/docs/README.md b/docs/README.md new file mode 100644 index 0000000..a4d69e6 --- /dev/null +++ b/docs/README.md @@ -0,0 +1,35 @@ +# 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 new file mode 100644 index 0000000..fa401c7 --- /dev/null +++ b/docs/_coverpage.md @@ -0,0 +1,13 @@ +![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 new file mode 100644 index 0000000..98fcd8b --- /dev/null +++ b/docs/_sidebar.md @@ -0,0 +1,32 @@ +- 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 new file mode 100644 index 0000000..de14ede --- /dev/null +++ b/docs/index.html @@ -0,0 +1,27 @@ + + + + + Branch Framework + + + + + + + +
+ + + + + diff --git a/docs/media/branch.png b/docs/media/branch.png new file mode 100644 index 0000000..f97d1f0 Binary files /dev/null and b/docs/media/branch.png differ diff --git a/pom.xml b/pom.xml index 630011f..31d7368 100644 --- a/pom.xml +++ b/pom.xml @@ -1,4 +1,25 @@ + + @@ -7,19 +28,40 @@ branch pom 0.1.0 - - core - - beetle me.aurium - 0.2.0 + insect + 0.2.1 + + core + core-tests + spigot-impl + + ${compiler.version} ${compiler.version} + + + + branch-core + me.aurium + ${project.version} + + + + + + + jfrog + a0phrw82hnl4g-artifactory-primary-0-releases + https://aurium.jfrog.io/artifactory/aurium-libs-release-local + + + \ No newline at end of file diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..d6bc020 --- /dev/null +++ b/readme.md @@ -0,0 +1,35 @@ +# 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 **Auriium#0001** 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/spigot-impl/pom.xml b/spigot-impl/pom.xml new file mode 100644 index 0000000..a4e66d9 --- /dev/null +++ b/spigot-impl/pom.xml @@ -0,0 +1,65 @@ + + + + + + branch + me.aurium + 0.1.0 + + 4.0.0 + + spigot-impl + + + ${compiler.version} + ${compiler.version} + + + + + me.aurium + branch-core + + + com.destroystokyo.paper + paper-api + 1.16.5-R0.1-SNAPSHOT + provided + + + org.spigotmc + spigot-api + 1.16.5-R0.1-SNAPSHOT + + + + + + papermc + https://papermc.io/repo/repository/maven-public/ + + + + \ No newline at end of file diff --git a/spigot-impl/src/main/java/me/aurium/branch/spigot/CommandWrapper.java b/spigot-impl/src/main/java/me/aurium/branch/spigot/CommandWrapper.java new file mode 100644 index 0000000..a30ae1e --- /dev/null +++ b/spigot-impl/src/main/java/me/aurium/branch/spigot/CommandWrapper.java @@ -0,0 +1,51 @@ +/* + * + * 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.centralized.base.NodeBase; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.jetbrains.annotations.NotNull; + +import java.util.List; + +public class CommandWrapper extends Command { + + private final NodeBase base; + + public CommandWrapper(NodeBase base) { + super(base.getIdentifier(),base.getDescription().getTextDescription(), base.getDescription().getTextDescription(), base.getAliases()); + this.base = base; + } + + @Override + public boolean execute(@NotNull CommandSender commandSender, @NotNull 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 { + return base.suggest(sender, alias, args); + } +} 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 new file mode 100644 index 0000000..b1eb1c2 --- /dev/null +++ b/spigot-impl/src/main/java/me/aurium/branch/spigot/SpigotContext.java @@ -0,0 +1,54 @@ +/* + * + * 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/SpigotContextProvider.java b/spigot-impl/src/main/java/me/aurium/branch/spigot/SpigotContextProvider.java new file mode 100644 index 0000000..6080886 --- /dev/null +++ b/spigot-impl/src/main/java/me/aurium/branch/spigot/SpigotContextProvider.java @@ -0,0 +1,44 @@ +/* + * + * 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.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 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); + } +} diff --git a/spigot-impl/src/main/java/me/aurium/branch/spigot/SpigotManager.java b/spigot-impl/src/main/java/me/aurium/branch/spigot/SpigotManager.java new file mode 100644 index 0000000..a6629e9 --- /dev/null +++ b/spigot-impl/src/main/java/me/aurium/branch/spigot/SpigotManager.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 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; +import org.bukkit.command.CommandSender; +import org.bukkit.plugin.java.JavaPlugin; + +import java.util.HashSet; +import java.util.Set; + +public class SpigotManager implements CentralizedManager { + + private final static SenderAdapter defaultAdapter = new SenderAdapter(); + + private final InterfacingHandler defaultInterfacing; + private final Set> senders = new HashSet<>(); + + //fuck code in the constructor rules + // (This can be easily fixed if you give a shit but i happen to not care - make a pr if you do!) + + public SpigotManager(MessageMap defaultResponser) { + this.defaultInterfacing = defaultResponser.make(); + } + + public SpigotManager() { + this.defaultInterfacing = new SpigotMessageMap<>().make(); + } + + @Override + public CentralizedManagerBinder getBinder(JavaPlugin platform) { + return new SpigotManagerBinder(platform.getName(), platform.getServer().getCommandMap(), senders); + } + + @Override + public NodeSource getSource() { + return null; + } + + @Override + public NodeBaseBuilder newCommand() { + return new NodeBaseBuilder<>(this, defaultAdapter, new OneBackStrategy<>(), new SpigotContextProvider<>(defaultInterfacing), defaultInterfacing); + } + + @Override + public NodeBaseBuilder newCommand(ManagerAdapter adapter) { + return new NodeBaseBuilder<>(this,adapter, new OneBackStrategy<>(), new SpigotContextProvider<>(defaultInterfacing), defaultInterfacing); + } + + @Override + public void injectCommand(NodeBase base) { + senders.add(base); + } + +} diff --git a/spigot-impl/src/main/java/me/aurium/branch/spigot/SpigotManagerBinder.java b/spigot-impl/src/main/java/me/aurium/branch/spigot/SpigotManagerBinder.java new file mode 100644 index 0000000..0b69afb --- /dev/null +++ b/spigot-impl/src/main/java/me/aurium/branch/spigot/SpigotManagerBinder.java @@ -0,0 +1,49 @@ +/* + * + * 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.centralized.CentralizedManagerBinder; +import me.aurium.branch.centralized.base.NodeBase; +import org.bukkit.command.CommandMap; +import org.bukkit.command.CommandSender; + +import java.util.Set; + +public class SpigotManagerBinder implements CentralizedManagerBinder { + + private final String pluginName; + private final CommandMap map; + private final Set> senders; + + public SpigotManagerBinder(String pluginName, CommandMap map, Set> senders) { + this.pluginName = pluginName; + this.map = map; + this.senders = senders; + } + + @Override + public void bind() { //TODO implement + for (NodeBase node : senders) { + map.register(pluginName,new CommandWrapper(node)); + } + } +} diff --git a/spigot-impl/src/main/java/me/aurium/branch/spigot/adapter/PlayerAdapter.java b/spigot-impl/src/main/java/me/aurium/branch/spigot/adapter/PlayerAdapter.java new file mode 100644 index 0000000..ce98e38 --- /dev/null +++ b/spigot-impl/src/main/java/me/aurium/branch/spigot/adapter/PlayerAdapter.java @@ -0,0 +1,51 @@ +/* + * + * 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.adapter; + +import me.aurium.branch.interfacing.responses.FailedAdaptingResponse; +import me.aurium.branch.centralized.typeadapter.ManagerAdapter; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class PlayerAdapter implements ManagerAdapter { + + public static PlayerAdapter INSTANCE = new PlayerAdapter(); + + PlayerAdapter(){} + + @Override + public Player adapt(CommandSender sender) { + return (Player) sender; + } + + @Override + public boolean canAdapt(CommandSender sender) { + return sender instanceof Player; + } + + @Override + public FailedAdaptingResponse failedParseResponse(CommandSender sender) { + return new FailedAdaptingResponse(Player.class, CommandSender.class); + } + + +} diff --git a/spigot-impl/src/main/java/me/aurium/branch/spigot/adapter/SenderAdapter.java b/spigot-impl/src/main/java/me/aurium/branch/spigot/adapter/SenderAdapter.java new file mode 100644 index 0000000..aeb67fd --- /dev/null +++ b/spigot-impl/src/main/java/me/aurium/branch/spigot/adapter/SenderAdapter.java @@ -0,0 +1,28 @@ +/* + * + * 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.adapter; + +import me.aurium.branch.centralized.typeadapter.CommonAdapter; +import org.bukkit.command.CommandSender; + +public class SenderAdapter implements CommonAdapter { +} diff --git a/spigot-impl/src/main/java/me/aurium/branch/spigot/message/FormattedMessage.java b/spigot-impl/src/main/java/me/aurium/branch/spigot/message/FormattedMessage.java new file mode 100644 index 0000000..fad79d9 --- /dev/null +++ b/spigot-impl/src/main/java/me/aurium/branch/spigot/message/FormattedMessage.java @@ -0,0 +1,37 @@ +/* + * + * 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.command.CommandSender; + +public abstract class FormattedMessage implements Message { + + //TODO private final Formatter formatter; + + protected abstract void accept(C sender, String postFormatted); + + @Override + public void accept(C sender) { + + } +} 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 new file mode 100644 index 0000000..bff08f2 --- /dev/null +++ b/spigot-impl/src/main/java/me/aurium/branch/spigot/message/SpigotMessageMap.java @@ -0,0 +1,52 @@ +/* + * + * 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 new file mode 100644 index 0000000..846e202 --- /dev/null +++ b/spigot-impl/src/main/java/me/aurium/branch/spigot/message/TextMessage.java @@ -0,0 +1,44 @@ +/* + * + * 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)); + } + + } +} diff --git a/spigot-impl/src/main/java/me/aurium/branch/spigot/permisison/SpigotPermission.java b/spigot-impl/src/main/java/me/aurium/branch/spigot/permisison/SpigotPermission.java new file mode 100644 index 0000000..e23d7b4 --- /dev/null +++ b/spigot-impl/src/main/java/me/aurium/branch/spigot/permisison/SpigotPermission.java @@ -0,0 +1,23 @@ +package me.aurium.branch.spigot.permisison; + +import me.aurium.branch.fallback.permissions.Permission; +import org.bukkit.command.CommandSender; + +public class SpigotPermission implements Permission { + + private final String permission; + + public SpigotPermission(String permission) { + this.permission = permission; + } + + @Override + public boolean attempt(CommandSender sender, String alias, String[] args) { + return sender.hasPermission(permission); + } + + @Override + public String failureIdentifiableName() { + return "'" + permission + "'"; + } +} diff --git a/spigot-impl/src/test/java/me/aurium/branch/spigot/ExampleBinding.java b/spigot-impl/src/test/java/me/aurium/branch/spigot/ExampleBinding.java new file mode 100644 index 0000000..5f755a6 --- /dev/null +++ b/spigot-impl/src/test/java/me/aurium/branch/spigot/ExampleBinding.java @@ -0,0 +1,34 @@ +/* + * + * 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 org.bukkit.plugin.java.JavaPlugin; + +public class ExampleBinding extends JavaPlugin { + + @Override + public void onEnable() { + + + + } +} diff --git a/spigot-impl/src/test/resources/plugin.yml b/spigot-impl/src/test/resources/plugin.yml new file mode 100644 index 0000000..e69de29