Solved Commands help

Discussion in 'Plugin Development' started by SixFeedUnder, Oct 17, 2015.

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


    Hello, I have written a plugin that allows you to right click a mob and it will open up a inventory and display a few items that you can click to activate commands but I would like to implement a command into the code that you have to use to spawn this special mob instead of it being any mob on the map, Im new to java coding and im trying to learn Java and Bukkit and I do not know a whole lot so If someone could add the command for me it would be great and then I can see for my self how to do it, Thanks!

    package me.sixfeedunder.core;
    import java.util.logging.Logger;
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.entity.Entity;
    import org.bukkit.entity.Player;
    import org.bukkit.entity.Wolf;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.inventory.InventoryClickEvent;
    import org.bukkit.event.player.PlayerInteractEntityEvent;
    import org.bukkit.inventory.Inventory;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    import org.bukkit.potion.PotionEffect;
    import org.bukkit.potion.PotionEffectType;
    public class Main extends JavaPlugin implements Listener{
        public Main plugin;
        public final Logger logger = Bukkit.getServer().getLogger();
        public void onEnable(){
            this.getServer().getPluginManager().registerEvents(this, this);
        public void RightClickedEntity(PlayerInteractEntityEvent event){
            Player p = (Player) event.getPlayer();
            Entity e = event.getRightClicked();
            Inventory inv;
            if( e instanceof Wolf){
                ((Wolf) e).setMaximumNoDamageTicks(999999999);
                ((Wolf) e).setMaxHealth(999999999);
                ((Wolf) e).setBreed(false);
                ((Wolf) e).setTamed(true);
                ((Wolf) e).addPotionEffect(new PotionEffect(PotionEffectType.SLOW, Integer.MAX_VALUE, 10));
                for (String st : getConfig().getStringList("MobName")){
                    e.setCustomName(ChatColor.translateAlternateColorCodes('&', st)); 
                ItemStack bone = new ItemStack(Material.BONE);
                ItemStack enderchest = new ItemStack(Material.ENDER_CHEST);
                ItemStack stone = new ItemStack(Material.STONE);
                ItemStack cobblestone = new ItemStack(Material.COBBLESTONE);
                ItemStack beef = new ItemStack(Material.COOKED_BEEF);
                ItemStack emerald = new ItemStack(Material.EMERALD_BLOCK);
                ItemStack diamond = new ItemStack(Material.DIAMOND);
                // create the meta item
                ItemMeta mbone = bone.getItemMeta();
                ItemMeta mchest = enderchest.getItemMeta();
                ItemMeta mstone = stone.getItemMeta();
                ItemMeta mcobblestone = cobblestone.getItemMeta();
                ItemMeta mbeef = beef.getItemMeta();
                ItemMeta mdiamond = diamond.getItemMeta();
                ItemMeta memerald = emerald.getItemMeta();
                // set the display name
                mbone.setDisplayName(ChatColor.AQUA + "Clear Inventory");
                mchest.setDisplayName(ChatColor.AQUA + "example");
                mstone.setDisplayName(ChatColor.AQUA + "example");
                mcobblestone.setDisplayName(ChatColor.RED + "example");
                mbeef.setDisplayName(ChatColor.AQUA + "Free Food");
                mdiamond.setDisplayName(ChatColor.LIGHT_PURPLE + "Warp Shop");
                memerald.setDisplayName(ChatColor.GREEN + "See your Balance");
                // set the meta
                // create the inventory
                for (String st : getConfig().getStringList("InvDisplayName")){
                    inv = Bukkit.createInventory(null, 9, ChatColor.translateAlternateColorCodes('&', st));
                    // set the item in the inventory
                    inv.setItem(0, diamond);
                    inv.setItem(1, emerald);
                    inv.setItem(2, beef);
                    inv.setItem(3, bone);
                    inv.setItem(4, enderchest);
                    inv.setItem(5, stone);
                    inv.setItem(6, cobblestone);
                    // open the inventory
        public void onInventoryClick(InventoryClickEvent e) {
            Player p = (Player) e.getWhoClicked();
            if (e.getCurrentItem() == null || e.getCurrentItem().getItemMeta() == null || e.getCurrentItem().getItemMeta().getDisplayName() == null) return;
            if (e.getCurrentItem().getItemMeta().getDisplayName().contains("Clear Inventory")) {
                p.sendMessage(ChatColor.GREEN + "Your inventory has been cleared.");
            } else if (e.getCurrentItem().getItemMeta().getDisplayName().contains("Free Food")) {
                p.getInventory().addItem(new ItemStack(Material.COOKED_BEEF));
                p.getInventory().addItem(new ItemStack(Material.COOKED_BEEF));
                p.getInventory().addItem(new ItemStack(Material.COOKED_BEEF));
                p.sendMessage(ChatColor.GREEN + "You recieved free food.");
            } else if (e.getCurrentItem().getItemMeta().getDisplayName().contains("Warp Shop")) {
                p.performCommand("warp shop");
                p.sendMessage(ChatColor.GREEN + "You warped to shop.");
            } else {
  2. Offline


    People writing code for you is not the way to learn, and has become a large problem in the Bukkit community due to so many people copy-pasting youtube video code, and code from the forums without having a clue what it does.

    If you want a command, you need to run a CommandExecutor, and register the command both in your plugin.yml, and onEnable() method in your main class.

    I would suggest you have a read through this before continuing with this thread:

    That tutorial will give you an overview of how to set up CommandExecutors,and how to use them.
    The only information you will get from this thread is the same as in that link.

    Try working it out based on the information there, and ask back if you're having issues with parts of it
  3. Offline


    Don't dive in bukkit without learning java first. With a high experience can be bukkit frustrating too (basically because you need to export the jar file, then reload the server, then all the testing, an you need to do this hundreds of times), imagina what it is like, if you don't know java.
Thread Status:
Not open for further replies.

Share This Page