Portable Items (Problem)

Discussion in 'Plugin Development' started by OwningDaPeopleHD, Oct 16, 2015.

Thread Status:
Not open for further replies.
  1. I've got a problem that I can't quite figure out what it's caused by. My plugin has portable inventories. I have 4 commands- /enchanttable, /brew, /anvil, and /furnace. They all work. But, only /anvil actually repairs stuff. /brew doesn't brew when i put something in there, /furnace doesn't smelt, and /enchanttable doesn't enchant. Only the GUIs pop up. D: If any of you other devs can tell me what's wrong, I'd greatly appreciate it. (Note- I'm a new dev) Here's my code-

    (Note- I used player.openInventory( ), and I created a specific inventory for each command.)

    Code:
    package me.LAjessy1;
    
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.craftbukkit.v1_8_R3.inventory.CraftInventoryCustom;
    import org.bukkit.entity.Player;
    import org.bukkit.event.inventory.InventoryType;
    import org.bukkit.inventory.Inventory;
    import org.bukkit.permissions.Permission;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class BeastMain extends JavaPlugin {
     
        public Permission playerPermission1 = new Permission("beastEnchant.allowed");
        public Permission playerPermission2 = new Permission("beastBrew.allowed");
        public Permission playerPermission3 = new Permission("beastAnvil.allowed");
        public Permission playerPermission4 = new Permission("beastFurnace.allowed");
    
        @Override
        public void onEnable() {
            System.out.println("BeastPortables enabled! Made by LAjessy!");
            PluginManager pm = getServer().getPluginManager();
            pm.addPermission(playerPermission1);
            pm.addPermission(playerPermission2);
            pm.addPermission(playerPermission3);
            pm.addPermission(playerPermission4);
        }
    
        @Override
        public void onDisable() {
         
        }
    
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            if (cmd.getName().equalsIgnoreCase("enchanttable")) {
                if (sender instanceof Player) {
                    int length = args.length;
                    Player player = (Player) sender;
                    if (player.hasPermission("beastEnchant.allowed")) {
                        if (length == 1) {
                            player.sendMessage("Incorrect usage. Usage: /<command>");
                        } else if (length == 0) {
                            Inventory enchantingInventory = new CraftInventoryCustom(player, InventoryType.ENCHANTING);
                            player.sendMessage(ChatColor.GOLD + "Beast" + ChatColor.DARK_PURPLE + "Portables"
                                    + ChatColor.BLACK + "> " + ChatColor.GREEN + " Opening enchantment table...");
                            player.openInventory(enchantingInventory);
                            return true;
                        }
                    } else if (!player.hasPermission("beastEnchant.allowed")) {
                        player.sendMessage(ChatColor.GOLD + "Beast" + ChatColor.DARK_PURPLE + "Portables" + ChatColor.BLACK
                                + "> " + ChatColor.RED + " You do not have permission to execute this command.");
                        return true;
                    }
                } else {
                    sender.sendMessage(ChatColor.GOLD + "Beast" + ChatColor.DARK_PURPLE + "Portables" + ChatColor.BLACK
                            + "> " + ChatColor.RED + "You must be a player to execute this command.");
                    return true;
                }
            } else if (cmd.getName().equalsIgnoreCase("brew")) {
                if (sender instanceof Player) {
                    int length = args.length;
                    Player player2 = (Player) sender;
                    if (player2.hasPermission("beastBrew.allowed")) {
                        if (length == 1) {
                            player2.sendMessage("Incorrect usage. Usage: /<command>");
                        } else if (length == 0) {
                            Inventory brewingInventory = new CraftInventoryCustom(player2, InventoryType.BREWING);
                            player2.sendMessage(ChatColor.GOLD + "Beast" + ChatColor.DARK_PURPLE + "Portables"
                                    + ChatColor.BLACK + "> " + ChatColor.GREEN + "Opening brewing stand...");
                            player2.openInventory(brewingInventory);
                            return true;
                        }
                    } else if (!player2.hasPermission("beastBrew.allowed")) {
                        player2.sendMessage(ChatColor.GOLD + "Beast" + ChatColor.DARK_PURPLE + "Portables" + ChatColor.BLACK
                                + "> " + ChatColor.RED + "You do not have permission to execute this command.");
                        return true;
                    }
                } else {
                    sender.sendMessage(ChatColor.GOLD + "Beast" + ChatColor.DARK_PURPLE + "Portables" + ChatColor.BLACK
                            + "> " + ChatColor.RED + "You must be a player to execute this command.");
                    return true;
                }
            } else if (cmd.getName().equalsIgnoreCase("anvil")) {
                if (sender instanceof Player) {
                    int length = args.length;
                    Player player3 = (Player) sender;
                    if (player3.hasPermission("beastAnvil.allowed")) {
                        if (length == 1) {
                            player3.sendMessage("Incorrect usage. Usage: /<command>");
                        } else if (length == 0) {
                            Inventory anvilInventory = new CraftInventoryCustom(player3, InventoryType.ANVIL);
                            player3.sendMessage(ChatColor.GOLD + "Beast" + ChatColor.DARK_PURPLE + "Portables"
                                    + ChatColor.BLACK + "> " + ChatColor.GREEN + "Opening anvil...");
                            player3.openInventory(anvilInventory);
                            return true;
                        }
                    } else if (!player3.hasPermission("beastAnvil.allowed")) {
                        player3.sendMessage(ChatColor.GOLD + "Beast" + ChatColor.DARK_PURPLE + "Portables" + ChatColor.BLACK
                                + "> " + ChatColor.RED + "You do not have permission to execute this command.");
                        return true;
                    }
                } else {
                    sender.sendMessage(ChatColor.GOLD + "Beast" + ChatColor.DARK_PURPLE + "Portables" + ChatColor.BLACK
                            + "> " + ChatColor.RED + "You must be a player to execute this command.");
                    return true;
                }
            } else if (cmd.getName().equalsIgnoreCase("furnace")) {
                if (sender instanceof Player) {
                    int length = args.length;
                    Player player4 = (Player) sender;
                    if (player4.hasPermission("beastFurnace.allowed")) {
                        if (length == 1) {
                            player4.sendMessage("Incorrect usage. Usage: /<command>");
                        } else if (length == 0) {
                            Inventory furnaceInventory = new CraftInventoryCustom(player4, InventoryType.FURNACE);
                            player4.sendMessage(ChatColor.GOLD + "Beast" + ChatColor.DARK_PURPLE + "Portables"
                                    + ChatColor.BLACK + "> " + ChatColor.GREEN + "Opening furnace...");
                            player4.openInventory(furnaceInventory);
                            return true;
                        }
                    } else if (!player4.hasPermission("beastFurnace.allowed")) {
                        player4.sendMessage(ChatColor.GOLD + "Beast" + ChatColor.DARK_PURPLE + "Portables" + ChatColor.BLACK
                                + "> " + ChatColor.RED + "You do not have permission to execute this command.");
                        return true;
                    }
                } else {
                    sender.sendMessage(ChatColor.GOLD + "Beast" + ChatColor.DARK_PURPLE + "Portables" + ChatColor.BLACK
                            + "> " + ChatColor.RED + "You must be a player to execute this command.");
                    return true;
                }
            }
            return false;
        }
    }[code]
    Code:
    if (sender instanceof Player) {
                    int length = args.length;
                    Player player = (Player) sender;
                    if (player.hasPermission("beastEnchant.allowed")) {
                        if (length == 1) {
                            player.sendMessage("Incorrect usage. Usage: /<command>");
                        } else if (length == 0) {
                            Inventory enchantingInventory = new CraftInventoryCustom(player, InventoryType.ENCHANTING);
                            player.sendMessage(ChatColor.GOLD + "Beast" + ChatColor.DARK_PURPLE + "Portables"
                                    + ChatColor.BLACK + "> " + ChatColor.GREEN + " Opening enchantment table...");
                            player.openInventory(enchantingInventory);
                            return true;
                        }
    --------------------------------------------------------------------------
    if (sender instanceof Player) {
                    int length = args.length;
                    Player player2 = (Player) sender;
                    if (player2.hasPermission("beastBrew.allowed")) {
                        if (length == 1) {
                            player2.sendMessage("Incorrect usage. Usage: /<command>");
                        } else if (length == 0) {
                            Inventory brewingInventory = new CraftInventoryCustom(player2, InventoryType.BREWING);
                            player2.sendMessage(ChatColor.GOLD + "Beast" + ChatColor.DARK_PURPLE + "Portables"
                                    + ChatColor.BLACK + "> " + ChatColor.GREEN + "Opening brewing stand...");
                            player2.openInventory(brewingInventory);
                            return true;\
    ----------------------------------------------------------------------------------------------------------------------
    if (sender instanceof Player) {
                    int length = args.length;
                    Player player3 = (Player) sender;
                    if (player3.hasPermission("beastAnvil.allowed")) {
                        if (length == 1) {
                            player3.sendMessage("Incorrect usage. Usage: /<command>");
                        } else if (length == 0) {
                            Inventory anvilInventory = new CraftInventoryCustom(player3, InventoryType.ANVIL);
                            player3.sendMessage(ChatColor.GOLD + "Beast" + ChatColor.DARK_PURPLE + "Portables"
                                    + ChatColor.BLACK + "> " + ChatColor.GREEN + "Opening anvil...");
                            player3.openInventory(anvilInventory);
                            return true;
    ------------------------------------------------------------------------------------------------------------------------
    if (sender instanceof Player) {
                    int length = args.length;
                    Player player4 = (Player) sender;
                    if (player4.hasPermission("beastFurnace.allowed")) {
                        if (length == 1) {
                            player4.sendMessage("Incorrect usage. Usage: /<command>");
                        } else if (length == 0) {
                            Inventory furnaceInventory = new CraftInventoryCustom(player4, InventoryType.FURNACE);
                            player4.sendMessage(ChatColor.GOLD + "Beast" + ChatColor.DARK_PURPLE + "Portables"
                                    + ChatColor.BLACK + "> " + ChatColor.GREEN + "Opening furnace...");
                            player4.openInventory(furnaceInventory);
                            return true; [code]
    
    
    These 4 spots are where I think the problem is
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Oct 29, 2015
  2. Offline

    Scimiguy

    @OwningDaPeopleHD

    I refuse to read and/or help until you use the code tags
    They're under the insert menu
     
  3. Code:
    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            if (cmd.getName().equalsIgnoreCase("enchanttable")) {
                if (sender instanceof Player) {
                    int length = args.length;
                    Player player = (Player) sender;
                    if (player.hasPermission("beastEnchant.allowed")) {
                        if (length == 1) {
                            player.sendMessage("Incorrect usage. Usage: /<command>");
                        } else if (length == 0) {
                            Inventory enchantingInventory = new CraftInventoryCustom(player, InventoryType.ENCHANTING);
                            player.sendMessage(ChatColor.GOLD + "Beast" + ChatColor.DARK_PURPLE + "Portables"
                                    + ChatColor.BLACK + "> " + ChatColor.GREEN + " Opening enchantment table...");
                            player.openInventory(enchantingInventory);
                            return true;
                        }
                    } else if (!player.hasPermission("beastEnchant.allowed")) {
                        player.sendMessage(ChatColor.GOLD + "Beast" + ChatColor.DARK_PURPLE + "Portables" + ChatColor.BLACK
                                + "> " + ChatColor.RED + " You do not have permission to execute this command.");
                        return true;
                    }
                } else {
                    sender.sendMessage(ChatColor.GOLD + "Beast" + ChatColor.DARK_PURPLE + "Portables" + ChatColor.BLACK
                            + "> " + ChatColor.RED + "You must be a player to execute this command.");
                    return true;
                }
            } else if (cmd.getName().equalsIgnoreCase("brew")) {
                if (sender instanceof Player) {
                    int length = args.length;
                    Player player2 = (Player) sender;
                    if (player2.hasPermission("beastBrew.allowed")) {
                        if (length == 1) {
                            player2.sendMessage("Incorrect usage. Usage: /<command>");
                        } else if (length == 0) {
                            Inventory brewingInventory = new CraftInventoryCustom(player2, InventoryType.BREWING);
                            player2.sendMessage(ChatColor.GOLD + "Beast" + ChatColor.DARK_PURPLE + "Portables"
                                    + ChatColor.BLACK + "> " + ChatColor.GREEN + "Opening brewing stand...");
                            player2.openInventory(brewingInventory);
                            return true;
                        }
                    } else if (!player2.hasPermission("beastBrew.allowed")) {
                        player2.sendMessage(ChatColor.GOLD + "Beast" + ChatColor.DARK_PURPLE + "Portables" + ChatColor.BLACK
                                + "> " + ChatColor.RED + "You do not have permission to execute this command.");
                        return true;
                    }
                } else {
                    sender.sendMessage(ChatColor.GOLD + "Beast" + ChatColor.DARK_PURPLE + "Portables" + ChatColor.BLACK
                            + "> " + ChatColor.RED + "You must be a player to execute this command.");
                    return true;
                }
            } else if (cmd.getName().equalsIgnoreCase("anvil")) {
                if (sender instanceof Player) {
                    int length = args.length;
                    Player player3 = (Player) sender;
                    if (player3.hasPermission("beastAnvil.allowed")) {
                        if (length == 1) {
                            player3.sendMessage("Incorrect usage. Usage: /<command>");
                        } else if (length == 0) {
                            Inventory anvilInventory = new CraftInventoryCustom(player3, InventoryType.ANVIL);
                            player3.sendMessage(ChatColor.GOLD + "Beast" + ChatColor.DARK_PURPLE + "Portables"
                                    + ChatColor.BLACK + "> " + ChatColor.GREEN + "Opening anvil...");
                            player3.openInventory(anvilInventory);
                            return true;
                        }
                    } else if (!player3.hasPermission("beastAnvil.allowed")) {
                        player3.sendMessage(ChatColor.GOLD + "Beast" + ChatColor.DARK_PURPLE + "Portables" + ChatColor.BLACK
                                + "> " + ChatColor.RED + "You do not have permission to execute this command.");
                        return true;
                    }
                } else {
                    sender.sendMessage(ChatColor.GOLD + "Beast" + ChatColor.DARK_PURPLE + "Portables" + ChatColor.BLACK
                            + "> " + ChatColor.RED + "You must be a player to execute this command.");
                    return true;
                }
            } else if (cmd.getName().equalsIgnoreCase("furnace")) {
                if (sender instanceof Player) {
                    int length = args.length;
                    Player player4 = (Player) sender;
                    if (player4.hasPermission("beastFurnace.allowed")) {
                        if (length == 1) {
                            player4.sendMessage("Incorrect usage. Usage: /<command>");
                        } else if (length == 0) {
                            Inventory furnaceInventory = new CraftInventoryCustom(player4, InventoryType.FURNACE);
                            player4.sendMessage(ChatColor.GOLD + "Beast" + ChatColor.DARK_PURPLE + "Portables"
                                    + ChatColor.BLACK + "> " + ChatColor.GREEN + "Opening furnace...");
                            player4.openInventory(furnaceInventory);
                            return true;
                        }
                    } else if (!player4.hasPermission("beastFurnace.allowed")) {
                        player4.sendMessage(ChatColor.GOLD + "Beast" + ChatColor.DARK_PURPLE + "Portables" + ChatColor.BLACK
                                + "> " + ChatColor.RED + "You do not have permission to execute this command.");
                        return true;
                    }
                } else {
                    sender.sendMessage(ChatColor.GOLD + "Beast" + ChatColor.DARK_PURPLE + "Portables" + ChatColor.BLACK
                            + "> " + ChatColor.RED + "You must be a player to execute this command.");
                    return true;
                }
            }
            return false;
        }
    The /anvil works, but /enchanttable, /brew, and /furnace doesn't
     
  4. Offline

    Scimiguy

    @OwningDaPeopleHD

    Edit your posts and put code tags around them.
    Then I'll look at it
     
  5. Done
     
  6. Offline

    Scimiguy

    The reason they aren't working is because all but the Anvil Repairing mechanism requires external input/output.

    Brewing requires a timer to be set to the block.
    Enchanting requires information about how many bookcases are around
    Cooking requires a timer to be set to the block.

    I haven't ever done this sort of thing, but if I had to make my best guestimate, I'd say you'll have to handle the cooking, enchanting, and brewing events and actions yourself, because the game doesn't have enough information to do it itself
    @OwningDaPeopleHD
     
Thread Status:
Not open for further replies.

Share This Page