Creaiting a CRATE plugin?

Discussion in 'Plugin Development' started by mateo226, Sep 6, 2015.

Thread Status:
Not open for further replies.
  1. Hello everyone!
    I started creating a crate plugin for my server. It is almost the same as the plugin on Desteria or CosmicPvP.

    I already implemented opening a crate and choosing slots, but not the rewards.
    I decided to scrap that plugin because of the way I programmed it.
    The code was messy and hard to use. Now I have started rewriting it but I need a way to somehow have different types of crates using different rewards. I am not sure how to do this since I am using a HashMap<Player, Inventory>. That way everyone can open a different crate. If I didn't have that line, everyone would open the SAME inventory. I think what I am trying to do might be done using classes and inheritance, but I am just not sure how to do it.

    I need a way to open different kind of crates with different loot???
    I'm kind of stuck, any help would be appreciated!
    Thank you in advance!
     
  2. Offline

    stormneo7

    Create a class for each create (or use an abstract/interface Base Crate class if you want to be organized).
    In each extending class, have a variable defining the type of chest it is.
    You haven't mentioned how you plan on organizing it so some suggestions on organization methods are by Permissions, Name, Rank, Achievements, and Awards.

    Instead of having your Value as a Inventory, make it a BaseCrate. Inside BaseCreate, I suggest that you add a .getInventory() method to retrieve the inventory.
     
  3. @stormneo7
    Code:
    package me.mateo226.crates;
    
    import org.bukkit.Bukkit;
    import org.bukkit.inventory.Inventory;
    
    public class BaseCrate {
       
        public String type = "none";
       
        public BaseCrate() {
           
        }
       
       
        public static Inventory getInventory() {
            return Bukkit.createInventory(null, 36, "Base Supply Crate");
        }
       
    }
    
    And the second class doesn't really have any code except
    Code:
    public class CommonCrate extends BaseCrate{
    Am I missing anything?
    I also changed the HashMap from:
    Code:
        public static HashMap<Player, Inventory> invs = new HashMap<Player,Inventory>();
    To:
    Code:
        public static HashMap<Player, BaseCrate> invs = new HashMap<Player,BaseCrate>();
    ALright I am back online, quickly bumping this thread :D

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 11, 2016
Thread Status:
Not open for further replies.

Share This Page