Skip to content

Commit

Permalink
feat: Support create event for lobby server
Browse files Browse the repository at this point in the history
  • Loading branch information
CarmJos committed Aug 6, 2024
1 parent 9a14366 commit b85e922
Show file tree
Hide file tree
Showing 11 changed files with 54 additions and 12 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.asset/
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
Expand Down
2 changes: 1 addition & 1 deletion api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.artformgames</groupId>
<artifactId>votepass-parent</artifactId>
<version>1.4.2</version>
<version>1.4.3</version>
</parent>
<properties>
<maven.compiler.source>${project.jdk.version}</maven.compiler.source>
Expand Down
2 changes: 1 addition & 1 deletion core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.artformgames</groupId>
<artifactId>votepass-parent</artifactId>
<version>1.4.2</version>
<version>1.4.3</version>
</parent>
<properties>
<maven.compiler.source>${project.jdk.version}</maven.compiler.source>
Expand Down
2 changes: 1 addition & 1 deletion game/api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.artformgames</groupId>
<artifactId>votepass-parent</artifactId>
<version>1.4.2</version>
<version>1.4.3</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<properties>
Expand Down
2 changes: 1 addition & 1 deletion game/plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.artformgames</groupId>
<artifactId>votepass-parent</artifactId>
<version>1.4.2</version>
<version>1.4.3</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<properties>
Expand Down
2 changes: 1 addition & 1 deletion lobby/api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.artformgames</groupId>
<artifactId>votepass-parent</artifactId>
<version>1.4.2</version>
<version>1.4.3</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<properties>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.artformgames.plugin.votepass.lobby.api.event;

import com.artformgames.plugin.votepass.api.data.request.RequestInformation;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull;

public class RequestCreatedEvent extends Event {

private static final HandlerList handlerList = new HandlerList();

protected final RequestInformation request;

public RequestCreatedEvent(RequestInformation request) {
super(true);
this.request = request;
}

public RequestInformation getRequest() {
return request;
}

@Override
public @NotNull HandlerList getHandlers() {
return handlerList;
}

public static HandlerList getHandlerList() {
return handlerList;
}


}
2 changes: 1 addition & 1 deletion lobby/plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.artformgames</groupId>
<artifactId>votepass-parent</artifactId>
<version>1.4.2</version>
<version>1.4.3</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class RequestManager implements UserRequestManager {
DataSerializer.serializeAnswers(request.getAnswers()), LocalDateTime.now()
).returnGeneratedKey().execute();


return new RequestInformation(
id, request.getSettings().id(), user,
request.getAnswers(), new HashSet<>(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@
import com.artformgames.plugin.votepass.api.data.request.RequestAnswer;
import com.artformgames.plugin.votepass.api.data.request.RequestInformation;
import com.artformgames.plugin.votepass.core.conf.CommonConfig;
import com.artformgames.plugin.votepass.lobby.Main;
import com.artformgames.plugin.votepass.lobby.VotePassLobbyAPI;
import com.artformgames.plugin.votepass.lobby.api.data.server.ServerQuestion;
import com.artformgames.plugin.votepass.lobby.api.data.server.ServerSettings;
import com.artformgames.plugin.votepass.lobby.api.data.user.PendingRequest;
import com.artformgames.plugin.votepass.lobby.api.event.RequestCreatedEvent;
import com.artformgames.plugin.votepass.lobby.api.user.LobbyUserData;
import com.artformgames.plugin.votepass.lobby.conf.PluginConfig;
import com.artformgames.plugin.votepass.lobby.conf.PluginMessages;
Expand All @@ -29,6 +31,7 @@
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;

public class RequestingGUI extends AutoPagedGUI {

Expand All @@ -37,9 +40,12 @@ public static void open(Player player, LobbyUserData data, PendingRequest reques
questionsGUI.openGUI(player);
}

@NotNull Player player;
@NotNull LobbyUserData data;
@NotNull PendingRequest pendingRequest;
@NotNull
Player player;
@NotNull
LobbyUserData data;
@NotNull
PendingRequest pendingRequest;

public RequestingGUI(@NotNull Player player, @NotNull LobbyUserData data, @NotNull PendingRequest pendingRequest) {
super(
Expand Down Expand Up @@ -134,15 +140,16 @@ public void onClick(Player clicker, ClickType type) {

VotePassLobbyAPI.getRequestManager()
.commit(getData().getKey(), getPendingRequest())
.thenAccept(request -> {
.thenCompose(request -> {
if (request == null) {
PluginMessages.ERROR.send(player, getSettings().name());
return;
return CompletableFuture.completedFuture(null);
}

getData().addRequest(request);
getData().removePendingRequest();
PluginMessages.POSTED.send(player, request.getID(), getSettings().name());
return Main.getInstance().callAsync(new RequestCreatedEvent(request));
});
}
};
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
</properties>
<groupId>com.artformgames</groupId>
<artifactId>votepass-parent</artifactId>
<version>1.4.2</version>
<version>1.4.3</version>
<modules>
<module>api</module>
<module>lobby/api</module>
Expand Down

0 comments on commit b85e922

Please sign in to comment.