mirror of
https://github.com/dmulloy2/ProtocolLib.git
synced 2024-12-25 10:38:19 +01:00
Provide a remove method in NbtCompound. Discourage getValue().
Added a missing remove method in NbtCompound. In addition, the getValue() method in NbtCompount has been depreciated. It is far better to use the put and get methods in NbtCompound instead.
This commit is contained in:
parent
8c0a671078
commit
e919056f9b
@ -64,6 +64,9 @@ public interface NbtBase<TType> {
|
||||
* Is either a primitive {@link java.lang.Number wrapper}, {@link java.lang.String String},
|
||||
* {@link java.util.List List} or a {@link java.util.Map Map}.
|
||||
* <p>
|
||||
* Users are encouraged to cast an NBT compound to {@link NbtCompound} and use its put and get-methods
|
||||
* instead of accessing its content from getValue().
|
||||
* <p>
|
||||
* All operations that modify collections directly, such as {@link java.util.List#add(Object) List.add(Object)} or
|
||||
* {@link java.util.Map#clear() Map.clear()}, are considered optional. This also include members in {@link java.util.Iterator Iterator} and
|
||||
* {@link java.util.ListIterator ListIterator}. Operations that are not implemented throw a
|
||||
|
@ -16,6 +16,10 @@ import java.util.Set;
|
||||
* @author Kristian
|
||||
*/
|
||||
public interface NbtCompound extends NbtBase<Map<String, NbtBase<?>>>, Iterable<NbtBase<?>> {
|
||||
@Override
|
||||
@Deprecated()
|
||||
public Map<String, NbtBase<?>> getValue();
|
||||
|
||||
/**
|
||||
* Determine if an entry with the given key exists or not.
|
||||
* @param key - the key to lookup.
|
||||
@ -304,6 +308,13 @@ public interface NbtCompound extends NbtBase<Map<String, NbtBase<?>>>, Iterable<
|
||||
*/
|
||||
public abstract <T> NbtCompound put(String key, Collection<? extends NbtBase<T>> list);
|
||||
|
||||
/**
|
||||
* Remove the NBT element that is associated with the given key.
|
||||
* @param key - the key of the element to remove.
|
||||
* @return The removed element, or NULL if no such element was found.
|
||||
*/
|
||||
public abstract <T> NbtBase<?> remove(String key);
|
||||
|
||||
/**
|
||||
* Retrieve an iterator view of the NBT tags stored in this compound.
|
||||
* @return The tags stored in this compound.
|
||||
|
@ -215,6 +215,9 @@ class WrappedCompound implements NbtWrapper<Map<String, NbtBase<?>>>, Iterable<N
|
||||
*/
|
||||
@Override
|
||||
public <T> NbtCompound put(NbtBase<T> entry) {
|
||||
if (entry == null)
|
||||
throw new IllegalArgumentException("Entry cannot be NULL.");
|
||||
|
||||
getValue().put(entry.getName(), entry);
|
||||
return this;
|
||||
}
|
||||
@ -565,6 +568,9 @@ class WrappedCompound implements NbtWrapper<Map<String, NbtBase<?>>>, Iterable<N
|
||||
|
||||
@Override
|
||||
public NbtCompound put(String key, NbtBase<?> entry) {
|
||||
if (entry == null)
|
||||
throw new IllegalArgumentException("Entry cannot be NULL.");
|
||||
|
||||
// Don't modify the original NBT
|
||||
NbtBase<?> clone = entry.deepClone();
|
||||
|
||||
@ -583,6 +589,11 @@ class WrappedCompound implements NbtWrapper<Map<String, NbtBase<?>>>, Iterable<N
|
||||
return put(WrappedList.fromList(key, list));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> NbtBase<?> remove(String key) {
|
||||
return getValue().remove(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(DataOutput destination) {
|
||||
NbtBinarySerializer.DEFAULT.serialize(container, destination);
|
||||
|
Loading…
Reference in New Issue
Block a user