Compare commits
7 Commits
Author | SHA1 | Date | |
---|---|---|---|
31ad6dd453 | |||
8ccbb6b9e6 | |||
0ee676e724 | |||
2ab4e67c1d | |||
7504c231ff | |||
556dd63c8f | |||
dfa8a3d55f |
4
.gitignore
vendored
4
.gitignore
vendored
@@ -23,7 +23,3 @@ run
|
|||||||
|
|
||||||
artifacts
|
artifacts
|
||||||
src/test/**
|
src/test/**
|
||||||
|
|
||||||
workspace
|
|
||||||
upstream
|
|
||||||
rejects
|
|
8
.idea/.gitignore
generated
vendored
Normal file
8
.idea/.gitignore
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
# 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
Normal file
7
.idea/discord.xml
generated
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
<?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
Normal file
18
.idea/misc.xml
generated
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
<?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_17" default="true" project-jdk-name="corretto-17" project-jdk-type="JavaSDK">
|
||||||
|
<output url="file://$PROJECT_DIR$/out" />
|
||||||
|
</component>
|
||||||
|
</project>
|
@@ -1,24 +1,15 @@
|
|||||||
def JDK = "21"
|
|
||||||
def majorMc = "1.21.9";
|
|
||||||
|
|
||||||
pipeline {
|
pipeline {
|
||||||
agent {
|
agent {
|
||||||
docker {
|
label "master"
|
||||||
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 ${majorMc} Deploy #${BUILD_NUMBER}",
|
title: "Deploy Started: CraterLib 1.20 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})"
|
||||||
@@ -47,7 +38,7 @@ pipeline {
|
|||||||
deleteDir()
|
deleteDir()
|
||||||
|
|
||||||
discordSend webhookURL: env.FDD_WH_ADMIN,
|
discordSend webhookURL: env.FDD_WH_ADMIN,
|
||||||
title: "CraterLib Port Deploy #${BUILD_NUMBER}",
|
title: "CraterLib 1.20 Deploy #${BUILD_NUMBER}",
|
||||||
link: env.BUILD_URL,
|
link: env.BUILD_URL,
|
||||||
result: currentBuild.currentResult,
|
result: currentBuild.currentResult,
|
||||||
description: "Build: [${BUILD_NUMBER}](${env.BUILD_URL})\nStatus: ${currentBuild.currentResult}"
|
description: "Build: [${BUILD_NUMBER}](${env.BUILD_URL})\nStatus: ${currentBuild.currentResult}"
|
||||||
|
@@ -1,35 +1,19 @@
|
|||||||
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 {
|
||||||
docker {
|
label "master"
|
||||||
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} ${majorMc} Deploy #${BUILD_NUMBER}",
|
title: "Deploy Started: ${projectName} 1.20.1/2 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})"
|
||||||
@@ -39,14 +23,20 @@ pipeline {
|
|||||||
stage("Prepare") {
|
stage("Prepare") {
|
||||||
steps {
|
steps {
|
||||||
sh "chmod +x ./gradlew"
|
sh "chmod +x ./gradlew"
|
||||||
sh "./gradlew build -PreleaseType=${reltype}"
|
sh "./gradlew clean"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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 -PreleaseType=${reltype}"
|
sh "./gradlew publish"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -61,10 +51,10 @@ pipeline {
|
|||||||
projectSlug: "craterlib",
|
projectSlug: "craterlib",
|
||||||
projectName: "${projectName}",
|
projectName: "${projectName}",
|
||||||
projectIcon: "${projectIcon}",
|
projectIcon: "${projectIcon}",
|
||||||
modLoaders: "${modLoaders}",
|
versionName: "Snapshot 1.1.${BUILD_NUMBER}",
|
||||||
minecraftVersions: "${supportedMc}",
|
version: "1.1.${BUILD_NUMBER}",
|
||||||
type: "experimental",
|
modLoaders: "forge|fabric|quilt",
|
||||||
dependsOn: "",
|
minecraftVersions: "1.20|1.20.1",
|
||||||
failWebhook: env.SSS_WEBHOOK,
|
failWebhook: env.SSS_WEBHOOK,
|
||||||
publishWebhooks: "${env.SSS_WEBHOOK}|${env.FDD_WH}"
|
publishWebhooks: "${env.SSS_WEBHOOK}|${env.FDD_WH}"
|
||||||
|
|
||||||
|
@@ -1,22 +1,19 @@
|
|||||||
archivesBaseName = "${mod_name.replace(" ", "")}-Common-${minecraft_version}"
|
archivesBaseName = "${mod_name.replace(" ", "")}-Common-${minecraft_version}"
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
stupidRemapArch("dev.ftb.mods:ftb-essentials:${ftb_essentials}")
|
implementation "com.hypherionmc:rpcsdk:1.0"
|
||||||
stupidRemapArch("dev.ftb.mods:ftb-ranks:${ftb_ranks}")
|
implementation("me.hypherionmc.sdlink:mcdiscordformatter-1.19.1:2.0.0")
|
||||||
|
|
||||||
stupidRemapArch("me.shedaniel.cloth:cloth-config:${cloth_config}")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
shadowJar {
|
shadowJar {
|
||||||
from sourceSets.main.output
|
from sourceSets.main.output
|
||||||
configurations = [project.configurations.shade]
|
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
exclude(dependency('com.google.code.gson:.*'))
|
include(dependency("me.hypherionmc.moon-config:core:${moon_config}"))
|
||||||
|
include(dependency("me.hypherionmc.moon-config:toml:${moon_config}"))
|
||||||
|
include(dependency("me.hypherionmc.sdlink:mcdiscordformatter-1.19.1:2.0.0"))
|
||||||
|
|
||||||
relocate 'me.hypherionmc.moonconfig', 'shadow.hypherionmc.moonconfig'
|
relocate 'me.hypherionmc.moonconfig', 'shadow.hypherionmc.moonconfig'
|
||||||
relocate 'me.hypherionmc.mcdiscordformatter', 'shadow.hypherionmc.mcdiscordformatter'
|
relocate 'me.hypherionmc.mcdiscordformatter', 'shadow.hypherionmc.mcdiscordformatter'
|
||||||
relocate 'net.kyori', 'shadow.kyori'
|
|
||||||
}
|
}
|
||||||
setArchiveClassifier("dev")
|
setArchiveClassifier("dev")
|
||||||
}
|
}
|
||||||
@@ -49,7 +46,9 @@ processResources {
|
|||||||
publishing {
|
publishing {
|
||||||
publications {
|
publications {
|
||||||
mavenCommon(MavenPublication) {
|
mavenCommon(MavenPublication) {
|
||||||
|
groupId project.group
|
||||||
artifactId project.archivesBaseName
|
artifactId project.archivesBaseName
|
||||||
|
version project.version
|
||||||
from components.java
|
from components.java
|
||||||
|
|
||||||
pom.withXml {
|
pom.withXml {
|
||||||
@@ -66,6 +65,12 @@ publishing {
|
|||||||
}
|
}
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
maven rootProject.orion.getPublishingMaven()
|
maven {
|
||||||
|
url "https://maven.firstdark.dev/" + (project.release ? "releases" : "snapshots")
|
||||||
|
credentials {
|
||||||
|
username System.getenv("MAVEN_USER")
|
||||||
|
password System.getenv("MAVEN_PASS")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -1,162 +0,0 @@
|
|||||||
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.commands.BridgedCommandSourceStack;
|
|
||||||
import com.hypherionmc.craterlib.nojang.world.entity.player.BridgedPlayer;
|
|
||||||
import com.hypherionmc.craterlib.utils.TriConsumer;
|
|
||||||
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.world.entity.player.Player;
|
|
||||||
import org.jetbrains.annotations.ApiStatus;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.function.Consumer;
|
|
||||||
|
|
||||||
public class CraterCommand {
|
|
||||||
|
|
||||||
private final LiteralArgumentBuilder<CommandSourceStack> mojangCommand;
|
|
||||||
private int permLevel = 4;
|
|
||||||
private String luckPermNode = "";
|
|
||||||
|
|
||||||
CraterCommand(LiteralArgumentBuilder<CommandSourceStack> cmd) {
|
|
||||||
this.mojangCommand = cmd;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static CraterCommand literal(String commandName) {
|
|
||||||
return new CraterCommand(Commands.literal(commandName));
|
|
||||||
}
|
|
||||||
|
|
||||||
public CraterCommand requiresPermission(int perm) {
|
|
||||||
this.permLevel = perm;
|
|
||||||
this.mojangCommand.requires(this::checkPermission);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public CraterCommand withNode(String key) {
|
|
||||||
this.luckPermNode = key;
|
|
||||||
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) {
|
|
||||||
return this.execute(stack -> {
|
|
||||||
ctx.accept(stack);
|
|
||||||
return 1;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated(forRemoval = true)
|
|
||||||
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,26 @@
|
|||||||
|
package com.hypherionmc.craterlib.api.event.client;
|
||||||
|
|
||||||
|
import com.hypherionmc.craterlib.core.event.CraterEvent;
|
||||||
|
import net.minecraft.client.multiplayer.ClientLevel;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author HypherionSA
|
||||||
|
* Cross Modloader Client Tick Event.
|
||||||
|
*/
|
||||||
|
public class CraterClientTickEvent extends CraterEvent {
|
||||||
|
|
||||||
|
private final ClientLevel level;
|
||||||
|
|
||||||
|
public CraterClientTickEvent(ClientLevel level) {
|
||||||
|
this.level = level;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ClientLevel getLevel() {
|
||||||
|
return level;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canCancel() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,30 @@
|
|||||||
|
package com.hypherionmc.craterlib.api.event.client;
|
||||||
|
|
||||||
|
import com.hypherionmc.craterlib.core.event.CraterEvent;
|
||||||
|
import net.minecraft.world.entity.player.Player;
|
||||||
|
|
||||||
|
public class CraterSinglePlayerEvent extends CraterEvent {
|
||||||
|
|
||||||
|
private final Player player;
|
||||||
|
|
||||||
|
public CraterSinglePlayerEvent(Player player) {
|
||||||
|
this.player = player;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Player getPlayer() {
|
||||||
|
return player;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canCancel() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class PlayerLogin extends CraterSinglePlayerEvent {
|
||||||
|
|
||||||
|
public PlayerLogin(Player player) {
|
||||||
|
super(player);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,29 @@
|
|||||||
|
package com.hypherionmc.craterlib.api.event.client;
|
||||||
|
|
||||||
|
import com.hypherionmc.craterlib.core.event.CraterEvent;
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.client.Options;
|
||||||
|
|
||||||
|
public class LateInitEvent extends CraterEvent {
|
||||||
|
|
||||||
|
private final Minecraft minecraft;
|
||||||
|
private final Options options;
|
||||||
|
|
||||||
|
public LateInitEvent(Minecraft minecraft, Options options) {
|
||||||
|
this.minecraft = minecraft;
|
||||||
|
this.options = options;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Minecraft getMinecraft() {
|
||||||
|
return minecraft;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Options getOptions() {
|
||||||
|
return options;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canCancel() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,22 @@
|
|||||||
|
package com.hypherionmc.craterlib.api.event.client;
|
||||||
|
|
||||||
|
import com.hypherionmc.craterlib.core.event.CraterEvent;
|
||||||
|
import com.mojang.realmsclient.dto.RealmsServer;
|
||||||
|
|
||||||
|
public class PlayerJoinRealmEvent extends CraterEvent {
|
||||||
|
|
||||||
|
private final RealmsServer server;
|
||||||
|
|
||||||
|
public PlayerJoinRealmEvent(RealmsServer server) {
|
||||||
|
this.server = server;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RealmsServer getServer() {
|
||||||
|
return server;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canCancel() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,49 @@
|
|||||||
|
package com.hypherionmc.craterlib.api.event.client;
|
||||||
|
|
||||||
|
import com.hypherionmc.craterlib.core.event.CraterEvent;
|
||||||
|
import net.minecraft.client.gui.screens.Screen;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
public class ScreenEvent extends CraterEvent {
|
||||||
|
|
||||||
|
private final Screen screen;
|
||||||
|
|
||||||
|
protected ScreenEvent(Screen screen) {
|
||||||
|
this.screen = Objects.requireNonNull(screen);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Screen getScreen() {
|
||||||
|
return screen;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canCancel() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Opening extends ScreenEvent {
|
||||||
|
|
||||||
|
private final Screen currentScreen;
|
||||||
|
private Screen newScreen;
|
||||||
|
|
||||||
|
public Opening(Screen currentScreen, Screen newScreen) {
|
||||||
|
super(newScreen);
|
||||||
|
this.currentScreen = currentScreen;
|
||||||
|
this.newScreen = newScreen;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Screen getCurrentScreen() {
|
||||||
|
return currentScreen;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Screen getNewScreen() {
|
||||||
|
return newScreen;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNewScreen(Screen newScreen) {
|
||||||
|
this.newScreen = newScreen;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,29 @@
|
|||||||
|
package com.hypherionmc.craterlib.api.event.common;
|
||||||
|
|
||||||
|
import com.hypherionmc.craterlib.core.event.CraterEvent;
|
||||||
|
import net.minecraft.world.damagesource.DamageSource;
|
||||||
|
import net.minecraft.world.entity.LivingEntity;
|
||||||
|
|
||||||
|
public class CraterLivingDeathEvent extends CraterEvent {
|
||||||
|
|
||||||
|
private final DamageSource damageSource;
|
||||||
|
private final LivingEntity entity;
|
||||||
|
|
||||||
|
public CraterLivingDeathEvent(LivingEntity entity, DamageSource source) {
|
||||||
|
this.entity = entity;
|
||||||
|
this.damageSource = source;
|
||||||
|
}
|
||||||
|
|
||||||
|
public LivingEntity getEntity() {
|
||||||
|
return entity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DamageSource getDamageSource() {
|
||||||
|
return damageSource;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canCancel() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,46 @@
|
|||||||
|
package com.hypherionmc.craterlib.api.event.server;
|
||||||
|
|
||||||
|
import com.hypherionmc.craterlib.core.event.CraterEvent;
|
||||||
|
import net.minecraft.advancements.Advancement;
|
||||||
|
import net.minecraft.advancements.DisplayInfo;
|
||||||
|
import net.minecraft.network.chat.Component;
|
||||||
|
import net.minecraft.world.entity.player.Player;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
public class CraterAdvancementEvent extends CraterEvent {
|
||||||
|
|
||||||
|
private final Advancement advancement;
|
||||||
|
private final Player player;
|
||||||
|
private final Component title;
|
||||||
|
private final Component description;
|
||||||
|
|
||||||
|
public CraterAdvancementEvent(Player player, Advancement advancement) {
|
||||||
|
this.player = player;
|
||||||
|
this.advancement = advancement;
|
||||||
|
|
||||||
|
this.title = advancement.getDisplay().getTitle();
|
||||||
|
this.description = advancement.getDisplay().getDescription();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Advancement getAdvancement() {
|
||||||
|
return advancement;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Component getDescription() {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Component getTitle() {
|
||||||
|
return title;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Player getPlayer() {
|
||||||
|
return player;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canCancel() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,46 @@
|
|||||||
|
package com.hypherionmc.craterlib.api.event.server;
|
||||||
|
|
||||||
|
import com.hypherionmc.craterlib.core.event.CraterEvent;
|
||||||
|
import com.mojang.brigadier.ParseResults;
|
||||||
|
import net.minecraft.commands.CommandSourceStack;
|
||||||
|
|
||||||
|
public class CraterCommandEvent extends CraterEvent {
|
||||||
|
|
||||||
|
private ParseResults<CommandSourceStack> parseResults;
|
||||||
|
private Throwable exception;
|
||||||
|
private String command;
|
||||||
|
|
||||||
|
public CraterCommandEvent(ParseResults<CommandSourceStack> parseResults, String command) {
|
||||||
|
this.parseResults = parseResults;
|
||||||
|
this.command = command;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ParseResults<CommandSourceStack> getParseResults() {
|
||||||
|
return parseResults;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setParseResults(ParseResults<CommandSourceStack> parseResults) {
|
||||||
|
this.parseResults = parseResults;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Throwable getException() {
|
||||||
|
return exception;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setException(Throwable exception) {
|
||||||
|
this.exception = exception;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCommand() {
|
||||||
|
return command;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCommand(String command) {
|
||||||
|
this.command = command;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canCancel() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,38 @@
|
|||||||
|
package com.hypherionmc.craterlib.api.event.server;
|
||||||
|
|
||||||
|
import com.hypherionmc.craterlib.core.event.CraterEvent;
|
||||||
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
|
|
||||||
|
public class CraterPlayerEvent extends CraterEvent {
|
||||||
|
|
||||||
|
private final ServerPlayer player;
|
||||||
|
|
||||||
|
public CraterPlayerEvent(ServerPlayer player) {
|
||||||
|
this.player = player;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ServerPlayer getPlayer() {
|
||||||
|
return player;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canCancel() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class PlayerLoggedIn extends CraterPlayerEvent {
|
||||||
|
|
||||||
|
public PlayerLoggedIn(ServerPlayer player) {
|
||||||
|
super(player);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class PlayerLoggedOut extends CraterPlayerEvent {
|
||||||
|
|
||||||
|
public PlayerLoggedOut(ServerPlayer player) {
|
||||||
|
super(player);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,23 @@
|
|||||||
|
package com.hypherionmc.craterlib.api.event.server;
|
||||||
|
|
||||||
|
import com.hypherionmc.craterlib.core.event.CraterEvent;
|
||||||
|
import com.mojang.brigadier.CommandDispatcher;
|
||||||
|
import net.minecraft.commands.CommandSourceStack;
|
||||||
|
|
||||||
|
public class CraterRegisterCommandEvent extends CraterEvent {
|
||||||
|
|
||||||
|
private final CommandDispatcher<CommandSourceStack> dispatcher;
|
||||||
|
|
||||||
|
public CraterRegisterCommandEvent(CommandDispatcher<CommandSourceStack> dispatcher) {
|
||||||
|
this.dispatcher = dispatcher;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CommandDispatcher<CommandSourceStack> getDispatcher() {
|
||||||
|
return dispatcher;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canCancel() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,44 @@
|
|||||||
|
package com.hypherionmc.craterlib.api.event.server;
|
||||||
|
|
||||||
|
import com.hypherionmc.craterlib.core.event.CraterEvent;
|
||||||
|
import net.minecraft.network.chat.Component;
|
||||||
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
|
|
||||||
|
public class CraterServerChatEvent extends CraterEvent {
|
||||||
|
|
||||||
|
private final String message, username;
|
||||||
|
private final ServerPlayer player;
|
||||||
|
private Component component;
|
||||||
|
|
||||||
|
public CraterServerChatEvent(ServerPlayer player, String message, Component component) {
|
||||||
|
this.message = message;
|
||||||
|
this.player = player;
|
||||||
|
this.username = player.getGameProfile().getName();
|
||||||
|
this.component = component;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Component getComponent() {
|
||||||
|
return component;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setComponent(Component component) {
|
||||||
|
this.component = component;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUsername() {
|
||||||
|
return username;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ServerPlayer getPlayer() {
|
||||||
|
return player;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMessage() {
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canCancel() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,49 @@
|
|||||||
|
package com.hypherionmc.craterlib.api.event.server;
|
||||||
|
|
||||||
|
import com.hypherionmc.craterlib.core.event.CraterEvent;
|
||||||
|
import net.minecraft.server.MinecraftServer;
|
||||||
|
|
||||||
|
public class CraterServerLifecycleEvent extends CraterEvent {
|
||||||
|
|
||||||
|
public CraterServerLifecycleEvent() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canCancel() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Starting extends CraterServerLifecycleEvent {
|
||||||
|
|
||||||
|
private final MinecraftServer server;
|
||||||
|
|
||||||
|
public Starting(MinecraftServer server) {
|
||||||
|
this.server = server;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MinecraftServer getServer() {
|
||||||
|
return server;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Started extends CraterServerLifecycleEvent {
|
||||||
|
|
||||||
|
public Started() {
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Stopping extends CraterServerLifecycleEvent {
|
||||||
|
|
||||||
|
public Stopping() {
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Stopped extends CraterServerLifecycleEvent {
|
||||||
|
|
||||||
|
public Stopped() {
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,43 @@
|
|||||||
|
package com.hypherionmc.craterlib.api.event.server;
|
||||||
|
|
||||||
|
import com.hypherionmc.craterlib.core.event.CraterEvent;
|
||||||
|
import net.minecraft.network.chat.Component;
|
||||||
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
|
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
|
public class MessageBroadcastEvent extends CraterEvent {
|
||||||
|
|
||||||
|
private final Component component;
|
||||||
|
private final Function<ServerPlayer, Component> function;
|
||||||
|
private final boolean bl;
|
||||||
|
private final String threadName;
|
||||||
|
|
||||||
|
public MessageBroadcastEvent(Component component, Function<ServerPlayer, Component> function, boolean bl, String threadName) {
|
||||||
|
this.component = component;
|
||||||
|
this.function = function;
|
||||||
|
this.bl = bl;
|
||||||
|
this.threadName = threadName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Component getComponent() {
|
||||||
|
return component;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isBl() {
|
||||||
|
return bl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Function<ServerPlayer, Component> getFunction() {
|
||||||
|
return function;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getThreadName() {
|
||||||
|
return threadName;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canCancel() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,40 @@
|
|||||||
|
package com.hypherionmc.craterlib.api.event.server;
|
||||||
|
|
||||||
|
import com.hypherionmc.craterlib.core.event.CraterEvent;
|
||||||
|
import com.mojang.authlib.GameProfile;
|
||||||
|
import net.minecraft.network.chat.Component;
|
||||||
|
|
||||||
|
import java.net.SocketAddress;
|
||||||
|
|
||||||
|
public class PlayerPreLoginEvent extends CraterEvent {
|
||||||
|
|
||||||
|
private final SocketAddress address;
|
||||||
|
private final GameProfile gameProfile;
|
||||||
|
private Component message;
|
||||||
|
|
||||||
|
public PlayerPreLoginEvent(SocketAddress address, GameProfile profile) {
|
||||||
|
this.address = address;
|
||||||
|
this.gameProfile = profile;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Component getMessage() {
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMessage(Component message) {
|
||||||
|
this.message = message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GameProfile getGameProfile() {
|
||||||
|
return gameProfile;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SocketAddress getAddress() {
|
||||||
|
return address;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canCancel() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
@@ -1,14 +0,0 @@
|
|||||||
package com.hypherionmc.craterlib.api.events.client;
|
|
||||||
|
|
||||||
import com.hypherionmc.craterlib.core.event.CraterEvent;
|
|
||||||
import com.hypherionmc.craterlib.nojang.client.multiplayer.BridgedClientLevel;
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
@Getter
|
|
||||||
public class CraterClientTickEvent extends CraterEvent {
|
|
||||||
|
|
||||||
private final BridgedClientLevel level;
|
|
||||||
|
|
||||||
}
|
|
@@ -1,21 +0,0 @@
|
|||||||
package com.hypherionmc.craterlib.api.events.client;
|
|
||||||
|
|
||||||
import com.hypherionmc.craterlib.core.event.CraterEvent;
|
|
||||||
import com.hypherionmc.craterlib.nojang.world.entity.player.BridgedPlayer;
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
@Getter
|
|
||||||
public class CraterSinglePlayerEvent extends CraterEvent {
|
|
||||||
|
|
||||||
private final BridgedPlayer player;
|
|
||||||
|
|
||||||
public static class PlayerLogin extends CraterSinglePlayerEvent {
|
|
||||||
|
|
||||||
public PlayerLogin(BridgedPlayer player) {
|
|
||||||
super(player);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,16 +0,0 @@
|
|||||||
package com.hypherionmc.craterlib.api.events.client;
|
|
||||||
|
|
||||||
import com.hypherionmc.craterlib.core.event.CraterEvent;
|
|
||||||
import com.hypherionmc.craterlib.nojang.client.BridgedMinecraft;
|
|
||||||
import com.hypherionmc.craterlib.nojang.client.BridgedOptions;
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
@Getter
|
|
||||||
public class LateInitEvent extends CraterEvent {
|
|
||||||
|
|
||||||
private final BridgedMinecraft minecraft;
|
|
||||||
private final BridgedOptions options;
|
|
||||||
|
|
||||||
}
|
|
@@ -1,14 +0,0 @@
|
|||||||
package com.hypherionmc.craterlib.api.events.client;
|
|
||||||
|
|
||||||
import com.hypherionmc.craterlib.core.event.CraterEvent;
|
|
||||||
import com.hypherionmc.craterlib.nojang.realmsclient.dto.BridgedRealmsServer;
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
@Getter
|
|
||||||
public class PlayerJoinRealmEvent extends CraterEvent {
|
|
||||||
|
|
||||||
private final BridgedRealmsServer server;
|
|
||||||
|
|
||||||
}
|
|
@@ -1,27 +0,0 @@
|
|||||||
package com.hypherionmc.craterlib.api.events.client;
|
|
||||||
|
|
||||||
import com.hypherionmc.craterlib.core.event.CraterEvent;
|
|
||||||
import com.hypherionmc.craterlib.nojang.client.gui.BridgedScreen;
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import lombok.Setter;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
public class ScreenEvent extends CraterEvent {
|
|
||||||
|
|
||||||
private final BridgedScreen screen;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
public static class Opening extends ScreenEvent {
|
|
||||||
|
|
||||||
private final BridgedScreen currentScreen;
|
|
||||||
@Setter private BridgedScreen newScreen;
|
|
||||||
|
|
||||||
public Opening(BridgedScreen currentScreen, BridgedScreen newScreen) {
|
|
||||||
super(newScreen);
|
|
||||||
this.currentScreen = currentScreen;
|
|
||||||
this.newScreen = newScreen;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,21 +0,0 @@
|
|||||||
package com.hypherionmc.craterlib.api.events.common;
|
|
||||||
|
|
||||||
import com.hypherionmc.craterlib.core.event.CraterEvent;
|
|
||||||
import com.hypherionmc.craterlib.nojang.world.entity.player.BridgedPlayer;
|
|
||||||
import com.hypherionmc.craterlib.utils.ChatUtils;
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import net.kyori.adventure.text.Component;
|
|
||||||
import net.minecraft.world.damagesource.DamageSource;
|
|
||||||
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
@Getter
|
|
||||||
public class CraterPlayerDeathEvent extends CraterEvent {
|
|
||||||
|
|
||||||
private final BridgedPlayer player;
|
|
||||||
private final DamageSource damageSource;
|
|
||||||
|
|
||||||
public Component getDeathMessage() {
|
|
||||||
return ChatUtils.mojangToAdventure(damageSource.getLocalizedDeathMessage(player.toMojang()));
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,56 +0,0 @@
|
|||||||
// @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));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,35 +0,0 @@
|
|||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,12 +0,0 @@
|
|||||||
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;
|
|
||||||
}
|
|
@@ -1,12 +0,0 @@
|
|||||||
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;
|
|
||||||
}
|
|
@@ -1,34 +0,0 @@
|
|||||||
package com.hypherionmc.craterlib.api.events.server;
|
|
||||||
|
|
||||||
import com.hypherionmc.craterlib.core.event.CraterEvent;
|
|
||||||
import com.hypherionmc.craterlib.nojang.advancements.BridgedAdvancement;
|
|
||||||
import com.hypherionmc.craterlib.nojang.advancements.BridgedDisplayInfo;
|
|
||||||
import com.hypherionmc.craterlib.nojang.world.entity.player.BridgedPlayer;
|
|
||||||
import lombok.Getter;
|
|
||||||
import net.kyori.adventure.text.Component;
|
|
||||||
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
public class CraterAdvancementEvent extends CraterEvent {
|
|
||||||
|
|
||||||
private final BridgedAdvancement advancement;
|
|
||||||
private final BridgedPlayer player;
|
|
||||||
private final Component title;
|
|
||||||
private final Component description;
|
|
||||||
|
|
||||||
public CraterAdvancementEvent(BridgedPlayer player, BridgedAdvancement advancement) {
|
|
||||||
this.advancement = advancement;
|
|
||||||
this.player = player;
|
|
||||||
|
|
||||||
Optional<BridgedDisplayInfo> displayInfo = advancement.displayInfo();
|
|
||||||
|
|
||||||
if (displayInfo.isPresent()) {
|
|
||||||
this.title = displayInfo.get().displayName();
|
|
||||||
this.description = displayInfo.get().description();
|
|
||||||
} else {
|
|
||||||
this.title = Component.text("Unknown");
|
|
||||||
this.description = Component.text("Unknown");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,58 +0,0 @@
|
|||||||
package com.hypherionmc.craterlib.api.events.server;
|
|
||||||
|
|
||||||
import com.hypherionmc.craterlib.core.event.CraterEvent;
|
|
||||||
import com.hypherionmc.craterlib.nojang.world.entity.player.BridgedPlayer;
|
|
||||||
import com.hypherionmc.craterlib.utils.ChatUtils;
|
|
||||||
import com.mojang.brigadier.ParseResults;
|
|
||||||
import com.mojang.brigadier.context.CommandContext;
|
|
||||||
import com.mojang.brigadier.context.StringRange;
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.Setter;
|
|
||||||
import net.kyori.adventure.text.Component;
|
|
||||||
import net.minecraft.commands.CommandSourceStack;
|
|
||||||
import net.minecraft.commands.arguments.ComponentArgument;
|
|
||||||
import net.minecraft.world.entity.player.Player;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
public class CraterCommandEvent extends CraterEvent {
|
|
||||||
|
|
||||||
private final ParseResults<CommandSourceStack> parseResults;
|
|
||||||
@Setter private Throwable exception;
|
|
||||||
private final String command;
|
|
||||||
|
|
||||||
private CraterCommandEvent(ParseResults<CommandSourceStack> parseResults, String command) {
|
|
||||||
this.parseResults = parseResults;
|
|
||||||
this.command = command;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static CraterCommandEvent of(ParseResults<CommandSourceStack> stack, String command) {
|
|
||||||
return new CraterCommandEvent(stack, command);
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getCommandString() {
|
|
||||||
return parseResults.getReader().getString();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
public BridgedPlayer getPlayer() {
|
|
||||||
try {
|
|
||||||
Player p = parseResults.getContext().getLastChild().getSource().getPlayer();
|
|
||||||
|
|
||||||
if (p != null)
|
|
||||||
return BridgedPlayer.of(p);
|
|
||||||
} catch (Exception ignored) {}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getTarget() {
|
|
||||||
CommandContext<CommandSourceStack> context = parseResults.getContext().build(parseResults.getReader().getString());
|
|
||||||
StringRange selector_range = parseResults.getContext().getArguments().get("targets").getRange();
|
|
||||||
return context.getInput().substring(selector_range.getStart(), selector_range.getEnd());
|
|
||||||
}
|
|
||||||
|
|
||||||
public Component getMessage() {
|
|
||||||
return ChatUtils.mojangToAdventure(ComponentArgument.getRawComponent(parseResults.getContext().build(parseResults.getReader().getString()), "message"));
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,44 +0,0 @@
|
|||||||
package com.hypherionmc.craterlib.api.events.server;
|
|
||||||
|
|
||||||
import com.hypherionmc.craterlib.core.event.CraterEvent;
|
|
||||||
import com.hypherionmc.craterlib.nojang.world.entity.player.BridgedPlayer;
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
@Getter
|
|
||||||
public class CraterPlayerEvent extends CraterEvent {
|
|
||||||
|
|
||||||
private final BridgedPlayer player;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
public static class PlayerLoggedIn extends CraterPlayerEvent {
|
|
||||||
private final boolean isFromVanish;
|
|
||||||
|
|
||||||
public PlayerLoggedIn(BridgedPlayer player) {
|
|
||||||
this(player, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public PlayerLoggedIn(BridgedPlayer player, boolean isFromVanish) {
|
|
||||||
super(player);
|
|
||||||
this.isFromVanish = isFromVanish;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
public static class PlayerLoggedOut extends CraterPlayerEvent {
|
|
||||||
private final boolean isFromVanish;
|
|
||||||
|
|
||||||
public PlayerLoggedOut(BridgedPlayer player) {
|
|
||||||
this(player, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public PlayerLoggedOut(BridgedPlayer player, boolean isFromVanish) {
|
|
||||||
super(player);
|
|
||||||
this.isFromVanish = isFromVanish;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,18 +0,0 @@
|
|||||||
package com.hypherionmc.craterlib.api.events.server;
|
|
||||||
|
|
||||||
import com.hypherionmc.craterlib.api.commands.CraterCommand;
|
|
||||||
import com.hypherionmc.craterlib.core.event.CraterEvent;
|
|
||||||
import com.mojang.brigadier.CommandDispatcher;
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import net.minecraft.commands.CommandSourceStack;
|
|
||||||
|
|
||||||
@AllArgsConstructor
|
|
||||||
public class CraterRegisterCommandEvent extends CraterEvent {
|
|
||||||
|
|
||||||
private final CommandDispatcher<CommandSourceStack> stack;
|
|
||||||
|
|
||||||
public void registerCommand(CraterCommand cmd) {
|
|
||||||
cmd.register(stack);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,25 +0,0 @@
|
|||||||
package com.hypherionmc.craterlib.api.events.server;
|
|
||||||
|
|
||||||
import com.hypherionmc.craterlib.core.event.CraterEvent;
|
|
||||||
import com.hypherionmc.craterlib.core.event.annot.Cancellable;
|
|
||||||
import com.hypherionmc.craterlib.nojang.world.entity.player.BridgedPlayer;
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.Setter;
|
|
||||||
import net.kyori.adventure.text.Component;
|
|
||||||
|
|
||||||
@Cancellable
|
|
||||||
@Getter
|
|
||||||
public class CraterServerChatEvent extends CraterEvent {
|
|
||||||
|
|
||||||
public final String message, username;
|
|
||||||
public final BridgedPlayer player;
|
|
||||||
@Setter private Component component;
|
|
||||||
|
|
||||||
public CraterServerChatEvent(BridgedPlayer player, String message, Component component) {
|
|
||||||
this.message = message;
|
|
||||||
this.player = player;
|
|
||||||
this.username = player.getGameProfile().getName();
|
|
||||||
this.component = component;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,34 +0,0 @@
|
|||||||
package com.hypherionmc.craterlib.api.events.server;
|
|
||||||
|
|
||||||
import com.hypherionmc.craterlib.core.event.CraterEvent;
|
|
||||||
import com.hypherionmc.craterlib.nojang.server.BridgedMinecraftServer;
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
|
|
||||||
public class CraterServerLifecycleEvent extends CraterEvent {
|
|
||||||
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
@Getter
|
|
||||||
public static class Starting extends CraterServerLifecycleEvent {
|
|
||||||
private final BridgedMinecraftServer server;
|
|
||||||
}
|
|
||||||
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
@Getter
|
|
||||||
public static class Started extends CraterServerLifecycleEvent {
|
|
||||||
private final BridgedMinecraftServer server;
|
|
||||||
}
|
|
||||||
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
@Getter
|
|
||||||
public static class Stopping extends CraterServerLifecycleEvent {
|
|
||||||
private final BridgedMinecraftServer server;
|
|
||||||
}
|
|
||||||
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
@Getter
|
|
||||||
public static class Stopped extends CraterServerLifecycleEvent {
|
|
||||||
private final BridgedMinecraftServer server;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,20 +0,0 @@
|
|||||||
package com.hypherionmc.craterlib.api.events.server;
|
|
||||||
|
|
||||||
import com.hypherionmc.craterlib.core.event.CraterEvent;
|
|
||||||
import com.hypherionmc.craterlib.nojang.world.entity.player.BridgedPlayer;
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import net.kyori.adventure.text.Component;
|
|
||||||
|
|
||||||
import java.util.function.Function;
|
|
||||||
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
@Getter
|
|
||||||
public class MessageBroadcastEvent extends CraterEvent {
|
|
||||||
|
|
||||||
private final Component component;
|
|
||||||
private final Function<BridgedPlayer, Component> function;
|
|
||||||
private final boolean bl;
|
|
||||||
private final String threadName;
|
|
||||||
|
|
||||||
}
|
|
@@ -1,20 +0,0 @@
|
|||||||
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;
|
|
||||||
import lombok.Setter;
|
|
||||||
import net.kyori.adventure.text.Component;
|
|
||||||
|
|
||||||
import java.net.SocketAddress;
|
|
||||||
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
@Getter
|
|
||||||
public class PlayerPreLoginEvent extends CraterEvent {
|
|
||||||
|
|
||||||
private final SocketAddress address;
|
|
||||||
private final BridgedGameProfile gameProfile;
|
|
||||||
@Setter private Component message;
|
|
||||||
|
|
||||||
}
|
|
@@ -1,35 +0,0 @@
|
|||||||
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();
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,26 +0,0 @@
|
|||||||
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;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,18 +0,0 @@
|
|||||||
package com.hypherionmc.craterlib.api.networking;
|
|
||||||
|
|
||||||
import com.hypherionmc.craterlib.core.networking.data.PacketHolder;
|
|
||||||
import com.hypherionmc.craterlib.nojang.network.BridgedFriendlyByteBuf;
|
|
||||||
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
|
|
||||||
|
|
||||||
public record CommonPacketWrapper<T>(PacketHolder<T> container, T packet) implements CustomPacketPayload {
|
|
||||||
public void encode(BridgedFriendlyByteBuf buf)
|
|
||||||
{
|
|
||||||
container().encoder().accept(packet(), buf);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Type<? extends CustomPacketPayload> type()
|
|
||||||
{
|
|
||||||
return container.type();
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,7 +1,7 @@
|
|||||||
package com.hypherionmc.craterlib.api.networking;
|
package com.hypherionmc.craterlib.api.networking;
|
||||||
|
|
||||||
import com.hypherionmc.craterlib.nojang.server.BridgedMinecraftServer;
|
import net.minecraft.server.MinecraftServer;
|
||||||
import com.hypherionmc.craterlib.nojang.world.entity.player.BridgedPlayer;
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -14,15 +14,15 @@ public interface CraterNetworkHandler {
|
|||||||
|
|
||||||
<T> void sendToServer(T packet, boolean ignoreCheck);
|
<T> void sendToServer(T packet, boolean ignoreCheck);
|
||||||
|
|
||||||
<T> void sendToClient(T packet, BridgedPlayer player);
|
<T> void sendToClient(T packet, ServerPlayer player);
|
||||||
|
|
||||||
default <T> void sendToClients(T packet, List<BridgedPlayer> players) {
|
default <T> void sendToClients(T packet, List<ServerPlayer> players) {
|
||||||
for (BridgedPlayer player : players) {
|
for (ServerPlayer player : players) {
|
||||||
sendToClient(packet, player);
|
sendToClient(packet, player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
default <T> void sendToAllClients(T packet, BridgedMinecraftServer server) {
|
default <T> void sendToAllClients(T packet, MinecraftServer server) {
|
||||||
sendToClients(packet, server.getPlayers());
|
sendToClients(packet, server.getPlayerList().getPlayers());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,409 +0,0 @@
|
|||||||
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.AbstractConfig;
|
import com.hypherionmc.craterlib.core.config.ModuleConfig;
|
||||||
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,8 +37,6 @@ 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;
|
||||||
@@ -46,11 +44,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 AbstractConfig config;
|
private final ModuleConfig config;
|
||||||
public double scrollerAmount;
|
public double scrollerAmount;
|
||||||
private boolean dragging;
|
private boolean dragging;
|
||||||
|
|
||||||
public CraterConfigScreen(AbstractConfig config, Screen parent, Object subConfig) {
|
public CraterConfigScreen(ModuleConfig 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;
|
||||||
@@ -61,7 +59,7 @@ public class CraterConfigScreen extends Screen {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public CraterConfigScreen(AbstractConfig config, Screen parent) {
|
public CraterConfigScreen(ModuleConfig config, Screen parent) {
|
||||||
this(config, parent, null);
|
this(config, parent, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -160,7 +158,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::parse);
|
return new TextConfigOption<>(Objects::toString, ResourceLocation::new);
|
||||||
}
|
}
|
||||||
if (isSubConfig) {
|
if (isSubConfig) {
|
||||||
return new SubConfigWidget<>(config, this, value);
|
return new SubConfigWidget<>(config, this, value);
|
||||||
@@ -180,7 +178,8 @@ 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();
|
||||||
@@ -189,9 +188,8 @@ public class CraterConfigScreen extends Screen {
|
|||||||
overlayBackground(matrices.pose(), height - BOTTOM, height, 64);
|
overlayBackground(matrices.pose(), height - BOTTOM, height, 64);
|
||||||
renderShadow(matrices.pose());
|
renderShadow(matrices.pose());
|
||||||
matrices.drawCenteredString(font, getTitle(), width / 2, 9, 0xFFFFFF);
|
matrices.drawCenteredString(font, getTitle(), width / 2, 9, 0xFFFFFF);
|
||||||
matrices.pose().popPose();
|
|
||||||
|
|
||||||
super.render(matrices, mouseX, mouseY, delta);
|
super.render(matrices, mouseX, mouseY, delta);
|
||||||
|
matrices.pose().popPose();
|
||||||
|
|
||||||
int y = (int) (TOP + 4 - Math.round(scrollerAmount));
|
int y = (int) (TOP + 4 - Math.round(scrollerAmount));
|
||||||
for (Option<?> option : options) {
|
for (Option<?> option : options) {
|
||||||
@@ -199,7 +197,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() {
|
||||||
@@ -218,47 +216,49 @@ 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.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR);
|
BufferBuilder buffer = tesselator.getBuilder();
|
||||||
//RenderSystem.setShader(RenderSystem.getShader());
|
RenderSystem.setShader(GameRenderer::getPositionColorShader);
|
||||||
|
buffer.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR);
|
||||||
|
|
||||||
buffer.addVertex(scrollbarPositionMinX, maxY, 0.0f).setColor(0, 0, 0, 255);
|
buffer.vertex(scrollbarPositionMinX, maxY, 0.0D).color(0, 0, 0, 255).endVertex();
|
||||||
buffer.addVertex(scrollbarPositionMaxX, maxY, 0.0f).setColor(0, 0, 0, 255);
|
buffer.vertex(scrollbarPositionMaxX, maxY, 0.0D).color(0, 0, 0, 255).endVertex();
|
||||||
buffer.addVertex(scrollbarPositionMaxX, TOP, 0.0f).setColor(0, 0, 0, 255);
|
buffer.vertex(scrollbarPositionMaxX, TOP, 0.0D).color(0, 0, 0, 255).endVertex();
|
||||||
buffer.addVertex(scrollbarPositionMinX, TOP, 0.0f).setColor(0, 0, 0, 255);
|
buffer.vertex(scrollbarPositionMinX, TOP, 0.0D).color(0, 0, 0, 255).endVertex();
|
||||||
|
|
||||||
buffer.addVertex(scrollbarPositionMinX, minY + height, 0.0f).setColor(SCROLLBAR_BOTTOM_COLOR, SCROLLBAR_BOTTOM_COLOR, SCROLLBAR_BOTTOM_COLOR, 1);
|
buffer.vertex(scrollbarPositionMinX, 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 + height, 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(scrollbarPositionMaxX, 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, 0.0D).color(SCROLLBAR_BOTTOM_COLOR, SCROLLBAR_BOTTOM_COLOR, SCROLLBAR_BOTTOM_COLOR, 1).endVertex();
|
||||||
buffer.addVertex(scrollbarPositionMinX, (minY + height - 1), 0.0f).setColor(SCROLLBAR_TOP_COLOR, SCROLLBAR_TOP_COLOR, SCROLLBAR_TOP_COLOR, 1);
|
buffer.vertex(scrollbarPositionMinX, (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 + height - 1), 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((scrollbarPositionMaxX - 1), 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);
|
buffer.vertex(scrollbarPositionMinX, minY, 0.0D).color(SCROLLBAR_TOP_COLOR, SCROLLBAR_TOP_COLOR, SCROLLBAR_TOP_COLOR, 1).endVertex();
|
||||||
//BufferUploader.drawWithShader(buffer.buildOrThrow());
|
tesselator.end();
|
||||||
//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.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX_COLOR);
|
BufferBuilder buffer = tesselator.getBuilder();
|
||||||
//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.addVertex(matrix, 0, TOP + 4, 0.0F).setUv(0, 1).setColor(0, 0, 0, 0);
|
buffer.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX_COLOR);
|
||||||
buffer.addVertex(matrix, width, TOP + 4, 0.0F).setUv(1, 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, 0.0F).setUv(1, 0).setColor(0, 0, 0, 185);
|
buffer.vertex(matrix, width, TOP + 4, 0.0F).uv(1, 1).color(0, 0, 0, 0).endVertex();
|
||||||
buffer.addVertex(matrix, 0, TOP, 0.0F).setUv(0, 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, height - BOTTOM, 0.0F).setUv(0, 1).setColor(0, 0, 0, 185);
|
buffer.vertex(matrix, 0, TOP, 0.0F).uv(0, 0).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, 0, height - BOTTOM, 0.0F).uv(0, 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, 0.0F).uv(1, 1).color(0, 0, 0, 185).endVertex();
|
||||||
buffer.addVertex(matrix, 0, height - BOTTOM - 4, 0.0F).setUv(0, 0).setColor(0, 0, 0, 0);
|
buffer.vertex(matrix, width, height - BOTTOM - 4, 0.0F).uv(1, 0).color(0, 0, 0, 0).endVertex();
|
||||||
//BufferUploader.drawWithShader(buffer.buildOrThrow());
|
buffer.vertex(matrix, 0, height - BOTTOM - 4, 0.0F).uv(0, 0).color(0, 0, 0, 0).endVertex();
|
||||||
|
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) {
|
||||||
@@ -266,16 +266,18 @@ 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.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX_COLOR);
|
BufferBuilder buffer = tesselator.getBuilder();
|
||||||
//RenderSystem.setShader(GameRenderer::getPositionTexColorShader);
|
RenderSystem.setShaderTexture(0, Screen.BACKGROUND_LOCATION);
|
||||||
//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);
|
RenderSystem.setShader(GameRenderer::getPositionTexColorShader);
|
||||||
buffer.addVertex(matrix, minX, maxY, 0.0F).setUv(minX / 32.0F, maxY / 32.0F).setColor(red, green, blue, endAlpha);
|
buffer.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX_COLOR);
|
||||||
buffer.addVertex(matrix, maxX, maxY, 0.0F).setUv(maxX / 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, minY, 0.0F).setUv(maxX / 32.0F, minY / 32.0F).setColor(red, green, blue, startAlpha);
|
buffer.vertex(matrix, maxX, maxY, 0.0F).uv(maxX / 32.0F, maxY / 32.0F).color(red, green, blue, endAlpha).endVertex();
|
||||||
buffer.addVertex(matrix, minX, minY, 0.0F).setUv(minX / 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();
|
||||||
//BufferUploader.drawWithShader(buffer.buildOrThrow());
|
buffer.vertex(matrix, minX, minY, 0.0F).uv(minX / 32.0F, minY / 32.0F).color(red, green, blue, startAlpha).endVertex();
|
||||||
|
tesselator.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int scrollHeight() {
|
public int scrollHeight() {
|
||||||
@@ -333,18 +335,18 @@ public class CraterConfigScreen extends Screen {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean mouseScrolled(double d, double e, double f, double g) {
|
public boolean mouseScrolled(double d, double e, double f) {
|
||||||
if (e >= TOP && e <= height - BOTTOM) {
|
if (e >= TOP && e <= height - BOTTOM) {
|
||||||
scrollerAmount = Mth.clamp(scrollerAmount - f * 16.0D, 0, scrollHeight());
|
scrollerAmount = Mth.clamp(scrollerAmount - f * 16.0D, 0, scrollHeight());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return super.mouseScrolled(d, e, f, g);
|
return super.mouseScrolled(d, e, f);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean mouseClicked(double d, double e, int i, boolean bl) {
|
public boolean mouseClicked(double d, double e, int i) {
|
||||||
this.dragging = i == 0 && d >= width - 6 && d < width;
|
this.dragging = i == 0 && d >= width - 6 && d < width;
|
||||||
return super.mouseClicked(d, e, i, bl);
|
return super.mouseClicked(d, e, i) || dragging;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -385,7 +387,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,7 +10,6 @@ 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,7 +13,6 @@ 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;
|
||||||
@@ -51,7 +50,7 @@ public class BaseWidget<T> extends Option<T> {
|
|||||||
} else {
|
} else {
|
||||||
text.withStyle(ChatFormatting.GRAY);
|
text.withStyle(ChatFormatting.GRAY);
|
||||||
}
|
}
|
||||||
matrices.drawString(font, text, x, y + font.lineHeight - 2, 0xFFFFFF);
|
matrices.drawString(font, text, x, y, 0xFFFFFF);
|
||||||
resetButton.setX(x + width - 46);
|
resetButton.setX(x + width - 46);
|
||||||
resetButton.setY(y + 1);
|
resetButton.setY(y + 1);
|
||||||
resetButton.active = isNotDefault();
|
resetButton.active = isNotDefault();
|
||||||
|
@@ -1,128 +0,0 @@
|
|||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
@@ -6,11 +6,11 @@ import net.minecraft.client.gui.components.AbstractButton;
|
|||||||
import net.minecraft.client.gui.narration.NarratedElementType;
|
import net.minecraft.client.gui.narration.NarratedElementType;
|
||||||
import net.minecraft.client.gui.narration.NarrationElementOutput;
|
import net.minecraft.client.gui.narration.NarrationElementOutput;
|
||||||
import net.minecraft.network.chat.Component;
|
import net.minecraft.network.chat.Component;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @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;
|
||||||
@@ -23,7 +23,7 @@ public class InternalConfigButton extends AbstractButton {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void renderWidget(GuiGraphics arg, int i, int j, float f) {
|
public void render(@NotNull GuiGraphics poseStack, int i, int j, float f) {
|
||||||
if (cancel) {
|
if (cancel) {
|
||||||
setMessage(Component.translatable(screen.isEdited() ? "t.clc.cancel_discard" : "gui.cancel"));
|
setMessage(Component.translatable(screen.isEdited() ? "t.clc.cancel_discard" : "gui.cancel"));
|
||||||
} else {
|
} else {
|
||||||
@@ -31,7 +31,7 @@ public class InternalConfigButton extends AbstractButton {
|
|||||||
active = screen.isEdited() && !hasErrors;
|
active = screen.isEdited() && !hasErrors;
|
||||||
setMessage(Component.translatable(hasErrors ? "t.clc.error" : "t.clc.save"));
|
setMessage(Component.translatable(hasErrors ? "t.clc.error" : "t.clc.save"));
|
||||||
}
|
}
|
||||||
super.renderWidget(arg, i, j, f);
|
super.render(poseStack, i, j, f);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -1,7 +1,5 @@
|
|||||||
package com.hypherionmc.craterlib.client.gui.config.widgets;
|
package com.hypherionmc.craterlib.client.gui.config.widgets;
|
||||||
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.Setter;
|
|
||||||
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;
|
||||||
@@ -20,7 +18,6 @@ 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;
|
||||||
@@ -31,10 +28,16 @@ public abstract class Option<T> extends AbstractContainerEventHandler {
|
|||||||
public T value;
|
public T value;
|
||||||
public boolean hasErrors;
|
public boolean hasErrors;
|
||||||
public List<? extends GuiEventListener> children = new ArrayList<>();
|
public List<? extends GuiEventListener> children = new ArrayList<>();
|
||||||
@Setter
|
|
||||||
@Getter
|
|
||||||
private List<String> langKeys = new ArrayList<>();
|
private List<String> langKeys = new ArrayList<>();
|
||||||
|
|
||||||
|
public List<String> getLangKeys() {
|
||||||
|
return langKeys;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLangKeys(List<String> langKeys) {
|
||||||
|
this.langKeys = langKeys;
|
||||||
|
}
|
||||||
|
|
||||||
public abstract void render(Minecraft minecraft, Font font, int x, int y, int width, int height, GuiGraphics matrices, int mouseX, int mouseY, float delta);
|
public abstract void render(Minecraft minecraft, Font font, int x, int y, int width, int height, GuiGraphics matrices, int mouseX, int mouseY, float delta);
|
||||||
|
|
||||||
public int height() {
|
public int height() {
|
||||||
|
@@ -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.AbstractConfig;
|
import com.hypherionmc.craterlib.core.config.ModuleConfig;
|
||||||
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,14 +12,13 @@ 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 AbstractConfig config;
|
private final ModuleConfig config;
|
||||||
private final Screen screen;
|
private final Screen screen;
|
||||||
|
|
||||||
public SubConfigWidget(AbstractConfig config, Screen screen, Object subConfig) {
|
public SubConfigWidget(ModuleConfig config, Screen screen, Object subConfig) {
|
||||||
this.config = config;
|
this.config = config;
|
||||||
this.subConfig = subConfig;
|
this.subConfig = subConfig;
|
||||||
this.screen = screen;
|
this.screen = screen;
|
||||||
|
@@ -10,7 +10,6 @@ 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,7 +10,6 @@ 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,7 +10,6 @@ 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,51 @@
|
|||||||
|
package com.hypherionmc.craterlib.client.gui.widgets;
|
||||||
|
|
||||||
|
import net.minecraft.client.gui.components.AbstractSliderButton;
|
||||||
|
import net.minecraft.network.chat.Component;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author HypherionSA
|
||||||
|
* A custom slider widget used for Time. Mostly used by the Hyper Lighting Smoke Machine
|
||||||
|
*/
|
||||||
|
public class TimeSliderWidget extends AbstractSliderButton {
|
||||||
|
|
||||||
|
private final double maxValue;
|
||||||
|
private final ISliderChanged sliderChanged;
|
||||||
|
|
||||||
|
public TimeSliderWidget(int x, int y, int width, int height, Component text, double value, double maxValue, ISliderChanged sliderChanged) {
|
||||||
|
super(x, y, width, height, text, value / maxValue);
|
||||||
|
this.maxValue = maxValue;
|
||||||
|
this.sliderChanged = sliderChanged;
|
||||||
|
this.updateMessage();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void updateMessage() {
|
||||||
|
this.setMessage(getDisplayString());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void applyValue() {
|
||||||
|
this.sliderChanged.onSliderChange(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Component getDisplayString() {
|
||||||
|
long seconds = Math.round(this.value * this.maxValue / 20);
|
||||||
|
long minutes = Math.round(seconds / 60);
|
||||||
|
if (this.value * this.maxValue >= 1200) {
|
||||||
|
String appendString = (minutes == 1) ? "Minute" : "Minutes";
|
||||||
|
String doSeconds = ((seconds - (minutes * 60)) > 0) ? ", " + (seconds - (minutes * 60)) + " Seconds" : "";
|
||||||
|
return Component.literal(minutes + " " + appendString + doSeconds);
|
||||||
|
} else {
|
||||||
|
return Component.literal(seconds + " Seconds");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getValue() {
|
||||||
|
return this.value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface ISliderChanged {
|
||||||
|
void onSliderChange(TimeSliderWidget slider);
|
||||||
|
}
|
||||||
|
}
|
@@ -1,13 +0,0 @@
|
|||||||
package com.hypherionmc.craterlib.client.mentions;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Based on <a href="https://github.com/SarahIsWeird/MoreChatSuggestions/blob/main/src/main/java/com/sarahisweird/morechatsuggestions/SuggestionCondition.java">...</a>
|
|
||||||
*/
|
|
||||||
@FunctionalInterface
|
|
||||||
public interface MentionCondition {
|
|
||||||
|
|
||||||
boolean shouldAddMention(String currentWord);
|
|
||||||
|
|
||||||
MentionCondition ALWAYS = currentWord -> true;
|
|
||||||
|
|
||||||
}
|
|
@@ -1,47 +0,0 @@
|
|||||||
package com.hypherionmc.craterlib.client.mentions;
|
|
||||||
|
|
||||||
import com.hypherionmc.craterlib.nojang.resources.ResourceIdentifier;
|
|
||||||
import lombok.Getter;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.LinkedHashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Based on <a href="https://github.com/SarahIsWeird/MoreChatSuggestions/blob/main/src/main/java/com/sarahisweird/morechatsuggestions/client/MoreChatSuggestions.java">...</a>
|
|
||||||
*/
|
|
||||||
public class MentionsController {
|
|
||||||
|
|
||||||
private static final Map<ResourceIdentifier, Collection<String>> mentions = new LinkedHashMap<>();
|
|
||||||
private static final Map<ResourceIdentifier, MentionCondition> mentionConditions = new LinkedHashMap<>();
|
|
||||||
@Getter
|
|
||||||
private static boolean lastMentionConditional = true;
|
|
||||||
|
|
||||||
public static void registerMention(ResourceIdentifier mentionClass, Collection<String> suggestions, MentionCondition condition) {
|
|
||||||
mentions.put(mentionClass, suggestions);
|
|
||||||
mentionConditions.put(mentionClass, condition);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Collection<String> getMentions(String currentWord) {
|
|
||||||
ArrayList<String> applicableMentions = new ArrayList<>();
|
|
||||||
lastMentionConditional = false;
|
|
||||||
|
|
||||||
mentionConditions.forEach((mention, condition) -> {
|
|
||||||
boolean shouldSuggest = condition.shouldAddMention(currentWord);
|
|
||||||
if (!shouldSuggest) return;
|
|
||||||
|
|
||||||
if (!lastMentionConditional && condition != MentionCondition.ALWAYS) {
|
|
||||||
lastMentionConditional = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
applicableMentions.addAll(mentions.get(mention));
|
|
||||||
});
|
|
||||||
|
|
||||||
return applicableMentions;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean hasMentions() {
|
|
||||||
return !mentions.isEmpty();
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,17 +0,0 @@
|
|||||||
// @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);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,102 +0,0 @@
|
|||||||
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();
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,24 +0,0 @@
|
|||||||
// @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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,83 +0,0 @@
|
|||||||
// @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,16 @@
|
|||||||
|
package com.hypherionmc.craterlib.core.abstraction.commands;
|
||||||
|
|
||||||
|
import com.mojang.brigadier.context.CommandContext;
|
||||||
|
import net.minecraft.commands.CommandSourceStack;
|
||||||
|
import net.minecraft.network.chat.MutableComponent;
|
||||||
|
|
||||||
|
public class AbstractCommand {
|
||||||
|
|
||||||
|
public static void replySuccess(CommandContext<CommandSourceStack> stack, MutableComponent message) {
|
||||||
|
stack.getSource().sendSuccess(() -> message, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void replyFailure(CommandContext<CommandSourceStack> stack, MutableComponent message) {
|
||||||
|
stack.getSource().sendFailure(message);
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,40 @@
|
|||||||
|
package com.hypherionmc.craterlib.core.abstraction.server;
|
||||||
|
|
||||||
|
import net.minecraft.commands.CommandSource;
|
||||||
|
import net.minecraft.commands.CommandSourceStack;
|
||||||
|
import net.minecraft.network.chat.Component;
|
||||||
|
import net.minecraft.network.chat.MutableComponent;
|
||||||
|
import net.minecraft.server.MinecraftServer;
|
||||||
|
import net.minecraft.world.phys.Vec2;
|
||||||
|
import net.minecraft.world.phys.Vec3;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
public class AbstractFakePlayer extends CommandSourceStack {
|
||||||
|
|
||||||
|
private final UUID uuid;
|
||||||
|
|
||||||
|
public AbstractFakePlayer(MinecraftServer server, String name, MutableComponent displayName, UUID uuid) {
|
||||||
|
super(CommandSource.NULL, Vec3.ZERO, Vec2.ZERO, server.overworld(), 4, name, displayName, server, null);
|
||||||
|
this.uuid = uuid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onSuccess(Component component, boolean bl) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sendSuccess(Supplier<Component> component, boolean bl) {
|
||||||
|
this.onSuccess(component.get(), bl);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sendFailure(Component component) {
|
||||||
|
sendSuccess(() -> component, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public UUID getUuid() {
|
||||||
|
return uuid;
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,13 @@
|
|||||||
|
package com.hypherionmc.craterlib.core.abstraction.server;
|
||||||
|
|
||||||
|
import net.minecraft.nbt.CompoundTag;
|
||||||
|
import net.minecraft.network.FriendlyByteBuf;
|
||||||
|
|
||||||
|
public class AbstractFriendlyByteBuff {
|
||||||
|
|
||||||
|
public static FriendlyByteBuf write(FriendlyByteBuf buf, CompoundTag tag) {
|
||||||
|
buf.writeNbt(tag);
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1,16 @@
|
|||||||
|
package com.hypherionmc.craterlib.core.abstraction.server;
|
||||||
|
|
||||||
|
import net.minecraft.commands.CommandSourceStack;
|
||||||
|
import net.minecraft.network.chat.MutableComponent;
|
||||||
|
import net.minecraft.server.MinecraftServer;
|
||||||
|
|
||||||
|
public class AbstractServer {
|
||||||
|
|
||||||
|
public static void broadcastMessage(MinecraftServer server, MutableComponent message) {
|
||||||
|
server.getPlayerList().broadcastSystemMessage(message, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void executeCommand(MinecraftServer server, CommandSourceStack stack, String command) {
|
||||||
|
server.getCommands().performPrefixedCommand(stack, command);
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,23 @@
|
|||||||
|
package com.hypherionmc.craterlib.core.abstraction.text;
|
||||||
|
|
||||||
|
import net.minecraft.network.chat.Component;
|
||||||
|
import net.minecraft.network.chat.MutableComponent;
|
||||||
|
import net.minecraft.network.chat.Style;
|
||||||
|
|
||||||
|
public class AbstractComponent {
|
||||||
|
|
||||||
|
public static MutableComponent literal(String component) {
|
||||||
|
return Component.literal(component);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static MutableComponent translatable(String component) {
|
||||||
|
return Component.translatable(component);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Component safeCopy(Component inComponent) {
|
||||||
|
String value = inComponent.getString();
|
||||||
|
Style style = inComponent.getStyle();
|
||||||
|
return Component.literal(value).withStyle(style);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -1,71 +0,0 @@
|
|||||||
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();
|
|
||||||
}
|
|
@@ -1,14 +1,11 @@
|
|||||||
package com.hypherionmc.craterlib.core.config;
|
package com.hypherionmc.craterlib.core.config;
|
||||||
|
|
||||||
import com.hypherionmc.craterlib.CraterConstants;
|
import com.hypherionmc.craterlib.CraterConstants;
|
||||||
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
|
||||||
@@ -19,10 +16,7 @@ public final class ConfigController implements Serializable {
|
|||||||
/**
|
/**
|
||||||
* Cache of registered configs
|
* Cache of registered configs
|
||||||
*/
|
*/
|
||||||
@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
|
||||||
@@ -30,34 +24,27 @@ 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) {
|
||||||
register_config((AbstractConfig) config);
|
if (monitoredConfigs.containsKey(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 {
|
||||||
watcher.addWatch(config.getConfigPath(), () -> {
|
configWatcher.setWatch(config.getConfigPath(), () -> {
|
||||||
if (!config.isWasSaveCalled()) {
|
if (!config.isSaveCalled()) {
|
||||||
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 {} for auto reloading. {}", config.getConfigPath().getName(), e.getMessage());
|
CraterConstants.LOG.error("Failed to register " + config.getConfigPath().getName() + " for auto reloading. " + e.getMessage());
|
||||||
}
|
}
|
||||||
watchedConfigs.put(config.getConfigPath().toString(), config);
|
monitoredConfigs.put(config, configWatcher);
|
||||||
CraterConstants.LOG.info("Registered {} successfully!", config.getConfigPath().getName());
|
CraterConstants.LOG.info("Registered " + config.getConfigPath().getName() + " successfully!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static HashMap<Object, FileWatcher> getMonitoredConfigs() {
|
||||||
|
return monitoredConfigs;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,7 +1,9 @@
|
|||||||
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;
|
||||||
|
|
||||||
@@ -10,8 +12,17 @@ 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
|
||||||
*/
|
*/
|
||||||
@Deprecated(forRemoval = true, since = "2.1.0")
|
public class ModuleConfig {
|
||||||
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
|
||||||
@@ -24,7 +35,20 @@ public class ModuleConfig extends AbstractConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public ModuleConfig(String modId, String subFolder, String configName) {
|
public ModuleConfig(String modId, String subFolder, String configName) {
|
||||||
super(modId, subFolder.isEmpty() ? null : subFolder, configName);
|
/* Preserve the order of the config values */
|
||||||
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -33,7 +57,14 @@ public class ModuleConfig extends AbstractConfig {
|
|||||||
* @param config - The config class to use
|
* @param config - The config class to use
|
||||||
*/
|
*/
|
||||||
public void registerAndSetup(ModuleConfig config) {
|
public void registerAndSetup(ModuleConfig config) {
|
||||||
super.registerAndSetup(config);
|
if (!configPath.exists() || configPath.length() < 2) {
|
||||||
|
saveConfig(config);
|
||||||
|
} else {
|
||||||
|
migrateConfig(config);
|
||||||
|
}
|
||||||
|
/* Register the Config for Watching and events */
|
||||||
|
ConfigController.register_config(this);
|
||||||
|
this.configReloaded();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -42,7 +73,16 @@ public class ModuleConfig extends AbstractConfig {
|
|||||||
* @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) {
|
||||||
super.registerAndSetup(conf);
|
this.isSaveCalled = true;
|
||||||
|
/* 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -52,7 +92,14 @@ public class ModuleConfig extends AbstractConfig {
|
|||||||
* @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) {
|
||||||
return (T) super.readConfig(conf);
|
/* Set up the Serializer and Config Object */
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -61,13 +108,31 @@ public class ModuleConfig extends AbstractConfig {
|
|||||||
* @param conf - The config class to load
|
* @param conf - The config class to load
|
||||||
*/
|
*/
|
||||||
public void migrateConfig(ModuleConfig conf) {
|
public void migrateConfig(ModuleConfig conf) {
|
||||||
super.migrateConfig(conf);
|
/* Set up the Serializer and Config Objects */
|
||||||
|
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) {
|
||||||
if (getConfigFormat() instanceof TomlConfigFormat<?> t) {
|
/* Loop over the config keys and check what has changed */
|
||||||
t.updateConfigValues(oldConfig, newConfig, outputConfig, subKey);
|
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);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -76,7 +141,7 @@ public class ModuleConfig extends AbstractConfig {
|
|||||||
* @return - The FILE object containing the config file
|
* @return - The FILE object containing the config file
|
||||||
*/
|
*/
|
||||||
public File getConfigPath() {
|
public File getConfigPath() {
|
||||||
return super.getConfigPath();
|
return configPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -85,13 +150,12 @@ public class ModuleConfig extends AbstractConfig {
|
|||||||
* @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 super.getNetworkID();
|
return networkID;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fired whenever changes to the config are detected
|
* Fired whenever changes to the config are detected
|
||||||
*/
|
*/
|
||||||
@Override
|
|
||||||
public void configReloaded() {
|
public void configReloaded() {
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -102,7 +166,7 @@ public class ModuleConfig extends AbstractConfig {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public String getConfigName() {
|
public String getConfigName() {
|
||||||
return super.getConfigName();
|
return configName;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -111,10 +175,10 @@ public class ModuleConfig extends AbstractConfig {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public String getModId() {
|
public String getModId() {
|
||||||
return super.getModId();
|
return modId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isSaveCalled() {
|
public boolean isSaveCalled() {
|
||||||
return super.isWasSaveCalled();
|
return isSaveCalled;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,12 +0,0 @@
|
|||||||
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 {
|
|
||||||
}
|
|
@@ -1,32 +0,0 @@
|
|||||||
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);
|
|
||||||
|
|
||||||
}
|
|
@@ -1,67 +0,0 @@
|
|||||||
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);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,67 +0,0 @@
|
|||||||
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);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,15 +1,12 @@
|
|||||||
package com.hypherionmc.craterlib.core.event;
|
package com.hypherionmc.craterlib.core.event;
|
||||||
|
|
||||||
import com.hypherionmc.craterlib.core.event.annot.Cancellable;
|
|
||||||
import com.hypherionmc.craterlib.core.event.exception.CraterEventCancellationException;
|
import com.hypherionmc.craterlib.core.event.exception.CraterEventCancellationException;
|
||||||
|
|
||||||
public class CraterEvent {
|
public abstract class CraterEvent {
|
||||||
|
|
||||||
private boolean canceled = false;
|
private boolean canceled = false;
|
||||||
|
|
||||||
private boolean canCancel() {
|
public abstract boolean canCancel();
|
||||||
return this.getClass().isAnnotationPresent(Cancellable.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void cancelEvent() {
|
public void cancelEvent() {
|
||||||
try {
|
try {
|
||||||
|
@@ -1,8 +0,0 @@
|
|||||||
package com.hypherionmc.craterlib.core.event.annot;
|
|
||||||
|
|
||||||
import java.lang.annotation.Retention;
|
|
||||||
import java.lang.annotation.RetentionPolicy;
|
|
||||||
|
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
|
||||||
public @interface Cancellable {
|
|
||||||
}
|
|
@@ -0,0 +1,34 @@
|
|||||||
|
package com.hypherionmc.craterlib.core.network;
|
||||||
|
|
||||||
|
import com.hypherionmc.craterlib.core.platform.ClientPlatform;
|
||||||
|
import com.hypherionmc.craterlib.core.platform.CommonPlatform;
|
||||||
|
import net.minecraft.network.protocol.Packet;
|
||||||
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
|
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author HypherionSA
|
||||||
|
*/
|
||||||
|
@Deprecated(forRemoval = true)
|
||||||
|
public interface CraterNetworkHandler {
|
||||||
|
|
||||||
|
<T extends CraterPacket<T>> void registerPacket(Class<? extends T> clazz, Supplier<T> supplier, PacketDirection packetDirection);
|
||||||
|
|
||||||
|
Packet<?> toServerBound(CraterPacket<?> packet);
|
||||||
|
|
||||||
|
Packet<?> toClientBound(CraterPacket<?> packet);
|
||||||
|
|
||||||
|
default void sendToServer(CraterPacket<?> packet) {
|
||||||
|
ClientPlatform.INSTANCE.getClientConnection().send(this.toServerBound(packet));
|
||||||
|
}
|
||||||
|
|
||||||
|
default void sendTo(CraterPacket<?> packet, ServerPlayer player) {
|
||||||
|
player.connection.send(this.toClientBound(packet));
|
||||||
|
}
|
||||||
|
|
||||||
|
default void sendToAll(CraterPacket<?> packet) {
|
||||||
|
CommonPlatform.INSTANCE.getMCServer().getPlayerList().broadcastAll(this.toClientBound(packet));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1,25 @@
|
|||||||
|
package com.hypherionmc.craterlib.core.network;
|
||||||
|
|
||||||
|
import net.minecraft.network.FriendlyByteBuf;
|
||||||
|
import net.minecraft.world.entity.player.Player;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author HypherionSA
|
||||||
|
*/
|
||||||
|
@Deprecated(forRemoval = true)
|
||||||
|
public interface CraterPacket<T extends CraterPacket<T>> {
|
||||||
|
|
||||||
|
void write(final FriendlyByteBuf buf);
|
||||||
|
|
||||||
|
void read(final FriendlyByteBuf buf);
|
||||||
|
|
||||||
|
default void handle(Player player, Object minecraft) {
|
||||||
|
this.createHandler().handle((T) this, player, minecraft);
|
||||||
|
}
|
||||||
|
|
||||||
|
PacketHandler<T> createHandler();
|
||||||
|
|
||||||
|
abstract class PacketHandler<T extends CraterPacket<T>> {
|
||||||
|
public abstract void handle(T packet, Player player, Object minecraft);
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,10 @@
|
|||||||
|
package com.hypherionmc.craterlib.core.network;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author HypherionSA
|
||||||
|
*/
|
||||||
|
@Deprecated(forRemoval = true)
|
||||||
|
public enum PacketDirection {
|
||||||
|
TO_SERVER,
|
||||||
|
TO_CLIENT
|
||||||
|
}
|
@@ -1,9 +1,8 @@
|
|||||||
package com.hypherionmc.craterlib.core.networking;
|
package com.hypherionmc.craterlib.core.networking;
|
||||||
|
|
||||||
import com.hypherionmc.craterlib.core.networking.data.PacketContext;
|
import com.hypherionmc.craterlib.core.networking.data.PacketContext;
|
||||||
import com.hypherionmc.craterlib.nojang.network.BridgedFriendlyByteBuf;
|
import net.minecraft.network.FriendlyByteBuf;
|
||||||
import com.hypherionmc.craterlib.nojang.resources.ResourceIdentifier;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import lombok.Getter;
|
|
||||||
|
|
||||||
import java.util.function.BiConsumer;
|
import java.util.function.BiConsumer;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
@@ -12,7 +11,6 @@ import java.util.function.Function;
|
|||||||
/**
|
/**
|
||||||
* Based on https://github.com/mysticdrew/common-networking/tree/1.20.4
|
* Based on https://github.com/mysticdrew/common-networking/tree/1.20.4
|
||||||
*/
|
*/
|
||||||
@Getter
|
|
||||||
public class CraterPacketNetwork {
|
public class CraterPacketNetwork {
|
||||||
|
|
||||||
private final PacketRegistry packetRegistry;
|
private final PacketRegistry packetRegistry;
|
||||||
@@ -32,7 +30,7 @@ public class CraterPacketNetwork {
|
|||||||
return delayedHandler;
|
return delayedHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T> PacketRegistrar registerPacket(ResourceIdentifier id, Class<T> messageType, BiConsumer<T, BridgedFriendlyByteBuf> encoder, Function<BridgedFriendlyByteBuf, T> decoder, Consumer<PacketContext<T>> handler) {
|
public static <T> PacketRegistrar registerPacket(ResourceLocation id, Class<T> messageType, BiConsumer<T, FriendlyByteBuf> encoder, Function<FriendlyByteBuf, T> decoder, Consumer<PacketContext<T>> handler) {
|
||||||
if (INSTANCE != null) {
|
if (INSTANCE != null) {
|
||||||
return INSTANCE.packetRegistry.registerPacket(id, messageType, encoder, decoder, handler);
|
return INSTANCE.packetRegistry.registerPacket(id, messageType, encoder, decoder, handler);
|
||||||
} else {
|
} else {
|
||||||
@@ -40,4 +38,7 @@ public class CraterPacketNetwork {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public PacketRegistry getPacketRegistry() {
|
||||||
|
return packetRegistry;
|
||||||
|
}
|
||||||
}
|
}
|
@@ -3,8 +3,8 @@ package com.hypherionmc.craterlib.core.networking;
|
|||||||
import com.hypherionmc.craterlib.core.networking.data.PacketContext;
|
import com.hypherionmc.craterlib.core.networking.data.PacketContext;
|
||||||
import com.hypherionmc.craterlib.core.networking.data.PacketHolder;
|
import com.hypherionmc.craterlib.core.networking.data.PacketHolder;
|
||||||
import com.hypherionmc.craterlib.core.networking.data.PacketSide;
|
import com.hypherionmc.craterlib.core.networking.data.PacketSide;
|
||||||
import com.hypherionmc.craterlib.nojang.network.BridgedFriendlyByteBuf;
|
import net.minecraft.network.FriendlyByteBuf;
|
||||||
import com.hypherionmc.craterlib.nojang.resources.ResourceIdentifier;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -25,7 +25,7 @@ public class DeferredPacketRegistrar implements PacketRegistrar {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <T> PacketRegistrar registerPacket(ResourceIdentifier packetIdentifier, Class<T> messageType, BiConsumer<T, BridgedFriendlyByteBuf> encoder, Function<BridgedFriendlyByteBuf, T> decoder, Consumer<PacketContext<T>> handler) {
|
public <T> PacketRegistrar registerPacket(ResourceLocation packetIdentifier, Class<T> messageType, BiConsumer<T, FriendlyByteBuf> encoder, Function<FriendlyByteBuf, T> decoder, Consumer<PacketContext<T>> handler) {
|
||||||
PacketHolder<T> container = new PacketHolder<>(packetIdentifier, messageType, encoder, decoder, handler);
|
PacketHolder<T> container = new PacketHolder<>(packetIdentifier, messageType, encoder, decoder, handler);
|
||||||
QUEUED_PACKET_MAP.put(messageType, container);
|
QUEUED_PACKET_MAP.put(messageType, container);
|
||||||
return this;
|
return this;
|
||||||
|
@@ -2,8 +2,8 @@ package com.hypherionmc.craterlib.core.networking;
|
|||||||
|
|
||||||
import com.hypherionmc.craterlib.core.networking.data.PacketContext;
|
import com.hypherionmc.craterlib.core.networking.data.PacketContext;
|
||||||
import com.hypherionmc.craterlib.core.networking.data.PacketSide;
|
import com.hypherionmc.craterlib.core.networking.data.PacketSide;
|
||||||
import com.hypherionmc.craterlib.nojang.network.BridgedFriendlyByteBuf;
|
import net.minecraft.network.FriendlyByteBuf;
|
||||||
import com.hypherionmc.craterlib.nojang.resources.ResourceIdentifier;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
|
||||||
import java.util.function.BiConsumer;
|
import java.util.function.BiConsumer;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
@@ -16,6 +16,6 @@ public interface PacketRegistrar {
|
|||||||
|
|
||||||
PacketSide side();
|
PacketSide side();
|
||||||
|
|
||||||
<T> PacketRegistrar registerPacket(ResourceIdentifier id, Class<T> messageType, BiConsumer<T, BridgedFriendlyByteBuf> encoder, Function<BridgedFriendlyByteBuf, T> decoder, Consumer<PacketContext<T>> handler);
|
<T> PacketRegistrar registerPacket(ResourceLocation id, Class<T> messageType, BiConsumer<T, FriendlyByteBuf> encoder, Function<FriendlyByteBuf, T> decoder, Consumer<PacketContext<T>> handler);
|
||||||
|
|
||||||
}
|
}
|
@@ -4,8 +4,8 @@ import com.hypherionmc.craterlib.api.networking.CraterNetworkHandler;
|
|||||||
import com.hypherionmc.craterlib.core.networking.data.PacketContext;
|
import com.hypherionmc.craterlib.core.networking.data.PacketContext;
|
||||||
import com.hypherionmc.craterlib.core.networking.data.PacketHolder;
|
import com.hypherionmc.craterlib.core.networking.data.PacketHolder;
|
||||||
import com.hypherionmc.craterlib.core.networking.data.PacketSide;
|
import com.hypherionmc.craterlib.core.networking.data.PacketSide;
|
||||||
import com.hypherionmc.craterlib.nojang.network.BridgedFriendlyByteBuf;
|
import net.minecraft.network.FriendlyByteBuf;
|
||||||
import com.hypherionmc.craterlib.nojang.resources.ResourceIdentifier;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -18,7 +18,7 @@ import java.util.function.Function;
|
|||||||
*/
|
*/
|
||||||
public abstract class PacketRegistry implements CraterNetworkHandler, PacketRegistrar {
|
public abstract class PacketRegistry implements CraterNetworkHandler, PacketRegistrar {
|
||||||
|
|
||||||
protected final Map<Class<?>, PacketHolder<?>> PACKET_MAP = new HashMap<>();
|
final Map<Class<?>, PacketHolder<?>> PACKET_MAP = new HashMap<>();
|
||||||
|
|
||||||
protected final PacketSide side;
|
protected final PacketSide side;
|
||||||
|
|
||||||
@@ -26,7 +26,7 @@ public abstract class PacketRegistry implements CraterNetworkHandler, PacketRegi
|
|||||||
this.side = side;
|
this.side = side;
|
||||||
}
|
}
|
||||||
|
|
||||||
public <T> PacketRegistrar registerPacket(ResourceIdentifier id, Class<T> messageType, BiConsumer<T, BridgedFriendlyByteBuf> encoder, Function<BridgedFriendlyByteBuf, T> decoder, Consumer<PacketContext<T>> handler) {
|
public <T> PacketRegistrar registerPacket(ResourceLocation id, Class<T> messageType, BiConsumer<T, FriendlyByteBuf> encoder, Function<FriendlyByteBuf, T> decoder, Consumer<PacketContext<T>> handler) {
|
||||||
PacketHolder<T> holder = new PacketHolder<>(id, messageType, encoder, decoder, handler);
|
PacketHolder<T> holder = new PacketHolder<>(id, messageType, encoder, decoder, handler);
|
||||||
PACKET_MAP.put(messageType, holder);
|
PACKET_MAP.put(messageType, holder);
|
||||||
registerPacket(holder);
|
registerPacket(holder);
|
||||||
|
@@ -1,12 +1,12 @@
|
|||||||
package com.hypherionmc.craterlib.core.networking.data;
|
package com.hypherionmc.craterlib.core.networking.data;
|
||||||
|
|
||||||
import com.hypherionmc.craterlib.nojang.world.entity.player.BridgedPlayer;
|
import net.minecraft.world.entity.player.Player;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Based on https://github.com/mysticdrew/common-networking/tree/1.20.4
|
* Based on https://github.com/mysticdrew/common-networking/tree/1.20.4
|
||||||
*/
|
*/
|
||||||
public record PacketContext<T>(@Nullable BridgedPlayer sender, T message, PacketSide side) {
|
public record PacketContext<T>(@Nullable Player sender, T message, PacketSide side) {
|
||||||
|
|
||||||
public PacketContext(T message, PacketSide side) {
|
public PacketContext(T message, PacketSide side) {
|
||||||
this(null, message, side);
|
this(null, message, side);
|
||||||
|
@@ -1,11 +1,7 @@
|
|||||||
package com.hypherionmc.craterlib.core.networking.data;
|
package com.hypherionmc.craterlib.core.networking.data;
|
||||||
|
|
||||||
import com.hypherionmc.craterlib.api.networking.CommonPacketWrapper;
|
|
||||||
import com.hypherionmc.craterlib.nojang.network.BridgedFriendlyByteBuf;
|
|
||||||
import com.hypherionmc.craterlib.nojang.resources.ResourceIdentifier;
|
|
||||||
import net.minecraft.network.FriendlyByteBuf;
|
import net.minecraft.network.FriendlyByteBuf;
|
||||||
import net.minecraft.network.codec.StreamCodec;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
|
|
||||||
|
|
||||||
import java.util.function.BiConsumer;
|
import java.util.function.BiConsumer;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
@@ -14,27 +10,9 @@ import java.util.function.Function;
|
|||||||
/**
|
/**
|
||||||
* Based on https://github.com/mysticdrew/common-networking/tree/1.20.4
|
* Based on https://github.com/mysticdrew/common-networking/tree/1.20.4
|
||||||
*/
|
*/
|
||||||
public record PacketHolder<T>(CustomPacketPayload.Type<? extends CustomPacketPayload> type,
|
public record PacketHolder<T>(ResourceLocation packetId,
|
||||||
Class<T> messageType,
|
Class<T> messageType,
|
||||||
BiConsumer<T, BridgedFriendlyByteBuf> encoder,
|
BiConsumer<T, FriendlyByteBuf> encoder,
|
||||||
Function<BridgedFriendlyByteBuf, T> decoder,
|
Function<FriendlyByteBuf, T> decoder,
|
||||||
Consumer<PacketContext<T>> handler) {
|
Consumer<PacketContext<T>> handler) {
|
||||||
|
|
||||||
public PacketHolder(ResourceIdentifier packetId, Class<T> messageType, BiConsumer<T, BridgedFriendlyByteBuf> encoder, Function<BridgedFriendlyByteBuf, T> decoder, Consumer<PacketContext<T>> handler) {
|
|
||||||
this(new CustomPacketPayload.Type<>(packetId.toMojang()), messageType, encoder, decoder, handler);
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public <K extends CustomPacketPayload> CustomPacketPayload.Type<K> getType()
|
|
||||||
{
|
|
||||||
return (CustomPacketPayload.Type<K>) type();
|
|
||||||
}
|
|
||||||
|
|
||||||
public StreamCodec<FriendlyByteBuf, CommonPacketWrapper> getCodec()
|
|
||||||
{
|
|
||||||
return CustomPacketPayload.codec(
|
|
||||||
(packet, buf) -> this.encoder().accept((T)packet.packet(), BridgedFriendlyByteBuf.of(buf)),
|
|
||||||
(buf) -> new CommonPacketWrapper<>(this, this.decoder().apply(BridgedFriendlyByteBuf.of(buf))));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
@@ -1,23 +1,23 @@
|
|||||||
package com.hypherionmc.craterlib.core.platform;
|
package com.hypherionmc.craterlib.core.platform;
|
||||||
|
|
||||||
import com.hypherionmc.craterlib.nojang.client.BridgedMinecraft;
|
import com.hypherionmc.craterlib.util.ServiceUtil;
|
||||||
import com.hypherionmc.craterlib.nojang.client.multiplayer.BridgedClientLevel;
|
import net.minecraft.client.Minecraft;
|
||||||
import com.hypherionmc.craterlib.nojang.world.entity.player.BridgedPlayer;
|
|
||||||
import com.hypherionmc.craterlib.utils.InternalServiceUtil;
|
|
||||||
import net.minecraft.network.Connection;
|
import net.minecraft.network.Connection;
|
||||||
|
import net.minecraft.world.entity.player.Player;
|
||||||
|
import net.minecraft.world.level.Level;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author HypherionSA
|
* @author HypherionSA
|
||||||
*/
|
*/
|
||||||
public interface ClientPlatform {
|
public interface ClientPlatform {
|
||||||
|
|
||||||
public final ClientPlatform INSTANCE = InternalServiceUtil.load(ClientPlatform.class);
|
public final ClientPlatform INSTANCE = ServiceUtil.load(ClientPlatform.class);
|
||||||
|
|
||||||
BridgedMinecraft getClientInstance();
|
Minecraft getClientInstance();
|
||||||
|
|
||||||
BridgedPlayer getClientPlayer();
|
Player getClientPlayer();
|
||||||
|
|
||||||
BridgedClientLevel getClientLevel();
|
Level getClientLevel();
|
||||||
|
|
||||||
Connection getClientConnection();
|
Connection getClientConnection();
|
||||||
}
|
}
|
@@ -1,15 +1,22 @@
|
|||||||
package com.hypherionmc.craterlib.core.platform;
|
package com.hypherionmc.craterlib.core.platform;
|
||||||
|
|
||||||
import com.hypherionmc.craterlib.nojang.server.BridgedMinecraftServer;
|
import com.hypherionmc.craterlib.core.network.CraterNetworkHandler;
|
||||||
import com.hypherionmc.craterlib.utils.InternalServiceUtil;
|
import com.hypherionmc.craterlib.util.ServiceUtil;
|
||||||
|
import net.minecraft.server.MinecraftServer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author HypherionSA
|
* @author HypherionSA
|
||||||
*/
|
*/
|
||||||
public interface CommonPlatform {
|
public interface CommonPlatform {
|
||||||
|
|
||||||
public CommonPlatform INSTANCE = InternalServiceUtil.load(CommonPlatform.class);
|
public CommonPlatform INSTANCE = ServiceUtil.load(CommonPlatform.class);
|
||||||
|
|
||||||
BridgedMinecraftServer getMCServer();
|
default CraterNetworkHandler createPacketHandler(String modid) {
|
||||||
|
return this.createPacketHandler(modid, true, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
CraterNetworkHandler createPacketHandler(String modid, boolean requiredClient, boolean requiredServer);
|
||||||
|
|
||||||
|
MinecraftServer getMCServer();
|
||||||
|
|
||||||
}
|
}
|
@@ -1,19 +0,0 @@
|
|||||||
package com.hypherionmc.craterlib.core.platform;
|
|
||||||
|
|
||||||
import com.hypherionmc.craterlib.nojang.world.entity.player.BridgedPlayer;
|
|
||||||
import com.hypherionmc.craterlib.utils.InternalServiceUtil;
|
|
||||||
import net.kyori.adventure.text.Component;
|
|
||||||
|
|
||||||
public interface CompatUtils {
|
|
||||||
|
|
||||||
public static final CompatUtils INSTANCE = InternalServiceUtil.load(CompatUtils.class);
|
|
||||||
|
|
||||||
boolean isPlayerActive(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);
|
|
||||||
|
|
||||||
}
|
|
@@ -1,8 +0,0 @@
|
|||||||
package com.hypherionmc.craterlib.core.platform;
|
|
||||||
|
|
||||||
public enum LoaderType {
|
|
||||||
FABRIC,
|
|
||||||
FORGE,
|
|
||||||
NEOFORGE,
|
|
||||||
PAPER
|
|
||||||
}
|
|
@@ -1,6 +1,6 @@
|
|||||||
package com.hypherionmc.craterlib.core.platform;
|
package com.hypherionmc.craterlib.core.platform;
|
||||||
|
|
||||||
import com.hypherionmc.craterlib.utils.InternalServiceUtil;
|
import com.hypherionmc.craterlib.util.ServiceUtil;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
@@ -10,13 +10,10 @@ import java.io.File;
|
|||||||
*/
|
*/
|
||||||
public interface ModloaderEnvironment {
|
public interface ModloaderEnvironment {
|
||||||
|
|
||||||
public final ModloaderEnvironment INSTANCE = InternalServiceUtil.load(ModloaderEnvironment.class);
|
public final ModloaderEnvironment INSTANCE = ServiceUtil.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,7 +11,6 @@ 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,7 +9,6 @@ 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,7 +13,6 @@ 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,7 +9,6 @@ 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,7 +6,6 @@ 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,7 +6,6 @@ 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,7 +6,6 @@ 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,7 +7,6 @@ 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,7 +7,6 @@ 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,7 +6,6 @@ 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 {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user