mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-02 22:16:22 +00:00
Add initial commands skeleton
This commit is contained in:
1 parent
39b3f12d1d
commit
1bc186bebd
12 files changed
+251
-8
No files matched your search
@@ -1,8 +1,14 @@
|
||||
package net.draycia.carbon.sponge;
|
||||
|
||||
import cloud.commandframework.CommandManager;
|
||||
import cloud.commandframework.execution.AsynchronousCommandExecutionCoordinator;
|
||||
import cloud.commandframework.sponge.SpongeCommandManager;
|
||||
import com.google.inject.Inject;
|
||||
import net.draycia.carbon.api.users.UserManager;
|
||||
import net.draycia.carbon.common.CarbonChatCommon;
|
||||
import net.draycia.carbon.common.command.Commander;
|
||||
import net.draycia.carbon.sponge.command.SpongeCommander;
|
||||
import net.draycia.carbon.sponge.command.SpongePlayerCommander;
|
||||
import net.draycia.carbon.sponge.users.MemoryUserManagerSponge;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
@@ -22,9 +28,10 @@ import static net.kyori.adventure.text.Component.empty;
|
||||
@Plugin("carbonchat")
|
||||
public class CarbonChatSponge extends CarbonChatCommon {
|
||||
|
||||
private static final int BSTATS_PLUGIN_ID = 11279;
|
||||
|
||||
private final PluginContainer pluginContainer;
|
||||
private final Logger logger;
|
||||
private static final int BSTATS_PLUGIN_ID = 11279;
|
||||
|
||||
private final @NonNull UserManager userManager = new MemoryUserManagerSponge();
|
||||
|
||||
@@ -51,6 +58,23 @@ public class CarbonChatSponge extends CarbonChatCommon {
|
||||
return this.userManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @NonNull CommandManager<Commander> createCommandManager() {
|
||||
final SpongeCommandManager<Commander> commandManager = new SpongeCommandManager<>(
|
||||
this.pluginContainer,
|
||||
AsynchronousCommandExecutionCoordinator.<Commander>newBuilder().build(),
|
||||
commander -> ((SpongeCommander) commander).commandCause(),
|
||||
commandCause -> {
|
||||
if (commandCause.subject() instanceof ServerPlayer) {
|
||||
return new SpongePlayerCommander(this, (ServerPlayer) commandCause.subject(), commandCause);
|
||||
}
|
||||
return SpongeCommander.from(commandCause);
|
||||
}
|
||||
);
|
||||
commandManager.parserMapper().cloudNumberSuggestions(true);
|
||||
return commandManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull Component createItemHoverComponent(final @NonNull UUID uuid) {
|
||||
final ServerPlayer player = Sponge.server().player(uuid).orElse(null);
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
package net.draycia.carbon.sponge.command;
|
||||
|
||||
import net.draycia.carbon.common.command.Commander;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.audience.ForwardingAudience;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.spongepowered.api.command.CommandCause;
|
||||
|
||||
public interface SpongeCommander extends Commander, ForwardingAudience.Single {
|
||||
@NonNull CommandCause commandCause();
|
||||
|
||||
static @NonNull SpongeCommander from(final @NonNull CommandCause commandCause) {
|
||||
return new SpongeCommanderImpl(commandCause);
|
||||
}
|
||||
|
||||
final class SpongeCommanderImpl implements SpongeCommander {
|
||||
private final CommandCause commandCause;
|
||||
|
||||
private SpongeCommanderImpl(final @NonNull CommandCause commandCause) {
|
||||
this.commandCause = commandCause;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull CommandCause commandCause() {
|
||||
return this.commandCause;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull Audience audience() {
|
||||
return this.commandCause.audience();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package net.draycia.carbon.sponge.command;
|
||||
|
||||
import net.draycia.carbon.api.CarbonChat;
|
||||
import net.draycia.carbon.api.users.CarbonPlayer;
|
||||
import net.draycia.carbon.common.command.PlayerCommander;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.spongepowered.api.command.CommandCause;
|
||||
import org.spongepowered.api.entity.living.player.server.ServerPlayer;
|
||||
|
||||
import static java.util.Objects.requireNonNull;
|
||||
|
||||
public final class SpongePlayerCommander implements PlayerCommander, SpongeCommander {
|
||||
private final CarbonChat carbon;
|
||||
private final ServerPlayer player;
|
||||
private final CommandCause commandCause;
|
||||
|
||||
public SpongePlayerCommander(final @NonNull CarbonChat carbon, final @NonNull ServerPlayer player, final @NonNull CommandCause commandCause) {
|
||||
this.carbon = carbon;
|
||||
this.player = player;
|
||||
this.commandCause = commandCause;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull CarbonPlayer carbonPlayer() {
|
||||
return requireNonNull(this.carbon.userManager().carbonPlayer(this.player.uniqueId()), "No CarbonPlayer for logged in Player!");
|
||||
}
|
||||
|
||||
public @NonNull ServerPlayer player() {
|
||||
return this.player;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull CommandCause commandCause() {
|
||||
return this.commandCause;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull Audience audience() {
|
||||
return this.commandCause.audience();
|
||||
}
|
||||
}
|
||||
@@ -51,6 +51,10 @@ public class MemoryUserManagerSponge implements UserManager {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (this.users.containsKey(player.get().uniqueId())) {
|
||||
return this.users.get(player.get().uniqueId());
|
||||
}
|
||||
|
||||
return new CarbonPlayerSponge(player.get().name(), text(player.get().name()),
|
||||
player.get().uniqueId());
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user