Refactor user stuff and start on channel stuff (#153)

Co-authored-by: Riley Park <[email protected]>
Co-authored-by: broccolai <[email protected]>
Co-authored-by: Jason Penilla <[email protected]>
This commit is contained in:
authored and GitHub committed 2021-07-01 15:53:17 -07:00
1 parent 715ba92264
commit 8854891e26
56 files changed
+1624 -574

No files matched your search

@@ -1,6 +1,7 @@
package net.draycia.carbon.api;
import java.nio.file.Path;
import net.draycia.carbon.api.channels.ChannelRegistry;
import net.draycia.carbon.api.events.CarbonEventHandler;
import org.apache.logging.log4j.Logger;
import org.checkerframework.checker.nullness.qual.NonNull;
@@ -49,4 +50,12 @@ public interface CarbonChat {
*/
CarbonServer server();
/**
* The registry that channels are registered to.
*
* @return the channel registry
* @since 2.0.0
*/
ChannelRegistry channelRegistry();
}
@@ -1,7 +1,9 @@
package net.draycia.carbon.api;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import net.draycia.carbon.api.users.CarbonPlayer;
import net.draycia.carbon.api.users.ComponentPlayerResult;
import net.kyori.adventure.audience.Audience;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
@@ -35,18 +37,36 @@ public interface CarbonServer extends Audience {
* Obtains a {@link CarbonPlayer} instance for the specified uuid.
*
* @param uuid the player's uuid
* @return the player
* @return the result
* @since 2.0.0
*/
@Nullable CarbonPlayer player(final UUID uuid);
CompletableFuture<ComponentPlayerResult> player(final UUID uuid);
/**
* Obtains a {@link CarbonPlayer} instance for the specified username.
*
* @param username the player's username
* @return the player
* @return the result
* @since 2.0.0
*/
@Nullable CarbonPlayer player(final String username);
CompletableFuture<ComponentPlayerResult> player(final String username);
/**
* Obtains the desired user's UUID.
*
* @param username the user's username
* @return the user's UUID
* @since 2.0.0
*/
CompletableFuture<@Nullable UUID> resolveUUID(final String username);
/**
* Obtains the desired player's name.
*
* @param uuid the user's UUID
* @return the user's name
* @since 2.0.0
*/
CompletableFuture<@Nullable String> resolveName(final UUID uuid);
}
@@ -0,0 +1,12 @@
package net.draycia.carbon.api.channels;
import net.draycia.carbon.api.util.DefaultedKeyValueRegistry;
import net.kyori.adventure.key.Key;
/**
* Registry for chat channels.
*
* @since 2.0.0
*/
public interface ChannelRegistry extends DefaultedKeyValueRegistry<Key, ChatChannel> {
}
@@ -2,6 +2,7 @@ package net.draycia.carbon.api.channels;
import java.util.List;
import java.util.Set;
import java.util.function.Supplier;
import net.draycia.carbon.api.users.CarbonPlayer;
import net.draycia.carbon.api.util.ChatComponentRenderer;
import net.kyori.adventure.audience.Audience;
@@ -88,6 +89,18 @@ public interface ChatChannel extends Keyed, ChatComponentRenderer {
return new ChannelPermissionResult(false, reason);
}
// TODO: redo this / reconsider this
public static ChannelPermissionResult allowedIf(
final Component reason,
final Supplier<Boolean> supplier
) {
if (supplier.get()) {
return ALLOWED;
} else {
return denied(reason);
}
}
}
}
@@ -1,12 +1,15 @@
package net.draycia.carbon.api.events;
import net.kyori.adventure.text.Component;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.framework.qual.DefaultQualifier;
/**
* Represents a {@link CarbonEvent} that has a result.
*
* @since 2.0.0
*/
@DefaultQualifier(NonNull.class)
public interface ResultedCarbonEvent<R extends ResultedCarbonEvent.Result> extends CarbonEvent {
/**
@@ -42,7 +45,7 @@ public interface ResultedCarbonEvent<R extends ResultedCarbonEvent.Result> exten
/**
* The reason of the result.<br>
* Typically only present if allowed is false.
* Typically empty unless allowed is false.
*
* @return the reason of the result
* @since 2.0.0
@@ -1,5 +1,6 @@
package net.draycia.carbon.api.users;
import java.util.List;
import java.util.Locale;
import java.util.UUID;
import net.draycia.carbon.api.channels.ChatChannel;
@@ -92,4 +93,20 @@ public interface CarbonPlayer extends Audience, Identified {
*/
boolean hasPermission(final String permission);
/**
* Returns the player's primary group.
*
* @return the player's primary group
* @since 2.0.0
*/
String primaryGroup();
/**
* Returns the complete list of groups the player is in.
*
* @return the groups the player is in
* @since 2.0.0
*/
List<String> groups();
}
@@ -0,0 +1,15 @@
package net.draycia.carbon.api.users;
import net.kyori.adventure.text.Component;
import org.checkerframework.checker.nullness.qual.Nullable;
/**
* The result of a player data operation.
*
* @param player the {@link CarbonPlayer}, or null if unsuccessful
* @param reason the reason of the result, typically empty unless {@link #player} is null
* @since 2.0.0
*/
public record ComponentPlayerResult(@Nullable CarbonPlayer player, Component reason) {
}
@@ -1,12 +1,12 @@
package net.draycia.carbon.api.users;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.checkerframework.framework.qual.DefaultQualifier;
/**
* Manager used to load and obtain {@link CarbonPlayer CarbonPlayers}.
* Manager used to load/obtain and save {@link CarbonPlayer CarbonPlayers}.
*
* @since 2.0.0
*/
@@ -16,19 +16,19 @@ public interface UserManager {
/**
* Loads and returns a {@link CarbonPlayer} with the given {@link UUID}.
*
* @param uuid The player's UUID.
* @return The {@link CarbonPlayer}, or null if the player doesn't exist.
* @param uuid the player's uuid
* @return the result
* @since 2.0.0
*/
@Nullable CarbonPlayer carbonPlayer(final UUID uuid);
CompletableFuture<ComponentPlayerResult> carbonPlayer(final UUID uuid);
/**
* Loads and returns a {@link CarbonPlayer} with the given username.
* Saves the {@link CarbonPlayer} and returns the result.
*
* @param username The player's username.
* @return The {@link CarbonPlayer}, or null if the player doesn't exist.
* @param player the player to save
* @return the result
* @since 2.0.0
*/
@Nullable CarbonPlayer carbonPlayer(final String username);
CompletableFuture<ComponentPlayerResult> savePlayer(final CarbonPlayer player);
}
@@ -26,7 +26,7 @@ public interface KeyedRenderer extends Keyed, ChatComponentRenderer {
* @return the keyed renderer
* @since 2.0.0
*/
static KeyedRenderer keyedRenderer(final Key key, ChatComponentRenderer renderer) {
static KeyedRenderer keyedRenderer(final Key key, final ChatComponentRenderer renderer) {
return new Impl(key, renderer);
}