Help making a Special Ability Kit.

Discussion in 'Plugin Development' started by Beasty, Apr 11, 2014.

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

    Beasty

    So, I am making a KitPvP plugin for my Server and this is what I got

    I am trying to make it so ONLY the Kobra Kit can get the Special Abilities with KobraListener. If someone could help that would be appreciated!

    MAIN CLASS:
    Code:
    package co.vbnk.src;
     
    import java.util.ArrayList;
    import java.util.List;
     
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.entity.PlayerDeathEvent;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class Main extends JavaPlugin implements Listener{
     
        public List<String> used = new ArrayList<String>();
     
        public void onEnable() {
            registerCommands();
            registerListeners();
            getServer().getPluginManager().registerEvents(this, this);
        }
     
        public void registerCommands() {
            getCommand("pvp").setExecutor(new PvPKit(this));
            getCommand("archer").setExecutor(new ArcherKit(this));
            getCommand("kobra").setExecutor(new KobraKit(this));
        }
     
        public void registerListeners(){
            getServer().getPluginManager().registerEvents(new KobraListener(this), this);
        }
     
        @EventHandler
        public void onDeathRemoveKit(PlayerDeathEvent e) {
            Player p = (Player)e.getEntity();
            if(used.contains(p.getName())) {
                used.remove(p.getName());
            }
        }
     
    }
    
    KobraKit CLASS:
    Code:
    package co.vbnk.src;
     
    import java.util.Random;
     
    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.enchantments.Enchantment;
    import org.bukkit.entity.LivingEntity;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.entity.EntityDamageByEntityEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.PlayerInventory;
    import org.bukkit.potion.PotionEffect;
    import org.bukkit.potion.PotionEffectType;
     
    public class KobraKit implements CommandExecutor {
     
        private Main plugin;
        private KobraListener Listener;
        public KobraKit(Main plugin) {
            this.plugin = plugin;
        }
     
     
        public boolean onCommand(CommandSender sender, Command cmd, String label,String[] args) {
            if(!(sender instanceof Player)) {
                sender.sendMessage(ChatColor.RED + "Hey Console, Why you do this - <3 CodeBeasty!");
                return true;
            }
            Player p = (Player)sender;
            if(plugin.used.contains(p.getName())) {
                p.sendMessage(ChatColor.GOLD + "[VibrantKits] " + ChatColor.DARK_AQUA + "You already have used a kit this life!");
                return true;
            }
            plugin.used.add(p.getName());
            p.sendMessage(ChatColor.GOLD + "[VibrantKits] " + ChatColor.DARK_AQUA + "You have recieved the " + ChatColor.RED + "[Kobra]" + ChatColor.DARK_AQUA + " kit!");
            PlayerInventory inv = p.getInventory();
            Utils.clearInv(p);
            ItemStack pvp = new ItemStack(Material.IRON_SWORD);
            if(p.getItemInHand().getType().equals(Material.IRON_SWORD))
                p.addPotionEffect(new PotionEffect(PotionEffectType.POISON, 5, 2));
            inv.addItem(pvp);
            ItemStack helmet = new ItemStack(Material.CHAINMAIL_HELMET, 1);
            helmet.addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 1);
            p.getEquipment().setHelmet(helmet);
            ItemStack chestplate = new ItemStack(Material.CHAINMAIL_CHESTPLATE, 1);
            chestplate.addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 1);
            p.getEquipment().setChestplate(chestplate);
            ItemStack leggings = new ItemStack(Material.CHAINMAIL_LEGGINGS, 1);
            leggings.addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 1);
            p.getEquipment().setLeggings(leggings);
            ItemStack boots = new ItemStack(Material.CHAINMAIL_BOOTS, 1);
            boots.addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 1);
            p.getEquipment().setBoots(boots);
            inv.addItem(new ItemStack(Material.ARROW));
            Utils.giveSoup(p);
       
            return false;
       
        }
     
     
    }
    
    KobraListener CLASS:
    Code:
    package co.vbnk.src;
     
    import java.util.Random;
     
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.entity.EntityDamageByEntityEvent;
    import org.bukkit.potion.PotionEffect;
    import org.bukkit.potion.PotionEffectType;
     
    public class KobraListener implements Listener {
     
        private Main plugin;
        public KobraListener(Main plugin) {
            this.plugin = plugin;
        }
     
        @EventHandler
        public void viperListener(EntityDamageByEntityEvent e) {
            if(e.getEntity() instanceof Player && e.getDamager() instanceof Player) {
                Player victim = (Player)e.getEntity();
                Player damager = (Player)e.getDamager();
                    Random r = new Random();
                    int percentage = r.nextInt(100) + 1;
                    if(percentage <= 20) {
                        victim.addPotionEffect(new PotionEffect(PotionEffectType.POISON, 100, 0));
                    }
               
                }
            }
        }
    
    I am trying to make it so ONLY the Kobra Kit can get the Special Abilities with KobraListener. If someone could help that would be appreciated!

    Bump

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  2. Offline

    Xyplo

    You can't bump your post this fast. Just be patient. I could help you with this, but I'm too busy coding my KitPvP plugin. Sorry. I hope someone else helps you out.
     
  3. Offline

    mazentheamazin

    Beasty
    You can only bump every 24 hours
     
  4. Offline

    Beasty

    Sorry about that, I didn't know, Is that I have a Time limit for the Plugin atm and I need to get this fix to give it to the person who requested it.
     
  5. Offline

    Ultimate_n00b

    I'm sorry, but please don't PM me to check out your threads. Just wait for someone to respond.
     
  6. Offline

    Xyplo

    A lot of people do, I'm waiting so should you. I'm sure the person will understand.
     
  7. Offline

    Beasty

    Sorry about that, I didn't know, Is that I have a Time limit for the Plugin atm and I need to get this fix to give it to the person who requested it.

    I just started using the forums. Sorry
     
  8. Offline

    mazentheamazin

    Beasty
    'Having a time limit' does not give you the permission to go around, breaking the rules, and stepping on top of everybody.
     
  9. Offline

    Beasty

    Ok, I understand, Can we please get over this, I just need to solve this.
     
  10. Offline

    leet4044

    Add the player to a List when they select the kit, and then on the listener check if they are in that list.
     
  11. Offline

    Beasty

    Can you define a bit more please?
     
  12. Offline

    Fhbgsdhkfbl

    What you want to do is add the player to the kit in the Class
    so
    plugin.Kobra.add(p.getName()) {
    Under the plugin.Used


    And in the listener put
    if(Kobra.contains(e.getPlayer().getName())){
    Right before the victim is called.

    If there is any confusion on this, (Im really bad at explaining things), just message me on here
     
  13. Offline

    Beasty

    It works, But I am having a Issue, It applys it to all the other kits?
     
  14. Offline

    Fhbgsdhkfbl

    Erm, I have no idea. It shouldn't be doing that.
    Do you have skype or something I we can talk on?
     
  15. Offline

    Beasty

    Yes, I have skype, It is ez1337cb1337ez
     
Thread Status:
Not open for further replies.

Share This Page