mirror of
https://gitlab.com/phoenix-dvpmt/mmoitems.git
synced 2025-01-10 07:47:35 +01:00
!Typing 'cancel' now works when editing crafting recipes
This commit is contained in:
parent
059a897595
commit
9a3a51d6f6
@ -11,24 +11,19 @@ import net.mmogroup.mmolib.MMOLib;
|
|||||||
|
|
||||||
public class StatEdition implements Edition {
|
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
|
* corresponding stat. some stats have complex chat formats, so the object
|
||||||
* array allow to save more complex edition info
|
* array allow to save more complex edition info
|
||||||
*/
|
*/
|
||||||
private final EditionInventory inv;
|
private final EditionInventory inv;
|
||||||
private final ItemStat stat;
|
private final ItemStat stat;
|
||||||
private final Object[] info;
|
private final Object[] info;
|
||||||
private final boolean goBack;
|
|
||||||
|
|
||||||
public StatEdition(EditionInventory inv, ItemStat stat, Object... info) {
|
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.inv = inv;
|
||||||
this.stat = stat;
|
this.stat = stat;
|
||||||
this.info = info;
|
this.info = info;
|
||||||
this.goBack = goBack;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ItemStat getStat() {
|
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() + ChatColor.translateAlternateColorCodes('&', line));
|
||||||
inv.getPlayer().sendMessage(MMOItems.plugin.getPrefix() + "Type 'cancel' to abort editing.");
|
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.
|
* 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)) {
|
if (MMOItems.plugin.getConfig().getBoolean("anvil-text-input") && MMOLib.plugin.getVersion().isBelowOrEqual(1, 13)) {
|
||||||
@ -55,7 +51,8 @@ public class StatEdition implements Edition {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* default chat edition feature
|
/*
|
||||||
|
* default chat edition feature
|
||||||
*/
|
*/
|
||||||
new ChatEdition(inv, this);
|
new ChatEdition(inv, this);
|
||||||
MMOLib.plugin.getNMS().sendTitle(inv.getPlayer(), ChatColor.GOLD + "" + ChatColor.BOLD + "Item Edition", "See chat.", 10, 40, 10);
|
MMOLib.plugin.getNMS().sendTitle(inv.getPlayer(), ChatColor.GOLD + "" + ChatColor.BOLD + "Item Edition", "See chat.", 10, 40, 10);
|
||||||
@ -65,7 +62,9 @@ public class StatEdition implements Edition {
|
|||||||
public boolean output(String input) {
|
public boolean output(String input) {
|
||||||
return input.equals("cancel") || stat.whenInput((EditionInventory) inv, ((EditionInventory) inv).getItemType().getConfigFile(), input, info);
|
return input.equals("cancel") || stat.whenInput((EditionInventory) inv, ((EditionInventory) inv).getItemType().getConfigFile(), input, info);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean shouldGoBack()
|
@Override
|
||||||
{ return goBack; }
|
public boolean shouldGoBack() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -84,7 +84,7 @@ public class CraftingEdition extends EditionInventory {
|
|||||||
if (event.getSlot() == 21 || event.getSlot() == 22)
|
if (event.getSlot() == 21 || event.getSlot() == 22)
|
||||||
new RecipeEdition(player, type, id, event.getSlot() == 22).open(getPreviousPage());
|
new RecipeEdition(player, type, id, event.getSlot() == 22).open(getPreviousPage());
|
||||||
else
|
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) {
|
if (event.getAction() == InventoryAction.PICKUP_HALF) {
|
||||||
|
@ -19,8 +19,8 @@ import net.Indyuce.mmoitems.gui.PluginInventory;
|
|||||||
import net.mmogroup.mmolib.version.VersionMaterial;
|
import net.mmogroup.mmolib.version.VersionMaterial;
|
||||||
|
|
||||||
public abstract class EditionInventory extends PluginInventory {
|
public abstract class EditionInventory extends PluginInventory {
|
||||||
protected Type type;
|
protected final Type type;
|
||||||
protected String id;
|
protected final String id;
|
||||||
|
|
||||||
private int prevPage;
|
private int prevPage;
|
||||||
private ItemStack cached;
|
private ItemStack cached;
|
||||||
@ -48,19 +48,6 @@ public abstract class EditionInventory extends PluginInventory {
|
|||||||
return cached != null;
|
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 is cached in the inventory class to allow GUIs not to generate
|
||||||
* the item each time the user goes to another GUI or page
|
* 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));
|
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) {
|
public void addEditionInventoryItems(Inventory inv, boolean backBool) {
|
||||||
ItemStack get = new ItemStack(VersionMaterial.GUNPOWDER.toMaterial());
|
ItemStack get = new ItemStack(VersionMaterial.GUNPOWDER.toMaterial());
|
||||||
ItemMeta getMeta = get.getItemMeta();
|
ItemMeta getMeta = get.getItemMeta();
|
||||||
@ -96,7 +101,7 @@ public abstract class EditionInventory extends PluginInventory {
|
|||||||
prevPage = page;
|
prevPage = page;
|
||||||
open();
|
open();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getPreviousPage() {
|
public int getPreviousPage() {
|
||||||
return prevPage;
|
return prevPage;
|
||||||
}
|
}
|
||||||
|
@ -69,7 +69,7 @@ public class Crafting extends ItemStat {
|
|||||||
Bukkit.getScheduler().runTask(MMOItems.plugin, new Runnable() {
|
Bukkit.getScheduler().runTask(MMOItems.plugin, new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
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]'");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user