Remove old IslandCreationPanel and move to the new one.

This commit is contained in:
BONNe 2024-01-04 09:39:02 +02:00
parent 7e05e6bacc
commit 328d6ffcda
4 changed files with 3 additions and 94 deletions

View File

@ -12,7 +12,7 @@ import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.objects.Island;
import world.bentobox.bentobox.managers.BlueprintsManager;
import world.bentobox.bentobox.managers.island.NewIsland;
import world.bentobox.bentobox.panels.IslandCreationPanel;
import world.bentobox.bentobox.panels.customizable.IslandCreationPanel;
import world.bentobox.bentobox.util.Util;
/**

View File

@ -16,7 +16,7 @@ import world.bentobox.bentobox.database.objects.Island;
import world.bentobox.bentobox.managers.BlueprintsManager;
import world.bentobox.bentobox.managers.island.NewIsland;
import world.bentobox.bentobox.managers.island.NewIsland.Builder;
import world.bentobox.bentobox.panels.IslandCreationPanel;
import world.bentobox.bentobox.panels.customizable.IslandCreationPanel;
import world.bentobox.bentobox.util.Util;
/**

View File

@ -1,91 +0,0 @@
package world.bentobox.bentobox.panels;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import org.eclipse.jdt.annotation.NonNull;
import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.api.commands.CompositeCommand;
import world.bentobox.bentobox.api.panels.PanelItem;
import world.bentobox.bentobox.api.panels.builders.PanelBuilder;
import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.blueprints.dataobjects.BlueprintBundle;
import world.bentobox.bentobox.managers.BlueprintsManager;
import world.bentobox.bentobox.util.Util;
/**
* Displays the available BlueprintBundles to pick up as the island.
* @author tastybento
* @since 1.5.0
*/
public class IslandCreationPanel {
private IslandCreationPanel() {}
/**
* Shows a player a panel of selectable blueprint bundles. Checks user's permission
* @param command - the command requesting the panel, e.g., create or reset
* @param user - the user
* @param label - label
*/
public static void openPanel(@NonNull CompositeCommand command, @NonNull User user, @NonNull String label) {
BentoBox plugin = BentoBox.getInstance();
// Create the panel
PanelBuilder pb = new PanelBuilder().name(user.getTranslation("commands.island.create.pick")).user(user);
// Get the bundles
Comparator<BlueprintBundle> sortByDisplayName = (p, o) -> p.getDisplayName().compareToIgnoreCase(o.getDisplayName());
List<BlueprintBundle> bbs = plugin.getBlueprintsManager().getBlueprintBundles(command.getAddon()).values()
.stream().sorted(sortByDisplayName).toList();
// Loop through them and create items in the panel
for (BlueprintBundle bb : bbs) {
String perm = command.getPermissionPrefix() + "island.create." + bb.getUniqueId();
if (bb.getUniqueId().equals(BlueprintsManager.DEFAULT_BUNDLE_NAME)
|| !bb.isRequirePermission()
|| user.hasPermission(perm)) {
// Add an item
PanelItem item = new PanelItemBuilder()
.name(bb.getDisplayName())
.description(bb.getDescription().stream().map(Util::translateColorCodes).toList())
.icon(bb.getIcon()).clickHandler((panel, user1, clickType, slot1) -> {
user1.closeInventory();
command.execute(user1, label, Collections.singletonList(bb.getUniqueId()));
return true;
}).build();
// Determine slot
if (bb.getSlot() < 0 || bb.getSlot() > BlueprintManagementPanel.MAX_BP_SLOT) {
bb.setSlot(0);
}
if (pb.slotOccupied(bb.getSlot())) {
int slot = getFirstAvailableSlot(pb);
if (slot == -1) {
// TODO add paging
plugin.logError("Too many blueprint bundles to show!");
pb.item(item);
} else {
pb.item(slot, item);
}
} else {
pb.item(bb.getSlot(), item);
}
}
}
pb.build();
}
/**
* @param pb - panel builder
* @return first available slot, or -1 if none
*/
private static int getFirstAvailableSlot(PanelBuilder pb) {
for (int i = 0; i < BlueprintManagementPanel.MAX_BP_SLOT; i++) {
if (!pb.slotOccupied(i)) {
return i;
}
}
return -1;
}
}

View File

@ -359,7 +359,7 @@ public class IslandCreationPanel
return null;
}
final String reference = "panels.buttons.bundle.";
final String reference = "panels.island_creation.buttons.bundle.";
// Get settings for island.
PanelItemBuilder builder = new PanelItemBuilder();