Virtual Anvil Weird

Discussion in 'Spigot Plugin Development' started by DustinThePlugin, Apr 18, 2017.

  1. So I wanted to code a simple /anvil plugin for my server, It works EXACTLY how it should, but when used, the item meta wont stick to the item, partially because I'm not familiar with anvil inventory item meta. Could someone help me complete the hole I don't understand

    Code (Text):
    package me.reheightyt.vanvil;

    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.inventory.InventoryType;
    import org.bukkit.inventory.Inventory;

    public class Main extends JavaPlugin {
        public void onEnable() {
            getServer().broadcastMessage(ChatColor.DARK_RED + "[VAnvil]: Enabled");
        public void onDisable() {
            getServer().broadcastMessage(ChatColor.DARK_RED + "[VAnvil] Disabled");
        public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
            Player p = (Player)sender;
            Inventory i = Bukkit.createInventory(p, InventoryType.ANVIL);
            if (label.equalsIgnoreCase("anvil")) {
                p.sendMessage(" ");
                p.sendMessage(" ");
                p.sendMessage(ChatColor.DARK_GRAY + "" + ChatColor.STRIKETHROUGH + "------------------------------------------");
                p.sendMessage(ChatColor.DARK_RED + "VAnvil " + ChatColor.GRAY + "➽" + ChatColor.GREEN + " Opening Virtual Anvil");
                p.sendMessage(ChatColor.DARK_GRAY + "" + ChatColor.STRIKETHROUGH + "------------------------------------------");
                p.sendMessage(" ");
                p.sendMessage(" ");
            return true;
  2. Bump? I don't know what to do
  3. In your on enable, I'd recommend using "getLogger().info(message);" instead of getServer().broadcastMessage because getLogger will send a message in console.

    Also, what have you tried? All you've done is shown us is the message part and the creation of the inventory. You're probably going to have to get the item meta's from both (or perhaps the first item only, depends on what you decide to do) and either combine them, or set the first item's meta to the result
  4. One way of doing it would be to check the result slot of the inventory when it is closed and transfer the data manually to your item.
  5. Thanks man, I understand you, the code I have only knows it as a inventory, without any save on it so, whatever happens there isn't actually happening so I need to tell it to recognize the outcomes and stuff