Compare commits
16
Commits
1.1.0
...
feat/extensions
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
17a2ff73b2 | ||
|
|
e8635bc6c8 | ||
|
|
a1e95295cc | ||
|
|
dac6354071 | ||
|
|
01bb19213c | ||
|
|
6ff764bf4c | ||
|
|
4a509e63a2 | ||
|
|
f9d3f01a34 | ||
|
|
e5cf5001eb | ||
|
|
a762a68901 | ||
|
|
20b7d92710 | ||
|
|
d0edacfafd | ||
|
|
43c034fc0b | ||
|
|
2337525e25 | ||
|
|
0bb6f6264a | ||
|
|
24a7591a0f |
No files matched your search
@@ -0,0 +1,13 @@
|
||||
# These are supported funding model platforms
|
||||
|
||||
github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
|
||||
patreon: # Replace with a single Patreon username
|
||||
open_collective: # Replace with a single Open Collective username
|
||||
ko_fi: # Replace with a single Ko-fi username
|
||||
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
|
||||
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
|
||||
liberapay: # Replace with a single Liberapay username
|
||||
issuehunt: # Replace with a single IssueHunt username
|
||||
otechie: # Replace with a single Otechie username
|
||||
lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry
|
||||
custom: https://paypal.me/4drian3d # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
|
||||
+16
-11
@@ -3,16 +3,21 @@ plugins {
|
||||
`maven-publish`
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compileOnly("net.kyori:adventure-api:4.10.1")
|
||||
compileOnly("net.kyori:adventure-text-minimessage:4.10.1")
|
||||
compileOnly("net.kyori:adventure-text-serializer-legacy:4.10.1")
|
||||
compileOnly("net.kyori:adventure-api:4.11.0")
|
||||
compileOnly("net.kyori:adventure-text-minimessage:4.11.0")
|
||||
compileOnly("net.kyori:adventure-text-serializer-legacy:4.11.0")
|
||||
compileOnly(project(":miniplaceholders-connect"))
|
||||
implementation("com.google.code.gson:gson:2.9.1")
|
||||
testImplementation(platform("org.junit:junit-bom:5.8.1"))
|
||||
testImplementation("org.junit.jupiter:junit-jupiter")
|
||||
testImplementation("net.kyori:adventure-api:4.10.1")
|
||||
testImplementation("net.kyori:adventure-text-minimessage:4.10.1")
|
||||
testImplementation("net.kyori:adventure-text-serializer-plain:4.10.1")
|
||||
testImplementation("net.kyori:adventure-api:4.11.0")
|
||||
testImplementation("net.kyori:adventure-text-minimessage:4.11.0")
|
||||
testImplementation("net.kyori:adventure-text-serializer-plain:4.11.0")
|
||||
}
|
||||
|
||||
tasks {
|
||||
@@ -29,9 +34,11 @@ jmh {
|
||||
iterations.set(2)
|
||||
fork.set(2)
|
||||
}
|
||||
|
||||
java {
|
||||
withSourcesJar()
|
||||
withJavadocJar()
|
||||
toolchain.languageVersion.set(JavaLanguageVersion.of(17))
|
||||
}
|
||||
|
||||
val projectGroup: String = project.group as String
|
||||
@@ -50,13 +57,11 @@ publishing {
|
||||
|
||||
tasks.withType<Javadoc> {
|
||||
(options as StandardJavadocDocletOptions).links(
|
||||
"https://jd.adventure.kyori.net/api/4.10.1/",
|
||||
"https://jd.adventure.kyori.net/text-minimessage/4.10.1/"
|
||||
"https://jd.adventure.kyori.net/api/4.10.0/",
|
||||
"https://jd.adventure.kyori.net/text-minimessage/4.11.0/"
|
||||
)
|
||||
}
|
||||
|
||||
java.toolchain.languageVersion.set(JavaLanguageVersion.of(17))
|
||||
|
||||
tasks {
|
||||
compileJava {
|
||||
options.encoding = Charsets.UTF_8.name()
|
||||
@@ -69,4 +74,4 @@ tasks {
|
||||
processResources {
|
||||
filteringCharset = Charsets.UTF_8.name()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,7 @@ import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import me.dreamerzero.miniplaceholders.api.enums.Platform;
|
||||
import me.dreamerzero.miniplaceholders.api.utils.Resolvers;
|
||||
import me.dreamerzero.miniplaceholders.connect.InternalPlatform;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||
@@ -34,7 +35,7 @@ public final class MiniPlaceholders {
|
||||
* @return the platform
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static @NotNull Platform getPlatform(){
|
||||
public static @NotNull Platform getPlatform() {
|
||||
return InternalPlatform.platform() == InternalPlatform.PAPER
|
||||
? Platform.PAPER
|
||||
: Platform.VELOCITY;
|
||||
@@ -51,10 +52,13 @@ public final class MiniPlaceholders {
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static @NotNull TagResolver getGlobalPlaceholders() {
|
||||
final TagResolver.Builder resolvers = TagResolver.builder();
|
||||
expansions.forEach(exp -> resolvers.resolver(exp.globalPlaceholders()));
|
||||
|
||||
return resolvers.build();
|
||||
final TagResolver.Builder builder = TagResolver.builder();
|
||||
for (final Expansion expansion : expansions) {
|
||||
final TagResolver resolver = expansion.globalPlaceholders();
|
||||
if (resolver != TagResolver.empty())
|
||||
builder.resolver(resolver);
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -72,8 +76,11 @@ public final class MiniPlaceholders {
|
||||
Objects.requireNonNull(audience, () -> "audience cannot be null");
|
||||
|
||||
final TagResolver.Builder resolvers = TagResolver.builder();
|
||||
expansions.forEach(exp -> resolvers.resolver(exp.audiencePlaceholders(audience)));
|
||||
|
||||
for (Expansion expansion : expansions) {
|
||||
final TagResolver resolver = expansion.audiencePlaceholders(audience);
|
||||
if (resolver != TagResolver.empty())
|
||||
resolvers.resolver(resolver);
|
||||
}
|
||||
return resolvers.build();
|
||||
}
|
||||
|
||||
@@ -93,10 +100,15 @@ public final class MiniPlaceholders {
|
||||
Objects.requireNonNull(audience, () -> "audience cannot be null");
|
||||
Objects.requireNonNull(otherAudience, () -> "otherAudience cannot be null");
|
||||
|
||||
final TagResolver.Builder resolvers = TagResolver.builder();
|
||||
expansions.forEach(exp -> resolvers.resolver(exp.relationalPlaceholders(audience, otherAudience)));
|
||||
final TagResolver.Builder builder = TagResolver.builder();
|
||||
for (final Expansion expansion : expansions) {
|
||||
Resolvers.applyIfNotEmpty(
|
||||
expansion.relationalPlaceholders(audience, otherAudience),
|
||||
builder
|
||||
);
|
||||
}
|
||||
|
||||
return resolvers.build();
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -122,9 +134,9 @@ public final class MiniPlaceholders {
|
||||
Objects.requireNonNull(audience, () -> "audience cannot be null");
|
||||
final TagResolver.Builder builder = TagResolver.builder();
|
||||
|
||||
for(final Expansion expansion : expansions) {
|
||||
builder.resolver(expansion.audiencePlaceholders(audience));
|
||||
builder.resolver(expansion.globalPlaceholders());
|
||||
for (final Expansion expansion : expansions) {
|
||||
Resolvers.applyIfNotEmpty(expansion.audiencePlaceholders(audience), builder);
|
||||
Resolvers.applyIfNotEmpty(expansion.globalPlaceholders(), builder);
|
||||
}
|
||||
|
||||
return builder.build();
|
||||
@@ -157,10 +169,10 @@ public final class MiniPlaceholders {
|
||||
Objects.requireNonNull(otherAudience, () -> "otherAudience cannot be null");
|
||||
|
||||
final TagResolver.Builder builder = TagResolver.builder();
|
||||
for(final Expansion expansion : expansions) {
|
||||
builder.resolver(expansion.audiencePlaceholders(audience));
|
||||
builder.resolver(expansion.relationalPlaceholders(audience, otherAudience));
|
||||
builder.resolver(expansion.globalPlaceholders());
|
||||
for (final Expansion expansion : expansions) {
|
||||
Resolvers.applyIfNotEmpty(expansion.audiencePlaceholders(audience), builder);
|
||||
Resolvers.applyIfNotEmpty(expansion.relationalPlaceholders(audience, otherAudience), builder);
|
||||
Resolvers.applyIfNotEmpty(expansion.globalPlaceholders(), builder);
|
||||
}
|
||||
|
||||
return builder.build();
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package me.dreamerzero.miniplaceholders.api.annotation;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import me.dreamerzero.miniplaceholders.api.enums.Platform;
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.TYPE)
|
||||
public @interface Extension {
|
||||
String name();
|
||||
|
||||
Platform[] platform();
|
||||
|
||||
String version() default "";
|
||||
}
|
||||
+63
@@ -0,0 +1,63 @@
|
||||
package me.dreamerzero.miniplaceholders.api.annotation.processor;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import javax.annotation.processing.AbstractProcessor;
|
||||
import javax.annotation.processing.ProcessingEnvironment;
|
||||
import javax.annotation.processing.RoundEnvironment;
|
||||
import javax.annotation.processing.SupportedAnnotationTypes;
|
||||
import javax.lang.model.element.Element;
|
||||
import javax.lang.model.element.ElementKind;
|
||||
import javax.lang.model.element.Name;
|
||||
import javax.lang.model.element.TypeElement;
|
||||
import javax.tools.Diagnostic;
|
||||
import javax.tools.FileObject;
|
||||
import javax.tools.StandardLocation;
|
||||
|
||||
import me.dreamerzero.miniplaceholders.api.annotation.Extension;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.Writer;
|
||||
import java.util.Set;
|
||||
|
||||
@SupportedAnnotationTypes({"me.dreamerzero.miniplaceholders.api.annotation.Extension"})
|
||||
public class ExtensionAnnotationProcessor extends AbstractProcessor {
|
||||
private ProcessingEnvironment environment;
|
||||
|
||||
@Override
|
||||
public synchronized void init(ProcessingEnvironment processingEnv) {
|
||||
this.environment = processingEnv;
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
|
||||
if (roundEnv.processingOver()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (Element element : roundEnv.getElementsAnnotatedWith(Extension.class)) {
|
||||
if (element.getKind() != ElementKind.CLASS) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Extension extension = element.getAnnotation(Extension.class);
|
||||
Name name = ((TypeElement) element).getQualifiedName();
|
||||
|
||||
try {
|
||||
FileObject object = environment.getFiler()
|
||||
.createResource(StandardLocation.CLASS_OUTPUT, "", "miniplaceholders-extension.json");
|
||||
try (Writer writer = new BufferedWriter(object.openWriter())) {
|
||||
new Gson().toJson(new ProcessedExtension(
|
||||
extension.name(),
|
||||
extension.version(),
|
||||
name.toString(),
|
||||
extension.platform()),
|
||||
writer);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
environment.getMessager().printMessage(Diagnostic.Kind.ERROR, "Cannot generate extension file");
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
package me.dreamerzero.miniplaceholders.api.annotation.processor;
|
||||
|
||||
import me.dreamerzero.miniplaceholders.api.enums.Platform;
|
||||
|
||||
public final class ProcessedExtension {
|
||||
private final String name;
|
||||
private final String version;
|
||||
private final Platform[] platforms;
|
||||
private final String clazz;
|
||||
|
||||
ProcessedExtension(String name, String version, String clazz, Platform... platforms) {
|
||||
this.name = name;
|
||||
this.version = version;
|
||||
this.platforms = platforms;
|
||||
this.clazz = clazz;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
public String getVersion() {
|
||||
return version;
|
||||
}
|
||||
public Platform[] getPlatforms() {
|
||||
return platforms;
|
||||
}
|
||||
public String getClazz() {
|
||||
return this.clazz;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package me.dreamerzero.miniplaceholders.api.utils;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||
|
||||
/**
|
||||
* Class of utilities to manage TagResolvers
|
||||
* @since 1.2.0
|
||||
*/
|
||||
public final class Resolvers {
|
||||
private Resolvers() {}
|
||||
|
||||
/**
|
||||
* Check if the TagResolver is an instance of TagResolver.empty(),
|
||||
* that is, it will always return null
|
||||
* @param resolver the resolver to check
|
||||
* @return true if the TagResolver is the same as TagResolver.empty(), else false
|
||||
* @since 1.2.0
|
||||
*/
|
||||
public static boolean isEmpty(final @NotNull TagResolver resolver) {
|
||||
return resolver == TagResolver.empty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the TagResolver provided is not a TagResolver.empty()
|
||||
* @param resolver the resolver to check
|
||||
* @return false if the TagResolver is the same as TagResolver.empty(), else true
|
||||
* @since 1.2.0
|
||||
*
|
||||
*/
|
||||
public static boolean isNotEmpty(final @NotNull TagResolver resolver) {
|
||||
return resolver != TagResolver.empty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies a TagResolver to a TagResolver.Builder in case it is not a TagResolver.empty()
|
||||
* @param resolver the resolver to check
|
||||
* @param builder the resolver that can be added to the builder
|
||||
* @since 1.2.0
|
||||
*/
|
||||
public static void applyIfNotEmpty(final @NotNull TagResolver resolver, final @NotNull TagResolver.Builder builder) {
|
||||
if (isNotEmpty(resolver)) {
|
||||
builder.resolver(resolver);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
module me.dreamerzero.miniplaceholders.api {
|
||||
requires net.kyori.adventure;
|
||||
requires net.kyori.examination.api;
|
||||
requires net.kyori.adventure.text.minimessage;
|
||||
requires static org.jetbrains.annotations;
|
||||
requires me.dreamerzero.miniplaceholders.connect;
|
||||
requires java.base;
|
||||
requires java.compiler;
|
||||
requires com.google.gson;
|
||||
|
||||
exports me.dreamerzero.miniplaceholders.api;
|
||||
exports me.dreamerzero.miniplaceholders.api.enums;
|
||||
exports me.dreamerzero.miniplaceholders.api.utils;
|
||||
exports me.dreamerzero.miniplaceholders.api.placeholder;
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
me.dreamerzero.miniplaceholders.api.annotation.processor.ExtensionAnnotationProcessor
|
||||
@@ -8,7 +8,7 @@ import org.junit.jupiter.api.Test;
|
||||
import me.dreamerzero.miniplaceholders.api.Expansion;
|
||||
import me.dreamerzero.miniplaceholders.api.utils.TagsUtils;
|
||||
|
||||
public class ExpansionsTest {
|
||||
class ExpansionsTest {
|
||||
@Test
|
||||
@DisplayName("Expansion Equality")
|
||||
void equalsExpansions(){
|
||||
|
||||
@@ -11,9 +11,9 @@ import me.dreamerzero.miniplaceholders.api.utils.TagsUtils;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||
|
||||
public class MiniPlaceholdersTest {
|
||||
class MiniPlaceholdersTest {
|
||||
@Test
|
||||
@Disabled("The tagresolvers implemented classes does not implement the equals method")
|
||||
@Disabled("Cannot correctly calculate the equity of 2 TagResolvers obtained in different ways")
|
||||
void methodEquality(){
|
||||
Expansion.builder("equality")
|
||||
.audiencePlaceholder("audience", TagsUtils.NULL_AUDIENCE_PLACEHOLDER)
|
||||
|
||||
@@ -15,7 +15,7 @@ import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.text.minimessage.tag.Tag;
|
||||
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
|
||||
|
||||
public class PlaceholderTest {
|
||||
class PlaceholderTest {
|
||||
|
||||
@Test
|
||||
@DisplayName("Audience Placeholder Test")
|
||||
|
||||
@@ -15,7 +15,7 @@ import net.kyori.adventure.text.minimessage.Context;
|
||||
import net.kyori.adventure.text.minimessage.tag.Tag;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.ArgumentQueue;
|
||||
|
||||
public class ThrowableTest {
|
||||
class ThrowableTest {
|
||||
@Test
|
||||
@DisplayName("Nullable Exception")
|
||||
void throwOnNull(){
|
||||
|
||||
+6
-2
@@ -8,11 +8,16 @@ plugins {
|
||||
allprojects {
|
||||
apply(plugin = "java")
|
||||
group = "me.dreamerzero.miniplaceholders"
|
||||
version = "1.1.0"
|
||||
version = "1.2.0"
|
||||
description = "MiniPlaceholders"
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
shadow(project(":miniplaceholders-connect"))
|
||||
shadow(project(":miniplaceholders-api"))
|
||||
shadow(project(":miniplaceholders-common"))
|
||||
shadow(project(":miniplaceholders-velocity"))
|
||||
@@ -21,7 +26,6 @@ dependencies {
|
||||
|
||||
subprojects {
|
||||
repositories {
|
||||
mavenCentral()
|
||||
maven("https://papermc.io/repo/repository/maven-public/")
|
||||
maven("https://repo.maven.apache.org/maven2/")
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
plugins {
|
||||
id("net.kyori.blossom") version "1.3.0"
|
||||
id("net.kyori.blossom") version "1.3.1"
|
||||
}
|
||||
|
||||
repositories {
|
||||
@@ -8,12 +8,12 @@ repositories {
|
||||
|
||||
dependencies {
|
||||
implementation(project(":miniplaceholders-api"))
|
||||
compileOnly("net.kyori:adventure-api:4.10.1")
|
||||
compileOnly("net.kyori:adventure-text-minimessage:4.10.1")
|
||||
compileOnly("net.kyori:adventure-api:4.11.0")
|
||||
compileOnly("net.kyori:adventure-text-minimessage:4.11.0")
|
||||
compileOnly("com.mojang:brigadier:1.0.18")
|
||||
}
|
||||
|
||||
blossom{
|
||||
blossom {
|
||||
replaceToken("{version}", version)
|
||||
replaceTokenIn("src/main/java/me/dreamerzero/miniplaceholders/common/PluginConstants.java")
|
||||
}
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
package me.dreamerzero.miniplaceholders.extension;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.DirectoryStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import me.dreamerzero.miniplaceholders.api.annotation.Extension;
|
||||
|
||||
public final class Loader {
|
||||
private Loader() {}
|
||||
public static Extension[] loadExtensions(Path extensionsPath) {
|
||||
List<Extension> extensions = new ArrayList<>();
|
||||
try (DirectoryStream<Path> stream = Files.newDirectoryStream(extensionsPath, (file) -> file.toString().endsWith(".jar"))) {
|
||||
for (Path ext : stream) {
|
||||
|
||||
}
|
||||
} catch(IOException e) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
module me.dreamerzero.miniplaceholders.connect {
|
||||
//TODO: exports to
|
||||
exports me.dreamerzero.miniplaceholders.connect;
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
# run-paper files
|
||||
/run
|
||||
@@ -1,6 +1,6 @@
|
||||
plugins {
|
||||
id("net.minecrell.plugin-yml.bukkit") version "0.5.1"
|
||||
id("io.papermc.paperweight.userdev") version "1.3.5"
|
||||
id("net.minecrell.plugin-yml.bukkit") version "0.5.2"
|
||||
id("io.papermc.paperweight.userdev") version "1.3.8"
|
||||
id("xyz.jpenilla.run-paper") version "1.0.6"
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ dependencies {
|
||||
compileOnly(project(":miniplaceholders-common"))
|
||||
compileOnly(project(":miniplaceholders-api"))
|
||||
compileOnly(project(":miniplaceholders-connect"))
|
||||
paperDevBundle("1.18.2-R0.1-SNAPSHOT")
|
||||
paperDevBundle("1.19.1-R0.1-SNAPSHOT")
|
||||
}
|
||||
|
||||
val pluginVersion: String = version as String
|
||||
@@ -33,5 +33,8 @@ tasks {
|
||||
|
||||
options.release.set(17)
|
||||
}
|
||||
runServer {
|
||||
minecraftVersion("1.19.1")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
package me.dreamerzero.miniplaceholders.paper;
|
||||
|
||||
import java.math.RoundingMode;
|
||||
import java.text.NumberFormat;
|
||||
import java.text.DecimalFormat;
|
||||
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.craftbukkit.v1_18_R2.CraftServer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
@@ -19,10 +18,11 @@ import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import net.kyori.adventure.text.minimessage.tag.Tag;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
|
||||
public final class PaperPlugin extends JavaPlugin implements PlaceholdersPlugin, Listener {
|
||||
private final NumberFormat tpsFormat = NumberFormat.getInstance();
|
||||
private final NumberFormat msptFormat = NumberFormat.getInstance();
|
||||
private final DecimalFormat tpsFormat = new DecimalFormat("###.##");
|
||||
private final DecimalFormat msptFormat = new DecimalFormat("###.###");
|
||||
|
||||
@Override
|
||||
public void onEnable(){
|
||||
@@ -30,11 +30,8 @@ public final class PaperPlugin extends JavaPlugin implements PlaceholdersPlugin,
|
||||
InternalPlatform.platform(InternalPlatform.PAPER);
|
||||
this.getServer().getPluginManager().registerEvents(this, this);
|
||||
|
||||
tpsFormat.setRoundingMode(RoundingMode.DOWN);
|
||||
tpsFormat.setMaximumFractionDigits(2);
|
||||
|
||||
msptFormat.setRoundingMode(RoundingMode.DOWN);
|
||||
msptFormat.setMaximumFractionDigits(3);
|
||||
tpsFormat.setRoundingMode(RoundingMode.HALF_UP);
|
||||
msptFormat.setRoundingMode(RoundingMode.HALF_UP);
|
||||
|
||||
this.loadDefaultExpansions();
|
||||
this.registerPlatformCommand();
|
||||
@@ -48,9 +45,9 @@ public final class PaperPlugin extends JavaPlugin implements PlaceholdersPlugin,
|
||||
.globalPlaceholder("version", TagsUtils.staticTag(this.getServer().getVersion()))
|
||||
.globalPlaceholder("max_players", (queue, ctx) -> TagsUtils.staticTag(Component.text(this.getServer().getMaxPlayers())))
|
||||
.globalPlaceholder("unique_joins", (queue, ctx) -> TagsUtils.staticTag(Component.text(this.getServer().getOfflinePlayers().length)))
|
||||
.globalPlaceholder("tps_1", (queue, ctx) -> TagsUtils.staticTag(tpsFormat.format(this.getCraftServer().getHandle().getServer().recentTps[0])))
|
||||
.globalPlaceholder("tps_5", (queue, ctx) -> TagsUtils.staticTag(tpsFormat.format(this.getCraftServer().getHandle().getServer().recentTps[1])))
|
||||
.globalPlaceholder("tps_15", (queue, ctx) -> TagsUtils.staticTag(tpsFormat.format(this.getCraftServer().getHandle().getServer().recentTps[2])))
|
||||
.globalPlaceholder("tps_1", (queue, ctx) -> TagsUtils.staticTag(tpsFormat.format(this.getServer().getTPS()[0])))
|
||||
.globalPlaceholder("tps_5", (queue, ctx) -> TagsUtils.staticTag(tpsFormat.format(this.getServer().getTPS()[1])))
|
||||
.globalPlaceholder("tps_15", (queue, ctx) -> TagsUtils.staticTag(tpsFormat.format(this.getServer().getTPS()[2])))
|
||||
.globalPlaceholder("has_whitelist", (queue, ctx) -> TagsUtils.staticTag(Component.text(this.getServer().hasWhitelist())))
|
||||
.globalPlaceholder("total_chunks", (queue, ctx) -> {
|
||||
int chunkCount = 0;
|
||||
@@ -80,9 +77,9 @@ public final class PaperPlugin extends JavaPlugin implements PlaceholdersPlugin,
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("all")
|
||||
@SuppressWarnings({"sonarlint(java:s1874)", "deprecation", /*TODO: replace with Java(536871800) */ "all"})
|
||||
public void registerPlatformCommand() {
|
||||
this.getCraftServer().getServer()
|
||||
MinecraftServer.getServer()
|
||||
.vanillaCommandDispatcher
|
||||
.getDispatcher()
|
||||
.register(new PlaceholdersCommand<>(
|
||||
@@ -92,8 +89,4 @@ public final class PaperPlugin extends JavaPlugin implements PlaceholdersPlugin,
|
||||
).placeholderTestBuilder("miniplaceholders")
|
||||
);
|
||||
}
|
||||
|
||||
private CraftServer getCraftServer(){
|
||||
return (CraftServer)this.getServer();
|
||||
}
|
||||
}
|
||||
+6
-10
@@ -7,14 +7,10 @@ pluginManagement {
|
||||
|
||||
rootProject.name = "miniplaceholders-parent"
|
||||
|
||||
include("miniplaceholders-connect")
|
||||
include("miniplaceholders-api")
|
||||
include("miniplaceholders-common")
|
||||
include("miniplaceholders-paper")
|
||||
include("miniplaceholders-velocity")
|
||||
val modules = listOf("connect", "api", "common", "paper", "velocity")
|
||||
|
||||
modules.forEach {
|
||||
include("miniplaceholders-$it")
|
||||
project(":miniplaceholders-$it").projectDir = file(it)
|
||||
}
|
||||
|
||||
project(":miniplaceholders-connect").projectDir = file("connect")
|
||||
project(":miniplaceholders-api").projectDir = file("api")
|
||||
project(":miniplaceholders-common").projectDir = file("common")
|
||||
project(":miniplaceholders-velocity").projectDir = file("velocity")
|
||||
project(":miniplaceholders-paper").projectDir = file("paper")
|
||||
Reference in new issue
Block a user