Skip to content

Commit

Permalink
Merge pull request #34 from JuliGames/development
Browse files Browse the repository at this point in the history
Version 1.6 brings the following major changes to the Core:

- security notice in APIs pom
- TODO#doNotcall defaults to false now
- option to get all configs as a collection
- new: EnumInterpreter
- API now has a lot of javadoc
- new: PrimitiveInterpreter
- new: Reverser
- new: Representation
- new: Interpretation
- added support for the AdventureWebUi
- new: APIUtils
- optimized DurationFormatUtilitis
- new: ThrowingRunnable
- new: MessageRepresentation
- new: IndexBackedInterpreterProvider
- new: IndexBackedInterpreterProviderBuilder
- a lot of new Prompts for Adventure
- new: PaperConversationManager - this opens support for ConversationLib! Currently, this has some issues and should not be used on production instances!
- new: Automatic Config Mapping
- a lot of prompts for paper
- new: SUPERCORE
- new: VelocityConversationManager - this extends support for ConversationLib to Velocity

Additionally, I need to announce that JuliGames may no longer pursue the development of the piece of software at the pace we had before. The person who is in charge of keeping the people behind this project united decided to stop all communication with the team for a while now. We cant provide any details about the health of the maven repo or other services that are maintained by the Juligames Development and Administration Team. I hope this gets resolved and innovation and development can continue as normal.
  • Loading branch information
TureBentzin authored Jun 19, 2023
2 parents 2873eea + 140993d commit decf81a
Show file tree
Hide file tree
Showing 104 changed files with 4,193 additions and 239 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,4 @@ latest.log.lck
config/messageSystem.properties=
Core/src/main/java/net/juligames/core/Test.java
config/messageSystem.properties
VelocityCore/src/main/java/test/ConversationTest.java
19 changes: 19 additions & 0 deletions .run/CoreMaster.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="CoreMaster" type="Application" factoryName="Application"
nameIsGenerated="true">
<option name="MAIN_CLASS_NAME" value="net.juligames.core.master.CoreMaster"/>
<module name="Master"/>
<option name="PROGRAM_PARAMETERS"
value="--add-modules java.se --add-exports java.base/jdk.internal.ref=ALL-UNNAMED --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/sun.nio.ch=ALL-UNNAMED --add-opens java.management/sun.management=ALL-UNNAMED --add-opens jdk.management/com.sun.management.internal=ALL-UNNAMED"/>
<option name="VM_PARAMETERS" value="-Dhazelcast.diagnostics.enabled=true -DcoreDebug=true "/>
<extension name="coverage">
<pattern>
<option name="PATTERN" value="net.juligames.core.master.*"/>
<option name="ENABLED" value="true"/>
</pattern>
</extension>
<method v="2">
<option name="Make" enabled="true"/>
</method>
</configuration>
</component>
8 changes: 7 additions & 1 deletion API/pom.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--suppress VulnerableLibrariesLocal -->
<!--
Security Note:
Please report any issues related to dependencies used in this project immediately to GitHub:
github.com/JuliGames/JuliGamesCore/issues.
For any other inquiries or concerns, please email the development team at [email protected]
-->
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>JuliGamesCore</artifactId>
<groupId>net.juligames.core</groupId>
<version>1.5</version>
<version>1.6</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
14 changes: 13 additions & 1 deletion API/src/main/java/net/juligames/core/api/API.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.juligames.core.api;

import de.bentzin.tools.logging.Logger;
import de.bentzin.tools.logging.Logging;
import de.bentzin.tools.misc.SubscribableType;
import net.juligames.core.api.cacheing.CacheApi;
import net.juligames.core.api.cluster.ClusterApi;
Expand All @@ -22,13 +23,14 @@
import java.util.Optional;
import java.util.function.Predicate;
import java.util.function.Supplier;
import java.util.logging.LogManager;

/**
* @author Ture Bentzin
* 16.11.2022
* @implNote Main class to be used to get the different parts of the api
*/
public interface API {
public interface API extends Logging {

/**
* This is the primary way for getting your API Instance. With this Instance you have access to all build in features in the core
Expand Down Expand Up @@ -148,6 +150,16 @@ public interface API {

@NotNull Collection<? extends MessageRecipient> supplyOnlineRecipients();

/**
* When using a {@link LogManager} you should use {@link API#getJavaLogManager()} to get hold of it
*
* @return an {@link LogManager} instance that is or acts like {@link LogManager#getLogManager()}
* @apiNote This is not associated with the {@link de.bentzin.tools.logging} package and environment
*/
@ApiStatus.Experimental
@ApiStatus.AvailableSince("1.6")
@NotNull LogManager getJavaLogManager();

/*
*
* @return if the core is connected and ready for operation
Expand Down
2 changes: 1 addition & 1 deletion API/src/main/java/net/juligames/core/api/TODO.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
*/
@SuppressWarnings("JavadocDeclaration")
public @interface TODO {
boolean doNotcall();
boolean doNotcall() default false;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.Unmodifiable;

import java.util.Collection;
import java.util.Comparator;
Expand Down Expand Up @@ -140,4 +141,10 @@ default <T> void spiltAndWrite(@NotNull Collection<T> collection, @NotNull Inter
*/
@ApiStatus.AvailableSince("1.5")
@NotNull Configuration createSectionClone(@NotNull Configuration root, @NotNull String section);

@ApiStatus.AvailableSince("1.6")
@NotNull @Unmodifiable Collection<Configuration> getAll();

@ApiStatus.AvailableSince("1.6")
@NotNull @Unmodifiable Collection<String> getAllHazels();
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,33 @@
import org.jetbrains.annotations.NotNull;

/**
* Here is an exmaple on how to use the {@link EnumInterpreter} with the fictional enum "Color"
* <pre>
* {@code
* public enum Color {
* RED,
* GREEN,
* BLUE
* }
*
* public class Main {
* public static void main(String[] args) {
* EnumInterpreter<Color> colorInterpreter = new EnumInterpreter<>(Color.class);
*
* // Reverse an enum value to a string
* Color color = Color.RED;
* String reversed = colorInterpreter.reverse(color);
* System.out.println("Reversed: " + reversed); // Output: Reversed: RED
*
* // Interpret a string as an enum value
* String input = "GREEN";
* Color interpreted = colorInterpreter.interpret(input);
* System.out.println("Interpreted: " + interpreted); // Output: Interpreted: GREEN
* }
* }
* }
* </pre>
*
* @author Ture Bentzin
* 15.03.2023
*/
Expand All @@ -13,21 +40,46 @@ public class EnumInterpreter<T extends Enum<T>> implements Interpreter<T> {

private final Class<T> enumClazz;

/**
* Constructs a new {@link EnumInterpreter} instance for the specified enum class.
*
* @param enumClazz the class object for the enum type
*/
public EnumInterpreter(Class<T> enumClazz) {
this.enumClazz = enumClazz;
}

/**
* Interprets the input string as an enum value of type T.
*
* @param input the input string to be interpreted
* @return the interpreted enum value
* @throws IllegalArgumentException if the input string is not a valid name of an enum constant belonging to type T
*/
@Override
public @NotNull T interpret(@NotNull String input) throws Exception {
public @NotNull T interpret(@NotNull String input) throws IllegalArgumentException {
return T.valueOf(enumClazz, input);
}

/**
* Returns the name of the specified enum value.
*
* @param t the enum value to be reversed
* @return the name of the enum value
*/
@Override
public @NotNull String reverse(@NotNull T t) {
return t.name();
}

/**
* Returns the class object for the enum type.
*
* @return the class object for the enum type
*/
public Class<T> getEnumClazz() {
return enumClazz;
}
}


105 changes: 102 additions & 3 deletions API/src/main/java/net/juligames/core/api/config/Interpreter.java
Original file line number Diff line number Diff line change
@@ -1,25 +1,124 @@
package net.juligames.core.api.config;

import de.bentzin.tools.DoNotOverride;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;

import java.util.concurrent.CompletableFuture;
import java.util.function.Function;

/**
* This interface defines methods for interpreting a string as an instance of a certain type and for reversing the
* interpretation back to a string.
* <p>
* This is an example implementation for interpreting Integers
* <pre>
* {@code
*
* public final class IntegerInterpreter implements Interpreter<Integer> {
*
* @Override
* public Integer interpret(String input) throws Exception {
* return Integer.parseInt(input);
* }
*
* @Override
* public String reverse(Integer integer) {
* return Integer.toString(integer);
* }
*
* public Class<Integer> getType() {
* return Integer.class;
* }
* }
* }
* </pre>
*
* @param <T> the type of object that this Interpreter can interpret
* @author Ture Bentzin
* 26.11.2022
* @see BuildInInterpreters
*/
public non-sealed interface Interpreter<T> extends Reverser<T>, PrimitiveInterpreter<T> {

public interface Interpreter<T> {
/**
* Converts the given input according to this implementation to a given Object of the provided Type.
* This process is known as "interpreting the input as an instance of Type T"
*
* @param input the input to be interpreted
* @return the instance of T that results from the interpretation
* @throws Exception will be thrown if the input can't be interpreted according to this implementation
*/
@NotNull T interpret(final String input) throws Exception;

/**
* Converts the given instance of T according to this implementation to a String with the intention that this string
* can be interpreted back to the instance of T with the correct implementation of {@link Interpreter} that
* implements this {@link Reverser}.
* It should always be possible to convert t to a string!
* This process is known as "reversing the interpretation of a string back to the string"
*
* @param t the object to be reversed
* @return the string that was reversed from the instance of T
*/
@NotNull String reverse(T t);

/**
* Applies the given function to the result of {@link #reverse(T)} and returns its result.
*
* @param t the object to be reversed
* @param function the function to apply to the result of {@link #reverse(T)}
* @param <R> the type of the result of the function
* @return the result of applying the function to the result of {@link #reverse(T)}
*/
default <R> R reverseAndThen(@NotNull T t, @NotNull Function<String, R> function) {
return function.apply(reverse(t));
}

default <R> R interpretAndThen(@NotNull String input, @NotNull Function<T, R> function) throws Exception {
return function.apply(interpret(input));
/**
* Completes the given CompletableFuture with the result of {@link #reverse(T)}.
*
* @param t the object to be reversed
* @param completableFuture the CompletableFuture to complete with the result of {@link #reverse(T)}
* @param <R> the type of the CompletableFuture
*/
@ApiStatus.AvailableSince("1.6")
@ApiStatus.Experimental
default <R> void reverseAndThenComplete(@NotNull T t, @NotNull CompletableFuture<String> completableFuture) {
completableFuture.complete(reverse(t));
}

/**
* Interprets the given input according to this implementation to an instance of T and completes the given
* CompletableFuture with the result of the interpretation. This process is known as "interpreting the input as an
* instance of Type T". If the interpretation fails, an Exception will be thrown.
*
* @param input the input to be interpreted
* @param completableFuture the CompletableFuture that should be completed with the result of the interpretation
* @throws Exception will be thrown if the input cant be interpreted according to this implementation
*/
@ApiStatus.AvailableSince("1.6")
@ApiStatus.Experimental
default <R> void interpretAndThenComplete(@NotNull String input, @NotNull CompletableFuture<T> completableFuture) throws Exception {
completableFuture.complete(interpret(input));
}

/**
* This will return a cast of this to a {@link Reverser}
*/
@DoNotOverride
@ApiStatus.AvailableSince("1.6")
default Reverser<T> asReverser() {
return this;
}

/**
* This will return a cast of this to a {@link PrimitiveInterpreter}
*/
@DoNotOverride
@ApiStatus.AvailableSince("1.6")
default PrimitiveInterpreter<T> asIInterpreter() {
return this;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package net.juligames.core.api.config;

import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;

/**
* This might be used later outside of this package
*
* @author Ture Bentzin
* 12.04.2023
*/
@ApiStatus.Internal
@ApiStatus.AvailableSince("1.6")
public sealed interface PrimitiveInterpreter<T> permits Interpreter {

/**
* Converts the given input according to this implementation to a given Object of the provided Type.
* This process is known as "interpreting the input as an instance of Type T"
*
* @param input the input to be interpreted
* @return the instance of T that results the interpretation
* @throws Exception will be thrown if the input cant be interpreted according to this implementation
*/
@SuppressWarnings("override")
@NotNull T interpret(final String input) throws Exception;
}
Loading

0 comments on commit decf81a

Please sign in to comment.