mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-02 06:28:49 +00:00
Rewrite map hooks, use more modern APIs
This commit is contained in:
1 parent
167d5d6c7a
commit
98fa779046
15 files changed
+457
-463
No files matched your search
@@ -4,7 +4,6 @@ import net.william278.huskhomes.HuskHomes;
|
||||
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 net.william278.huskhomes.user.User;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -13,55 +12,44 @@ import java.util.concurrent.CompletableFuture;
|
||||
/**
|
||||
* A hook for a mapping plugin, such as Dynmap
|
||||
*/
|
||||
public abstract class MapHook extends PluginHook {
|
||||
public abstract class MapHook extends Hook {
|
||||
|
||||
protected static final String PUBLIC_HOMES_MARKER_SET_ID = "huskhomes-public-homes";
|
||||
protected static final String WARPS_MARKER_SET_ID = "huskhomes-warps";
|
||||
protected static final String WARP_MARKER_IMAGE_NAME = "warp";
|
||||
protected static final String PUBLIC_HOME_MARKER_IMAGE_NAME = "public-home";
|
||||
|
||||
protected MapHook(@NotNull HuskHomes implementor, @NotNull String hookName) {
|
||||
super(implementor, hookName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean initialize() {
|
||||
initializeMap().thenRun(() -> {
|
||||
if (plugin.getSettings().isPublicHomesOnMap()) {
|
||||
plugin.getDatabase()
|
||||
.getLocalPublicHomes(plugin)
|
||||
.forEach(this::updateHome);
|
||||
}
|
||||
if (plugin.getSettings().isWarpsOnMap()) {
|
||||
plugin.getDatabase()
|
||||
.getLocalWarps(plugin)
|
||||
.forEach(this::updateWarp);
|
||||
}
|
||||
});
|
||||
return true;
|
||||
protected MapHook(@NotNull HuskHomes plugin, @NotNull MapHook.Plugin type) {
|
||||
super(plugin, type.getDisplayName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare the map plugin for adding homes to
|
||||
*
|
||||
* @return a {@link CompletableFuture} that completes when the map plugin is ready
|
||||
* Populate the map with public homes and warps
|
||||
*/
|
||||
protected abstract CompletableFuture<Void> initializeMap();
|
||||
protected void populateMap() {
|
||||
if (plugin.getSettings().isPublicHomesOnMap()) {
|
||||
plugin.getDatabase()
|
||||
.getLocalPublicHomes(plugin)
|
||||
.forEach(this::updateHome);
|
||||
}
|
||||
if (plugin.getSettings().isWarpsOnMap()) {
|
||||
plugin.getDatabase()
|
||||
.getLocalWarps(plugin)
|
||||
.forEach(this::updateWarp);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a home, adding it to the map if it exists, or updating it on the map if it doesn't
|
||||
*
|
||||
* @param home the home to update
|
||||
*/
|
||||
@SuppressWarnings("UnusedReturnValue")
|
||||
public abstract CompletableFuture<Void> updateHome(@NotNull Home home);
|
||||
public abstract void updateHome(@NotNull Home home);
|
||||
|
||||
/**
|
||||
* Removes a home from the map
|
||||
*
|
||||
* @param home the home to remove
|
||||
*/
|
||||
public abstract CompletableFuture<Void> removeHome(@NotNull Home home);
|
||||
public abstract void removeHome(@NotNull Home home);
|
||||
|
||||
/**
|
||||
* Clears homes owned by a player from the map
|
||||
@@ -75,15 +63,14 @@ public abstract class MapHook extends PluginHook {
|
||||
*
|
||||
* @param warp the warp to update
|
||||
*/
|
||||
@SuppressWarnings("UnusedReturnValue")
|
||||
public abstract CompletableFuture<Void> updateWarp(@NotNull Warp warp);
|
||||
public abstract void updateWarp(@NotNull Warp warp);
|
||||
|
||||
/**
|
||||
* Removes a warp from the map
|
||||
*
|
||||
* @param warp the warp to remove
|
||||
*/
|
||||
public abstract CompletableFuture<Void> removeWarp(@NotNull Warp warp);
|
||||
public abstract void removeWarp(@NotNull Warp warp);
|
||||
|
||||
/**
|
||||
* Clears all warps from the map
|
||||
@@ -98,30 +85,43 @@ public abstract class MapHook extends PluginHook {
|
||||
*/
|
||||
@SuppressWarnings("BooleanMethodIsAlwaysInverted")
|
||||
protected final boolean isValidPosition(@NotNull SavedPosition position) {
|
||||
if (position instanceof Warp && !plugin.getSettings().isWarpsOnMap()) return false;
|
||||
if (position instanceof Home && !plugin.getSettings().isPublicHomesOnMap()) return false;
|
||||
|
||||
try {
|
||||
return position.getServer().equals(plugin.getServerName());
|
||||
} catch (IllegalStateException e) {
|
||||
return plugin.getWorlds().stream()
|
||||
.map(World::getUuid)
|
||||
.anyMatch(uuid -> uuid.equals(position.getWorld().getUuid()));
|
||||
if (position instanceof Warp && !plugin.getSettings().isWarpsOnMap()) {
|
||||
return false;
|
||||
}
|
||||
if (position instanceof Home && !plugin.getSettings().isPublicHomesOnMap()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return position.getServer().equals(plugin.getServerName());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected final String getPublicHomesKey() {
|
||||
return plugin.getKey(getName().toLowerCase(), "public_homes", "markers").toString();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected final String getWarpsKey() {
|
||||
return plugin.getKey(getName().toLowerCase(), "warps", "markers").toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Identifies types of supported Map plugins
|
||||
*/
|
||||
public enum MappingPlugin {
|
||||
public enum Plugin {
|
||||
DYNMAP("Dynmap"),
|
||||
BLUEMAP("BlueMap");
|
||||
|
||||
@NotNull
|
||||
public final String displayName;
|
||||
private final String displayName;
|
||||
|
||||
MappingPlugin(@NotNull String displayName) {
|
||||
Plugin(@NotNull String displayName) {
|
||||
this.displayName = displayName;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getDisplayName() {
|
||||
return displayName;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user