Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/cache@v2
- uses: actions/cache@v4
with:
path: |
~/.gradle/loom-cache
Expand Down
37 changes: 25 additions & 12 deletions src/main/java/xyz/nucleoid/parties/PartyCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static void register(CommandDispatcher<ServerCommandSource> dispatcher) {
.executes(PartyCommand::listParties)
)
.then(literal("invite")
.then(argument("player", EntityArgumentType.player())
.then(argument("players", EntityArgumentType.players())
.executes(PartyCommand::invitePlayer)
))
.then(literal("kick")
Expand Down Expand Up @@ -123,20 +123,33 @@ private static int invitePlayer(CommandContext<ServerCommandSource> ctx) throws
var source = ctx.getSource();
var owner = source.getPlayer();

var player = EntityArgumentType.getPlayer(ctx, "player");
var players = EntityArgumentType.getPlayers(ctx, "players");

int inviteCount = 0;
var partyManager = PartyManager.get(source.getServer());
var result = partyManager.invitePlayer(PlayerRef.of(owner), PlayerRef.of(player));
if (result.isOk()) {
source.sendFeedback(() -> PartyTexts.invitedSender(player).formatted(Formatting.GOLD), false);
for (var player : players) {
var result = partyManager.invitePlayer(PlayerRef.of(owner), PlayerRef.of(player));
if (result.isOk() | result.error() == PartyError.ALREADY_INVITED) {
if (players.size() == 1) {
source.sendFeedback(() -> PartyTexts.invitedSender(player, result.error() == PartyError.ALREADY_INVITED).formatted(Formatting.GOLD), false);
} else {
inviteCount++;
}

var notification = PartyTexts.invitedReceiver(owner, result.party().getUuid())
.formatted(Formatting.GOLD);
var notification = PartyTexts.invitedReceiver(owner, result.party().getUuid())
.formatted(Formatting.GOLD);

player.sendMessage(notification, false);
} else {
var error = result.error();
source.sendError(PartyTexts.displayError(error, player));
player.sendMessage(notification, false);
} else {
var error = result.error();
if (!(players.size() > 1 && (player == owner | error == PartyError.ALREADY_PARTY_MEMBER))) {
source.sendError(PartyTexts.displayError(error, player));
}
}
}
if (inviteCount > 0) {
int finalInviteCount = inviteCount;
source.sendFeedback(() -> PartyTexts.invitedSender(finalInviteCount).formatted(Formatting.GOLD), false);
}

return Command.SINGLE_SUCCESS;
Expand All @@ -155,7 +168,7 @@ private static int kickPlayer(CommandContext<ServerCommandSource> ctx) throws Co
if (result.isOk()) {
var party = result.party();

var message = PartyTexts.kickedSender(owner);
var message = PartyTexts.kickedSender(profile);
party.getMemberPlayers().sendMessage(message.formatted(Formatting.GOLD));

PlayerRef.of(profile).ifOnline(server, player -> {
Expand Down
1 change: 1 addition & 0 deletions src/main/java/xyz/nucleoid/parties/PartyError.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ public enum PartyError {
DOES_NOT_EXIST,
ALREADY_INVITED,
ALREADY_IN_PARTY,
ALREADY_PARTY_MEMBER,
CANNOT_REMOVE_SELF,
NOT_IN_PARTY,
NOT_INVITED
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/xyz/nucleoid/parties/PartyManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,16 @@ private void onPartyOwnerLogOut(ServerPlayerEntity player, Party party) {

public PartyResult invitePlayer(PlayerRef owner, PlayerRef player) {
var party = this.getOrCreateOwnParty(owner);

if (party != null) {
if (party.getMemberPlayers().contains(player)) {
return PartyResult.err(PartyError.ALREADY_PARTY_MEMBER);
}

if (party.invite(player)) {
return PartyResult.ok(party);
} else {
return PartyResult.err(PartyError.ALREADY_INVITED);
return PartyResult.err(party, PartyError.ALREADY_INVITED);
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/main/java/xyz/nucleoid/parties/PartyResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ public static PartyResult err(PartyError error) {
return new PartyResult(null, error);
}

public static PartyResult err(Party party, PartyError error) {
return new PartyResult(party, error);
}

public boolean isOk() {
return this.error == null;
}
Expand Down
15 changes: 12 additions & 3 deletions src/main/java/xyz/nucleoid/parties/PartyTexts.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.UUID;

import com.mojang.authlib.GameProfile;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.MutableText;
Expand All @@ -21,6 +22,7 @@ public static MutableText displayError(PartyError error, String player) {
case DOES_NOT_EXIST -> Text.translatable("text.game_parties.party.error.does_not_exist");
case ALREADY_INVITED -> Text.translatable("text.game_parties.party.error.already_invited", player);
case ALREADY_IN_PARTY -> Text.translatable("text.game_parties.party.error.already_in_party");
case ALREADY_PARTY_MEMBER-> Text.translatable("text.game_parties.party.error.already_party_member", player);
case CANNOT_REMOVE_SELF -> Text.translatable("text.game_parties.party.error.cannot_remove_self");
case NOT_IN_PARTY -> Text.translatable("text.game_parties.party.error.not_in_party", player);
case NOT_INVITED -> Text.translatable("text.game_parties.party.error.not_invited");
Expand Down Expand Up @@ -55,18 +57,25 @@ public static MutableText transferredReceiver(ServerPlayerEntity transferredFrom
return Text.translatable("text.game_parties.party.transferred.receiver", transferredFrom.getDisplayName());
}

public static MutableText kickedSender(ServerPlayerEntity player) {
return Text.translatable("text.game_parties.party.kicked.sender", player.getDisplayName());
public static MutableText kickedSender(GameProfile player) {
return Text.translatable("text.game_parties.party.kicked.sender", player.getName());
}

public static MutableText kickedReceiver() {
return Text.translatable("text.game_parties.party.kicked.receiver");
}

public static MutableText invitedSender(ServerPlayerEntity player) {
public static MutableText invitedSender(ServerPlayerEntity player, boolean again) {
if (again) {
return Text.translatable("text.game_parties.party.invited.sender.again", player.getDisplayName());
}
return Text.translatable("text.game_parties.party.invited.sender", player.getDisplayName());
}

public static MutableText invitedSender(int count) {
return Text.translatable("text.game_parties.party.invited.sender.multiple", count);
}

public static MutableText invitedReceiver(ServerPlayerEntity owner, UUID uuid) {
return Text.translatable("text.game_parties.party.invited.receiver", owner.getDisplayName())
.append(PartyTexts.inviteNotificationLink(owner, uuid));
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/data/game_parties/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"text.game_parties.party.disband.success": "Your party has been disbanded!",
"text.game_parties.party.error.already_in_party": "You are already in this party!",
"text.game_parties.party.error.already_invited": "%s is already invited to this party!",
"text.game_parties.party.error.already_party_member": "%s is already a party member!",
"text.game_parties.party.error.cannot_remove_self": "Cannot remove yourself from the party!",
"text.game_parties.party.error.does_not_exist": "You do not control any party!",
"text.game_parties.party.error.not_in_party": "%s is not in this party!",
Expand All @@ -11,6 +12,8 @@
"text.game_parties.party.invited.receiver.click": "Click here to join",
"text.game_parties.party.invited.receiver.hover": "Join %s's party!",
"text.game_parties.party.invited.sender": "Invited %s to the party",
"text.game_parties.party.invited.sender.again": "%s is already invited, sent notification again",
"text.game_parties.party.invited.sender.multiple": "Invited %s players to the party",
"text.game_parties.party.join.success": "%s has joined the party!",
"text.game_parties.party.kicked.receiver": "You have been kicked from the party",
"text.game_parties.party.kicked.sender": "%s has been kicked from the party",
Expand Down