-
-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #391 from Mindgamesnl/feature/new-base-api
Feature/new base api (OA main api)
- Loading branch information
Showing
101 changed files
with
1,792 additions
and
354 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
target/ | ||
target/* | ||
.DS_Store | ||
test-storage/ | ||
test-server/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?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/maven-v4_0_0.xsd"> | ||
<parent> | ||
<artifactId>OpenAudioMc-Parent</artifactId> | ||
<groupId>com.craftmend.openaudiomc</groupId> | ||
<version>1.2</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
<artifactId>openaudiomc-api</artifactId> | ||
<name>openaudiomc-api</name> | ||
<version>${oa.version}</version> | ||
<build> | ||
<resources> | ||
<resource> | ||
<filtering>true</filtering> | ||
<directory>src/main/resources</directory> | ||
</resource> | ||
</resources> | ||
<finalName>openaudiomc-api</finalName> | ||
<plugins> | ||
<plugin> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>3.8.1</version> | ||
<configuration> | ||
<source>${java.version}</source> | ||
<target>${java.version}</target> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-shade-plugin</artifactId> | ||
<version>3.2.4</version> | ||
<executions> | ||
<execution> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>shade</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.projectlombok</groupId> | ||
<artifactId>lombok</artifactId> | ||
<version>1.18.30</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
</dependencies> | ||
<properties> | ||
<java.version>1.8</java.version> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
</properties> | ||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?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"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>openaudiomc-api</artifactId> | ||
<version>${oa.version}</version> | ||
<packaging>jar</packaging> | ||
<name>openaudiomc-api</name> | ||
|
||
<parent> | ||
<groupId>com.craftmend.openaudiomc</groupId> | ||
<artifactId>OpenAudioMc-Parent</artifactId> | ||
<relativePath>../pom.xml</relativePath> | ||
<version>1.2</version> | ||
</parent> | ||
|
||
<properties> | ||
<java.version>1.8</java.version> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
</properties> | ||
|
||
<build> | ||
<finalName>openaudiomc-api</finalName> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>3.8.1</version> | ||
<configuration> | ||
<source>${java.version}</source> | ||
<target>${java.version}</target> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-shade-plugin</artifactId> | ||
<version>3.2.4</version> | ||
<executions> | ||
<execution> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>shade</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
<resources> | ||
<resource> | ||
<directory>src/main/resources</directory> | ||
<filtering>true</filtering> | ||
</resource> | ||
</resources> | ||
</build> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.jetbrains</groupId> | ||
<artifactId>annotations</artifactId> | ||
<version>24.1.0</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.projectlombok</groupId> | ||
<artifactId>lombok</artifactId> | ||
<version>1.18.30</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
24 changes: 24 additions & 0 deletions
24
api/src/main/java/com/craftmend/openaudiomc/api/ApiHolder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.craftmend.openaudiomc.api; | ||
|
||
public class ApiHolder { | ||
|
||
static ClientApi clientApiInstance; | ||
static WorldApi worldApiInstance; | ||
static VoiceApi voiceApiInstance; | ||
static MediaApi mediaApiInstance; | ||
|
||
public static void initiate( | ||
ClientApi clientApi, | ||
WorldApi worldApi, | ||
VoiceApi voiceApi, | ||
MediaApi mediaApi | ||
) { | ||
if (clientApiInstance != null) throw new IllegalStateException("Api already initiated"); | ||
|
||
clientApiInstance = clientApi; | ||
worldApiInstance = worldApi; | ||
voiceApiInstance = voiceApi; | ||
mediaApiInstance = mediaApi; | ||
} | ||
|
||
} |
41 changes: 41 additions & 0 deletions
41
api/src/main/java/com/craftmend/openaudiomc/api/ClientApi.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.craftmend.openaudiomc.api; | ||
|
||
import com.craftmend.openaudiomc.api.clients.Client; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.Collection; | ||
import java.util.UUID; | ||
|
||
public interface ClientApi { | ||
|
||
/** | ||
* Get an instance of the client api. May be null if the plugin is not loaded yet | ||
* @return instance | ||
*/ | ||
static ClientApi getInstance() { | ||
return ApiHolder.clientApiInstance; | ||
} | ||
|
||
/** | ||
* Get a client by a player UUID, or null if the player is not online or not registered yet | ||
* @param clientUuid the UUID of the player | ||
* @return the client instance, or null if the client is not connected | ||
*/ | ||
@Nullable Client getClient(UUID clientUuid); | ||
|
||
/** | ||
* Get all clients that are currently known to the server | ||
* @return All clients | ||
*/ | ||
@NotNull | ||
Collection<Client> getAllClients(); | ||
|
||
/** | ||
* Check if a client is registered, and has an active web connection | ||
* @param uuid the UUID of the player | ||
* @return true if the player is connected, false if not or not registered | ||
*/ | ||
boolean isConnected(UUID uuid); | ||
|
||
} |
78 changes: 78 additions & 0 deletions
78
api/src/main/java/com/craftmend/openaudiomc/api/MediaApi.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package com.craftmend.openaudiomc.api; | ||
|
||
import com.craftmend.openaudiomc.api.clients.Client; | ||
import com.craftmend.openaudiomc.api.media.Media; | ||
import com.craftmend.openaudiomc.api.media.UrlMutation; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public interface MediaApi { | ||
|
||
/** | ||
* Get an instance of the media api. May be null if the plugin is not loaded yet | ||
* @return instance | ||
*/ | ||
static MediaApi getInstance() { | ||
return ApiHolder.mediaApiInstance; | ||
} | ||
|
||
/** | ||
* Create a new media instance with a source, and automatically translate the source | ||
* (if needed) and register a normalized time for the start instant. | ||
* | ||
* @param source the source of the media | ||
* @return a new media instance | ||
*/ | ||
@NotNull | ||
Media createMedia(@NotNull String source); | ||
|
||
/** | ||
* Translate server-sided aliases, playlists or other sources to a valid source. | ||
* This is automatically done by createMedia, but you might want to do this manually. | ||
* | ||
* @param source the source to translate | ||
* @return the translated source | ||
*/ | ||
@NotNull | ||
String translateSource(@NotNull String source); | ||
|
||
/** | ||
* URL mutations can be used to register custom server-side media hooks or source translators. | ||
* An example use case would be a custom media server aliased by hypixel:, which can be resolved | ||
* to https://hypixel.com/media/* by a mutation. | ||
* | ||
* @param prefix the prefix to register the mutation for, | ||
* the mutation will only be called for media sources starting with this prefix | ||
* @param mutation the mutation to register | ||
*/ | ||
void registerMutation(@NotNull String prefix, @NotNull UrlMutation mutation); | ||
|
||
/** | ||
* Get the current epoch time, but normalized to the start of the current media. | ||
* This timecodes is normalized based on heartbeats from an open audio server, to eliminate | ||
* timezone changes between this server and the web-client (because the player might be in a different timezone) | ||
* | ||
* @return the current epoch time, but normalized to the start of the current media | ||
*/ | ||
long getNormalizedCurrentEpoch(); | ||
|
||
/** | ||
* Play a media for a client | ||
* @param client Target client | ||
* @param media Media instance | ||
*/ | ||
void playFor(@NotNull Media media, @NotNull Client... clients); | ||
|
||
/** | ||
* Stop all media (except regions and speakers) for a client | ||
* @param clients Target clients | ||
*/ | ||
void stopFor(@NotNull Client... clients); | ||
|
||
/** | ||
* Stop a specific media by ID for a client | ||
* @param id Media ID | ||
* @param clients Target clients | ||
*/ | ||
void stopFor(@NotNull String id, @NotNull Client... clients); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
api/src/main/java/com/craftmend/openaudiomc/api/WorldApi.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package com.craftmend.openaudiomc.api; | ||
|
||
import com.craftmend.openaudiomc.api.regions.AudioRegion; | ||
import com.craftmend.openaudiomc.api.spakers.BasicSpeaker; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.Collection; | ||
|
||
public interface WorldApi { | ||
|
||
/** | ||
* Get an instance of the world api. May be null if the plugin is not loaded yet | ||
* @return instance | ||
*/ | ||
static WorldApi getInstance() { | ||
return ApiHolder.worldApiInstance; | ||
} | ||
|
||
/** | ||
* Get all regions at a location | ||
* @param x x | ||
* @param y y | ||
* @param z z | ||
* @param world world | ||
* @return regions | ||
*/ | ||
@NotNull | ||
Collection<AudioRegion> getRegionsAt(int x, int y, int z, @NotNull String world); | ||
|
||
/** | ||
* Get a speaker at a location, or null if invalid | ||
* @param x x | ||
* @param y y | ||
* @param z z | ||
* @param world world | ||
* @return speaker | ||
*/ | ||
@Nullable | ||
BasicSpeaker getSpeakerAt(int x, int y, int z, @NotNull String world); | ||
|
||
} |
Oops, something went wrong.