Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update/sponge 8 fix #421

Merged
merged 6 commits into from
Apr 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ private static void findMatches(String search, SpongeCommandSource requester, Li
while (iter.hasNext()) {
Player player = iter.next();
if (requester instanceof Player && !((Player) requester).canSee(player)) {
if (requester.hasPermission("acf.seevanish")) {
if (requester.commandCause().hasPermission("acf.seevanish")) {
if (!search.endsWith(":confirm")) {
confirmList.add(player);
iter.remove();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public SpongeCommandContexts(final SpongeCommandManager manager) {
return decoration;
});

registerIssuerAwareContext(CommandCause.class, SpongeCommandExecutionContext::getSource);
registerIssuerAwareContext(CommandCause.class, (context) -> context.getSource().commandCause());
registerIssuerAwareContext(SpongeCommandSource.class, SpongeCommandExecutionContext::getSource);
registerIssuerAwareContext(ServerPlayer.class, (c) -> {
ServerPlayer serverPlayer = c.getIssuer().getServerPlayer();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public SpongeCommandSource getIssuer() {
}

//generate a unique id based of the name (like for the console command sender)
return UUID.nameUUIDFromBytes(source.identifier().getBytes(StandardCharsets.UTF_8));
return UUID.nameUUIDFromBytes(source.commandCause().identifier().getBytes(StandardCharsets.UTF_8));
}

public Player getPlayer() {
Expand All @@ -83,13 +83,13 @@ public CommandManager getManager() {
@Override
public void sendMessageInternal(String message) {
try {
source.audience().sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(message));
source.commandCause().audience().sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(message));
} catch (Exception ignored) {}
}

@Override
public boolean hasPermission(final String permission) {
return this.source.hasPermission(permission);
return this.source.commandCause().hasPermission(permission);
}

@Override
Expand Down
96 changes: 27 additions & 69 deletions sponge10/src/main/java/co/aikar/commands/SpongeCommandSource.java
Original file line number Diff line number Diff line change
@@ -1,96 +1,54 @@
package co.aikar.commands;

import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.identity.Identified;
import net.kyori.adventure.identity.Identity;
import net.kyori.adventure.text.Component;
import org.spongepowered.api.block.BlockSnapshot;
import org.jetbrains.annotations.NotNull;
import org.spongepowered.api.command.CommandCause;
import org.spongepowered.api.command.parameter.CommandContext;
import org.spongepowered.api.event.Cause;
import org.spongepowered.api.service.permission.Subject;
import org.spongepowered.api.util.locale.LocaleSource;
import org.spongepowered.api.util.locale.Locales;
import org.spongepowered.api.world.server.ServerLocation;
import org.spongepowered.math.vector.Vector3d;

import java.util.Locale;
import java.util.Optional;

public class SpongeCommandSource implements LocaleSource, CommandCause {
private CommandCause commandCause;
private LocaleSource localeSource;
public class SpongeCommandSource {
private final @NotNull CommandCause commandCause;
private final @NotNull Locale locale;

public SpongeCommandSource(CommandContext commandContext) {
commandCause = commandContext.cause();
Subject subject = commandContext.subject();
if (subject instanceof LocaleSource) {
localeSource = (LocaleSource) subject;
public SpongeCommandSource(@NotNull CommandCause cause) {
this.commandCause = cause;
if (cause instanceof LocaleSource) {
locale = ((LocaleSource) cause).locale();
} else if (cause.subject() instanceof LocaleSource) {
locale = ((LocaleSource) cause.subject()).locale();
} else {
localeSource = null;
locale = Locales.DEFAULT;
}
}

@Deprecated
public SpongeCommandSource(CommandContext commandContext) {
this(commandContext.cause());
}

@Deprecated
public <T> SpongeCommandSource(T obj) {
if (obj instanceof CommandCause) {
commandCause = (CommandCause) obj;
} else {
//having it set to null will lead to unexpected behaviour/NPEs
throw new IllegalArgumentException("When creating SpongeCommandSource the object must extend CommandCause");
}

if (obj instanceof LocaleSource) {
localeSource = (LocaleSource) obj;
}
}

@Override
public Locale locale() {
if (localeSource == null) {
return Locales.DEFAULT;
locale = ((LocaleSource) obj).locale();
} else {
locale = Locales.DEFAULT;
}
return localeSource.locale();
}

@Override
public Cause cause() {
return commandCause.cause();
}

@Override
public Subject subject() {
return commandCause.subject();
}

@Override
public Audience audience() {
return commandCause.audience();
}

@Override
public Optional<ServerLocation> location() {
return commandCause.location();
}

@Override
public Optional<Vector3d> rotation() {
return commandCause.rotation();
}

@Override
public Optional<BlockSnapshot> targetBlock() {
return commandCause.targetBlock();
}

@Override
public void sendMessage(Component message) {
commandCause.sendMessage(message);
}

@Override
public void sendMessage(Identified source, Component message) {
commandCause.sendMessage(source, message);
public @NotNull Locale locale() {
return locale;
}

@Override
public void sendMessage(Identity source, Component message) {
commandCause.sendMessage(source, message);
public @NotNull CommandCause commandCause() {
return commandCause;
}
}