Skip to content

Commit e81134c

Browse files
feat(): dark auctions
1 parent 003ffee commit e81134c

50 files changed

Lines changed: 3113 additions & 237 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

commons/src/main/java/net/swofty/commons/ServiceType.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ public enum ServiceType {
77
API,
88
DATA_MUTEX,
99
PARTY,
10+
DARK_AUCTION,
1011
;
1112
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package net.swofty.commons.auctions;
2+
3+
public enum DarkAuctionPhase {
4+
QUEUE, // 35 seconds to enter
5+
BIDDING, // Active bidding
6+
BETWEEN, // Between rounds
7+
COMPLETE // Done
8+
}

commons/src/main/java/net/swofty/commons/item/ItemType.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ public enum ItemType {
9191
ABIPHONE_CONTACTS_TRIO(Material.COMPARATOR, Rarity.SPECIAL),
9292
PURE_WHITE_DYE(Material.BONE_MEAL, Rarity.EPIC),
9393
PURE_BLACK_DYE(Material.INK_SAC, Rarity.EPIC),
94+
DARK_PURPLE_DYE(Material.PLAYER_HEAD, Rarity.LEGENDARY),
9495
ACCESSORY_ENRICHMENT_SWAPPER(Material.COMPARATOR, Rarity.SPECIAL),
9596
ATTACK_SPEED_ENRICHMENT(Material.PLAYER_HEAD, Rarity.SPECIAL),
9697
CRITICAL_CHANCE_ENRICHMENT(Material.PLAYER_HEAD, Rarity.SPECIAL),
@@ -717,6 +718,7 @@ public enum ItemType {
717718
*/
718719
HUB_CASTLE_TRAVEL_SCROLL(Material.MAP, Rarity.EPIC),
719720
HUB_MUSEUM_TRAVEL_SCROLL(Material.MAP, Rarity.EPIC),
721+
HUB_DARK_AUCTION_TRAVEL_SCROLL(Material.MAP, Rarity.EPIC),
720722
HUB_CRYPTS_TRAVEL_SCROLL(Material.MAP, Rarity.EPIC),
721723

722724
/**
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
package net.swofty.commons.protocol.objects.darkauction;
2+
3+
import net.swofty.commons.auctions.DarkAuctionPhase;
4+
import net.swofty.commons.protocol.ProtocolObject;
5+
import net.swofty.commons.protocol.Serializer;
6+
import org.json.JSONArray;
7+
import org.json.JSONObject;
8+
9+
import java.util.ArrayList;
10+
import java.util.List;
11+
import java.util.UUID;
12+
13+
public class DarkAuctionEventProtocol extends ProtocolObject<
14+
DarkAuctionEventProtocol.DarkAuctionMessage,
15+
DarkAuctionEventProtocol.DarkAuctionResponse> {
16+
17+
public enum EventType {
18+
AUCTION_START, // Spawn Sirius, open door
19+
AUCTION_BEGIN, // Start bidding (after 35 sec queue)
20+
ROUND_START, // New round with item
21+
BID_PLACED, // Someone bid (sync across hubs)
22+
ROUND_END, // Round finished, winner announced
23+
AUCTION_END // Auction complete, cleanup
24+
}
25+
26+
@Override
27+
public Serializer<DarkAuctionMessage> getSerializer() {
28+
return new Serializer<>() {
29+
@Override
30+
public String serialize(DarkAuctionMessage value) {
31+
JSONObject json = new JSONObject();
32+
json.put("eventType", value.eventType.name());
33+
json.put("auctionId", value.auctionId.toString());
34+
json.put("phase", value.phase.name());
35+
json.put("currentRound", value.currentRound);
36+
json.put("currentItemType", value.currentItemType);
37+
json.put("currentBid", value.currentBid);
38+
json.put("highestBidderId", value.highestBidderId != null ? value.highestBidderId.toString() : null);
39+
json.put("highestBidderName", value.highestBidderName);
40+
json.put("countdown", value.countdown);
41+
42+
JSONArray itemsArray = new JSONArray();
43+
for (String item : value.roundItems) {
44+
itemsArray.put(item);
45+
}
46+
json.put("roundItems", itemsArray);
47+
48+
// Refund info for BID_PLACED events
49+
json.put("refundPlayerId", value.refundPlayerId != null ? value.refundPlayerId.toString() : null);
50+
json.put("refundAmount", value.refundAmount);
51+
52+
return json.toString();
53+
}
54+
55+
@Override
56+
public DarkAuctionMessage deserialize(String json) {
57+
JSONObject jsonObject = new JSONObject(json);
58+
59+
EventType eventType = EventType.valueOf(jsonObject.getString("eventType"));
60+
UUID auctionId = UUID.fromString(jsonObject.getString("auctionId"));
61+
DarkAuctionPhase phase = DarkAuctionPhase.valueOf(jsonObject.getString("phase"));
62+
int currentRound = jsonObject.getInt("currentRound");
63+
String currentItemType = jsonObject.optString("currentItemType", null);
64+
long currentBid = jsonObject.getLong("currentBid");
65+
66+
String bidderIdStr = jsonObject.optString("highestBidderId", null);
67+
UUID highestBidderId = bidderIdStr != null && !bidderIdStr.equals("null") ? UUID.fromString(bidderIdStr) : null;
68+
String highestBidderName = jsonObject.optString("highestBidderName", null);
69+
int countdown = jsonObject.getInt("countdown");
70+
71+
List<String> roundItems = new ArrayList<>();
72+
JSONArray itemsArray = jsonObject.optJSONArray("roundItems");
73+
if (itemsArray != null) {
74+
for (int i = 0; i < itemsArray.length(); i++) {
75+
roundItems.add(itemsArray.getString(i));
76+
}
77+
}
78+
79+
String refundPlayerIdStr = jsonObject.optString("refundPlayerId", null);
80+
UUID refundPlayerId = refundPlayerIdStr != null && !refundPlayerIdStr.equals("null") ? UUID.fromString(refundPlayerIdStr) : null;
81+
long refundAmount = jsonObject.optLong("refundAmount", 0);
82+
83+
return new DarkAuctionMessage(eventType, auctionId, phase, currentRound, currentItemType,
84+
currentBid, highestBidderId, highestBidderName, countdown, roundItems,
85+
refundPlayerId, refundAmount);
86+
}
87+
88+
@Override
89+
public DarkAuctionMessage clone(DarkAuctionMessage value) {
90+
return new DarkAuctionMessage(value.eventType, value.auctionId, value.phase, value.currentRound,
91+
value.currentItemType, value.currentBid, value.highestBidderId,
92+
value.highestBidderName, value.countdown, new ArrayList<>(value.roundItems),
93+
value.refundPlayerId, value.refundAmount);
94+
}
95+
};
96+
}
97+
98+
@Override
99+
public Serializer<DarkAuctionResponse> getReturnSerializer() {
100+
return new Serializer<>() {
101+
@Override
102+
public String serialize(DarkAuctionResponse value) {
103+
JSONObject json = new JSONObject();
104+
json.put("success", value.success);
105+
json.put("playersInAuction", value.playersInAuction);
106+
return json.toString();
107+
}
108+
109+
@Override
110+
public DarkAuctionResponse deserialize(String json) {
111+
JSONObject jsonObject = new JSONObject(json);
112+
return new DarkAuctionResponse(
113+
jsonObject.getBoolean("success"),
114+
jsonObject.getInt("playersInAuction")
115+
);
116+
}
117+
118+
@Override
119+
public DarkAuctionResponse clone(DarkAuctionResponse value) {
120+
return new DarkAuctionResponse(value.success, value.playersInAuction);
121+
}
122+
};
123+
}
124+
125+
public record DarkAuctionMessage(
126+
EventType eventType,
127+
UUID auctionId,
128+
DarkAuctionPhase phase,
129+
int currentRound,
130+
String currentItemType,
131+
long currentBid,
132+
UUID highestBidderId,
133+
String highestBidderName,
134+
int countdown,
135+
List<String> roundItems,
136+
UUID refundPlayerId,
137+
long refundAmount
138+
) {}
139+
140+
public record DarkAuctionResponse(
141+
boolean success,
142+
int playersInAuction
143+
) {}
144+
}
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
package net.swofty.commons.protocol.objects.darkauction;
2+
3+
import net.swofty.commons.auctions.DarkAuctionPhase;
4+
import net.swofty.commons.protocol.ProtocolObject;
5+
import net.swofty.commons.protocol.Serializer;
6+
import org.json.JSONArray;
7+
import org.json.JSONObject;
8+
9+
import java.util.ArrayList;
10+
import java.util.List;
11+
import java.util.UUID;
12+
13+
public class GetAuctionStateProtocol extends ProtocolObject<
14+
GetAuctionStateProtocol.GetAuctionStateMessage,
15+
GetAuctionStateProtocol.GetAuctionStateResponse> {
16+
17+
@Override
18+
public Serializer<GetAuctionStateMessage> getSerializer() {
19+
return new Serializer<>() {
20+
@Override
21+
public String serialize(GetAuctionStateMessage value) {
22+
return "";
23+
}
24+
25+
@Override
26+
public GetAuctionStateMessage deserialize(String json) {
27+
return new GetAuctionStateMessage();
28+
}
29+
30+
@Override
31+
public GetAuctionStateMessage clone(GetAuctionStateMessage value) {
32+
return new GetAuctionStateMessage();
33+
}
34+
};
35+
}
36+
37+
@Override
38+
public Serializer<GetAuctionStateResponse> getReturnSerializer() {
39+
return new Serializer<>() {
40+
@Override
41+
public String serialize(GetAuctionStateResponse value) {
42+
JSONObject json = new JSONObject();
43+
json.put("auctionActive", value.auctionActive);
44+
if (value.auctionActive) {
45+
json.put("auctionId", value.auctionId.toString());
46+
json.put("phase", value.phase.toString());
47+
json.put("currentRound", value.currentRound);
48+
json.put("currentItemType", value.currentItemType);
49+
json.put("currentBid", value.currentBid);
50+
json.put("highestBidderId", value.highestBidderId != null ? value.highestBidderId.toString() : null);
51+
json.put("highestBidderName", value.highestBidderName);
52+
53+
JSONArray itemsArray = new JSONArray();
54+
for (String item : value.roundItems) {
55+
itemsArray.put(item);
56+
}
57+
json.put("roundItems", itemsArray);
58+
}
59+
return json.toString();
60+
}
61+
62+
@Override
63+
public GetAuctionStateResponse deserialize(String json) {
64+
JSONObject jsonObject = new JSONObject(json);
65+
boolean auctionActive = jsonObject.getBoolean("auctionActive");
66+
67+
if (!auctionActive) {
68+
return new GetAuctionStateResponse(false, null, null, 0, null, 0, null, null, List.of());
69+
}
70+
71+
UUID auctionId = UUID.fromString(jsonObject.getString("auctionId"));
72+
String phase = jsonObject.getString("phase");
73+
int currentRound = jsonObject.getInt("currentRound");
74+
String currentItemType = jsonObject.optString("currentItemType", null);
75+
long currentBid = jsonObject.getLong("currentBid");
76+
77+
String bidderIdStr = jsonObject.optString("highestBidderId", null);
78+
UUID highestBidderId = bidderIdStr != null && !bidderIdStr.equals("null") ? UUID.fromString(bidderIdStr) : null;
79+
String highestBidderName = jsonObject.optString("highestBidderName", null);
80+
81+
List<String> roundItems = new ArrayList<>();
82+
JSONArray itemsArray = jsonObject.optJSONArray("roundItems");
83+
if (itemsArray != null) {
84+
for (int i = 0; i < itemsArray.length(); i++) {
85+
roundItems.add(itemsArray.getString(i));
86+
}
87+
}
88+
89+
return new GetAuctionStateResponse(true, auctionId, DarkAuctionPhase.valueOf(phase), currentRound, currentItemType,
90+
currentBid, highestBidderId, highestBidderName, roundItems);
91+
}
92+
93+
@Override
94+
public GetAuctionStateResponse clone(GetAuctionStateResponse value) {
95+
return new GetAuctionStateResponse(value.auctionActive, value.auctionId, value.phase,
96+
value.currentRound, value.currentItemType, value.currentBid,
97+
value.highestBidderId, value.highestBidderName, new ArrayList<>(value.roundItems));
98+
}
99+
};
100+
}
101+
102+
public record GetAuctionStateMessage() {}
103+
104+
public record GetAuctionStateResponse(
105+
boolean auctionActive,
106+
UUID auctionId,
107+
DarkAuctionPhase phase,
108+
int currentRound,
109+
String currentItemType,
110+
long currentBid,
111+
UUID highestBidderId,
112+
String highestBidderName,
113+
List<String> roundItems
114+
) {}
115+
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
package net.swofty.commons.protocol.objects.darkauction;
2+
3+
import net.swofty.commons.protocol.ProtocolObject;
4+
import net.swofty.commons.protocol.Serializer;
5+
import org.json.JSONObject;
6+
7+
import java.util.UUID;
8+
9+
public class PlaceBidProtocol extends ProtocolObject<
10+
PlaceBidProtocol.PlaceBidMessage,
11+
PlaceBidProtocol.PlaceBidResponse> {
12+
13+
@Override
14+
public Serializer<PlaceBidMessage> getSerializer() {
15+
return new Serializer<>() {
16+
@Override
17+
public String serialize(PlaceBidMessage value) {
18+
JSONObject json = new JSONObject();
19+
json.put("auctionId", value.auctionId.toString());
20+
json.put("playerId", value.playerId.toString());
21+
json.put("playerName", value.playerName);
22+
json.put("bidAmount", value.bidAmount);
23+
return json.toString();
24+
}
25+
26+
@Override
27+
public PlaceBidMessage deserialize(String json) {
28+
JSONObject jsonObject = new JSONObject(json);
29+
return new PlaceBidMessage(
30+
UUID.fromString(jsonObject.getString("auctionId")),
31+
UUID.fromString(jsonObject.getString("playerId")),
32+
jsonObject.getString("playerName"),
33+
jsonObject.getLong("bidAmount")
34+
);
35+
}
36+
37+
@Override
38+
public PlaceBidMessage clone(PlaceBidMessage value) {
39+
return new PlaceBidMessage(value.auctionId, value.playerId, value.playerName, value.bidAmount);
40+
}
41+
};
42+
}
43+
44+
@Override
45+
public Serializer<PlaceBidResponse> getReturnSerializer() {
46+
return new Serializer<>() {
47+
@Override
48+
public String serialize(PlaceBidResponse value) {
49+
JSONObject json = new JSONObject();
50+
json.put("success", value.success);
51+
json.put("message", value.message);
52+
return json.toString();
53+
}
54+
55+
@Override
56+
public PlaceBidResponse deserialize(String json) {
57+
JSONObject jsonObject = new JSONObject(json);
58+
return new PlaceBidResponse(
59+
jsonObject.getBoolean("success"),
60+
jsonObject.getString("message")
61+
);
62+
}
63+
64+
@Override
65+
public PlaceBidResponse clone(PlaceBidResponse value) {
66+
return new PlaceBidResponse(value.success, value.message);
67+
}
68+
};
69+
}
70+
71+
public record PlaceBidMessage(
72+
UUID auctionId,
73+
UUID playerId,
74+
String playerName,
75+
long bidAmount
76+
) {}
77+
78+
public record PlaceBidResponse(
79+
boolean success,
80+
String message
81+
) {}
82+
}

0 commit comments

Comments
 (0)