mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-04 14:38:53 +00:00
refactor: improve adapter on Bukkit
This commit is contained in:
10 files changed
+88
-156
No files matched your search
@@ -47,6 +47,7 @@ import net.william278.huskhomes.manager.Manager;
|
|||||||
import net.william278.huskhomes.network.Broker;
|
import net.william278.huskhomes.network.Broker;
|
||||||
import net.william278.huskhomes.network.PluginMessageBroker;
|
import net.william278.huskhomes.network.PluginMessageBroker;
|
||||||
import net.william278.huskhomes.network.RedisBroker;
|
import net.william278.huskhomes.network.RedisBroker;
|
||||||
|
import net.william278.huskhomes.position.Location;
|
||||||
import net.william278.huskhomes.position.Position;
|
import net.william278.huskhomes.position.Position;
|
||||||
import net.william278.huskhomes.position.World;
|
import net.william278.huskhomes.position.World;
|
||||||
import net.william278.huskhomes.random.NormalDistributionEngine;
|
import net.william278.huskhomes.random.NormalDistributionEngine;
|
||||||
@@ -272,9 +273,7 @@ public class BukkitHuskHomes extends JavaPlugin implements HuskHomes, BukkitTask
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setWorldSpawn(@NotNull Position position) {
|
public void setWorldSpawn(@NotNull Position position) {
|
||||||
BukkitAdapter.adaptLocation(position).ifPresent(location -> Objects
|
Objects.requireNonNull(Adapter.adapt(position).getWorld()).setSpawnLocation(Adapter.adapt(position));
|
||||||
.requireNonNull(location.getWorld(), "World is null")
|
|
||||||
.setSpawnLocation(location));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -322,10 +321,7 @@ public class BukkitHuskHomes extends JavaPlugin implements HuskHomes, BukkitTask
|
|||||||
@Override
|
@Override
|
||||||
@NotNull
|
@NotNull
|
||||||
public List<World> getWorlds() {
|
public List<World> getWorlds() {
|
||||||
return getServer().getWorlds().stream()
|
return getServer().getWorlds().stream().map(Adapter::adapt).toList();
|
||||||
.filter(world -> BukkitAdapter.adaptWorld(world).isPresent())
|
|
||||||
.map(world -> BukkitAdapter.adaptWorld(world).orElse(null))
|
|
||||||
.toList();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -418,4 +414,47 @@ public class BukkitHuskHomes extends JavaPlugin implements HuskHomes, BukkitTask
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class Adapter {
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public static Position adapt(@NotNull org.bukkit.Location location, @NotNull String server) {
|
||||||
|
return Position.at(
|
||||||
|
location.getX(), location.getY(), location.getZ(),
|
||||||
|
location.getYaw(), location.getPitch(),
|
||||||
|
adapt(Objects.requireNonNull(location.getWorld(), "Location world is null")),
|
||||||
|
server
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public static Location adapt(@NotNull org.bukkit.Location location) {
|
||||||
|
return Position.at(
|
||||||
|
location.getX(), location.getY(), location.getZ(),
|
||||||
|
location.getYaw(), location.getPitch(),
|
||||||
|
adapt(Objects.requireNonNull(location.getWorld(), "Location world is null"))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public static org.bukkit.Location adapt(@NotNull Location position) {
|
||||||
|
return new org.bukkit.Location(
|
||||||
|
adapt(position.getWorld()),
|
||||||
|
position.getX(), position.getY(), position.getZ(),
|
||||||
|
position.getYaw(), position.getPitch()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public static org.bukkit.World adapt(@NotNull World world) {
|
||||||
|
return Optional.ofNullable(Bukkit.getWorld(world.getUuid()))
|
||||||
|
.or(() -> Optional.ofNullable(Bukkit.getWorld(world.getName())))
|
||||||
|
.orElse(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public static World adapt(@NotNull org.bukkit.World world) {
|
||||||
|
return World.from(world.getName(), world.getUID(), World.Environment.match(world.getEnvironment().name()));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -26,7 +26,6 @@ import net.william278.huskhomes.position.Position;
|
|||||||
import net.william278.huskhomes.user.BukkitUser;
|
import net.william278.huskhomes.user.BukkitUser;
|
||||||
import net.william278.huskhomes.user.OnlineUser;
|
import net.william278.huskhomes.user.OnlineUser;
|
||||||
import net.william278.huskhomes.user.User;
|
import net.william278.huskhomes.user.User;
|
||||||
import net.william278.huskhomes.util.BukkitAdapter;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.jetbrains.annotations.ApiStatus;
|
import org.jetbrains.annotations.ApiStatus;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
@@ -105,7 +104,7 @@ public class HuskHomesAPI extends BaseHuskHomesAPI {
|
|||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
public org.bukkit.Location getLocation(@NotNull Position position) {
|
public org.bukkit.Location getLocation(@NotNull Position position) {
|
||||||
return BukkitAdapter.adaptLocation(position).orElse(null);
|
return BukkitHuskHomes.Adapter.adapt(position);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -117,7 +116,7 @@ public class HuskHomesAPI extends BaseHuskHomesAPI {
|
|||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
public Location adaptLocation(@NotNull org.bukkit.Location location) {
|
public Location adaptLocation(@NotNull org.bukkit.Location location) {
|
||||||
return BukkitAdapter.adaptLocation(location).orElse(null);
|
return BukkitHuskHomes.Adapter.adapt(location);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -24,9 +24,7 @@ import com.earth2me.essentials.Warps;
|
|||||||
import com.earth2me.essentials.commands.WarpNotFoundException;
|
import com.earth2me.essentials.commands.WarpNotFoundException;
|
||||||
import net.william278.huskhomes.BukkitHuskHomes;
|
import net.william278.huskhomes.BukkitHuskHomes;
|
||||||
import net.william278.huskhomes.HuskHomes;
|
import net.william278.huskhomes.HuskHomes;
|
||||||
import net.william278.huskhomes.position.Position;
|
|
||||||
import net.william278.huskhomes.user.User;
|
import net.william278.huskhomes.user.User;
|
||||||
import net.william278.huskhomes.util.BukkitAdapter;
|
|
||||||
import net.william278.huskhomes.util.ValidationException;
|
import net.william278.huskhomes.util.ValidationException;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
@@ -61,19 +59,15 @@ public class EssentialsXImporter extends Importer {
|
|||||||
if (essentialsUser.getHome(homeName) == null || essentialsUser.getHome(homeName).getWorld() == null) {
|
if (essentialsUser.getHome(homeName) == null || essentialsUser.getHome(homeName).getWorld() == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
BukkitAdapter.adaptLocation(essentialsUser.getHome(homeName))
|
|
||||||
.map(location -> Position.at(location, plugin.getServerName()))
|
|
||||||
.ifPresent(position -> {
|
|
||||||
plugin.getManager().homes().createHome(
|
plugin.getManager().homes().createHome(
|
||||||
user,
|
user,
|
||||||
this.normalizeName(homeName),
|
this.normalizeName(homeName),
|
||||||
position,
|
BukkitHuskHomes.Adapter.adapt(essentialsUser.getHome(homeName), plugin.getServerName()),
|
||||||
true,
|
true,
|
||||||
true,
|
true,
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
homesImported.getAndIncrement();
|
homesImported.getAndIncrement();
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return homesImported.get();
|
return homesImported.get();
|
||||||
@@ -87,16 +81,11 @@ public class EssentialsXImporter extends Importer {
|
|||||||
if (warps.getWarp(warpName) == null || warps.getWarp(warpName).getWorld() == null) {
|
if (warps.getWarp(warpName) == null || warps.getWarp(warpName).getWorld() == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
BukkitAdapter.adaptLocation(warps.getWarp(warpName))
|
|
||||||
.map(location -> Position.at(location, plugin.getServerName()))
|
|
||||||
.ifPresent(position -> {
|
|
||||||
plugin.getManager().warps().createWarp(
|
plugin.getManager().warps().createWarp(
|
||||||
this.normalizeName(warpName),
|
this.normalizeName(warpName),
|
||||||
position,
|
BukkitHuskHomes.Adapter.adapt(warps.getWarp(warpName), plugin.getServerName()),
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
warpsImported.getAndIncrement();
|
|
||||||
});
|
|
||||||
} catch (WarpNotFoundException e) {
|
} catch (WarpNotFoundException e) {
|
||||||
plugin.log(Level.WARNING, String.format("Skipped importing warp %s (could not be found)", warpName));
|
plugin.log(Level.WARNING, String.format("Skipped importing warp %s (could not be found)", warpName));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,6 @@ import net.william278.huskhomes.BukkitHuskHomes;
|
|||||||
import net.william278.huskhomes.config.Settings;
|
import net.william278.huskhomes.config.Settings;
|
||||||
import net.william278.huskhomes.position.Position;
|
import net.william278.huskhomes.position.Position;
|
||||||
import net.william278.huskhomes.user.BukkitUser;
|
import net.william278.huskhomes.user.BukkitUser;
|
||||||
import net.william278.huskhomes.util.BukkitAdapter;
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.block.data.type.Bed;
|
import org.bukkit.block.data.type.Bed;
|
||||||
import org.bukkit.block.data.type.RespawnAnchor;
|
import org.bukkit.block.data.type.RespawnAnchor;
|
||||||
@@ -85,9 +84,10 @@ public class BukkitEventListener extends EventListener implements Listener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final BukkitUser bukkitUser = BukkitUser.adapt(player, (BukkitHuskHomes) plugin);
|
this.handlePlayerTeleport(
|
||||||
BukkitAdapter.adaptLocation(event.getFrom()).ifPresent(sourceLocation ->
|
BukkitUser.adapt(player, (BukkitHuskHomes) plugin),
|
||||||
handlePlayerTeleport(bukkitUser, Position.at(sourceLocation, plugin.getServerName())));
|
BukkitHuskHomes.Adapter.adapt(event.getFrom(), plugin.getServerName())
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
||||||
@@ -107,9 +107,9 @@ public class BukkitEventListener extends EventListener implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Update the player's respawn location
|
// Update the player's respawn location
|
||||||
BukkitAdapter.adaptLocation(location).ifPresent(adaptedLocation -> super.handlePlayerUpdateSpawnPoint(
|
this.handlePlayerUpdateSpawnPoint(
|
||||||
BukkitUser.adapt(event.getPlayer(), (BukkitHuskHomes) plugin),
|
BukkitUser.adapt(event.getPlayer(), (BukkitHuskHomes) plugin),
|
||||||
Position.at(adaptedLocation, plugin.getServerName()))
|
BukkitHuskHomes.Adapter.adapt(location, plugin.getServerName())
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,6 @@ import net.william278.huskhomes.network.PluginMessageBroker;
|
|||||||
import net.william278.huskhomes.position.Location;
|
import net.william278.huskhomes.position.Location;
|
||||||
import net.william278.huskhomes.position.Position;
|
import net.william278.huskhomes.position.Position;
|
||||||
import net.william278.huskhomes.teleport.TeleportationException;
|
import net.william278.huskhomes.teleport.TeleportationException;
|
||||||
import net.william278.huskhomes.util.BukkitAdapter;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||||
import org.bukkit.metadata.MetadataValue;
|
import org.bukkit.metadata.MetadataValue;
|
||||||
@@ -61,17 +60,13 @@ public class BukkitUser extends OnlineUser {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Position getPosition() {
|
public Position getPosition() {
|
||||||
return Position.at(BukkitAdapter.adaptLocation(player.getLocation()).orElseThrow(
|
return BukkitHuskHomes.Adapter.adapt(player.getLocation(), plugin.getServerName());
|
||||||
() -> new IllegalStateException("Failed to get the position of a BukkitPlayer (null)")
|
|
||||||
),
|
|
||||||
plugin.getServerName());
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<Position> getBedSpawnPosition() {
|
public Optional<Position> getBedSpawnPosition() {
|
||||||
return Optional.ofNullable(player.getBedSpawnLocation()).flatMap(BukkitAdapter::adaptLocation)
|
return Optional.ofNullable(player.getBedSpawnLocation())
|
||||||
.map(location -> Position.at(location, plugin.getServerName()));
|
.map(loc -> BukkitHuskHomes.Adapter.adapt(loc, plugin.getServerName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -107,16 +102,13 @@ public class BukkitUser extends OnlineUser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void teleportLocally(@NotNull Location location, boolean async) throws TeleportationException {
|
public void teleportLocally(@NotNull Location target, boolean async) throws TeleportationException {
|
||||||
// Ensure the world exists
|
// Ensure the location is valid (world exists, coordinates are within the world border)
|
||||||
final Optional<org.bukkit.Location> resolvedLocation = BukkitAdapter.adaptLocation(location);
|
final org.bukkit.Location location = BukkitHuskHomes.Adapter.adapt(target);
|
||||||
if (resolvedLocation.isEmpty() || resolvedLocation.get().getWorld() == null) {
|
if (location.getWorld() == null) {
|
||||||
throw new TeleportationException(TeleportationException.Type.WORLD_NOT_FOUND, plugin);
|
throw new TeleportationException(TeleportationException.Type.WORLD_NOT_FOUND, plugin);
|
||||||
}
|
}
|
||||||
|
if (!location.getWorld().getWorldBorder().isInside(location)) {
|
||||||
// Ensure the coordinates are within the world limits
|
|
||||||
final org.bukkit.Location bukkitLocation = resolvedLocation.get();
|
|
||||||
if (!bukkitLocation.getWorld().getWorldBorder().isInside(resolvedLocation.get())) {
|
|
||||||
throw new TeleportationException(TeleportationException.Type.ILLEGAL_TARGET_COORDINATES, plugin);
|
throw new TeleportationException(TeleportationException.Type.ILLEGAL_TARGET_COORDINATES, plugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -125,10 +117,10 @@ public class BukkitUser extends OnlineUser {
|
|||||||
player.leaveVehicle();
|
player.leaveVehicle();
|
||||||
player.eject();
|
player.eject();
|
||||||
if (async || ((BukkitHuskHomes) plugin).getScheduler().isUsingFolia()) {
|
if (async || ((BukkitHuskHomes) plugin).getScheduler().isUsingFolia()) {
|
||||||
PaperLib.teleportAsync(player, bukkitLocation, PlayerTeleportEvent.TeleportCause.PLUGIN);
|
PaperLib.teleportAsync(player, location, PlayerTeleportEvent.TeleportCause.PLUGIN);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
player.teleport(bukkitLocation, PlayerTeleportEvent.TeleportCause.PLUGIN);
|
player.teleport(location, PlayerTeleportEvent.TeleportCause.PLUGIN);
|
||||||
}, this);
|
}, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,95 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is part of HuskHomes, licensed under the Apache License 2.0.
|
|
||||||
*
|
|
||||||
* Copyright (c) William278 <[email protected]>
|
|
||||||
* Copyright (c) contributors
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package net.william278.huskhomes.util;
|
|
||||||
|
|
||||||
import net.william278.huskhomes.position.Location;
|
|
||||||
import net.william278.huskhomes.position.World;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Static class providing utility methods for adapting Bukkit objects to HuskHomes and vice versa.
|
|
||||||
*/
|
|
||||||
public final class BukkitAdapter {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Adapt a Bukkit {@link org.bukkit.Location} to a HuskHomes {@link Location}.
|
|
||||||
*
|
|
||||||
* @param location the Bukkit {@link org.bukkit.Location} to adapt
|
|
||||||
* @return the adapted {@link Location}
|
|
||||||
*/
|
|
||||||
public static Optional<org.bukkit.Location> adaptLocation(@NotNull Location location) {
|
|
||||||
org.bukkit.World world = Bukkit.getWorld(location.getWorld().getName());
|
|
||||||
if (world == null) {
|
|
||||||
world = Bukkit.getWorld(location.getWorld().getUuid());
|
|
||||||
}
|
|
||||||
if (world == null) {
|
|
||||||
world = Bukkit.getWorlds().stream()
|
|
||||||
.filter(w -> w.getEnvironment().name().equalsIgnoreCase(
|
|
||||||
location.getWorld().getEnvironment().name())).findFirst()
|
|
||||||
.orElse(null);
|
|
||||||
}
|
|
||||||
if (world == null) {
|
|
||||||
return Optional.empty();
|
|
||||||
}
|
|
||||||
return Optional.of(new org.bukkit.Location(
|
|
||||||
world,
|
|
||||||
location.getX(),
|
|
||||||
location.getY(),
|
|
||||||
location.getZ(),
|
|
||||||
location.getYaw(),
|
|
||||||
location.getPitch()
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Adapt a HuskHomes {@link org.bukkit.Location} to a Bukkit {@link org.bukkit.Location}.
|
|
||||||
*
|
|
||||||
* @param location the HuskHomes {@link org.bukkit.Location} to adapt
|
|
||||||
* @return the adapted {@link org.bukkit.Location}
|
|
||||||
*/
|
|
||||||
public static Optional<Location> adaptLocation(@NotNull org.bukkit.Location location) {
|
|
||||||
if (location.getWorld() == null) {
|
|
||||||
return Optional.empty();
|
|
||||||
}
|
|
||||||
return Optional.of(Location.at(location.getX(), location.getY(), location.getZ(),
|
|
||||||
location.getYaw(), location.getPitch(),
|
|
||||||
adaptWorld(location.getWorld()).orElse(new net.william278.huskhomes.position.World())));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Optional<World> adaptWorld(@Nullable org.bukkit.World world) {
|
|
||||||
if (world == null) {
|
|
||||||
return Optional.empty();
|
|
||||||
}
|
|
||||||
return Optional.of(World.from(
|
|
||||||
world.getName(), world.getUID(),
|
|
||||||
switch (world.getEnvironment()) {
|
|
||||||
case NORMAL -> World.Environment.OVERWORLD;
|
|
||||||
case NETHER -> World.Environment.NETHER;
|
|
||||||
case THE_END -> World.Environment.THE_END;
|
|
||||||
default -> World.Environment.CUSTOM;
|
|
||||||
})
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -20,6 +20,7 @@
|
|||||||
package net.william278.huskhomes.util;
|
package net.william278.huskhomes.util;
|
||||||
|
|
||||||
import io.papermc.lib.PaperLib;
|
import io.papermc.lib.PaperLib;
|
||||||
|
import net.william278.huskhomes.BukkitHuskHomes;
|
||||||
import net.william278.huskhomes.position.Location;
|
import net.william278.huskhomes.position.Location;
|
||||||
import org.bukkit.Chunk;
|
import org.bukkit.Chunk;
|
||||||
import org.bukkit.ChunkSnapshot;
|
import org.bukkit.ChunkSnapshot;
|
||||||
@@ -33,7 +34,7 @@ public interface BukkitSafetyResolver extends SafetyResolver {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
default CompletableFuture<Optional<Location>> findSafeGroundLocation(@NotNull Location location) {
|
default CompletableFuture<Optional<Location>> findSafeGroundLocation(@NotNull Location location) {
|
||||||
final org.bukkit.Location bukkitLocation = BukkitAdapter.adaptLocation(location).orElse(null);
|
final org.bukkit.Location bukkitLocation = BukkitHuskHomes.Adapter.adapt(location);
|
||||||
if (bukkitLocation == null || bukkitLocation.getWorld() == null) {
|
if (bukkitLocation == null || bukkitLocation.getWorld() == null) {
|
||||||
return CompletableFuture.completedFuture(Optional.empty());
|
return CompletableFuture.completedFuture(Optional.empty());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,7 +30,6 @@ import net.william278.huskhomes.user.BukkitUser;
|
|||||||
import net.william278.huskhomes.user.ConsoleUser;
|
import net.william278.huskhomes.user.ConsoleUser;
|
||||||
import net.william278.huskhomes.user.OnlineUser;
|
import net.william278.huskhomes.user.OnlineUser;
|
||||||
import net.william278.huskhomes.user.User;
|
import net.william278.huskhomes.user.User;
|
||||||
import net.william278.huskhomes.util.BukkitAdapter;
|
|
||||||
import net.william278.huskhomes.util.TransactionResolver;
|
import net.william278.huskhomes.util.TransactionResolver;
|
||||||
import net.william278.huskhomes.util.ValidationException;
|
import net.william278.huskhomes.util.ValidationException;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
@@ -362,7 +361,7 @@ public class BukkitPluginTests {
|
|||||||
@MethodSource("provideWarpData")
|
@MethodSource("provideWarpData")
|
||||||
@Order(4)
|
@Order(4)
|
||||||
public void testWarpRelocation(@NotNull String name, @NotNull Position position) {
|
public void testWarpRelocation(@NotNull String name, @NotNull Position position) {
|
||||||
final World world = BukkitAdapter.adaptWorld(server.getWorld("world")).orElseThrow();
|
final World world = BukkitHuskHomes.Adapter.adapt(server.getWorld("world"));
|
||||||
final Position newPosition = Position.at(
|
final Position newPosition = Position.at(
|
||||||
position.getX() + 10, position.getY() + 10, position.getZ() + 10,
|
position.getX() + 10, position.getY() + 10, position.getZ() + 10,
|
||||||
0, 0,
|
0, 0,
|
||||||
@@ -382,7 +381,7 @@ public class BukkitPluginTests {
|
|||||||
@MethodSource("provideWarpData")
|
@MethodSource("provideWarpData")
|
||||||
@Order(5)
|
@Order(5)
|
||||||
public void testWarpOverwrite(@NotNull String name, @NotNull Position position) {
|
public void testWarpOverwrite(@NotNull String name, @NotNull Position position) {
|
||||||
final World world = BukkitAdapter.adaptWorld(server.getWorld("world")).orElseThrow();
|
final World world = BukkitHuskHomes.Adapter.adapt(server.getWorld("world"));
|
||||||
final Position newPosition = Position.at(
|
final Position newPosition = Position.at(
|
||||||
position.getX() + 10, position.getY() + 10, position.getZ() + 10,
|
position.getX() + 10, position.getY() + 10, position.getZ() + 10,
|
||||||
0, 0,
|
0, 0,
|
||||||
@@ -442,7 +441,7 @@ public class BukkitPluginTests {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static Stream<Arguments> provideWarpData() {
|
public static Stream<Arguments> provideWarpData() {
|
||||||
final World world = BukkitAdapter.adaptWorld(server.getWorld("world")).orElseThrow();
|
final World world = BukkitHuskHomes.Adapter.adapt(server.getWorld("world"));
|
||||||
final Position position = Position.at(0, 0, 0, 0, 0, world, plugin.getServerName());
|
final Position position = Position.at(0, 0, 0, 0, 0, world, plugin.getServerName());
|
||||||
return WARP_NAMES.stream()
|
return WARP_NAMES.stream()
|
||||||
.flatMap(name -> Stream.of(Arguments.of(name, position)));
|
.flatMap(name -> Stream.of(Arguments.of(name, position)));
|
||||||
@@ -536,7 +535,7 @@ public class BukkitPluginTests {
|
|||||||
@Order(4)
|
@Order(4)
|
||||||
public void testHomeRelocation(@NotNull OnlineUser owner, @NotNull String name,
|
public void testHomeRelocation(@NotNull OnlineUser owner, @NotNull String name,
|
||||||
@NotNull Position position) {
|
@NotNull Position position) {
|
||||||
final World world = BukkitAdapter.adaptWorld(server.getWorld("world")).orElseThrow();
|
final World world = BukkitHuskHomes.Adapter.adapt(server.getWorld("world"));
|
||||||
final Position newPosition = Position.at(
|
final Position newPosition = Position.at(
|
||||||
position.getX() + 10, position.getY() + 10, position.getZ() + 10,
|
position.getX() + 10, position.getY() + 10, position.getZ() + 10,
|
||||||
0, 0,
|
0, 0,
|
||||||
@@ -557,7 +556,7 @@ public class BukkitPluginTests {
|
|||||||
@MethodSource("provideHomeData")
|
@MethodSource("provideHomeData")
|
||||||
@Order(5)
|
@Order(5)
|
||||||
public void testHomeOverwrite(@NotNull OnlineUser owner, @NotNull String name, @NotNull Position position) {
|
public void testHomeOverwrite(@NotNull OnlineUser owner, @NotNull String name, @NotNull Position position) {
|
||||||
final World world = BukkitAdapter.adaptWorld(server.getWorld("world")).orElseThrow();
|
final World world = BukkitHuskHomes.Adapter.adapt(server.getWorld("world"));
|
||||||
final Position newPosition = Position.at(
|
final Position newPosition = Position.at(
|
||||||
position.getX() + 10, position.getY() + 10, position.getZ() + 10,
|
position.getX() + 10, position.getY() + 10, position.getZ() + 10,
|
||||||
0, 0,
|
0, 0,
|
||||||
@@ -651,7 +650,7 @@ public class BukkitPluginTests {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static Stream<Arguments> provideHomeData() {
|
public static Stream<Arguments> provideHomeData() {
|
||||||
final World world = BukkitAdapter.adaptWorld(server.getWorld("world")).orElseThrow();
|
final World world = BukkitHuskHomes.Adapter.adapt(server.getWorld("world"));
|
||||||
final Position position = Position.at(0, 0, 0, 0, 0, world, plugin.getServerName());
|
final Position position = Position.at(0, 0, 0, 0, 0, world, plugin.getServerName());
|
||||||
return HOME_NAMES.stream()
|
return HOME_NAMES.stream()
|
||||||
.flatMap(name -> Stream.of(Arguments.of(homeOwner, name, position)));
|
.flatMap(name -> Stream.of(Arguments.of(homeOwner, name, position)));
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import lombok.NoArgsConstructor;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.Locale;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@@ -99,7 +100,16 @@ public class World {
|
|||||||
OVERWORLD,
|
OVERWORLD,
|
||||||
NETHER,
|
NETHER,
|
||||||
THE_END,
|
THE_END,
|
||||||
CUSTOM
|
CUSTOM;
|
||||||
|
|
||||||
|
public static Environment match(@NotNull String name) {
|
||||||
|
return switch (name.toLowerCase(Locale.ENGLISH)) {
|
||||||
|
case "overworld" -> OVERWORLD;
|
||||||
|
case "nether" -> NETHER;
|
||||||
|
case "the_end" -> THE_END;
|
||||||
|
default -> CUSTOM;
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -23,9 +23,7 @@ import com.destroystokyo.paper.event.player.PlayerSetSpawnEvent;
|
|||||||
import net.william278.huskhomes.BukkitHuskHomes;
|
import net.william278.huskhomes.BukkitHuskHomes;
|
||||||
import net.william278.huskhomes.PaperHuskHomes;
|
import net.william278.huskhomes.PaperHuskHomes;
|
||||||
import net.william278.huskhomes.config.Settings;
|
import net.william278.huskhomes.config.Settings;
|
||||||
import net.william278.huskhomes.position.Position;
|
|
||||||
import net.william278.huskhomes.user.BukkitUser;
|
import net.william278.huskhomes.user.BukkitUser;
|
||||||
import net.william278.huskhomes.util.BukkitAdapter;
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
@@ -61,9 +59,9 @@ public class PaperEventListener extends BukkitEventListener implements Listener
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Update the player's respawn location
|
// Update the player's respawn location
|
||||||
BukkitAdapter.adaptLocation(location).ifPresent(adaptedLocation -> super.handlePlayerUpdateSpawnPoint(
|
this.handlePlayerUpdateSpawnPoint(
|
||||||
BukkitUser.adapt(event.getPlayer(), (PaperHuskHomes) plugin),
|
BukkitUser.adapt(event.getPlayer(), (BukkitHuskHomes) plugin),
|
||||||
Position.at(adaptedLocation, plugin.getServerName()))
|
BukkitHuskHomes.Adapter.adapt(location, plugin.getServerName())
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user