From dcf275deb9974c9ca3cde97df8296a7a2f70824a Mon Sep 17 00:00:00 2001 From: olin Date: Tue, 12 Nov 2024 03:53:53 -0500 Subject: [PATCH] Fixes bugs --- .../reignofnether/alliance/AllyCommand.java | 26 +++++++++---------- .../building/BuildingClientEvents.java | 23 +++++++++++----- .../orthoview/OrthoviewClientEvents.java | 2 +- .../assets/reignofnether/lang/en_us.json | 2 ++ 4 files changed, 33 insertions(+), 20 deletions(-) diff --git a/src/main/java/com/solegendary/reignofnether/alliance/AllyCommand.java b/src/main/java/com/solegendary/reignofnether/alliance/AllyCommand.java index 8a712344..e58613d5 100644 --- a/src/main/java/com/solegendary/reignofnether/alliance/AllyCommand.java +++ b/src/main/java/com/solegendary/reignofnether/alliance/AllyCommand.java @@ -20,8 +20,8 @@ public class AllyCommand { - public static final Map pendingAlliances = new HashMap<>(); // Tracks pending alliance requests - public static final Set pendingDisbands = new HashSet<>(); // Tracks pending disbands by player UUID + public static final Map pendingAlliances = new HashMap<>(); + public static final Set pendingDisbands = new HashSet<>(); private static final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1); public static void register(CommandDispatcher dispatcher) { @@ -38,7 +38,6 @@ public static void register(CommandDispatcher dispatcher) { .executes(AllyCommand::disband))); } - // Initiates an ally request private static int ally(CommandContext context) throws CommandSyntaxException { ServerPlayer player = context.getSource().getPlayerOrException(); ServerPlayer allyPlayer = EntityArgument.getPlayer(context, "player"); @@ -47,7 +46,6 @@ private static int ally(CommandContext 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())); @@ -55,14 +53,11 @@ private static int ally(CommandContext context) throws Comma return Command.SINGLE_SUCCESS; } - // Confirms an ally request private static int allyConfirm(CommandContext 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()); @@ -75,26 +70,31 @@ private static int allyConfirm(CommandContext context) throw return Command.SINGLE_SUCCESS; } - // Initiates disbanding an alliance with a delay private static int disband(CommandContext 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; } -} \ No newline at end of file +} diff --git a/src/main/java/com/solegendary/reignofnether/building/BuildingClientEvents.java b/src/main/java/com/solegendary/reignofnether/building/BuildingClientEvents.java index a7bba781..f0d519d4 100644 --- a/src/main/java/com/solegendary/reignofnether/building/BuildingClientEvents.java +++ b/src/main/java/com/solegendary/reignofnether/building/BuildingClientEvents.java @@ -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; @@ -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? diff --git a/src/main/java/com/solegendary/reignofnether/orthoview/OrthoviewClientEvents.java b/src/main/java/com/solegendary/reignofnether/orthoview/OrthoviewClientEvents.java index 4eb23363..07d54ee6 100644 --- a/src/main/java/com/solegendary/reignofnether/orthoview/OrthoviewClientEvents.java +++ b/src/main/java/com/solegendary/reignofnether/orthoview/OrthoviewClientEvents.java @@ -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; } } diff --git a/src/main/resources/assets/reignofnether/lang/en_us.json b/src/main/resources/assets/reignofnether/lang/en_us.json index 9ff35738..595ff22f 100644 --- a/src/main/resources/assets/reignofnether/lang/en_us.json +++ b/src/main/resources/assets/reignofnether/lang/en_us.json @@ -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...",