Command Help

Discussion in 'Plugin Development' started by konnor77, Aug 1, 2014.

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

    konnor77

    I'm making a bag plugin where I want players to do /bag to open the chest but I only know how to do click events as seen in my BackPackListener.java here
    Code:
     package me.konnor77.EpixVIP;
     
    import java.util.List;
    import java.util.UUID;
     
    import org.bukkit.Bukkit;
    import org.bukkit.Material;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.event.player.PlayerQuitEvent;
    import org.bukkit.inventory.Inventory;
    import org.bukkit.inventory.ItemStack;
     
     
     
    public class BackPackListener implements Listener {
    public Main plugin;
    public BackPackListener(Main m){
    this.plugin = m;
    }
     
    @EventHandler
    public void interact(PlayerInteractEvent event){
    Player player = event.getPlayer();
    UUID id = player.getUniqueId();
    ItemStack is = event.getItem();
    if(is!= null){
    if(event.getAction()==Action.LEFT_CLICK_AIR || event.getAction()== Action.LEFT_CLICK_AIR)
    if(is.getType()==Material.CHEST);
     if(plugin.inventories.containsKey(id)){
     player.openInventory(plugin.inventories.get(id));
     }
    }
     
    }
    @SuppressWarnings("unchecked")
    @EventHandler
    public void join(PlayerJoinEvent event){
    Player player = event.getPlayer();
    UUID id = player.getUniqueId();
    if(!plugin.inventories.containsKey(id)){
    if(plugin.config.get(id.toString())!= null){
    Object i = plugin.config.get(id.toString() + ".items");
    ItemStack[] contents = null;
    if(i instanceof ItemStack[]){
    contents = (ItemStack[]) i;
    }else if (i instanceof List){
    contents = (ItemStack[]) ((List<ItemStack>) i).toArray(new ItemStack[27]);
    }
    Inventory inv = Bukkit.createInventory(player, 36);
    inv.setContents(contents);
    plugin.inventories.put(id, inv);
    }else{
    plugin.inventories.put(id, Bukkit.createInventory(player, 36));
     
    }
    }
    }
     
    @EventHandler
    public void Leave(PlayerQuitEvent event){
    Player player = event.getPlayer();
    UUID id = player.getUniqueId();
    ItemStack[] contents = player.getInventory().getContents();
    plugin.config.set(id.toString() + ".items", contents);
    plugin.saveConfig();
    }
     
    }
    
    I'm not sure where or how to make instead of clicking with a chest, they can just do /bag. I have a Main class to but I don't think it's relevant to post it? Just need some help.
     
  2. Offline

    travja

    You need to register the bag command in your plugin.yml and then make a CommandExecutor to handle the command stuff.
     
  3. Offline

    konnor77

    travja How would I make the command in CommandExecuter do whats in my BackPackListener?
     
  4. Offline

    Niknea

    konnor77 Add them to an array list, then checking if there in the array list before executing the event.
     
  5. Offline

    travja

    konnor77 Just look up info on CommandExecutors
     
Thread Status:
Not open for further replies.

Share This Page