Skip to content

Commit

Permalink
add predicte overload to delete entry
Browse files Browse the repository at this point in the history
  • Loading branch information
ghzdude committed Jun 30, 2024
1 parent 6a16bc1 commit 4e076ed
Showing 1 changed file with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.function.Predicate;

@SuppressWarnings("SameParameterValue")
public class VirtualRegistryBase extends WorldSavedData {
Expand Down Expand Up @@ -49,17 +50,23 @@ public static boolean hasEntry(@Nullable UUID owner, EntryTypes<?> type, String
* @param type Type of the registry to remove from
* @param name The name of the entry
*/
protected static void deleteEntry(@Nullable UUID owner, EntryTypes<?> type, String name) {
public static void deleteEntry(@Nullable UUID owner, EntryTypes<?> type, String name) {
var registry = getRegistry(owner);
if (registry.contains(type, name)) {
registry.deleteEntry(type, name);
} else {
GTLog.logger.warn("Attempted to delete {} entry {} of type {}, which does not exist",
owner == null ? "public" : String.format("private [%s]", owner),
name, type);
return;
}
GTLog.logger.warn("Attempted to delete {} entry {} of type {}, which does not exist",
owner == null ? "public" : String.format("private [%s]", owner), name, type);
}

public static <T extends VirtualEntry> void deleteEntry(@Nullable UUID owner, EntryTypes<T> type, String name, Predicate<T> shouldDelete) {
T entry = getEntry(owner, type, name);
if (shouldDelete.test(entry))
deleteEntry(owner, type, name);
}


public static Set<String> getEntryNames(UUID owner, EntryTypes<?> type) {
return getRegistry(owner).getEntryNames(type);
}
Expand Down

0 comments on commit 4e076ed

Please sign in to comment.