A Custom Item.

Discussion in 'Plugin Requests' started by BlueBearPvP, Apr 1, 2016.

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


    Hey Guys,

    I really want to make a custom item. The item will be a bow that spawn lighting on a player if it hit a player over 20 blocks. The custom recipe for the item:

    " B "
    " D "

    A = Arrow
    T = TNT
    B = Bow
    D = Diamond

    I really want the plugin to support 1.8.

    - Thanks for your time, Blue
  2. Offline


    I'll make it!

    Edit: nvm vvvvv
    Last edited: Apr 3, 2016
  3. Offline


    Thanks @Meatiex! Tell me when you are done making it. If you can also post the codes in Pastebin that will be great. I would really love to learn from the code and probably get better at coding. Thanks for you time in making the plugin!
  4. Hi, I know that someone else has already started on the code but I decided I'd make it aswell as a mini project so I can improve! I would like to ask, would you like a command to go with this to disable and enable the crafting of this bow? Or would you like this in the config instead?
    Last edited: Apr 2, 2016
  5. Offline


    Hey @CreeperFace0777 ,

    It well be ok if you want to code the plugin too! I would love the command to go with it! It would also be appreciated if you could make a command like "/customitem give BlueBearPvP ThunderBower" or something like that and it will give the player with the right permission the Custom Item.

    Maybe also the source code too so that I can learn from it and expand my knowledge on coding, if you want.

    Thanks for your time!
  6. Offline


    Like CreeperFace0777 I'm doing this to improve. I've done what you've requested although have not quite figured out the 20+ blocks aspect (will continue working on it though!)

    Here is a compiled download link

    Tell me what you think!
    - Slayergold3
    Last edited: Apr 2, 2016
  7. Offline

    I Al Istannen

    Why do you use a hashMap there, if you only want to look up the value? A HashSet would be easier probably.
    "lBowArrows.clear()" has some nasty side effects. Imagine there are 2 players, "A" and "B". Both shoot an arrow. The map now has 2 entries. One arrow hits, BOTH entries will be cleared. The other arrow hits and no lightning will be summoned, as it doesn't contain the value.

    The enable and disable messages are unneeded, bukkit does that for you automatically.

    For the location you could use the entityId of the arrow as the key and the location the player shoot the arrow from as the value. Then just use the Location#distance[Squared] method to get the distance.

    Also why do you need the try block there? There shouldn't really be any exception thrown there. The only causes would be if the item has no ItemMeta or the Meta has no display name. Check for that with ItemStack#hasItemMeta() and ItemMeta#hasDisplayName(). Try and catch blocks should only be used when neccessary. They are slower than a normal check, but way more important obscure the cause of the exception. If the item should have a displayname, but it doesn't have one you should check for that. Imagine the item was somehow null. An exception would be thrown, but it would just be swallowed. It wouldn't work and you don't know why.

    I might have missed some things or not correctly stated some, so feel free to correct me.
  8. Offline



    I am loving the outcome of the plugin. It would be really cool when you can get the 20 blocks aspect to work!

    Here is a list of what I am looking for (Just got some more ideas):

    -20 Blocks Aspect on Bow
    -Message when you shot a player over 20 blocks. Ex: "[!] You had shot BlueBearPvP (20 blocks)"
    -Custom Message & Sound when you craft the item.
    -Custom damage on lightning when you shot a player over 20 blocks. Ex: Like 4 hearts on player, dont matter what armor they had.
    - A command that will give u the custom item if you have the right permission. Ex: /customitems give BlueBearPvP Thunder Bower

    I would not mine that everyone is working on the plugin. I would probably pick out the plugin that have all the aspects that I am looking for. Thanks to everyone for taking their time in making this plugin.
    Last edited: Apr 2, 2016
  9. Offline


    The hashmap was originally there for the 20+ blocks aspect. The EnityDamage event doesn't record who actually shot the arrow as the arrow is the damager.
    Good point on using clear() will fix.

    Thanks for that! Again doing this to improve so I will definitely look into these.
    Last edited: Apr 2, 2016
  10. Offline


    No, but you can always do arrow.getShooter. You should store the original position of the shooter on the arrow though, so they run towatds the other player, it won't get messed uo
  11. Offline


    Are you sure? I can call getShooter in the ProjectileLaunchEvent, but the EntityDamageByEntityEvent (which I assume is event.getDamager().getShooter()) but .getShooter results in an error. If I can call it in the EntityDamageByEntityEvent I think I could delete the ProjectileLaunchEvent entirely.
    Also is there any way I can get the key associated with a value and not the other way around? (hashmap.get(key) returns a value)

    Alright then I haven't worked with Bukkit for 2-3 years now, no need to bash me for asking a question... We all have to start somewhere.

    Quick question: what exactly is the message and sound you want playing on craft?
    Last edited by a moderator: Apr 2, 2016
  12. Offline



    It doesnt matter. Something maybe like "[!] You have crafted Lightning Bow! and maybe a firework sound
  13. Offline


    Alright I believe it's done!
    I've fixed a few things and tested it with another account I have so it should work smoothly.

    /customitem help
    /customitem <item name> [optional player]
    Alias: /ci​

    customitem.command - To use anything related to /customitem
    customitem.command.lightningbow - Give yourself the Lightning Bow
    customitem.command.giveother - Give someone else a custom item

    Download Link

    Hope you like it and tell me if you need anything changed!
    - Slayergold3
  14. Offline



    I love the plugin! Thank you so much for your time in making this plugin. I thought of a idea that you might be able to add to the plugin.

    Maybe after 20 shots, that are over 20 blocks, the next time you shoot your screen starts to shakes or something like that so that its hard to aim. And maybe a message saying "[!] Your Lightning Bow is running out of power!". That will be really cool and something that I have never seen before. To add on to that, maybe if you do land a arrow even tho your screen is shaking, it will spawn in 2 lightning on the player that you shot.

    This will be really cool if you could make it happen. If not, its fine. Thanks for your time!

    The plugin is awesome and really what I was looking for.
  15. Offline

    I Al Istannen



    you still don't need the enable and disable messages ;)

              Long rDist = Long.valueOf(Math.round(((Location)this.shooterLoc.get(a.getShooter().toString())).distance(e.getEntity().getLocation())));
    No need for Wrapper classes, long is fine. Even integer will be. I bet nobody shoots an arrow more than (2^31 - 1) blocks. Rounding is proably also unnecessary.

            if ((((Player)a.getShooter()).getItemInHand().getItemMeta().getDisplayName() != null) &&
              (((Player)a.getShooter()).getItemInHand().getItemMeta().getDisplayName().equals(ChatColor.AQUA + "Lightning Bow")))
    Maybe preference but the hasItemMeta() and hasDisplayName() methods are there, so you could use them.

              Long rDist = Long.valueOf(Math.round(((Location)this.shooterLoc.get(a.getShooter().toString())).distance(e.getEntity().getLocation())));
              if (((Location)this.shooterLoc.get(a.getShooter().toString())).distance(e.getEntity().getLocation()) >= 20.0D)
    Calculating the distance two times. Not needed. Just use the rDist variable.

        PacketPlayOutChat lBowDesc = new PacketPlayOutChat(IChatBaseComponent.ChatSerializer.a("{\"text\":\"    - \\\"LBow\\\" (Lightning Bow)\",\"color\":\"aqua\",\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Shoot a player that is 20+ blocks away \nto strike them with lightning!\"}]}}}"));
    Involves NMS, will only work on version "v1_8_R3" (as that is your import). Not really much you can do about except dynamically creating/choosing a special handler for every version. (You could also just remove that part as it has no real use except looking nice ;) Depends on your intentions.)

      HashMap<String, Integer> lBowArrows = new HashMap();
      HashMap<String, Location> shooterLoc = new HashMap();
    You only use the value of the firstMap. You could reduce that to one map with the entity Id of the arrow as the key and the Location it was shot from as the value. Saves one map and some fiddeling.

    There may be more things to improve, just pointed out what came to my mind. It is not meant offensive, just because you stated you were doing this to learn :)
  16. Offline


    @I Al Istannen
    Hey, thanks for the feedback! (Even though you decompiled it :p)
    1. Those completely slipped my mind while making the other features/fixing other things.
    2. Since its used in PvP I'd think it to be beneficial to be precise because it could mean all the difference while fighting. I only use the round method so that when a player receives the message that they hit somebody it comes up as 30 and not 30.215379...
    3. I saw that come up, but if someone had an anvil named bow or a bow from another plugin it would still trigger it so better safe than sorry.
    4. See 2
    5. Very good point, I forgot NMS does that every version.
    6. I'll leave it for now because it works, but I'll definitely change it for future plugins.
    No need to apologize I don't find it offensive at all (only the other guy was)! It's always great when I see what could have been done better.
    Glad you like the plugin!
    I'm a bit busier during the week so I might not have time to get it done too soon, but if I have the time I'll look into it.
    Last edited: Apr 3, 2016
    I Al Istannen likes this.
  17. Offline



    It's ok if you dont have time.

    Thanks for your time in working on the plugin. Thanks again!
  18. Offline

    I Al Istannen

    Hey, (I apologize, but it's Java :p)
    1. Well, know that feeling... . Leaving debug messages in the craziest places
    2. I didn't think far enough to realize you send the message with the distance ... Shame on me ;)
      What I meant with Wrapper is the following: In java there are some primitive types (as you probably know) int, long and char are some examples. Then there are some Wrappers for them, to be used with Collections or places where you need an actual Object. These start with an uppercase character and are fully written out (Integer, Character, Long). Java will automatically convert between them. Usage of the primitive type is often preferred, it is faster can't be null and you can do some other stuff.
      It can also lead to some nice errors:
      Integer five = new Integer(5);
      Integer five2 = new Integer(5);
      System.out.println(five == five2);    // output is false, as "==" does a comparison for the address in the memory.
      You are using a "Long" indicating a Wrapper, where I believe you don't need one.

      While I agree with the precision, I think shooting an arrow 2,147,483,647 blocks is a bit unrealistic. Would be cool though :p
    3. I just meant replacing the null check. You are totally right with the rest. Again, is not needed I just wanted to point out that some poor soul implemented them.
    4. Jup.
    Otherwise neat plugin, hope you will continue to have fun programming :) (Also a good attitude to have when programming, you will learn something new every day, no matter how experienced you are)!
  19. I guess as its already been done I wont make my version :)
Thread Status:
Not open for further replies.

Share This Page