Filled Soulbound

Discussion in 'Plugin Requests' started by chunkaymonkay, Jun 27, 2016.

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

    chunkaymonkay

    Type: Fun

    Name: soulbound

    What I want: I need a plugin that when a player kills a mob the mob drop will be his no one else can pick it up so lets say I kill a mob and it drops a steak that steak and someone else tries to pick it up he wont be able to only I can

    permissions: none

    commands: none
     
  2. Offline

    Destroyer7712

    I'll start this
     
  3. Offline

    chunkaymonkay

  4. Offline

    Destroyer7712

    Last edited: Jun 28, 2016
  5. Offline

    I Al Istannen

    @Destroyer7712
    Hey, I had a short look at your plugin and there are a few things you could improve:
    Code:
    log = Logger.getLogger("Minecraft");
    Don't steal minecrafts logger. In fact, I would delete the whole messenger class. You can just call getLogger() in the Main class (or an instance of it) and get a logger already with the right prefix.

    Code:
    Messenger.info("SoulboundItems enabled");
    Bukkit already logs this for you :)


    Code:
    private ArrayList<String> notifiedDelay;
    A HashSet would be better for this, as it offers constant lookup, add and remove time. Arraylist takes O(n), where n is the amounts of elements in it. If you have 1000 items in the collection, arraylist will loop through all for the contains method. HashSet will be much faster.


    Code:
    private ArrayList<String> notifiedDelay;
    Always code against an interface/abstract class, if you need no methods from the extending one. In this case, declaring it as a List<String> would work too (you need no methods from ArrayList), but makes it easier for you to later switch to a different list.
     
  6. Offline

    Destroyer7712

    @I Al Istannen
    This is actually really cool thanks. Where'd you figure out how the contains method works (for both)? I looked at the docs and couldn't find it.


    This is something I should've been doing already, thank you.

    Download <-- the updated file
     
    Last edited: Jun 29, 2016
  7. Offline

    I Al Istannen

    @Destroyer7712
    Javadocs for the general contract and knowledge about how they work internal for the remaining things.
    For HashSet:
    Constant time performance means nearly instantious (O(1)). The hash function of String will work correctly, which means it will reach the time stated there.

    For the ArrayList:
    The first bold ones run as fast as the HashSet contains,add,remove and size method. The add is normally constant too. It takes longer if the size of the intern Array is exceeded and it needs to create a new one.
    The contains method is one of "all the other operations", meaning linear time (O(n)). It iterates over the intern array, which is not mentioned there, but I am quite sure it is right ;)
     
  8. Offline

    Destroyer7712

    I was looking under the methods specifically, thanks ;D
     
  9. Offline

    I Al Istannen

    @Destroyer7712
    No problem :)

    Have a nice day using the most fitting collection the next time (although there are some more, quite useful ones. Just look at the subclasses and subinterfaces of the Collection interface :)) :p
     
    Destroyer7712 likes this.
Thread Status:
Not open for further replies.

Share This Page