Solved How Do I give effects

Discussion in 'Plugin Development' started by MineMeetsRoblox, Aug 26, 2015.

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

    MineMeetsRoblox

    Ok so I am creating an SG server and I am trying to make a plugin that gives players effect if that have a certain item they are holding.
    So if the lore of golden boots are set to "With God Speed You are off" How would i make the plugin look for that and set the speed? I am kinda new to this sooo.....
     
  2. Offline

    au2001

    @MineMeetsRoblox Check for pickup, drop and item held events.
    Get the player's item in hand.
    Check for item meta and lore.
    Get the lore, if it contains your string, use:
    LivingEntity#addPotionEffect(PotionEffect#PotionEffect(PotionEffectType, int, int, boolean), boolean);
     
  3. Offline

    MineMeetsRoblox

    I know that. I am trying to figure out how to check for them wearing it. Not holding it.
     
  4. Offline

    au2001

    @MineMeetsRoblox On InventoryClick, check for:
    PlayerInventory#getHelmet()
    PlayerInventory#getChestplate()
    PlayerInventory#getLeggings()
    PlayerInventory#getBoots()

    You should also check for when the armor breaks, just in case.
     
  5. Offline

    MineMeetsRoblox

    Thx Will use! how do i check for armour break and lore.... I AM REALY NEW AT THIS!!
     
  6. Offline

    au2001

    @MineMeetsRoblox For lore:
    ItemStack#hasItemMeta() and ItemStack#getItemMeta()
    Then ItemMeta#hasLore() and ItemMeta#getLore()

    For armor break: PlayerItemBreakEvent
     
  7. Offline

    MineMeetsRoblox

    @au2001 you sir, are amazing!

    So im guessing the code would be like

    Code:
              
              public void speedBoots(PlayerInventoryClick event){
              if(ItemStack#hasItemMeta()){
              if(ItemStack#getItemMeta("May God Speed go With You!"){
              LivingEntity#addPotionEffect(PotionEffect#PotionEffect(Speed, 2, MAX_VALUE, boolean), boolean);
       }}
    }
    If not them im totaly lost in this java understanding i thought I had
     
  8. Offline

    au2001

    @MineMeetsRoblox Well, we use Class#method() to indicate that there is a class named "Class" that has a method "method"

    In your code, you must always put dots (e.g. "Class.method()").
    And "Class#Class()" means it's a constructor. Use constructors like this: "new Class()"

    "event.getCurrentItem()" returns the item you need to check. Save to an ItemStack variable (let's call it "item")
    Then, do item.hasItemMeta() to know if the item supports meta (it's basically a null check for the meta)
    Create a new ItemMeta variable (we'll simply call it "meta"), where you store item.getItemMeta()

    In this meta, you can get the lore with meta.getLore(), but don't forget to null check with meta.hasLore().
    This lore returns a List<String>, each string representing a line.
    Use lore.contains("something here") to check whether the list contains the string or not.
    If it does, use event.getWhoClicked() to get the HumanEntity (it's basically a player) that clicked the item.
    Save it to a Player variable named player or anything.
    Then do, for exemple:
    Code:
    player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, Integer.MAX_VALUE, false), true);
    This would add a potion to the player of Speed, that will never expire, without particles and it will "force" it to be equipped.
    So if the player has an incompatible potion, it will remove it (or if he has speed for 3 seconds, it will override it).

    I hope that's clear and you can understand it ;)
     
  9. Offline

    MineMeetsRoblox

    @au2001 thanks. the code that i worked with while tring to figure it out was:
    Code:
        @EventHandler
        public void SpeedBoots(PlayerInventoryEvent event) {
            Player p = event.getEntity();
                for (ItemStack item : p.getInventory()) {
                    if (item.getType() == Material.GOLD_BOOTS && item.hasItemMeta()) {
                        ItemMeta meta = item.getItemMeta();
                        if (meta.hasLore() && meta.hasDisplayName()  && meta.getLore().equals("May God Speed Be With You")) {
                           
                            p.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 2000, 2));
                           
                        }
                    }
                }
    
           
        }
       
        @EventHandler
        public void onDeath(PlayerItemBreakEvent event) {
            Player p = event.getEntity();
                for (ItemStack item : p.getInventory()) {
                    if (item.getType() == Material.GOLD_BOOTS && item.hasItemMeta()) {
                        ItemMeta meta = item.getItemMeta();
                        if (meta.hasLore() && meta.hasDisplayName()  && meta.getLore().equals(ChatColor.BOLD + "May God Speed Be With You")) {
                           
                            p.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 0, 0));
                           
                        }
                    }
                }
    
           
        }
    
    
    
    IDK it it works....
     
  10. Offline

    au2001

    @MineMeetsRoblox
    Code:
    meta.getLore().equals("May God Speed Be With You")
     
  11. Offline

    MineMeetsRoblox

    @au2001 Thx so much for all the help!
     
  12. Offline

    au2001

Thread Status:
Not open for further replies.

Share This Page