mirror of
https://github.com/aikar/commands.git
synced 2026-05-31 06:11:55 +00:00
Add @NotNull annotations, restore and deprecate old constructors, only store Locale.
This commit is contained in:
@@ -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 <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) {
|
||||
locale = ((LocaleSource) obj).locale();
|
||||
} else {
|
||||
locale = Locales.DEFAULT;
|
||||
}
|
||||
}
|
||||
|
||||
public @NotNull Locale locale() {
|
||||
return locale;
|
||||
}
|
||||
|
||||
public @NotNull CommandCause commandCause() {
|
||||
return commandCause;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user