mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-04 14:38:53 +00:00
Cleanup SavedPositionManager, remove unused name-based methods, cleaner position updating
This commit is contained in:
1 parent
10b7f1629f
commit
059baa174d
2 files changed
+18
-114
No files matched your search
@@ -30,6 +30,21 @@ public class Position extends Location {
|
|||||||
public Position() {
|
public Position() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the position to match that of another position
|
||||||
|
*
|
||||||
|
* @param newPosition The position to update to
|
||||||
|
*/
|
||||||
|
public void update(@NotNull Position newPosition) {
|
||||||
|
this.x = newPosition.x;
|
||||||
|
this.y = newPosition.y;
|
||||||
|
this.z = newPosition.z;
|
||||||
|
this.yaw = newPosition.yaw;
|
||||||
|
this.pitch = newPosition.pitch;
|
||||||
|
this.world = newPosition.world;
|
||||||
|
this.server = newPosition.server;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parses the position from a set of values
|
* Parses the position from a set of values
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -131,24 +131,6 @@ public class SavedPositionManager {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Tries to update an existing home with new metadata
|
|
||||||
*
|
|
||||||
* @param homeOwner the owner of the home
|
|
||||||
* @param existingHomeName the current name of the home to update
|
|
||||||
* @param newHomeMeta the new metadata for the home
|
|
||||||
* @return a future supplying the {@link SaveResult}; the result of updating the home
|
|
||||||
*/
|
|
||||||
public CompletableFuture<SaveResult> updateHomeMeta(@NotNull User homeOwner, @NotNull String existingHomeName,
|
|
||||||
@NotNull PositionMeta newHomeMeta) {
|
|
||||||
return database.getHome(homeOwner, existingHomeName).thenApply(optionalHome -> {
|
|
||||||
if (optionalHome.isPresent()) {
|
|
||||||
return updateHomeMeta(optionalHome.get(), newHomeMeta).join();
|
|
||||||
}
|
|
||||||
return new SaveResult(SaveResult.ResultType.FAILED_DOES_NOT_EXIST, Optional.empty());
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tries to update an existing home with new metadata
|
* Tries to update an existing home with new metadata
|
||||||
*
|
*
|
||||||
@@ -186,24 +168,6 @@ public class SavedPositionManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tries to update the position of a {@link User}'s home
|
|
||||||
*
|
|
||||||
* @param homeOwner the owner of the home
|
|
||||||
* @param homeName the name of the home
|
|
||||||
* @param newPosition the new position for the home
|
|
||||||
* @return a future supplying the {@link SaveResult}; the result of updating the home
|
|
||||||
*/
|
|
||||||
public CompletableFuture<Boolean> updateHomePosition(@NotNull User homeOwner, @NotNull String homeName,
|
|
||||||
@NotNull Position newPosition) {
|
|
||||||
return database.getHome(homeOwner, homeName).thenApply(optionalHome -> {
|
|
||||||
if (optionalHome.isPresent()) {
|
|
||||||
return updateHomePosition(optionalHome.get(), newPosition).join();
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tries to update the position of a {@link User}'s home
|
* Tries to update the position of a {@link User}'s home
|
||||||
*
|
*
|
||||||
@@ -212,13 +176,7 @@ public class SavedPositionManager {
|
|||||||
* @return a future supplying the {@link SaveResult}; the result of updating the home
|
* @return a future supplying the {@link SaveResult}; the result of updating the home
|
||||||
*/
|
*/
|
||||||
public CompletableFuture<Boolean> updateHomePosition(@NotNull Home home, @NotNull Position newPosition) {
|
public CompletableFuture<Boolean> updateHomePosition(@NotNull Home home, @NotNull Position newPosition) {
|
||||||
home.x = newPosition.x;
|
home.update(newPosition);
|
||||||
home.y = newPosition.y;
|
|
||||||
home.z = newPosition.z;
|
|
||||||
home.pitch = newPosition.pitch;
|
|
||||||
home.yaw = newPosition.yaw;
|
|
||||||
home.world = newPosition.world;
|
|
||||||
home.server = newPosition.server;
|
|
||||||
return eventDispatcher.dispatchHomeSaveEvent(home).thenApply(event -> {
|
return eventDispatcher.dispatchHomeSaveEvent(home).thenApply(event -> {
|
||||||
if (event.isCancelled()) {
|
if (event.isCancelled()) {
|
||||||
return false;
|
return false;
|
||||||
@@ -230,25 +188,6 @@ public class SavedPositionManager {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Tries to change the privacy of a {@link User}'s home by given name
|
|
||||||
*
|
|
||||||
* @param homeOwner the owner of the home
|
|
||||||
* @param homeName the name of the home
|
|
||||||
* @param isHomePublic whether the home should be public or not
|
|
||||||
* @return a future supplying a boolean; {@code true} if the privacy was changed, otherwise {@code false}
|
|
||||||
* if the home name was invalid.
|
|
||||||
*/
|
|
||||||
public CompletableFuture<Boolean> updateHomePrivacy(@NotNull User homeOwner, @NotNull String homeName,
|
|
||||||
final boolean isHomePublic) {
|
|
||||||
return database.getHome(homeOwner, homeName).thenApply(optionalHome -> {
|
|
||||||
if (optionalHome.isPresent()) {
|
|
||||||
return updateHomePrivacy(optionalHome.get(), isHomePublic).join();
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tries to change the privacy of a {@link User}'s home by given name
|
* Tries to change the privacy of a {@link User}'s home by given name
|
||||||
*
|
*
|
||||||
@@ -344,23 +283,6 @@ public class SavedPositionManager {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Tries to update an existing home with new metadata
|
|
||||||
*
|
|
||||||
* @param existingWarpName the current name of the home to update
|
|
||||||
* @param newWarpMeta the new metadata for the home
|
|
||||||
* @return a future supplying the {@link SaveResult}; the result of updating the home
|
|
||||||
*/
|
|
||||||
public CompletableFuture<SaveResult> updateWarpMeta(@NotNull String existingWarpName,
|
|
||||||
@NotNull PositionMeta newWarpMeta) {
|
|
||||||
return database.getWarp(existingWarpName).thenApply(optionalWarp -> {
|
|
||||||
if (optionalWarp.isPresent()) {
|
|
||||||
return updateWarpMeta(optionalWarp.get(), newWarpMeta).join();
|
|
||||||
}
|
|
||||||
return new SaveResult(SaveResult.ResultType.FAILED_DOES_NOT_EXIST, Optional.empty());
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tries to update an existing warp with new metadata
|
* Tries to update an existing warp with new metadata
|
||||||
*
|
*
|
||||||
@@ -397,23 +319,6 @@ public class SavedPositionManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tries to update the position of a warp
|
|
||||||
*
|
|
||||||
* @param warpName the name of the home
|
|
||||||
* @param newPosition the new position for the home
|
|
||||||
* @return a future supplying the {@link SaveResult}; the result of updating the home
|
|
||||||
*/
|
|
||||||
public CompletableFuture<Boolean> updateWarpPosition(@NotNull String warpName,
|
|
||||||
@NotNull Position newPosition) {
|
|
||||||
return database.getWarp(warpName).thenApply(optionalWarp -> {
|
|
||||||
if (optionalWarp.isPresent()) {
|
|
||||||
return updateWarpPosition(optionalWarp.get(), newPosition).join();
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tries to update the position of a warp
|
* Tries to update the position of a warp
|
||||||
*
|
*
|
||||||
@@ -422,13 +327,7 @@ public class SavedPositionManager {
|
|||||||
* @return a future supplying the {@link SaveResult}; the result of updating the warp
|
* @return a future supplying the {@link SaveResult}; the result of updating the warp
|
||||||
*/
|
*/
|
||||||
public CompletableFuture<Boolean> updateWarpPosition(@NotNull Warp warp, @NotNull Position newPosition) {
|
public CompletableFuture<Boolean> updateWarpPosition(@NotNull Warp warp, @NotNull Position newPosition) {
|
||||||
warp.x = newPosition.x;
|
warp.update(newPosition);
|
||||||
warp.y = newPosition.y;
|
|
||||||
warp.z = newPosition.z;
|
|
||||||
warp.pitch = newPosition.pitch;
|
|
||||||
warp.yaw = newPosition.yaw;
|
|
||||||
warp.world = newPosition.world;
|
|
||||||
warp.server = newPosition.server;
|
|
||||||
return eventDispatcher.dispatchWarpSaveEvent(warp).thenApply(event -> {
|
return eventDispatcher.dispatchWarpSaveEvent(warp).thenApply(event -> {
|
||||||
if (event.isCancelled()) {
|
if (event.isCancelled()) {
|
||||||
return false;
|
return false;
|
||||||
@@ -487,11 +386,6 @@ public class SavedPositionManager {
|
|||||||
*/
|
*/
|
||||||
SUCCESS(true),
|
SUCCESS(true),
|
||||||
|
|
||||||
/**
|
|
||||||
* The home or warp was not set or updated because it does not exist
|
|
||||||
*/
|
|
||||||
FAILED_DOES_NOT_EXIST(false),
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The position was not set; one by this name has already been set (for the user in the case of homes)
|
* The position was not set; one by this name has already been set (for the user in the case of homes)
|
||||||
*/
|
*/
|
||||||
@@ -520,12 +414,7 @@ public class SavedPositionManager {
|
|||||||
/**
|
/**
|
||||||
* The position was not set or updated; the save event was cancelled by a plugin
|
* The position was not set or updated; the save event was cancelled by a plugin
|
||||||
*/
|
*/
|
||||||
FAILED_EVENT_CANCELLED(false),
|
FAILED_EVENT_CANCELLED(false);
|
||||||
|
|
||||||
/**
|
|
||||||
* The position was not set or updated; an exception occurred
|
|
||||||
*/
|
|
||||||
FAILED_ERROR(false);
|
|
||||||
|
|
||||||
public final boolean successful;
|
public final boolean successful;
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user