Start command refactor

This commit is contained in:
William278 committed 2023-03-05 19:10:19 +00:00
1 parent 39e0b25d46
commit 3e27f7c5b1
57 files changed
+728 -384

No files matched your search

@@ -0,0 +1,23 @@
package net.william278.huskhomes.user;
import de.themoep.minedown.adventure.MineDown;
import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.text.Component;
import org.jetbrains.annotations.NotNull;
public interface CommandUser {
@NotNull
Audience getAudience();
boolean hasPermission(@NotNull String permission);
default void sendMessage(@NotNull Component component) {
getAudience().sendMessage(component);
}
default void sendMessage(@NotNull MineDown mineDown) {
this.sendMessage(mineDown.toComponent());
}
}
@@ -0,0 +1,25 @@
package net.william278.huskhomes.user;
import net.kyori.adventure.audience.Audience;
import org.jetbrains.annotations.NotNull;
public final class ConsoleUser implements CommandUser {
@NotNull
private final Audience audience;
public ConsoleUser(@NotNull Audience console) {
this.audience = console;
}
@Override
@NotNull
public Audience getAudience() {
return audience;
}
@Override
public boolean hasPermission(@NotNull String permission) {
return true;
}
}
@@ -21,7 +21,7 @@ import java.util.concurrent.CompletableFuture;
/**
* A cross-platform representation of a logged-in {@link User}
*/
public abstract class OnlineUser extends User implements Teleportable {
public abstract class OnlineUser extends User implements Teleportable, CommandUser {
public OnlineUser(@NotNull UUID uuid, @NotNull String username) {
super(uuid, username);
@@ -134,7 +134,7 @@ public abstract class OnlineUser extends User implements Teleportable {
* @return the adventure {@link Audience} for this player
*/
@NotNull
protected abstract Audience getAudience();
public abstract Audience getAudience();
/**
* Teleport a player to the specified local {@link Location}
@@ -8,13 +8,14 @@ import java.util.UUID;
/**
* Represents data about a player on the server
*/
public record UserData(@NotNull User user, int homeSlots, boolean ignoringTeleports, @NotNull Instant rtpCooldown) {
public record SavedUser(@NotNull User user, int homeSlots, boolean ignoringTeleports, @NotNull Instant rtpCooldown) {
@NotNull
public UUID getUserUuid() {
return user.getUuid();
}
@NotNull
public String getUsername() {
return user.getUsername();
}