Skip to content

Commit

Permalink
Update to v1.6.0 version.
Browse files Browse the repository at this point in the history
Remove AnvilGUI, as it is broken. Replaced with Spigot Conversation API.
Remove lore-config from GUI (broken).
Remove RIGHT_CLICK to complete multiple times (broken).
  • Loading branch information
BuildTools committed Aug 25, 2019
1 parent b6e2133 commit c516d53
Show file tree
Hide file tree
Showing 16 changed files with 531 additions and 302 deletions.
12 changes: 1 addition & 11 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,9 @@
<powermock.version>1.7.4</powermock.version>
<!-- More visible way how to change dependency versions -->
<spigot.version>1.13.2-R0.1-SNAPSHOT</spigot.version>
<bentobox.version>1.6.0-SNAPSHOT</bentobox.version>
<bentobox.version>1.6.0</bentobox.version>
<level.version>1.5.0</level.version>
<vault.version>1.7</vault.version>
<anvilgui.version>1.2.2-SNAPSHOT</anvilgui.version>
<!-- Revision variable removes warning about dynamic version -->
<revision>${build.version}-SNAPSHOT</revision>
<!-- This allows to change between versions and snapshots. -->
Expand Down Expand Up @@ -115,10 +114,6 @@
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
<repository>
<id>wesjd-repo</id>
<url>https://nexus.wesjd.net/repository/thirdparty/</url>
</repository>
</repositories>

<dependencies>
Expand Down Expand Up @@ -170,11 +165,6 @@
<version>${vault.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>net.wesjd</groupId>
<artifactId>anvilgui</artifactId>
<version>${anvilgui.version}</version>
</dependency>
</dependencies>

<build>
Expand Down
70 changes: 70 additions & 0 deletions src/main/java/world/bentobox/challenges/panel/CommonGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;

import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.conversations.*;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
Expand All @@ -21,7 +23,12 @@
import org.bukkit.inventory.meta.SpawnEggMeta;
import org.bukkit.inventory.meta.TropicalFishBucketMeta;
import org.bukkit.potion.PotionData;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;

import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.TextComponent;
import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.api.panels.PanelItem;
import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder;
import world.bentobox.bentobox.api.user.User;
Expand Down Expand Up @@ -917,5 +924,68 @@ else if (meta instanceof TropicalFishBucketMeta)

return result;
}


// ---------------------------------------------------------------------
// Section: Chat Input Methods
// ---------------------------------------------------------------------


/**
* 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.
* @param message Message that will be set in player text field when clicked on question.
*/
protected void getFriendlyName(Consumer<String> consumer, @NonNull String question, @Nullable String message)
{
final User user = this.user;

Conversation conversation =
new ConversationFactory(BentoBox.getInstance()).withFirstPrompt(
new StringPrompt()
{
/**
* @see Prompt#getPromptText(ConversationContext)
*/
@Override
public String getPromptText(ConversationContext conversationContext)
{
// Close input GUI.
user.closeInventory();

if (message != null)
{
// Create Edit Text message.
TextComponent component = new TextComponent(user.getTranslation("challenges.gui.descriptions.admin.click-to-edit"));
component.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, message));
// Send question and message to player.
user.getPlayer().spigot().sendMessage(component);
}

// There are no editable message. Just return question.
return question;
}


/**
* @see Prompt#acceptInput(ConversationContext, String)
*/
@Override
public Prompt acceptInput(ConversationContext conversationContext, String answer)
{
// Add answer to consumer.
consumer.accept(answer);
// End conversation
return Prompt.END_OF_CONVERSATION;
}
}).
withLocalEcho(false).
withPrefix(context -> user.getTranslation("challenges.gui.questions.prefix")).
buildConversation(user.getPlayer());

conversation.begin();
}
}

197 changes: 150 additions & 47 deletions src/main/java/world/bentobox/challenges/panel/admin/AdminGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,19 @@

import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.conversations.*;
import org.bukkit.inventory.ItemStack;
import org.eclipse.jdt.annotation.NonNull;

import net.wesjd.anvilgui.AnvilGUI;
import java.util.function.Consumer;
import java.util.function.Function;

import world.bentobox.bentobox.BentoBox;
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.util.Util;
import world.bentobox.challenges.ChallengesAddon;
import world.bentobox.challenges.panel.CommonGUI;
import world.bentobox.challenges.panel.util.ConfirmationGUI;
Expand Down Expand Up @@ -208,29 +214,24 @@ private PanelItem createButton(Button button)
description = this.user.getTranslation("challenges.gui.descriptions.admin.create-challenge");
icon = new ItemStack(Material.BOOK);
clickHandler = (panel, user, clickType, slot) -> {
new AnvilGUI(this.addon.getPlugin(),
this.user.getPlayer(),
"unique_id",
(player, reply) -> {
String newName = Utils.getGameMode(this.world) + "_" + reply;

if (!this.addon.getChallengesManager().containsChallenge(newName))
{
new EditChallengeGUI(this.addon,
this.world,
this.user,
this.addon.getChallengesManager().createChallenge(newName),
this.topLabel,
this.permissionPrefix,
this).build();
}
else
{
this.user.sendMessage("challenges.errors.unique-id", "[id]", reply);
}

return reply;
});

this.getNewUniqueID(challenge -> {
String newName = Utils.getGameMode(this.world) + "_" + challenge;

new EditChallengeGUI(this.addon,
this.world,
this.user,
this.addon.getChallengesManager().createChallenge(newName),
this.topLabel,
this.permissionPrefix,
this).build();
},
input -> {
String newName = Utils.getGameMode(this.world) + "_" + input;
return !this.addon.getChallengesManager().containsChallenge(newName);
},
this.user.getTranslation("challenges.question.admin.unique-id")
);

return true;
};
Expand All @@ -244,29 +245,24 @@ private PanelItem createButton(Button button)
description = this.user.getTranslation("challenges.gui.descriptions.admin.create-level");
icon = new ItemStack(Material.BOOK);
clickHandler = (panel, user, clickType, slot) -> {
new AnvilGUI(this.addon.getPlugin(),
this.user.getPlayer(),
"unique_id",
(player, reply) -> {
String newName = Utils.getGameMode(this.world) + "_" + reply;

if (!this.addon.getChallengesManager().containsLevel(newName))
{
new EditLevelGUI(this.addon,
this.world,
this.user,
this.addon.getChallengesManager().createLevel(newName, this.world),
this.topLabel,
this.permissionPrefix,
this).build();
}
else
{
this.user.sendMessage("challenges.errors.unique-id", "[id]", reply);
}

return reply;
});

this.getNewUniqueID(level -> {
String newName = Utils.getGameMode(this.world) + "_" + level;

new EditLevelGUI(this.addon,
this.world,
this.user,
this.addon.getChallengesManager().createLevel(newName, this.world),
this.topLabel,
this.permissionPrefix,
this).build();
},
input -> {
String newName = Utils.getGameMode(this.world) + "_" + input;
return !this.addon.getChallengesManager().containsLevel(newName);
},
this.user.getTranslation("challenges.question.admin.unique-id")
);

return true;
};
Expand Down Expand Up @@ -496,4 +492,111 @@ private PanelItem createButton(Button button)
clickHandler(clickHandler).
build();
}


// ---------------------------------------------------------------------
// 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,
Function<String, Boolean> stringValidation,
@NonNull String question)
{
final User user = this.user;

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)
{
// Close input GUI.
user.closeInventory();

// 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)
{
return stringValidation.apply(input);
}


/**
* Optionally override this method to
* display an additional message if the
* user enters an invalid input.
*
* @param context Context information
* about the conversation.
* @param invalidInput The invalid input
* provided by the user.
* @return A message explaining how to
* correct the input.
*/
@Override
protected String getFailedValidationText(ConversationContext context,
String invalidInput)
{
return user.getTranslation("challenges.errors.unique-id", "[id]", invalidInput);
}


/**
* 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("challenges.gui.questions.prefix")).
buildConversation(user.getPlayer());

conversation.begin();
}
}

0 comments on commit c516d53

Please sign in to comment.