mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-04 14:38:53 +00:00
Further caching improvements
This commit is contained in:
12 files changed
+212
-46
No files matched your search
@@ -98,7 +98,7 @@ public class DynMapHook extends MapHook {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<Void> clearHomes(@NotNull User user) {
|
public void clearHomes(@NotNull User user) {
|
||||||
final CompletableFuture<Void> clearedFuture = new CompletableFuture<>();
|
final CompletableFuture<Void> clearedFuture = new CompletableFuture<>();
|
||||||
Bukkit.getScheduler().runTask((BukkitHuskHomes) plugin, () -> {
|
Bukkit.getScheduler().runTask((BukkitHuskHomes) plugin, () -> {
|
||||||
dynmapAPI.getMarkerAPI().getMarkerSet(PUBLIC_HOMES_MARKER_SET_ID).getMarkers().stream()
|
dynmapAPI.getMarkerAPI().getMarkerSet(PUBLIC_HOMES_MARKER_SET_ID).getMarkers().stream()
|
||||||
@@ -106,7 +106,6 @@ public class DynMapHook extends MapHook {
|
|||||||
.forEach(Marker::deleteMarker);
|
.forEach(Marker::deleteMarker);
|
||||||
clearedFuture.complete(null);
|
clearedFuture.complete(null);
|
||||||
});
|
});
|
||||||
return clearedFuture;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -144,14 +143,13 @@ public class DynMapHook extends MapHook {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<Void> clearWarps() {
|
public void clearWarps() {
|
||||||
final CompletableFuture<Void> clearedFuture = new CompletableFuture<>();
|
final CompletableFuture<Void> clearedFuture = new CompletableFuture<>();
|
||||||
Bukkit.getScheduler().runTask((BukkitHuskHomes) plugin, () -> {
|
Bukkit.getScheduler().runTask((BukkitHuskHomes) plugin, () -> {
|
||||||
dynmapAPI.getMarkerAPI().getMarkerSet(WARPS_MARKER_SET_ID).getMarkers()
|
dynmapAPI.getMarkerAPI().getMarkerSet(WARPS_MARKER_SET_ID).getMarkers()
|
||||||
.forEach(Marker::deleteMarker);
|
.forEach(Marker::deleteMarker);
|
||||||
clearedFuture.complete(null);
|
clearedFuture.complete(null);
|
||||||
});
|
});
|
||||||
return clearedFuture;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -99,7 +99,7 @@ public class BlueMapHook extends MapHook {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<Void> clearHomes(@NotNull User user) {
|
public void clearHomes(@NotNull User user) {
|
||||||
BlueMapAPI.getInstance().ifPresent((BlueMapAPI blueMapAPI) -> blueMapAPI.getWorlds()
|
BlueMapAPI.getInstance().ifPresent((BlueMapAPI blueMapAPI) -> blueMapAPI.getWorlds()
|
||||||
.forEach(blueMapWorld -> blueMapWorld.getMaps()
|
.forEach(blueMapWorld -> blueMapWorld.getMaps()
|
||||||
.forEach(blueMapMap -> blueMapMap.getMarkerSets()
|
.forEach(blueMapMap -> blueMapMap.getMarkerSets()
|
||||||
@@ -108,7 +108,7 @@ public class BlueMapHook extends MapHook {
|
|||||||
return markerSet;
|
return markerSet;
|
||||||
}))));
|
}))));
|
||||||
|
|
||||||
return CompletableFuture.completedFuture(null);
|
CompletableFuture.completedFuture(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -143,7 +143,7 @@ public class BlueMapHook extends MapHook {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<Void> clearWarps() {
|
public void clearWarps() {
|
||||||
BlueMapAPI.getInstance().ifPresent((BlueMapAPI blueMapAPI) -> blueMapAPI.getWorlds()
|
BlueMapAPI.getInstance().ifPresent((BlueMapAPI blueMapAPI) -> blueMapAPI.getWorlds()
|
||||||
.forEach(blueMapWorld -> blueMapWorld.getMaps()
|
.forEach(blueMapWorld -> blueMapWorld.getMaps()
|
||||||
.forEach(blueMapMap -> blueMapMap.getMarkerSets()
|
.forEach(blueMapMap -> blueMapMap.getMarkerSets()
|
||||||
@@ -152,7 +152,7 @@ public class BlueMapHook extends MapHook {
|
|||||||
return markerSet;
|
return markerSet;
|
||||||
}))));
|
}))));
|
||||||
|
|
||||||
return CompletableFuture.completedFuture(null);
|
CompletableFuture.completedFuture(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -67,9 +67,8 @@ public abstract class MapHook extends PluginHook {
|
|||||||
* Clears homes owned by a player from the map
|
* Clears homes owned by a player from the map
|
||||||
*
|
*
|
||||||
* @param user the player whose homes to clear
|
* @param user the player whose homes to clear
|
||||||
* @return a {@link CompletableFuture} that completes when the homes have been cleared
|
|
||||||
*/
|
*/
|
||||||
public abstract CompletableFuture<Void> clearHomes(@NotNull User user);
|
public abstract void clearHomes(@NotNull User user);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update a warp, adding it to the map if it exists, or updating it on the map if it doesn't
|
* Update a warp, adding it to the map if it exists, or updating it on the map if it doesn't
|
||||||
@@ -88,10 +87,8 @@ public abstract class MapHook extends PluginHook {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Clears all warps from the map
|
* Clears all warps from the map
|
||||||
*
|
|
||||||
* @return a {@link CompletableFuture} that completes when the warps have been cleared
|
|
||||||
*/
|
*/
|
||||||
public abstract CompletableFuture<Void> clearWarps();
|
public abstract void clearWarps();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns if the position is valid to be set on this server
|
* Returns if the position is valid to be set on this server
|
||||||
|
|||||||
@@ -40,20 +40,24 @@ public class EventListener {
|
|||||||
if (plugin.getSettings().isCrossServer()) {
|
if (plugin.getSettings().isCrossServer()) {
|
||||||
this.handleInboundTeleport(onlineUser);
|
this.handleInboundTeleport(onlineUser);
|
||||||
|
|
||||||
|
// Update caches
|
||||||
|
if (plugin.getOnlineUsers().size() == 1) {
|
||||||
|
plugin.getManager().homes().updatePublicHomeCache();
|
||||||
|
plugin.getManager().warps().updateWarpCache();
|
||||||
|
}
|
||||||
|
|
||||||
// Update the player list
|
// Update the player list
|
||||||
plugin.runLater(() -> {
|
plugin.runLater(() -> {
|
||||||
if (plugin.getOnlineUsers().size() == 1) {
|
// Send a player list update to other servers
|
||||||
Message.builder()
|
sendPlayerListUpdates(onlineUser);
|
||||||
.scope(Message.Scope.SERVER)
|
|
||||||
.target(Message.TARGET_ALL)
|
|
||||||
.type(Message.Type.REQUEST_PLAYER_LIST)
|
|
||||||
.build().send(plugin.getMessenger(), onlineUser);
|
|
||||||
}
|
|
||||||
|
|
||||||
plugin.getOnlineUsers().stream()
|
// Request updated player lists from other servers
|
||||||
.filter(user -> !user.equals(onlineUser))
|
plugin.getGlobalPlayerList().clear();
|
||||||
.findAny()
|
Message.builder()
|
||||||
.ifPresent(this::sendPlayerListUpdates);
|
.scope(Message.Scope.SERVER)
|
||||||
|
.target(Message.TARGET_ALL)
|
||||||
|
.type(Message.Type.REQUEST_PLAYER_LIST)
|
||||||
|
.build().send(plugin.getMessenger(), onlineUser);
|
||||||
}, plugin.getSettings().getBrokerType() == Broker.Type.PLUGIN_MESSAGE ? 40L : 0L);
|
}, plugin.getSettings().getBrokerType() == Broker.Type.PLUGIN_MESSAGE ? 40L : 0L);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ package net.william278.huskhomes.manager;
|
|||||||
|
|
||||||
import net.william278.huskhomes.HuskHomes;
|
import net.william278.huskhomes.HuskHomes;
|
||||||
import net.william278.huskhomes.hook.EconomyHook;
|
import net.william278.huskhomes.hook.EconomyHook;
|
||||||
|
import net.william278.huskhomes.network.Message;
|
||||||
|
import net.william278.huskhomes.network.Payload;
|
||||||
import net.william278.huskhomes.position.Home;
|
import net.william278.huskhomes.position.Home;
|
||||||
import net.william278.huskhomes.position.Position;
|
import net.william278.huskhomes.position.Position;
|
||||||
import net.william278.huskhomes.position.PositionMeta;
|
import net.william278.huskhomes.position.PositionMeta;
|
||||||
@@ -12,17 +14,19 @@ import net.william278.huskhomes.util.ValidationException;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||||
|
|
||||||
public class HomesManager {
|
public class HomesManager {
|
||||||
|
|
||||||
private final HuskHomes plugin;
|
private final HuskHomes plugin;
|
||||||
private final List<Home> publicHomes;
|
private final ConcurrentLinkedQueue<Home> publicHomes;
|
||||||
private final Map<String, List<Home>> userHomes;
|
private final ConcurrentHashMap<String, ConcurrentLinkedQueue<Home>> userHomes;
|
||||||
|
|
||||||
protected HomesManager(@NotNull HuskHomes plugin) {
|
protected HomesManager(@NotNull HuskHomes plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
this.publicHomes = plugin.getDatabase().getPublicHomes();
|
this.publicHomes = new ConcurrentLinkedQueue<>(plugin.getDatabase().getPublicHomes());
|
||||||
this.userHomes = new HashMap<>();
|
this.userHomes = new ConcurrentHashMap<>();
|
||||||
plugin.runAsync(() -> plugin.getOnlineUsers()
|
plugin.runAsync(() -> plugin.getOnlineUsers()
|
||||||
.forEach(this::cacheUserHomes));
|
.forEach(this::cacheUserHomes));
|
||||||
}
|
}
|
||||||
@@ -38,7 +42,56 @@ public class HomesManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void cacheUserHomes(@NotNull User user) {
|
public void cacheUserHomes(@NotNull User user) {
|
||||||
userHomes.put(user.getUuid().toString(), plugin.getDatabase().getHomes(user));
|
userHomes.put(user.getUsername(), new ConcurrentLinkedQueue<>(plugin.getDatabase().getHomes(user)));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void cacheHome(@NotNull Home home, boolean propagate) {
|
||||||
|
userHomes.computeIfPresent(home.getOwner().getUsername(), (k, v) -> {
|
||||||
|
v.remove(home);
|
||||||
|
v.add(home);
|
||||||
|
return v;
|
||||||
|
});
|
||||||
|
if (publicHomes.remove(home) && !home.isPublic()) {
|
||||||
|
plugin.getMapHook().ifPresent(hook -> hook.removeHome(home));
|
||||||
|
}
|
||||||
|
if (home.isPublic()) {
|
||||||
|
publicHomes.add(home);
|
||||||
|
plugin.getMapHook().ifPresent(hook -> hook.updateHome(home));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (propagate) {
|
||||||
|
propagateCacheUpdate(home.getUuid());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void unCacheHome(@NotNull UUID homeId, boolean propagate) {
|
||||||
|
userHomes.values().forEach(homes -> homes.removeIf(home -> home.getUuid().equals(homeId)));
|
||||||
|
publicHomes.removeIf(home -> {
|
||||||
|
if (home.getUuid().equals(homeId)) {
|
||||||
|
plugin.getMapHook().ifPresent(hook -> hook.removeHome(home));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (propagate) {
|
||||||
|
this.propagateCacheUpdate(homeId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void propagateCacheUpdate(@NotNull UUID homeId) {
|
||||||
|
if (plugin.getSettings().isCrossServer()) {
|
||||||
|
plugin.getOnlineUsers().stream().findAny().ifPresent(user -> Message.builder()
|
||||||
|
.type(Message.Type.UPDATE_HOME)
|
||||||
|
.scope(Message.Scope.SERVER)
|
||||||
|
.target(Message.TARGET_ALL)
|
||||||
|
.payload(Payload.withString(homeId.toString()))
|
||||||
|
.build().send(plugin.getMessenger(), user));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updatePublicHomeCache() {
|
||||||
|
plugin.getDatabase().getPublicHomes().forEach(home -> cacheHome(home, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeUserHomes(@NotNull User user) {
|
public void removeUserHomes(@NotNull User user) {
|
||||||
@@ -99,6 +152,7 @@ public class HomesManager {
|
|||||||
})
|
})
|
||||||
.orElse(new Home(position, new PositionMeta(name, ""), owner));
|
.orElse(new Home(position, new PositionMeta(name, ""), owner));
|
||||||
plugin.getDatabase().saveHome(home);
|
plugin.getDatabase().saveHome(home);
|
||||||
|
this.cacheHome(home, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void createHome(@NotNull OnlineUser owner, @NotNull String name, @NotNull Position position) throws ValidationException {
|
public void createHome(@NotNull OnlineUser owner, @NotNull String name, @NotNull Position position) throws ValidationException {
|
||||||
@@ -116,10 +170,19 @@ public class HomesManager {
|
|||||||
|
|
||||||
public void deleteHome(@NotNull Home home) {
|
public void deleteHome(@NotNull Home home) {
|
||||||
plugin.getDatabase().deleteHome(home.getUuid());
|
plugin.getDatabase().deleteHome(home.getUuid());
|
||||||
|
this.unCacheHome(home.getUuid(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int deleteAllHomes(@NotNull User owner) {
|
public int deleteAllHomes(@NotNull User owner) {
|
||||||
return plugin.getDatabase().deleteAllHomes(owner);
|
final int deleted = plugin.getDatabase().deleteAllHomes(owner);
|
||||||
|
userHomes.computeIfPresent(owner.getUsername(), (k, v) -> {
|
||||||
|
v.clear();
|
||||||
|
return v;
|
||||||
|
});
|
||||||
|
publicHomes.removeIf(h -> h.getOwner().getUuid().equals(owner.getUuid()));
|
||||||
|
plugin.getMapHook().ifPresent(hook -> hook.clearHomes(owner));
|
||||||
|
plugin.getManager().propagateCacheUpdate();
|
||||||
|
return deleted;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setHomePosition(@NotNull User owner, @NotNull String name, @NotNull Position position) throws ValidationException {
|
public void setHomePosition(@NotNull User owner, @NotNull String name, @NotNull Position position) throws ValidationException {
|
||||||
@@ -134,6 +197,7 @@ public class HomesManager {
|
|||||||
public void setHomePosition(@NotNull Home home, @NotNull Position position) throws ValidationException {
|
public void setHomePosition(@NotNull Home home, @NotNull Position position) throws ValidationException {
|
||||||
home.update(position);
|
home.update(position);
|
||||||
plugin.getDatabase().saveHome(home);
|
plugin.getDatabase().saveHome(home);
|
||||||
|
this.cacheHome(home, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setHomeName(@NotNull User owner, @NotNull String name, @NotNull String newName) throws ValidationException {
|
public void setHomeName(@NotNull User owner, @NotNull String name, @NotNull String newName) throws ValidationException {
|
||||||
@@ -152,6 +216,7 @@ public class HomesManager {
|
|||||||
|
|
||||||
home.getMeta().setName(newName);
|
home.getMeta().setName(newName);
|
||||||
plugin.getDatabase().saveHome(home);
|
plugin.getDatabase().saveHome(home);
|
||||||
|
this.cacheHome(home, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setHomeDescription(@NotNull User owner, @NotNull String name, @NotNull String description) throws ValidationException {
|
public void setHomeDescription(@NotNull User owner, @NotNull String name, @NotNull String description) throws ValidationException {
|
||||||
@@ -170,6 +235,7 @@ public class HomesManager {
|
|||||||
|
|
||||||
home.getMeta().setDescription(description);
|
home.getMeta().setDescription(description);
|
||||||
plugin.getDatabase().saveHome(home);
|
plugin.getDatabase().saveHome(home);
|
||||||
|
this.cacheHome(home, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setHomePrivacy(@NotNull User owner, @NotNull String name, boolean isPublic) throws ValidationException {
|
public void setHomePrivacy(@NotNull User owner, @NotNull String name, boolean isPublic) throws ValidationException {
|
||||||
@@ -199,6 +265,7 @@ public class HomesManager {
|
|||||||
|
|
||||||
home.setPublic(isPublic);
|
home.setPublic(isPublic);
|
||||||
plugin.getDatabase().saveHome(home);
|
plugin.getDatabase().saveHome(home);
|
||||||
|
this.cacheHome(home, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,15 +1,18 @@
|
|||||||
package net.william278.huskhomes.manager;
|
package net.william278.huskhomes.manager;
|
||||||
|
|
||||||
import net.william278.huskhomes.HuskHomes;
|
import net.william278.huskhomes.HuskHomes;
|
||||||
|
import net.william278.huskhomes.network.Message;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public class Manager {
|
public class Manager {
|
||||||
|
|
||||||
|
private final HuskHomes plugin;
|
||||||
private final HomesManager homes;
|
private final HomesManager homes;
|
||||||
private final WarpsManager warps;
|
private final WarpsManager warps;
|
||||||
private final RequestsManager requests;
|
private final RequestsManager requests;
|
||||||
|
|
||||||
public Manager(@NotNull HuskHomes plugin) {
|
public Manager(@NotNull HuskHomes plugin) {
|
||||||
|
this.plugin = plugin;
|
||||||
this.homes = new HomesManager(plugin);
|
this.homes = new HomesManager(plugin);
|
||||||
this.warps = new WarpsManager(plugin);
|
this.warps = new WarpsManager(plugin);
|
||||||
this.requests = new RequestsManager(plugin);
|
this.requests = new RequestsManager(plugin);
|
||||||
@@ -29,4 +32,13 @@ public class Manager {
|
|||||||
public RequestsManager requests() {
|
public RequestsManager requests() {
|
||||||
return requests;
|
return requests;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Update caches on all servers
|
||||||
|
protected void propagateCacheUpdate() {
|
||||||
|
plugin.getOnlineUsers().stream().findAny().ifPresent(user -> Message.builder()
|
||||||
|
.type(Message.Type.UPDATE_CACHES)
|
||||||
|
.scope(Message.Scope.SERVER)
|
||||||
|
.target(Message.TARGET_ALL)
|
||||||
|
.build().send(plugin.getMessenger(), user));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,9 @@
|
|||||||
package net.william278.huskhomes.manager;
|
package net.william278.huskhomes.manager;
|
||||||
|
|
||||||
import net.william278.huskhomes.HuskHomes;
|
import net.william278.huskhomes.HuskHomes;
|
||||||
|
import net.william278.huskhomes.hook.MapHook;
|
||||||
|
import net.william278.huskhomes.network.Message;
|
||||||
|
import net.william278.huskhomes.network.Payload;
|
||||||
import net.william278.huskhomes.position.Position;
|
import net.william278.huskhomes.position.Position;
|
||||||
import net.william278.huskhomes.position.PositionMeta;
|
import net.william278.huskhomes.position.PositionMeta;
|
||||||
import net.william278.huskhomes.position.Warp;
|
import net.william278.huskhomes.position.Warp;
|
||||||
@@ -9,14 +12,54 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||||
|
|
||||||
public class WarpsManager {
|
public class WarpsManager {
|
||||||
private final HuskHomes plugin;
|
private final HuskHomes plugin;
|
||||||
private final List<Warp> warps;
|
private final ConcurrentLinkedQueue<Warp> warps;
|
||||||
|
|
||||||
protected WarpsManager(@NotNull HuskHomes plugin) {
|
protected WarpsManager(@NotNull HuskHomes plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
this.warps = plugin.getDatabase().getWarps();
|
this.warps = new ConcurrentLinkedQueue<>(plugin.getDatabase().getWarps());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void cacheWarp(@NotNull Warp warp, boolean propagate) {
|
||||||
|
warps.remove(warp);
|
||||||
|
warps.add(warp);
|
||||||
|
plugin.getMapHook().ifPresent(hook -> hook.updateWarp(warp));
|
||||||
|
if (propagate) {
|
||||||
|
this.propagateCacheUpdate(warp.getUuid());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void unCacheWarp(@NotNull UUID warpId, boolean propagate) {
|
||||||
|
warps.removeIf(warp -> {
|
||||||
|
if (warp.getUuid().equals(warpId)) {
|
||||||
|
plugin.getMapHook().ifPresent(hook -> hook.removeWarp(warp));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (propagate) {
|
||||||
|
this.propagateCacheUpdate(warpId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void propagateCacheUpdate(@NotNull UUID warpId) {
|
||||||
|
if (plugin.getSettings().isCrossServer()) {
|
||||||
|
plugin.getOnlineUsers().stream().findAny().ifPresent(user -> Message.builder()
|
||||||
|
.type(Message.Type.UPDATE_WARP)
|
||||||
|
.scope(Message.Scope.SERVER)
|
||||||
|
.target(Message.TARGET_ALL)
|
||||||
|
.payload(Payload.withString(warpId.toString()))
|
||||||
|
.build().send(plugin.getMessenger(), user));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateWarpCache() {
|
||||||
|
plugin.getDatabase().getWarps().forEach(warp -> cacheWarp(warp, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -50,6 +93,7 @@ public class WarpsManager {
|
|||||||
})
|
})
|
||||||
.orElse(new Warp(position, new PositionMeta(name, "")));
|
.orElse(new Warp(position, new PositionMeta(name, "")));
|
||||||
plugin.getDatabase().saveWarp(warp);
|
plugin.getDatabase().saveWarp(warp);
|
||||||
|
this.cacheWarp(warp, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void createWarp(@NotNull String name, @NotNull Position position) throws ValidationException {
|
public void createWarp(@NotNull String name, @NotNull Position position) throws ValidationException {
|
||||||
@@ -67,10 +111,15 @@ public class WarpsManager {
|
|||||||
|
|
||||||
public void deleteWarp(@NotNull Warp warp) {
|
public void deleteWarp(@NotNull Warp warp) {
|
||||||
plugin.getDatabase().deleteWarp(warp.getUuid());
|
plugin.getDatabase().deleteWarp(warp.getUuid());
|
||||||
|
this.unCacheWarp(warp.getUuid(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int deleteAllWarps() {
|
public int deleteAllWarps() {
|
||||||
return plugin.getDatabase().deleteAllWarps();
|
final int deleted = plugin.getDatabase().deleteAllWarps();
|
||||||
|
warps.clear();
|
||||||
|
plugin.getMapHook().ifPresent(MapHook::clearWarps);
|
||||||
|
plugin.getManager().propagateCacheUpdate();
|
||||||
|
return deleted;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void relocateWarp(@NotNull String name, @NotNull Position position) throws ValidationException {
|
public void relocateWarp(@NotNull String name, @NotNull Position position) throws ValidationException {
|
||||||
@@ -85,6 +134,7 @@ public class WarpsManager {
|
|||||||
public void relocateWarp(@NotNull Warp warp, @NotNull Position position) {
|
public void relocateWarp(@NotNull Warp warp, @NotNull Position position) {
|
||||||
warp.update(position);
|
warp.update(position);
|
||||||
plugin.getDatabase().saveWarp(warp);
|
plugin.getDatabase().saveWarp(warp);
|
||||||
|
this.cacheWarp(warp, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void renameWarp(@NotNull String name, @NotNull String newName) throws ValidationException {
|
public void renameWarp(@NotNull String name, @NotNull String newName) throws ValidationException {
|
||||||
@@ -103,6 +153,7 @@ public class WarpsManager {
|
|||||||
|
|
||||||
warp.getMeta().setName(newName);
|
warp.getMeta().setName(newName);
|
||||||
plugin.getDatabase().saveWarp(warp);
|
plugin.getDatabase().saveWarp(warp);
|
||||||
|
this.cacheWarp(warp, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setWarpDescription(@NotNull String name, @NotNull String description) throws ValidationException {
|
public void setWarpDescription(@NotNull String name, @NotNull String description) throws ValidationException {
|
||||||
@@ -121,6 +172,7 @@ public class WarpsManager {
|
|||||||
|
|
||||||
warp.getMeta().setDescription(description);
|
warp.getMeta().setDescription(description);
|
||||||
plugin.getDatabase().saveWarp(warp);
|
plugin.getDatabase().saveWarp(warp);
|
||||||
|
this.cacheWarp(warp, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,11 +1,16 @@
|
|||||||
package net.william278.huskhomes.network;
|
package net.william278.huskhomes.network;
|
||||||
|
|
||||||
import net.william278.huskhomes.HuskHomes;
|
import net.william278.huskhomes.HuskHomes;
|
||||||
|
import net.william278.huskhomes.position.Home;
|
||||||
|
import net.william278.huskhomes.position.Warp;
|
||||||
import net.william278.huskhomes.teleport.Teleport;
|
import net.william278.huskhomes.teleport.Teleport;
|
||||||
import net.william278.huskhomes.user.OnlineUser;
|
import net.william278.huskhomes.user.OnlineUser;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
public abstract class Broker {
|
public abstract class Broker {
|
||||||
|
|
||||||
protected final HuskHomes plugin;
|
protected final HuskHomes plugin;
|
||||||
@@ -63,6 +68,30 @@ public abstract class Broker {
|
|||||||
case PLAYER_LIST -> message.getPayload()
|
case PLAYER_LIST -> message.getPayload()
|
||||||
.getStringList()
|
.getStringList()
|
||||||
.ifPresent(players -> plugin.setPlayerList(message.getSourceServer(), players));
|
.ifPresent(players -> plugin.setPlayerList(message.getSourceServer(), players));
|
||||||
|
case UPDATE_HOME -> message.getPayload().getString()
|
||||||
|
.map(UUID::fromString)
|
||||||
|
.ifPresent(homeId -> {
|
||||||
|
final Optional<Home> optionalHome = plugin.getDatabase().getHome(homeId);
|
||||||
|
if (optionalHome.isPresent()) {
|
||||||
|
plugin.getManager().homes().cacheHome(optionalHome.get(), false);
|
||||||
|
} else {
|
||||||
|
plugin.getManager().homes().unCacheHome(homeId, false);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
case UPDATE_WARP -> message.getPayload().getString()
|
||||||
|
.map(UUID::fromString)
|
||||||
|
.ifPresent(warpId -> {
|
||||||
|
final Optional<Warp> optionalWarp = plugin.getDatabase().getWarp(warpId);
|
||||||
|
if (optionalWarp.isPresent()) {
|
||||||
|
plugin.getManager().warps().cacheWarp(optionalWarp.get(), false);
|
||||||
|
} else {
|
||||||
|
plugin.getManager().warps().unCacheWarp(warpId, false);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
case UPDATE_CACHES -> {
|
||||||
|
plugin.getManager().homes().updatePublicHomeCache();
|
||||||
|
plugin.getManager().warps().updateWarpCache();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -143,6 +143,9 @@ public class Message {
|
|||||||
TELEPORT_REQUEST_RESPONSE,
|
TELEPORT_REQUEST_RESPONSE,
|
||||||
REQUEST_PLAYER_LIST,
|
REQUEST_PLAYER_LIST,
|
||||||
PLAYER_LIST,
|
PLAYER_LIST,
|
||||||
|
UPDATE_HOME,
|
||||||
|
UPDATE_WARP,
|
||||||
|
UPDATE_CACHES,
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum Scope {
|
public enum Scope {
|
||||||
|
|||||||
@@ -33,12 +33,6 @@ public abstract class SavedPosition extends Position implements Comparable<Saved
|
|||||||
this.uuid = UUID.randomUUID();
|
this.uuid = UUID.randomUUID();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compare based on names for alphabetical sorting
|
|
||||||
@Override
|
|
||||||
public int compareTo(@NotNull SavedPosition o) {
|
|
||||||
return this.getMeta().getName().compareTo(o.getMeta().getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Metadata about this position (name, description)
|
* Metadata about this position (name, description)
|
||||||
*/
|
*/
|
||||||
@@ -66,4 +60,19 @@ public abstract class SavedPosition extends Position implements Comparable<Saved
|
|||||||
public UUID getUuid() {
|
public UUID getUuid() {
|
||||||
return uuid;
|
return uuid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Compare based on names for alphabetical sorting
|
||||||
|
@Override
|
||||||
|
public int compareTo(@NotNull SavedPosition o) {
|
||||||
|
return this.getMeta().getName().compareTo(o.getMeta().getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if (obj instanceof SavedPosition) {
|
||||||
|
return this.getUuid().equals(((SavedPosition) obj).getUuid());
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -16,21 +16,16 @@ public class TeleportRequest {
|
|||||||
@Expose
|
@Expose
|
||||||
@SerializedName("requester_name")
|
@SerializedName("requester_name")
|
||||||
private String requesterName;
|
private String requesterName;
|
||||||
|
|
||||||
@Expose
|
@Expose
|
||||||
@SerializedName("requester_position")
|
@SerializedName("requester_position")
|
||||||
private Position requesterPosition;
|
private Position requesterPosition;
|
||||||
|
|
||||||
@Expose
|
@Expose
|
||||||
@SerializedName("expiry_time")
|
@SerializedName("expiry_time")
|
||||||
private long expiryTime;
|
private long expiryTime;
|
||||||
|
|
||||||
@Expose
|
@Expose
|
||||||
private Type type;
|
private Type type;
|
||||||
|
|
||||||
@Expose
|
@Expose
|
||||||
private Status status;
|
private Status status;
|
||||||
|
|
||||||
@Expose
|
@Expose
|
||||||
private String recipientName;
|
private String recipientName;
|
||||||
|
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ public class TimedTeleport extends Teleport {
|
|||||||
|
|
||||||
// Run the warmup
|
// Run the warmup
|
||||||
final AtomicInteger warmupTaskId = new AtomicInteger();
|
final AtomicInteger warmupTaskId = new AtomicInteger();
|
||||||
final Runnable delayRunnable = (() -> {
|
final Runnable countdownRunnable = (() -> {
|
||||||
// Display countdown action bar message
|
// Display countdown action bar message
|
||||||
if (timeLeft > 0) {
|
if (timeLeft > 0) {
|
||||||
plugin.getSettings().getSoundEffect(Settings.SoundEffectAction.TELEPORTATION_WARMUP)
|
plugin.getSettings().getSoundEffect(Settings.SoundEffectAction.TELEPORTATION_WARMUP)
|
||||||
@@ -82,7 +82,7 @@ public class TimedTeleport extends Teleport {
|
|||||||
plugin.cancelTask(warmupTaskId.get());
|
plugin.cancelTask(warmupTaskId.get());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
warmupTaskId.set(plugin.runAsyncRepeating(delayRunnable, 20));
|
warmupTaskId.set(plugin.runAsyncRepeating(countdownRunnable, 20L));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user