Structure for my hats plugin + other question.

Discussion in 'Spigot Plugin Development' started by avighnash, Jun 28, 2016.

  1. Hello everyone! I want to make a hats plugin for my server, and I was asking myself, "how should I structure this hat plugin?". So how should I structure a new hat plugin? What are your opinions on certain ideas?

    Next question, simply what is the maven dependency for LibsDisguises for 1.8.8? Lol, when i tried the version 8.6.7, it is still colored dark red in the pom.xml. Thanks!
  2. Choco


    What type of hat plugin? /hat putting the held block on your head?
    • Agree Agree x 1
  3. Your description is not clear.. What do you mean by structure?
    • Funny Funny x 1
  4. I mean, there will be a GUI which players can unlock hat by buying it with coins, and then, if the hat is unlocked, they can click on it and the hat would be placed in their helmet slot. The cannot take off the hat, the only way is to click a specific item in the GUI which will turn their hat to air.
  5. Choco


    If there are specific hats, I'd say perhaps make an abstract Hat class, and make classes for every hat you want to add extending said abstract class. Add instances of them to some sort of registry list, then that way you can keep track of a custom player class as well containing a Hat object (Or a Map<Player, Hat>). That will be the current hat they're wearing (if any). There are many ways you can structure it, but there's no "better" way. That's the way I would do it.
  6. Oh ok, well you could get the item the player clicks on and set it has its head.. That part's easy. :)
  7. I like this idea! I was thinking though, of creating an enum for each hat type, but, I like your idea a lot.
    • Friendly Friendly x 1
  8. Choco


    The abstract class allows for flexibility with an API. All people would have to do is create a class that extends your abstract Hat class, create its methods, etc. and register it in the onEnable(), boom, custom hats for all :D Always program with the idea in mind that other developers are going to use your code as an API
  9. But, what should I keep in the hat (abstract) class?

    EDIT: I made a hat registry command, that would add new hat classes to a list.
  10. Choco


    An abstract String-return getPermission() method (Returns the required permission node to get the hat), and an abstract ItemStack-return getHatItem() method or something.

    Code (Java):
    public abstract class Hat{
        public abstract ItemStack getHatItem();

        public abstract String getRequiredPermission();
    Something like that I guess. You could always add more to that as well. Maybe an abstract String-return getName() method. I DUNNO :D It's up to you
  11. so that's why people keep spamming public static!
  12. Choco


    Noooo, there's a difference between "static" and programming with the idea of people using your code as an API. "static" does not mean API ;)
    EDIT: I totally overlooked your sarcasm. Lol
  13. it was a joke ;)
    • Like Like x 1
  14. So.. any answers for the other question? XD

    And any other methods that I should add to the hat class?
  15. Choco


    If you want, you can just have a regular no-bodied method such as getEffect() or something if you want the hat to do something special when it's on your head. It's really up to you.
    As for the second question, I wouldn't have a clue. Lol. I don't use Maven often