Skip to content

Commit 0adf2c2

Browse files
committed
feat: Introduce party and chat channel systems with related events and services
1 parent 8aabfcf commit 0adf2c2

13 files changed

Lines changed: 935 additions & 2 deletions

‎build.gradle.kts‎

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

66
group = "com.github.ItsHarshXD"
7-
version = "90.1.0"
7+
version = "1.1.0"
88

99
java {
1010
sourceCompatibility = JavaVersion.VERSION_21

‎src/main/java/dev/itsharshxd/zentrix/api/ZentrixAPI.java‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22

33
import dev.itsharshxd.zentrix.api.addon.AddonManager;
44
import dev.itsharshxd.zentrix.api.broadcast.BroadcastService;
5+
import dev.itsharshxd.zentrix.api.chat.ChatChannelService;
56
import dev.itsharshxd.zentrix.api.classes.ClassService;
67
import dev.itsharshxd.zentrix.api.currency.CurrencyService;
78
import dev.itsharshxd.zentrix.api.data.DataService;
89
import dev.itsharshxd.zentrix.api.game.GameService;
910
import dev.itsharshxd.zentrix.api.gametype.GameTypeService;
1011
import dev.itsharshxd.zentrix.api.item.ItemService;
12+
import dev.itsharshxd.zentrix.api.party.PartyService;
1113
import dev.itsharshxd.zentrix.api.phase.PhaseService;
1214
import dev.itsharshxd.zentrix.api.player.PlayerService;
1315
import dev.itsharshxd.zentrix.api.profile.ProfileService;
@@ -46,6 +48,8 @@
4648
* <li>{@link BroadcastService} - Broadcast registration and management (since 1.1.0)</li>
4749
* <li>{@link GameTypeService} - Game type registration and management (since 1.1.0)</li>
4850
* <li>{@link ItemService} - Item registration and management (since 1.1.0)</li>
51+
* <li>{@link PartyService} - Party system operations (since 1.2.0)</li>
52+
* <li>{@link ChatChannelService} - Chat channel management (since 1.2.0)</li>
4953
* </ul>
5054
*
5155
* @author ItsHarshXD
@@ -326,4 +330,38 @@ static boolean isAvailable() {
326330
*/
327331
@NotNull
328332
ItemService getItemService();
333+
334+
/**
335+
* Gets the party service for party system operations.
336+
* <p>
337+
* Use this service to:
338+
* <ul>
339+
* <li>Query party state and membership</li>
340+
* <li>Create, disband, and manage parties</li>
341+
* <li>Invite, kick, and promote members</li>
342+
* </ul>
343+
* </p>
344+
*
345+
* @return The party service instance
346+
* @since 1.2.0
347+
*/
348+
@NotNull
349+
PartyService getPartyService();
350+
351+
/**
352+
* Gets the chat channel service for chat channel management.
353+
* <p>
354+
* Use this service to:
355+
* <ul>
356+
* <li>Get and set player chat channels</li>
357+
* <li>Toggle between available channels</li>
358+
* <li>Check channel availability (team, party)</li>
359+
* </ul>
360+
* </p>
361+
*
362+
* @return The chat channel service instance
363+
* @since 1.2.0
364+
*/
365+
@NotNull
366+
ChatChannelService getChatChannelService();
329367
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package dev.itsharshxd.zentrix.api.chat;
2+
3+
/**
4+
* Represents the available chat channels for players.
5+
* <p>
6+
* Players can switch between chat channels to communicate with
7+
* different groups:
8+
* <ul>
9+
* <li>{@link #GLOBAL} - All players can see messages</li>
10+
* <li>{@link #TEAM} - Only teammates in the same game can see messages</li>
11+
* <li>{@link #PARTY} - Only party members can see messages</li>
12+
* </ul>
13+
* </p>
14+
*
15+
* @author ItsHarshXD
16+
* @since 1.2.0
17+
*/
18+
public enum ChatChannel {
19+
20+
/**
21+
* Global chat channel. Messages are visible to all players.
22+
*/
23+
GLOBAL("global"),
24+
25+
/**
26+
* Team chat channel. Messages are visible only to teammates in the same game.
27+
*/
28+
TEAM("team"),
29+
30+
/**
31+
* Party chat channel. Messages are visible only to party members.
32+
*/
33+
PARTY("party");
34+
35+
private final String id;
36+
37+
ChatChannel(String id) {
38+
this.id = id;
39+
}
40+
41+
/**
42+
* Gets the string identifier for this channel.
43+
*
44+
* @return The channel ID (e.g., "global", "team", "party")
45+
*/
46+
public String getId() {
47+
return id;
48+
}
49+
50+
/**
51+
* Gets a ChatChannel by its ID (case-insensitive).
52+
*
53+
* @param id The channel ID
54+
* @return The ChatChannel, or {@link #GLOBAL} if not found or null
55+
*/
56+
public static ChatChannel fromId(String id) {
57+
if (id == null) return GLOBAL;
58+
for (ChatChannel channel : values()) {
59+
if (channel.id.equalsIgnoreCase(id)) {
60+
return channel;
61+
}
62+
}
63+
return GLOBAL;
64+
}
65+
}
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
package dev.itsharshxd.zentrix.api.chat;
2+
3+
import org.bukkit.entity.Player;
4+
import org.jetbrains.annotations.NotNull;
5+
6+
import java.util.UUID;
7+
8+
/**
9+
* Service for managing player chat channels in Zentrix.
10+
* <p>
11+
* Players can switch between global, team, and party chat channels.
12+
* Channel availability depends on the player's current state (in-game,
13+
* in a party, etc.).
14+
* </p>
15+
*
16+
* <h2>Example Usage</h2>
17+
* <pre>{@code
18+
* ChatChannelService chatService = ZentrixAPI.get().getChatChannelService();
19+
*
20+
* // Get a player's current channel
21+
* ChatChannel channel = chatService.getChannel(player);
22+
*
23+
* // Switch to team chat
24+
* if (chatService.canUseTeamChat(player)) {
25+
* chatService.setChannel(player, ChatChannel.TEAM);
26+
* }
27+
*
28+
* // Toggle through available channels
29+
* ChatChannel newChannel = chatService.toggleChannel(player);
30+
* player.sendMessage("Switched to " + newChannel.getId() + " chat");
31+
* }</pre>
32+
*
33+
* @author ItsHarshXD
34+
* @since 1.2.0
35+
*/
36+
public interface ChatChannelService {
37+
38+
/**
39+
* Gets a player's current chat channel.
40+
*
41+
* @param player The player
42+
* @return The player's current chat channel (defaults to {@link ChatChannel#GLOBAL})
43+
*/
44+
@NotNull
45+
ChatChannel getChannel(@NotNull Player player);
46+
47+
/**
48+
* Gets a player's current chat channel by UUID.
49+
*
50+
* @param playerId The player's UUID
51+
* @return The player's current chat channel (defaults to {@link ChatChannel#GLOBAL})
52+
*/
53+
@NotNull
54+
ChatChannel getChannel(@NotNull UUID playerId);
55+
56+
/**
57+
* Sets a player's chat channel.
58+
*
59+
* @param player The player
60+
* @param channel The channel to set
61+
*/
62+
void setChannel(@NotNull Player player, @NotNull ChatChannel channel);
63+
64+
/**
65+
* Toggles a player's chat channel to the next available channel.
66+
* <p>
67+
* Cycle order: GLOBAL &rarr; TEAM &rarr; PARTY &rarr; GLOBAL,
68+
* skipping channels that are not currently available to the player.
69+
* </p>
70+
*
71+
* @param player The player
72+
* @return The new chat channel after toggling
73+
*/
74+
@NotNull
75+
ChatChannel toggleChannel(@NotNull Player player);
76+
77+
/**
78+
* Resets a player's chat channel back to {@link ChatChannel#GLOBAL}.
79+
*
80+
* @param player The player
81+
*/
82+
void resetChannel(@NotNull Player player);
83+
84+
/**
85+
* Checks if a player can use team chat.
86+
* <p>
87+
* Team chat requires the player to be in a game with a team size greater
88+
* than 1 and not be a spectator.
89+
* </p>
90+
*
91+
* @param player The player
92+
* @return {@code true} if team chat is available
93+
*/
94+
boolean canUseTeamChat(@NotNull Player player);
95+
96+
/**
97+
* Checks if a player can use party chat.
98+
* <p>
99+
* Party chat requires the player to be in a party.
100+
* </p>
101+
*
102+
* @param player The player
103+
* @return {@code true} if party chat is available
104+
*/
105+
boolean canUsePartyChat(@NotNull Player player);
106+
}
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
package dev.itsharshxd.zentrix.api.events.chat;
2+
3+
import dev.itsharshxd.zentrix.api.chat.ChatChannel;
4+
import dev.itsharshxd.zentrix.api.events.ZentrixEvent;
5+
import org.bukkit.entity.Player;
6+
import org.bukkit.event.Cancellable;
7+
import org.bukkit.event.HandlerList;
8+
import org.jetbrains.annotations.NotNull;
9+
10+
import java.util.UUID;
11+
12+
/**
13+
* Called when a player switches their chat channel.
14+
* <p>
15+
* This event is <b>cancellable</b>. Cancelling prevents the channel change.
16+
* </p>
17+
*
18+
* <h2>Example Usage</h2>
19+
* <pre>{@code
20+
* @EventHandler
21+
* public void onChannelSwitch(ChatChannelSwitchEvent event) {
22+
* if (event.getNewChannel() == ChatChannel.PARTY) {
23+
* // Block switching to party chat for certain players
24+
* if (!hasPermission(event.getPlayer())) {
25+
* event.setCancelled(true);
26+
* }
27+
* }
28+
* }
29+
* }</pre>
30+
*
31+
* @author ItsHarshXD
32+
* @since 1.2.0
33+
*/
34+
public class ChatChannelSwitchEvent extends ZentrixEvent implements Cancellable {
35+
36+
private static final HandlerList HANDLERS = new HandlerList();
37+
38+
private final Player player;
39+
private final ChatChannel oldChannel;
40+
private ChatChannel newChannel;
41+
private boolean cancelled;
42+
43+
public ChatChannelSwitchEvent(@NotNull Player player,
44+
@NotNull ChatChannel oldChannel,
45+
@NotNull ChatChannel newChannel) {
46+
super(false);
47+
this.player = player;
48+
this.oldChannel = oldChannel;
49+
this.newChannel = newChannel;
50+
this.cancelled = false;
51+
}
52+
53+
/**
54+
* Gets the player switching channels.
55+
*
56+
* @return The player
57+
*/
58+
@NotNull
59+
public Player getPlayer() {
60+
return player;
61+
}
62+
63+
/**
64+
* Gets the player's UUID.
65+
*
66+
* @return The player's UUID
67+
*/
68+
@NotNull
69+
public UUID getPlayerId() {
70+
return player.getUniqueId();
71+
}
72+
73+
/**
74+
* Gets the channel the player is switching from.
75+
*
76+
* @return The old/current channel
77+
*/
78+
@NotNull
79+
public ChatChannel getOldChannel() {
80+
return oldChannel;
81+
}
82+
83+
/**
84+
* Gets the channel the player is switching to.
85+
*
86+
* @return The new channel
87+
*/
88+
@NotNull
89+
public ChatChannel getNewChannel() {
90+
return newChannel;
91+
}
92+
93+
/**
94+
* Sets the channel the player will switch to.
95+
* <p>
96+
* This allows addons to redirect channel switches.
97+
* </p>
98+
*
99+
* @param newChannel The new target channel
100+
*/
101+
public void setNewChannel(@NotNull ChatChannel newChannel) {
102+
this.newChannel = newChannel;
103+
}
104+
105+
@Override
106+
public boolean isCancelled() {
107+
return cancelled;
108+
}
109+
110+
@Override
111+
public void setCancelled(boolean cancel) {
112+
this.cancelled = cancel;
113+
}
114+
115+
@NotNull
116+
@Override
117+
public HandlerList getHandlers() {
118+
return HANDLERS;
119+
}
120+
121+
public static HandlerList getHandlerList() {
122+
return HANDLERS;
123+
}
124+
}

‎src/main/java/dev/itsharshxd/zentrix/api/events/currency/CurrencyChangeEvent.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
/**
1414
* Called when a player's currency balance is about to change.
1515
* <p>
16-
* This event is fired before the balance modification is applied, allowing
16+
* This event is fired <b>before</b> the balance modification is applied, allowing
1717
* addons to:
1818
* <ul>
1919
* <li>Cancel the change entirely</li>

0 commit comments

Comments
 (0)