Allow default blueprint bundle to have a friendly name change in the GUI

https://github.com/BentoBoxWorld/BentoBox/issues/1543
This commit is contained in:
tastybento 2020-10-09 14:51:21 -07:00
parent 6b852e0368
commit a07676ac05
4 changed files with 63 additions and 28 deletions

View File

@ -88,26 +88,26 @@ public class AdminBlueprintCommand extends ConfirmableCommand {
// Drawing x-axes
for (int x = minX; x <= maxX; x++) {
user.spawnParticle(PARTICLE, PARTICLE_DUST_OPTIONS, x, minY, minZ);
user.spawnParticle(PARTICLE, PARTICLE_DUST_OPTIONS, x, maxY, minZ);
user.spawnParticle(PARTICLE, PARTICLE_DUST_OPTIONS, x, minY, maxZ);
user.spawnParticle(PARTICLE, PARTICLE_DUST_OPTIONS, x, maxY, maxZ);
user.spawnParticle(PARTICLE, PARTICLE_DUST_OPTIONS, x + 0.5, minY + 0.5, minZ + 0.5);
user.spawnParticle(PARTICLE, PARTICLE_DUST_OPTIONS, x + 0.5, maxY + 0.5, minZ + 0.5);
user.spawnParticle(PARTICLE, PARTICLE_DUST_OPTIONS, x + 0.5, minY + 0.5, maxZ + 0.5);
user.spawnParticle(PARTICLE, PARTICLE_DUST_OPTIONS, x + 0.5, maxY + 0.5, maxZ + 0.5);
}
// Drawing y-axes
for (int y = minY; y <= maxY; y++) {
user.spawnParticle(PARTICLE, PARTICLE_DUST_OPTIONS, minX, y, minZ);
user.spawnParticle(PARTICLE, PARTICLE_DUST_OPTIONS, maxX, y, minZ);
user.spawnParticle(PARTICLE, PARTICLE_DUST_OPTIONS, minX, y, maxZ);
user.spawnParticle(PARTICLE, PARTICLE_DUST_OPTIONS, maxX, y, maxZ);
user.spawnParticle(PARTICLE, PARTICLE_DUST_OPTIONS, minX + 0.5, y + 0.5, minZ + 0.5);
user.spawnParticle(PARTICLE, PARTICLE_DUST_OPTIONS, maxX + 0.5, y + 0.5, minZ + 0.5);
user.spawnParticle(PARTICLE, PARTICLE_DUST_OPTIONS, minX + 0.5, y + 0.5, maxZ + 0.5);
user.spawnParticle(PARTICLE, PARTICLE_DUST_OPTIONS, maxX + 0.5, y + 0.5, maxZ + 0.5);
}
// Drawing z-axes
for (int z = minZ; z <= maxZ; z++) {
user.spawnParticle(PARTICLE, PARTICLE_DUST_OPTIONS, minX, minY, z);
user.spawnParticle(PARTICLE, PARTICLE_DUST_OPTIONS, maxX, minY, z);
user.spawnParticle(PARTICLE, PARTICLE_DUST_OPTIONS, minX, maxY, z);
user.spawnParticle(PARTICLE, PARTICLE_DUST_OPTIONS, maxX, maxY, z);
user.spawnParticle(PARTICLE, PARTICLE_DUST_OPTIONS, minX + 0.5, minY + 0.5, z + 0.5);
user.spawnParticle(PARTICLE, PARTICLE_DUST_OPTIONS, maxX + 0.5, minY + 0.5, z + 0.5);
user.spawnParticle(PARTICLE, PARTICLE_DUST_OPTIONS, minX + 0.5, maxY + 0.5, z + 0.5);
user.spawnParticle(PARTICLE, PARTICLE_DUST_OPTIONS, maxX + 0.5, maxY + 0.5, z + 0.5);
}
// Drawing origin

View File

@ -12,6 +12,7 @@ import world.bentobox.bentobox.api.addons.GameModeAddon;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.blueprints.Blueprint;
import world.bentobox.bentobox.blueprints.dataobjects.BlueprintBundle;
import world.bentobox.bentobox.managers.BlueprintsManager;
public class NamePrompt extends StringPrompt {
@ -45,18 +46,23 @@ public class NamePrompt extends StringPrompt {
context.getForWhom().sendRawMessage("Too long");
return this;
}
// Make a uniqueid
StringBuilder uniqueId = new StringBuilder(ChatColor.stripColor(input).toLowerCase(Locale.ENGLISH).replace(" ", "_"));
// Check if this name is unique
int max = 0;
while (max++ < 32 && addon.getPlugin().getBlueprintsManager().getBlueprintBundles(addon).containsKey(uniqueId.toString())) {
uniqueId.append("x");
if (!bb.getUniqueId().equals(BlueprintsManager.DEFAULT_BUNDLE_NAME)) {
// Make a uniqueid
StringBuilder uniqueId = new StringBuilder(ChatColor.stripColor(input).toLowerCase(Locale.ENGLISH).replace(" ", "_"));
// Check if this name is unique
int max = 0;
while (max++ < 32 && addon.getPlugin().getBlueprintsManager().getBlueprintBundles(addon).containsKey(uniqueId.toString())) {
uniqueId.append("x");
}
if (max == 32) {
context.getForWhom().sendRawMessage(user.getTranslation("commands.admin.blueprint.management.name.pick-a-unique-name"));
return this;
}
context.setSessionData("uniqueId", uniqueId.toString());
} else {
// Default stays as default
context.setSessionData("uniqueId", bb.getUniqueId());
}
if (max == 32) {
context.getForWhom().sendRawMessage(user.getTranslation("commands.admin.blueprint.management.name.pick-a-unique-name"));
return this;
}
context.setSessionData("uniqueId", uniqueId.toString());
context.setSessionData("name", input);
return new NameSuccessPrompt(addon, bb, bp);
}

View File

@ -57,6 +57,12 @@ public class BlueprintManagementPanel {
private final User user;
private final GameModeAddon addon;
/**
* Class to display the Blueprint Management Panel
* @param plugin - BentoBox
* @param user - user to see the panel
* @param addon - game mode addon requesting the panel
*/
public BlueprintManagementPanel(@NonNull BentoBox plugin, @NonNull User user, @NonNull GameModeAddon addon) {
this.plugin = plugin;
this.user = user;
@ -100,13 +106,12 @@ public class BlueprintManagementPanel {
// Make item
PanelItem item = new PanelItemBuilder()
.name(bb.getDisplayName())
.description(t("edit"),
!bb.getUniqueId().equals(BlueprintsManager.DEFAULT_BUNDLE_NAME) ? t("rename") : "")
.description(t("edit"), t("rename"))
.icon(bb.getIcon())
.clickHandler((panel, u, clickType, slot) -> {
u.closeInventory();
if (clickType.equals(ClickType.RIGHT) && !bb.getUniqueId().equals(BlueprintsManager.DEFAULT_BUNDLE_NAME)) {
if (clickType.equals(ClickType.RIGHT)) {
// Rename
askForName(u.getPlayer(), addon, bb);
} else {
@ -173,8 +178,13 @@ public class BlueprintManagementPanel {
}
blueprints.entrySet().stream().limit(18).forEach(b -> pb.item(getBlueprintItem(addon, b.getKey(), bb, b.getValue())));
// Buttons for non-default bundle
if (!bb.getUniqueId().equals(BlueprintsManager.DEFAULT_BUNDLE_NAME)) {
// Panel has a Trash icon. If right clicked it is discarded
if (bb.getUniqueId().equals(BlueprintsManager.DEFAULT_BUNDLE_NAME)) {
// Panel has a No Trash icon. If right clicked it is discarded
pb.item(36, getNoTrashIcon(addon, bb));
// Toggle permission - default is always allowed
pb.item(39, getNoPermissionIcon(addon, bb));
} else {
// Panel has a Trash icon. If right clicked it is discarded
pb.item(36, getTrashIcon(addon, bb));
// Toggle permission - default is always allowed
pb.item(39, getPermissionIcon(addon, bb));
@ -272,6 +282,15 @@ public class BlueprintManagementPanel {
})
.build();
}
private PanelItem getNoTrashIcon(@NonNull GameModeAddon addon, BlueprintBundle bb) {
return new PanelItemBuilder()
.name(t("no-trash"))
.description(t("no-trash-instructions"))
.icon(Material.TNT)
.build();
}
private PanelItem getPermissionIcon(@NonNull GameModeAddon addon, BlueprintBundle bb) {
return new PanelItemBuilder().icon(Material.PAINTING).name(t("permission"))
@ -287,6 +306,12 @@ public class BlueprintManagementPanel {
return true;
}).build();
}
private PanelItem getNoPermissionIcon(@NonNull GameModeAddon addon, BlueprintBundle bb) {
return new PanelItemBuilder().icon(Material.PAINTING).name(t("no-permission"))
.description(t("no-perm-required"))
.build();
}
/**
* Gets a panel item that fully represents a blueprint in a bundle for an addon

View File

@ -321,9 +321,13 @@ commands:
Place blueprint
to right to set
trash: "Trash"
no-trash: "Cannot Trash"
trash-instructions: "Right click here to delete"
no-trash-instructions: "Cannot trash default bundle"
permission: "Permission"
no-permission: "No Permission"
perm-required: "Required"
no-perm-required: "Cannot set perm for default bundle"
perm-not-required: "Not Required"
perm-format: "&e "
remove: "Right click to remove"