Skip to content

Commit

Permalink
Merge branch 'dev/4.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
phinner committed Dec 30, 2024
2 parents a021eea + e753737 commit 0a607a8
Show file tree
Hide file tree
Showing 89 changed files with 616 additions and 445 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Javadocs are mostly done, the wiki is next.

Final beta release.
All major feature I wanted for distributor 4 have been implemented.
It is now time to use it in more production plugins to asses the usability of the new APIs.
It is now time to use it in more production plugins to assess the usability of the new APIs.

## v4.0.0-beta.2 - 2024-04-08

Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ plugins {
id("distributor.parent-conventions")
}

version = "4.0.2" + if (indraGit.headTag() == null) "-SNAPSHOT" else ""
version = "4.1.0" + if (indraGit.headTag() == null) "-SNAPSHOT" else ""
group = "com.xpdustry"
description = "The Mindustry plugin of ur dreams..."

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public String getName() {

@Override
public DescriptionFacade getDescription() {
return descriptionFacade;
return this.descriptionFacade;
}

@Override
Expand All @@ -84,17 +84,19 @@ public boolean isAlias() {

@Override
public boolean isVisible(final CommandSender sender) {
final var mapped = manager.senderMapper().map(sender);
return manager.commands().stream()
.anyMatch(command -> command.rootComponent().name().equalsIgnoreCase(realName)
&& manager.testPermission(mapped, command.commandPermission())
final var mapped = this.manager.senderMapper().map(sender);
return this.manager.commands().stream()
.anyMatch(command -> command.rootComponent().name().equalsIgnoreCase(this.realName)
&& this.manager
.testPermission(mapped, command.commandPermission())
.allowed());
}

@Override
public CommandHelp getHelp(final CommandSender sender, final String query) {
final var mapped = manager.senderMapper().map(sender);
final var result = manager.createHelpHandler().query(HelpQuery.of(mapped, getRealName() + " " + query));
final var mapped = this.manager.senderMapper().map(sender);
final var result =
this.manager.createHelpHandler().query(HelpQuery.of(mapped, this.getRealName() + " " + query));
if (result instanceof MultipleCommandResult<C> multi) {
return CommandHelp.Suggestion.of(multi.longestPath(), multi.childSuggestions());
} else if (result instanceof VerboseCommandResult<C> verbose) {
Expand All @@ -107,8 +109,8 @@ public CommandHelp getHelp(final CommandSender sender, final String query) {
this.manager
.descriptionMapper()
.map(command.commandDescription().verboseDescription()),
getArguments(command),
getFlags(command));
this.getArguments(command),
this.getFlags(command));
} else {
return CommandHelp.Empty.of();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ public MindustryCommandManager(

this.captionRegistry()
.registerProvider(
createCaptionProviderFromSource(Distributor.get().getGlobalTranslationSource()))
.registerProvider(createCaptionProviderFromSource(DEFAULT_TRANSLATION_SOURCE));
this.createCaptionProviderFromSource(Distributor.get().getGlobalTranslationSource()))
.registerProvider(this.createCaptionProviderFromSource(DEFAULT_TRANSLATION_SOURCE));

this.parserRegistry().registerParser(PlayerParser.playerParser());
this.parserRegistry().registerParser(TeamParser.teamParser());
Expand Down Expand Up @@ -152,7 +152,7 @@ public final void descriptionMapper(final DescriptionMapper<Description> descrip
@Override
public boolean hasPermission(final @NonNull C sender, final String permission) {
return permission.isEmpty()
|| senderMapper()
|| this.senderMapper()
.reverse(sender)
.getPermissions()
.getPermission(permission)
Expand All @@ -176,11 +176,11 @@ protected void registerDefaultExceptionHandlers() {
this.registerDefaultExceptionHandlers(
triplet -> {
final var context = triplet.first();
senderMapper()
this.senderMapper()
.reverse(context.sender())
.error(context.formatCaption(triplet.second(), triplet.third()));
},
pair -> logger.error(pair.first(), pair.second()));
pair -> this.logger.error(pair.first(), pair.second()));
}

private CaptionProvider<C> createCaptionProviderFromSource(final TranslationSource source) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ public ContentParser(final CTypeKey<T> contentType) {
@Override
public ArgumentParseResult<T> parse(final CommandContext<C> ctx, final CommandInput input) {
final var name = input.readString().toLowerCase(Locale.ROOT);
final var content = Vars.content.getByName(contentType.getContentType(), name);
final var content = Vars.content.getByName(this.contentType.getContentType(), name);
return (content == null)
? ArgumentParseResult.failure(new ContentParseException(ctx, name, contentType))
? ArgumentParseResult.failure(new ContentParseException(ctx, name, this.contentType))
: ArgumentParseResult.success((T) content);
}

Expand Down Expand Up @@ -95,11 +95,11 @@ public ContentParseException(final CommandContext<?> ctx, final String input, fi
}

public String getInput() {
return input;
return this.input;
}

public CTypeKey<?> getContentType() {
return contentType;
return this.contentType;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public ArgumentParseResult<Team> parse(final CommandContext<C> ctx, final Comman
@Override
public @NonNull SuggestionProvider<C> suggestionProvider() {
return SuggestionProvider.suggestingStrings(
getTeamIndex().keySet().stream().sorted().toArray(String[]::new));
this.getTeamIndex().keySet().stream().sorted().toArray(String[]::new));
}

private Map<String, Team> getTeamIndex() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public final Optional<O> process(final Object instance) {
results.add(this.process(instance, method, (A) annotation));
}
}
return reduce(Collections.unmodifiableList(results));
return this.reduce(Collections.unmodifiableList(results));
}

protected abstract R process(final Object instance, final Method method, final A annotation);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ default void showLabel(final Component label, final float x, final float y, fina
* @param duration the duration
*/
default void kick(final Component reason, final Duration duration) {
kick(reason, duration, true);
this.kick(reason, duration, true);
}

/**
Expand All @@ -167,7 +167,7 @@ default void kick(final Component reason, final Duration duration, final boolean
* @param duration the duration
*/
default void kick(final Packets.KickReason reason, final Duration duration) {
kick(reason, duration, true);
this.kick(reason, duration, true);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public interface ForwardingAudience extends Audience {

@Override
default Stream<Audience> toStream() {
final var audiences = getAudiences();
final var audiences = this.getAudiences();
final Stream<Audience> stream;
if (audiences instanceof Collection<Audience> collection) {
stream = collection.stream();
Expand All @@ -56,77 +56,77 @@ default Stream<Audience> toStream() {

@Override
default void sendMessage(final Component component) {
for (final var audience : getAudiences()) {
for (final var audience : this.getAudiences()) {
audience.sendMessage(component);
}
}

@Override
default void sendMessage(final Component component, final Component unformatted, final Audience sender) {
for (final var audience : getAudiences()) {
for (final var audience : this.getAudiences()) {
audience.sendMessage(component, unformatted, sender);
}
}

@Override
default void sendWarning(final Component component) {
for (final var audience : getAudiences()) {
for (final var audience : this.getAudiences()) {
audience.sendWarning(component);
}
}

@Override
default void showHUDText(final Component component) {
for (final var audience : getAudiences()) {
for (final var audience : this.getAudiences()) {
audience.showHUDText(component);
}
}

@Override
default void hideHUDText() {
for (final var audience : getAudiences()) {
for (final var audience : this.getAudiences()) {
audience.hideHUDText();
}
}

@Override
default void sendNotification(final Component component, final char icon) {
for (final var audience : getAudiences()) {
for (final var audience : this.getAudiences()) {
audience.sendNotification(component, icon);
}
}

@Override
default void sendAnnouncement(final Component component) {
for (final var audience : getAudiences()) {
for (final var audience : this.getAudiences()) {
audience.sendAnnouncement(component);
}
}

@Override
default void openURI(final URI uri) {
for (final var audience : getAudiences()) {
for (final var audience : this.getAudiences()) {
audience.openURI(uri);
}
}

@Override
default void showLabel(final Component label, final float x, final float y, final Duration duration) {
for (final var audience : getAudiences()) {
for (final var audience : this.getAudiences()) {
audience.showLabel(label, x, y, duration);
}
}

@Override
default void kick(final Component reason, final Duration duration, final boolean log) {
for (final var audience : getAudiences()) {
for (final var audience : this.getAudiences()) {
audience.kick(reason, duration, log);
}
}

@Override
default void kick(final Packets.KickReason reason, final Duration duration, final boolean log) {
for (final var audience : getAudiences()) {
for (final var audience : this.getAudiences()) {
audience.kick(reason, duration, log);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public boolean contains(final Object o) {
@SuppressWarnings("SuspiciousSystemArraycopy")
@Override
public <T> T[] toArray(final T[] a) {
if (a.length >= size()) {
if (a.length >= this.size()) {
System.arraycopy(this.seq.items, 0, a, 0, this.seq.size);
Arrays.fill(a, this.seq.size, a.length, null);
return a;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,27 +60,27 @@ public boolean containsValue(final Object value) {
@SuppressWarnings("unchecked")
@Override
public boolean containsKey(final Object key) {
checkNullKey(key);
this.checkNullKey(key);
return this.map.containsKey((K) key);
}

@SuppressWarnings("unchecked")
@Override
public V get(final Object key) {
checkNullKey(key);
this.checkNullKey(key);
return this.map.get((K) key);
}

@Override
public V put(final K key, final V value) {
checkNullKey(key);
this.checkNullKey(key);
return this.map.put(key, value);
}

@SuppressWarnings("unchecked")
@Override
public V remove(final Object key) {
checkNullKey(key);
this.checkNullKey(key);
return this.map.remove((K) key);
}

Expand All @@ -92,7 +92,7 @@ public void clear() {
@SuppressWarnings("unchecked")
@Override
public V getOrDefault(final Object key, final V defaultValue) {
checkNullKey(key);
this.checkNullKey(key);
return this.map.get((K) key, defaultValue);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,20 @@ public boolean isEmpty() {
@SuppressWarnings("unchecked")
@Override
public boolean contains(final Object o) {
checkNullElement(o);
this.checkNullElement(o);
return this.set.contains((E) o);
}

@Override
public boolean add(final E e) {
checkNullElement(e);
this.checkNullElement(e);
return this.set.add(e);
}

@SuppressWarnings("unchecked")
@Override
public boolean remove(final Object o) {
checkNullElement(o);
this.checkNullElement(o);
return this.set.remove((E) o);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
*/
package com.xpdustry.distributor.api.command;

import com.xpdustry.distributor.api.Distributor;
import com.xpdustry.distributor.api.component.Component;
import com.xpdustry.distributor.internal.annotation.DistributorDataClass;
import java.util.Locale;
import org.immutables.value.Value;
Expand Down Expand Up @@ -59,7 +61,7 @@ static DescriptionFacade translated(final String key, final Locale defaultLocale
String getText();

/**
* Returns the description text for the given locale holder.
* Returns the description text for the given command sender.
*
* @param sender the command sender
* @return the description text
Expand All @@ -68,6 +70,23 @@ default String getText(final CommandSender sender) {
return this.getText();
}

/**
* Returns the description text as a {@link Component}.
*/
default Component getComponent() {
return Distributor.get().getMindustryComponentDecoder().decode(this.getText());
}

/**
* Returns the description text as a {@link Component} for the given command sender.
*
* @param sender the command sender
* @return the description {@link Component}
*/
default Component getComponent(final CommandSender sender) {
return Distributor.get().getMindustryComponentDecoder().decode(this.getText(sender));
}

/**
* Returns whether this description is empty.
*/
Expand Down
Loading

0 comments on commit 0a607a8

Please sign in to comment.