[DEV] Temporary Attributes [Snippet]

Discussion in 'Bukkit Tools' started by Ansaf <Nitemarish111>, Jan 27, 2012.

Thread Status:
Not open for further replies.
  1. This is basicly a piece of code that you can add to any plugins to allow it to set temporary attributes. Personally I don't know if the config system in bukkit does better (or if the config system is used to temp. attributes >.>) but I personally find this myself a tad easier. ;)

    Code:
        private final Map<String, Object> attributes = new HashMap<String, Object>();
       
        public void setAttribute(String string, Object object) {
            attributes.put(string, object);
        }
       
        @SuppressWarnings("unchecked")
        public <T> T getAttribute(String string) {
            return (T) attributes.get(string);
        }
     
        @SuppressWarnings("unchecked")
        public <T> T getAttribute(String string, T fail) {
            T object = (T) attributes.get(string);
            if (object != null) {
                return object;
            }
            return fail;
        }
       
        public void removeAttribute(String string) {
            attributes.remove(string);
        }
    Ofcourse you may create instances and such for the class you're going to put it in.


    Please Note I am quite a new person to bukkit but doesn't mean I ain't know no java. :p
     
Thread Status:
Not open for further replies.

Share This Page