Skip to content

Commit

Permalink
Version up to 1.6.0.2
Browse files Browse the repository at this point in the history
Remove AnvilGUI. Replace with Spigot Conversation API.
Add SelectBlocksGUI that allows to choose icon for BiomeObject
  • Loading branch information
BuildTools committed Aug 25, 2019
1 parent 4847e3b commit 007d5ea
Show file tree
Hide file tree
Showing 13 changed files with 929 additions and 228 deletions.
20 changes: 5 additions & 15 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,14 @@
<java.version>1.8</java.version>
<powermock.version>1.7.4</powermock.version>
<!-- More visible way how to change dependency versions -->
<spigot.version>1.14.3-R0.1-SNAPSHOT</spigot.version>
<bentobox.version>1.5.3</bentobox.version>
<level.version>1.5.0</level.version>
<spigot.version>1.13.2-R0.1-SNAPSHOT</spigot.version>
<bentobox.version>1.6.0</bentobox.version>
<level.version>1.6.0</level.version>
<vault.version>1.7</vault.version>
<anvilgui.version>a07c9b64f7</anvilgui.version>
<!-- Revision variable removes warning about dynamic version -->
<revision>${build.version}-SNAPSHOT</revision>
<!-- This allows to change between versions and snapshots. -->
<build.version>1.5.2.1</build.version>
<build.version>1.6.0.2</build.version>
<build.number>-LOCAL</build.number>
</properties>

Expand Down Expand Up @@ -107,10 +106,6 @@
<id>vault-repo</id>
<url>http://nexus.hc.to/content/repositories/pub_releases</url>
</repository>
<repository>
<id>wesjd-repo</id>
<url>https://nexus.wesjd.net/repository/thirdparty/</url>
</repository>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
Expand All @@ -135,19 +130,14 @@
<artifactId>level</artifactId>
<version>${level.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.github.BONNe</groupId>
<artifactId>AnvilGUI</artifactId>
<version>${anvilgui.version}</version>
</dependency>
<dependency>
<groupId>net.milkbowl.vault</groupId>
<artifactId>VaultAPI</artifactId>
<version>${vault.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
</dependencies>

<build>
<!-- By default ${revision} is ${build.version}-SNAPSHOT -->
Expand Down
128 changes: 105 additions & 23 deletions src/main/java/world/bentobox/biomes/commands/admin/AddBiomeCommand.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package world.bentobox.biomes.commands.admin;


import org.bukkit.World;
import org.bukkit.conversations.*;
import org.eclipse.jdt.annotation.NonNull;
import java.util.List;
import java.util.function.Consumer;

import net.wesjd.anvilgui.AnvilGUI;
import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.api.addons.Addon;
import world.bentobox.bentobox.api.commands.CompositeCommand;
import world.bentobox.bentobox.api.user.User;
Expand Down Expand Up @@ -84,29 +88,22 @@ public boolean execute(User user, String label, List<String> args)
if (user.isPlayer() && args.isEmpty())
{
// Shows BiomesPanel in Edit mode.
new AnvilGUI(this.addon.getPlugin(),
user.getPlayer(),
"unique_id",
(player, reply) -> {
String worldName = Util.getWorld(this.getWorld()).getName();
String newName = worldName + "-" + reply;

if (!this.addon.getAddonManager().containsBiome(newName))
{
new EditBiomeGUI(this.addon,
this.getWorld(),
user,
this.getTopLabel(),
this.getPermissionPrefix(),
this.addon.getAddonManager().createBiome(newName, worldName)).build();
}
else
{
user.sendMessage("biomes.errors.unique-id", "[id]", reply);
}

return reply;
});
this.getNewUniqueID(uniqueID ->
{
String worldName = Util.getWorld(this.getWorld()).getName();
String newName = worldName + "-" + uniqueID.toLowerCase();

new EditBiomeGUI(this.addon,
this.getWorld(),
user,
this.getTopLabel(),
this.getPermissionPrefix(),
this.addon.getAddonManager().createBiome(newName, worldName)).build();
},
user.getTranslation("biomes.gui.questions.admin.uniqueID"),
user,
this.getWorld());

return true;
}
Expand Down Expand Up @@ -136,4 +133,89 @@ public boolean execute(User user, String label, List<String> args)
return true;
}
}


// ---------------------------------------------------------------------
// Section: Conversation
// ---------------------------------------------------------------------

/**
* This method will close opened gui and writes inputText in chat. After players answers on inputText in
* chat, message will trigger consumer and gui will reopen.
* @param consumer Consumer that accepts player output text.
* @param question Message that will be displayed in chat when player triggers conversion.
*/
private void getNewUniqueID(Consumer<String> consumer,
@NonNull String question,
@NonNull User user,
@NonNull World world)
{
Conversation conversation =
new ConversationFactory(BentoBox.getInstance()).withFirstPrompt(
new ValidatingPrompt()
{

/**
* Gets the text to display to the user when
* this prompt is first presented.
*
* @param context Context information about the
* conversation.
* @return The text to display.
*/
@Override
public String getPromptText(ConversationContext context)
{
// There are no editable message. Just return question.
return question;
}


/**
* Override this method to check the validity of
* the player's input.
*
* @param context Context information about the
* conversation.
* @param input The player's raw console input.
* @return True or false depending on the
* validity of the input.
*/
@Override
protected boolean isInputValid(ConversationContext context, String input)
{
String worldName = Util.getWorld(world).getName();
String newName = worldName + "-" + input.toLowerCase();

return !AddBiomeCommand.this.addon.getAddonManager().containsBiome(newName);
}


/**
* Override this method to accept and processes
* the validated input from the user. Using the
* input, the next Prompt in the prompt graph
* should be returned.
*
* @param context Context information about the
* conversation.
* @param input The validated input text from
* the user.
* @return The next Prompt in the prompt graph.
*/
@Override
protected Prompt acceptValidatedInput(ConversationContext context, String input)
{
// Add answer to consumer.
consumer.accept(input);
// End conversation
return Prompt.END_OF_CONVERSATION;
}
}).
withLocalEcho(false).
withPrefix(context -> user.getTranslation("biomes.gui.questions.prefix")).
buildConversation(user.getPlayer());

conversation.begin();
}
}
118 changes: 118 additions & 0 deletions src/main/java/world/bentobox/biomes/panels/GuiUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -171,4 +171,122 @@ public static List<String> stringSplit(List<String> stringList, int warpLength)
stringList.stream().map(string -> GuiUtils.stringSplit(string, warpLength)).forEach(newList::addAll);
return newList;
}


// ---------------------------------------------------------------------
// Section: Materials
// ---------------------------------------------------------------------


/**
* This method transforms material into item stack that can be displayed in users
* inventory.
* @param material Material which item stack must be returned.
* @return ItemStack that represents given material.
*/
public static ItemStack getMaterialItem(Material material)
{
return GuiUtils.getMaterialItem(material, 1);
}


/**
* This method transforms material into item stack that can be displayed in users
* inventory.
* @param material Material which item stack must be returned.
* @param amount Amount of ItemStack elements.
* @return ItemStack that represents given material.
*/
public static ItemStack getMaterialItem(Material material, int amount)
{
ItemStack itemStack;

// Process items that cannot be item-stacks.
if (material.name().contains("WALL_"))
{
// Materials that is attached to wall cannot be showed in GUI. But they should be in list.
itemStack = new ItemStack(Material.getMaterial(material.name().replace("WALL_", "")));
}
else if (material.name().startsWith("POTTED_"))
{
// Materials Potted elements cannot be in inventory.
itemStack = new ItemStack(Material.getMaterial(material.name().replace("POTTED_", "")));
}
else if (material.equals(Material.MELON_STEM) || material.equals(Material.ATTACHED_MELON_STEM))
{
itemStack = new ItemStack(Material.MELON_SEEDS);
}
else if (material.equals(Material.PUMPKIN_STEM) || material.equals(Material.ATTACHED_PUMPKIN_STEM))
{
itemStack = new ItemStack(Material.PUMPKIN_SEEDS);
}
else if (material.equals(Material.TALL_SEAGRASS))
{
itemStack = new ItemStack(Material.SEAGRASS);
}
else if (material.equals(Material.CARROTS))
{
itemStack = new ItemStack(Material.CARROT);
}
else if (material.equals(Material.BEETROOTS))
{
itemStack = new ItemStack(Material.BEETROOT);
}
else if (material.equals(Material.POTATOES))
{
itemStack = new ItemStack(Material.POTATO);
}
else if (material.equals(Material.COCOA))
{
itemStack = new ItemStack(Material.COCOA_BEANS);
}
else if (material.equals(Material.KELP_PLANT))
{
itemStack = new ItemStack(Material.KELP);
}
else if (material.equals(Material.REDSTONE_WIRE))
{
itemStack = new ItemStack(Material.REDSTONE);
}
else if (material.equals(Material.TRIPWIRE))
{
itemStack = new ItemStack(Material.STRING);
}
else if (material.equals(Material.FROSTED_ICE))
{
itemStack = new ItemStack(Material.ICE);
}
else if (material.equals(Material.END_PORTAL) || material.equals(Material.END_GATEWAY) || material.equals(Material.NETHER_PORTAL))
{
itemStack = new ItemStack(Material.PAPER);
}
else if (material.equals(Material.BUBBLE_COLUMN) || material.equals(Material.WATER))
{
itemStack = new ItemStack(Material.WATER_BUCKET);
}
else if (material.equals(Material.LAVA))
{
itemStack = new ItemStack(Material.LAVA_BUCKET);
}
else if (material.equals(Material.FIRE))
{
itemStack = new ItemStack(Material.FIRE_CHARGE);
}
else if (material.equals(Material.AIR) || material.equals(Material.CAVE_AIR) || material.equals(Material.VOID_AIR))
{
itemStack = new ItemStack(Material.GLASS_BOTTLE);
}
else if (material.equals(Material.PISTON_HEAD) || material.equals(Material.MOVING_PISTON))
{
itemStack = new ItemStack(Material.PISTON);
}
else
{
itemStack = new ItemStack(material);
}

itemStack.setAmount(amount);

return itemStack;
}
}

0 comments on commit 007d5ea

Please sign in to comment.