diff --git a/sponge10/src/main/java/co/aikar/commands/SpongeCommandSource.java b/sponge10/src/main/java/co/aikar/commands/SpongeCommandSource.java index b5ae221c..9d876399 100644 --- a/sponge10/src/main/java/co/aikar/commands/SpongeCommandSource.java +++ b/sponge10/src/main/java/co/aikar/commands/SpongeCommandSource.java @@ -1,34 +1,54 @@ package co.aikar.commands; +import org.jetbrains.annotations.NotNull; import org.spongepowered.api.command.CommandCause; +import org.spongepowered.api.command.parameter.CommandContext; import org.spongepowered.api.util.locale.LocaleSource; import org.spongepowered.api.util.locale.Locales; import java.util.Locale; public class SpongeCommandSource { - private final CommandCause commandCause; - private final LocaleSource localeSource; + private final @NotNull CommandCause commandCause; + private final @NotNull Locale locale; - public SpongeCommandSource(CommandCause cause) { + public SpongeCommandSource(@NotNull CommandCause cause) { this.commandCause = cause; if (cause instanceof LocaleSource) { - localeSource = (LocaleSource) cause; + locale = ((LocaleSource) cause).locale(); } else if (cause.subject() instanceof LocaleSource) { - localeSource = (LocaleSource) cause.subject(); + locale = ((LocaleSource) cause.subject()).locale(); } else { - localeSource = null; + locale = Locales.DEFAULT; } } - public Locale locale() { - if (localeSource == null) { - return Locales.DEFAULT; - } - return localeSource.locale(); + @Deprecated + public SpongeCommandSource(CommandContext commandContext) { + this(commandContext.cause()); } - public CommandCause commandCause() { + @Deprecated + public 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) { + locale = ((LocaleSource) obj).locale(); + } else { + locale = Locales.DEFAULT; + } + } + + public @NotNull Locale locale() { + return locale; + } + + public @NotNull CommandCause commandCause() { return commandCause; } }