mirror of
https://gitlab.com/phoenix-dvpmt/mmoitems.git
synced 2025-02-07 12:11:22 +01:00
CreateItem button and ChatEdition changes
This commit is contained in:
parent
6443f85b4b
commit
c98878ed4e
@ -12,10 +12,10 @@ import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import net.Indyuce.mmoitems.MMOItems;
|
||||
import net.Indyuce.mmoitems.api.edition.StatEdition.StatEditionProcess;
|
||||
import net.Indyuce.mmoitems.api.edition.ChatEditionBase.ChatEditionProcess;
|
||||
|
||||
public class AnvilGUI implements StatEditionProcess, Listener {
|
||||
private StatEdition edition;
|
||||
public class AnvilGUI implements ChatEditionProcess, Listener {
|
||||
private ChatEditionBase edition;
|
||||
|
||||
private int containerId;
|
||||
private Inventory inventory;
|
||||
@ -26,7 +26,7 @@ public class AnvilGUI implements StatEditionProcess, Listener {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void open(StatEdition edition) {
|
||||
public void open(ChatEditionBase edition) {
|
||||
this.edition = edition;
|
||||
|
||||
ItemStack paper = new ItemStack(Material.PAPER);
|
||||
|
@ -9,13 +9,13 @@ import org.bukkit.event.inventory.InventoryOpenEvent;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
|
||||
import net.Indyuce.mmoitems.MMOItems;
|
||||
import net.Indyuce.mmoitems.api.edition.StatEdition.StatEditionProcess;
|
||||
import net.Indyuce.mmoitems.api.edition.ChatEditionBase.ChatEditionProcess;
|
||||
|
||||
public class ChatEdition implements StatEditionProcess, Listener {
|
||||
private StatEdition edition;
|
||||
public class ChatEdition implements ChatEditionProcess, Listener {
|
||||
private ChatEditionBase edition;
|
||||
|
||||
@Override
|
||||
public void open(StatEdition edition) {
|
||||
public void open(ChatEditionBase edition) {
|
||||
this.edition = edition;
|
||||
|
||||
Bukkit.getPluginManager().registerEvents(this, MMOItems.plugin);
|
||||
|
@ -0,0 +1,35 @@
|
||||
package net.Indyuce.mmoitems.api.edition;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import net.Indyuce.mmoitems.gui.PluginInventory;
|
||||
|
||||
public abstract class ChatEditionBase {
|
||||
|
||||
/*
|
||||
* saves the last inventory opened. it saves the item data, and the last
|
||||
* opened page. allows for a much easier access to this data
|
||||
*/
|
||||
protected PluginInventory inv;
|
||||
|
||||
public ChatEditionBase(PluginInventory inv) {
|
||||
this.inv = inv;
|
||||
}
|
||||
|
||||
public PluginInventory getInventory() {
|
||||
return inv;
|
||||
}
|
||||
|
||||
public Player getPlayer() {
|
||||
return inv.getPlayer();
|
||||
}
|
||||
|
||||
public abstract void enable(String... messages);
|
||||
|
||||
public abstract void output(String output);
|
||||
|
||||
public interface ChatEditionProcess {
|
||||
void open(ChatEditionBase edition);
|
||||
|
||||
void close();
|
||||
}
|
||||
}
|
@ -0,0 +1,64 @@
|
||||
package net.Indyuce.mmoitems.api.edition;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import net.Indyuce.mmoitems.MMOItems;
|
||||
import net.Indyuce.mmoitems.api.Type;
|
||||
import net.Indyuce.mmoitems.gui.PluginInventory;
|
||||
|
||||
public class NewItemEdition extends ChatEditionBase {
|
||||
|
||||
/*
|
||||
* 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 Type type;
|
||||
|
||||
public NewItemEdition(PluginInventory inv, Type type) {
|
||||
super(inv);
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public Type getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enable(String... messages) {
|
||||
getPlayer().closeInventory();
|
||||
|
||||
getPlayer().sendMessage(ChatColor.YELLOW + "" + ChatColor.STRIKETHROUGH + "-----------------------------------------------------");
|
||||
getPlayer().sendMessage(MMOItems.plugin.getPrefix() + ChatColor.translateAlternateColorCodes('&', "Write in the chat, the id of the new item."));
|
||||
getPlayer().sendMessage(MMOItems.plugin.getPrefix() + "Type 'cancel' to abort editing.");
|
||||
|
||||
/*
|
||||
* 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") && MMOItems.plugin.getVersion().isBelowOrEqual(1, 13)) {
|
||||
new AnvilGUI().open(this);
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* default chat edition feature
|
||||
*/
|
||||
new ChatEdition().open(this);
|
||||
MMOItems.plugin.getNMS().sendTitle(getPlayer(), ChatColor.GOLD + "" + ChatColor.BOLD + "Item Creation", "See chat.", 10, 40, 10);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void output(String output) {
|
||||
if (output.equals("cancel"))
|
||||
inv.open();
|
||||
else new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Bukkit.dispatchCommand(getPlayer(), "mi create " + type.getId() + " " + output.toUpperCase().replace(" ", "_").replace("-", "_"));
|
||||
}
|
||||
}.runTask(MMOItems.plugin);
|
||||
}
|
||||
}
|
@ -1,19 +1,12 @@
|
||||
package net.Indyuce.mmoitems.api.edition;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import net.Indyuce.mmoitems.MMOItems;
|
||||
import net.Indyuce.mmoitems.gui.edition.EditionInventory;
|
||||
import net.Indyuce.mmoitems.stat.type.ItemStat;
|
||||
|
||||
public class StatEdition {
|
||||
|
||||
/*
|
||||
* saves the last inventory opened. it saves the item data, and the last
|
||||
* opened page. allows for a much easier access to this data
|
||||
*/
|
||||
private EditionInventory inv;
|
||||
public class StatEdition extends ChatEditionBase {
|
||||
|
||||
/*
|
||||
* saves the data about the edited data so the plugin can edit the
|
||||
@ -24,15 +17,11 @@ public class StatEdition {
|
||||
private Object[] info;
|
||||
|
||||
public StatEdition(EditionInventory inv, ItemStat stat, Object... info) {
|
||||
this.inv = inv;
|
||||
super(inv);
|
||||
this.stat = stat;
|
||||
this.info = info;
|
||||
}
|
||||
|
||||
public EditionInventory getEditionInventory() {
|
||||
return inv;
|
||||
}
|
||||
|
||||
public ItemStat getStat() {
|
||||
return stat;
|
||||
}
|
||||
@ -41,10 +30,7 @@ public class StatEdition {
|
||||
return info;
|
||||
}
|
||||
|
||||
public Player getPlayer() {
|
||||
return inv.getPlayer();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enable(String... messages) {
|
||||
getPlayer().closeInventory();
|
||||
|
||||
@ -69,16 +55,11 @@ public class StatEdition {
|
||||
MMOItems.plugin.getNMS().sendTitle(getPlayer(), ChatColor.GOLD + "" + ChatColor.BOLD + "Item Edition", "See chat.", 10, 40, 10);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void output(String output) {
|
||||
if (output.equals("cancel"))
|
||||
inv.open();
|
||||
else
|
||||
stat.whenInput(inv, inv.getItemType().getConfigFile(), output, info);
|
||||
}
|
||||
|
||||
public interface StatEditionProcess {
|
||||
void open(StatEdition edition);
|
||||
|
||||
void close();
|
||||
stat.whenInput((EditionInventory)inv, ((EditionInventory) inv).getItemType().getConfigFile(), output, info);
|
||||
}
|
||||
}
|
||||
|
@ -20,6 +20,7 @@ import org.bukkit.inventory.meta.ItemMeta;
|
||||
import net.Indyuce.mmoitems.MMOItems;
|
||||
import net.Indyuce.mmoitems.MMOUtils;
|
||||
import net.Indyuce.mmoitems.api.Type;
|
||||
import net.Indyuce.mmoitems.api.edition.NewItemEdition;
|
||||
import net.Indyuce.mmoitems.api.item.NBTItem;
|
||||
import net.Indyuce.mmoitems.api.util.AltChar;
|
||||
import net.Indyuce.mmoitems.gui.edition.ItemEdition;
|
||||
@ -68,7 +69,7 @@ public class ItemBrowser extends PluginInventory {
|
||||
meta.setDisplayName(ChatColor.GREEN + type.getName() + ChatColor.DARK_GRAY + " (Click to browse)");
|
||||
meta.addItemFlags(ItemFlag.values());
|
||||
List<String> lore = new ArrayList<>();
|
||||
lore.add(ChatColor.GRAY + "" + ChatColor.ITALIC + "There " + (items > 1 || items < 1 ? "are" : "is") + " " + (items < 1 ? "" + ChatColor.RED + ChatColor.ITALIC + "no" : "" + ChatColor.GOLD + ChatColor.ITALIC + items) + ChatColor.GRAY + ChatColor.ITALIC + " item" + (items > 1 ? "s" : "") + " in that type.");
|
||||
lore.add(ChatColor.GRAY + "" + ChatColor.ITALIC + "There " + (items != 1 ? "are" : "is") + " " + (items < 1 ? "" + ChatColor.RED + ChatColor.ITALIC + "no" : "" + ChatColor.GOLD + ChatColor.ITALIC + items) + ChatColor.GRAY + ChatColor.ITALIC + " item" + (items != 1 ? "s" : "") + " in that type.");
|
||||
meta.setLore(lore);
|
||||
item.setItemMeta(meta);
|
||||
|
||||
@ -151,6 +152,11 @@ public class ItemBrowser extends PluginInventory {
|
||||
backMeta.setDisplayName(ChatColor.GREEN + AltChar.rightArrow + " Back");
|
||||
back.setItemMeta(backMeta);
|
||||
|
||||
ItemStack create = new ItemStack(Material.GREEN_STAINED_GLASS_PANE);
|
||||
ItemMeta createMeta = create.getItemMeta();
|
||||
createMeta.setDisplayName(ChatColor.GREEN + "Create New");
|
||||
create.setItemMeta(createMeta);
|
||||
|
||||
ItemStack previous = new ItemStack(Material.ARROW);
|
||||
ItemMeta previousMeta = previous.getItemMeta();
|
||||
previousMeta.setDisplayName(ChatColor.GREEN + "Previous Page");
|
||||
@ -159,6 +165,7 @@ public class ItemBrowser extends PluginInventory {
|
||||
while (n < slots.length)
|
||||
inv.setItem(slots[n++], noItem);
|
||||
inv.setItem(49, back);
|
||||
inv.setItem(51, create);
|
||||
inv.setItem(18, page > 1 ? previous : null);
|
||||
inv.setItem(26, max >= itemIDs.size() ? null : next);
|
||||
return inv;
|
||||
@ -187,6 +194,9 @@ public class ItemBrowser extends PluginInventory {
|
||||
if (item.getItemMeta().getDisplayName().equals(ChatColor.GREEN + AltChar.rightArrow + " Back"))
|
||||
new ItemBrowser(player).open();
|
||||
|
||||
if (item.getItemMeta().getDisplayName().equals(ChatColor.GREEN + "Create New"))
|
||||
new NewItemEdition(this, this.type).enable("Write in the chat the text you want.");
|
||||
|
||||
if (type == null && !item.getItemMeta().getDisplayName().equals(ChatColor.RED + "- No type -")) {
|
||||
Type type = MMOItems.plugin.getTypes().get(NBTItem.get(item).getString("typeId"));
|
||||
new ItemBrowser(player, type).open();
|
||||
|
Loading…
Reference in New Issue
Block a user