Skip to content

Commit

Permalink
v1.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
byteful committed Jun 17, 2024
1 parent 2257950 commit a847a22
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 69 deletions.
14 changes: 7 additions & 7 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ plugins {
}

repositories {
mavenLocal()
mavenCentral()
maven {
url = uri('https://hub.spigotmc.org/nexus/content/repositories/snapshots/')
}
maven {
url = uri('https://repo.papermc.io/repository/maven-public/')
}
maven {
url = uri('https://oss.sonatype.org/content/groups/public/')
}
Expand All @@ -20,17 +22,14 @@ repositories {
maven {
url = uri('https://repo.maven.apache.org/maven2/')
}
maven {
url = uri('https://jitpack.io')
}
maven {
url = uri('https://redempt.dev')
}
maven {
url = uri('https://repo.extendedclip.com/content/repositories/placeholderapi/')
url = uri('https://jitpack.io')
}
maven {
url = uri('https://repo.papermc.io/repository/maven-public/')
url = uri('https://repo.extendedclip.com/content/repositories/placeholderapi/')
}
maven {
url = uri('https://hub.jeff-media.com/nexus/repository/jeff-media-public/')
Expand All @@ -48,7 +47,8 @@ dependencies {
implementation 'org.bstats:bstats-bukkit:3.0.2'
implementation 'com.jeff_media:MorePersistentDataTypes:2.4.0'

compileOnly 'dev.folia:folia-api:1.20.4-R0.1-SNAPSHOT'
compileOnly files('libs/folia-api-1.20.4-R0.1-SNAPSHOT.jar') // Modified API jar with Java 8 support
compileOnly 'net.kyori:adventure-api:4.17.0' // Not used but needed for Folia compilation
compileOnly 'org.spigotmc:spigot-api:1.14.4-R0.1-SNAPSHOT'
compileOnly 'org.jetbrains:annotations:24.1.0'
compileOnly 'me.clip:placeholderapi:2.11.6'
Expand Down
Binary file added libs/folia-api-1.20.4-R0.1-SNAPSHOT.jar
Binary file not shown.
82 changes: 20 additions & 62 deletions src/main/java/me/byteful/plugin/leveltools/util/Text.java
Original file line number Diff line number Diff line change
@@ -1,86 +1,44 @@
package me.byteful.plugin.leveltools.util;

import org.apache.commons.lang3.ArrayUtils;
import java.util.*;
import org.bukkit.ChatColor;
import org.jetbrains.annotations.NotNull;
import redempt.redlib.misc.FormatUtils;

import java.util.*;
import java.util.stream.Collectors;

// Borrowed from RedLib (https://github.com/boxbeam/RedCommands/blob/master/src/redempt/redlib/misc/FormatUtils.java)
public final class Text {
@NotNull
public static String decolorize(@NotNull String string) {
return colorize(string).replace("" + ChatColor.COLOR_CHAR, "&");
}

private static Set<Character> colorChars = "4c6e2ab319d5f780rlonmk".chars().mapToObj(i -> (char) i).collect(Collectors.toSet());

@NotNull
// Author: boxbeam
public static String colorize(String input) {
StringBuilder builder = new StringBuilder();
for (int i = 0; i < input.length(); i++) {
char c = input.charAt(i);
if (i + 1 >= input.length()) {
builder.append(c);
continue;
}
char n = input.charAt(i + 1);
if (c == '\\' && (n == '&' || n == '\\')) {
i++;
builder.append(n);
continue;
}
if (c != '&') {
builder.append(c);
continue;
}
if (colorChars.contains(n)) {
builder.append(ChatColor.COLOR_CHAR);
continue;
}
if (n == '#' && i + 7 <= input.length()) {
String hexCode = input.substring(i + 2, i + 8).toUpperCase(Locale.ROOT);
if (hexCode.chars().allMatch(ch -> (ch <= '9' && ch >= '0') || (ch <= 'F' && ch >= 'A'))) {
hexCode = Arrays.stream(hexCode.split("")).map(s -> ChatColor.COLOR_CHAR + s).collect(Collectors.joining());
builder.append(ChatColor.COLOR_CHAR).append("x").append(hexCode);
i += 7;
continue;
}
}
builder.append(c);
}
return builder.toString();
return FormatUtils.color(input);
}

// From Apache lang library
public static String[] substringsBetween(String str, String open, String close) {
int strLen = str.length();
if (strLen == 0) {
return ArrayUtils.EMPTY_STRING_ARRAY;
} else {
int closeLen = close.length();
int openLen = open.length();
List<String> list = new ArrayList();

int end;
for(int pos = 0; pos < strLen - closeLen; pos = end + closeLen) {
int start = str.indexOf(open, pos);
if (start < 0) {
break;
}

start += openLen;
end = str.indexOf(close, start);
if (end < 0) {
break;
}
int closeLen = close.length();
int openLen = open.length();
List<String> list = new ArrayList();

int end;
for (int pos = 0; pos < strLen - closeLen; pos = end + closeLen) {
int start = str.indexOf(open, pos);
if (start < 0) {
break;
}

list.add(str.substring(start, end));
start += openLen;
end = str.indexOf(close, start);
if (end < 0) {
break;
}

return list.isEmpty() ? null : (String[])list.toArray(ArrayUtils.EMPTY_STRING_ARRAY);
list.add(str.substring(start, end));
}

return list.isEmpty() ? null : list.toArray(new String[0]);
}
}

0 comments on commit a847a22

Please sign in to comment.