Use Utilities-OG API, update gradle
This commit is contained in:
1 parent
9ab24f4453
commit
98abba5dda
15 files changed
+157
-205
No files matched your search
@@ -0,0 +1,3 @@
|
||||
[submodule "libs/Utilities-OG"]
|
||||
path = libs/Utilities-OG
|
||||
url = https://github.com/true-og/Utilities-OG
|
||||
Executable
+4
@@ -0,0 +1,4 @@
|
||||
#!/usr/bin/bash
|
||||
|
||||
# Fetch all submodule content.
|
||||
git submodule update --force --recursive --init
|
||||
+10
-21
@@ -1,8 +1,7 @@
|
||||
plugins {
|
||||
id("com.gradleup.shadow") version "8.3.6" // Import shadow API.
|
||||
java // Tell gradle this is a java project.
|
||||
id("io.github.goooler.shadow") version "8.1.8"
|
||||
eclipse // Import eclipse plugin for IDE integration.
|
||||
kotlin("jvm") version "1.9.23" // Import kotlin jvm plugin for kotlin/java integration.
|
||||
}
|
||||
|
||||
java {
|
||||
@@ -25,17 +24,17 @@ tasks.named<ProcessResources>("processResources") {
|
||||
filesMatching("plugin.yml") {
|
||||
expand(props)
|
||||
}
|
||||
from("LICENSE") { // Bundle license into .jars.
|
||||
into("/")
|
||||
}
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
|
||||
gradlePluginPortal()
|
||||
|
||||
maven {
|
||||
url = uri("https://repo.purpurmc.org/snapshots")
|
||||
}
|
||||
|
||||
maven {
|
||||
url = uri("https://oss.sonatype.org/content/groups/public/")
|
||||
}
|
||||
@@ -44,46 +43,36 @@ repositories {
|
||||
dependencies {
|
||||
compileOnly("org.purpurmc.purpur:purpur-api:1.19.4-R0.1-SNAPSHOT") // Declare purpur API version to be packaged.
|
||||
compileOnly("io.github.miniplaceholders:miniplaceholders-api:2.2.3") // Import MiniPlaceholders API.
|
||||
|
||||
compileOnly(project(":libs:Utilities-OG"))
|
||||
compileOnly("org.projectlombok:lombok:1.18.28")
|
||||
}
|
||||
|
||||
tasks.withType<AbstractArchiveTask>().configureEach {
|
||||
tasks.withType<AbstractArchiveTask>().configureEach { // Ensure reproducible .jars
|
||||
isPreserveFileTimestamps = false
|
||||
isReproducibleFileOrder = true
|
||||
}
|
||||
|
||||
tasks.shadowJar {
|
||||
exclude("io.github.miniplaceholders.*") // Exclude the MiniPlaceholders package from being shadowed.
|
||||
archiveClassifier.set("") // Use empty string instead of null.
|
||||
minimize()
|
||||
}
|
||||
|
||||
tasks.jar {
|
||||
tasks.build {
|
||||
dependsOn(tasks.shadowJar)
|
||||
archiveClassifier.set("part")
|
||||
}
|
||||
|
||||
tasks.shadowJar {
|
||||
archiveClassifier.set("") // Use empty string instead of null
|
||||
from("LICENSE") {
|
||||
into("/")
|
||||
}
|
||||
}
|
||||
|
||||
tasks.jar {
|
||||
dependsOn("shadowJar")
|
||||
archiveClassifier.set("part")
|
||||
}
|
||||
|
||||
tasks.withType<JavaCompile>().configureEach {
|
||||
options.compilerArgs.add("-parameters")
|
||||
options.compilerArgs.add("-Xlint:deprecation") // Triggers deprecation warning messages.
|
||||
options.encoding = "UTF-8"
|
||||
options.isFork = true
|
||||
}
|
||||
|
||||
kotlin {
|
||||
jvmToolchain(17)
|
||||
}
|
||||
|
||||
java {
|
||||
toolchain {
|
||||
languageVersion = JavaLanguageVersion.of(17)
|
||||
|
||||
Vendored
BIN
Binary file not shown.
+1
-1
@@ -1,6 +1,6 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.1-bin.zip
|
||||
networkTimeout=10000
|
||||
validateDistributionUrl=true
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
|
||||
##############################################################################
|
||||
#
|
||||
@@ -55,7 +57,7 @@
|
||||
# Darwin, MinGW, and NonStop.
|
||||
#
|
||||
# (3) This script is generated from the Groovy template
|
||||
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
||||
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
||||
# within the Gradle project.
|
||||
#
|
||||
# You can find Gradle at https://github.com/gradle/gradle/.
|
||||
@@ -84,7 +86,7 @@ done
|
||||
# shellcheck disable=SC2034
|
||||
APP_BASE_NAME=${0##*/}
|
||||
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
|
||||
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
|
||||
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD=maximum
|
||||
@@ -112,7 +114,7 @@ case "$( uname )" in #(
|
||||
NONSTOP* ) nonstop=true ;;
|
||||
esac
|
||||
|
||||
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
||||
CLASSPATH="\\\"\\\""
|
||||
|
||||
|
||||
# Determine the Java command to use to start the JVM.
|
||||
@@ -203,7 +205,7 @@ fi
|
||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||
|
||||
# Collect all arguments for the java command:
|
||||
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
|
||||
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
|
||||
# and any embedded shellness will be escaped.
|
||||
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
|
||||
# treated as '${Hostname}' itself on the command line.
|
||||
@@ -211,7 +213,7 @@ DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||
set -- \
|
||||
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
||||
-classpath "$CLASSPATH" \
|
||||
org.gradle.wrapper.GradleWrapperMain \
|
||||
-jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \
|
||||
"$@"
|
||||
|
||||
# Stop when "xargs" is not available.
|
||||
|
||||
Vendored
+4
-2
@@ -13,6 +13,8 @@
|
||||
@rem See the License for the specific language governing permissions and
|
||||
@rem limitations under the License.
|
||||
@rem
|
||||
@rem SPDX-License-Identifier: Apache-2.0
|
||||
@rem
|
||||
|
||||
@if "%DEBUG%"=="" @echo off
|
||||
@rem ##########################################################################
|
||||
@@ -68,11 +70,11 @@ goto fail
|
||||
:execute
|
||||
@rem Setup the command line
|
||||
|
||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||
set CLASSPATH=
|
||||
|
||||
|
||||
@rem Execute Gradle
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %*
|
||||
|
||||
:end
|
||||
@rem End local scope for the variables with windows NT shell
|
||||
|
||||
Submodule
+1
Submodule libs/Utilities-OG added at 6151b2de7f.
@@ -6,3 +6,15 @@ pluginManagement {
|
||||
}
|
||||
|
||||
rootProject.name = "PlayTimes-OG"
|
||||
|
||||
// Run the bootstrap at configuration time.
|
||||
val process = ProcessBuilder("sh", "bootstrap.sh")
|
||||
.directory(rootDir)
|
||||
.start()
|
||||
|
||||
val exitValue = process.waitFor()
|
||||
if (exitValue != 0) {
|
||||
throw GradleException("bootstrap.sh failed with exit code $exitValue")
|
||||
}
|
||||
|
||||
include("libs:Utilities-OG")
|
||||
@@ -20,7 +20,6 @@ import me.codedred.playtimes.data.DataManager;
|
||||
import me.codedred.playtimes.data.database.manager.DatabaseManager;
|
||||
import me.codedred.playtimes.listeners.Join;
|
||||
import me.codedred.playtimes.listeners.Quit;
|
||||
import me.codedred.playtimes.server.ServerManager;
|
||||
import me.codedred.playtimes.statistics.StatManager;
|
||||
import me.codedred.playtimes.time.TimeManager;
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@ package me.codedred.playtimes.commands;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@@ -24,7 +23,7 @@ import me.codedred.playtimes.statistics.StatManager;
|
||||
import me.codedred.playtimes.time.TimeConstants;
|
||||
import me.codedred.playtimes.time.TimeManager;
|
||||
import me.codedred.playtimes.utils.ChatUtil;
|
||||
import me.codedred.playtimes.utils.OGUtils;
|
||||
import net.trueog.utilitiesog.UtilitiesOG;
|
||||
|
||||
public class Time implements CommandExecutor {
|
||||
|
||||
@@ -116,7 +115,7 @@ public class Time implements CommandExecutor {
|
||||
}
|
||||
sender.sendMessage(ChatUtil.format("&6&l*** PlayTimes Version Info ***"));
|
||||
if (sender instanceof Player) {
|
||||
OGUtils.playTimesOGMessage((Player) sender,
|
||||
UtilitiesOG.trueogMessage((Player) sender,
|
||||
"&6" +
|
||||
"Server version: " +
|
||||
"&f" +
|
||||
@@ -140,9 +139,8 @@ public class Time implements CommandExecutor {
|
||||
);
|
||||
}
|
||||
else {
|
||||
Logger logger = Bukkit.getServer().getLogger();
|
||||
logger.info(OGUtils.legacySerializerAnyCase(
|
||||
"&6" +
|
||||
UtilitiesOG.logToConsole("[PlayTimes-OG] ",
|
||||
"&6" +
|
||||
"Server version: " +
|
||||
"&f" +
|
||||
Bukkit.getServer().getVersion() +
|
||||
@@ -162,7 +160,7 @@ public class Time implements CommandExecutor {
|
||||
"\nAFK Status: " +
|
||||
"&f" +
|
||||
DataManager.getInstance().hasAfkEnabled()
|
||||
).content());
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,67 +1,67 @@
|
||||
package me.codedred.playtimes.data;
|
||||
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import me.codedred.playtimes.PlayTimes;
|
||||
import me.codedred.playtimes.afk.AFKManager;
|
||||
import me.codedred.playtimes.data.database.manager.DatabaseManager;
|
||||
import me.codedred.playtimes.server.ServerManager;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public class DataManager {
|
||||
|
||||
private static final DataManager instance = new DataManager();
|
||||
private final CustomConfig data = new CustomConfig(
|
||||
JavaPlugin.getPlugin(PlayTimes.class),
|
||||
"data.yml"
|
||||
);
|
||||
private final CustomConfig db = new CustomConfig(
|
||||
JavaPlugin.getPlugin(PlayTimes.class),
|
||||
"database.yml"
|
||||
);
|
||||
private final CustomConfig cfg = new CustomConfig(
|
||||
JavaPlugin.getPlugin(PlayTimes.class),
|
||||
"config.yml"
|
||||
);
|
||||
private static final DataManager instance = new DataManager();
|
||||
private final CustomConfig data = new CustomConfig(
|
||||
JavaPlugin.getPlugin(PlayTimes.class),
|
||||
"data.yml"
|
||||
);
|
||||
private final CustomConfig db = new CustomConfig(
|
||||
JavaPlugin.getPlugin(PlayTimes.class),
|
||||
"database.yml"
|
||||
);
|
||||
private final CustomConfig cfg = new CustomConfig(
|
||||
JavaPlugin.getPlugin(PlayTimes.class),
|
||||
"config.yml"
|
||||
);
|
||||
|
||||
public static DataManager getInstance() {
|
||||
return instance;
|
||||
}
|
||||
public static DataManager getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
public FileConfiguration getConfig() {
|
||||
return cfg.getConfig();
|
||||
}
|
||||
public FileConfiguration getConfig() {
|
||||
return cfg.getConfig();
|
||||
}
|
||||
|
||||
public FileConfiguration getData() {
|
||||
return data.getConfig();
|
||||
}
|
||||
public FileConfiguration getData() {
|
||||
return data.getConfig();
|
||||
}
|
||||
|
||||
public FileConfiguration getDBConfig() {
|
||||
return db.getConfig();
|
||||
}
|
||||
public FileConfiguration getDBConfig() {
|
||||
return db.getConfig();
|
||||
}
|
||||
|
||||
public void saveData() {
|
||||
data.saveConfig();
|
||||
}
|
||||
public void saveData() {
|
||||
data.saveConfig();
|
||||
}
|
||||
|
||||
public void reloadAll() {
|
||||
data.reloadConfig();
|
||||
cfg.reloadConfig();
|
||||
db.reloadConfig();
|
||||
if (hasAfkEnabled()) AFKManager.getInstance().reload();
|
||||
}
|
||||
public void reloadAll() {
|
||||
data.reloadConfig();
|
||||
cfg.reloadConfig();
|
||||
db.reloadConfig();
|
||||
if (hasAfkEnabled()) AFKManager.getInstance().reload();
|
||||
}
|
||||
|
||||
public void reloadDatabase() {
|
||||
db.reloadConfig();
|
||||
}
|
||||
public void reloadDatabase() {
|
||||
db.reloadConfig();
|
||||
}
|
||||
|
||||
public boolean hasDatabase() {
|
||||
return (
|
||||
getDBConfig().getBoolean("database-settings.enabled") &&
|
||||
DatabaseManager.getInstance().isConnected()
|
||||
);
|
||||
}
|
||||
public boolean hasDatabase() {
|
||||
return (
|
||||
getDBConfig().getBoolean("database-settings.enabled") &&
|
||||
DatabaseManager.getInstance().isConnected()
|
||||
);
|
||||
}
|
||||
|
||||
public boolean hasAfkEnabled() {
|
||||
return getConfig().getBoolean("afk-settings.enabled", false);
|
||||
}
|
||||
public boolean hasAfkEnabled() {
|
||||
return getConfig().getBoolean("afk-settings.enabled", false);
|
||||
}
|
||||
}
|
||||
@@ -4,18 +4,22 @@ import org.bukkit.command.CommandSender;
|
||||
|
||||
import me.codedred.playtimes.data.DataManager;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import net.trueog.utilitiesog.UtilitiesOG;
|
||||
|
||||
public class ChatUtil {
|
||||
|
||||
private static final DataManager DATA_MANAGER = DataManager.getInstance();
|
||||
|
||||
public enum ChatTypes {
|
||||
|
||||
NO_PERMISSION,
|
||||
PLAYER_NOT_FOUND,
|
||||
PLAYER_NEVER_PLAYED,
|
||||
|
||||
}
|
||||
|
||||
public static void errno(CommandSender sender, ChatTypes type) {
|
||||
|
||||
switch (type) {
|
||||
case NO_PERMISSION:
|
||||
sender.sendMessage(
|
||||
@@ -37,14 +41,19 @@ public class ChatUtil {
|
||||
);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static TextComponent format(String msg) {
|
||||
return OGUtils.legacySerializerAnyCase(msg);
|
||||
|
||||
return UtilitiesOG.trueogColorize(msg);
|
||||
|
||||
}
|
||||
|
||||
public static TextComponent formatWithPrefix(String msg) {
|
||||
return OGUtils.legacySerializerAnyCase(DATA_MANAGER.getConfig().getString("prefix") + msg);
|
||||
|
||||
return UtilitiesOG.trueogColorize(DATA_MANAGER.getConfig().getString("prefix") + msg);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,37 +1,60 @@
|
||||
package me.codedred.playtimes.utils;
|
||||
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import net.trueog.utilitiesog.utils.TextUtils;
|
||||
|
||||
public class HexUtil {
|
||||
|
||||
private HexUtil() {
|
||||
throw new IllegalStateException("Utility Class");
|
||||
}
|
||||
private HexUtil() {
|
||||
|
||||
public static String hex(String message) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
int length = message.length();
|
||||
throw new IllegalStateException("Utility Class");
|
||||
|
||||
for (int i = 0; i < length; i++) {
|
||||
if (
|
||||
message.charAt(i) == '<' &&
|
||||
i + 8 < length &&
|
||||
message.charAt(i + 1) == '#'
|
||||
) {
|
||||
String hexCode = message.substring(i + 2, i + 8);
|
||||
if (message.charAt(i + 8) == '>' && isValidHexCode(hexCode)) {
|
||||
builder.append(ChatColor.of('#' + hexCode));
|
||||
i += 8; // Skip the processed hex code and the '>'
|
||||
continue;
|
||||
}
|
||||
}
|
||||
builder.append(message.charAt(i));
|
||||
}
|
||||
}
|
||||
|
||||
return ChatColor.translateAlternateColorCodes('&', builder.toString());
|
||||
}
|
||||
public static String hex(String message) {
|
||||
|
||||
private static boolean isValidHexCode(String hexCode) {
|
||||
return hexCode.matches("^[a-fA-F0-9]{6}$");
|
||||
}
|
||||
StringBuilder builder = new StringBuilder();
|
||||
int length = message.length();
|
||||
for (int i = 0; i < length; i++) {
|
||||
|
||||
if (message.charAt(i) == '<' && i + 8 < length && message.charAt(i + 1) == '#') {
|
||||
|
||||
String hexCode = message.substring(i + 2, i + 8);
|
||||
if (message.charAt(i + 8) == '>' && isValidHexCode(hexCode)) {
|
||||
|
||||
builder.append(toLegacyHex(hexCode));
|
||||
|
||||
i += 8;
|
||||
continue;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
builder.append(message.charAt(i));
|
||||
|
||||
}
|
||||
|
||||
return TextUtils.processColorCodes(builder.toString());
|
||||
|
||||
}
|
||||
|
||||
private static boolean isValidHexCode(String hexCode) {
|
||||
|
||||
return hexCode.matches("^[a-fA-F0-9]{6}$");
|
||||
|
||||
}
|
||||
|
||||
private static String toLegacyHex(String hexCode) {
|
||||
|
||||
StringBuilder legacy = new StringBuilder("&x");
|
||||
|
||||
for (char c : hexCode.toCharArray()) {
|
||||
|
||||
legacy.append('&').append(c);
|
||||
|
||||
}
|
||||
|
||||
return legacy.toString();
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,90 +0,0 @@
|
||||
package me.codedred.playtimes.utils;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
|
||||
public class OGUtils {
|
||||
|
||||
// Sends a formatted message to the player (including name replacement).
|
||||
public static void playTimesOGMessage(Player p, String message) {
|
||||
|
||||
p.sendMessage(legacySerializerAnyCase((message)));
|
||||
|
||||
}
|
||||
|
||||
public static TextComponent legacySerializerAnyCase(String subject) {
|
||||
|
||||
int count = 0;
|
||||
// Count the number of '&' characters to determine the size of the array
|
||||
for (char c : subject.toCharArray()) {
|
||||
|
||||
if (c == '&') {
|
||||
|
||||
count++;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Create an array to store the positions of '&' characters
|
||||
int[] positions = new int[count];
|
||||
int index = 0;
|
||||
// Find the positions of '&' characters and store in the array
|
||||
for (int i = 0; i < subject.length(); i++) {
|
||||
|
||||
if (subject.charAt(i) == '&') {
|
||||
|
||||
if (isUpperBukkitCode(subject.charAt(i + 1))) {
|
||||
|
||||
subject = replaceCharAtIndex(subject, (i + 1), Character.toLowerCase(subject.charAt(i + 1)));
|
||||
|
||||
}
|
||||
|
||||
positions[index++] = i;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return LegacyComponentSerializer.legacyAmpersand().deserialize(subject);
|
||||
|
||||
}
|
||||
|
||||
private static boolean isUpperBukkitCode(char input) {
|
||||
|
||||
char[] bukkitColorCodes = {'A', 'B', 'C', 'D', 'E', 'F', 'K', 'L', 'M', 'N', 'O', 'R'};
|
||||
boolean match = false;
|
||||
|
||||
// Loop through each character in the array.
|
||||
for (char c : bukkitColorCodes) {
|
||||
// Check if the current character in the array is equal to the input character.
|
||||
if (c == input) {
|
||||
|
||||
match = true;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return match;
|
||||
|
||||
}
|
||||
|
||||
private static String replaceCharAtIndex(String original, int index, char newChar) {
|
||||
|
||||
// Check if the index is valid
|
||||
if (index >= 0 && index < original.length()) {
|
||||
|
||||
// Create a new string with the replaced character
|
||||
return original.substring(0, index) + newChar + original.substring(index + 1);
|
||||
|
||||
}
|
||||
|
||||
// If the index is invalid, return the original string
|
||||
return original;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user