mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-01 14:38:48 +00:00
user manager bukkit
This commit is contained in:
1 parent
0b3245ef0c
commit
9fd13aecb4
4 files changed
+80
No files matched your search
@@ -1,6 +1,7 @@
|
||||
package net.draycia.carbon.api;
|
||||
|
||||
import net.draycia.carbon.api.events.CarbonEventHandler;
|
||||
import net.draycia.carbon.api.users.UserManager;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.event.HoverEvent;
|
||||
import net.kyori.adventure.text.event.HoverEventSource;
|
||||
@@ -15,6 +16,8 @@ public interface CarbonChat {
|
||||
|
||||
@NonNull CarbonEventHandler eventHandler();
|
||||
|
||||
@NonNull UserManager userManager();
|
||||
|
||||
@NonNull Component createItemHoverComponent(final @NonNull UUID uuid);
|
||||
|
||||
@NonNull Component createItemHoverComponent(
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
package net.draycia.carbon.api.users;
|
||||
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public interface UserManager {
|
||||
|
||||
@Nullable CarbonPlayer carbonPlayer(final @NonNull UUID uuid);
|
||||
|
||||
@Nullable CarbonPlayer carbonPlayer(final @NonNull String username);
|
||||
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
package net.draycia.carbon.bukkit;
|
||||
|
||||
import net.draycia.carbon.api.users.UserManager;
|
||||
import net.draycia.carbon.bukkit.users.MemoryUserManagerBukkit;
|
||||
import net.draycia.carbon.common.CarbonChatCommon;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
@@ -15,6 +17,13 @@ import static net.kyori.adventure.text.Component.translatable;
|
||||
|
||||
public final class CarbonChatBukkit extends CarbonChatCommon {
|
||||
|
||||
private UserManager userManager = new MemoryUserManagerBukkit();
|
||||
|
||||
@Override
|
||||
public @NonNull UserManager userManager() {
|
||||
return this.userManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull Component createItemHoverComponent(final @NonNull UUID uuid) {
|
||||
final Player player = Bukkit.getPlayer(uuid); // This is temporary (it's not)
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
package net.draycia.carbon.bukkit.users;
|
||||
|
||||
import net.draycia.carbon.api.users.CarbonPlayer;
|
||||
import net.draycia.carbon.api.users.UserManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* This class should not be used.
|
||||
* No data is persisted or saved.
|
||||
* This exists merely as a placeholder.
|
||||
*/
|
||||
public class MemoryUserManagerBukkit implements UserManager {
|
||||
|
||||
private Map<UUID, CarbonPlayer> users = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public @Nullable CarbonPlayer carbonPlayer(final @NonNull UUID uuid) {
|
||||
if (this.users.containsKey(uuid)) {
|
||||
return this.users.get(uuid);
|
||||
}
|
||||
|
||||
final Player player = Bukkit.getPlayer(uuid);
|
||||
|
||||
if (player == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final CarbonPlayer carbonPlayer = new CarbonPlayerBukkit(player.getName(),
|
||||
player.displayName(), player.getUniqueId());
|
||||
|
||||
this.users.put(uuid, carbonPlayer);
|
||||
|
||||
return carbonPlayer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable CarbonPlayer carbonPlayer(final @NonNull String username) {
|
||||
final Player player = Bukkit.getPlayer(username);
|
||||
|
||||
if (player == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new CarbonPlayerBukkit(player.getName(), player.displayName(), player.getUniqueId());
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user