Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes the other alliance bugs #141

Merged
merged 1 commit into from
Nov 12, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@

public class AllyCommand {

public static final Map<String, String> pendingAlliances = new HashMap<>(); // Tracks pending alliance requests
public static final Set<UUID> pendingDisbands = new HashSet<>(); // Tracks pending disbands by player UUID
public static final Map<String, String> pendingAlliances = new HashMap<>();
public static final Set<UUID> pendingDisbands = new HashSet<>();
private static final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);

public static void register(CommandDispatcher<CommandSourceStack> dispatcher) {
Expand All @@ -38,7 +38,6 @@ public static void register(CommandDispatcher<CommandSourceStack> dispatcher) {
.executes(AllyCommand::disband)));
}

// Initiates an ally request
private static int ally(CommandContext<CommandSourceStack> context) throws CommandSyntaxException {
ServerPlayer player = context.getSource().getPlayerOrException();
ServerPlayer allyPlayer = EntityArgument.getPlayer(context, "player");
Expand All @@ -47,22 +46,18 @@ private static int ally(CommandContext<CommandSourceStack> context) throws Comma
player.sendSystemMessage(Component.translatable("alliance.reignofnether.ally_self", player.getName().getString()));
return 0;
}
// Record the pending alliance
pendingAlliances.put(allyPlayer.getName().getString(), player.getName().getString());
context.getSource().sendSuccess(Component.translatable("alliance.reignofnether.sent_request", allyPlayer.getName().getString()), false);
allyPlayer.sendSystemMessage(Component.translatable("alliance.reignofnether.ally_confirm", player.getName().getString(), player.getName().getString()));

return Command.SINGLE_SUCCESS;
}

// Confirms an ally request
private static int allyConfirm(CommandContext<CommandSourceStack> context) throws CommandSyntaxException {
ServerPlayer player = context.getSource().getPlayerOrException();
ServerPlayer requesterPlayer = EntityArgument.getPlayer(context, "player");

// Check if there is a pending alliance request from the specified player
if (pendingAlliances.getOrDefault(player.getName().getString(), "").equals(requesterPlayer.getName().getString())) {
// Create the alliance
AllianceSystem.addAlliance(player.getName().getString(), requesterPlayer.getName().getString());
pendingAlliances.remove(player.getName().getString());

Expand All @@ -75,26 +70,31 @@ private static int allyConfirm(CommandContext<CommandSourceStack> context) throw
return Command.SINGLE_SUCCESS;
}

// Initiates disbanding an alliance with a delay
private static int disband(CommandContext<CommandSourceStack> context) throws CommandSyntaxException {
ServerPlayer player = context.getSource().getPlayerOrException();
ServerPlayer allyPlayer = EntityArgument.getPlayer(context, "player");

// Schedule disbanding after 30 seconds
if (player.equals(allyPlayer)) {
context.getSource().sendFailure(Component.translatable("alliance.reignofnether.disband_self"));
return 0;
}

UUID playerId = player.getUUID();
pendingDisbands.add(playerId);
if (pendingDisbands.contains(playerId)) {
context.getSource().sendFailure(Component.translatable("alliance.reignofnether.disband_pending", allyPlayer.getName().getString()));
return 0;
}

pendingDisbands.add(playerId);
scheduler.schedule(() -> {
// Check if still pending
if (pendingDisbands.remove(playerId)) {
AllianceSystem.removeAlliance(player.getName().getString(), allyPlayer.getName().getString());
player.sendSystemMessage(Component.translatable("alliance.reignofnether.disbanded", allyPlayer.getName().getString()));
allyPlayer.sendSystemMessage(Component.translatable("alliance.reignofnether.disbanded", player.getName().getString()));

}
}, 30, TimeUnit.SECONDS);

context.getSource().sendSuccess(Component.translatable("alliance.reignofnether.disbanding", allyPlayer.getName().getString()), false);
return Command.SINGLE_SUCCESS;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.mojang.blaze3d.platform.NativeImage;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.PoseStack;
import com.solegendary.reignofnether.alliance.AllianceSystem;
import com.solegendary.reignofnether.building.buildings.monsters.Laboratory;
import com.solegendary.reignofnether.building.buildings.piglins.Portal;
import com.solegendary.reignofnether.building.buildings.shared.AbstractBridge;
Expand Down Expand Up @@ -1019,13 +1020,23 @@ public static void syncBuildingBlocks(Building serverBuilding, int blocksPlaced)
}

public static Relationship getPlayerToBuildingRelationship(Building building) {
if (MC.player != null && building.ownerName.equals(MC.player.getName().getString())) {
return Relationship.OWNED;
} else if (building.ownerName.isBlank()) {
return Relationship.NEUTRAL;
} else {
return Relationship.HOSTILE;
if (MC.player != null) {
String playerName = MC.player.getName().getString();
String buildingOwnerName = building.ownerName;

if (playerName.equals(buildingOwnerName)) {
return Relationship.OWNED;
} else if (AllianceSystem.isAllied(playerName, buildingOwnerName)) {
return Relationship.FRIENDLY;
} else if (buildingOwnerName.isBlank()) {
return Relationship.NEUTRAL;
} else {
return Relationship.HOSTILE;
}
}

// If MC.player is null, we can't determine the relationship, so return NEUTRAL.
return Relationship.NEUTRAL;
}

// does the player own one of these buildings?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public static void updateOrthoviewY() {
int avgHeight = count > 0 ? sumHeights / count : playerPos.getY();

// Update ORTHOVIEW values based on the average height
ORTHOVIEW_PLAYER_BASE_Y = avgHeight + 40;
ORTHOVIEW_PLAYER_BASE_Y = Math.max(avgHeight + 40, 0);
ORTHOVIEW_PLAYER_MAX_Y = avgHeight + 100;
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/assets/reignofnether/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,8 @@
"alliance.reignofnether.no_request": "No pending alliance request from %s.",
"alliance.reignofnether.disbanded": "Your alliance with %s has been disbanded.",
"alliance.reignofnether.disbanding": "Disbanding alliance with %s in 30 seconds...",
"alliance.reignofnether.disband_self": "You cannot disband yourself.",
"alliance.reignofnether.disband_pending": "A disband request for this player is already pending.",

"survival.reignofnether.dawn": "Dawn breaks",
"survival.reignofnether.dusk": "Night falls...",
Expand Down
Loading