mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-04 06:28:49 +00:00
Fix hook retrieval not working properly
This commit is contained in:
1 parent
c316d290c5
commit
42adc13425
6 files changed
+66
-86
No files matched your search
@@ -68,7 +68,7 @@ public class BukkitHuskHomes extends JavaPlugin implements HuskHomes, BukkitTask
|
|||||||
private RandomTeleportEngine randomTeleportEngine;
|
private RandomTeleportEngine randomTeleportEngine;
|
||||||
private Spawn serverSpawn;
|
private Spawn serverSpawn;
|
||||||
private UnsafeBlocks unsafeBlocks;
|
private UnsafeBlocks unsafeBlocks;
|
||||||
private Set<Hook> hooks;
|
private List<Hook> hooks;
|
||||||
private List<Command> commands;
|
private List<Command> commands;
|
||||||
private Map<String, List<String>> globalPlayerList;
|
private Map<String, List<String>> globalPlayerList;
|
||||||
private Set<UUID> currentlyOnWarmup;
|
private Set<UUID> currentlyOnWarmup;
|
||||||
@@ -168,7 +168,7 @@ public class BukkitHuskHomes extends JavaPlugin implements HuskHomes, BukkitTask
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void loadHooks() {
|
private void loadHooks() {
|
||||||
this.hooks = new HashSet<>();
|
this.hooks = new ArrayList<>();
|
||||||
if (settings.doEconomy()) {
|
if (settings.doEconomy()) {
|
||||||
if (Bukkit.getPluginManager().getPlugin("RedisEconomy") != null) {
|
if (Bukkit.getPluginManager().getPlugin("RedisEconomy") != null) {
|
||||||
hooks.add(new RedisEconomyHook(this));
|
hooks.add(new RedisEconomyHook(this));
|
||||||
@@ -314,7 +314,7 @@ public class BukkitHuskHomes extends JavaPlugin implements HuskHomes, BukkitTask
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
@NotNull
|
@NotNull
|
||||||
public Set<Hook> getPluginHooks() {
|
public List<Hook> getHooks() {
|
||||||
return hooks;
|
return hooks;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -166,38 +166,21 @@ public interface HuskHomes extends TaskRunner, EventDispatcher {
|
|||||||
* @return the {@link Set} of active {@link Hook}s
|
* @return the {@link Set} of active {@link Hook}s
|
||||||
*/
|
*/
|
||||||
@NotNull
|
@NotNull
|
||||||
Set<Hook> getPluginHooks();
|
List<Hook> getHooks();
|
||||||
|
|
||||||
/**
|
default <T extends Hook> Optional<T> getHook(@NotNull Class<T> hookClass) {
|
||||||
* Finds the {@link Hook} of the given class instance from the set of active {@link Hook}s
|
return getHooks().stream()
|
||||||
*
|
.filter(hook -> hookClass.isAssignableFrom(hook.getClass()))
|
||||||
* @param hookClass the class of the {@link Hook} to get
|
.map(hookClass::cast)
|
||||||
* @param <H> the type of the {@link Hook}
|
.findFirst();
|
||||||
* @return the {@link Hook} instance, or an empty {@link Optional} if not found
|
|
||||||
*/
|
|
||||||
default <H extends Hook> Optional<H> getHook(@NotNull Class<H> hookClass) {
|
|
||||||
return getPluginHooks().stream()
|
|
||||||
.filter(hook -> hook.getClass() == hookClass)
|
|
||||||
.findFirst()
|
|
||||||
.map(hookClass::cast);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 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} optionally being used
|
|
||||||
*/
|
|
||||||
default Optional<MapHook> getMapHook() {
|
|
||||||
return getSettings().doMapHook() ? getHook(MapHook.class) : Optional.empty();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the {@link EconomyHook} being used to charge players for commands, if there is one, and it is enabled
|
|
||||||
*
|
|
||||||
* @return the {@link EconomyHook} optionally being used
|
|
||||||
*/
|
|
||||||
default Optional<EconomyHook> getEconomyHook() {
|
default Optional<EconomyHook> getEconomyHook() {
|
||||||
return getSettings().doEconomy() ? getHook(EconomyHook.class) : Optional.empty();
|
return getHook(EconomyHook.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
default Optional<MapHook> getMapHook() {
|
||||||
|
return getHook(MapHook.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -483,11 +483,11 @@ public class Settings {
|
|||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isPublicHomesOnMap() {
|
public boolean doPublicHomesOnMap() {
|
||||||
return publicHomesOnMap;
|
return publicHomesOnMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isWarpsOnMap() {
|
public boolean doWarpsOnMap() {
|
||||||
return warpsOnMap;
|
return warpsOnMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import net.william278.huskhomes.position.Home;
|
|||||||
import net.william278.huskhomes.position.Warp;
|
import net.william278.huskhomes.position.Warp;
|
||||||
import net.william278.huskhomes.position.World;
|
import net.william278.huskhomes.position.World;
|
||||||
import net.william278.huskhomes.user.User;
|
import net.william278.huskhomes.user.User;
|
||||||
|
import net.william278.huskhomes.util.ThrowingConsumer;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
@@ -21,7 +22,6 @@ import java.nio.file.Files;
|
|||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -43,7 +43,7 @@ public class BlueMapHook extends MapHook {
|
|||||||
this.warpsMarkerSets = new HashMap<>();
|
this.warpsMarkerSets = new HashMap<>();
|
||||||
|
|
||||||
for (World world : plugin.getWorlds()) {
|
for (World world : plugin.getWorlds()) {
|
||||||
getMapWorld(world).ifPresent(mapWorld -> {
|
this.editMapWorld(world, (mapWorld -> {
|
||||||
final MarkerSet publicHomeMarkers = MarkerSet.builder().label(getPublicHomesMarkerSetName()).build();
|
final MarkerSet publicHomeMarkers = MarkerSet.builder().label(getPublicHomesMarkerSetName()).build();
|
||||||
final MarkerSet warpsMarkers = MarkerSet.builder().label(getWarpsMarkerSetName()).build();
|
final MarkerSet warpsMarkers = MarkerSet.builder().label(getWarpsMarkerSetName()).build();
|
||||||
|
|
||||||
@@ -54,7 +54,7 @@ public class BlueMapHook extends MapHook {
|
|||||||
|
|
||||||
publicHomesMarkerSets.put(world.getName(), publicHomeMarkers);
|
publicHomesMarkerSets.put(world.getName(), publicHomeMarkers);
|
||||||
warpsMarkerSets.put(world.getName(), warpsMarkers);
|
warpsMarkerSets.put(world.getName(), warpsMarkers);
|
||||||
});
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
this.populateMap();
|
this.populateMap();
|
||||||
@@ -67,33 +67,30 @@ public class BlueMapHook extends MapHook {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
getPublicHomesMarkerSet(home.getWorld())
|
this.editPublicHomesMarkerSet(home.getWorld(), (markerSet -> {
|
||||||
.ifPresent(markerSet -> {
|
final String markerId = home.getOwner().getUuid() + ":" + home.getUuid();
|
||||||
final String markerId = home.getOwner().getUuid() + ":" + home.getUuid();
|
markerSet.remove(markerId);
|
||||||
markerSet.remove(markerId);
|
markerSet.put(markerId, POIMarker.builder()
|
||||||
markerSet.put(markerId, POIMarker.builder()
|
.label("/phome " + home.getOwner().getUsername() + "." + home.getName())
|
||||||
.label("/phome " + home.getOwner().getUsername() + "." + home.getName())
|
.position(home.getX(), home.getY(), home.getZ())
|
||||||
.position(home.getX(), home.getY(), home.getZ())
|
.maxDistance(5000)
|
||||||
.maxDistance(5000)
|
.icon(getIcon(PUBLIC_HOME_MARKER_IMAGE_NAME), 25, 25)
|
||||||
.icon(getIcon(PUBLIC_HOME_MARKER_IMAGE_NAME), 25, 25)
|
.build());
|
||||||
.build());
|
}));
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removeHome(@NotNull Home home) {
|
public void removeHome(@NotNull Home home) {
|
||||||
getPublicHomesMarkerSet(home.getWorld())
|
this.editPublicHomesMarkerSet(home.getWorld(), markerSet -> markerSet
|
||||||
.ifPresent(markerSet -> markerSet.remove(home.getOwner().getUuid() + ":" + home.getUuid()));
|
.remove(home.getOwner().getUuid() + ":" + home.getUuid()));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void clearHomes(@NotNull User user) {
|
public void clearHomes(@NotNull User user) {
|
||||||
if (publicHomesMarkerSets != null) {
|
if (publicHomesMarkerSets != null) {
|
||||||
for (MarkerSet markerSet : publicHomesMarkerSets.values()) {
|
publicHomesMarkerSets.values().forEach(markerSet -> markerSet.getMarkers().keySet()
|
||||||
markerSet.getMarkers().keySet()
|
.removeIf(markerId -> markerId.startsWith(user.getUuid().toString())));
|
||||||
.removeIf(markerId -> markerId.startsWith(user.getUuid().toString()));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -103,32 +100,27 @@ public class BlueMapHook extends MapHook {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
getWarpsMarkerSet(warp.getWorld())
|
this.editWarpsMarkerSet(warp.getWorld(), (markerSet -> {
|
||||||
.ifPresent(markerSet -> {
|
final String markerId = warp.getUuid().toString();
|
||||||
final String markerId = warp.getUuid().toString();
|
markerSet.remove(markerId);
|
||||||
markerSet.remove(markerId);
|
markerSet.put(markerId, POIMarker.builder()
|
||||||
markerSet.put(markerId, POIMarker.builder()
|
.label("/warp " + warp.getName())
|
||||||
.label("/warp " + warp.getName())
|
.position(warp.getX(), warp.getY(), warp.getZ())
|
||||||
.position(warp.getX(), warp.getY(), warp.getZ())
|
.maxDistance(5000)
|
||||||
.maxDistance(5000)
|
.icon(getIcon(WARP_MARKER_IMAGE_NAME), 25, 25)
|
||||||
.icon(getIcon(WARP_MARKER_IMAGE_NAME), 25, 25)
|
.build());
|
||||||
.build());
|
}));
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removeWarp(@NotNull Warp warp) {
|
public void removeWarp(@NotNull Warp warp) {
|
||||||
getWarpsMarkerSet(warp.getWorld())
|
editWarpsMarkerSet(warp.getWorld(), markerSet -> markerSet.remove(warp.getUuid().toString()));
|
||||||
.ifPresent(markerSet -> markerSet.remove(warp.getUuid().toString()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void clearWarps() {
|
public void clearWarps() {
|
||||||
if (warpsMarkerSets != null) {
|
if (warpsMarkerSets != null) {
|
||||||
for (MarkerSet markerSet : warpsMarkerSets.values()) {
|
warpsMarkerSets.values().forEach(markerSet -> markerSet.getMarkers().clear());
|
||||||
markerSet.getMarkers().keySet()
|
|
||||||
.forEach(markerSet::remove);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -157,19 +149,24 @@ public class BlueMapHook extends MapHook {
|
|||||||
}).orElse(null);
|
}).orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
private void editPublicHomesMarkerSet(@NotNull World world, @NotNull ThrowingConsumer<MarkerSet> editor) {
|
||||||
private Optional<MarkerSet> getPublicHomesMarkerSet(@NotNull World world) {
|
editMapWorld(world, (mapWorld -> {
|
||||||
return publicHomesMarkerSets == null ? Optional.empty() : Optional.ofNullable(publicHomesMarkerSets.get(world.getName()));
|
if (publicHomesMarkerSets != null) {
|
||||||
|
editor.accept(publicHomesMarkerSets.get(world.getName()));
|
||||||
|
}
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
private void editWarpsMarkerSet(@NotNull World world, @NotNull ThrowingConsumer<MarkerSet> editor) {
|
||||||
private Optional<MarkerSet> getWarpsMarkerSet(@NotNull World world) {
|
editMapWorld(world, (mapWorld -> {
|
||||||
return warpsMarkerSets == null ? Optional.empty() : Optional.ofNullable(warpsMarkerSets.get(world.getName()));
|
if (warpsMarkerSets != null) {
|
||||||
|
editor.accept(warpsMarkerSets.get(world.getName()));
|
||||||
|
}
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
private void editMapWorld(@NotNull World world, @NotNull ThrowingConsumer<BlueMapWorld> editor) {
|
||||||
private Optional<BlueMapWorld> getMapWorld(@NotNull World world) {
|
BlueMapAPI.getInstance().flatMap(api -> api.getWorld(world.getName())).ifPresent(editor);
|
||||||
return BlueMapAPI.getInstance().flatMap(api -> api.getWorld(world.getName()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -40,12 +40,12 @@ public class DynmapHook extends MapHook {
|
|||||||
public void apiEnabled(@NotNull DynmapCommonAPI dynmapCommonAPI) {
|
public void apiEnabled(@NotNull DynmapCommonAPI dynmapCommonAPI) {
|
||||||
dynmapApi = dynmapCommonAPI;
|
dynmapApi = dynmapCommonAPI;
|
||||||
|
|
||||||
if (plugin.getSettings().isPublicHomesOnMap()) {
|
if (plugin.getSettings().doPublicHomesOnMap()) {
|
||||||
getMarkerIcon(PUBLIC_HOME_MARKER_IMAGE_NAME).orElseThrow();
|
getMarkerIcon(PUBLIC_HOME_MARKER_IMAGE_NAME).orElseThrow();
|
||||||
dynmapApi.getMarkerAPI().createMarkerSet(getPublicHomesKey(),
|
dynmapApi.getMarkerAPI().createMarkerSet(getPublicHomesKey(),
|
||||||
getPublicHomesMarkerSetName(), dynmapApi.getMarkerAPI().getMarkerIcons(), false);
|
getPublicHomesMarkerSetName(), dynmapApi.getMarkerAPI().getMarkerIcons(), false);
|
||||||
}
|
}
|
||||||
if (plugin.getSettings().isWarpsOnMap()) {
|
if (plugin.getSettings().doWarpsOnMap()) {
|
||||||
getMarkerIcon(WARP_MARKER_IMAGE_NAME).orElseThrow();
|
getMarkerIcon(WARP_MARKER_IMAGE_NAME).orElseThrow();
|
||||||
dynmapApi.getMarkerAPI().createMarkerSet(getWarpsKey(),
|
dynmapApi.getMarkerAPI().createMarkerSet(getWarpsKey(),
|
||||||
getWarpsMarkerSetName(), dynmapApi.getMarkerAPI().getMarkerIcons(), false);
|
getWarpsMarkerSetName(), dynmapApi.getMarkerAPI().getMarkerIcons(), false);
|
||||||
|
|||||||
@@ -23,12 +23,12 @@ public abstract class MapHook extends Hook {
|
|||||||
* Populate the map with public homes and warps
|
* Populate the map with public homes and warps
|
||||||
*/
|
*/
|
||||||
protected void populateMap() {
|
protected void populateMap() {
|
||||||
if (plugin.getSettings().isPublicHomesOnMap()) {
|
if (plugin.getSettings().doPublicHomesOnMap()) {
|
||||||
plugin.getDatabase()
|
plugin.getDatabase()
|
||||||
.getLocalPublicHomes(plugin)
|
.getLocalPublicHomes(plugin)
|
||||||
.forEach(this::updateHome);
|
.forEach(this::updateHome);
|
||||||
}
|
}
|
||||||
if (plugin.getSettings().isWarpsOnMap()) {
|
if (plugin.getSettings().doWarpsOnMap()) {
|
||||||
plugin.getDatabase()
|
plugin.getDatabase()
|
||||||
.getLocalWarps(plugin)
|
.getLocalWarps(plugin)
|
||||||
.forEach(this::updateWarp);
|
.forEach(this::updateWarp);
|
||||||
@@ -83,14 +83,14 @@ public abstract class MapHook extends Hook {
|
|||||||
*/
|
*/
|
||||||
@SuppressWarnings("BooleanMethodIsAlwaysInverted")
|
@SuppressWarnings("BooleanMethodIsAlwaysInverted")
|
||||||
protected final boolean isValidPosition(@NotNull SavedPosition position) {
|
protected final boolean isValidPosition(@NotNull SavedPosition position) {
|
||||||
if (position instanceof Warp && !plugin.getSettings().isWarpsOnMap()) {
|
if (position instanceof Warp && !plugin.getSettings().doWarpsOnMap()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (position instanceof Home && !plugin.getSettings().isPublicHomesOnMap()) {
|
if (position instanceof Home && !plugin.getSettings().doPublicHomesOnMap()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return position.getServer().equals(plugin.getServerName());
|
return !plugin.getSettings().isCrossServer() || position.getServer().equals(plugin.getServerName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
|
|||||||
Reference in new issue
Block a user