Update gradle to 8.14.2, add auto formatting

This commit is contained in:
NotAlexNoyle committed 2025-06-20 20:22:54 -04:00
1 parent e676fa95a7
commit de9ded8ed0
12 files changed
+396 -373

No files matched your search

+3
View File
@@ -0,0 +1,3 @@
[submodule "libs/Utilities-OG"]
path = libs/Utilities-OG
url = https://github.com/true-og/Utilities-OG
Executable
+4
View File
@@ -0,0 +1,4 @@
#!/usr/bin/bash
# Fetch all submodule content.
git submodule update --force --recursive --init
+27 -25
View File
@@ -1,8 +1,9 @@
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.
kotlin("jvm") version "2.1.21" // Import kotlin jvm plugin for kotlin/java integration.
}
java {
@@ -11,20 +12,17 @@ java {
}
group = "net.trueog.holygrail-og" // Declare bundle identifier.
version = "1.2" // 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("/")
}
@@ -33,23 +31,21 @@ tasks.named<ProcessResources>("processResources") {
repositories {
mavenCentral()
gradlePluginPortal()
maven {
url = uri("https://repo.purpurmc.org/snapshots")
}
maven {
maven { url = uri("https://repo.purpurmc.org/snapshots") }
url = uri("https://maven.enginehub.org/repo/")
}
maven { url = uri("https://maven.enginehub.org/repo/") }
}
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("com.sk89q.worldedit:worldedit-bukkit:7.3.0-SNAPSHOT") // Import WorldEdit.
compileOnly("com.sk89q.worldguard:worldguard-bukkit:7.0.9") { // Import WorldGuard but without its bundled WorldEdit.
compileOnly(
"com.sk89q.worldguard:worldguard-bukkit:7.0.9"
) { // Import WorldGuard but without its bundled WorldEdit.
exclude(group = "com.sk89q.worldedit")
}
compileOnlyApi(project(":libs:Utilities-OG"))
}
tasks.withType<AbstractArchiveTask>().configureEach { // Ensure reproducible .jars
@@ -58,18 +54,17 @@ tasks.withType<AbstractArchiveTask>().configureEach { // Ensure reproducible .ja
}
tasks.shadowJar {
archiveClassifier.set("") // Use empty string instead of null.
exclude("io.github.miniplaceholders.*") // Exclude the MiniPlaceholders package from being shadowed.
archiveClassifier.set("") // Use empty string instead of null.
minimize()
}
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")
@@ -78,13 +73,20 @@ tasks.withType<JavaCompile>().configureEach {
options.isFork = true
}
kotlin {
jvmToolchain(17)
}
java {
toolchain {
languageVersion = JavaLanguageVersion.of(17)
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
Submodule libs/Utilities-OG added at e68d3fec7a.
+11
View File
@@ -1 +1,12 @@
rootProject.name = "HolyGrail-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")
+17 -19
View File
@@ -5,29 +5,27 @@ package plugin;
// Import required libraries.
import org.bukkit.plugin.java.JavaPlugin;
// Extending this class is standard bukkit boilerplate for any plugin, or else the server software won't load the classes.
// Extending this class is standard bukkit boilerplate for any plugin, or else the server software won't load the
// classes.
public class HolyGrailOG extends JavaPlugin {
// Declare variable to hold class for passing.
private static HolyGrailOG plugin;
// What to do when the plugin is run by the server.
public void onEnable() {
// Assign the plugin variable to the main class instance.
plugin = this;
// Declare variable to hold class for passing.
private static HolyGrailOG plugin;
// Register the event.
getServer().getPluginManager().registerEvents(new Listeners(), this);
// What to do when the plugin is run by the server.
public void onEnable() {
}
// Assign the plugin variable to the main class instance.
plugin = this;
// Class constructor.
public static HolyGrailOG getPlugin() {
// Register the event.
getServer().getPluginManager().registerEvents(new Listeners(), this);
}
// Pass instance of main to other classes.
return plugin;
// Class constructor.
public static HolyGrailOG getPlugin() {
}
}
// Pass instance of main to other classes.
return plugin;
}
}
+278 -266
View File
@@ -2,10 +2,24 @@
// Author: NotAlexNoyle.
package plugin;
import com.destroystokyo.paper.event.block.AnvilDamagedEvent;
import com.destroystokyo.paper.event.block.AnvilDamagedEvent.DamageState;
import com.google.common.collect.Lists;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.util.Location;
import com.sk89q.worldguard.WorldGuard;
import com.sk89q.worldguard.protection.ApplicableRegionSet;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import com.sk89q.worldguard.protection.regions.RegionContainer;
import com.sk89q.worldguard.protection.regions.RegionQuery;
import java.util.ArrayList;
// Import required libraries.
import java.util.List;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.event.ClickEvent;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.format.TextDecoration;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.Particle;
@@ -22,286 +36,284 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.scheduler.BukkitTask;
import org.jetbrains.annotations.NotNull;
import com.destroystokyo.paper.event.block.AnvilDamagedEvent;
import com.destroystokyo.paper.event.block.AnvilDamagedEvent.DamageState;
import com.google.common.collect.Lists;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.util.Location;
import com.sk89q.worldguard.WorldGuard;
import com.sk89q.worldguard.protection.ApplicableRegionSet;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import com.sk89q.worldguard.protection.regions.RegionContainer;
import com.sk89q.worldguard.protection.regions.RegionQuery;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.event.ClickEvent;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.format.TextDecoration;
// Declare listener class.
public class Listeners implements Listener {
private BukkitTask task = null;
private BukkitTask task = null;
// Listen for an anvil being damaged.
@EventHandler(priority = EventPriority.HIGHEST)
public void onAnvilBreak(AnvilDamagedEvent event) {
// If the anvil is in the spawn region, do this...
if (event.isBreaking()
&& getRegionNames(BukkitAdapter.adapt(event.getInventory().getLocation()))
.contains("spawn")) {
// Spawn a particle effect to indicate the anvil restoration.
event.getInventory()
.getLocation()
.getWorld()
.spawnParticle(Particle.SPELL, event.getInventory().getLocation(), 5);
// Restore the anvil to unused status.
event.setDamageState(DamageState.FULL);
}
}
// Listen for entities being damaged.
@EventHandler(priority = EventPriority.HIGHEST)
public void onEntityDamage(EntityDamageEvent event) {
// TODO: Test destroying crystals in vs outside of duels.
// TODO: Test to make sure crystals only do damage to those in a duel match.
// If the entity that was damaged is an ender crystal, do this...
if (event.getEntityType().equals(EntityType.ENDER_CRYSTAL)) {
// Get a list of regions from WorldGuard.
ArrayList<String> regionQuery =
getRegionNames(BukkitAdapter.adapt(event.getEntity().getLocation()));
// If the ender crystal that was damaged is in the spawn region, do this...
if (regionQuery.contains("spawn")) {
CharSequence arenaQuery = "arena";
if (!doAnyRegionNamesContain(arenaQuery, event.getEntity())) {
event.setCancelled(true);
} else {
// TODO: Test the pending restore particles.
// Create a final array to capture the value of the remaining seconds (similar to a loop).
final int[] secondsRemaining = {5};
// Schedule a repeating task to show pending end crystal restore particles.
task = Bukkit.getScheduler()
.runTaskTimer(
HolyGrailOG.getPlugin(),
new Runnable() {
@Override
public void run() {
event.getEntity()
.getWorld()
.spawnParticle(
Particle.FIREWORKS_SPARK,
event.getEntity().getLocation(),
3);
// Decrease the remaining time
secondsRemaining[0] = secondsRemaining[0] - 1;
// Check if we should stop the task
if (secondsRemaining[0] <= 0) {
Bukkit.getScheduler().cancelTask(task.getTaskId()); // Cancel the task
}
}
},
0L,
20L); // The '0L' means start immediately, and '20L' means run every 20 ticks (1
// second).
// Wait 5 seconds, so that it doesn't appear that the crystal didn't get destroyed.
Bukkit.getScheduler()
.runTaskLater(
HolyGrailOG.getPlugin(),
new Runnable() {
// Run a scheduled task.
@Override
public void run() {
// Delete existing crystals at the location.
// TODO: Test this code...
org.bukkit.@NotNull Location crystalLocation =
event.getEntity().getLocation();
for (Entity nearbyEntity : crystalLocation
.getWorld()
.getNearbyEntities(crystalLocation, 2, 2, 2)) {
if (nearbyEntity.getType() == EntityType.ENDER_CRYSTAL) {
nearbyEntity.remove();
}
}
// Restore the ender crystal to its original location.
event.getEntity()
.getWorld()
.spawnEntity(crystalLocation, EntityType.ENDER_CRYSTAL);
}
},
100L); // 100L = 5 seconds delay
}
}
}
}
// Listen for entities exploding.
/*@EventHandler(priority = EventPriority.HIGHEST)
public void onEntityExplosion(EntityExplodeEvent event) {
// Stop explosion from being cancelled in arenas.
if(doAnyRegionNamesContain("arena", event.getEntity())) {
event.setCancelled(false);
}
}*/
// Listen for a player interacting with a block or entity.
@EventHandler(priority = EventPriority.HIGHEST)
public void onEntityInteract(PlayerInteractEntityEvent event) {
// Get the nature of the interaction.
Entity entityClicked = event.getRightClicked();
// If the player right clicked on an ender crystal, do this...
if (entityClicked.getType().equals(EntityType.ENDER_CRYSTAL)) {
// Get the player who performed the interaction.
Player player = event.getPlayer();
// Get the item in the player's main hand.
ItemStack itemInHand = player.getInventory().getItemInMainHand();
// If the player is holding an ender crystal in their hand, and they have permission, send them an ender
// crystal deletion confirmation prompt.
if (itemInHand.getType().equals(Material.END_CRYSTAL) && player.hasPermission("holygrail.deletecrystals")) {
// TODO: Delete all crystals at the entity location according to player command.
// TODO: Test this code...
org.bukkit.@NotNull Location crystalLocation = entityClicked.getLocation();
for (Entity nearbyEntity : crystalLocation.getWorld().getNearbyEntities(crystalLocation, 2, 2, 2)) {
if (nearbyEntity.getType() == EntityType.ENDER_CRYSTAL) {
nearbyEntity.remove();
}
}
sendClickableMessage(
player,
entityClicked.getLocation().getX(),
entityClicked.getLocation().getY(),
entityClicked.getLocation().getBlockZ());
}
}
}
// Listen for entities being spawned.
@EventHandler(priority = EventPriority.HIGHEST)
public void onEntitySpawn(EntitySpawnEvent event) {
// If the entity that was spawned is an ender crystal, and it is in the spawn region, do this...
if (event.getEntityType().equals(EntityType.ENDER_CRYSTAL)
&& getRegionNames(BukkitAdapter.adapt(event.getLocation())).contains("spawn")) {
// Make a list of to hold the nearby entities sized of the maximum reasonable amount of nearby entities.
List<Entity> entityList = new ArrayList<Entity>(3457);
// Make a list of to hold the nearby entity names sized of the maximum reasonable amount of nearby entities.
ArrayList<String> entityTitles = new ArrayList<String>(3457);
// Iterate over the nearby entities with a pre-set maximum.
for (int i = 0; i < entityList.size(); i++) {
// Attempt to run error-throwing code.
try {
// Get a list of nearby entities.
entityList.add(event.getEntity().getNearbyEntities(2, 2, 2).get(i));
// Get a list of nearby entities' titles.
entityTitles.add(event.getEntity()
.getNearbyEntities(2, 2, 2)
.get(i)
.getType()
.toString()
.toLowerCase());
}
// If the amount of entities is less than 3457, this error will be thrown.
catch (IndexOutOfBoundsException error) {
// Stop the loop if maximum entity count was reached. The last value of i will be used as the list
// size.
break;
}
}
// Listen for an anvil being damaged.
@EventHandler(priority = EventPriority.HIGHEST)
public void onAnvilBreak(AnvilDamagedEvent event) {
// If an ender crystal already exists at the location, do this...
if (entityTitles.contains("ender_crystal")) {
// If the anvil is in the spawn region, do this...
if(event.isBreaking() && getRegionNames(BukkitAdapter.adapt(event.getInventory().getLocation())).contains("spawn") ) {
// Don't spawn in another crystal since there is one already.
event.setCancelled(true);
// Spawn a particle effect to indicate the anvil restoration.
event.getInventory().getLocation().getWorld().spawnParticle(Particle.SPELL, event.getInventory().getLocation(), 5);
} else {
// Restore the anvil to unused status.
event.setDamageState(DamageState.FULL);
// Spawn particles to indicate the ender crystal being restored.
event.getEntity()
.getWorld()
.spawnParticle(Particle.SPELL, event.getEntity().getLocation(), 6);
}
}
}
}
// Declare a function for searching for specific sequences of characters in region names.
private boolean doAnyRegionNamesContain(CharSequence lookup, Entity entity) {
}
// Get a list of regions from WorldGuard.
ArrayList<String> regionQuery = getRegionNames(BukkitAdapter.adapt(entity.getLocation()));
boolean queryFound = false;
// Listen for entities being damaged.
@EventHandler(priority = EventPriority.HIGHEST)
public void onEntityDamage(EntityDamageEvent event) {
for (int i = 0; i < regionQuery.size(); i++) {
if (regionQuery.get(i).contains(lookup)) {
// TODO: Test destroying crystals in vs outside of duels.
// TODO: Test to make sure crystals only do damage to those in a duel match.
queryFound = true;
}
}
return queryFound;
}
// Declare a function for checking whether a location is in a region.
private ArrayList<String> getRegionNames(Location worldGuardBlockLocation) {
// Query the list of regions at the location using the WorldGuard API.
WorldGuard.getInstance();
RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer();
RegionQuery query = container.createQuery();
ApplicableRegionSet set = query.getApplicableRegions(worldGuardBlockLocation);
List<ProtectedRegion> region = Lists.newArrayList(set);
ArrayList<String> regionNames = new ArrayList<String>(region.size());
regionNames.add("none");
for (int i = 0; i < region.size(); i++) {
// If the entity that was damaged is an ender crystal, do this...
if(event.getEntityType().equals(EntityType.ENDER_CRYSTAL)) {
regionNames.add(i, region.get(i).getId());
}
// Get a list of regions from WorldGuard.
ArrayList<String> regionQuery = getRegionNames(BukkitAdapter.adapt(event.getEntity().getLocation()));
// Return a list of all applicable regions.
return regionNames;
}
// If the ender crystal that was damaged is in the spawn region, do this...
if(regionQuery.contains("spawn")) {
// Turns chat text into a command button.
public static void sendClickableMessage(Player player, double x, double y, double z) {
CharSequence arenaQuery = "arena";
if(! doAnyRegionNamesContain(arenaQuery, event.getEntity())) {
// Declare a TextComponent with contents.
TextComponent clickableText = Component.text("[Click Here]");
event.setCancelled(true);
// Style the clickable text.
clickableText.color(NamedTextColor.AQUA).decoration(TextDecoration.BOLD, TextDecoration.State.TRUE);
}
else {
// Create a click event on the chat text.
clickableText = clickableText.clickEvent(ClickEvent.clickEvent(ClickEvent.Action.RUN_COMMAND, "tps"));
// TODO: Test the pending restore particles.
// Create a final array to capture the value of the remaining seconds (similar to a loop).
final int[] secondsRemaining = { 5 };
// Schedule a repeating task to show pending end crystal restore particles.
task = Bukkit.getScheduler().runTaskTimer(HolyGrailOG.getPlugin(), new Runnable() {
@Override
public void run() {
event.getEntity().getWorld().spawnParticle(Particle.FIREWORKS_SPARK, event.getEntity().getLocation(), 3);
// Decrease the remaining time
secondsRemaining[0] = secondsRemaining[0] - 1;
// Check if we should stop the task
if (secondsRemaining[0] <= 0) {
Bukkit.getScheduler().cancelTask(task.getTaskId()); // Cancel the task
}
}
}, 0L, 20L); // The '0L' means start immediately, and '20L' means run every 20 ticks (1 second).
// Wait 5 seconds, so that it doesn't appear that the crystal didn't get destroyed.
Bukkit.getScheduler().runTaskLater(HolyGrailOG.getPlugin(), new Runnable() {
// Run a scheduled task.
@Override
public void run() {
// Delete existing crystals at the location.
// TODO: Test this code...
org.bukkit.@NotNull Location crystalLocation = event.getEntity().getLocation();
for (Entity nearbyEntity : crystalLocation.getWorld().getNearbyEntities(crystalLocation, 2, 2, 2)) {
if (nearbyEntity.getType() == EntityType.ENDER_CRYSTAL) {
nearbyEntity.remove();
}
}
// Restore the ender crystal to its original location.
event.getEntity().getWorld().spawnEntity(crystalLocation, EntityType.ENDER_CRYSTAL);
}
}, 100L); // 100L = 5 seconds delay
}
}
}
}
// Listen for entities exploding.
/*@EventHandler(priority = EventPriority.HIGHEST)
public void onEntityExplosion(EntityExplodeEvent event) {
// Stop explosion from being cancelled in arenas.
if(doAnyRegionNamesContain("arena", event.getEntity())) {
event.setCancelled(false);
}
}*/
// Listen for a player interacting with a block or entity.
@EventHandler(priority = EventPriority.HIGHEST)
public void onEntityInteract(PlayerInteractEntityEvent event) {
// Get the nature of the interaction.
Entity entityClicked = event.getRightClicked();
// If the player right clicked on an ender crystal, do this...
if(entityClicked.getType().equals(EntityType.ENDER_CRYSTAL)) {
// Get the player who performed the interaction.
Player player = event.getPlayer();
// Get the item in the player's main hand.
ItemStack itemInHand = player.getInventory().getItemInMainHand();
// If the player is holding an ender crystal in their hand, and they have permission, send them an ender crystal deletion confirmation prompt.
if(itemInHand.getType().equals(Material.END_CRYSTAL) && player.hasPermission("holygrail.deletecrystals")) {
// TODO: Delete all crystals at the entity location according to player command.
// TODO: Test this code...
org.bukkit.@NotNull Location crystalLocation = entityClicked.getLocation();
for (Entity nearbyEntity : crystalLocation.getWorld().getNearbyEntities(crystalLocation, 2, 2, 2)) {
if (nearbyEntity.getType() == EntityType.ENDER_CRYSTAL) {
nearbyEntity.remove();
}
}
sendClickableMessage(player, entityClicked.getLocation().getX(), entityClicked.getLocation().getY(), entityClicked.getLocation().getBlockZ());
}
}
}
// Listen for entities being spawned.
@EventHandler(priority = EventPriority.HIGHEST)
public void onEntitySpawn(EntitySpawnEvent event) {
// If the entity that was spawned is an ender crystal, and it is in the spawn region, do this...
if(event.getEntityType().equals(EntityType.ENDER_CRYSTAL) && getRegionNames(BukkitAdapter.adapt(event.getLocation())).contains("spawn")) {
// Make a list of to hold the nearby entities sized of the maximum reasonable amount of nearby entities.
List<Entity> entityList = new ArrayList<Entity>(3457);
// Make a list of to hold the nearby entity names sized of the maximum reasonable amount of nearby entities.
ArrayList<String> entityTitles = new ArrayList<String>(3457);
// Iterate over the nearby entities with a pre-set maximum.
for(int i = 0; i < entityList.size(); i++) {
// Attempt to run error-throwing code.
try {
// Get a list of nearby entities.
entityList.add(event.getEntity().getNearbyEntities(2, 2, 2).get(i));
// Get a list of nearby entities' titles.
entityTitles.add(event.getEntity().getNearbyEntities(2, 2, 2).get(i).getType().toString().toLowerCase());
}
// If the amount of entities is less than 3457, this error will be thrown.
catch(IndexOutOfBoundsException error) {
// Stop the loop if maximum entity count was reached. The last value of i will be used as the list size.
break;
}
}
// If an ender crystal already exists at the location, do this...
if(entityTitles.contains("ender_crystal")) {
// Don't spawn in another crystal since there is one already.
event.setCancelled(true);
}
else {
// Spawn particles to indicate the ender crystal being restored.
event.getEntity().getWorld().spawnParticle(Particle.SPELL, event.getEntity().getLocation(), 6);
}
}
}
// Declare a function for searching for specific sequences of characters in region names.
private boolean doAnyRegionNamesContain(CharSequence lookup, Entity entity) {
// Get a list of regions from WorldGuard.
ArrayList<String> regionQuery = getRegionNames(BukkitAdapter.adapt(entity.getLocation()));
boolean queryFound = false;
for(int i = 0; i < regionQuery.size(); i++) {
if(regionQuery.get(i).contains(lookup)) {
queryFound = true;
}
}
return queryFound;
}
// Declare a function for checking whether a location is in a region.
private ArrayList<String> getRegionNames(Location worldGuardBlockLocation) {
// Query the list of regions at the location using the WorldGuard API.
WorldGuard.getInstance();
RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer();
RegionQuery query = container.createQuery();
ApplicableRegionSet set = query.getApplicableRegions(worldGuardBlockLocation);
List<ProtectedRegion> region = Lists.newArrayList(set);
ArrayList<String> regionNames = new ArrayList<String>(region.size());
regionNames.add("none");
for(int i = 0; i < region.size(); i++) {
regionNames.add(i, region.get(i).getId());
}
// Return a list of all applicable regions.
return regionNames;
}
// Turns chat text into a command button.
public static void sendClickableMessage(Player player, double x, double y, double z) {
// Declare a TextComponent with contents.
TextComponent clickableText = Component.text("[Click Here]");
// Style the clickable text.
clickableText.color(NamedTextColor.AQUA).decoration(TextDecoration.BOLD, TextDecoration.State.TRUE);
// Create a click event on the chat text.
clickableText = clickableText.clickEvent(ClickEvent.clickEvent(ClickEvent.Action.RUN_COMMAND, "tps"));
// Send the clickable text to the player.
player.sendMessage(Utils.legacySerializerAnyCase("&6Are you sure you want to &cdelete &6the ender crystal at X = &e\" + x + \"&6, Y = &e\" + y + \"&6, Z = &e\" + z + \"&6? To confirm: &B\"") + clickableText.content());
}
}
// Send the clickable text to the player.
player.sendMessage(Utils.legacySerializerAnyCase(
"&6Are you sure you want to &cdelete &6the ender crystal at X = &e\" + x + \"&6, Y = &e\" + y + \"&6, Z = &e\" + z + \"&6? To confirm: &B\"")
+ clickableText.content());
}
}
+44 -56
View File
@@ -5,77 +5,65 @@ import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
public class Utils {
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) == '&') {
// 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 (isUpperBukkitCode(subject.charAt(i + 1))) {
if (subject.charAt(i) == '&') {
subject = replaceCharAtIndex(subject, (i + 1), Character.toLowerCase(subject.charAt(i + 1)));
}
if (isUpperBukkitCode(subject.charAt(i + 1))) {
positions[index++] = i;
}
}
subject = replaceCharAtIndex(subject, (i + 1), Character.toLowerCase(subject.charAt(i + 1)));
return LegacyComponentSerializer.legacyAmpersand().deserialize(subject);
}
}
private static boolean isUpperBukkitCode(char input) {
positions[index++] = i;
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 LegacyComponentSerializer.legacyAmpersand().deserialize(subject);
return match;
}
}
private static String replaceCharAtIndex(String original, int index, char newChar) {
private static boolean isUpperBukkitCode(char input) {
// Check if the index is valid
if (index >= 0 && index < original.length()) {
char[] bukkitColorCodes = {'A', 'B', 'C', 'D', 'E', 'F', 'K', 'L', 'M', 'N', 'O', 'R'};
boolean match = false;
// Create a new string with the replaced character
return original.substring(0, index) + newChar + original.substring(index + 1);
}
// 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;
}
}