Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions branch-adventure/branch-adventure.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_11">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module" module-name="branch-core" />
<orderEntry type="library" name="Maven: net.kyori:adventure-api:4.8.1" level="project" />
<orderEntry type="library" name="Maven: net.kyori:adventure-key:4.8.1" level="project" />
<orderEntry type="library" name="Maven: net.kyori:examination-api:1.1.0" level="project" />
<orderEntry type="library" name="Maven: org.checkerframework:checker-qual:3.10.0" level="project" />
<orderEntry type="library" name="Maven: net.kyori:examination-string:1.1.0" level="project" />
<orderEntry type="library" name="Maven: org.jetbrains:annotations:21.0.1" level="project" />
<orderEntry type="library" name="Maven: net.kyori:adventure-text-serializer-legacy:4.8.1" level="project" />
</component>
</module>
36 changes: 36 additions & 0 deletions branch-adventure/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>branch</artifactId>
<groupId>xyz.auriium</groupId>
<version>0.1.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>branch-spigot-adventure</artifactId>

<properties>
<maven.compiler.source>${compiler.version}</maven.compiler.source>
<maven.compiler.target>${compiler.version}</maven.compiler.target>
</properties>

<dependencies>
<dependency>
<groupId>xyz.auriium</groupId>
<artifactId>branch-core</artifactId>
</dependency>
<dependency>
<groupId>net.kyori</groupId>
<artifactId>adventure-api</artifactId>
<version>4.8.1</version>
</dependency>
<dependency>
<groupId>net.kyori</groupId>
<artifactId>adventure-text-serializer-legacy</artifactId> <!-- todo !-->
<version>4.8.1</version>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package xyz.auriium.branch.adventure;

import net.kyori.adventure.text.Component;
import xyz.auriium.branch.interfacing.MessageWorker;
import xyz.auriium.branch.interfacing.WorkerMessageBoss;

public class AdventureMessageBoss<I,A> extends WorkerMessageBoss<I,A,Component> {

public AdventureMessageBoss(AudienceTransmogrifier<I> iTransmogrifier, AudienceTransmogrifier<A> aTransmogrifier) {
super(new AdventureMessageWorker<>(iTransmogrifier), new AdventureMessageWorker<>(aTransmogrifier));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package xyz.auriium.branch.adventure;

import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import xyz.auriium.branch.interfacing.MessageWorker;

public class AdventureMessageWorker<T> implements MessageWorker<T, Component> {

private final AudienceTransmogrifier<T> transmogrifier;

public AdventureMessageWorker(AudienceTransmogrifier<T> transmogrifier) {
this.transmogrifier = transmogrifier;
}

@Override
public void sendMessage(String message, T type) {
transmogrifier.transmogrify(type).sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(message));
}

@Override
public void sendObject(Component message, T type) {
transmogrifier.transmogrify(type).sendMessage(message);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package xyz.auriium.branch.adventure;

import net.kyori.adventure.audience.Audience;

/**
* I am not one to be outdone with names
*/
public interface AudienceTransmogrifier<A> {

Audience transmogrify(A user);

}
22 changes: 19 additions & 3 deletions core/pom.xml → branch-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>branch</artifactId>
<groupId>me.aurium</groupId>
<groupId>xyz.auriium</groupId>
<version>0.1.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand All @@ -37,6 +37,24 @@
<maven.compiler.target>${compiler.version}</maven.compiler.target>
</properties>

<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
Expand All @@ -51,6 +69,4 @@
</build>




</project>
26 changes: 26 additions & 0 deletions branch-core/src/main/java/module-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
module branch.core {
exports xyz.auriium.branch;
exports xyz.auriium.branch.base;
exports xyz.auriium.branch.base.execution;
exports xyz.auriium.branch.base.execution.blocks;
exports xyz.auriium.branch.base.permissions;
exports xyz.auriium.branch.base.suggestion;
exports xyz.auriium.branch.nodes;
exports xyz.auriium.branch.nodes.argument;
exports xyz.auriium.branch.nodes.argument.model;
exports xyz.auriium.branch.nodes.argument.impl;
exports xyz.auriium.branch.nodes.argument.types;
exports xyz.auriium.branch.results;
exports xyz.auriium.branch.nodes.branching;
exports xyz.auriium.branch.nodes.description;
exports xyz.auriium.branch.nodes.single;
exports xyz.auriium.branch.nodes.single.impl;
exports xyz.auriium.branch.nodes.help;
exports xyz.auriium.branch.nodes.proxy;
exports xyz.auriium.branch.interfacing;
exports xyz.auriium.branch.interfacing.exceptional;
exports xyz.auriium.branch.interfacing.exceptional.anomalies;
exports xyz.auriium.branch.interfacing.exceptional.caption;
exports xyz.auriium.branch.interfacing.exceptional.printing;
exports xyz.auriium.branch.typeadapter;
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@
*
*/

package me.aurium.branch.centralized;
package xyz.auriium.branch;

import me.aurium.branch.centralized.base.NodeBase;
import me.aurium.branch.centralized.base.NodeBaseBuilder;
import me.aurium.branch.centralized.typeadapter.ManagerAdapter;
import xyz.auriium.branch.base.NodeBase;
import xyz.auriium.branch.base.NodeBaseBuilder;
import xyz.auriium.branch.typeadapter.ManagerAdapter;
import xyz.auriium.branch.nodes.CommandNode;

/**
* Represents the utmost base part of the command framework which has the ability to bind any injected commands to a platform
Expand All @@ -35,10 +36,13 @@ public interface CentralizedManager<T,V> {
CentralizedManagerBinder getBinder(V platform);
NodeSource<T> getSource();

NodeBaseBuilder<T,T> newCommand();
<C extends T> NodeBaseBuilder<T,C> newCommand(ManagerAdapter<T,C> adapter);
NodeBaseBuilder<T,T> newCommandWithBuilder();
<C extends T> NodeBaseBuilder<T,C> newCommandWithBuilder(ManagerAdapter<T,C> adapter);

void injectCommand(NodeBase<T> base);
void newCommandWithNode(CommandNode<T> node);
<C extends T> void newCommandWithNode(CommandNode<T> node, ManagerAdapter<T,C> adapter);

void newCommand(NodeBase<T> base);


}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*
*/

package me.aurium.branch.centralized;
package xyz.auriium.branch;

/**
* Represents a carrier vessel which is typically attached to the instance of a centralizedManagerBinder's platform
Expand Down
20 changes: 20 additions & 0 deletions branch-core/src/main/java/xyz/auriium/branch/NodeSource.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package xyz.auriium.branch;

import xyz.auriium.branch.base.execution.ExecutionHandler;
import xyz.auriium.branch.base.permissions.Permission;
import xyz.auriium.branch.nodes.description.Description;
import xyz.auriium.branch.nodes.branching.BranchingBuilder;
import xyz.auriium.branch.nodes.single.SingleNode;
import xyz.auriium.branch.nodes.single.SingleNodeBuilder;

public interface NodeSource<T> {

SingleNodeBuilder<T> single();
BranchingBuilder<T> branch();
//TODO argument


SingleNode<T> singleNode(String literal, ExecutionHandler<T> handler);
SingleNode<T> singleNode(String literal, ExecutionHandler<T> handler, Permission<T> permission, Description description);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
/*
*
* Branch
* Copyright © 2021 Aurium
*
* Branch is free software: you can redistribute it and/or modify
* It under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* Branch is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Branch. If not, see <https://www.gnu.org/licenses/>
* and navigate to version 3 of the GNU Affero General Public License.
*
*/

package xyz.auriium.branch.base;

import xyz.auriium.branch.base.suggestion.Suggestion;
import xyz.auriium.branch.base.suggestion.SuggestionSearchStrategy;
import xyz.auriium.branch.typeadapter.ManagerAdapter;
import xyz.auriium.branch.base.execution.Execution;
import xyz.auriium.branch.base.execution.ExecutionSearchStrategy;
import xyz.auriium.branch.interfacing.exceptional.AnomalyHandler;
import xyz.auriium.branch.nodes.CommandNode;
import xyz.auriium.branch.results.PreProcessSearch;
import xyz.auriium.branch.results.SearcherEquality;
import xyz.auriium.branch.results.Result;

import java.util.ArrayList;
import java.util.List;

/**
* Represents a node base that has the ability to convert it's input sender to a sender of type C or fail with a result.
* @param <I> the input type of nodebase
* @param <A> the adjusted type desired by the output of the {@link ManagerAdapter} found in this nodebase
*/
public abstract class AbstractNodeBase<I, A extends I> implements NodeBase<I> {

private final ManagerAdapter<I, A> adapter;
private final AnomalyHandler<I, A> handler;

private final CommandNode<A> baseNode;
private final ExecutionSearchStrategy<A> executionStrategy;
private final SuggestionSearchStrategy<A> suggestionStrategy;
private final ContextProvider<A> provider;
private final SearcherEquality equality;

private final static List<String> EMPTY = new ArrayList<>();

protected AbstractNodeBase(ManagerAdapter<I, A> adapter, AnomalyHandler<I, A> handler, CommandNode<A> baseNode, ExecutionSearchStrategy<A> executionStrategy, SuggestionSearchStrategy<A> suggestionStrategy, ContextProvider<A> provider, SearcherEquality equality) {
this.adapter = adapter;
this.handler = handler;
this.baseNode = baseNode;
this.executionStrategy = executionStrategy;
this.suggestionStrategy = suggestionStrategy;
this.provider = provider;
this.equality = equality;
}


/**
* Method for execution of runnable once runnable is found
* Exists in order to allow for concurrent-type nodebases
*
* @param execution the runnable
*/
abstract void submitExecution(Execution<A> execution);

public void execute(I input, String alias, String[] args) {
//have not aqcuired C-type (cannot use Result object or message handling-parsing)

if (!adapter.canAdapt(input)) {
handler.communicateNotAdapted(input, adapter.failedParseResponse(input));

return;
}

//have acquired C-type via parsing.

A adaptedSender = adapter.adapt(input);
NodeContext<A> produced = provider.produce(adaptedSender, alias, args);

Result<PreProcessSearch<A>> preprocessResult = executionStrategy.attemptPreprocess(produced, equality, baseNode);

if (!preprocessResult.isSuccessful()) {
handler.communicateAdapted(adaptedSender, preprocessResult.getFailure());

return;
}

PreProcessSearch<A> info = preprocessResult.getSuccess();

Result<Execution<A>> executionResult = info.getFoundNode().searchExecute(produced, info);

if (!executionResult.isSuccessful()) {
handler.communicateAdapted(adaptedSender, preprocessResult.getFailure());

return;
}

submitExecution(executionResult.getSuccess());
}

public List<String> suggest(I input, String alias, String[] args) {

if (!adapter.canAdapt(input)) {
handler.communicateNotAdapted(input, adapter.failedParseResponse(input));

return EMPTY;
}

//have acquired C-type via parsing.

A adaptedSender = adapter.adapt(input);
NodeContext<A> produced = provider.produce(adaptedSender, alias, args);

Result<PreProcessSearch<A>> preprocessResult = executionStrategy.attemptPreprocess(produced, equality, baseNode);

if (!preprocessResult.isSuccessful()) {
handler.communicateAdapted(adaptedSender, preprocessResult.getFailure());

return EMPTY;
}

PreProcessSearch<A> info = preprocessResult.getSuccess();

var searchResult = info.getFoundNode().searchSuggestion(produced, info);

if (!searchResult.isSuccessful()) {
handler.communicateAdapted(adaptedSender, searchResult.getFailure());

return EMPTY;
}

List<Suggestion<A>> suggestions = searchResult.getSuccess();

return suggestionStrategy.order(suggestions,produced);
}



}
Loading