Compare commits
78 Commits
Author | SHA1 | Date | |
---|---|---|---|
402fb532e0
|
|||
|
aba17260c3 | ||
3bda062a70
|
|||
a4a51b7cd8
|
|||
ff56045903
|
|||
062b3a642a | |||
8bb17f3c4c | |||
4a0314462e | |||
c6e5549fa9 | |||
fbcf545119 | |||
7eb86b012e | |||
|
cf3b89ea7f | ||
79b2277a77 | |||
e7b3e33253 | |||
dc3f3aa0b8 | |||
771d438533 | |||
c38c7e4722 | |||
b800a4ea78 | |||
15b9b40b0e | |||
76be1292f9 | |||
f4ba4d43f6 | |||
801f92a223 | |||
a91ebdaa7b | |||
f33363fc2d | |||
3986f08540 | |||
7f9ff38768 | |||
4c3cc6b034 | |||
5d0ad68c64 | |||
aded006f30 | |||
78cc17f718 | |||
5a8769bee9 | |||
d2aca8ffa9 | |||
cc26cd450d | |||
4e2eafb702 | |||
4fab7e51a1 | |||
1ccb4c1f56 | |||
d4a8de0fd2 | |||
197bfaf6df | |||
eda815c460 | |||
dbf5415b50 | |||
6f6c93c6ee | |||
c808f53841 | |||
fcc1c816e7 | |||
aea07af3d5 | |||
0dbf07de46 | |||
2c13d507c3 | |||
862b5b2af4 | |||
c8cfa985b1 | |||
df50b0e82d | |||
e895a71cad | |||
597358db06 | |||
abdb68ca08 | |||
4314009479 | |||
d21bf13b4a | |||
8d135fe0f2 | |||
0f17e8f844 | |||
55e7e2211b | |||
7d5c11772a | |||
843f23b9c7 | |||
ce16c08760 | |||
6a8301f79a | |||
6b05af6c83 | |||
dd69ecd7cc | |||
fabef0e6f1 | |||
a355daccb2 | |||
648441ec78 | |||
40bb37e111 | |||
d3ffc2856f | |||
493a1568ff | |||
55c6f60197 | |||
d9fcf54728 | |||
da7518e08d | |||
f712036d2e | |||
261ea4c3f8 | |||
16163ac944 | |||
7bbbd7be62 | |||
21d9618283 | |||
97d8eaa5e8 |
6
.gitignore
vendored
6
.gitignore
vendored
@@ -22,4 +22,8 @@ eclipse
|
|||||||
run
|
run
|
||||||
|
|
||||||
artifacts
|
artifacts
|
||||||
src/test/**
|
src/test/**
|
||||||
|
|
||||||
|
workspace
|
||||||
|
upstream
|
||||||
|
rejects
|
8
.idea/.gitignore
generated
vendored
8
.idea/.gitignore
generated
vendored
@@ -1,8 +0,0 @@
|
|||||||
# Default ignored files
|
|
||||||
/shelf/
|
|
||||||
/workspace.xml
|
|
||||||
# Editor-based HTTP Client requests
|
|
||||||
/httpRequests/
|
|
||||||
# Datasource local storage ignored files
|
|
||||||
/dataSources/
|
|
||||||
/dataSources.local.xml
|
|
7
.idea/discord.xml
generated
7
.idea/discord.xml
generated
@@ -1,7 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="DiscordProjectSettings">
|
|
||||||
<option name="show" value="ASK" />
|
|
||||||
<option name="description" value="" />
|
|
||||||
</component>
|
|
||||||
</project>
|
|
18
.idea/misc.xml
generated
18
.idea/misc.xml
generated
@@ -1,18 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="EntryPointsManager">
|
|
||||||
<list size="4">
|
|
||||||
<item index="0" class="java.lang.String" itemvalue="net.minecraftforge.fml.common.Mod" />
|
|
||||||
<item index="1" class="java.lang.String" itemvalue="net.minecraftforge.fml.common.Mod.EventHandler" />
|
|
||||||
<item index="2" class="java.lang.String" itemvalue="net.minecraftforge.fml.common.eventhandler.SubscribeEvent" />
|
|
||||||
<item index="3" class="java.lang.String" itemvalue="net.minecraftforge.eventbus.api.SubscribeEvent" />
|
|
||||||
</list>
|
|
||||||
</component>
|
|
||||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
|
||||||
<component name="FrameworkDetectionExcludesConfiguration">
|
|
||||||
<file type="web" url="file://$PROJECT_DIR$" />
|
|
||||||
</component>
|
|
||||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="corretto-21" project-jdk-type="JavaSDK">
|
|
||||||
<output url="file://$PROJECT_DIR$/out" />
|
|
||||||
</component>
|
|
||||||
</project>
|
|
@@ -1,15 +1,24 @@
|
|||||||
|
def JDK = "21"
|
||||||
|
def majorMc = "1.21.9";
|
||||||
|
|
||||||
pipeline {
|
pipeline {
|
||||||
agent {
|
agent {
|
||||||
label "master"
|
docker {
|
||||||
|
image "registry.firstdark.dev/java${JDK}:latest"
|
||||||
|
alwaysPull true
|
||||||
|
args '-v gradle-cache:/home/gradle/.gradle'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
tools {
|
|
||||||
jdk "JAVA17"
|
environment {
|
||||||
|
GRADLE_USER_HOME = '/home/gradle/.gradle'
|
||||||
}
|
}
|
||||||
|
|
||||||
stages {
|
stages {
|
||||||
stage("Notify Discord") {
|
stage("Notify Discord") {
|
||||||
steps {
|
steps {
|
||||||
discordSend webhookURL: env.FDD_WH_ADMIN,
|
discordSend webhookURL: env.FDD_WH_ADMIN,
|
||||||
title: "Deploy Started: CraterLib Port Deploy #${BUILD_NUMBER}",
|
title: "Deploy Started: CraterLib ${majorMc} Deploy #${BUILD_NUMBER}",
|
||||||
link: env.BUILD_URL,
|
link: env.BUILD_URL,
|
||||||
result: 'SUCCESS',
|
result: 'SUCCESS',
|
||||||
description: "Build: [${BUILD_NUMBER}](${env.BUILD_URL})"
|
description: "Build: [${BUILD_NUMBER}](${env.BUILD_URL})"
|
||||||
|
@@ -1,19 +1,35 @@
|
|||||||
def projectName = "CraterLib";
|
def projectName = "CraterLib";
|
||||||
def projectIcon = "https://cdn.modrinth.com/data/Nn8Wasaq/a172c634683a11a2e9ae593e56eba7885743bb44.png";
|
def projectIcon = "https://cdn.modrinth.com/data/Nn8Wasaq/a172c634683a11a2e9ae593e56eba7885743bb44.png";
|
||||||
|
def JDK = "21";
|
||||||
|
def majorMc = "25w35a";
|
||||||
|
def modLoaders = "fabric|quilt";
|
||||||
|
def supportedMc = "25w35a";
|
||||||
|
def reltype = "experimental";
|
||||||
|
|
||||||
pipeline {
|
pipeline {
|
||||||
agent {
|
agent {
|
||||||
label "master"
|
docker {
|
||||||
|
image "registry.firstdark.dev/java${JDK}:latest"
|
||||||
|
alwaysPull true
|
||||||
|
args '-v gradle-cache:/home/gradle/.gradle'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
tools {
|
|
||||||
jdk "JAVA17"
|
environment {
|
||||||
|
GRADLE_USER_HOME = '/home/gradle/.gradle'
|
||||||
}
|
}
|
||||||
|
|
||||||
stages {
|
stages {
|
||||||
|
stage('Checkout') {
|
||||||
|
steps {
|
||||||
|
scmSkip(deleteBuild: false, skipPattern:'.*\\[ci skip\\].*')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
stage("Notify Discord") {
|
stage("Notify Discord") {
|
||||||
steps {
|
steps {
|
||||||
discordSend webhookURL: env.SSS_WEBHOOK,
|
discordSend webhookURL: env.SSS_WEBHOOK,
|
||||||
title: "Deploy Started: ${projectName} Port Deploy #${BUILD_NUMBER}",
|
title: "Deploy Started: ${projectName} ${majorMc} Deploy #${BUILD_NUMBER}",
|
||||||
link: env.BUILD_URL,
|
link: env.BUILD_URL,
|
||||||
result: 'SUCCESS',
|
result: 'SUCCESS',
|
||||||
description: "Build: [${BUILD_NUMBER}](${env.BUILD_URL})"
|
description: "Build: [${BUILD_NUMBER}](${env.BUILD_URL})"
|
||||||
@@ -23,20 +39,14 @@ pipeline {
|
|||||||
stage("Prepare") {
|
stage("Prepare") {
|
||||||
steps {
|
steps {
|
||||||
sh "chmod +x ./gradlew"
|
sh "chmod +x ./gradlew"
|
||||||
sh "./gradlew clean"
|
sh "./gradlew build -PreleaseType=${reltype}"
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
stage("Build") {
|
|
||||||
steps {
|
|
||||||
sh "./gradlew build"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stage("Publish to Maven") {
|
stage("Publish to Maven") {
|
||||||
steps {
|
steps {
|
||||||
catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') {
|
catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') {
|
||||||
sh "./gradlew publish"
|
sh "./gradlew publish -PreleaseType=${reltype}"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -51,8 +61,10 @@ pipeline {
|
|||||||
projectSlug: "craterlib",
|
projectSlug: "craterlib",
|
||||||
projectName: "${projectName}",
|
projectName: "${projectName}",
|
||||||
projectIcon: "${projectIcon}",
|
projectIcon: "${projectIcon}",
|
||||||
modLoaders: "forge|neoforge|fabric|quilt",
|
modLoaders: "${modLoaders}",
|
||||||
minecraftVersions: "1.20.6",
|
minecraftVersions: "${supportedMc}",
|
||||||
|
type: "experimental",
|
||||||
|
dependsOn: "",
|
||||||
failWebhook: env.SSS_WEBHOOK,
|
failWebhook: env.SSS_WEBHOOK,
|
||||||
publishWebhooks: "${env.SSS_WEBHOOK}|${env.FDD_WH}"
|
publishWebhooks: "${env.SSS_WEBHOOK}|${env.FDD_WH}"
|
||||||
|
|
||||||
|
@@ -1,7 +1,10 @@
|
|||||||
archivesBaseName = "${mod_name.replace(" ", "")}-Common-${minecraft_version}"
|
archivesBaseName = "${mod_name.replace(" ", "")}-Common-${minecraft_version}"
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
stupidRemapArch("dev.ftb.mods:ftb-essentials:${ftb_essentials}")
|
||||||
|
stupidRemapArch("dev.ftb.mods:ftb-ranks:${ftb_ranks}")
|
||||||
|
|
||||||
|
stupidRemapArch("me.shedaniel.cloth:cloth-config:${cloth_config}")
|
||||||
}
|
}
|
||||||
|
|
||||||
shadowJar {
|
shadowJar {
|
||||||
|
@@ -1,53 +1,162 @@
|
|||||||
package com.hypherionmc.craterlib.api.commands;
|
package com.hypherionmc.craterlib.api.commands;
|
||||||
|
|
||||||
|
import com.hypherionmc.craterlib.CraterConstants;
|
||||||
|
import com.hypherionmc.craterlib.compat.LuckPermsCompat;
|
||||||
|
import com.hypherionmc.craterlib.core.platform.LoaderType;
|
||||||
|
import com.hypherionmc.craterlib.core.platform.ModloaderEnvironment;
|
||||||
import com.hypherionmc.craterlib.nojang.authlib.BridgedGameProfile;
|
import com.hypherionmc.craterlib.nojang.authlib.BridgedGameProfile;
|
||||||
import com.hypherionmc.craterlib.nojang.commands.BridgedCommandSourceStack;
|
import com.hypherionmc.craterlib.nojang.commands.BridgedCommandSourceStack;
|
||||||
import com.hypherionmc.craterlib.nojang.world.entity.player.BridgedPlayer;
|
import com.hypherionmc.craterlib.nojang.world.entity.player.BridgedPlayer;
|
||||||
import com.mojang.brigadier.arguments.ArgumentType;
|
import com.hypherionmc.craterlib.utils.TriConsumer;
|
||||||
import lombok.Getter;
|
import com.mojang.brigadier.CommandDispatcher;
|
||||||
|
import com.mojang.brigadier.arguments.BoolArgumentType;
|
||||||
|
import com.mojang.brigadier.arguments.IntegerArgumentType;
|
||||||
|
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||||
|
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||||
|
import net.minecraft.commands.CommandSourceStack;
|
||||||
|
import net.minecraft.commands.Commands;
|
||||||
import net.minecraft.commands.arguments.GameProfileArgument;
|
import net.minecraft.commands.arguments.GameProfileArgument;
|
||||||
import org.apache.commons.lang3.function.TriConsumer;
|
import net.minecraft.world.entity.player.Player;
|
||||||
import org.apache.commons.lang3.tuple.Pair;
|
import org.jetbrains.annotations.ApiStatus;
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.LinkedHashMap;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
@Getter
|
|
||||||
public class CraterCommand {
|
public class CraterCommand {
|
||||||
|
|
||||||
private final HashMap<String, Pair<ArgumentType<?>, TriConsumer<?, ?, BridgedCommandSourceStack>>> arguments = new LinkedHashMap<>();
|
private final LiteralArgumentBuilder<CommandSourceStack> mojangCommand;
|
||||||
private Consumer<BridgedCommandSourceStack> executor;
|
private int permLevel = 4;
|
||||||
|
private String luckPermNode = "";
|
||||||
|
|
||||||
private final String commandName;
|
CraterCommand(LiteralArgumentBuilder<CommandSourceStack> cmd) {
|
||||||
private int permissionLevel = 4;
|
this.mojangCommand = cmd;
|
||||||
|
|
||||||
CraterCommand(String commandName) {
|
|
||||||
this.commandName = commandName;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static CraterCommand literal(String commandName) {
|
public static CraterCommand literal(String commandName) {
|
||||||
return new CraterCommand(commandName);
|
return new CraterCommand(Commands.literal(commandName));
|
||||||
}
|
}
|
||||||
|
|
||||||
public CraterCommand requiresPermission(int perm) {
|
public CraterCommand requiresPermission(int perm) {
|
||||||
this.permissionLevel = perm;
|
this.permLevel = perm;
|
||||||
|
this.mojangCommand.requires(this::checkPermission);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CraterCommand withGameProfileArgument(String key, TriConsumer<BridgedPlayer, List<BridgedGameProfile>, BridgedCommandSourceStack> executor) {
|
public CraterCommand withNode(String key) {
|
||||||
arguments.put(key, Pair.of(GameProfileArgument.gameProfile(), executor));
|
this.luckPermNode = key;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public CraterCommand then(CraterCommand child) {
|
||||||
|
this.mojangCommand.then(child.mojangCommand);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CraterCommand withGameProfilesArgument(String key, CommandExecutorWithArgs<List<BridgedGameProfile>> executor) {
|
||||||
|
this.mojangCommand.then(Commands.argument(key, GameProfileArgument.gameProfile())
|
||||||
|
.executes(context -> executor.run(
|
||||||
|
BridgedPlayer.of(context.getSource().getPlayer()),
|
||||||
|
GameProfileArgument.getGameProfiles(context, key).stream().map(BridgedGameProfile::of).toList(),
|
||||||
|
BridgedCommandSourceStack.of(context.getSource()))
|
||||||
|
));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CraterCommand withBoolArgument(String key, CommandExecutorWithArgs<Boolean> executor) {
|
||||||
|
this.mojangCommand.then(Commands.argument(key, BoolArgumentType.bool())
|
||||||
|
.executes(context -> executor.run(
|
||||||
|
BridgedPlayer.of(context.getSource().getPlayer()),
|
||||||
|
BoolArgumentType.getBool(context, key),
|
||||||
|
BridgedCommandSourceStack.of(context.getSource())
|
||||||
|
)));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CraterCommand withWordArgument(String key, CommandExecutorWithArgs<String> executor) {
|
||||||
|
this.mojangCommand.then(Commands.argument(key, StringArgumentType.word())
|
||||||
|
.executes(context -> executor.run(
|
||||||
|
BridgedPlayer.of(context.getSource().getPlayer()),
|
||||||
|
StringArgumentType.getString(context, key),
|
||||||
|
BridgedCommandSourceStack.of(context.getSource())
|
||||||
|
)));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CraterCommand withStringArgument(String key, CommandExecutorWithArgs<String> executor) {
|
||||||
|
this.mojangCommand.then(Commands.argument(key, StringArgumentType.string())
|
||||||
|
.executes(context -> executor.run(
|
||||||
|
BridgedPlayer.of(context.getSource().getPlayer()),
|
||||||
|
StringArgumentType.getString(context, key),
|
||||||
|
BridgedCommandSourceStack.of(context.getSource())
|
||||||
|
)));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CraterCommand withPhraseArgument(String key, CommandExecutorWithArgs<String> executor) {
|
||||||
|
this.mojangCommand.then(Commands.argument(key, StringArgumentType.greedyString())
|
||||||
|
.executes(context -> executor.run(
|
||||||
|
BridgedPlayer.of(context.getSource().getPlayer()),
|
||||||
|
StringArgumentType.getString(context, key),
|
||||||
|
BridgedCommandSourceStack.of(context.getSource())
|
||||||
|
)));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CraterCommand withIntegerArgument(String key, CommandExecutorWithArgs<Integer> executor) {
|
||||||
|
this.mojangCommand.then(Commands.argument(key, IntegerArgumentType.integer())
|
||||||
|
.executes(context -> executor.run(
|
||||||
|
BridgedPlayer.of(context.getSource().getPlayer()),
|
||||||
|
IntegerArgumentType.getInteger(context, key),
|
||||||
|
BridgedCommandSourceStack.of(context.getSource())
|
||||||
|
)));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CraterCommand execute(SingleCommandExecutor<BridgedCommandSourceStack> executor) {
|
||||||
|
this.mojangCommand.executes(context -> executor.run(BridgedCommandSourceStack.of(context.getSource())));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated(forRemoval = true)
|
||||||
public CraterCommand executes(Consumer<BridgedCommandSourceStack> ctx) {
|
public CraterCommand executes(Consumer<BridgedCommandSourceStack> ctx) {
|
||||||
executor = ctx;
|
return this.execute(stack -> {
|
||||||
return this;
|
ctx.accept(stack);
|
||||||
|
return 1;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasArguments() {
|
@Deprecated(forRemoval = true)
|
||||||
return !arguments.isEmpty();
|
public CraterCommand withGameProfileArgument(String key, TriConsumer<BridgedPlayer, List<BridgedGameProfile>, BridgedCommandSourceStack> executor) {
|
||||||
|
return this.withGameProfilesArgument(key, (player, argument, stack) -> {
|
||||||
|
executor.accept(player, argument, stack);
|
||||||
|
return 1;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ApiStatus.Internal
|
||||||
|
public void register(CommandDispatcher<CommandSourceStack> stack) {
|
||||||
|
stack.register(this.mojangCommand);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean checkPermission(CommandSourceStack stack) {
|
||||||
|
try {
|
||||||
|
if (!ModloaderEnvironment.INSTANCE.isModLoaded("luckperms") || ModloaderEnvironment.INSTANCE.getLoaderType() == LoaderType.PAPER || !stack.isPlayer() || luckPermNode.isEmpty())
|
||||||
|
return stack.hasPermission(this.permLevel);
|
||||||
|
|
||||||
|
return LuckPermsCompat.INSTANCE.hasPermission(stack.getPlayer(), this.luckPermNode) || stack.hasPermission(this.permLevel);
|
||||||
|
} catch (Exception e) {
|
||||||
|
CraterConstants.LOG.error("Failed to check luckperms permissions", e);
|
||||||
|
return stack.hasPermission(this.permLevel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@FunctionalInterface
|
||||||
|
public interface CommandExecutorWithArgs<S> {
|
||||||
|
int run(BridgedPlayer player, S argument, BridgedCommandSourceStack stack);
|
||||||
|
}
|
||||||
|
|
||||||
|
@FunctionalInterface
|
||||||
|
public interface SingleCommandExecutor<S> {
|
||||||
|
int run(S stack);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,56 @@
|
|||||||
|
// @excludeplugin
|
||||||
|
package com.hypherionmc.craterlib.api.events.compat;
|
||||||
|
|
||||||
|
import com.hypherionmc.craterlib.compat.ftbranks.BridgedRank;
|
||||||
|
import com.hypherionmc.craterlib.core.event.CraterEvent;
|
||||||
|
import com.hypherionmc.craterlib.nojang.authlib.BridgedGameProfile;
|
||||||
|
import com.mojang.authlib.GameProfile;
|
||||||
|
import dev.ftb.mods.ftbranks.api.Rank;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
public class FTBRankEvents {
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
public static class RankAddedEvent extends CraterEvent {
|
||||||
|
private final BridgedGameProfile gameProfile;
|
||||||
|
private final BridgedRank rank;
|
||||||
|
|
||||||
|
private RankAddedEvent(BridgedGameProfile gameProfile, BridgedRank rank) {
|
||||||
|
this.gameProfile = gameProfile;
|
||||||
|
this.rank = rank;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static RankAddedEvent of(GameProfile profile, Rank rank) {
|
||||||
|
return new RankAddedEvent(BridgedGameProfile.of(profile), BridgedRank.of(rank));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
public static class RankRemovedEvent extends CraterEvent {
|
||||||
|
private final BridgedGameProfile gameProfile;
|
||||||
|
private final BridgedRank rank;
|
||||||
|
|
||||||
|
private RankRemovedEvent(BridgedGameProfile gameProfile, BridgedRank rank) {
|
||||||
|
this.gameProfile = gameProfile;
|
||||||
|
this.rank = rank;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static RankRemovedEvent of(GameProfile profile, Rank rank) {
|
||||||
|
return new RankRemovedEvent(BridgedGameProfile.of(profile), BridgedRank.of(rank));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
public static class RankDeletedEvent extends CraterEvent {
|
||||||
|
private final BridgedRank rank;
|
||||||
|
|
||||||
|
private RankDeletedEvent(BridgedRank rank) {
|
||||||
|
this.rank = rank;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static RankDeletedEvent of(Rank rank) {
|
||||||
|
return new RankDeletedEvent(BridgedRank.of(rank));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1,35 @@
|
|||||||
|
package com.hypherionmc.craterlib.api.events.compat;
|
||||||
|
|
||||||
|
import com.hypherionmc.craterlib.core.event.CraterEvent;
|
||||||
|
import com.hypherionmc.craterlib.nojang.authlib.BridgedGameProfile;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class LuckPermsCompatEvents {
|
||||||
|
|
||||||
|
@RequiredArgsConstructor(staticName = "of")
|
||||||
|
@Getter
|
||||||
|
public static class GroupAddedEvent extends CraterEvent {
|
||||||
|
private final String identifier;
|
||||||
|
private final UUID uuid;
|
||||||
|
private final String username;
|
||||||
|
|
||||||
|
public BridgedGameProfile toProfile() {
|
||||||
|
return BridgedGameProfile.mojang(uuid, username);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequiredArgsConstructor(staticName = "of")
|
||||||
|
@Getter
|
||||||
|
public static class GroupRemovedEvent extends CraterEvent {
|
||||||
|
private final String identifier;
|
||||||
|
private final UUID uuid;
|
||||||
|
private final String username;
|
||||||
|
|
||||||
|
public BridgedGameProfile toProfile() {
|
||||||
|
return BridgedGameProfile.mojang(uuid, username);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,12 @@
|
|||||||
|
package com.hypherionmc.craterlib.api.events.compat;
|
||||||
|
|
||||||
|
import com.hypherionmc.craterlib.core.event.CraterEvent;
|
||||||
|
import com.hypherionmc.craterlib.nojang.world.entity.player.BridgedPlayer;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
|
||||||
|
@RequiredArgsConstructor(staticName = "of")
|
||||||
|
@Getter
|
||||||
|
public class PlayerBleedOutEvent extends CraterEvent {
|
||||||
|
private final BridgedPlayer player;
|
||||||
|
}
|
@@ -0,0 +1,12 @@
|
|||||||
|
package com.hypherionmc.craterlib.api.events.compat;
|
||||||
|
|
||||||
|
import com.hypherionmc.craterlib.core.event.CraterEvent;
|
||||||
|
import com.hypherionmc.craterlib.nojang.world.entity.player.BridgedPlayer;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
|
||||||
|
@RequiredArgsConstructor(staticName = "of")
|
||||||
|
@Getter
|
||||||
|
public class PlayerRevivedEvent extends CraterEvent {
|
||||||
|
private final BridgedPlayer player;
|
||||||
|
}
|
@@ -53,6 +53,6 @@ public class CraterCommandEvent extends CraterEvent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Component getMessage() {
|
public Component getMessage() {
|
||||||
return ChatUtils.mojangToAdventure(ComponentArgument.getComponent(parseResults.getContext().build(parseResults.getReader().getString()), "message"));
|
return ChatUtils.mojangToAdventure(ComponentArgument.getRawComponent(parseResults.getContext().build(parseResults.getReader().getString()), "message"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -11,18 +11,32 @@ public class CraterPlayerEvent extends CraterEvent {
|
|||||||
|
|
||||||
private final BridgedPlayer player;
|
private final BridgedPlayer player;
|
||||||
|
|
||||||
|
@Getter
|
||||||
public static class PlayerLoggedIn extends CraterPlayerEvent {
|
public static class PlayerLoggedIn extends CraterPlayerEvent {
|
||||||
|
private final boolean isFromVanish;
|
||||||
|
|
||||||
public PlayerLoggedIn(BridgedPlayer player) {
|
public PlayerLoggedIn(BridgedPlayer player) {
|
||||||
|
this(player, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public PlayerLoggedIn(BridgedPlayer player, boolean isFromVanish) {
|
||||||
super(player);
|
super(player);
|
||||||
|
this.isFromVanish = isFromVanish;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Getter
|
||||||
public static class PlayerLoggedOut extends CraterPlayerEvent {
|
public static class PlayerLoggedOut extends CraterPlayerEvent {
|
||||||
|
private final boolean isFromVanish;
|
||||||
|
|
||||||
public PlayerLoggedOut(BridgedPlayer player) {
|
public PlayerLoggedOut(BridgedPlayer player) {
|
||||||
|
this(player, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public PlayerLoggedOut(BridgedPlayer player, boolean isFromVanish) {
|
||||||
super(player);
|
super(player);
|
||||||
|
this.isFromVanish = isFromVanish;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -2,14 +2,17 @@ package com.hypherionmc.craterlib.api.events.server;
|
|||||||
|
|
||||||
import com.hypherionmc.craterlib.api.commands.CraterCommand;
|
import com.hypherionmc.craterlib.api.commands.CraterCommand;
|
||||||
import com.hypherionmc.craterlib.core.event.CraterEvent;
|
import com.hypherionmc.craterlib.core.event.CraterEvent;
|
||||||
import com.hypherionmc.craterlib.nojang.commands.CommandsRegistry;
|
import com.mojang.brigadier.CommandDispatcher;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
|
import net.minecraft.commands.CommandSourceStack;
|
||||||
|
|
||||||
@NoArgsConstructor
|
@AllArgsConstructor
|
||||||
public class CraterRegisterCommandEvent extends CraterEvent {
|
public class CraterRegisterCommandEvent extends CraterEvent {
|
||||||
|
|
||||||
|
private final CommandDispatcher<CommandSourceStack> stack;
|
||||||
|
|
||||||
public void registerCommand(CraterCommand cmd) {
|
public void registerCommand(CraterCommand cmd) {
|
||||||
CommandsRegistry.INSTANCE.registerCommand(cmd);
|
cmd.register(stack);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,35 @@
|
|||||||
|
package com.hypherionmc.craterlib.api.events.server;
|
||||||
|
|
||||||
|
import com.hypherionmc.craterlib.core.event.CraterEvent;
|
||||||
|
import com.hypherionmc.craterlib.nojang.network.protocol.status.WrappedServerStatus;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.Setter;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
public class ServerStatusEvent {
|
||||||
|
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
public static class StatusRequestEvent extends CraterEvent {
|
||||||
|
|
||||||
|
private final Component status;
|
||||||
|
@Nullable
|
||||||
|
private Component newStatus = null;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
public static class FaviconRequestEvent extends CraterEvent {
|
||||||
|
|
||||||
|
private final Optional<WrappedServerStatus.WrappedFavicon> favicon;
|
||||||
|
private Optional<WrappedServerStatus.WrappedFavicon> newIcon = Optional.empty();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,26 @@
|
|||||||
|
package com.hypherionmc.craterlib.api.events.server;
|
||||||
|
|
||||||
|
import com.hypherionmc.craterlib.core.event.CraterEvent;
|
||||||
|
import com.hypherionmc.craterlib.nojang.authlib.BridgedGameProfile;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
|
||||||
|
public class WhitelistChangedEvent {
|
||||||
|
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@Getter
|
||||||
|
public static final class EntryAdded extends CraterEvent {
|
||||||
|
|
||||||
|
private final BridgedGameProfile profile;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@Getter
|
||||||
|
public static final class EntryRemoved extends CraterEvent {
|
||||||
|
|
||||||
|
private final BridgedGameProfile profile;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -4,8 +4,7 @@ import com.hypherionmc.craterlib.core.networking.data.PacketHolder;
|
|||||||
import com.hypherionmc.craterlib.nojang.network.BridgedFriendlyByteBuf;
|
import com.hypherionmc.craterlib.nojang.network.BridgedFriendlyByteBuf;
|
||||||
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
|
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
|
||||||
|
|
||||||
public record CommonPacketWrapper<T>(PacketHolder<T> container, T packet) implements CustomPacketPayload
|
public record CommonPacketWrapper<T>(PacketHolder<T> container, T packet) implements CustomPacketPayload {
|
||||||
{
|
|
||||||
public void encode(BridgedFriendlyByteBuf buf)
|
public void encode(BridgedFriendlyByteBuf buf)
|
||||||
{
|
{
|
||||||
container().encoder().accept(packet(), buf);
|
container().encoder().accept(packet(), buf);
|
||||||
|
@@ -0,0 +1,409 @@
|
|||||||
|
package com.hypherionmc.craterlib.client.gui.config;
|
||||||
|
|
||||||
|
import com.hypherionmc.craterlib.CraterConstants;
|
||||||
|
import com.hypherionmc.craterlib.client.gui.config.widgets.ClothConfigButtonEntry;
|
||||||
|
import com.hypherionmc.craterlib.core.config.AbstractConfig;
|
||||||
|
import com.hypherionmc.craterlib.core.config.annotations.HideFromScreen;
|
||||||
|
import com.hypherionmc.craterlib.core.config.annotations.SubConfig;
|
||||||
|
import com.hypherionmc.craterlib.core.config.annotations.Tooltip;
|
||||||
|
import me.hypherionmc.moonconfig.core.conversion.SpecComment;
|
||||||
|
import me.shedaniel.clothconfig2.api.ConfigBuilder;
|
||||||
|
import me.shedaniel.clothconfig2.api.ConfigCategory;
|
||||||
|
import me.shedaniel.clothconfig2.api.ConfigEntryBuilder;
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.client.gui.components.toasts.SystemToast;
|
||||||
|
import net.minecraft.client.gui.screens.Screen;
|
||||||
|
import net.minecraft.network.chat.Component;
|
||||||
|
import org.jetbrains.annotations.ApiStatus;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.lang.reflect.Modifier;
|
||||||
|
import java.lang.reflect.ParameterizedType;
|
||||||
|
import java.lang.reflect.Type;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.StandardCopyOption;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author HypherionSA
|
||||||
|
* A Helper Class to convert {@link AbstractConfig}s into Cloth Config Screens
|
||||||
|
*/
|
||||||
|
@SuppressWarnings({"rawtypes", "unchecked"})
|
||||||
|
@ApiStatus.Internal
|
||||||
|
public class ClothConfigScreenBuilder {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Build a new Cloth Config screen, from an {@link AbstractConfig}
|
||||||
|
*
|
||||||
|
* @param config The {@link AbstractConfig} the config screen is for
|
||||||
|
* @param parent The parent {@link Screen} this screen will return to when closed
|
||||||
|
* @return A fully usable Cloth Config screen
|
||||||
|
*/
|
||||||
|
public static Screen buildConfigScreen(AbstractConfig config, @Nullable Screen parent) {
|
||||||
|
ConfigBuilder builder = ConfigBuilder.create()
|
||||||
|
.setParentScreen(parent)
|
||||||
|
.setTitle(getTranslationKey(config, config, null));
|
||||||
|
|
||||||
|
readConfigFields(config, config, builder);
|
||||||
|
|
||||||
|
builder.setSavingRunnable(() -> safeSaveConfig(config));
|
||||||
|
return builder.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Build a new sub-screen for config entries marked with {@link SubConfig}
|
||||||
|
*
|
||||||
|
* @param config The {@link AbstractConfig} the config screen is for
|
||||||
|
* @param clazz The object or class that the screen is being built for
|
||||||
|
* @param parent The parent {@link Screen} this screen will return to when closed
|
||||||
|
* @return A fully usable Cloth Config screen
|
||||||
|
*/
|
||||||
|
private static Screen buildSubScreen(AbstractConfig config, Object clazz, @Nullable Screen parent) {
|
||||||
|
ConfigBuilder builder = ConfigBuilder.create()
|
||||||
|
.setParentScreen(parent)
|
||||||
|
.setTitle(getTranslationKey(config, clazz, null));
|
||||||
|
|
||||||
|
readConfigFields(config, clazz, builder);
|
||||||
|
|
||||||
|
builder.setSavingRunnable(() -> safeSaveConfig(config));
|
||||||
|
return builder.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Build a new screen, that allows editing lists of complex objects, like a list of Classes
|
||||||
|
*
|
||||||
|
* @param config The {@link AbstractConfig} the config screen is for
|
||||||
|
* @param list The list of objects this screen will be responsible for
|
||||||
|
* @param field The field this list belongs to in the main config
|
||||||
|
* @param invoker The object used to invoke the field, when setting the new value
|
||||||
|
* @param parent The parent {@link Screen} this screen will return to when closed
|
||||||
|
* @param edited Was this list edited
|
||||||
|
* @return A fully usable Cloth Config screen
|
||||||
|
*/
|
||||||
|
private static Screen buildListScreen(AbstractConfig config, List list, Field field, Object invoker, @Nullable Screen parent, boolean edited) {
|
||||||
|
ConfigBuilder builder = ConfigBuilder.create()
|
||||||
|
.setParentScreen(parent)
|
||||||
|
.setTitle(getTranslationKey(config, invoker, field.getName()));
|
||||||
|
|
||||||
|
ConfigCategory category = builder.getOrCreateCategory(Component.literal("Entries"));
|
||||||
|
|
||||||
|
// Handle Existing items in the list
|
||||||
|
for (int i = 0; i < list.size(); i++) {
|
||||||
|
Object item = list.get(i);
|
||||||
|
|
||||||
|
int finalI = i;
|
||||||
|
// Add a button to open the edit screen, as well as a delete button
|
||||||
|
category.addEntry(
|
||||||
|
new ClothConfigButtonEntry(
|
||||||
|
Component.translatable("cl.buttons.entry", (i + 1)),
|
||||||
|
Component.translatable("cl.buttons.edit"),
|
||||||
|
button -> Minecraft.getInstance().setScreen(
|
||||||
|
buildSubScreen(config, item, builder.build())
|
||||||
|
),
|
||||||
|
button -> {
|
||||||
|
list.remove(finalI);
|
||||||
|
saveFieldValue(list, field, invoker);
|
||||||
|
Minecraft.getInstance().setScreen(buildListScreen(config, list, field, invoker, parent, true));
|
||||||
|
},
|
||||||
|
edited
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add a button to add new list entries
|
||||||
|
Type listType = field.getGenericType();
|
||||||
|
if (listType instanceof ParameterizedType paramType) {
|
||||||
|
Class<?> elementType = (Class<?>) paramType.getActualTypeArguments()[0];
|
||||||
|
|
||||||
|
category.addEntry(
|
||||||
|
new ClothConfigButtonEntry(
|
||||||
|
Component.literal(""),
|
||||||
|
Component.translatable("cl.buttons.add_entry"),
|
||||||
|
button -> {
|
||||||
|
try {
|
||||||
|
Object newItem = elementType.getDeclaredConstructor().newInstance();
|
||||||
|
list.add(newItem);
|
||||||
|
saveFieldValue(list, field, invoker);
|
||||||
|
Minecraft.getInstance().setScreen(buildListScreen(config, list, field, invoker, parent, true));
|
||||||
|
} catch (Exception e) {
|
||||||
|
CraterConstants.LOG.error("Failed to create new list entry", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
builder.setSavingRunnable(() -> safeSaveConfig(config));
|
||||||
|
return builder.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A helper method to convert an {@link AbstractConfig} into the corresponding cloth config gui fields
|
||||||
|
*
|
||||||
|
* @param baseConfig The {@link AbstractConfig} to convert
|
||||||
|
* @param config The base class that is being processed
|
||||||
|
* @param builder The {@link ClothConfigScreenBuilder} we are currently working with
|
||||||
|
*/
|
||||||
|
private static void readConfigFields(AbstractConfig baseConfig, Object config, ConfigBuilder builder) {
|
||||||
|
ConfigEntryBuilder entryBuilder = builder.entryBuilder();
|
||||||
|
ConfigCategory configCategory = builder.getOrCreateCategory(Component.literal("General"));
|
||||||
|
|
||||||
|
for (Field field : config.getClass().getDeclaredFields()) {
|
||||||
|
try {
|
||||||
|
field.setAccessible(true);
|
||||||
|
|
||||||
|
// We ignore static, transient fields or fields marked with @HideFromScreen
|
||||||
|
final int fieldModifiers = field.getModifiers();
|
||||||
|
if (Modifier.isStatic(fieldModifiers) || Modifier.isTransient(fieldModifiers) || field.isAnnotationPresent(HideFromScreen.class))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
Object val = field.get(config);
|
||||||
|
|
||||||
|
// Field is marked as sub-config, so we add a button field for it
|
||||||
|
if (field.isAnnotationPresent(SubConfig.class)) {
|
||||||
|
if (val != null) {
|
||||||
|
configCategory.addEntry(
|
||||||
|
new ClothConfigButtonEntry(
|
||||||
|
Component.translatable("cl.config." + baseConfig.getClass().getSimpleName().toLowerCase() + "." + field.getName().toLowerCase()),
|
||||||
|
Component.translatable("cl.buttons.edit"),
|
||||||
|
button -> Minecraft.getInstance().setScreen(
|
||||||
|
buildSubScreen(baseConfig, val, builder.build())
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Boolean Values
|
||||||
|
if (val instanceof Boolean bool) {
|
||||||
|
configCategory.addEntry(entryBuilder.startBooleanToggle(getTranslationKey(baseConfig, config, field.getName()), bool)
|
||||||
|
.setTooltip(getToolTip(field))
|
||||||
|
.setSaveConsumer(newValue -> saveFieldValue(newValue, field, config))
|
||||||
|
.setDefaultValue(bool).build());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Enum Values
|
||||||
|
if (val instanceof Enum<?> enumValue) {
|
||||||
|
Class<Enum> enumClass = (Class<Enum>)enumValue.getDeclaringClass();
|
||||||
|
configCategory.addEntry(entryBuilder.startEnumSelector(
|
||||||
|
getTranslationKey(baseConfig, config, field.getName()),
|
||||||
|
enumClass,
|
||||||
|
enumValue)
|
||||||
|
.setTooltip(getToolTip(field))
|
||||||
|
.setSaveConsumer(newValue -> saveFieldValue(newValue, field, config))
|
||||||
|
.setDefaultValue(enumValue)
|
||||||
|
.build());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Int Values
|
||||||
|
if (val instanceof Integer intt) {
|
||||||
|
configCategory.addEntry(entryBuilder.startIntField(getTranslationKey(baseConfig, config, field.getName()), intt)
|
||||||
|
.setTooltip(getToolTip(field))
|
||||||
|
.setSaveConsumer(newValue -> saveFieldValue(newValue, field, config))
|
||||||
|
.setDefaultValue(intt).build());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Long Values
|
||||||
|
if (val instanceof Long longt) {
|
||||||
|
configCategory.addEntry(entryBuilder.startLongField(getTranslationKey(baseConfig, config, field.getName()), longt)
|
||||||
|
.setTooltip(getToolTip(field))
|
||||||
|
.setSaveConsumer(newValue -> saveFieldValue(newValue, field, config))
|
||||||
|
.setDefaultValue(longt).build());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Float Values
|
||||||
|
if (val instanceof Float floatt) {
|
||||||
|
configCategory.addEntry(entryBuilder.startFloatField(getTranslationKey(baseConfig, config, field.getName()), floatt)
|
||||||
|
.setTooltip(getToolTip(field))
|
||||||
|
.setSaveConsumer(newValue -> saveFieldValue(newValue, field, config))
|
||||||
|
.setDefaultValue(floatt).build());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Double Values
|
||||||
|
if (val instanceof Double doublet) {
|
||||||
|
configCategory.addEntry(entryBuilder.startDoubleField(getTranslationKey(baseConfig, config, field.getName()), doublet)
|
||||||
|
.setTooltip(getToolTip(field))
|
||||||
|
.setSaveConsumer(newValue -> saveFieldValue(newValue, field, config))
|
||||||
|
.setDefaultValue(doublet).build());
|
||||||
|
}
|
||||||
|
|
||||||
|
// String Values
|
||||||
|
if (val instanceof String string) {
|
||||||
|
configCategory.addEntry(entryBuilder.startStrField(getTranslationKey(baseConfig, config, field.getName()), string)
|
||||||
|
.setTooltip(getToolTip(field))
|
||||||
|
.setSaveConsumer(newValue -> saveFieldValue(newValue, field, config))
|
||||||
|
.setDefaultValue(string).build());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Lists
|
||||||
|
if (val instanceof List<?> list) {
|
||||||
|
Type listType = field.getGenericType();
|
||||||
|
if (listType instanceof ParameterizedType paramType) {
|
||||||
|
Type elementType = paramType.getActualTypeArguments()[0];
|
||||||
|
|
||||||
|
// String List
|
||||||
|
if (elementType.equals(String.class)) {
|
||||||
|
configCategory.addEntry(entryBuilder.startStrList(getTranslationKey(baseConfig, config, field.getName()), (List<String>) list)
|
||||||
|
.setTooltip(getToolTip(field))
|
||||||
|
.setSaveConsumer(newValue -> saveFieldValue(new ArrayList<>(newValue), field, config))
|
||||||
|
.setDefaultValue((List<String>) list).build());
|
||||||
|
|
||||||
|
// Int List
|
||||||
|
} else if (elementType.equals(Integer.class)) {
|
||||||
|
configCategory.addEntry(entryBuilder.startIntList(getTranslationKey(baseConfig, config, field.getName()), (List<Integer>) list)
|
||||||
|
.setTooltip(getToolTip(field))
|
||||||
|
.setSaveConsumer(newValue -> saveFieldValue(new ArrayList<>(newValue), field, config))
|
||||||
|
.setDefaultValue((List<Integer>) list).build());
|
||||||
|
|
||||||
|
// Long List
|
||||||
|
} else if (elementType.equals(Long.class)) {
|
||||||
|
configCategory.addEntry(entryBuilder.startLongList(getTranslationKey(baseConfig, config, field.getName()), (List<Long>) list)
|
||||||
|
.setTooltip(getToolTip(field))
|
||||||
|
.setSaveConsumer(newValue -> saveFieldValue(new ArrayList<>(newValue), field, config))
|
||||||
|
.setDefaultValue((List<Long>) list).build());
|
||||||
|
|
||||||
|
// Float List
|
||||||
|
} else if (elementType.equals(Float.class)) {
|
||||||
|
configCategory.addEntry(entryBuilder.startFloatList(getTranslationKey(baseConfig, config, field.getName()), (List<Float>) list)
|
||||||
|
.setTooltip(getToolTip(field))
|
||||||
|
.setSaveConsumer(newValue -> saveFieldValue(new ArrayList<>(newValue), field, config))
|
||||||
|
.setDefaultValue((List<Float>) list).build());
|
||||||
|
|
||||||
|
// Double List
|
||||||
|
} else if (elementType.equals(Double.class)) {
|
||||||
|
configCategory.addEntry(entryBuilder.startDoubleList(getTranslationKey(baseConfig, config, field.getName()), (List<Double>) list)
|
||||||
|
.setTooltip(getToolTip(field))
|
||||||
|
.setSaveConsumer(newValue -> saveFieldValue(new ArrayList<>(newValue), field, config))
|
||||||
|
.setDefaultValue((List<Double>) list).build());
|
||||||
|
} else {
|
||||||
|
// List of complex objects
|
||||||
|
configCategory.addEntry(
|
||||||
|
new ClothConfigButtonEntry(
|
||||||
|
getTranslationKey(baseConfig, config, field.getName()),
|
||||||
|
Component.translatable("cl.buttons.edit"),
|
||||||
|
button -> Minecraft.getInstance().setScreen(
|
||||||
|
buildListScreen(baseConfig, list, field, config, builder.build(), false)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
CraterConstants.LOG.error("Failed to process config file {}", baseConfig.getConfigName(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper method to supply tooltips to config fields.
|
||||||
|
* If the field has an {@link SpecComment}, we use that, otherwise we use the {@link Tooltip} annotation
|
||||||
|
* or generate one from the field name
|
||||||
|
*
|
||||||
|
* @param field The field that is being processed
|
||||||
|
* @return A {@link Component} that can be used for the tooltip
|
||||||
|
*/
|
||||||
|
private static Component getToolTip(Field field) {
|
||||||
|
Component component = Component.empty();
|
||||||
|
|
||||||
|
if (field.isAnnotationPresent(SpecComment.class)) {
|
||||||
|
SpecComment comment = field.getAnnotation(SpecComment.class);
|
||||||
|
component = Component.literal(comment.value());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (field.isAnnotationPresent(Tooltip.class)) {
|
||||||
|
Tooltip tooltip = field.getAnnotation(Tooltip.class);
|
||||||
|
Component c = Component.empty();
|
||||||
|
|
||||||
|
for (String comment : tooltip.value()) {
|
||||||
|
c.getSiblings().add(Component.literal(comment));
|
||||||
|
}
|
||||||
|
|
||||||
|
component = c;
|
||||||
|
}
|
||||||
|
|
||||||
|
return component;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A helper method to build translation keys for config screens, fields etc
|
||||||
|
*
|
||||||
|
* @param baseConfig The {@link AbstractConfig} being processed
|
||||||
|
* @param currentConfig The field being processed
|
||||||
|
* @param fieldName The raw name of the field
|
||||||
|
* @return A {@link Component} with the new translation key
|
||||||
|
*/
|
||||||
|
private static Component getTranslationKey(AbstractConfig baseConfig, Object currentConfig, String fieldName) {
|
||||||
|
String baseKey = "cl.config." + baseConfig.getClass().getSimpleName().toLowerCase();
|
||||||
|
|
||||||
|
if (currentConfig != baseConfig) {
|
||||||
|
baseKey += "." + currentConfig.getClass().getSimpleName().toLowerCase();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fieldName != null) {
|
||||||
|
baseKey += "." + fieldName.toLowerCase();
|
||||||
|
}
|
||||||
|
|
||||||
|
return Component.translatable(baseKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper method to write changes values back to the config using reflection
|
||||||
|
*
|
||||||
|
* @param value The new value of the field
|
||||||
|
* @param field The field that needs to be updated
|
||||||
|
* @param config The object used to invoke the field for updating
|
||||||
|
*/
|
||||||
|
private static void saveFieldValue(Object value, Field field, Object config) {
|
||||||
|
try {
|
||||||
|
if (value instanceof List && !field.getType().equals(List.class)) {
|
||||||
|
List newList = (List)field.getType().getDeclaredConstructor().newInstance();
|
||||||
|
newList.addAll((List)value);
|
||||||
|
field.set(config, newList);
|
||||||
|
} else {
|
||||||
|
field.set(config, value);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
CraterConstants.LOG.error("Failed to write config field {}", field.getName(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Safety method to prevent config screens from corrupting configs. In some edge cases, the config gui
|
||||||
|
* can generate invalid values, that cause the config saving to fail, and then save an empty file.
|
||||||
|
* This method makes a backup of the config before writing to it, and restores the backup if it fails
|
||||||
|
*
|
||||||
|
* @param config The {@link AbstractConfig} being saved
|
||||||
|
*/
|
||||||
|
private static void safeSaveConfig(AbstractConfig config) {
|
||||||
|
File configPath = config.getConfigPath();
|
||||||
|
Path backupPath = configPath.toPath().resolveSibling(configPath.getName() + ".bak");
|
||||||
|
|
||||||
|
try {
|
||||||
|
Files.copy(configPath.toPath(), backupPath, StandardCopyOption.REPLACE_EXISTING);
|
||||||
|
config.saveConfig(config);
|
||||||
|
Files.deleteIfExists(backupPath);
|
||||||
|
} catch (Exception e) {
|
||||||
|
Minecraft.getInstance().getToastManager().addToast(
|
||||||
|
new SystemToast(
|
||||||
|
SystemToast.SystemToastId.PACK_LOAD_FAILURE,
|
||||||
|
Component.literal("Failed To Save Config"),
|
||||||
|
Component.literal("Restoring Backup Copy. Check log for details"))
|
||||||
|
);
|
||||||
|
CraterConstants.LOG.error("Failed to save config, restoring backup", e);
|
||||||
|
try {
|
||||||
|
Files.copy(backupPath, configPath.toPath(), StandardCopyOption.REPLACE_EXISTING);
|
||||||
|
config.configReloaded();
|
||||||
|
} catch (Exception restoreError) {
|
||||||
|
CraterConstants.LOG.error("Failed to restore config backup", restoreError);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -2,7 +2,7 @@ package com.hypherionmc.craterlib.client.gui.config;
|
|||||||
|
|
||||||
import com.hypherionmc.craterlib.CraterConstants;
|
import com.hypherionmc.craterlib.CraterConstants;
|
||||||
import com.hypherionmc.craterlib.client.gui.config.widgets.*;
|
import com.hypherionmc.craterlib.client.gui.config.widgets.*;
|
||||||
import com.hypherionmc.craterlib.core.config.ModuleConfig;
|
import com.hypherionmc.craterlib.core.config.AbstractConfig;
|
||||||
import com.hypherionmc.craterlib.core.config.annotations.HideFromScreen;
|
import com.hypherionmc.craterlib.core.config.annotations.HideFromScreen;
|
||||||
import com.hypherionmc.craterlib.core.config.annotations.SubConfig;
|
import com.hypherionmc.craterlib.core.config.annotations.SubConfig;
|
||||||
import com.hypherionmc.craterlib.core.config.annotations.Tooltip;
|
import com.hypherionmc.craterlib.core.config.annotations.Tooltip;
|
||||||
@@ -37,6 +37,8 @@ import java.util.function.Supplier;
|
|||||||
/**
|
/**
|
||||||
* @author HypherionSA
|
* @author HypherionSA
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
@Deprecated(forRemoval = true, since = "2.1.3")
|
||||||
public class CraterConfigScreen extends Screen {
|
public class CraterConfigScreen extends Screen {
|
||||||
public static final float SCROLLBAR_BOTTOM_COLOR = .5f;
|
public static final float SCROLLBAR_BOTTOM_COLOR = .5f;
|
||||||
public static final float SCROLLBAR_TOP_COLOR = .67f;
|
public static final float SCROLLBAR_TOP_COLOR = .67f;
|
||||||
@@ -44,11 +46,11 @@ public class CraterConfigScreen extends Screen {
|
|||||||
private static final int BOTTOM = 24;
|
private static final int BOTTOM = 24;
|
||||||
private final Screen parent;
|
private final Screen parent;
|
||||||
private final List<Option<?>> options = new ArrayList<>();
|
private final List<Option<?>> options = new ArrayList<>();
|
||||||
private final ModuleConfig config;
|
private final AbstractConfig config;
|
||||||
public double scrollerAmount;
|
public double scrollerAmount;
|
||||||
private boolean dragging;
|
private boolean dragging;
|
||||||
|
|
||||||
public CraterConfigScreen(ModuleConfig config, Screen parent, Object subConfig) {
|
public CraterConfigScreen(AbstractConfig config, Screen parent, Object subConfig) {
|
||||||
super(Component.translatable("cl." + config.getClass().getSimpleName().toLowerCase() + ".title"));
|
super(Component.translatable("cl." + config.getClass().getSimpleName().toLowerCase() + ".title"));
|
||||||
this.parent = parent;
|
this.parent = parent;
|
||||||
this.config = config;
|
this.config = config;
|
||||||
@@ -59,7 +61,7 @@ public class CraterConfigScreen extends Screen {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public CraterConfigScreen(ModuleConfig config, Screen parent) {
|
public CraterConfigScreen(AbstractConfig config, Screen parent) {
|
||||||
this(config, parent, null);
|
this(config, parent, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -158,7 +160,7 @@ public class CraterConfigScreen extends Screen {
|
|||||||
return new TextConfigOption<>(Objects::toString, BigDecimal::new);
|
return new TextConfigOption<>(Objects::toString, BigDecimal::new);
|
||||||
}
|
}
|
||||||
if (value instanceof ResourceLocation) {
|
if (value instanceof ResourceLocation) {
|
||||||
return new TextConfigOption<>(Objects::toString, ResourceLocation::new);
|
return new TextConfigOption<>(Objects::toString, ResourceLocation::parse);
|
||||||
}
|
}
|
||||||
if (isSubConfig) {
|
if (isSubConfig) {
|
||||||
return new SubConfigWidget<>(config, this, value);
|
return new SubConfigWidget<>(config, this, value);
|
||||||
@@ -178,7 +180,7 @@ public class CraterConfigScreen extends Screen {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render(@NotNull GuiGraphics matrices, int mouseX, int mouseY, float delta) {
|
public void render(@NotNull GuiGraphics matrices, int mouseX, int mouseY, float delta) {
|
||||||
overlayBackground(matrices.pose(), TOP, height - BOTTOM, 32);
|
/*overlayBackground(matrices.pose(), TOP, height - BOTTOM, 32);
|
||||||
renderScrollBar();
|
renderScrollBar();
|
||||||
|
|
||||||
matrices.pose().pushPose();
|
matrices.pose().pushPose();
|
||||||
@@ -197,7 +199,7 @@ public class CraterConfigScreen extends Screen {
|
|||||||
option.render(minecraft, font, 40, y, width - 80, height1, matrices, mouseX, mouseY, delta);
|
option.render(minecraft, font, 40, y, width - 80, height1, matrices, mouseX, mouseY, delta);
|
||||||
renderConfigTooltip(matrices, font, mouseX, mouseY, 40, y, font.width(option.text), height1, option.text.getString(), option.getLangKeys().toArray(new String[0]));
|
renderConfigTooltip(matrices, font, mouseX, mouseY, 40, y, font.width(option.text), height1, option.text.getString(), option.getLangKeys().toArray(new String[0]));
|
||||||
y += height1;
|
y += height1;
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
private void renderScrollBar() {
|
private void renderScrollBar() {
|
||||||
@@ -216,49 +218,47 @@ public class CraterConfigScreen extends Screen {
|
|||||||
int maxY = this.height - BOTTOM;
|
int maxY = this.height - BOTTOM;
|
||||||
//RenderSystem.disableTexture();
|
//RenderSystem.disableTexture();
|
||||||
Tesselator tesselator = Tesselator.getInstance();
|
Tesselator tesselator = Tesselator.getInstance();
|
||||||
BufferBuilder buffer = tesselator.getBuilder();
|
BufferBuilder buffer = tesselator.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR);
|
||||||
RenderSystem.setShader(GameRenderer::getPositionColorShader);
|
//RenderSystem.setShader(RenderSystem.getShader());
|
||||||
buffer.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR);
|
|
||||||
|
|
||||||
buffer.vertex(scrollbarPositionMinX, maxY, 0.0D).color(0, 0, 0, 255).endVertex();
|
buffer.addVertex(scrollbarPositionMinX, maxY, 0.0f).setColor(0, 0, 0, 255);
|
||||||
buffer.vertex(scrollbarPositionMaxX, maxY, 0.0D).color(0, 0, 0, 255).endVertex();
|
buffer.addVertex(scrollbarPositionMaxX, maxY, 0.0f).setColor(0, 0, 0, 255);
|
||||||
buffer.vertex(scrollbarPositionMaxX, TOP, 0.0D).color(0, 0, 0, 255).endVertex();
|
buffer.addVertex(scrollbarPositionMaxX, TOP, 0.0f).setColor(0, 0, 0, 255);
|
||||||
buffer.vertex(scrollbarPositionMinX, TOP, 0.0D).color(0, 0, 0, 255).endVertex();
|
buffer.addVertex(scrollbarPositionMinX, TOP, 0.0f).setColor(0, 0, 0, 255);
|
||||||
|
|
||||||
buffer.vertex(scrollbarPositionMinX, minY + height, 0.0D).color(SCROLLBAR_BOTTOM_COLOR, SCROLLBAR_BOTTOM_COLOR, SCROLLBAR_BOTTOM_COLOR, 1).endVertex();
|
buffer.addVertex(scrollbarPositionMinX, minY + height, 0.0f).setColor(SCROLLBAR_BOTTOM_COLOR, SCROLLBAR_BOTTOM_COLOR, SCROLLBAR_BOTTOM_COLOR, 1);
|
||||||
buffer.vertex(scrollbarPositionMaxX, minY + height, 0.0D).color(SCROLLBAR_BOTTOM_COLOR, SCROLLBAR_BOTTOM_COLOR, SCROLLBAR_BOTTOM_COLOR, 1).endVertex();
|
buffer.addVertex(scrollbarPositionMaxX, minY + height, 0.0f).setColor(SCROLLBAR_BOTTOM_COLOR, SCROLLBAR_BOTTOM_COLOR, SCROLLBAR_BOTTOM_COLOR, 1);
|
||||||
buffer.vertex(scrollbarPositionMaxX, minY, 0.0D).color(SCROLLBAR_BOTTOM_COLOR, SCROLLBAR_BOTTOM_COLOR, SCROLLBAR_BOTTOM_COLOR, 1).endVertex();
|
buffer.addVertex(scrollbarPositionMaxX, minY, 0.0f).setColor(SCROLLBAR_BOTTOM_COLOR, SCROLLBAR_BOTTOM_COLOR, SCROLLBAR_BOTTOM_COLOR, 1);
|
||||||
buffer.vertex(scrollbarPositionMinX, minY, 0.0D).color(SCROLLBAR_BOTTOM_COLOR, SCROLLBAR_BOTTOM_COLOR, SCROLLBAR_BOTTOM_COLOR, 1).endVertex();
|
buffer.addVertex(scrollbarPositionMinX, minY, 0.0f).setColor(SCROLLBAR_BOTTOM_COLOR, SCROLLBAR_BOTTOM_COLOR, SCROLLBAR_BOTTOM_COLOR, 1);
|
||||||
buffer.vertex(scrollbarPositionMinX, (minY + height - 1), 0.0D).color(SCROLLBAR_TOP_COLOR, SCROLLBAR_TOP_COLOR, SCROLLBAR_TOP_COLOR, 1).endVertex();
|
buffer.addVertex(scrollbarPositionMinX, (minY + height - 1), 0.0f).setColor(SCROLLBAR_TOP_COLOR, SCROLLBAR_TOP_COLOR, SCROLLBAR_TOP_COLOR, 1);
|
||||||
buffer.vertex((scrollbarPositionMaxX - 1), (minY + height - 1), 0.0D).color(SCROLLBAR_TOP_COLOR, SCROLLBAR_TOP_COLOR, SCROLLBAR_TOP_COLOR, 1).endVertex();
|
buffer.addVertex((scrollbarPositionMaxX - 1), (minY + height - 1), 0.0f).setColor(SCROLLBAR_TOP_COLOR, SCROLLBAR_TOP_COLOR, SCROLLBAR_TOP_COLOR, 1);
|
||||||
buffer.vertex((scrollbarPositionMaxX - 1), minY, 0.0D).color(SCROLLBAR_TOP_COLOR, SCROLLBAR_TOP_COLOR, SCROLLBAR_TOP_COLOR, 1).endVertex();
|
buffer.addVertex((scrollbarPositionMaxX - 1), minY, 0.0f).setColor(SCROLLBAR_TOP_COLOR, SCROLLBAR_TOP_COLOR, SCROLLBAR_TOP_COLOR, 1);
|
||||||
buffer.vertex(scrollbarPositionMinX, minY, 0.0D).color(SCROLLBAR_TOP_COLOR, SCROLLBAR_TOP_COLOR, SCROLLBAR_TOP_COLOR, 1).endVertex();
|
buffer.addVertex(scrollbarPositionMinX, minY, 0.0f).setColor(SCROLLBAR_TOP_COLOR, SCROLLBAR_TOP_COLOR, SCROLLBAR_TOP_COLOR, 1);
|
||||||
tesselator.end();
|
//BufferUploader.drawWithShader(buffer.buildOrThrow());
|
||||||
RenderSystem.disableBlend();
|
//RenderSystem.disableBlend();
|
||||||
//RenderSystem.enableTexture();
|
//RenderSystem.enableTexture();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void renderShadow(PoseStack matrices) {
|
private void renderShadow(PoseStack matrices) {
|
||||||
Tesselator tesselator = Tesselator.getInstance();
|
Tesselator tesselator = Tesselator.getInstance();
|
||||||
BufferBuilder buffer = tesselator.getBuilder();
|
BufferBuilder buffer = tesselator.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX_COLOR);
|
||||||
RenderSystem.enableBlend();
|
//RenderSystem.enableBlend();
|
||||||
RenderSystem.blendFuncSeparate(770, 771, 0, 1);
|
//RenderSystem.blendFuncSeparate(770, 771, 0, 1);
|
||||||
//RenderSystem.disableTexture();
|
//RenderSystem.disableTexture();
|
||||||
RenderSystem.setShader(GameRenderer::getPositionTexColorShader);
|
//RenderSystem.setShader(GameRenderer::getPositionTexColorShader);
|
||||||
Matrix4f matrix = matrices.last().pose();
|
Matrix4f matrix = matrices.last().pose();
|
||||||
buffer.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX_COLOR);
|
buffer.addVertex(matrix, 0, TOP + 4, 0.0F).setUv(0, 1).setColor(0, 0, 0, 0);
|
||||||
buffer.vertex(matrix, 0, TOP + 4, 0.0F).uv(0, 1).color(0, 0, 0, 0).endVertex();
|
buffer.addVertex(matrix, width, TOP + 4, 0.0F).setUv(1, 1).setColor(0, 0, 0, 0);
|
||||||
buffer.vertex(matrix, width, TOP + 4, 0.0F).uv(1, 1).color(0, 0, 0, 0).endVertex();
|
buffer.addVertex(matrix, width, TOP, 0.0F).setUv(1, 0).setColor(0, 0, 0, 185);
|
||||||
buffer.vertex(matrix, width, TOP, 0.0F).uv(1, 0).color(0, 0, 0, 185).endVertex();
|
buffer.addVertex(matrix, 0, TOP, 0.0F).setUv(0, 0).setColor(0, 0, 0, 185);
|
||||||
buffer.vertex(matrix, 0, TOP, 0.0F).uv(0, 0).color(0, 0, 0, 185).endVertex();
|
buffer.addVertex(matrix, 0, height - BOTTOM, 0.0F).setUv(0, 1).setColor(0, 0, 0, 185);
|
||||||
buffer.vertex(matrix, 0, height - BOTTOM, 0.0F).uv(0, 1).color(0, 0, 0, 185).endVertex();
|
buffer.addVertex(matrix, width, height - BOTTOM, 0.0F).setUv(1, 1).setColor(0, 0, 0, 185);
|
||||||
buffer.vertex(matrix, width, height - BOTTOM, 0.0F).uv(1, 1).color(0, 0, 0, 185).endVertex();
|
buffer.addVertex(matrix, width, height - BOTTOM - 4, 0.0F).setUv(1, 0).setColor(0, 0, 0, 0);
|
||||||
buffer.vertex(matrix, width, height - BOTTOM - 4, 0.0F).uv(1, 0).color(0, 0, 0, 0).endVertex();
|
buffer.addVertex(matrix, 0, height - BOTTOM - 4, 0.0F).setUv(0, 0).setColor(0, 0, 0, 0);
|
||||||
buffer.vertex(matrix, 0, height - BOTTOM - 4, 0.0F).uv(0, 0).color(0, 0, 0, 0).endVertex();
|
//BufferUploader.drawWithShader(buffer.buildOrThrow());
|
||||||
tesselator.end();
|
|
||||||
//RenderSystem.enableTexture();
|
//RenderSystem.enableTexture();
|
||||||
RenderSystem.disableBlend();
|
//RenderSystem.disableBlend();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void overlayBackground(PoseStack matrices, int h1, int h2, int color) {
|
protected void overlayBackground(PoseStack matrices, int h1, int h2, int color) {
|
||||||
@@ -267,16 +267,15 @@ public class CraterConfigScreen extends Screen {
|
|||||||
|
|
||||||
protected void overlayBackground(Matrix4f matrix, int minX, int minY, int maxX, int maxY, int red, int green, int blue, int startAlpha, int endAlpha) {
|
protected void overlayBackground(Matrix4f matrix, int minX, int minY, int maxX, int maxY, int red, int green, int blue, int startAlpha, int endAlpha) {
|
||||||
Tesselator tesselator = Tesselator.getInstance();
|
Tesselator tesselator = Tesselator.getInstance();
|
||||||
BufferBuilder buffer = tesselator.getBuilder();
|
BufferBuilder buffer = tesselator.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX_COLOR);
|
||||||
RenderSystem.setShader(GameRenderer::getPositionTexColorShader);
|
//RenderSystem.setShader(GameRenderer::getPositionTexColorShader);
|
||||||
RenderSystem.setShaderTexture(0, Screen.MENU_BACKGROUND);
|
//RenderSystem.setShaderTexture(0, Screen.MENU_BACKGROUND);
|
||||||
RenderSystem.setShaderColor(1.0f, 1.0f, 1.0f, 1.0f);
|
//RenderSystem.setShaderColor(1.0f, 1.0f, 1.0f, 1.0f);
|
||||||
buffer.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX_COLOR);
|
buffer.addVertex(matrix, minX, maxY, 0.0F).setUv(minX / 32.0F, maxY / 32.0F).setColor(red, green, blue, endAlpha);
|
||||||
buffer.vertex(matrix, minX, maxY, 0.0F).uv(minX / 32.0F, maxY / 32.0F).color(red, green, blue, endAlpha).endVertex();
|
buffer.addVertex(matrix, maxX, maxY, 0.0F).setUv(maxX / 32.0F, maxY / 32.0F).setColor(red, green, blue, endAlpha);
|
||||||
buffer.vertex(matrix, maxX, maxY, 0.0F).uv(maxX / 32.0F, maxY / 32.0F).color(red, green, blue, endAlpha).endVertex();
|
buffer.addVertex(matrix, maxX, minY, 0.0F).setUv(maxX / 32.0F, minY / 32.0F).setColor(red, green, blue, startAlpha);
|
||||||
buffer.vertex(matrix, maxX, minY, 0.0F).uv(maxX / 32.0F, minY / 32.0F).color(red, green, blue, startAlpha).endVertex();
|
buffer.addVertex(matrix, minX, minY, 0.0F).setUv(minX / 32.0F, minY / 32.0F).setColor(red, green, blue, startAlpha);
|
||||||
buffer.vertex(matrix, minX, minY, 0.0F).uv(minX / 32.0F, minY / 32.0F).color(red, green, blue, startAlpha).endVertex();
|
//BufferUploader.drawWithShader(buffer.buildOrThrow());
|
||||||
tesselator.end();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int scrollHeight() {
|
public int scrollHeight() {
|
||||||
@@ -343,9 +342,9 @@ public class CraterConfigScreen extends Screen {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean mouseClicked(double d, double e, int i) {
|
public boolean mouseClicked(double d, double e, int i, boolean bl) {
|
||||||
this.dragging = i == 0 && d >= width - 6 && d < width;
|
this.dragging = i == 0 && d >= width - 6 && d < width;
|
||||||
return super.mouseClicked(d, e, i) || dragging;
|
return super.mouseClicked(d, e, i, bl);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -386,7 +385,7 @@ public class CraterConfigScreen extends Screen {
|
|||||||
for (String desc : description) {
|
for (String desc : description) {
|
||||||
list.add(Component.translatable(desc));
|
list.add(Component.translatable(desc));
|
||||||
}
|
}
|
||||||
stack.renderComponentTooltip(font, list, mouseX, mouseY);
|
//stack.renderComponentTooltip(font, list, mouseX, mouseY);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -10,6 +10,7 @@ import net.minecraft.client.gui.components.EditBox;
|
|||||||
* Copied from Cloth Config Lite
|
* Copied from Cloth Config Lite
|
||||||
* <a href="https://github.com/shedaniel/cloth-config-lite/blob/1.17/src/main/java/me/shedaniel/clothconfiglite/impl/option/AbstractWidgetOption.java">...</a>
|
* <a href="https://github.com/shedaniel/cloth-config-lite/blob/1.17/src/main/java/me/shedaniel/clothconfiglite/impl/option/AbstractWidgetOption.java">...</a>
|
||||||
*/
|
*/
|
||||||
|
@Deprecated(forRemoval = true, since = "2.1.3")
|
||||||
public class AbstractConfigWidget<T, W extends AbstractWidget> extends BaseWidget<T> {
|
public class AbstractConfigWidget<T, W extends AbstractWidget> extends BaseWidget<T> {
|
||||||
|
|
||||||
public static final int buttonWidth = 200;
|
public static final int buttonWidth = 200;
|
||||||
|
@@ -13,6 +13,7 @@ import net.minecraft.network.chat.TextColor;
|
|||||||
* Copied from Cloth Config Lite
|
* Copied from Cloth Config Lite
|
||||||
* <a href="https://github.com/shedaniel/cloth-config-lite/blob/1.17/src/main/java/me/shedaniel/clothconfiglite/impl/option/BaseOption.java">...</a>
|
* <a href="https://github.com/shedaniel/cloth-config-lite/blob/1.17/src/main/java/me/shedaniel/clothconfiglite/impl/option/BaseOption.java">...</a>
|
||||||
*/
|
*/
|
||||||
|
@Deprecated(forRemoval = true, since = "2.1.3")
|
||||||
public class BaseWidget<T> extends Option<T> {
|
public class BaseWidget<T> extends Option<T> {
|
||||||
|
|
||||||
public static final int resetButtonOffset = 48;
|
public static final int resetButtonOffset = 48;
|
||||||
|
@@ -0,0 +1,128 @@
|
|||||||
|
package com.hypherionmc.craterlib.client.gui.config.widgets;
|
||||||
|
|
||||||
|
import com.mojang.blaze3d.platform.Window;
|
||||||
|
import me.shedaniel.clothconfig2.api.AbstractConfigListEntry;
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.client.gui.GuiGraphics;
|
||||||
|
import net.minecraft.client.gui.components.Button;
|
||||||
|
import net.minecraft.client.gui.components.events.GuiEventListener;
|
||||||
|
import net.minecraft.client.gui.narration.NarratableEntry;
|
||||||
|
import net.minecraft.network.chat.Component;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author HypherionSA
|
||||||
|
* A Custom Cloth Config GUI entry to allow buttons to be added to the GUI
|
||||||
|
*/
|
||||||
|
public class ClothConfigButtonEntry extends AbstractConfigListEntry<Void> {
|
||||||
|
|
||||||
|
private final Button button;
|
||||||
|
private final Button deleteButton;
|
||||||
|
private final Component displayName;
|
||||||
|
private final boolean hasDeleteButton;
|
||||||
|
private final boolean wasEdited;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new Cloth Button Entry, that will have no delete button
|
||||||
|
*
|
||||||
|
* @param displayName The Display Name that will be used for the field
|
||||||
|
* @param fieldName The Display Name that will be used on the button
|
||||||
|
* @param onPress The Action to perform when the button was pressed
|
||||||
|
*/
|
||||||
|
public ClothConfigButtonEntry(Component displayName, Component fieldName, @Nullable Button.OnPress onPress) {
|
||||||
|
this(displayName, fieldName, onPress, null, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/***
|
||||||
|
* Create a new Cloth Button Entry, with optional delete button
|
||||||
|
*
|
||||||
|
* @param displayName The Display Name that will be used for the field
|
||||||
|
* @param fieldName The Display Name that will be used on the button
|
||||||
|
* @param onPress The Action to perform when the button was pressed
|
||||||
|
* @param deletePress The Action to perform when the delete button is pressed. If this is null, the button is disabled
|
||||||
|
* @param wasEdited Was a change made to the field this button belongs to. This is to tell cloth to enable the save button
|
||||||
|
*/
|
||||||
|
public ClothConfigButtonEntry(Component displayName, Component fieldName, Button.OnPress onPress, @Nullable Button.OnPress deletePress, boolean wasEdited) {
|
||||||
|
super(fieldName, false);
|
||||||
|
this.hasDeleteButton = deletePress != null;
|
||||||
|
this.wasEdited = wasEdited;
|
||||||
|
|
||||||
|
int mainButtonWidth = hasDeleteButton ? 75 : 100;
|
||||||
|
this.button = Button.builder(fieldName, onPress).size(mainButtonWidth, 20).pos(0, 0).build();
|
||||||
|
this.deleteButton = deletePress != null ? Button.builder(Component.literal("X"), deletePress).size(20, 20).pos(0, 0).build() : null;
|
||||||
|
this.displayName = displayName;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void render(GuiGraphics matrices, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean isHovered, float delta) {
|
||||||
|
Window window = Minecraft.getInstance().getWindow();
|
||||||
|
Component displayedFieldName = displayName;
|
||||||
|
if (Minecraft.getInstance().font.isBidirectional()) {
|
||||||
|
matrices.drawString(Minecraft.getInstance().font, displayedFieldName.getVisualOrderText(), window.getGuiScaledWidth() - x - Minecraft.getInstance().font.width(displayedFieldName), y + 6, 16777215);
|
||||||
|
this.button.setX(x);
|
||||||
|
if (hasDeleteButton) {
|
||||||
|
this.deleteButton.setX(x + this.button.getWidth() + 4);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
matrices.drawString(Minecraft.getInstance().font, displayedFieldName.getVisualOrderText(), x, y + 6, this.getPreferredTextColor());
|
||||||
|
if (hasDeleteButton) {
|
||||||
|
this.button.setX(x + entryWidth - this.button.getWidth() - 24);
|
||||||
|
this.deleteButton.setX(x + entryWidth - 20);
|
||||||
|
} else {
|
||||||
|
this.button.setX(x + entryWidth - this.button.getWidth());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
button.setY(y + (entryHeight - 20) / 2);
|
||||||
|
button.render(matrices, mouseX, mouseY, delta);
|
||||||
|
|
||||||
|
if (hasDeleteButton) {
|
||||||
|
deleteButton.setY(y + (entryHeight - 20) / 2);
|
||||||
|
deleteButton.render(matrices, mouseX, mouseY, delta);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Void getValue() { return null; }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Optional<Void> getDefaultValue() { return Optional.empty(); }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void save() {}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public List<? extends GuiEventListener> children() {
|
||||||
|
ArrayList<GuiEventListener> children = new ArrayList<>();
|
||||||
|
children.add(button);
|
||||||
|
|
||||||
|
if (hasDeleteButton) {
|
||||||
|
children.add(deleteButton);
|
||||||
|
}
|
||||||
|
|
||||||
|
return children;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<? extends NarratableEntry> narratables() {
|
||||||
|
ArrayList<NarratableEntry> children = new ArrayList<>();
|
||||||
|
children.add(button);
|
||||||
|
|
||||||
|
if (hasDeleteButton) {
|
||||||
|
children.add(deleteButton);
|
||||||
|
}
|
||||||
|
|
||||||
|
return children;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isEdited() {
|
||||||
|
return wasEdited;
|
||||||
|
}
|
||||||
|
}
|
@@ -10,6 +10,7 @@ import net.minecraft.network.chat.Component;
|
|||||||
/**
|
/**
|
||||||
* @author HypherionSA
|
* @author HypherionSA
|
||||||
*/
|
*/
|
||||||
|
@Deprecated(forRemoval = true, since = "2.1.3")
|
||||||
public class InternalConfigButton extends AbstractButton {
|
public class InternalConfigButton extends AbstractButton {
|
||||||
|
|
||||||
CraterConfigScreen screen;
|
CraterConfigScreen screen;
|
||||||
|
@@ -20,6 +20,7 @@ import java.util.function.Supplier;
|
|||||||
* Copied from Cloth Config Lite
|
* Copied from Cloth Config Lite
|
||||||
* <a href="https://github.com/shedaniel/cloth-config-lite/blob/1.17/src/main/java/me/shedaniel/clothconfiglite/impl/option/Option.java">...</a>
|
* <a href="https://github.com/shedaniel/cloth-config-lite/blob/1.17/src/main/java/me/shedaniel/clothconfiglite/impl/option/Option.java">...</a>
|
||||||
*/
|
*/
|
||||||
|
@Deprecated(forRemoval = true, since = "2.1.3")
|
||||||
public abstract class Option<T> extends AbstractContainerEventHandler {
|
public abstract class Option<T> extends AbstractContainerEventHandler {
|
||||||
|
|
||||||
public Component text;
|
public Component text;
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
package com.hypherionmc.craterlib.client.gui.config.widgets;
|
package com.hypherionmc.craterlib.client.gui.config.widgets;
|
||||||
|
|
||||||
import com.hypherionmc.craterlib.client.gui.config.CraterConfigScreen;
|
import com.hypherionmc.craterlib.client.gui.config.CraterConfigScreen;
|
||||||
import com.hypherionmc.craterlib.core.config.ModuleConfig;
|
import com.hypherionmc.craterlib.core.config.AbstractConfig;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.gui.Font;
|
import net.minecraft.client.gui.Font;
|
||||||
import net.minecraft.client.gui.GuiGraphics;
|
import net.minecraft.client.gui.GuiGraphics;
|
||||||
@@ -12,13 +12,14 @@ import net.minecraft.network.chat.Component;
|
|||||||
/**
|
/**
|
||||||
* @author HypherionSA
|
* @author HypherionSA
|
||||||
*/
|
*/
|
||||||
|
@Deprecated(forRemoval = true, since = "2.1.3")
|
||||||
public class SubConfigWidget<T> extends AbstractConfigWidget<T, Button> {
|
public class SubConfigWidget<T> extends AbstractConfigWidget<T, Button> {
|
||||||
|
|
||||||
private final Object subConfig;
|
private final Object subConfig;
|
||||||
private final ModuleConfig config;
|
private final AbstractConfig config;
|
||||||
private final Screen screen;
|
private final Screen screen;
|
||||||
|
|
||||||
public SubConfigWidget(ModuleConfig config, Screen screen, Object subConfig) {
|
public SubConfigWidget(AbstractConfig config, Screen screen, Object subConfig) {
|
||||||
this.config = config;
|
this.config = config;
|
||||||
this.subConfig = subConfig;
|
this.subConfig = subConfig;
|
||||||
this.screen = screen;
|
this.screen = screen;
|
||||||
|
@@ -10,6 +10,7 @@ import java.util.function.Function;
|
|||||||
* Copied from Cloth Config Lite
|
* Copied from Cloth Config Lite
|
||||||
* <a href="https://github.com/shedaniel/cloth-config-lite/blob/1.17/src/main/java/me/shedaniel/clothconfiglite/impl/option/TextFieldOption.java">...</a>
|
* <a href="https://github.com/shedaniel/cloth-config-lite/blob/1.17/src/main/java/me/shedaniel/clothconfiglite/impl/option/TextFieldOption.java">...</a>
|
||||||
*/
|
*/
|
||||||
|
@Deprecated(forRemoval = true, since = "2.1.3")
|
||||||
public class TextConfigOption<T> extends AbstractConfigWidget<T, WrappedEditBox> {
|
public class TextConfigOption<T> extends AbstractConfigWidget<T, WrappedEditBox> {
|
||||||
|
|
||||||
private final Function<T, String> toString;
|
private final Function<T, String> toString;
|
||||||
|
@@ -10,6 +10,7 @@ import java.util.function.Function;
|
|||||||
* Copied from Cloth Config Lite
|
* Copied from Cloth Config Lite
|
||||||
* <a href="https://github.com/shedaniel/cloth-config-lite/blob/1.17/src/main/java/me/shedaniel/clothconfiglite/impl/option/ToggleOption.java">...</a>
|
* <a href="https://github.com/shedaniel/cloth-config-lite/blob/1.17/src/main/java/me/shedaniel/clothconfiglite/impl/option/ToggleOption.java">...</a>
|
||||||
*/
|
*/
|
||||||
|
@Deprecated(forRemoval = true, since = "2.1.3")
|
||||||
public class ToggleButton<T> extends AbstractConfigWidget<T, Button> {
|
public class ToggleButton<T> extends AbstractConfigWidget<T, Button> {
|
||||||
|
|
||||||
private final List<T> options;
|
private final List<T> options;
|
||||||
|
@@ -10,6 +10,7 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
/**
|
/**
|
||||||
* @author HypherionSA
|
* @author HypherionSA
|
||||||
*/
|
*/
|
||||||
|
@Deprecated(forRemoval = true, since = "2.1.3")
|
||||||
public class WrappedEditBox extends EditBox {
|
public class WrappedEditBox extends EditBox {
|
||||||
|
|
||||||
public WrappedEditBox(Font font, int i, int j, int k, int l, @NotNull Component component) {
|
public WrappedEditBox(Font font, int i, int j, int k, int l, @NotNull Component component) {
|
||||||
|
@@ -0,0 +1,17 @@
|
|||||||
|
// @excludeplugin
|
||||||
|
package com.hypherionmc.craterlib.compat;
|
||||||
|
|
||||||
|
import com.hypherionmc.craterlib.nojang.world.entity.player.BridgedPlayer;
|
||||||
|
import dev.ftb.mods.ftbessentials.util.FTBEPlayerData;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
public class FTBEssentials {
|
||||||
|
|
||||||
|
public static boolean isPlayerMuted(BridgedPlayer player) {
|
||||||
|
Optional<FTBEPlayerData> data = FTBEPlayerData.getOrCreate(player.toMojang());
|
||||||
|
return data.map(FTBEPlayerData::isMuted).orElse(false);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1,102 @@
|
|||||||
|
package com.hypherionmc.craterlib.compat;
|
||||||
|
|
||||||
|
import com.hypherionmc.craterlib.api.events.compat.LuckPermsCompatEvents;
|
||||||
|
import com.hypherionmc.craterlib.core.event.CraterEventBus;
|
||||||
|
import net.luckperms.api.LuckPerms;
|
||||||
|
import net.luckperms.api.LuckPermsProvider;
|
||||||
|
import net.luckperms.api.event.EventBus;
|
||||||
|
import net.luckperms.api.event.node.NodeMutateEvent;
|
||||||
|
import net.luckperms.api.model.group.Group;
|
||||||
|
import net.luckperms.api.model.user.User;
|
||||||
|
import net.luckperms.api.node.NodeType;
|
||||||
|
import net.luckperms.api.node.types.InheritanceNode;
|
||||||
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
public class LuckPermsCompat {
|
||||||
|
|
||||||
|
public static final LuckPermsCompat INSTANCE = new LuckPermsCompat();
|
||||||
|
private final LuckPerms luckPerms = LuckPermsProvider.get();
|
||||||
|
|
||||||
|
LuckPermsCompat() {
|
||||||
|
EventBus bus = luckPerms.getEventBus();
|
||||||
|
|
||||||
|
bus.subscribe(NodeMutateEvent.class, e -> {
|
||||||
|
if (!e.isUser())
|
||||||
|
return;
|
||||||
|
|
||||||
|
User user = (User) e.getTarget();
|
||||||
|
|
||||||
|
Set<InheritanceNode> addedInheritance = e.getDataAfter().stream()
|
||||||
|
.filter(node -> node.getType() == NodeType.INHERITANCE && !e.getDataBefore().contains(node))
|
||||||
|
.map(NodeType.INHERITANCE::cast)
|
||||||
|
.collect(Collectors.toSet());
|
||||||
|
|
||||||
|
Set<InheritanceNode> removedInheritance = e.getDataBefore().stream()
|
||||||
|
.filter(node -> node.getType() == NodeType.INHERITANCE && !e.getDataAfter().contains(node))
|
||||||
|
.map(NodeType.INHERITANCE::cast)
|
||||||
|
.collect(Collectors.toSet());
|
||||||
|
|
||||||
|
if(addedInheritance.isEmpty() && removedInheritance.isEmpty()) return;
|
||||||
|
|
||||||
|
addedInheritance.forEach(node -> {
|
||||||
|
CraterEventBus.INSTANCE.postEvent(LuckPermsCompatEvents.GroupAddedEvent.of(node.getGroupName(), user.getUniqueId(), user.getUsername()));
|
||||||
|
});
|
||||||
|
|
||||||
|
removedInheritance.forEach(node -> {
|
||||||
|
CraterEventBus.INSTANCE.postEvent(LuckPermsCompatEvents.GroupRemovedEvent.of(node.getGroupName(), user.getUniqueId(), user.getUsername()));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasPermission(ServerPlayer player, String perm) {
|
||||||
|
User luckPermsUser = luckPerms.getPlayerAdapter(ServerPlayer.class).getUser(player);
|
||||||
|
return luckPermsUser.getCachedData().getPermissionData().checkPermission(perm).asBoolean();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasGroup(UUID uuid, String group) {
|
||||||
|
return getUserGroups(uuid).stream().anyMatch(g -> g.equalsIgnoreCase(group));
|
||||||
|
}
|
||||||
|
|
||||||
|
public Set<String> getUserGroups(UUID uuid) {
|
||||||
|
User user = luckPerms.getUserManager().getUser(uuid);
|
||||||
|
if (user == null)
|
||||||
|
return new HashSet<>();
|
||||||
|
|
||||||
|
return user.getNodes(NodeType.INHERITANCE).stream().map(InheritanceNode::getGroupName).collect(Collectors.toSet());
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean addGroupToUser(UUID uuid, String group) {
|
||||||
|
AtomicBoolean added = new AtomicBoolean(false);
|
||||||
|
|
||||||
|
Group g = luckPerms.getGroupManager().getGroup(group);
|
||||||
|
if (g == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
luckPerms.getUserManager().loadUser(uuid).thenAcceptAsync(user -> {
|
||||||
|
if (user == null) return;
|
||||||
|
user.data().add(InheritanceNode.builder(group).build());
|
||||||
|
luckPerms.getUserManager().saveUser(user);
|
||||||
|
added.set(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
return added.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean removeGroupFromUser(UUID uuid, String group) {
|
||||||
|
AtomicBoolean removed = new AtomicBoolean(false);
|
||||||
|
|
||||||
|
luckPerms.getUserManager().loadUser(uuid).thenAcceptAsync(user -> {
|
||||||
|
if (user == null) return;
|
||||||
|
user.data().remove(InheritanceNode.builder(group).build());
|
||||||
|
luckPerms.getUserManager().saveUser(user);
|
||||||
|
removed.set(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
return removed.get();
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,24 @@
|
|||||||
|
// @excludeplugin
|
||||||
|
package com.hypherionmc.craterlib.compat.ftbranks;
|
||||||
|
|
||||||
|
import dev.ftb.mods.ftbranks.api.Rank;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
|
||||||
|
@RequiredArgsConstructor(staticName = "of")
|
||||||
|
public class BridgedRank {
|
||||||
|
|
||||||
|
private final Rank internal;
|
||||||
|
|
||||||
|
public String name() {
|
||||||
|
return internal.getName();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String id() {
|
||||||
|
return internal.getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Rank toFtb() {
|
||||||
|
return internal;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1,83 @@
|
|||||||
|
// @excludeplugin
|
||||||
|
package com.hypherionmc.craterlib.compat.ftbranks;
|
||||||
|
|
||||||
|
import com.hypherionmc.craterlib.api.events.compat.FTBRankEvents;
|
||||||
|
import com.hypherionmc.craterlib.core.event.CraterEventBus;
|
||||||
|
import com.hypherionmc.craterlib.nojang.authlib.BridgedGameProfile;
|
||||||
|
import dev.ftb.mods.ftbranks.api.FTBRanksAPI;
|
||||||
|
import dev.ftb.mods.ftbranks.api.event.PlayerAddedToRankEvent;
|
||||||
|
import dev.ftb.mods.ftbranks.api.event.PlayerRemovedFromRankEvent;
|
||||||
|
import dev.ftb.mods.ftbranks.api.event.RankDeletedEvent;
|
||||||
|
import dev.ftb.mods.ftbranks.api.event.RankEvent;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
|
public class FTBRanks {
|
||||||
|
|
||||||
|
public static final FTBRanks INSTANCE = new FTBRanks();
|
||||||
|
|
||||||
|
private FTBRanks() {
|
||||||
|
registerEvents();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<BridgedRank> getPlayerRanks(BridgedGameProfile profile) {
|
||||||
|
List<BridgedRank> ranks = new ArrayList<>();
|
||||||
|
FTBRanksAPI.manager().getAddedRanks(profile.toMojang()).forEach(rank -> ranks.add(BridgedRank.of(rank)));
|
||||||
|
return ranks;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<BridgedRank> getAllRanks() {
|
||||||
|
List<BridgedRank> ranks = new ArrayList<>();
|
||||||
|
FTBRanksAPI.manager().getAllRanks().forEach(r -> ranks.add(BridgedRank.of(r)));
|
||||||
|
return ranks;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasRank(BridgedGameProfile profile, String rank) {
|
||||||
|
return getPlayerRanks(profile).stream().anyMatch(r -> r.toFtb().getName().equalsIgnoreCase(rank) || r.toFtb().getId().equalsIgnoreCase(rank));
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean addRank(BridgedGameProfile profile, String rank) {
|
||||||
|
rank = rank.toLowerCase();
|
||||||
|
|
||||||
|
AtomicBoolean didAddRank = new AtomicBoolean(false);
|
||||||
|
FTBRanksAPI.manager().getRank(rank).ifPresent(r -> {
|
||||||
|
r.add(profile.toMojang());
|
||||||
|
didAddRank.set(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
return didAddRank.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean removeRank(BridgedGameProfile profile, String rank) {
|
||||||
|
rank = rank.toLowerCase();
|
||||||
|
|
||||||
|
AtomicBoolean didRemoveRank = new AtomicBoolean(false);
|
||||||
|
FTBRanksAPI.manager().getRank(rank).ifPresent(r -> {
|
||||||
|
r.remove(profile.toMojang());
|
||||||
|
didRemoveRank.set(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
return didRemoveRank.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void registerEvents() {
|
||||||
|
RankEvent.ADD_PLAYER.register(this::playerAddedToRank);
|
||||||
|
RankEvent.REMOVE_PLAYER.register(this::playerRemovedFromRank);
|
||||||
|
RankEvent.DELETED.register(this::rankDeleted);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void rankDeleted(RankDeletedEvent rankDeletedEvent) {
|
||||||
|
CraterEventBus.INSTANCE.postEvent(FTBRankEvents.RankDeletedEvent.of(rankDeletedEvent.getRank()));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void playerRemovedFromRank(PlayerRemovedFromRankEvent playerRemovedFromRankEvent) {
|
||||||
|
CraterEventBus.INSTANCE.postEvent(FTBRankEvents.RankRemovedEvent.of(playerRemovedFromRankEvent.getPlayer(), playerRemovedFromRankEvent.getRank()));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void playerAddedToRank(PlayerAddedToRankEvent playerAddedToRankEvent) {
|
||||||
|
CraterEventBus.INSTANCE.postEvent(FTBRankEvents.RankAddedEvent.of(playerAddedToRankEvent.getPlayer(), playerAddedToRankEvent.getRank()));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1,71 @@
|
|||||||
|
package com.hypherionmc.craterlib.core.config;
|
||||||
|
|
||||||
|
import com.hypherionmc.craterlib.core.config.formats.AbstractConfigFormat;
|
||||||
|
import com.hypherionmc.craterlib.core.config.formats.JsonConfigFormat;
|
||||||
|
import com.hypherionmc.craterlib.core.config.formats.TomlConfigFormat;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
import me.hypherionmc.moonconfig.core.Config;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
public abstract class AbstractConfig<S> {
|
||||||
|
|
||||||
|
/* Final Variables */
|
||||||
|
private final transient File configPath;
|
||||||
|
private final transient String networkID;
|
||||||
|
private final transient String configName;
|
||||||
|
private final transient String modId;
|
||||||
|
private transient boolean wasSaveCalled = false;
|
||||||
|
|
||||||
|
@Setter
|
||||||
|
private transient AbstractConfigFormat<S> configFormat;
|
||||||
|
|
||||||
|
public AbstractConfig(String modId, String configName) {
|
||||||
|
this(modId, null, configName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public AbstractConfig(String modId, @Nullable String subFolder, String configName) {
|
||||||
|
Config.setInsertionOrderPreserved(true);
|
||||||
|
|
||||||
|
if (!configName.endsWith(".toml") && !configName.endsWith(".json"))
|
||||||
|
configName = configName + ".toml";
|
||||||
|
|
||||||
|
File configDir = new File("config" + (subFolder == null ? "" : File.separator + subFolder));
|
||||||
|
configPath = new File(configDir, configName);
|
||||||
|
this.modId = modId;
|
||||||
|
this.networkID = modId + ":conf_" + configName.replace(".toml", "").replace(".json", "").replace("-", "_").toLowerCase();
|
||||||
|
this.configName = configName.replace(".toml", "").replace(".json", "");
|
||||||
|
configDir.mkdirs();
|
||||||
|
|
||||||
|
configFormat = configName.endsWith(".json") ? new JsonConfigFormat<>(configPath, this::onSave) : new TomlConfigFormat<>(configPath, this::onSave);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void registerAndSetup(S config) {
|
||||||
|
configFormat.register(config);
|
||||||
|
ConfigController.register_config(this);
|
||||||
|
this.configReloaded();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void saveConfig(S config) {
|
||||||
|
this.wasSaveCalled = true;
|
||||||
|
configFormat.saveConfig(config);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void onSave() {
|
||||||
|
this.configReloaded();
|
||||||
|
this.wasSaveCalled = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public S readConfig(S config) {
|
||||||
|
return configFormat.readConfig(config);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void migrateConfig(S config) {
|
||||||
|
configFormat.migrateConfig(config);
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract void configReloaded();
|
||||||
|
}
|
@@ -3,10 +3,12 @@ package com.hypherionmc.craterlib.core.config;
|
|||||||
import com.hypherionmc.craterlib.CraterConstants;
|
import com.hypherionmc.craterlib.CraterConstants;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import me.hypherionmc.moonconfig.core.file.FileWatcher;
|
import me.hypherionmc.moonconfig.core.file.FileWatcher;
|
||||||
|
import org.apache.commons.lang3.tuple.Pair;
|
||||||
import org.jetbrains.annotations.ApiStatus;
|
import org.jetbrains.annotations.ApiStatus;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author HypherionSA
|
* @author HypherionSA
|
||||||
@@ -18,7 +20,9 @@ public final class ConfigController implements Serializable {
|
|||||||
* Cache of registered configs
|
* Cache of registered configs
|
||||||
*/
|
*/
|
||||||
@Getter
|
@Getter
|
||||||
private static final HashMap<Object, FileWatcher> monitoredConfigs = new HashMap<>();
|
private static final HashMap<String, AbstractConfig> watchedConfigs = new HashMap<>();
|
||||||
|
|
||||||
|
private static FileWatcher watcher = new FileWatcher(e -> CraterConstants.LOG.error("Config Watcher Error", e));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* INTERNAL METHOD - Register and watch the config
|
* INTERNAL METHOD - Register and watch the config
|
||||||
@@ -26,23 +30,33 @@ public final class ConfigController implements Serializable {
|
|||||||
* @param config - The config class to register and watch
|
* @param config - The config class to register and watch
|
||||||
*/
|
*/
|
||||||
@ApiStatus.Internal
|
@ApiStatus.Internal
|
||||||
|
@Deprecated
|
||||||
public static void register_config(ModuleConfig config) {
|
public static void register_config(ModuleConfig config) {
|
||||||
if (monitoredConfigs.containsKey(config)) {
|
register_config((AbstractConfig) config);
|
||||||
CraterConstants.LOG.error("Failed to register " + config.getConfigPath().getName() + ". Config already registered");
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* INTERNAL METHOD - Register and watch the config
|
||||||
|
*
|
||||||
|
* @param config - The config class to register and watch
|
||||||
|
*/
|
||||||
|
@ApiStatus.Internal
|
||||||
|
public static void register_config(AbstractConfig config) {
|
||||||
|
if (watchedConfigs.containsKey(config.getConfigPath().toString())) {
|
||||||
|
CraterConstants.LOG.error("Failed to register {}. Config already registered", config.getConfigPath().getName());
|
||||||
} else {
|
} else {
|
||||||
FileWatcher configWatcher = new FileWatcher();
|
|
||||||
try {
|
try {
|
||||||
configWatcher.setWatch(config.getConfigPath(), () -> {
|
watcher.addWatch(config.getConfigPath(), () -> {
|
||||||
if (!config.isSaveCalled()) {
|
if (!config.isWasSaveCalled()) {
|
||||||
CraterConstants.LOG.info("Sending Reload Event for: " + config.getConfigPath().getName());
|
CraterConstants.LOG.info("Sending Reload Event for: {}", config.getConfigPath().getName());
|
||||||
config.configReloaded();
|
config.configReloaded();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
CraterConstants.LOG.error("Failed to register " + config.getConfigPath().getName() + " for auto reloading. " + e.getMessage());
|
CraterConstants.LOG.error("Failed to register {} for auto reloading. {}", config.getConfigPath().getName(), e.getMessage());
|
||||||
}
|
}
|
||||||
monitoredConfigs.put(config, configWatcher);
|
watchedConfigs.put(config.getConfigPath().toString(), config);
|
||||||
CraterConstants.LOG.info("Registered " + config.getConfigPath().getName() + " successfully!");
|
CraterConstants.LOG.info("Registered {} successfully!", config.getConfigPath().getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,9 +1,7 @@
|
|||||||
package com.hypherionmc.craterlib.core.config;
|
package com.hypherionmc.craterlib.core.config;
|
||||||
|
|
||||||
|
import com.hypherionmc.craterlib.core.config.formats.TomlConfigFormat;
|
||||||
import me.hypherionmc.moonconfig.core.CommentedConfig;
|
import me.hypherionmc.moonconfig.core.CommentedConfig;
|
||||||
import me.hypherionmc.moonconfig.core.Config;
|
|
||||||
import me.hypherionmc.moonconfig.core.conversion.ObjectConverter;
|
|
||||||
import me.hypherionmc.moonconfig.core.file.CommentedFileConfig;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
@@ -12,17 +10,8 @@ import java.io.File;
|
|||||||
* Base Config class containing the save, upgrading and loading logic.
|
* Base Config class containing the save, upgrading and loading logic.
|
||||||
* All config classes must extend this class
|
* All config classes must extend this class
|
||||||
*/
|
*/
|
||||||
public class ModuleConfig {
|
@Deprecated(forRemoval = true, since = "2.1.0")
|
||||||
|
public class ModuleConfig extends AbstractConfig {
|
||||||
/* Final Variables */
|
|
||||||
private final transient File configPath;
|
|
||||||
private final transient String networkID;
|
|
||||||
|
|
||||||
private final transient String configName;
|
|
||||||
|
|
||||||
private final transient String modId;
|
|
||||||
|
|
||||||
private transient boolean isSaveCalled = false;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set up the config
|
* Set up the config
|
||||||
@@ -35,20 +24,7 @@ public class ModuleConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public ModuleConfig(String modId, String subFolder, String configName) {
|
public ModuleConfig(String modId, String subFolder, String configName) {
|
||||||
/* Preserve the order of the config values */
|
super(modId, subFolder.isEmpty() ? null : subFolder, configName);
|
||||||
Config.setInsertionOrderPreserved(true);
|
|
||||||
|
|
||||||
/* Configure Paths and Network SYNC ID */
|
|
||||||
File configDir = new File("config" + (subFolder.isEmpty() ? "" : File.separator + subFolder));
|
|
||||||
configPath = new File(configDir + File.separator + configName + ".toml");
|
|
||||||
networkID = modId + ":conf_" + configName.replace("-", "_");
|
|
||||||
this.modId = modId;
|
|
||||||
this.configName = configName;
|
|
||||||
|
|
||||||
/* Check if the required directories exists, otherwise we create them */
|
|
||||||
if (!configDir.exists()) {
|
|
||||||
configDir.mkdirs();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -57,14 +33,7 @@ public class ModuleConfig {
|
|||||||
* @param config - The config class to use
|
* @param config - The config class to use
|
||||||
*/
|
*/
|
||||||
public void registerAndSetup(ModuleConfig config) {
|
public void registerAndSetup(ModuleConfig config) {
|
||||||
if (!configPath.exists() || configPath.length() < 2) {
|
super.registerAndSetup(config);
|
||||||
saveConfig(config);
|
|
||||||
} else {
|
|
||||||
migrateConfig(config);
|
|
||||||
}
|
|
||||||
/* Register the Config for Watching and events */
|
|
||||||
ConfigController.register_config(this);
|
|
||||||
this.configReloaded();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -73,16 +42,7 @@ public class ModuleConfig {
|
|||||||
* @param conf - The config class to serialize and save
|
* @param conf - The config class to serialize and save
|
||||||
*/
|
*/
|
||||||
public void saveConfig(ModuleConfig conf) {
|
public void saveConfig(ModuleConfig conf) {
|
||||||
this.isSaveCalled = true;
|
super.registerAndSetup(conf);
|
||||||
/* Set up the Serializer and Config Object */
|
|
||||||
ObjectConverter converter = new ObjectConverter();
|
|
||||||
CommentedFileConfig config = CommentedFileConfig.builder(configPath).build();
|
|
||||||
|
|
||||||
/* Save the config and fire the reload events */
|
|
||||||
converter.toConfig(conf, config);
|
|
||||||
config.save();
|
|
||||||
configReloaded();
|
|
||||||
this.isSaveCalled = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -92,14 +52,7 @@ public class ModuleConfig {
|
|||||||
* @return - Returns the loaded version of the class
|
* @return - Returns the loaded version of the class
|
||||||
*/
|
*/
|
||||||
public <T> T loadConfig(Object conf) {
|
public <T> T loadConfig(Object conf) {
|
||||||
/* Set up the Serializer and Config Object */
|
return (T) super.readConfig(conf);
|
||||||
ObjectConverter converter = new ObjectConverter();
|
|
||||||
CommentedFileConfig config = CommentedFileConfig.builder(configPath).build();
|
|
||||||
config.load();
|
|
||||||
|
|
||||||
/* Load the config and return the loaded config */
|
|
||||||
converter.toObject(config, conf);
|
|
||||||
return (T) conf;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -108,31 +61,13 @@ public class ModuleConfig {
|
|||||||
* @param conf - The config class to load
|
* @param conf - The config class to load
|
||||||
*/
|
*/
|
||||||
public void migrateConfig(ModuleConfig conf) {
|
public void migrateConfig(ModuleConfig conf) {
|
||||||
/* Set up the Serializer and Config Objects */
|
super.migrateConfig(conf);
|
||||||
CommentedFileConfig config = CommentedFileConfig.builder(configPath).build();
|
|
||||||
CommentedFileConfig newConfig = CommentedFileConfig.builder(configPath).build();
|
|
||||||
config.load();
|
|
||||||
|
|
||||||
/* Upgrade the config */
|
|
||||||
new ObjectConverter().toConfig(conf, newConfig);
|
|
||||||
updateConfigValues(config, newConfig, newConfig, "");
|
|
||||||
newConfig.save();
|
|
||||||
|
|
||||||
config.close();
|
|
||||||
newConfig.close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateConfigValues(CommentedConfig oldConfig, CommentedConfig newConfig, CommentedConfig outputConfig, String subKey) {
|
public void updateConfigValues(CommentedConfig oldConfig, CommentedConfig newConfig, CommentedConfig outputConfig, String subKey) {
|
||||||
/* Loop over the config keys and check what has changed */
|
if (getConfigFormat() instanceof TomlConfigFormat<?> t) {
|
||||||
newConfig.valueMap().forEach((key, value) -> {
|
t.updateConfigValues(oldConfig, newConfig, outputConfig, subKey);
|
||||||
String finalKey = subKey + (subKey.isEmpty() ? "" : ".") + key;
|
}
|
||||||
if (value instanceof CommentedConfig commentedConfig) {
|
|
||||||
updateConfigValues(oldConfig, commentedConfig, outputConfig, finalKey);
|
|
||||||
} else {
|
|
||||||
outputConfig.set(finalKey,
|
|
||||||
oldConfig.contains(finalKey) ? oldConfig.get(finalKey) : value);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -141,7 +76,7 @@ public class ModuleConfig {
|
|||||||
* @return - The FILE object containing the config file
|
* @return - The FILE object containing the config file
|
||||||
*/
|
*/
|
||||||
public File getConfigPath() {
|
public File getConfigPath() {
|
||||||
return configPath;
|
return super.getConfigPath();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -150,12 +85,13 @@ public class ModuleConfig {
|
|||||||
* @return - Returns the Sync ID in format modid:config_name
|
* @return - Returns the Sync ID in format modid:config_name
|
||||||
*/
|
*/
|
||||||
public String getNetworkID() {
|
public String getNetworkID() {
|
||||||
return networkID;
|
return super.getNetworkID();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fired whenever changes to the config are detected
|
* Fired whenever changes to the config are detected
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public void configReloaded() {
|
public void configReloaded() {
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -166,7 +102,7 @@ public class ModuleConfig {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public String getConfigName() {
|
public String getConfigName() {
|
||||||
return configName;
|
return super.getConfigName();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -175,10 +111,10 @@ public class ModuleConfig {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public String getModId() {
|
public String getModId() {
|
||||||
return modId;
|
return super.getModId();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isSaveCalled() {
|
public boolean isSaveCalled() {
|
||||||
return isSaveCalled;
|
return super.isWasSaveCalled();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,12 @@
|
|||||||
|
package com.hypherionmc.craterlib.core.config.annotations;
|
||||||
|
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author HypherionSA
|
||||||
|
* Allow mods to make use of the new Cloth Config based Config Screens
|
||||||
|
*/
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
public @interface ClothScreen {
|
||||||
|
}
|
@@ -0,0 +1,32 @@
|
|||||||
|
package com.hypherionmc.craterlib.core.config.formats;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import me.hypherionmc.moonconfig.core.Config;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@Getter
|
||||||
|
public abstract class AbstractConfigFormat<S> {
|
||||||
|
|
||||||
|
private final File configPath;
|
||||||
|
private final Runnable onSave;
|
||||||
|
|
||||||
|
public void register(S conf) {
|
||||||
|
if (!configPath.exists() || configPath.length() < 2) {
|
||||||
|
saveConfig(conf);
|
||||||
|
} else {
|
||||||
|
migrateConfig(conf);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean wasConfigChanged(Config old, Config newConfig) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract void saveConfig(S config);
|
||||||
|
public abstract S readConfig(S config);
|
||||||
|
public abstract void migrateConfig(S config);
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1,67 @@
|
|||||||
|
package com.hypherionmc.craterlib.core.config.formats;
|
||||||
|
|
||||||
|
import me.hypherionmc.moonconfig.core.Config;
|
||||||
|
import me.hypherionmc.moonconfig.core.conversion.ObjectConverter;
|
||||||
|
import me.hypherionmc.moonconfig.core.file.FileConfig;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
public class JsonConfigFormat<S> extends AbstractConfigFormat<S> {
|
||||||
|
|
||||||
|
public JsonConfigFormat(File configPath, Runnable afterSave) {
|
||||||
|
super(configPath, afterSave);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void saveConfig(S conf) {
|
||||||
|
ObjectConverter converter = new ObjectConverter();
|
||||||
|
FileConfig config = FileConfig.builder(getConfigPath()).sync().build();
|
||||||
|
|
||||||
|
converter.toConfig(conf, config);
|
||||||
|
config.save();
|
||||||
|
getOnSave().run();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public S readConfig(S conf) {
|
||||||
|
/* Set up the Serializer and Config Object */
|
||||||
|
ObjectConverter converter = new ObjectConverter();
|
||||||
|
FileConfig config = FileConfig.builder(getConfigPath()).sync().build();
|
||||||
|
config.load();
|
||||||
|
|
||||||
|
/* Load the config and return the loaded config */
|
||||||
|
converter.toObject(config, conf);
|
||||||
|
return conf;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void migrateConfig(S conf) {
|
||||||
|
/* Set up the Serializer and Config Objects */
|
||||||
|
FileConfig config = FileConfig.builder(getConfigPath()).build();
|
||||||
|
FileConfig newConfig = FileConfig.builder(getConfigPath()).sync().build();
|
||||||
|
config.load();
|
||||||
|
|
||||||
|
/* Upgrade the config */
|
||||||
|
if (wasConfigChanged(config, newConfig)) {
|
||||||
|
new ObjectConverter().toConfig(conf, newConfig);
|
||||||
|
updateConfigValues(config, newConfig, newConfig, "");
|
||||||
|
newConfig.save();
|
||||||
|
}
|
||||||
|
|
||||||
|
config.close();
|
||||||
|
newConfig.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateConfigValues(Config oldConfig, Config newConfig, Config outputConfig, String subKey) {
|
||||||
|
/* Loop over the config keys and check what has changed */
|
||||||
|
newConfig.valueMap().forEach((key, value) -> {
|
||||||
|
String finalKey = subKey + (subKey.isEmpty() ? "" : ".") + key;
|
||||||
|
if (value instanceof Config commentedConfig) {
|
||||||
|
updateConfigValues(oldConfig, commentedConfig, outputConfig, finalKey);
|
||||||
|
} else {
|
||||||
|
outputConfig.set(finalKey,
|
||||||
|
oldConfig.contains(finalKey) ? oldConfig.get(finalKey) : value);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,67 @@
|
|||||||
|
package com.hypherionmc.craterlib.core.config.formats;
|
||||||
|
|
||||||
|
import me.hypherionmc.moonconfig.core.CommentedConfig;
|
||||||
|
import me.hypherionmc.moonconfig.core.conversion.ObjectConverter;
|
||||||
|
import me.hypherionmc.moonconfig.core.file.CommentedFileConfig;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
public class TomlConfigFormat<S> extends AbstractConfigFormat<S> {
|
||||||
|
|
||||||
|
public TomlConfigFormat(File configPath, Runnable onSave) {
|
||||||
|
super(configPath, onSave);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void saveConfig(S conf) {
|
||||||
|
ObjectConverter converter = new ObjectConverter();
|
||||||
|
CommentedFileConfig config = CommentedFileConfig.builder(getConfigPath()).sync().build();
|
||||||
|
|
||||||
|
converter.toConfig(conf, config);
|
||||||
|
config.save();
|
||||||
|
getOnSave().run();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public S readConfig(S conf) {
|
||||||
|
/* Set up the Serializer and Config Object */
|
||||||
|
ObjectConverter converter = new ObjectConverter();
|
||||||
|
CommentedFileConfig config = CommentedFileConfig.builder(getConfigPath()).sync().build();
|
||||||
|
config.load();
|
||||||
|
|
||||||
|
/* Load the config and return the loaded config */
|
||||||
|
converter.toObject(config, conf);
|
||||||
|
return conf;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void migrateConfig(S conf) {
|
||||||
|
/* Set up the Serializer and Config Objects */
|
||||||
|
CommentedFileConfig config = CommentedFileConfig.builder(getConfigPath()).build();
|
||||||
|
CommentedFileConfig newConfig = CommentedFileConfig.builder(getConfigPath()).sync().build();
|
||||||
|
config.load();
|
||||||
|
|
||||||
|
/* Upgrade the config */
|
||||||
|
if (wasConfigChanged(config, newConfig)) {
|
||||||
|
new ObjectConverter().toConfig(conf, newConfig);
|
||||||
|
updateConfigValues(config, newConfig, newConfig, "");
|
||||||
|
newConfig.save();
|
||||||
|
}
|
||||||
|
|
||||||
|
config.close();
|
||||||
|
newConfig.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateConfigValues(CommentedConfig oldConfig, CommentedConfig newConfig, CommentedConfig outputConfig, String subKey) {
|
||||||
|
/* Loop over the config keys and check what has changed */
|
||||||
|
newConfig.valueMap().forEach((key, value) -> {
|
||||||
|
String finalKey = subKey + (subKey.isEmpty() ? "" : ".") + key;
|
||||||
|
if (value instanceof CommentedConfig commentedConfig) {
|
||||||
|
updateConfigValues(oldConfig, commentedConfig, outputConfig, finalKey);
|
||||||
|
} else {
|
||||||
|
outputConfig.set(finalKey,
|
||||||
|
oldConfig.contains(finalKey) ? oldConfig.get(finalKey) : value);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
@@ -2,6 +2,7 @@ package com.hypherionmc.craterlib.core.platform;
|
|||||||
|
|
||||||
import com.hypherionmc.craterlib.nojang.world.entity.player.BridgedPlayer;
|
import com.hypherionmc.craterlib.nojang.world.entity.player.BridgedPlayer;
|
||||||
import com.hypherionmc.craterlib.utils.InternalServiceUtil;
|
import com.hypherionmc.craterlib.utils.InternalServiceUtil;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
|
||||||
public interface CompatUtils {
|
public interface CompatUtils {
|
||||||
|
|
||||||
@@ -9,5 +10,10 @@ public interface CompatUtils {
|
|||||||
|
|
||||||
boolean isPlayerActive(BridgedPlayer player);
|
boolean isPlayerActive(BridgedPlayer player);
|
||||||
String getSkinUUID(BridgedPlayer player);
|
String getSkinUUID(BridgedPlayer player);
|
||||||
|
boolean isPlayerBleeding(BridgedPlayer player);
|
||||||
|
boolean playerBledOut(BridgedPlayer player);
|
||||||
|
boolean playerRevived(BridgedPlayer player);
|
||||||
|
boolean isPrivateMessage(BridgedPlayer player);
|
||||||
|
Component getChannelPrefix(BridgedPlayer player);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,8 @@
|
|||||||
|
package com.hypherionmc.craterlib.core.platform;
|
||||||
|
|
||||||
|
public enum LoaderType {
|
||||||
|
FABRIC,
|
||||||
|
FORGE,
|
||||||
|
NEOFORGE,
|
||||||
|
PAPER
|
||||||
|
}
|
@@ -12,8 +12,11 @@ public interface ModloaderEnvironment {
|
|||||||
|
|
||||||
public final ModloaderEnvironment INSTANCE = InternalServiceUtil.load(ModloaderEnvironment.class);
|
public final ModloaderEnvironment INSTANCE = InternalServiceUtil.load(ModloaderEnvironment.class);
|
||||||
|
|
||||||
|
@Deprecated(forRemoval = true, since = "2.0.2")
|
||||||
boolean isFabric();
|
boolean isFabric();
|
||||||
|
|
||||||
|
LoaderType getLoaderType();
|
||||||
|
|
||||||
String getGameVersion();
|
String getGameVersion();
|
||||||
|
|
||||||
File getGameFolder();
|
File getGameFolder();
|
||||||
|
@@ -11,6 +11,7 @@ import java.util.List;
|
|||||||
* Class containing references to all available discord event handles.
|
* Class containing references to all available discord event handles.
|
||||||
* Registering a handler is optional, and non-assigned handlers will be ignored
|
* Registering a handler is optional, and non-assigned handlers will be ignored
|
||||||
*/
|
*/
|
||||||
|
@Deprecated(forRemoval = true)
|
||||||
public class DiscordEventHandlers extends Structure {
|
public class DiscordEventHandlers extends Structure {
|
||||||
|
|
||||||
// Callback for when the RPC was initialized successfully
|
// Callback for when the RPC was initialized successfully
|
||||||
|
@@ -9,6 +9,7 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
* @author HypherionSA
|
* @author HypherionSA
|
||||||
* Java Wrapper of the Discord-RPC Library
|
* Java Wrapper of the Discord-RPC Library
|
||||||
*/
|
*/
|
||||||
|
@Deprecated(forRemoval = true)
|
||||||
public interface DiscordRPC extends Library {
|
public interface DiscordRPC extends Library {
|
||||||
|
|
||||||
DiscordRPC INSTANCE = Native.load("discord-rpc", DiscordRPC.class);
|
DiscordRPC INSTANCE = Native.load("discord-rpc", DiscordRPC.class);
|
||||||
|
@@ -13,6 +13,7 @@ import java.util.List;
|
|||||||
* @author HypherionSA
|
* @author HypherionSA
|
||||||
* Class reprenting a Discord RPC activity
|
* Class reprenting a Discord RPC activity
|
||||||
*/
|
*/
|
||||||
|
@Deprecated(forRemoval = true)
|
||||||
public class DiscordRichPresence extends Structure {
|
public class DiscordRichPresence extends Structure {
|
||||||
|
|
||||||
// First line of text on the RPC
|
// First line of text on the RPC
|
||||||
|
@@ -9,6 +9,7 @@ import java.util.List;
|
|||||||
* @author HypherionSA
|
* @author HypherionSA
|
||||||
* Class representing the Discord User
|
* Class representing the Discord User
|
||||||
*/
|
*/
|
||||||
|
@Deprecated(forRemoval = true)
|
||||||
public class DiscordUser extends Structure {
|
public class DiscordUser extends Structure {
|
||||||
|
|
||||||
// The User ID of the User
|
// The User ID of the User
|
||||||
|
@@ -6,6 +6,7 @@ import com.sun.jna.Callback;
|
|||||||
* @author HypherionSA
|
* @author HypherionSA
|
||||||
* Callback for when the Discord RPC disconnects
|
* Callback for when the Discord RPC disconnects
|
||||||
*/
|
*/
|
||||||
|
@Deprecated(forRemoval = true)
|
||||||
public interface DisconnectedCallback extends Callback {
|
public interface DisconnectedCallback extends Callback {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -6,6 +6,7 @@ import com.sun.jna.Callback;
|
|||||||
* @author HypherionSA
|
* @author HypherionSA
|
||||||
* Callback for when the RPC ran into an error
|
* Callback for when the RPC ran into an error
|
||||||
*/
|
*/
|
||||||
|
@Deprecated(forRemoval = true)
|
||||||
public interface ErroredCallback extends Callback {
|
public interface ErroredCallback extends Callback {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -6,6 +6,7 @@ import com.sun.jna.Callback;
|
|||||||
* @author HypherionSA
|
* @author HypherionSA
|
||||||
* Callback for when someone was approved to join your game
|
* Callback for when someone was approved to join your game
|
||||||
*/
|
*/
|
||||||
|
@Deprecated(forRemoval = true)
|
||||||
public interface JoinGameCallback extends Callback {
|
public interface JoinGameCallback extends Callback {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -7,6 +7,7 @@ import com.sun.jna.Callback;
|
|||||||
* @author HypherionSA
|
* @author HypherionSA
|
||||||
* Callback for when someone requests to join your game
|
* Callback for when someone requests to join your game
|
||||||
*/
|
*/
|
||||||
|
@Deprecated(forRemoval = true)
|
||||||
public interface JoinRequestCallback extends Callback {
|
public interface JoinRequestCallback extends Callback {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -7,6 +7,7 @@ import com.sun.jna.Callback;
|
|||||||
* @author HypherionSA
|
* @author HypherionSA
|
||||||
* Callback for when the RPC has connected successfully
|
* Callback for when the RPC has connected successfully
|
||||||
*/
|
*/
|
||||||
|
@Deprecated(forRemoval = true)
|
||||||
public interface ReadyCallback extends Callback {
|
public interface ReadyCallback extends Callback {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -6,6 +6,7 @@ import com.sun.jna.Callback;
|
|||||||
* @author HypherionSA
|
* @author HypherionSA
|
||||||
* Callback for when someone is requesting to spectate your game
|
* Callback for when someone is requesting to spectate your game
|
||||||
*/
|
*/
|
||||||
|
@Deprecated(forRemoval = true)
|
||||||
public interface SpectateGameCallback extends Callback {
|
public interface SpectateGameCallback extends Callback {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -9,6 +9,7 @@ import java.io.Serializable;
|
|||||||
* Helper class to add Buttons to Discord Rich Presence
|
* Helper class to add Buttons to Discord Rich Presence
|
||||||
* This can not be used with Join/Spectate
|
* This can not be used with Join/Spectate
|
||||||
*/
|
*/
|
||||||
|
@Deprecated(forRemoval = true)
|
||||||
public class RPCButton implements Serializable {
|
public class RPCButton implements Serializable {
|
||||||
|
|
||||||
// The label of the button
|
// The label of the button
|
||||||
|
@@ -12,6 +12,7 @@ import net.minecraft.network.Connection;
|
|||||||
import net.minecraft.network.chat.Component;
|
import net.minecraft.network.chat.Component;
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
import net.minecraft.server.network.CommonListenerCookie;
|
import net.minecraft.server.network.CommonListenerCookie;
|
||||||
|
import net.minecraft.server.players.NameAndId;
|
||||||
import net.minecraft.server.players.PlayerList;
|
import net.minecraft.server.players.PlayerList;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
@@ -43,8 +44,8 @@ public class PlayerListMixin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Inject(method = "canPlayerLogin", at = @At("HEAD"), cancellable = true)
|
@Inject(method = "canPlayerLogin", at = @At("HEAD"), cancellable = true)
|
||||||
private void injectPreLoginEvent(SocketAddress address, GameProfile gameProfile, CallbackInfoReturnable<Component> cir) {
|
private void injectPreLoginEvent(SocketAddress socketAddress, NameAndId arg, CallbackInfoReturnable<Component> cir) {
|
||||||
PlayerPreLoginEvent event = new PlayerPreLoginEvent(address, BridgedGameProfile.of(gameProfile));
|
PlayerPreLoginEvent event = new PlayerPreLoginEvent(socketAddress, BridgedGameProfile.of(arg));
|
||||||
CraterEventBus.INSTANCE.postEvent(event);
|
CraterEventBus.INSTANCE.postEvent(event);
|
||||||
if (event.getMessage() != null) {
|
if (event.getMessage() != null) {
|
||||||
cir.setReturnValue(ChatUtils.adventureToMojang(event.getMessage()));
|
cir.setReturnValue(ChatUtils.adventureToMojang(event.getMessage()));
|
||||||
|
@@ -0,0 +1,27 @@
|
|||||||
|
package com.hypherionmc.craterlib.mixin.events;
|
||||||
|
|
||||||
|
import com.hypherionmc.craterlib.api.events.server.ServerStatusEvent;
|
||||||
|
import com.hypherionmc.craterlib.core.event.CraterEventBus;
|
||||||
|
import com.hypherionmc.craterlib.nojang.network.protocol.status.WrappedServerStatus;
|
||||||
|
import net.minecraft.network.protocol.status.ServerStatus;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
@Mixin(ServerStatus.class)
|
||||||
|
public class ServerStatusMixin {
|
||||||
|
|
||||||
|
@Inject(method = "favicon", at = @At("RETURN"), cancellable = true)
|
||||||
|
private void injectIconEvent(CallbackInfoReturnable<Optional<ServerStatus.Favicon>> cir) {
|
||||||
|
ServerStatusEvent.FaviconRequestEvent event = new ServerStatusEvent.FaviconRequestEvent(cir.getReturnValue().isEmpty() ? Optional.empty() : Optional.of(new WrappedServerStatus.WrappedFavicon(cir.getReturnValue().get())));
|
||||||
|
CraterEventBus.INSTANCE.postEvent(event);
|
||||||
|
|
||||||
|
if (event.getNewIcon().isPresent()) {
|
||||||
|
cir.setReturnValue(Optional.of(event.getNewIcon().get().toMojang()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1,14 @@
|
|||||||
|
package com.hypherionmc.craterlib.mixin.events;
|
||||||
|
|
||||||
|
import net.minecraft.server.players.StoredUserEntry;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||||
|
|
||||||
|
@Mixin(StoredUserEntry.class)
|
||||||
|
public interface StoredUserEntryAccessor<T> {
|
||||||
|
|
||||||
|
@Accessor("user")
|
||||||
|
@Nullable T getUser();
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1,47 @@
|
|||||||
|
package com.hypherionmc.craterlib.mixin.events;
|
||||||
|
|
||||||
|
import com.hypherionmc.craterlib.api.events.server.WhitelistChangedEvent;
|
||||||
|
import com.hypherionmc.craterlib.core.event.CraterEventBus;
|
||||||
|
import com.hypherionmc.craterlib.nojang.authlib.BridgedGameProfile;
|
||||||
|
import com.mojang.authlib.GameProfile;
|
||||||
|
import net.minecraft.server.players.StoredUserEntry;
|
||||||
|
import net.minecraft.server.players.StoredUserList;
|
||||||
|
import net.minecraft.server.players.UserWhiteListEntry;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.Shadow;
|
||||||
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||||
|
|
||||||
|
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||||
|
@Mixin(StoredUserList.class)
|
||||||
|
public abstract class WhitelistMixin<K, V extends StoredUserEntry<K>> {
|
||||||
|
|
||||||
|
@Shadow protected abstract boolean contains(K k0);
|
||||||
|
|
||||||
|
@Inject(method = "add", at = @At("HEAD"))
|
||||||
|
private void injectAddEvent(V arg, CallbackInfoReturnable<Boolean> cir) {
|
||||||
|
try {
|
||||||
|
if (arg instanceof UserWhiteListEntry entry) {
|
||||||
|
StoredUserEntryAccessor entryAccessor = (StoredUserEntryAccessor) entry;
|
||||||
|
if (entryAccessor.getUser() != null && !contains((K) entryAccessor.getUser())) {
|
||||||
|
CraterEventBus.INSTANCE.postEvent(new WhitelistChangedEvent.EntryAdded(BridgedGameProfile.of((GameProfile) entryAccessor.getUser())));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception ignored) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Inject(method = "remove(Lnet/minecraft/server/players/StoredUserEntry;)Z", at = @At("HEAD"))
|
||||||
|
private void injectRemoveEvent(StoredUserEntry<K> arg, CallbackInfoReturnable<Boolean> cir) {
|
||||||
|
try {
|
||||||
|
if (arg instanceof UserWhiteListEntry entry) {
|
||||||
|
StoredUserEntryAccessor entryAccessor = (StoredUserEntryAccessor) entry;
|
||||||
|
if (entryAccessor.getUser() != null && contains((K) entryAccessor.getUser())) {
|
||||||
|
CraterEventBus.INSTANCE.postEvent(new WhitelistChangedEvent.EntryRemoved(BridgedGameProfile.of((GameProfile) entryAccessor.getUser())));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception ignored) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -2,6 +2,7 @@ package com.hypherionmc.craterlib.nojang.authlib;
|
|||||||
|
|
||||||
import com.mojang.authlib.GameProfile;
|
import com.mojang.authlib.GameProfile;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import net.minecraft.server.players.NameAndId;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@@ -14,16 +15,24 @@ public class BridgedGameProfile {
|
|||||||
return new BridgedGameProfile(new GameProfile(id, name));
|
return new BridgedGameProfile(new GameProfile(id, name));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static BridgedGameProfile of(NameAndId nameAndId) {
|
||||||
|
return BridgedGameProfile.of(new GameProfile(nameAndId.id(), nameAndId.name()));
|
||||||
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return internal.getName();
|
return internal.name();
|
||||||
}
|
}
|
||||||
|
|
||||||
public UUID getId() {
|
public UUID getId() {
|
||||||
return internal.getId();
|
return internal.id();
|
||||||
}
|
}
|
||||||
|
|
||||||
public GameProfile toMojang() {
|
public GameProfile toMojang() {
|
||||||
return internal;
|
return internal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public NameAndId toNameAndId() {
|
||||||
|
return new NameAndId(internal);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -4,9 +4,13 @@ import com.hypherionmc.craterlib.nojang.client.multiplayer.BridgedClientLevel;
|
|||||||
import com.hypherionmc.craterlib.nojang.client.multiplayer.BridgedServerData;
|
import com.hypherionmc.craterlib.nojang.client.multiplayer.BridgedServerData;
|
||||||
import com.hypherionmc.craterlib.nojang.client.server.BridgedIntegratedServer;
|
import com.hypherionmc.craterlib.nojang.client.server.BridgedIntegratedServer;
|
||||||
import com.hypherionmc.craterlib.nojang.world.entity.player.BridgedPlayer;
|
import com.hypherionmc.craterlib.nojang.world.entity.player.BridgedPlayer;
|
||||||
|
import com.hypherionmc.craterlib.utils.ChatUtils;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
import net.minecraft.SharedConstants;
|
import net.minecraft.SharedConstants;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.client.gui.screens.AlertScreen;
|
||||||
|
import net.minecraft.client.gui.screens.Screen;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@@ -51,7 +55,7 @@ public class BridgedMinecraft {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String getGameVersion() {
|
public String getGameVersion() {
|
||||||
return SharedConstants.getCurrentVersion().getName();
|
return SharedConstants.getCurrentVersion().name();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getUserName() {
|
public String getUserName() {
|
||||||
@@ -72,9 +76,31 @@ public class BridgedMinecraft {
|
|||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public BridgedIntegratedServer getSinglePlayerServer() {
|
public BridgedIntegratedServer getSinglePlayerServer() {
|
||||||
|
if (internal.getSingleplayerServer() == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
return BridgedIntegratedServer.of(internal.getSingleplayerServer());
|
return BridgedIntegratedServer.of(internal.getSingleplayerServer());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void showWarningScreen(Component title, Component message) {
|
||||||
|
Screen currentScreen = internal.screen;
|
||||||
|
internal.setScreen(
|
||||||
|
new AlertScreen(
|
||||||
|
() -> internal.setScreen(currentScreen),
|
||||||
|
ChatUtils.adventureToMojang(title),
|
||||||
|
ChatUtils.adventureToMojang(message)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Screen buildWarningScreen(Component title, Component message, Screen parent) {
|
||||||
|
return new AlertScreen(
|
||||||
|
() -> internal.setScreen(parent),
|
||||||
|
ChatUtils.adventureToMojang(title),
|
||||||
|
ChatUtils.adventureToMojang(message)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
public int getServerPlayerCount () {
|
public int getServerPlayerCount () {
|
||||||
if (internal.getConnection() == null)
|
if (internal.getConnection() == null)
|
||||||
return 0;
|
return 0;
|
||||||
|
@@ -1,10 +1,7 @@
|
|||||||
package com.hypherionmc.craterlib.nojang.client.gui;
|
package com.hypherionmc.craterlib.nojang.client.gui;
|
||||||
|
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import net.minecraft.client.gui.screens.LevelLoadingScreen;
|
import net.minecraft.client.gui.screens.*;
|
||||||
import net.minecraft.client.gui.screens.ReceivingLevelScreen;
|
|
||||||
import net.minecraft.client.gui.screens.Screen;
|
|
||||||
import net.minecraft.client.gui.screens.TitleScreen;
|
|
||||||
import net.minecraft.client.gui.screens.multiplayer.JoinMultiplayerScreen;
|
import net.minecraft.client.gui.screens.multiplayer.JoinMultiplayerScreen;
|
||||||
import net.minecraft.realms.RealmsScreen;
|
import net.minecraft.realms.RealmsScreen;
|
||||||
|
|
||||||
@@ -26,7 +23,15 @@ public class BridgedScreen {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean isLoadingScreen() {
|
public boolean isLoadingScreen() {
|
||||||
return internal instanceof LevelLoadingScreen || internal instanceof ReceivingLevelScreen;
|
return internal instanceof LevelLoadingScreen || internal instanceof ConnectScreen;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isPauseScreen() {
|
||||||
|
return internal instanceof PauseScreen;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isDisconnetedScreen() {
|
||||||
|
return internal instanceof DisconnectedScreen;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Screen toMojang() {
|
public Screen toMojang() {
|
||||||
|
@@ -4,7 +4,6 @@ import com.hypherionmc.craterlib.utils.ChatUtils;
|
|||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.minecraft.client.multiplayer.ServerData;
|
import net.minecraft.client.multiplayer.ServerData;
|
||||||
import net.minecraft.client.multiplayer.ServerStatusPinger;
|
|
||||||
|
|
||||||
@RequiredArgsConstructor(staticName = "of")
|
@RequiredArgsConstructor(staticName = "of")
|
||||||
public class BridgedServerData {
|
public class BridgedServerData {
|
||||||
@@ -25,12 +24,10 @@ public class BridgedServerData {
|
|||||||
|
|
||||||
public int getMaxPlayers() {
|
public int getMaxPlayers() {
|
||||||
if (internal.players == null) {
|
if (internal.players == null) {
|
||||||
try {
|
return internal.playerList.size() + 1;
|
||||||
new ServerStatusPinger().pingServer(internal, () -> {}, () -> {});
|
|
||||||
} catch (Exception ignored) {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return internal.players == null ? 0 : internal.players.max();
|
return internal.players.max();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ServerData toMojang() {
|
public ServerData toMojang() {
|
||||||
|
@@ -1,5 +1,6 @@
|
|||||||
package com.hypherionmc.craterlib.nojang.commands;
|
package com.hypherionmc.craterlib.nojang.commands;
|
||||||
|
|
||||||
|
import com.hypherionmc.craterlib.nojang.world.entity.player.BridgedPlayer;
|
||||||
import com.hypherionmc.craterlib.utils.ChatUtils;
|
import com.hypherionmc.craterlib.utils.ChatUtils;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
@@ -7,13 +8,35 @@ import net.minecraft.commands.CommandSourceStack;
|
|||||||
|
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
import static net.minecraft.world.level.GameRules.RULE_SENDCOMMANDFEEDBACK;
|
||||||
|
|
||||||
@RequiredArgsConstructor(staticName = "of")
|
@RequiredArgsConstructor(staticName = "of")
|
||||||
public class BridgedCommandSourceStack {
|
public class BridgedCommandSourceStack {
|
||||||
|
|
||||||
private final CommandSourceStack internal;
|
private final CommandSourceStack internal;
|
||||||
|
|
||||||
public void sendSuccess(Supplier<Component> supplier, boolean bl) {
|
public void sendSuccess(Supplier<Component> supplier, boolean bl) {
|
||||||
internal.sendSuccess(() -> ChatUtils.adventureToMojang(supplier.get()), bl);
|
if (!internal.getServer().getGameRules().getBoolean(RULE_SENDCOMMANDFEEDBACK)) {
|
||||||
|
internal.sendSystemMessage(ChatUtils.adventureToMojang(supplier.get()));
|
||||||
|
} else {
|
||||||
|
internal.sendSuccess(() -> ChatUtils.adventureToMojang(supplier.get()), bl);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendMessage(Component text) {
|
||||||
|
internal.sendSystemMessage(ChatUtils.adventureToMojang(text));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendFailure(Component text) {
|
||||||
|
internal.sendFailure(ChatUtils.adventureToMojang(text));
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isPlayer() {
|
||||||
|
return internal.isPlayer();
|
||||||
|
}
|
||||||
|
|
||||||
|
public BridgedPlayer getPlayer() {
|
||||||
|
return BridgedPlayer.of(internal.getPlayer());
|
||||||
}
|
}
|
||||||
|
|
||||||
public CommandSourceStack toMojang() {
|
public CommandSourceStack toMojang() {
|
||||||
|
@@ -1,85 +0,0 @@
|
|||||||
package com.hypherionmc.craterlib.nojang.commands;
|
|
||||||
|
|
||||||
import com.hypherionmc.craterlib.api.commands.CraterCommand;
|
|
||||||
import com.hypherionmc.craterlib.nojang.authlib.BridgedGameProfile;
|
|
||||||
import com.hypherionmc.craterlib.nojang.world.entity.player.BridgedPlayer;
|
|
||||||
import com.mojang.authlib.GameProfile;
|
|
||||||
import com.mojang.brigadier.CommandDispatcher;
|
|
||||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
|
||||||
import lombok.AccessLevel;
|
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
import net.minecraft.commands.CommandSourceStack;
|
|
||||||
import net.minecraft.commands.Commands;
|
|
||||||
import net.minecraft.commands.arguments.GameProfileArgument;
|
|
||||||
import org.apache.commons.lang3.function.TriConsumer;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
|
||||||
public class CommandsRegistry {
|
|
||||||
|
|
||||||
public static final CommandsRegistry INSTANCE = new CommandsRegistry();
|
|
||||||
|
|
||||||
private final List<CraterCommand> commands = new ArrayList<>();
|
|
||||||
|
|
||||||
public void registerCommand(CraterCommand cmd) {
|
|
||||||
commands.add(cmd);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void registerCommands(CommandDispatcher<CommandSourceStack> stack) {
|
|
||||||
commands.forEach(cmd -> {
|
|
||||||
if (cmd.hasArguments()) {
|
|
||||||
CommandWithArguments.register(cmd, stack);
|
|
||||||
} else {
|
|
||||||
CommandWithoutArguments.register(cmd, stack);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
static class CommandWithoutArguments {
|
|
||||||
|
|
||||||
public static void register(CraterCommand cmd, CommandDispatcher<CommandSourceStack> dispatcher) {
|
|
||||||
LiteralArgumentBuilder<CommandSourceStack> command = Commands.literal(cmd.getCommandName())
|
|
||||||
.requires(source -> source.hasPermission(cmd.getPermissionLevel()))
|
|
||||||
.executes(context -> {
|
|
||||||
cmd.getExecutor().accept(BridgedCommandSourceStack.of(context.getSource()));
|
|
||||||
return 1;
|
|
||||||
});
|
|
||||||
|
|
||||||
dispatcher.register(command);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
static class CommandWithArguments {
|
|
||||||
|
|
||||||
public static void register(CraterCommand cmd, CommandDispatcher<CommandSourceStack> dispatcher) {
|
|
||||||
LiteralArgumentBuilder<CommandSourceStack> command = Commands.literal(cmd.getCommandName())
|
|
||||||
.requires(source -> source.hasPermission(cmd.getPermissionLevel()));
|
|
||||||
|
|
||||||
cmd.getArguments().forEach((key, pair) -> command.then(Commands.argument(key, pair.getLeft()).executes(context -> {
|
|
||||||
|
|
||||||
// This is FUCKING UGLY.... Need to improve this in the future
|
|
||||||
if (pair.getLeft() instanceof GameProfileArgument) {
|
|
||||||
Collection<GameProfile> profiles = GameProfileArgument.getGameProfiles(context, key);
|
|
||||||
List<BridgedGameProfile> bridgedGameProfiles = new ArrayList<>();
|
|
||||||
|
|
||||||
profiles.forEach(p -> bridgedGameProfiles.add(BridgedGameProfile.of(p)));
|
|
||||||
|
|
||||||
((TriConsumer<BridgedPlayer, List<BridgedGameProfile>, BridgedCommandSourceStack>) pair.getRight())
|
|
||||||
.accept(BridgedPlayer.of(context.getSource().getPlayer()), bridgedGameProfiles, BridgedCommandSourceStack.of(context.getSource()));
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
})));
|
|
||||||
|
|
||||||
dispatcher.register(command);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -15,19 +15,19 @@ public class BridgedCompoundTag {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public BridgedCompoundTag getCompound(String key) {
|
public BridgedCompoundTag getCompound(String key) {
|
||||||
return BridgedCompoundTag.of(internal.getCompound(key));
|
return BridgedCompoundTag.of(internal.getCompound(key).orElse(new CompoundTag()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<String> getAllKeys() {
|
public Set<String> getAllKeys() {
|
||||||
return internal.getAllKeys();
|
return internal.keySet();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getString(String key) {
|
public String getString(String key) {
|
||||||
return internal.getString(key);
|
return internal.getStringOr(key, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean getBoolean(String key) {
|
public boolean getBoolean(String key) {
|
||||||
return internal.getBoolean(key);
|
return internal.getBooleanOr(key, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void putString(String key, String value) {
|
public void putString(String key, String value) {
|
||||||
|
@@ -0,0 +1,31 @@
|
|||||||
|
package com.hypherionmc.craterlib.nojang.network.protocol.status;
|
||||||
|
|
||||||
|
import net.minecraft.network.protocol.status.ServerStatus;
|
||||||
|
import org.jetbrains.annotations.ApiStatus;
|
||||||
|
|
||||||
|
public final class WrappedServerStatus {
|
||||||
|
|
||||||
|
public static final class WrappedFavicon {
|
||||||
|
|
||||||
|
private final ServerStatus.Favicon internal;
|
||||||
|
|
||||||
|
public WrappedFavicon(byte[] iconBytes) {
|
||||||
|
internal = new ServerStatus.Favicon(iconBytes);
|
||||||
|
}
|
||||||
|
|
||||||
|
@ApiStatus.Internal
|
||||||
|
public WrappedFavicon(ServerStatus.Favicon internal) {
|
||||||
|
this.internal = internal;
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte[] iconBytes() {
|
||||||
|
return internal.iconBytes();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ServerStatus.Favicon toMojang() {
|
||||||
|
return internal;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -7,11 +7,11 @@ public class ResourceIdentifier {
|
|||||||
private final ResourceLocation internal;
|
private final ResourceLocation internal;
|
||||||
|
|
||||||
public ResourceIdentifier(String namespace, String path) {
|
public ResourceIdentifier(String namespace, String path) {
|
||||||
this.internal = new ResourceLocation(namespace, path);
|
this.internal = ResourceLocation.fromNamespaceAndPath(namespace, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ResourceIdentifier(String path) {
|
public ResourceIdentifier(String path) {
|
||||||
this.internal = new ResourceLocation(path);
|
this.internal = ResourceLocation.parse(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getNamespace() {
|
public String getNamespace() {
|
||||||
|
@@ -1,8 +1,10 @@
|
|||||||
package com.hypherionmc.craterlib.nojang.server;
|
package com.hypherionmc.craterlib.nojang.server;
|
||||||
|
|
||||||
import com.hypherionmc.craterlib.nojang.authlib.BridgedGameProfile;
|
import com.hypherionmc.craterlib.nojang.authlib.BridgedGameProfile;
|
||||||
|
import com.hypherionmc.craterlib.nojang.client.multiplayer.BridgedClientLevel;
|
||||||
import com.hypherionmc.craterlib.nojang.commands.BridgedFakePlayer;
|
import com.hypherionmc.craterlib.nojang.commands.BridgedFakePlayer;
|
||||||
import com.hypherionmc.craterlib.nojang.world.entity.player.BridgedPlayer;
|
import com.hypherionmc.craterlib.nojang.world.entity.player.BridgedPlayer;
|
||||||
|
import com.hypherionmc.craterlib.nojang.world.level.BridgedGameRules;
|
||||||
import com.hypherionmc.craterlib.utils.ChatUtils;
|
import com.hypherionmc.craterlib.utils.ChatUtils;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
@@ -36,7 +38,7 @@ public class BridgedMinecraftServer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return SharedConstants.getCurrentVersion().getName();
|
return SharedConstants.getCurrentVersion().name();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean usesAuthentication() {
|
public boolean usesAuthentication() {
|
||||||
@@ -48,21 +50,21 @@ public class BridgedMinecraftServer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean isPlayerBanned(BridgedGameProfile profile) {
|
public boolean isPlayerBanned(BridgedGameProfile profile) {
|
||||||
return internal.getPlayerList().getBans().isBanned(profile.toMojang());
|
return internal.getPlayerList().getBans().isBanned(profile.toNameAndId());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void whitelistPlayer(BridgedGameProfile gameProfile) {
|
public void whitelistPlayer(BridgedGameProfile gameProfile) {
|
||||||
if (!internal.getPlayerList().isUsingWhitelist())
|
if (!internal.getPlayerList().isUsingWhitelist())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
internal.getPlayerList().getWhiteList().add(new UserWhiteListEntry(gameProfile.toMojang()));
|
internal.getPlayerList().getWhiteList().add(new UserWhiteListEntry(gameProfile.toNameAndId()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void unWhitelistPlayer(BridgedGameProfile gameProfile) {
|
public void unWhitelistPlayer(BridgedGameProfile gameProfile) {
|
||||||
if (!internal.getPlayerList().isUsingWhitelist())
|
if (!internal.getPlayerList().isUsingWhitelist())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
internal.getPlayerList().getWhiteList().remove(new UserWhiteListEntry(gameProfile.toMojang()));
|
internal.getPlayerList().getWhiteList().remove(new UserWhiteListEntry(gameProfile.toNameAndId()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<BridgedPlayer> getPlayers() {
|
public List<BridgedPlayer> getPlayers() {
|
||||||
@@ -76,8 +78,12 @@ public class BridgedMinecraftServer {
|
|||||||
return profiles;
|
return profiles;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public BridgedGameRules getGameRules() {
|
||||||
|
return BridgedGameRules.bridge(internal.getGameRules());
|
||||||
|
}
|
||||||
|
|
||||||
public void banPlayer(BridgedGameProfile profile) {
|
public void banPlayer(BridgedGameProfile profile) {
|
||||||
internal.getPlayerList().getBans().add(new UserBanListEntry(profile.toMojang()));
|
internal.getPlayerList().getBans().add(new UserBanListEntry(profile.toNameAndId()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void executeCommand(BridgedMinecraftServer server, BridgedFakePlayer player, String command) {
|
public void executeCommand(BridgedMinecraftServer server, BridgedFakePlayer player, String command) {
|
||||||
|
@@ -7,6 +7,7 @@ import lombok.RequiredArgsConstructor;
|
|||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
import net.minecraft.server.network.ServerGamePacketListenerImpl;
|
import net.minecraft.server.network.ServerGamePacketListenerImpl;
|
||||||
|
import net.minecraft.world.InteractionHand;
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
@@ -49,6 +50,34 @@ public class BridgedPlayer {
|
|||||||
return BridgedBlockPos.of(internal.getOnPos());
|
return BridgedBlockPos.of(internal.getOnPos());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public float getHealth() {
|
||||||
|
return internal.getHealth();
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getMaxHealth() {
|
||||||
|
return internal.getMaxHealth();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getHeldItemMainHand() {
|
||||||
|
String value = "Nothing";
|
||||||
|
|
||||||
|
if (!internal.getItemInHand(InteractionHand.MAIN_HAND).isEmpty()) {
|
||||||
|
value = internal.getItemInHand(InteractionHand.MAIN_HAND).getDisplayName().getString();
|
||||||
|
}
|
||||||
|
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getHeldItemOffHand() {
|
||||||
|
String value = "Nothing";
|
||||||
|
|
||||||
|
if (!internal.getItemInHand(InteractionHand.OFF_HAND).isEmpty()) {
|
||||||
|
value = internal.getItemInHand(InteractionHand.OFF_HAND).getDisplayName().getString();
|
||||||
|
}
|
||||||
|
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public ServerGamePacketListenerImpl getConnection() {
|
public ServerGamePacketListenerImpl getConnection() {
|
||||||
if (isServerPlayer()) {
|
if (isServerPlayer()) {
|
||||||
@@ -57,6 +86,11 @@ public class BridgedPlayer {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void disconnect(Component message) {
|
||||||
|
if (isServerPlayer())
|
||||||
|
toMojangServerPlayer().connection.disconnect(ChatUtils.adventureToMojang(message));
|
||||||
|
}
|
||||||
|
|
||||||
public ServerPlayer toMojangServerPlayer() {
|
public ServerPlayer toMojangServerPlayer() {
|
||||||
return (ServerPlayer) internal;
|
return (ServerPlayer) internal;
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,97 @@
|
|||||||
|
package com.hypherionmc.craterlib.nojang.world.level;
|
||||||
|
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import net.minecraft.world.level.GameRules;
|
||||||
|
|
||||||
|
@RequiredArgsConstructor(staticName = "bridge")
|
||||||
|
public class BridgedGameRules {
|
||||||
|
|
||||||
|
private final GameRules internal;
|
||||||
|
|
||||||
|
// Wrapped Mojang Rules for convenience
|
||||||
|
public static final WrappedBooleanKey RULE_DOFIRETICK = WrappedBooleanKey.wrap(GameRules.RULE_DOFIRETICK);
|
||||||
|
public static final WrappedBooleanKey RULE_ALLOWFIRETICKAWAYFROMPLAYERS = WrappedBooleanKey.wrap(GameRules.RULE_ALLOWFIRETICKAWAYFROMPLAYERS);
|
||||||
|
public static final WrappedBooleanKey RULE_MOBGRIEFING = WrappedBooleanKey.wrap(GameRules.RULE_MOBGRIEFING);
|
||||||
|
public static final WrappedBooleanKey RULE_KEEPINVENTORY = WrappedBooleanKey.wrap(GameRules.RULE_KEEPINVENTORY);
|
||||||
|
public static final WrappedBooleanKey RULE_DOMOBSPAWNING = WrappedBooleanKey.wrap(GameRules.RULE_DOMOBSPAWNING);
|
||||||
|
public static final WrappedBooleanKey RULE_DOMOBLOOT = WrappedBooleanKey.wrap(GameRules.RULE_DOMOBLOOT);
|
||||||
|
public static final WrappedBooleanKey RULE_PROJECTILESCANBREAKBLOCKS = WrappedBooleanKey.wrap(GameRules.RULE_PROJECTILESCANBREAKBLOCKS);
|
||||||
|
public static final WrappedBooleanKey RULE_DOBLOCKDROPS = WrappedBooleanKey.wrap(GameRules.RULE_DOBLOCKDROPS);
|
||||||
|
public static final WrappedBooleanKey RULE_DOENTITYDROPS = WrappedBooleanKey.wrap(GameRules.RULE_DOENTITYDROPS);
|
||||||
|
public static final WrappedBooleanKey RULE_COMMANDBLOCKOUTPUT = WrappedBooleanKey.wrap(GameRules.RULE_COMMANDBLOCKOUTPUT);
|
||||||
|
public static final WrappedBooleanKey RULE_NATURAL_REGENERATION = WrappedBooleanKey.wrap(GameRules.RULE_NATURAL_REGENERATION);
|
||||||
|
public static final WrappedBooleanKey RULE_DAYLIGHT = WrappedBooleanKey.wrap(GameRules.RULE_DAYLIGHT);
|
||||||
|
public static final WrappedBooleanKey RULE_LOGADMINCOMMANDS = WrappedBooleanKey.wrap(GameRules.RULE_LOGADMINCOMMANDS);
|
||||||
|
public static final WrappedBooleanKey RULE_SHOWDEATHMESSAGES = WrappedBooleanKey.wrap(GameRules.RULE_SHOWDEATHMESSAGES);
|
||||||
|
public static final WrappedIntegerKey RULE_RANDOMTICKING = WrappedIntegerKey.wrap(GameRules.RULE_RANDOMTICKING);
|
||||||
|
public static final WrappedBooleanKey RULE_SENDCOMMANDFEEDBACK = WrappedBooleanKey.wrap(GameRules.RULE_SENDCOMMANDFEEDBACK);
|
||||||
|
public static final WrappedBooleanKey RULE_REDUCEDDEBUGINFO = WrappedBooleanKey.wrap(GameRules.RULE_REDUCEDDEBUGINFO);
|
||||||
|
public static final WrappedBooleanKey RULE_SPECTATORSGENERATECHUNKS = WrappedBooleanKey.wrap(GameRules.RULE_SPECTATORSGENERATECHUNKS);
|
||||||
|
public static final WrappedIntegerKey RULE_SPAWN_RADIUS = WrappedIntegerKey.wrap(GameRules.RULE_SPAWN_RADIUS);
|
||||||
|
public static final WrappedBooleanKey RULE_DISABLE_PLAYER_MOVEMENT_CHECK = WrappedBooleanKey.wrap(GameRules.RULE_DISABLE_PLAYER_MOVEMENT_CHECK);
|
||||||
|
public static final WrappedBooleanKey RULE_DISABLE_ELYTRA_MOVEMENT_CHECK = WrappedBooleanKey.wrap(GameRules.RULE_DISABLE_ELYTRA_MOVEMENT_CHECK);
|
||||||
|
public static final WrappedIntegerKey RULE_MAX_ENTITY_CRAMMING = WrappedIntegerKey.wrap(GameRules.RULE_MAX_ENTITY_CRAMMING);
|
||||||
|
public static final WrappedBooleanKey RULE_WEATHER_CYCLE = WrappedBooleanKey.wrap(GameRules.RULE_WEATHER_CYCLE);
|
||||||
|
public static final WrappedBooleanKey RULE_LIMITED_CRAFTING = WrappedBooleanKey.wrap(GameRules.RULE_LIMITED_CRAFTING);
|
||||||
|
public static final WrappedIntegerKey RULE_MAX_COMMAND_CHAIN_LENGTH = WrappedIntegerKey.wrap(GameRules.RULE_MAX_COMMAND_CHAIN_LENGTH);
|
||||||
|
public static final WrappedIntegerKey RULE_MAX_COMMAND_FORK_COUNT = WrappedIntegerKey.wrap(GameRules.RULE_MAX_COMMAND_FORK_COUNT);
|
||||||
|
public static final WrappedIntegerKey RULE_COMMAND_MODIFICATION_BLOCK_LIMIT = WrappedIntegerKey.wrap(GameRules.RULE_COMMAND_MODIFICATION_BLOCK_LIMIT);
|
||||||
|
public static final WrappedBooleanKey RULE_ANNOUNCE_ADVANCEMENTS = WrappedBooleanKey.wrap(GameRules.RULE_ANNOUNCE_ADVANCEMENTS);
|
||||||
|
public static final WrappedBooleanKey RULE_DISABLE_RAIDS = WrappedBooleanKey.wrap(GameRules.RULE_DISABLE_RAIDS);
|
||||||
|
public static final WrappedBooleanKey RULE_DOINSOMNIA = WrappedBooleanKey.wrap(GameRules.RULE_DOINSOMNIA);
|
||||||
|
public static final WrappedBooleanKey RULE_DO_IMMEDIATE_RESPAWN = WrappedBooleanKey.wrap(GameRules.RULE_DO_IMMEDIATE_RESPAWN);
|
||||||
|
public static final WrappedIntegerKey RULE_PLAYERS_NETHER_PORTAL_DEFAULT_DELAY = WrappedIntegerKey.wrap(GameRules.RULE_PLAYERS_NETHER_PORTAL_DEFAULT_DELAY);
|
||||||
|
public static final WrappedIntegerKey RULE_PLAYERS_NETHER_PORTAL_CREATIVE_DELAY = WrappedIntegerKey.wrap(GameRules.RULE_PLAYERS_NETHER_PORTAL_CREATIVE_DELAY);
|
||||||
|
public static final WrappedBooleanKey RULE_DROWNING_DAMAGE = WrappedBooleanKey.wrap(GameRules.RULE_DROWNING_DAMAGE);
|
||||||
|
public static final WrappedBooleanKey RULE_FALL_DAMAGE = WrappedBooleanKey.wrap(GameRules.RULE_FALL_DAMAGE);
|
||||||
|
public static final WrappedBooleanKey RULE_FIRE_DAMAGE = WrappedBooleanKey.wrap(GameRules.RULE_FIRE_DAMAGE);
|
||||||
|
public static final WrappedBooleanKey RULE_FREEZE_DAMAGE = WrappedBooleanKey.wrap(GameRules.RULE_FREEZE_DAMAGE);
|
||||||
|
public static final WrappedBooleanKey RULE_DO_PATROL_SPAWNING = WrappedBooleanKey.wrap(GameRules.RULE_DO_PATROL_SPAWNING);
|
||||||
|
public static final WrappedBooleanKey RULE_DO_TRADER_SPAWNING = WrappedBooleanKey.wrap(GameRules.RULE_DO_TRADER_SPAWNING);
|
||||||
|
public static final WrappedBooleanKey RULE_DO_WARDEN_SPAWNING = WrappedBooleanKey.wrap(GameRules.RULE_DO_WARDEN_SPAWNING);
|
||||||
|
public static final WrappedBooleanKey RULE_FORGIVE_DEAD_PLAYERS = WrappedBooleanKey.wrap(GameRules.RULE_FORGIVE_DEAD_PLAYERS);
|
||||||
|
public static final WrappedBooleanKey RULE_UNIVERSAL_ANGER = WrappedBooleanKey.wrap(GameRules.RULE_UNIVERSAL_ANGER);
|
||||||
|
public static final WrappedIntegerKey RULE_PLAYERS_SLEEPING_PERCENTAGE = WrappedIntegerKey.wrap(GameRules.RULE_PLAYERS_SLEEPING_PERCENTAGE);
|
||||||
|
public static final WrappedBooleanKey RULE_BLOCK_EXPLOSION_DROP_DECAY = WrappedBooleanKey.wrap(GameRules.RULE_BLOCK_EXPLOSION_DROP_DECAY);
|
||||||
|
public static final WrappedBooleanKey RULE_MOB_EXPLOSION_DROP_DECAY = WrappedBooleanKey.wrap(GameRules.RULE_MOB_EXPLOSION_DROP_DECAY);
|
||||||
|
public static final WrappedBooleanKey RULE_TNT_EXPLOSION_DROP_DECAY = WrappedBooleanKey.wrap(GameRules.RULE_TNT_EXPLOSION_DROP_DECAY);
|
||||||
|
public static final WrappedIntegerKey RULE_SNOW_ACCUMULATION_HEIGHT = WrappedIntegerKey.wrap(GameRules.RULE_SNOW_ACCUMULATION_HEIGHT);
|
||||||
|
public static final WrappedBooleanKey RULE_WATER_SOURCE_CONVERSION = WrappedBooleanKey.wrap(GameRules.RULE_WATER_SOURCE_CONVERSION);
|
||||||
|
public static final WrappedBooleanKey RULE_LAVA_SOURCE_CONVERSION = WrappedBooleanKey.wrap(GameRules.RULE_LAVA_SOURCE_CONVERSION);
|
||||||
|
public static final WrappedBooleanKey RULE_GLOBAL_SOUND_EVENTS = WrappedBooleanKey.wrap(GameRules.RULE_GLOBAL_SOUND_EVENTS);
|
||||||
|
public static final WrappedBooleanKey RULE_DO_VINES_SPREAD = WrappedBooleanKey.wrap(GameRules.RULE_DO_VINES_SPREAD);
|
||||||
|
public static final WrappedBooleanKey RULE_ENDER_PEARLS_VANISH_ON_DEATH = WrappedBooleanKey.wrap(GameRules.RULE_ENDER_PEARLS_VANISH_ON_DEATH);
|
||||||
|
public static final WrappedIntegerKey RULE_MINECART_MAX_SPEED = WrappedIntegerKey.wrap(GameRules.RULE_MINECART_MAX_SPEED);
|
||||||
|
public static final WrappedIntegerKey RULE_SPAWN_CHUNK_RADIUS = WrappedIntegerKey.wrap(null);
|
||||||
|
public static final WrappedBooleanKey RULE_TNT_EXPLODES = WrappedBooleanKey.wrap(GameRules.RULE_TNT_EXPLODES);
|
||||||
|
|
||||||
|
public boolean getBoolean(WrappedBooleanKey key) {
|
||||||
|
return internal.getBoolean(key.toMojang());
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getInt(WrappedIntegerKey key) {
|
||||||
|
return internal.getInt(key.toMojang());
|
||||||
|
}
|
||||||
|
|
||||||
|
public GameRules toMojang() {
|
||||||
|
return internal;
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequiredArgsConstructor(staticName = "wrap")
|
||||||
|
public static final class WrappedBooleanKey {
|
||||||
|
private final GameRules.Key<GameRules.BooleanValue> internal;
|
||||||
|
|
||||||
|
public GameRules.Key<GameRules.BooleanValue> toMojang() {
|
||||||
|
return internal;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequiredArgsConstructor(staticName = "wrap")
|
||||||
|
public static final class WrappedIntegerKey {
|
||||||
|
private final GameRules.Key<GameRules.IntegerValue> internal;
|
||||||
|
|
||||||
|
public GameRules.Key<GameRules.IntegerValue> toMojang() {
|
||||||
|
return internal;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -1,26 +1,72 @@
|
|||||||
package com.hypherionmc.craterlib.utils;
|
package com.hypherionmc.craterlib.utils;
|
||||||
|
|
||||||
|
import com.google.gson.JsonElement;
|
||||||
|
import com.google.gson.JsonParseException;
|
||||||
|
import com.hypherionmc.craterlib.core.platform.CommonPlatform;
|
||||||
|
import com.hypherionmc.craterlib.core.platform.ModloaderEnvironment;
|
||||||
import com.hypherionmc.craterlib.nojang.resources.ResourceIdentifier;
|
import com.hypherionmc.craterlib.nojang.resources.ResourceIdentifier;
|
||||||
|
import com.mojang.serialization.JsonOps;
|
||||||
|
import lombok.Getter;
|
||||||
import me.hypherionmc.mcdiscordformatter.discord.DiscordSerializer;
|
import me.hypherionmc.mcdiscordformatter.discord.DiscordSerializer;
|
||||||
import me.hypherionmc.mcdiscordformatter.minecraft.MinecraftSerializer;
|
import me.hypherionmc.mcdiscordformatter.minecraft.MinecraftSerializer;
|
||||||
import net.kyori.adventure.text.format.NamedTextColor;
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
|
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||||
|
import net.kyori.adventure.text.serializer.json.JSONOptions;
|
||||||
import net.minecraft.ChatFormatting;
|
import net.minecraft.ChatFormatting;
|
||||||
|
import net.minecraft.SharedConstants;
|
||||||
import net.minecraft.Util;
|
import net.minecraft.Util;
|
||||||
|
// @noplugin
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
// #noplugin
|
||||||
|
import net.minecraft.core.HolderLookup;
|
||||||
import net.minecraft.core.RegistryAccess;
|
import net.minecraft.core.RegistryAccess;
|
||||||
import net.minecraft.network.chat.Component;
|
import net.minecraft.network.chat.Component;
|
||||||
|
import net.minecraft.network.chat.ComponentSerialization;
|
||||||
import net.minecraft.network.chat.Style;
|
import net.minecraft.network.chat.Style;
|
||||||
|
import net.minecraft.util.StrictJsonParser;
|
||||||
|
|
||||||
public class ChatUtils {
|
public class ChatUtils {
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
private static final GsonComponentSerializer adventureSerializer = GsonComponentSerializer.builder().options(
|
||||||
|
JSONOptions.byDataVersion().at(SharedConstants.getCurrentVersion().dataVersion().version())
|
||||||
|
).build();
|
||||||
|
|
||||||
|
private static final MiniMessage miniMessage = MiniMessage.miniMessage();
|
||||||
|
|
||||||
public static Component adventureToMojang(net.kyori.adventure.text.Component inComponent) {
|
public static Component adventureToMojang(net.kyori.adventure.text.Component inComponent) {
|
||||||
final String serialised = GsonComponentSerializer.gson().serialize(inComponent);
|
final JsonElement serialised = adventureSerializer.serializeToTree(inComponent);
|
||||||
return Component.Serializer.fromJson(serialised, RegistryAccess.EMPTY);
|
|
||||||
|
// FUCK YOU MOJANG. SERIOUSLY. FUCK OFF WITH THIS SHIT
|
||||||
|
return ComponentSerialization.CODEC
|
||||||
|
.parse(getRegistryLookup().createSerializationContext(JsonOps.INSTANCE), serialised)
|
||||||
|
.getOrThrow(JsonParseException::new);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static net.kyori.adventure.text.Component mojangToAdventure(Component inComponent) {
|
public static net.kyori.adventure.text.Component mojangToAdventure(Component inComponent) {
|
||||||
final String serialised = Component.Serializer.toJson(inComponent, RegistryAccess.EMPTY);
|
try {
|
||||||
return GsonComponentSerializer.gson().deserialize(serialised);
|
// FUCK YOU MOJANG. SERIOUSLY. FUCK OFF WITH THIS SHIT
|
||||||
|
final JsonElement serialised = ComponentSerialization.CODEC
|
||||||
|
.encodeStart(JsonOps.INSTANCE, inComponent)
|
||||||
|
.getOrThrow(JsonParseException::new);
|
||||||
|
|
||||||
|
return adventureSerializer.deserializeFromTree(serialised);
|
||||||
|
} catch (Exception e) {
|
||||||
|
return net.kyori.adventure.text.Component.text(inComponent.getString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static HolderLookup.Provider getRegistryLookup() {
|
||||||
|
// @noplugin
|
||||||
|
if (ModloaderEnvironment.INSTANCE.getEnvironment().isClient() && Minecraft.getInstance().level != null)
|
||||||
|
return Minecraft.getInstance().level.registryAccess();
|
||||||
|
// #noplugin
|
||||||
|
|
||||||
|
if (ModloaderEnvironment.INSTANCE.getEnvironment().isServer() && CommonPlatform.INSTANCE.getMCServer() != null)
|
||||||
|
return CommonPlatform.INSTANCE.getMCServer().toMojang().registryAccess();
|
||||||
|
|
||||||
|
return RegistryAccess.EMPTY;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Some text components contain duplicate text, resulting in duplicate messages
|
// Some text components contain duplicate text, resulting in duplicate messages
|
||||||
@@ -47,7 +93,7 @@ public class ChatUtils {
|
|||||||
|
|
||||||
public static String resolve(net.kyori.adventure.text.Component component, boolean formatted) {
|
public static String resolve(net.kyori.adventure.text.Component component, boolean formatted) {
|
||||||
Component c = adventureToMojang(component);
|
Component c = adventureToMojang(component);
|
||||||
String returnVal = ChatFormatting.stripFormatting(c.getString());
|
String returnVal = ChatFormatting.stripFormatting(DiscordMarkdownStripper.stripMarkdown(c.getString()));
|
||||||
|
|
||||||
if (formatted) {
|
if (formatted) {
|
||||||
returnVal = DiscordSerializer.INSTANCE.serialize(safeCopy(c).copy());
|
returnVal = DiscordSerializer.INSTANCE.serialize(safeCopy(c).copy());
|
||||||
@@ -87,4 +133,21 @@ public class ChatUtils {
|
|||||||
|
|
||||||
return mojangToAdventure(Component.translatable(Util.makeDescriptionId("biome", identifier.toMojang())));
|
return mojangToAdventure(Component.translatable(Util.makeDescriptionId("biome", identifier.toMojang())));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static net.kyori.adventure.text.Component format(String value) {
|
||||||
|
value = convertFormattingCodes(value);
|
||||||
|
|
||||||
|
try {
|
||||||
|
return miniMessage.deserializeOr(value, net.kyori.adventure.text.Component.translatable(value));
|
||||||
|
} catch (Exception ignored) {
|
||||||
|
// Mini message fails to format text that contain legacy formatting. Since we support both, that's bad.
|
||||||
|
// We just ignore the exception here so that the whole format doesn't fail
|
||||||
|
}
|
||||||
|
|
||||||
|
return net.kyori.adventure.text.Component.translatable(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String convertFormattingCodes(String input) {
|
||||||
|
return input.replaceAll("§([0-9a-fklmnor])", "\u00A7$1");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,35 @@
|
|||||||
|
package com.hypherionmc.craterlib.utils;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
public class DiscordMarkdownStripper {
|
||||||
|
|
||||||
|
// Patterns for different markdown syntaxes
|
||||||
|
private static final Pattern BOLD = Pattern.compile("\\*\\*(.*?)\\*\\*");
|
||||||
|
private static final Pattern ITALIC_UNDERSCORE = Pattern.compile("_(.*?)_");
|
||||||
|
private static final Pattern ITALIC_ASTERISK = Pattern.compile("\\*(.*?)\\*");
|
||||||
|
private static final Pattern UNDERLINE = Pattern.compile("__(.*?)__");
|
||||||
|
private static final Pattern STRIKETHROUGH = Pattern.compile("~~(.*?)~~");
|
||||||
|
private static final Pattern CODE_BLOCK = Pattern.compile("```(.+?)```", Pattern.DOTALL);
|
||||||
|
private static final Pattern INLINE_CODE = Pattern.compile("`([^`]*)`");
|
||||||
|
private static final Pattern BLOCKQUOTE = Pattern.compile("^> (.*?$)", Pattern.MULTILINE);
|
||||||
|
private static final Pattern MARKDOWN_LINK = Pattern.compile("\\[(.*?)\\]\\((.*?)\\)");
|
||||||
|
private static final Pattern PLAIN_URL = Pattern.compile("\\b(https?|ftp|file)://[-a-zA-Z0-9+&@#/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#/%=~_|]");
|
||||||
|
|
||||||
|
public static String stripMarkdown(@NotNull String text) {
|
||||||
|
text = BOLD.matcher(text).replaceAll("$1");
|
||||||
|
text = ITALIC_UNDERSCORE.matcher(text).replaceAll("$1");
|
||||||
|
text = ITALIC_ASTERISK.matcher(text).replaceAll("$1");
|
||||||
|
text = UNDERLINE.matcher(text).replaceAll("$1");
|
||||||
|
text = STRIKETHROUGH.matcher(text).replaceAll("$1");
|
||||||
|
text = CODE_BLOCK.matcher(text).replaceAll("$1");
|
||||||
|
text = INLINE_CODE.matcher(text).replaceAll("$1");
|
||||||
|
text = BLOCKQUOTE.matcher(text).replaceAll("$1");
|
||||||
|
text = MARKDOWN_LINK.matcher(text).replaceAll("$1");
|
||||||
|
text = PLAIN_URL.matcher(text).replaceAll("<$0>");
|
||||||
|
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
}
|
@@ -10,6 +10,8 @@ import java.util.ServiceLoader;
|
|||||||
*/
|
*/
|
||||||
public class InternalServiceUtil {
|
public class InternalServiceUtil {
|
||||||
|
|
||||||
|
public static ClassLoader loader = Thread.currentThread().getContextClassLoader();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Try to load a service
|
* Try to load a service
|
||||||
*
|
*
|
||||||
@@ -17,7 +19,7 @@ public class InternalServiceUtil {
|
|||||||
* @return The loaded class
|
* @return The loaded class
|
||||||
*/
|
*/
|
||||||
public static <T> T load(Class<T> clazz) {
|
public static <T> T load(Class<T> clazz) {
|
||||||
final T loadedService = ServiceLoader.load(clazz)
|
final T loadedService = ServiceLoader.load(clazz, loader)
|
||||||
.findFirst()
|
.findFirst()
|
||||||
.orElseThrow(() -> new NullPointerException("Failed to load service for " + clazz.getName()));
|
.orElseThrow(() -> new NullPointerException("Failed to load service for " + clazz.getName()));
|
||||||
CraterConstants.LOG.debug("Loaded {} for service {}", loadedService, clazz);
|
CraterConstants.LOG.debug("Loaded {} for service {}", loadedService, clazz);
|
||||||
|
@@ -0,0 +1,5 @@
|
|||||||
|
package com.hypherionmc.craterlib.utils;
|
||||||
|
|
||||||
|
public interface TriConsumer<T, U, V> {
|
||||||
|
void accept(T t, U u, V v);
|
||||||
|
}
|
12
Common/src/main/resources/assets/craterlib/lang/en_pt.json
Normal file
12
Common/src/main/resources/assets/craterlib/lang/en_pt.json
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"t.clc.opensubconfig": "Change Course",
|
||||||
|
"t.clc.save": "Plot Map",
|
||||||
|
"t.clc.cancel_discard": "Return to yer barnacle-covered map",
|
||||||
|
"t.clc.quit_config": "New course not given t' yer cap'n",
|
||||||
|
"t.clc.quit_config_sure": "Ye haven't given yer new course t' yer cap'n yet. Do ye want t' go back t' yer barnacle-covered map?",
|
||||||
|
"t.clc.quit_discard": "Aye, return t' barnacle-covered map",
|
||||||
|
|
||||||
|
"cl.buttons.edit": "Mark Path",
|
||||||
|
"cl.buttons.add_entry": "+ Add Belay",
|
||||||
|
"cl.buttons.entry": "Belay %s"
|
||||||
|
}
|
@@ -4,5 +4,9 @@
|
|||||||
"t.clc.cancel_discard": "Discard",
|
"t.clc.cancel_discard": "Discard",
|
||||||
"t.clc.quit_config": "Unsaved Changes",
|
"t.clc.quit_config": "Unsaved Changes",
|
||||||
"t.clc.quit_config_sure": "You have unsaved config changes. Are you sure you want to discard them?",
|
"t.clc.quit_config_sure": "You have unsaved config changes. Are you sure you want to discard them?",
|
||||||
"t.clc.quit_discard": "Quit & Discard"
|
"t.clc.quit_discard": "Quit & Discard",
|
||||||
|
|
||||||
|
"cl.buttons.edit": "Edit",
|
||||||
|
"cl.buttons.add_entry": "+ Add Entry",
|
||||||
|
"cl.buttons.entry": "Entry %s"
|
||||||
}
|
}
|
||||||
|
12
Common/src/main/resources/assets/craterlib/lang/ru_ru.json
Normal file
12
Common/src/main/resources/assets/craterlib/lang/ru_ru.json
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"t.clc.opensubconfig": "Открыть конфигурацию",
|
||||||
|
"t.clc.save": "Сохранить",
|
||||||
|
"t.clc.cancel_discard": "Отменить",
|
||||||
|
"t.clc.quit_config": "Несохранённые изменения",
|
||||||
|
"t.clc.quit_config_sure": "У вас есть несохранённые изменения конфигурации. Вы уверены, что хотите их отменить?",
|
||||||
|
"t.clc.quit_discard": "Закрыть и отменить",
|
||||||
|
|
||||||
|
"cl.buttons.edit": "Редактировать",
|
||||||
|
"cl.buttons.add_entry": "+ Добавить запись",
|
||||||
|
"cl.buttons.entry": "Запись %s"
|
||||||
|
}
|
@@ -4,6 +4,8 @@
|
|||||||
"package": "com.hypherionmc.craterlib.mixin",
|
"package": "com.hypherionmc.craterlib.mixin",
|
||||||
"compatibilityLevel": "JAVA_17",
|
"compatibilityLevel": "JAVA_17",
|
||||||
"mixins": [
|
"mixins": [
|
||||||
|
"events.StoredUserEntryAccessor",
|
||||||
|
"events.WhitelistMixin"
|
||||||
],
|
],
|
||||||
"client": [
|
"client": [
|
||||||
"ChatInputSuggestorMixin",
|
"ChatInputSuggestorMixin",
|
||||||
@@ -16,7 +18,8 @@
|
|||||||
"events.CommandMixin",
|
"events.CommandMixin",
|
||||||
"events.PlayerAdvancementsMixin",
|
"events.PlayerAdvancementsMixin",
|
||||||
"events.PlayerListMixin",
|
"events.PlayerListMixin",
|
||||||
"events.ServerPlayerMixin"
|
"events.ServerPlayerMixin",
|
||||||
|
"events.ServerStatusMixin"
|
||||||
],
|
],
|
||||||
"injectors": {
|
"injectors": {
|
||||||
"defaultRequire": 1
|
"defaultRequire": 1
|
||||||
|
@@ -9,8 +9,13 @@ dependencies {
|
|||||||
exclude(group: "net.fabricmc.fabric-api")
|
exclude(group: "net.fabricmc.fabric-api")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
stupidRemapArch("dev.ftb.mods:ftb-essentials:${ftb_essentials}")
|
||||||
|
stupidRemapArch("dev.ftb.mods:ftb-ranks:${ftb_ranks}")
|
||||||
|
|
||||||
|
modImplementation("me.shedaniel.cloth:cloth-config-fabric:${cloth_config}")
|
||||||
modImplementation "maven.modrinth:fabrictailor:${fabrictailor}"
|
modImplementation "maven.modrinth:fabrictailor:${fabrictailor}"
|
||||||
modImplementation "maven.modrinth:vanish:${vanish}"
|
modImplementation "maven.modrinth:vanish:${vanish}"
|
||||||
|
modImplementation("unimaven.modrinth:advanced-chat:${advanced_chat}")
|
||||||
|
|
||||||
// Do not edit or remove
|
// Do not edit or remove
|
||||||
implementation project(":Common")
|
implementation project(":Common")
|
||||||
@@ -29,6 +34,7 @@ shadowJar {
|
|||||||
}
|
}
|
||||||
|
|
||||||
setArchiveClassifier('dev-shadow')
|
setArchiveClassifier('dev-shadow')
|
||||||
|
mergeServiceFiles()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -103,24 +109,29 @@ publisher {
|
|||||||
apiKeys {
|
apiKeys {
|
||||||
modrinth(System.getenv("MODRINTH_TOKEN"))
|
modrinth(System.getenv("MODRINTH_TOKEN"))
|
||||||
curseforge(System.getenv("CURSE_TOKEN"))
|
curseforge(System.getenv("CURSE_TOKEN"))
|
||||||
|
nightbloom(System.getenv("PLATFORM_KEY"))
|
||||||
}
|
}
|
||||||
|
|
||||||
setCurseID(curse_id)
|
setCurseID(curse_id)
|
||||||
setModrinthID(modrinth_id)
|
setModrinthID(modrinth_id)
|
||||||
|
setNightbloomID("craterlib")
|
||||||
setVersionType("release")
|
setVersionType("release")
|
||||||
setChangelog("https://raw.githubusercontent.com/hypherionmc/changelogs/main/craterlib/changelog-fabric.md")
|
setChangelog(rootProject.file("changelog.md"))
|
||||||
setProjectVersion("${minecraft_version}-${project.version}")
|
setProjectVersion("${minecraft_version}-${project.version}")
|
||||||
setDisplayName("[FABRIC/QUILT 1.20.6] CraterLib - ${project.version}")
|
setDisplayName("[FABRIC/QUILT 1.21.9] CraterLib - ${project.version}")
|
||||||
setGameVersions("1.20.6")
|
setGameVersions("1.21.9")
|
||||||
setLoaders("fabric", "quilt")
|
setLoaders("fabric", "quilt")
|
||||||
setArtifact(remapJar)
|
setArtifact(remapJar)
|
||||||
setCurseEnvironment("both")
|
setCurseEnvironment("both")
|
||||||
|
setIsManualRelease(true)
|
||||||
|
|
||||||
modrinthDepends {
|
modrinthDepends {
|
||||||
required("fabric-api")
|
required("fabric-api")
|
||||||
|
optional("cloth-config", "modmenu")
|
||||||
}
|
}
|
||||||
|
|
||||||
curseDepends {
|
curseDepends {
|
||||||
required("fabric-api")
|
required("fabric-api")
|
||||||
|
optional("cloth-config", "modmenu")
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -9,7 +9,6 @@ import com.hypherionmc.craterlib.core.networking.CraterPacketNetwork;
|
|||||||
import com.hypherionmc.craterlib.core.networking.data.PacketSide;
|
import com.hypherionmc.craterlib.core.networking.data.PacketSide;
|
||||||
import com.hypherionmc.craterlib.core.platform.ModloaderEnvironment;
|
import com.hypherionmc.craterlib.core.platform.ModloaderEnvironment;
|
||||||
import com.hypherionmc.craterlib.network.CraterFabricNetworkHandler;
|
import com.hypherionmc.craterlib.network.CraterFabricNetworkHandler;
|
||||||
import com.hypherionmc.craterlib.nojang.commands.CommandsRegistry;
|
|
||||||
import com.hypherionmc.craterlib.nojang.server.BridgedMinecraftServer;
|
import com.hypherionmc.craterlib.nojang.server.BridgedMinecraftServer;
|
||||||
import net.fabricmc.api.ModInitializer;
|
import net.fabricmc.api.ModInitializer;
|
||||||
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
|
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
|
||||||
@@ -21,8 +20,7 @@ public class CraterLibInitializer implements ModInitializer {
|
|||||||
public void onInitialize() {
|
public void onInitialize() {
|
||||||
new CraterPacketNetwork(new CraterFabricNetworkHandler(PacketSide.SERVER));
|
new CraterPacketNetwork(new CraterFabricNetworkHandler(PacketSide.SERVER));
|
||||||
CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> {
|
CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> {
|
||||||
CraterEventBus.INSTANCE.postEvent(new CraterRegisterCommandEvent());
|
CraterEventBus.INSTANCE.postEvent(new CraterRegisterCommandEvent(dispatcher));
|
||||||
CommandsRegistry.INSTANCE.registerCommands(dispatcher);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
@@ -1,11 +1,17 @@
|
|||||||
package com.hypherionmc.craterlib;
|
package com.hypherionmc.craterlib;
|
||||||
|
|
||||||
import com.hypherionmc.craterlib.client.gui.config.CraterConfigScreen;
|
import com.hypherionmc.craterlib.client.gui.config.ClothConfigScreenBuilder;
|
||||||
import com.hypherionmc.craterlib.core.config.ConfigController;
|
import com.hypherionmc.craterlib.core.config.ConfigController;
|
||||||
import com.hypherionmc.craterlib.core.config.ModuleConfig;
|
import com.hypherionmc.craterlib.core.config.annotations.ClothScreen;
|
||||||
import com.hypherionmc.craterlib.core.config.annotations.NoConfigScreen;
|
import com.hypherionmc.craterlib.core.config.annotations.NoConfigScreen;
|
||||||
|
import com.hypherionmc.craterlib.core.platform.ModloaderEnvironment;
|
||||||
|
import com.hypherionmc.craterlib.nojang.client.BridgedMinecraft;
|
||||||
import com.terraformersmc.modmenu.api.ConfigScreenFactory;
|
import com.terraformersmc.modmenu.api.ConfigScreenFactory;
|
||||||
import com.terraformersmc.modmenu.api.ModMenuApi;
|
import com.terraformersmc.modmenu.api.ModMenuApi;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
|
import net.kyori.adventure.text.format.Style;
|
||||||
|
import net.kyori.adventure.text.format.TextDecoration;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -19,9 +25,18 @@ public class CraterLibModMenuIntegration implements ModMenuApi {
|
|||||||
public Map<String, ConfigScreenFactory<?>> getProvidedConfigScreenFactories() {
|
public Map<String, ConfigScreenFactory<?>> getProvidedConfigScreenFactories() {
|
||||||
Map<String, ConfigScreenFactory<?>> configScreens = new HashMap<>();
|
Map<String, ConfigScreenFactory<?>> configScreens = new HashMap<>();
|
||||||
|
|
||||||
ConfigController.getMonitoredConfigs().forEach((conf, watcher) -> {
|
ConfigController.getWatchedConfigs().forEach((conf, config) -> {
|
||||||
if (!conf.getClass().isAnnotationPresent(NoConfigScreen.class)) {
|
if (config.getClass().isAnnotationPresent(NoConfigScreen.class))
|
||||||
configScreens.put(((ModuleConfig) conf).getModId(), screen -> new CraterConfigScreen((ModuleConfig) conf, screen));
|
return;
|
||||||
|
|
||||||
|
if (config.getClass().isAnnotationPresent(ClothScreen.class) && (ModloaderEnvironment.INSTANCE.isModLoaded("cloth_config") || ModloaderEnvironment.INSTANCE.isModLoaded("cloth-config") || ModloaderEnvironment.INSTANCE.isModLoaded("clothconfig"))) {
|
||||||
|
configScreens.put(config.getModId(), screen -> ClothConfigScreenBuilder.buildConfigScreen(config, screen));
|
||||||
|
} else {
|
||||||
|
configScreens.put(config.getModId(), screen -> BridgedMinecraft.getInstance().buildWarningScreen(
|
||||||
|
Component.text("Notice").style(Style.style(NamedTextColor.YELLOW).decorate(TextDecoration.BOLD)),
|
||||||
|
Component.text("This mod does not have a config screen, or Cloth Config is not installed"),
|
||||||
|
screen
|
||||||
|
));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@@ -5,6 +5,8 @@ import com.hypherionmc.craterlib.compat.Vanish;
|
|||||||
import com.hypherionmc.craterlib.core.platform.CompatUtils;
|
import com.hypherionmc.craterlib.core.platform.CompatUtils;
|
||||||
import com.hypherionmc.craterlib.core.platform.ModloaderEnvironment;
|
import com.hypherionmc.craterlib.core.platform.ModloaderEnvironment;
|
||||||
import com.hypherionmc.craterlib.nojang.world.entity.player.BridgedPlayer;
|
import com.hypherionmc.craterlib.nojang.world.entity.player.BridgedPlayer;
|
||||||
|
import me.wesley1808.advancedchat.api.AdvancedChatAPI;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
|
||||||
public class FabricCompatHelper implements CompatUtils {
|
public class FabricCompatHelper implements CompatUtils {
|
||||||
|
|
||||||
@@ -13,11 +15,37 @@ public class FabricCompatHelper implements CompatUtils {
|
|||||||
if (!ModloaderEnvironment.INSTANCE.isModLoaded("melius-vanish"))
|
if (!ModloaderEnvironment.INSTANCE.isModLoaded("melius-vanish"))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return Vanish.isPlayerVanished(player.toMojangServerPlayer());
|
return !Vanish.isPlayerVanished(player.toMojangServerPlayer());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getSkinUUID(BridgedPlayer player) {
|
public String getSkinUUID(BridgedPlayer player) {
|
||||||
return FabricTailor.getTailorSkin(player.toMojangServerPlayer());
|
return FabricTailor.getTailorSkin(player.toMojangServerPlayer());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isPlayerBleeding(BridgedPlayer player) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean playerBledOut(BridgedPlayer player) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean playerRevived(BridgedPlayer player) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isPrivateMessage(BridgedPlayer player) {
|
||||||
|
return !AdvancedChatAPI.isPublicChat(player.toMojangServerPlayer());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Component getChannelPrefix(BridgedPlayer player) {
|
||||||
|
net.minecraft.network.chat.Component c = AdvancedChatAPI.getChannelPrefix(player.toMojangServerPlayer());
|
||||||
|
return c.getString().isBlank() ? Component.empty() : Component.text(c.getString());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
package com.hypherionmc.craterlib.common;
|
package com.hypherionmc.craterlib.common;
|
||||||
|
|
||||||
import com.hypherionmc.craterlib.core.platform.Environment;
|
import com.hypherionmc.craterlib.core.platform.Environment;
|
||||||
|
import com.hypherionmc.craterlib.core.platform.LoaderType;
|
||||||
import com.hypherionmc.craterlib.core.platform.ModloaderEnvironment;
|
import com.hypherionmc.craterlib.core.platform.ModloaderEnvironment;
|
||||||
import net.fabricmc.loader.api.FabricLoader;
|
import net.fabricmc.loader.api.FabricLoader;
|
||||||
import net.minecraft.SharedConstants;
|
import net.minecraft.SharedConstants;
|
||||||
@@ -19,9 +20,14 @@ public class FabricLoaderHelper implements ModloaderEnvironment {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LoaderType getLoaderType() {
|
||||||
|
return LoaderType.FABRIC;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getGameVersion() {
|
public String getGameVersion() {
|
||||||
return SharedConstants.VERSION_STRING;
|
return SharedConstants.getCurrentVersion().name();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -12,9 +12,9 @@ public class Vanish {
|
|||||||
public static void register() {
|
public static void register() {
|
||||||
VanishEvents.VANISH_EVENT.register((serverPlayer, b) -> {
|
VanishEvents.VANISH_EVENT.register((serverPlayer, b) -> {
|
||||||
if (b) {
|
if (b) {
|
||||||
CraterEventBus.INSTANCE.postEvent(new CraterPlayerEvent.PlayerLoggedOut(BridgedPlayer.of(serverPlayer)));
|
CraterEventBus.INSTANCE.postEvent(new CraterPlayerEvent.PlayerLoggedOut(BridgedPlayer.of(serverPlayer), true));
|
||||||
} else {
|
} else {
|
||||||
CraterEventBus.INSTANCE.postEvent(new CraterPlayerEvent.PlayerLoggedIn(BridgedPlayer.of(serverPlayer)));
|
CraterEventBus.INSTANCE.postEvent(new CraterPlayerEvent.PlayerLoggedIn(BridgedPlayer.of(serverPlayer), true));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@@ -22,12 +22,13 @@ public class ServerGamePacketListenerImplMixin {
|
|||||||
public ServerPlayer player;
|
public ServerPlayer player;
|
||||||
|
|
||||||
@Inject(
|
@Inject(
|
||||||
method = "lambda$handleChat$5",
|
method = "lambda$handleChat$6",
|
||||||
at = @At("HEAD"),
|
at = @At("HEAD"),
|
||||||
cancellable = true
|
cancellable = true
|
||||||
)
|
)
|
||||||
private void injectChatEvent(PlayerChatMessage arg, Component arg2, FilteredText arg3, CallbackInfo ci) {
|
private void injectChatEvent(PlayerChatMessage arg, Component arg2, FilteredText arg3, CallbackInfo ci) {
|
||||||
CraterServerChatEvent event = new CraterServerChatEvent(BridgedPlayer.of(this.player), arg.decoratedContent().getString(), ChatUtils.mojangToAdventure(arg.decoratedContent()));
|
Component finalcomp = arg2 == null ? arg.decoratedContent() : arg2;
|
||||||
|
CraterServerChatEvent event = new CraterServerChatEvent(BridgedPlayer.of(this.player), finalcomp.getString(), ChatUtils.mojangToAdventure(finalcomp));
|
||||||
CraterEventBus.INSTANCE.postEvent(event);
|
CraterEventBus.INSTANCE.postEvent(event);
|
||||||
if (event.wasCancelled())
|
if (event.wasCancelled())
|
||||||
ci.cancel();
|
ci.cancel();
|
||||||
|
@@ -0,0 +1,52 @@
|
|||||||
|
package com.hypherionmc.craterlib.mixin;
|
||||||
|
|
||||||
|
import com.hypherionmc.craterlib.api.events.server.ServerStatusEvent;
|
||||||
|
import com.hypherionmc.craterlib.core.event.CraterEventBus;
|
||||||
|
import com.hypherionmc.craterlib.utils.ChatUtils;
|
||||||
|
import net.minecraft.network.Connection;
|
||||||
|
import net.minecraft.network.protocol.status.ClientboundStatusResponsePacket;
|
||||||
|
import net.minecraft.network.protocol.status.ServerStatus;
|
||||||
|
import net.minecraft.network.protocol.status.ServerboundStatusRequestPacket;
|
||||||
|
import net.minecraft.server.network.ServerStatusPacketListenerImpl;
|
||||||
|
import org.spongepowered.asm.mixin.Final;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.Shadow;
|
||||||
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
|
|
||||||
|
@Mixin(ServerStatusPacketListenerImpl.class)
|
||||||
|
public class ServerStatusPacketListenerMixin {
|
||||||
|
|
||||||
|
@Shadow
|
||||||
|
@Final
|
||||||
|
private ServerStatus status;
|
||||||
|
|
||||||
|
@Shadow @Final private Connection connection;
|
||||||
|
|
||||||
|
@Inject(method = "handleStatusRequest",
|
||||||
|
at = @At(
|
||||||
|
value = "INVOKE",
|
||||||
|
target = "Lnet/minecraft/network/Connection;send(Lnet/minecraft/network/protocol/Packet;)V",
|
||||||
|
shift = At.Shift.BEFORE),
|
||||||
|
cancellable = true
|
||||||
|
)
|
||||||
|
private void injectHandleStatusRequest(ServerboundStatusRequestPacket arg, CallbackInfo ci) {
|
||||||
|
ServerStatusEvent.StatusRequestEvent event = new ServerStatusEvent.StatusRequestEvent(ChatUtils.mojangToAdventure(status.description()));
|
||||||
|
CraterEventBus.INSTANCE.postEvent(event);
|
||||||
|
|
||||||
|
if (event.getNewStatus() != null) {
|
||||||
|
ci.cancel();
|
||||||
|
this.connection.send(new ClientboundStatusResponsePacket(
|
||||||
|
new ServerStatus(ChatUtils.adventureToMojang(
|
||||||
|
event.getNewStatus()),
|
||||||
|
status.players(),
|
||||||
|
status.version(),
|
||||||
|
status.favicon(),
|
||||||
|
status.enforcesSecureChat()
|
||||||
|
)
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -38,7 +38,7 @@ public class CraterFabricNetworkHandler extends PacketRegistry {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ServerPlayNetworking.registerGlobalReceiver(holder.getType(),
|
ServerPlayNetworking.registerGlobalReceiver(holder.getType(),
|
||||||
(ServerPlayNetworking.PlayPayloadHandler<CommonPacketWrapper<T>>) (payload, context) -> context.player().server.execute(() ->
|
(ServerPlayNetworking.PlayPayloadHandler<CommonPacketWrapper<T>>) (payload, context) -> context.player().getServer().execute(() ->
|
||||||
holder.handler().accept(
|
holder.handler().accept(
|
||||||
new PacketContext<>(BridgedPlayer.of(context.player()), payload.packet(), side))));
|
new PacketContext<>(BridgedPlayer.of(context.player()), payload.packet(), side))));
|
||||||
}
|
}
|
||||||
|
@@ -9,7 +9,8 @@
|
|||||||
"TutorialMixin"
|
"TutorialMixin"
|
||||||
],
|
],
|
||||||
"server": [
|
"server": [
|
||||||
"ServerGamePacketListenerImplMixin"
|
"ServerGamePacketListenerImplMixin",
|
||||||
|
"ServerStatusPacketListenerMixin"
|
||||||
],
|
],
|
||||||
"injectors": {
|
"injectors": {
|
||||||
"defaultRequire": 1
|
"defaultRequire": 1
|
||||||
|
@@ -31,9 +31,9 @@
|
|||||||
"${mod_id}.fabric.mixins.json"
|
"${mod_id}.fabric.mixins.json"
|
||||||
],
|
],
|
||||||
"depends": {
|
"depends": {
|
||||||
"fabricloader": ">=0.15.0",
|
"fabricloader": ">=0.16.7",
|
||||||
"fabric-api": "*",
|
"fabric-api": "*",
|
||||||
"minecraft": ">=1.20.6",
|
"minecraft": "*",
|
||||||
"java": ">=21"
|
"java": ">=21"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -3,7 +3,11 @@ archivesBaseName = "${mod_name.replace(" ", "")}-Forge-${minecraft_version}"
|
|||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
// Compat
|
// Compat
|
||||||
modImplementation("maven.modrinth:vanishmod:${vanishmod}")
|
// NOT AVAILABLE ON FORGE modImplementation("maven.modrinth:vanishmod:${vanishmod}")
|
||||||
|
|
||||||
|
modImplementation("me.shedaniel.cloth:cloth-config-forge:${cloth_config}")
|
||||||
|
modImplementation("unimaven.curseforge:playerrevive-266890:${player_revive}")
|
||||||
|
modImplementation("unimaven.curseforge:creativecore-257814:${creative_core}")
|
||||||
|
|
||||||
// Do not edit or remove
|
// Do not edit or remove
|
||||||
implementation project(":Common")
|
implementation project(":Common")
|
||||||
@@ -22,6 +26,7 @@ shadowJar {
|
|||||||
}
|
}
|
||||||
|
|
||||||
setArchiveClassifier('dev-shadow')
|
setArchiveClassifier('dev-shadow')
|
||||||
|
mergeServiceFiles()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -97,16 +102,27 @@ publisher {
|
|||||||
apiKeys {
|
apiKeys {
|
||||||
modrinth(System.getenv("MODRINTH_TOKEN"))
|
modrinth(System.getenv("MODRINTH_TOKEN"))
|
||||||
curseforge(System.getenv("CURSE_TOKEN"))
|
curseforge(System.getenv("CURSE_TOKEN"))
|
||||||
|
nightbloom(System.getenv("PLATFORM_KEY"))
|
||||||
}
|
}
|
||||||
|
|
||||||
setCurseID(curse_id)
|
setCurseID(curse_id)
|
||||||
setModrinthID(modrinth_id)
|
setModrinthID(modrinth_id)
|
||||||
|
setNightbloomID("craterlib")
|
||||||
setVersionType("release")
|
setVersionType("release")
|
||||||
setChangelog("https://raw.githubusercontent.com/hypherionmc/changelogs/main/craterlib/changelog-forge.md")
|
setChangelog(rootProject.file("changelog.md"))
|
||||||
setProjectVersion("${minecraft_version}-${project.version}")
|
setProjectVersion("${minecraft_version}-${project.version}")
|
||||||
setDisplayName("[Forge 1.20.6] CraterLib - ${project.version}")
|
setDisplayName("[Forge 1.20.6] CraterLib - ${project.version}")
|
||||||
setGameVersions("1.20.6")
|
setGameVersions("1.20.6")
|
||||||
setLoaders("forge")
|
setLoaders("forge")
|
||||||
setArtifact(remapJar)
|
setArtifact(remapJar)
|
||||||
setCurseEnvironment("both")
|
setCurseEnvironment("both")
|
||||||
|
setIsManualRelease(true)
|
||||||
|
|
||||||
|
curseDepends {
|
||||||
|
optional("cloth-config")
|
||||||
|
}
|
||||||
|
|
||||||
|
modrinthDepends {
|
||||||
|
optional("cloth-config")
|
||||||
|
}
|
||||||
}
|
}
|
@@ -2,7 +2,6 @@ package com.hypherionmc.craterlib;
|
|||||||
|
|
||||||
import com.hypherionmc.craterlib.api.events.client.LateInitEvent;
|
import com.hypherionmc.craterlib.api.events.client.LateInitEvent;
|
||||||
import com.hypherionmc.craterlib.common.ForgeServerEvents;
|
import com.hypherionmc.craterlib.common.ForgeServerEvents;
|
||||||
import com.hypherionmc.craterlib.compat.Vanish;
|
|
||||||
import com.hypherionmc.craterlib.core.event.CraterEventBus;
|
import com.hypherionmc.craterlib.core.event.CraterEventBus;
|
||||||
import com.hypherionmc.craterlib.core.networking.CraterPacketNetwork;
|
import com.hypherionmc.craterlib.core.networking.CraterPacketNetwork;
|
||||||
import com.hypherionmc.craterlib.core.networking.data.PacketSide;
|
import com.hypherionmc.craterlib.core.networking.data.PacketSide;
|
||||||
@@ -33,9 +32,5 @@ public class CraterLib {
|
|||||||
LateInitEvent event = new LateInitEvent(new BridgedMinecraft(), BridgedOptions.of(Minecraft.getInstance().options));
|
LateInitEvent event = new LateInitEvent(new BridgedMinecraft(), BridgedOptions.of(Minecraft.getInstance().options));
|
||||||
CraterEventBus.INSTANCE.postEvent(event);
|
CraterEventBus.INSTANCE.postEvent(event);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (ModloaderEnvironment.INSTANCE.isModLoaded("vmod")) {
|
|
||||||
MinecraftForge.EVENT_BUS.register(new Vanish());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -15,7 +15,7 @@ public class ForgeClientEvents {
|
|||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public static void clientTick(TickEvent.LevelTickEvent event) {
|
public static void clientTick(TickEvent.LevelTickEvent event) {
|
||||||
if (event.level == null)
|
if (Minecraft.getInstance().level == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
CraterClientTickEvent craterClientTickEvent = new CraterClientTickEvent(BridgedClientLevel.of(Minecraft.getInstance().level));
|
CraterClientTickEvent craterClientTickEvent = new CraterClientTickEvent(BridgedClientLevel.of(Minecraft.getInstance().level));
|
||||||
|
@@ -1,22 +1,55 @@
|
|||||||
package com.hypherionmc.craterlib.common;
|
package com.hypherionmc.craterlib.common;
|
||||||
|
|
||||||
import com.hypherionmc.craterlib.core.platform.CompatUtils;
|
import com.hypherionmc.craterlib.core.platform.CompatUtils;
|
||||||
import com.hypherionmc.craterlib.core.platform.ModloaderEnvironment;
|
|
||||||
import com.hypherionmc.craterlib.nojang.world.entity.player.BridgedPlayer;
|
import com.hypherionmc.craterlib.nojang.world.entity.player.BridgedPlayer;
|
||||||
import redstonedubstep.mods.vanishmod.VanishUtil;
|
import team.creative.playerrevive.api.IBleeding;
|
||||||
|
import team.creative.playerrevive.server.PlayerReviveServer;
|
||||||
|
|
||||||
public class ForgeCompatHelper implements CompatUtils {
|
public class ForgeCompatHelper implements CompatUtils {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isPlayerActive(BridgedPlayer player) {
|
public boolean isPlayerActive(BridgedPlayer player) {
|
||||||
if (!ModloaderEnvironment.INSTANCE.isModLoaded("vmod"))
|
return true;
|
||||||
return true;
|
|
||||||
|
|
||||||
return VanishUtil.isVanished(player.toMojangServerPlayer());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getSkinUUID(BridgedPlayer player) {
|
public String getSkinUUID(BridgedPlayer player) {
|
||||||
return player.getStringUUID();
|
return player.getStringUUID();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isPlayerBleeding(BridgedPlayer player) {
|
||||||
|
if (!ModloaderEnvironment.INSTANCE.isModLoaded("playerrevive"))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return PlayerReviveServer.isBleeding(player.toMojangServerPlayer());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean playerBledOut(BridgedPlayer player) {
|
||||||
|
if (!ModloaderEnvironment.INSTANCE.isModLoaded("playerrevive"))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
IBleeding bleeding = PlayerReviveServer.getBleeding(player.toMojangServerPlayer());
|
||||||
|
return bleeding != null && bleeding.bledOut();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean playerRevived(BridgedPlayer player) {
|
||||||
|
if (!ModloaderEnvironment.INSTANCE.isModLoaded("playerrevive"))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
IBleeding bleeding = PlayerReviveServer.getBleeding(player.toMojangServerPlayer());
|
||||||
|
return bleeding != null && bleeding.revived();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isPrivateMessage(BridgedPlayer player) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Component getChannelPrefix(BridgedPlayer player) {
|
||||||
|
return Component.empty();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
package com.hypherionmc.craterlib.common;
|
package com.hypherionmc.craterlib.common;
|
||||||
|
|
||||||
import com.hypherionmc.craterlib.core.platform.Environment;
|
import com.hypherionmc.craterlib.core.platform.Environment;
|
||||||
|
import com.hypherionmc.craterlib.core.platform.LoaderType;
|
||||||
import com.hypherionmc.craterlib.core.platform.ModloaderEnvironment;
|
import com.hypherionmc.craterlib.core.platform.ModloaderEnvironment;
|
||||||
import net.minecraft.SharedConstants;
|
import net.minecraft.SharedConstants;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
@@ -23,6 +24,11 @@ public class ForgeLoaderHelper implements ModloaderEnvironment {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LoaderType getLoaderType() {
|
||||||
|
return LoaderType.FORGE;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getGameVersion() {
|
public String getGameVersion() {
|
||||||
return SharedConstants.VERSION_STRING;
|
return SharedConstants.VERSION_STRING;
|
||||||
|
@@ -1,24 +0,0 @@
|
|||||||
package com.hypherionmc.craterlib.compat;
|
|
||||||
|
|
||||||
import com.hypherionmc.craterlib.api.events.server.CraterPlayerEvent;
|
|
||||||
import com.hypherionmc.craterlib.core.event.CraterEventBus;
|
|
||||||
import com.hypherionmc.craterlib.nojang.world.entity.player.BridgedPlayer;
|
|
||||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
|
||||||
import redstonedubstep.mods.vanishmod.api.PlayerVanishEvent;
|
|
||||||
|
|
||||||
public class Vanish {
|
|
||||||
|
|
||||||
public Vanish() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@SubscribeEvent
|
|
||||||
public void vanishevent(PlayerVanishEvent event) {
|
|
||||||
if (event.isVanished()) {
|
|
||||||
CraterEventBus.INSTANCE.postEvent(new CraterPlayerEvent.PlayerLoggedOut(BridgedPlayer.of(event.getEntity())));
|
|
||||||
} else {
|
|
||||||
CraterEventBus.INSTANCE.postEvent(new CraterPlayerEvent.PlayerLoggedIn(BridgedPlayer.of(event.getEntity())));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -28,14 +28,14 @@ public class ConfigScreenHandlerMixin {
|
|||||||
*/
|
*/
|
||||||
@Inject(at = @At("RETURN"), method = "getScreenFactoryFor", cancellable = true, remap = false)
|
@Inject(at = @At("RETURN"), method = "getScreenFactoryFor", cancellable = true, remap = false)
|
||||||
private static void injectConfigScreen(IModInfo selectedMod, CallbackInfoReturnable<Optional<BiFunction<Minecraft, Screen, Screen>>> cir) {
|
private static void injectConfigScreen(IModInfo selectedMod, CallbackInfoReturnable<Optional<BiFunction<Minecraft, Screen, Screen>>> cir) {
|
||||||
ConfigController.getMonitoredConfigs().forEach((conf, watcher) -> {
|
ConfigController.getMonitoredConfigs().forEach((conf, config) -> {
|
||||||
if (!conf.getClass().isAnnotationPresent(NoConfigScreen.class)) {
|
if (config.getClass().isAnnotationPresent(NoConfigScreen.class))
|
||||||
ModuleConfig config = (ModuleConfig) conf;
|
return;
|
||||||
if (config.getModId().equals(selectedMod.getModId())) {
|
|
||||||
cir.setReturnValue(
|
if (config.getClass().isAnnotationPresent(ClothScreen.class) && (ModloaderEnvironment.INSTANCE.isModLoaded("cloth_config") || ModloaderEnvironment.INSTANCE.isModLoaded("cloth-config") || ModloaderEnvironment.INSTANCE.isModLoaded("clothconfig"))) {
|
||||||
Optional.of((minecraft, screen) -> new CraterConfigScreen(config, screen))
|
ModList.get().getModContainerById(config.getModId()).ifPresent(c -> c.registerExtensionPoint(IConfigScreenFactory.class, ((minecraft, screen) -> ClothConfigScreenBuilder.buildConfigScreen(config, screen))));
|
||||||
);
|
} else {
|
||||||
}
|
//ModList.get().getModContainerById(config.getModId()).ifPresent(c -> c.registerExtensionPoint(IConfigScreenFactory.class, ((minecraft, screen) -> new CraterConfigScreen(config, screen))));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@@ -27,7 +27,8 @@ public class ServerGamePacketListenerImplMixin {
|
|||||||
cancellable = true
|
cancellable = true
|
||||||
)
|
)
|
||||||
private void injectChatEvent(Component component, PlayerChatMessage arg, FilteredText p_296589_, CallbackInfo ci) {
|
private void injectChatEvent(Component component, PlayerChatMessage arg, FilteredText p_296589_, CallbackInfo ci) {
|
||||||
CraterServerChatEvent event = new CraterServerChatEvent(BridgedPlayer.of(this.player), arg.decoratedContent().getString(), ChatUtils.mojangToAdventure(arg.decoratedContent()));
|
Component finalcomp = component == null ? arg.decoratedContent() : component;
|
||||||
|
CraterServerChatEvent event = new CraterServerChatEvent(BridgedPlayer.of(this.player), finalcomp.getString(), ChatUtils.mojangToAdventure(finalcomp));
|
||||||
CraterEventBus.INSTANCE.postEvent(event);
|
CraterEventBus.INSTANCE.postEvent(event);
|
||||||
if (event.wasCancelled())
|
if (event.wasCancelled())
|
||||||
ci.cancel();
|
ci.cancel();
|
||||||
|
@@ -0,0 +1,53 @@
|
|||||||
|
package com.hypherionmc.craterlib.mixin;
|
||||||
|
|
||||||
|
import com.hypherionmc.craterlib.api.events.server.ServerStatusEvent;
|
||||||
|
import com.hypherionmc.craterlib.core.event.CraterEventBus;
|
||||||
|
import com.hypherionmc.craterlib.utils.ChatUtils;
|
||||||
|
import net.minecraft.network.Connection;
|
||||||
|
import net.minecraft.network.protocol.status.ClientboundStatusResponsePacket;
|
||||||
|
import net.minecraft.network.protocol.status.ServerStatus;
|
||||||
|
import net.minecraft.network.protocol.status.ServerboundStatusRequestPacket;
|
||||||
|
import net.minecraft.server.network.ServerStatusPacketListenerImpl;
|
||||||
|
import org.spongepowered.asm.mixin.Final;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.Shadow;
|
||||||
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
|
|
||||||
|
@Mixin(ServerStatusPacketListenerImpl.class)
|
||||||
|
public class ServerStatusPacketListenerMixin {
|
||||||
|
|
||||||
|
@Shadow
|
||||||
|
@Final
|
||||||
|
private ServerStatus status;
|
||||||
|
|
||||||
|
@Shadow @Final private Connection connection;
|
||||||
|
|
||||||
|
@Inject(method = "handleStatusRequest",
|
||||||
|
at = @At(
|
||||||
|
value = "INVOKE",
|
||||||
|
target = "Lnet/minecraft/network/Connection;send(Lnet/minecraft/network/protocol/Packet;)V",
|
||||||
|
shift = At.Shift.BEFORE),
|
||||||
|
cancellable = true
|
||||||
|
)
|
||||||
|
private void injectHandleStatusRequest(ServerboundStatusRequestPacket arg, CallbackInfo ci) {
|
||||||
|
ServerStatusEvent.StatusRequestEvent event = new ServerStatusEvent.StatusRequestEvent(ChatUtils.mojangToAdventure(status.description()));
|
||||||
|
CraterEventBus.INSTANCE.postEvent(event);
|
||||||
|
|
||||||
|
if (event.getNewStatus() != null) {
|
||||||
|
ci.cancel();
|
||||||
|
this.connection.send(new ClientboundStatusResponsePacket(
|
||||||
|
new ServerStatus(ChatUtils.adventureToMojang(
|
||||||
|
event.getNewStatus()),
|
||||||
|
status.players(),
|
||||||
|
status.version(),
|
||||||
|
status.favicon(),
|
||||||
|
status.enforcesSecureChat(),
|
||||||
|
status.isModded()
|
||||||
|
)
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -9,7 +9,8 @@
|
|||||||
"ConfigScreenHandlerMixin"
|
"ConfigScreenHandlerMixin"
|
||||||
],
|
],
|
||||||
"server": [
|
"server": [
|
||||||
"ServerGamePacketListenerImplMixin"
|
"ServerGamePacketListenerImplMixin",
|
||||||
|
"ServerStatusPacketListenerMixin"
|
||||||
],
|
],
|
||||||
"injectors": {
|
"injectors": {
|
||||||
"defaultRequire": 1
|
"defaultRequire": 1
|
||||||
|
@@ -4,6 +4,13 @@ dependencies {
|
|||||||
// Compat
|
// Compat
|
||||||
modImplementation("maven.modrinth:vanishmod:${vanishmod_neo}")
|
modImplementation("maven.modrinth:vanishmod:${vanishmod_neo}")
|
||||||
|
|
||||||
|
stupidRemapArch("dev.ftb.mods:ftb-essentials-neoforge:${ftb_essentials}")
|
||||||
|
stupidRemapArch("dev.ftb.mods:ftb-ranks-neoforge:${ftb_ranks}")
|
||||||
|
|
||||||
|
modImplementation("me.shedaniel.cloth:cloth-config-neoforge:${cloth_config}")
|
||||||
|
modImplementation("unimaven.curseforge:playerrevive-266890:${player_revive}")
|
||||||
|
modImplementation("unimaven.curseforge:creativecore-257814:${creative_core}")
|
||||||
|
|
||||||
// Do not edit or remove
|
// Do not edit or remove
|
||||||
implementation project(":Common")
|
implementation project(":Common")
|
||||||
}
|
}
|
||||||
@@ -21,6 +28,7 @@ shadowJar {
|
|||||||
}
|
}
|
||||||
|
|
||||||
setArchiveClassifier('dev-shadow')
|
setArchiveClassifier('dev-shadow')
|
||||||
|
mergeServiceFiles()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -31,7 +39,12 @@ shadowJar {
|
|||||||
|
|
||||||
unimined.minecraft {
|
unimined.minecraft {
|
||||||
neoForged {
|
neoForged {
|
||||||
loader neoforge_version
|
if (isPort) {
|
||||||
|
loader "net.neoforged:neoforge:${neoforge_version}:universal"
|
||||||
|
} else {
|
||||||
|
loader neoforge_version
|
||||||
|
}
|
||||||
|
|
||||||
mixinConfig("${mod_id}.mixins.json", "${mod_id}.neoforge.mixins.json")
|
mixinConfig("${mod_id}.mixins.json", "${mod_id}.neoforge.mixins.json")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -96,16 +109,27 @@ publisher {
|
|||||||
apiKeys {
|
apiKeys {
|
||||||
modrinth(System.getenv("MODRINTH_TOKEN"))
|
modrinth(System.getenv("MODRINTH_TOKEN"))
|
||||||
curseforge(System.getenv("CURSE_TOKEN"))
|
curseforge(System.getenv("CURSE_TOKEN"))
|
||||||
|
nightbloom(System.getenv("PLATFORM_KEY"))
|
||||||
}
|
}
|
||||||
|
|
||||||
setCurseID(curse_id)
|
setCurseID(curse_id)
|
||||||
setModrinthID(modrinth_id)
|
setModrinthID(modrinth_id)
|
||||||
|
setNightbloomID("craterlib")
|
||||||
setVersionType("release")
|
setVersionType("release")
|
||||||
setChangelog("https://raw.githubusercontent.com/hypherionmc/changelogs/main/craterlib/changelog-forge.md")
|
setChangelog(rootProject.file("changelog.md"))
|
||||||
setProjectVersion("${minecraft_version}-${project.version}")
|
setProjectVersion("${minecraft_version}-${project.version}")
|
||||||
setDisplayName("[NeoForge 1.20.6] CraterLib - ${project.version}")
|
setDisplayName("[NeoForge 1.21.9] CraterLib - ${project.version}")
|
||||||
setGameVersions("1.20.6")
|
setGameVersions("1.21.9")
|
||||||
setLoaders("neoforge")
|
setLoaders("neoforge")
|
||||||
setArtifact(remapJar)
|
setArtifact(remapJar)
|
||||||
setCurseEnvironment("both")
|
setCurseEnvironment("both")
|
||||||
|
setIsManualRelease(true)
|
||||||
|
|
||||||
|
curseDepends {
|
||||||
|
optional("cloth-config")
|
||||||
|
}
|
||||||
|
|
||||||
|
modrinthDepends {
|
||||||
|
optional("cloth-config")
|
||||||
|
}
|
||||||
}
|
}
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user