Skip to content

Commit

Permalink
Merge pull request #7 from TechnicallyCoded/dev
Browse files Browse the repository at this point in the history
Support Java 1.8 while retaining gradle builds & a direct folia api dependency on it's sub-module.
  • Loading branch information
TechnicallyCoded authored Aug 18, 2023
2 parents 208607e + 318ca67 commit 0d8b9b5
Show file tree
Hide file tree
Showing 23 changed files with 458 additions and 183 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,5 @@ bin/
/.idea/
/gradle/
gradlew
gradlew.bat
gradlew.bat
/target/
77 changes: 58 additions & 19 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,30 +1,69 @@
plugins {
id 'java'
buildscript {
ext {
revision = '0.2.4'
}
}

group 'com.tcoded'
version '0.2.3'
allprojects {
apply plugin: 'java'

java {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
version = '0.2.5'

repositories {

mavenCentral()

maven {
url 'https://hub.spigotmc.org/nexus/content/repositories/snapshots/'
}

maven {
url 'https://hub.spigotmc.org/nexus/content/repositories/public/'
}

maven {
url = "https://repo.papermc.io/repository/maven-public/"
}

maven {
url = "https://nexuslite.gcnt.net/repos/paper/"
}
}

repositories {
mavenCentral()
maven {
url 'https://repo.papermc.io/repository/maven-public/'
java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}

dependencies {
implementation 'org.jetbrains:annotations:23.0.0'

testImplementation platform('org.junit:junit-bom:5.9.1')
testImplementation 'org.junit.jupiter:junit-jupiter'
}

test {
useJUnitPlatform()
}
}

dependencies {
implementation 'dev.folia:folia-api:1.19.4-R0.1-SNAPSHOT'
implementation 'org.jetbrains:annotations:23.0.0'
group 'com.tcoded'

def baseName

testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1'
subprojects.each { subproject -> evaluationDependsOn(subproject.path)}
tasks.register('allJar', Jar) {
dependsOn 'compileJava'
dependsOn 'jar'
dependsOn subprojects.tasks['build']
baseName = 'allJar'
subprojects.each { subproject ->
from subproject.configurations.archives.allArtifacts.files.collect {
zipTree(it)
}
}
}

test {
useJUnitPlatform()
artifacts {
archives allJar
}
7 changes: 7 additions & 0 deletions common/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
group = 'com.tcoded.folialib'

dependencies {
compileOnly 'org.spigotmc:spigot-api:1.8.8-R0.1-SNAPSHOT'

implementation(project(":platform:common"))
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import com.tcoded.folialib.impl.*;
import org.bukkit.plugin.java.JavaPlugin;

import java.lang.reflect.InvocationTargetException;

public class FoliaLib {

private final JavaPlugin plugin;
Expand Down Expand Up @@ -36,11 +38,42 @@ public FoliaLib(JavaPlugin plugin) {
// Apply the implementation based on the type
this.implementationType = foundType;
switch (foundType) {
case FOLIA -> this.implementation = new FoliaImplementation(this);
case PAPER -> this.implementation = new PaperImplementation(this);
case SPIGOT -> this.implementation = new SpigotImplementation(this);
default -> this.implementation = new UnsupportedImplementation(this);
case FOLIA:
this.implementation = this.createServerImpl("FoliaImplementation");
break;
case PAPER:
this.implementation = this.createServerImpl("PaperImplementation");
break;
case SPIGOT:
this.implementation = this.createServerImpl("SpigotImplementation");
break;
default:
this.implementation = this.createServerImpl("UnsupportedImplementation");
break;
}

// Check for valid implementation
if (this.implementation == null) {
throw new IllegalStateException(
"Failed to create server implementation. Please report this to the FoliaLib GitHub issues page. " +
"Forks of server software may not all be supported. If you are using an unofficial fork, " +
"please report this to the fork's developers first.");
}
}

private ServerImplementation createServerImpl(String implName) {
String basePackage = "com.tcoded.folialib.impl.";

try {
return (ServerImplementation) Class.forName(basePackage + implName)
.getConstructor(this.getClass())
.newInstance(this);
} catch (InstantiationException | ClassNotFoundException | NoSuchMethodException | InvocationTargetException |
IllegalAccessException e) {
e.printStackTrace();
}

return null;
}

@SuppressWarnings("unused")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,7 @@ public static long toTicks(long time, TimeUnit unit) {
return unit.toMillis(time) / 50;
}

public static long toMillis(long delay) {
return delay * 50L;
}
}
1 change: 1 addition & 0 deletions platform/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
group = 'com.tcoded.folialib'
5 changes: 5 additions & 0 deletions platform/common/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
group = 'com.tcoded.folialib.platform'

dependencies {
compileOnly 'org.spigotmc:spigot-api:1.8.8-R0.1-SNAPSHOT'
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.tcoded.folialib.impl;

import com.tcoded.folialib.enums.EntityTaskResult;
import com.tcoded.folialib.wrapper.WrappedTask;
import com.tcoded.folialib.wrapper.task.WrappedTask;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
Expand Down Expand Up @@ -35,6 +35,16 @@ public interface ServerImplementation {

// ----- Run Later -----

/**
* Folia: Synced with the server daylight cycle tick
* Paper: Synced with the server main thread
* Spigot: Synced with the server main thread
* @param runnable Task to run
* @param delay Delay before execution in ticks
* @return WrappedTask instance
*/
WrappedTask runLater(Runnable runnable, long delay);

/**
* Folia: Synced with the server daylight cycle tick
* Paper: Synced with the server main thread
Expand All @@ -46,6 +56,16 @@ public interface ServerImplementation {
*/
WrappedTask runLater(Runnable runnable, long delay, TimeUnit unit);

/**
* Folia: Async
* Paper: Async
* Spigot: Async
* @param runnable Task to run
* @param delay Delay before execution in ticks
* @return WrappedTask instance
*/
WrappedTask runLaterAsync(Runnable runnable, long delay);

/**
* Folia: Async
* Paper: Async
Expand All @@ -59,6 +79,17 @@ public interface ServerImplementation {

// ----- Global Timers -----

/**
* Folia: Synced with the server daylight cycle tick
* Paper: Synced with the server main thread
* Spigot: Synced with the server main thread
* @param runnable Task to run
* @param delay Delay before first execution in ticks
* @param period Delay between executions in ticks
* @return WrappedTask instance
*/
WrappedTask runTimer(Runnable runnable, long delay, long period);

/**
* Folia: Synced with the server daylight cycle tick
* Paper: Synced with the server main thread
Expand All @@ -71,6 +102,17 @@ public interface ServerImplementation {
*/
WrappedTask runTimer(Runnable runnable, long delay, long period, TimeUnit unit);

/**
* Folia: Async
* Paper: Async
* Spigot: Async
* @param runnable Task to run
* @param delay Delay before first execution in ticks
* @param period Delay between executions in ticks
* @return WrappedTask instance
*/
WrappedTask runTimerAsync(Runnable runnable, long delay, long period);

/**
* Folia: Async
* Paper: Async
Expand All @@ -96,6 +138,17 @@ public interface ServerImplementation {
*/
CompletableFuture<Void> runAtLocation(Location location, Runnable runnable);

/**
* Folia: Synced with the tick of the region of the chunk of the location
* Paper: Synced with the server main thread
* Spigot: Synced with the server main thread
* @param location Location to run the task at
* @param runnable Task to run
* @param delay Delay before execution in ticks
* @return WrappedTask instance
*/
WrappedTask runAtLocationLater(Location location, Runnable runnable, long delay);

/**
* Folia: Synced with the tick of the region of the chunk of the location
* Paper: Synced with the server main thread
Expand All @@ -108,6 +161,18 @@ public interface ServerImplementation {
*/
WrappedTask runAtLocationLater(Location location, Runnable runnable, long delay, TimeUnit unit);

/**
* Folia: Synced with the tick of the region of the chunk of the location
* Paper: Synced with the server main thread
* Spigot: Synced with the server main thread
* @param location Location to run the task at
* @param runnable Task to run
* @param delay Delay before first execution in ticks
* @param period Delay between executions in ticks
* @return WrappedTask instance
*/
WrappedTask runAtLocationTimer(Location location, Runnable runnable, long delay, long period);

/**
* Folia: Synced with the tick of the region of the chunk of the location
* Paper: Synced with the server main thread
Expand Down Expand Up @@ -144,6 +209,17 @@ public interface ServerImplementation {
*/
CompletableFuture<EntityTaskResult> runAtEntityWithFallback(Entity entity, Runnable runnable, Runnable fallback);

/**
* Folia: Synced with the tick of the region of the entity (even if the entity moves)
* Paper: Synced with the server main thread
* Spigot: Synced with the server main thread
* @param entity Entity to run the task at
* @param runnable Task to run
* @param delay Delay before execution in ticks
* @return WrappedTask instance
*/
WrappedTask runAtEntityLater(Entity entity, Runnable runnable, long delay);

/**
* Folia: Synced with the tick of the region of the entity (even if the entity moves)
* Paper: Synced with the server main thread
Expand All @@ -156,6 +232,18 @@ public interface ServerImplementation {
*/
WrappedTask runAtEntityLater(Entity entity, Runnable runnable, long delay, TimeUnit unit);

/**
* Folia: Synced with the tick of the region of the entity (even if the entity moves)
* Paper: Synced with the server main thread
* Spigot: Synced with the server main thread
* @param entity Entity to run the task at
* @param runnable Task to run
* @param delay Delay before first execution in ticks
* @param period Delay between executions in ticks
* @return WrappedTask instance
*/
WrappedTask runAtEntityTimer(Entity entity, Runnable runnable, long delay, long period);

/**
* Folia: Synced with the tick of the region of the entity (even if the entity moves)
* Paper: Synced with the server main thread
Expand All @@ -181,23 +269,29 @@ public interface ServerImplementation {
void cancelAllTasks();

/**
* Get a player by name (approximately)
* Get a player by name (approximately).
* When using folia, this can be run sync or async. If this is run async on non-folia platforms, it will block
* until the next tick to get the player safely.
* @param name Name of the player
* @return Player instance
* @return Player instance or null if not found
*/
Player getPlayer(String name);

/**
* Get a player by name (exactly)
* When using folia, this can be run sync or async. If this is run async on non-folia platforms, it will block
* until the next tick to get the player safely.
* @param name Name of the player
* @return Player instance
* @return Player instance or null if not found
*/
Player getPlayerExact(String name);

/**
* Get a player by UUID
* When using folia, this can be run sync or async. If this is run async on non-folia platforms, it will block
* until the next tick to get the player safely.
* @param uuid UUID of the player
* @return Player instance
* @return Player instance or null if not found
*/
Player getPlayer(UUID uuid);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.tcoded.folialib.wrapper;
package com.tcoded.folialib.wrapper.task;

import org.bukkit.plugin.Plugin;

Expand Down
13 changes: 13 additions & 0 deletions platform/folia/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
group = 'com.tcoded.folialib.platform'

java {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}

dependencies {
compileOnly "dev.folia:folia-api:1.19.4-R0.1-SNAPSHOT"

implementation(project(":common"))
implementation(project(":platform:common"))
}
Loading

0 comments on commit 0d8b9b5

Please sign in to comment.