Skip to content

Commit

Permalink
Fix code style.
Browse files Browse the repository at this point in the history
  • Loading branch information
Rollczi committed Jun 18, 2023
1 parent 94342f3 commit b2e8e03
Show file tree
Hide file tree
Showing 11 changed files with 70 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ public EternalCore(Plugin plugin) {
.contextualBind(User.class, new UserContextual(this.translationManager, this.userManager))

.invalidUsageHandler(new InvalidUsage(this.viewerProvider, this.noticeService))
.permissionHandler(new PermissionMessage(this.viewerProvider, noticeService))
.permissionHandler(new PermissionMessage(this.viewerProvider, this.noticeService))
.resultHandler(Notice.class, new NotificationHandler(this.viewerProvider, this.noticeService))

.commandInstance(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public void handle(CommandSender sender, LiteInvocation invocation, RequiredPerm
.join(requiredPermissions.getPermissions())
.toString();

noticeService.create()
this.noticeService.create()
.notice(translation -> translation.argument().permissionMessage())
.placeholder("{PERMISSIONS}", perms)
.viewer(viewer)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
import com.eternalcode.core.language.Language;
import com.eternalcode.core.viewer.Viewer;

import java.util.*;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

class LanguageViewersIndex {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,17 @@
import org.bukkit.SoundCategory;

import java.time.Duration;
import java.util.*;

import static com.eternalcode.core.notice.NoticeContent.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import static com.eternalcode.core.notice.NoticeContent.Music;
import static com.eternalcode.core.notice.NoticeContent.None;
import static com.eternalcode.core.notice.NoticeContent.Text;
import static com.eternalcode.core.notice.NoticeContent.Times;

public class Notice {

Expand Down Expand Up @@ -157,12 +165,13 @@ public Builder sound(Sound sound, float pitch, float volume) {
return this.withPart(new Part<>(NoticeType.SOUND, new Music(sound, null, pitch, volume)));
}

public Builder sound(Sound sound, SoundCategory category, float pitch, float volume) {
public Builder sound(Sound sound, SoundCategory category, float pitch, float volume) {
return this.withPart(new Part<>(NoticeType.SOUND, new Music(sound, category, pitch, volume)));
}

}

record Part<T extends NoticeContent>(NoticeType type, T content) { }
record Part<T extends NoticeContent>(NoticeType type, T content) {
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,17 @@
import panda.utilities.text.Joiner;

import javax.annotation.CheckReturnValue;
import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.function.UnaryOperator;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
import dev.rollczi.litecommands.shared.EstimatedTemporalAmountParser;
import net.dzikoysk.cdn.CdnSettings;
import net.dzikoysk.cdn.CdnUtils;
import net.dzikoysk.cdn.model.*;
import net.dzikoysk.cdn.model.Element;
import net.dzikoysk.cdn.model.Entry;
import net.dzikoysk.cdn.model.Piece;
import net.dzikoysk.cdn.model.Section;
import net.dzikoysk.cdn.module.standard.StandardOperators;
import net.dzikoysk.cdn.reflect.TargetType;
import net.dzikoysk.cdn.serdes.Composer;
Expand All @@ -32,9 +35,9 @@ public class NoticeComposer implements Composer<Notice> {
public Result<? extends Element<?>, ? extends Exception> serialize(CdnSettings settings, List<String> description, String key, TargetType type, Notice entity) {
SerializeContext context = new SerializeContext(settings, description, key, type, entity);

return serializeEmpty(context)
.orElse(error -> serializerUndisclosedChat(context))
.orElse(error -> serializeAll(context));
return this.serializeEmpty(context)
.orElse(error -> this.serializerUndisclosedChat(context))
.orElse(error -> this.serializeAll(context));
}

private Result<Element<?>, Exception> serializeEmpty(SerializeContext context) {
Expand Down Expand Up @@ -167,15 +170,16 @@ private static Section toSection(String key, List<String> description, List<Stri
return section;
}

private record SerializeContext(CdnSettings settings, List<String> description, String key, TargetType type, Notice notice) {
private record SerializeContext(CdnSettings settings, List<String> description, String key, TargetType type,
Notice notice) {
}

@Override
public Result<Notice, Exception> deserialize(CdnSettings settings, Element<?> source, TargetType type, Notice defaultValue, boolean entryAsRecord) {
DeserializeContext context = new DeserializeContext(settings, source, type, defaultValue, entryAsRecord);

return deserializeEmpty(context)
.orElse(error -> deserializeAll(context));
return this.deserializeEmpty(context)
.orElse(error -> this.deserializeAll(context));
}

private Result<Notice, Exception> deserializeEmpty(DeserializeContext context) {
Expand All @@ -200,7 +204,7 @@ private Result<Notice, Exception> deserializeAll(DeserializeContext context) {
}

if (context.source() instanceof Section section) {
return deserializeSection(section);
return this.deserializeSection(section);
}

return Result.error(new UnsupportedOperationException("Unsupported element type: " + context.source().getClass()));
Expand All @@ -211,12 +215,12 @@ private Result<Notice, Exception> deserializeSection(Section section) {

for (Element<?> element : section.getValue()) {
if (element instanceof Piece piece) {
builder.chat(deserializePiece(piece));
builder.chat(this.deserializePiece(piece));
continue;
}

if (element instanceof Entry entry) {
String value = deserializePiece(entry.getValue());
String value = this.deserializePiece(entry.getValue());
NoticeType noticeType = NoticeType.fromKey(entry.getName());

if (noticeType.contentType() == Text.class) {
Expand Down Expand Up @@ -269,7 +273,7 @@ private Result<Notice, Exception> deserializeSection(Section section) {
throw new IllegalStateException("Unsupported element type: " + subElement.getValue());
}

builder.chat(deserializePiece(piece));
builder.chat(this.deserializePiece(piece));
}

continue;
Expand All @@ -291,7 +295,8 @@ private String deserializePiece(Piece piece) {
return CdnUtils.destringify(value.trim());
}

record DeserializeContext(CdnSettings settings, Element<?> source, TargetType type, Notice defaultValue, boolean entryAsRecord) {
record DeserializeContext(CdnSettings settings, Element<?> source, TargetType type, Notice defaultValue,
boolean entryAsRecord) {
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@

sealed interface NoticeContent {

record Text(List<String> messages) implements NoticeContent { }
record Text(List<String> messages) implements NoticeContent {
}

record Times(Duration fadeIn, Duration stay, Duration fadeOut) implements NoticeContent { }
record Times(Duration fadeIn, Duration stay, Duration fadeOut) implements NoticeContent {
}

record Music(Sound sound, @Nullable SoundCategory category, float pitch, float volume) implements NoticeContent { }
record Music(Sound sound, @Nullable SoundCategory category, float pitch, float volume) implements NoticeContent {
}

record None() implements NoticeContent {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public enum NoticeTextType {
}

NoticeType getType() {
return type;
return this.type;
}

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.eternalcode.core.notice;

import static com.eternalcode.core.notice.NoticeContent.None;
import static com.eternalcode.core.notice.NoticeContent.Music;
import static com.eternalcode.core.notice.NoticeContent.None;
import static com.eternalcode.core.notice.NoticeContent.Text;
import static com.eternalcode.core.notice.NoticeContent.Times;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
class PlatformBroadcasterAdventureImpl implements PlatformBroadcaster {

private final Map<NoticeType, NoticePartAnnouncer<?>> announcers = new ImmutableBiMap.Builder<NoticeType, NoticePartAnnouncer<?>>()
.put(NoticeType.CHAT, text(Audience::sendMessage))
.put(NoticeType.ACTION_BAR, text(Audience::sendActionBar))
.put(NoticeType.TITLE, text((audience, title) -> audience.sendTitlePart(TitlePart.TITLE, title)))
.put(NoticeType.SUBTITLE, text((audience, subtitle) -> audience.sendTitlePart(TitlePart.SUBTITLE, subtitle)))
.put(NoticeType.CHAT, this.text((audience, message) -> audience.sendMessage(message)))
.put(NoticeType.ACTION_BAR, this.text((audience, message) -> audience.sendActionBar(message)))
.put(NoticeType.TITLE, this.text((audience, title) -> audience.sendTitlePart(TitlePart.TITLE, title)))
.put(NoticeType.SUBTITLE, this.text((audience, subtitle) -> audience.sendTitlePart(TitlePart.SUBTITLE, subtitle)))
.put(NoticeType.TITLE_TIMES, new TimesNoticePartAnnouncer())
.put(NoticeType.TITLE_HIDE, (viewer, audience, input) -> audience.clearTitle())
.put(NoticeType.TITLE_HIDE, (viewer, audience, input) -> audience.clearTitle())
.put(NoticeType.SOUND, new SoundNoticePartAnnouncer())
.build();

Expand All @@ -39,8 +39,8 @@ class PlatformBroadcasterAdventureImpl implements PlatformBroadcaster {
public void announce(Viewer viewer, Notice notice) {
for (Notice.Part<?> part : notice.parts()) {
Audience audience = viewer.isConsole()
? audienceProvider.console()
: audienceProvider.player(viewer.getUniqueId());
? this.audienceProvider.console()
: this.audienceProvider.player(viewer.getUniqueId());

this.announce(viewer, audience, part);
}
Expand All @@ -49,8 +49,8 @@ public void announce(Viewer viewer, Notice notice) {
@Override
public void announce(Viewer viewer, Notice.Part<?> part) {
Audience audience = viewer.isConsole()
? audienceProvider.console()
: audienceProvider.player(viewer.getUniqueId());
? this.audienceProvider.console()
: this.audienceProvider.player(viewer.getUniqueId());

this.announce(viewer, audience, part);
}
Expand All @@ -73,7 +73,7 @@ interface NoticePartAnnouncer<T extends NoticeContent> {
private NoticePartAnnouncer<NoticeContent.Text> text(BiConsumer<Audience, Component> consumer) {
return (viewer, audience, input) -> {
for (String text : input.messages()) {
consumer.accept(audience, componentSerializer.deserialize(text));
consumer.accept(audience, this.componentSerializer.deserialize(text));
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,11 @@ private void assertTimes(Notice notice, int index, Duration in, Duration stay, D
assertEquals(out, delay.fadeOut());
}

private void assertSound(Notice notice, int index, Sound sound, float volume, float pitch) {
assertSound(notice, index, sound, volume, pitch, null);
private void assertSound(Notice notice, int index, Sound sound, float pitch, float volume) {
assertSound(notice, index, sound, pitch, volume, null);
}

private void assertSound(Notice notice, int index, Sound sound, float volume, float pitch, SoundCategory category) {
private void assertSound(Notice notice, int index, Sound sound, float pitch, float volume, SoundCategory category) {
Notice.Part<?> part = notice.parts().get(index);
NoticeContent.Music soundInput = assertInstanceOf(NoticeContent.Music.class, part.content());

Expand Down

0 comments on commit b2e8e03

Please sign in to comment.