Command won't run?

Discussion in 'Plugin Development' started by poilet66, Feb 2, 2019.

Thread Status:
Not open for further replies.
  1. Offline

    poilet66

    Hey so, as a continuation of my chestrefill plugin, I found an API that allows me to add a chance of a certain item being added to a chest at a location with a certain chance, here's a link to that and its classes: https://github.com/kicjow/Chest-Refill-API

    So, I've created a command that when ran, should iterate through the items in the 'items' HashMap and add them into the chest I'm currently looking at but when I run it, I don't get the message saying it's been refilled and the chest will remain empty despite me adding 100 as the item being added chance.

    Also, I heard you can use null instead of making an essentially blank HashSet but when I try to do so it just says 'The method getTargetBlock(HashSet<Byte>, int) is ambiguous for the type Player' so thats kinda got me stuck.

    Here's the code I made, the rest is just the ChestRefillAPI:

    Code:
    public boolean refillCommand(CommandSender sender, Command cmd, String label, String[] args) {
            HashSet<Material> transparent = new HashSet<Material>(); //hashset of ignored blocks
            HashMap<ItemStack,Integer> items = new HashMap<>(); //Hashmap containing the item and its % chance of being in chest
            transparent.add(Material.AIR); //add air to blocks ignored for targetblock
            items.put(new ItemStack (Material.BAKED_POTATO),new Integer(args[0])); //add Baked Potato with the args % chance of being in chest
            Player player = (Player) sender;
         
            if (cmd.getName().equalsIgnoreCase("refill") && player instanceof Player) { //on /refill command
                Block block = player.getTargetBlock(null, 200); //get the block theyre looking at, ignoring all blocks in transparent
                ChestRefiller.refillChest(block.getLocation(), items, 4); //command from API, refill chest at block location, do for items in HashMap, max of 4 items in chest
                player.sendMessage("Chest at " + block.getLocation() + "has been refilled!"); //message player command has been ran
             
                return true;
            }
            return false; 
        }
    Heres my plugin yml too if you need it:

    Code:
    name: ChestRefiller
    main: me.chestrefill.ChestRefiller
    version: 1.0
    description: chest refiller
    commands:
        refill:
            description: refill chest you are looking at
            usage: /<command>
    EDIT: I've just managed to fix this! Turns out that I needed to use onCommand instead of refillCommand. :)
     
    Last edited by a moderator: Feb 2, 2019
  2. Offline

    Chr0mosom3

    @poilet66, please mark this post as solved
     
Thread Status:
Not open for further replies.

Share This Page