Solved Problem getting events to work :/

Discussion in 'Plugin Development' started by winitro, Sep 12, 2014.

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

    winitro

    This is the only class
    Code:
    package me.winitro.kits;
     
    import java.util.ArrayList;
    import java.util.Arrays;
    import java.util.List;
     
    import org.bukkit.ChatColor;
    import org.bukkit.Color;
    import org.bukkit.Material;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.enchantments.Enchantment;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.entity.PlayerDeathEvent;
    import org.bukkit.event.player.PlayerRespawnEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    import org.bukkit.inventory.meta.LeatherArmorMeta;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.potion.PotionEffect;
    import org.bukkit.potion.PotionEffectType;
     
    public class Main extends JavaPlugin implements Listener{
     
        public static ArrayList<String> KeeperofThings = new ArrayList<>();
       
        public ItemStack dyeArmour(Material material, int r, int g, int b){
            ItemStack armour = new ItemStack(material);
            LeatherArmorMeta lam = (LeatherArmorMeta) armour.getItemMeta();
           
            lam.setColor(Color.fromRGB(r, g, b));
            armour.setItemMeta(lam);
           
            return armour;
        }
        @EventHandler
        public void onPlayerDeath(PlayerDeathEvent e)
        {
            e.getDrops().clear();
            }
        @EventHandler
        public void PlayerRespawn(PlayerRespawnEvent e)
        {
            Player player = e.getPlayer();
            KeeperofThings.remove(player.getName());
            }
        public ItemStack setMeta(ItemStack material, String name, List<String> lore) {
            if(((material == null) || material.getType() == Material.AIR) || (name == null && lore == null))
                return null;
           
            ItemMeta im = material.getItemMeta();
            if(name != null)
                im.setDisplayName(name);
            if(lore != null)
                im.setLore(lore);
           
            material.setItemMeta(im);
            return material;
        }
       
       
        public boolean onCommand(CommandSender sender, Command cmd,
                String commandLabel, String[] args) {
            if(commandLabel.equalsIgnoreCase("Kits")){
                Player player = (Player) sender;
                player.sendMessage("§6-----------{§cYour kits§6}----------");
                player.sendMessage("§eUse the kits by name you don't need to do /kit <name>");
                if(!(player.hasPermission("MassKits.Member"))){
                    player.sendMessage("§4- Member - Not owned buy it!");
                } else {
                    player.sendMessage("§a- Member");
                }
                    if(!(player.hasPermission("MassKits.Fighter"))){
                        player.sendMessage("§4- Fighter - Not owned buy it!");
                    } else {
                        player.sendMessage("§a- Fighter");
                    }
                        if(!(player.hasPermission("MassKits.Warrior"))){
                            player.sendMessage("§4- Warrior - Not owned buy it!");
                        } else {
                            player.sendMessage("§a- Warrior");
                        }
                            if(!(player.hasPermission("MassKits.Killer"))){
                                player.sendMessage("§4- Killer - Not owned buy it!");
                            } else {
                                player.sendMessage("§a- Killer");
                            }
            }
                Player player = (Player) sender;
                            if(commandLabel.equalsIgnoreCase("Member")){
                                if(KeeperofThings.contains(player.getName())){
                                    player.sendMessage(ChatColor.DARK_RED + "There's only one kit per life!");
                                    if(!(player.hasPermission("MassKits.Member"))){
                                    player.sendMessage("§4You do not have permission to kit Member!");
                                }
                            } else {
                                player.sendMessage("§4Mass§cPvP §4> §cYou got kit Member!");
                                KeeperofThings.add(player.getName());
                                player.getInventory().clear();
                                ItemStack newBoots = dyeArmour(Material.LEATHER_BOOTS, 0, 0, 0);
                                ItemStack newA = dyeArmour(Material.LEATHER_CHESTPLATE, 0, 0, 0);
                                ItemStack newG = dyeArmour(Material.LEATHER_HELMET, 0, 0, 0);
                                ItemStack newE = dyeArmour(Material.LEATHER_LEGGINGS, 0, 0, 0);
                                ItemStack GI = setMeta(new ItemStack(Material.WOOD_SWORD), "" + "", Arrays.asList(""));
                               
                                player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 100000000, 1));
                               
                                player.getInventory().setBoots(newBoots);
                                player.getInventory().setChestplate(newA);
                                player.getInventory().setLeggings(newE);
                                player.getInventory().setHelmet(newG);
                                player.getInventory().addItem(GI);
                                }
                            }
                            if(commandLabel.equalsIgnoreCase("Fighter")){
                                if(KeeperofThings.contains(player.getName())){
                                    player.sendMessage(ChatColor.DARK_RED + "There's only one kit per life!");
                               
                                if(!(player.hasPermission("MassKits.Fighter"))){
                                    player.sendMessage("§4You do not have permission to kit Fighter!");
                                }
                            } else {
                                player.sendMessage("§4Mass§cPvP §4> §cYou got kit Fighter!");
                                KeeperofThings.add(player.getName());
                                player.getInventory().clear();
                                ItemStack neBoots = dyeArmour(Material.LEATHER_BOOTS, 0, 0, 0);
                                ItemStack neA = dyeArmour(Material.LEATHER_CHESTPLATE, 0, 0, 0);
                                ItemStack neG = dyeArmour(Material.LEATHER_HELMET, 0, 0, 0);
                                ItemStack neE = dyeArmour(Material.LEATHER_LEGGINGS, 0, 0, 0);
                                ItemStack GE = setMeta(new ItemStack(Material.WOOD_SWORD), "" + "", Arrays.asList(""));
                               
                                neBoots.addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 1);
                                player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 100000000, 1));
                                GE.addEnchantment(Enchantment.DAMAGE_ALL, 1);
                               
                                player.getInventory().setBoots(neBoots);
                                player.getInventory().setChestplate(neA);
                                player.getInventory().setLeggings(neE);
                                player.getInventory().setHelmet(neG);
                                player.getInventory().addItem(GE);
                                    }
                            }
                               
                                if(commandLabel.equalsIgnoreCase("Warrior")){
                                if(KeeperofThings.contains(player.getName())){
                                    player.sendMessage(ChatColor.DARK_RED + "There's only one kit per life!");
                                    if(!(player.hasPermission("MassKits.Warrior"))){
                                    player.sendMessage("§4You do not have permission to kit Warrior!");
                                    }
                                } else {
                                    player.sendMessage("§4Mass§cPvP §4> §cYou got kit Warrior!");
                                    KeeperofThings.add(player.getName());
                                    player.getInventory().clear();
                                ItemStack Boots = dyeArmour(Material.LEATHER_BOOTS, 0, 0, 0);
                                ItemStack A = dyeArmour(Material.LEATHER_CHESTPLATE, 0, 0, 0);
                                ItemStack G = dyeArmour(Material.LEATHER_HELMET, 0, 0, 0);
                                ItemStack E = dyeArmour(Material.LEATHER_LEGGINGS, 0, 0, 0);
                                ItemStack GA = setMeta(new ItemStack(Material.WOOD_SWORD), "" + "", Arrays.asList(""));
                               
                                Boots.addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 1);
                                G.addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 1);
                                player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 100000000, 1));
                                GA.addEnchantment(Enchantment.DAMAGE_ALL, 1);
                                GA.addEnchantment(Enchantment.DAMAGE_UNDEAD, 2);
                               
                                player.getInventory().setBoots(Boots);
                                player.getInventory().setChestplate(A);
                                player.getInventory().setLeggings(E);
                                player.getInventory().setHelmet(G);
                                player.getInventory().addItem(GA);
                                }
                            }
                            if(commandLabel.equalsIgnoreCase("Killer")){
                                if(KeeperofThings.contains(player.getName())){
                                    player.sendMessage(ChatColor.DARK_RED + "There's only one kit per life!");
                                if(!(player.hasPermission("MassKits.Killer"))){
                                    player.sendMessage("§4You do not have permission to kit Killer!");
                                }
                                } else {
                                    player.sendMessage("§4Mass§cPvP §4> §cYou got kit Killer!");
                                    KeeperofThings.add(player.getName());
                                    player.getInventory().clear();
                                ItemStack newEoots = dyeArmour(Material.LEATHER_BOOTS, 0, 0, 0);
                                ItemStack newJ = dyeArmour(Material.LEATHER_CHESTPLATE, 0, 0, 0);
                                ItemStack newW = dyeArmour(Material.LEATHER_HELMET, 0, 0, 0);
                                ItemStack newL = dyeArmour(Material.LEATHER_LEGGINGS, 0, 0, 0);
                                ItemStack GN = setMeta(new ItemStack(Material.WOOD_SWORD), "" + "", Arrays.asList(""));
                               
                                newEoots.addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 1);
                                newW.addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 1);
                                newL.addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 1);
                                player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 100000000, 1));
                                GN.addEnchantment(Enchantment.DAMAGE_UNDEAD, 3);
                                GN.addEnchantment(Enchantment.DAMAGE_ALL, 1);
                               
                                player.getInventory().setBoots(newEoots);
                                player.getInventory().setChestplate(newJ);
                                player.getInventory().setLeggings(newL);
                                player.getInventory().setHelmet(newW);
                                player.getInventory().addItem(GN);
                                }
                                }
            return false;
        }
    }
    
     
  2. Offline

    nivek1212

    You have to register Events:
    Code:
    public class Main extends JavaPlugin implements Listener{
     
        public static ArrayList<String> KeeperofThings = new ArrayList<>();
     
        public ItemStack dyeArmour(Material material, int r, int g, int b){
            ItemStack armour = new ItemStack(material);
            LeatherArmorMeta lam = (LeatherArmorMeta) armour.getItemMeta();
         
            lam.setColor(Color.fromRGB(r, g, b));
            armour.setItemMeta(lam);
         
            return armour;
        }
    public void onEnable() {
    plugin.getServer().getPluginManager().registerEvents(this, this);
    }
     
        @EventHandler
        public void onPlayerDeath(PlayerDeathEvent e)
        {
     
  3. Offline

    winitro

    Plugin gives an error.
     
  4. Offline

    Monkey_Swag

    winitro
    extends JavaPlugin implements Listener{
    //all your code
    }

    That'll fix it
     
  5. Offline

    Assist

    Monkey_Swag
    That's exactly what he has.

    nivek1212 's answer was right. You need to register your events. As for the error, just remove the "plugin." in front of the line and it'll work.
     
  6. Offline

    winitro

    Thanks it works now Assist :) thanks for the help guys
     
Thread Status:
Not open for further replies.

Share This Page