From 7ea0edea9122f7ba7fb791662d5f0335a00bd174 Mon Sep 17 00:00:00 2001 From: tastybento Date: Sat, 18 May 2019 12:22:19 -0700 Subject: [PATCH] Shifted panel to IslandCreationPanel --- .../blueprints/AdminBlueprintCommand.java | 2 +- .../commands/island/IslandCreateCommand.java | 3 +- .../commands/island/IslandResetCommand.java | 5 +- .../bentobox/managers/BlueprintsManager.java | 74 +++++-------------- .../bentobox/panels/IslandCreationPanel.java | 57 +++++++------- 5 files changed, 56 insertions(+), 85 deletions(-) diff --git a/src/main/java/world/bentobox/bentobox/api/commands/admin/blueprints/AdminBlueprintCommand.java b/src/main/java/world/bentobox/bentobox/api/commands/admin/blueprints/AdminBlueprintCommand.java index 20580804f..f412983ad 100644 --- a/src/main/java/world/bentobox/bentobox/api/commands/admin/blueprints/AdminBlueprintCommand.java +++ b/src/main/java/world/bentobox/bentobox/api/commands/admin/blueprints/AdminBlueprintCommand.java @@ -25,7 +25,7 @@ public class AdminBlueprintCommand extends ConfirmableCommand { private static final Particle.DustOptions PARTICLE_DUST_OPTIONS = new Particle.DustOptions(Color.RED, 1.0F); public AdminBlueprintCommand(CompositeCommand parent) { - super(parent, "blueprint", "bp"); + super(parent, "blueprint", "bp", "blu"); } @Override diff --git a/src/main/java/world/bentobox/bentobox/api/commands/island/IslandCreateCommand.java b/src/main/java/world/bentobox/bentobox/api/commands/island/IslandCreateCommand.java index 2d6ea5223..111fda006 100644 --- a/src/main/java/world/bentobox/bentobox/api/commands/island/IslandCreateCommand.java +++ b/src/main/java/world/bentobox/bentobox/api/commands/island/IslandCreateCommand.java @@ -66,8 +66,7 @@ public class IslandCreateCommand extends CompositeCommand { return makeIsland(user, name); } else { // Show panel - getPlugin().getBlueprintsManager().showPanel(this, user, label); - //IslandCreationPanel.openPanel(user, (GameModeAddon) getAddon()); + IslandCreationPanel.openPanel(this, user, label); return true; } } diff --git a/src/main/java/world/bentobox/bentobox/api/commands/island/IslandResetCommand.java b/src/main/java/world/bentobox/bentobox/api/commands/island/IslandResetCommand.java index 60fe976ae..968273303 100644 --- a/src/main/java/world/bentobox/bentobox/api/commands/island/IslandResetCommand.java +++ b/src/main/java/world/bentobox/bentobox/api/commands/island/IslandResetCommand.java @@ -86,10 +86,9 @@ public class IslandResetCommand extends ConfirmableCommand { } else { // Show panel after confirmation if (getPlugin().getSettings().isResetConfirmation()) { - this.askConfirmation(user, () -> getPlugin().getBlueprintsManager().showPanel(this, user, label)); + this.askConfirmation(user, () -> IslandCreationPanel.openPanel(this, user, label)); } else { - getPlugin().getBlueprintsManager().showPanel(this, user, label); - //IslandCreationPanel.openPanel(user, (GameModeAddon) getAddon()); + IslandCreationPanel.openPanel(this, user, label); } return true; } diff --git a/src/main/java/world/bentobox/bentobox/managers/BlueprintsManager.java b/src/main/java/world/bentobox/bentobox/managers/BlueprintsManager.java index 1bf4eba45..5fe7f7e5a 100644 --- a/src/main/java/world/bentobox/bentobox/managers/BlueprintsManager.java +++ b/src/main/java/world/bentobox/bentobox/managers/BlueprintsManager.java @@ -1,22 +1,35 @@ package world.bentobox.bentobox.managers; -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import com.google.gson.InstanceCreator; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.lang.reflect.ParameterizedType; +import java.lang.reflect.Type; +import java.util.Collections; +import java.util.EnumMap; +import java.util.HashMap; +import java.util.Locale; +import java.util.Map; +import java.util.Objects; +import java.util.TreeMap; +import java.util.jar.JarFile; + import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.World; import org.bukkit.util.Vector; import org.eclipse.jdt.annotation.NonNull; import org.eclipse.jdt.annotation.Nullable; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.InstanceCreator; + import world.bentobox.bentobox.BentoBox; import world.bentobox.bentobox.api.addons.Addon; import world.bentobox.bentobox.api.addons.GameModeAddon; -import world.bentobox.bentobox.api.commands.CompositeCommand; import world.bentobox.bentobox.api.localization.TextVariables; -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.Blueprint; import world.bentobox.bentobox.blueprints.BlueprintPaster; @@ -27,22 +40,6 @@ import world.bentobox.bentobox.database.objects.Island; import world.bentobox.bentobox.schems.SchemToBlueprint; import world.bentobox.bentobox.util.Util; -import java.io.File; -import java.io.FileReader; -import java.io.FileWriter; -import java.io.IOException; -import java.lang.reflect.ParameterizedType; -import java.lang.reflect.Type; -import java.util.Collection; -import java.util.Collections; -import java.util.EnumMap; -import java.util.HashMap; -import java.util.Locale; -import java.util.Map; -import java.util.Objects; -import java.util.TreeMap; -import java.util.jar.JarFile; - /** * Handles Blueprints * @since 1.5.0 @@ -367,37 +364,6 @@ public class BlueprintsManager { } - /** - * 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 void showPanel(CompositeCommand command, User user, String label) { - // Create the panel - PanelBuilder pb = new PanelBuilder().name(user.getTranslation("commands.island.create.pick")).user(user); - // Get the bundles - Collection bbs = getBlueprintBundles((@NonNull GameModeAddon) command.getAddon()).values(); - // 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)) { - // Skip bundles that the user has no permission for - continue; - } - PanelItem pi = new PanelItemBuilder().name(bb.getDisplayName()).description(bb.getDescription()) - .icon(bb.getIcon()).name(bb.getUniqueId()).clickHandler((panel, user1, clickType, slot1) -> { - user1.closeInventory(); - command.execute(user1, label, Collections.singletonList(bb.getUniqueId())); - return true; - }).build(); - pb.item(pi); - } - pb.build(); - } - /** * Checks if a player has permission to see or use this blueprint bundle. * @param addon - addon making the request diff --git a/src/main/java/world/bentobox/bentobox/panels/IslandCreationPanel.java b/src/main/java/world/bentobox/bentobox/panels/IslandCreationPanel.java index f557a97f2..1d31ed5b2 100644 --- a/src/main/java/world/bentobox/bentobox/panels/IslandCreationPanel.java +++ b/src/main/java/world/bentobox/bentobox/panels/IslandCreationPanel.java @@ -1,48 +1,55 @@ package world.bentobox.bentobox.panels; +import java.util.Collection; +import java.util.Collections; + import org.eclipse.jdt.annotation.NonNull; + import world.bentobox.bentobox.BentoBox; import world.bentobox.bentobox.api.addons.GameModeAddon; +import world.bentobox.bentobox.api.commands.CompositeCommand; 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; /** * Displays the available BlueprintBundles to pick up as the island. - * @author Poslovitch, tastybento + * @author tastybento * @since 1.5.0 */ public class IslandCreationPanel { - private static final String LOCALE_REF = "island-creation."; - private IslandCreationPanel() {} /** - * Shows the island creation panel for this Gamemode to this User. - * @param user the User to show the panel to. - * @param addon the addon to display the blueprint bundles from. + * 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 User user, @NonNull GameModeAddon addon) { + public static void openPanel(@NonNull CompositeCommand command, @NonNull User user, @NonNull String label) { BentoBox plugin = BentoBox.getInstance(); - PanelBuilder builder = new PanelBuilder() - .name(user.getTranslation(LOCALE_REF + "title")); - - plugin.getBlueprintsManager().getBlueprintBundles(addon).forEach((id, bundle) -> { - PanelItemBuilder itemBuilder = new PanelItemBuilder() - .icon(bundle.getIcon()) - .name(bundle.getDisplayName()) - .description(bundle.getDescription()) - .clickHandler((panel, user1, clickType, slot) -> { - user1.closeInventory(); - // TODO create the island; - return true; - }); - - builder.item(itemBuilder.build()); - }); - - builder.build().open(user); + // Create the panel + PanelBuilder pb = new PanelBuilder().name(user.getTranslation("commands.island.create.pick")).user(user); + // Get the bundles + Collection bbs = plugin.getBlueprintsManager().getBlueprintBundles((@NonNull GameModeAddon) command.getAddon()).values(); + // 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 + pb.item(new PanelItemBuilder().name(bb.getDisplayName()).description(bb.getDescription()) + .icon(bb.getIcon()).name(bb.getUniqueId()).clickHandler((panel, user1, clickType, slot1) -> { + user1.closeInventory(); + command.execute(user1, label, Collections.singletonList(bb.getUniqueId())); + return true; + }).build()); + } + } + pb.build(); } }