Compare commits
8 Commits
lts
...
old/1.18.2
Author | SHA1 | Date | |
---|---|---|---|
9d9217485b | |||
eda7bf4bf2 | |||
0e4a46f98a | |||
9c05bec9a0 | |||
d97e6df36e | |||
ee80626bf7 | |||
556dd63c8f | |||
dfa8a3d55f |
2
.gitattributes
vendored
2
.gitattributes
vendored
@@ -2,7 +2,7 @@
|
|||||||
*.bat text eol=crlf
|
*.bat text eol=crlf
|
||||||
*.patch text eol=lf
|
*.patch text eol=lf
|
||||||
*.java text eol=lf
|
*.java text eol=lf
|
||||||
*.gradle text eol=lf
|
*.gradle text eol=crlf
|
||||||
*.png binary
|
*.png binary
|
||||||
*.gif binary
|
*.gif binary
|
||||||
*.exe binary
|
*.exe binary
|
||||||
|
4
.gitignore
vendored
4
.gitignore
vendored
@@ -23,7 +23,3 @@ run
|
|||||||
|
|
||||||
artifacts
|
artifacts
|
||||||
src/test/**
|
src/test/**
|
||||||
dev
|
|
||||||
upstream
|
|
||||||
rejects
|
|
||||||
workspace
|
|
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>
|
47
.jenkins/Jenkinsfile.deploy
Normal file
47
.jenkins/Jenkinsfile.deploy
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
pipeline {
|
||||||
|
agent {
|
||||||
|
label "master"
|
||||||
|
}
|
||||||
|
tools {
|
||||||
|
jdk "JAVA17"
|
||||||
|
}
|
||||||
|
stages {
|
||||||
|
stage("Notify Discord") {
|
||||||
|
steps {
|
||||||
|
discordSend webhookURL: env.FDD_WH_ADMIN,
|
||||||
|
title: "Deploy Started: CraterLib 1.18.2 Deploy #${BUILD_NUMBER}",
|
||||||
|
link: env.BUILD_URL,
|
||||||
|
result: 'SUCCESS',
|
||||||
|
description: "Build: [${BUILD_NUMBER}](${env.BUILD_URL})"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
stage("Prepare") {
|
||||||
|
steps {
|
||||||
|
sh "chmod +x ./gradlew"
|
||||||
|
sh "./gradlew clean"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
stage("Publish to Modrinth/Curseforge") {
|
||||||
|
steps {
|
||||||
|
sh "./gradlew publishMod -Prelease=true"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
stage("Publish to Maven") {
|
||||||
|
steps {
|
||||||
|
sh "./gradlew publish -Prelease=true"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
post {
|
||||||
|
always {
|
||||||
|
sh "./gradlew --stop"
|
||||||
|
deleteDir()
|
||||||
|
|
||||||
|
discordSend webhookURL: env.FDD_WH_ADMIN,
|
||||||
|
title: "CraterLib 1.18.2 Deploy #${BUILD_NUMBER}",
|
||||||
|
link: env.BUILD_URL,
|
||||||
|
result: currentBuild.currentResult,
|
||||||
|
description: "Build: [${BUILD_NUMBER}](${env.BUILD_URL})\nStatus: ${currentBuild.currentResult}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
64
.jenkins/Jenkinsfile.snapshot
Normal file
64
.jenkins/Jenkinsfile.snapshot
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
def projectName = "CraterLib";
|
||||||
|
def projectIcon = "https://cdn.modrinth.com/data/Nn8Wasaq/a172c634683a11a2e9ae593e56eba7885743bb44.png";
|
||||||
|
|
||||||
|
pipeline {
|
||||||
|
agent {
|
||||||
|
label "master"
|
||||||
|
}
|
||||||
|
tools {
|
||||||
|
jdk "JAVA17"
|
||||||
|
}
|
||||||
|
|
||||||
|
stages {
|
||||||
|
stage("Notify Discord") {
|
||||||
|
steps {
|
||||||
|
discordSend webhookURL: env.SSS_WEBHOOK,
|
||||||
|
title: "Deploy Started: ${projectName} 1.18.2 Deploy #${BUILD_NUMBER}",
|
||||||
|
link: env.BUILD_URL,
|
||||||
|
result: 'SUCCESS',
|
||||||
|
description: "Build: [${BUILD_NUMBER}](${env.BUILD_URL})"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stage("Prepare") {
|
||||||
|
steps {
|
||||||
|
sh "chmod +x ./gradlew"
|
||||||
|
sh "./gradlew clean"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stage("Build") {
|
||||||
|
steps {
|
||||||
|
sh "./gradlew build"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stage("Publish to Maven") {
|
||||||
|
steps {
|
||||||
|
catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') {
|
||||||
|
sh "./gradlew publish"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
post {
|
||||||
|
always {
|
||||||
|
sh "./gradlew --stop"
|
||||||
|
archiveArtifacts artifacts: 'artifacts/*.jar'
|
||||||
|
|
||||||
|
fddsnapshotter apiKey: env.PLATFORM_KEY,
|
||||||
|
projectSlug: "craterlib",
|
||||||
|
projectName: "${projectName}",
|
||||||
|
projectIcon: "${projectIcon}",
|
||||||
|
versionName: "Snapshot 1.1.${BUILD_NUMBER}",
|
||||||
|
version: "1.1.${BUILD_NUMBER}",
|
||||||
|
modLoaders: "forge|fabric|quilt",
|
||||||
|
minecraftVersions: "1.18.2",
|
||||||
|
failWebhook: env.SSS_WEBHOOK,
|
||||||
|
publishWebhooks: "${env.SSS_WEBHOOK}|${env.FDD_WH}"
|
||||||
|
|
||||||
|
deleteDir()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
15
1.18.2/.gitattributes
vendored
15
1.18.2/.gitattributes
vendored
@@ -1,15 +0,0 @@
|
|||||||
* text eol=lf
|
|
||||||
*.bat text eol=crlf
|
|
||||||
*.patch text eol=lf
|
|
||||||
*.java text eol=lf
|
|
||||||
*.gradle text eol=crlf
|
|
||||||
*.png binary
|
|
||||||
*.gif binary
|
|
||||||
*.exe binary
|
|
||||||
*.dll binary
|
|
||||||
*.jar binary
|
|
||||||
*.lzma binary
|
|
||||||
*.zip binary
|
|
||||||
*.pyd binary
|
|
||||||
*.cfg text eol=lf
|
|
||||||
*.jks binary
|
|
29
1.18.2/.gitignore
vendored
29
1.18.2/.gitignore
vendored
@@ -1,29 +0,0 @@
|
|||||||
# eclipse
|
|
||||||
bin
|
|
||||||
*.launch
|
|
||||||
.settings
|
|
||||||
.metadata
|
|
||||||
.classpath
|
|
||||||
.project
|
|
||||||
|
|
||||||
# idea
|
|
||||||
out
|
|
||||||
*.ipr
|
|
||||||
*.iws
|
|
||||||
*.iml
|
|
||||||
.idea
|
|
||||||
|
|
||||||
# gradle
|
|
||||||
build
|
|
||||||
.gradle
|
|
||||||
|
|
||||||
# other
|
|
||||||
eclipse
|
|
||||||
run
|
|
||||||
|
|
||||||
artifacts
|
|
||||||
src/test/**
|
|
||||||
|
|
||||||
workspace
|
|
||||||
upstream
|
|
||||||
rejects
|
|
@@ -1,64 +0,0 @@
|
|||||||
def majorMc = "1.18.2";
|
|
||||||
def JDK = "17"
|
|
||||||
|
|
||||||
pipeline {
|
|
||||||
agent {
|
|
||||||
docker {
|
|
||||||
image "registry.firstdark.dev/java${JDK}:latest"
|
|
||||||
alwaysPull true
|
|
||||||
args '-v gradle-cache:/home/gradle/.gradle'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
environment {
|
|
||||||
GRADLE_USER_HOME = '/home/gradle/.gradle'
|
|
||||||
}
|
|
||||||
|
|
||||||
stages {
|
|
||||||
stage("Notify Discord") {
|
|
||||||
steps {
|
|
||||||
discordSend webhookURL: env.FDD_WH_ADMIN,
|
|
||||||
title: "Deploy Started: CraterLib ${majorMc} Deploy #${BUILD_NUMBER}",
|
|
||||||
link: env.BUILD_URL,
|
|
||||||
result: 'SUCCESS',
|
|
||||||
description: "Build: [${BUILD_NUMBER}](${env.BUILD_URL})"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
stage("Prepare") {
|
|
||||||
steps {
|
|
||||||
dir("${WORKSPACE}/${majorMc}") {
|
|
||||||
sh "chmod +x ./gradlew"
|
|
||||||
sh "./gradlew clean"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
stage("Publish to Modrinth/Curseforge") {
|
|
||||||
steps {
|
|
||||||
dir("${WORKSPACE}/${majorMc}") {
|
|
||||||
sh "./gradlew publishMod -Prelease=true"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
stage("Publish to Maven") {
|
|
||||||
steps {
|
|
||||||
dir("${WORKSPACE}/${majorMc}") {
|
|
||||||
sh "./gradlew publish -Prelease=true"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
post {
|
|
||||||
always {
|
|
||||||
dir("${WORKSPACE}/${majorMc}") {
|
|
||||||
sh "./gradlew --stop"
|
|
||||||
deleteDir()
|
|
||||||
}
|
|
||||||
|
|
||||||
discordSend webhookURL: env.FDD_WH_ADMIN,
|
|
||||||
title: "CraterLib Port Deploy #${BUILD_NUMBER}",
|
|
||||||
link: env.BUILD_URL,
|
|
||||||
result: currentBuild.currentResult,
|
|
||||||
description: "Build: [${BUILD_NUMBER}](${env.BUILD_URL})\nStatus: ${currentBuild.currentResult}"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,80 +0,0 @@
|
|||||||
def projectName = "CraterLib";
|
|
||||||
def projectIcon = "https://cdn.modrinth.com/data/Nn8Wasaq/a172c634683a11a2e9ae593e56eba7885743bb44.png";
|
|
||||||
def JDK = "17";
|
|
||||||
def majorMc = "1.18.2";
|
|
||||||
def modLoaders = "forge|fabric|quilt";
|
|
||||||
def supportedMc = "1.18.2";
|
|
||||||
def reltype = "snapshot";
|
|
||||||
|
|
||||||
pipeline {
|
|
||||||
agent {
|
|
||||||
docker {
|
|
||||||
image "registry.firstdark.dev/java${JDK}:latest"
|
|
||||||
alwaysPull true
|
|
||||||
args '-v gradle-cache:/home/gradle/.gradle'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
environment {
|
|
||||||
GRADLE_USER_HOME = '/home/gradle/.gradle'
|
|
||||||
}
|
|
||||||
|
|
||||||
stages {
|
|
||||||
stage('Checkout') {
|
|
||||||
steps {
|
|
||||||
scmSkip(deleteBuild: false, skipPattern:'.*\\[ci skip\\].*')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
stage("Notify Discord") {
|
|
||||||
steps {
|
|
||||||
discordSend webhookURL: env.SSS_WEBHOOK,
|
|
||||||
title: "Deploy Started: ${projectName} ${majorMc} Deploy #${BUILD_NUMBER}",
|
|
||||||
link: env.BUILD_URL,
|
|
||||||
result: 'SUCCESS',
|
|
||||||
description: "Build: [${BUILD_NUMBER}](${env.BUILD_URL})"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
stage("Prepare") {
|
|
||||||
steps {
|
|
||||||
dir("${WORKSPACE}/${majorMc}") {
|
|
||||||
sh "chmod +x ./gradlew"
|
|
||||||
sh "./gradlew build -PreleaseType=${reltype}"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
stage("Publish to Maven") {
|
|
||||||
steps {
|
|
||||||
dir ("${WORKSPACE}/${majorMc}") {
|
|
||||||
catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') {
|
|
||||||
sh "./gradlew publish -PreleaseType=${reltype}"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
post {
|
|
||||||
always {
|
|
||||||
dir("${WORKSPACE}/${majorMc}") {
|
|
||||||
sh "./gradlew --stop"
|
|
||||||
archiveArtifacts artifacts: 'artifacts/*.jar'
|
|
||||||
|
|
||||||
fddsnapshotter apiKey: env.PLATFORM_KEY,
|
|
||||||
projectSlug: "craterlib",
|
|
||||||
projectName: "${projectName}",
|
|
||||||
projectIcon: "${projectIcon}",
|
|
||||||
modLoaders: "${modLoaders}",
|
|
||||||
minecraftVersions: "${supportedMc}",
|
|
||||||
type: "snapshot",
|
|
||||||
dependsOn: "",
|
|
||||||
failWebhook: env.SSS_WEBHOOK,
|
|
||||||
publishWebhooks: "${env.SSS_WEBHOOK}|${env.FDD_WH}"
|
|
||||||
|
|
||||||
deleteDir()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,71 +0,0 @@
|
|||||||
archivesBaseName = "${mod_name.replace(" ", "")}-Common-${minecraft_version}"
|
|
||||||
|
|
||||||
dependencies {
|
|
||||||
stupidRemapArch("dev.ftb.mods:ftb-ranks:${ftb_ranks}")
|
|
||||||
|
|
||||||
stupidRemapArch("me.shedaniel.cloth:cloth-config:${cloth_config}")
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
shadowJar {
|
|
||||||
from sourceSets.main.output
|
|
||||||
configurations = [project.configurations.shade]
|
|
||||||
|
|
||||||
dependencies {
|
|
||||||
exclude(dependency('com.google.code.gson:.*'))
|
|
||||||
|
|
||||||
relocate 'me.hypherionmc.moonconfig', 'shadow.hypherionmc.moonconfig'
|
|
||||||
relocate 'me.hypherionmc.mcdiscordformatter', 'shadow.hypherionmc.mcdiscordformatter'
|
|
||||||
relocate 'net.kyori', 'shadow.kyori'
|
|
||||||
}
|
|
||||||
setArchiveClassifier("dev")
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* ===============================================================================
|
|
||||||
* = DO NOT EDIT BELOW THIS LINE UNLESS YOU KNOW WHAT YOU ARE DOING =
|
|
||||||
* ===============================================================================
|
|
||||||
*/
|
|
||||||
|
|
||||||
unimined.minecraft {
|
|
||||||
fabric {
|
|
||||||
loader fabric_loader
|
|
||||||
}
|
|
||||||
|
|
||||||
defaultRemapJar = false
|
|
||||||
}
|
|
||||||
|
|
||||||
processResources {
|
|
||||||
def buildProps = project.properties.clone()
|
|
||||||
|
|
||||||
filesMatching(['pack.mcmeta']) {
|
|
||||||
expand buildProps
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Publishing Config
|
|
||||||
*/
|
|
||||||
publishing {
|
|
||||||
publications {
|
|
||||||
mavenCommon(MavenPublication) {
|
|
||||||
artifactId project.archivesBaseName
|
|
||||||
from components.java
|
|
||||||
|
|
||||||
pom.withXml {
|
|
||||||
Node pomNode = asNode()
|
|
||||||
pomNode.dependencies.'*'.findAll() {
|
|
||||||
it.artifactId.text() == 'regutils-joined-fabric' ||
|
|
||||||
it.artifactId.text() == 'core' ||
|
|
||||||
it.artifactId.text() == 'toml'
|
|
||||||
}.each() {
|
|
||||||
it.parent().remove(it)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
repositories {
|
|
||||||
maven rootProject.orion.getPublishingMaven()
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,163 +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.server.level.ServerPlayer;
|
|
||||||
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().getPlayerOrException()),
|
|
||||||
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().getPlayerOrException()),
|
|
||||||
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().getPlayerOrException()),
|
|
||||||
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().getPlayerOrException()),
|
|
||||||
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().getPlayerOrException()),
|
|
||||||
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().getPlayerOrException()),
|
|
||||||
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.getEntity() instanceof Player) || luckPermNode.isEmpty())
|
|
||||||
return stack.hasPermission(this.permLevel);
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
CraterConstants.LOG.error("Failed to check luckperms permissions", e);
|
|
||||||
return stack.hasPermission(this.permLevel);
|
|
||||||
}
|
|
||||||
return LuckPermsCompat.INSTANCE.hasPermission((ServerPlayer) stack.getEntity(), this.luckPermNode) || 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);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -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().getPlayerOrException();
|
|
||||||
|
|
||||||
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.getComponent(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,28 +0,0 @@
|
|||||||
package com.hypherionmc.craterlib.api.networking;
|
|
||||||
|
|
||||||
import com.hypherionmc.craterlib.nojang.server.BridgedMinecraftServer;
|
|
||||||
import com.hypherionmc.craterlib.nojang.world.entity.player.BridgedPlayer;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Based on https://github.com/mysticdrew/common-networking/tree/1.20.4
|
|
||||||
*/
|
|
||||||
public interface CraterNetworkHandler {
|
|
||||||
|
|
||||||
<T> void sendToServer(T packet);
|
|
||||||
|
|
||||||
<T> void sendToServer(T packet, boolean ignoreCheck);
|
|
||||||
|
|
||||||
<T> void sendToClient(T packet, BridgedPlayer player);
|
|
||||||
|
|
||||||
default <T> void sendToClients(T packet, List<BridgedPlayer> players) {
|
|
||||||
for (BridgedPlayer player : players) {
|
|
||||||
sendToClient(packet, player);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
default <T> void sendToAllClients(T packet, BridgedMinecraftServer server) {
|
|
||||||
sendToClients(packet, server.getPlayers());
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,411 +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 net.minecraft.network.chat.TextComponent;
|
|
||||||
import net.minecraft.network.chat.TranslatableComponent;
|
|
||||||
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(new TextComponent("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(
|
|
||||||
new TranslatableComponent("cl.buttons.entry", (i + 1)),
|
|
||||||
new TranslatableComponent("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(
|
|
||||||
new TextComponent(""),
|
|
||||||
new TranslatableComponent("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(new TextComponent("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(
|
|
||||||
new TranslatableComponent("cl.config." + baseConfig.getClass().getSimpleName().toLowerCase() + "." + field.getName().toLowerCase()),
|
|
||||||
new TranslatableComponent("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()),
|
|
||||||
new TranslatableComponent("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 = new TextComponent("");
|
|
||||||
|
|
||||||
if (field.isAnnotationPresent(SpecComment.class)) {
|
|
||||||
SpecComment comment = field.getAnnotation(SpecComment.class);
|
|
||||||
component = new TextComponent(comment.value());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (field.isAnnotationPresent(Tooltip.class)) {
|
|
||||||
Tooltip tooltip = field.getAnnotation(Tooltip.class);
|
|
||||||
Component c = new TextComponent("");
|
|
||||||
|
|
||||||
for (String comment : tooltip.value()) {
|
|
||||||
c.getSiblings().add(new TextComponent(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 new TranslatableComponent(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().getToasts().addToast(
|
|
||||||
new SystemToast(
|
|
||||||
SystemToast.SystemToastIds.PACK_LOAD_FAILURE,
|
|
||||||
new TextComponent("Failed To Save Config"),
|
|
||||||
new TextComponent("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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,395 +0,0 @@
|
|||||||
package com.hypherionmc.craterlib.client.gui.config;
|
|
||||||
|
|
||||||
import com.hypherionmc.craterlib.CraterConstants;
|
|
||||||
import com.hypherionmc.craterlib.client.gui.config.widgets.*;
|
|
||||||
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 com.mojang.blaze3d.systems.RenderSystem;
|
|
||||||
import com.mojang.blaze3d.vertex.*;
|
|
||||||
import com.mojang.math.Matrix4f;
|
|
||||||
import me.hypherionmc.moonconfig.core.conversion.SpecComment;
|
|
||||||
import net.minecraft.ChatFormatting;
|
|
||||||
import net.minecraft.client.gui.Font;
|
|
||||||
import net.minecraft.client.gui.screens.ConfirmScreen;
|
|
||||||
import net.minecraft.client.gui.screens.Screen;
|
|
||||||
import net.minecraft.client.renderer.GameRenderer;
|
|
||||||
import net.minecraft.network.chat.Component;
|
|
||||||
import net.minecraft.network.chat.TextComponent;
|
|
||||||
import net.minecraft.network.chat.TranslatableComponent;
|
|
||||||
import net.minecraft.resources.ResourceLocation;
|
|
||||||
import net.minecraft.util.Mth;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
|
||||||
import java.lang.reflect.Modifier;
|
|
||||||
import java.math.BigDecimal;
|
|
||||||
import java.math.BigInteger;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.function.Consumer;
|
|
||||||
import java.util.function.Function;
|
|
||||||
import java.util.function.Supplier;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author HypherionSA
|
|
||||||
*/
|
|
||||||
@Deprecated(forRemoval = true, since = "2.1.3")
|
|
||||||
public class CraterConfigScreen extends Screen {
|
|
||||||
public static final float SCROLLBAR_BOTTOM_COLOR = .5f;
|
|
||||||
public static final float SCROLLBAR_TOP_COLOR = .67f;
|
|
||||||
private static final int TOP = 26;
|
|
||||||
private static final int BOTTOM = 24;
|
|
||||||
private final Screen parent;
|
|
||||||
private final List<Option<?>> options = new ArrayList<>();
|
|
||||||
private final AbstractConfig config;
|
|
||||||
public double scrollerAmount;
|
|
||||||
private boolean dragging;
|
|
||||||
|
|
||||||
public CraterConfigScreen(AbstractConfig config, Screen parent, Object subConfig) {
|
|
||||||
super(new TranslatableComponent("cl." + config.getClass().getSimpleName().toLowerCase() + ".title"));
|
|
||||||
this.parent = parent;
|
|
||||||
this.config = config;
|
|
||||||
if (subConfig != null) {
|
|
||||||
setupScreenFromConfig(subConfig, subConfig.getClass());
|
|
||||||
} else {
|
|
||||||
setupScreenFromConfig(config, config.getClass());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public CraterConfigScreen(AbstractConfig config, Screen parent) {
|
|
||||||
this(config, parent, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Component toText(Enum<?> val) {
|
|
||||||
return new TranslatableComponent(val.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Component toText(Boolean bool) {
|
|
||||||
return new TranslatableComponent(bool.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setupScreenFromConfig(Object object, Class<?> clazz) {
|
|
||||||
while (clazz != Object.class) {
|
|
||||||
for (Field field : clazz.getDeclaredFields()) {
|
|
||||||
final int fieldModifiers = field.getModifiers();
|
|
||||||
if (object == null || Modifier.isStatic(fieldModifiers) || Modifier.isTransient(fieldModifiers)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (!field.isAccessible()) {
|
|
||||||
field.setAccessible(true);
|
|
||||||
}
|
|
||||||
if (field.isAnnotationPresent(HideFromScreen.class))
|
|
||||||
return;
|
|
||||||
Object val = field.get(object);
|
|
||||||
|
|
||||||
/* Lang Stuff */
|
|
||||||
String baseLangKey = "cl." + clazz.getSimpleName().toLowerCase() + "." + field.getName().toLowerCase();
|
|
||||||
String[] tooltipLang = field.isAnnotationPresent(SpecComment.class) ? new String[]{field.getAnnotation(SpecComment.class).value()} : new String[0];
|
|
||||||
if (field.isAnnotationPresent(Tooltip.class)) {
|
|
||||||
tooltipLang = field.getAnnotation(Tooltip.class).value();
|
|
||||||
}
|
|
||||||
|
|
||||||
add(new TranslatableComponent(baseLangKey),
|
|
||||||
val,
|
|
||||||
() -> val,
|
|
||||||
(ret) -> {
|
|
||||||
try {
|
|
||||||
field.set(object, ret);
|
|
||||||
config.saveConfig(config);
|
|
||||||
} catch (IllegalAccessException e) {
|
|
||||||
CraterConstants.LOG.error("Failed to update value for field {} in config {}", field.getName(), config.getConfigName(), e);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
field.isAnnotationPresent(SubConfig.class),
|
|
||||||
tooltipLang
|
|
||||||
);
|
|
||||||
} catch (IllegalAccessException e) {
|
|
||||||
CraterConstants.LOG.error("Failed to access value for field {} in config {}", field.getName(), config.getConfigName(), e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
clazz = clazz.getSuperclass();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public <T> void add(Component text, T value, @Nullable Supplier<T> defaultValue, Consumer<T> savingConsumer, boolean isSubConfig, String... langKeys) {
|
|
||||||
Option<T> option = (Option<T>) createOption(value, isSubConfig);
|
|
||||||
option.text = text;
|
|
||||||
option.defaultValue = defaultValue;
|
|
||||||
option.savingConsumer = savingConsumer;
|
|
||||||
option.originalValue = value;
|
|
||||||
option.value = value;
|
|
||||||
option.setLangKeys(List.of(langKeys));
|
|
||||||
options.add(option);
|
|
||||||
option.onAdd();
|
|
||||||
}
|
|
||||||
|
|
||||||
private <T> Option<?> createOption(T value, boolean isSubConfig) {
|
|
||||||
if (value instanceof Enum) {
|
|
||||||
Object[] objects = value.getClass().getEnumConstants();
|
|
||||||
return new ToggleButton<Enum<?>>((List) Arrays.asList(objects), CraterConfigScreen::toText);
|
|
||||||
}
|
|
||||||
if (value instanceof Boolean) {
|
|
||||||
return new ToggleButton<>(Arrays.asList(Boolean.TRUE, Boolean.FALSE), CraterConfigScreen::toText);
|
|
||||||
}
|
|
||||||
if (value instanceof String) {
|
|
||||||
return new TextConfigOption<>(Function.identity(), Function.identity());
|
|
||||||
}
|
|
||||||
if (value instanceof Integer) {
|
|
||||||
return new TextConfigOption<>(Objects::toString, Integer::valueOf);
|
|
||||||
}
|
|
||||||
if (value instanceof Long) {
|
|
||||||
return new TextConfigOption<>(Objects::toString, Long::valueOf);
|
|
||||||
}
|
|
||||||
if (value instanceof Double) {
|
|
||||||
return new TextConfigOption<>(Objects::toString, Double::valueOf);
|
|
||||||
}
|
|
||||||
if (value instanceof Float) {
|
|
||||||
return new TextConfigOption<>(Objects::toString, Float::valueOf);
|
|
||||||
}
|
|
||||||
if (value instanceof BigInteger) {
|
|
||||||
return new TextConfigOption<>(Objects::toString, BigInteger::new);
|
|
||||||
}
|
|
||||||
if (value instanceof BigDecimal) {
|
|
||||||
return new TextConfigOption<>(Objects::toString, BigDecimal::new);
|
|
||||||
}
|
|
||||||
if (value instanceof ResourceLocation) {
|
|
||||||
return new TextConfigOption<>(Objects::toString, ResourceLocation::new);
|
|
||||||
}
|
|
||||||
if (isSubConfig) {
|
|
||||||
return new SubConfigWidget<>(config, this, value);
|
|
||||||
}
|
|
||||||
throw new IllegalArgumentException(String.valueOf(value));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void init() {
|
|
||||||
super.init();
|
|
||||||
((List) children()).addAll(options);
|
|
||||||
|
|
||||||
int buttonWidths = Math.min(200, (width - 50 - 12) / 3);
|
|
||||||
addRenderableWidget(new InternalConfigButton(this, width / 2 - buttonWidths - 3, height - 22, buttonWidths, 20, new TextComponent(""), true));
|
|
||||||
addRenderableWidget(new InternalConfigButton(this, width / 2 + 3, height - 22, buttonWidths, 20, new TextComponent(""), false));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void render(@NotNull PoseStack matrices, int mouseX, int mouseY, float delta) {
|
|
||||||
overlayBackground(matrices, TOP, height - BOTTOM, 32);
|
|
||||||
|
|
||||||
renderScrollBar();
|
|
||||||
|
|
||||||
matrices.pushPose();
|
|
||||||
matrices.translate(0, 0, 500.0);
|
|
||||||
overlayBackground(matrices, 0, TOP, 64);
|
|
||||||
overlayBackground(matrices, height - BOTTOM, height, 64);
|
|
||||||
renderShadow(matrices);
|
|
||||||
drawCenteredString(matrices, font, getTitle(), width / 2, 9, 0xFFFFFF);
|
|
||||||
super.render(matrices, mouseX, mouseY, delta);
|
|
||||||
matrices.popPose();
|
|
||||||
|
|
||||||
int y = (int) (TOP + 4 - Math.round(scrollerAmount));
|
|
||||||
for (Option<?> option : options) {
|
|
||||||
int height1 = option.height();
|
|
||||||
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]));
|
|
||||||
y += height1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void renderScrollBar() {
|
|
||||||
int listHeight = height - BOTTOM - TOP;
|
|
||||||
int totalHeight = totalHeight();
|
|
||||||
if (totalHeight > listHeight) {
|
|
||||||
int maxScroll = Math.max(0, totalHeight - listHeight);
|
|
||||||
int height = listHeight * listHeight / totalHeight;
|
|
||||||
height = Mth.clamp(height, 32, listHeight);
|
|
||||||
height = Math.max(10, height);
|
|
||||||
int minY = Math.min(Math.max((int) scrollerAmount * (listHeight - height) / maxScroll + TOP, TOP), this.height - BOTTOM - height);
|
|
||||||
|
|
||||||
int scrollbarPositionMaxX = width;
|
|
||||||
int scrollbarPositionMinX = scrollbarPositionMaxX - 6;
|
|
||||||
|
|
||||||
int maxY = this.height - BOTTOM;
|
|
||||||
//RenderSystem.disableTexture();
|
|
||||||
Tesselator tesselator = Tesselator.getInstance();
|
|
||||||
BufferBuilder buffer = tesselator.getBuilder();
|
|
||||||
RenderSystem.setShader(GameRenderer::getPositionColorShader);
|
|
||||||
buffer.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR);
|
|
||||||
|
|
||||||
buffer.vertex(scrollbarPositionMinX, maxY, 0.0D).color(0, 0, 0, 255).endVertex();
|
|
||||||
buffer.vertex(scrollbarPositionMaxX, maxY, 0.0D).color(0, 0, 0, 255).endVertex();
|
|
||||||
buffer.vertex(scrollbarPositionMaxX, TOP, 0.0D).color(0, 0, 0, 255).endVertex();
|
|
||||||
buffer.vertex(scrollbarPositionMinX, TOP, 0.0D).color(0, 0, 0, 255).endVertex();
|
|
||||||
|
|
||||||
buffer.vertex(scrollbarPositionMinX, minY + height, 0.0D).color(SCROLLBAR_BOTTOM_COLOR, SCROLLBAR_BOTTOM_COLOR, SCROLLBAR_BOTTOM_COLOR, 1).endVertex();
|
|
||||||
buffer.vertex(scrollbarPositionMaxX, minY + height, 0.0D).color(SCROLLBAR_BOTTOM_COLOR, SCROLLBAR_BOTTOM_COLOR, SCROLLBAR_BOTTOM_COLOR, 1).endVertex();
|
|
||||||
buffer.vertex(scrollbarPositionMaxX, minY, 0.0D).color(SCROLLBAR_BOTTOM_COLOR, SCROLLBAR_BOTTOM_COLOR, SCROLLBAR_BOTTOM_COLOR, 1).endVertex();
|
|
||||||
buffer.vertex(scrollbarPositionMinX, minY, 0.0D).color(SCROLLBAR_BOTTOM_COLOR, SCROLLBAR_BOTTOM_COLOR, SCROLLBAR_BOTTOM_COLOR, 1).endVertex();
|
|
||||||
buffer.vertex(scrollbarPositionMinX, (minY + height - 1), 0.0D).color(SCROLLBAR_TOP_COLOR, SCROLLBAR_TOP_COLOR, SCROLLBAR_TOP_COLOR, 1).endVertex();
|
|
||||||
buffer.vertex((scrollbarPositionMaxX - 1), (minY + height - 1), 0.0D).color(SCROLLBAR_TOP_COLOR, SCROLLBAR_TOP_COLOR, SCROLLBAR_TOP_COLOR, 1).endVertex();
|
|
||||||
buffer.vertex((scrollbarPositionMaxX - 1), minY, 0.0D).color(SCROLLBAR_TOP_COLOR, SCROLLBAR_TOP_COLOR, SCROLLBAR_TOP_COLOR, 1).endVertex();
|
|
||||||
buffer.vertex(scrollbarPositionMinX, minY, 0.0D).color(SCROLLBAR_TOP_COLOR, SCROLLBAR_TOP_COLOR, SCROLLBAR_TOP_COLOR, 1).endVertex();
|
|
||||||
tesselator.end();
|
|
||||||
RenderSystem.disableBlend();
|
|
||||||
//RenderSystem.enableTexture();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void renderShadow(PoseStack matrices) {
|
|
||||||
Tesselator tesselator = Tesselator.getInstance();
|
|
||||||
BufferBuilder buffer = tesselator.getBuilder();
|
|
||||||
RenderSystem.enableBlend();
|
|
||||||
RenderSystem.blendFuncSeparate(770, 771, 0, 1);
|
|
||||||
//RenderSystem.disableTexture();
|
|
||||||
RenderSystem.setShader(GameRenderer::getPositionTexColorShader);
|
|
||||||
Matrix4f matrix = matrices.last().pose();
|
|
||||||
buffer.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX_COLOR);
|
|
||||||
buffer.vertex(matrix, 0, TOP + 4, 0.0F).uv(0, 1).color(0, 0, 0, 0).endVertex();
|
|
||||||
buffer.vertex(matrix, width, TOP + 4, 0.0F).uv(1, 1).color(0, 0, 0, 0).endVertex();
|
|
||||||
buffer.vertex(matrix, width, TOP, 0.0F).uv(1, 0).color(0, 0, 0, 185).endVertex();
|
|
||||||
buffer.vertex(matrix, 0, TOP, 0.0F).uv(0, 0).color(0, 0, 0, 185).endVertex();
|
|
||||||
buffer.vertex(matrix, 0, height - BOTTOM, 0.0F).uv(0, 1).color(0, 0, 0, 185).endVertex();
|
|
||||||
buffer.vertex(matrix, width, height - BOTTOM, 0.0F).uv(1, 1).color(0, 0, 0, 185).endVertex();
|
|
||||||
buffer.vertex(matrix, width, height - BOTTOM - 4, 0.0F).uv(1, 0).color(0, 0, 0, 0).endVertex();
|
|
||||||
buffer.vertex(matrix, 0, height - BOTTOM - 4, 0.0F).uv(0, 0).color(0, 0, 0, 0).endVertex();
|
|
||||||
tesselator.end();
|
|
||||||
//RenderSystem.enableTexture();
|
|
||||||
RenderSystem.disableBlend();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void overlayBackground(PoseStack matrices, int h1, int h2, int color) {
|
|
||||||
overlayBackground(matrices.last().pose(), 0, h1, width, h2, color, color, color, 255, 255);
|
|
||||||
}
|
|
||||||
|
|
||||||
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();
|
|
||||||
BufferBuilder buffer = tesselator.getBuilder();
|
|
||||||
RenderSystem.setShaderTexture(0, Screen.BACKGROUND_LOCATION);
|
|
||||||
RenderSystem.setShaderColor(1.0f, 1.0f, 1.0f, 1.0f);
|
|
||||||
RenderSystem.setShader(GameRenderer::getPositionTexColorShader);
|
|
||||||
buffer.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX_COLOR);
|
|
||||||
buffer.vertex(matrix, minX, maxY, 0.0F).uv(minX / 32.0F, maxY / 32.0F).color(red, green, blue, endAlpha).endVertex();
|
|
||||||
buffer.vertex(matrix, maxX, maxY, 0.0F).uv(maxX / 32.0F, maxY / 32.0F).color(red, green, blue, endAlpha).endVertex();
|
|
||||||
buffer.vertex(matrix, maxX, minY, 0.0F).uv(maxX / 32.0F, minY / 32.0F).color(red, green, blue, startAlpha).endVertex();
|
|
||||||
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() {
|
|
||||||
int totalHeight = totalHeight();
|
|
||||||
int listHeight = height - BOTTOM - TOP;
|
|
||||||
if (totalHeight <= listHeight) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return totalHeight - listHeight;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int totalHeight() {
|
|
||||||
int i = 8;
|
|
||||||
for (Option<?> option : options) {
|
|
||||||
i += option.height();
|
|
||||||
}
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean hasErrors() {
|
|
||||||
for (Option<?> option : options) {
|
|
||||||
if (option.hasErrors) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isEdited() {
|
|
||||||
for (Option<?> option : options) {
|
|
||||||
if (option.isEdited()) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void save() {
|
|
||||||
for (Option option : options) {
|
|
||||||
option.save();
|
|
||||||
option.originalValue = option.value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onClose() {
|
|
||||||
if (isEdited()) {
|
|
||||||
minecraft.setScreen(new ConfirmScreen(this::acceptConfirm, new TranslatableComponent("t.clc.quit_config"),
|
|
||||||
new TranslatableComponent("t.clc.quit_config_sure"),
|
|
||||||
new TranslatableComponent("t.clc.quit_discard"),
|
|
||||||
new TranslatableComponent("gui.cancel")));
|
|
||||||
} else {
|
|
||||||
minecraft.setScreen(parent);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean mouseScrolled(double d, double e, double f) {
|
|
||||||
if (e >= TOP && e <= height - BOTTOM) {
|
|
||||||
scrollerAmount = Mth.clamp(scrollerAmount - f * 16.0D, 0, scrollHeight());
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return super.mouseScrolled(d, e, f);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean mouseClicked(double d, double e, int i) {
|
|
||||||
this.dragging = i == 0 && d >= width - 6 && d < width;
|
|
||||||
return super.mouseClicked(d, e, i) || dragging;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean mouseDragged(double d, double e, int i, double f, double g) {
|
|
||||||
if (super.mouseDragged(d, e, i, f, g)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (i != 0 || !this.dragging) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (e < TOP) {
|
|
||||||
scrollerAmount = 0;
|
|
||||||
} else if (e > height - BOTTOM) {
|
|
||||||
scrollerAmount = scrollHeight();
|
|
||||||
} else {
|
|
||||||
double h = Math.max(1, this.scrollHeight());
|
|
||||||
int j = height - BOTTOM - TOP;
|
|
||||||
int k = Mth.clamp((int) ((float) (j * j) / (float) this.scrollHeight()), 32, j - 8);
|
|
||||||
double l = Math.max(1.0, h / (double) (j - k));
|
|
||||||
scrollerAmount = Mth.clamp(scrollerAmount + g * l, 0, scrollHeight());
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void acceptConfirm(boolean t) {
|
|
||||||
if (!t) {
|
|
||||||
minecraft.setScreen(this);
|
|
||||||
} else {
|
|
||||||
minecraft.setScreen(parent);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void renderConfigTooltip(PoseStack stack, Font font, int mouseX, int mouseY, int startX, int startY, int sizeX, int sizeY, String title, String... description) {
|
|
||||||
if (mouseX > startX && mouseX < startX + sizeX) {
|
|
||||||
if (mouseY > startY && mouseY < startY + sizeY) {
|
|
||||||
List<Component> list = new ArrayList<>();
|
|
||||||
list.add(new TranslatableComponent(ChatFormatting.BOLD + "" + ChatFormatting.YELLOW + title));
|
|
||||||
for (String desc : description) {
|
|
||||||
list.add(new TranslatableComponent(desc));
|
|
||||||
}
|
|
||||||
renderComponentTooltip(stack, list, mouseX, mouseY);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,62 +0,0 @@
|
|||||||
package com.hypherionmc.craterlib.client.gui.config.widgets;
|
|
||||||
|
|
||||||
import com.mojang.blaze3d.vertex.PoseStack;
|
|
||||||
import net.minecraft.ChatFormatting;
|
|
||||||
import net.minecraft.client.Minecraft;
|
|
||||||
import net.minecraft.client.gui.Font;
|
|
||||||
import net.minecraft.client.gui.components.Button;
|
|
||||||
import net.minecraft.network.chat.MutableComponent;
|
|
||||||
import net.minecraft.network.chat.TextColor;
|
|
||||||
import net.minecraft.network.chat.TextComponent;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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>
|
|
||||||
*/
|
|
||||||
@Deprecated(forRemoval = true, since = "2.1.3")
|
|
||||||
public class BaseWidget<T> extends Option<T> {
|
|
||||||
|
|
||||||
public static final int resetButtonOffset = 48;
|
|
||||||
private final Button resetButton = addChild(new Button(0, 0, 46, 20, new TextComponent("Reset"), this::onResetPressed));
|
|
||||||
private boolean hideReset = false;
|
|
||||||
|
|
||||||
private boolean isSubConfig = false;
|
|
||||||
|
|
||||||
private void onResetPressed(Button button) {
|
|
||||||
value = defaultValue.get();
|
|
||||||
reset();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void hideReset() {
|
|
||||||
this.hideReset = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isSubConfig() {
|
|
||||||
return isSubConfig;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSubConfig(boolean subConfig) {
|
|
||||||
isSubConfig = subConfig;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void render(Minecraft minecraft, Font font, int x, int y, int width, int height, PoseStack matrices, int mouseX, int mouseY, float delta) {
|
|
||||||
MutableComponent text = new TextComponent(this.text.getString());
|
|
||||||
boolean edited = isEdited() || hasErrors;
|
|
||||||
if (edited) {
|
|
||||||
text.withStyle(ChatFormatting.ITALIC);
|
|
||||||
if (hasErrors) {
|
|
||||||
text.withStyle(style -> style.withColor(TextColor.fromRgb(16733525)));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
text.withStyle(ChatFormatting.GRAY);
|
|
||||||
}
|
|
||||||
font.draw(matrices, text, x, y, 0xFFFFFF);
|
|
||||||
resetButton.x = (x + width - 46);
|
|
||||||
resetButton.y = (y + 1);
|
|
||||||
resetButton.active = isNotDefault();
|
|
||||||
if (!hideReset) {
|
|
||||||
resetButton.render(matrices, mouseX, mouseY, delta);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,129 +0,0 @@
|
|||||||
package com.hypherionmc.craterlib.client.gui.config.widgets;
|
|
||||||
|
|
||||||
import com.mojang.blaze3d.platform.Window;
|
|
||||||
import com.mojang.blaze3d.vertex.PoseStack;
|
|
||||||
import me.shedaniel.clothconfig2.api.AbstractConfigListEntry;
|
|
||||||
import net.minecraft.client.Minecraft;
|
|
||||||
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 net.minecraft.network.chat.TextComponent;
|
|
||||||
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 = new Button(0, 0, mainButtonWidth, 20, fieldName, onPress);
|
|
||||||
this.deleteButton = deletePress != null ? new Button(0, 0, 20, 20, new TextComponent("X"), deletePress) : null;
|
|
||||||
this.displayName = displayName;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void render(PoseStack 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()) {
|
|
||||||
drawString(matrices, Minecraft.getInstance().font, displayedFieldName.getVisualOrderText(), window.getGuiScaledWidth() - x - Minecraft.getInstance().font.width(displayedFieldName), y + 6, 16777215);
|
|
||||||
this.button.x = x;
|
|
||||||
if (hasDeleteButton) {
|
|
||||||
this.deleteButton.x = x + this.button.getWidth() + 4;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
drawString(matrices, Minecraft.getInstance().font, displayedFieldName.getVisualOrderText(), x, y + 6, this.getPreferredTextColor());
|
|
||||||
if (hasDeleteButton) {
|
|
||||||
this.button.x = x + entryWidth - this.button.getWidth() - 24;
|
|
||||||
this.deleteButton.x = x + entryWidth - 20;
|
|
||||||
} else {
|
|
||||||
this.button.x = x + entryWidth - this.button.getWidth();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
button.y = y + (entryHeight - 20) / 2;
|
|
||||||
button.render(matrices, mouseX, mouseY, delta);
|
|
||||||
|
|
||||||
if (hasDeleteButton) {
|
|
||||||
deleteButton.y = 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;
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,54 +0,0 @@
|
|||||||
package com.hypherionmc.craterlib.client.gui.config.widgets;
|
|
||||||
|
|
||||||
import com.hypherionmc.craterlib.client.gui.config.CraterConfigScreen;
|
|
||||||
import com.mojang.blaze3d.vertex.PoseStack;
|
|
||||||
import net.minecraft.client.gui.components.AbstractButton;
|
|
||||||
import net.minecraft.client.gui.narration.NarratedElementType;
|
|
||||||
import net.minecraft.client.gui.narration.NarrationElementOutput;
|
|
||||||
import net.minecraft.network.chat.Component;
|
|
||||||
import net.minecraft.network.chat.TranslatableComponent;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author HypherionSA
|
|
||||||
*/
|
|
||||||
@Deprecated(forRemoval = true, since = "2.1.3")
|
|
||||||
public class InternalConfigButton extends AbstractButton {
|
|
||||||
|
|
||||||
CraterConfigScreen screen;
|
|
||||||
boolean cancel;
|
|
||||||
|
|
||||||
public InternalConfigButton(CraterConfigScreen screen, int i, int j, int k, int l, Component component, boolean cancel) {
|
|
||||||
super(i, j, k, l, component);
|
|
||||||
this.screen = screen;
|
|
||||||
this.cancel = cancel;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void render(@NotNull PoseStack poseStack, int i, int j, float f) {
|
|
||||||
if (cancel) {
|
|
||||||
setMessage(new TranslatableComponent(screen.isEdited() ? "t.clc.cancel_discard" : "gui.cancel"));
|
|
||||||
} else {
|
|
||||||
boolean hasErrors = screen.hasErrors();
|
|
||||||
active = screen.isEdited() && !hasErrors;
|
|
||||||
setMessage(new TranslatableComponent(hasErrors ? "t.clc.error" : "t.clc.save"));
|
|
||||||
}
|
|
||||||
super.render(poseStack, i, j, f);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void updateNarration(NarrationElementOutput narrationElementOutput) {
|
|
||||||
narrationElementOutput.add(NarratedElementType.USAGE, getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onPress() {
|
|
||||||
if (cancel) {
|
|
||||||
screen.onClose();
|
|
||||||
} else {
|
|
||||||
screen.save();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
@@ -1,72 +0,0 @@
|
|||||||
package com.hypherionmc.craterlib.client.gui.config.widgets;
|
|
||||||
|
|
||||||
import com.mojang.blaze3d.vertex.PoseStack;
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.Setter;
|
|
||||||
import net.minecraft.client.Minecraft;
|
|
||||||
import net.minecraft.client.gui.Font;
|
|
||||||
import net.minecraft.client.gui.components.events.AbstractContainerEventHandler;
|
|
||||||
import net.minecraft.client.gui.components.events.GuiEventListener;
|
|
||||||
import net.minecraft.network.chat.Component;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.function.Consumer;
|
|
||||||
import java.util.function.Supplier;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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>
|
|
||||||
*/
|
|
||||||
@Deprecated(forRemoval = true, since = "2.1.3")
|
|
||||||
public abstract class Option<T> extends AbstractContainerEventHandler {
|
|
||||||
|
|
||||||
public Component text;
|
|
||||||
@Nullable
|
|
||||||
public Supplier<T> defaultValue;
|
|
||||||
public Consumer<T> savingConsumer;
|
|
||||||
public T originalValue;
|
|
||||||
public T value;
|
|
||||||
public boolean hasErrors;
|
|
||||||
public List<? extends GuiEventListener> children = new ArrayList<>();
|
|
||||||
@Setter
|
|
||||||
@Getter
|
|
||||||
private List<String> langKeys = new ArrayList<>();
|
|
||||||
|
|
||||||
public abstract void render(Minecraft minecraft, Font font, int x, int y, int width, int height, PoseStack matrices, int mouseX, int mouseY, float delta);
|
|
||||||
|
|
||||||
public int height() {
|
|
||||||
return 22;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<? extends GuiEventListener> children() {
|
|
||||||
return children;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected <R extends GuiEventListener> R addChild(R listener) {
|
|
||||||
((List) children).add(listener);
|
|
||||||
return listener;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onAdd() {
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void reset() {
|
|
||||||
onAdd();
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isEdited() {
|
|
||||||
return !Objects.equals(originalValue, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected boolean isNotDefault() {
|
|
||||||
return defaultValue != null && !Objects.equals(defaultValue.get(), value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void save() {
|
|
||||||
savingConsumer.accept(value);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,35 +0,0 @@
|
|||||||
package com.hypherionmc.craterlib.client.gui.config.widgets;
|
|
||||||
|
|
||||||
import net.minecraft.client.gui.components.Button;
|
|
||||||
import net.minecraft.network.chat.Component;
|
|
||||||
import net.minecraft.network.chat.TextComponent;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.function.Function;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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>
|
|
||||||
*/
|
|
||||||
@Deprecated(forRemoval = true, since = "2.1.3")
|
|
||||||
public class ToggleButton<T> extends AbstractConfigWidget<T, Button> {
|
|
||||||
|
|
||||||
private final List<T> options;
|
|
||||||
private final Function<T, Component> toComponent;
|
|
||||||
|
|
||||||
public ToggleButton(List<T> options, Function<T, Component> toComponent) {
|
|
||||||
this.options = options;
|
|
||||||
this.toComponent = toComponent;
|
|
||||||
this.widget = addChild(new Button(0, 0, buttonWidth, buttonHeight, new TextComponent(""), this::switchNext));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onAdd() {
|
|
||||||
widget.setMessage(toComponent.apply(value));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void switchNext(Button button) {
|
|
||||||
value = options.get((options.indexOf(value) + 1) % options.size());
|
|
||||||
onAdd();
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,30 +0,0 @@
|
|||||||
package com.hypherionmc.craterlib.client.gui.config.widgets;
|
|
||||||
|
|
||||||
import net.minecraft.client.Minecraft;
|
|
||||||
import net.minecraft.client.gui.Font;
|
|
||||||
import net.minecraft.client.gui.components.EditBox;
|
|
||||||
import net.minecraft.client.gui.components.events.GuiEventListener;
|
|
||||||
import net.minecraft.network.chat.Component;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author HypherionSA
|
|
||||||
*/
|
|
||||||
@Deprecated(forRemoval = true, since = "2.1.3")
|
|
||||||
public class WrappedEditBox extends EditBox {
|
|
||||||
|
|
||||||
public WrappedEditBox(Font font, int i, int j, int k, int l, @NotNull Component component) {
|
|
||||||
super(font, i, j, k, l, component);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setFocused(boolean bl) {
|
|
||||||
for (GuiEventListener child : Minecraft.getInstance().screen.children()) {
|
|
||||||
if (child instanceof TextConfigOption<?> option) {
|
|
||||||
WrappedEditBox box = option.widget;
|
|
||||||
super.setFocused(box == this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
super.setFocused(bl);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -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) {
|
|
||||||
FTBEPlayerData data = FTBEPlayerData.get(player.toMojang());
|
|
||||||
return data != null && data.muted;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -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.INSTANCE.getManager().getAddedRanks(profile.toMojang()).forEach(rank -> ranks.add(BridgedRank.of(rank)));
|
|
||||||
return ranks;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<BridgedRank> getAllRanks() {
|
|
||||||
List<BridgedRank> ranks = new ArrayList<>();
|
|
||||||
FTBRanksAPI.INSTANCE.getManager().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.INSTANCE.getManager().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.INSTANCE.getManager().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()));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -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,63 +0,0 @@
|
|||||||
package com.hypherionmc.craterlib.core.config;
|
|
||||||
|
|
||||||
import com.hypherionmc.craterlib.CraterConstants;
|
|
||||||
import lombok.Getter;
|
|
||||||
import me.hypherionmc.moonconfig.core.file.FileWatcher;
|
|
||||||
import org.apache.commons.lang3.tuple.Pair;
|
|
||||||
import org.jetbrains.annotations.ApiStatus;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.HashSet;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author HypherionSA
|
|
||||||
* Controls Config File Reloads and Events
|
|
||||||
*/
|
|
||||||
public final class ConfigController implements Serializable {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Cache of registered configs
|
|
||||||
*/
|
|
||||||
@Getter
|
|
||||||
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
|
|
||||||
*
|
|
||||||
* @param config - The config class to register and watch
|
|
||||||
*/
|
|
||||||
@ApiStatus.Internal
|
|
||||||
@Deprecated
|
|
||||||
public static void register_config(ModuleConfig config) {
|
|
||||||
register_config((AbstractConfig) config);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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 {
|
|
||||||
try {
|
|
||||||
watcher.addWatch(config.getConfigPath(), () -> {
|
|
||||||
if (!config.isWasSaveCalled()) {
|
|
||||||
CraterConstants.LOG.info("Sending Reload Event for: {}", config.getConfigPath().getName());
|
|
||||||
config.configReloaded();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} catch (Exception e) {
|
|
||||||
CraterConstants.LOG.error("Failed to register {} for auto reloading. {}", config.getConfigPath().getName(), e.getMessage());
|
|
||||||
}
|
|
||||||
watchedConfigs.put(config.getConfigPath().toString(), config);
|
|
||||||
CraterConstants.LOG.info("Registered {} successfully!", config.getConfigPath().getName());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,120 +0,0 @@
|
|||||||
package com.hypherionmc.craterlib.core.config;
|
|
||||||
|
|
||||||
import com.hypherionmc.craterlib.core.config.formats.TomlConfigFormat;
|
|
||||||
import me.hypherionmc.moonconfig.core.CommentedConfig;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author HypherionSA
|
|
||||||
* Base Config class containing the save, upgrading and loading logic.
|
|
||||||
* All config classes must extend this class
|
|
||||||
*/
|
|
||||||
@Deprecated(forRemoval = true, since = "2.1.0")
|
|
||||||
public class ModuleConfig extends AbstractConfig {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set up the config
|
|
||||||
*
|
|
||||||
* @param modId - The ID of the Mod/Module the config belongs to
|
|
||||||
* @param configName - The name of the config file, excluding extension
|
|
||||||
*/
|
|
||||||
public ModuleConfig(String modId, String configName) {
|
|
||||||
this(modId, "", configName);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ModuleConfig(String modId, String subFolder, String configName) {
|
|
||||||
super(modId, subFolder.isEmpty() ? null : subFolder, configName);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This method has to be called in the config constructor. This creates or upgrades the config file as needed
|
|
||||||
*
|
|
||||||
* @param config - The config class to use
|
|
||||||
*/
|
|
||||||
public void registerAndSetup(ModuleConfig config) {
|
|
||||||
super.registerAndSetup(config);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Save the config to the disk
|
|
||||||
*
|
|
||||||
* @param conf - The config class to serialize and save
|
|
||||||
*/
|
|
||||||
public void saveConfig(ModuleConfig conf) {
|
|
||||||
super.registerAndSetup(conf);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Load the config from the file into a Class
|
|
||||||
*
|
|
||||||
* @param conf - The config Class to load
|
|
||||||
* @return - Returns the loaded version of the class
|
|
||||||
*/
|
|
||||||
public <T> T loadConfig(Object conf) {
|
|
||||||
return (T) super.readConfig(conf);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* INTERNAL METHOD - Upgrades the config files in the events the config structure changes
|
|
||||||
*
|
|
||||||
* @param conf - The config class to load
|
|
||||||
*/
|
|
||||||
public void migrateConfig(ModuleConfig conf) {
|
|
||||||
super.migrateConfig(conf);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void updateConfigValues(CommentedConfig oldConfig, CommentedConfig newConfig, CommentedConfig outputConfig, String subKey) {
|
|
||||||
if (getConfigFormat() instanceof TomlConfigFormat<?> t) {
|
|
||||||
t.updateConfigValues(oldConfig, newConfig, outputConfig, subKey);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the location of the config file
|
|
||||||
*
|
|
||||||
* @return - The FILE object containing the config file
|
|
||||||
*/
|
|
||||||
public File getConfigPath() {
|
|
||||||
return super.getConfigPath();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the NETWORK SYNC ID
|
|
||||||
*
|
|
||||||
* @return - Returns the Sync ID in format modid:config_name
|
|
||||||
*/
|
|
||||||
public String getNetworkID() {
|
|
||||||
return super.getNetworkID();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Fired whenever changes to the config are detected
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void configReloaded() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the name of the Config File
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public String getConfigName() {
|
|
||||||
return super.getConfigName();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the MODID of the Module the config is registered to
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public String getModId() {
|
|
||||||
return super.getModId();
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isSaveCalled() {
|
|
||||||
return super.isWasSaveCalled();
|
|
||||||
}
|
|
||||||
}
|
|
@@ -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,30 +0,0 @@
|
|||||||
package com.hypherionmc.craterlib.core.event;
|
|
||||||
|
|
||||||
import com.hypherionmc.craterlib.core.event.annot.Cancellable;
|
|
||||||
import com.hypherionmc.craterlib.core.event.exception.CraterEventCancellationException;
|
|
||||||
|
|
||||||
public class CraterEvent {
|
|
||||||
|
|
||||||
private boolean canceled = false;
|
|
||||||
|
|
||||||
private boolean canCancel() {
|
|
||||||
return this.getClass().isAnnotationPresent(Cancellable.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void cancelEvent() {
|
|
||||||
try {
|
|
||||||
if (!this.canCancel()) {
|
|
||||||
throw new CraterEventCancellationException("Tried to cancel non-cancelable event: " + this.getClass().getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
this.canceled = true;
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean wasCancelled() {
|
|
||||||
return this.canceled;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,241 +0,0 @@
|
|||||||
package com.hypherionmc.craterlib.core.event;
|
|
||||||
|
|
||||||
import com.hypherionmc.craterlib.CraterConstants;
|
|
||||||
import com.hypherionmc.craterlib.core.event.annot.CraterEventListener;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
|
|
||||||
import java.lang.annotation.Annotation;
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.lang.reflect.Modifier;
|
|
||||||
import java.util.*;
|
|
||||||
import java.util.function.Consumer;
|
|
||||||
|
|
||||||
public final class CraterEventBus {
|
|
||||||
|
|
||||||
public static final CraterEventBus INSTANCE = new CraterEventBus();
|
|
||||||
private static final Logger LOGGER = CraterConstants.LOG;
|
|
||||||
private final Map<Class<? extends CraterEvent>, List<ListenerContainer>> events = new HashMap<>();
|
|
||||||
|
|
||||||
public void postEvent(CraterEvent event) {
|
|
||||||
if (eventsRegisteredForType(event.getClass())) {
|
|
||||||
List<ListenerContainer> l = new ArrayList<>(events.get(event.getClass()));
|
|
||||||
l.sort((o1, o2) -> Integer.compare(o2.priority, o1.priority));
|
|
||||||
|
|
||||||
for (ListenerContainer c : l) {
|
|
||||||
c.notifyListener(event);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void registerEventListener(Class<?> clazz) {
|
|
||||||
this.registerListenerMethods(this.getEventMethodsOf(clazz));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void registerEventListener(Object object) {
|
|
||||||
this.registerListenerMethods(this.getEventMethodsOf(object));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void registerListenerMethods(List<EventMethod> methods) {
|
|
||||||
for (EventMethod m : methods) {
|
|
||||||
Consumer<CraterEvent> listener = (event) -> {
|
|
||||||
try {
|
|
||||||
m.method.invoke(m.parentObject, event);
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
ListenerContainer container = new ListenerContainer(m.eventType, listener, m.priority);
|
|
||||||
container.listenerParentClassName = m.parentClass.getName();
|
|
||||||
container.listenerMethodName = m.method.getName();
|
|
||||||
this.registerListener(container);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<EventMethod> getEventMethodsOf(Object objectOrClass) {
|
|
||||||
List<EventMethod> l = new ArrayList<>();
|
|
||||||
try {
|
|
||||||
if (objectOrClass != null) {
|
|
||||||
boolean isClass = (objectOrClass instanceof Class<?>);
|
|
||||||
Class<?> c = isClass ? (Class<?>) objectOrClass : objectOrClass.getClass();
|
|
||||||
for (Method m : c.getMethods()) {
|
|
||||||
if (isClass && Modifier.isStatic(m.getModifiers())) {
|
|
||||||
EventMethod em = EventMethod.tryCreateFrom(new AnalyzedMethod(m, c));
|
|
||||||
if ((em != null) && this.hasEventAnnotation(em)) l.add(em);
|
|
||||||
}
|
|
||||||
if (!isClass && !Modifier.isStatic(m.getModifiers())) {
|
|
||||||
EventMethod em = EventMethod.tryCreateFrom(new AnalyzedMethod(m, objectOrClass));
|
|
||||||
if ((em != null) && this.hasEventAnnotation(em)) l.add(em);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
return l;
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean hasEventAnnotation(EventMethod m) {
|
|
||||||
for (Annotation a : m.annotations) {
|
|
||||||
if (a instanceof CraterEventListener) return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void registerListener(Consumer<CraterEvent> listener, Class<? extends CraterEvent> eventType) {
|
|
||||||
this.registerListener(listener, eventType, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void registerListener(Consumer<CraterEvent> listener, Class<? extends CraterEvent> eventType, int priority) {
|
|
||||||
this.registerListener(new ListenerContainer(eventType, listener, priority));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void registerListener(ListenerContainer listenerContainer) {
|
|
||||||
try {
|
|
||||||
if (!eventsRegisteredForType(listenerContainer.eventType)) {
|
|
||||||
events.put(listenerContainer.eventType, new ArrayList<>());
|
|
||||||
}
|
|
||||||
events.get(listenerContainer.eventType).add(listenerContainer);
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean eventsRegisteredForType(Class<? extends CraterEvent> eventType) {
|
|
||||||
if (eventType == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return this.events.containsKey(eventType);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected final static class ListenerContainer {
|
|
||||||
|
|
||||||
private final Consumer<CraterEvent> listener;
|
|
||||||
private final Class<? extends CraterEvent> eventType;
|
|
||||||
private final int priority;
|
|
||||||
private String listenerParentClassName = "[unknown]";
|
|
||||||
private String listenerMethodName = "[unknown]";
|
|
||||||
|
|
||||||
private ListenerContainer(Class<? extends CraterEvent> eventType, Consumer<CraterEvent> listener, int priority) {
|
|
||||||
this.eventType = eventType;
|
|
||||||
this.listener = listener;
|
|
||||||
this.priority = priority;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void notifyListener(CraterEvent event) {
|
|
||||||
try {
|
|
||||||
this.listener.accept(event);
|
|
||||||
} catch (Exception e) {
|
|
||||||
LOGGER.error("##################################");
|
|
||||||
LOGGER.error("Failed to notify event listener!");
|
|
||||||
LOGGER.error("Event Type: " + this.eventType.getName());
|
|
||||||
LOGGER.error("Listener Parent Class Name: " + this.listenerParentClassName);
|
|
||||||
LOGGER.error("Listener Method Name In Parent Class: " + this.listenerMethodName);
|
|
||||||
LOGGER.error("##################################");
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected static class AnalyzedMethod {
|
|
||||||
|
|
||||||
protected Method method;
|
|
||||||
protected Object parentObject;
|
|
||||||
protected Class<?> parentClass;
|
|
||||||
protected boolean isStatic;
|
|
||||||
protected List<Annotation> annotations = new ArrayList<>();
|
|
||||||
|
|
||||||
protected AnalyzedMethod() {
|
|
||||||
}
|
|
||||||
|
|
||||||
protected AnalyzedMethod(Method method, Object parentObjectOrClass) {
|
|
||||||
this.method = method;
|
|
||||||
this.parentObject = parentObjectOrClass;
|
|
||||||
this.parentClass = this.tryGetParentClass();
|
|
||||||
this.isStatic = Modifier.isStatic(method.getModifiers());
|
|
||||||
collectMethodAnnotations(this.isStatic ? null : this.parentObject.getClass(), this.method, this.annotations);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected static void collectMethodAnnotations(Class<?> c, Method m, List<Annotation> addToList) {
|
|
||||||
try {
|
|
||||||
addToList.addAll(Arrays.asList(m.getAnnotations()));
|
|
||||||
if (!Modifier.isStatic(m.getModifiers()) && (c != null)) {
|
|
||||||
Class<?> sc = c.getSuperclass();
|
|
||||||
if (sc != null) {
|
|
||||||
try {
|
|
||||||
Method sm = sc.getMethod(m.getName(), m.getParameterTypes());
|
|
||||||
collectMethodAnnotations(sc, sm, addToList);
|
|
||||||
} catch (Exception ignored) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (Exception ignored) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Class<?> tryGetParentClass() {
|
|
||||||
if (this.parentObject instanceof Class<?>) {
|
|
||||||
return (Class<?>) this.parentObject;
|
|
||||||
}
|
|
||||||
return this.parentObject.getClass();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
protected static class EventMethod extends AnalyzedMethod {
|
|
||||||
|
|
||||||
protected final int priority;
|
|
||||||
protected final Class<? extends CraterEvent> eventType;
|
|
||||||
|
|
||||||
protected EventMethod(AnalyzedMethod method) {
|
|
||||||
|
|
||||||
super();
|
|
||||||
this.method = method.method;
|
|
||||||
this.parentObject = method.parentObject;
|
|
||||||
this.parentClass = method.parentClass;
|
|
||||||
this.isStatic = method.isStatic;
|
|
||||||
this.annotations = method.annotations;
|
|
||||||
|
|
||||||
this.priority = this.tryGetPriority();
|
|
||||||
this.eventType = this.tryGetEventType();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
protected static EventMethod tryCreateFrom(AnalyzedMethod method) {
|
|
||||||
EventMethod em = new EventMethod(method);
|
|
||||||
return (em.eventType != null) ? em : null;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Class<? extends CraterEvent> tryGetEventType() {
|
|
||||||
try {
|
|
||||||
if (this.method != null) {
|
|
||||||
Class<?>[] params = this.method.getParameterTypes();
|
|
||||||
if (params.length > 0) {
|
|
||||||
Class<?> firstParam = params[0];
|
|
||||||
if (CraterEvent.class.isAssignableFrom(firstParam)) {
|
|
||||||
return (Class<? extends CraterEvent>) firstParam;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected int tryGetPriority() {
|
|
||||||
try {
|
|
||||||
for (Annotation a : this.annotations) {
|
|
||||||
if (a instanceof CraterEventListener craterEventListener) {
|
|
||||||
return craterEventListener.priority();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,13 +0,0 @@
|
|||||||
package com.hypherionmc.craterlib.core.event;
|
|
||||||
|
|
||||||
public class CraterEventPriority {
|
|
||||||
|
|
||||||
public static final int LOWEST = -3;
|
|
||||||
public static final int LOWER = -2;
|
|
||||||
public static final int LOW = -1;
|
|
||||||
public static final int NORMAL = 0;
|
|
||||||
public static final int HIGH = 1;
|
|
||||||
public static final int HIGHER = 2;
|
|
||||||
public static final int HIGHEST = 3;
|
|
||||||
|
|
||||||
}
|
|
@@ -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 {
|
|
||||||
}
|
|
@@ -1,43 +0,0 @@
|
|||||||
package com.hypherionmc.craterlib.core.networking;
|
|
||||||
|
|
||||||
import com.hypherionmc.craterlib.core.networking.data.PacketContext;
|
|
||||||
import com.hypherionmc.craterlib.nojang.network.BridgedFriendlyByteBuf;
|
|
||||||
import com.hypherionmc.craterlib.nojang.resources.ResourceIdentifier;
|
|
||||||
import lombok.Getter;
|
|
||||||
|
|
||||||
import java.util.function.BiConsumer;
|
|
||||||
import java.util.function.Consumer;
|
|
||||||
import java.util.function.Function;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Based on https://github.com/mysticdrew/common-networking/tree/1.20.4
|
|
||||||
*/
|
|
||||||
@Getter
|
|
||||||
public class CraterPacketNetwork {
|
|
||||||
|
|
||||||
private final PacketRegistry packetRegistry;
|
|
||||||
public static CraterPacketNetwork INSTANCE;
|
|
||||||
private static DeferredPacketRegistrar delayedHandler;
|
|
||||||
|
|
||||||
public CraterPacketNetwork(PacketRegistry registry) {
|
|
||||||
INSTANCE = this;
|
|
||||||
this.packetRegistry = registry;
|
|
||||||
getDelayedHandler().registerQueuedPackets(registry);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static DeferredPacketRegistrar getDelayedHandler() {
|
|
||||||
if (delayedHandler == null) {
|
|
||||||
delayedHandler = new DeferredPacketRegistrar();
|
|
||||||
}
|
|
||||||
return delayedHandler;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static <T> PacketRegistrar registerPacket(ResourceIdentifier id, Class<T> messageType, BiConsumer<T, BridgedFriendlyByteBuf> encoder, Function<BridgedFriendlyByteBuf, T> decoder, Consumer<PacketContext<T>> handler) {
|
|
||||||
if (INSTANCE != null) {
|
|
||||||
return INSTANCE.packetRegistry.registerPacket(id, messageType, encoder, decoder, handler);
|
|
||||||
} else {
|
|
||||||
return getDelayedHandler().registerPacket(id, messageType, encoder, decoder, handler);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,41 +0,0 @@
|
|||||||
package com.hypherionmc.craterlib.core.networking;
|
|
||||||
|
|
||||||
import com.hypherionmc.craterlib.core.networking.data.PacketContext;
|
|
||||||
import com.hypherionmc.craterlib.core.networking.data.PacketHolder;
|
|
||||||
import com.hypherionmc.craterlib.core.networking.data.PacketSide;
|
|
||||||
import com.hypherionmc.craterlib.nojang.network.BridgedFriendlyByteBuf;
|
|
||||||
import com.hypherionmc.craterlib.nojang.resources.ResourceIdentifier;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.function.BiConsumer;
|
|
||||||
import java.util.function.Consumer;
|
|
||||||
import java.util.function.Function;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Based on https://github.com/mysticdrew/common-networking/tree/1.20.4
|
|
||||||
*/
|
|
||||||
public class DeferredPacketRegistrar implements PacketRegistrar {
|
|
||||||
|
|
||||||
private static final Map<Class<?>, PacketHolder<?>> QUEUED_PACKET_MAP = new HashMap<>();
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public PacketSide side() {
|
|
||||||
return PacketSide.CLIENT;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public <T> PacketRegistrar registerPacket(ResourceIdentifier packetIdentifier, Class<T> messageType, BiConsumer<T, BridgedFriendlyByteBuf> encoder, Function<BridgedFriendlyByteBuf, T> decoder, Consumer<PacketContext<T>> handler) {
|
|
||||||
PacketHolder<T> container = new PacketHolder<>(packetIdentifier, messageType, encoder, decoder, handler);
|
|
||||||
QUEUED_PACKET_MAP.put(messageType, container);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void registerQueuedPackets(PacketRegistry packetRegistration) {
|
|
||||||
if (!QUEUED_PACKET_MAP.isEmpty()) {
|
|
||||||
packetRegistration.PACKET_MAP.putAll(QUEUED_PACKET_MAP);
|
|
||||||
QUEUED_PACKET_MAP.forEach((aClass, container) -> packetRegistration.registerPacket(container));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,21 +0,0 @@
|
|||||||
package com.hypherionmc.craterlib.core.networking;
|
|
||||||
|
|
||||||
import com.hypherionmc.craterlib.core.networking.data.PacketContext;
|
|
||||||
import com.hypherionmc.craterlib.core.networking.data.PacketSide;
|
|
||||||
import com.hypherionmc.craterlib.nojang.network.BridgedFriendlyByteBuf;
|
|
||||||
import com.hypherionmc.craterlib.nojang.resources.ResourceIdentifier;
|
|
||||||
|
|
||||||
import java.util.function.BiConsumer;
|
|
||||||
import java.util.function.Consumer;
|
|
||||||
import java.util.function.Function;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Based on https://github.com/mysticdrew/common-networking/tree/1.20.4
|
|
||||||
*/
|
|
||||||
public interface PacketRegistrar {
|
|
||||||
|
|
||||||
PacketSide side();
|
|
||||||
|
|
||||||
<T> PacketRegistrar registerPacket(ResourceIdentifier id, Class<T> messageType, BiConsumer<T, BridgedFriendlyByteBuf> encoder, Function<BridgedFriendlyByteBuf, T> decoder, Consumer<PacketContext<T>> handler);
|
|
||||||
|
|
||||||
}
|
|
@@ -1,41 +0,0 @@
|
|||||||
package com.hypherionmc.craterlib.core.networking;
|
|
||||||
|
|
||||||
import com.hypherionmc.craterlib.api.networking.CraterNetworkHandler;
|
|
||||||
import com.hypherionmc.craterlib.core.networking.data.PacketContext;
|
|
||||||
import com.hypherionmc.craterlib.core.networking.data.PacketHolder;
|
|
||||||
import com.hypherionmc.craterlib.core.networking.data.PacketSide;
|
|
||||||
import com.hypherionmc.craterlib.nojang.network.BridgedFriendlyByteBuf;
|
|
||||||
import com.hypherionmc.craterlib.nojang.resources.ResourceIdentifier;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.function.BiConsumer;
|
|
||||||
import java.util.function.Consumer;
|
|
||||||
import java.util.function.Function;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Based on https://github.com/mysticdrew/common-networking/tree/1.20.4
|
|
||||||
*/
|
|
||||||
public abstract class PacketRegistry implements CraterNetworkHandler, PacketRegistrar {
|
|
||||||
|
|
||||||
protected final Map<Class<?>, PacketHolder<?>> PACKET_MAP = new HashMap<>();
|
|
||||||
|
|
||||||
protected final PacketSide side;
|
|
||||||
|
|
||||||
public PacketRegistry(PacketSide 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) {
|
|
||||||
PacketHolder<T> holder = new PacketHolder<>(id, messageType, encoder, decoder, handler);
|
|
||||||
PACKET_MAP.put(messageType, holder);
|
|
||||||
registerPacket(holder);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public PacketSide side() {
|
|
||||||
return side;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected abstract <T> void registerPacket(PacketHolder<T> packetHolder);
|
|
||||||
}
|
|
@@ -1,15 +0,0 @@
|
|||||||
package com.hypherionmc.craterlib.core.networking.data;
|
|
||||||
|
|
||||||
import com.hypherionmc.craterlib.nojang.world.entity.player.BridgedPlayer;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Based on https://github.com/mysticdrew/common-networking/tree/1.20.4
|
|
||||||
*/
|
|
||||||
public record PacketContext<T>(@Nullable BridgedPlayer sender, T message, PacketSide side) {
|
|
||||||
|
|
||||||
public PacketContext(T message, PacketSide side) {
|
|
||||||
this(null, message, side);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,18 +0,0 @@
|
|||||||
package com.hypherionmc.craterlib.core.networking.data;
|
|
||||||
|
|
||||||
import com.hypherionmc.craterlib.nojang.network.BridgedFriendlyByteBuf;
|
|
||||||
import com.hypherionmc.craterlib.nojang.resources.ResourceIdentifier;
|
|
||||||
|
|
||||||
import java.util.function.BiConsumer;
|
|
||||||
import java.util.function.Consumer;
|
|
||||||
import java.util.function.Function;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Based on https://github.com/mysticdrew/common-networking/tree/1.20.4
|
|
||||||
*/
|
|
||||||
public record PacketHolder<T>(ResourceIdentifier type,
|
|
||||||
Class<T> messageType,
|
|
||||||
BiConsumer<T, BridgedFriendlyByteBuf> encoder,
|
|
||||||
Function<BridgedFriendlyByteBuf, T> decoder,
|
|
||||||
Consumer<PacketContext<T>> handler) {
|
|
||||||
}
|
|
@@ -1,13 +0,0 @@
|
|||||||
package com.hypherionmc.craterlib.core.networking.data;
|
|
||||||
|
|
||||||
public enum PacketSide {
|
|
||||||
CLIENT,
|
|
||||||
SERVER;
|
|
||||||
|
|
||||||
public PacketSide flipped() {
|
|
||||||
if (CLIENT.equals(this))
|
|
||||||
return SERVER;
|
|
||||||
|
|
||||||
return CLIENT;
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,23 +0,0 @@
|
|||||||
package com.hypherionmc.craterlib.core.platform;
|
|
||||||
|
|
||||||
import com.hypherionmc.craterlib.nojang.client.BridgedMinecraft;
|
|
||||||
import com.hypherionmc.craterlib.nojang.client.multiplayer.BridgedClientLevel;
|
|
||||||
import com.hypherionmc.craterlib.nojang.world.entity.player.BridgedPlayer;
|
|
||||||
import com.hypherionmc.craterlib.utils.InternalServiceUtil;
|
|
||||||
import net.minecraft.network.Connection;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author HypherionSA
|
|
||||||
*/
|
|
||||||
public interface ClientPlatform {
|
|
||||||
|
|
||||||
public final ClientPlatform INSTANCE = InternalServiceUtil.load(ClientPlatform.class);
|
|
||||||
|
|
||||||
BridgedMinecraft getClientInstance();
|
|
||||||
|
|
||||||
BridgedPlayer getClientPlayer();
|
|
||||||
|
|
||||||
BridgedClientLevel getClientLevel();
|
|
||||||
|
|
||||||
Connection getClientConnection();
|
|
||||||
}
|
|
@@ -1,15 +0,0 @@
|
|||||||
package com.hypherionmc.craterlib.core.platform;
|
|
||||||
|
|
||||||
import com.hypherionmc.craterlib.nojang.server.BridgedMinecraftServer;
|
|
||||||
import com.hypherionmc.craterlib.utils.InternalServiceUtil;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author HypherionSA
|
|
||||||
*/
|
|
||||||
public interface CommonPlatform {
|
|
||||||
|
|
||||||
public CommonPlatform INSTANCE = InternalServiceUtil.load(CommonPlatform.class);
|
|
||||||
|
|
||||||
BridgedMinecraftServer 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,18 +0,0 @@
|
|||||||
package com.hypherionmc.craterlib.core.platform;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author HypherionSA
|
|
||||||
*/
|
|
||||||
public enum Environment {
|
|
||||||
CLIENT,
|
|
||||||
SERVER,
|
|
||||||
UNKNOWN;
|
|
||||||
|
|
||||||
public boolean isClient() {
|
|
||||||
return this == CLIENT;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isServer() {
|
|
||||||
return this == SERVER;
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,8 +0,0 @@
|
|||||||
package com.hypherionmc.craterlib.core.platform;
|
|
||||||
|
|
||||||
public enum LoaderType {
|
|
||||||
FABRIC,
|
|
||||||
FORGE,
|
|
||||||
NEOFORGE,
|
|
||||||
PAPER
|
|
||||||
}
|
|
@@ -1,35 +0,0 @@
|
|||||||
package com.hypherionmc.craterlib.core.platform;
|
|
||||||
|
|
||||||
import com.hypherionmc.craterlib.utils.InternalServiceUtil;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author HypherionSA
|
|
||||||
* Helper class to provide information about the ModLoader
|
|
||||||
*/
|
|
||||||
public interface ModloaderEnvironment {
|
|
||||||
|
|
||||||
public final ModloaderEnvironment INSTANCE = InternalServiceUtil.load(ModloaderEnvironment.class);
|
|
||||||
|
|
||||||
@Deprecated(forRemoval = true, since = "2.0.2")
|
|
||||||
boolean isFabric();
|
|
||||||
|
|
||||||
LoaderType getLoaderType();
|
|
||||||
|
|
||||||
String getGameVersion();
|
|
||||||
|
|
||||||
File getGameFolder();
|
|
||||||
|
|
||||||
File getConfigFolder();
|
|
||||||
|
|
||||||
File getModsFolder();
|
|
||||||
|
|
||||||
Environment getEnvironment();
|
|
||||||
|
|
||||||
boolean isModLoaded(String modid);
|
|
||||||
|
|
||||||
boolean isDevEnv();
|
|
||||||
|
|
||||||
int getModCount();
|
|
||||||
}
|
|
@@ -1,91 +0,0 @@
|
|||||||
package com.hypherionmc.craterlib.core.rpcsdk;
|
|
||||||
|
|
||||||
import com.hypherionmc.craterlib.core.rpcsdk.callbacks.*;
|
|
||||||
import com.sun.jna.Structure;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author HypherionSA
|
|
||||||
* Class containing references to all available discord event handles.
|
|
||||||
* Registering a handler is optional, and non-assigned handlers will be ignored
|
|
||||||
*/
|
|
||||||
@Deprecated(forRemoval = true)
|
|
||||||
public class DiscordEventHandlers extends Structure {
|
|
||||||
|
|
||||||
// Callback for when the RPC was initialized successfully
|
|
||||||
public ReadyCallback ready;
|
|
||||||
|
|
||||||
// Callback for when the Discord connection was ended
|
|
||||||
public DisconnectedCallback disconnected;
|
|
||||||
|
|
||||||
// Callback for when a Discord Error occurs
|
|
||||||
public ErroredCallback errored;
|
|
||||||
|
|
||||||
// Callback for when a player joins the game
|
|
||||||
public JoinGameCallback joinGame;
|
|
||||||
|
|
||||||
// Callback for when a player spectates the game
|
|
||||||
public SpectateGameCallback spectateGame;
|
|
||||||
|
|
||||||
// Callback for when a players request to join your game
|
|
||||||
public JoinRequestCallback joinRequest;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* DO NOT TOUCH THIS... EVER!
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
protected List<String> getFieldOrder() {
|
|
||||||
return Arrays.asList(
|
|
||||||
"ready",
|
|
||||||
"disconnected",
|
|
||||||
"errored",
|
|
||||||
"joinGame",
|
|
||||||
"spectateGame",
|
|
||||||
"joinRequest"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class Builder {
|
|
||||||
private final DiscordEventHandlers handlers;
|
|
||||||
|
|
||||||
public Builder() {
|
|
||||||
this.handlers = new DiscordEventHandlers();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder ready(ReadyCallback readyCallback) {
|
|
||||||
handlers.ready = readyCallback;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder disconnected(DisconnectedCallback disconnectedCallback) {
|
|
||||||
handlers.disconnected = disconnectedCallback;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder errored(ErroredCallback erroredCallback) {
|
|
||||||
handlers.errored = erroredCallback;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder joinGame(JoinGameCallback joinGameCallback) {
|
|
||||||
handlers.joinGame = joinGameCallback;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder spectateGame(SpectateGameCallback spectateGameCallback) {
|
|
||||||
handlers.spectateGame = spectateGameCallback;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder joinRequest(JoinRequestCallback joinRequestCallback) {
|
|
||||||
handlers.joinRequest = joinRequestCallback;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public DiscordEventHandlers build() {
|
|
||||||
return handlers;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,100 +0,0 @@
|
|||||||
package com.hypherionmc.craterlib.core.rpcsdk;
|
|
||||||
|
|
||||||
import com.sun.jna.Library;
|
|
||||||
import com.sun.jna.Native;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author HypherionSA
|
|
||||||
* Java Wrapper of the Discord-RPC Library
|
|
||||||
*/
|
|
||||||
@Deprecated(forRemoval = true)
|
|
||||||
public interface DiscordRPC extends Library {
|
|
||||||
|
|
||||||
DiscordRPC INSTANCE = Native.load("discord-rpc", DiscordRPC.class);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Open a New RPC Connection
|
|
||||||
*
|
|
||||||
* @param applicationId The ID of the Application the RPC is tied to
|
|
||||||
* @param handlers Optional Event Callback Handlers
|
|
||||||
* @param autoRegister Auto Register the running game
|
|
||||||
* @param steamId Steam ID of the game
|
|
||||||
*/
|
|
||||||
void Discord_Initialize(@NotNull String applicationId, @Nullable DiscordEventHandlers handlers, boolean autoRegister, @Nullable String steamId);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Shutdown the RPC instance and disconnect from discord
|
|
||||||
*/
|
|
||||||
void Discord_Shutdown();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Need to be called manually at least every 2 seconds, to allow RPC updates
|
|
||||||
* and callback handlers to fire
|
|
||||||
*/
|
|
||||||
void Discord_RunCallbacks();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Not sure about this. Believe it needs to be called manually in some circumstances
|
|
||||||
*/
|
|
||||||
void Discord_UpdateConnection();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Update the Rich Presence
|
|
||||||
*
|
|
||||||
* @param struct Constructed {@link DiscordRichPresence}
|
|
||||||
*/
|
|
||||||
void Discord_UpdatePresence(@Nullable DiscordRichPresence struct);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Clear the current Rich Presence
|
|
||||||
*/
|
|
||||||
void Discord_ClearPresence();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Respond to Join/Spectate callback
|
|
||||||
*
|
|
||||||
* @param userid The Discord User ID of the user that initiated the request
|
|
||||||
* @param reply Reply to the request. See {@link DiscordReply}
|
|
||||||
*/
|
|
||||||
void Discord_Respond(@NotNull String userid, int reply);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Replace the already registered {@link DiscordEventHandlers}
|
|
||||||
*
|
|
||||||
* @param handlers The new handlers to apply
|
|
||||||
*/
|
|
||||||
void Discord_UpdateHandlers(@Nullable DiscordEventHandlers handlers);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Register the executable of the application/game
|
|
||||||
* Only applicable when autoRegister is set to false
|
|
||||||
*
|
|
||||||
* @param applicationId The Application ID
|
|
||||||
* @param command The Launch command of the game
|
|
||||||
* <p>
|
|
||||||
* NB: THIS DOES NOT WORK WITH MINECRAFT
|
|
||||||
*/
|
|
||||||
void Discord_Register(String applicationId, String command);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Register the Steam executable of the application/game
|
|
||||||
*
|
|
||||||
* @param applicationId The Application ID
|
|
||||||
* @param steamId The Steam ID of the application/game
|
|
||||||
*/
|
|
||||||
void Discord_RegisterSteamGame(String applicationId, String steamId);
|
|
||||||
|
|
||||||
public enum DiscordReply {
|
|
||||||
NO(0),
|
|
||||||
YES(1),
|
|
||||||
IGNORE(2);
|
|
||||||
|
|
||||||
public final int reply;
|
|
||||||
|
|
||||||
DiscordReply(int reply) {
|
|
||||||
this.reply = reply;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,249 +0,0 @@
|
|||||||
package com.hypherionmc.craterlib.core.rpcsdk;
|
|
||||||
|
|
||||||
import com.hypherionmc.craterlib.core.rpcsdk.helpers.RPCButton;
|
|
||||||
import com.sun.jna.Structure;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
import java.time.OffsetDateTime;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author HypherionSA
|
|
||||||
* Class reprenting a Discord RPC activity
|
|
||||||
*/
|
|
||||||
@Deprecated(forRemoval = true)
|
|
||||||
public class DiscordRichPresence extends Structure {
|
|
||||||
|
|
||||||
// First line of text on the RPC
|
|
||||||
public String state;
|
|
||||||
|
|
||||||
// Second line of text on the RPC
|
|
||||||
public String details;
|
|
||||||
|
|
||||||
// Time the activity started in UNIX-Timestamp format
|
|
||||||
public long startTimestamp;
|
|
||||||
|
|
||||||
// Time the activity will end in UNIX-Timestamp format
|
|
||||||
public long endTimestamp;
|
|
||||||
|
|
||||||
// URL or Asset key of the Large Image
|
|
||||||
public String largeImageKey;
|
|
||||||
|
|
||||||
// Hover text to display when hovering the Large Image
|
|
||||||
public String largeImageText;
|
|
||||||
|
|
||||||
// URL or Asset key of the Small Image
|
|
||||||
public String smallImageKey;
|
|
||||||
|
|
||||||
// Hover text to display when hovering the Small Image
|
|
||||||
public String smallImageText;
|
|
||||||
|
|
||||||
// Id of the player's party, lobby, or group.
|
|
||||||
public String partyId;
|
|
||||||
|
|
||||||
// Current size of the player's party, lobby, or group.
|
|
||||||
public int partySize;
|
|
||||||
|
|
||||||
// Maximum size of the player's party, lobby, or group.
|
|
||||||
public int partyMax;
|
|
||||||
|
|
||||||
// Unused
|
|
||||||
public String partyPrivacy;
|
|
||||||
|
|
||||||
// Unused.
|
|
||||||
public String matchSecret;
|
|
||||||
|
|
||||||
// Unique hashed string for chat invitations and Ask to Join.
|
|
||||||
public String joinSecret;
|
|
||||||
|
|
||||||
// Unique hashed string for Spectate button.
|
|
||||||
public String spectateSecret;
|
|
||||||
|
|
||||||
// Label of the First RPC Button
|
|
||||||
public String button_label_1;
|
|
||||||
|
|
||||||
// URL of the First RPC Button
|
|
||||||
public String button_url_1;
|
|
||||||
|
|
||||||
// Label of the Second RPC Button
|
|
||||||
public String button_label_2;
|
|
||||||
|
|
||||||
// URL of the Second RPC Button
|
|
||||||
public String button_url_2;
|
|
||||||
|
|
||||||
// Unused
|
|
||||||
public int instance;
|
|
||||||
|
|
||||||
public DiscordRichPresence() {
|
|
||||||
setStringEncoding("UTF-8");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* DO NOT TOUCH THIS... EVER!
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
protected List<String> getFieldOrder() {
|
|
||||||
return Arrays.asList(
|
|
||||||
"state",
|
|
||||||
"details",
|
|
||||||
"startTimestamp",
|
|
||||||
"endTimestamp",
|
|
||||||
"largeImageKey",
|
|
||||||
"largeImageText",
|
|
||||||
"smallImageKey",
|
|
||||||
"smallImageText",
|
|
||||||
"partyId",
|
|
||||||
"partySize",
|
|
||||||
"partyMax",
|
|
||||||
"partyPrivacy",
|
|
||||||
"matchSecret",
|
|
||||||
"joinSecret",
|
|
||||||
"spectateSecret",
|
|
||||||
"button_label_1",
|
|
||||||
"button_url_1",
|
|
||||||
"button_label_2",
|
|
||||||
"button_url_2",
|
|
||||||
"instance"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class Builder {
|
|
||||||
private final DiscordRichPresence rpc;
|
|
||||||
|
|
||||||
public Builder(String state) {
|
|
||||||
rpc = new DiscordRichPresence();
|
|
||||||
|
|
||||||
if (state != null && !state.isEmpty()) {
|
|
||||||
rpc.state = state.substring(0, Math.min(state.length(), 128));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder setDetails(String details) {
|
|
||||||
if (details != null && !details.isEmpty()) {
|
|
||||||
rpc.details = details.substring(0, Math.min(details.length(), 128));
|
|
||||||
}
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder setStartTimestamp(long timestamp) {
|
|
||||||
rpc.startTimestamp = timestamp;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder setStartTimestamp(OffsetDateTime timestamp) {
|
|
||||||
rpc.startTimestamp = timestamp.toEpochSecond();
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder setEndTimestamp(long timestamp) {
|
|
||||||
rpc.endTimestamp = timestamp;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder setEndTimestamp(OffsetDateTime timestamp) {
|
|
||||||
rpc.endTimestamp = timestamp.toEpochSecond();
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder setLargeImage(String key) {
|
|
||||||
return this.setLargeImage(key, "");
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder setLargeImage(@NotNull String key, String text) {
|
|
||||||
// Null check used for users blatantly ignoring the NotNull marker
|
|
||||||
if ((text != null && !text.isEmpty()) && key != null) {
|
|
||||||
throw new IllegalArgumentException("Image key cannot be null when assigning a hover text");
|
|
||||||
}
|
|
||||||
|
|
||||||
rpc.largeImageKey = key;
|
|
||||||
rpc.largeImageText = text;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder setSmallImage(String key) {
|
|
||||||
return this.setSmallImage(key, "");
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder setSmallImage(@NotNull String key, String text) {
|
|
||||||
// Null check used for users blatantly ignoring the NotNull marker
|
|
||||||
if ((text != null && !text.isEmpty()) && key != null) {
|
|
||||||
throw new IllegalArgumentException("Image key cannot be null when assigning a hover text");
|
|
||||||
}
|
|
||||||
|
|
||||||
rpc.smallImageKey = key;
|
|
||||||
rpc.smallImageText = text;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder setParty(String party, int size, int max) {
|
|
||||||
// Buttons are present, ignore
|
|
||||||
if ((rpc.button_label_1 != null && rpc.button_label_1.isEmpty()) || (rpc.button_label_2 != null && rpc.button_label_2.isEmpty()))
|
|
||||||
return this;
|
|
||||||
|
|
||||||
rpc.partyId = party;
|
|
||||||
rpc.partySize = size;
|
|
||||||
rpc.partyMax = max;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder setSecrets(String match, String join, String spectate) {
|
|
||||||
// Buttons are present, ignore
|
|
||||||
if ((rpc.button_label_1 != null && rpc.button_label_1.isEmpty()) || (rpc.button_label_2 != null && rpc.button_label_2.isEmpty()))
|
|
||||||
return this;
|
|
||||||
|
|
||||||
rpc.matchSecret = match;
|
|
||||||
rpc.joinSecret = join;
|
|
||||||
rpc.spectateSecret = spectate;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder setSecrets(String join, String spectate) {
|
|
||||||
// Buttons are present, ignore
|
|
||||||
if ((rpc.button_label_1 != null && rpc.button_label_1.isEmpty()) || (rpc.button_label_2 != null && rpc.button_label_2.isEmpty()))
|
|
||||||
return this;
|
|
||||||
|
|
||||||
rpc.joinSecret = join;
|
|
||||||
rpc.spectateSecret = spectate;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder setInstance(boolean i) {
|
|
||||||
// Buttons are present, ignore
|
|
||||||
if ((rpc.button_label_1 != null && rpc.button_label_1.isEmpty()) || (rpc.button_label_2 != null && rpc.button_label_2.isEmpty()))
|
|
||||||
return this;
|
|
||||||
|
|
||||||
rpc.instance = i ? 1 : 0;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder setButtons(RPCButton button) {
|
|
||||||
return this.setButtons(Collections.singletonList(button));
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder setButtons(RPCButton button1, RPCButton button2) {
|
|
||||||
return this.setButtons(Arrays.asList(button1, button2));
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder setButtons(List<RPCButton> rpcButtons) {
|
|
||||||
// Limit to 2 Buttons. Discord Limitation
|
|
||||||
if (rpcButtons != null && !rpcButtons.isEmpty()) {
|
|
||||||
int length = Math.min(rpcButtons.size(), 2);
|
|
||||||
rpc.button_label_1 = rpcButtons.get(0).getLabel();
|
|
||||||
rpc.button_url_1 = rpcButtons.get(0).getUrl();
|
|
||||||
|
|
||||||
if (length == 2) {
|
|
||||||
rpc.button_label_2 = rpcButtons.get(1).getLabel();
|
|
||||||
rpc.button_url_2 = rpcButtons.get(1).getUrl();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public DiscordRichPresence build() {
|
|
||||||
return rpc;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,19 +0,0 @@
|
|||||||
package com.hypherionmc.craterlib.core.rpcsdk.callbacks;
|
|
||||||
|
|
||||||
import com.sun.jna.Callback;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author HypherionSA
|
|
||||||
* Callback for when the Discord RPC disconnects
|
|
||||||
*/
|
|
||||||
@Deprecated(forRemoval = true)
|
|
||||||
public interface DisconnectedCallback extends Callback {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Called when RPC disconnected
|
|
||||||
*
|
|
||||||
* @param errorCode Error code if any
|
|
||||||
* @param message Details about the disconnection
|
|
||||||
*/
|
|
||||||
void apply(int errorCode, String message);
|
|
||||||
}
|
|
@@ -1,19 +0,0 @@
|
|||||||
package com.hypherionmc.craterlib.core.rpcsdk.callbacks;
|
|
||||||
|
|
||||||
import com.sun.jna.Callback;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author HypherionSA
|
|
||||||
* Callback for when the RPC ran into an error
|
|
||||||
*/
|
|
||||||
@Deprecated(forRemoval = true)
|
|
||||||
public interface ErroredCallback extends Callback {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Called when an RPC error occurs
|
|
||||||
*
|
|
||||||
* @param errorCode Error code if any
|
|
||||||
* @param message Details about the error
|
|
||||||
*/
|
|
||||||
void apply(int errorCode, String message);
|
|
||||||
}
|
|
@@ -1,18 +0,0 @@
|
|||||||
package com.hypherionmc.craterlib.core.rpcsdk.callbacks;
|
|
||||||
|
|
||||||
import com.sun.jna.Callback;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author HypherionSA
|
|
||||||
* Callback for when someone was approved to join your game
|
|
||||||
*/
|
|
||||||
@Deprecated(forRemoval = true)
|
|
||||||
public interface JoinGameCallback extends Callback {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Called when someone joins a game from {@link JoinRequestCallback}
|
|
||||||
*
|
|
||||||
* @param joinSecret Secret or Password required to let the player join the game
|
|
||||||
*/
|
|
||||||
void apply(String joinSecret);
|
|
||||||
}
|
|
@@ -1,20 +0,0 @@
|
|||||||
package com.hypherionmc.craterlib.core.rpcsdk.callbacks;
|
|
||||||
|
|
||||||
import com.hypherionmc.craterlib.core.rpcsdk.DiscordUser;
|
|
||||||
import com.sun.jna.Callback;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author HypherionSA
|
|
||||||
* Callback for when someone requests to join your game
|
|
||||||
*/
|
|
||||||
@Deprecated(forRemoval = true)
|
|
||||||
public interface JoinRequestCallback extends Callback {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Called when someone clicks on the Join Game button
|
|
||||||
*
|
|
||||||
* @param user The Discord User trying to join your game
|
|
||||||
* @see DiscordUser
|
|
||||||
*/
|
|
||||||
void apply(DiscordUser user);
|
|
||||||
}
|
|
@@ -1,20 +0,0 @@
|
|||||||
package com.hypherionmc.craterlib.core.rpcsdk.callbacks;
|
|
||||||
|
|
||||||
import com.hypherionmc.craterlib.core.rpcsdk.DiscordUser;
|
|
||||||
import com.sun.jna.Callback;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author HypherionSA
|
|
||||||
* Callback for when the RPC has connected successfully
|
|
||||||
*/
|
|
||||||
@Deprecated(forRemoval = true)
|
|
||||||
public interface ReadyCallback extends Callback {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Called when the RPC is connected and ready to be used
|
|
||||||
*
|
|
||||||
* @param user The user the RPC is displayed on
|
|
||||||
* @see DiscordUser
|
|
||||||
*/
|
|
||||||
void apply(DiscordUser user);
|
|
||||||
}
|
|
@@ -1,18 +0,0 @@
|
|||||||
package com.hypherionmc.craterlib.core.rpcsdk.callbacks;
|
|
||||||
|
|
||||||
import com.sun.jna.Callback;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author HypherionSA
|
|
||||||
* Callback for when someone is requesting to spectate your game
|
|
||||||
*/
|
|
||||||
@Deprecated(forRemoval = true)
|
|
||||||
public interface SpectateGameCallback extends Callback {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Called when joining the game
|
|
||||||
*
|
|
||||||
* @param spectateSecret Secret or Password required to let the player spectate
|
|
||||||
*/
|
|
||||||
void apply(String spectateSecret);
|
|
||||||
}
|
|
@@ -1,56 +0,0 @@
|
|||||||
package com.hypherionmc.craterlib.core.rpcsdk.helpers;
|
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author HypherionSA
|
|
||||||
* Helper class to add Buttons to Discord Rich Presence
|
|
||||||
* This can not be used with Join/Spectate
|
|
||||||
*/
|
|
||||||
@Deprecated(forRemoval = true)
|
|
||||||
public class RPCButton implements Serializable {
|
|
||||||
|
|
||||||
// The label of the button
|
|
||||||
private final String label;
|
|
||||||
|
|
||||||
// The URL the button will open when clicked
|
|
||||||
private final String url;
|
|
||||||
|
|
||||||
protected RPCButton(String label, String url) {
|
|
||||||
this.label = label;
|
|
||||||
this.url = url;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new RPC Button
|
|
||||||
*
|
|
||||||
* @param label The label of the button
|
|
||||||
* @param url The URL the button will open when clicked
|
|
||||||
* @return The constructed button
|
|
||||||
*/
|
|
||||||
public static RPCButton create(@NotNull String label, @NotNull String url) {
|
|
||||||
// Null check used here for users blatantly ignoring the NotNull marker
|
|
||||||
if (label == null || label.isEmpty() || url == null || url.isEmpty()) {
|
|
||||||
throw new IllegalArgumentException("RPC Buttons require both a label and url");
|
|
||||||
}
|
|
||||||
|
|
||||||
label = label.substring(0, Math.min(label.length(), 31));
|
|
||||||
return new RPCButton(label, url);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return The label assigned to the button
|
|
||||||
*/
|
|
||||||
public String getLabel() {
|
|
||||||
return label;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return The URL of the button
|
|
||||||
*/
|
|
||||||
public String getUrl() {
|
|
||||||
return url;
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,84 +0,0 @@
|
|||||||
package com.hypherionmc.craterlib.mixin;
|
|
||||||
|
|
||||||
import com.hypherionmc.craterlib.client.mentions.MentionsController;
|
|
||||||
import net.minecraft.client.gui.components.CommandSuggestions;
|
|
||||||
import net.minecraft.client.gui.components.EditBox;
|
|
||||||
import org.objectweb.asm.Opcodes;
|
|
||||||
import org.spongepowered.asm.mixin.Final;
|
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
|
||||||
import org.spongepowered.asm.mixin.Shadow;
|
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
|
||||||
import org.spongepowered.asm.mixin.injection.Inject;
|
|
||||||
import org.spongepowered.asm.mixin.injection.ModifyVariable;
|
|
||||||
import org.spongepowered.asm.mixin.injection.Slice;
|
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collection;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author HypherionSA
|
|
||||||
* Allow Users, Roles and Channels to be pingable from MC chat (Client Side)
|
|
||||||
*/
|
|
||||||
@Mixin(CommandSuggestions.class)
|
|
||||||
public abstract class ChatInputSuggestorMixin {
|
|
||||||
|
|
||||||
@Shadow
|
|
||||||
public abstract void showSuggestions(boolean p_93931_);
|
|
||||||
|
|
||||||
@Shadow @Final
|
|
||||||
EditBox input;
|
|
||||||
|
|
||||||
@Shadow
|
|
||||||
private static int getLastWordIndex(String p_93913_) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Inject(
|
|
||||||
method = "updateCommandInfo",
|
|
||||||
at = @At(
|
|
||||||
value = "FIELD",
|
|
||||||
target = "Lnet/minecraft/client/gui/components/CommandSuggestions;pendingSuggestions:Ljava/util/concurrent/CompletableFuture;",
|
|
||||||
opcode = Opcodes.PUTFIELD,
|
|
||||||
shift = At.Shift.AFTER,
|
|
||||||
ordinal = 0
|
|
||||||
),
|
|
||||||
slice = @Slice(
|
|
||||||
from = @At(
|
|
||||||
value = "INVOKE",
|
|
||||||
target = "Lnet/minecraft/client/gui/components/CommandSuggestions;getLastWordIndex(Ljava/lang/String;)I"
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
private void injectSuggestions(CallbackInfo ci) {
|
|
||||||
if (MentionsController.hasMentions() && MentionsController.isLastMentionConditional()) {
|
|
||||||
this.showSuggestions(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("InvalidInjectorMethodSignature")
|
|
||||||
@ModifyVariable(method = "updateCommandInfo", at = @At(value = "STORE"), ordinal = 0, name = "collection")
|
|
||||||
private Collection<String> injectMentions(Collection<String> vanilla) {
|
|
||||||
if (!MentionsController.hasMentions())
|
|
||||||
return vanilla;
|
|
||||||
|
|
||||||
ArrayList<String> newSuggest = new ArrayList<>(vanilla);
|
|
||||||
|
|
||||||
String currentInput = this.input.getValue();
|
|
||||||
int currentCursorPosition = this.input.getCursorPosition();
|
|
||||||
|
|
||||||
String textBeforeCursor = currentInput.substring(0, currentCursorPosition);
|
|
||||||
int startOfCurrentWord = getLastWordIndex(textBeforeCursor);
|
|
||||||
|
|
||||||
String currentWord = textBeforeCursor.substring(startOfCurrentWord);
|
|
||||||
String finalWord = currentWord.replace("[", "").replace("]", "");
|
|
||||||
|
|
||||||
Collection<String> mentions = MentionsController.getMentions(finalWord);
|
|
||||||
|
|
||||||
if (!mentions.isEmpty()) {
|
|
||||||
mentions.forEach(m -> newSuggest.add("[" + m + "]"));
|
|
||||||
}
|
|
||||||
|
|
||||||
return newSuggest;
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,29 +0,0 @@
|
|||||||
package com.hypherionmc.craterlib.mixin.events;
|
|
||||||
|
|
||||||
import com.hypherionmc.craterlib.api.events.server.CraterAdvancementEvent;
|
|
||||||
import com.hypherionmc.craterlib.core.event.CraterEventBus;
|
|
||||||
import com.hypherionmc.craterlib.nojang.advancements.BridgedAdvancement;
|
|
||||||
import com.hypherionmc.craterlib.nojang.world.entity.player.BridgedPlayer;
|
|
||||||
import net.minecraft.advancements.Advancement;
|
|
||||||
import net.minecraft.server.PlayerAdvancements;
|
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
|
||||||
import org.spongepowered.asm.mixin.Shadow;
|
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
|
||||||
import org.spongepowered.asm.mixin.injection.Inject;
|
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
|
||||||
|
|
||||||
@Mixin(PlayerAdvancements.class)
|
|
||||||
public class PlayerAdvancementsMixin {
|
|
||||||
|
|
||||||
@Shadow
|
|
||||||
private ServerPlayer player;
|
|
||||||
|
|
||||||
@Inject(method = "award", at = @At(value = "INVOKE", target = "Lnet/minecraft/advancements/AdvancementRewards;grant(Lnet/minecraft/server/level/ServerPlayer;)V", shift = At.Shift.AFTER))
|
|
||||||
private void injectAdvancementEvent(Advancement advancement, String string, CallbackInfoReturnable<Boolean> cir) {
|
|
||||||
if (advancement.getDisplay() == null || !advancement.getDisplay().shouldAnnounceChat())
|
|
||||||
return;
|
|
||||||
|
|
||||||
CraterEventBus.INSTANCE.postEvent(new CraterAdvancementEvent(BridgedPlayer.of(this.player), BridgedAdvancement.of(advancement)));
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,21 +0,0 @@
|
|||||||
package com.hypherionmc.craterlib.mixin.events;
|
|
||||||
|
|
||||||
import com.hypherionmc.craterlib.api.events.common.CraterPlayerDeathEvent;
|
|
||||||
import com.hypherionmc.craterlib.core.event.CraterEventBus;
|
|
||||||
import com.hypherionmc.craterlib.nojang.world.entity.player.BridgedPlayer;
|
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
|
||||||
import net.minecraft.world.damagesource.DamageSource;
|
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
|
||||||
import org.spongepowered.asm.mixin.injection.Inject;
|
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
|
||||||
|
|
||||||
@Mixin(ServerPlayer.class)
|
|
||||||
public class ServerPlayerMixin {
|
|
||||||
|
|
||||||
@Inject(method = "die", at = @At("HEAD"))
|
|
||||||
private void injectPlayerDeathEvent(DamageSource damageSource, CallbackInfo ci) {
|
|
||||||
CraterEventBus.INSTANCE.postEvent(new CraterPlayerDeathEvent(BridgedPlayer.of(((ServerPlayer) (Object) this)), damageSource));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,31 +0,0 @@
|
|||||||
package com.hypherionmc.craterlib.mixin.events;
|
|
||||||
|
|
||||||
import com.hypherionmc.craterlib.api.events.server.ServerStatusEvent;
|
|
||||||
import com.hypherionmc.craterlib.core.event.CraterEventBus;
|
|
||||||
import com.hypherionmc.craterlib.nojang.network.protocol.status.WrappedServerStatus;
|
|
||||||
import net.minecraft.network.protocol.status.ServerStatus;
|
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
|
||||||
import org.spongepowered.asm.mixin.injection.Inject;
|
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
|
||||||
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
@Mixin(ServerStatus.class)
|
|
||||||
public class ServerStatusMixin {
|
|
||||||
|
|
||||||
@Inject(method = "getFavicon", at = @At("RETURN"), cancellable = true)
|
|
||||||
private void injectIconEvent(CallbackInfoReturnable<String> cir) {
|
|
||||||
ServerStatusEvent.FaviconRequestEvent event = new ServerStatusEvent.FaviconRequestEvent(isEmpty(cir.getReturnValue()) ? Optional.empty() : Optional.of(new WrappedServerStatus.WrappedFavicon(cir.getReturnValue())));
|
|
||||||
CraterEventBus.INSTANCE.postEvent(event);
|
|
||||||
|
|
||||||
if (event.getNewIcon().isPresent()) {
|
|
||||||
cir.setReturnValue(event.getNewIcon().get().toMojang());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isEmpty(String input) {
|
|
||||||
return input == null || input.isEmpty();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,46 +0,0 @@
|
|||||||
package com.hypherionmc.craterlib.mixin.events;
|
|
||||||
|
|
||||||
import com.hypherionmc.craterlib.api.events.server.ServerStatusEvent;
|
|
||||||
import com.hypherionmc.craterlib.core.event.CraterEventBus;
|
|
||||||
import com.hypherionmc.craterlib.utils.ChatUtils;
|
|
||||||
import net.minecraft.network.Connection;
|
|
||||||
import net.minecraft.network.protocol.status.ClientboundStatusResponsePacket;
|
|
||||||
import net.minecraft.network.protocol.status.ServerStatus;
|
|
||||||
import net.minecraft.network.protocol.status.ServerboundStatusRequestPacket;
|
|
||||||
import net.minecraft.server.MinecraftServer;
|
|
||||||
import net.minecraft.server.network.ServerStatusPacketListenerImpl;
|
|
||||||
import org.spongepowered.asm.mixin.Final;
|
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
|
||||||
import org.spongepowered.asm.mixin.Shadow;
|
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
|
||||||
import org.spongepowered.asm.mixin.injection.Inject;
|
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
|
||||||
|
|
||||||
@Mixin(ServerStatusPacketListenerImpl.class)
|
|
||||||
public class ServerStatusPacketListenerMixin {
|
|
||||||
|
|
||||||
@Shadow @Final private Connection connection;
|
|
||||||
|
|
||||||
@Shadow @Final private MinecraftServer server;
|
|
||||||
|
|
||||||
@Inject(method = "handleStatusRequest",
|
|
||||||
at = @At(
|
|
||||||
value = "INVOKE",
|
|
||||||
target = "Lnet/minecraft/network/Connection;send(Lnet/minecraft/network/protocol/Packet;)V",
|
|
||||||
shift = At.Shift.BEFORE),
|
|
||||||
cancellable = true
|
|
||||||
)
|
|
||||||
private void injectHandleStatusRequest(ServerboundStatusRequestPacket arg, CallbackInfo ci) {
|
|
||||||
ServerStatusEvent.StatusRequestEvent event = new ServerStatusEvent.StatusRequestEvent(ChatUtils.mojangToAdventure(server.getStatus().getDescription()));
|
|
||||||
CraterEventBus.INSTANCE.postEvent(event);
|
|
||||||
|
|
||||||
if (event.getNewStatus() != null) {
|
|
||||||
ci.cancel();
|
|
||||||
ServerStatus serverStatus = this.server.getStatus();
|
|
||||||
serverStatus.setDescription(ChatUtils.adventureToMojang(event.getNewStatus()));
|
|
||||||
|
|
||||||
this.connection.send(new ClientboundStatusResponsePacket(serverStatus));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,14 +0,0 @@
|
|||||||
package com.hypherionmc.craterlib.mixin.events;
|
|
||||||
|
|
||||||
import net.minecraft.server.players.StoredUserEntry;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
|
||||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
|
||||||
|
|
||||||
@Mixin(StoredUserEntry.class)
|
|
||||||
public interface StoredUserEntryAccessor<T> {
|
|
||||||
|
|
||||||
@Accessor("user")
|
|
||||||
@Nullable T getUser();
|
|
||||||
|
|
||||||
}
|
|
@@ -1,46 +0,0 @@
|
|||||||
package com.hypherionmc.craterlib.mixin.events;
|
|
||||||
|
|
||||||
import com.hypherionmc.craterlib.api.events.server.WhitelistChangedEvent;
|
|
||||||
import com.hypherionmc.craterlib.core.event.CraterEventBus;
|
|
||||||
import com.hypherionmc.craterlib.nojang.authlib.BridgedGameProfile;
|
|
||||||
import com.mojang.authlib.GameProfile;
|
|
||||||
import net.minecraft.server.players.StoredUserEntry;
|
|
||||||
import net.minecraft.server.players.StoredUserList;
|
|
||||||
import net.minecraft.server.players.UserWhiteListEntry;
|
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
|
||||||
import org.spongepowered.asm.mixin.Shadow;
|
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
|
||||||
import org.spongepowered.asm.mixin.injection.Inject;
|
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
|
||||||
|
|
||||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
|
||||||
@Mixin(StoredUserList.class)
|
|
||||||
public abstract class WhitelistMixin<K, V extends StoredUserEntry<K>> {
|
|
||||||
|
|
||||||
@Shadow protected abstract boolean contains(K k0);
|
|
||||||
|
|
||||||
@Inject(method = "add", at = @At("HEAD"))
|
|
||||||
private void injectAddEvent(V arg, CallbackInfo ci) {
|
|
||||||
try {
|
|
||||||
if (arg instanceof UserWhiteListEntry entry) {
|
|
||||||
StoredUserEntryAccessor entryAccessor = (StoredUserEntryAccessor) entry;
|
|
||||||
if (entryAccessor.getUser() != null && !contains((K) entryAccessor.getUser())) {
|
|
||||||
CraterEventBus.INSTANCE.postEvent(new WhitelistChangedEvent.EntryAdded(BridgedGameProfile.of((GameProfile) entryAccessor.getUser())));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (Exception ignored) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Inject(method = "remove(Lnet/minecraft/server/players/StoredUserEntry;)V", at = @At("HEAD"))
|
|
||||||
private void injectRemoveEvent(V arg, CallbackInfo ci) {
|
|
||||||
try {
|
|
||||||
if (arg instanceof UserWhiteListEntry entry) {
|
|
||||||
StoredUserEntryAccessor entryAccessor = (StoredUserEntryAccessor) entry;
|
|
||||||
if (entryAccessor.getUser() != null && contains((K) entryAccessor.getUser())) {
|
|
||||||
CraterEventBus.INSTANCE.postEvent(new WhitelistChangedEvent.EntryRemoved(BridgedGameProfile.of((GameProfile) entryAccessor.getUser())));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (Exception ignored) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,25 +0,0 @@
|
|||||||
package com.hypherionmc.craterlib.mixin.events.client;
|
|
||||||
|
|
||||||
import com.hypherionmc.craterlib.api.events.client.CraterSinglePlayerEvent;
|
|
||||||
import com.hypherionmc.craterlib.core.event.CraterEventBus;
|
|
||||||
import com.hypherionmc.craterlib.nojang.world.entity.player.BridgedPlayer;
|
|
||||||
import net.minecraft.client.multiplayer.ClientLevel;
|
|
||||||
import net.minecraft.world.entity.Entity;
|
|
||||||
import net.minecraft.world.entity.player.Player;
|
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
|
||||||
import org.spongepowered.asm.mixin.injection.Inject;
|
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
|
||||||
|
|
||||||
@Mixin(ClientLevel.class)
|
|
||||||
public class ClientLevelMixin {
|
|
||||||
|
|
||||||
@Inject(method = "addEntity", at = @At("HEAD"))
|
|
||||||
private void injectSinglePlayerJoinEvent(int i, Entity entity, CallbackInfo ci) {
|
|
||||||
if (entity instanceof Player player) {
|
|
||||||
CraterSinglePlayerEvent.PlayerLogin playerLogin = new CraterSinglePlayerEvent.PlayerLogin(BridgedPlayer.of(player));
|
|
||||||
CraterEventBus.INSTANCE.postEvent(playerLogin);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,31 +0,0 @@
|
|||||||
package com.hypherionmc.craterlib.mixin.events.client;
|
|
||||||
|
|
||||||
import com.hypherionmc.craterlib.api.events.client.ScreenEvent;
|
|
||||||
import com.hypherionmc.craterlib.core.event.CraterEventBus;
|
|
||||||
import com.hypherionmc.craterlib.nojang.client.gui.BridgedScreen;
|
|
||||||
import net.minecraft.client.Minecraft;
|
|
||||||
import net.minecraft.client.gui.screens.Screen;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
|
||||||
import org.spongepowered.asm.mixin.Shadow;
|
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
|
||||||
import org.spongepowered.asm.mixin.injection.Inject;
|
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
|
||||||
|
|
||||||
@Mixin(Minecraft.class)
|
|
||||||
public class MinecraftMixin {
|
|
||||||
|
|
||||||
@Shadow
|
|
||||||
@Nullable
|
|
||||||
public Screen screen;
|
|
||||||
|
|
||||||
@Inject(method = "setScreen", at = @At(value = "TAIL"))
|
|
||||||
private void injectScreenOpeningEvent(Screen screen, CallbackInfo ci) {
|
|
||||||
Screen old = this.screen;
|
|
||||||
if (screen != null) {
|
|
||||||
ScreenEvent.Opening opening = new ScreenEvent.Opening(BridgedScreen.of(old), BridgedScreen.of(screen));
|
|
||||||
CraterEventBus.INSTANCE.postEvent(opening);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,23 +0,0 @@
|
|||||||
package com.hypherionmc.craterlib.mixin.events.client;
|
|
||||||
|
|
||||||
import com.hypherionmc.craterlib.api.events.client.PlayerJoinRealmEvent;
|
|
||||||
import com.hypherionmc.craterlib.core.event.CraterEventBus;
|
|
||||||
import com.hypherionmc.craterlib.nojang.realmsclient.dto.BridgedRealmsServer;
|
|
||||||
import com.mojang.realmsclient.RealmsMainScreen;
|
|
||||||
import com.mojang.realmsclient.dto.RealmsServer;
|
|
||||||
import net.minecraft.client.gui.screens.Screen;
|
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
|
||||||
import org.spongepowered.asm.mixin.injection.Inject;
|
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
|
||||||
|
|
||||||
@Mixin(RealmsMainScreen.class)
|
|
||||||
public class RealmsMainScreenMixin {
|
|
||||||
|
|
||||||
@Inject(at = @At("HEAD"), method = "play")
|
|
||||||
private void play(RealmsServer serverData, Screen arg2, CallbackInfo ci) {
|
|
||||||
PlayerJoinRealmEvent playerJoinRealm = new PlayerJoinRealmEvent(BridgedRealmsServer.of(serverData));
|
|
||||||
CraterEventBus.INSTANCE.postEvent(playerJoinRealm);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,21 +0,0 @@
|
|||||||
package com.hypherionmc.craterlib.nojang.advancements;
|
|
||||||
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import net.minecraft.advancements.Advancement;
|
|
||||||
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
@RequiredArgsConstructor(staticName = "of")
|
|
||||||
public class BridgedAdvancement {
|
|
||||||
|
|
||||||
private final Advancement internal;
|
|
||||||
|
|
||||||
public Optional<BridgedDisplayInfo> displayInfo() {
|
|
||||||
if (internal.getDisplay() != null) {
|
|
||||||
return Optional.of(BridgedDisplayInfo.of(internal.getDisplay()));
|
|
||||||
}
|
|
||||||
|
|
||||||
return Optional.empty();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,29 +0,0 @@
|
|||||||
package com.hypherionmc.craterlib.nojang.advancements;
|
|
||||||
|
|
||||||
import com.hypherionmc.craterlib.utils.ChatUtils;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import net.kyori.adventure.text.Component;
|
|
||||||
import net.minecraft.advancements.DisplayInfo;
|
|
||||||
|
|
||||||
@RequiredArgsConstructor(staticName = "of")
|
|
||||||
public class BridgedDisplayInfo {
|
|
||||||
|
|
||||||
private final DisplayInfo internal;
|
|
||||||
|
|
||||||
public boolean shouldDisplay() {
|
|
||||||
return internal.shouldAnnounceChat();
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isHidden() {
|
|
||||||
return internal.isHidden();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Component displayName() {
|
|
||||||
return ChatUtils.mojangToAdventure(internal.getTitle());
|
|
||||||
}
|
|
||||||
|
|
||||||
public Component description() {
|
|
||||||
return ChatUtils.mojangToAdventure(internal.getDescription());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,29 +0,0 @@
|
|||||||
package com.hypherionmc.craterlib.nojang.authlib;
|
|
||||||
|
|
||||||
import com.mojang.authlib.GameProfile;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
@RequiredArgsConstructor(staticName = "of")
|
|
||||||
public class BridgedGameProfile {
|
|
||||||
|
|
||||||
private final GameProfile internal;
|
|
||||||
|
|
||||||
public static BridgedGameProfile mojang(UUID id, String name) {
|
|
||||||
return new BridgedGameProfile(new GameProfile(id, name));
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return internal.getName();
|
|
||||||
}
|
|
||||||
|
|
||||||
public UUID getId() {
|
|
||||||
return internal.getId();
|
|
||||||
}
|
|
||||||
|
|
||||||
public GameProfile toMojang() {
|
|
||||||
return internal;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,110 +0,0 @@
|
|||||||
package com.hypherionmc.craterlib.nojang.client;
|
|
||||||
|
|
||||||
import com.hypherionmc.craterlib.nojang.client.multiplayer.BridgedClientLevel;
|
|
||||||
import com.hypherionmc.craterlib.nojang.client.multiplayer.BridgedServerData;
|
|
||||||
import com.hypherionmc.craterlib.nojang.client.server.BridgedIntegratedServer;
|
|
||||||
import com.hypherionmc.craterlib.nojang.world.entity.player.BridgedPlayer;
|
|
||||||
import com.hypherionmc.craterlib.utils.ChatUtils;
|
|
||||||
import lombok.Getter;
|
|
||||||
import net.kyori.adventure.text.Component;
|
|
||||||
import net.minecraft.SharedConstants;
|
|
||||||
import net.minecraft.client.Minecraft;
|
|
||||||
import net.minecraft.client.gui.screens.AlertScreen;
|
|
||||||
import net.minecraft.client.gui.screens.Screen;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public class BridgedMinecraft {
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
private static final BridgedMinecraft instance = new BridgedMinecraft();
|
|
||||||
private final Minecraft internal = Minecraft.getInstance();
|
|
||||||
|
|
||||||
public File getGameDirectory() {
|
|
||||||
return internal.gameDirectory;
|
|
||||||
}
|
|
||||||
|
|
||||||
public BridgedOptions getOptions() {
|
|
||||||
return BridgedOptions.of(internal.options);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
public BridgedClientLevel getLevel() {
|
|
||||||
if (internal.level == null)
|
|
||||||
return null;
|
|
||||||
|
|
||||||
return BridgedClientLevel.of(internal.level);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isRealmServer() {
|
|
||||||
return internal.getCurrentServer() != null && internal.isConnectedToRealms();
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isSinglePlayer() {
|
|
||||||
return internal.hasSingleplayerServer();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
public BridgedPlayer getPlayer() {
|
|
||||||
if (internal.player == null)
|
|
||||||
return null;
|
|
||||||
|
|
||||||
return BridgedPlayer.of(internal.player);
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getGameVersion() {
|
|
||||||
return SharedConstants.getCurrentVersion().getName();
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getUserName() {
|
|
||||||
return internal.getUser().getName();
|
|
||||||
}
|
|
||||||
|
|
||||||
public UUID getPlayerId() {
|
|
||||||
return internal.getUser().getGameProfile().getId();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
public BridgedServerData getCurrentServer() {
|
|
||||||
if (internal.getCurrentServer() == null)
|
|
||||||
return null;
|
|
||||||
|
|
||||||
return BridgedServerData.of(internal.getCurrentServer());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
public BridgedIntegratedServer getSinglePlayerServer() {
|
|
||||||
if (internal.getSingleplayerServer() == null)
|
|
||||||
return null;
|
|
||||||
|
|
||||||
return BridgedIntegratedServer.of(internal.getSingleplayerServer());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void showWarningScreen(Component title, Component message) {
|
|
||||||
Screen currentScreen = internal.screen;
|
|
||||||
internal.setScreen(
|
|
||||||
new AlertScreen(
|
|
||||||
() -> internal.setScreen(currentScreen),
|
|
||||||
ChatUtils.adventureToMojang(title),
|
|
||||||
ChatUtils.adventureToMojang(message)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Screen buildWarningScreen(Component title, Component message, Screen parent) {
|
|
||||||
return new AlertScreen(
|
|
||||||
() -> internal.setScreen(parent),
|
|
||||||
ChatUtils.adventureToMojang(title),
|
|
||||||
ChatUtils.adventureToMojang(message)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getServerPlayerCount () {
|
|
||||||
if (internal.getConnection() == null)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
return internal.getConnection().getOnlinePlayers().size();
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,15 +0,0 @@
|
|||||||
package com.hypherionmc.craterlib.nojang.client;
|
|
||||||
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import net.minecraft.client.Options;
|
|
||||||
|
|
||||||
@RequiredArgsConstructor(staticName = "of")
|
|
||||||
public class BridgedOptions {
|
|
||||||
|
|
||||||
private final Options internal;
|
|
||||||
|
|
||||||
public String getLanguage() {
|
|
||||||
return internal.languageCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,41 +0,0 @@
|
|||||||
package com.hypherionmc.craterlib.nojang.client.gui;
|
|
||||||
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import net.minecraft.client.gui.screens.*;
|
|
||||||
import net.minecraft.client.gui.screens.multiplayer.JoinMultiplayerScreen;
|
|
||||||
import net.minecraft.realms.RealmsScreen;
|
|
||||||
|
|
||||||
@RequiredArgsConstructor(staticName = "of")
|
|
||||||
public class BridgedScreen {
|
|
||||||
|
|
||||||
private final Screen internal;
|
|
||||||
|
|
||||||
public boolean isTitleScreen() {
|
|
||||||
return internal instanceof TitleScreen;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isRealmsScreen() {
|
|
||||||
return internal instanceof RealmsScreen;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isServerBrowserScreen() {
|
|
||||||
return internal instanceof JoinMultiplayerScreen;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isLoadingScreen() {
|
|
||||||
return internal instanceof LevelLoadingScreen || internal instanceof ReceivingLevelScreen;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isPauseScreen() {
|
|
||||||
return internal instanceof PauseScreen;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isDisconnetedScreen() {
|
|
||||||
return internal instanceof DisconnectedScreen;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Screen toMojang() {
|
|
||||||
return internal;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,59 +0,0 @@
|
|||||||
package com.hypherionmc.craterlib.nojang.client.multiplayer;
|
|
||||||
|
|
||||||
import com.hypherionmc.craterlib.nojang.core.BridgedBlockPos;
|
|
||||||
import com.hypherionmc.craterlib.nojang.resources.ResourceIdentifier;
|
|
||||||
import com.hypherionmc.craterlib.utils.ChatUtils;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import net.kyori.adventure.text.Component;
|
|
||||||
import net.minecraft.client.multiplayer.ClientLevel;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
|
||||||
|
|
||||||
@RequiredArgsConstructor(staticName = "of")
|
|
||||||
public class BridgedClientLevel {
|
|
||||||
|
|
||||||
private final ClientLevel internal;
|
|
||||||
|
|
||||||
public boolean isClientSide() {
|
|
||||||
return internal.isClientSide();
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getGameTime() {
|
|
||||||
return internal.getGameTime();
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getDayTime() {
|
|
||||||
return internal.getDayTime();
|
|
||||||
}
|
|
||||||
|
|
||||||
public long dayTime() {
|
|
||||||
return internal.dayTime();
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isRaining() {
|
|
||||||
return internal.isRaining();
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isThundering() {
|
|
||||||
return internal.isThundering();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
public ResourceIdentifier getDimensionKey() {
|
|
||||||
return ResourceIdentifier.fromMojang(internal.dimension().location());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
public ResourceIdentifier getBiomeIdentifier(BridgedBlockPos onPos) {
|
|
||||||
AtomicReference<ResourceIdentifier> identifier = new AtomicReference<>(null);
|
|
||||||
internal.getBiome(onPos.toMojang()).unwrap().ifLeft(b -> identifier.set(ResourceIdentifier.fromMojang(b.location())));
|
|
||||||
return identifier.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
public Component getDifficulty() {
|
|
||||||
return ChatUtils.mojangToAdventure(internal.getDifficulty().getDisplayName());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,42 +0,0 @@
|
|||||||
package com.hypherionmc.craterlib.nojang.client.multiplayer;
|
|
||||||
|
|
||||||
import com.hypherionmc.craterlib.utils.ChatUtils;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import net.kyori.adventure.text.Component;
|
|
||||||
import net.minecraft.ChatFormatting;
|
|
||||||
import net.minecraft.client.multiplayer.ServerData;
|
|
||||||
|
|
||||||
@RequiredArgsConstructor(staticName = "of")
|
|
||||||
public class BridgedServerData {
|
|
||||||
|
|
||||||
private final ServerData internal;
|
|
||||||
|
|
||||||
public String name() {
|
|
||||||
return internal.name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String ip() {
|
|
||||||
return internal.ip;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Component motd() {
|
|
||||||
return ChatUtils.mojangToAdventure(internal.motd);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getMaxPlayers() {
|
|
||||||
if (!internal.pinged || internal.status.getString() == null) {
|
|
||||||
return internal.playerList.size() + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
return Integer.parseInt(ChatFormatting.stripFormatting(internal.status.getString()).split("/")[1]);
|
|
||||||
} catch (Exception ignored) {}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ServerData toMojang() {
|
|
||||||
return internal;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user