Skip to content

Commit 3eaf249

Browse files
Merge pull request #31 from OneLiteFeatherNET/develop
Release 1.11.0
2 parents 4a95309 + 36816a6 commit 3eaf249

File tree

14 files changed

+173
-86
lines changed

14 files changed

+173
-86
lines changed

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ plugins {
77
}
88

99
group = "net.theevilreaper"
10-
version = "1.10.1"
10+
version = "1.11.0"
1111
description = "Aves"
1212

1313
java {

settings.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ dependencyResolutionManagement {
2626
}
2727
versionCatalogs {
2828
create("libs") {
29-
version("bom", "1.4.0")
29+
version("bom", "1.4.2")
3030
version("publishdata", "1.4.0")
3131
library("mycelium.bom", "net.onelitefeather", "mycelium-bom").versionRef("bom")
3232
library("minestom","net.minestom", "minestom").withoutVersion()

src/main/java/net/theevilreaper/aves/inventory/InventoryBuilder.java

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,12 @@
2525
import org.slf4j.LoggerFactory;
2626

2727
import java.util.Locale;
28+
import java.util.function.Consumer;
29+
import java.util.function.Supplier;
2830

2931
/**
3032
* @author Patrick Zdarsky / Rxcki
31-
* @version 1.2.0
33+
* @version 1.3.0
3234
* @since 1.0.12
3335
*/
3436
@SuppressWarnings("java:S3252")
@@ -53,34 +55,55 @@ public abstract class InventoryBuilder {
5355
protected InventoryBuilder(@NotNull InventoryType type) {
5456
this.type = type;
5557

56-
this.inventoryClick = (player, slot, clickType) -> {
57-
if (slot == InventoryConstants.INVALID_SLOT_ID) return ClickHolder.noClick();
58+
this.inventoryClick = (player, slot, clickType, stack, result) -> {
59+
if (slot == InventoryConstants.INVALID_SLOT_ID) {
60+
result.accept(ClickHolder.noClick());
61+
return;
62+
}
5863

5964
if (this.dataLayout != null) {
6065
var clickedSlot = this.dataLayout.getSlot(slot);
61-
return acceptClick(clickedSlot, player, clickType, slot);
66+
acceptClick(clickedSlot, player, clickType, slot, stack, result);
67+
return;
6268
}
6369

6470
if (this.inventoryLayout != null) {
6571
var clickedSlot = this.inventoryLayout.getSlot(slot);
66-
return acceptClick(clickedSlot, player, clickType, slot);
72+
acceptClick(clickedSlot, player, clickType, slot, stack, result);
73+
return;
6774
}
6875

69-
return ClickHolder.noClick();
76+
result.accept(ClickHolder.noClick());
7077
};
7178
}
7279

7380
/**
7481
* Handles the click request on a given slot.
7582
*
76-
* @param slot the {@link ISlot} which is clicked
77-
* @param player the {@link Player} who is involved
78-
* @param clickType the given {@link ClickType}
83+
* @param slot the {@link ISlot} which is clicked
84+
* @param player the {@link Player} who is involved
85+
* @param click the given {@link ClickType}
86+
* @param slotID the slot ID which is clicked
87+
* @param stack the {@link ItemStack} which is clicked
88+
* @param result the consumer to accept the {@link ClickHolder} result
7989
*/
80-
private @NotNull ClickHolder acceptClick(@Nullable ISlot slot, @NotNull Player player, @NotNull Click clickType, int slotID) {
81-
if (slot == null) return ClickHolder.noClick();
82-
if (slot instanceof EmptySlot) return ClickHolder.noClick();
83-
return slot.getClick().onClick(player, slotID, clickType);
90+
private void acceptClick(
91+
@Nullable ISlot slot,
92+
@NotNull Player player,
93+
@NotNull Click click,
94+
int slotID,
95+
@NotNull ItemStack stack,
96+
@NotNull Consumer<ClickHolder> result
97+
) {
98+
if (slot == null) {
99+
result.accept(ClickHolder.noClick());
100+
return;
101+
}
102+
if (slot instanceof EmptySlot) {
103+
result.accept(ClickHolder.noClick());
104+
return;
105+
}
106+
slot.getClick().onClick(player, slotID, click, stack, result);
84107
}
85108

86109
/**

src/main/java/net/theevilreaper/aves/inventory/InventoryListenerHandler.java

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@
1414
import org.jetbrains.annotations.NotNull;
1515
import org.jetbrains.annotations.Nullable;
1616

17+
import java.util.function.Consumer;
18+
1719
/**
1820
* Handles the {@link EventListener} creation for some {@link InventoryEvent}'s.
1921
* The class reduces some duplicated code parts in the inventory system.
2022
*
2123
* @author theEvilReaper
22-
* @version 1.0.0
24+
* @version 1.1.0
2325
* @since 1.0.0
2426
**/
2527
sealed interface InventoryListenerHandler permits BaseInventoryBuilderImpl {
@@ -130,15 +132,16 @@ default EventListener<InventoryPreClickEvent> registerClick(
130132
) {
131133
return EventListener.of(InventoryPreClickEvent.class, event -> {
132134
if (event.getInventory() instanceof CustomInventory customInventory && customInventory.getHolder() == holder) {
133-
ClickHolder click = builder.inventoryClick.onClick(event.getPlayer(), event.getSlot(), event.getClick());
134-
135-
switch (click) {
136-
case ClickHolder.CancelClick ignored1 -> event.setCancelled(true);
137-
case ClickHolder.MinestomClick(@NotNull Click minestomClick) -> event.setClick(minestomClick);
138-
case ClickHolder.NOPClick ignored -> {
139-
// No operation
135+
Consumer<ClickHolder> result = click -> {
136+
switch (click) {
137+
case ClickHolder.CancelClick ignored1 -> event.setCancelled(true);
138+
case ClickHolder.MinestomClick(@NotNull Click minestomClick) -> event.setClick(minestomClick);
139+
case ClickHolder.NOPClick ignored -> {
140+
// No operation
141+
}
140142
}
141-
}
143+
};
144+
builder.inventoryClick.onClick(event.getPlayer(), event.getSlot(), event.getClick(), event.getClickedItem(), result);
142145
}
143146
});
144147
}

src/main/java/net/theevilreaper/aves/inventory/function/InventoryClick.java

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,37 @@
33
import net.minestom.server.entity.Player;
44
import net.minestom.server.inventory.click.Click;
55
import net.minestom.server.inventory.click.ClickType;
6+
import net.minestom.server.item.ItemStack;
67
import net.theevilreaper.aves.inventory.click.ClickHolder;
78
import net.theevilreaper.aves.inventory.slot.ISlot;
89
import org.jetbrains.annotations.NotNull;
910

11+
import java.util.function.Consumer;
12+
1013
/**
1114
* Represents a click function which can be applied to an implementation from the {@link ISlot} interface.
1215
*
1316
* @author theEvilReaper
1417
* @version 1.0.0
15-
* @since 1.2.0
18+
* @since 1.3.0
1619
**/
1720
@FunctionalInterface
1821
public interface InventoryClick {
1922

2023
/**
21-
* Handles what happen when a player clicks on an item in a inventory.
24+
* Handles what happen when a player clicks on an item in an inventory.
2225
*
23-
* @param player the {@link Player} who is involved
24-
* @param clickType the given {@link ClickType}
25-
* @param slot the clicked slot as int
26+
* @param player the {@link Player} who is involved
27+
* @param slot the clicked slot as int
28+
* @param click the given {@link ClickType}
29+
* @param stack the {@link ItemStack} which was clicked
30+
* @param result a {@link Consumer} which will be called with a {@link ClickHolder} to handle the result of the click
2631
*/
27-
@NotNull ClickHolder onClick(@NotNull Player player, int slot, @NotNull Click clickType);
32+
void onClick(
33+
@NotNull Player player,
34+
int slot, @NotNull
35+
Click click,
36+
@NotNull ItemStack stack,
37+
@NotNull Consumer<@NotNull ClickHolder> result
38+
);
2839
}

src/main/java/net/theevilreaper/aves/inventory/pageable/PlayerPageableInventoryImpl.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,14 @@ public final class PlayerPageableInventoryImpl implements PageableInventory {
9292
ISlot givenForwardSlot = this.layout.getSlot(this.pageableControls.getNextSlot());
9393
this.forwardSlot = givenForwardSlot == null ? BLANK_SLOT : ISlot.of(givenForwardSlot);
9494

95-
this.forwardClick = (clickPlayer, slot, click) -> {
95+
this.forwardClick = (clickPlayer, slot, click, stack, result) -> {
9696
this.update(PageAction.FORWARD);
97-
return ClickHolder.cancelClick();
97+
result.accept(ClickHolder.cancelClick());
9898
};
9999

100-
this.backwardsClick = (clickPlayer, slot, click) -> {
100+
this.backwardsClick = (clickPlayer, slot, click, stack,result) -> {
101101
this.update(PageAction.BACKWARDS);
102-
return ClickHolder.cancelClick();
102+
result.accept(ClickHolder.cancelClick());
103103
};
104104

105105
this.builder.setDataLayoutFunction(inventoryLayout -> dataLayout);

src/main/java/net/theevilreaper/aves/inventory/util/InventoryConstants.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
**/
1616
public final class InventoryConstants {
1717

18-
public static final InventoryClick CANCEL_CLICK = (player, slot, click) -> ClickHolder.cancelClick();
18+
public static final InventoryClick CANCEL_CLICK = (player, slot, click, stack, result) -> result.accept(ClickHolder.cancelClick());
1919
@Deprecated(forRemoval = true, since = "Not needed anymore due to the changes to the inventory system")
2020
public static final Consumer<CancellableEvent> CANCELLABLE_EVENT = event -> event.setCancelled(true);
2121
public static final EmptySlot BLANK_SLOT = new EmptySlot();

src/main/java/net/theevilreaper/aves/map/BaseMap.java

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -46,45 +46,6 @@ public BaseMap(@NotNull String name, Pos spawn, String... builders) {
4646
this.spawn = spawn;
4747
}
4848

49-
/**
50-
* Creates a new instance from the {@link BaseMap} with all given values.
51-
* Deprecated since 1.9.0, use {@link #builder()} instead.
52-
*
53-
* @param name the name from the map
54-
*/
55-
@Deprecated(forRemoval = true, since = "1.9.0")
56-
@Contract(value = "_ -> new", pure = true)
57-
public static @NotNull BaseMap of(@NotNull String name) {
58-
return new BaseMap(name, null);
59-
}
60-
61-
/**
62-
* The constructor sets all relevant values for a map.
63-
* Deprecated since 1.9.0, use {@link #builder()} instead.
64-
*
65-
* @param name the name from the map
66-
* @param spawn the spawn location from the map
67-
*/
68-
@Deprecated(forRemoval = true, since = "1.9.0")
69-
@Contract(value = "_, _ -> new", pure = true)
70-
public static @NotNull BaseMap of(@NotNull String name, Pos spawn) {
71-
return new BaseMap(name, spawn, "team");
72-
}
73-
74-
/**
75-
* The constructor sets all relevant values for a map.
76-
* Deprecated since 1.9.0, use {@link #builder()} instead.
77-
*
78-
* @param name the name from the map
79-
* @param builders the builders from the map
80-
* @param spawn the spawn location from the map
81-
*/
82-
@Contract(value = "_, _, _ -> new", pure = true)
83-
@Deprecated(forRemoval = true, since = "1.9.0")
84-
public static @NotNull BaseMap of(@NotNull String name, Pos spawn, String... builders) {
85-
return new BaseMap(name, spawn, builders);
86-
}
87-
8849
/**
8950
* Creates a new instance of the {@link BaseMapBuilder} to build a new map.
9051
* The builder can be used to set all values that are required for a map.

src/test/java/net/theevilreaper/aves/file/FileHandlerTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ void testOtherConstructor() {
4141
@Test
4242
void testGsonFileHandlerWrite() {
4343
var path = tempDir.toPath().resolve(testMap);
44-
var baseMap = BaseMap.of("TestMap");
44+
var baseMap = new BaseMap("TestMap", null);
4545
baseMap.setBuilders("Builder1", "Builder2");
4646
fileHandler.save(path, baseMap);
4747
assertTrue(Files.exists(path));

src/test/java/net/theevilreaper/aves/file/ModernFileHandlerTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ void testOtherConstructor() {
4646
@Test
4747
void testGsonFileHandlerWrite() {
4848
var path = tempDir.toPath().resolve(testMap);
49-
var baseMap = BaseMap.of("TestMap");
49+
var baseMap = new BaseMap("TestMap", null);
5050
baseMap.setBuilders("Builder1", "Builder2");
5151
fileHandler.save(path, baseMap, TypeToken.get(BaseMap.class));
5252
assertTrue(Files.exists(path));
@@ -77,7 +77,7 @@ void testFileNotExistsRead() {
7777
@Test
7878
void testInvalidPathSave() {
7979
var path = tempDir.toPath();
80-
var baseMap = BaseMap.of("TestMap");
80+
var baseMap = new BaseMap("TestMap", null);
8181
var exception = assertThrows(
8282
IllegalArgumentException.class,
8383
() -> fileHandler.save(path, baseMap, TypeToken.get(BaseMap.class))

0 commit comments

Comments
 (0)