Skip to content

Commit

Permalink
fix: issues with the global user list
Browse files Browse the repository at this point in the history
  • Loading branch information
WiIIiam278 committed Feb 4, 2024
1 parent 7f7ea8f commit 8e8e112
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
import java.util.logging.Level;
import java.util.stream.Collectors;

public interface HuskTowns extends Task.Supplier, ConfigProvider, EventDispatcher, GlobalUserList,
public interface HuskTowns extends Task.Supplier, ConfigProvider, EventDispatcher, UserListProvider,
AdvancementProvider, DataPruner, GsonProvider, OperationHandler, UserListener {

int SPIGOT_RESOURCE_ID = 92672;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,35 @@

package net.william278.husktowns.util;

import com.google.common.collect.Multimap;
import net.william278.husktowns.HuskTowns;
import net.william278.husktowns.user.User;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;

import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.stream.Stream;

public interface GlobalUserList {
public interface UserListProvider {

@NotNull
Multimap<String, User> getGlobalUserList();
Map<String, List<User>> getGlobalUserList();

@NotNull
default List<User> getUserList() {
return getGlobalUserList().values().stream().toList();
return Stream.concat(
getGlobalUserList().values().stream().flatMap(Collection::stream),
getPlugin().getOnlineUsers().stream()
).distinct().sorted().toList();
}

default void setUserList(@NotNull String server, @NotNull List<User> players) {
getGlobalUserList().replaceValues(server, players);
getGlobalUserList().values().forEach(list -> {
list.removeAll(players);
list.removeAll(getPlugin().getOnlineUsers());
});
getGlobalUserList().put(server, players);
}

@NotNull
Expand Down

0 comments on commit 8e8e112

Please sign in to comment.