Skip to content
Closed
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 @@ -172,7 +172,12 @@ private boolean handleLayoutAction(GuiLayout layout, Player player, SpawnerData
}
// If no items to sell, still allow exp collection
if (spawner.getVirtualInventory().getUsedSlots() == 0) {
boolean success = handleExpBottleAcceptedClick(player, spawner, true);
boolean success = false;
if (spawner.getSpawnerExp() > 0) {
success = tryCollectExpForPlayer(player, spawner);
} else {
messageService.sendMessage(player, "spawner_storage_empty");
}
playActionResult(player, button, clickType, success);
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,10 +227,10 @@ private void handleSellAction(Player player, SpawnerData spawner, boolean collec

// Check if there are items to sell
if (spawner.getVirtualInventory().getUsedSlots() == 0) {
if (collectExp) {
// No items to sell but still collect exp
if (collectExp && spawner.getSpawnerExp() > 0) {
// No items to sell, but collect available exp without leaving the storage GUI
boolean success = plugin.getSpawnerMenuAction()
.handleExpBottleAcceptedClick(player, spawner, true);
.tryCollectExpForPlayer(player, spawner);
playActionResult(player, sourceButton, sourceClickType, success);
} else {
messageService.sendMessage(player, "spawner_storage_empty");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ public void checkAndUpdateLayouts() {
plugin.getResource(resource),
java.util.List.of(),
ConfigMigrations.GUI_LAYOUT,
true,
YamlMigrator.OwnedSection.fullyUserManaged(
(defaults, path) -> !path.contains(".") && path.startsWith("slot_")),
plugin.getLogger());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,18 +71,22 @@ public interface SectionMatcher {
* children back would resurrect deleted drops, or put a chat line back under a message the
* owner turned into an action bar.</p>
*
* <p>Either way, once the user has the section its contents are left alone. The two factories
* <p>Either way, once the user has the section its contents are left alone. The factories
* differ only in what an <em>absent</em> section means, which is not the same question for a
* drop list as for a message.</p>
* drop list, a message, or a fully user-managed GUI button list.</p>
*/
public record OwnedSection(SectionMatcher matcher, boolean keepDeleted) {
public record OwnedSection(SectionMatcher matcher, boolean keepDeleted, boolean alwaysLocked) {

public OwnedSection(SectionMatcher matcher, boolean keepDeleted) {
this(matcher, keepDeleted, false);
}

/**
* For a list the user curates. A section they removed entirely stays removed, as long as
* they still have its parent. Deleting a mob's whole {@code loot} block has to stick.
*/
public static OwnedSection curated(SectionMatcher matcher) {
return new OwnedSection(matcher, true);
return new OwnedSection(matcher, true, false);
}

/**
Expand All @@ -92,7 +96,15 @@ public static OwnedSection curated(SectionMatcher matcher) {
* theirs; only a wholly absent message is refilled.
*/
public static OwnedSection restoredWhenAbsent(SectionMatcher matcher) {
return new OwnedSection(matcher, false);
return new OwnedSection(matcher, false, false);
}

/**
* For sections whose presence and contents are both controlled by the user. Matching
* default sections are never topped up, even when the user removed or relocated them.
*/
public static OwnedSection fullyUserManaged(SectionMatcher matcher) {
return new OwnedSection(matcher, true, true);
}
}

Expand Down Expand Up @@ -247,14 +259,19 @@ private static int addMissingKeys(YamlConfiguration user, YamlConfiguration defa
* leaf of a brand new section create that section, after which every remaining leaf of it looks
* user-owned and gets skipped, leaving the section half filled.</p>
*
* <p>A section the user has is always owned. A section they do not have is owned only for a
* {@link OwnedSection#curated} marker, and then only when they still have its parent, which is
* what tells a block they deleted apart from one they have never seen.</p>
* <p>A section the user has is always owned. A fully user-managed section is also owned when
* absent. Other absent sections are owned only for a {@link OwnedSection#curated} marker, and
* then only when they still have its parent, which tells a block they deleted apart from one
* they have never seen.</p>
*/
private static Set<String> lockedSections(YamlConfiguration user, YamlConfiguration defaults, OwnedSection owned) {
Set<String> locked = new HashSet<>();
for (String path : defaults.getKeys(true)) {
if (!defaults.isConfigurationSection(path) || !owned.matcher().matches(defaults, path)) continue;
if (owned.alwaysLocked()) {
locked.add(path);
continue;
}
if (user.isConfigurationSection(path)) {
locked.add(path);
continue;
Expand Down
Loading