Java 类org.bukkit.metadata.Metadatable 实例源码

项目:Skellett    文件:ExprMetadata.java   
@Override
public void change(Event e, Object[] delta, Changer.ChangeMode mode){
    if (object.getSingle(e) instanceof Metadatable) {
        Metadatable metadata = (Metadatable)object.getSingle(e);
        if (mode == ChangeMode.SET) {
            if (metadata.hasMetadata(string.getSingle(e))) {
                metadata.removeMetadata(string.getSingle(e), Skellett.plugin);
            }
            metadata.setMetadata(string.getSingle(e), (MetadataValue)new FixedMetadataValue(Skellett.plugin, (Object)(delta[0])));
        } else if (mode == ChangeMode.RESET || mode == ChangeMode.DELETE) {
            if (metadata.hasMetadata(string.getSingle(e))) {
                metadata.removeMetadata(string.getSingle(e), Skellett.plugin);
            }
        }
    }
}
项目:AntiCheat    文件:Metadatas.java   
public static Object getMetadata(JavaPlugin plugin, Metadatable object, String key)
{
    List<MetadataValue> values = object.getMetadata(key);
    for (MetadataValue value : values)
    {
        if (value.getOwningPlugin().equals(plugin))
        {
            return value.value();
        }
    }

    return null;
}
项目:Kineticraft    文件:MetadataManager.java   
/**
 * Set a metadata value.
 * @param metadata - The object to set the metadata of.
 * @param key - The key to index the metadata by.
 * @param o - The object value to set.
 */
public static void setMetadata(Metadatable metadata, String key, Object o) {
    if (o instanceof MetadataValue)
        o = ((MetadataValue) o).value();
    if (o instanceof Enum<?>)
        o = ((Enum<?>) o).name();
    metadata.setMetadata(key, new FixedMetadataValue(Core.getInstance(), o));
}
项目:Kineticraft    文件:MetadataManager.java   
/**
 * Does this player have a cooldown? Alerts them if they do.
 * @param meta
 * @param cooldown
 * @return hasCooldown
 */
public static boolean alertCooldown(Metadatable meta, String cooldown) {
    boolean has = hasCooldown(meta, cooldown);
    if (has && meta instanceof CommandSender)
        ((CommandSender) meta).sendMessage(ChatColor.RED + "You must wait "
                + Utils.formatTime(meta.getMetadata(cooldown).get(0).asLong() - System.currentTimeMillis())
                + " before doing this.");
    return has;
}
项目:MassiveCoreForgeFixes    文件:FactionsEvents.java   
public Boolean isNPC(Object object) {
    if ( ! (object instanceof Metadatable)) return false;
    Metadatable metadatable = (Metadatable) object;

    try {
        return metadatable.hasMetadata("NPC");
    } catch (UnsupportedOperationException e) {
        return false;
    }
}
项目:Skellett    文件:ExprMetadata.java   
@Override
@Nullable
protected Object[] get(Event e) {   
    Metadatable metadata;
    if (object.getSingle(e) instanceof Metadatable && (metadata = (Metadatable)object.getSingle(e)).hasMetadata(string.getSingle(e))) {
        return new Object[]{((MetadataValue)metadata.getMetadata(string.getSingle(e)).iterator().next()).value()};
    }
    return null;
}
项目:NovaGuilds    文件:Meta.java   
/**
 * Gets metadata
 *
 * @param obj object
 * @param key key
 * @return metadata value
 */
public static MetadataValue getMetadata(Metadatable obj, String key) {
    for(MetadataValue value : obj.getMetadata(key)) {
        if(value.getOwningPlugin().getDescription().getName().equals(plugin.getDescription().getName())) {
            return value;
        }
    }

    return null;
}
项目:GameDispenser    文件:GameBase.java   
@Override
public final GameMetadata getMetadata(Metadatable object, String key) {
    for (MetadataValue v : object.getMetadata(key)) {
        if (v instanceof GameMetadata) {
            GameMetadata data = (GameMetadata) v;
            if (data.getOwningPlugin() == fakePlugin) {
                return data;
            }
        }
    }
    return null;
}
项目:parchment    文件:Metadata.java   
private Metadatable resolveObject(Parameter object) {
    if ( object instanceof PlayerParameter ) return object.as(org.bukkit.entity.Player.class);
    if ( object instanceof EntityParameter ) return object.as(org.bukkit.entity.Entity.class);
    if ( object instanceof WorldParameter) return object.as(org.bukkit.World.class);
    if ( object instanceof BlockParameter) return object.as(org.bukkit.block.Block.class);
    if ( object instanceof LocationParameter) return object.as(org.bukkit.block.Block.class);
    throw new FizzleException("Couldn't convert object into something we can use metadata with: " + object.toString());
}
项目:GameCore    文件:MetadataUtil.java   
public boolean hasKeys(Metadatable m, String... keys) {
    for (String key : keys) {
        if (!hasKey(m, key)) {
            return false;
        }
    }
    return true;
}
项目:sensibletoolbox    文件:STBUtil.java   
/**
 * Convenience wrapper to get the metadata value set by STB.
 *
 * @param m the metadatable object
 * @param key the metadata key
 * @return the metadata value, or null if there is none
 */
public static Object getMetadataValue(Metadatable m, String key) {
    for (MetadataValue mv : m.getMetadata(key)) {
        if (mv.getOwningPlugin() == SensibleToolboxPlugin.getInstance()) {
            return mv.value();
        }
    }
    return null;
}
项目:EndHQ-Libraries    文件:Meta.java   
public static Object getMetadata(Metadatable object, String key, Plugin plugin) {
    List<MetadataValue> values = object.getMetadata(key);
    for (MetadataValue value : values) {
        if (value.getOwningPlugin() == plugin) {
            return value.value();
        }
    }
    return null;
}
项目:ReadySetJump    文件:ReadySetJumpPlugin.java   
MetadataValue getMetadata(Metadatable metadatable, String key) {
  List<MetadataValue> values = metadatable.getMetadata(key);
  if(values == null)
    return null;
  for(MetadataValue value : values) {
    if(this.equals(value.getOwningPlugin()))
      return value;
  }
  return null;
}
项目:FactionChat    文件:FactionChatListener.java   
public static boolean isNpc(Object object) {
    if (!(object instanceof Metadatable)) {
        return false;
    }
    Metadatable metadatable = (Metadatable) object;
    return metadatable.hasMetadata("NPC");
}
项目:AntiCheat    文件:Metadatas.java   
public static void setMetadata(JavaPlugin plugin, Metadatable object, String key, Object value)
{
    object.setMetadata(key, new FixedMetadataValue(plugin, value));
}
项目:ProjectAres    文件:Grenade.java   
public static boolean is(Metadatable entity) {
    return entity.hasMetadata(METADATA_KEY);
}
项目:ProjectAres    文件:Grenade.java   
public static @Nullable Grenade get(Metadatable entity) {
    return entity.hasMetadata(METADATA_KEY) ? (Grenade) entity.getMetadata(METADATA_KEY).get(0).value() : null;
}
项目:ProjectAres    文件:Grenade.java   
public void set(Plugin plugin, Metadatable entity) {
    entity.setMetadata(METADATA_KEY, new FixedMetadataValue(plugin, this));
}
项目:Kineticraft    文件:MetadataManager.java   
/**
 * Remove metadata from the given object.
 * @param obj - Object with the metadata.
 * @param key - The key to remove.
 */
public static <T> T removeMetadata(Metadatable obj, String key) {
    T value = getValue(obj ,key);
    obj.removeMetadata(key, Core.getInstance());
    return value;
}
项目:GameDispenser    文件:GameBase.java   
@Override
public final void removeMetadata(Metadatable object, String key) {
    object.removeMetadata(key, fakePlugin);
}
项目:Stoa    文件:BukkitMetaUtil.java   
public static MetadataValue getMetadata(Metadatable obj, String key) {
    return Iterables.getFirst(obj.getMetadata(key), null);
}
项目:GameCore    文件:MetadataUtil.java   
public Object get(Metadatable m, String key) {
    return hasKey(m, key) ? m.getMetadata(pluginName + "_" + key).get(0).value() : null;
}
项目:GameCore    文件:MetadataUtil.java   
public boolean hasKey(Metadatable m, String key) {
    return m.getMetadata(pluginName + "_" + key).size() > 0;
}
项目:GameCore    文件:MetadataUtil.java   
public void remove(Metadatable m, String key) {
    m.removeMetadata(pluginName + "_" + key, plugin);
}
项目:GameCore    文件:MetadataUtil.java   
public void removeAll(Metadatable m, String... keys) {
    for (String k : keys) {
        remove(m, k);
    }
}
项目:GameCore    文件:MetadataUtil.java   
public void set(Metadatable m, String key, Object value) {
    m.setMetadata(pluginName + "_" + key, new FixedMetadataValue(plugin, value));
}
项目:EndHQ-Libraries    文件:Meta.java   
public static void setMetadata(Metadatable object, String key, Object value, Plugin plugin) {
    object.setMetadata(key, new FixedMetadataValue(plugin, value));
}
项目:ReadySetJump    文件:ReadySetJumpPlugin.java   
void setMetadata(Metadatable metadatable, String key, Object value) {
  metadatable.setMetadata(key, new FixedMetadataValue(this, value));
}
项目:Kineticraft    文件:MetadataManager.java   
/**
 * Checks if this player has the given cooldown, and if they don't, give it to them after telling them they have it.
 * Returns whether or not the player had the cooldown before this was called.
 *
 * @param meta
 * @param cooldown
 * @param ticks
 * @return hasCooldown
 */
public static boolean updateCooldown(Metadatable meta, String cooldown, int ticks) {
    boolean has = alertCooldown(meta, cooldown);
    if (!has)
        setCooldown(meta, cooldown, ticks);
    return has;
}
项目:Kineticraft    文件:MetadataManager.java   
/**
 * Checks if this player has the given cooldown, and if they don't, give it to them silently.
 * Returns whether or not the player had the cooldown before this was called.
 *
 * @param meta
 * @param cooldown
 * @param ticks
 * @return hasCooldown
 */
public static boolean updateCooldownSilently(Metadatable meta, String cooldown, int ticks) {
    boolean has = hasCooldown(meta, cooldown);
    if (!has)
        setCooldown(meta, cooldown, ticks);
    return has;
}
项目:Kineticraft    文件:MetadataManager.java   
/**
 * Does this object have the given metadata?
 * @param obj - Object with metadata
 * @param type - Metadata key
 * @return hasKey
 */
public static boolean hasMetadata(Metadatable obj, String type) {
    return obj.hasMetadata(type);
}
项目:Kineticraft    文件:MetadataManager.java   
/**
 * Get a metadata value from a player.
 * @param obj - The object with the metadata.
 * @parma key - The key to get the metadata from.
 * @return getMetadata
 */
public static MetadataValue getMetadata(Metadatable obj, String key) {
    return hasMetadata(obj, key) ? obj.getMetadata(key).get(0) : null;
}
项目:Kineticraft    文件:MetadataManager.java   
/**
 * Get a metadata value as an enum.
 * @param obj - The object to get the value from
 * @param key - The key the value is indexed by.
 * @param clazz - The enum class we want to load.
 * @param <E>
 * @return enumValue
 */
public static <E extends Enum<E>> E getEnum(Metadatable obj, String key, Class<E> clazz) {
    return Utils.getEnum(getValue(obj, key), clazz);
}
项目:Kineticraft    文件:MetadataManager.java   
/**
 * Get a metadata value from a metadatable object.
 * @param obj - The object with the metadata.
 * @param key - The key the metadata is indexed by.
 * @param <T> - The type to return the value as.
 * @return value
 */
@SuppressWarnings({"unchecked", "ConstantConditions"})
public static <T> T getValue(Metadatable obj, String key) {
    return (T) (hasMetadata(obj, key) ? getMetadata(obj, key).value() : null);
}
项目:Kineticraft    文件:MetadataManager.java   
/**
 * Get a metadata value from a given object, if the metadata key is not present it will return the fallback value.
 * If the fallback value is returned, it is stored as the actual value.
 * @param obj - The object with the metadata.
 * @param key - The key the metadata is indexed by.
 * @param fallback - The fallback value.
 * @param <T>
 * @return value
 */
public static <T> T getValue(Metadatable obj, String key, T fallback) {
    if (!hasMetadata(obj, key))
        setMetadata(obj, key, fallback);
    return getValue(obj, key);
}
项目:Kineticraft    文件:MetadataManager.java   
/**
 * Enact a cooldown on the given type.
 *
 * IMPORTANT:
 * Cooldowns are seperate from the metadata enum because the metadata enum will get removed on logout.
 * Also, it's inconvenient to add them to the enum.
 *
 * @param obj
 * @param cooldown
 * @param ticks
 */
public static void setCooldown(Metadatable obj, String cooldown, int ticks) {
    obj.setMetadata(cooldown, new FixedMetadataValue(Core.getInstance(), System.currentTimeMillis() + (ticks * 50)));
}
项目:Kineticraft    文件:MetadataManager.java   
/**
 * Does this object have an active cooldown?
 * @param obj
 * @param cooldown
 * @return hasCooldown - Only will be true if the cooldown has not expired as well.
 */
public static boolean hasCooldown(Metadatable obj, String cooldown) {
    return obj.hasMetadata(cooldown) && obj.getMetadata(cooldown).get(0).asLong() > System.currentTimeMillis();
}
项目:NovaGuilds    文件:Meta.java   
/**
 * Sets metadata
 *
 * @param obj   object
 * @param key   key
 * @param value value
 */
public static void setMetadata(Metadatable obj, String key, Object value) {
    obj.setMetadata(key, new FixedMetadataValue(plugin, value));
}
项目:NovaGuilds    文件:Meta.java   
/**
 * Removes metadata
 *
 * @param obj object
 * @param key key
 */
public static void removeMetadata(Metadatable obj, String key) {
    obj.removeMetadata(key, plugin);
}
项目:GameDispenser    文件:Game.java   
/**
 * Retrieves the metadata for a metadatable object using key
 * and this game instance to ensure correct selection
 * @param object a metadatable object
 * @param key metadata key
 * @return game metadata
 */
public GameMetadata getMetadata(Metadatable object, String key);