Skip to content

Commit 1795660

Browse files
committed
fix: update DominionAPI dependency version to 4.6.0 and refactor event handling to use Provider methods
1 parent facc81f commit 1795660

18 files changed

Lines changed: 879 additions & 78 deletions

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ repositories {
1818
}
1919
2020
dependencies {
21-
compileOnly("cn.lunadeer:DominionAPI:4.5.0")
21+
compileOnly("cn.lunadeer:DominionAPI:4.6.0")
2222
}
2323
```
2424

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ java {
1515
}
1616

1717
group = "cn.lunadeer"
18-
version = "4.5.2" // << The main version should keep consistent with the core module
18+
version = "4.6.0" // << The main version should keep consistent with the core module
1919

2020
// utf-8
2121
tasks.withType<JavaCompile> {

src/main/java/cn/lunadeer/dominion/api/DominionAPI.java

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
import cn.lunadeer.dominion.api.dtos.PlayerDTO;
77
import cn.lunadeer.dominion.api.dtos.flag.EnvFlag;
88
import cn.lunadeer.dominion.api.dtos.flag.PriFlag;
9+
import cn.lunadeer.dominion.providers.DominionProvider;
10+
import cn.lunadeer.dominion.providers.GroupProvider;
11+
import cn.lunadeer.dominion.providers.MemberProvider;
912
import org.bukkit.Location;
1013
import org.bukkit.entity.Player;
1114
import org.jetbrains.annotations.ApiStatus;
@@ -329,4 +332,40 @@ public static DominionAPI getInstance() {
329332
*/
330333
@Deprecated(since = "4.5.0")
331334
public abstract boolean checkEnvironmentFlag(@Nullable DominionDTO dom, @NotNull EnvFlag flag);
335+
336+
/**
337+
* Retrieves the DominionProvider instance.
338+
* <p>
339+
* This method provides access to the DominionProvider, which handles dominion-related operations
340+
* such as creating, updating, and deleting dominions.
341+
*
342+
* @return the singleton instance of DominionProvider
343+
*/
344+
public static DominionProvider getDominionProvider() {
345+
return DominionProvider.getInstance();
346+
}
347+
348+
/**
349+
* Retrieves the GroupProvider instance.
350+
* <p>
351+
* This method provides access to the GroupProvider, which handles group-related operations
352+
* such as creating, updating, and deleting groups within dominions.
353+
*
354+
* @return the singleton instance of GroupProvider
355+
*/
356+
public static GroupProvider getGroupProvider() {
357+
return GroupProvider.getInstance();
358+
}
359+
360+
/**
361+
* Retrieves the MemberProvider instance.
362+
* <p>
363+
* This method provides access to the MemberProvider, which handles member-related operations
364+
* such as adding, updating, and removing members from dominions and groups.
365+
*
366+
* @return the singleton instance of MemberProvider
367+
*/
368+
public static MemberProvider getMemberProvider() {
369+
return MemberProvider.getInstance();
370+
}
332371
}

src/main/java/cn/lunadeer/dominion/api/dtos/GroupDTO.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import cn.lunadeer.dominion.api.dtos.flag.PriFlag;
44
import net.kyori.adventure.text.Component;
55
import org.jetbrains.annotations.NotNull;
6-
import org.jetbrains.annotations.Nullable;
76

87
import java.sql.SQLException;
98
import java.util.List;
@@ -90,7 +89,7 @@ public interface GroupDTO {
9089
* @return the group object
9190
* @throws SQLException if a database access error occurs
9291
*/
93-
@Nullable GroupDTO setFlagValue(@NotNull PriFlag flag, @NotNull Boolean value) throws SQLException;
92+
@NotNull GroupDTO setFlagValue(@NotNull PriFlag flag, @NotNull Boolean value) throws SQLException;
9493

9594
/**
9695
* Gets all members of the group.

src/main/java/cn/lunadeer/dominion/events/dominion/DominionCreateEvent.java

Lines changed: 33 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010
import org.jetbrains.annotations.Nullable;
1111

1212
import java.util.UUID;
13+
import java.util.concurrent.CompletableFuture;
14+
import java.util.function.Consumer;
1315

1416
/**
1517
* Event triggered when a Dominion is created in the Dominion system.
1618
* Setting setSkipEconomy(true) can skip the economic system processing.
17-
* To modify creation information, set your EventPriority to {@link org.bukkit.event.EventPriority#LOWEST}.
18-
* Changes made after this will not take effect.
1919
*/
2020
@ApiStatus.Experimental
2121
public class DominionCreateEvent extends ResultEvent {
@@ -26,7 +26,7 @@ public class DominionCreateEvent extends ResultEvent {
2626
private CuboidDTO cuboid;
2727
private DominionDTO parent;
2828
private UUID owner;
29-
private DominionDTO dominion = null;
29+
private final CompletableFuture<DominionDTO> future = new CompletableFuture<>();
3030

3131
/**
3232
* Constructs a new DominionCreateEvent.
@@ -53,9 +53,6 @@ public DominionCreateEvent(@NotNull CommandSender operator,
5353

5454
/**
5555
* Sets whether to skip the economic system processing.
56-
* <p>
57-
* Changes made in {@link org.bukkit.event.EventPriority} HIGH or higher {@link org.bukkit.event.EventHandler} will not take effect.
58-
* (Default is {@link org.bukkit.event.EventPriority#NORMAL})
5956
*
6057
* @param skipEconomy true to skip the economic system processing, false otherwise
6158
*/
@@ -83,9 +80,6 @@ public boolean isSkipEconomy() {
8380

8481
/**
8582
* Sets the name of the dominion.
86-
* <p>
87-
* Changes made in {@link org.bukkit.event.EventPriority} HIGH or higher {@link org.bukkit.event.EventHandler} will not take effect.
88-
* (Default is {@link org.bukkit.event.EventPriority#NORMAL})
8983
*
9084
* @param name the name of the dominion
9185
*/
@@ -140,9 +134,6 @@ public void setWorld(@NotNull World world) {
140134

141135
/**
142136
* Sets the parent dominion.
143-
* <p>
144-
* Changes made in {@link org.bukkit.event.EventPriority} HIGH or higher {@link org.bukkit.event.EventHandler} will not take effect.
145-
* (Default is {@link org.bukkit.event.EventPriority#NORMAL})
146137
*
147138
* @param parent the parent dominion
148139
*/
@@ -161,9 +152,6 @@ public void setParent(@Nullable DominionDTO parent) {
161152

162153
/**
163154
* Sets the owner of the dominion.
164-
* <p>
165-
* Changes made in {@link org.bukkit.event.EventPriority} HIGH or higher {@link org.bukkit.event.EventHandler} will not take effect.
166-
* (Default is {@link org.bukkit.event.EventPriority#NORMAL})
167155
*
168156
* @param owner the owner of the dominion
169157
*/
@@ -172,23 +160,44 @@ public void setOwner(@NotNull UUID owner) {
172160
}
173161

174162
/**
175-
* Gets the dominion.
163+
* Gets the CompletableFuture that will be completed with the created DominionDTO.
176164
* <p>
177-
* If retrieved in {@link org.bukkit.event.EventPriority} LOW, LOWEST, or NORMAL {@link org.bukkit.event.EventHandler}, it will be null,
178-
* as the dominion has not been created yet.
165+
* Under most circumstances, you should not need to use this method directly. If you
166+
* need to perform actions after the dominion is created, you should use the
167+
* {@link #afterCreated(Consumer)} method instead.
179168
*
180-
* @return the dominion, or null if it has not been created yet
169+
* @return the CompletableFuture to be completed
181170
*/
182-
public @Nullable DominionDTO getDominion() {
183-
return dominion;
171+
public CompletableFuture<DominionDTO> getFutureToComplete() {
172+
return future;
184173
}
185174

186175
/**
187-
* Sets the dominion.
176+
* Call back after the dominion is created.
177+
* <p>
178+
* Use this method to perform actions after the dominion has been created (may fail),
179+
* if you need to do something with the created dominion.
188180
*
189-
* @param dominion the dominion to set
181+
* @param consumer the consumer to handle the created dominion
182+
* @return a CompletableFuture that completes when the consumer has been executed
183+
*/
184+
public CompletableFuture<Void> afterCreated(Consumer<DominionDTO> consumer) {
185+
return future.thenAccept(consumer);
186+
}
187+
188+
/**
189+
* @deprecated This method is deprecated and will be removed in future versions.
190+
* To get the created dominion, use the {@link #afterCreated(Consumer)} method instead.
191+
*/
192+
@Deprecated(since = "4.6.0", forRemoval = true)
193+
public @Nullable DominionDTO getDominion() {
194+
return null;
195+
}
196+
197+
/**
198+
* @deprecated This method is deprecated and will be removed in future versions.
190199
*/
200+
@Deprecated(since = "4.6.0", forRemoval = true)
191201
public void setDominion(@NotNull DominionDTO dominion) {
192-
this.dominion = dominion;
193202
}
194203
}

src/main/java/cn/lunadeer/dominion/events/dominion/modify/DominionModifyEvent.java

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,17 @@
66
import org.jetbrains.annotations.ApiStatus;
77
import org.jetbrains.annotations.NotNull;
88

9+
import java.util.concurrent.CompletableFuture;
10+
import java.util.function.Consumer;
11+
912
/**
1013
* Event triggered when a Dominion is modified in the Dominion system.
1114
*/
1215
@ApiStatus.Experimental
1316
public class DominionModifyEvent extends ResultEvent {
1417

1518
private DominionDTO dominion;
19+
private final CompletableFuture<DominionDTO> future = new CompletableFuture<>();
1620

1721
/**
1822
* Constructs a new DominionModifyEvent.
@@ -26,11 +30,36 @@ public DominionModifyEvent(@NotNull CommandSender operator, @NotNull DominionDTO
2630
}
2731

2832
/**
29-
* Returns the dominion being modified.
33+
* Gets the CompletableFuture that will be completed with the created DominionDTO.
34+
* <p>
35+
* Under most circumstances, you should not need to use this method directly. If you
36+
* need to perform actions after the dominion is modified, you should use the
37+
* {@link #afterModified(Consumer)} method instead.
38+
*
39+
* @return the CompletableFuture to be completed
40+
*/
41+
public CompletableFuture<DominionDTO> getFutureToComplete() {
42+
return future;
43+
}
44+
45+
/**
46+
* Call back after the dominion is modified.
3047
* <p>
31-
* To get changed dominion your event listener need to be {@link org.bukkit.event.EventPriority} HIGH or higher {@link org.bukkit.event.EventHandler}.
32-
* (Default is {@link org.bukkit.event.EventPriority#NORMAL})
33-
* Or otherwise get the dominion before the changes are applied.
48+
* Use this method to perform actions after the dominion has been modified.
49+
*
50+
* @param consumer the consumer to handle the created dominion
51+
* @return a CompletableFuture that completes when the consumer has been executed
52+
*/
53+
public CompletableFuture<Void> afterModified(Consumer<DominionDTO> consumer) {
54+
return future.thenAccept(consumer);
55+
}
56+
57+
/**
58+
* Returns the dominion to be modified.
59+
* <p>
60+
* This method retrieves the dominion that is going to be modified by this event.
61+
* To get the modified dominion after the event is processed, use the
62+
* {@link #afterModified(Consumer)} method to register a callback.
3463
*
3564
* @return the dominion
3665
*/
@@ -39,9 +68,11 @@ public DominionModifyEvent(@NotNull CommandSender operator, @NotNull DominionDTO
3968
}
4069

4170
/**
42-
* Sets the dominion being modified.
71+
* Sets the dominion to be modified.
72+
* <p>
73+
* This method can only change which dominion will be modified.
4374
*
44-
* @param dominion the new dominion
75+
* @param dominion the dominion to set
4576
*/
4677
public void setDominion(@NotNull DominionDTO dominion) {
4778
this.dominion = dominion;

src/main/java/cn/lunadeer/dominion/events/group/GroupAddMemberEvent.java

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
import org.bukkit.command.CommandSender;
88
import org.jetbrains.annotations.NotNull;
99

10+
import java.util.concurrent.CompletableFuture;
11+
import java.util.function.Consumer;
12+
1013
/**
1114
* Event triggered when a member is added to a group within a dominion.
1215
*/
@@ -15,6 +18,7 @@ public class GroupAddMemberEvent extends ResultEvent {
1518
private final DominionDTO dominion;
1619
private final GroupDTO group;
1720
private MemberDTO member;
21+
private final CompletableFuture<MemberDTO> future = new CompletableFuture<>();
1822

1923
/**
2024
* Constructs a new GroupAddMemberEvent.
@@ -24,7 +28,10 @@ public class GroupAddMemberEvent extends ResultEvent {
2428
* @param group the group to which the member is being added
2529
* @param member the member being added to the group
2630
*/
27-
public GroupAddMemberEvent(@NotNull CommandSender operator, @NotNull DominionDTO dominion, @NotNull GroupDTO group, @NotNull MemberDTO member) {
31+
public GroupAddMemberEvent(@NotNull CommandSender operator,
32+
@NotNull DominionDTO dominion,
33+
@NotNull GroupDTO group,
34+
@NotNull MemberDTO member) {
2835
super(operator);
2936
this.dominion = dominion;
3037
this.group = group;
@@ -42,6 +49,10 @@ public GroupAddMemberEvent(@NotNull CommandSender operator, @NotNull DominionDTO
4249

4350
/**
4451
* Gets the member being added to the group.
52+
* <p>
53+
* This method returns the member that will be added to the group. If you want to
54+
* get the member after it has been added (which may fail), you should use the
55+
* {@link #afterAdded(Consumer)} method instead.
4556
*
4657
* @return the member
4758
*/
@@ -66,4 +77,30 @@ public void setMember(@NotNull MemberDTO member) {
6677
public @NotNull DominionDTO getDominion() {
6778
return dominion;
6879
}
80+
81+
/**
82+
* Gets the CompletableFuture that will be completed with the added MemberDTO.
83+
* <p>
84+
* Under most circumstances, you should not need to use this method directly. If you
85+
* need to perform actions after the member is added, you should use the
86+
* {@link #afterAdded(Consumer)} method instead.
87+
*
88+
* @return the CompletableFuture to be completed
89+
*/
90+
public CompletableFuture<MemberDTO> getFutureToComplete() {
91+
return future;
92+
}
93+
94+
/**
95+
* Call back after the member is added.
96+
* <p>
97+
* Use this method to perform actions after the member has been added (may fail),
98+
* if you need to do something with the added member.
99+
*
100+
* @param consumer the consumer to handle the created member
101+
* @return a CompletableFuture that completes when the consumer has been executed
102+
*/
103+
public CompletableFuture<Void> afterAdded(Consumer<MemberDTO> consumer) {
104+
return future.thenAccept(consumer);
105+
}
69106
}

0 commit comments

Comments
 (0)