mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-01 14:38:48 +00:00
user manager sponge
This commit is contained in:
1 parent
9fd13aecb4
commit
475aeda0eb
4 files changed
+69
-3
No files matched your search
@@ -17,7 +17,7 @@ import static net.kyori.adventure.text.Component.translatable;
|
||||
|
||||
public final class CarbonChatBukkit extends CarbonChatCommon {
|
||||
|
||||
private UserManager userManager = new MemoryUserManagerBukkit();
|
||||
private final @NonNull UserManager userManager = new MemoryUserManagerBukkit();
|
||||
|
||||
@Override
|
||||
public @NonNull UserManager userManager() {
|
||||
|
||||
@@ -18,7 +18,7 @@ import java.util.UUID;
|
||||
*/
|
||||
public class MemoryUserManagerBukkit implements UserManager {
|
||||
|
||||
private Map<UUID, CarbonPlayer> users = new HashMap<>();
|
||||
private final @NonNull Map<UUID, @NonNull CarbonPlayer> users = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public @Nullable CarbonPlayer carbonPlayer(final @NonNull UUID uuid) {
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
package net.draycia.carbon.sponge;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import net.draycia.carbon.api.events.CarbonEventHandler;
|
||||
import net.draycia.carbon.api.users.UserManager;
|
||||
import net.draycia.carbon.common.CarbonChatCommon;
|
||||
import net.draycia.carbon.sponge.users.MemoryUserManagerSponge;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.spongepowered.api.Sponge;
|
||||
@@ -23,6 +24,8 @@ public class CarbonChatSponge extends CarbonChatCommon {
|
||||
private final PluginContainer pluginContainer;
|
||||
private static final int BSTATS_PLUGIN_ID = 11279;
|
||||
|
||||
private final @NonNull UserManager userManager = new MemoryUserManagerSponge();
|
||||
|
||||
@Inject
|
||||
public CarbonChatSponge(
|
||||
//final Metrics.@NonNull Factory metricsFactory,
|
||||
@@ -34,6 +37,11 @@ public class CarbonChatSponge extends CarbonChatCommon {
|
||||
//metricsFactory.make(BSTATS_PLUGIN_ID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull UserManager userManager() {
|
||||
return this.userManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull Component createItemHoverComponent(final @NonNull UUID uuid) {
|
||||
final ServerPlayer player = Sponge.server().player(uuid).orElse(null);
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
package net.draycia.carbon.sponge.users;
|
||||
|
||||
import net.draycia.carbon.api.users.CarbonPlayer;
|
||||
import net.draycia.carbon.api.users.UserManager;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import org.spongepowered.api.Sponge;
|
||||
import org.spongepowered.api.entity.living.player.server.ServerPlayer;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
import static net.kyori.adventure.text.Component.text;
|
||||
|
||||
/**
|
||||
* This class should not be used.
|
||||
* No data is persisted or saved.
|
||||
* This exists merely as a placeholder.
|
||||
*/
|
||||
public class MemoryUserManagerSponge implements UserManager {
|
||||
|
||||
private final @NonNull Map<UUID, @NonNull CarbonPlayer> users = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public @Nullable CarbonPlayer carbonPlayer(final @NonNull UUID uuid) {
|
||||
if (this.users.containsKey(uuid)) {
|
||||
return this.users.get(uuid);
|
||||
}
|
||||
|
||||
final Optional<ServerPlayer> player = Sponge.server().player(uuid);
|
||||
|
||||
if (player.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final CarbonPlayer carbonPlayer = new CarbonPlayerSponge(player.get().name(),
|
||||
text(player.get().name()), player.get().uniqueId());
|
||||
|
||||
this.users.put(uuid, carbonPlayer);
|
||||
|
||||
return carbonPlayer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable CarbonPlayer carbonPlayer(final @NonNull String username) {
|
||||
final Optional<ServerPlayer> player = Sponge.server().player(username);
|
||||
|
||||
if (player.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new CarbonPlayerSponge(player.get().name(), text(player.get().name()),
|
||||
player.get().uniqueId());
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user