!Typing 'cancel' now works when editing crafting recipes

This commit is contained in:
Indyuce 2020-02-22 18:50:21 +01:00
parent 059a897595
commit 9a3a51d6f6
4 changed files with 34 additions and 30 deletions

View File

@ -11,24 +11,19 @@ import net.mmogroup.mmolib.MMOLib;
public class StatEdition implements Edition {
/* saves the data about the edited data so the plugin can edit the
/*
* saves the data about the edited data so the plugin can edit the
* corresponding stat. some stats have complex chat formats, so the object
* array allow to save more complex edition info
*/
private final EditionInventory inv;
private final ItemStat stat;
private final Object[] info;
private final boolean goBack;
public StatEdition(EditionInventory inv, ItemStat stat, Object... info) {
this(inv, true, stat, info);
}
public StatEdition(EditionInventory inv, boolean goBack, ItemStat stat, Object... info) {
this.inv = inv;
this.stat = stat;
this.info = info;
this.goBack = goBack;
}
public ItemStat getStat() {
@ -47,7 +42,8 @@ public class StatEdition implements Edition {
inv.getPlayer().sendMessage(MMOItems.plugin.getPrefix() + ChatColor.translateAlternateColorCodes('&', line));
inv.getPlayer().sendMessage(MMOItems.plugin.getPrefix() + "Type 'cancel' to abort editing.");
/* anvil text input feature. enables players to use an anvil to input
/*
* anvil text input feature. enables players to use an anvil to input
* text if they are having conflicts with their chat management plugins.
*/
if (MMOItems.plugin.getConfig().getBoolean("anvil-text-input") && MMOLib.plugin.getVersion().isBelowOrEqual(1, 13)) {
@ -55,7 +51,8 @@ public class StatEdition implements Edition {
return;
}
/* default chat edition feature
/*
* default chat edition feature
*/
new ChatEdition(inv, this);
MMOLib.plugin.getNMS().sendTitle(inv.getPlayer(), ChatColor.GOLD + "" + ChatColor.BOLD + "Item Edition", "See chat.", 10, 40, 10);
@ -66,6 +63,8 @@ public class StatEdition implements Edition {
return input.equals("cancel") || stat.whenInput((EditionInventory) inv, ((EditionInventory) inv).getItemType().getConfigFile(), input, info);
}
public boolean shouldGoBack()
{ return goBack; }
@Override
public boolean shouldGoBack() {
return true;
}
}

View File

@ -84,7 +84,7 @@ public class CraftingEdition extends EditionInventory {
if (event.getSlot() == 21 || event.getSlot() == 22)
new RecipeEdition(player, type, id, event.getSlot() == 22).open(getPreviousPage());
else
new StatEdition(this, false, ItemStat.CRAFTING, "item", getTypeFromSlot(event.getSlot()).name().toLowerCase()).enable("Write in the chat the item you want.", "Format: '[MATERIAL]' or '[MATERIAL]:[DURABILITY]' or '[TYPE].[ID]'");
new StatEdition(this, ItemStat.CRAFTING, "item", getTypeFromSlot(event.getSlot()).name().toLowerCase()).enable("Write in the chat the item you want.", "Format: '[MATERIAL]' or '[MATERIAL]:[DURABILITY]' or '[TYPE].[ID]'");
}
if (event.getAction() == InventoryAction.PICKUP_HALF) {

View File

@ -19,8 +19,8 @@ import net.Indyuce.mmoitems.gui.PluginInventory;
import net.mmogroup.mmolib.version.VersionMaterial;
public abstract class EditionInventory extends PluginInventory {
protected Type type;
protected String id;
protected final Type type;
protected final String id;
private int prevPage;
private ItemStack cached;
@ -48,19 +48,6 @@ public abstract class EditionInventory extends PluginInventory {
return cached != null;
}
public void flushItem() {
cached = null;
}
public void registerItemEdition(ConfigFile config, boolean uuid) {
flushItem();
getItemType().registerItemEdition(config, uuid ? id : null);
}
public void registerItemEdition(ConfigFile config) {
registerItemEdition(config, true);
}
/*
* the item is cached in the inventory class to allow GUIs not to generate
* the item each time the user goes to another GUI or page
@ -69,6 +56,24 @@ public abstract class EditionInventory extends PluginInventory {
return cached != null ? cached : (cached = MMOItems.plugin.getItems().getItem(type, id));
}
public void flushItem() {
cached = null;
}
public void registerItemEdition(ConfigFile config, boolean uuid) {
/*
* cached item needs to be flushed otherwise modifications applied
* cannot display on the edition GUI
*/
flushItem();
getItemType().registerItemEdition(config, uuid ? id : null);
}
public void registerItemEdition(ConfigFile config) {
registerItemEdition(config, true);
}
public void addEditionInventoryItems(Inventory inv, boolean backBool) {
ItemStack get = new ItemStack(VersionMaterial.GUNPOWDER.toMaterial());
ItemMeta getMeta = get.getItemMeta();

View File

@ -69,7 +69,7 @@ public class Crafting extends ItemStat {
Bukkit.getScheduler().runTask(MMOItems.plugin, new Runnable() {
@Override
public void run() {
new StatEdition(inv, false, ItemStat.CRAFTING, "time", info[1], message).enable("Write in the chat the cooktime (in ticks) for your recipe.", "Format: '[INTEGER]'");
new StatEdition(inv, ItemStat.CRAFTING, "time", info[1], message).enable("Write in the chat the cooktime (in ticks) for your recipe.", "Format: '[INTEGER]'");
}
});
}