How to use Player metadata

Discussion in 'Spigot Plugin Development' started by TheGamerPlayz, Jun 8, 2016.

Thread Status:
Not open for further replies.
  1. I am trying to store a things inside of a player Metadata, but I can't find any tutorials on how to do it. Can anyone tell me?
    Here is something to help you understand:
    Code (Java):

                            if(!mage.hasMetadata("BulletDelay") || mage.hasPermission("Arena.unlimited")){  //if delay isn't set
                                mage.setMetadata("BulletDelay", new FixedMetadataValue(pl, "BulletDelay")); //sets delay
                                HashMap<String, BukkitRunnable> task = new HashMap<String, BukkitRunnable>();
                                task.put("task", new BukkitRunnable() {
                                    int i = 100;
                                    public void run() {
                                        if(i == 0){
                                            mage.removeMetadata("BulletDelay", pl);    //removes after 5 seconds
                                }); task.get("task").runTaskTimer(pl, 1, 1);
    • Friendly Friendly x 1
  2. What are you trying to accomplish with metadata? Thus far, the code looks fine xD.
  3. Metadata is used to store a string that has some value. For example, I want to grant each of my players no damage without adding them to a hashmap every time. So I use:

    Code (Text):
            e.getPlayer().setMetadata("no_damage", new FixedMetadataValue(MainClass.getInstance(), 0));
Thread Status:
Not open for further replies.