ExoticUtils 0.4

A one stop shop API

  1. kingmo100
    Native Minecraft Version:
    Legacy (< 1.13)
    Tested Minecraft Versions:
    • 1.8
    Source Code:
    https://github.com/redbostan567/ExoticUtils
    This is a one stop shop API supporting things from custom blocks to commands. I will describe everything you can do, currently. I will also be updating this page as I upload more content.

    This is a simple Item building tool, which makes the process completely robust and fast.

    To use first create the ItemBuilder object

    Code (Java):
    ItemBuilder builder = new ItemBuilder(String name, Material material, List<String> lore);
    ***note*** ItemBuilder also will take items directly from configs in this configuration

    Code (YAML):
    Path:
        mat
    : MATERIAL
        lore
    : []
        name
    : NAME
        glow
    : true|false
    You now are free to add pretty much anything to the item that could ever be used.

    To get the Item back just use ItemBuilder#getItem();

    This has the ability to give rewards to players from config files quickly and easily.

    To set up first make a rewardManager object

    Code (Java):
    RewardManager manager = new RewardManager(String path, Plugin plugin, RewardType type);
    let path be the way to rewards in the config.yml. (currently there is no support for other configs)

    RewardType is the type of rewards you would like to use (currently only WeightedRewards, but Im adding RandomRewards soon)

    The Config can hold two kinds of rewards right now (looking to make its any)

    Item reward and Command reward
    Code (YAML):
            '1':
                weight
    : 1
                commands
    :
                  - 'tell %player% &5&lnope still nothing'
    That would output 100% of the time nope still nothing to the player

    (Use the same concept with items... more later).

    To Give player the random reward (how random is dictated by the RewardType) use RewardManager#GivePlayerReward(Player player);

    Blocks provide the ability for servers to have meta data held on blocks and have them even run tasks every so often.

    First to make blocks register your own Enum class that implements Block Type

    Code (Java):
    package com.exoticpvp.energy;

    import java.util.HashMap;
    import java.util.List;
    import java.util.Map;

    import org.bukkit.Material;

    import com.kingmo.utils.blocks.Block;
    import com.kingmo.utils.blocks.BlockType;
    import com.kingmo.utils.main.Utils;
    import com.kingmo.utils.nbt.NBTTagManager;

    import net.minecraft.server.v1_8_R3.NBTBase;

    public enum ExoticBlockType implements BlockType {

        ENERGY_STORAGE_CENTER(EnergyStorageCenter.class, "esc", "Energy Storage Center",
                Utils.color("&b&lEnergy &3&lStorage &c&lCenter"),
                Utils.toList(Utils.color("&f&l(Place in a chunk with Energy Forges to use)"), "",
                        Utils.color("&7Collects nearby energy from forges and "),
                        Utils.color("&7converts it into a usable, non destructive form")), Material.CHEST, true, null, 20, true);

        private Class<? extends Block> clazz;
        private String id;
        private String name;
        private String itemName;
        private List<String> lore;
        private Material material;
        private boolean glow;
        private Map<String, NBTBase> tags;
        private int delay;
        private boolean show;
     
        ExoticBlockType(Class<? extends Block> clazz, String id, String name, String itemName, List<String> lore,
                Material mat) {
            this(clazz, id, name, itemName, lore, mat, false, null);
        }

        ExoticBlockType(Class<? extends Block> clazz, String id, String name, String itemName, List<String> lore,
                Material mat, boolean glow) {
            this(clazz, id, name, itemName, lore, mat, glow, null);
        }

        ExoticBlockType(Class<? extends Block> clazz, String id, String name, String itemName, List<String> lore,
                Material mat, Map<String, NBTBase> tags) {
            this(clazz, id, name, itemName, lore, mat, false, tags);
        }

        ExoticBlockType(Class<? extends Block> clazz, String id, String name, String itemName, List<String> lore,
                Material mat, int delay) {
            this(clazz, id, name, itemName, lore, mat, false, null, delay);
        }

        ExoticBlockType(Class<? extends Block> clazz, String id, String name, String itemName, List<String> lore,
                Material mat, boolean glow, Map<String, NBTBase> tags) {
            this(clazz, id, name, itemName, lore, mat, glow, tags, 0);
        }

        ExoticBlockType(Class<? extends Block> clazz, String id, String name, String itemName, List<String> lore,
                Material mat, boolean glow, Map<String, NBTBase> tags, int delay){
            this(clazz, id, name, itemName, lore, mat, glow, tags, 0, false);
        }
     
        ExoticBlockType(Class<? extends Block> clazz, String id, String name, String itemName, List<String> lore,
                Material mat, boolean glow, Map<String, NBTBase> tags, int delay, boolean show) {

            this.clazz= clazz;
            this.id = id;
            this.name = name;
            this.itemName = itemName;
            this.lore = lore;
            this.material = mat;
            this.glow = glow;
            this.tags = tags;
            this.delay = delay;
            this.show = show;
        }

        @SuppressWarnings("unchecked")
        ExoticBlockType(Map<String, Object> map) {
            this((Class<? extends Block>) map.get("class"), (String) map.get("id"), (String) map.get("name"),
                    (String) map.get("itemName"), (List<String>) map.get("lore"), Material.valueOf((String) map.get("mat")),
                    (boolean) map.get("glow"), NBTTagManager.cast((Map<String, String>) map.get("tags")),
                    (int) map.get("delay"), (boolean) map.get("show"));
        }

        @Override
        public Class<? extends Block> getBlockClass() {
            return this.clazz;
        }

        @Override
        public int getDelay() {
            return this.delay;
        }

        @Override
        public String getID() {
            return this.id;
        }

        @Override
        public String getItemName() {
            return this.itemName;
        }

        @Override
        public List<String> getLore() {
            return this.lore;
        }

        @Override
        public Material getMaterial() {
            return this.material;
        }

        @Override
        public String getName() {
            return this.name;
        }

        @Override
        public Map<String, NBTBase> getTags() {
            return this.tags;
        }

        @Override
        public boolean isGlowing() {
            return this.glow;
        }

        @Override
        public Map<String, Object> serialize() {
            Map<String, Object> map = new HashMap<>();

            map.put("class", this.getBlockClass());
            map.put("id", this.getID());
            map.put("name", this.getName());
            map.put("itemName", this.getItemName());
            map.put("lore", this.getLore());
            map.put("mat", this.getMaterial().toString());
            map.put("glow", this.isGlowing());
            map.put("tags", NBTTagManager.castTo(this.getTags()));
            map.put("delay", this.getDelay());
            map.put("show", show);
         
            return map;
        }

        @Override
        public boolean showName() {
            return show;
        }

    }
     

    then create your blocks as shown by ENERGY_STORAGE_CENTER

    Create the EnergyStorageCenter class

    Code (Java):
    package com.exoticpvp.energy;

    import java.util.Map;

    import org.bukkit.Location;
    import org.bukkit.OfflinePlayer;

    import com.kingmo.utils.blocks.Block;
    import com.kingmo.utils.blocks.BlockType;

    public class EnergyStorageCenter extends Block{

        public EnergyStorageCenter(Location loc, BlockType type) {
            super(loc, type);
        }
     
        public EnergyStorageCenter(Location loc) {
            super(loc, ExoticBlockType.ENERGY_STORAGE_CENTER);
        }

        public EnergyStorageCenter(Map<String, Object> ser) {
            super(ser);
        }

        @Override
        public void run(Location loc, OfflinePlayer player) {
         
        }

    }
     
    Now, to first understand what the constructors mean
    The Lore, ItemName, glow, nbt, and Material are all for the blocks ItemStack.

    The clazz is the class that defines the run method and all other methods.

    The ID goes unused, but is what you would use if you were to connect it up to a client with custom textures (when I release a client later this will work)

    name is what is used in maps can be named anything, pretty much doesnt matter.

    delay is the delay between every time the block is updated (this corresponds to loopedRun which is another method set in the Block class). If delay = 0 then no loopedRun happens and the Run is only called once on block place.

    boolean show is whether or not you want the title of the Block to be displayed over the block itself using armor stands

    Methods used in Block that are optional whether or not you wish to call.


    Block#onPlace(Player placer) is called when the block is placed

    Block#onBreak(Player breaker) is called when the block is broken

    Block#loopedRun(Location loc, OfflinePlayer player) is called on a loop where the BlockType#getDelay() determines speed.

    Finally to register the block simply use BlockListener#registerBlock(BlockType type)

    Code (Java):

    BlockListener.registerBlock(ExoticBlockType.ENERGY_STORAGE_CENTER);
     
    To now recieve the block in game use

    Block#createItemStack(BlockType type);

    Code (Java):
    EnergyStorageCenter.createItemStack(ExoticBlockType.ENERGY_STORAGE_CENTER)

    There are three types of commands

    Command

    BranchCommand

    SubCommand

    Right now they are 90% done.

    Basic Command. To use simply just create a class that extends Command. Fill in constructor and run (if you want to differentiate between player and commandSender use run(Player player, String[] args); along side run(CommandSender sender, String[] args) and the API will naturally differ.

    This class helps the programmer create large commands seen on most servers (think factions /f create|claim|kick...). It naturally makes a Help command.

    To use make a class extend BranchCommand and follow the constructor.

    *** note *** SubCommands can be added later if you want as seen in this example, typically tho is not wanted and should only be added in the constructor

    Code (Java):
    package com.kingmo.utils.test;

    import java.util.ArrayList;
    import java.util.HashMap;

    import com.kingmo.utils.commands.BranchCommand;
    import com.kingmo.utils.main.Utils;

    public class TestBranchCommand extends BranchCommand{

        public TestBranchCommand() {
            super("testing", Utils.toList("t", "te"), "used for testing", "/testing", "", new HashMap<>(),
                    new ArrayList<>(), Utils.color("&d"), Utils.color("&5&l"));
         
            this.addSubCommand(new TestSubCommand());
         
        }

    }

    These are the sub commands of the large branches adding the ability to quickly add a sub division of the command. Fill this out like a normal command.

    The combination of the Sub command and Branch Command look like this in the real game

    https://gyazo.com/b6c30330e90003c011f845774d86d9f8?token=dbd485bb3e383b28c40bfba75b785920

    Note this commands automatically add Hover and Click Events to the help command.

    All in all, I need to go through and add comments to all of these classes and over time I will. This code is open source so if anyone wants to make a branch and have at it, feel free too! I will update this page with more info on how to use Blocks and Commands later (plus general API uses such as the Utils class, UtilityLists, PacketManager, ExpManager, NBTManager, and more.)