Skip to content
Merged
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
23 changes: 23 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,29 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

* * *

## [0.19.0]

### Added

- **Consistent party disband events for addons**
- Disbanding from the party screen, the provider API, the admin command, or BetterQuesting now respects `PartyEvent.Pre.Disbanded`. If an addon cancels it, party membership, claims, and link settings stay intact.
- `PartyEvent.Post.Disbanded` fires once after a successful disband. Both events expose the IDs of any additional BLPC party records scheduled for deletion or deleted, respectively, through `getBackingPartyIds()`.

### Changed

- **Stable IDs for linked BetterQuesting parties**
- Linked parties now use an ID derived from the BetterQuesting party itself, so ownership changes no longer change the party ID used by BLPC and addons.
- Existing ally and enemy settings targeting a linked party by its old BLPC ID still apply.

### Fixed

- **Disbanded BetterQuesting parties no longer restore old BLPC memberships**
- Successfully disbanding a linked party removes its members from their original BLPC party records. Empty parties are deleted, while parties with other members are preserved.

[0.19.0]: https://github.com/gtexpert/BetterLinkPartyClaim/releases/tag/v0.19.0-beta

* * *

## [0.18.2]

### Added
Expand Down
2 changes: 1 addition & 1 deletion buildscript.properties
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ modGroup = com.github.gtexpert.blpc

# Version of your mod.
# This field can be left empty if you want your mod's version to be determined by the latest git tag instead.
modVersion = 0.18.2-beta
modVersion = 0.19.0-beta

# Whether to use the old jar naming structure (modid-mcversion-version) instead of the new version (modid-version)
includeMCVersionJar = true
Expand Down
24 changes: 24 additions & 0 deletions src/main/java/com/github/gtexpert/blpc/api/event/PartyEvent.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.github.gtexpert.blpc.api.event;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.UUID;
Expand Down Expand Up @@ -106,8 +107,20 @@ public UUID getOwnerUUID() {
@Cancelable
public static class Disbanded extends Pre {

private final List<UUID> backingPartyIds;

public Disbanded(UUID partyId, String partyName) {
this(partyId, partyName, Collections.emptyList());
}

public Disbanded(UUID partyId, String partyName, List<UUID> backingPartyIds) {
super(partyId, partyName);
this.backingPartyIds = Collections.unmodifiableList(new ArrayList<>(backingPartyIds));
}

/** Additional BLPC records that would be deleted by this linked-party disband. */
public List<UUID> getBackingPartyIds() {
return backingPartyIds;
}
}
}
Expand Down Expand Up @@ -141,10 +154,21 @@ public UUID getOwnerUUID() {
public static class Disbanded extends Post {

private final List<UUID> memberUUIDs;
private final List<UUID> backingPartyIds;

public Disbanded(UUID partyId, String partyName, List<UUID> memberUUIDs) {
this(partyId, partyName, memberUUIDs, Collections.emptyList());
}

public Disbanded(UUID partyId, String partyName, List<UUID> memberUUIDs, List<UUID> backingPartyIds) {
super(partyId, partyName);
this.memberUUIDs = Collections.unmodifiableList(memberUUIDs);
this.backingPartyIds = Collections.unmodifiableList(new ArrayList<>(backingPartyIds));
}

/** Additional BLPC records deleted by this linked-party disband. */
public List<UUID> getBackingPartyIds() {
return backingPartyIds;
}

/** UUIDs of all members who were in the party at the time of disbanding. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;

/**
* Service Provider Interface for party management.
Expand Down Expand Up @@ -53,6 +54,22 @@ default Party getEffectiveParty(UUID playerUUID) {
return null;
}

/** UUID used by older saves for relations targeting this party. */
default UUID getLegacyRelationId(Party party) {
return party.getPartyId();
}

/** Resolves the old saved relation ID when the caller only has a target party ID. */
default UUID getLegacyRelationId(UUID partyId) {
return partyId;
}

/** Backing record for settings changes after the caller checks the effective role. */
@Nullable
default Party getSettingsParty(Party party) {
return party;
}

/** Convenience shortcut for {@code getEffectiveParty(uuid).getOwner()}. */
@Nullable
default UUID getOwner(UUID playerUUID) {
Expand Down Expand Up @@ -84,8 +101,15 @@ default List<Party> pendingInvitesFor(UUID playerUUID) {
/** Returns false if the player already has a party. */
boolean createParty(EntityPlayerMP player, String name);

/** Returns false on a veto without changing the party. */
/** Applies the disband veto before mutation; on success the provider persists and syncs the change. */
boolean disbandParty(EntityPlayerMP player);

/** Disbands a party for an already authorized administrative caller. */
default boolean disbandByAdmin(Party party, World world) {
return false;
}

boolean renameParty(EntityPlayerMP player, String newName);

boolean invitePlayer(EntityPlayerMP inviter, String targetUsername);
Expand Down
26 changes: 23 additions & 3 deletions src/main/java/com/github/gtexpert/blpc/api/party/Party.java
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,22 @@ public void setProtectExplosions(boolean protect) {
*/
@Nullable
public TrustLevel getEffectiveTrustLevel(UUID playerUUID, @Nullable UUID playerPartyId) {
return getEffectiveTrustLevel(playerUUID, playerPartyId, playerPartyId);
}

/** Resolves trust using the effective party ID and its legacy relation ID. */
@Nullable
public TrustLevel getEffectiveTrustLevel(UUID playerUUID, @Nullable UUID playerPartyId,
@Nullable UUID legacyPartyId) {
PartyRole role = members.get(playerUUID);
if (role != null) return role.toTrustLevel();
if (playerPartyId == null) return TrustLevel.NONE;

if (playerPartyId != null && enemies.contains(playerPartyId)) return null;
if (playerPartyId != null && allies.contains(playerPartyId)) return TrustLevel.ALLY;
return TrustLevel.NONE;
return switch (getRelation(playerPartyId, legacyPartyId)) {
case ENEMY -> null;
case ALLY -> TrustLevel.ALLY;
default -> TrustLevel.NONE;
};
}

public Set<UUID> getAllies() {
Expand Down Expand Up @@ -209,6 +219,16 @@ public void removeEnemy(UUID uuid) {
enemies.remove(uuid);
}

/** Resolves a relation to a party whose effective ID may differ from its old saved ID. */
public RelationType getRelation(UUID partyId, @Nullable UUID legacyId) {
if (isEnemy(partyId)) return RelationType.ENEMY;
if (isAlly(partyId)) return RelationType.ALLY;
if (legacyId == null || partyId.equals(legacyId)) return RelationType.NONE;
if (isEnemy(legacyId)) return RelationType.ENEMY;
if (isAlly(legacyId)) return RelationType.ALLY;
return RelationType.NONE;
}

public boolean isFreeToJoin() {
return freeToJoin;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,9 @@

import com.github.gtexpert.blpc.api.party.Party;
import com.github.gtexpert.blpc.api.party.PartyProviderRegistry;
import com.github.gtexpert.blpc.common.BLPCSaveHandler;
import com.github.gtexpert.blpc.common.chunk.ChunkManagerData;
import com.github.gtexpert.blpc.common.command.BLPCCommandHelper;
import com.github.gtexpert.blpc.common.network.ModNetwork;
import com.github.gtexpert.blpc.common.network.message.ClientNotify;
import com.github.gtexpert.blpc.common.party.PartyManagerData;

public class DisbandCommand extends AdminSubCommand {

Expand All @@ -46,15 +43,9 @@ public void execute(@NotNull MinecraftServer server, @NotNull ICommandSender sen
String partyName = party.getName();
List<UUID> members = new ArrayList<>(party.getMemberUUIDs());

PartyManagerData pm = PartyManagerData.getInstance();
pm.removeParty(party.getPartyId());
ChunkManagerData.getInstance().releaseAllMemberClaims(members, sender.getEntityWorld());
for (UUID memberId : members) {
pm.setBQuLinked(memberId, false);
if (!PartyProviderRegistry.get().disbandByAdmin(party, sender.getEntityWorld())) {
throw new CommandException("command.blpc.disband.denied", partyName);
}
PartyProviderRegistry.get().syncToAll();
BLPCSaveHandler.INSTANCE.markDirty();

ModNetwork.broadcastToMembers(members, null, server,
ClientNotify.partyEvent(ClientNotify.EVENT_DISBANDED, "", ""));
sender.sendMessage(new TextComponentTranslation("command.blpc.disband.success", partyName));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,9 @@
import com.github.gtexpert.blpc.api.event.PartyEvent;
import com.github.gtexpert.blpc.api.party.*;
import com.github.gtexpert.blpc.common.BLPCSaveHandler;
import com.github.gtexpert.blpc.common.chunk.ChunkManagerData;
import com.github.gtexpert.blpc.common.network.ModNetwork;
import com.github.gtexpert.blpc.common.party.DefaultPartyProvider;
import com.github.gtexpert.blpc.common.party.PartyManagerData;
import com.github.gtexpert.blpc.common.waypoint.WaypointManagerData;

import io.netty.buffer.ByteBuf;

Expand Down Expand Up @@ -235,8 +233,10 @@ private static void dispatch(PartyAction msg, MessageContext ctx) {
};

if (success) {
c.provider.syncToAll();
BLPCSaveHandler.INSTANCE.markDirty();
if (msg.getAction() != PartyAction.ACTION_DISBAND) {
c.provider.syncToAll();
BLPCSaveHandler.INSTANCE.markDirty();
}
for (Runnable notification : c.pendingNotifications) {
notification.run();
}
Expand Down Expand Up @@ -271,25 +271,10 @@ private static boolean createParty(ActionContext c) {

private static boolean disbandParty(ActionContext c) {
UUID playerId = c.player.getUniqueID();
PartyManagerData pm = PartyManagerData.getInstance();
Party party = c.provider.getEffectiveParty(playerId);
Party party = c.activeProvider.getEffectiveParty(playerId);
if (party == null) return false;

PartyRole role = party.getRole(playerId);
if (role != PartyRole.OWNER && !c.player.canUseCommand(2, "")) return false;

UUID partyId = party.getPartyId();
String partyName = party.getName();
if (MinecraftForge.EVENT_BUS.post(new PartyEvent.Pre.Disbanded(partyId, partyName))) return false;

List<UUID> members = new ArrayList<>(party.getMemberUUIDs());
pm.removeParty(partyId);
ChunkManagerData.getInstance().releaseAllMemberClaims(members, c.player.world);
WaypointManagerData.getInstance().removeParty(partyId);
for (UUID memberId : members) {
pm.setBQuLinked(memberId, false);
}
MinecraftForge.EVENT_BUS.post(new PartyEvent.Post.Disbanded(partyId, partyName, members));
if (!c.activeProvider.disbandParty(c.player)) return false;
MinecraftServer srv = c.player.getServer();
// The party record is already gone — broadcast against the pre-disband member
// snapshot, not a fresh provider lookup.
Expand Down Expand Up @@ -497,19 +482,36 @@ private static boolean toggleExplosionProtection(ActionContext c) {
}

private static boolean updateRelation(ActionContext c, int action) {
return onAdminParty(c, party -> {
return onAdminParty(c, effective -> {
UUID targetPartyId;
try {
targetPartyId = UUID.fromString(c.stringArg);
} catch (IllegalArgumentException e) {
return false;
}
if (targetPartyId.equals(party.getPartyId())) return false;
if (targetPartyId.equals(effective.getPartyId())) return false;
Party party = c.activeProvider.getSettingsParty(effective);
if (party == null) return false;
PartyRole storedRole = party.getRole(c.player.getUniqueID());
if (storedRole == null || !storedRole.canInvite()) return false;
UUID legacyId = c.provider.getLegacyRelationId(targetPartyId);
switch (action) {
case PartyAction.ACTION_ADD_ALLY -> party.addAlly(targetPartyId);
case PartyAction.ACTION_REMOVE_ALLY -> party.removeAlly(targetPartyId);
case PartyAction.ACTION_ADD_ENEMY -> party.addEnemy(targetPartyId);
case PartyAction.ACTION_REMOVE_ENEMY -> party.removeEnemy(targetPartyId);
case PartyAction.ACTION_ADD_ALLY -> {
party.removeEnemy(legacyId);
party.addAlly(targetPartyId);
}
case PartyAction.ACTION_REMOVE_ALLY -> {
party.removeAlly(targetPartyId);
party.removeAlly(legacyId);
}
case PartyAction.ACTION_ADD_ENEMY -> {
party.removeAlly(legacyId);
party.addEnemy(targetPartyId);
}
case PartyAction.ACTION_REMOVE_ENEMY -> {
party.removeEnemy(targetPartyId);
party.removeEnemy(legacyId);
}
}
return true;
});
Expand Down
Loading
Loading