What Exactly is wrong?

Discussion in 'Plugin Development' started by OfficialSammy, Oct 12, 2017.

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

    OfficialSammy

    Hello I am just getting into developing plugins for my Minecraft server and I wanted to create a Custom Kill Effect plugin that when the player kills the enemy they have the little animation.
    But I cant seem to get the inventory to work.
    when I do my command /effects
    no errors occur but nothing happens.
    This is my effects.java class
    Code:
    package me.OfficialSammy.CosemeticKillEffects;
    
    import java.util.ArrayList;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.inventory.InventoryClickEvent;
    import org.bukkit.inventory.Inventory;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    
    public class Effects implements Listener, CommandExecutor{
      
        Main plugin;
      
        public Effects(Main passedplugin){
          
          
            this.plugin = passedplugin;
            {
              
            }
            }
            @Override
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            Inventory i = Bukkit.createInventory(null, 45, ChatColor.AQUA + "Kill Effects");
            i.setItem(11, new ItemStack(Material.REDSTONE, 1));{
            }
            return false;
        }
        @EventHandler
        public void onInventoryClick(InventoryClickEvent e){
            Player player = (Player) e.getWhoClicked();
            ItemStack clicked = e.getCurrentItem();
            Inventory i = e.getInventory();
            if(i.getName().equals(i.getName())){  
            if(clicked.getType() == Material.REDSTONE){
            e.setCancelled(true);
            player.sendMessage(ChatColor.AQUA + "this works lol");
            player.openInventory(i);
            }
            }
             ItemStack blood = new ItemStack(Material.REDSTONE);
             ItemMeta bloodMeta = blood.getItemMeta();
             ArrayList<String> pworld = new ArrayList<String>();
             bloodMeta.setDisplayName(ChatColor.AQUA + "Blood Kill Effect Enabled");
             pworld.add(ChatColor.DARK_RED + "Click to enable the Blood Kill Effect!");
             bloodMeta.setLore(pworld);
             blood.setItemMeta(bloodMeta);
          
          
            }
      
    
    }
    
    And if you wish heres my Main class
    Code:
    package me.OfficialSammy.CosemeticKillEffects;
    
    import org.bukkit.Bukkit;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Main extends JavaPlugin{
    
        java.util.logging.Logger Logger = Bukkit.getLogger();
        PluginManager pm = Bukkit.getPluginManager();
        public void onEnable(){
          
            Logger.info("This plugin was made by OfficialSammy");
            Logger.info("if you have this plugin wihtout his knowledge");
            Logger.info("lmao");
            Logger.info("so dont use this or i will call the cops on you");
            Logger.info("no not really");
            Bukkit.getServer().getPluginManager();
            this.getCommand("effects").setExecutor(new Effects(this));
        }
      
    
    
      
        public void onDisable(){
          
        }
    }
    
    Any help would be lovely. :)
    Again I'm not a experienced coder with Bukkit so if its completely wrong I apologize
     
  2. Offline

    Side8StarLite

    @OfficialSammy
    You forgot to open the inventory using Player#openInventory(inventory).

    But why do you have dangling brackets everywhere in your code?
    Code:
        public Effects(Main passedplugin){
       
       
            this.plugin = passedplugin;
            {                                                      // here
           
            }                                                      // here
            }                                                      // here
            @Override
    Code:
            i.setItem(11, new ItemStack(Material.REDSTONE, 1));{          // here
            }                                                      // here
            return false;
    Please delete these
    Also, try format your code so it's easier to read. In Eclipse, it is Ctrl + Shift + F. There's also an online formatter here
    Gl :)
     
  3. Offline

    OfficialSammy

    hehe..thing about that is my eclipse is giving an error about when I do something CRTL+Shift.
    Also where would I put the Player#openInventory(Inventory)
     
  4. Offline

    Side8StarLite

    @OfficialSammy
    Code:
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            Inventory i = Bukkit.createInventory(null, 45, ChatColor.AQUA + "Kill Effects");
            i.setItem(11, new ItemStack(Material.REDSTONE, 1));
            // over here, after you instantiate the inventory
            return false;
     
  5. Offline

    OfficialSammy

    Thank you so much @Side8StarLite
    Also, e.setcancelled(true);
    resets the item to its spot in the inventory. I can still take the item out however. how to fix? sorry if I'm being buggy I am sorry aswell.
     
  6. Offline

    Reflxction

    @OfficialSammy That could be an issue with updating inventories. Not sure if it was only me, but it was an issue like that in 1.12
     
  7. Offline

    OfficialSammy

  8. Offline

    Side8StarLite

    @OfficialSammy
    This is just something you'll have to deal with; I don't think there's any way of fixing this.
     
Thread Status:
Not open for further replies.

Share This Page