Shifted panel to IslandCreationPanel

This commit is contained in:
tastybento 2019-05-18 12:22:19 -07:00
parent 7c07982669
commit 7ea0edea91
5 changed files with 56 additions and 85 deletions

View File

@ -25,7 +25,7 @@ public class AdminBlueprintCommand extends ConfirmableCommand {
private static final Particle.DustOptions PARTICLE_DUST_OPTIONS = new Particle.DustOptions(Color.RED, 1.0F); private static final Particle.DustOptions PARTICLE_DUST_OPTIONS = new Particle.DustOptions(Color.RED, 1.0F);
public AdminBlueprintCommand(CompositeCommand parent) { public AdminBlueprintCommand(CompositeCommand parent) {
super(parent, "blueprint", "bp"); super(parent, "blueprint", "bp", "blu");
} }
@Override @Override

View File

@ -66,8 +66,7 @@ public class IslandCreateCommand extends CompositeCommand {
return makeIsland(user, name); return makeIsland(user, name);
} else { } else {
// Show panel // Show panel
getPlugin().getBlueprintsManager().showPanel(this, user, label); IslandCreationPanel.openPanel(this, user, label);
//IslandCreationPanel.openPanel(user, (GameModeAddon) getAddon());
return true; return true;
} }
} }

View File

@ -86,10 +86,9 @@ public class IslandResetCommand extends ConfirmableCommand {
} else { } else {
// Show panel after confirmation // Show panel after confirmation
if (getPlugin().getSettings().isResetConfirmation()) { if (getPlugin().getSettings().isResetConfirmation()) {
this.askConfirmation(user, () -> getPlugin().getBlueprintsManager().showPanel(this, user, label)); this.askConfirmation(user, () -> IslandCreationPanel.openPanel(this, user, label));
} else { } else {
getPlugin().getBlueprintsManager().showPanel(this, user, label); IslandCreationPanel.openPanel(this, user, label);
//IslandCreationPanel.openPanel(user, (GameModeAddon) getAddon());
} }
return true; return true;
} }

View File

@ -1,22 +1,35 @@
package world.bentobox.bentobox.managers; package world.bentobox.bentobox.managers;
import com.google.gson.Gson; import java.io.File;
import com.google.gson.GsonBuilder; import java.io.FileReader;
import com.google.gson.InstanceCreator; 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.ChatColor;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import org.eclipse.jdt.annotation.NonNull; import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable; 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.BentoBox;
import world.bentobox.bentobox.api.addons.Addon; import world.bentobox.bentobox.api.addons.Addon;
import world.bentobox.bentobox.api.addons.GameModeAddon; 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.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.api.user.User;
import world.bentobox.bentobox.blueprints.Blueprint; import world.bentobox.bentobox.blueprints.Blueprint;
import world.bentobox.bentobox.blueprints.BlueprintPaster; 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.schems.SchemToBlueprint;
import world.bentobox.bentobox.util.Util; 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 * Handles Blueprints
* @since 1.5.0 * @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<BlueprintBundle> 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. * Checks if a player has permission to see or use this blueprint bundle.
* @param addon - addon making the request * @param addon - addon making the request

View File

@ -1,48 +1,55 @@
package world.bentobox.bentobox.panels; package world.bentobox.bentobox.panels;
import java.util.Collection;
import java.util.Collections;
import org.eclipse.jdt.annotation.NonNull; import org.eclipse.jdt.annotation.NonNull;
import world.bentobox.bentobox.BentoBox; import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.api.addons.GameModeAddon; 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.PanelBuilder;
import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder; import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder;
import world.bentobox.bentobox.api.user.User; import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.blueprints.dataobjects.BlueprintBundle; import world.bentobox.bentobox.blueprints.dataobjects.BlueprintBundle;
import world.bentobox.bentobox.managers.BlueprintsManager;
/** /**
* Displays the available BlueprintBundles to pick up as the island. * Displays the available BlueprintBundles to pick up as the island.
* @author Poslovitch, tastybento * @author tastybento
* @since 1.5.0 * @since 1.5.0
*/ */
public class IslandCreationPanel { public class IslandCreationPanel {
private static final String LOCALE_REF = "island-creation.";
private IslandCreationPanel() {} private IslandCreationPanel() {}
/** /**
* Shows the island creation panel for this Gamemode to this User. * Shows a player a panel of selectable blueprint bundles. Checks user's permission
* @param user the User to show the panel to. * @param command - the command requesting the panel, e.g., create or reset
* @param addon the addon to display the blueprint bundles from. * @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(); BentoBox plugin = BentoBox.getInstance();
PanelBuilder builder = new PanelBuilder() // Create the panel
.name(user.getTranslation(LOCALE_REF + "title")); PanelBuilder pb = new PanelBuilder().name(user.getTranslation("commands.island.create.pick")).user(user);
// Get the bundles
plugin.getBlueprintsManager().getBlueprintBundles(addon).forEach((id, bundle) -> { Collection<BlueprintBundle> bbs = plugin.getBlueprintsManager().getBlueprintBundles((@NonNull GameModeAddon) command.getAddon()).values();
PanelItemBuilder itemBuilder = new PanelItemBuilder() // Loop through them and create items in the panel
.icon(bundle.getIcon()) for (BlueprintBundle bb : bbs) {
.name(bundle.getDisplayName()) String perm = command.getPermissionPrefix() + "island.create." + bb.getUniqueId();
.description(bundle.getDescription()) if (bb.getUniqueId().equals(BlueprintsManager.DEFAULT_BUNDLE_NAME)
.clickHandler((panel, user1, clickType, slot) -> { || !bb.isRequirePermission()
user1.closeInventory(); || user.hasPermission(perm)) {
// TODO create the island; // Add an item
return true; pb.item(new PanelItemBuilder().name(bb.getDisplayName()).description(bb.getDescription())
}); .icon(bb.getIcon()).name(bb.getUniqueId()).clickHandler((panel, user1, clickType, slot1) -> {
user1.closeInventory();
builder.item(itemBuilder.build()); command.execute(user1, label, Collections.singletonList(bb.getUniqueId()));
}); return true;
}).build());
builder.build().open(user); }
}
pb.build();
} }
} }