Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
WiIIiam278 committed Mar 7, 2024
2 parents d0c6d54 + 8a883c1 commit 31ac9ce
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,20 +82,20 @@ record BukkitGroundItem(@Nullable ItemStack stack) implements DropsProtector.Gro

@Override
public Optional<User> 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
Expand Down
2 changes: 1 addition & 1 deletion common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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<ClaimWorld> toPrune = getWorldsToPrune();
final Set<User> inactiveUsers = Sets.intersection(getInactiveUsers(), getAllClaimers(toPrune));
final Set<User> 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()));
Expand Down Expand Up @@ -107,20 +105,14 @@ private void refundPrunedBlocks(@NotNull Map<User, Long> blocksToRefund) {
@Unmodifiable
default Set<ClaimWorld> 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<User> getAllClaimers(@NotNull Set<ClaimWorld> worlds) {
return worlds.stream().map(ClaimWorld::getClaimers)
.flatMap(Collection::stream).collect(Collectors.toSet());
}

@NotNull
default Set<User> 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())))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -109,14 +107,6 @@ public List<Claim> getClaimsByUser(@Nullable UUID uuid) {
.orElse(uuid == null)).toList();
}

@NotNull
@Unmodifiable
public Set<User> getClaimers() {
return claims.stream()
.map(c -> c.getOwner().flatMap(this::getUser).orElse(null))
.filter(Objects::nonNull).collect(Collectors.toSet());
}

@NotNull
public List<Claim> getAdminClaims() {
return getClaimsByUser(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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<User> locker = item.getLockedBy(getPlugin());
if (locker.isEmpty()) {
return false;
}
if (locker.get().equals(pickerUpper)) {
item.unlock(getPlugin());
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ default void lockDrops(@NotNull Collection<? extends GroundItem> 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();
Expand All @@ -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<User> lockedBy = getLockedBy(plugin);
return lockedBy.isPresent() && lockedBy.get().equals(user);
}

}
Expand Down

0 comments on commit 31ac9ce

Please sign in to comment.