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

Switch to Google Java Format #219

Merged
merged 1 commit into from
Jul 27, 2024
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 @@ -23,7 +23,7 @@ java {

spotless {
java {
palantirJavaFormat().style("GOOGLE")
googleJavaFormat().formatJavadoc(false)
formatAnnotations()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ public boolean onCommand(

final AtomicInteger count = new AtomicInteger(0);

final Button counter = Button.of(ItemType.DIAMOND)
.onClick((click) -> sender.sendMessage(click.button().name()));
final Button counter =
Button.of(ItemType.DIAMOND).onClick((click) -> sender.sendMessage(click.button().name()));

scheduler.runTaskTimer(
plugin,
Expand All @@ -47,11 +47,12 @@ public boolean onCommand(
20,
10);

final Gui gui = Gui.chest()
.title(Component.text("Paper Example"))
.rows(3)
.slot(Slot.of(1, 4), counter)
.build();
final Gui gui =
Gui.chest()
.title(Component.text("Paper Example"))
.rows(3)
.slot(Slot.of(1, 4), counter)
.build();

vision.open(player, gui);

Expand Down
13 changes: 7 additions & 6 deletions vision-api/src/main/java/me/sparky983/vision/ButtonImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,13 @@ public Button glow(final boolean glow) {
public Button onClick(final Consumer<? super Click> handler) {
Objects.requireNonNull(handler, "handler cannot be null");

subscribe(new Subscriber() {
@Override
public void click(final Click click) {
handler.accept(click);
}
});
subscribe(
new Subscriber() {
@Override
public void click(final Click click) {
handler.accept(click);
}
});

return this;
}
Expand Down
9 changes: 3 additions & 6 deletions vision-api/src/main/java/me/sparky983/vision/Chest.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ public non-sealed interface Chest extends Gui {
* @since 1.0
* @vision.experimental because this may be deleted, renamed or moved.
*/
@ApiStatus.Experimental
int MIN_ROWS = 1;
@ApiStatus.Experimental int MIN_ROWS = 1;

/**
* The maximum number of rows that a {@code Chest} can have.
Expand All @@ -40,8 +39,7 @@ public non-sealed interface Chest extends Gui {
* @since 1.0
* @vision.experimental because this may be deleted, renamed or moved.
*/
@ApiStatus.Experimental
int MAX_ROWS = 6;
@ApiStatus.Experimental int MAX_ROWS = 6;

/**
* The number of columns {@code Chest}s have.
Expand All @@ -50,8 +48,7 @@ public non-sealed interface Chest extends Gui {
* @since 1.0
* @vision.experimental because this may be deleted, renamed or moved.
*/
@ApiStatus.Experimental
int COLUMNS = 9;
@ApiStatus.Experimental int COLUMNS = 9;

/**
* {@inheritDoc}
Expand Down
3 changes: 1 addition & 2 deletions vision-api/src/main/java/me/sparky983/vision/ChestImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ final class ChestImpl implements Chest {
@VisibleForTesting
static final Component DEFAULT_TITLE = Component.translatable("container.chest");

@VisibleForTesting
static final int DEFAULT_ROWS = 1;
@VisibleForTesting static final int DEFAULT_ROWS = 1;

private final Container container;

Expand Down
22 changes: 12 additions & 10 deletions vision-api/src/main/java/me/sparky983/vision/Container.java
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,11 @@ void slot(final Slot slot, final @Nullable Button button) {
} else {
buttons.put(slot, button);
}
subscribers.notify((subscriber) -> {
subscriber.button(slot, button); // Backwards compatibility
subscriber.slot(slot, button);
});
subscribers.notify(
(subscriber) -> {
subscriber.button(slot, button); // Backwards compatibility
subscriber.slot(slot, button);
});
}

List<Slot> slots() {
Expand All @@ -146,12 +147,13 @@ List<Slot> slots() {
void onClose(final Consumer<? super Close> handler) {
Objects.requireNonNull(handler, "handler cannot be null");

subscribers.subscribe(new Gui.Subscriber() {
@Override
public void close(final Close close) {
handler.accept(close);
}
});
subscribers.subscribe(
new Gui.Subscriber() {
@Override
public void close(final Close close) {
handler.accept(close);
}
});
}

Gui.Publisher publisher() {
Expand Down
6 changes: 2 additions & 4 deletions vision-api/src/main/java/me/sparky983/vision/Dropper.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ public non-sealed interface Dropper extends Gui {
* @since 1.0
* @vision.experimental because this may be deleted, renamed or moved.
*/
@ApiStatus.Experimental
int ROWS = 3;
@ApiStatus.Experimental int ROWS = 3;

/**
* The number of columns {@code Dropper}s have.
Expand All @@ -39,8 +38,7 @@ public non-sealed interface Dropper extends Gui {
* @since 1.0
* @vision.experimental because this may be deleted, renamed or moved.
*/
@ApiStatus.Experimental
int COLUMNS = 3;
@ApiStatus.Experimental int COLUMNS = 3;

/**
* {@inheritDoc}
Expand Down
6 changes: 2 additions & 4 deletions vision-api/src/main/java/me/sparky983/vision/Hopper.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ public non-sealed interface Hopper extends Gui {
* @since 1.0
* @vision.experimental because this may be deleted, renamed or moved.
*/
@ApiStatus.Experimental
int ROWS = 1;
@ApiStatus.Experimental int ROWS = 1;

/**
* The number of columns {@code Hopper}s have.
Expand All @@ -39,8 +38,7 @@ public non-sealed interface Hopper extends Gui {
* @since 1.0
* @vision.experimental because this may be deleted, renamed or moved.
*/
@ApiStatus.Experimental
int COLUMNS = 5;
@ApiStatus.Experimental int COLUMNS = 5;

/**
* {@inheritDoc}
Expand Down
1 change: 1 addition & 0 deletions vision-api/src/main/java/me/sparky983/vision/ItemType.java
Original file line number Diff line number Diff line change
Expand Up @@ -8803,6 +8803,7 @@ public sealed interface ItemType extends Keyed, Translatable permits ItemTypeImp
* @since 0.1
*/
ItemType ZOMBIFIED_PIGLIN_SPAWN_EGG = item(Key.key("zombified_piglin_spawn_egg"));

// @formatter:on
// </editor-fold>

Expand Down
29 changes: 15 additions & 14 deletions vision-api/src/main/java/me/sparky983/vision/Subscribers.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,22 @@ final class Subscribers<T extends Subscribable.Subscriber> implements Subscribab
public Subscription subscribe(final T subscriber) {
Objects.requireNonNull(subscriber, "subscriber cannot be null");

final Subscription subscription = new Subscription() {
@Override
public void cancel() {
final Map<Subscription, T> copy = new HashMap<>(subscribers);
if (copy.remove(this) == null) {
throw new IllegalStateException("Subscription has already been cancelled");
}
subscribers = copy;
}
final Subscription subscription =
new Subscription() {
@Override
public void cancel() {
final Map<Subscription, T> copy = new HashMap<>(subscribers);
if (copy.remove(this) == null) {
throw new IllegalStateException("Subscription has already been cancelled");
}
subscribers = copy;
}

@Override
public boolean isCanceled() {
return !subscribers.containsKey(this);
}
};
@Override
public boolean isCanceled() {
return !subscribers.containsKey(this);
}
};

final Map<Subscription, T> copy = new HashMap<>(subscribers);
copy.put(subscription, subscriber);
Expand Down
13 changes: 7 additions & 6 deletions vision-api/src/test/java/me/sparky983/vision/ButtonTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,9 @@ void testVarargsLoreWhenLoreIsNull() {
void testVarargsLoreWhenLoreContainsNull() {
final Button button = Button.of(ItemType.STONE);

final Exception e = assertThrows(
NullPointerException.class, () -> button.lore(Arrays.asList(LORE_LINE_1, null)));
final Exception e =
assertThrows(
NullPointerException.class, () -> button.lore(Arrays.asList(LORE_LINE_1, null)));
assertEquals("lore[1] cannot be null", e.getMessage());

assertNotEquals(Arrays.asList(LORE_LINE_1, null), button.lore());
Expand Down Expand Up @@ -191,8 +192,9 @@ void testListLoreWhenLoreIsNull() {
void testListLoreWhenLoreContainsNull() {
final Button button = Button.of(ItemType.STONE);

final Exception e = assertThrows(
NullPointerException.class, () -> button.lore(Arrays.asList(LORE_LINE_1, null)));
final Exception e =
assertThrows(
NullPointerException.class, () -> button.lore(Arrays.asList(LORE_LINE_1, null)));
assertEquals("lore[1] cannot be null", e.getMessage());
}

Expand Down Expand Up @@ -367,8 +369,7 @@ void testCancelSubscription() {

@Test
void testToString() {
final Button button =
Button.of(ItemType.STONE).name(NAME).lore(LORE_LIST).amount(2).glow(true);
final Button button = Button.of(ItemType.STONE).name(NAME).lore(LORE_LIST).amount(2).glow(true);

assertEquals(
String.format(
Expand Down
Loading
Loading