Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4a6a616211 |
No files matched your search
@@ -1 +0,0 @@
|
||||
.gitea/CODEOWNERS linguist-detectable=false
|
||||
@@ -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
|
||||
@@ -14,6 +14,6 @@ repositories {
|
||||
|
||||
kotlin {
|
||||
jvmToolchain {
|
||||
languageVersion = JavaLanguageVersion.of(17)
|
||||
languageVersion.set(JavaLanguageVersion.of(17))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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
@@ -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.22" apply false
|
||||
}
|
||||
|
||||
tasks {
|
||||
|
||||
@@ -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"
|
||||
@@ -0,0 +1 @@
|
||||
/run
|
||||
@@ -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,113 @@
|
||||
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.ModInitializer;
|
||||
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 class FabricMod implements ModInitializer, 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 onInitialize() {
|
||||
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.preProcessParsed(this.minecraftServer.getServerModName()))
|
||||
.globalPlaceholder("online", (queue, ctx) -> Tag.preProcessParsed(Integer.toString(this.minecraftServer.getPlayerCount())))
|
||||
.globalPlaceholder("version", (ctx, queue) -> Tag.preProcessParsed(this.minecraftServer.getServerVersion()))
|
||||
.globalPlaceholder("max_players", (ctx, queue) -> Tag.preProcessParsed(Integer.toString(this.minecraftServer.getMaxPlayers())))
|
||||
.globalPlaceholder("unique_joins", (queue, ctx) -> Tag.preProcessParsed(Integer.toString(this.minecraftServer.getProfileCache().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.preProcessParsed(Integer.toString(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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
{
|
||||
"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": {
|
||||
"main": [
|
||||
"io.github.miniplaceholders.fabric.FabricMod"
|
||||
]
|
||||
},
|
||||
"depends": {
|
||||
"fabricloader": ">=0.14.19",
|
||||
"fabric": "*",
|
||||
"java": ">=17",
|
||||
"minecraft": ">=1.20.2",
|
||||
"fabric-permissions-api-v0": "*"
|
||||
}
|
||||
}
|
||||
@@ -8,10 +8,10 @@ minecraft = "1.20.2"
|
||||
|
||||
runtask = "2.2.3"
|
||||
pluginyml = "0.6.0"
|
||||
userdev = "1.5.11"
|
||||
userdev = "1.7.1"
|
||||
blossom = "2.1.0"
|
||||
indra = "3.1.3"
|
||||
shadow = "8.3.5"
|
||||
shadow = "8.1.1"
|
||||
jmh = "0.7.2"
|
||||
dokka = "1.9.10"
|
||||
|
||||
@@ -52,7 +52,7 @@ 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" }
|
||||
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" }
|
||||
@@ -62,7 +62,6 @@ desertwell = { group = "net.william278", name = "DesertWell", version.ref = "des
|
||||
|
||||
junit-bom = "org.junit:junit-bom:5.10.2"
|
||||
|
||||
|
||||
[plugins]
|
||||
|
||||
pluginyml = { id = "net.minecrell.plugin-yml.bukkit", version.ref = "pluginyml" }
|
||||
@@ -70,7 +69,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" }
|
||||
Vendored
BIN
Binary file not shown.
+1
-1
@@ -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.6-bin.zip
|
||||
networkTimeout=10000
|
||||
validateDistributionUrl=true
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
|
||||
@@ -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
@@ -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
|
||||
|
||||
+8
-20
@@ -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")
|
||||
}
|
||||
+4
-4
@@ -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 {
|
||||
@@ -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)
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
# run-paper files
|
||||
/run
|
||||
@@ -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,115 @@
|
||||
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.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.minimessage.tag.Tag;
|
||||
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", Tag.preProcessParsed("Sponge"))
|
||||
.globalPlaceholder("online", (queue, ctx) -> Tag.preProcessParsed(Integer.toString(server.onlinePlayers().size())))
|
||||
.globalPlaceholder("max_players", (queue, ctx) -> Tag.preProcessParsed(Integer.toString(server.maxPlayers())))
|
||||
.globalPlaceholder("unique_joins", (queue, ctx) -> Tag.preProcessParsed(Long.toString(server.userManager().streamAll().count())))
|
||||
.globalPlaceholder("has_whitelist", (queue, ctx) -> Tag.preProcessParsed(Boolean.toString(server.isWhitelistEnabled())))
|
||||
.globalPlaceholder("total_chunks", (queue, ctx) -> {
|
||||
int chunkCount = 0;
|
||||
for (ServerWorld world : server.worldManager().worlds()){
|
||||
chunkCount += world.entities().size();
|
||||
}
|
||||
return Tag.preProcessParsed(Integer.toString(chunkCount));
|
||||
})
|
||||
.globalPlaceholder("total_entities", (queue, ctx) -> {
|
||||
int entityCount = 0;
|
||||
for (ServerWorld world : server.worldManager().worlds()){
|
||||
entityCount += world.entities().size();
|
||||
}
|
||||
return Tag.preProcessParsed(Integer.toString(entityCount));
|
||||
})
|
||||
.globalPlaceholder("mspt", (queue, ctx) -> Tag.preProcessParsed(Double.toString(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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
#run velocity files
|
||||
/run
|
||||
@@ -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,103 @@
|
||||
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.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.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.preProcessParsed(Integer.toString(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 Tag.selfClosingInserting(proxy.getPlayer(playerName).isPresent() ? Components.YES_COMPONENT : Components.NO_COMPONENT);
|
||||
})
|
||||
.globalPlaceholder("version", Tag.preProcessParsed(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();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user