Continuously checking player?

Discussion in 'Plugin Development' started by BuuR, Jul 5, 2015.

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

    BuuR

    I want the bottom part to be continuously checking the player. how would i go about doing that?

    Code:
    package me.buur.main;
    import static org.bukkit.ChatColor.*;
    import org.bukkit.Material;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.potion.*;
    import org.bukkit.command.*;
    import org.bukkit.command.Command;
    import org.bukkit.enchantments.Enchantment;
    import org.bukkit.inventory.*;
    import org.bukkit.inventory.meta.ItemMeta;
    import org.bukkit.entity.*;
    public class rpgpluginmain extends JavaPlugin {
        public void onEnable() {
        }
        public void onDisable() {
        }
     
     
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
         
            Player p = (Player) sender;
         
            if (label.equalsIgnoreCase("class")) {
                if (args.length == 0) {
                    p.sendMessage(RED + "No arguments. Try /class ?");
                }
             
                //CHARACTER CLASSES
             
                //WARRIOR
                if (args[0].equalsIgnoreCase("Choose")) {
                    if (args[1].equalsIgnoreCase("warrior")) {
                        Inventory inv = p.getInventory();
                        ItemStack warriorWeap = new ItemStack(Material.IRON_SWORD);
                        warriorWeap.addEnchantment(Enchantment.KNOCKBACK, 0);
                        ItemMeta warriorWeapMeta = warriorWeap.getItemMeta();
                        warriorWeapMeta.setDisplayName("Long Sword");
                        warriorWeap.setItemMeta(warriorWeapMeta);
                        ItemStack warriorHelm = new ItemStack(Material.IRON_HELMET);
                        ItemStack warriorChest = new ItemStack(Material.IRON_CHESTPLATE);
                        ItemStack warriorLegs = new ItemStack(Material.IRON_LEGGINGS);
                        ItemStack warriorFeet = new ItemStack(Material.IRON_BOOTS);
                        inv.addItem(warriorWeap);
                        inv.addItem(warriorHelm);
                        inv.addItem(warriorChest);
                        inv.addItem(warriorLegs);
                        inv.addItem(warriorFeet);
                        p.sendMessage(GREEN + "Fight hard, brave one!");
                    }
                 
                    //ARCHER
                 
                    if (args[1].equalsIgnoreCase("archer")) {
                        Inventory inv = p.getInventory();
                        ItemStack archerWeap = new ItemStack(Material.BOW);
                        ItemStack archerAmmo = new ItemStack(Material.ARROW, 128);
                        archerWeap.addEnchantment(Enchantment.ARROW_DAMAGE, 0);
                        ItemStack archerHelm = new ItemStack(Material.LEATHER_HELMET);
                        ItemStack archerChest = new ItemStack(Material.LEATHER_CHESTPLATE);
                        ItemStack archerLegs = new ItemStack(Material.LEATHER_LEGGINGS);
                        ItemStack archerFeet = new ItemStack(Material.LEATHER_BOOTS);
                        inv.addItem(archerWeap);
                        inv.addItem(archerAmmo);
                        inv.addItem(archerHelm);
                        inv.addItem(archerChest);
                        inv.addItem(archerLegs);
                        inv.addItem(archerFeet);
                        p.sendMessage(GREEN + "Fight hard, brave one!");
                    }
                 
                    //ROGUE
                 
                    if (args[0].equalsIgnoreCase("Choose")) {
                        if (args[1].equalsIgnoreCase("rogue")) {
                            Inventory inv = p.getInventory();
                            ItemStack rogueWeap = new ItemStack(Material.GOLD_SWORD);
                            rogueWeap.addEnchantment(Enchantment.DAMAGE_ALL, 0);
                            inv.addItem(rogueWeap);
                            p.sendMessage(GREEN + "Fight hard, brave one!");
                        }
         
                    }
                }
                if (args[0].equalsIgnoreCase("?")) {
                    p.sendMessage("Use /class choose [class name]");
                }
                if (args[0].equalsIgnoreCase("list")) {
                    p.sendMessage("List of classes: Warrior, Rogue, Archer.");
                }
             
             
            }
         
            if (p.getInventory().getItemInHand().getType() == Material.GOLD_SWORD){
                p.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 999999, 0));
             
            }else if (p.getInventory().getItemInHand().getType() == Material.IRON_SWORD) {
                p.addPotionEffect(new PotionEffect(PotionEffectType.ABSORPTION, 999999, 0));
             
            }
         
            return true;
        }
     
    }
    here is the part i want to have the player being checked for:

    Code:
            if (p.getInventory().getItemInHand().getType() == Material.GOLD_SWORD){
                p.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 999999, 0));
            
            }else if (p.getInventory().getItemInHand().getType() == Material.IRON_SWORD) {
                p.addPotionEffect(new PotionEffect(PotionEffectType.ABSORPTION, 999999, 0));
            
            }
     
  2. Offline

    WesJD

    If you want it continuously, use a runnable.
     
  3. Offline

    BuuR

    how would i do that? can you provide an example, please?
     
  4. Offline

    teej107

    @BuuR
    That is nowhere near as efficient as checking in the PlayerItemHeldEvent.
     
  5. Offline

    WesJD

    @teej107 He asked for continuously, I gave him continuously.
     
Thread Status:
Not open for further replies.

Share This Page