diff --git a/bukkit/src/main/java/net/william278/huskclaims/listener/BukkitDropsListener.java b/bukkit/src/main/java/net/william278/huskclaims/listener/BukkitDropsListener.java index 2b56f4e0..089919f0 100644 --- a/bukkit/src/main/java/net/william278/huskclaims/listener/BukkitDropsListener.java +++ b/bukkit/src/main/java/net/william278/huskclaims/listener/BukkitDropsListener.java @@ -82,20 +82,20 @@ record BukkitGroundItem(@Nullable ItemStack stack) implements DropsProtector.Gro @Override public Optional getLockedBy(@NotNull HuskClaims plugin) { - if (stack() == null || !stack().hasItemMeta()) { + if (stack() == null || stack().getItemMeta() == null) { return Optional.empty(); } - final ItemMeta meta = Objects.requireNonNull(stack().getItemMeta(), "Couldn't get null ItemMeta"); - return getLockedBy(meta.getPersistentDataContainer(), plugin); + return getLockedBy(stack().getItemMeta().getPersistentDataContainer(), plugin); } @Override public void setLocked(@Nullable User user, @NotNull HuskClaims plugin) { - if (stack() == null || !stack().hasItemMeta()) { + if (stack() == null || stack().getItemMeta() == null) { return; } - final ItemMeta meta = Objects.requireNonNull(stack().getItemMeta(), "Couldn't set null ItemMeta"); + final ItemMeta meta = stack().getItemMeta(); setLockedBy(meta.getPersistentDataContainer(), user, plugin); + stack().setItemMeta(meta); } @NotNull diff --git a/common/build.gradle b/common/build.gradle index 61907295..17fcd23a 100644 --- a/common/build.gradle +++ b/common/build.gradle @@ -25,7 +25,7 @@ dependencies { compileOnly 'org.projectlombok:lombok:1.18.30' compileOnly 'net.luckperms:api:5.4' - compileOnly 'com.github.BlueMap-Minecraft:BlueMapAPI:2.6.2' + compileOnly 'com.github.BlueMap-Minecraft:BlueMapAPI:2.7.0' compileOnly 'us.dynmap:DynmapCoreAPI:3.6' compileOnly 'maven.modrinth:pl3xmap:1.20.4-484' compileOnly 'com.github.plan-player-analytics:Plan:5.6.2614' diff --git a/common/src/main/java/net/william278/huskclaims/claim/ClaimPruner.java b/common/src/main/java/net/william278/huskclaims/claim/ClaimPruner.java index 9d635916..6a7436ef 100644 --- a/common/src/main/java/net/william278/huskclaims/claim/ClaimPruner.java +++ b/common/src/main/java/net/william278/huskclaims/claim/ClaimPruner.java @@ -20,7 +20,6 @@ package net.william278.huskclaims.claim; import com.google.common.collect.Maps; -import com.google.common.collect.Sets; import net.william278.huskclaims.HuskClaims; import net.william278.huskclaims.database.Database; import net.william278.huskclaims.user.ClaimBlocksManager.ClaimBlockSource; @@ -32,7 +31,6 @@ import java.time.LocalTime; import java.time.temporal.ChronoUnit; -import java.util.Collection; import java.util.Map; import java.util.Set; import java.util.logging.Level; @@ -58,13 +56,13 @@ public interface ClaimPruner { */ @Blocking default void pruneClaims() { - if (!getSettings().isEnabled()) { + if (!getSettings().isEnabled() || getSettings().getInactiveDays() <= 0) { return; } // Determine who to prune final Set toPrune = getWorldsToPrune(); - final Set inactiveUsers = Sets.intersection(getInactiveUsers(), getAllClaimers(toPrune)); + final Set inactiveUsers = getInactiveUsers(); final LocalTime startTime = LocalTime.now(); getPlugin().log(Level.INFO, String.format("Pruning %s claim worlds with claims by %s inactive users...", toPrune.size(), inactiveUsers.size())); @@ -107,20 +105,14 @@ private void refundPrunedBlocks(@NotNull Map blocksToRefund) { @Unmodifiable default Set getWorldsToPrune() { return getPlugin().getClaimWorlds().entrySet().stream() - .filter((entry) -> getSettings().getExcludedWorlds().contains(entry.getKey())) + .filter((entry) -> !getSettings().getExcludedWorlds().contains(entry.getKey())) .map(Map.Entry::getValue).collect(Collectors.toSet()); } - @NotNull - @Unmodifiable - default Set getAllClaimers(@NotNull Set worlds) { - return worlds.stream().map(ClaimWorld::getClaimers) - .flatMap(Collection::stream).collect(Collectors.toSet()); - } - @NotNull default Set getInactiveUsers() { - return getPlugin().getDatabase().getInactiveUsers(getSettings().getInactiveDays()).stream() + final long days = Math.max(1, getSettings().getInactiveDays()); + return getPlugin().getDatabase().getInactiveUsers(days).stream() .map(SavedUser::getUser) .filter(user -> !(getSettings().getExcludedUsers().contains(user.getUuid().toString()) || getSettings().getExcludedUsers().contains(user.getName()))) diff --git a/common/src/main/java/net/william278/huskclaims/claim/ClaimWorld.java b/common/src/main/java/net/william278/huskclaims/claim/ClaimWorld.java index b764ec40..015bbc4d 100644 --- a/common/src/main/java/net/william278/huskclaims/claim/ClaimWorld.java +++ b/common/src/main/java/net/william278/huskclaims/claim/ClaimWorld.java @@ -38,12 +38,10 @@ import net.william278.huskclaims.user.User; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import org.jetbrains.annotations.Unmodifiable; import java.util.*; import java.util.concurrent.ConcurrentMap; import java.util.concurrent.CopyOnWriteArraySet; -import java.util.stream.Collectors; @Getter @NoArgsConstructor(access = AccessLevel.PRIVATE) @@ -109,14 +107,6 @@ public List getClaimsByUser(@Nullable UUID uuid) { .orElse(uuid == null)).toList(); } - @NotNull - @Unmodifiable - public Set getClaimers() { - return claims.stream() - .map(c -> c.getOwner().flatMap(this::getUser).orElse(null)) - .filter(Objects::nonNull).collect(Collectors.toSet()); - } - @NotNull public List getAdminClaims() { return getClaimsByUser(null); diff --git a/common/src/main/java/net/william278/huskclaims/moderation/DropsListener.java b/common/src/main/java/net/william278/huskclaims/moderation/DropsListener.java index 4c05541c..46548985 100644 --- a/common/src/main/java/net/william278/huskclaims/moderation/DropsListener.java +++ b/common/src/main/java/net/william278/huskclaims/moderation/DropsListener.java @@ -22,10 +22,12 @@ import net.william278.huskclaims.HuskClaims; import net.william278.huskclaims.config.Settings; import net.william278.huskclaims.user.OnlineUser; +import net.william278.huskclaims.user.User; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.Collection; +import java.util.Optional; public interface DropsListener { @@ -42,7 +44,11 @@ default boolean cancelItemPickup(@Nullable OnlineUser pickerUpper, @NotNull Drop if (!getSettings().isLockItems() || pickerUpper == null) { return false; } - if (item.isLockedBy(pickerUpper, getPlugin())) { + final Optional locker = item.getLockedBy(getPlugin()); + if (locker.isEmpty()) { + return false; + } + if (locker.get().equals(pickerUpper)) { item.unlock(getPlugin()); return false; } diff --git a/common/src/main/java/net/william278/huskclaims/moderation/DropsProtector.java b/common/src/main/java/net/william278/huskclaims/moderation/DropsProtector.java index f3d92296..3f21d1fd 100644 --- a/common/src/main/java/net/william278/huskclaims/moderation/DropsProtector.java +++ b/common/src/main/java/net/william278/huskclaims/moderation/DropsProtector.java @@ -40,7 +40,8 @@ default void lockDrops(@NotNull Collection drops, @NotNull } default long unlockDrops(@NotNull User user) { - return getTrackedDrops().stream().filter(a -> a.isLockedBy(user, getPlugin())) + return getTrackedDrops().stream() + .filter(a -> a.isLockedBy(user, getPlugin())) .peek(g -> g.unlock(getPlugin())) .peek(getTrackedDrops()::remove) .count(); @@ -64,7 +65,8 @@ default void unlock(@NotNull HuskClaims plugin) { } default boolean isLockedBy(@NotNull User user, @NotNull HuskClaims plugin) { - return getLockedBy(plugin).isPresent() && getLockedBy(plugin).get().equals(user); + final Optional lockedBy = getLockedBy(plugin); + return lockedBy.isPresent() && lockedBy.get().equals(user); } }