mirror of
https://gitlab.com/phoenix-dvpmt/mmoitems.git
synced 2025-01-06 07:07:35 +01:00
Now opens again the item browser when canceling item creation
This commit is contained in:
parent
e39f73e5ce
commit
e045a6a2ab
MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/edition
@ -9,6 +9,7 @@ import org.bukkit.ChatColor;
|
||||
|
||||
public class NewItemEdition implements Edition {
|
||||
private final ItemBrowser inv;
|
||||
private boolean successful;
|
||||
|
||||
public NewItemEdition(ItemBrowser inv) {
|
||||
this.inv = inv;
|
||||
@ -24,8 +25,8 @@ public class NewItemEdition implements Edition {
|
||||
inv.getPlayer().closeInventory();
|
||||
|
||||
inv.getPlayer().sendMessage(ChatColor.YELLOW + "" + ChatColor.STRIKETHROUGH + "-----------------------------------------------------");
|
||||
inv.getPlayer().sendMessage(MMOItems.plugin.getPrefix() + "Write in the chat, the id of the new item.");
|
||||
inv.getPlayer().sendMessage(MMOItems.plugin.getPrefix() + "Type 'cancel' to abort editing.");
|
||||
inv.getPlayer().sendMessage(MMOItems.plugin.getPrefix() + "Write in the chat the ID of the new item.");
|
||||
inv.getPlayer().sendMessage(MMOItems.plugin.getPrefix() + "Type 'cancel' to abort.");
|
||||
|
||||
// Default chat edition feature
|
||||
new ChatEdition(this);
|
||||
@ -34,16 +35,12 @@ public class NewItemEdition implements Edition {
|
||||
|
||||
@Override
|
||||
public boolean processInput(String input) {
|
||||
if (input.equals("cancel"))
|
||||
return true;
|
||||
|
||||
Bukkit.dispatchCommand(inv.getPlayer(),
|
||||
return successful = Bukkit.dispatchCommand(inv.getPlayer(),
|
||||
"mmoitems create " + inv.getType().getId() + " " + input.toUpperCase().replace(" ", "_").replace("-", "_"));
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldGoBack() {
|
||||
return false;
|
||||
return !successful;
|
||||
}
|
||||
}
|
||||
|
@ -54,13 +54,6 @@ public class StatEdition implements Edition {
|
||||
|
||||
@Override
|
||||
public boolean processInput(String input) {
|
||||
|
||||
// If cancel, open back inventory
|
||||
if (input.equals("cancel")) {
|
||||
inv.open();
|
||||
return true;
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
// Perform WhenInput Operation
|
||||
|
@ -1,10 +1,9 @@
|
||||
package net.Indyuce.mmoitems.api.edition.input;
|
||||
|
||||
import net.Indyuce.mmoitems.api.edition.Edition;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import net.Indyuce.mmoitems.api.edition.Edition;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public abstract class PlayerInputHandler {
|
||||
@ -31,7 +30,7 @@ public abstract class PlayerInputHandler {
|
||||
/**
|
||||
* Processes the player input, closes the edition process if needed and
|
||||
* opens the previously opened GUI if needed. This method is protected
|
||||
* because it should only be ran by edition process classes.
|
||||
* because it should only be run by edition process classes.
|
||||
* For security this method should be called on the main server thread.
|
||||
*
|
||||
* @param input Player input
|
||||
@ -39,12 +38,11 @@ public abstract class PlayerInputHandler {
|
||||
protected void registerInput(@NotNull String input) {
|
||||
Validate.isTrue(Bukkit.isPrimaryThread(), "Input must be registered on primary thread");
|
||||
|
||||
if (!edition.processInput(input))
|
||||
return;
|
||||
|
||||
if (edition.shouldGoBack())
|
||||
edition.getInventory().open();
|
||||
close();
|
||||
// If input is 'cancel' just cancel
|
||||
if (input.equalsIgnoreCase("cancel") || edition.processInput(input)) {
|
||||
if (edition.shouldGoBack()) edition.getInventory().open();
|
||||
close();
|
||||
}
|
||||
}
|
||||
|
||||
public abstract void close();
|
||||
|
Loading…
Reference in New Issue
Block a user