mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-02 06:28:49 +00:00
Add Dynmap support, revert to requiring Java 17
This commit is contained in:
1 parent
c22276908a
commit
a3cf54e776
10 files changed
+337
-15
No files matched your search
@@ -1,22 +1,26 @@
|
||||
package net.william278.huskhomes;
|
||||
|
||||
import net.william278.desertwell.UpdateChecker;
|
||||
import net.william278.desertwell.Version;
|
||||
import net.william278.huskhomes.command.CommandBase;
|
||||
import net.william278.huskhomes.config.Locales;
|
||||
import net.william278.huskhomes.config.Settings;
|
||||
import net.william278.huskhomes.config.Spawn;
|
||||
import net.william278.huskhomes.database.Database;
|
||||
import net.william278.huskhomes.hook.EconomyHook;
|
||||
import net.william278.huskhomes.hook.MapHook;
|
||||
import net.william278.huskhomes.hook.PluginHook;
|
||||
import net.william278.huskhomes.messenger.NetworkMessenger;
|
||||
import net.william278.huskhomes.player.OnlineUser;
|
||||
import net.william278.huskhomes.position.*;
|
||||
import net.william278.huskhomes.position.Location;
|
||||
import net.william278.huskhomes.position.SavedPositionManager;
|
||||
import net.william278.huskhomes.position.Server;
|
||||
import net.william278.huskhomes.position.World;
|
||||
import net.william278.huskhomes.random.RtpEngine;
|
||||
import net.william278.huskhomes.request.RequestManager;
|
||||
import net.william278.huskhomes.teleport.TeleportManager;
|
||||
import net.william278.huskhomes.util.Logger;
|
||||
import net.william278.huskhomes.util.Permission;
|
||||
import net.william278.desertwell.Version;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -172,6 +176,19 @@ public interface HuskHomes {
|
||||
@NotNull
|
||||
Set<PluginHook> getPluginHooks();
|
||||
|
||||
/**
|
||||
* Gets the {@link MapHook} being used to display public homes and warps on a web map, if there is one, and it is enabled
|
||||
*
|
||||
* @return the {@link MapHook} being used, if there is one, and it is enabled
|
||||
*/
|
||||
default Optional<MapHook> getMapHook() {
|
||||
return getSettings().doMapHook ? getPluginHooks()
|
||||
.stream()
|
||||
.filter(pluginHook -> pluginHook instanceof MapHook)
|
||||
.findFirst()
|
||||
.map(hook -> (MapHook) hook) : Optional.empty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform an economy check on the {@link OnlineUser}; returning {@code true} if it passes the check
|
||||
*
|
||||
@@ -203,7 +220,9 @@ public interface HuskHomes {
|
||||
* @param action the action to deduct the cost from if needed
|
||||
*/
|
||||
default void performEconomyTransaction(@NotNull OnlineUser player, @NotNull Settings.EconomyAction action) {
|
||||
if (!getSettings().economy) return;
|
||||
final Optional<Double> cost = getSettings().getEconomyCost(action).map(Math::abs);
|
||||
|
||||
if (cost.isPresent() && !player.hasPermission(Permission.BYPASS_ECONOMY_CHECKS.node)) {
|
||||
final Optional<EconomyHook> hook = getPluginHooks().stream().filter(pluginHook ->
|
||||
pluginHook instanceof EconomyHook).findFirst().map(pluginHook -> (EconomyHook) pluginHook);
|
||||
|
||||
@@ -217,6 +217,20 @@ public class Settings {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
// Mapping plugins
|
||||
@KeyPath("map_hook.enabled")
|
||||
public boolean doMapHook = false;
|
||||
|
||||
@KeyPath("map_hook.map_plugin")
|
||||
public MappingPlugin mappingPlugin = MappingPlugin.DYNMAP;
|
||||
|
||||
@KeyPath("map_hook.show_public_homes")
|
||||
public boolean publicHomesOnMap = true;
|
||||
|
||||
@KeyPath("map_hook.show_warps")
|
||||
public boolean warpsOnMap = true;
|
||||
|
||||
|
||||
// Disabled commands
|
||||
@KeyPath("disabled_commands")
|
||||
public List<String> disabledCommands = Collections.emptyList();
|
||||
@@ -319,4 +333,14 @@ public class Settings {
|
||||
REDIS
|
||||
}
|
||||
|
||||
/**
|
||||
* Identifies types of supported Map plugins
|
||||
*/
|
||||
public enum MappingPlugin {
|
||||
DYNMAP,
|
||||
SQUAREMAP,
|
||||
PL3XMAP,
|
||||
BLUEMAP
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
package net.william278.huskhomes.hook;
|
||||
|
||||
import net.william278.huskhomes.HuskHomes;
|
||||
import net.william278.huskhomes.position.Home;
|
||||
import net.william278.huskhomes.position.Warp;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
/**
|
||||
* A hook for a mapping plugin, such as Dynmap
|
||||
*/
|
||||
public abstract class MapHook extends PluginHook {
|
||||
|
||||
protected static final String PUBLIC_HOMES_MARKER_SET_ID = "huskhomes:public_homes";
|
||||
protected static final String WARPS_MARKER_SET_ID = "huskhomes:warps";
|
||||
|
||||
protected MapHook(@NotNull HuskHomes implementor, @NotNull String hookName) {
|
||||
super(implementor, hookName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean initialize() {
|
||||
initializeMap().thenRun(() -> {
|
||||
if (plugin.getSettings().publicHomesOnMap) {
|
||||
plugin.getDatabase().getPublicHomes().thenAccept(homes -> homes.stream()
|
||||
.filter(home -> plugin.getWorlds().stream().anyMatch(world -> world.uuid.equals(home.world.uuid)))
|
||||
.forEach(this::updateHome));
|
||||
}
|
||||
if (plugin.getSettings().warpsOnMap) {
|
||||
plugin.getDatabase().getWarps().thenAccept(warps -> warps
|
||||
.stream()
|
||||
.filter(warp -> plugin.getWorlds().stream().anyMatch(world -> world.uuid.equals(warp.world.uuid)))
|
||||
.forEach(this::updateWarp));
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare the map plugin for adding homes to
|
||||
*
|
||||
* @return a {@link CompletableFuture} that completes when the map plugin is ready
|
||||
*/
|
||||
protected abstract CompletableFuture<Void> initializeMap();
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
public abstract void updateHome(@NotNull Home home);
|
||||
|
||||
/**
|
||||
* Removes a home from the map
|
||||
*
|
||||
* @param home the home to remove
|
||||
*/
|
||||
public abstract void removeHome(@NotNull Home home);
|
||||
|
||||
/**
|
||||
* Update a warp, adding it to the map if it exists, or updating it on the map if it doesn't
|
||||
*
|
||||
* @param warp the warp to update
|
||||
*/
|
||||
public abstract void updateWarp(@NotNull Warp warp);
|
||||
|
||||
/**
|
||||
* Removes a warp from the map
|
||||
*
|
||||
* @param warp the warp to remove
|
||||
*/
|
||||
public abstract void removeWarp(@NotNull Warp warp);
|
||||
|
||||
}
|
||||
@@ -2,9 +2,11 @@ package net.william278.huskhomes.position;
|
||||
|
||||
import net.william278.huskhomes.Cache;
|
||||
import net.william278.huskhomes.database.Database;
|
||||
import net.william278.huskhomes.hook.MapHook;
|
||||
import net.william278.huskhomes.player.User;
|
||||
import net.william278.huskhomes.util.RegexUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Optional;
|
||||
@@ -25,6 +27,12 @@ public class SavedPositionManager {
|
||||
*/
|
||||
private final Cache cache;
|
||||
|
||||
/**
|
||||
* The {@link MapHook} used to update the map when a home or warp is set
|
||||
*/
|
||||
@Nullable
|
||||
private MapHook mapHook;
|
||||
|
||||
/**
|
||||
* Whether to allow unicode characters in SavedPosition names
|
||||
*/
|
||||
@@ -43,6 +51,15 @@ public class SavedPositionManager {
|
||||
this.allowUnicodeDescriptions = allowUnicodeDescriptions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the {@link MapHook} used to update the map when a home or warp is set
|
||||
*
|
||||
* @param mapHook the {@link MapHook} to set
|
||||
*/
|
||||
public void setMapHook(@NotNull MapHook mapHook) {
|
||||
this.mapHook = mapHook;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tries to create a {@link Home} for a {@link User} at the specified {@link Position} from supplied
|
||||
* {@link PositionMeta} data and add it to the database
|
||||
@@ -87,6 +104,9 @@ public class SavedPositionManager {
|
||||
});
|
||||
cache.privateHomeLists.remove(home.owner.uuid);
|
||||
cache.publicHomeLists.clear();
|
||||
if (mapHook != null) {
|
||||
mapHook.removeHome(home);
|
||||
}
|
||||
return true;
|
||||
}).join();
|
||||
}
|
||||
@@ -134,6 +154,9 @@ public class SavedPositionManager {
|
||||
}
|
||||
cache.privateHomeLists.remove(home.owner.uuid);
|
||||
cache.publicHomeLists.clear();
|
||||
if (home.isPublic && mapHook != null) {
|
||||
mapHook.updateHome(home);
|
||||
}
|
||||
return database.setHome(home).thenApply(value ->
|
||||
new SaveResult(SaveResult.ResultType.SUCCESS, Optional.of(home))).join();
|
||||
});
|
||||
@@ -174,6 +197,9 @@ public class SavedPositionManager {
|
||||
home.yaw = newPosition.yaw;
|
||||
home.world = newPosition.world;
|
||||
home.server = newPosition.server;
|
||||
if (home.isPublic && mapHook != null) {
|
||||
mapHook.updateHome(home);
|
||||
}
|
||||
return database.setHome(home).thenApply(ignored -> true);
|
||||
}
|
||||
|
||||
@@ -209,8 +235,16 @@ public class SavedPositionManager {
|
||||
if (isHomePublic) {
|
||||
cache.publicHomes.putIfAbsent(home.owner.username, new ArrayList<>());
|
||||
cache.publicHomes.get(home.owner.username).add(home.meta.name);
|
||||
} else if (cache.publicHomes.containsKey(home.owner.username)) {
|
||||
cache.publicHomes.get(home.owner.username).remove(home.meta.name);
|
||||
if (mapHook != null) {
|
||||
mapHook.updateHome(home);
|
||||
}
|
||||
} else {
|
||||
if (cache.publicHomes.containsKey(home.owner.username)) {
|
||||
cache.publicHomes.get(home.owner.username).remove(home.meta.name);
|
||||
}
|
||||
if (mapHook != null) {
|
||||
mapHook.removeHome(home);
|
||||
}
|
||||
}
|
||||
cache.privateHomeLists.remove(home.owner.uuid);
|
||||
cache.publicHomeLists.clear();
|
||||
@@ -233,6 +267,9 @@ public class SavedPositionManager {
|
||||
final Warp warp = new Warp(position, warpMeta);
|
||||
cache.warps.add(warp.meta.name);
|
||||
cache.warpLists.clear();
|
||||
if (mapHook != null) {
|
||||
mapHook.updateWarp(warp);
|
||||
}
|
||||
return database.setWarp(warp).thenApply(ignored ->
|
||||
new SaveResult(SaveResult.ResultType.SUCCESS, Optional.of(warp))).join();
|
||||
}
|
||||
@@ -254,6 +291,9 @@ public class SavedPositionManager {
|
||||
return database.deleteWarp(warp.uuid).thenApply(ignored -> {
|
||||
cache.warps.remove(warp.meta.name);
|
||||
cache.warpLists.clear();
|
||||
if (mapHook != null) {
|
||||
mapHook.removeWarp(warp);
|
||||
}
|
||||
return true;
|
||||
}).join();
|
||||
}
|
||||
@@ -299,6 +339,9 @@ public class SavedPositionManager {
|
||||
cache.warps.add(newWarpMeta.name);
|
||||
}
|
||||
cache.warpLists.clear();
|
||||
if (mapHook != null) {
|
||||
mapHook.updateWarp(warp);
|
||||
}
|
||||
return database.setWarp(warp).thenApply(value ->
|
||||
new SaveResult(SaveResult.ResultType.SUCCESS, Optional.of(warp))).join();
|
||||
});
|
||||
@@ -338,6 +381,9 @@ public class SavedPositionManager {
|
||||
warp.yaw = newPosition.yaw;
|
||||
warp.world = newPosition.world;
|
||||
warp.server = newPosition.server;
|
||||
if (mapHook != null) {
|
||||
mapHook.updateWarp(warp);
|
||||
}
|
||||
return database.setWarp(warp).thenApply(ignored -> true);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user