Linking effects with an items given name.

Discussion in 'Plugin Development' started by tommyhoogstra, Sep 13, 2013.

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

    tommyhoogstra

    PeterK

    I'm back!
    Using the legendaryWeapon plugin, i gave items, such as boots the ability to jump higher with the enchantment jump 5. The enchantment was from the enchantmentAPI plugin and the enchantmentPACK addon.

    So it seems, whenever my plugin is activated and a event is ran, e.g. closing inventory it will stop the jump effect from working. Because the effect on the boots actually gives players the enchantment.

    This is definitely a conflict, and a tricky one.

    Conclusion, because the item gives jump 5, or something like that, once the player closes their inventory, or equips via right click causing his the itemheld event to activate, and because the user doesn't have a full GOD set equipped, the plugin goes through the else statements, and removes the enchantments from the user.
    I don't see how that is in effect as the user must have the weapon selected to run the if statement.
     
  2. It will always remove the effects connected to a set of armor if the player is not holding the item and wearing the armor. What you can do to avoid this are else if statements. However, this will still conflict with potion effects gained from actual in-game potions, but so does the current implementation
    Code:
    if( player wears set a)
    {
    //apply effects a
    }
    else if( player wears set b)
    {
    //apply effects b
    }
    else
    {
    //remove all effects.
    }
    
     
  3. Offline

    tommyhoogstra

    PeterK what if the player isnt wearing a set at all, the effects are still taken off and the IF statements are still ran regardless of the player having weapon in hand.
     
  4. simply use that system, I forgot to say that the if-statements would of course need to check if the player held the item
     
  5. Offline

    tommyhoogstra

    PeterK
    Tried it, still removes the jump effect from players if they arent wearing the set at all.

    Heres the code: http://pastebin.com/sanU4M1p
    Its pretty hard to explain the issue, if you want, jump on my server later and ill help explain it via items, etc.
    ip: mc.kozancraft.com
     
  6. Oh, are the boots themselves meant to give an effect, even without the full armor?
    In that case, edit the else statement to something like this:
    Code:
    else{
    if( /* player doesn't wear boots */ ) remove Effect...;
    if( /* player doesn't wear another special item */ ) remove Effect...;
    // remove effects not bound to a specific item.
    
     
  7. Offline

    tommyhoogstra

    Will try it now, thanks!

    Edit: Added this into the else statement, didn't fix the issue.
    The bonuses themselves are given from the item, they aren't given via this plugin, ideally I could solve this by using a seperate else for each set so it won't remove the jump effect from the boots.
    Thats a last resort though.
    Edit: Because the current else removes all effects if no set is equipped, its going to do this everytime the event is ran, so perhaps an if statement for.
    Yeah, im stuck here, tried a few things but theoretically it wouldn't work.
    Edit: Another solution, how would I go about making it so e.g. .DOESNTequalignorecase("Moonlanders")
    Code:
        if(getCustomName(playerArmor[0]) != null &&
            getCustomName(playerArmor[0]).equalsIgnoreCase("Moonlanders") )
     
        {
                //Does nothing, should keep the effects the boots give.
        }
    Another Edit: OMG IM AWESOME :)
    Code:
    if(getCustomName(playerArmor[0]) != null &&
    getCustomName(playerArmor[0]).equalsIgnoreCase("Moonlanders") || getCustomName(playerArmor[0]).equalsIgnoreCase("Mazurels Light Plated Boots") ){
    }else{
    p.removePotionEffect(PotionEffectType.JUMP);
     
    }
    
    this magic work :)
     
  8. Yea, that's what i meant ;P Was in a hurry when I posted earlier
     
  9. Offline

    tommyhoogstra

    PeterK
    Code:
    17.09 01:02:03 [Server] INFO at net.minecraft.server.v1_6_R2.ThreadServerApplication.run(SourceFile:582)
    17.09 01:02:03 [Server] INFO at net.minecraft.server.v1_6_R2.MinecraftServer.run(MinecraftServer.java:419)
    17.09 01:02:03 [Server] INFO at net.minecraft.server.v1_6_R2.MinecraftServer.s(MinecraftServer.java:486)
    17.09 01:02:03 [Server] INFO at net.minecraft.server.v1_6_R2.DedicatedServer.t(DedicatedServer.java:226)
    17.09 01:02:03 [Server] INFO at net.minecraft.server.v1_6_R2.MinecraftServer.t(MinecraftServer.java:522)
    17.09 01:02:03 [Server] INFO at org.bukkit.craftbukkit.v1_6_R2.scheduler.CraftScheduler.mainThreadHeartbeat(CraftScheduler.java:345)
    17.09 01:02:03 [Server] INFO at org.bukkit.craftbukkit.v1_6_R2.scheduler.CraftTask.run(CraftTask.java:53)
    17.09 01:02:03 [Server] INFO at me.Hoogstra.Bukkit.Kozancraft$3.run(Kozancraft.java:172)
    17.09 01:02:03 [Server] INFO at me.Hoogstra.Bukkit.Kozancraft.checkKit(Kozancraft.java:118)
    17.09 01:02:03 [Server] INFO java.lang.NullPointerException
    17.09 01:02:03 [Server] WARNING Task #917 for Kozancraft v1 generated an exception
    
    Any ideas?
     
  10. Offline

    CeramicTitan

    tommyhoogstra PeterK I think both of you are really over complicating things.

    Would not just create a method that does all the null checks and stuff for you. This is what I would use:
    Code:java
    1. public boolean checkSet(Player p, String helmname, String chestname, String pantname, String bootname){
    2. EntityEquipment equiptment = p.getEquipment();
    3. if(equiptment.getHelmet() != null
    4. && equiptment.getChestplate() != null
    5. && equiptment.getLeggings() !=null
    6. && equiptment.getBoots() !=null){
    7. if(getCustomName(equiptment.getHelmet()).equalsIgnoreCase(helmname)
    8. && getCustomName(equiptment.getChestplate()).equalsIgnoreCase(chestname)
    9. && getCustomName(equiptment.getLeggings()).equalsIgnoreCase(pantname)
    10. && getCustomName(equiptment.getBoots()).equalsIgnoreCase(bootname)){
    11. return true;
    12. }
    13.  
    14. }
    15.  
    16. return false;
    17.  
    18. }
    19. public static String getCustomName(ItemStack i)
    20. {
    21. if( i == null ) return null;
    22. if( i.hasItemMeta() && i.getItemMeta().hasDisplayName() ) {
    23. return ChatColor.stripColor(i.getItemMeta().getDisplayName());
    24. }
    25. return null;
    26. }


    then you could do something like:

    Code:java
    1. if(checkSet(...)){
    2. //Apply potioneffect
    3. }
     
  11. Offline

    tommyhoogstra

    I don't see how that i'm proves what we have already done, in fact looks more confusing, why bother with 2 if statements when you can just have one? But thanks anyway
     
  12. Offline

    CeramicTitan

    1) This stops you from getting Array Index Out Of Bounds Exceptions.
    2) It's a method which stops you from copying and pasting code.
    3) It's versatile.
    4) It's effective and efficient
    5) I've already made a plugin like this

    Why would you want one if statement, that would make it an absolute nightmare to debug
     
  13. Offline

    tommyhoogstra

    For such a small program I don't see how effectiveness and efficiency are going to take part, if there were a different it would be so minuscule that nobody would care regardless.

    There is going to be copy and pasting anyway as there are 3 different sets, and each set requires a different WEAPON in hand.
     
  14. Offline

    CeramicTitan

    This is were the versatility factor comes in, You can edit the method to accommodate the WEAPON in hand
     
  15. I kind of agree with CeramicTitan, having one method to do all the checks kind of makes sense due to the amount of copying and pasting required for future additions, etc. :)
     
  16. Offline

    CeramicTitan

  17. Offline

    tommyhoogstra

    CeramicTitan
    PeterK

    So you believe your solution will fix the error spam in my console?
    Code:
    2013-09-18 23:30:29 [WARNING] [Kozancraft] Task #79467 for Kozancraft v1 generated an exception
    java.lang.NullPointerException
    at me.Hoogstra.Bukkit.Kozancraft.checkKit(Kozancraft.java:118)
    at me.Hoogstra.Bukkit.Kozancraft$1.run(Kozancraft.java:134)
    at org.bukkit.craftbukkit.v1_6_R2.scheduler.CraftTask.run(CraftTask.java:53)
    at org.bukkit.craftbukkit.v1_6_R2.scheduler.CraftScheduler.mainThreadHeartbeat(CraftScheduler.java:345)
    at net.minecraft.server.v1_6_R2.MinecraftServer.t(MinecraftServer.java:522)
    at net.minecraft.server.v1_6_R2.DedicatedServer.t(DedicatedServer.java:226)
    at net.minecraft.server.v1_6_R2.MinecraftServer.s(MinecraftServer.java:486)
    at net.minecraft.server.v1_6_R2.MinecraftServer.run(MinecraftServer.java:419)
    at net.minecraft.server.v1_6_R2.ThreadServerApplication.run(SourceFile:582)
    
     
  18. Offline

    CeramicTitan

    No, I believe my solution is better than the solution you are currently using. If you paste the code, i an fix your problem
     
  19. Offline

    tommyhoogstra

    What I don't understand with your solution is setting it up with multiple sets with just that one paste,
    Because the weapon has to match the set, where would i customize that.
     
  20. Offline

    CeramicTitan

    Add this to the method(String weaponname)

    Add this on the first if statement: p.getItemInHand() != null && ...
    This on the second if statement: getCustomName(p.getItemInHand()).equalsIgnorCase(weaponname)

    It should look like something like this:
    Code:java
    1. public boolean checkSet(Player p, String weaponname, String helmname, String chestname, String pantname, String bootname){
    2. EntityEquipment equiptment = p.getEquipment();
    3. if(p.getItemInHand() != null
    4. && equiptment.getHelmet() != null
    5. && equiptment.getChestplate() != null
    6. && equiptment.getLeggings() !=null
    7. && equiptment.getBoots() !=null){
    8. if(getCustomName(p.getItemInHand()).equalsIgnorCase(weaponname)
    9. && getCustomName(equiptment.getHelmet()).equalsIgnoreCase(helmname)
    10. && getCustomName(equiptment.getChestplate()).equalsIgnoreCase(chestname)
    11. && getCustomName(equiptment.getLeggings()).equalsIgnoreCase(pantname)
    12. && getCustomName(equiptment.getBoots()).equalsIgnoreCase(bootname)){
    13. return true;
    14. }
    15.  
    16. }
    17.  
    18. return false;
    19.  
    20. }
    21. public static String getCustomName(ItemStack i)
    22. {
    23. if( i == null ) return null;
    24. if( i.hasItemMeta() && i.getItemMeta().hasDisplayName() ) {
    25. return ChatColor.stripColor(i.getItemMeta().getDisplayName());
    26. }
    27. return null;
    28. }


    To check multiple sets:

    Code:java
    1. if(checkSet(...parameters)){//if this returns true, player is wearing the set
    2. //so add the potion effect
    3. }
    4. if(checkSet(...parameters for next set)){ ""
    5. // so add the potion effects
    6. }


    Use this check for every set you have, you can use it as many times as you want, in your code.
     
  21. Offline

    tommyhoogstra

  22. Offline

    CeramicTitan

    hover over it, what does it say?
     
  23. Offline

    tommyhoogstra


    [​IMG]
    There ye go.
    Something must not be right with:
    Code:
    public static String getCustomName(ItemStack i)
    {
    if( i == null ) return null;
    if( i.hasItemMeta() && i.getItemMeta().hasDisplayName() ) {
    return ChatColor.stripColor(i.getItemMeta().getDisplayName());
    }
    return null;
    }
    
     
  24. Offline

    CeramicTitan

    you can get rid of that whole method, it shouldn't make a difference to your overall code
     
  25. Offline

    tommyhoogstra

    So how would I go about running this under events?
    From the previous
    Code:
    @EventHandler
        public void onItemPickup(final PlayerPickupItemEvent event){
    Bukkit.getScheduler().scheduleSyncDelayedTask(
       this,
       new Runnable()
       {
           public void run() {
               checkKit(event.getPlayer());
           }
       },
       5);
    }
    
     
  26. Offline

    CeramicTitan

    checkKit(event.getPlayer(), weaponame, helmname, chestname, pantname, bootname); <-- Replace these variables with the actual names of the items
     
Thread Status:
Not open for further replies.

Share This Page