Update gradle to 8.14.2, add auto formatting

This commit is contained in:
NotAlexNoyle committed 2025-06-24 22:52:27 -04:00
1 parent 892d76432c
commit 62c97bc6e5
8 files changed
+273 -274

No files matched your search

+21 -14
View File
@@ -1,6 +1,8 @@
plugins {
id("java") // Tell gradle this is a java project.
id("java-library") // Import helper for source-based libraries.
id("com.diffplug.spotless") version "7.0.4" // Import auto-formatter.
id("com.gradleup.shadow") version "8.3.6" // Import shadow API.
java // Tell gradle this is a java project.
eclipse // Import eclipse plugin for IDE integration.
}
@@ -10,20 +12,17 @@ java {
}
group = "net.trueog.antipearlglitchog" // Declare bundle identifier.
version = "1.0" // Declare plugin version (will be in .jar).
val apiVersion = "1.19" // Declare minecraft server target version.
tasks.named<ProcessResources>("processResources") {
val props = mapOf(
"version" to version,
"apiVersion" to apiVersion
)
val props = mapOf("version" to version, "apiVersion" to apiVersion)
inputs.properties(props) // Indicates to rerun if version changes.
filesMatching("plugin.yml") {
expand(props)
}
filesMatching("plugin.yml") { expand(props) }
from("LICENSE") { // Bundle license into .jars.
into("/")
}
@@ -32,9 +31,7 @@ tasks.named<ProcessResources>("processResources") {
repositories {
mavenCentral()
gradlePluginPortal()
maven {
url = uri("https://repo.purpurmc.org/snapshots")
}
maven { url = uri("https://repo.purpurmc.org/snapshots") }
}
dependencies {
@@ -54,12 +51,11 @@ tasks.shadowJar {
}
tasks.build {
dependsOn(tasks.spotlessApply)
dependsOn(tasks.shadowJar)
}
tasks.jar {
archiveClassifier.set("part")
}
tasks.jar { archiveClassifier.set("part") }
tasks.withType<JavaCompile>().configureEach {
options.compilerArgs.add("-parameters")
@@ -74,3 +70,14 @@ java {
vendor = JvmVendorSpec.GRAAL_VM
}
}
spotless {
java {
removeUnusedImports()
palantirJavaFormat()
}
kotlinGradle {
ktfmt().kotlinlangStyle().configure { it.setMaxWidth(120) }
target("build.gradle.kts", "settings.gradle.kts")
}
}
Binary file not shown.
+1 -1
View File
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.2-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Vendored
+6 -4
View File
@@ -15,6 +15,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0
#
##############################################################################
#
@@ -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
View File
@@ -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
@@ -1,7 +1,6 @@
package net.trueog.antipearlglitchog;
import java.util.logging.Logger;
import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;
@@ -18,7 +17,6 @@ public final class AntiPearlGlitch extends JavaPlugin {
Bukkit.getPluginManager().registerEvents(new PearlInteractEvent(), this);
this.saveDefaultConfig();
log.info("[AntiPearlGlitch] Plugin enabled!");
}
@Override
@@ -26,13 +24,10 @@ public final class AntiPearlGlitch extends JavaPlugin {
// Plugin shutdown logic.
log.info("[AntiPearlGlitch] Plugin disabled!");
}
public static AntiPearlGlitch getInstance() {
return instance;
}
}
}
@@ -1,7 +1,6 @@
package net.trueog.antipearlglitchog;
import java.util.logging.Logger;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Location;
@@ -19,214 +18,222 @@ import org.bukkit.util.BoundingBox;
public class PearlInteractEvent implements Listener {
AntiPearlGlitch plugin = AntiPearlGlitch.getInstance();
AntiPearlGlitch plugin = AntiPearlGlitch.getInstance();
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onPearlTeleport(PlayerTeleportEvent event) {
if (!(event.getCause() == PlayerTeleportEvent.TeleportCause.ENDER_PEARL)) return;
Player player = event.getPlayer();
Location pearlLandingLocation = event.getTo();
double patchedPearlYLocation = Math.rint(pearlLandingLocation.getY());
// Set the initial pearl landing location and check if the player can bypass the checks.
pearlLandingLocation.setY(patchedPearlYLocation);
event.setTo(pearlLandingLocation);
// Create a bounding box with and set it's center at the pearl landing location.
BoundingBox playerHitBox = player.getBoundingBox();
// Subtract the original bounding box coordinates to set them to zero. Then add the new bounding box coordinates
// to match the pearl land location.
playerHitBox.shift(
-playerHitBox.getCenterX() + pearlLandingLocation.getX(),
-playerHitBox.getCenterY() + pearlLandingLocation.getY(),
-playerHitBox.getCenterZ() + pearlLandingLocation.getZ());
Block pearlLandingBlock = pearlLandingLocation.getBlock();
Block pearlLandingBlockNorth = pearlLandingBlock.getRelative(BlockFace.NORTH);
Block pearlLandingBlockSouth = pearlLandingBlock.getRelative(BlockFace.SOUTH);
Block pearlLandingBlockEast = pearlLandingBlock.getRelative(BlockFace.EAST);
Block pearlLandingBlockWest = pearlLandingBlock.getRelative(BlockFace.WEST);
// Patch carpets.
if (pearlLandingBlock.getType().name().contains("CARPET")) {
pearlLandingLocation.setY(pearlLandingLocation.getY() + 0.08);
playerHitBox.shift(0.0, 0.08, 0.0);
}
// Cancel the checks if the player has permission to bypass them.
if (player.hasPermission("antipearlglitch.bypass")) return;
// If the pearl lands somewhere without any blocks adjacent to the landing spot then return.
if (pearlLandingBlock.getType().isAir()
&& pearlLandingBlockNorth.getType().isAir()
&& pearlLandingBlockSouth.getType().isAir()
&& pearlLandingBlockEast.getType().isAir()
&& pearlLandingBlockWest.getType().isAir()) {
return;
}
// Create bounding boxes for blocks that are adjacent to the pearl landing location.
BoundingBox blockBoundingBox = pearlLandingBlock.getBoundingBox();
BoundingBox blockBoundingBoxNorth = pearlLandingBlockNorth.getBoundingBox();
BoundingBox blockBoundingBoxSouth = pearlLandingBlockSouth.getBoundingBox();
BoundingBox blockBoundingBoxEast = pearlLandingBlockEast.getBoundingBox();
BoundingBox blockBoundingBoxWest = pearlLandingBlockWest.getBoundingBox();
// Check if the bounding boxes of the blocks under overlap with the bounding box of the player.
if (playerHitBox.overlaps(blockBoundingBox)
&& !pearlLandingBlock.isPassable()
&& !pearlLandingBlock.getType().name().contains("CARPET")) {
// Get the pearl landing location.
Block pearlLandingBlockDown = pearlLandingBlock.getRelative(BlockFace.DOWN);
// Get all the blocks relative to the block that's under the pearl landing location.
Block pearlLandingBlockDownNorth = pearlLandingBlockDown.getRelative(BlockFace.NORTH);
Block pearlLandingBlockDownSouth = pearlLandingBlockDown.getRelative(BlockFace.SOUTH);
Block pearlLandingBlockDownEast = pearlLandingBlockDown.getRelative(BlockFace.EAST);
Block pearlLandingBlockDownWest = pearlLandingBlockDown.getRelative(BlockFace.WEST);
if (pearlLandingBlockDown.isPassable()) {
if (!pearlLandingBlockDownNorth.getBoundingBox().overlaps(playerHitBox)
&& pearlLandingBlockDownNorth.isPassable()
&& !pearlLandingBlockDownSouth.getBoundingBox().overlaps(playerHitBox)
&& pearlLandingBlockDownSouth.isPassable()
&& !pearlLandingBlockDownEast.getBoundingBox().overlaps(playerHitBox)
&& pearlLandingBlockDownEast.isPassable()
&& !pearlLandingBlockDownWest.getBoundingBox().overlaps(playerHitBox)
&& pearlLandingBlockDownWest.isPassable()) {
pearlLandingLocation.setY(pearlLandingLocation.getY() - 1.0);
// Set the final teleport location.
event.setTo(pearlLandingLocation);
return;
}
}
if (pearlLandingBlockDownNorth.getBoundingBox().overlaps(playerHitBox)
&& !pearlLandingBlockDownNorth.isPassable()
&& pearlLandingBlockDownSouth.getBoundingBox().overlaps(playerHitBox)
&& !pearlLandingBlockDownSouth.isPassable()
&& pearlLandingBlockDownEast.getBoundingBox().overlaps(playerHitBox)
&& !pearlLandingBlockDownEast.isPassable()
&& pearlLandingBlockDownWest.getBoundingBox().overlaps(playerHitBox)
&& !pearlLandingBlockDownWest.isPassable()
&& !pearlLandingBlockDown.getBoundingBox().overlaps(playerHitBox)
&& !pearlLandingBlockDown
.getRelative(BlockFace.DOWN)
.getBoundingBox()
.overlaps(playerHitBox)) {
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onPearlTeleport(PlayerTeleportEvent event) {
pearlLandingLocation.setY(pearlLandingLocation.getY() - 1.0);
// Set the final teleport location.
event.setTo(pearlLandingLocation);
if (! (event.getCause() == PlayerTeleportEvent.TeleportCause.ENDER_PEARL)) return;
return;
}
Player player = event.getPlayer();
// Checks are now done.
// Return the pearl to the player.
returnPearl(player);
// Warn the staff about the incident.
// Requires antipearlglitch.notify.
warnStaff(player, pearlLandingBlock);
// Cancel the event.
event.setCancelled(true);
Location pearlLandingLocation = event.getTo();
double patchedPearlYLocation = Math.rint(pearlLandingLocation.getY());
return;
}
if (playerHitBox.overlaps(blockBoundingBoxNorth)
&& !pearlLandingBlockNorth.isPassable()
&& !pearlLandingBlockNorth.getType().name().contains("CARPET")) {
// Set the initial pearl landing location and check if the player can bypass the checks.
pearlLandingLocation.setY(patchedPearlYLocation);
event.setTo(pearlLandingLocation);
warnStaff(player, pearlLandingBlockNorth);
// Create a bounding box with and set it's center at the pearl landing location.
BoundingBox playerHitBox = player.getBoundingBox();
pearlLandingLocation.setZ(
pearlLandingBlockNorth.getRelative(BlockFace.SOUTH).getZ() + 0.3);
}
if (playerHitBox.overlaps(blockBoundingBoxSouth)
&& !pearlLandingBlockSouth.isPassable()
&& !pearlLandingBlockSouth.getType().name().contains("CARPET")) {
// Subtract the original bounding box coordinates to set them to zero. Then add the new bounding box coordinates to match the pearl land location.
playerHitBox.shift(-playerHitBox.getCenterX()+pearlLandingLocation.getX(), -playerHitBox.getCenterY()+pearlLandingLocation.getY(), -playerHitBox.getCenterZ()+pearlLandingLocation.getZ());
warnStaff(player, pearlLandingBlockSouth);
pearlLandingLocation.setZ(
pearlLandingBlockSouth.getRelative(BlockFace.NORTH).getZ() + 0.7);
}
if (playerHitBox.overlaps(blockBoundingBoxEast)
&& !pearlLandingBlockEast.isPassable()
&& !pearlLandingBlockEast.getType().name().contains("CARPET")) {
Block pearlLandingBlock = pearlLandingLocation.getBlock();
Block pearlLandingBlockNorth = pearlLandingBlock.getRelative(BlockFace.NORTH);
Block pearlLandingBlockSouth = pearlLandingBlock.getRelative(BlockFace.SOUTH);
Block pearlLandingBlockEast = pearlLandingBlock.getRelative(BlockFace.EAST);
Block pearlLandingBlockWest = pearlLandingBlock.getRelative(BlockFace.WEST);
warnStaff(player, pearlLandingBlockEast);
// Patch carpets.
if (pearlLandingBlock.getType().name().contains("CARPET")) {
pearlLandingLocation.setX(
pearlLandingBlockEast.getRelative(BlockFace.WEST).getX() + 0.7);
}
if (playerHitBox.overlaps(blockBoundingBoxWest)
&& !pearlLandingBlockWest.isPassable()
&& !pearlLandingBlockWest.getType().name().contains("CARPET")) {
pearlLandingLocation.setY(pearlLandingLocation.getY() + 0.08);
playerHitBox.shift(0.0, 0.08, 0.0);
warnStaff(player, pearlLandingBlockWest);
}
pearlLandingLocation.setX(
pearlLandingBlockWest.getRelative(BlockFace.EAST).getX() + 0.3);
}
// Cancel the checks if the player has permission to bypass them.
if (player.hasPermission("antipearlglitch.bypass")) return;
// Set the final teleport location.
event.setTo(pearlLandingLocation);
}
// If the pearl lands somewhere without any blocks adjacent to the landing spot then return.
if (
pearlLandingBlock.getType().isAir() &&
pearlLandingBlockNorth.getType().isAir() &&
pearlLandingBlockSouth.getType().isAir() &&
pearlLandingBlockEast.getType().isAir() &&
pearlLandingBlockWest.getType().isAir()
) {
public void returnPearl(Player player) {
return;
// Return the pearl if in survival or adventure mode.
if (player.getGameMode().equals(GameMode.ADVENTURE)
|| player.getGameMode().equals(GameMode.SURVIVAL)) {
}
player.getInventory().addItem(new ItemStack(Material.ENDER_PEARL));
}
}
// Create bounding boxes for blocks that are adjacent to the pearl landing location.
BoundingBox blockBoundingBox = pearlLandingBlock.getBoundingBox();
BoundingBox blockBoundingBoxNorth = pearlLandingBlockNorth.getBoundingBox();
BoundingBox blockBoundingBoxSouth = pearlLandingBlockSouth.getBoundingBox();
BoundingBox blockBoundingBoxEast = pearlLandingBlockEast.getBoundingBox();
BoundingBox blockBoundingBoxWest = pearlLandingBlockWest.getBoundingBox();
public void warnStaff(Player pearledPlayer, Block pearlGlitchBlock) {
// Check if the bounding boxes of the blocks under overlap with the bounding box of the player.
if (playerHitBox.overlaps(blockBoundingBox) && ! pearlLandingBlock.isPassable() && ! pearlLandingBlock.getType().name().contains("CARPET")) {
FileConfiguration config = plugin.getConfig();
String message = config.getString("pearl-glitch-notify-message");
boolean sendToConsole = config.getBoolean("log-pearl-glitch-to-console");
// Get the pearl landing location.
Block pearlLandingBlockDown = pearlLandingBlock.getRelative(BlockFace.DOWN);
if (message == null) {
// Get all the blocks relative to the block that's under the pearl landing location.
Block pearlLandingBlockDownNorth = pearlLandingBlockDown.getRelative(BlockFace.NORTH);
Block pearlLandingBlockDownSouth = pearlLandingBlockDown.getRelative(BlockFace.SOUTH);
Block pearlLandingBlockDownEast = pearlLandingBlockDown.getRelative(BlockFace.EAST);
Block pearlLandingBlockDownWest = pearlLandingBlockDown.getRelative(BlockFace.WEST);
return;
}
if (pearlLandingBlockDown.isPassable()) {
if (
! pearlLandingBlockDownNorth.getBoundingBox().overlaps(playerHitBox) && pearlLandingBlockDownNorth.isPassable() &&
! pearlLandingBlockDownSouth.getBoundingBox().overlaps(playerHitBox) && pearlLandingBlockDownSouth.isPassable() &&
! pearlLandingBlockDownEast.getBoundingBox().overlaps(playerHitBox) && pearlLandingBlockDownEast.isPassable() &&
! pearlLandingBlockDownWest.getBoundingBox().overlaps(playerHitBox) && pearlLandingBlockDownWest.isPassable()
) {
String blockX = Integer.toString(pearlGlitchBlock.getX());
String blockY = Integer.toString(pearlGlitchBlock.getY());
String blockZ = Integer.toString(pearlGlitchBlock.getZ());
pearlLandingLocation.setY(pearlLandingLocation.getY() - 1.0);
String coordinates = "x=" + blockX + " y=" + blockY + " z=" + blockZ;
// Set the final teleport location.
event.setTo(pearlLandingLocation);
String messageToPlayer = message.replace("%player%", pearledPlayer.getName())
.replace("%block%", pearlGlitchBlock.getType().name())
.replace("%coordinates%", coordinates);
return;
if (sendToConsole) {
}
}
// Fetch the console.
Logger logger = Bukkit.getServer().getLogger();
if (
pearlLandingBlockDownNorth.getBoundingBox().overlaps(playerHitBox) && !pearlLandingBlockDownNorth.isPassable() &&
pearlLandingBlockDownSouth.getBoundingBox().overlaps(playerHitBox) && !pearlLandingBlockDownSouth.isPassable() &&
pearlLandingBlockDownEast.getBoundingBox().overlaps(playerHitBox) && !pearlLandingBlockDownEast.isPassable() &&
pearlLandingBlockDownWest.getBoundingBox().overlaps(playerHitBox) && !pearlLandingBlockDownWest.isPassable() &&
! pearlLandingBlockDown.getBoundingBox().overlaps(playerHitBox) &&
! pearlLandingBlockDown.getRelative(BlockFace.DOWN).getBoundingBox().overlaps(playerHitBox)
) {
// Send a message to the console.
logger.info(Utils.legacySerializerAnyCase(messageToPlayer).content());
}
pearlLandingLocation.setY(pearlLandingLocation.getY() - 1.0);
for (Player player : Bukkit.getOnlinePlayers()) {
// Set the final teleport location.
event.setTo(pearlLandingLocation);
if (player.hasPermission("antipearlglitch.notify")) {
return;
}
// Checks are now done.
// Return the pearl to the player.
returnPearl(player);
// Warn the staff about the incident.
// Requires antipearlglitch.notify.
warnStaff(player, pearlLandingBlock);
// Cancel the event.
event.setCancelled(true);
return;
}
if (playerHitBox.overlaps(blockBoundingBoxNorth) && ! pearlLandingBlockNorth.isPassable() && ! pearlLandingBlockNorth.getType().name().contains("CARPET")) {
warnStaff(player, pearlLandingBlockNorth);
pearlLandingLocation.setZ(pearlLandingBlockNorth.getRelative(BlockFace.SOUTH).getZ() + 0.3);
}
if (playerHitBox.overlaps(blockBoundingBoxSouth) && ! pearlLandingBlockSouth.isPassable() && ! pearlLandingBlockSouth.getType().name().contains("CARPET")) {
warnStaff(player, pearlLandingBlockSouth);
pearlLandingLocation.setZ(pearlLandingBlockSouth.getRelative(BlockFace.NORTH).getZ() + 0.7);
}
if (playerHitBox.overlaps(blockBoundingBoxEast) && ! pearlLandingBlockEast.isPassable() && ! pearlLandingBlockEast.getType().name().contains("CARPET")) {
warnStaff(player, pearlLandingBlockEast);
pearlLandingLocation.setX(pearlLandingBlockEast.getRelative(BlockFace.WEST).getX() + 0.7);
}
if (playerHitBox.overlaps(blockBoundingBoxWest) && ! pearlLandingBlockWest.isPassable() && ! pearlLandingBlockWest.getType().name().contains("CARPET")) {
warnStaff(player, pearlLandingBlockWest);
pearlLandingLocation.setX(pearlLandingBlockWest.getRelative(BlockFace.EAST).getX() + 0.3);
}
// Set the final teleport location.
event.setTo(pearlLandingLocation);
}
public void returnPearl(Player player) {
// Return the pearl if in survival or adventure mode.
if (player.getGameMode().equals(GameMode.ADVENTURE) || player.getGameMode().equals(GameMode.SURVIVAL)) {
player.getInventory().addItem(new ItemStack(Material.ENDER_PEARL));
}
}
public void warnStaff(Player pearledPlayer, Block pearlGlitchBlock) {
FileConfiguration config = plugin.getConfig();
String message = config.getString("pearl-glitch-notify-message");
boolean sendToConsole = config.getBoolean("log-pearl-glitch-to-console");
if (message == null) {
return;
}
String blockX = Integer.toString(pearlGlitchBlock.getX());
String blockY = Integer.toString(pearlGlitchBlock.getY());
String blockZ = Integer.toString(pearlGlitchBlock.getZ());
String coordinates = "x=" + blockX + " y=" + blockY + " z=" + blockZ;
String messageToPlayer = message.replace("%player%", pearledPlayer.getName()).replace("%block%", pearlGlitchBlock.getType().name()).replace("%coordinates%", coordinates);
if (sendToConsole) {
// Fetch the console.
Logger logger = Bukkit.getServer().getLogger();
// Send a message to the console.
logger.info(Utils.legacySerializerAnyCase(messageToPlayer).content());
}
for (Player player : Bukkit.getOnlinePlayers()) {
if (player.hasPermission("antipearlglitch.notify")) {
// Send a formatted message to the player.
Utils.antiPearlGlitchOGMessage(player, messageToPlayer);
}
}
}
}
// Send a formatted message to the player.
Utils.antiPearlGlitchOGMessage(player, messageToPlayer);
}
}
}
}
@@ -1,90 +1,76 @@
package net.trueog.antipearlglitchog;
import org.bukkit.entity.Player;
import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import org.bukkit.entity.Player;
public class Utils {
// Sends a formatted message to the player (including name replacement).
public static void antiPearlGlitchOGMessage(Player p, String message) {
// Sends a formatted message to the player (including name replacement).
public static void antiPearlGlitchOGMessage(Player p, String message) {
p.sendMessage(legacySerializerAnyCase((message)));
p.sendMessage(legacySerializerAnyCase((message)));
}
}
public static TextComponent legacySerializerAnyCase(String subject) {
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()) {
int count = 0;
// Count the number of '&' characters to determine the size of the array
for (char c : subject.toCharArray()) {
if (c == '&') {
if (c == '&') {
count++;
}
}
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))) {
// 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++) {
subject = replaceCharAtIndex(subject, (i + 1), Character.toLowerCase(subject.charAt(i + 1)));
}
if (subject.charAt(i) == '&') {
positions[index++] = i;
}
}
if (isUpperBukkitCode(subject.charAt(i + 1))) {
return LegacyComponentSerializer.legacyAmpersand().deserialize(subject);
}
subject = replaceCharAtIndex(subject, (i + 1), Character.toLowerCase(subject.charAt(i + 1)));
private static boolean isUpperBukkitCode(char input) {
}
char[] bukkitColorCodes = {'A', 'B', 'C', 'D', 'E', 'F', 'K', 'L', 'M', 'N', 'O', 'R'};
boolean match = false;
positions[index++] = i;
// 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;
}
return LegacyComponentSerializer.legacyAmpersand().deserialize(subject);
private static String replaceCharAtIndex(String original, int index, char newChar) {
}
// Check if the index is valid
if (index >= 0 && index < original.length()) {
private static boolean isUpperBukkitCode(char input) {
// Create a new string with the replaced character
return original.substring(0, index) + newChar + original.substring(index + 1);
}
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;
}
}
// If the index is invalid, return the original string
return original;
}
}