Added javadoc / API info

This commit is contained in:
Stijn Bannink 2023-11-10 11:49:47 +01:00
parent b25cd1323f
commit 2d194af704
15 changed files with 269 additions and 2 deletions

View file

@ -0,0 +1,32 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="ShowControl build" type="MavenRunConfiguration" factoryName="Maven">
<MavenSettings>
<option name="myGeneralSettings" />
<option name="myRunnerSettings" />
<option name="myRunnerParameters">
<MavenRunnerParameters>
<option name="cmdOptions" />
<option name="profiles">
<set />
</option>
<option name="goals">
<list>
<option value="clean" />
<option value="package" />
</list>
</option>
<option name="pomFileName" />
<option name="profilesMap">
<map />
</option>
<option name="projectsCmdOptionValues">
<list />
</option>
<option name="resolveToWorkspace" value="false" />
<option name="workingDirPath" value="$PROJECT_DIR$" />
</MavenRunnerParameters>
</option>
</MavenSettings>
<method v="2" />
</configuration>
</component>

View file

@ -0,0 +1,32 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="ShowControl deploy" type="MavenRunConfiguration" factoryName="Maven">
<MavenSettings>
<option name="myGeneralSettings" />
<option name="myRunnerSettings" />
<option name="myRunnerParameters">
<MavenRunnerParameters>
<option name="cmdOptions" />
<option name="profiles">
<set />
</option>
<option name="goals">
<list>
<option value="clean" />
<option value="deploy" />
</list>
</option>
<option name="pomFileName" />
<option name="profilesMap">
<map />
</option>
<option name="projectsCmdOptionValues">
<list />
</option>
<option name="resolveToWorkspace" value="false" />
<option name="workingDirPath" value="$PROJECT_DIR$" />
</MavenRunnerParameters>
</option>
</MavenSettings>
<method v="2" />
</configuration>
</component>

View file

@ -0,0 +1,32 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="ShowControl javadoc" type="MavenRunConfiguration" factoryName="Maven">
<MavenSettings>
<option name="myGeneralSettings" />
<option name="myRunnerSettings" />
<option name="myRunnerParameters">
<MavenRunnerParameters>
<option name="cmdOptions" />
<option name="profiles">
<set />
</option>
<option name="goals">
<list>
<option value="clean" />
<option value="javadoc:javadoc" />
</list>
</option>
<option name="pomFileName" />
<option name="profilesMap">
<map />
</option>
<option name="projectsCmdOptionValues">
<list />
</option>
<option name="resolveToWorkspace" value="false" />
<option name="workingDirPath" value="$PROJECT_DIR$" />
</MavenRunnerParameters>
</option>
</MavenSettings>
<method v="2" />
</configuration>
</component>

19
pom.xml
View file

@ -23,6 +23,13 @@
</pluginRepository>
</pluginRepositories>
<distributionManagement>
<repository>
<id>sbdevelopment-repo</id>
<url>https://repo.sbdevelopment.tech/releases</url>
</repository>
</distributionManagement>
<build>
<defaultGoal>clean package</defaultGoal>
<finalName>${project.name} v${project.version}</finalName>
@ -85,6 +92,18 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.6.0</version>
<configuration>
<release>11</release>
<additionalJOption>--no-module-directories</additionalJOption> <!-- Fix for undefined in search -->
<sourceFileIncludes>
<sourceFileInclude>**/tech/sbdevelopment/showcontrol/api/**</sourceFileInclude>
</sourceFileIncludes>
</configuration>
</plugin>
</plugins>
<resources>
<resource>

View file

@ -17,6 +17,7 @@ import tech.sbdevelopment.showcontrol.api.triggers.TriggerIdentifier;
import tech.sbdevelopment.showcontrol.data.DataStorage;
import tech.sbdevelopment.showcontrol.utils.YamlFile;
import javax.annotation.Nullable;
import java.io.File;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
@ -25,15 +26,36 @@ import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
/**
* This class is the main class of the API.
*/
public class SCAPI {
/**
* A map of all default trigger, only used for tab complete.
*/
@Getter
private static final Map<String, Trigger> defaultTriggers = new HashMap<>(); //DO NOT USE, just for tab complete!
private static final Map<String, Trigger> defaultTriggers = new HashMap<>();
/**
* A map of all triggers, used for creating new triggers.
*/
@Getter
private static final Map<String, Class<? extends Trigger>> triggers = new HashMap<>();
/**
* A map of all shows with their cue points.
*/
@Getter
private static final HashMap<String, List<ShowCuePoint>> showsMap = new HashMap<>();
/**
* A map of all show timers.
*/
private static final HashMap<String, ScheduledExecutorService> showTimers = new HashMap<>();
/**
* Index all triggers in a package. Call this method in your onEnable method.
*
* @param clazz The class to use as starting point, usually your main class.
* @param packages The packages to index.
*/
public static void index(Class<?> clazz, String... packages) {
ShowControlPlugin.getInstance().getLogger().info("Indexing triggers for starting point " + clazz.getSimpleName() + "...");
@ -62,11 +84,31 @@ public class SCAPI {
}
}
public static List<String> getTabComplete(String triggerType, Player player, int index, String arg) {
/**
* Get the tab complete for a trigger.
*
* @param triggerType The trigger type.
* @param player The player that wants to add the cue, will be null if it's not a player.
* @param index The current argument index.
* @param arg The current argument.
* @return The tab complete value based on the index and argument.
*/
public static List<String> getTabComplete(String triggerType, @Nullable Player player, int index, String arg) {
if (!defaultTriggers.containsKey(triggerType)) return new ArrayList<>();
return defaultTriggers.get(triggerType).getArgumentTabComplete(player, index, arg);
}
/**
* Get a trigger from a data string.
*
* @param data The data string.
* @return The trigger.
* @param <T> The trigger type.
* @throws ReflectiveOperationException When the trigger could not be created.
* @throws InvalidTriggerException When the trigger does not exist.
* @throws TooFewArgumentsException When the trigger data does not have enough arguments.
* @throws IllegalArgumentException When the trigger data is invalid.
*/
public static <T extends Trigger> T getTrigger(String data) throws ReflectiveOperationException, InvalidTriggerException, TooFewArgumentsException, IllegalArgumentException {
String[] dataSplitter = data.split(" ");
String[] dataSplitterNew = Arrays.copyOfRange(dataSplitter, 1, dataSplitter.length);
@ -83,11 +125,21 @@ public class SCAPI {
return ctor.newInstance(new Object[]{dataSplitterNew});
}
/**
* Create a new show.
*
* @param name The name of the show.
*/
public static void create(String name) {
showsMap.put(name, new ArrayList<>());
DataStorage.save();
}
/**
* Delete a show.
*
* @param name The name of the show.
*/
public static void delete(String name) {
showsMap.remove(name);
@ -95,21 +147,46 @@ public class SCAPI {
data.delete();
}
/**
* Check if a show exists.
*
* @param name The name of the show.
* @return If the show exists.
*/
public static boolean exists(String name) {
return showsMap.containsKey(name);
}
/**
* Get the points of a show.
*
* @param name The name of the show.
* @return The points of the show.
*/
public static List<ShowCuePoint> getPoints(String name) {
if (!exists(name)) return new ArrayList<>();
return showsMap.get(name);
}
/**
* Add a point to a show.
*
* @param name The name of the show.
* @param time The time of the point.
* @param data The data of the point.
*/
public static void addPoint(String name, Long time, Trigger data) {
if (!exists(name)) return;
getPoints(name).add(new ShowCuePoint(time, data));
DataStorage.save();
}
/**
* Remove a point from a show.
*
* @param name The name of the show.
* @param point The point to remove.
*/
public static void removePoint(String name, ShowCuePoint point) {
if (!exists(name)) return;
@ -122,6 +199,11 @@ public class SCAPI {
data.saveFile();
}
/**
* Start a show.
*
* @param name The name of the show.
*/
public static void startShow(String name) {
if (!exists(name)) return;
ScheduledExecutorService showTimer = Executors.newSingleThreadScheduledExecutor();
@ -131,6 +213,11 @@ public class SCAPI {
showTimers.put(name, showTimer);
}
/**
* Cancel a show.
*
* @param name The name of the show.
*/
public static void cancelShow(String name) {
if (!exists(name)) return;
if (!showTimers.containsKey(name)) return;

View file

@ -2,6 +2,9 @@ package tech.sbdevelopment.showcontrol.api.exceptions;
import lombok.experimental.StandardException;
/**
* Thrown when an argument is invalid
*/
@StandardException
public class InvalidArgumentException extends Exception {
}

View file

@ -2,6 +2,9 @@ package tech.sbdevelopment.showcontrol.api.exceptions;
import lombok.experimental.StandardException;
/**
* Thrown when a trigger is invalid
*/
@StandardException
public class InvalidTriggerException extends Exception {
}

View file

@ -2,6 +2,9 @@ package tech.sbdevelopment.showcontrol.api.exceptions;
import lombok.experimental.StandardException;
/**
* Thrown when a trigger has too few arguments
*/
@StandardException
public class TooFewArgumentsException extends Exception {
}

View file

@ -0,0 +1,4 @@
/**
* This package contains the exceptions thrown by the plugin.
*/
package tech.sbdevelopment.showcontrol.api.exceptions;

View file

@ -0,0 +1,4 @@
/**
* This package contains the API of the ShowControl plugin.
*/
package tech.sbdevelopment.showcontrol.api;

View file

@ -12,8 +12,19 @@ import java.util.UUID;
@Getter
@AllArgsConstructor
public class ShowCuePoint {
/**
* The ID of the cue point
*/
private final UUID cueID;
/**
* The start-time (milliseconds)
*/
private final Long time;
/**
* The data
*/
private final Trigger data;
/**

View file

@ -0,0 +1,4 @@
/**
* This package contains the point API.
*/
package tech.sbdevelopment.showcontrol.api.points;

View file

@ -8,10 +8,16 @@ import org.bukkit.entity.Player;
import javax.annotation.Nullable;
import java.util.List;
/**
* This class is the base class for all triggers
*/
@NoArgsConstructor(force = true)
@AllArgsConstructor
@Getter
public abstract class Trigger {
/**
* The datastring of the trigger
*/
private final String[] dataString;
/**

View file

@ -7,14 +7,37 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* This annotation is used to identify a trigger.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface TriggerIdentifier {
/**
* The identifier of the trigger, used in the add command.
*
* @return The identifier of the trigger.
*/
String value();
/**
* The minimum amount of arguments the trigger needs.
*
* @return The minimum amount of arguments the trigger needs.
*/
int minArgs() default 0;
/**
* The description of the arguments the trigger needs.
*
* @return The description of the arguments the trigger needs.
*/
String argDesc() default "";
/**
* The item shown in the GUI for a show.
*
* @return The item shown in the GUI for a show.
*/
Material item() default Material.NOTE_BLOCK;
}

View file

@ -0,0 +1,4 @@
/**
* This package contains the trigger API.
*/
package tech.sbdevelopment.showcontrol.api.triggers;