mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-04 14:38:53 +00:00
New API methods, refactor position object to use static creators
This commit is contained in:
1 parent
42adc13425
commit
6b8c515b61
42 files changed
+587
-232
No files matched your search
@@ -22,7 +22,7 @@ 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.Location;
|
||||||
import net.william278.huskhomes.position.Server;
|
import net.william278.huskhomes.config.Server;
|
||||||
import net.william278.huskhomes.position.World;
|
import net.william278.huskhomes.position.World;
|
||||||
import net.william278.huskhomes.random.NormalDistributionEngine;
|
import net.william278.huskhomes.random.NormalDistributionEngine;
|
||||||
import net.william278.huskhomes.random.RandomTeleportEngine;
|
import net.william278.huskhomes.random.RandomTeleportEngine;
|
||||||
@@ -341,7 +341,7 @@ public class BukkitHuskHomes extends JavaPlugin implements HuskHomes, BukkitTask
|
|||||||
final int y = snapshot.getHighestBlockYAt(x, z);
|
final int y = snapshot.getHighestBlockYAt(x, z);
|
||||||
final Material blockType = snapshot.getBlockType(chunkX, y, chunkZ);
|
final Material blockType = snapshot.getBlockType(chunkX, y, chunkZ);
|
||||||
if (!isBlockUnsafe(blockType.getKey().toString())) {
|
if (!isBlockUnsafe(blockType.getKey().toString())) {
|
||||||
return new Location((location.getX() + dX) + 0.5d, y + 1.25d, (location.getZ() + dZ) + 0.5d, location.getWorld());
|
return Location.at((location.getX() + dX) + 0.5d, y + 1.25d, (location.getZ() + dZ) + 0.5d, location.getWorld());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package net.william278.huskhomes.api;
|
|||||||
import net.william278.huskhomes.BukkitHuskHomes;
|
import net.william278.huskhomes.BukkitHuskHomes;
|
||||||
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.position.Server;
|
import net.william278.huskhomes.config.Server;
|
||||||
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;
|
||||||
@@ -26,7 +26,7 @@ public class HuskHomesAPI extends BaseHuskHomesAPI {
|
|||||||
/**
|
/**
|
||||||
* <b>(Internal use only)</b> - Instance of the API class
|
* <b>(Internal use only)</b> - Instance of the API class
|
||||||
*/
|
*/
|
||||||
private static final HuskHomesAPI INSTANCE = new HuskHomesAPI();
|
private static HuskHomesAPI instance;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <b>(Internal use only)</b> - Constructor, instantiating the API
|
* <b>(Internal use only)</b> - Constructor, instantiating the API
|
||||||
@@ -40,8 +40,9 @@ public class HuskHomesAPI extends BaseHuskHomesAPI {
|
|||||||
*
|
*
|
||||||
* @return instance of the HuskHomes API
|
* @return instance of the HuskHomes API
|
||||||
*/
|
*/
|
||||||
|
@NotNull
|
||||||
public static HuskHomesAPI getInstance() {
|
public static HuskHomesAPI getInstance() {
|
||||||
return INSTANCE;
|
return instance == null ? instance = new HuskHomesAPI() : instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -103,18 +104,19 @@ public class HuskHomesAPI extends BaseHuskHomesAPI {
|
|||||||
*/
|
*/
|
||||||
@NotNull
|
@NotNull
|
||||||
public Position adaptPosition(@NotNull org.bukkit.Location location, @NotNull String server) {
|
public Position adaptPosition(@NotNull org.bukkit.Location location, @NotNull String server) {
|
||||||
return new Position(Objects.requireNonNull(adaptLocation(location)), server);
|
return Position.at(Objects.requireNonNull(adaptLocation(location)), server);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a {@link Position} instance for the given bukkit {@link Location} on the server the plugin is running on.
|
* Returns a {@link Position} instance for the given bukkit {@link Location} on the server the plugin is running on.
|
||||||
|
*
|
||||||
* @param location the bukkit location to get the {@link Position} instance for
|
* @param location the bukkit location to get the {@link Position} instance for
|
||||||
* @return the {@link Position} instance for the given bukkit {@link Location} on the server the plugin is running on
|
* @return the {@link Position} instance for the given bukkit {@link Location} on the server the plugin is running on
|
||||||
* @since 4.0
|
* @since 4.0
|
||||||
*/
|
*/
|
||||||
@NotNull
|
@NotNull
|
||||||
public Position adaptPosition(@NotNull org.bukkit.Location location) {
|
public Position adaptPosition(@NotNull org.bukkit.Location location) {
|
||||||
return new Position(Objects.requireNonNull(adaptLocation(location)), getServer());
|
return Position.at(Objects.requireNonNull(adaptLocation(location)), getServer());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -6,8 +6,8 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
|
|
||||||
public class RedisEconomyHook extends VaultEconomyHook {
|
public class RedisEconomyHook extends VaultEconomyHook {
|
||||||
|
|
||||||
public RedisEconomyHook(@NotNull HuskHomes implementor) {
|
public RedisEconomyHook(@NotNull HuskHomes plugin) {
|
||||||
super(implementor);
|
super(plugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -16,8 +16,8 @@ public class VaultEconomyHook extends EconomyHook {
|
|||||||
|
|
||||||
protected Economy economy;
|
protected Economy economy;
|
||||||
|
|
||||||
public VaultEconomyHook(@NotNull HuskHomes implementor) {
|
public VaultEconomyHook(@NotNull HuskHomes plugin) {
|
||||||
super(implementor, "Vault (Economy)");
|
super(plugin, "Vault (Economy)");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ public class BukkitEventListener extends EventListener implements Listener {
|
|||||||
|
|
||||||
final BukkitUser bukkitUser = BukkitUser.adapt(player);
|
final BukkitUser bukkitUser = BukkitUser.adapt(player);
|
||||||
BukkitAdapter.adaptLocation(event.getFrom()).ifPresent(sourceLocation ->
|
BukkitAdapter.adaptLocation(event.getFrom()).ifPresent(sourceLocation ->
|
||||||
handlePlayerTeleport(bukkitUser, new Position(sourceLocation, plugin.getServerName())));
|
handlePlayerTeleport(bukkitUser, Position.at(sourceLocation, plugin.getServerName())));
|
||||||
}
|
}
|
||||||
|
|
||||||
//todo When defining paper-plugin.yml files gets merged, use the PlayerSetSpawnEvent in the paper module
|
//todo When defining paper-plugin.yml files gets merged, use the PlayerSetSpawnEvent in the paper module
|
||||||
@@ -73,7 +73,7 @@ public class BukkitEventListener extends EventListener implements Listener {
|
|||||||
// Update the player's respawn location
|
// Update the player's respawn location
|
||||||
BukkitAdapter.adaptLocation(location).ifPresent(adaptedLocation -> {
|
BukkitAdapter.adaptLocation(location).ifPresent(adaptedLocation -> {
|
||||||
final OnlineUser onlineUser = BukkitUser.adapt(event.getPlayer());
|
final OnlineUser onlineUser = BukkitUser.adapt(event.getPlayer());
|
||||||
super.handlePlayerUpdateSpawnPoint(onlineUser, new Position(
|
super.handlePlayerUpdateSpawnPoint(onlineUser, Position.at(
|
||||||
adaptedLocation.getX(), adaptedLocation.getY(), adaptedLocation.getZ(),
|
adaptedLocation.getX(), adaptedLocation.getY(), adaptedLocation.getZ(),
|
||||||
adaptedLocation.getYaw(), adaptedLocation.getPitch(),
|
adaptedLocation.getYaw(), adaptedLocation.getPitch(),
|
||||||
adaptedLocation.getWorld(), plugin.getServerName()));
|
adaptedLocation.getWorld(), plugin.getServerName()));
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ public class BukkitUser extends OnlineUser {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Position getPosition() {
|
public Position getPosition() {
|
||||||
return new Position(BukkitAdapter.adaptLocation(player.getLocation())
|
return Position.at(BukkitAdapter.adaptLocation(player.getLocation())
|
||||||
.orElseThrow(() -> new IllegalStateException("Failed to get the position of a BukkitPlayer (null)")),
|
.orElseThrow(() -> new IllegalStateException("Failed to get the position of a BukkitPlayer (null)")),
|
||||||
plugin.getServerName());
|
plugin.getServerName());
|
||||||
|
|
||||||
@@ -54,7 +54,7 @@ public class BukkitUser extends OnlineUser {
|
|||||||
@Override
|
@Override
|
||||||
public Optional<Position> getBedSpawnPosition() {
|
public Optional<Position> getBedSpawnPosition() {
|
||||||
return Optional.ofNullable(player.getBedSpawnLocation()).flatMap(BukkitAdapter::adaptLocation)
|
return Optional.ofNullable(player.getBedSpawnLocation()).flatMap(BukkitAdapter::adaptLocation)
|
||||||
.map(location -> new Position(location, plugin.getServerName()));
|
.map(location -> Position.at(location, plugin.getServerName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package net.william278.huskhomes.util;
|
package net.william278.huskhomes.util;
|
||||||
|
|
||||||
import net.william278.huskhomes.position.Location;
|
import net.william278.huskhomes.position.Location;
|
||||||
|
import net.william278.huskhomes.position.World;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
@@ -38,21 +39,21 @@ public final class BukkitAdapter {
|
|||||||
*/
|
*/
|
||||||
public static Optional<Location> adaptLocation(@NotNull org.bukkit.Location location) {
|
public static Optional<Location> adaptLocation(@NotNull org.bukkit.Location location) {
|
||||||
if (location.getWorld() == null) return Optional.empty();
|
if (location.getWorld() == null) return Optional.empty();
|
||||||
return Optional.of(new Location(location.getX(), location.getY(), location.getZ(),
|
return Optional.of(Location.at(location.getX(), location.getY(), location.getZ(),
|
||||||
location.getYaw(), location.getPitch(),
|
location.getYaw(), location.getPitch(),
|
||||||
adaptWorld(location.getWorld()).orElse(new net.william278.huskhomes.position.World())));
|
adaptWorld(location.getWorld()).orElse(new net.william278.huskhomes.position.World())));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Optional<net.william278.huskhomes.position.World> adaptWorld(@Nullable org.bukkit.World world) {
|
public static Optional<World> adaptWorld(@Nullable org.bukkit.World world) {
|
||||||
if (world == null) {
|
if (world == null) {
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
return Optional.of(new net.william278.huskhomes.position.World(world.getName(), world.getUID(),
|
return Optional.of(World.from(world.getName(), world.getUID(),
|
||||||
switch (world.getEnvironment()) {
|
switch (world.getEnvironment()) {
|
||||||
case NORMAL -> net.william278.huskhomes.position.World.Environment.OVERWORLD;
|
case NORMAL -> World.Environment.OVERWORLD;
|
||||||
case NETHER -> net.william278.huskhomes.position.World.Environment.NETHER;
|
case NETHER -> World.Environment.NETHER;
|
||||||
case THE_END -> net.william278.huskhomes.position.World.Environment.THE_END;
|
case THE_END -> World.Environment.THE_END;
|
||||||
case CUSTOM -> net.william278.huskhomes.position.World.Environment.CUSTOM;
|
case CUSTOM -> World.Environment.CUSTOM;
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -271,9 +271,9 @@ public class BukkitPluginTests {
|
|||||||
@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 = BukkitAdapter.adaptWorld(server.getWorld("world")).orElseThrow();
|
||||||
final Position newPosition = new Position(position.getX() + 10, position.getY() + 10, position.getZ() + 10,
|
final Position newPosition = Position.at(position.getX() + 10, position.getY() + 10, position.getZ() + 10,
|
||||||
0, 0, world, plugin.getServerName());
|
0, 0, world, plugin.getServerName());
|
||||||
plugin.getManager().warps().relocateWarp(name, newPosition);
|
plugin.getManager().warps().setWarpPosition(name, newPosition);
|
||||||
|
|
||||||
final Optional<Position> warpPosition = plugin.getDatabase().getWarp(name).map(warp -> warp);
|
final Optional<Position> warpPosition = plugin.getDatabase().getWarp(name).map(warp -> warp);
|
||||||
Assertions.assertTrue(warpPosition.isPresent());
|
Assertions.assertTrue(warpPosition.isPresent());
|
||||||
@@ -288,7 +288,7 @@ public class BukkitPluginTests {
|
|||||||
@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 = BukkitAdapter.adaptWorld(server.getWorld("world")).orElseThrow();
|
||||||
final Position newPosition = new Position(position.getX() + 10, position.getY() + 10, position.getZ() + 10,
|
final Position newPosition = Position.at(position.getX() + 10, position.getY() + 10, position.getZ() + 10,
|
||||||
0, 0, world, plugin.getServerName());
|
0, 0, world, plugin.getServerName());
|
||||||
plugin.getManager().warps().createWarp(name, newPosition, true);
|
plugin.getManager().warps().createWarp(name, newPosition, true);
|
||||||
|
|
||||||
@@ -327,7 +327,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 = BukkitAdapter.adaptWorld(server.getWorld("world")).orElseThrow();
|
||||||
final Position position = new Position(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)));
|
||||||
}
|
}
|
||||||
@@ -415,7 +415,7 @@ public class BukkitPluginTests {
|
|||||||
@Order(4)
|
@Order(4)
|
||||||
public void testHomeRelocation(@NotNull OnlineUser owner, @NotNull String name, @NotNull Position position) {
|
public void testHomeRelocation(@NotNull OnlineUser owner, @NotNull String name, @NotNull Position position) {
|
||||||
final World world = BukkitAdapter.adaptWorld(server.getWorld("world")).orElseThrow();
|
final World world = BukkitAdapter.adaptWorld(server.getWorld("world")).orElseThrow();
|
||||||
final Position newPosition = new Position(position.getX() + 10, position.getY() + 10, position.getZ() + 10,
|
final Position newPosition = Position.at(position.getX() + 10, position.getY() + 10, position.getZ() + 10,
|
||||||
0, 0, world, plugin.getServerName());
|
0, 0, world, plugin.getServerName());
|
||||||
plugin.getManager().homes().setHomePosition(owner, name, newPosition);
|
plugin.getManager().homes().setHomePosition(owner, name, newPosition);
|
||||||
Assertions.assertTrue(plugin.getDatabase().getHome(owner, name).isPresent());
|
Assertions.assertTrue(plugin.getDatabase().getHome(owner, name).isPresent());
|
||||||
@@ -434,7 +434,7 @@ public class BukkitPluginTests {
|
|||||||
@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 = BukkitAdapter.adaptWorld(server.getWorld("world")).orElseThrow();
|
||||||
final Position newPosition = new Position(position.getX() + 10, position.getY() + 10, position.getZ() + 10,
|
final Position newPosition = Position.at(position.getX() + 10, position.getY() + 10, position.getZ() + 10,
|
||||||
0, 0, world, plugin.getServerName());
|
0, 0, world, plugin.getServerName());
|
||||||
plugin.getManager().homes().setHomePosition(owner, name, newPosition);
|
plugin.getManager().homes().setHomePosition(owner, name, newPosition);
|
||||||
Assertions.assertTrue(plugin.getDatabase().getHome(owner, name).isPresent());
|
Assertions.assertTrue(plugin.getDatabase().getHome(owner, name).isPresent());
|
||||||
@@ -507,7 +507,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 = BukkitAdapter.adaptWorld(server.getWorld("world")).orElseThrow();
|
||||||
final Position position = new Position(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)));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ import net.william278.huskhomes.manager.Manager;
|
|||||||
import net.william278.huskhomes.network.Broker;
|
import net.william278.huskhomes.network.Broker;
|
||||||
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.position.Server;
|
import net.william278.huskhomes.config.Server;
|
||||||
import net.william278.huskhomes.position.World;
|
import net.william278.huskhomes.position.World;
|
||||||
import net.william278.huskhomes.random.RandomTeleportEngine;
|
import net.william278.huskhomes.random.RandomTeleportEngine;
|
||||||
import net.william278.huskhomes.user.ConsoleUser;
|
import net.william278.huskhomes.user.ConsoleUser;
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ import java.util.List;
|
|||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
import java.util.function.Consumer;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -123,6 +124,40 @@ public abstract class BaseHuskHomesAPI {
|
|||||||
plugin.runAsync(() -> plugin.getDatabase().updateUserData(savedUser));
|
plugin.runAsync(() -> plugin.getDatabase().updateUserData(savedUser));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Edit {@link SavedUser} data for a given player by username, if they exist.
|
||||||
|
*
|
||||||
|
* @param username The username of the user to edit data for.
|
||||||
|
* @param editor A {@link Consumer} that will be passed the {@link SavedUser} to edit
|
||||||
|
* @since 4.0
|
||||||
|
*/
|
||||||
|
public final void editUserData(@NotNull String username, @NotNull Consumer<SavedUser> editor) {
|
||||||
|
plugin.runAsync(() -> {
|
||||||
|
Optional<SavedUser> savedUser = plugin.getDatabase().getUserDataByName(username);
|
||||||
|
if (savedUser.isPresent()) {
|
||||||
|
editor.accept(savedUser.get());
|
||||||
|
plugin.getDatabase().updateUserData(savedUser.get());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Edit {@link SavedUser} data for the given player's account {@link UUID}, if they exist.
|
||||||
|
*
|
||||||
|
* @param uuid The {@link UUID} of the user to edit data for.
|
||||||
|
* @param editor A {@link Consumer} that will be passed the {@link SavedUser} to edit
|
||||||
|
* @since 4.0
|
||||||
|
*/
|
||||||
|
public final void editUserData(@NotNull UUID uuid, @NotNull Consumer<SavedUser> editor) {
|
||||||
|
plugin.runAsync(() -> {
|
||||||
|
Optional<SavedUser> savedUser = plugin.getDatabase().getUserData(uuid);
|
||||||
|
if (savedUser.isPresent()) {
|
||||||
|
editor.accept(savedUser.get());
|
||||||
|
plugin.getDatabase().updateUserData(savedUser.get());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a list of {@link Home}s set by the given user.
|
* Get a list of {@link Home}s set by the given user.
|
||||||
*
|
*
|
||||||
@@ -142,11 +177,22 @@ public abstract class BaseHuskHomesAPI {
|
|||||||
* @since 3.0
|
* @since 3.0
|
||||||
*/
|
*/
|
||||||
public final CompletableFuture<List<Home>> getUserPublicHomes(@NotNull User user) {
|
public final CompletableFuture<List<Home>> getUserPublicHomes(@NotNull User user) {
|
||||||
return getUserHomes(user).thenApply(homes -> homes.stream()
|
return plugin.supplyAsync(() -> plugin.getDatabase().getHomes(user).stream()
|
||||||
.filter(Home::isPublic)
|
.filter(Home::isPublic)
|
||||||
.collect(Collectors.toList()));
|
.collect(Collectors.toList()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a list of public homes local to this server
|
||||||
|
*
|
||||||
|
* @param user The {@link User} to get the local public homes of
|
||||||
|
* @return A {@link CompletableFuture} that will complete with a list of public {@link Home}s local to the server
|
||||||
|
* @since 4.0
|
||||||
|
*/
|
||||||
|
public final CompletableFuture<List<Home>> getLocalPublicHomes(@NotNull User user) {
|
||||||
|
return plugin.supplyAsync(() -> plugin.getDatabase().getLocalPublicHomes(plugin));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a list of homes that have been made public ("public homes")
|
* Get a list of homes that have been made public ("public homes")
|
||||||
*
|
*
|
||||||
@@ -169,6 +215,7 @@ public abstract class BaseHuskHomesAPI {
|
|||||||
return plugin.supplyAsync(() -> plugin.getDatabase().getHome(user, homeName));
|
return plugin.supplyAsync(() -> plugin.getDatabase().getHome(user, homeName));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a {@link Home} from the database by its' unique id
|
* Get a {@link Home} from the database by its' unique id
|
||||||
*
|
*
|
||||||
@@ -179,6 +226,141 @@ public abstract class BaseHuskHomesAPI {
|
|||||||
return plugin.supplyAsync(() -> plugin.getDatabase().getHome(homeUuid));
|
return plugin.supplyAsync(() -> plugin.getDatabase().getHome(homeUuid));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a home for a given user with the specified name and position
|
||||||
|
*
|
||||||
|
* @param owner The {@link User} to create the home for
|
||||||
|
* @param name The name of the home
|
||||||
|
* @param position The {@link Position} of the home
|
||||||
|
* @since 4.0
|
||||||
|
*/
|
||||||
|
public void createHome(@NotNull User owner, @NotNull String name, @NotNull Position position) {
|
||||||
|
plugin.runAsync(() -> plugin.getManager().homes().createHome(owner, name, position, false, false));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete a home for a given user with the specified name
|
||||||
|
*
|
||||||
|
* @param owner The {@link User} to delete the home for
|
||||||
|
* @param name The name of the home
|
||||||
|
* @since 4.0
|
||||||
|
*/
|
||||||
|
public final void deleteHome(@NotNull User owner, @NotNull String name) {
|
||||||
|
plugin.runAsync(() -> plugin.getManager().homes().deleteHome(owner, name));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete a home
|
||||||
|
*
|
||||||
|
* @param home The {@link Home} to delete
|
||||||
|
* @since 4.0
|
||||||
|
*/
|
||||||
|
public final void deleteHome(@NotNull Home home) {
|
||||||
|
plugin.runAsync(() -> plugin.getManager().homes().deleteHome(home));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Rename a home for a given user
|
||||||
|
*
|
||||||
|
* @param owner The {@link User} to rename the home for
|
||||||
|
* @param oldName The name of the home to rename
|
||||||
|
* @param newName The new name of the home
|
||||||
|
* @since 4.0
|
||||||
|
*/
|
||||||
|
public final void renameHome(@NotNull User owner, @NotNull String oldName, @NotNull String newName) {
|
||||||
|
plugin.runAsync(() -> plugin.getManager().homes().setHomeName(owner, oldName, newName));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Rename a home
|
||||||
|
*
|
||||||
|
* @param home The {@link Home} to rename
|
||||||
|
* @param newName The new name of the home
|
||||||
|
* @since 4.0
|
||||||
|
*/
|
||||||
|
public final void renameHome(@NotNull Home home, @NotNull String newName) {
|
||||||
|
plugin.runAsync(() -> plugin.getManager().homes().setHomeName(home, newName));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the privacy of a home
|
||||||
|
*
|
||||||
|
* @param owner The {@link User} to set the privacy of the home for
|
||||||
|
* @param name The name of the home
|
||||||
|
* @param isPublic Whether the home should be public or not
|
||||||
|
* @since 4.0
|
||||||
|
*/
|
||||||
|
public final void setHomePrivacy(@NotNull User owner, @NotNull String name, boolean isPublic) {
|
||||||
|
plugin.runAsync(() -> plugin.getManager().homes().setHomePrivacy(owner, name, isPublic));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the privacy of a home
|
||||||
|
*
|
||||||
|
* @param home The {@link Home} to set the privacy of
|
||||||
|
* @param isPublic Whether the home should be public or not
|
||||||
|
* @since 4.0
|
||||||
|
*/
|
||||||
|
public final void setHomePrivacy(@NotNull Home home, boolean isPublic) {
|
||||||
|
plugin.runAsync(() -> plugin.getManager().homes().setHomePrivacy(home, isPublic));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the description of a home
|
||||||
|
*
|
||||||
|
* @param owner The {@link User} to set the description of the home for
|
||||||
|
* @param name The name of the home
|
||||||
|
* @param description The description of the home
|
||||||
|
* @since 4.0
|
||||||
|
*/
|
||||||
|
public final void setHomeDescription(@NotNull User owner, @NotNull String name, @NotNull String description) {
|
||||||
|
plugin.runAsync(() -> plugin.getManager().homes().setHomeDescription(owner, name, description));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the description of a home
|
||||||
|
*
|
||||||
|
* @param home The {@link Home} to set the description of
|
||||||
|
* @param description The description of the home
|
||||||
|
* @since 4.0
|
||||||
|
*/
|
||||||
|
public final void setHomeDescription(@NotNull Home home, @NotNull String description) {
|
||||||
|
plugin.runAsync(() -> plugin.getManager().homes().setHomeDescription(home, description));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Relocate a home for a given user
|
||||||
|
*
|
||||||
|
* @param owner The {@link User} to relocate the home for
|
||||||
|
* @param name The name of the home
|
||||||
|
* @param position The new {@link Position} of the home
|
||||||
|
* @since 4.0
|
||||||
|
*/
|
||||||
|
public final void relocateHome(@NotNull User owner, @NotNull String name, @NotNull Position position) {
|
||||||
|
plugin.runAsync(() -> plugin.getManager().homes().setHomePosition(owner, name, position));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Relocate a home
|
||||||
|
*
|
||||||
|
* @param home The {@link Home} to relocate
|
||||||
|
* @param position The new {@link Position} of the home
|
||||||
|
* @since 4.0
|
||||||
|
*/
|
||||||
|
public final void relocateHome(@NotNull Home home, @NotNull Position position) {
|
||||||
|
plugin.runAsync(() -> plugin.getManager().homes().setHomePosition(home, position));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a list of {@link Warp}s local to this server
|
||||||
|
*
|
||||||
|
* @return A {@link CompletableFuture} that will complete with a list of {@link Warp}s local to the server
|
||||||
|
* @since 4.0
|
||||||
|
*/
|
||||||
|
public final CompletableFuture<List<Warp>> getLocalWarps() {
|
||||||
|
return plugin.supplyAsync(() -> plugin.getDatabase().getLocalWarps(plugin));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a list of {@link Warp}s
|
* Get a list of {@link Warp}s
|
||||||
*
|
*
|
||||||
@@ -210,6 +392,95 @@ public abstract class BaseHuskHomesAPI {
|
|||||||
return plugin.supplyAsync(() -> plugin.getDatabase().getWarp(warpUuid));
|
return plugin.supplyAsync(() -> plugin.getDatabase().getWarp(warpUuid));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new {@link Warp} with the given name and {@link Position}
|
||||||
|
*
|
||||||
|
* @param name The name of the warp
|
||||||
|
* @param position The {@link Position} of the warp
|
||||||
|
* @since 4.0
|
||||||
|
*/
|
||||||
|
public final void createWarp(@NotNull String name, @NotNull Position position) {
|
||||||
|
plugin.runAsync(() -> plugin.getManager().warps().createWarp(name, position));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete a {@link Warp} with the given name
|
||||||
|
*
|
||||||
|
* @param name The name of the warp to delete
|
||||||
|
*/
|
||||||
|
public final void deleteWarp(@NotNull String name) {
|
||||||
|
plugin.runAsync(() -> plugin.getManager().warps().deleteWarp(name));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete a {@link Warp}
|
||||||
|
*
|
||||||
|
* @param warp The {@link Warp} to delete
|
||||||
|
*/
|
||||||
|
public final void deleteWarp(@NotNull Warp warp) {
|
||||||
|
plugin.runAsync(() -> plugin.getManager().warps().deleteWarp(warp));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Rename a {@link Warp} by name
|
||||||
|
*
|
||||||
|
* @param oldName The name of the warp to rename
|
||||||
|
* @param newName The new name of the warp
|
||||||
|
*/
|
||||||
|
public final void renameWarp(@NotNull String oldName, @NotNull String newName) {
|
||||||
|
plugin.runAsync(() -> plugin.getManager().warps().setWarpName(oldName, newName));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Rename a {@link Warp}
|
||||||
|
*
|
||||||
|
* @param warp The {@link Warp} to rename
|
||||||
|
* @param newName The new name of the warp
|
||||||
|
*/
|
||||||
|
public final void renameWarp(@NotNull Warp warp, @NotNull String newName) {
|
||||||
|
plugin.runAsync(() -> plugin.getManager().warps().setWarpName(warp, newName));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the description of a {@link Warp} by name
|
||||||
|
*
|
||||||
|
* @param name The name of the warp to set the description of
|
||||||
|
* @param description The new description of the warp
|
||||||
|
*/
|
||||||
|
public final void setWarpDescription(@NotNull String name, @NotNull String description) {
|
||||||
|
plugin.runAsync(() -> plugin.getManager().warps().setWarpDescription(name, description));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the description of a {@link Warp}
|
||||||
|
*
|
||||||
|
* @param warp The {@link Warp} to set the description of
|
||||||
|
* @param description The new description of the warp
|
||||||
|
*/
|
||||||
|
public final void setWarpDescription(@NotNull Warp warp, @NotNull String description) {
|
||||||
|
plugin.runAsync(() -> plugin.getManager().warps().setWarpDescription(warp, description));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the {@link Position} of a {@link Warp} by name
|
||||||
|
*
|
||||||
|
* @param name The name of the warp to set the {@link Position} of
|
||||||
|
* @param position The new {@link Position} of the warp
|
||||||
|
*/
|
||||||
|
public final void relocateWarp(@NotNull String name, @NotNull Position position) {
|
||||||
|
plugin.runAsync(() -> plugin.getManager().warps().setWarpPosition(name, position));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the {@link Position} of a {@link Warp}
|
||||||
|
*
|
||||||
|
* @param warp The {@link Warp} to set the {@link Position} of
|
||||||
|
* @param position The new {@link Position} of the warp
|
||||||
|
*/
|
||||||
|
public final void relocateWarp(@NotNull Warp warp, @NotNull Position position) {
|
||||||
|
plugin.runAsync(() -> plugin.getManager().warps().setWarpPosition(warp, position));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the canonical {@link Position} of the spawn point. Note that if cross-server and global spawn
|
* Get the canonical {@link Position} of the spawn point. Note that if cross-server and global spawn
|
||||||
* are enabled in the config, this may not return a position on this server.
|
* are enabled in the config, this may not return a position on this server.
|
||||||
@@ -278,7 +549,7 @@ public abstract class BaseHuskHomesAPI {
|
|||||||
* @param rtpArgs Arguments that will be passed to the implementing {@link RandomTeleportEngine}
|
* @param rtpArgs Arguments that will be passed to the implementing {@link RandomTeleportEngine}
|
||||||
* @since 3.0
|
* @since 3.0
|
||||||
*/
|
*/
|
||||||
public final void randomlyTeleportPlayer(@NotNull OnlineUser user, final boolean timedTeleport, @NotNull String... rtpArgs) {
|
public final void randomlyTeleportPlayer(@NotNull OnlineUser user, boolean timedTeleport, @NotNull String... rtpArgs) {
|
||||||
plugin.runAsync(() -> {
|
plugin.runAsync(() -> {
|
||||||
final Optional<Position> position = plugin.getRandomTeleportEngine()
|
final Optional<Position> position = plugin.getRandomTeleportEngine()
|
||||||
.getRandomPosition(user.getPosition().getWorld(), rtpArgs);
|
.getRandomPosition(user.getPosition().getWorld(), rtpArgs);
|
||||||
|
|||||||
@@ -11,8 +11,8 @@ import java.util.List;
|
|||||||
|
|
||||||
public class DelHomeCommand extends SavedPositionCommand<Home> {
|
public class DelHomeCommand extends SavedPositionCommand<Home> {
|
||||||
|
|
||||||
public DelHomeCommand(@NotNull HuskHomes implementor) {
|
public DelHomeCommand(@NotNull HuskHomes plugin) {
|
||||||
super("delhome", List.of(), Home.class, List.of(), implementor);
|
super("delhome", List.of(), Home.class, List.of(), plugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -10,8 +10,8 @@ import java.util.List;
|
|||||||
|
|
||||||
public class DelWarpCommand extends SavedPositionCommand<Warp> {
|
public class DelWarpCommand extends SavedPositionCommand<Warp> {
|
||||||
|
|
||||||
public DelWarpCommand(@NotNull HuskHomes implementor) {
|
public DelWarpCommand(@NotNull HuskHomes plugin) {
|
||||||
super("delwarp", List.of(), Warp.class, List.of(), implementor);
|
super("delwarp", List.of(), Warp.class, List.of(), plugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ public class EditHomeCommand extends SavedPositionCommand<Home> {
|
|||||||
|
|
||||||
private void setHomeDescription(@NotNull CommandUser executor, @NotNull Home home, boolean ownerEditing, @NotNull String[] args) {
|
private void setHomeDescription(@NotNull CommandUser executor, @NotNull Home home, boolean ownerEditing, @NotNull String[] args) {
|
||||||
final String oldDescription = home.getMeta().getDescription();
|
final String oldDescription = home.getMeta().getDescription();
|
||||||
final Optional<String> optionalDescription = parseGreedyString(args, 1);
|
final Optional<String> optionalDescription = parseGreedyArguments(args);
|
||||||
if (optionalDescription.isEmpty()) {
|
if (optionalDescription.isEmpty()) {
|
||||||
plugin.getLocales().getLocale("error_invalid_syntax",
|
plugin.getLocales().getLocale("error_invalid_syntax",
|
||||||
"/edithome " + home.getName() + " description <text>")
|
"/edithome " + home.getName() + " description <text>")
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ public class EditWarpCommand extends SavedPositionCommand<Warp> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void setWarpDescription(@NotNull CommandUser executor, @NotNull Warp warp, @NotNull String[] args) {
|
private void setWarpDescription(@NotNull CommandUser executor, @NotNull Warp warp, @NotNull String[] args) {
|
||||||
final Optional<String> optionalDescription = parseGreedyString(args, 1);
|
final Optional<String> optionalDescription = parseGreedyArguments(args);
|
||||||
if (optionalDescription.isEmpty()) {
|
if (optionalDescription.isEmpty()) {
|
||||||
plugin.getLocales().getLocale("error_invalid_syntax",
|
plugin.getLocales().getLocale("error_invalid_syntax",
|
||||||
"/editwarp " + warp.getName() + " description <text>")
|
"/editwarp " + warp.getName() + " description <text>")
|
||||||
@@ -99,7 +99,7 @@ public class EditWarpCommand extends SavedPositionCommand<Warp> {
|
|||||||
warp.update(user.getPosition());
|
warp.update(user.getPosition());
|
||||||
plugin.fireEvent(plugin.getWarpEditEvent(warp, executor), (event) -> {
|
plugin.fireEvent(plugin.getWarpEditEvent(warp, executor), (event) -> {
|
||||||
try {
|
try {
|
||||||
plugin.getManager().warps().relocateWarp(warp, warp);
|
plugin.getManager().warps().setWarpPosition(warp, warp);
|
||||||
} catch (ValidationException e) {
|
} catch (ValidationException e) {
|
||||||
e.dispatchWarpError(executor, plugin, warp.getName());
|
e.dispatchWarpError(executor, plugin, warp.getName());
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -114,15 +114,15 @@ public abstract class Node implements Executable {
|
|||||||
return Optional.of(plugin.getWorlds().stream()
|
return Optional.of(plugin.getWorlds().stream()
|
||||||
.filter(world -> world.getName().equalsIgnoreCase(worldName))
|
.filter(world -> world.getName().equalsIgnoreCase(worldName))
|
||||||
.findFirst()
|
.findFirst()
|
||||||
.orElse(new World(worldName, new UUID(0, 0), environment)));
|
.orElse(World.from(worldName, new UUID(0, 0), environment)));
|
||||||
}
|
}
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Optional<String> parseGreedyString(@NotNull String[] args, int startIndex) {
|
protected Optional<String> parseGreedyArguments(@NotNull String[] args) {
|
||||||
if (args.length > startIndex) {
|
if (args.length > 1) {
|
||||||
final StringJoiner sentence = new StringJoiner(" ");
|
final StringJoiner sentence = new StringJoiner(" ");
|
||||||
for (int i = startIndex; i < args.length; i++) {
|
for (int i = 1; i < args.length; i++) {
|
||||||
sentence.add(args[i]);
|
sentence.add(args[i]);
|
||||||
}
|
}
|
||||||
return Optional.of(sentence.toString().trim());
|
return Optional.of(sentence.toString().trim());
|
||||||
@@ -132,7 +132,7 @@ public abstract class Node implements Executable {
|
|||||||
|
|
||||||
protected Position getBasePosition(@NotNull CommandUser executor) {
|
protected Position getBasePosition(@NotNull CommandUser executor) {
|
||||||
return executor instanceof OnlineUser user ? user.getPosition() : plugin.getSpawn()
|
return executor instanceof OnlineUser user ? user.getPosition() : plugin.getSpawn()
|
||||||
.orElse(new Position(0, 0, 0, 0, 0, plugin.getWorlds().get(0), plugin.getServerName()));
|
.orElse(Position.at(0, 0, 0, 0, 0, plugin.getWorlds().get(0), plugin.getServerName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Optional<Position> parsePositionArgs(@NotNull Position basePosition, @NotNull String[] args, int startIndex) {
|
protected Optional<Position> parsePositionArgs(@NotNull Position basePosition, @NotNull String[] args, int startIndex) {
|
||||||
@@ -153,7 +153,7 @@ public abstract class Node implements Executable {
|
|||||||
final Optional<Float> yaw = parseFloatArg(args, startIndex + angleStartIndex);
|
final Optional<Float> yaw = parseFloatArg(args, startIndex + angleStartIndex);
|
||||||
final Optional<Float> pitch = parseFloatArg(args, startIndex + angleStartIndex + 1);
|
final Optional<Float> pitch = parseFloatArg(args, startIndex + angleStartIndex + 1);
|
||||||
|
|
||||||
return Optional.of(new Position(x.get(), y.get(), z.get(),
|
return Optional.of(Position.at(x.get(), y.get(), z.get(),
|
||||||
yaw.orElse(basePosition.getYaw()), pitch.orElse(basePosition.getPitch()),
|
yaw.orElse(basePosition.getYaw()), pitch.orElse(basePosition.getPitch()),
|
||||||
world.orElse(basePosition.getWorld()), server.orElse(basePosition.getServer())));
|
world.orElse(basePosition.getWorld()), server.orElse(basePosition.getServer())));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -64,13 +64,14 @@ public class RtpCommand extends Command {
|
|||||||
.orElseThrow(() -> new IllegalStateException("No user data found for " + teleporter.getUsername()));
|
.orElseThrow(() -> new IllegalStateException("No user data found for " + teleporter.getUsername()));
|
||||||
final Instant currentTime = Instant.now();
|
final Instant currentTime = Instant.now();
|
||||||
if (executor.equals(teleporter) && !currentTime.isAfter(user.getRtpCooldown()) &&
|
if (executor.equals(teleporter) && !currentTime.isAfter(user.getRtpCooldown()) &&
|
||||||
!executor.hasPermission(getPermission("bypass_cooldown"))) {
|
!executor.hasPermission(getPermission("bypass_cooldown"))) {
|
||||||
plugin.getLocales().getLocale("error_rtp_cooldown",
|
plugin.getLocales().getLocale("error_rtp_cooldown",
|
||||||
Long.toString(currentTime.until(user.getRtpCooldown(), ChronoUnit.MINUTES) + 1))
|
Long.toString(currentTime.until(user.getRtpCooldown(), ChronoUnit.MINUTES) + 1))
|
||||||
.ifPresent(executor::sendMessage);
|
.ifPresent(executor::sendMessage);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Generate a random position
|
||||||
plugin.getLocales().getLocale("teleporting_random_generation")
|
plugin.getLocales().getLocale("teleporting_random_generation")
|
||||||
.ifPresent(teleporter::sendMessage);
|
.ifPresent(teleporter::sendMessage);
|
||||||
final Optional<Position> position = plugin.getRandomTeleportEngine()
|
final Optional<Position> position = plugin.getRandomTeleportEngine()
|
||||||
|
|||||||
@@ -14,8 +14,8 @@ import java.util.stream.Collectors;
|
|||||||
|
|
||||||
public class TpCommand extends Command implements TabProvider {
|
public class TpCommand extends Command implements TabProvider {
|
||||||
|
|
||||||
protected TpCommand(@NotNull HuskHomes implementor) {
|
protected TpCommand(@NotNull HuskHomes plugin) {
|
||||||
super("tp", List.of("tpo"), "[<player|position>] [target]", implementor);
|
super("tp", List.of("tpo"), "[<player|position>] [target]", plugin);
|
||||||
setOperatorCommand(true);
|
setOperatorCommand(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -172,4 +172,14 @@ public class Locales {
|
|||||||
.setSpaceBeforeFooter(false);
|
.setSpaceBeforeFooter(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents where a locale should be displayed
|
||||||
|
*/
|
||||||
|
public enum DisplaySlot {
|
||||||
|
CHAT,
|
||||||
|
ACTION_BAR,
|
||||||
|
SUBTITLE,
|
||||||
|
TITLE
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
package net.william278.huskhomes.position;
|
package net.william278.huskhomes.config;
|
||||||
|
|
||||||
import net.william278.annotaml.YamlFile;
|
import net.william278.annotaml.YamlFile;
|
||||||
import net.william278.annotaml.YamlKey;
|
import net.william278.annotaml.YamlKey;
|
||||||
@@ -100,7 +100,7 @@ public class Settings {
|
|||||||
private int maxPublicHomes = 10;
|
private int maxPublicHomes = 10;
|
||||||
|
|
||||||
@YamlKey("general.stack_permission_limits")
|
@YamlKey("general.stack_permission_limits")
|
||||||
private boolean stackPermissionLimits = true;
|
private boolean stackPermissionLimits = false;
|
||||||
|
|
||||||
@YamlKey("general.permission_restrict_warps")
|
@YamlKey("general.permission_restrict_warps")
|
||||||
private boolean permissionRestrictWarps = false;
|
private boolean permissionRestrictWarps = false;
|
||||||
@@ -112,7 +112,7 @@ public class Settings {
|
|||||||
private int teleportWarmupTime = 5;
|
private int teleportWarmupTime = 5;
|
||||||
|
|
||||||
@YamlKey("general.teleport_warmup_display")
|
@YamlKey("general.teleport_warmup_display")
|
||||||
private MessageDisplayType teleportWarmupDisplay = MessageDisplayType.ACTION_BAR;
|
private Locales.DisplaySlot teleportWarmupDisplay = Locales.DisplaySlot.ACTION_BAR;
|
||||||
|
|
||||||
@YamlKey("general.teleport_request_expiry_time")
|
@YamlKey("general.teleport_request_expiry_time")
|
||||||
private int teleportRequestExpiryTime = 60;
|
private int teleportRequestExpiryTime = 60;
|
||||||
@@ -351,7 +351,7 @@ public class Settings {
|
|||||||
return teleportWarmupTime;
|
return teleportWarmupTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MessageDisplayType getTeleportWarmupDisplay() {
|
public Locales.DisplaySlot getTeleportWarmupDisplay() {
|
||||||
return teleportWarmupDisplay;
|
return teleportWarmupDisplay;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -503,16 +503,6 @@ public class Settings {
|
|||||||
return brigadierTabCompletion;
|
return brigadierTabCompletion;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Represents where a chat message should display
|
|
||||||
*/
|
|
||||||
public enum MessageDisplayType {
|
|
||||||
MESSAGE,
|
|
||||||
ACTION_BAR,
|
|
||||||
SUBTITLE,
|
|
||||||
TITLE
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents the sound effect to play when an action happens
|
* Represents the sound effect to play when an action happens
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ public class Spawn {
|
|||||||
*/
|
*/
|
||||||
@NotNull
|
@NotNull
|
||||||
public Position getPosition(@NotNull String server) {
|
public Position getPosition(@NotNull String server) {
|
||||||
return new Position(x, y, z, yaw, pitch, new World(worldName, UUID.fromString(worldUuid)), server);
|
return Position.at(x, y, z, yaw, pitch, World.from(worldName, UUID.fromString(worldUuid)), server);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package net.william278.huskhomes.database;
|
package net.william278.huskhomes.database;
|
||||||
|
|
||||||
import net.william278.huskhomes.HuskHomes;
|
import net.william278.huskhomes.HuskHomes;
|
||||||
|
import net.william278.huskhomes.config.Server;
|
||||||
import net.william278.huskhomes.position.*;
|
import net.william278.huskhomes.position.*;
|
||||||
import net.william278.huskhomes.teleport.Teleport;
|
import net.william278.huskhomes.teleport.Teleport;
|
||||||
import net.william278.huskhomes.user.OnlineUser;
|
import net.william278.huskhomes.user.OnlineUser;
|
||||||
@@ -86,7 +87,7 @@ public abstract class Database {
|
|||||||
* <b>(Internal use only)</b> - Updates position data
|
* <b>(Internal use only)</b> - Updates position data
|
||||||
*
|
*
|
||||||
* @param positionId ID of the position to update
|
* @param positionId ID of the position to update
|
||||||
* @param position the new position
|
* @param position the Position.at
|
||||||
* @param connection SQL connection
|
* @param connection SQL connection
|
||||||
* @throws SQLException if an SQL exception occurs doing this
|
* @throws SQLException if an SQL exception occurs doing this
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -302,15 +302,15 @@ public class MySqlDatabase extends Database {
|
|||||||
|
|
||||||
final ResultSet resultSet = statement.executeQuery();
|
final ResultSet resultSet = statement.executeQuery();
|
||||||
while (resultSet.next()) {
|
while (resultSet.next()) {
|
||||||
userHomes.add(new Home(resultSet.getDouble("x"),
|
userHomes.add(Home.from(resultSet.getDouble("x"),
|
||||||
resultSet.getDouble("y"),
|
resultSet.getDouble("y"),
|
||||||
resultSet.getDouble("z"),
|
resultSet.getDouble("z"),
|
||||||
resultSet.getFloat("yaw"),
|
resultSet.getFloat("yaw"),
|
||||||
resultSet.getFloat("pitch"),
|
resultSet.getFloat("pitch"),
|
||||||
new World(resultSet.getString("world_name"),
|
World.from(resultSet.getString("world_name"),
|
||||||
UUID.fromString(resultSet.getString("world_uuid"))),
|
UUID.fromString(resultSet.getString("world_uuid"))),
|
||||||
resultSet.getString("server_name"),
|
resultSet.getString("server_name"),
|
||||||
new PositionMeta(resultSet.getString("name"),
|
PositionMeta.from(resultSet.getString("name"),
|
||||||
resultSet.getString("description"),
|
resultSet.getString("description"),
|
||||||
resultSet.getTimestamp("timestamp").toInstant(),
|
resultSet.getTimestamp("timestamp").toInstant(),
|
||||||
resultSet.getString("tags")),
|
resultSet.getString("tags")),
|
||||||
@@ -338,15 +338,15 @@ public class MySqlDatabase extends Database {
|
|||||||
|
|
||||||
final ResultSet resultSet = statement.executeQuery();
|
final ResultSet resultSet = statement.executeQuery();
|
||||||
while (resultSet.next()) {
|
while (resultSet.next()) {
|
||||||
warps.add(new Warp(resultSet.getDouble("x"),
|
warps.add(Warp.from(resultSet.getDouble("x"),
|
||||||
resultSet.getDouble("y"),
|
resultSet.getDouble("y"),
|
||||||
resultSet.getDouble("z"),
|
resultSet.getDouble("z"),
|
||||||
resultSet.getFloat("yaw"),
|
resultSet.getFloat("yaw"),
|
||||||
resultSet.getFloat("pitch"),
|
resultSet.getFloat("pitch"),
|
||||||
new World(resultSet.getString("world_name"),
|
World.from(resultSet.getString("world_name"),
|
||||||
UUID.fromString(resultSet.getString("world_uuid"))),
|
UUID.fromString(resultSet.getString("world_uuid"))),
|
||||||
resultSet.getString("server_name"),
|
resultSet.getString("server_name"),
|
||||||
new PositionMeta(resultSet.getString("name"),
|
PositionMeta.from(resultSet.getString("name"),
|
||||||
resultSet.getString("description"),
|
resultSet.getString("description"),
|
||||||
resultSet.getTimestamp("timestamp").toInstant(),
|
resultSet.getTimestamp("timestamp").toInstant(),
|
||||||
resultSet.getString("tags")),
|
resultSet.getString("tags")),
|
||||||
@@ -374,15 +374,15 @@ public class MySqlDatabase extends Database {
|
|||||||
|
|
||||||
final ResultSet resultSet = statement.executeQuery();
|
final ResultSet resultSet = statement.executeQuery();
|
||||||
while (resultSet.next()) {
|
while (resultSet.next()) {
|
||||||
userHomes.add(new Home(resultSet.getDouble("x"),
|
userHomes.add(Home.from(resultSet.getDouble("x"),
|
||||||
resultSet.getDouble("y"),
|
resultSet.getDouble("y"),
|
||||||
resultSet.getDouble("z"),
|
resultSet.getDouble("z"),
|
||||||
resultSet.getFloat("yaw"),
|
resultSet.getFloat("yaw"),
|
||||||
resultSet.getFloat("pitch"),
|
resultSet.getFloat("pitch"),
|
||||||
new World(resultSet.getString("world_name"),
|
World.from(resultSet.getString("world_name"),
|
||||||
UUID.fromString(resultSet.getString("world_uuid"))),
|
UUID.fromString(resultSet.getString("world_uuid"))),
|
||||||
resultSet.getString("server_name"),
|
resultSet.getString("server_name"),
|
||||||
new PositionMeta(resultSet.getString("name"),
|
PositionMeta.from(resultSet.getString("name"),
|
||||||
resultSet.getString("description"),
|
resultSet.getString("description"),
|
||||||
resultSet.getTimestamp("timestamp").toInstant(),
|
resultSet.getTimestamp("timestamp").toInstant(),
|
||||||
resultSet.getString("tags")),
|
resultSet.getString("tags")),
|
||||||
@@ -414,15 +414,15 @@ public class MySqlDatabase extends Database {
|
|||||||
|
|
||||||
final ResultSet resultSet = statement.executeQuery();
|
final ResultSet resultSet = statement.executeQuery();
|
||||||
if (resultSet.next()) {
|
if (resultSet.next()) {
|
||||||
return Optional.of(new Home(resultSet.getDouble("x"),
|
return Optional.of(Home.from(resultSet.getDouble("x"),
|
||||||
resultSet.getDouble("y"),
|
resultSet.getDouble("y"),
|
||||||
resultSet.getDouble("z"),
|
resultSet.getDouble("z"),
|
||||||
resultSet.getFloat("yaw"),
|
resultSet.getFloat("yaw"),
|
||||||
resultSet.getFloat("pitch"),
|
resultSet.getFloat("pitch"),
|
||||||
new World(resultSet.getString("world_name"),
|
World.from(resultSet.getString("world_name"),
|
||||||
UUID.fromString(resultSet.getString("world_uuid"))),
|
UUID.fromString(resultSet.getString("world_uuid"))),
|
||||||
resultSet.getString("server_name"),
|
resultSet.getString("server_name"),
|
||||||
new PositionMeta(resultSet.getString("name"),
|
PositionMeta.from(resultSet.getString("name"),
|
||||||
resultSet.getString("description"),
|
resultSet.getString("description"),
|
||||||
resultSet.getTimestamp("timestamp").toInstant(),
|
resultSet.getTimestamp("timestamp").toInstant(),
|
||||||
resultSet.getString("tags")),
|
resultSet.getString("tags")),
|
||||||
@@ -451,15 +451,15 @@ public class MySqlDatabase extends Database {
|
|||||||
|
|
||||||
final ResultSet resultSet = statement.executeQuery();
|
final ResultSet resultSet = statement.executeQuery();
|
||||||
if (resultSet.next()) {
|
if (resultSet.next()) {
|
||||||
return Optional.of(new Home(resultSet.getDouble("x"),
|
return Optional.of(Home.from(resultSet.getDouble("x"),
|
||||||
resultSet.getDouble("y"),
|
resultSet.getDouble("y"),
|
||||||
resultSet.getDouble("z"),
|
resultSet.getDouble("z"),
|
||||||
resultSet.getFloat("yaw"),
|
resultSet.getFloat("yaw"),
|
||||||
resultSet.getFloat("pitch"),
|
resultSet.getFloat("pitch"),
|
||||||
new World(resultSet.getString("world_name"),
|
World.from(resultSet.getString("world_name"),
|
||||||
UUID.fromString(resultSet.getString("world_uuid"))),
|
UUID.fromString(resultSet.getString("world_uuid"))),
|
||||||
resultSet.getString("server_name"),
|
resultSet.getString("server_name"),
|
||||||
new PositionMeta(resultSet.getString("name"),
|
PositionMeta.from(resultSet.getString("name"),
|
||||||
resultSet.getString("description"),
|
resultSet.getString("description"),
|
||||||
resultSet.getTimestamp("timestamp").toInstant(),
|
resultSet.getTimestamp("timestamp").toInstant(),
|
||||||
resultSet.getString("tags")),
|
resultSet.getString("tags")),
|
||||||
@@ -488,15 +488,15 @@ public class MySqlDatabase extends Database {
|
|||||||
|
|
||||||
final ResultSet resultSet = statement.executeQuery();
|
final ResultSet resultSet = statement.executeQuery();
|
||||||
if (resultSet.next()) {
|
if (resultSet.next()) {
|
||||||
return Optional.of(new Warp(resultSet.getDouble("x"),
|
return Optional.of(Warp.from(resultSet.getDouble("x"),
|
||||||
resultSet.getDouble("y"),
|
resultSet.getDouble("y"),
|
||||||
resultSet.getDouble("z"),
|
resultSet.getDouble("z"),
|
||||||
resultSet.getFloat("yaw"),
|
resultSet.getFloat("yaw"),
|
||||||
resultSet.getFloat("pitch"),
|
resultSet.getFloat("pitch"),
|
||||||
new World(resultSet.getString("world_name"),
|
World.from(resultSet.getString("world_name"),
|
||||||
UUID.fromString(resultSet.getString("world_uuid"))),
|
UUID.fromString(resultSet.getString("world_uuid"))),
|
||||||
resultSet.getString("server_name"),
|
resultSet.getString("server_name"),
|
||||||
new PositionMeta(resultSet.getString("name"),
|
PositionMeta.from(resultSet.getString("name"),
|
||||||
resultSet.getString("description"),
|
resultSet.getString("description"),
|
||||||
resultSet.getTimestamp("timestamp").toInstant(),
|
resultSet.getTimestamp("timestamp").toInstant(),
|
||||||
resultSet.getString("tags")),
|
resultSet.getString("tags")),
|
||||||
@@ -522,15 +522,15 @@ public class MySqlDatabase extends Database {
|
|||||||
|
|
||||||
final ResultSet resultSet = statement.executeQuery();
|
final ResultSet resultSet = statement.executeQuery();
|
||||||
if (resultSet.next()) {
|
if (resultSet.next()) {
|
||||||
return Optional.of(new Warp(resultSet.getDouble("x"),
|
return Optional.of(Warp.from(resultSet.getDouble("x"),
|
||||||
resultSet.getDouble("y"),
|
resultSet.getDouble("y"),
|
||||||
resultSet.getDouble("z"),
|
resultSet.getDouble("z"),
|
||||||
resultSet.getFloat("yaw"),
|
resultSet.getFloat("yaw"),
|
||||||
resultSet.getFloat("pitch"),
|
resultSet.getFloat("pitch"),
|
||||||
new World(resultSet.getString("world_name"),
|
World.from(resultSet.getString("world_name"),
|
||||||
UUID.fromString(resultSet.getString("world_uuid"))),
|
UUID.fromString(resultSet.getString("world_uuid"))),
|
||||||
resultSet.getString("server_name"),
|
resultSet.getString("server_name"),
|
||||||
new PositionMeta(resultSet.getString("name"),
|
PositionMeta.from(resultSet.getString("name"),
|
||||||
resultSet.getString("description"),
|
resultSet.getString("description"),
|
||||||
resultSet.getTimestamp("timestamp").toInstant(),
|
resultSet.getTimestamp("timestamp").toInstant(),
|
||||||
resultSet.getString("tags")),
|
resultSet.getString("tags")),
|
||||||
@@ -557,12 +557,12 @@ public class MySqlDatabase extends Database {
|
|||||||
if (resultSet.next()) {
|
if (resultSet.next()) {
|
||||||
return Optional.of(Teleport.builder(plugin)
|
return Optional.of(Teleport.builder(plugin)
|
||||||
.teleporter(onlineUser)
|
.teleporter(onlineUser)
|
||||||
.target(new Position(resultSet.getDouble("x"),
|
.target(Position.at(resultSet.getDouble("x"),
|
||||||
resultSet.getDouble("y"),
|
resultSet.getDouble("y"),
|
||||||
resultSet.getDouble("z"),
|
resultSet.getDouble("z"),
|
||||||
resultSet.getFloat("yaw"),
|
resultSet.getFloat("yaw"),
|
||||||
resultSet.getFloat("pitch"),
|
resultSet.getFloat("pitch"),
|
||||||
new World(resultSet.getString("world_name"),
|
World.from(resultSet.getString("world_name"),
|
||||||
UUID.fromString(resultSet.getString("world_uuid"))),
|
UUID.fromString(resultSet.getString("world_uuid"))),
|
||||||
resultSet.getString("server_name")))
|
resultSet.getString("server_name")))
|
||||||
.type(Teleport.Type.getTeleportType(resultSet.getInt("type"))
|
.type(Teleport.Type.getTeleportType(resultSet.getInt("type"))
|
||||||
@@ -640,12 +640,12 @@ public class MySqlDatabase extends Database {
|
|||||||
|
|
||||||
final ResultSet resultSet = statement.executeQuery();
|
final ResultSet resultSet = statement.executeQuery();
|
||||||
if (resultSet.next()) {
|
if (resultSet.next()) {
|
||||||
return Optional.of(new Position(resultSet.getDouble("x"),
|
return Optional.of(Position.at(resultSet.getDouble("x"),
|
||||||
resultSet.getDouble("y"),
|
resultSet.getDouble("y"),
|
||||||
resultSet.getDouble("z"),
|
resultSet.getDouble("z"),
|
||||||
resultSet.getFloat("yaw"),
|
resultSet.getFloat("yaw"),
|
||||||
resultSet.getFloat("pitch"),
|
resultSet.getFloat("pitch"),
|
||||||
new World(resultSet.getString("world_name"),
|
World.from(resultSet.getString("world_name"),
|
||||||
UUID.fromString(resultSet.getString("world_uuid"))),
|
UUID.fromString(resultSet.getString("world_uuid"))),
|
||||||
resultSet.getString("server_name")));
|
resultSet.getString("server_name")));
|
||||||
}
|
}
|
||||||
@@ -699,12 +699,12 @@ public class MySqlDatabase extends Database {
|
|||||||
|
|
||||||
final ResultSet resultSet = statement.executeQuery();
|
final ResultSet resultSet = statement.executeQuery();
|
||||||
if (resultSet.next()) {
|
if (resultSet.next()) {
|
||||||
return Optional.of(new Position(resultSet.getDouble("x"),
|
return Optional.of(Position.at(resultSet.getDouble("x"),
|
||||||
resultSet.getDouble("y"),
|
resultSet.getDouble("y"),
|
||||||
resultSet.getDouble("z"),
|
resultSet.getDouble("z"),
|
||||||
resultSet.getFloat("yaw"),
|
resultSet.getFloat("yaw"),
|
||||||
resultSet.getFloat("pitch"),
|
resultSet.getFloat("pitch"),
|
||||||
new World(resultSet.getString("world_name"),
|
World.from(resultSet.getString("world_name"),
|
||||||
UUID.fromString(resultSet.getString("world_uuid"))),
|
UUID.fromString(resultSet.getString("world_uuid"))),
|
||||||
resultSet.getString("server_name")));
|
resultSet.getString("server_name")));
|
||||||
}
|
}
|
||||||
@@ -757,12 +757,12 @@ public class MySqlDatabase extends Database {
|
|||||||
|
|
||||||
final ResultSet resultSet = statement.executeQuery();
|
final ResultSet resultSet = statement.executeQuery();
|
||||||
if (resultSet.next()) {
|
if (resultSet.next()) {
|
||||||
return Optional.of(new Position(resultSet.getDouble("x"),
|
return Optional.of(Position.at(resultSet.getDouble("x"),
|
||||||
resultSet.getDouble("y"),
|
resultSet.getDouble("y"),
|
||||||
resultSet.getDouble("z"),
|
resultSet.getDouble("z"),
|
||||||
resultSet.getFloat("yaw"),
|
resultSet.getFloat("yaw"),
|
||||||
resultSet.getFloat("pitch"),
|
resultSet.getFloat("pitch"),
|
||||||
new World(resultSet.getString("world_name"),
|
World.from(resultSet.getString("world_name"),
|
||||||
UUID.fromString(resultSet.getString("world_uuid"))),
|
UUID.fromString(resultSet.getString("world_uuid"))),
|
||||||
resultSet.getString("server_name")));
|
resultSet.getString("server_name")));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,9 +38,9 @@ public class SqLiteDatabase extends Database {
|
|||||||
private Connection connection;
|
private Connection connection;
|
||||||
|
|
||||||
|
|
||||||
public SqLiteDatabase(@NotNull HuskHomes implementor) {
|
public SqLiteDatabase(@NotNull HuskHomes plugin) {
|
||||||
super(implementor);
|
super(plugin);
|
||||||
this.databaseFile = new File(implementor.getDataFolder(), DATABASE_FILE_NAME);
|
this.databaseFile = new File(plugin.getDataFolder(), DATABASE_FILE_NAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Connection getConnection() throws SQLException {
|
private Connection getConnection() throws SQLException {
|
||||||
@@ -310,15 +310,15 @@ public class SqLiteDatabase extends Database {
|
|||||||
|
|
||||||
final ResultSet resultSet = statement.executeQuery();
|
final ResultSet resultSet = statement.executeQuery();
|
||||||
while (resultSet.next()) {
|
while (resultSet.next()) {
|
||||||
userHomes.add(new Home(resultSet.getDouble("x"),
|
userHomes.add(Home.from(resultSet.getDouble("x"),
|
||||||
resultSet.getDouble("y"),
|
resultSet.getDouble("y"),
|
||||||
resultSet.getDouble("z"),
|
resultSet.getDouble("z"),
|
||||||
resultSet.getFloat("yaw"),
|
resultSet.getFloat("yaw"),
|
||||||
resultSet.getFloat("pitch"),
|
resultSet.getFloat("pitch"),
|
||||||
new World(resultSet.getString("world_name"),
|
World.from(resultSet.getString("world_name"),
|
||||||
UUID.fromString(resultSet.getString("world_uuid"))),
|
UUID.fromString(resultSet.getString("world_uuid"))),
|
||||||
resultSet.getString("server_name"),
|
resultSet.getString("server_name"),
|
||||||
new PositionMeta(resultSet.getString("name"),
|
PositionMeta.from(resultSet.getString("name"),
|
||||||
resultSet.getString("description"),
|
resultSet.getString("description"),
|
||||||
resultSet.getTimestamp("timestamp").toInstant(),
|
resultSet.getTimestamp("timestamp").toInstant(),
|
||||||
resultSet.getString("tags")),
|
resultSet.getString("tags")),
|
||||||
@@ -346,15 +346,15 @@ public class SqLiteDatabase extends Database {
|
|||||||
|
|
||||||
final ResultSet resultSet = statement.executeQuery();
|
final ResultSet resultSet = statement.executeQuery();
|
||||||
while (resultSet.next()) {
|
while (resultSet.next()) {
|
||||||
warps.add(new Warp(resultSet.getDouble("x"),
|
warps.add(Warp.from(resultSet.getDouble("x"),
|
||||||
resultSet.getDouble("y"),
|
resultSet.getDouble("y"),
|
||||||
resultSet.getDouble("z"),
|
resultSet.getDouble("z"),
|
||||||
resultSet.getFloat("yaw"),
|
resultSet.getFloat("yaw"),
|
||||||
resultSet.getFloat("pitch"),
|
resultSet.getFloat("pitch"),
|
||||||
new World(resultSet.getString("world_name"),
|
World.from(resultSet.getString("world_name"),
|
||||||
UUID.fromString(resultSet.getString("world_uuid"))),
|
UUID.fromString(resultSet.getString("world_uuid"))),
|
||||||
resultSet.getString("server_name"),
|
resultSet.getString("server_name"),
|
||||||
new PositionMeta(resultSet.getString("name"),
|
PositionMeta.from(resultSet.getString("name"),
|
||||||
resultSet.getString("description"),
|
resultSet.getString("description"),
|
||||||
resultSet.getTimestamp("timestamp").toInstant(),
|
resultSet.getTimestamp("timestamp").toInstant(),
|
||||||
resultSet.getString("tags")),
|
resultSet.getString("tags")),
|
||||||
@@ -382,15 +382,15 @@ public class SqLiteDatabase extends Database {
|
|||||||
|
|
||||||
final ResultSet resultSet = statement.executeQuery();
|
final ResultSet resultSet = statement.executeQuery();
|
||||||
while (resultSet.next()) {
|
while (resultSet.next()) {
|
||||||
userHomes.add(new Home(resultSet.getDouble("x"),
|
userHomes.add(Home.from(resultSet.getDouble("x"),
|
||||||
resultSet.getDouble("y"),
|
resultSet.getDouble("y"),
|
||||||
resultSet.getDouble("z"),
|
resultSet.getDouble("z"),
|
||||||
resultSet.getFloat("yaw"),
|
resultSet.getFloat("yaw"),
|
||||||
resultSet.getFloat("pitch"),
|
resultSet.getFloat("pitch"),
|
||||||
new World(resultSet.getString("world_name"),
|
World.from(resultSet.getString("world_name"),
|
||||||
UUID.fromString(resultSet.getString("world_uuid"))),
|
UUID.fromString(resultSet.getString("world_uuid"))),
|
||||||
resultSet.getString("server_name"),
|
resultSet.getString("server_name"),
|
||||||
new PositionMeta(resultSet.getString("name"),
|
PositionMeta.from(resultSet.getString("name"),
|
||||||
resultSet.getString("description"),
|
resultSet.getString("description"),
|
||||||
resultSet.getTimestamp("timestamp").toInstant(),
|
resultSet.getTimestamp("timestamp").toInstant(),
|
||||||
resultSet.getString("tags")),
|
resultSet.getString("tags")),
|
||||||
@@ -422,15 +422,15 @@ public class SqLiteDatabase extends Database {
|
|||||||
|
|
||||||
final ResultSet resultSet = statement.executeQuery();
|
final ResultSet resultSet = statement.executeQuery();
|
||||||
if (resultSet.next()) {
|
if (resultSet.next()) {
|
||||||
return Optional.of(new Home(resultSet.getDouble("x"),
|
return Optional.of(Home.from(resultSet.getDouble("x"),
|
||||||
resultSet.getDouble("y"),
|
resultSet.getDouble("y"),
|
||||||
resultSet.getDouble("z"),
|
resultSet.getDouble("z"),
|
||||||
resultSet.getFloat("yaw"),
|
resultSet.getFloat("yaw"),
|
||||||
resultSet.getFloat("pitch"),
|
resultSet.getFloat("pitch"),
|
||||||
new World(resultSet.getString("world_name"),
|
World.from(resultSet.getString("world_name"),
|
||||||
UUID.fromString(resultSet.getString("world_uuid"))),
|
UUID.fromString(resultSet.getString("world_uuid"))),
|
||||||
resultSet.getString("server_name"),
|
resultSet.getString("server_name"),
|
||||||
new PositionMeta(resultSet.getString("name"),
|
PositionMeta.from(resultSet.getString("name"),
|
||||||
resultSet.getString("description"),
|
resultSet.getString("description"),
|
||||||
resultSet.getTimestamp("timestamp").toInstant(),
|
resultSet.getTimestamp("timestamp").toInstant(),
|
||||||
resultSet.getString("tags")),
|
resultSet.getString("tags")),
|
||||||
@@ -459,15 +459,15 @@ public class SqLiteDatabase extends Database {
|
|||||||
|
|
||||||
final ResultSet resultSet = statement.executeQuery();
|
final ResultSet resultSet = statement.executeQuery();
|
||||||
if (resultSet.next()) {
|
if (resultSet.next()) {
|
||||||
return Optional.of(new Home(resultSet.getDouble("x"),
|
return Optional.of(Home.from(resultSet.getDouble("x"),
|
||||||
resultSet.getDouble("y"),
|
resultSet.getDouble("y"),
|
||||||
resultSet.getDouble("z"),
|
resultSet.getDouble("z"),
|
||||||
resultSet.getFloat("yaw"),
|
resultSet.getFloat("yaw"),
|
||||||
resultSet.getFloat("pitch"),
|
resultSet.getFloat("pitch"),
|
||||||
new World(resultSet.getString("world_name"),
|
World.from(resultSet.getString("world_name"),
|
||||||
UUID.fromString(resultSet.getString("world_uuid"))),
|
UUID.fromString(resultSet.getString("world_uuid"))),
|
||||||
resultSet.getString("server_name"),
|
resultSet.getString("server_name"),
|
||||||
new PositionMeta(resultSet.getString("name"),
|
PositionMeta.from(resultSet.getString("name"),
|
||||||
resultSet.getString("description"),
|
resultSet.getString("description"),
|
||||||
resultSet.getTimestamp("timestamp").toInstant(),
|
resultSet.getTimestamp("timestamp").toInstant(),
|
||||||
resultSet.getString("tags")),
|
resultSet.getString("tags")),
|
||||||
@@ -496,15 +496,15 @@ public class SqLiteDatabase extends Database {
|
|||||||
|
|
||||||
final ResultSet resultSet = statement.executeQuery();
|
final ResultSet resultSet = statement.executeQuery();
|
||||||
if (resultSet.next()) {
|
if (resultSet.next()) {
|
||||||
return Optional.of(new Warp(resultSet.getDouble("x"),
|
return Optional.of(Warp.from(resultSet.getDouble("x"),
|
||||||
resultSet.getDouble("y"),
|
resultSet.getDouble("y"),
|
||||||
resultSet.getDouble("z"),
|
resultSet.getDouble("z"),
|
||||||
resultSet.getFloat("yaw"),
|
resultSet.getFloat("yaw"),
|
||||||
resultSet.getFloat("pitch"),
|
resultSet.getFloat("pitch"),
|
||||||
new World(resultSet.getString("world_name"),
|
World.from(resultSet.getString("world_name"),
|
||||||
UUID.fromString(resultSet.getString("world_uuid"))),
|
UUID.fromString(resultSet.getString("world_uuid"))),
|
||||||
resultSet.getString("server_name"),
|
resultSet.getString("server_name"),
|
||||||
new PositionMeta(resultSet.getString("name"),
|
PositionMeta.from(resultSet.getString("name"),
|
||||||
resultSet.getString("description"),
|
resultSet.getString("description"),
|
||||||
resultSet.getTimestamp("timestamp").toInstant(),
|
resultSet.getTimestamp("timestamp").toInstant(),
|
||||||
resultSet.getString("tags")),
|
resultSet.getString("tags")),
|
||||||
@@ -530,15 +530,15 @@ public class SqLiteDatabase extends Database {
|
|||||||
|
|
||||||
final ResultSet resultSet = statement.executeQuery();
|
final ResultSet resultSet = statement.executeQuery();
|
||||||
if (resultSet.next()) {
|
if (resultSet.next()) {
|
||||||
return Optional.of(new Warp(resultSet.getDouble("x"),
|
return Optional.of(Warp.from(resultSet.getDouble("x"),
|
||||||
resultSet.getDouble("y"),
|
resultSet.getDouble("y"),
|
||||||
resultSet.getDouble("z"),
|
resultSet.getDouble("z"),
|
||||||
resultSet.getFloat("yaw"),
|
resultSet.getFloat("yaw"),
|
||||||
resultSet.getFloat("pitch"),
|
resultSet.getFloat("pitch"),
|
||||||
new World(resultSet.getString("world_name"),
|
World.from(resultSet.getString("world_name"),
|
||||||
UUID.fromString(resultSet.getString("world_uuid"))),
|
UUID.fromString(resultSet.getString("world_uuid"))),
|
||||||
resultSet.getString("server_name"),
|
resultSet.getString("server_name"),
|
||||||
new PositionMeta(resultSet.getString("name"),
|
PositionMeta.from(resultSet.getString("name"),
|
||||||
resultSet.getString("description"),
|
resultSet.getString("description"),
|
||||||
resultSet.getTimestamp("timestamp").toInstant(),
|
resultSet.getTimestamp("timestamp").toInstant(),
|
||||||
resultSet.getString("tags")),
|
resultSet.getString("tags")),
|
||||||
@@ -565,12 +565,12 @@ public class SqLiteDatabase extends Database {
|
|||||||
if (resultSet.next()) {
|
if (resultSet.next()) {
|
||||||
return Optional.of(Teleport.builder(plugin)
|
return Optional.of(Teleport.builder(plugin)
|
||||||
.teleporter(onlineUser)
|
.teleporter(onlineUser)
|
||||||
.target(new Position(resultSet.getDouble("x"),
|
.target(Position.at(resultSet.getDouble("x"),
|
||||||
resultSet.getDouble("y"),
|
resultSet.getDouble("y"),
|
||||||
resultSet.getDouble("z"),
|
resultSet.getDouble("z"),
|
||||||
resultSet.getFloat("yaw"),
|
resultSet.getFloat("yaw"),
|
||||||
resultSet.getFloat("pitch"),
|
resultSet.getFloat("pitch"),
|
||||||
new World(resultSet.getString("world_name"),
|
World.from(resultSet.getString("world_name"),
|
||||||
UUID.fromString(resultSet.getString("world_uuid"))),
|
UUID.fromString(resultSet.getString("world_uuid"))),
|
||||||
resultSet.getString("server_name")))
|
resultSet.getString("server_name")))
|
||||||
.type(Teleport.Type.getTeleportType(resultSet.getInt("type"))
|
.type(Teleport.Type.getTeleportType(resultSet.getInt("type"))
|
||||||
@@ -648,12 +648,12 @@ public class SqLiteDatabase extends Database {
|
|||||||
|
|
||||||
final ResultSet resultSet = statement.executeQuery();
|
final ResultSet resultSet = statement.executeQuery();
|
||||||
if (resultSet.next()) {
|
if (resultSet.next()) {
|
||||||
return Optional.of(new Position(resultSet.getDouble("x"),
|
return Optional.of(Position.at(resultSet.getDouble("x"),
|
||||||
resultSet.getDouble("y"),
|
resultSet.getDouble("y"),
|
||||||
resultSet.getDouble("z"),
|
resultSet.getDouble("z"),
|
||||||
resultSet.getFloat("yaw"),
|
resultSet.getFloat("yaw"),
|
||||||
resultSet.getFloat("pitch"),
|
resultSet.getFloat("pitch"),
|
||||||
new World(resultSet.getString("world_name"),
|
World.from(resultSet.getString("world_name"),
|
||||||
UUID.fromString(resultSet.getString("world_uuid"))),
|
UUID.fromString(resultSet.getString("world_uuid"))),
|
||||||
resultSet.getString("server_name")));
|
resultSet.getString("server_name")));
|
||||||
}
|
}
|
||||||
@@ -705,12 +705,12 @@ public class SqLiteDatabase extends Database {
|
|||||||
|
|
||||||
final ResultSet resultSet = statement.executeQuery();
|
final ResultSet resultSet = statement.executeQuery();
|
||||||
if (resultSet.next()) {
|
if (resultSet.next()) {
|
||||||
return Optional.of(new Position(resultSet.getDouble("x"),
|
return Optional.of(Position.at(resultSet.getDouble("x"),
|
||||||
resultSet.getDouble("y"),
|
resultSet.getDouble("y"),
|
||||||
resultSet.getDouble("z"),
|
resultSet.getDouble("z"),
|
||||||
resultSet.getFloat("yaw"),
|
resultSet.getFloat("yaw"),
|
||||||
resultSet.getFloat("pitch"),
|
resultSet.getFloat("pitch"),
|
||||||
new World(resultSet.getString("world_name"),
|
World.from(resultSet.getString("world_name"),
|
||||||
UUID.fromString(resultSet.getString("world_uuid"))),
|
UUID.fromString(resultSet.getString("world_uuid"))),
|
||||||
resultSet.getString("server_name")));
|
resultSet.getString("server_name")));
|
||||||
}
|
}
|
||||||
@@ -760,12 +760,12 @@ public class SqLiteDatabase extends Database {
|
|||||||
|
|
||||||
final ResultSet resultSet = statement.executeQuery();
|
final ResultSet resultSet = statement.executeQuery();
|
||||||
if (resultSet.next()) {
|
if (resultSet.next()) {
|
||||||
return Optional.of(new Position(resultSet.getDouble("x"),
|
return Optional.of(Position.at(resultSet.getDouble("x"),
|
||||||
resultSet.getDouble("y"),
|
resultSet.getDouble("y"),
|
||||||
resultSet.getDouble("z"),
|
resultSet.getDouble("z"),
|
||||||
resultSet.getFloat("yaw"),
|
resultSet.getFloat("yaw"),
|
||||||
resultSet.getFloat("pitch"),
|
resultSet.getFloat("pitch"),
|
||||||
new World(resultSet.getString("world_name"),
|
World.from(resultSet.getString("world_name"),
|
||||||
UUID.fromString(resultSet.getString("world_uuid"))),
|
UUID.fromString(resultSet.getString("world_uuid"))),
|
||||||
resultSet.getString("server_name")));
|
resultSet.getString("server_name")));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,8 +9,8 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
*/
|
*/
|
||||||
public abstract class EconomyHook extends Hook {
|
public abstract class EconomyHook extends Hook {
|
||||||
|
|
||||||
protected EconomyHook(@NotNull HuskHomes implementor, @NotNull String hookName) {
|
protected EconomyHook(@NotNull HuskHomes plugin, @NotNull String hookName) {
|
||||||
super(implementor, hookName);
|
super(plugin, hookName);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -22,8 +22,8 @@ public class EventListener {
|
|||||||
@NotNull
|
@NotNull
|
||||||
protected final HuskHomes plugin;
|
protected final HuskHomes plugin;
|
||||||
|
|
||||||
protected EventListener(@NotNull HuskHomes implementor) {
|
protected EventListener(@NotNull HuskHomes plugin) {
|
||||||
this.plugin = implementor;
|
this.plugin = plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -89,11 +89,18 @@ public class EventListener {
|
|||||||
if (teleport.getType() == Teleport.Type.RESPAWN) {
|
if (teleport.getType() == Teleport.Type.RESPAWN) {
|
||||||
final Optional<Position> bedPosition = teleporter.getBedSpawnPosition();
|
final Optional<Position> bedPosition = teleporter.getBedSpawnPosition();
|
||||||
if (bedPosition.isEmpty()) {
|
if (bedPosition.isEmpty()) {
|
||||||
plugin.getLocalCachedSpawn()
|
plugin.getSpawn().ifPresent(spawn -> {
|
||||||
.map(spawn -> spawn.getPosition(plugin.getServerName()))
|
if (plugin.getSettings().isCrossServer() && !spawn.getServer().equals(plugin.getServerName())) {
|
||||||
.ifPresent(position -> teleporter.teleportLocally(position,
|
plugin.runLater(() -> Teleport.builder(plugin)
|
||||||
plugin.getSettings().isAsynchronousTeleports()));
|
.teleporter(teleporter)
|
||||||
teleporter.sendTranslatableMessage("block.minecraft.spawn.not_valid");
|
.target(spawn)
|
||||||
|
.updateLastPosition(false)
|
||||||
|
.toTeleport().execute(), 40L);
|
||||||
|
} else {
|
||||||
|
teleporter.teleportLocally(spawn, plugin.getSettings().isAsynchronousTeleports());
|
||||||
|
}
|
||||||
|
teleporter.sendTranslatableMessage("block.minecraft.spawn.not_valid");
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
teleporter.teleportLocally(bedPosition.get(), plugin.getSettings().isAsynchronousTeleports());
|
teleporter.teleportLocally(bedPosition.get(), plugin.getSettings().isAsynchronousTeleports());
|
||||||
}
|
}
|
||||||
@@ -104,8 +111,7 @@ public class EventListener {
|
|||||||
|
|
||||||
teleporter.teleportLocally((Position) teleport.getTarget(), plugin.getSettings().isAsynchronousTeleports());
|
teleporter.teleportLocally((Position) teleport.getTarget(), plugin.getSettings().isAsynchronousTeleports());
|
||||||
plugin.getDatabase().setCurrentTeleport(teleporter, null);
|
plugin.getDatabase().setCurrentTeleport(teleporter, null);
|
||||||
plugin.getLocales().getLocale("teleporting_complete")
|
teleport.displayTeleportingComplete(teleporter);
|
||||||
.ifPresent(teleporter::sendMessage);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -146,7 +152,7 @@ public class EventListener {
|
|||||||
protected final void handlePlayerDeath(@NotNull OnlineUser onlineUser) {
|
protected final void handlePlayerDeath(@NotNull OnlineUser onlineUser) {
|
||||||
// Set the player's last position to where they died
|
// Set the player's last position to where they died
|
||||||
if (plugin.getSettings().isBackCommandReturnByDeath()
|
if (plugin.getSettings().isBackCommandReturnByDeath()
|
||||||
&& onlineUser.hasPermission(Permission.COMMAND_BACK_RETURN_BY_DEATH.node)) {
|
&& onlineUser.hasPermission(Permission.COMMAND_BACK_RETURN_BY_DEATH.node)) {
|
||||||
plugin.getDatabase().setLastPosition(onlineUser, onlineUser.getPosition());
|
plugin.getDatabase().setLastPosition(onlineUser, onlineUser.getPosition());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -160,8 +166,8 @@ public class EventListener {
|
|||||||
plugin.runAsync(() -> {
|
plugin.runAsync(() -> {
|
||||||
// Display the return by death via /back notification
|
// Display the return by death via /back notification
|
||||||
if (plugin.getSettings().isBackCommandReturnByDeath()
|
if (plugin.getSettings().isBackCommandReturnByDeath()
|
||||||
&& onlineUser.hasPermission(Permission.COMMAND_BACK.node)
|
&& onlineUser.hasPermission(Permission.COMMAND_BACK.node)
|
||||||
&& onlineUser.hasPermission(Permission.COMMAND_BACK_RETURN_BY_DEATH.node)) {
|
&& onlineUser.hasPermission(Permission.COMMAND_BACK_RETURN_BY_DEATH.node)) {
|
||||||
plugin.getLocales().getLocale("return_by_death_notification")
|
plugin.getLocales().getLocale("return_by_death_notification")
|
||||||
.ifPresent(onlineUser::sendMessage);
|
.ifPresent(onlineUser::sendMessage);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -150,7 +150,7 @@ public class HomesManager {
|
|||||||
existing.update(position);
|
existing.update(position);
|
||||||
return existing;
|
return existing;
|
||||||
})
|
})
|
||||||
.orElse(new Home(position, new PositionMeta(name, ""), owner));
|
.orElse(Home.from(position, PositionMeta.create(name, ""), owner));
|
||||||
plugin.getDatabase().saveHome(home);
|
plugin.getDatabase().saveHome(home);
|
||||||
this.cacheHome(home, true);
|
this.cacheHome(home, true);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ public class WarpsManager {
|
|||||||
existing.setPitch(position.getPitch());
|
existing.setPitch(position.getPitch());
|
||||||
return existing;
|
return existing;
|
||||||
})
|
})
|
||||||
.orElse(new Warp(position, new PositionMeta(name, "")));
|
.orElse(Warp.from(position, PositionMeta.create(name, "")));
|
||||||
plugin.getDatabase().saveWarp(warp);
|
plugin.getDatabase().saveWarp(warp);
|
||||||
this.cacheWarp(warp, true);
|
this.cacheWarp(warp, true);
|
||||||
}
|
}
|
||||||
@@ -122,16 +122,16 @@ public class WarpsManager {
|
|||||||
return deleted;
|
return deleted;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void relocateWarp(@NotNull String name, @NotNull Position position) throws ValidationException {
|
public void setWarpPosition(@NotNull String name, @NotNull Position position) throws ValidationException {
|
||||||
final Optional<Warp> optionalWarp = plugin.getDatabase().getWarp(name);
|
final Optional<Warp> optionalWarp = plugin.getDatabase().getWarp(name);
|
||||||
if (optionalWarp.isEmpty()) {
|
if (optionalWarp.isEmpty()) {
|
||||||
throw new ValidationException(ValidationException.Type.NOT_FOUND);
|
throw new ValidationException(ValidationException.Type.NOT_FOUND);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.relocateWarp(optionalWarp.get(), position);
|
this.setWarpPosition(optionalWarp.get(), position);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void relocateWarp(@NotNull Warp warp, @NotNull Position position) {
|
public void setWarpPosition(@NotNull Warp warp, @NotNull Position position) {
|
||||||
warp.update(position);
|
warp.update(position);
|
||||||
plugin.getDatabase().saveWarp(warp);
|
plugin.getDatabase().saveWarp(warp);
|
||||||
this.cacheWarp(warp, true);
|
this.cacheWarp(warp, true);
|
||||||
|
|||||||
@@ -13,19 +13,30 @@ public class Home extends SavedPosition {
|
|||||||
private final User owner;
|
private final User owner;
|
||||||
private boolean isPublic;
|
private boolean isPublic;
|
||||||
|
|
||||||
public Home(double x, double y, double z, float yaw, float pitch, @NotNull World world, @NotNull String server,
|
private Home(double x, double y, double z, float yaw, float pitch, @NotNull World world, @NotNull String server,
|
||||||
@NotNull PositionMeta positionMeta, @NotNull UUID uuid, @NotNull User owner, boolean isPublic) {
|
@NotNull PositionMeta positionMeta, @NotNull UUID uuid, @NotNull User owner, boolean isPublic) {
|
||||||
super(x, y, z, yaw, pitch, world, server, positionMeta, uuid);
|
super(x, y, z, yaw, pitch, world, server, positionMeta, uuid);
|
||||||
this.owner = owner;
|
this.owner = owner;
|
||||||
this.setPublic(isPublic);
|
this.setPublic(isPublic);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Home(@NotNull Position position, @NotNull PositionMeta meta, @NotNull User owner) {
|
private Home(@NotNull Position position, @NotNull PositionMeta meta, @NotNull User owner) {
|
||||||
super(position, meta);
|
super(position, meta);
|
||||||
this.owner = owner;
|
this.owner = owner;
|
||||||
this.setPublic(false);
|
this.setPublic(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public static Home from(double x, double y, double z, float yaw, float pitch, @NotNull World world, @NotNull String server,
|
||||||
|
@NotNull PositionMeta positionMeta, @NotNull UUID uuid, @NotNull User owner, boolean isPublic) {
|
||||||
|
return new Home(x, y, z, yaw, pitch, world, server, positionMeta, uuid, owner, isPublic);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public static Home from(@NotNull Position position, @NotNull PositionMeta meta, @NotNull User owner) {
|
||||||
|
return new Home(position, meta, owner);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The {@link User} who owns this home
|
* The {@link User} who owns this home
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -1,30 +1,26 @@
|
|||||||
package net.william278.huskhomes.position;
|
package net.william278.huskhomes.position;
|
||||||
|
|
||||||
|
import com.google.gson.annotations.Expose;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a local position on this server
|
* Represents a local position on this server
|
||||||
*/
|
*/
|
||||||
public class Location {
|
public class Location {
|
||||||
|
@Expose
|
||||||
private double x;
|
private double x;
|
||||||
|
@Expose
|
||||||
private double y;
|
private double y;
|
||||||
|
@Expose
|
||||||
private double z;
|
private double z;
|
||||||
|
@Expose
|
||||||
private float yaw;
|
private float yaw;
|
||||||
|
@Expose
|
||||||
private float pitch;
|
private float pitch;
|
||||||
|
@Expose
|
||||||
private World world;
|
private World world;
|
||||||
|
|
||||||
public Location(double x, double y, double z, @NotNull World world) {
|
protected Location(double x, double y, double z, float yaw, float pitch, @NotNull World world) {
|
||||||
this.setX(x);
|
|
||||||
this.setY(y);
|
|
||||||
this.setZ(z);
|
|
||||||
this.setYaw(0);
|
|
||||||
this.setPitch(0);
|
|
||||||
this.setWorld(world);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Location(double x, double y, double z, float yaw, float pitch,
|
|
||||||
@NotNull World world) {
|
|
||||||
this.setX(x);
|
this.setX(x);
|
||||||
this.setY(y);
|
this.setY(y);
|
||||||
this.setZ(z);
|
this.setZ(z);
|
||||||
@@ -36,6 +32,16 @@ public class Location {
|
|||||||
public Location() {
|
public Location() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public static Location at(double x, double y, double z, float yaw, float pitch, @NotNull World world) {
|
||||||
|
return new Location(x, y, z, yaw, pitch, world);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public static Location at(double x, double y, double z, @NotNull World world) {
|
||||||
|
return Location.at(x, y, z, 0, 0, world);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update the position to match that of another position
|
* Update the position to match that of another position
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package net.william278.huskhomes.position;
|
package net.william278.huskhomes.position;
|
||||||
|
|
||||||
|
import com.google.gson.annotations.Expose;
|
||||||
import net.william278.huskhomes.teleport.Target;
|
import net.william278.huskhomes.teleport.Target;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
@@ -8,15 +9,15 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
*/
|
*/
|
||||||
public class Position extends Location implements Target {
|
public class Position extends Location implements Target {
|
||||||
|
|
||||||
|
@Expose
|
||||||
private String server;
|
private String server;
|
||||||
|
|
||||||
public Position(double x, double y, double z, float yaw, float pitch,
|
protected Position(double x, double y, double z, float yaw, float pitch, @NotNull World world, @NotNull String server) {
|
||||||
@NotNull World world, @NotNull String server) {
|
|
||||||
super(x, y, z, yaw, pitch, world);
|
super(x, y, z, yaw, pitch, world);
|
||||||
this.setServer(server);
|
this.setServer(server);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Position(@NotNull Location location, @NotNull String server) {
|
protected Position(@NotNull Location location, @NotNull String server) {
|
||||||
super(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch(), location.getWorld());
|
super(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch(), location.getWorld());
|
||||||
this.setServer(server);
|
this.setServer(server);
|
||||||
}
|
}
|
||||||
@@ -25,6 +26,21 @@ public class Position extends Location implements Target {
|
|||||||
private Position() {
|
private Position() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public static Position at(double x, double y, double z, float yaw, float pitch, @NotNull World world, @NotNull String server) {
|
||||||
|
return new Position(x, y, z, yaw, pitch, world, server);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public static Position at(double x, double y, double z, @NotNull World world, @NotNull String server) {
|
||||||
|
return Position.at(x, y, z, 0, 0, world, server);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public static Position at(@NotNull Location location, @NotNull String server) {
|
||||||
|
return new Position(location, server);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update(@NotNull Position newPosition) {
|
public void update(@NotNull Position newPosition) {
|
||||||
super.update(newPosition);
|
super.update(newPosition);
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents metadata about a {@link Position}, used in {@link SavedPosition} implementations
|
* Represents metadata about a {@link Position}, used in {@link SavedPosition} implementations
|
||||||
@@ -16,24 +15,27 @@ import java.util.Optional;
|
|||||||
public class PositionMeta {
|
public class PositionMeta {
|
||||||
|
|
||||||
private String name;
|
private String name;
|
||||||
@Nullable
|
|
||||||
private String description;
|
private String description;
|
||||||
private Map<String, String> tags;
|
private Map<String, String> tags;
|
||||||
private Instant creationTime;
|
private Instant creationTime;
|
||||||
|
|
||||||
public PositionMeta(@NotNull String name, @NotNull String description, @NotNull Instant creationTime,
|
private PositionMeta(@NotNull String name, @NotNull String description,
|
||||||
@Nullable String serializedTags) {
|
@NotNull Instant creationTime, @Nullable String serializedTags) {
|
||||||
this.setName(name);
|
this.setName(name);
|
||||||
this.setDescription(description);
|
this.setDescription(description);
|
||||||
this.setCreationTime(creationTime);
|
this.setCreationTime(creationTime);
|
||||||
this.setTags(deserializeTags(serializedTags));
|
this.setTags(deserializeTags(serializedTags));
|
||||||
}
|
}
|
||||||
|
|
||||||
public PositionMeta(@NotNull String name, @NotNull String description) {
|
@NotNull
|
||||||
this.setName(name);
|
public static PositionMeta from(@NotNull String name, @NotNull String description,
|
||||||
this.setDescription(description);
|
@NotNull Instant creationTime, @Nullable String serializedTags) {
|
||||||
this.setCreationTime(Instant.now());
|
return new PositionMeta(name, description, creationTime, serializedTags);
|
||||||
this.setTags(new HashMap<>());
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public static PositionMeta create(@NotNull String name, @NotNull String description) {
|
||||||
|
return PositionMeta.from(name, description, Instant.now(), "");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -42,6 +44,7 @@ public class PositionMeta {
|
|||||||
* @param serializedTags The JSON string to deserialize
|
* @param serializedTags The JSON string to deserialize
|
||||||
* @return The deserialized {@link Map}
|
* @return The deserialized {@link Map}
|
||||||
*/
|
*/
|
||||||
|
@NotNull
|
||||||
private static Map<String, String> deserializeTags(@Nullable String serializedTags) {
|
private static Map<String, String> deserializeTags(@Nullable String serializedTags) {
|
||||||
try {
|
try {
|
||||||
if (serializedTags == null || serializedTags.isBlank()) {
|
if (serializedTags == null || serializedTags.isBlank()) {
|
||||||
@@ -89,7 +92,7 @@ public class PositionMeta {
|
|||||||
*/
|
*/
|
||||||
@NotNull
|
@NotNull
|
||||||
public String getDescription() {
|
public String getDescription() {
|
||||||
return Optional.ofNullable(description).orElse("");
|
return description;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDescription(@Nullable String description) {
|
public void setDescription(@Nullable String description) {
|
||||||
|
|||||||
@@ -12,9 +12,8 @@ public abstract class SavedPosition extends Position implements Comparable<Saved
|
|||||||
private PositionMeta meta;
|
private PositionMeta meta;
|
||||||
private final UUID uuid;
|
private final UUID uuid;
|
||||||
|
|
||||||
protected SavedPosition(double x, double y, double z, float yaw, float pitch,
|
protected SavedPosition(double x, double y, double z, float yaw, float pitch, @NotNull World world,
|
||||||
@NotNull World world, @NotNull String server,
|
@NotNull String server, @NotNull PositionMeta meta, @NotNull UUID uuid) {
|
||||||
@NotNull PositionMeta meta, @NotNull UUID uuid) {
|
|
||||||
super(x, y, z, yaw, pitch, world, server);
|
super(x, y, z, yaw, pitch, world, server);
|
||||||
this.setMeta(meta);
|
this.setMeta(meta);
|
||||||
this.uuid = uuid;
|
this.uuid = uuid;
|
||||||
|
|||||||
@@ -11,9 +11,8 @@ public class Warp extends SavedPosition {
|
|||||||
|
|
||||||
private static final String PERMISSION_PREFIX = "huskhomes.command.warp.";
|
private static final String PERMISSION_PREFIX = "huskhomes.command.warp.";
|
||||||
|
|
||||||
public Warp(double x, double y, double z, float yaw, float pitch,
|
private Warp(double x, double y, double z, float yaw, float pitch, @NotNull World world, @NotNull String server,
|
||||||
@NotNull World world, @NotNull String server,
|
@NotNull PositionMeta positionMeta, @NotNull UUID uuid) {
|
||||||
@NotNull PositionMeta positionMeta, @NotNull UUID uuid) {
|
|
||||||
super(x, y, z, yaw, pitch, world, server, positionMeta, uuid);
|
super(x, y, z, yaw, pitch, world, server, positionMeta, uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -23,10 +22,19 @@ public class Warp extends SavedPosition {
|
|||||||
* @param position The {@link Position} to save as a warp
|
* @param position The {@link Position} to save as a warp
|
||||||
* @param meta {@link PositionMeta} information about this position
|
* @param meta {@link PositionMeta} information about this position
|
||||||
*/
|
*/
|
||||||
public Warp(@NotNull Position position, @NotNull PositionMeta meta) {
|
private Warp(@NotNull Position position, @NotNull PositionMeta meta) {
|
||||||
super(position, meta);
|
super(position, meta);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Warp from(double x, double y, double z, float yaw, float pitch, @NotNull World world,
|
||||||
|
@NotNull String server, @NotNull PositionMeta positionMeta, @NotNull UUID uuid) {
|
||||||
|
return new Warp(x, y, z, yaw, pitch, world, server, positionMeta, uuid);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Warp from(@NotNull Position position, @NotNull PositionMeta meta) {
|
||||||
|
return new Warp(position, meta);
|
||||||
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static String getPermission(@NotNull String warpName) {
|
public static String getPermission(@NotNull String warpName) {
|
||||||
return PERMISSION_PREFIX + warpName.toLowerCase();
|
return PERMISSION_PREFIX + warpName.toLowerCase();
|
||||||
|
|||||||
@@ -16,12 +16,7 @@ public class World {
|
|||||||
@Nullable
|
@Nullable
|
||||||
private Environment environment;
|
private Environment environment;
|
||||||
|
|
||||||
public World(@NotNull String name, @NotNull UUID uuid) {
|
private World(@NotNull String name, @NotNull UUID uuid, @Nullable Environment environment) {
|
||||||
this.setName(name);
|
|
||||||
this.setUuid(uuid);
|
|
||||||
}
|
|
||||||
|
|
||||||
public World(@NotNull String name, @NotNull UUID uuid, @Nullable Environment environment) {
|
|
||||||
this.setName(name);
|
this.setName(name);
|
||||||
this.setUuid(uuid);
|
this.setUuid(uuid);
|
||||||
this.setEnvironment(environment);
|
this.setEnvironment(environment);
|
||||||
@@ -31,14 +26,25 @@ public class World {
|
|||||||
public World() {
|
public World() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public static World from(@NotNull String name, @NotNull UUID uuid, @NotNull Environment environment) {
|
||||||
|
return new World(name, uuid, environment);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public static World from(@NotNull String name, @NotNull UUID uuid) {
|
||||||
|
return new World(name, uuid, null);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The name of this world, as defined by the world directory name
|
* The name of this world, as defined by the world directory name
|
||||||
*/
|
*/
|
||||||
|
@NotNull
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setName(String name) {
|
public void setName(@NotNull String name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,13 +56,15 @@ public class World {
|
|||||||
return uuid;
|
return uuid;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setUuid(UUID uuid) {
|
public void setUuid(@NotNull UUID uuid) {
|
||||||
this.uuid = uuid;
|
this.uuid = uuid;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Environment of the world ({@link Environment#OVERWORLD}, {@link Environment#NETHER}, {@link Environment#THE_END},
|
* Environment of the world ({@link Environment#OVERWORLD}, {@link Environment#NETHER}, {@link Environment#THE_END},
|
||||||
* or {@link Environment#CUSTOM})
|
* or {@link Environment#CUSTOM})
|
||||||
|
* <p>
|
||||||
|
* Will return {@link Environment#OVERWORLD} if the environment is null
|
||||||
*/
|
*/
|
||||||
@NotNull
|
@NotNull
|
||||||
public Environment getEnvironment() {
|
public Environment getEnvironment() {
|
||||||
|
|||||||
+20
-14
@@ -13,19 +13,19 @@ import java.util.concurrent.CompletableFuture;
|
|||||||
/**
|
/**
|
||||||
* A random teleport engine that uses a Gaussian normal distribution to generate random positions.
|
* A random teleport engine that uses a Gaussian normal distribution to generate random positions.
|
||||||
*/
|
*/
|
||||||
public class NormalDistributionEngine extends RandomTeleportEngine {
|
public final class NormalDistributionEngine extends RandomTeleportEngine {
|
||||||
|
|
||||||
protected final int radius;
|
private final int radius;
|
||||||
protected final int spawnRadius;
|
private final int spawnRadius;
|
||||||
private final float mean;
|
private final float mean;
|
||||||
private final float standardDeviation;
|
private final float standardDeviation;
|
||||||
|
|
||||||
public NormalDistributionEngine(@NotNull HuskHomes implementor) {
|
public NormalDistributionEngine(@NotNull HuskHomes plugin) {
|
||||||
super(implementor, "Normal Distribution");
|
super(plugin, "Normal Distribution");
|
||||||
this.radius = implementor.getSettings().getRtpRadius();
|
this.radius = plugin.getSettings().getRtpRadius();
|
||||||
this.spawnRadius = implementor.getSettings().getRtpSpawnRadius();
|
this.spawnRadius = plugin.getSettings().getRtpSpawnRadius();
|
||||||
this.mean = implementor.getSettings().getRtpDistributionMean();
|
this.mean = plugin.getSettings().getRtpDistributionMean();
|
||||||
this.standardDeviation = implementor.getSettings().getRtpDistributionStandardDeviation();
|
this.standardDeviation = plugin.getSettings().getRtpDistributionStandardDeviation();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -36,7 +36,7 @@ public class NormalDistributionEngine extends RandomTeleportEngine {
|
|||||||
* @return A generated location
|
* @return A generated location
|
||||||
*/
|
*/
|
||||||
@NotNull
|
@NotNull
|
||||||
protected static Location generateLocation(@NotNull Location origin, float mean, float standardDeviation,
|
public static Location generateLocation(@NotNull Location origin, float mean, float standardDeviation,
|
||||||
float spawnRadius, float maxRadius) {
|
float spawnRadius, float maxRadius) {
|
||||||
// Generate random values
|
// Generate random values
|
||||||
final float radius = getDistributedRadius(mean, standardDeviation, spawnRadius, maxRadius);
|
final float radius = getDistributedRadius(mean, standardDeviation, spawnRadius, maxRadius);
|
||||||
@@ -46,7 +46,12 @@ public class NormalDistributionEngine extends RandomTeleportEngine {
|
|||||||
final float z = (float) (radius * Math.cos(angle));
|
final float z = (float) (radius * Math.cos(angle));
|
||||||
final float x = (float) (radius * Math.sin(angle));
|
final float x = (float) (radius * Math.sin(angle));
|
||||||
|
|
||||||
return new Location(Math.round(origin.getX()) + x, 128d, Math.round(origin.getZ()) + z, origin.getWorld());
|
return Location.at(
|
||||||
|
Math.round(origin.getX()) + x,
|
||||||
|
128d,
|
||||||
|
Math.round(origin.getZ()) + z,
|
||||||
|
origin.getWorld()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -57,7 +62,7 @@ public class NormalDistributionEngine extends RandomTeleportEngine {
|
|||||||
*/
|
*/
|
||||||
private CompletableFuture<Optional<Location>> generateSafeLocation(@NotNull World world) {
|
private CompletableFuture<Optional<Location>> generateSafeLocation(@NotNull World world) {
|
||||||
return plugin.resolveSafeGroundLocation(generateLocation(
|
return plugin.resolveSafeGroundLocation(generateLocation(
|
||||||
getOrigin(world), mean, standardDeviation, spawnRadius, radius));
|
getCenterPoint(world), mean, standardDeviation, spawnRadius, radius));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -90,10 +95,11 @@ public class NormalDistributionEngine extends RandomTeleportEngine {
|
|||||||
int attempts = 0;
|
int attempts = 0;
|
||||||
while (location.isEmpty()) {
|
while (location.isEmpty()) {
|
||||||
location = generateSafeLocation(world).join();
|
location = generateSafeLocation(world).join();
|
||||||
if (attempts > randomTimeout) {
|
if (attempts >= maxAttempts) {
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
attempts++;
|
||||||
}
|
}
|
||||||
return location.map(resolved -> new Position(resolved, plugin.getServerName()));
|
return location.map(resolved -> Position.at(resolved, plugin.getServerName()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -12,19 +12,9 @@ import java.util.Optional;
|
|||||||
*/
|
*/
|
||||||
public abstract class RandomTeleportEngine {
|
public abstract class RandomTeleportEngine {
|
||||||
|
|
||||||
@NotNull
|
|
||||||
protected final HuskHomes plugin;
|
protected final HuskHomes plugin;
|
||||||
|
|
||||||
/**
|
|
||||||
* The name of the random teleport engine
|
|
||||||
*/
|
|
||||||
@NotNull
|
|
||||||
public final String name;
|
public final String name;
|
||||||
|
public long maxAttempts = 12;
|
||||||
/**
|
|
||||||
* How many attempts to allow {@link #getRandomPosition} lookups before timing out
|
|
||||||
*/
|
|
||||||
public long randomTimeout = 8;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor for a random teleport engine
|
* Constructor for a random teleport engine
|
||||||
@@ -37,15 +27,21 @@ public abstract class RandomTeleportEngine {
|
|||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public final String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the origin position (spawn) of this server
|
* Get the origin position (spawn) of this server
|
||||||
*
|
*
|
||||||
* @return The origin position
|
* @return The origin position
|
||||||
*/
|
*/
|
||||||
protected final Position getOrigin(@NotNull World world) {
|
@NotNull
|
||||||
|
protected Position getCenterPoint(@NotNull World world) {
|
||||||
return plugin.getLocalCachedSpawn()
|
return plugin.getLocalCachedSpawn()
|
||||||
.map(s -> s.getPosition(plugin.getServerName()))
|
.map(s -> s.getPosition(plugin.getServerName()))
|
||||||
.orElse(new Position(0d, 128d, 0d, 0f, 0f,
|
.orElse(Position.at(0d, 128d, 0d, 0f, 0f,
|
||||||
world, plugin.getServerName()));
|
world, plugin.getServerName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -56,7 +52,7 @@ public abstract class RandomTeleportEngine {
|
|||||||
* @param world The world to find a random position in
|
* @param world The world to find a random position in
|
||||||
* @param args The arguments to pass to the random teleport engine
|
* @param args The arguments to pass to the random teleport engine
|
||||||
* @return The position, optionally, which will be empty if the random teleport engine timed out after a
|
* @return The position, optionally, which will be empty if the random teleport engine timed out after a
|
||||||
* {@link #randomTimeout configured number of attempts}
|
* {@link #maxAttempts configured number of attempts}
|
||||||
*/
|
*/
|
||||||
public abstract Optional<Position> getRandomPosition(@NotNull World world, @NotNull String[] args);
|
public abstract Optional<Position> getRandomPosition(@NotNull World world, @NotNull String[] args);
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package net.william278.huskhomes.teleport;
|
package net.william278.huskhomes.teleport;
|
||||||
|
|
||||||
import net.william278.huskhomes.HuskHomes;
|
import net.william278.huskhomes.HuskHomes;
|
||||||
|
import net.william278.huskhomes.config.Settings;
|
||||||
import net.william278.huskhomes.event.ITeleportEvent;
|
import net.william278.huskhomes.event.ITeleportEvent;
|
||||||
import net.william278.huskhomes.hook.EconomyHook;
|
import net.william278.huskhomes.hook.EconomyHook;
|
||||||
import net.william278.huskhomes.network.Message;
|
import net.william278.huskhomes.network.Message;
|
||||||
@@ -85,8 +86,7 @@ public class Teleport {
|
|||||||
fireEvent((event) -> {
|
fireEvent((event) -> {
|
||||||
executeEconomyActions();
|
executeEconomyActions();
|
||||||
teleporter.teleportLocally(localTarget.get().getPosition(), async);
|
teleporter.teleportLocally(localTarget.get().getPosition(), async);
|
||||||
plugin.getLocales().getLocale("teleporting_complete")
|
this.displayTeleportingComplete(teleporter);
|
||||||
.ifPresent(teleporter::sendMessage);
|
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -98,8 +98,7 @@ public class Teleport {
|
|||||||
.type(Message.Type.TELEPORT_TO_NETWORKED_POSITION)
|
.type(Message.Type.TELEPORT_TO_NETWORKED_POSITION)
|
||||||
.target(username.name())
|
.target(username.name())
|
||||||
.build().send(plugin.getMessenger(), executor);
|
.build().send(plugin.getMessenger(), executor);
|
||||||
plugin.getLocales().getLocale("teleporting_complete")
|
this.displayTeleportingComplete(teleporter);
|
||||||
.ifPresent(teleporter::sendMessage);
|
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -113,8 +112,7 @@ public class Teleport {
|
|||||||
final Position target = (Position) this.target;
|
final Position target = (Position) this.target;
|
||||||
if (!plugin.getSettings().isCrossServer() || target.getServer().equals(plugin.getServerName())) {
|
if (!plugin.getSettings().isCrossServer() || target.getServer().equals(plugin.getServerName())) {
|
||||||
teleporter.teleportLocally(target, async);
|
teleporter.teleportLocally(target, async);
|
||||||
plugin.getLocales().getLocale("teleporting_complete")
|
this.displayTeleportingComplete(teleporter);
|
||||||
.ifPresent(teleporter::sendMessage);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -131,6 +129,13 @@ public class Teleport {
|
|||||||
return Optional.of((OnlineUser) this.teleporter);
|
return Optional.of((OnlineUser) this.teleporter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void displayTeleportingComplete(@NotNull OnlineUser teleporter) {
|
||||||
|
plugin.getLocales().getLocale("teleporting_complete")
|
||||||
|
.ifPresent(teleporter::sendMessage);
|
||||||
|
plugin.getSettings().getSoundEffect(Settings.SoundEffectAction.TELEPORTATION_CANCELLED)
|
||||||
|
.ifPresent(teleporter::playSound);
|
||||||
|
}
|
||||||
|
|
||||||
// Fire the teleport event
|
// Fire the teleport event
|
||||||
private void fireEvent(@NotNull Consumer<ITeleportEvent> afterFired) {
|
private void fireEvent(@NotNull Consumer<ITeleportEvent> afterFired) {
|
||||||
plugin.fireEvent(plugin.getTeleportEvent(this), afterFired);
|
plugin.fireEvent(plugin.getTeleportEvent(this), afterFired);
|
||||||
|
|||||||
@@ -132,12 +132,7 @@ public class TimedTeleport extends Teleport {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void sendStatusMessage(@NotNull MineDown message) {
|
private void sendStatusMessage(@NotNull MineDown message) {
|
||||||
switch (plugin.getSettings().getTeleportWarmupDisplay()) {
|
teleporter.sendMessage(message, plugin.getSettings().getTeleportWarmupDisplay());
|
||||||
case ACTION_BAR -> teleporter.sendActionBar(message);
|
|
||||||
case SUBTITLE -> teleporter.sendTitle(message, true);
|
|
||||||
case TITLE -> teleporter.sendTitle(message, false);
|
|
||||||
case MESSAGE -> teleporter.sendMessage(message);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean hasTeleporterMoved() {
|
private boolean hasTeleporterMoved() {
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import net.kyori.adventure.key.Key;
|
|||||||
import net.kyori.adventure.sound.Sound;
|
import net.kyori.adventure.sound.Sound;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.kyori.adventure.title.TitlePart;
|
import net.kyori.adventure.title.TitlePart;
|
||||||
|
import net.william278.huskhomes.config.Locales;
|
||||||
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.Teleportable;
|
import net.william278.huskhomes.teleport.Teleportable;
|
||||||
@@ -98,6 +99,24 @@ public abstract class OnlineUser extends User implements Teleportable, CommandUs
|
|||||||
.replace().toComponent());
|
.replace().toComponent());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Dispatch a MineDown-formatted message to this player
|
||||||
|
*
|
||||||
|
* @param mineDown the parsed {@link MineDown} to send
|
||||||
|
* @param slot the {@link Locales.DisplaySlot} to send the message to
|
||||||
|
*/
|
||||||
|
public final void sendMessage(@NotNull MineDown mineDown, @NotNull Locales.DisplaySlot slot) {
|
||||||
|
if (slot == Locales.DisplaySlot.CHAT) {
|
||||||
|
sendMessage(mineDown);
|
||||||
|
} else if (slot == Locales.DisplaySlot.ACTION_BAR) {
|
||||||
|
sendActionBar(mineDown);
|
||||||
|
} else if (slot == Locales.DisplaySlot.TITLE) {
|
||||||
|
sendTitle(mineDown, false);
|
||||||
|
} else if (slot == Locales.DisplaySlot.SUBTITLE) {
|
||||||
|
sendTitle(mineDown, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Dispatch a Minecraft translatable keyed-message to this player
|
* Dispatch a Minecraft translatable keyed-message to this player
|
||||||
*
|
*
|
||||||
@@ -144,6 +163,7 @@ public abstract class OnlineUser extends User implements Teleportable, CommandUs
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Send a plugin message to the user
|
* Send a plugin message to the user
|
||||||
|
*
|
||||||
* @param channel channel to send it on
|
* @param channel channel to send it on
|
||||||
* @param message byte array of message data
|
* @param message byte array of message data
|
||||||
*/
|
*/
|
||||||
|
|||||||
+4
-4
@@ -28,8 +28,8 @@ public class MessageSerializationTests {
|
|||||||
.type(Message.Type.TELEPORT_REQUEST)
|
.type(Message.Type.TELEPORT_REQUEST)
|
||||||
.target("TestTarget")
|
.target("TestTarget")
|
||||||
.payload(Payload.withPosition(
|
.payload(Payload.withPosition(
|
||||||
new Position(63.25, 127.43, -32, 180f, -94.3f,
|
Position.at(63.25, 127.43, -32, 180f, -94.3f,
|
||||||
new World("TestWorld", UUID.randomUUID()), "TestServer")))
|
World.from("TestWorld", UUID.randomUUID()), "TestServer")))
|
||||||
.build(),
|
.build(),
|
||||||
Message.builder()
|
Message.builder()
|
||||||
.type(Message.Type.TELEPORT_TO_NETWORKED_USER)
|
.type(Message.Type.TELEPORT_TO_NETWORKED_USER)
|
||||||
@@ -45,8 +45,8 @@ public class MessageSerializationTests {
|
|||||||
.type(Message.Type.TELEPORT_TO_POSITION)
|
.type(Message.Type.TELEPORT_TO_POSITION)
|
||||||
.target("TestTarget")
|
.target("TestTarget")
|
||||||
.payload(Payload.withPosition(
|
.payload(Payload.withPosition(
|
||||||
new Position(63.25, 127.43, -32, 180f, -94.3f,
|
Position.at(63.25, 127.43, -32, 180f, -94.3f,
|
||||||
new World("TestWorld", UUID.randomUUID()), "TestServer")))
|
World.from("TestWorld", UUID.randomUUID()), "TestServer")))
|
||||||
.build()
|
.build()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ public class NormalDistributionTests {
|
|||||||
final List<Location> locations = new ArrayList<>();
|
final List<Location> locations = new ArrayList<>();
|
||||||
for (int i = 0; i < amount; i++) {
|
for (int i = 0; i < amount; i++) {
|
||||||
locations.add(NormalDistributionEngine.generateLocation(
|
locations.add(NormalDistributionEngine.generateLocation(
|
||||||
new Location(0, 0, 0, 0, 0, new World("TestWorld", UUID.randomUUID())),
|
Location.at(0, 0, 0, 0, 0, World.from("TestWorld", UUID.randomUUID())),
|
||||||
MEAN, STANDARD_DEVIATION, SPAWN_RADIUS, MAX_RADIUS));
|
MEAN, STANDARD_DEVIATION, SPAWN_RADIUS, MAX_RADIUS));
|
||||||
}
|
}
|
||||||
return locations;
|
return locations;
|
||||||
|
|||||||
Reference in new issue
Block a user