Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
import io.github.niestrat99.advancedteleport.listeners.spigot.SpigotSignChangeListener;
import io.github.niestrat99.advancedteleport.listeners.spigot.SpigotSignOpenListener;
import io.github.niestrat99.advancedteleport.managers.*;
import io.github.niestrat99.advancedteleport.rtp.RTPManager;
import io.github.niestrat99.advancedteleport.sql.*;
import io.github.niestrat99.advancedteleport.utilities.RandomTPAlgorithms;
import io.github.niestrat99.advancedteleport.rtp.RandomTPAlgorithms;
import io.github.slimjar.app.builder.InjectingApplicationBuilder;
import io.github.slimjar.logging.ProcessLogger;
import io.papermc.lib.PaperLib;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
import io.github.niestrat99.advancedteleport.api.events.warps.WarpPostCreateEvent;
import io.github.niestrat99.advancedteleport.config.MainConfig;
import io.github.niestrat99.advancedteleport.managers.NamedLocationManager;
import io.github.niestrat99.advancedteleport.managers.RTPManager;
import io.github.niestrat99.advancedteleport.rtp.RTPManager;
import io.github.niestrat99.advancedteleport.managers.SignManager;
import io.github.niestrat99.advancedteleport.sql.MetadataSQLManager;
import io.github.niestrat99.advancedteleport.sql.SpawnSQLManager;
import io.github.niestrat99.advancedteleport.sql.WarpSQLManager;

import io.github.niestrat99.advancedteleport.utilities.RandomTPAlgorithms;
import io.github.niestrat99.advancedteleport.rtp.RandomTPAlgorithms;
import io.papermc.lib.PaperLib;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import io.github.niestrat99.advancedteleport.CoreClass;
import io.github.niestrat99.advancedteleport.commands.SubATCommand;
import io.github.niestrat99.advancedteleport.config.CustomMessages;
import io.github.niestrat99.advancedteleport.managers.RTPManager;
import io.github.niestrat99.advancedteleport.rtp.RTPManager;

import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import io.github.niestrat99.advancedteleport.config.MainConfig;
import io.github.niestrat99.advancedteleport.managers.CommandManager;
import io.github.niestrat99.advancedteleport.managers.CooldownManager;
import io.github.niestrat99.advancedteleport.utilities.RandomCoords;
import io.github.niestrat99.advancedteleport.rtp.RTPManager;

import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
Expand Down Expand Up @@ -44,9 +44,9 @@ public boolean onCommand(
ex.printStackTrace();
}
}
RandomCoords.reload();
CooldownManager.init();
CommandManager.registerCommands();
RTPManager.checkLocationsInBorder();
CustomMessages.sendMessage(sender, "Info.reloadedConfig");
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ public final class MainConfig extends ATConfig {
public ConfigOption<ConfigSection> X;
public ConfigOption<ConfigSection> Z;
public ConfigOption<Boolean> RAPID_RESPONSE;
public ConfigOption<Boolean> USE_VANILLA_BORDER;
public ConfigOption<Boolean> USE_PLUGIN_BORDERS;
public ConfigOption<Boolean> SYNC_VANILLA_BORDER;
public ConfigOption<Boolean> SYNC_PLUGIN_BORDERS;
public ConfigOption<Boolean> PROTECT_CLAIM_LOCATIONS;
public ConfigOption<Integer> PREPARED_LOCATIONS_LIMIT;
public ConfigOption<List<String>> IGNORE_WORLD_GENS;
Expand Down Expand Up @@ -555,12 +555,13 @@ To use multiple worlds, use a comma (,).
IMPORTANT NOTE - this feature only works on the Paper server type and any of its forks. It is not considered safe to use on Spigot or Bukkit.\
""");
addDefault(
"use-vanilla-border",
"sync-vanilla-border",
false,
"Whether the plugin should use the Vanilla world border as a viable "
+ "option for managing /tpr boundaries.");
"Whether the plugin should sync its /tpr boundaries with the Vanilla world border."
+ "\nThis does not need to be enabled to respect a smaller Vanilla world border - the plugin" +
"will automatically adjust to smaller world borders if required.");
addDefault(
"use-plugin-borders",
"sync-plugin-borders",
true,
"Whether the plugin should use plugin world borders for managing /tpr "
+ "boundaries.\n"
Expand Down Expand Up @@ -991,6 +992,9 @@ public void moveToNew() {
moveTo(
"permissions.allow-admin-perms-as-defaults",
"allow-admin-permissions-as-default-perms");

moveTo("use-vanilla-border", "sync-vanilla-border");
moveTo("use-plugin-borders", "sync-plugin-borders");
}

@Override
Expand Down Expand Up @@ -1074,8 +1078,8 @@ public void postSave() {
X = new ConfigOption<>("x");
Z = new ConfigOption<>("z");
RAPID_RESPONSE = new ConfigOption<>("use-rapid-response");
USE_VANILLA_BORDER = new ConfigOption<>("use-vanilla-border");
USE_PLUGIN_BORDERS = new ConfigOption<>("use-plugin-borders");
SYNC_VANILLA_BORDER = new ConfigOption<>("sync-vanilla-border");
SYNC_PLUGIN_BORDERS = new ConfigOption<>("sync-plugin-borders");
PROTECT_CLAIM_LOCATIONS = new ConfigOption<>("protect-claim-locations");
PREPARED_LOCATIONS_LIMIT = new ConfigOption<>("prepared-locations-limit");
IGNORE_WORLD_GENS = new ConfigOption<>("ignore-world-generators");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ protected BorderPlugin(@Nullable final String pluginName) {
* @return true if the plugin is enabled and there is a viable world border, false if not.
*/
public boolean canUse(@NotNull final World world) {
return MainConfig.get().USE_PLUGIN_BORDERS.get() && this.pluginUsable();
return MainConfig.get().SYNC_PLUGIN_BORDERS.get() && this.pluginUsable();
}

/**
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package io.github.niestrat99.advancedteleport.listeners;

import io.github.niestrat99.advancedteleport.config.MainConfig;
import io.github.niestrat99.advancedteleport.managers.RTPManager;
import io.github.niestrat99.advancedteleport.rtp.RTPManager;

import io.papermc.lib.PaperLib;
import io.papermc.paper.event.world.border.WorldBorderBoundsChangeEvent;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.world.WorldLoadEvent;
Expand All @@ -17,7 +18,13 @@ public void onWorldLoad(WorldLoadEvent event) {
RTPManager.loadWorldData(event.getWorld());
}

@EventHandler
public void onWorldUnload(WorldUnloadEvent event) {
RTPManager.unloadWorldData(event.getWorld());
}

@EventHandler(ignoreCancelled = true)
public void onWorldBorderChange(WorldBorderBoundsChangeEvent event) {
RTPManager.checkLocationsInBorder();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import io.github.niestrat99.advancedteleport.hooks.MapPlugin;
import io.github.niestrat99.advancedteleport.hooks.PluginHook;
import io.github.niestrat99.advancedteleport.hooks.borders.ChunkyBorderHook;
import io.github.niestrat99.advancedteleport.hooks.borders.VanillaBorderHook;
import io.github.niestrat99.advancedteleport.hooks.borders.WorldBorderHook;
import io.github.niestrat99.advancedteleport.hooks.claims.GriefPreventionClaimHook;
import io.github.niestrat99.advancedteleport.hooks.claims.LandsClaimHook;
Expand All @@ -16,6 +15,7 @@
import io.github.niestrat99.advancedteleport.hooks.maps.DynmapHook;
import io.github.niestrat99.advancedteleport.hooks.maps.SquaremapHook;
import io.github.niestrat99.advancedteleport.hooks.particles.PlayerParticlesHook;
import io.github.niestrat99.advancedteleport.rtp.RandomTPBorders;
import io.github.niestrat99.advancedteleport.sql.HomeSQLManager;
import io.github.niestrat99.advancedteleport.sql.SpawnSQLManager;
import io.github.niestrat99.advancedteleport.sql.WarpSQLManager;
Expand Down Expand Up @@ -52,7 +52,6 @@ public void init() {
// World border Plugins
loadPlugin("worldborder", WorldBorderHook.class);
loadPlugin("chunkyborder", ChunkyBorderHook.class);
loadPlugin("vanilla", VanillaBorderHook.class);

// Particle plugins
loadPlugin("playerparticles", PlayerParticlesHook.class);
Expand Down Expand Up @@ -127,19 +126,26 @@ private void loadPlugin(
}

@Contract(pure = true)
public double[] getRandomCoords(@NotNull final World world) {
return getPluginHooks(BorderPlugin.class, true)
.filter(plugin -> plugin.canUse(world))
.findFirst()
.map(
hook ->
new double[] {
hook.getMinX(world),
hook.getMaxX(world),
hook.getMinZ(world),
hook.getMaxZ(world)
})
.orElse(null);
public RandomTPBorders getBorders(@NotNull final World world) {

RandomTPBorders border = null;
for (BorderPlugin hook : getPluginHooks(BorderPlugin.class, true).toList()) {
if (!hook.canUse(world)) continue;
RandomTPBorders otherBorder = new RandomTPBorders(
hook.getMinX(world),
hook.getMaxX(world),
hook.getMinZ(world),
hook.getMaxZ(world)
);

if (border == null) {
border = otherBorder;
} else {
border = border.minimal(otherBorder);
}
}

return border;
}

@Contract(pure = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import io.github.niestrat99.advancedteleport.api.Spawn;
import io.github.niestrat99.advancedteleport.config.CustomMessages;
import io.github.niestrat99.advancedteleport.config.MainConfig;
import io.github.niestrat99.advancedteleport.rtp.RTPManager;
import io.github.niestrat99.advancedteleport.utilities.ConditionChecker;
import io.github.thatsmusic99.configurationmaster.api.ConfigSection;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
package io.github.niestrat99.advancedteleport.rtp;

import io.github.niestrat99.advancedteleport.CoreClass;
import io.github.niestrat99.advancedteleport.config.MainConfig;
import io.github.niestrat99.advancedteleport.managers.PluginHookManager;
import io.github.thatsmusic99.configurationmaster.api.ConfigSection;

import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.WorldBorder;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.Random;

public class CoordinateGenerator {

private static final Random random = new Random();

public static double getRandomCoords(double min, double max) {
return random.nextInt((int) Math.round(max - min) + 1) + min;
}

public static @Nullable Location getRandCoords(
World world, RandomTPBorders borders, int y, int attempt) {
if (attempt++ > 15) {
return null;
}

Location loc =
new Location(
world,
getRandomCoords(borders.minX(), borders.maxX()),
y,
getRandomCoords(borders.minZ(), borders.maxZ()));
if (PluginHookManager.get()
.isClaimed(
loc)) { // Should look into a limiter, so we don't get stuck in a loop
// somehow
return getRandCoords(world, borders, y, attempt);
}
return loc;
}

public static @Nullable Location generateCoords(World world) {

int y = world.getEnvironment() == World.Environment.NETHER ? 0 : 255;
return getRandCoords(world, getBorders(world), y, 0);
}

public static @NotNull RandomTPBorders getBorders(final @NotNull World world) {
RandomTPBorders vanillaBorder = getVanillaWorldBorders(world);
RandomTPBorders pluginBorders = PluginHookManager.get().getBorders(world);

RandomTPBorders borders;
if (MainConfig.get().SYNC_VANILLA_BORDER.get()) {
borders = vanillaBorder;
} else if (MainConfig.get().SYNC_PLUGIN_BORDERS.get()) {
borders = pluginBorders;
} else {

ConfigSection x = MainConfig.get().X.get();
ConfigSection z = MainConfig.get().Z.get();

String xStr =
x.contains(world.getName())
? x.getString(world.getName())
: x.getString("default");
String zStr =
x.contains(world.getName())
? z.getString(world.getName())
: z.getString("default");

double[] coordsDouble = new double[4];

if (xStr != null || zStr != null) {
String[] xSplit =
xStr != null
? xStr.split(";")
: zStr.split(
";"); // Use the Z coord if X isn't present for
// some reason
setArray(coordsDouble, xSplit, 1, 0);

String[] zSplit =
zStr != null
? zStr.split(";")
: xStr.split(
";"); // Use the X coord if Z isn't present for
// some reason
setArray(coordsDouble, zSplit, 3, 2);

borders = new RandomTPBorders(
Math.min(coordsDouble[0], coordsDouble[1]),
Math.max(coordsDouble[0], coordsDouble[1]),
Math.min(coordsDouble[2], coordsDouble[3]),
Math.max(coordsDouble[2], coordsDouble[3]));
} else {
CoreClass.getInstance().getLogger().warning("X and Z /rtp boundaries for " + world.getName() + " are " +
"not set up properly. A range of -5000 to 5000 will be used.");
borders = new RandomTPBorders(-5000, 5000, -5000, 5000);
}
}

// Minimise the border so it's smaller
borders = borders.minimal(vanillaBorder);
borders = borders.minimal(pluginBorders);

return borders;
}

private static RandomTPBorders getVanillaWorldBorders(final @NotNull World world) {
WorldBorder border = world.getWorldBorder();
return new RandomTPBorders(
Math.ceil(border.getCenter().getX() - border.getSize() / 2),
Math.floor(border.getCenter().getX() + border.getSize() / 2),
Math.ceil(border.getCenter().getZ() - border.getSize() / 2),
Math.floor(border.getCenter().getZ() + border.getSize() / 2));
}

private static void setArray(double[] array, String[] strArray, int c1, int c2) {
if (strArray.length > 1) {
array[c1] = Integer.parseInt(strArray[0]);
array[c2] = Integer.parseInt(strArray[1]);
} else {
array[c1] = Integer.parseInt(strArray[0]);
array[c2] = Integer.parseInt(String.format("-%s", strArray[0]));
}
}
}
Loading
Loading