mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-02 06:28:49 +00:00
Merge branch 'master' into it-it-fix
This commit is contained in:
commit
824ada0bc5
15 files changed
+151
-60
No files matched your search
@@ -167,7 +167,7 @@ public class BukkitHuskHomes extends JavaPlugin implements HuskHomes {
|
||||
|
||||
// Prepare the home and warp position manager
|
||||
this.savedPositionManager = new SavedPositionManager(database, cache, eventDispatcher,
|
||||
settings.allowUnicodeNames, settings.allowUnicodeDescriptions);
|
||||
settings.allowUnicodeNames, settings.allowUnicodeDescriptions, settings.overwriteExistingHomesWarps);
|
||||
|
||||
// Initialize the RTP engine with the default normal distribution engine
|
||||
setRandomTeleportEngine(new NormalDistributionEngine(this));
|
||||
|
||||
@@ -3,8 +3,8 @@ package net.william278.huskhomes.messenger;
|
||||
import com.google.common.io.ByteArrayDataInput;
|
||||
import com.google.common.io.ByteArrayDataOutput;
|
||||
import com.google.common.io.ByteStreams;
|
||||
import net.william278.huskhomes.HuskHomes;
|
||||
import net.william278.huskhomes.BukkitHuskHomes;
|
||||
import net.william278.huskhomes.HuskHomes;
|
||||
import net.william278.huskhomes.player.BukkitPlayer;
|
||||
import net.william278.huskhomes.player.OnlineUser;
|
||||
import net.william278.huskhomes.position.Server;
|
||||
@@ -13,6 +13,8 @@ import org.bukkit.plugin.messaging.PluginMessageListener;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.Arrays;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.logging.Level;
|
||||
|
||||
@@ -55,7 +57,8 @@ public class PluginMessenger extends NetworkMessenger implements PluginMessageLi
|
||||
@SuppressWarnings("UnstableApiUsage")
|
||||
public CompletableFuture<String[]> getOnlinePlayerNames(@NotNull OnlineUser requester) {
|
||||
final BukkitHuskHomes plugin = (BukkitHuskHomes) this.plugin;
|
||||
onlinePlayerNamesRequest = new CompletableFuture<>();
|
||||
final CompletableFuture<String[]> future = new CompletableFuture<>();
|
||||
onlinePlayerNamesRequests.add(future);
|
||||
Bukkit.getScheduler().runTaskLater(plugin, () -> {
|
||||
final ByteArrayDataOutput pluginMessageWriter = ByteStreams.newDataOutput();
|
||||
pluginMessageWriter.writeUTF("PlayerList");
|
||||
@@ -63,35 +66,39 @@ public class PluginMessenger extends NetworkMessenger implements PluginMessageLi
|
||||
((BukkitPlayer) requester).sendPluginMessage(plugin,
|
||||
BUNGEE_PLUGIN_CHANNEL_NAME, pluginMessageWriter.toByteArray());
|
||||
}, PLUGIN_MESSAGE_DELAY_TICKS);
|
||||
return onlinePlayerNamesRequest;
|
||||
return future;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("UnstableApiUsage")
|
||||
public CompletableFuture<String> getServerName(@NotNull OnlineUser requester) {
|
||||
final BukkitHuskHomes plugin = (BukkitHuskHomes) this.plugin;
|
||||
serverNameRequest = new CompletableFuture<>();
|
||||
final CompletableFuture<String> future = new CompletableFuture<>();
|
||||
serverNameRequests.add(future);
|
||||
Bukkit.getScheduler().runTaskLater(plugin, () -> {
|
||||
final ByteArrayDataOutput pluginMessageWriter = ByteStreams.newDataOutput();
|
||||
pluginMessageWriter.writeUTF("GetServer");
|
||||
((BukkitPlayer) requester).sendPluginMessage(plugin,
|
||||
BUNGEE_PLUGIN_CHANNEL_NAME, pluginMessageWriter.toByteArray());
|
||||
BUNGEE_PLUGIN_CHANNEL_NAME,
|
||||
pluginMessageWriter.toByteArray());
|
||||
}, PLUGIN_MESSAGE_DELAY_TICKS);
|
||||
return serverNameRequest;
|
||||
return future;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("UnstableApiUsage")
|
||||
public CompletableFuture<String[]> getOnlineServers(@NotNull OnlineUser requester) {
|
||||
final BukkitHuskHomes plugin = (BukkitHuskHomes) this.plugin;
|
||||
onlineServersRequest = new CompletableFuture<>();
|
||||
final CompletableFuture<String[]> future = new CompletableFuture<>();
|
||||
onlineServersRequests.add(future);
|
||||
Bukkit.getScheduler().runTaskLater(plugin, () -> {
|
||||
final ByteArrayDataOutput pluginMessageWriter = ByteStreams.newDataOutput();
|
||||
pluginMessageWriter.writeUTF("GetServers");
|
||||
((BukkitPlayer) requester).sendPluginMessage(plugin,
|
||||
BUNGEE_PLUGIN_CHANNEL_NAME, pluginMessageWriter.toByteArray());
|
||||
BUNGEE_PLUGIN_CHANNEL_NAME,
|
||||
pluginMessageWriter.toByteArray());
|
||||
}, PLUGIN_MESSAGE_DELAY_TICKS);
|
||||
return onlineServersRequest;
|
||||
return future;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -99,17 +106,20 @@ public class PluginMessenger extends NetworkMessenger implements PluginMessageLi
|
||||
public CompletableFuture<Boolean> sendPlayer(@NotNull OnlineUser onlineUser, @NotNull Server server) {
|
||||
final BukkitHuskHomes plugin = (BukkitHuskHomes) this.plugin;
|
||||
return getOnlineServers(onlineUser).thenApplyAsync(onlineServers -> {
|
||||
for (String onlineServerName : onlineServers) {
|
||||
if (onlineServerName.equals(server.name)) {
|
||||
Bukkit.getScheduler().runTask(plugin, () -> {
|
||||
final ByteArrayDataOutput pluginMessageWriter = ByteStreams.newDataOutput();
|
||||
pluginMessageWriter.writeUTF("Connect");
|
||||
pluginMessageWriter.writeUTF(server.name);
|
||||
((BukkitPlayer) onlineUser).sendPluginMessage(plugin,
|
||||
BUNGEE_PLUGIN_CHANNEL_NAME, pluginMessageWriter.toByteArray());
|
||||
});
|
||||
return true;
|
||||
}
|
||||
final Optional<String> targetServer = Arrays.stream(onlineServers)
|
||||
.filter(serverName -> serverName.equals(server.name))
|
||||
.findFirst();
|
||||
|
||||
if (targetServer.isPresent()) {
|
||||
Bukkit.getScheduler().runTask(plugin, () -> {
|
||||
final ByteArrayDataOutput pluginMessageWriter = ByteStreams.newDataOutput();
|
||||
pluginMessageWriter.writeUTF("Connect");
|
||||
pluginMessageWriter.writeUTF(server.name);
|
||||
((BukkitPlayer) onlineUser).sendPluginMessage(plugin,
|
||||
BUNGEE_PLUGIN_CHANNEL_NAME,
|
||||
pluginMessageWriter.toByteArray());
|
||||
});
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
@@ -138,19 +148,20 @@ public class PluginMessenger extends NetworkMessenger implements PluginMessageLi
|
||||
messageWriter.writeUTF(NETWORK_MESSAGE_CHANNEL);
|
||||
|
||||
// Write the plugin message
|
||||
try (ByteArrayOutputStream messageByteOutputStream = new ByteArrayOutputStream()) {
|
||||
try (final ByteArrayOutputStream messageByteOutputStream = new ByteArrayOutputStream()) {
|
||||
try (DataOutputStream messageDataOutputStream = new DataOutputStream(messageByteOutputStream)) {
|
||||
messageDataOutputStream.writeUTF(message.toJson());
|
||||
messageWriter.writeShort(messageByteOutputStream.toByteArray().length);
|
||||
messageWriter.write(messageByteOutputStream.toByteArray());
|
||||
}
|
||||
} catch (IOException e) {
|
||||
plugin.getLoggingAdapter().log(Level.SEVERE,
|
||||
"An error occurred dispatching a plugin message", e);
|
||||
plugin.getLoggingAdapter().log(Level.SEVERE, "An error occurred dispatching a plugin message", e);
|
||||
}
|
||||
|
||||
// Send the written message
|
||||
player.sendPluginMessage(plugin, BUNGEE_PLUGIN_CHANNEL_NAME, messageWriter.toByteArray());
|
||||
player.sendPluginMessage(plugin,
|
||||
BUNGEE_PLUGIN_CHANNEL_NAME,
|
||||
messageWriter.toByteArray());
|
||||
}, PLUGIN_MESSAGE_DELAY_TICKS);
|
||||
}
|
||||
|
||||
@@ -192,22 +203,16 @@ public class PluginMessenger extends NetworkMessenger implements PluginMessageLi
|
||||
}
|
||||
case "GetServer" -> {
|
||||
final String serverName = pluginMessage.readUTF();
|
||||
if (serverNameRequest != null) {
|
||||
serverNameRequest.completeAsync(() -> serverName);
|
||||
}
|
||||
serverNameRequests.forEach(future -> future.complete(serverName));
|
||||
}
|
||||
case "PlayerList" -> {
|
||||
pluginMessage.readUTF(); // Read the server name (unused)
|
||||
final String[] playerNames = pluginMessage.readUTF().split(", ");
|
||||
if (onlinePlayerNamesRequest != null) {
|
||||
onlinePlayerNamesRequest.completeAsync(() -> playerNames);
|
||||
}
|
||||
onlinePlayerNamesRequests.forEach(future -> future.complete(playerNames));
|
||||
}
|
||||
case "GetServers" -> {
|
||||
final String[] serverNames = pluginMessage.readUTF().split(", ");
|
||||
if (onlineServersRequest != null) {
|
||||
onlineServersRequest.completeAsync(() -> serverNames);
|
||||
}
|
||||
onlineServersRequests.forEach(future -> future.complete(serverNames));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
dependencies {
|
||||
implementation 'commons-io:commons-io:2.11.0'
|
||||
implementation 'de.themoep:minedown-adventure:1.7.2-SNAPSHOT'
|
||||
implementation 'com.google.code.gson:gson:2.9.1'
|
||||
implementation 'com.google.code.gson:gson:2.10'
|
||||
implementation 'net.william278:Annotaml:2.0'
|
||||
implementation 'net.william278:PagineDown:1.1'
|
||||
implementation 'net.william278:DesertWell:1.1'
|
||||
|
||||
@@ -57,7 +57,7 @@ public class HomeCommand extends CommandBase implements TabCompletable, ConsoleE
|
||||
}
|
||||
|
||||
private void teleportToNamedHome(@NotNull OnlineUser teleporter, @NotNull User owner, @NotNull String homeName) {
|
||||
final boolean otherHome = owner.uuid.equals(teleporter.uuid);
|
||||
final boolean otherHome = !owner.uuid.equals(teleporter.uuid);
|
||||
plugin.getDatabase()
|
||||
.getHome(owner, homeName)
|
||||
.thenAccept(homeResult -> homeResult.ifPresentOrElse(home -> {
|
||||
@@ -65,6 +65,7 @@ public class HomeCommand extends CommandBase implements TabCompletable, ConsoleE
|
||||
if (!teleporter.hasPermission(Permission.COMMAND_HOME_OTHER.node)) {
|
||||
plugin.getLocales().getLocale("error_no_permission")
|
||||
.ifPresent(teleporter::sendMessage);
|
||||
return;
|
||||
}
|
||||
}
|
||||
Teleport.builder(plugin, teleporter)
|
||||
@@ -73,10 +74,10 @@ public class HomeCommand extends CommandBase implements TabCompletable, ConsoleE
|
||||
.thenAccept(TimedTeleport::execute);
|
||||
}, () -> {
|
||||
if (otherHome) {
|
||||
plugin.getLocales().getLocale("error_home_invalid", homeName)
|
||||
plugin.getLocales().getLocale("error_home_invalid_other", owner.username, homeName)
|
||||
.ifPresent(teleporter::sendMessage);
|
||||
} else {
|
||||
plugin.getLocales().getLocale("error_home_invalid_other", owner.username, homeName)
|
||||
plugin.getLocales().getLocale("error_home_invalid", homeName)
|
||||
.ifPresent(teleporter::sendMessage);
|
||||
}
|
||||
}));
|
||||
|
||||
@@ -69,7 +69,7 @@ public class PublicHomeCommand extends CommandBase implements TabCompletable, Co
|
||||
}
|
||||
|
||||
private void teleportToNamedHome(@NotNull OnlineUser teleporter, @NotNull User owner, @NotNull String homeName) {
|
||||
final boolean otherHome = owner.uuid.equals(teleporter.uuid);
|
||||
final boolean otherHome = !owner.uuid.equals(teleporter.uuid);
|
||||
plugin.getDatabase()
|
||||
.getHome(owner, homeName)
|
||||
.thenAccept(homeResult -> homeResult.ifPresentOrElse(home -> {
|
||||
@@ -77,6 +77,7 @@ public class PublicHomeCommand extends CommandBase implements TabCompletable, Co
|
||||
if (!teleporter.hasPermission(Permission.COMMAND_HOME_OTHER.node)) {
|
||||
plugin.getLocales().getLocale("error_no_permission")
|
||||
.ifPresent(teleporter::sendMessage);
|
||||
return;
|
||||
}
|
||||
}
|
||||
Teleport.builder(plugin, teleporter)
|
||||
@@ -85,10 +86,10 @@ public class PublicHomeCommand extends CommandBase implements TabCompletable, Co
|
||||
.thenAccept(TimedTeleport::execute);
|
||||
}, () -> {
|
||||
if (otherHome) {
|
||||
plugin.getLocales().getLocale("error_home_invalid", homeName)
|
||||
plugin.getLocales().getLocale("error_home_invalid_other", owner.username, homeName)
|
||||
.ifPresent(teleporter::sendMessage);
|
||||
} else {
|
||||
plugin.getLocales().getLocale("error_home_invalid_other", owner.username, homeName)
|
||||
plugin.getLocales().getLocale("error_home_invalid", homeName)
|
||||
.ifPresent(teleporter::sendMessage);
|
||||
}
|
||||
}));
|
||||
|
||||
@@ -105,6 +105,11 @@ public class SetHomeCommand extends CommandBase {
|
||||
}
|
||||
yield plugin.getLocales().getLocale("set_home_success", setResult.savedPosition().get().meta.name);
|
||||
}
|
||||
case SUCCESS_OVERWRITTEN -> {
|
||||
assert setResult.savedPosition().isPresent();
|
||||
yield plugin.getLocales().getLocale("edit_home_update_location",
|
||||
setResult.savedPosition().get().meta.name);
|
||||
}
|
||||
case FAILED_DUPLICATE -> plugin.getLocales().getLocale("error_home_name_taken");
|
||||
case FAILED_NAME_LENGTH -> plugin.getLocales().getLocale("error_home_name_length");
|
||||
case FAILED_NAME_CHARACTERS -> plugin.getLocales().getLocale("error_home_name_characters");
|
||||
|
||||
@@ -31,6 +31,11 @@ public class SetWarpCommand extends CommandBase {
|
||||
yield plugin.getLocales().getLocale("set_warp_success",
|
||||
setResult.savedPosition().get().meta.name);
|
||||
}
|
||||
case SUCCESS_OVERWRITTEN -> {
|
||||
assert setResult.savedPosition().isPresent();
|
||||
yield plugin.getLocales().getLocale("edit_warp_update_location",
|
||||
setResult.savedPosition().get().meta.name);
|
||||
}
|
||||
case FAILED_DUPLICATE -> plugin.getLocales().getLocale("error_warp_name_taken");
|
||||
case FAILED_NAME_LENGTH -> plugin.getLocales().getLocale("error_warp_name_length");
|
||||
case FAILED_NAME_CHARACTERS -> plugin.getLocales().getLocale("error_warp_name_characters");
|
||||
|
||||
@@ -39,7 +39,14 @@ public class TpCommand extends CommandBase implements TabCompletable, ConsoleExe
|
||||
|
||||
// Find the online user to teleport
|
||||
plugin.getCache().updatePlayerListCache(plugin, onlineUser).thenRun(() -> {
|
||||
final String playerToTeleport = plugin.getCache().players.stream()
|
||||
// Get the list of potential teleports, filtered against vanished players, but ensuring the executor is in the list
|
||||
final List<String> players = plugin.getCache().players;
|
||||
if (!players.contains(onlineUser.username)) {
|
||||
players.add(onlineUser.username);
|
||||
}
|
||||
|
||||
// Find the player to teleport
|
||||
final String playerToTeleport = players.stream()
|
||||
.filter(user -> user.equalsIgnoreCase(targetPlayerToTeleport)).findFirst()
|
||||
.or(() -> Optional.ofNullable(targetPlayerToTeleport.equals("@s") ? onlineUser.username : null))
|
||||
.or(() -> plugin.getCache().players.stream().filter(user -> user.toLowerCase().startsWith(targetPlayerToTeleport)).findFirst())
|
||||
@@ -98,7 +105,7 @@ public class TpCommand extends CommandBase implements TabCompletable, ConsoleExe
|
||||
final Position destination = result.getDestination().get();
|
||||
result.getTeleporter()
|
||||
.flatMap(teleporter -> plugin.getLocales()
|
||||
.getLocale("teleporting_other_complete", teleporter.username,
|
||||
.getLocale("teleporting_other_complete_position", teleporter.username,
|
||||
Integer.toString((int) destination.x),
|
||||
Integer.toString((int) destination.y),
|
||||
Integer.toString((int) destination.z)))
|
||||
|
||||
@@ -6,6 +6,7 @@ import net.william278.huskhomes.position.Warp;
|
||||
import net.william278.huskhomes.teleport.Teleport;
|
||||
import net.william278.huskhomes.teleport.TimedTeleport;
|
||||
import net.william278.huskhomes.util.Permission;
|
||||
import org.intellij.lang.annotations.Subst;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -36,11 +37,20 @@ public class WarpCommand extends CommandBase implements TabCompletable, ConsoleE
|
||||
final String warpName = args[0];
|
||||
plugin.getDatabase()
|
||||
.getWarp(warpName)
|
||||
.thenAccept(warpResult -> warpResult.ifPresentOrElse(warp ->
|
||||
Teleport.builder(plugin, onlineUser)
|
||||
.setTarget(warp)
|
||||
.toTimedTeleport()
|
||||
.thenAccept(TimedTeleport::execute),
|
||||
.thenAccept(warpResult -> warpResult.ifPresentOrElse(warp -> {
|
||||
if (plugin.getSettings().permissionRestrictWarps) {
|
||||
@Subst("huskhomes.command.warp") final String warpPermission = Permission.COMMAND_WARP + "." + warp.meta.name;
|
||||
if (!onlineUser.hasPermission(Permission.COMMAND_SET_WARP.node) && !onlineUser.hasPermission(warpPermission)) {
|
||||
plugin.getLocales().getLocale("error_no_permission")
|
||||
.ifPresent(onlineUser::sendMessage);
|
||||
return;
|
||||
}
|
||||
}
|
||||
Teleport.builder(plugin, onlineUser)
|
||||
.setTarget(warp)
|
||||
.toTimedTeleport()
|
||||
.thenAccept(TimedTeleport::execute);
|
||||
},
|
||||
() -> plugin.getLocales().getLocale("error_warp_invalid", warpName)
|
||||
.ifPresent(onlineUser::sendMessage)));
|
||||
}
|
||||
|
||||
@@ -103,6 +103,9 @@ public class Settings {
|
||||
@YamlKey("general.permission_restrict_warps")
|
||||
public boolean permissionRestrictWarps = false;
|
||||
|
||||
@YamlKey("general.overwrite_existing_homes_warps")
|
||||
public boolean overwriteExistingHomesWarps = true;
|
||||
|
||||
@YamlKey("general.teleport_warmup_time")
|
||||
public int teleportWarmupTime = 5;
|
||||
|
||||
|
||||
@@ -22,19 +22,19 @@ public abstract class NetworkMessenger {
|
||||
protected HashMap<UUID, CompletableFuture<Message>> processingMessages;
|
||||
|
||||
/**
|
||||
* Future for processing {@link #getServerName(OnlineUser)} requests
|
||||
* List of pending futures for processing {@link #getServerName(OnlineUser)} requests
|
||||
*/
|
||||
protected CompletableFuture<String> serverNameRequest;
|
||||
protected List<CompletableFuture<String>> serverNameRequests;
|
||||
|
||||
/**
|
||||
* Future for processing {@link #getOnlinePlayerNames(OnlineUser)} requests
|
||||
* List of pending futures for processing {@link #getOnlinePlayerNames(OnlineUser)} requests
|
||||
*/
|
||||
protected CompletableFuture<String[]> onlinePlayerNamesRequest;
|
||||
protected List<CompletableFuture<String[]>> onlinePlayerNamesRequests;
|
||||
|
||||
/**
|
||||
* Future for processing {@link #getOnlineServers(OnlineUser)} requests
|
||||
* List of pending futures for processing {@link #getOnlineServers(OnlineUser)} requests
|
||||
*/
|
||||
protected CompletableFuture<String[]> onlineServersRequest;
|
||||
protected List<CompletableFuture<String[]>> onlineServersRequests;
|
||||
|
||||
/**
|
||||
* ID of the HuskHomes network cluster this server is on
|
||||
@@ -53,6 +53,9 @@ public abstract class NetworkMessenger {
|
||||
*/
|
||||
public void initialize(@NotNull HuskHomes implementor) {
|
||||
this.processingMessages = new HashMap<>();
|
||||
this.serverNameRequests = new ArrayList<>();
|
||||
this.onlinePlayerNamesRequests = new ArrayList<>();
|
||||
this.onlineServersRequests = new ArrayList<>();
|
||||
this.clusterId = implementor.getSettings().clusterId;
|
||||
this.plugin = implementor;
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import net.william278.huskhomes.event.EventDispatcher;
|
||||
import net.william278.huskhomes.hook.MapHook;
|
||||
import net.william278.huskhomes.player.User;
|
||||
import net.william278.huskhomes.util.RegexUtil;
|
||||
import net.william278.huskhomes.config.Settings;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -14,7 +15,7 @@ import java.util.Optional;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
/**
|
||||
* Cross-platform manager for validating homes and warps and updating them as neccessary
|
||||
* Cross-platform manager for validating homes and warps and updating them as necessary
|
||||
*/
|
||||
public class SavedPositionManager {
|
||||
|
||||
@@ -49,13 +50,20 @@ public class SavedPositionManager {
|
||||
*/
|
||||
private final boolean allowUnicodeDescriptions;
|
||||
|
||||
/**
|
||||
* Whether to automatically relocate existing homes and warps when a user tries to set a home/warp with the same name
|
||||
*/
|
||||
private final boolean overwriteExistingHomesWarps;
|
||||
|
||||
public SavedPositionManager(@NotNull Database database, @NotNull Cache cache, @NotNull EventDispatcher eventDispatcher,
|
||||
boolean allowUnicodeNames, boolean allowUnicodeDescriptions) {
|
||||
boolean allowUnicodeNames, boolean allowUnicodeDescriptions,
|
||||
boolean overwriteExistingHomesWarps) {
|
||||
this.database = database;
|
||||
this.cache = cache;
|
||||
this.eventDispatcher = eventDispatcher;
|
||||
this.allowUnicodeNames = allowUnicodeNames;
|
||||
this.allowUnicodeDescriptions = allowUnicodeDescriptions;
|
||||
this.overwriteExistingHomesWarps = overwriteExistingHomesWarps;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -81,6 +89,7 @@ public class SavedPositionManager {
|
||||
return database.getHome(homeOwner, homeMeta.name).thenApplyAsync(optionalHome ->
|
||||
validateMeta(homeMeta).map(resultType -> new SaveResult(resultType, Optional.empty())).orElseGet(() -> {
|
||||
if (optionalHome.isEmpty()) {
|
||||
// Handle setting a new home
|
||||
final Home home = new Home(position, homeMeta, homeOwner);
|
||||
return eventDispatcher.dispatchHomeSaveEvent(home).thenApplyAsync(event -> {
|
||||
if (event.isCancelled()) {
|
||||
@@ -92,6 +101,18 @@ public class SavedPositionManager {
|
||||
return database.saveHome(home).thenApplyAsync(value ->
|
||||
new SaveResult(SaveResult.ResultType.SUCCESS, Optional.of(home))).join();
|
||||
}).join();
|
||||
} else if (overwriteExistingHomesWarps) {
|
||||
// Handle overwriting existing homes if the option is enabled
|
||||
final Home existingHome = optionalHome.get();
|
||||
updateHomePosition(existingHome, position).thenApplyAsync(result -> {
|
||||
if (result) {
|
||||
if (mapHook != null && existingHome.isPublic) {
|
||||
mapHook.updateHome(existingHome);
|
||||
}
|
||||
return new SaveResult(SaveResult.ResultType.SUCCESS_OVERWRITTEN, Optional.of(existingHome));
|
||||
}
|
||||
return new SaveResult(SaveResult.ResultType.FAILED_EVENT_CANCELLED, Optional.empty());
|
||||
}).join();
|
||||
}
|
||||
return new SaveResult(SaveResult.ResultType.FAILED_DUPLICATE, Optional.empty());
|
||||
}));
|
||||
@@ -202,6 +223,7 @@ public class SavedPositionManager {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Save the home to database and propagate updates to cache and map hook
|
||||
return database.saveHome(home).thenApplyAsync(ignored -> {
|
||||
if (home.isPublic) {
|
||||
cache.publicHomes.putIfAbsent(home.owner.username, new ArrayList<>());
|
||||
@@ -236,6 +258,7 @@ public class SavedPositionManager {
|
||||
return database.getWarp(warpMeta.name).thenApplyAsync(optionalWarp ->
|
||||
validateMeta(warpMeta).map(resultType -> new SaveResult(resultType, Optional.empty())).orElseGet(() -> {
|
||||
if (optionalWarp.isEmpty()) {
|
||||
// Handle setting new warps
|
||||
final Warp warp = new Warp(position, warpMeta);
|
||||
return eventDispatcher.dispatchWarpSaveEvent(warp).thenApplyAsync(event -> {
|
||||
if (event.isCancelled()) {
|
||||
@@ -249,6 +272,18 @@ public class SavedPositionManager {
|
||||
return database.saveWarp(warp).thenApplyAsync(ignored ->
|
||||
new SaveResult(SaveResult.ResultType.SUCCESS, Optional.of(warp))).join();
|
||||
}).join();
|
||||
} else if (overwriteExistingHomesWarps) {
|
||||
// Handle overwriting existing warps if the option is enabled
|
||||
final Warp existingWarp = optionalWarp.get();
|
||||
updateWarpPosition(existingWarp, position).thenApplyAsync(result -> {
|
||||
if (result) {
|
||||
if (mapHook != null) {
|
||||
mapHook.updateWarp(existingWarp);
|
||||
}
|
||||
return new SaveResult(SaveResult.ResultType.SUCCESS_OVERWRITTEN, Optional.of(existingWarp));
|
||||
}
|
||||
return new SaveResult(SaveResult.ResultType.FAILED_EVENT_CANCELLED, Optional.empty());
|
||||
}).join();
|
||||
}
|
||||
return new SaveResult(SaveResult.ResultType.FAILED_DUPLICATE, Optional.empty());
|
||||
}));
|
||||
@@ -268,6 +303,8 @@ public class SavedPositionManager {
|
||||
if (event.isCancelled()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Delete the warp from database and propagate updates to cache and map hook
|
||||
final Warp warp = event.getWarp();
|
||||
return database.deleteWarp(warp.uuid).thenApplyAsync(ignored -> {
|
||||
cache.warps.remove(warp.meta.name);
|
||||
@@ -386,8 +423,22 @@ public class SavedPositionManager {
|
||||
*/
|
||||
SUCCESS(true),
|
||||
|
||||
/**
|
||||
* A home or warp was attempted to be set, but one already exists with the same name (for the user in the
|
||||
* case of homes), so the existing position was updated instead.
|
||||
* <p>
|
||||
*
|
||||
* @implNote This will only fire if the {@link Settings#overwriteExistingHomesWarps} config value is
|
||||
* set to {@code true}
|
||||
*/
|
||||
SUCCESS_OVERWRITTEN(true),
|
||||
|
||||
/**
|
||||
* The position was not set; one by this name has already been set (for the user in the case of homes)
|
||||
* <p>
|
||||
*
|
||||
* @implNote This will only fire if the {@link Settings#overwriteExistingHomesWarps} config value is
|
||||
* set to {@code false}
|
||||
*/
|
||||
FAILED_DUPLICATE(false),
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ public enum TeleportResult {
|
||||
/**
|
||||
* Returns if the {@link Teleport} was completed cross-server
|
||||
*/
|
||||
COMPLETED_CROSS_SERVER(true, "teleporting_complete"),
|
||||
COMPLETED_CROSS_SERVER(true),
|
||||
|
||||
/**
|
||||
* Returns if the {@link Teleport} failed because the user is already teleporting
|
||||
|
||||
@@ -141,8 +141,8 @@ error_home_invalid_other: '[Fehler:](#ff3300) [%1% hat kein Home namens "%2%"!](
|
||||
error_edit_home_maximum_public_homes: '[Fehler:](#ff3300) [Du kannst maximal %1% Home(s) öffentlich sichtbar machen.](#ff7e5e)'
|
||||
error_illegal_target_coordinates: '[Fehler:](#ff3300) [Teleportation abgebrochen, da sie die möglichen Grenzen der Spielwelt überschreitet.](#ff7e5e)'
|
||||
error_no_players_online: '[Fehler:](#ff3300) [Es sind keine Spieler online, die sich zu dir teleportieren könnten.](#ff7e5e)'
|
||||
error_teleport_target_not_resolved: '[Error:](#ff3300) [Cancelled teleport as a target position could not be found.](#ff7e5e)'
|
||||
error_teleport_teleporter_not_resolved: '[Error:](#ff3300) [Cancelled teleport as the user to teleport could not be found](#ff7e5e)'
|
||||
error_teleport_target_not_resolved: '[Fehler:](#ff3300) [Teleportation abgebrochen, da die Zielposition nicht gefunden werden konnte.](#ff7e5e)'
|
||||
error_teleport_teleporter_not_resolved: '[Fehler:](#ff3300) [Teleportation abgebrochen, da der Nutzer, zu dem teleportiert werden sollte, nicht gefunden werden konnte.](#ff7e5e)'
|
||||
home_command_description: 'Teleportiere dich zu einem deiner Homes'
|
||||
sethome_command_description: 'Setze ein neues Home mit dem angegebenen Namen'
|
||||
delhome_command_description: 'Lösche ein Home, welches du vorher gesetzt hast'
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@ org.gradle.jvmargs='-Dfile.encoding=UTF-8'
|
||||
org.gradle.daemon=true
|
||||
javaVersion=16
|
||||
|
||||
plugin_version=3.1
|
||||
plugin_version=3.1.1
|
||||
plugin_archive=huskhomes
|
||||
|
||||
jedis_version=4.2.3
|
||||
|
||||
Reference in new issue
Block a user