From 818aeef2b70bbd3115301256df9d11260c1a257e Mon Sep 17 00:00:00 2001 From: CitralFlo Date: Thu, 23 Jan 2025 21:47:52 +0100 Subject: [PATCH 1/6] innit --- .../randomteleport/RandomTeleportSafeLocationService.java | 7 +++++-- .../feature/randomteleport/RandomTeleportTaskService.java | 3 +-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/randomteleport/RandomTeleportSafeLocationService.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/randomteleport/RandomTeleportSafeLocationService.java index bbb3be754..250078422 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/feature/randomteleport/RandomTeleportSafeLocationService.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/randomteleport/RandomTeleportSafeLocationService.java @@ -5,6 +5,7 @@ import com.eternalcode.core.injector.annotations.Inject; import com.eternalcode.core.injector.annotations.component.Service; import io.papermc.lib.PaperLib; +import lombok.extern.slf4j.Slf4j; import org.bukkit.Chunk; import org.bukkit.Location; import org.bukkit.Material; @@ -17,6 +18,7 @@ import java.util.Set; import java.util.concurrent.CompletableFuture; +@Slf4j @Service class RandomTeleportSafeLocationService { @@ -49,8 +51,9 @@ public CompletableFuture getSafeRandomLocation(World world, RandomTele int spawnX = spawnLocation.getBlockX(); int spawnZ = spawnLocation.getBlockZ(); - int randomX = spawnX + this.random.nextInt(radius.maxX() - radius.minX() + 1) + radius.minX(); - int randomZ = spawnZ + this.random.nextInt(radius.maxZ() - radius.minZ() + 1) + radius.minZ(); + int randomX = this.random.nextInt(-radius.minX(), radius.maxX()); + int randomZ = this.random.nextInt(-radius.minZ(), radius.maxZ()); + return PaperLib.getChunkAtAsync(new Location(world, randomX, 100, randomZ)).thenCompose(chunk -> { int randomY = chunk.getWorld().getHighestBlockYAt(randomX, randomZ); diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/randomteleport/RandomTeleportTaskService.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/randomteleport/RandomTeleportTaskService.java index 366e6c6e6..6d45902a0 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/feature/randomteleport/RandomTeleportTaskService.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/randomteleport/RandomTeleportTaskService.java @@ -42,10 +42,9 @@ class RandomTeleportTaskService { CompletableFuture createTeleport(Player player) { World world = resolveWorld(player, randomTeleportSettings); - RandomTeleportRadius radius = this.randomTeleportSettings.radius(); return this.randomTeleportSafeLocationService.getSafeRandomLocation( world, - radius, + this.randomTeleportSettings.radius(), this.randomTeleportSettings.teleportAttempts() ).thenCompose(location -> this.createTeleport(player, location)); } From 9c5874616ba0ff1279df2d3a78ec6821e72cb2ea Mon Sep 17 00:00:00 2001 From: CitralFlo Date: Thu, 23 Jan 2025 22:17:11 +0100 Subject: [PATCH 2/6] Fix logic, add additional comments to clarify the usage. --- .../randomteleport/RandomTeleportSafeLocationService.java | 7 ++----- .../feature/randomteleport/RandomTeleportSettingsImpl.java | 5 ++++- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/randomteleport/RandomTeleportSafeLocationService.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/randomteleport/RandomTeleportSafeLocationService.java index 250078422..31ee45a86 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/feature/randomteleport/RandomTeleportSafeLocationService.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/randomteleport/RandomTeleportSafeLocationService.java @@ -5,7 +5,6 @@ import com.eternalcode.core.injector.annotations.Inject; import com.eternalcode.core.injector.annotations.component.Service; import io.papermc.lib.PaperLib; -import lombok.extern.slf4j.Slf4j; import org.bukkit.Chunk; import org.bukkit.Location; import org.bukkit.Material; @@ -18,7 +17,6 @@ import java.util.Set; import java.util.concurrent.CompletableFuture; -@Slf4j @Service class RandomTeleportSafeLocationService { @@ -51,9 +49,8 @@ public CompletableFuture getSafeRandomLocation(World world, RandomTele int spawnX = spawnLocation.getBlockX(); int spawnZ = spawnLocation.getBlockZ(); - int randomX = this.random.nextInt(-radius.minX(), radius.maxX()); - int randomZ = this.random.nextInt(-radius.minZ(), radius.maxZ()); - + int randomX = spawnX + Math.random() < 0.5 ? 1 : -1 * this.random.nextInt(radius.minX(), radius.maxX()); + int randomZ = spawnZ + Math.random() < 0.5 ? 1 : -1 * this.random.nextInt(radius.minZ(), radius.maxX()); return PaperLib.getChunkAtAsync(new Location(world, randomX, 100, randomZ)).thenCompose(chunk -> { int randomY = chunk.getWorld().getHighestBlockYAt(randomX, randomZ); diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/randomteleport/RandomTeleportSettingsImpl.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/randomteleport/RandomTeleportSettingsImpl.java index b83b93407..5976c72ad 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/feature/randomteleport/RandomTeleportSettingsImpl.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/randomteleport/RandomTeleportSettingsImpl.java @@ -29,9 +29,12 @@ public class RandomTeleportSettingsImpl implements RandomTeleportSettings, Migra @Description({ "# Radius of random teleportation, this uses for starting point spawn via /setworldspawn.", "# If you want to use a static radius, set the type to STATIC_RADIUS and set the radius here.", + "# Radius is defined as space from the world spawn. Example minX=0, maxX=1000 means that the player will be teleported to random X from 0 to 1000 blocks from spawn.", + "# Ex. minX=1000, maxX=10000 means X coordinate will be random from 1000 to 10000 blocks from spawn.", + "# Please use positive values!", "# If you using WORLD_BORDER_RADIUS, this value will be ignored." }) - public RandomTeleportRadiusConfig radius = new RandomTeleportRadiusConfig(5000, 5000, 5000, 5000); + public RandomTeleportRadiusConfig radius = new RandomTeleportRadiusConfig(0, 5000, 0, 5000); @Deprecated public Integer randomTeleportRadius = null; @Description("# Teleport to a specific world, if left empty it will teleport to the player's current world") From 65ca9cd54936bdfaf310d403d9feeb3c998bd971 Mon Sep 17 00:00:00 2001 From: CitralFlo Date: Thu, 23 Jan 2025 23:10:14 +0100 Subject: [PATCH 3/6] Another fix --- .../randomteleport/RandomTeleportSafeLocationService.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/randomteleport/RandomTeleportSafeLocationService.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/randomteleport/RandomTeleportSafeLocationService.java index 31ee45a86..cf4747c56 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/feature/randomteleport/RandomTeleportSafeLocationService.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/randomteleport/RandomTeleportSafeLocationService.java @@ -2,6 +2,7 @@ import com.eternalcode.commons.bukkit.position.PositionAdapter; import com.eternalcode.core.configuration.implementation.LocationsConfiguration; +import com.eternalcode.core.configuration.implementation.PluginConfiguration; import com.eternalcode.core.injector.annotations.Inject; import com.eternalcode.core.injector.annotations.component.Service; import io.papermc.lib.PaperLib; @@ -49,8 +50,8 @@ public CompletableFuture getSafeRandomLocation(World world, RandomTele int spawnX = spawnLocation.getBlockX(); int spawnZ = spawnLocation.getBlockZ(); - int randomX = spawnX + Math.random() < 0.5 ? 1 : -1 * this.random.nextInt(radius.minX(), radius.maxX()); - int randomZ = spawnZ + Math.random() < 0.5 ? 1 : -1 * this.random.nextInt(radius.minZ(), radius.maxX()); + int randomX = spawnX + (Math.random() < 0.5 ? 1 : -1) * this.random.nextInt(radius.minX(), radius.maxX()); + int randomZ = spawnZ + (Math.random() < 0.5 ? 1 : -1) * this.random.nextInt(radius.minZ(), radius.maxZ()); return PaperLib.getChunkAtAsync(new Location(world, randomX, 100, randomZ)).thenCompose(chunk -> { int randomY = chunk.getWorld().getHighestBlockYAt(randomX, randomZ); From 1442f6828f417538fbf3854c27451d3d0e9c9635 Mon Sep 17 00:00:00 2001 From: CitralFlo Date: Thu, 23 Jan 2025 23:17:35 +0100 Subject: [PATCH 4/6] Fix configuration not supplying for Beans --- .../src/main/java/com/eternalcode/core/EternalCore.java | 4 ++++ .../compatibility/ConfigurationCompatibilityV21_2.java | 3 ++- .../com/eternalcode/core/injector/bean/LazyBeanCandidate.java | 4 +--- .../core/injector/bean/LazyFieldBeanCandidate.java | 2 +- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/EternalCore.java b/eternalcore-core/src/main/java/com/eternalcode/core/EternalCore.java index c65ad7aeb..8ac7b5066 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/EternalCore.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/EternalCore.java @@ -1,6 +1,8 @@ package com.eternalcode.core; import com.eternalcode.core.compatibility.CompatibilityService; +import com.eternalcode.core.configuration.ReloadableConfig; +import com.eternalcode.core.configuration.compatibility.ConfigurationCompatibilityV21_2; import com.eternalcode.core.injector.DependencyInjector; import com.eternalcode.core.injector.annotations.component.Component; import com.eternalcode.core.injector.annotations.component.ConfigurationFile; @@ -78,6 +80,8 @@ public EternalCore(Plugin plugin) { beanFactory.addCandidate(beanCandidate); } + beanFactory.initializeCandidates(ConfigurationCompatibilityV21_2.class); // TODO: Remove this when the cdn will be fixed + beanFactory.initializeCandidates(ReloadableConfig.class); // TODO: Remove this when the cdn will be fixed beanFactory.initializeCandidates(); this.publisher = beanFactory.getDependency(Publisher.class); diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/configuration/compatibility/ConfigurationCompatibilityV21_2.java b/eternalcore-core/src/main/java/com/eternalcode/core/configuration/compatibility/ConfigurationCompatibilityV21_2.java index 3bb32900d..0e6701b9b 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/configuration/compatibility/ConfigurationCompatibilityV21_2.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/configuration/compatibility/ConfigurationCompatibilityV21_2.java @@ -7,9 +7,10 @@ import com.eternalcode.core.injector.annotations.component.Controller; import com.eternalcode.core.publish.Subscribe; +// TODO: Make this package private @Controller @Compatibility(from = @Version(minor = 21, patch = 2)) -class ConfigurationCompatibilityV21_2 { +public class ConfigurationCompatibilityV21_2 { @Subscribe void onConfigSettingsSetup(ConfigurationSettingsSetupEvent event) { diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/injector/bean/LazyBeanCandidate.java b/eternalcore-core/src/main/java/com/eternalcode/core/injector/bean/LazyBeanCandidate.java index 6ed6f1af0..55deec453 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/injector/bean/LazyBeanCandidate.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/injector/bean/LazyBeanCandidate.java @@ -15,9 +15,7 @@ public LazyBeanCandidate(String name, Supplier instanceSupplier) { @Override public boolean isCandidate(Class clazz) { - Class type = this.getInstance().getClass(); - - return clazz.isAssignableFrom(type); + return clazz.isAssignableFrom(getType()); } @Override diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/injector/bean/LazyFieldBeanCandidate.java b/eternalcore-core/src/main/java/com/eternalcode/core/injector/bean/LazyFieldBeanCandidate.java index dded5caef..db8333681 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/injector/bean/LazyFieldBeanCandidate.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/injector/bean/LazyFieldBeanCandidate.java @@ -28,7 +28,7 @@ public LazyFieldBeanCandidate(Supplier instance, Field field, Bean bean) } public LazyFieldBeanCandidate(DependencyInjector dependencyInjector, Class componentClass, Field field, Bean bean) { - this(() -> dependencyInjector.newInstance(componentClass), field, bean); + this(() -> dependencyInjector.getDependencyProvider().getDependency(componentClass), field, bean); } @Override From 2f8aff5898d41a804bfa50982656eb061a8b095a Mon Sep 17 00:00:00 2001 From: CitralFlo Date: Sat, 25 Jan 2025 16:17:32 +0100 Subject: [PATCH 5/6] Rollback logic for rtp --- .../randomteleport/RandomTeleportSafeLocationService.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/randomteleport/RandomTeleportSafeLocationService.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/randomteleport/RandomTeleportSafeLocationService.java index cf4747c56..bbb3be754 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/feature/randomteleport/RandomTeleportSafeLocationService.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/randomteleport/RandomTeleportSafeLocationService.java @@ -2,7 +2,6 @@ import com.eternalcode.commons.bukkit.position.PositionAdapter; import com.eternalcode.core.configuration.implementation.LocationsConfiguration; -import com.eternalcode.core.configuration.implementation.PluginConfiguration; import com.eternalcode.core.injector.annotations.Inject; import com.eternalcode.core.injector.annotations.component.Service; import io.papermc.lib.PaperLib; @@ -50,8 +49,8 @@ public CompletableFuture getSafeRandomLocation(World world, RandomTele int spawnX = spawnLocation.getBlockX(); int spawnZ = spawnLocation.getBlockZ(); - int randomX = spawnX + (Math.random() < 0.5 ? 1 : -1) * this.random.nextInt(radius.minX(), radius.maxX()); - int randomZ = spawnZ + (Math.random() < 0.5 ? 1 : -1) * this.random.nextInt(radius.minZ(), radius.maxZ()); + int randomX = spawnX + this.random.nextInt(radius.maxX() - radius.minX() + 1) + radius.minX(); + int randomZ = spawnZ + this.random.nextInt(radius.maxZ() - radius.minZ() + 1) + radius.minZ(); return PaperLib.getChunkAtAsync(new Location(world, randomX, 100, randomZ)).thenCompose(chunk -> { int randomY = chunk.getWorld().getHighestBlockYAt(randomX, randomZ); From 4e0dfedb57669717e45d527f055cd60c4972dcd2 Mon Sep 17 00:00:00 2001 From: CitralFlo Date: Sat, 25 Jan 2025 16:20:12 +0100 Subject: [PATCH 6/6] Rollback rtp config --- .../feature/randomteleport/RandomTeleportSettingsImpl.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/randomteleport/RandomTeleportSettingsImpl.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/randomteleport/RandomTeleportSettingsImpl.java index 5976c72ad..34da3af6d 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/feature/randomteleport/RandomTeleportSettingsImpl.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/randomteleport/RandomTeleportSettingsImpl.java @@ -29,12 +29,9 @@ public class RandomTeleportSettingsImpl implements RandomTeleportSettings, Migra @Description({ "# Radius of random teleportation, this uses for starting point spawn via /setworldspawn.", "# If you want to use a static radius, set the type to STATIC_RADIUS and set the radius here.", - "# Radius is defined as space from the world spawn. Example minX=0, maxX=1000 means that the player will be teleported to random X from 0 to 1000 blocks from spawn.", - "# Ex. minX=1000, maxX=10000 means X coordinate will be random from 1000 to 10000 blocks from spawn.", - "# Please use positive values!", "# If you using WORLD_BORDER_RADIUS, this value will be ignored." }) - public RandomTeleportRadiusConfig radius = new RandomTeleportRadiusConfig(0, 5000, 0, 5000); + public RandomTeleportRadiusConfig radius = new RandomTeleportRadiusConfig(-5000, 5000, -5000, 5000); @Deprecated public Integer randomTeleportRadius = null; @Description("# Teleport to a specific world, if left empty it will teleport to the player's current world")