diff --git a/common/src/main/java/dev/ftb/mods/ftbchunks/client/gui/WaypointShareMenu.java b/common/src/main/java/dev/ftb/mods/ftbchunks/client/gui/WaypointShareMenu.java index 3b1c37f6..86a3bbb2 100644 --- a/common/src/main/java/dev/ftb/mods/ftbchunks/client/gui/WaypointShareMenu.java +++ b/common/src/main/java/dev/ftb/mods/ftbchunks/client/gui/WaypointShareMenu.java @@ -42,43 +42,7 @@ public static Optional makeShareMenu(Player sharingPlayer, Wayp .filter(p -> !p.id().equals(sharingPlayer.getGameProfile().getId())) .map(KnownClientPlayer::profile).toList(); List selectedProfiles = new ArrayList<>(); - new AbstractButtonListScreen() { - @Override - protected void doCancel() { - closeGui(); - } - - @Override - protected void doAccept() { - List toShare = selectedProfiles.stream().map(GameProfile::getId).toList(); - if (!toShare.isEmpty()) { - shareWaypoint(waypoint, ShareWaypointPacket.ShareType.PLAYER, toShare); - } - closeGui(); - } - - @Override - public void addButtons(Panel panel) { - for (GameProfile gameProfile : list) { - Component unchecked = (Component.literal("☐ ")).append(gameProfile.getName()); - Component checked = (Component.literal("☑ ").withStyle(ChatFormatting.GREEN)).append(gameProfile.getName()); - NordButton widget = new NordButton(panel, unchecked, FaceIcon.getFace(gameProfile)) { - @Override - public void onClicked(MouseButton button) { - if (selectedProfiles.contains(gameProfile)) { - selectedProfiles.remove(gameProfile); - title = unchecked; - } else { - selectedProfiles.add(gameProfile); - title = checked; - } - playClickSound(); - } - }; - panel.add(widget); - } - } - }.openGui(); + new ShareWaypointButtonList(selectedProfiles, waypoint, list).openGui(); })); } @@ -92,4 +56,52 @@ private static void shareWaypoint(Waypoint waypoint, ShareWaypointPacket.ShareTy NetworkManager.sendToServer(new ShareWaypointPacket(waypoint.getName(), waypointPos, type, targets)); SimpleToast.info(Component.translatable("ftbchunks.waypoint.shared_by_you", waypoint.getName()), Component.empty()); } + + private static class ShareWaypointButtonList extends AbstractButtonListScreen { + private final List selectedProfiles; + private final Waypoint waypoint; + private final List gameProfiles; + + public ShareWaypointButtonList(List selectedProfiles, Waypoint waypoint, List gameProfiles) { + this.selectedProfiles = selectedProfiles; + this.waypoint = waypoint; + this.gameProfiles = gameProfiles; + } + + @Override + protected void doCancel() { + closeGui(); + } + + @Override + protected void doAccept() { + List toShare = selectedProfiles.stream().map(GameProfile::getId).toList(); + if (!toShare.isEmpty()) { + shareWaypoint(waypoint, ShareWaypointPacket.ShareType.PLAYER, toShare); + } + closeGui(); + } + + @Override + public void addButtons(Panel panel) { + for (GameProfile gameProfile : gameProfiles) { + Component unchecked = (Component.literal("☐ ")).append(gameProfile.getName()); + Component checked = (Component.literal("☑ ").withStyle(ChatFormatting.GREEN)).append(gameProfile.getName()); + NordButton widget = new NordButton(panel, unchecked, FaceIcon.getFace(gameProfile)) { + @Override + public void onClicked(MouseButton button) { + if (selectedProfiles.contains(gameProfile)) { + selectedProfiles.remove(gameProfile); + title = unchecked; + } else { + selectedProfiles.add(gameProfile); + title = checked; + } + playClickSound(); + } + }; + panel.add(widget); + } + } + } } diff --git a/common/src/main/java/dev/ftb/mods/ftbchunks/net/ShareWaypointPacket.java b/common/src/main/java/dev/ftb/mods/ftbchunks/net/ShareWaypointPacket.java index 61f26e5c..483cb9aa 100644 --- a/common/src/main/java/dev/ftb/mods/ftbchunks/net/ShareWaypointPacket.java +++ b/common/src/main/java/dev/ftb/mods/ftbchunks/net/ShareWaypointPacket.java @@ -41,7 +41,6 @@ public static void handle(ShareWaypointPacket message, NetworkManager.PacketCont context.queue(() -> { ServerPlayer serverPlayer = (ServerPlayer) context.getPlayer(); PlayerList playerList = serverPlayer.getServer().getPlayerList(); - ChatType.Bound bound2 = ChatType.bind(ChatType.CHAT, serverPlayer).withTargetName(serverPlayer.getDisplayName()); List playersToSend = switch (message.shareType) { case SERVER -> playerList.getPlayers(); case PARTY -> { @@ -58,6 +57,9 @@ public static void handle(ShareWaypointPacket message, NetworkManager.PacketCont .map(playerList::getPlayer) .filter(Objects::nonNull).toList(); }; + + ChatType.Bound chatBound = ChatType.bind(ChatType.CHAT, serverPlayer).withTargetName(serverPlayer.getDisplayName()); + for (ServerPlayer playerListPlayer : playersToSend) { String cords = message.position.pos().getX() + " " + message.position.pos().getY() + " " + message.position.pos().getZ(); String dim = message.position.dimension().location().toString(); @@ -70,7 +72,7 @@ public static void handle(ShareWaypointPacket message, NetworkManager.PacketCont playerListPlayer.sendChatMessage(OutgoingChatMessage.create(PlayerChatMessage.system("") .withUnsignedContent(Component.translatable("ftbchunks.waypoint.shared", waypointText) .withStyle(style -> - style.withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/ftbchunks waypoint add \"" + message.name + "\" " + cords + " " + dim + " white true"))))), false, bound2); + style.withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/ftbchunks waypoint add \"" + message.name + "\" " + cords + " " + dim + " white true"))))), false, chatBound); } }); }