Skip to content

Commit

Permalink
Reformat some code based on Mikey comments
Browse files Browse the repository at this point in the history
  • Loading branch information
UnRealDinnerbone committed Aug 5, 2024
1 parent ed77e24 commit edde049
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,43 +42,7 @@ public static Optional<ContextMenuItem> makeShareMenu(Player sharingPlayer, Wayp
.filter(p -> !p.id().equals(sharingPlayer.getGameProfile().getId()))
.map(KnownClientPlayer::profile).toList();
List<GameProfile> selectedProfiles = new ArrayList<>();
new AbstractButtonListScreen() {
@Override
protected void doCancel() {
closeGui();
}

@Override
protected void doAccept() {
List<UUID> 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();
}));
}

Expand All @@ -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<GameProfile> selectedProfiles;
private final Waypoint waypoint;
private final List<GameProfile> gameProfiles;

public ShareWaypointButtonList(List<GameProfile> selectedProfiles, Waypoint waypoint, List<GameProfile> gameProfiles) {
this.selectedProfiles = selectedProfiles;
this.waypoint = waypoint;
this.gameProfiles = gameProfiles;
}

@Override
protected void doCancel() {
closeGui();
}

@Override
protected void doAccept() {
List<UUID> 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);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<ServerPlayer> playersToSend = switch (message.shareType) {
case SERVER -> playerList.getPlayers();
case PARTY -> {
Expand All @@ -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();
Expand All @@ -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);
}
});
}
Expand Down

0 comments on commit edde049

Please sign in to comment.