mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-02 22:17:17 +00:00
More refactor work, encapsulate classes
This commit is contained in:
1 parent
3e1ec09487
commit
1cebdac9b8
51 files changed
+756
-621
No files matched your search
@@ -35,9 +35,9 @@ public class BlueMapHook extends MapHook {
|
||||
@Override
|
||||
protected CompletableFuture<Void> initializeMap() {
|
||||
final CompletableFuture<Void> initializedFuture = new CompletableFuture<>();
|
||||
CompletableFuture.runAsync(() -> BlueMapAPI.onEnable(blueMapAPI -> {
|
||||
plugin.runAsync(() -> BlueMapAPI.onEnable(blueMapAPI -> {
|
||||
// Create marker sets
|
||||
plugin.getWorlds().forEach(world -> blueMapAPI.getWorld(world.uuid)
|
||||
plugin.getWorlds().forEach(world -> blueMapAPI.getWorld(world.getUuid())
|
||||
.ifPresent(blueMapWorld -> blueMapWorld.getMaps().forEach(map -> {
|
||||
if (plugin.getSettings().isPublicHomesOnMap()) {
|
||||
map.getMarkerSets().put(blueMapWorld.getId() + ":" + PUBLIC_HOMES_MARKER_SET_ID,
|
||||
@@ -71,13 +71,13 @@ public class BlueMapHook extends MapHook {
|
||||
if (!isValidPosition(home)) return CompletableFuture.completedFuture(null);
|
||||
|
||||
return removeHome(home).thenRun(() -> BlueMapAPI.getInstance().flatMap(
|
||||
blueMapAPI -> getBlueMapWorld(blueMapAPI, home.world)).ifPresent(blueMapWorld -> blueMapWorld.getMaps()
|
||||
blueMapAPI -> getBlueMapWorld(blueMapAPI, home.getWorld())).ifPresent(blueMapWorld -> blueMapWorld.getMaps()
|
||||
.forEach(blueMapMap -> blueMapMap.getMarkerSets()
|
||||
.computeIfPresent(blueMapWorld.getId() + ":" + PUBLIC_HOMES_MARKER_SET_ID, (s, markerSet) -> {
|
||||
markerSet.getMarkers().put(home.owner.uuid + ":" + home.uuid,
|
||||
markerSet.getMarkers().put(home.getOwner().uuid + ":" + home.getUuid(),
|
||||
POIMarker.toBuilder()
|
||||
.label("/phome" + home.owner.username + "." + home.meta.name)
|
||||
.position((int) home.x, (int) home.y, (int) home.z)
|
||||
.label("/phome" + home.getOwner().username + "." + home.getMeta().getName())
|
||||
.position((int) home.getX(), (int) home.getY(), (int) home.getZ())
|
||||
.icon(publicHomeMarkerIconPath, Vector2i.from(25, 25))
|
||||
.maxDistance(5000)
|
||||
.build());
|
||||
@@ -89,10 +89,10 @@ public class BlueMapHook extends MapHook {
|
||||
public CompletableFuture<Void> removeHome(@NotNull Home home) {
|
||||
if (!isValidPosition(home)) return CompletableFuture.completedFuture(null);
|
||||
|
||||
BlueMapAPI.getInstance().flatMap(blueMapAPI -> getBlueMapWorld(blueMapAPI, home.world))
|
||||
BlueMapAPI.getInstance().flatMap(blueMapAPI -> getBlueMapWorld(blueMapAPI, home.getWorld()))
|
||||
.ifPresent(blueMapWorld -> blueMapWorld.getMaps().forEach(blueMapMap -> blueMapMap.getMarkerSets()
|
||||
.computeIfPresent(blueMapWorld.getId() + ":" + PUBLIC_HOMES_MARKER_SET_ID, (s, markerSet) -> {
|
||||
markerSet.getMarkers().remove(home.owner.uuid + ":" + home.uuid);
|
||||
markerSet.getMarkers().remove(home.getOwner().uuid + ":" + home.getUuid());
|
||||
return markerSet;
|
||||
})));
|
||||
return CompletableFuture.completedFuture(null);
|
||||
@@ -115,13 +115,13 @@ public class BlueMapHook extends MapHook {
|
||||
public CompletableFuture<Void> updateWarp(@NotNull Warp warp) {
|
||||
if (!isValidPosition(warp)) return CompletableFuture.completedFuture(null);
|
||||
|
||||
return removeWarp(warp).thenRun(() -> BlueMapAPI.getInstance().flatMap(blueMapAPI -> getBlueMapWorld(blueMapAPI, warp.world))
|
||||
return removeWarp(warp).thenRun(() -> BlueMapAPI.getInstance().flatMap(blueMapAPI -> getBlueMapWorld(blueMapAPI, warp.getWorld()))
|
||||
.ifPresent(blueMapWorld -> blueMapWorld.getMaps().forEach(blueMapMap -> blueMapMap.getMarkerSets()
|
||||
.computeIfPresent(blueMapWorld.getId() + ":" + WARPS_MARKER_SET_ID, (s, markerSet) -> {
|
||||
markerSet.getMarkers().put(warp.uuid.toString(),
|
||||
markerSet.getMarkers().put(warp.getUuid().toString(),
|
||||
POIMarker.toBuilder()
|
||||
.label("/warp " + warp.meta.name)
|
||||
.position((int) warp.x, (int) warp.y, (int) warp.z)
|
||||
.label("/warp " + warp.getMeta().getName())
|
||||
.position((int) warp.getX(), (int) warp.getY(), (int) warp.getZ())
|
||||
.icon(warpMarkerIconPath, Vector2i.from(25, 25))
|
||||
.maxDistance(10000)
|
||||
.build());
|
||||
@@ -133,10 +133,10 @@ public class BlueMapHook extends MapHook {
|
||||
public CompletableFuture<Void> removeWarp(@NotNull Warp warp) {
|
||||
if (!isValidPosition(warp)) return CompletableFuture.completedFuture(null);
|
||||
|
||||
BlueMapAPI.getInstance().flatMap(blueMapAPI -> getBlueMapWorld(blueMapAPI, warp.world))
|
||||
BlueMapAPI.getInstance().flatMap(blueMapAPI -> getBlueMapWorld(blueMapAPI, warp.getWorld()))
|
||||
.ifPresent(blueMapWorld -> blueMapWorld.getMaps().forEach(blueMapMap -> blueMapMap.getMarkerSets()
|
||||
.computeIfPresent(blueMapWorld.getId() + ":" + WARPS_MARKER_SET_ID, (s, markerSet) -> {
|
||||
markerSet.getMarkers().remove(warp.uuid.toString());
|
||||
markerSet.getMarkers().remove(warp.getUuid().toString());
|
||||
return markerSet;
|
||||
})));
|
||||
return CompletableFuture.completedFuture(null);
|
||||
@@ -163,10 +163,10 @@ public class BlueMapHook extends MapHook {
|
||||
*/
|
||||
@NotNull
|
||||
private Optional<BlueMapWorld> getBlueMapWorld(@NotNull BlueMapAPI blueMapAPI, @NotNull World world) {
|
||||
if (world.uuid.equals(new UUID(0, 0))) {
|
||||
return blueMapAPI.getWorld(world.name);
|
||||
if (world.getUuid().equals(new UUID(0, 0))) {
|
||||
return blueMapAPI.getWorld(world.getName());
|
||||
} else {
|
||||
return blueMapAPI.getWorld(world.uuid);
|
||||
return blueMapAPI.getWorld(world.getUuid());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import net.william278.huskhomes.player.User;
|
||||
import net.william278.huskhomes.position.Home;
|
||||
import net.william278.huskhomes.position.SavedPosition;
|
||||
import net.william278.huskhomes.position.Warp;
|
||||
import net.william278.huskhomes.position.World;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
@@ -104,11 +105,11 @@ public abstract class MapHook extends PluginHook {
|
||||
if (position instanceof Home && !plugin.getSettings().isPublicHomesOnMap()) return false;
|
||||
|
||||
try {
|
||||
return position.server.equals(plugin.getServerName());
|
||||
return position.getServer().equals(plugin.getServerName());
|
||||
} catch (IllegalStateException e) {
|
||||
return plugin.getWorlds().stream()
|
||||
.map(world -> world.uuid)
|
||||
.anyMatch(uuid -> uuid.equals(position.world.uuid));
|
||||
.map(World::getUuid)
|
||||
.anyMatch(uuid -> uuid.equals(position.getWorld().getUuid()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -78,7 +78,7 @@ public class PlanDataExtension implements DataExtension {
|
||||
public long getPublicHomeCount(@NotNull UUID uuid) {
|
||||
return database.getUserData(uuid)
|
||||
.map(userData -> database.getHomes(userData.user())
|
||||
.stream().filter(home -> home.isPublic).count())
|
||||
.stream().filter(home -> home.isPublic()).count())
|
||||
.orElse(0L);
|
||||
}
|
||||
|
||||
@@ -121,9 +121,9 @@ public class PlanDataExtension implements DataExtension {
|
||||
public String getOfflinePosition(@NotNull UUID uuid) {
|
||||
return database.getUserData(uuid)
|
||||
.map(userData -> database.getOfflinePosition(userData.user())
|
||||
.map(position -> "x: " + (int) position.x + ", y: " + (int) position.y + ", z: " + (int) position.z
|
||||
+ " (" + position.world.name +
|
||||
((crossServer) ? "/" + position.server.name + ")" : ")"))
|
||||
.map(position -> "x: " + (int) position.getX() + ", y: " + (int) position.getY() + ", z: " + (int) position.getZ()
|
||||
+ " (" + position.getWorld().getName() +
|
||||
((crossServer) ? "/" + position.getServer().getName() + ")" : ")"))
|
||||
.orElse(UNKNOWN_STRING))
|
||||
.orElse(UNKNOWN_STRING);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user