Compare commits

..
Author SHA1 Message Date
Adrian 37b4ddcd84 feat(fabric): Initial Fabric Client Mod 2023-11-17 09:11:19 -05:00
37 changed files with 854 additions and 247 deletions

No files matched your search

-1
View File
@@ -1 +0,0 @@
.gitea/CODEOWNERS linguist-detectable=false
-3
View File
@@ -1,3 +0,0 @@
# Pull requests request review from the eligible staff team(s).
# One approval from either an Admin or Developer satisfies branch protection.
* @trueog/Admins @trueog/Developers
+3 -3
View File
@@ -11,21 +11,21 @@ jobs:
uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
uses: actions/setup-java@v3
with:
java-version: 17
distribution: 'temurin'
cache: 'gradle'
- name: Build with Gradle
uses: nick-invision/retry@v3
uses: nick-invision/retry@v2
with:
timeout_minutes: 10
max_attempts: 2
command: gradle build
- name: Upload Artifacts
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@v3
with:
name: MiniPlaceholders
path: jar/MiniPlaceholders-*.jar
@@ -43,20 +43,6 @@ public sealed interface Expansion permits ExpansionImpl {
*/
@NotNull String name();
/**
* Get the author of this expansion
* @return the author or null
* @since 2.3.0
*/
@Nullable String author();
/**
* Get the version of this expansion
* @return the version or null
* @since 2.3.0
*/
@Nullable String version();
/**
* Get the {@link TagResolver} of the desired {@link Audience}
* @param audience the audience
@@ -231,25 +217,5 @@ public sealed interface Expansion permits ExpansionImpl {
*/
@Contract("_ -> this")
@NotNull Builder filter(final @Nullable Predicate<@NotNull Audience> predicate);
/**
* Sets the author of this expansion
*
* @param author the author of this expansion
* @return the {@link Builder} itself
* @since 2.3.0
*/
@Contract("_ -> this")
@NotNull Builder author(final @Nullable String author);
/**
* Sets the version of this expansion
*
* @param version the version of this expansion
* @return the {@link Builder} itself
* @since 2.3.0
*/
@Contract("_ -> this")
@NotNull Builder version(final @Nullable String version);
}
}
@@ -27,8 +27,6 @@ final class ExpansionImpl implements Expansion {
private final TagResolver globalPlaceholders;
private final Class<? extends Audience> filterClass;
private final Predicate<Audience> predicateFilter;
private final String author;
private final String version;
ExpansionImpl(
@NotNull final String expansionName,
@@ -36,10 +34,7 @@ final class ExpansionImpl implements Expansion {
@Nullable final Collection<Tags.Relational> relationalPlaceholders,
@Nullable final TagResolver globalPlaceholders,
@Nullable final Class<? extends Audience> filterClass,
@Nullable final Predicate<Audience> predicateFilter,
@Nullable final String author,
@Nullable final String version
) {
@Nullable final Predicate<Audience> predicateFilter){
this.name = expansionName+"-";
this.audiencePlaceholders = audiencePlaceholders != null
? audiencePlaceholders.toArray(EMPTY_SINGLE_AUDIENCE)
@@ -50,8 +45,6 @@ final class ExpansionImpl implements Expansion {
this.globalPlaceholders = globalPlaceholders;
this.filterClass = filterClass;
this.predicateFilter = predicateFilter;
this.author = author;
this.version = version;
}
@Override
@@ -59,16 +52,6 @@ final class ExpansionImpl implements Expansion {
return this.name;
}
@Override
public @Nullable String author(){
return this.author;
}
@Override
public @Nullable String version(){
return this.version;
}
@Override
public @NotNull TagResolver audiencePlaceholders(@NotNull Audience audience) {
if (audiencePlaceholders.length == 0) return TagResolver.empty();
@@ -153,8 +136,6 @@ final class ExpansionImpl implements Expansion {
private TagResolver.Builder globalPlaceholders;
private Class<? extends Audience> filterClass;
private Predicate<Audience> predicateFilter;
private String author;
private String version;
Builder(@NotNull final String name){
this.expansionName = nonNullOrEmptyString(name, "Expansion name")
@@ -217,18 +198,6 @@ final class ExpansionImpl implements Expansion {
return this;
}
@Override
public Expansion.@NotNull Builder author(@Nullable final String author) {
this.author = author;
return this;
}
@Override
public Expansion.@NotNull Builder version(@Nullable final String version) {
this.version = version;
return this;
}
@Override
public @NotNull Expansion build(){
return new ExpansionImpl(
@@ -237,9 +206,7 @@ final class ExpansionImpl implements Expansion {
this.relationalPlaceholders,
this.globalPlaceholders != null ? this.globalPlaceholders.build() : TagResolver.empty(),
this.filterClass,
this.predicateFilter,
this.version,
this.author
this.predicateFilter
);
}
}
@@ -7,9 +7,6 @@ import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.function.Function;
import static java.util.Objects.requireNonNull;
import static net.kyori.adventure.text.minimessage.MiniMessage.miniMessage;
/**
@@ -71,10 +68,7 @@ public final class LegacyUtils {
* @return a parsed string
* @since 2.2.1
*/
public static @NotNull Component parsePossibleLegacy(
@Nullable String string,
final @NotNull Context context
) {
public static @NotNull Component parsePossibleLegacy(@Nullable String string, @NotNull final Context context) {
if (string == null || string.isEmpty()) return Component.empty();
if (string.indexOf(LegacyComponentSerializer.SECTION_CHAR) != -1) {
string = string.replace(LegacyComponentSerializer.SECTION_CHAR, LegacyComponentSerializer.AMPERSAND_CHAR);
@@ -103,10 +97,7 @@ public final class LegacyUtils {
* @return a parsed string
* @since 2.2.1
*/
public static @NotNull Component parsePossibleLegacy(
@Nullable String string,
final @NotNull TagResolver resolver
) {
public static @NotNull Component parsePossibleLegacy(@Nullable String string, @NotNull final TagResolver resolver) {
if (string == null || string.isEmpty()) return Component.empty();
if (string.indexOf(LegacyComponentSerializer.SECTION_CHAR) != -1) {
string = string.replace(LegacyComponentSerializer.SECTION_CHAR, LegacyComponentSerializer.AMPERSAND_CHAR);
@@ -121,47 +112,4 @@ public final class LegacyUtils {
resolver
);
}
/**
* Checks if the provided string contains legacy formatting.
*
* @param string the string input
* @return whether the string has legacy content
* @see LegacyComponentSerializer#AMPERSAND_CHAR
* @see LegacyComponentSerializer#SECTION_CHAR
* @since 2.3.0
*/
public static boolean hasLegacyFormat(final String string) {
requireNonNull(string, "string");
return string.indexOf(LegacyComponentSerializer.SECTION_CHAR) != -1
|| string.indexOf(LegacyComponentSerializer.AMPERSAND_CHAR) != -1;
}
/**
* Maps the input to a type depending on whether it contains legacy formatting or not.
*
* @param string the string input
* @param legacyMapping the mapping function in case the string contains legacy formatting
* @param modernMapping the mapping function in case the string does not contain any legacy character type,
* being safe to use with MiniMessage
* @return the mapped result
* @param <R> the result type
* @see LegacyComponentSerializer#AMPERSAND_CHAR
* @see LegacyComponentSerializer#SECTION_CHAR
* @see #hasLegacyFormat(String)
* @since 2.3.0
*/
public static <R> R mapLegacyOrElse(
final @NotNull String string,
final @NotNull Function<String, R> legacyMapping,
final @NotNull Function<String, R> modernMapping
) {
requireNonNull(legacyMapping, "legacyMapping");
requireNonNull(modernMapping, "modernInput");
if (hasLegacyFormat(string)) {
return legacyMapping.apply(string);
} else {
return modernMapping.apply(string);
}
}
}
@@ -41,7 +41,6 @@ public final class TagsUtils {
* @return a new basic self closing Tag of a string
* @since 1.1.0
*/
@Deprecated
public static @NotNull Tag staticTag(@NotNull String string) {
return Tag.selfClosingInserting(Component.text(string));
}
@@ -52,7 +51,6 @@ public final class TagsUtils {
* @return a new basic self closing Tag of a component
* @since 1.1.0
*/
@Deprecated
public static @NotNull Tag staticTag(@NotNull Component component) {
return Tag.selfClosingInserting(component);
}
@@ -2,13 +2,10 @@ package io.github.miniplaceholders.test;
import io.github.miniplaceholders.api.utils.LegacyUtils;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.tag.Inserting;
import net.kyori.adventure.text.minimessage.tag.PreProcess;
import net.kyori.adventure.text.minimessage.tag.Tag;
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.Assertions.assertEquals;
class LegacyTest {
@Test
@@ -20,23 +17,4 @@ class LegacyTest {
assertEquals(expected, result);
}
@Test
void testMapLegacyOrElse() {
final String legacyInput = "&fhi <red>aaaa";
Tag legacyProcessedTag = LegacyUtils.mapLegacyOrElse(
legacyInput,
legacy -> Tag.inserting(LegacyUtils.parsePossibleLegacy(legacy)),
Tag::preProcessParsed
);
assertInstanceOf(Inserting.class, legacyProcessedTag);
final String modernInput = "<rainbow>aaaaaaaaaaaaa";
Tag modernProcessedTag = LegacyUtils.mapLegacyOrElse(
modernInput,
__ -> fail(),
Tag::preProcessParsed
);
assertInstanceOf(PreProcess.class, modernProcessedTag);
}
}
+2 -2
View File
@@ -14,6 +14,6 @@ repositories {
kotlin {
jvmToolchain {
languageVersion = JavaLanguageVersion.of(17)
languageVersion.set(JavaLanguageVersion.of(17))
}
}
}
+1 -1
View File
@@ -15,5 +15,5 @@ dependencyResolutionManagement {
}
plugins {
id("org.gradle.toolchains.foojay-resolver-convention") version "0.8.0"
id("org.gradle.toolchains.foojay-resolver-convention") version "0.7.0"
}
@@ -1,6 +1,6 @@
plugins {
id("miniplaceholders.base")
id("com.gradleup.shadow")
id("com.github.johnrengelman.shadow")
}
tasks {
@@ -18,4 +18,4 @@ tasks {
build {
dependsOn(shadowJar)
}
}
}
+1 -3
View File
@@ -1,7 +1,5 @@
plugins {
kotlin("jvm") version "2.1.21" apply false
eclipse
id("com.gradleup.shadow") version "8.3.8"
kotlin("jvm") version "1.9.20" apply false
}
tasks {
-9
View File
@@ -1,9 +0,0 @@
#!/usr/bin/env bash
VERSION="$1"
# Ensure the target directory exists
mkdir -p build/libs
# Copy and rename the jar, using $VERSION in the final filename
cp jar/MiniPlaceholders*.jar "build/libs/MiniPlaceholders-${VERSION}.jar"
+1
View File
@@ -0,0 +1 @@
/run
+61
View File
@@ -0,0 +1,61 @@
plugins {
id("miniplaceholders.auto.module")
id("fabric-loom")
alias(libs.plugins.shadow)
}
val shade: Configuration by configurations.creating
dependencies {
minecraft(libs.minecraft)
mappings(loom.officialMojangMappings())
modImplementation(libs.fabric.loader)
modImplementation(libs.fabric.api)
includeDependency(libs.adventure.platform.fabric)
includeDependency(libs.adventure.serializer.legacy)
includeDependency(libs.luckopermissionsapi)
includeDependency(libs.cloud.fabric)
includeDependency(libs.cloud.core)
includeDependency(libs.cloud.extras)
includeDependency(libs.desertwell)
shadeModule(projects.miniplaceholdersApi)
shadeModule(projects.miniplaceholdersCommon)
shadeModule(projects.miniplaceholdersConnect)
}
fun DependencyHandlerScope.shadeModule(module: ProjectDependency) {
shade(module) {
isTransitive = false
}
implementation(module) {
isTransitive = false
}
}
fun DependencyHandlerScope.includeDependency(dependency: Any) {
modImplementation(dependency)
include(dependency)
}
tasks {
processResources {
filteringCharset = Charsets.UTF_8.name()
filesMatching("fabric.mod.json") {
expand("version" to project.version)
}
}
remapJar {
inputFile.set(shadowJar.get().archiveFile)
archiveFileName.set("MiniPlaceholders-Fabric-${project.version}.jar")
destinationDirectory.set(file("${project.rootDir}/jar"))
}
shadowJar {
configurations = listOf(shade)
}
}
java {
withSourcesJar()
}
@@ -0,0 +1,56 @@
package io.github.miniplaceholders.fabric;
import cloud.commandframework.execution.AsynchronousCommandExecutionCoordinator;
import cloud.commandframework.fabric.FabricServerCommandManager;
import io.github.miniplaceholders.common.PlaceholdersCommand;
import io.github.miniplaceholders.common.PlaceholdersPlugin;
import io.github.miniplaceholders.connect.InternalPlatform;
import me.lucko.fabric.api.permissions.v0.Permissions;
import net.fabricmc.api.ClientModInitializer;
import net.minecraft.client.Minecraft;
import net.minecraft.commands.CommandSourceStack;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;
public final class FabricClientMod implements ClientModInitializer, PlaceholdersPlugin {
@Override
public void onInitializeClient() {
InternalPlatform.platform(InternalPlatform.FABRIC);
registerPlatformCommand();
}
@Override
public void loadDefaultExpansions() {
}
@Override
public void registerPlatformCommand() {
final FabricServerCommandManager<CommandSourceStack> commandManager = new FabricServerCommandManager<>(
AsynchronousCommandExecutionCoordinator.simpleCoordinator(),
Function.identity(),
Function.identity()
);
PlaceholdersCommand.<CommandSourceStack>builder()
.hasPermissionCheck((source, permission) -> Permissions.check(source, permission, 4))
.toAudience(string -> {
var server = Minecraft.getInstance().getSingleplayerServer();
if (server != null) {
return server.getPlayerList().getPlayerByName(string);
}
return Minecraft.getInstance().player;
})
.playerSuggestions(() -> {
var server = Minecraft.getInstance().getSingleplayerServer();
if (server != null) {
return new ArrayList<>(List.of(server.getPlayerList().getPlayerNamesArray()));
}
return new ArrayList<>();
})
.manager(commandManager)
.command("miniplaceholders")
.build()
.register();
}
}
@@ -0,0 +1,119 @@
package io.github.miniplaceholders.fabric;
import cloud.commandframework.execution.AsynchronousCommandExecutionCoordinator;
import cloud.commandframework.fabric.FabricServerCommandManager;
import io.github.miniplaceholders.api.Expansion;
import io.github.miniplaceholders.common.PlaceholdersCommand;
import io.github.miniplaceholders.common.PlaceholdersPlugin;
import io.github.miniplaceholders.connect.InternalPlatform;
import me.lucko.fabric.api.permissions.v0.Permissions;
import net.fabricmc.api.DedicatedServerModInitializer;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.tag.Tag;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.packs.PackResources;
import net.minecraft.world.entity.Entity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;
public final class FabricServerMod implements DedicatedServerModInitializer, PlaceholdersPlugin {
private final Logger logger = LoggerFactory.getLogger("miniplaceholders");
private static final DecimalFormat MSPT_FORMAT = new DecimalFormat("###.###");
private final TickManager tickManager = new TickManager();
private MinecraftServer minecraftServer;
@Override
public void onInitializeServer() {
logger.info("Starting MiniPlaceholders Fabric");
InternalPlatform.platform(InternalPlatform.FABRIC);
ServerLifecycleEvents.SERVER_STARTING.register(minecraftServer -> {
this.minecraftServer = minecraftServer;
this.loadDefaultExpansions();
});
this.registerPlatformCommand();
}
@Override
public void loadDefaultExpansions() {
Expansion.builder("server")
.globalPlaceholder("name", Tag.selfClosingInserting(Component.text(this.minecraftServer.getServerModName())))
.globalPlaceholder("online", (queue, ctx) -> Tag.preProcessParsed(Integer.toString(this.minecraftServer.getPlayerCount())))
.globalPlaceholder("version", (ctx, queue) -> Tag.selfClosingInserting(Component.text(this.minecraftServer.getServerVersion())))
.globalPlaceholder("max_players", (ctx, queue) -> Tag.selfClosingInserting(Component.text(this.minecraftServer.getMaxPlayers())))
.globalPlaceholder("unique_joins", (queue, ctx) -> {
final var profileCache = this.minecraftServer.getProfileCache();
if (profileCache == null) {
return null;
}
return Tag.preProcessParsed(Integer.toString(profileCache.load().size()));
})
.globalPlaceholder("tps_1m", (ctx, queue) -> Tag.preProcessParsed(tickManager.getTps1m().formattedAverage()))
.globalPlaceholder("tps_5m", (ctx, queue) -> Tag.preProcessParsed(tickManager.getTps5m().formattedAverage()))
//.globalPlaceholder("tps_15m", (ctx, queue) -> Tag.preProcessParsed(tickManager.getTps15m().formattedAverage()))
.globalPlaceholder("tick_count", (queue, ctx) -> Tag.selfClosingInserting(Component.text(this.minecraftServer.getTickCount())))
.globalPlaceholder("has_whitelist", (queue, ctx) -> Tag.preProcessParsed(Boolean.toString(this.minecraftServer.getPlayerList().isUsingWhitelist())))
.globalPlaceholder("total_chunks", (queue, ctx) -> {
int chunks = 0;
for (final ServerLevel level : this.minecraftServer.getAllLevels()) {
chunks += level.getChunkSource().getLoadedChunksCount();
}
return Tag.preProcessParsed(Integer.toString(chunks));
})
.globalPlaceholder("total_entities", (queue, ctx) -> {
int entities = 0;
for (final ServerLevel level : this.minecraftServer.getAllLevels()) {
for (final Entity ignored : level.getAllEntities()) {
entities++;
}
}
return Tag.preProcessParsed(Integer.toString(entities));
})
.globalPlaceholder("mspt", (queue, ctx) -> Tag.preProcessParsed(MSPT_FORMAT.format(this.minecraftServer.getAverageTickTime())))
.globalPlaceholder("datapack_list", (queue, ctx) ->
Tag.selfClosingInserting(this.minecraftServer.getResourceManager()
.listPacks()
.map(PackResources::packId)
.map(id -> Component.text()
.content("[")
.append(Component.text(id))
.append(Component.text("]"))
.build())
.collect(Component.toComponent(Component.space())))
)
.globalPlaceholder("datapack_count", (queue, ctx) ->
Tag.preProcessParsed(Long.toString(this.minecraftServer.getResourceManager()
.listPacks()
.count()))
)
.build()
.register();
}
@Override
public void registerPlatformCommand() {
final FabricServerCommandManager<CommandSourceStack> commandManager = new FabricServerCommandManager<>(
AsynchronousCommandExecutionCoordinator.simpleCoordinator(),
Function.identity(),
Function.identity()
);
PlaceholdersCommand.<CommandSourceStack>builder()
.hasPermissionCheck((source, permission) -> Permissions.check(source, permission, 4))
.toAudience(string -> this.minecraftServer.getPlayerList().getPlayerByName(string))
.playerSuggestions(() -> new ArrayList<>(List.of(this.minecraftServer.getPlayerNames())))
.manager(commandManager)
.command("miniplaceholders")
.build()
.register();
}
}
@@ -0,0 +1,59 @@
package io.github.miniplaceholders.fabric;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.DecimalFormat;
/**
* Based on the MIT licensed Paper-Server patch "Further improve server tick loop".
*
* @author Daniel Ennis/Aikar
*/
final class RollingAverage {
private static final DecimalFormat TPS_FORMAT = new DecimalFormat("###.##");
static { TPS_FORMAT.setRoundingMode(RoundingMode.HALF_UP); }
private static final int TPS = 20;
private static final long SEC_IN_NANO = 1000000000;
private final int size;
private final BigDecimal[] samples;
private final long[] times;
private long time;
private BigDecimal total;
private int index = 0;
RollingAverage(final int size) {
this.size = size;
this.samples = new BigDecimal[size];
this.times = new long[size];
this.time = size * SEC_IN_NANO;
this.total = dec(TPS).multiply(dec(SEC_IN_NANO)).multiply(dec(size));
for (int i = 0; i < size; i++) {
this.samples[i] = dec(TPS);
this.times[i] = SEC_IN_NANO;
}
}
private static BigDecimal dec(final long t) {
return new BigDecimal(t);
}
void add(final BigDecimal x, final long t) {
this.time -= this.times[this.index];
this.total = this.total.subtract(this.samples[this.index].multiply(dec(this.times[this.index])));
this.samples[this.index] = x;
this.times[this.index] = t;
this.time += t;
this.total = this.total.add(x.multiply(dec(t)));
if (++this.index == this.size) {
this.index = 0;
}
}
double average() {
return this.total.divide(dec(this.time), 30, RoundingMode.HALF_UP).doubleValue();
}
String formattedAverage() {
return TPS_FORMAT.format(average());
}
}
@@ -0,0 +1,45 @@
package io.github.miniplaceholders.fabric;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
import java.math.BigDecimal;
import java.math.RoundingMode;
final class TickManager {
private static final int TICK_DURATION = 20;
private static final BigDecimal TPS_BASE = new BigDecimal("1E9").multiply(new BigDecimal(TICK_DURATION));
private final RollingAverage tps1m = new RollingAverage(60);
private final RollingAverage tps5m = new RollingAverage(60 * 5);
private final RollingAverage tps15m = new RollingAverage(60 * 15);
private long lastStartTick = 0;
private long lastEndTick = 0;
TickManager() {
ServerTickEvents.START_SERVER_TICK.register(server -> this.lastStartTick = System.nanoTime());
ServerTickEvents.END_SERVER_TICK.register(server -> {
if (server.getTickCount() % TICK_DURATION == 0) {
final long diff = lastStartTick - lastEndTick;
final BigDecimal currentTps = TPS_BASE.divide(new BigDecimal(diff), 30, RoundingMode.HALF_UP);
this.tps1m.add(currentTps, diff);
this.tps5m.add(currentTps, diff);
this.tps15m.add(currentTps, diff);
this.lastEndTick = System.nanoTime();
}
});
}
public RollingAverage getTps1m() {
return tps1m;
}
public RollingAverage getTps5m() {
return tps5m;
}
public RollingAverage getTps15m() {
return tps15m;
}
}
+32
View File
@@ -0,0 +1,32 @@
{
"schemaVersion": 1,
"id": "miniplaceholders",
"version": "${version}",
"name": "MiniPlaceholders",
"description": "MiniMessage Component-based Placeholders for PaperMC, Fabric, Krypton and Velocity platforms",
"authors": [
"4drian3d"
],
"contact": {
"homepage": "https://github.com/MiniPlaceholders/MiniPlaceholders",
"sources": "https://github.com/MiniPlaceholders/MiniPlaceholders",
"issues": "https://github.com/MiniPlaceholders/MiniPlaceholders/issues"
},
"license": "Apache-2",
"environment": "server",
"entrypoints": {
"server": [
"io.github.miniplaceholders.fabric.FabricServerMod"
],
"client": [
"io.github.miniplaceholders.fabric.FabricClientMod"
]
},
"depends": {
"fabricloader": ">=0.14.19",
"fabric": "*",
"java": ">=17",
"minecraft": ">=1.19.4",
"fabric-permissions-api-v0": "*"
}
}
+1 -1
View File
@@ -1,5 +1,5 @@
group = io.github.miniplaceholders
version = 2.3.0-SNAPSHOT
version = 2.2.2
description = MiniMessage Component-based Placeholders for Paper, Fabric, Sponge, Folia and Velocity platforms
org.gradle.jvmargs=-Xmx2G
+15 -12
View File
@@ -4,25 +4,26 @@ metadata.format.version = "1.1"
velocity = "3.2.0-SNAPSHOT"
paper = "1.20.2-R0.1-SNAPSHOT"
krypton = "7796647145"
minecraft = "1.20.2"
runtask = "2.2.3"
runtask = "2.2.2"
pluginyml = "0.6.0"
userdev = "1.5.11"
userdev = "1.5.9"
blossom = "2.1.0"
indra = "3.1.3"
shadow = "8.3.5"
shadow = "8.1.1"
jmh = "0.7.2"
dokka = "1.9.10"
cloud = "1.8.4"
adventure = "4.15.0"
adventurefabric = "5.12.0"
adventure = "4.14.0"
adventurefabric = "5.10.1"
brigadier = "1.0.500"
kotlin="1.9.22"
kotlin="1.9.20"
fabric-api = "0.96.4+1.20.5"
fabric-loader = "0.15.7"
fabric-api = "0.90.1+1.20.3"
fabric-loader = "0.14.24"
desertwell = "2.0.4"
@@ -30,6 +31,7 @@ desertwell = "2.0.4"
velocity = { group = "com.velocitypowered", name = "velocity-api", version.ref = "velocity" }
paper = { group = "io.papermc.paper", name = "paper-api", version.ref = "paper" }
krypton-server = { group = "org.kryptonmc", name = "krypton-server", version.ref = "krypton" }
minecraft = { group = "com.mojang", name = "minecraft", version.ref = "minecraft" }
fabric-api = { group = "net.fabricmc.fabric-api", name = "fabric-api", version.ref = "fabric-api" }
@@ -52,7 +54,9 @@ cloud-extras = { group = "cloud.commandframework", name = "cloud-minecraft-extra
brigadier = { group = "com.mojang", name = "brigadier", version.ref = "brigadier" }
plugin-shadow = { module = "com.gradleup.shadow:shadow-gradle-plugin", version.ref = "shadow" }
krypton-annotation = { group = "org.kryptonmc", name = "krypton-annotation-processor", version.ref = "krypton" }
plugin-shadow = { group = "com.github.johnrengelman", name = "shadow", version.ref = "shadow" }
plugin-kotlin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" }
plugin-indra-common = { module = "net.kyori:indra-common", version.ref = "indra" }
plugin-indra-spotless = { module = "net.kyori:indra-licenser-spotless", version.ref = "indra" }
@@ -60,8 +64,7 @@ plugin-dokka = "org.jetbrains.dokka:dokka-gradle-plugin:1.9.10"
desertwell = { group = "net.william278", name = "DesertWell", version.ref = "desertwell" }
junit-bom = "org.junit:junit-bom:5.10.2"
junit-bom = "org.junit:junit-bom:5.10.1"
[plugins]
@@ -70,7 +73,7 @@ userdev = { id = "io.papermc.paperweight.userdev", version.ref = "userdev" }
runpaper = { id = "xyz.jpenilla.run-paper", version.ref = "runtask" }
runvelocity = { id = "xyz.jpenilla.run-velocity", version.ref = "runtask" }
blossom = { id = "net.kyori.blossom", version.ref = "blossom" }
shadow = { id = "com.gradleup.shadow", version.ref = "shadow" }
shadow = { id = "com.github.johnrengelman.shadow", version.ref = "shadow" }
jmh = { id = "me.champeau.jmh", version.ref = "jmh" }
dokka = { id = "org.jetbrains.dokka", version.ref = "dokka" }
idea-ext = { id = "org.jetbrains.gradle.plugin.idea-ext", version = "1.1.7" }
Binary file not shown.
+1 -1
View File
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.3-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Vendored
+5 -7
View File
@@ -15,8 +15,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0
#
##############################################################################
#
@@ -57,7 +55,7 @@
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
@@ -86,7 +84,7 @@ done
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
@@ -114,7 +112,7 @@ case "$( uname )" in #(
NONSTOP* ) nonstop=true ;;
esac
CLASSPATH="\\\"\\\""
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM.
@@ -205,7 +203,7 @@ fi
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# Collect all arguments for the java command:
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
# and any embedded shellness will be escaped.
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
# treated as '${Hostname}' itself on the command line.
@@ -213,7 +211,7 @@ DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
set -- \
"-Dorg.gradle.appname=$APP_BASE_NAME" \
-classpath "$CLASSPATH" \
-jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \
org.gradle.wrapper.GradleWrapperMain \
"$@"
# Stop when "xargs" is not available.
Vendored
+12 -14
View File
@@ -13,8 +13,6 @@
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@rem SPDX-License-Identifier: Apache-2.0
@rem
@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
@@ -45,11 +43,11 @@ set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if %ERRORLEVEL% equ 0 goto execute
echo. 1>&2
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
@@ -59,22 +57,22 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto execute
echo. 1>&2
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:execute
@rem Setup the command line
set CLASSPATH=
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %*
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
:end
@rem End local scope for the variables with windows NT shell
+27
View File
@@ -0,0 +1,27 @@
plugins {
kotlin("jvm")
kotlin("kapt")
alias(libs.plugins.shadow)
}
repositories {
maven("https://repo.kryptonmc.org/releases")
maven("https://s01.oss.sonatype.org/content/repositories/snapshots/")
maven("https://repo.kryptonmc.org/snapshots")
}
dependencies {
compileOnly(libs.krypton.server)
compileOnly(kotlin("stdlib"))
kapt(libs.krypton.annotation)
implementation(projects.miniplaceholdersCommon)
implementation(projects.miniplaceholdersApi)
implementation(projects.miniplaceholdersConnect)
implementation(projects.miniplaceholdersKotlinExt)
}
kotlin {
jvmToolchain {
languageVersion.set(JavaLanguageVersion.of(17))
}
}
@@ -0,0 +1,85 @@
package io.github.miniplaceholders.krypton
import com.google.inject.Inject
import io.github.miniplaceholders.api.utils.TagsUtils
import io.github.miniplaceholders.common.PlaceholdersCommand
import io.github.miniplaceholders.common.PlaceholdersPlugin
import io.github.miniplaceholders.common.PluginConstants
import io.github.miniplaceholders.connect.InternalPlatform
import io.github.miniplaceholders.kotlin.asClosingTag
import io.github.miniplaceholders.kotlin.expansion
import net.kyori.adventure.text.Component
import org.apache.logging.log4j.Logger
import org.kryptonmc.api.command.BrigadierCommand
import org.kryptonmc.api.command.CommandExecutionContext
import org.kryptonmc.api.event.Listener
import org.kryptonmc.api.event.server.ServerStartEvent
import org.kryptonmc.api.plugin.annotation.Plugin
import org.kryptonmc.krypton.KryptonServer
import org.kryptonmc.krypton.command.KryptonCommandMeta
@Plugin(
name = "MiniPlaceholders",
id = "miniplaceholders",
version = PluginConstants.VERSION,
authors = ["4drian3d"]
)
class KotlinKryptonPlugin @Inject constructor(
private val server: KryptonServer,
private val logger: Logger
) : PlaceholdersPlugin {
init {
InternalPlatform.platform(InternalPlatform.KRYPTON)
}
@Listener
@Suppress("UNUSED")
fun onServerStart(event: ServerStartEvent) {
logger.info("Starting MiniPlaceholders Krypton")
this.loadDefaultExpansions()
this.registerPlatformCommand()
}
override fun loadDefaultExpansions() {
expansion("server") {
globalPlaceholder("total_entities") { _, _ ->
var entityCount = 0
for ((_, value) in server.worldManager.worlds) {
entityCount += value.entities.size
}
Component.text(entityCount).asClosingTag()
}
globalPlaceholder("total_chunks") { _, _ ->
var chunkCount = 0
for ((_, value) in server.worldManager.worlds) {
chunkCount += value.chunks.size
}
Component.text(chunkCount).asClosingTag()
}
globalPlaceholder("name", TagsUtils.staticTag(server.platform.name))
globalPlaceholder("online") { queue, _ ->
if (queue.hasNext()) {
val worldName = queue.pop().value()
val players = server.players.filter { it.world.name == worldName }
return@globalPlaceholder Component.text(players.joinToString(", ")).asClosingTag()
}
Component.text(server.players.size).asClosingTag()
}
globalPlaceholder("version", TagsUtils.staticTag(server.platform.version))
globalPlaceholder("max_players", Component.text(server.config.maxPlayers).asClosingTag())
}.register()
}
override fun registerPlatformCommand() {
/*val command = PlaceholdersCommand.builder<CommandExecutionContext>()
.fromSourceToAudience { it.sender }
.playerSuggestions { server.players.map { it.name } }
.toAudience { server.getPlayer(it) }
.build()
val brigadierCMD = BrigadierCommand.of(command.asNode("miniplaceholders"))
val meta = KryptonCommandMeta.Builder("miniplaceholders").build()
server.commandManager.register(brigadierCMD, meta)*/
}
}
+8 -20
View File
@@ -12,26 +12,14 @@ dependencies {
implementation(libs.cloud.paper)
}
tasks.named<ProcessResources>("processResources") {
val pluginVersion = project.version.toString()
inputs.property("version", pluginVersion)
filesMatching("paper-plugin.yml") {
expand("version" to pluginVersion)
tasks {
runServer {
minecraftVersion("1.20.2")
}
processResources {
filesMatching("paper-plugin.yml") {
expand("version" to project.version)
}
}
}
tasks.named("assemble") {
dependsOn("shadowJar")
}
tasks.register<Exec>("runCopyJarScript") {
group = "build"
description = "Runs the copyjar.sh script after build completion."
workingDir(rootDir)
commandLine("sh", "copyjar.sh", project.version.toString())
}
tasks.named("build") {
finalizedBy("runCopyJarScript")
}
@@ -3,6 +3,7 @@ package io.github.miniplaceholders.paper;
import cloud.commandframework.execution.AsynchronousCommandExecutionCoordinator;
import cloud.commandframework.paper.PaperCommandManager;
import io.github.miniplaceholders.api.Expansion;
import io.github.miniplaceholders.api.utils.TagsUtils;
import io.github.miniplaceholders.common.PlaceholdersCommand;
import io.github.miniplaceholders.common.PlaceholdersPlugin;
import io.github.miniplaceholders.connect.InternalPlatform;
@@ -43,38 +44,38 @@ public final class PaperPlugin extends JavaPlugin implements PlaceholdersPlugin
@Override
public void loadDefaultExpansions() {
Expansion.builder("server")
.globalPlaceholder("name", Tag.preProcessParsed(this.getServer().getName()))
.globalPlaceholder("online", (queue, ctx) -> Tag.preProcessParsed(Integer.toString(this.getServer().getOnlinePlayers().size())))
.globalPlaceholder("version", Tag.preProcessParsed(this.getServer().getVersion()))
.globalPlaceholder("max_players", (queue, ctx) -> Tag.preProcessParsed(Integer.toString(this.getServer().getMaxPlayers())))
.globalPlaceholder("unique_joins", (queue, ctx) -> Tag.preProcessParsed(Integer.toString(this.getServer().getOfflinePlayers().length)))
.globalPlaceholder("tps_1", (queue, ctx) -> Tag.preProcessParsed(TPS_FORMAT.format(this.getServer().getTPS()[0])))
.globalPlaceholder("tps_5", (queue, ctx) -> Tag.preProcessParsed(TPS_FORMAT.format(this.getServer().getTPS()[1])))
.globalPlaceholder("tps_15", (queue, ctx) -> Tag.preProcessParsed(TPS_FORMAT.format(this.getServer().getTPS()[2])))
.globalPlaceholder("has_whitelist", (queue, ctx) -> Tag.preProcessParsed(Boolean.toString(this.getServer().hasWhitelist())))
.globalPlaceholder("name", TagsUtils.staticTag(Component.text(this.getServer().getName())))
.globalPlaceholder("online", (queue, ctx) -> TagsUtils.staticTag(Component.text(this.getServer().getOnlinePlayers().size())))
.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(TPS_FORMAT.format(this.getServer().getTPS()[0])))
.globalPlaceholder("tps_5", (queue, ctx) -> TagsUtils.staticTag(TPS_FORMAT.format(this.getServer().getTPS()[1])))
.globalPlaceholder("tps_15", (queue, ctx) -> TagsUtils.staticTag(TPS_FORMAT.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;
for (World world : this.getServer().getWorlds()){
chunkCount += world.getLoadedChunks().length;
}
return Tag.preProcessParsed(Integer.toString(chunkCount));
return TagsUtils.staticTag(Component.text(chunkCount));
})
.globalPlaceholder("total_entities", (queue, ctx) -> {
int entityCount = 0;
for (World world : this.getServer().getWorlds()){
entityCount += world.getEntityCount();
}
return Tag.preProcessParsed(Integer.toString(entityCount));
return TagsUtils.staticTag(Component.text(entityCount));
})
.globalPlaceholder("mspt", (queue, ctx) -> Tag.preProcessParsed(MSPT_FORMAT.format(this.getServer().getAverageTickTime())))
.globalPlaceholder("mspt", (queue, ctx) -> TagsUtils.staticTag(MSPT_FORMAT.format(this.getServer().getAverageTickTime())))
.globalPlaceholder("datapack_list", (queue, ctx) -> {
final TextComponent.Builder builder = Component.text();
for (final Datapack datapack : this.getServer().getDatapackManager().getEnabledPacks()) {
for (Datapack datapack : this.getServer().getDatapackManager().getEnabledPacks()){
builder.append(Component.text("[").append(Component.text(datapack.getName()).append(Component.text("] "))));
}
return Tag.selfClosingInserting(builder.build());
})
.globalPlaceholder("datapack_count", (queue, ctx) -> Tag.preProcessParsed(Integer.toString(this.getServer().getDatapackManager().getEnabledPacks().size())))
.globalPlaceholder("datapack_count", (queue, ctx) -> Tag.selfClosingInserting(Component.text(this.getServer().getDatapackManager().getEnabledPacks().size())))
.build()
.register();
}
+6 -6
View File
@@ -17,7 +17,7 @@ pluginManagement {
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
maven("https://repo.papermc.io/repository/maven-public/")
maven("https://papermc.io/repo/repository/maven-public/")
maven("https://repo.maven.apache.org/maven2/")
maven("https://jitpack.io") {
mavenContent {
@@ -30,9 +30,9 @@ dependencyResolutionManagement {
}
plugins {
id("fabric-loom") version "1.5.8"
id("fabric-loom") version "1.4.4"
id("org.spongepowered.gradle.plugin") version "2.2.0"
id("org.gradle.toolchains.foojay-resolver-convention") version "0.8.0"
id("org.gradle.toolchains.foojay-resolver-convention") version "0.7.0"
}
arrayOf(
@@ -41,10 +41,10 @@ arrayOf(
"kotlin-ext",
"common",
"paper",
//"velocity",
"velocity",
//"krypton",
//"fabric"
//"sponge"
"fabric",
"sponge"
).forEach {
include("miniplaceholders-$it")
project(":miniplaceholders-$it").projectDir = file(it)
+2
View File
@@ -0,0 +1,2 @@
# run-paper files
/run
+47
View File
@@ -0,0 +1,47 @@
import org.spongepowered.gradle.plugin.config.PluginLoaders
import org.spongepowered.plugin.metadata.model.PluginDependency
plugins {
id("miniplaceholders.auto.module")
id("miniplaceholders.shadow")
id("org.spongepowered.gradle.plugin")
}
dependencies {
implementation(projects.miniplaceholdersCommon)
implementation(projects.miniplaceholdersApi)
implementation(projects.miniplaceholdersConnect)
implementation(libs.cloud.sponge)
}
sponge {
apiVersion("8.1.0")
license("GPL-3")
loader {
name(PluginLoaders.JAVA_PLAIN)
version("1.0")
}
plugin("miniplaceholders") {
displayName("MiniPlaceholders")
entrypoint("io.github.miniplaceholders.sponge.SpongePlugin")
description(project.description)
links {
homepage("https://github.com/MiniPlaceholders/MiniPlaceholders")
source("https://github.com/MiniPlaceholders/MiniPlaceholders")
issues("https://github.com/MiniPlaceholders/MiniPlaceholders/issues")
}
contributor("4drian3d") {
description("Lead Developer")
}
dependency("spongeapi") {
loadOrder(PluginDependency.LoadOrder.AFTER)
optional(false)
}
}
}
tasks {
shadowJar {
exclude("io/leangen/geantyref/**")
}
}
@@ -0,0 +1,116 @@
package io.github.miniplaceholders.sponge;
import cloud.commandframework.execution.CommandExecutionCoordinator;
import cloud.commandframework.sponge.SpongeCommandManager;
import com.google.inject.Inject;
import io.github.miniplaceholders.api.Expansion;
import io.github.miniplaceholders.api.utils.TagsUtils;
import io.github.miniplaceholders.common.PlaceholdersCommand;
import io.github.miniplaceholders.common.PlaceholdersPlugin;
import io.github.miniplaceholders.connect.InternalPlatform;
import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.audience.ForwardingAudience;
import net.kyori.adventure.text.Component;
import org.apache.logging.log4j.Logger;
import org.jetbrains.annotations.NotNull;
import org.spongepowered.api.Server;
import org.spongepowered.api.command.Command;
import org.spongepowered.api.command.CommandCause;
import org.spongepowered.api.entity.living.player.server.ServerPlayer;
import org.spongepowered.api.event.Listener;
import org.spongepowered.api.event.lifecycle.RegisterCommandEvent;
import org.spongepowered.api.event.lifecycle.StartingEngineEvent;
import org.spongepowered.api.world.server.ServerWorld;
import org.spongepowered.plugin.PluginContainer;
import org.spongepowered.plugin.builtin.jvm.Plugin;
import java.util.ArrayList;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
@Plugin("miniplaceholders")
public class SpongePlugin implements PlaceholdersPlugin {
@Inject
private PluginContainer pluginContainer;
@Inject
private Logger logger;
private Server server;
@Listener
public void onServerStart(final StartingEngineEvent<Server> event) {
this.server = event.engine();
logger.info("Starting MiniPlaceholders Sponge");
InternalPlatform.platform(InternalPlatform.SPONGE);
this.loadDefaultExpansions();
}
private final AtomicInteger registration = new AtomicInteger(0);
@Listener
public void onCommandRegister(final RegisterCommandEvent<Command.Parameterized> event) {
if (registration.getAndIncrement() == 0) {
this.registerPlatformCommand();
}
}
@Override
public void loadDefaultExpansions() {
Expansion.builder("server")
.globalPlaceholder("name", TagsUtils.staticTag("Sponge"))
.globalPlaceholder("online", (queue, ctx) -> TagsUtils.staticTag(Component.text(server.onlinePlayers().size())))
.globalPlaceholder("max_players", (queue, ctx) -> TagsUtils.staticTag(Component.text(server.maxPlayers())))
.globalPlaceholder("unique_joins", (queue, ctx) -> TagsUtils.staticTag(Component.text(server.userManager().streamAll().count())))
.globalPlaceholder("has_whitelist", (queue, ctx) -> TagsUtils.staticTag(Component.text(server.isWhitelistEnabled())))
.globalPlaceholder("total_chunks", (queue, ctx) -> {
int chunkCount = 0;
for (ServerWorld world : server.worldManager().worlds()){
chunkCount += world.entities().size();
}
return TagsUtils.staticTag(Component.text(chunkCount));
})
.globalPlaceholder("total_entities", (queue, ctx) -> {
int entityCount = 0;
for (ServerWorld world : server.worldManager().worlds()){
entityCount += world.entities().size();
}
return TagsUtils.staticTag(Component.text(entityCount));
})
.globalPlaceholder("mspt", (queue, ctx) -> TagsUtils.staticTag(Component.text(server.averageTickTime())))
.build()
.register();
}
@Override
public void registerPlatformCommand() {
final SpongeCommandManager<AudienceHolder> commandManager = new SpongeCommandManager<>(
pluginContainer,
CommandExecutionCoordinator.simpleCoordinator(),
AudienceHolder::cause,
AudienceHolder::new
);
PlaceholdersCommand.<AudienceHolder>builder()
.manager(commandManager)
.command("miniplaceholders")
.playerSuggestions(() -> server.onlinePlayers()
.stream()
.map(ServerPlayer::name)
.collect(Collectors.toCollection(ArrayList::new)))
.toAudience(st -> server.player(st).orElse(null))
.hasPermissionCheck((holder, permission) -> holder.cause.hasPermission(permission))
.build()
.register();
}
record AudienceHolder(@NotNull CommandCause cause) implements ForwardingAudience.Single {
@Override
public @NotNull Audience audience() {
return cause.audience();
}
}
}
+2
View File
@@ -0,0 +1,2 @@
#run velocity files
/run
+20
View File
@@ -0,0 +1,20 @@
plugins {
id("miniplaceholders.shadow")
id("miniplaceholders.auto.module")
alias(libs.plugins.runvelocity)
}
dependencies {
compileOnly(libs.velocity)
annotationProcessor(libs.velocity)
implementation(projects.miniplaceholdersCommon)
implementation(projects.miniplaceholdersApi)
implementation(projects.miniplaceholdersConnect)
implementation(libs.cloud.velocity)
}
tasks {
runVelocity {
velocityVersion(libs.versions.velocity.get())
}
}
@@ -0,0 +1,105 @@
package io.github.miniplaceholders.velocity;
import cloud.commandframework.execution.CommandExecutionCoordinator;
import cloud.commandframework.velocity.CloudInjectionModule;
import cloud.commandframework.velocity.VelocityCommandManager;
import com.google.inject.Inject;
import com.google.inject.Injector;
import com.google.inject.Key;
import com.google.inject.TypeLiteral;
import com.velocitypowered.api.command.CommandSource;
import com.velocitypowered.api.event.Subscribe;
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
import com.velocitypowered.api.plugin.Plugin;
import com.velocitypowered.api.proxy.Player;
import com.velocitypowered.api.proxy.ProxyServer;
import io.github.miniplaceholders.api.Expansion;
import io.github.miniplaceholders.api.utils.Components;
import io.github.miniplaceholders.api.utils.TagsUtils;
import io.github.miniplaceholders.common.PlaceholdersCommand;
import io.github.miniplaceholders.common.PlaceholdersPlugin;
import io.github.miniplaceholders.common.PluginConstants;
import io.github.miniplaceholders.connect.InternalPlatform;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.tag.Tag;
import org.slf4j.Logger;
import java.util.ArrayList;
import java.util.function.Function;
import java.util.stream.Collectors;
@Plugin(
name = "MiniPlaceholders",
id = "miniplaceholders",
version = PluginConstants.VERSION,
authors = {"4drian3d"}
)
public final class VelocityPlugin implements PlaceholdersPlugin {
private final Logger logger;
private final ProxyServer proxy;
@Inject
private Injector injector;
@Inject
public VelocityPlugin(final Logger logger, final ProxyServer proxy) {
this.logger = logger;
this.proxy = proxy;
}
@Subscribe
public void onProxyInitialize(final ProxyInitializeEvent event) {
logger.info("Starting MiniPlaceholders Velocity");
InternalPlatform.platform(InternalPlatform.VELOCITY);
this.loadDefaultExpansions();
this.registerPlatformCommand();
}
@Override
public void loadDefaultExpansions() {
Expansion.builder("proxy")
.globalPlaceholder("online_players", (queue, ctx) -> {
if (queue.hasNext()) {
String server = queue.pop().value();
return Tag.preProcessParsed(proxy.getServer(server)
.map(sv -> sv.getPlayersConnected().size())
.map(size -> Integer.toString(size))
.orElse("0"));
}
return Tag.selfClosingInserting(Component.text(proxy.getPlayerCount()));
})
.globalPlaceholder("server_count", (queue, ctx) -> Tag.preProcessParsed(Integer.toString(proxy.getAllServers().size())))
.globalPlaceholder("is_player_online", (queue, ctx) -> {
String playerName = queue.popOr(() -> "you need to introduce an argument").value();
return TagsUtils.staticTag(proxy.getPlayer(playerName).isPresent() ? Components.YES_COMPONENT : Components.NO_COMPONENT);
})
.globalPlaceholder("version", TagsUtils.staticTag(proxy.getVersion().getVersion()))
.build()
.register();
}
@Override
public void registerPlatformCommand() {
injector = injector.createChildInjector(
new CloudInjectionModule<>(
CommandSource.class,
CommandExecutionCoordinator.simpleCoordinator(),
Function.identity(),
Function.identity()
)
);
final VelocityCommandManager<CommandSource> commandManager = injector.getInstance(
Key.get(new TypeLiteral<>() {})
);
PlaceholdersCommand.<CommandSource>builder()
.playerSuggestions(() -> proxy.getAllPlayers()
.stream()
.map(Player::getUsername)
.collect(Collectors.toCollection(ArrayList::new)))
.toAudience(st -> proxy.getPlayer(st).orElse(null))
.command("vminiplaceholders")
.manager(commandManager)
.build().register();
}
}