-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
48 changed files
with
776 additions
and
221 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
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
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,13 @@ | ||
plugins { | ||
`java-library` | ||
alias(libs.plugins.lombok) | ||
} | ||
repositories { | ||
mavenCentral() | ||
maven("https://repo.papermc.io/repository/maven-public/") | ||
} | ||
|
||
dependencies { | ||
compileOnly(libs.paper) | ||
compileOnly(libs.guice) | ||
} |
3 changes: 3 additions & 0 deletions
3
paper/src/main/java/de/rexlmanu/fairychat/plugin/paper/AdaptPluginMeta.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,3 @@ | ||
package de.rexlmanu.fairychat.plugin.paper; | ||
|
||
public record AdaptPluginMeta(String version) {} |
14 changes: 14 additions & 0 deletions
14
paper/src/main/java/de/rexlmanu/fairychat/plugin/paper/DefaultChatRenderer.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,14 @@ | ||
package de.rexlmanu.fairychat.plugin.paper; | ||
|
||
import net.kyori.adventure.audience.Audience; | ||
import net.kyori.adventure.text.Component; | ||
import org.bukkit.entity.Player; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public interface DefaultChatRenderer { | ||
Component render( | ||
@NotNull Player source, | ||
@NotNull Component sourceDisplayName, | ||
@NotNull Component message, | ||
@NotNull Audience viewer); | ||
} |
37 changes: 37 additions & 0 deletions
37
paper/src/main/java/de/rexlmanu/fairychat/plugin/paper/Environment.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,37 @@ | ||
package de.rexlmanu.fairychat.plugin.paper; | ||
|
||
public enum Environment { | ||
SPIGOT, | ||
PAPER, | ||
UNKNOWN; | ||
|
||
public static final Environment ENVIRONMENT = detectEnvironment(); | ||
|
||
public boolean isPaper() { | ||
return this == PAPER; | ||
} | ||
|
||
public boolean isSpigot() { | ||
return this == SPIGOT; | ||
} | ||
|
||
private static Environment detectEnvironment() { | ||
if (hasClass("com.destroystokyo.paper.PaperConfig") | ||
|| hasClass("io.papermc.paper.configuration.Configuration")) { | ||
return PAPER; | ||
} else if (hasClass("org.spigotmc.SpigotConfig")) { | ||
return SPIGOT; | ||
} else { | ||
return UNKNOWN; | ||
} | ||
} | ||
|
||
private static boolean hasClass(String className) { | ||
try { | ||
Class.forName(className); | ||
return true; | ||
} catch (ClassNotFoundException e) { | ||
return false; | ||
} | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
paper/src/main/java/de/rexlmanu/fairychat/plugin/paper/FairyChatLoader.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,49 @@ | ||
package de.rexlmanu.fairychat.plugin.paper; | ||
|
||
import com.google.gson.Gson; | ||
import io.papermc.paper.plugin.loader.PluginClasspathBuilder; | ||
import io.papermc.paper.plugin.loader.PluginLoader; | ||
import io.papermc.paper.plugin.loader.library.impl.MavenLibraryResolver; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.stream.Stream; | ||
import org.eclipse.aether.artifact.DefaultArtifact; | ||
import org.eclipse.aether.graph.Dependency; | ||
import org.eclipse.aether.repository.RemoteRepository; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
@SuppressWarnings("UnstableApiUsage") | ||
public class FairyChatLoader implements PluginLoader { | ||
@Override | ||
public void classloader(@NotNull PluginClasspathBuilder classpathBuilder) { | ||
MavenLibraryResolver resolver = new MavenLibraryResolver(); | ||
PluginLibraries pluginLibraries = this.load(); | ||
pluginLibraries.asDependencies().forEach(resolver::addDependency); | ||
pluginLibraries.asRepositories().forEach(resolver::addRepository); | ||
classpathBuilder.addLibrary(resolver); | ||
} | ||
|
||
public PluginLibraries load() { | ||
try (var inputStream = this.getClass().getResourceAsStream("/paper-libraries.json")) { | ||
return new Gson() | ||
.fromJson( | ||
new InputStreamReader(inputStream, StandardCharsets.UTF_8), PluginLibraries.class); | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
private record PluginLibraries(Map<String, String> repositories, List<String> dependencies) { | ||
public Stream<Dependency> asDependencies() { | ||
return this.dependencies.stream().map(d -> new Dependency(new DefaultArtifact(d), null)); | ||
} | ||
|
||
public Stream<RemoteRepository> asRepositories() { | ||
return this.repositories.entrySet().stream() | ||
.map(e -> new RemoteRepository.Builder(e.getKey(), "default", e.getValue()).build()); | ||
} | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...ility/scheduler/FoliaPluginScheduler.java → ...at/plugin/paper/FoliaPluginScheduler.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
50 changes: 50 additions & 0 deletions
50
paper/src/main/java/de/rexlmanu/fairychat/plugin/paper/PaperAsyncChatHandler.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,50 @@ | ||
package de.rexlmanu.fairychat.plugin.paper; | ||
|
||
import io.papermc.paper.event.player.AsyncChatEvent; | ||
import java.util.Set; | ||
import java.util.function.Consumer; | ||
import lombok.Data; | ||
import lombok.RequiredArgsConstructor; | ||
import net.kyori.adventure.audience.Audience; | ||
import net.kyori.adventure.text.Component; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.EventPriority; | ||
import org.bukkit.event.Listener; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
@RequiredArgsConstructor | ||
public class PaperAsyncChatHandler implements Listener { | ||
@RequiredArgsConstructor | ||
@Data | ||
public static class WrappedAsyncChatEvent { | ||
private final AsyncChatEvent event; | ||
|
||
public Player getPlayer() { | ||
return this.event.getPlayer(); | ||
} | ||
|
||
public void setCancelled(boolean cancelled) { | ||
this.event.setCancelled(cancelled); | ||
} | ||
|
||
public void renderer(DefaultChatRenderer renderer) { | ||
this.event.renderer(renderer::render); | ||
} | ||
|
||
public @NotNull Set<Audience> viewers() { | ||
return this.event.viewers(); | ||
} | ||
|
||
public Component message() { | ||
return this.event.message(); | ||
} | ||
} | ||
|
||
private final Consumer<WrappedAsyncChatEvent> eventConsumer; | ||
|
||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) | ||
public void handle(AsyncChatEvent event) { | ||
this.eventConsumer.accept(new WrappedAsyncChatEvent(event)); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
paper/src/main/java/de/rexlmanu/fairychat/plugin/paper/PluginMetaFactory.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,15 @@ | ||
package de.rexlmanu.fairychat.plugin.paper; | ||
|
||
import lombok.experimental.UtilityClass; | ||
import org.bukkit.plugin.java.JavaPlugin; | ||
|
||
@UtilityClass | ||
public class PluginMetaFactory { | ||
public AdaptPluginMeta create(JavaPlugin javaPlugin) { | ||
if (Environment.ENVIRONMENT.isPaper()) { | ||
return new AdaptPluginMeta(javaPlugin.getPluginMeta().getVersion()); | ||
} | ||
|
||
return new AdaptPluginMeta(javaPlugin.getDescription().getVersion()); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...in/utility/scheduler/PluginScheduler.java → ...irychat/plugin/paper/PluginScheduler.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
Oops, something went wrong.