Skip to content
Open
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 @@ -92,6 +92,10 @@ public boolean showChangelogHeader() {
return getBoolean("dialog_header", true);
}

public boolean allowCloseWithoutRead() {
return getBoolean("allow_close_without_read", false);
}

public boolean useNativeFallbackPermissions() {
return getBoolean("use_native_fallback_permissions", false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ public void recreate() {
plugin.pluginConfig().getDateFormatter(),
plugin.pluginConfig().showChangelogHeader(),
plugin.pluginConfig().createChangelogHeaderStack(),
plugin.pluginConfig().useNativeFallbackPermissions()
plugin.pluginConfig().useNativeFallbackPermissions(),
plugin.pluginConfig().allowCloseWithoutRead()
));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@
import com.codingcat.changelogs.base.dialog.ui.editor.EditorSession;
import com.codingcat.changelogs.platformapi.player.IPlayer;
import com.github.retrooper.packetevents.protocol.dialog.CommonDialogData;
import com.github.retrooper.packetevents.protocol.dialog.ConfirmationDialog;
import com.github.retrooper.packetevents.protocol.dialog.Dialog;
import com.github.retrooper.packetevents.protocol.dialog.DialogAction;
import com.github.retrooper.packetevents.protocol.dialog.NoticeDialog;
import com.github.retrooper.packetevents.protocol.dialog.action.Action;
import com.github.retrooper.packetevents.protocol.dialog.body.DialogBody;
import com.github.retrooper.packetevents.protocol.dialog.body.ItemDialogBody;
import com.github.retrooper.packetevents.protocol.dialog.body.PlainMessage;
Expand Down Expand Up @@ -49,6 +51,7 @@ public class ChangelogDialog implements IDialog {
private final boolean addHeader;
private final @Nullable ItemStack headerItem;
private final boolean useFallbackPermissions;
private final boolean allowCloseWithoutRead;

@Override
public @NotNull Dialog build(@NotNull IPlayer p, @NotNull DialogSessionManager sessionManager) {
Expand Down Expand Up @@ -76,11 +79,23 @@ public class ChangelogDialog implements IDialog {
null, true, false,
canManage ? DialogAction.NONE : DialogAction.CLOSE, body, List.of()
);
ActionButton button = new ActionButton(new CommonButtonData(
ActionButton readAllButton = new ActionButton(new CommonButtonData(
translatableManual(p, "dialog.changelog.button.read_all"),
null, 100
), sessionManager.createStaticAction(this, "confirm_read"));
Action closeAction = null;
if (canManage) closeAction = sessionManager.createSessionBasedAction(this, "close", false);
// Configuration-phase viewers need a callback to release the join freeze after closing without reading.
else if (this.allowCloseWithoutRead && sessionManager.isFrozen(p))
closeAction = sessionManager.createStaticAction(this, "close");
ActionButton closeButton = new ActionButton(new CommonButtonData(
translatableManual(p, "dialog.changelog.button.close"),
null, 60
), sessionManager.createStaticAction(this, "confirm_read"));
return new NoticeDialog(common, button);
), closeAction);
boolean hasUnreadEntries = this.storage.listEntries().stream().anyMatch(e -> !e.hasRead(p));
if (!hasUnreadEntries) return new NoticeDialog(common, closeButton);
if (this.allowCloseWithoutRead) return new ConfirmationDialog(common, readAllButton, closeButton);
return new NoticeDialog(common, new ActionButton(closeButton.getButton(), readAllButton.getAction()));
}

private @NotNull Component formatEntry(@NotNull ChangelogEntry entry, @NotNull IPlayer player, @NotNull DialogSessionManager sessionManager, boolean canManage) {
Expand Down Expand Up @@ -134,6 +149,12 @@ public void onActionTriggered(@NotNull String action, @Nullable NBTCompound data
if (!uids.isEmpty())
source.asAudience().sendMessage(translatable("dialog.changelog.read", text(uids.size())));
}
case "close" -> {
if (canManage) {
sessionManager.endSession(source);
DialogPackets.clearDialog(source, DialogPackets.PacketPhase.PLAY);
}
}
case "reopen" -> {
if (canManage) this.showTo(source, sessionManager, DialogPackets.PacketPhase.PLAY);
}
Expand Down Expand Up @@ -166,7 +187,7 @@ public void onActionTriggered(@NotNull String action, @Nullable NBTCompound data
}
} finally {
// Ensure the player is able to continue gameplay even if any exceptions occur
if (action.equals("confirm_read")) sessionManager.unfreeze(source);
if (action.equals("confirm_read") || action.equals("close")) sessionManager.unfreeze(source);
}
}

Expand Down
6 changes: 5 additions & 1 deletion base/src/main/resources/defaults/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ use_native_fallback_permissions: false
# The CONFIGURATION phase has the advantage of players not being able to take damage etc. due to the dialogs.
dialog_phase: CONFIGURATION

# Whether players can close the changelog dialog without marking unread entries as read.
# When disabled, exiting the dialog automatically marks all entries as read.
allow_close_without_read: false

# Whether to add a header section to the changelog dialog that will show
# above the actual changelogs. This can be used to give players a bit of context,
# or link to e.g. a discord to give feedback, follow announcements, etc.
Expand All @@ -60,4 +64,4 @@ dialog_header_item: "minecraft:written_book"
# -- DO NOT MODIFY UNLESS YOU KNOW WHAT YOU ARE DOING --
# Manually enable workarounds/fixes for certain bugs in e.g. PacketEvents
# that normally don't apply to the current version
enable_manual_workarounds: []
enable_manual_workarounds: []
5 changes: 3 additions & 2 deletions base/src/main/resources/lang/en_US.yml
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ dialog: # Translations for the plugin's dialog UIs
entry_line: "<gray>- <reset><arg:0>" # The format for a single changelog line (adds a gray dash in front)
unspecified_author: "<dark_red>Unspecified" # The author that will be shown when this field was left empty during publishing
button:
close: "<translate:icon.confirm> <green>Exit"
read_all: "<translate:icon.confirm> <green>Read All"
close: "<translate:icon.deny> <red>Exit"
read: "<prefix><translate:icon.confirm> <green>Marked <yellow><arg:0></yellow> entries as read!"
manage:
changelog_action:
Expand All @@ -133,4 +134,4 @@ dialog: # Translations for the plugin's dialog UIs
content: |-
Are you sure that you want to <b><red>delete</red></b> the <aqua>selected changelog</aqua>?

Please note that this action <b><red>CANNOT BE UNDONE</red></b>!
Please note that this action <b><red>CANNOT BE UNDONE</red></b>!
3 changes: 2 additions & 1 deletion base/src/main/resources/lang/ru_RU.yml
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ dialog: # Переводы диалоговых интерфейсов (UI) пл
entry_line: "<gray>- <reset><arg:0>" # Формат строки (добавляет серый дефис в начале)
unspecified_author: "<dark_red>Не указан" # Автор по умолчанию
button:
close: "<translate:icon.confirm> <green>Выход"
read_all: "<translate:icon.confirm> <green>Прочитать всё"
close: "<translate:icon.deny> <red>Выход"
read: "<prefix><translate:icon.confirm> <green>Отмечено как прочитанные: <yellow><arg:0></yellow>!"
manage:
changelog_action:
Expand Down
Loading