mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-02 14:38:52 +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
@@ -18,7 +18,7 @@ import net.william278.huskhomes.manager.Manager;
|
||||
import net.william278.huskhomes.network.Broker;
|
||||
import net.william278.huskhomes.position.Location;
|
||||
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.random.RandomTeleportEngine;
|
||||
import net.william278.huskhomes.user.ConsoleUser;
|
||||
|
||||
@@ -18,6 +18,7 @@ import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@@ -123,6 +124,40 @@ public abstract class BaseHuskHomesAPI {
|
||||
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.
|
||||
*
|
||||
@@ -142,11 +177,22 @@ public abstract class BaseHuskHomesAPI {
|
||||
* @since 3.0
|
||||
*/
|
||||
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)
|
||||
.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")
|
||||
*
|
||||
@@ -169,6 +215,7 @@ public abstract class BaseHuskHomesAPI {
|
||||
return plugin.supplyAsync(() -> plugin.getDatabase().getHome(user, homeName));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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));
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*
|
||||
@@ -210,6 +392,95 @@ public abstract class BaseHuskHomesAPI {
|
||||
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
|
||||
* 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}
|
||||
* @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(() -> {
|
||||
final Optional<Position> position = plugin.getRandomTeleportEngine()
|
||||
.getRandomPosition(user.getPosition().getWorld(), rtpArgs);
|
||||
|
||||
@@ -11,8 +11,8 @@ import java.util.List;
|
||||
|
||||
public class DelHomeCommand extends SavedPositionCommand<Home> {
|
||||
|
||||
public DelHomeCommand(@NotNull HuskHomes implementor) {
|
||||
super("delhome", List.of(), Home.class, List.of(), implementor);
|
||||
public DelHomeCommand(@NotNull HuskHomes plugin) {
|
||||
super("delhome", List.of(), Home.class, List.of(), plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -10,8 +10,8 @@ import java.util.List;
|
||||
|
||||
public class DelWarpCommand extends SavedPositionCommand<Warp> {
|
||||
|
||||
public DelWarpCommand(@NotNull HuskHomes implementor) {
|
||||
super("delwarp", List.of(), Warp.class, List.of(), implementor);
|
||||
public DelWarpCommand(@NotNull HuskHomes plugin) {
|
||||
super("delwarp", List.of(), Warp.class, List.of(), plugin);
|
||||
}
|
||||
|
||||
@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) {
|
||||
final String oldDescription = home.getMeta().getDescription();
|
||||
final Optional<String> optionalDescription = parseGreedyString(args, 1);
|
||||
final Optional<String> optionalDescription = parseGreedyArguments(args);
|
||||
if (optionalDescription.isEmpty()) {
|
||||
plugin.getLocales().getLocale("error_invalid_syntax",
|
||||
"/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) {
|
||||
final Optional<String> optionalDescription = parseGreedyString(args, 1);
|
||||
final Optional<String> optionalDescription = parseGreedyArguments(args);
|
||||
if (optionalDescription.isEmpty()) {
|
||||
plugin.getLocales().getLocale("error_invalid_syntax",
|
||||
"/editwarp " + warp.getName() + " description <text>")
|
||||
@@ -99,7 +99,7 @@ public class EditWarpCommand extends SavedPositionCommand<Warp> {
|
||||
warp.update(user.getPosition());
|
||||
plugin.fireEvent(plugin.getWarpEditEvent(warp, executor), (event) -> {
|
||||
try {
|
||||
plugin.getManager().warps().relocateWarp(warp, warp);
|
||||
plugin.getManager().warps().setWarpPosition(warp, warp);
|
||||
} catch (ValidationException e) {
|
||||
e.dispatchWarpError(executor, plugin, warp.getName());
|
||||
return;
|
||||
|
||||
@@ -114,15 +114,15 @@ public abstract class Node implements Executable {
|
||||
return Optional.of(plugin.getWorlds().stream()
|
||||
.filter(world -> world.getName().equalsIgnoreCase(worldName))
|
||||
.findFirst()
|
||||
.orElse(new World(worldName, new UUID(0, 0), environment)));
|
||||
.orElse(World.from(worldName, new UUID(0, 0), environment)));
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
protected Optional<String> parseGreedyString(@NotNull String[] args, int startIndex) {
|
||||
if (args.length > startIndex) {
|
||||
protected Optional<String> parseGreedyArguments(@NotNull String[] args) {
|
||||
if (args.length > 1) {
|
||||
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]);
|
||||
}
|
||||
return Optional.of(sentence.toString().trim());
|
||||
@@ -132,7 +132,7 @@ public abstract class Node implements Executable {
|
||||
|
||||
protected Position getBasePosition(@NotNull CommandUser executor) {
|
||||
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) {
|
||||
@@ -153,7 +153,7 @@ public abstract class Node implements Executable {
|
||||
final Optional<Float> yaw = parseFloatArg(args, startIndex + angleStartIndex);
|
||||
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()),
|
||||
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()));
|
||||
final Instant currentTime = Instant.now();
|
||||
if (executor.equals(teleporter) && !currentTime.isAfter(user.getRtpCooldown()) &&
|
||||
!executor.hasPermission(getPermission("bypass_cooldown"))) {
|
||||
!executor.hasPermission(getPermission("bypass_cooldown"))) {
|
||||
plugin.getLocales().getLocale("error_rtp_cooldown",
|
||||
Long.toString(currentTime.until(user.getRtpCooldown(), ChronoUnit.MINUTES) + 1))
|
||||
.ifPresent(executor::sendMessage);
|
||||
return;
|
||||
}
|
||||
|
||||
// Generate a random position
|
||||
plugin.getLocales().getLocale("teleporting_random_generation")
|
||||
.ifPresent(teleporter::sendMessage);
|
||||
final Optional<Position> position = plugin.getRandomTeleportEngine()
|
||||
|
||||
@@ -14,8 +14,8 @@ import java.util.stream.Collectors;
|
||||
|
||||
public class TpCommand extends Command implements TabProvider {
|
||||
|
||||
protected TpCommand(@NotNull HuskHomes implementor) {
|
||||
super("tp", List.of("tpo"), "[<player|position>] [target]", implementor);
|
||||
protected TpCommand(@NotNull HuskHomes plugin) {
|
||||
super("tp", List.of("tpo"), "[<player|position>] [target]", plugin);
|
||||
setOperatorCommand(true);
|
||||
}
|
||||
|
||||
|
||||
@@ -172,4 +172,14 @@ public class Locales {
|
||||
.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.YamlKey;
|
||||
@@ -100,7 +100,7 @@ public class Settings {
|
||||
private int maxPublicHomes = 10;
|
||||
|
||||
@YamlKey("general.stack_permission_limits")
|
||||
private boolean stackPermissionLimits = true;
|
||||
private boolean stackPermissionLimits = false;
|
||||
|
||||
@YamlKey("general.permission_restrict_warps")
|
||||
private boolean permissionRestrictWarps = false;
|
||||
@@ -112,7 +112,7 @@ public class Settings {
|
||||
private int teleportWarmupTime = 5;
|
||||
|
||||
@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")
|
||||
private int teleportRequestExpiryTime = 60;
|
||||
@@ -351,7 +351,7 @@ public class Settings {
|
||||
return teleportWarmupTime;
|
||||
}
|
||||
|
||||
public MessageDisplayType getTeleportWarmupDisplay() {
|
||||
public Locales.DisplaySlot getTeleportWarmupDisplay() {
|
||||
return teleportWarmupDisplay;
|
||||
}
|
||||
|
||||
@@ -503,16 +503,6 @@ public class Settings {
|
||||
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
|
||||
*/
|
||||
|
||||
@@ -37,7 +37,7 @@ public class Spawn {
|
||||
*/
|
||||
@NotNull
|
||||
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;
|
||||
|
||||
import net.william278.huskhomes.HuskHomes;
|
||||
import net.william278.huskhomes.config.Server;
|
||||
import net.william278.huskhomes.position.*;
|
||||
import net.william278.huskhomes.teleport.Teleport;
|
||||
import net.william278.huskhomes.user.OnlineUser;
|
||||
@@ -86,7 +87,7 @@ public abstract class Database {
|
||||
* <b>(Internal use only)</b> - Updates position data
|
||||
*
|
||||
* @param positionId ID of the position to update
|
||||
* @param position the new position
|
||||
* @param position the Position.at
|
||||
* @param connection SQL connection
|
||||
* @throws SQLException if an SQL exception occurs doing this
|
||||
*/
|
||||
|
||||
@@ -302,15 +302,15 @@ public class MySqlDatabase extends Database {
|
||||
|
||||
final ResultSet resultSet = statement.executeQuery();
|
||||
while (resultSet.next()) {
|
||||
userHomes.add(new Home(resultSet.getDouble("x"),
|
||||
userHomes.add(Home.from(resultSet.getDouble("x"),
|
||||
resultSet.getDouble("y"),
|
||||
resultSet.getDouble("z"),
|
||||
resultSet.getFloat("yaw"),
|
||||
resultSet.getFloat("pitch"),
|
||||
new World(resultSet.getString("world_name"),
|
||||
World.from(resultSet.getString("world_name"),
|
||||
UUID.fromString(resultSet.getString("world_uuid"))),
|
||||
resultSet.getString("server_name"),
|
||||
new PositionMeta(resultSet.getString("name"),
|
||||
PositionMeta.from(resultSet.getString("name"),
|
||||
resultSet.getString("description"),
|
||||
resultSet.getTimestamp("timestamp").toInstant(),
|
||||
resultSet.getString("tags")),
|
||||
@@ -338,15 +338,15 @@ public class MySqlDatabase extends Database {
|
||||
|
||||
final ResultSet resultSet = statement.executeQuery();
|
||||
while (resultSet.next()) {
|
||||
warps.add(new Warp(resultSet.getDouble("x"),
|
||||
warps.add(Warp.from(resultSet.getDouble("x"),
|
||||
resultSet.getDouble("y"),
|
||||
resultSet.getDouble("z"),
|
||||
resultSet.getFloat("yaw"),
|
||||
resultSet.getFloat("pitch"),
|
||||
new World(resultSet.getString("world_name"),
|
||||
World.from(resultSet.getString("world_name"),
|
||||
UUID.fromString(resultSet.getString("world_uuid"))),
|
||||
resultSet.getString("server_name"),
|
||||
new PositionMeta(resultSet.getString("name"),
|
||||
PositionMeta.from(resultSet.getString("name"),
|
||||
resultSet.getString("description"),
|
||||
resultSet.getTimestamp("timestamp").toInstant(),
|
||||
resultSet.getString("tags")),
|
||||
@@ -374,15 +374,15 @@ public class MySqlDatabase extends Database {
|
||||
|
||||
final ResultSet resultSet = statement.executeQuery();
|
||||
while (resultSet.next()) {
|
||||
userHomes.add(new Home(resultSet.getDouble("x"),
|
||||
userHomes.add(Home.from(resultSet.getDouble("x"),
|
||||
resultSet.getDouble("y"),
|
||||
resultSet.getDouble("z"),
|
||||
resultSet.getFloat("yaw"),
|
||||
resultSet.getFloat("pitch"),
|
||||
new World(resultSet.getString("world_name"),
|
||||
World.from(resultSet.getString("world_name"),
|
||||
UUID.fromString(resultSet.getString("world_uuid"))),
|
||||
resultSet.getString("server_name"),
|
||||
new PositionMeta(resultSet.getString("name"),
|
||||
PositionMeta.from(resultSet.getString("name"),
|
||||
resultSet.getString("description"),
|
||||
resultSet.getTimestamp("timestamp").toInstant(),
|
||||
resultSet.getString("tags")),
|
||||
@@ -414,15 +414,15 @@ public class MySqlDatabase extends Database {
|
||||
|
||||
final ResultSet resultSet = statement.executeQuery();
|
||||
if (resultSet.next()) {
|
||||
return Optional.of(new Home(resultSet.getDouble("x"),
|
||||
return Optional.of(Home.from(resultSet.getDouble("x"),
|
||||
resultSet.getDouble("y"),
|
||||
resultSet.getDouble("z"),
|
||||
resultSet.getFloat("yaw"),
|
||||
resultSet.getFloat("pitch"),
|
||||
new World(resultSet.getString("world_name"),
|
||||
World.from(resultSet.getString("world_name"),
|
||||
UUID.fromString(resultSet.getString("world_uuid"))),
|
||||
resultSet.getString("server_name"),
|
||||
new PositionMeta(resultSet.getString("name"),
|
||||
PositionMeta.from(resultSet.getString("name"),
|
||||
resultSet.getString("description"),
|
||||
resultSet.getTimestamp("timestamp").toInstant(),
|
||||
resultSet.getString("tags")),
|
||||
@@ -451,15 +451,15 @@ public class MySqlDatabase extends Database {
|
||||
|
||||
final ResultSet resultSet = statement.executeQuery();
|
||||
if (resultSet.next()) {
|
||||
return Optional.of(new Home(resultSet.getDouble("x"),
|
||||
return Optional.of(Home.from(resultSet.getDouble("x"),
|
||||
resultSet.getDouble("y"),
|
||||
resultSet.getDouble("z"),
|
||||
resultSet.getFloat("yaw"),
|
||||
resultSet.getFloat("pitch"),
|
||||
new World(resultSet.getString("world_name"),
|
||||
World.from(resultSet.getString("world_name"),
|
||||
UUID.fromString(resultSet.getString("world_uuid"))),
|
||||
resultSet.getString("server_name"),
|
||||
new PositionMeta(resultSet.getString("name"),
|
||||
PositionMeta.from(resultSet.getString("name"),
|
||||
resultSet.getString("description"),
|
||||
resultSet.getTimestamp("timestamp").toInstant(),
|
||||
resultSet.getString("tags")),
|
||||
@@ -488,15 +488,15 @@ public class MySqlDatabase extends Database {
|
||||
|
||||
final ResultSet resultSet = statement.executeQuery();
|
||||
if (resultSet.next()) {
|
||||
return Optional.of(new Warp(resultSet.getDouble("x"),
|
||||
return Optional.of(Warp.from(resultSet.getDouble("x"),
|
||||
resultSet.getDouble("y"),
|
||||
resultSet.getDouble("z"),
|
||||
resultSet.getFloat("yaw"),
|
||||
resultSet.getFloat("pitch"),
|
||||
new World(resultSet.getString("world_name"),
|
||||
World.from(resultSet.getString("world_name"),
|
||||
UUID.fromString(resultSet.getString("world_uuid"))),
|
||||
resultSet.getString("server_name"),
|
||||
new PositionMeta(resultSet.getString("name"),
|
||||
PositionMeta.from(resultSet.getString("name"),
|
||||
resultSet.getString("description"),
|
||||
resultSet.getTimestamp("timestamp").toInstant(),
|
||||
resultSet.getString("tags")),
|
||||
@@ -522,15 +522,15 @@ public class MySqlDatabase extends Database {
|
||||
|
||||
final ResultSet resultSet = statement.executeQuery();
|
||||
if (resultSet.next()) {
|
||||
return Optional.of(new Warp(resultSet.getDouble("x"),
|
||||
return Optional.of(Warp.from(resultSet.getDouble("x"),
|
||||
resultSet.getDouble("y"),
|
||||
resultSet.getDouble("z"),
|
||||
resultSet.getFloat("yaw"),
|
||||
resultSet.getFloat("pitch"),
|
||||
new World(resultSet.getString("world_name"),
|
||||
World.from(resultSet.getString("world_name"),
|
||||
UUID.fromString(resultSet.getString("world_uuid"))),
|
||||
resultSet.getString("server_name"),
|
||||
new PositionMeta(resultSet.getString("name"),
|
||||
PositionMeta.from(resultSet.getString("name"),
|
||||
resultSet.getString("description"),
|
||||
resultSet.getTimestamp("timestamp").toInstant(),
|
||||
resultSet.getString("tags")),
|
||||
@@ -557,12 +557,12 @@ public class MySqlDatabase extends Database {
|
||||
if (resultSet.next()) {
|
||||
return Optional.of(Teleport.builder(plugin)
|
||||
.teleporter(onlineUser)
|
||||
.target(new Position(resultSet.getDouble("x"),
|
||||
.target(Position.at(resultSet.getDouble("x"),
|
||||
resultSet.getDouble("y"),
|
||||
resultSet.getDouble("z"),
|
||||
resultSet.getFloat("yaw"),
|
||||
resultSet.getFloat("pitch"),
|
||||
new World(resultSet.getString("world_name"),
|
||||
World.from(resultSet.getString("world_name"),
|
||||
UUID.fromString(resultSet.getString("world_uuid"))),
|
||||
resultSet.getString("server_name")))
|
||||
.type(Teleport.Type.getTeleportType(resultSet.getInt("type"))
|
||||
@@ -640,12 +640,12 @@ public class MySqlDatabase extends Database {
|
||||
|
||||
final ResultSet resultSet = statement.executeQuery();
|
||||
if (resultSet.next()) {
|
||||
return Optional.of(new Position(resultSet.getDouble("x"),
|
||||
return Optional.of(Position.at(resultSet.getDouble("x"),
|
||||
resultSet.getDouble("y"),
|
||||
resultSet.getDouble("z"),
|
||||
resultSet.getFloat("yaw"),
|
||||
resultSet.getFloat("pitch"),
|
||||
new World(resultSet.getString("world_name"),
|
||||
World.from(resultSet.getString("world_name"),
|
||||
UUID.fromString(resultSet.getString("world_uuid"))),
|
||||
resultSet.getString("server_name")));
|
||||
}
|
||||
@@ -699,12 +699,12 @@ public class MySqlDatabase extends Database {
|
||||
|
||||
final ResultSet resultSet = statement.executeQuery();
|
||||
if (resultSet.next()) {
|
||||
return Optional.of(new Position(resultSet.getDouble("x"),
|
||||
return Optional.of(Position.at(resultSet.getDouble("x"),
|
||||
resultSet.getDouble("y"),
|
||||
resultSet.getDouble("z"),
|
||||
resultSet.getFloat("yaw"),
|
||||
resultSet.getFloat("pitch"),
|
||||
new World(resultSet.getString("world_name"),
|
||||
World.from(resultSet.getString("world_name"),
|
||||
UUID.fromString(resultSet.getString("world_uuid"))),
|
||||
resultSet.getString("server_name")));
|
||||
}
|
||||
@@ -757,12 +757,12 @@ public class MySqlDatabase extends Database {
|
||||
|
||||
final ResultSet resultSet = statement.executeQuery();
|
||||
if (resultSet.next()) {
|
||||
return Optional.of(new Position(resultSet.getDouble("x"),
|
||||
return Optional.of(Position.at(resultSet.getDouble("x"),
|
||||
resultSet.getDouble("y"),
|
||||
resultSet.getDouble("z"),
|
||||
resultSet.getFloat("yaw"),
|
||||
resultSet.getFloat("pitch"),
|
||||
new World(resultSet.getString("world_name"),
|
||||
World.from(resultSet.getString("world_name"),
|
||||
UUID.fromString(resultSet.getString("world_uuid"))),
|
||||
resultSet.getString("server_name")));
|
||||
}
|
||||
|
||||
@@ -38,9 +38,9 @@ public class SqLiteDatabase extends Database {
|
||||
private Connection connection;
|
||||
|
||||
|
||||
public SqLiteDatabase(@NotNull HuskHomes implementor) {
|
||||
super(implementor);
|
||||
this.databaseFile = new File(implementor.getDataFolder(), DATABASE_FILE_NAME);
|
||||
public SqLiteDatabase(@NotNull HuskHomes plugin) {
|
||||
super(plugin);
|
||||
this.databaseFile = new File(plugin.getDataFolder(), DATABASE_FILE_NAME);
|
||||
}
|
||||
|
||||
private Connection getConnection() throws SQLException {
|
||||
@@ -310,15 +310,15 @@ public class SqLiteDatabase extends Database {
|
||||
|
||||
final ResultSet resultSet = statement.executeQuery();
|
||||
while (resultSet.next()) {
|
||||
userHomes.add(new Home(resultSet.getDouble("x"),
|
||||
userHomes.add(Home.from(resultSet.getDouble("x"),
|
||||
resultSet.getDouble("y"),
|
||||
resultSet.getDouble("z"),
|
||||
resultSet.getFloat("yaw"),
|
||||
resultSet.getFloat("pitch"),
|
||||
new World(resultSet.getString("world_name"),
|
||||
World.from(resultSet.getString("world_name"),
|
||||
UUID.fromString(resultSet.getString("world_uuid"))),
|
||||
resultSet.getString("server_name"),
|
||||
new PositionMeta(resultSet.getString("name"),
|
||||
PositionMeta.from(resultSet.getString("name"),
|
||||
resultSet.getString("description"),
|
||||
resultSet.getTimestamp("timestamp").toInstant(),
|
||||
resultSet.getString("tags")),
|
||||
@@ -346,15 +346,15 @@ public class SqLiteDatabase extends Database {
|
||||
|
||||
final ResultSet resultSet = statement.executeQuery();
|
||||
while (resultSet.next()) {
|
||||
warps.add(new Warp(resultSet.getDouble("x"),
|
||||
warps.add(Warp.from(resultSet.getDouble("x"),
|
||||
resultSet.getDouble("y"),
|
||||
resultSet.getDouble("z"),
|
||||
resultSet.getFloat("yaw"),
|
||||
resultSet.getFloat("pitch"),
|
||||
new World(resultSet.getString("world_name"),
|
||||
World.from(resultSet.getString("world_name"),
|
||||
UUID.fromString(resultSet.getString("world_uuid"))),
|
||||
resultSet.getString("server_name"),
|
||||
new PositionMeta(resultSet.getString("name"),
|
||||
PositionMeta.from(resultSet.getString("name"),
|
||||
resultSet.getString("description"),
|
||||
resultSet.getTimestamp("timestamp").toInstant(),
|
||||
resultSet.getString("tags")),
|
||||
@@ -382,15 +382,15 @@ public class SqLiteDatabase extends Database {
|
||||
|
||||
final ResultSet resultSet = statement.executeQuery();
|
||||
while (resultSet.next()) {
|
||||
userHomes.add(new Home(resultSet.getDouble("x"),
|
||||
userHomes.add(Home.from(resultSet.getDouble("x"),
|
||||
resultSet.getDouble("y"),
|
||||
resultSet.getDouble("z"),
|
||||
resultSet.getFloat("yaw"),
|
||||
resultSet.getFloat("pitch"),
|
||||
new World(resultSet.getString("world_name"),
|
||||
World.from(resultSet.getString("world_name"),
|
||||
UUID.fromString(resultSet.getString("world_uuid"))),
|
||||
resultSet.getString("server_name"),
|
||||
new PositionMeta(resultSet.getString("name"),
|
||||
PositionMeta.from(resultSet.getString("name"),
|
||||
resultSet.getString("description"),
|
||||
resultSet.getTimestamp("timestamp").toInstant(),
|
||||
resultSet.getString("tags")),
|
||||
@@ -422,15 +422,15 @@ public class SqLiteDatabase extends Database {
|
||||
|
||||
final ResultSet resultSet = statement.executeQuery();
|
||||
if (resultSet.next()) {
|
||||
return Optional.of(new Home(resultSet.getDouble("x"),
|
||||
return Optional.of(Home.from(resultSet.getDouble("x"),
|
||||
resultSet.getDouble("y"),
|
||||
resultSet.getDouble("z"),
|
||||
resultSet.getFloat("yaw"),
|
||||
resultSet.getFloat("pitch"),
|
||||
new World(resultSet.getString("world_name"),
|
||||
World.from(resultSet.getString("world_name"),
|
||||
UUID.fromString(resultSet.getString("world_uuid"))),
|
||||
resultSet.getString("server_name"),
|
||||
new PositionMeta(resultSet.getString("name"),
|
||||
PositionMeta.from(resultSet.getString("name"),
|
||||
resultSet.getString("description"),
|
||||
resultSet.getTimestamp("timestamp").toInstant(),
|
||||
resultSet.getString("tags")),
|
||||
@@ -459,15 +459,15 @@ public class SqLiteDatabase extends Database {
|
||||
|
||||
final ResultSet resultSet = statement.executeQuery();
|
||||
if (resultSet.next()) {
|
||||
return Optional.of(new Home(resultSet.getDouble("x"),
|
||||
return Optional.of(Home.from(resultSet.getDouble("x"),
|
||||
resultSet.getDouble("y"),
|
||||
resultSet.getDouble("z"),
|
||||
resultSet.getFloat("yaw"),
|
||||
resultSet.getFloat("pitch"),
|
||||
new World(resultSet.getString("world_name"),
|
||||
World.from(resultSet.getString("world_name"),
|
||||
UUID.fromString(resultSet.getString("world_uuid"))),
|
||||
resultSet.getString("server_name"),
|
||||
new PositionMeta(resultSet.getString("name"),
|
||||
PositionMeta.from(resultSet.getString("name"),
|
||||
resultSet.getString("description"),
|
||||
resultSet.getTimestamp("timestamp").toInstant(),
|
||||
resultSet.getString("tags")),
|
||||
@@ -496,15 +496,15 @@ public class SqLiteDatabase extends Database {
|
||||
|
||||
final ResultSet resultSet = statement.executeQuery();
|
||||
if (resultSet.next()) {
|
||||
return Optional.of(new Warp(resultSet.getDouble("x"),
|
||||
return Optional.of(Warp.from(resultSet.getDouble("x"),
|
||||
resultSet.getDouble("y"),
|
||||
resultSet.getDouble("z"),
|
||||
resultSet.getFloat("yaw"),
|
||||
resultSet.getFloat("pitch"),
|
||||
new World(resultSet.getString("world_name"),
|
||||
World.from(resultSet.getString("world_name"),
|
||||
UUID.fromString(resultSet.getString("world_uuid"))),
|
||||
resultSet.getString("server_name"),
|
||||
new PositionMeta(resultSet.getString("name"),
|
||||
PositionMeta.from(resultSet.getString("name"),
|
||||
resultSet.getString("description"),
|
||||
resultSet.getTimestamp("timestamp").toInstant(),
|
||||
resultSet.getString("tags")),
|
||||
@@ -530,15 +530,15 @@ public class SqLiteDatabase extends Database {
|
||||
|
||||
final ResultSet resultSet = statement.executeQuery();
|
||||
if (resultSet.next()) {
|
||||
return Optional.of(new Warp(resultSet.getDouble("x"),
|
||||
return Optional.of(Warp.from(resultSet.getDouble("x"),
|
||||
resultSet.getDouble("y"),
|
||||
resultSet.getDouble("z"),
|
||||
resultSet.getFloat("yaw"),
|
||||
resultSet.getFloat("pitch"),
|
||||
new World(resultSet.getString("world_name"),
|
||||
World.from(resultSet.getString("world_name"),
|
||||
UUID.fromString(resultSet.getString("world_uuid"))),
|
||||
resultSet.getString("server_name"),
|
||||
new PositionMeta(resultSet.getString("name"),
|
||||
PositionMeta.from(resultSet.getString("name"),
|
||||
resultSet.getString("description"),
|
||||
resultSet.getTimestamp("timestamp").toInstant(),
|
||||
resultSet.getString("tags")),
|
||||
@@ -565,12 +565,12 @@ public class SqLiteDatabase extends Database {
|
||||
if (resultSet.next()) {
|
||||
return Optional.of(Teleport.builder(plugin)
|
||||
.teleporter(onlineUser)
|
||||
.target(new Position(resultSet.getDouble("x"),
|
||||
.target(Position.at(resultSet.getDouble("x"),
|
||||
resultSet.getDouble("y"),
|
||||
resultSet.getDouble("z"),
|
||||
resultSet.getFloat("yaw"),
|
||||
resultSet.getFloat("pitch"),
|
||||
new World(resultSet.getString("world_name"),
|
||||
World.from(resultSet.getString("world_name"),
|
||||
UUID.fromString(resultSet.getString("world_uuid"))),
|
||||
resultSet.getString("server_name")))
|
||||
.type(Teleport.Type.getTeleportType(resultSet.getInt("type"))
|
||||
@@ -648,12 +648,12 @@ public class SqLiteDatabase extends Database {
|
||||
|
||||
final ResultSet resultSet = statement.executeQuery();
|
||||
if (resultSet.next()) {
|
||||
return Optional.of(new Position(resultSet.getDouble("x"),
|
||||
return Optional.of(Position.at(resultSet.getDouble("x"),
|
||||
resultSet.getDouble("y"),
|
||||
resultSet.getDouble("z"),
|
||||
resultSet.getFloat("yaw"),
|
||||
resultSet.getFloat("pitch"),
|
||||
new World(resultSet.getString("world_name"),
|
||||
World.from(resultSet.getString("world_name"),
|
||||
UUID.fromString(resultSet.getString("world_uuid"))),
|
||||
resultSet.getString("server_name")));
|
||||
}
|
||||
@@ -705,12 +705,12 @@ public class SqLiteDatabase extends Database {
|
||||
|
||||
final ResultSet resultSet = statement.executeQuery();
|
||||
if (resultSet.next()) {
|
||||
return Optional.of(new Position(resultSet.getDouble("x"),
|
||||
return Optional.of(Position.at(resultSet.getDouble("x"),
|
||||
resultSet.getDouble("y"),
|
||||
resultSet.getDouble("z"),
|
||||
resultSet.getFloat("yaw"),
|
||||
resultSet.getFloat("pitch"),
|
||||
new World(resultSet.getString("world_name"),
|
||||
World.from(resultSet.getString("world_name"),
|
||||
UUID.fromString(resultSet.getString("world_uuid"))),
|
||||
resultSet.getString("server_name")));
|
||||
}
|
||||
@@ -760,12 +760,12 @@ public class SqLiteDatabase extends Database {
|
||||
|
||||
final ResultSet resultSet = statement.executeQuery();
|
||||
if (resultSet.next()) {
|
||||
return Optional.of(new Position(resultSet.getDouble("x"),
|
||||
return Optional.of(Position.at(resultSet.getDouble("x"),
|
||||
resultSet.getDouble("y"),
|
||||
resultSet.getDouble("z"),
|
||||
resultSet.getFloat("yaw"),
|
||||
resultSet.getFloat("pitch"),
|
||||
new World(resultSet.getString("world_name"),
|
||||
World.from(resultSet.getString("world_name"),
|
||||
UUID.fromString(resultSet.getString("world_uuid"))),
|
||||
resultSet.getString("server_name")));
|
||||
}
|
||||
|
||||
@@ -9,8 +9,8 @@ import org.jetbrains.annotations.NotNull;
|
||||
*/
|
||||
public abstract class EconomyHook extends Hook {
|
||||
|
||||
protected EconomyHook(@NotNull HuskHomes implementor, @NotNull String hookName) {
|
||||
super(implementor, hookName);
|
||||
protected EconomyHook(@NotNull HuskHomes plugin, @NotNull String hookName) {
|
||||
super(plugin, hookName);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -22,8 +22,8 @@ public class EventListener {
|
||||
@NotNull
|
||||
protected final HuskHomes plugin;
|
||||
|
||||
protected EventListener(@NotNull HuskHomes implementor) {
|
||||
this.plugin = implementor;
|
||||
protected EventListener(@NotNull HuskHomes plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -89,11 +89,18 @@ public class EventListener {
|
||||
if (teleport.getType() == Teleport.Type.RESPAWN) {
|
||||
final Optional<Position> bedPosition = teleporter.getBedSpawnPosition();
|
||||
if (bedPosition.isEmpty()) {
|
||||
plugin.getLocalCachedSpawn()
|
||||
.map(spawn -> spawn.getPosition(plugin.getServerName()))
|
||||
.ifPresent(position -> teleporter.teleportLocally(position,
|
||||
plugin.getSettings().isAsynchronousTeleports()));
|
||||
teleporter.sendTranslatableMessage("block.minecraft.spawn.not_valid");
|
||||
plugin.getSpawn().ifPresent(spawn -> {
|
||||
if (plugin.getSettings().isCrossServer() && !spawn.getServer().equals(plugin.getServerName())) {
|
||||
plugin.runLater(() -> Teleport.builder(plugin)
|
||||
.teleporter(teleporter)
|
||||
.target(spawn)
|
||||
.updateLastPosition(false)
|
||||
.toTeleport().execute(), 40L);
|
||||
} else {
|
||||
teleporter.teleportLocally(spawn, plugin.getSettings().isAsynchronousTeleports());
|
||||
}
|
||||
teleporter.sendTranslatableMessage("block.minecraft.spawn.not_valid");
|
||||
});
|
||||
} else {
|
||||
teleporter.teleportLocally(bedPosition.get(), plugin.getSettings().isAsynchronousTeleports());
|
||||
}
|
||||
@@ -104,8 +111,7 @@ public class EventListener {
|
||||
|
||||
teleporter.teleportLocally((Position) teleport.getTarget(), plugin.getSettings().isAsynchronousTeleports());
|
||||
plugin.getDatabase().setCurrentTeleport(teleporter, null);
|
||||
plugin.getLocales().getLocale("teleporting_complete")
|
||||
.ifPresent(teleporter::sendMessage);
|
||||
teleport.displayTeleportingComplete(teleporter);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -146,7 +152,7 @@ public class EventListener {
|
||||
protected final void handlePlayerDeath(@NotNull OnlineUser onlineUser) {
|
||||
// Set the player's last position to where they died
|
||||
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());
|
||||
}
|
||||
}
|
||||
@@ -160,8 +166,8 @@ public class EventListener {
|
||||
plugin.runAsync(() -> {
|
||||
// Display the return by death via /back notification
|
||||
if (plugin.getSettings().isBackCommandReturnByDeath()
|
||||
&& onlineUser.hasPermission(Permission.COMMAND_BACK.node)
|
||||
&& onlineUser.hasPermission(Permission.COMMAND_BACK_RETURN_BY_DEATH.node)) {
|
||||
&& onlineUser.hasPermission(Permission.COMMAND_BACK.node)
|
||||
&& onlineUser.hasPermission(Permission.COMMAND_BACK_RETURN_BY_DEATH.node)) {
|
||||
plugin.getLocales().getLocale("return_by_death_notification")
|
||||
.ifPresent(onlineUser::sendMessage);
|
||||
}
|
||||
|
||||
@@ -150,7 +150,7 @@ public class HomesManager {
|
||||
existing.update(position);
|
||||
return existing;
|
||||
})
|
||||
.orElse(new Home(position, new PositionMeta(name, ""), owner));
|
||||
.orElse(Home.from(position, PositionMeta.create(name, ""), owner));
|
||||
plugin.getDatabase().saveHome(home);
|
||||
this.cacheHome(home, true);
|
||||
}
|
||||
|
||||
@@ -91,7 +91,7 @@ public class WarpsManager {
|
||||
existing.setPitch(position.getPitch());
|
||||
return existing;
|
||||
})
|
||||
.orElse(new Warp(position, new PositionMeta(name, "")));
|
||||
.orElse(Warp.from(position, PositionMeta.create(name, "")));
|
||||
plugin.getDatabase().saveWarp(warp);
|
||||
this.cacheWarp(warp, true);
|
||||
}
|
||||
@@ -122,16 +122,16 @@ public class WarpsManager {
|
||||
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);
|
||||
if (optionalWarp.isEmpty()) {
|
||||
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);
|
||||
plugin.getDatabase().saveWarp(warp);
|
||||
this.cacheWarp(warp, true);
|
||||
|
||||
@@ -13,19 +13,30 @@ public class Home extends SavedPosition {
|
||||
private final User owner;
|
||||
private boolean isPublic;
|
||||
|
||||
public 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) {
|
||||
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) {
|
||||
super(x, y, z, yaw, pitch, world, server, positionMeta, uuid);
|
||||
this.owner = owner;
|
||||
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);
|
||||
this.owner = owner;
|
||||
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
|
||||
*/
|
||||
|
||||
@@ -1,30 +1,26 @@
|
||||
package net.william278.huskhomes.position;
|
||||
|
||||
import com.google.gson.annotations.Expose;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Represents a local position on this server
|
||||
*/
|
||||
public class Location {
|
||||
|
||||
@Expose
|
||||
private double x;
|
||||
@Expose
|
||||
private double y;
|
||||
@Expose
|
||||
private double z;
|
||||
@Expose
|
||||
private float yaw;
|
||||
@Expose
|
||||
private float pitch;
|
||||
@Expose
|
||||
private World world;
|
||||
|
||||
public Location(double x, double y, double z, @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) {
|
||||
protected Location(double x, double y, double z, float yaw, float pitch, @NotNull World world) {
|
||||
this.setX(x);
|
||||
this.setY(y);
|
||||
this.setZ(z);
|
||||
@@ -36,6 +32,16 @@ public class 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
|
||||
*
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package net.william278.huskhomes.position;
|
||||
|
||||
import com.google.gson.annotations.Expose;
|
||||
import net.william278.huskhomes.teleport.Target;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -8,15 +9,15 @@ import org.jetbrains.annotations.NotNull;
|
||||
*/
|
||||
public class Position extends Location implements Target {
|
||||
|
||||
@Expose
|
||||
private String server;
|
||||
|
||||
public Position(double x, double y, double z, float yaw, float pitch,
|
||||
@NotNull World world, @NotNull String server) {
|
||||
protected Position(double x, double y, double z, float yaw, float pitch, @NotNull World world, @NotNull String server) {
|
||||
super(x, y, z, yaw, pitch, world);
|
||||
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());
|
||||
this.setServer(server);
|
||||
}
|
||||
@@ -25,6 +26,21 @@ public class Position extends Location implements Target {
|
||||
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
|
||||
public void update(@NotNull Position newPosition) {
|
||||
super.update(newPosition);
|
||||
|
||||
@@ -8,7 +8,6 @@ import org.jetbrains.annotations.Nullable;
|
||||
import java.time.Instant;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* Represents metadata about a {@link Position}, used in {@link SavedPosition} implementations
|
||||
@@ -16,24 +15,27 @@ import java.util.Optional;
|
||||
public class PositionMeta {
|
||||
|
||||
private String name;
|
||||
@Nullable
|
||||
private String description;
|
||||
private Map<String, String> tags;
|
||||
private Instant creationTime;
|
||||
|
||||
public PositionMeta(@NotNull String name, @NotNull String description, @NotNull Instant creationTime,
|
||||
@Nullable String serializedTags) {
|
||||
private PositionMeta(@NotNull String name, @NotNull String description,
|
||||
@NotNull Instant creationTime, @Nullable String serializedTags) {
|
||||
this.setName(name);
|
||||
this.setDescription(description);
|
||||
this.setCreationTime(creationTime);
|
||||
this.setTags(deserializeTags(serializedTags));
|
||||
}
|
||||
|
||||
public PositionMeta(@NotNull String name, @NotNull String description) {
|
||||
this.setName(name);
|
||||
this.setDescription(description);
|
||||
this.setCreationTime(Instant.now());
|
||||
this.setTags(new HashMap<>());
|
||||
@NotNull
|
||||
public static PositionMeta from(@NotNull String name, @NotNull String description,
|
||||
@NotNull Instant creationTime, @Nullable String serializedTags) {
|
||||
return new PositionMeta(name, description, creationTime, serializedTags);
|
||||
}
|
||||
|
||||
@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
|
||||
* @return The deserialized {@link Map}
|
||||
*/
|
||||
@NotNull
|
||||
private static Map<String, String> deserializeTags(@Nullable String serializedTags) {
|
||||
try {
|
||||
if (serializedTags == null || serializedTags.isBlank()) {
|
||||
@@ -89,7 +92,7 @@ public class PositionMeta {
|
||||
*/
|
||||
@NotNull
|
||||
public String getDescription() {
|
||||
return Optional.ofNullable(description).orElse("");
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(@Nullable String description) {
|
||||
|
||||
@@ -12,9 +12,8 @@ public abstract class SavedPosition extends Position implements Comparable<Saved
|
||||
private PositionMeta meta;
|
||||
private final UUID uuid;
|
||||
|
||||
protected SavedPosition(double x, double y, double z, float yaw, float pitch,
|
||||
@NotNull World world, @NotNull String server,
|
||||
@NotNull PositionMeta meta, @NotNull UUID uuid) {
|
||||
protected SavedPosition(double x, double y, double z, float yaw, float pitch, @NotNull World world,
|
||||
@NotNull String server, @NotNull PositionMeta meta, @NotNull UUID uuid) {
|
||||
super(x, y, z, yaw, pitch, world, server);
|
||||
this.setMeta(meta);
|
||||
this.uuid = uuid;
|
||||
|
||||
@@ -11,9 +11,8 @@ public class Warp extends SavedPosition {
|
||||
|
||||
private static final String PERMISSION_PREFIX = "huskhomes.command.warp.";
|
||||
|
||||
public Warp(double x, double y, double z, float yaw, float pitch,
|
||||
@NotNull World world, @NotNull String server,
|
||||
@NotNull PositionMeta positionMeta, @NotNull UUID uuid) {
|
||||
private Warp(double x, double y, double z, float yaw, float pitch, @NotNull World world, @NotNull String server,
|
||||
@NotNull PositionMeta positionMeta, @NotNull UUID 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 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);
|
||||
}
|
||||
|
||||
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
|
||||
public static String getPermission(@NotNull String warpName) {
|
||||
return PERMISSION_PREFIX + warpName.toLowerCase();
|
||||
|
||||
@@ -16,12 +16,7 @@ public class World {
|
||||
@Nullable
|
||||
private Environment environment;
|
||||
|
||||
public World(@NotNull String name, @NotNull UUID uuid) {
|
||||
this.setName(name);
|
||||
this.setUuid(uuid);
|
||||
}
|
||||
|
||||
public World(@NotNull String name, @NotNull UUID uuid, @Nullable Environment environment) {
|
||||
private World(@NotNull String name, @NotNull UUID uuid, @Nullable Environment environment) {
|
||||
this.setName(name);
|
||||
this.setUuid(uuid);
|
||||
this.setEnvironment(environment);
|
||||
@@ -31,14 +26,25 @@ public class 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
|
||||
*/
|
||||
@NotNull
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
public void setName(@NotNull String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@@ -50,13 +56,15 @@ public class World {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
public void setUuid(UUID uuid) {
|
||||
public void setUuid(@NotNull UUID uuid) {
|
||||
this.uuid = uuid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Environment of the world ({@link Environment#OVERWORLD}, {@link Environment#NETHER}, {@link Environment#THE_END},
|
||||
* or {@link Environment#CUSTOM})
|
||||
* <p>
|
||||
* Will return {@link Environment#OVERWORLD} if the environment is null
|
||||
*/
|
||||
@NotNull
|
||||
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.
|
||||
*/
|
||||
public class NormalDistributionEngine extends RandomTeleportEngine {
|
||||
public final class NormalDistributionEngine extends RandomTeleportEngine {
|
||||
|
||||
protected final int radius;
|
||||
protected final int spawnRadius;
|
||||
private final int radius;
|
||||
private final int spawnRadius;
|
||||
private final float mean;
|
||||
private final float standardDeviation;
|
||||
|
||||
public NormalDistributionEngine(@NotNull HuskHomes implementor) {
|
||||
super(implementor, "Normal Distribution");
|
||||
this.radius = implementor.getSettings().getRtpRadius();
|
||||
this.spawnRadius = implementor.getSettings().getRtpSpawnRadius();
|
||||
this.mean = implementor.getSettings().getRtpDistributionMean();
|
||||
this.standardDeviation = implementor.getSettings().getRtpDistributionStandardDeviation();
|
||||
public NormalDistributionEngine(@NotNull HuskHomes plugin) {
|
||||
super(plugin, "Normal Distribution");
|
||||
this.radius = plugin.getSettings().getRtpRadius();
|
||||
this.spawnRadius = plugin.getSettings().getRtpSpawnRadius();
|
||||
this.mean = plugin.getSettings().getRtpDistributionMean();
|
||||
this.standardDeviation = plugin.getSettings().getRtpDistributionStandardDeviation();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -36,7 +36,7 @@ public class NormalDistributionEngine extends RandomTeleportEngine {
|
||||
* @return A generated location
|
||||
*/
|
||||
@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) {
|
||||
// Generate random values
|
||||
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 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) {
|
||||
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;
|
||||
while (location.isEmpty()) {
|
||||
location = generateSafeLocation(world).join();
|
||||
if (attempts > randomTimeout) {
|
||||
if (attempts >= maxAttempts) {
|
||||
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 {
|
||||
|
||||
@NotNull
|
||||
protected final HuskHomes plugin;
|
||||
|
||||
/**
|
||||
* The name of the random teleport engine
|
||||
*/
|
||||
@NotNull
|
||||
public final String name;
|
||||
|
||||
/**
|
||||
* How many attempts to allow {@link #getRandomPosition} lookups before timing out
|
||||
*/
|
||||
public long randomTimeout = 8;
|
||||
public long maxAttempts = 12;
|
||||
|
||||
/**
|
||||
* Constructor for a random teleport engine
|
||||
@@ -37,15 +27,21 @@ public abstract class RandomTeleportEngine {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public final String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the origin position (spawn) of this server
|
||||
*
|
||||
* @return The origin position
|
||||
*/
|
||||
protected final Position getOrigin(@NotNull World world) {
|
||||
@NotNull
|
||||
protected Position getCenterPoint(@NotNull World world) {
|
||||
return plugin.getLocalCachedSpawn()
|
||||
.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()));
|
||||
}
|
||||
|
||||
@@ -56,7 +52,7 @@ public abstract class RandomTeleportEngine {
|
||||
* @param world The world to find a random position in
|
||||
* @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
|
||||
* {@link #randomTimeout configured number of attempts}
|
||||
* {@link #maxAttempts configured number of attempts}
|
||||
*/
|
||||
public abstract Optional<Position> getRandomPosition(@NotNull World world, @NotNull String[] args);
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package net.william278.huskhomes.teleport;
|
||||
|
||||
import net.william278.huskhomes.HuskHomes;
|
||||
import net.william278.huskhomes.config.Settings;
|
||||
import net.william278.huskhomes.event.ITeleportEvent;
|
||||
import net.william278.huskhomes.hook.EconomyHook;
|
||||
import net.william278.huskhomes.network.Message;
|
||||
@@ -85,8 +86,7 @@ public class Teleport {
|
||||
fireEvent((event) -> {
|
||||
executeEconomyActions();
|
||||
teleporter.teleportLocally(localTarget.get().getPosition(), async);
|
||||
plugin.getLocales().getLocale("teleporting_complete")
|
||||
.ifPresent(teleporter::sendMessage);
|
||||
this.displayTeleportingComplete(teleporter);
|
||||
});
|
||||
return;
|
||||
}
|
||||
@@ -98,8 +98,7 @@ public class Teleport {
|
||||
.type(Message.Type.TELEPORT_TO_NETWORKED_POSITION)
|
||||
.target(username.name())
|
||||
.build().send(plugin.getMessenger(), executor);
|
||||
plugin.getLocales().getLocale("teleporting_complete")
|
||||
.ifPresent(teleporter::sendMessage);
|
||||
this.displayTeleportingComplete(teleporter);
|
||||
});
|
||||
return;
|
||||
}
|
||||
@@ -113,8 +112,7 @@ public class Teleport {
|
||||
final Position target = (Position) this.target;
|
||||
if (!plugin.getSettings().isCrossServer() || target.getServer().equals(plugin.getServerName())) {
|
||||
teleporter.teleportLocally(target, async);
|
||||
plugin.getLocales().getLocale("teleporting_complete")
|
||||
.ifPresent(teleporter::sendMessage);
|
||||
this.displayTeleportingComplete(teleporter);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -131,6 +129,13 @@ public class Teleport {
|
||||
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
|
||||
private void fireEvent(@NotNull Consumer<ITeleportEvent> afterFired) {
|
||||
plugin.fireEvent(plugin.getTeleportEvent(this), afterFired);
|
||||
|
||||
@@ -132,12 +132,7 @@ public class TimedTeleport extends Teleport {
|
||||
}
|
||||
|
||||
private void sendStatusMessage(@NotNull MineDown message) {
|
||||
switch (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);
|
||||
}
|
||||
teleporter.sendMessage(message, plugin.getSettings().getTeleportWarmupDisplay());
|
||||
}
|
||||
|
||||
private boolean hasTeleporterMoved() {
|
||||
|
||||
@@ -8,6 +8,7 @@ import net.kyori.adventure.key.Key;
|
||||
import net.kyori.adventure.sound.Sound;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.title.TitlePart;
|
||||
import net.william278.huskhomes.config.Locales;
|
||||
import net.william278.huskhomes.position.Location;
|
||||
import net.william278.huskhomes.position.Position;
|
||||
import net.william278.huskhomes.teleport.Teleportable;
|
||||
@@ -98,6 +99,24 @@ public abstract class OnlineUser extends User implements Teleportable, CommandUs
|
||||
.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
|
||||
*
|
||||
@@ -144,6 +163,7 @@ public abstract class OnlineUser extends User implements Teleportable, CommandUs
|
||||
|
||||
/**
|
||||
* Send a plugin message to the user
|
||||
*
|
||||
* @param channel channel to send it on
|
||||
* @param message byte array of message data
|
||||
*/
|
||||
|
||||
Reference in new issue
Block a user