mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2024-09-19 13:58:22 +00:00
108 lines
2.8 KiB
Java
108 lines
2.8 KiB
Java
|
/*
|
||
|
* WorldEdit, a Minecraft world manipulation toolkit
|
||
|
* Copyright (C) sk89q <http://www.sk89q.com>
|
||
|
* Copyright (C) WorldEdit team and contributors
|
||
|
*
|
||
|
* This program is free software: you can redistribute it and/or modify it
|
||
|
* under the terms of the GNU Lesser General Public License as published by the
|
||
|
* Free Software Foundation, either version 3 of the License, or
|
||
|
* (at your option) any later version.
|
||
|
*
|
||
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||
|
* for more details.
|
||
|
*
|
||
|
* You should have received a copy of the GNU Lesser General Public License
|
||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||
|
*/
|
||
|
|
||
|
package com.sk89q.jnbt;
|
||
|
|
||
|
import java.util.HashMap;
|
||
|
import java.util.Map;
|
||
|
|
||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||
|
|
||
|
/**
|
||
|
* Helps create compound tags.
|
||
|
*/
|
||
|
public class CompoundTagBuilder {
|
||
|
|
||
|
private final Map<String, Tag> entries;
|
||
|
|
||
|
/**
|
||
|
* Create a new instance.
|
||
|
*/
|
||
|
CompoundTagBuilder() {
|
||
|
this.entries = new HashMap<String, Tag>();
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Create a new instance and use the given map (which will be modified).
|
||
|
*
|
||
|
* @param value the value
|
||
|
*/
|
||
|
CompoundTagBuilder(Map<String, Tag> value) {
|
||
|
checkNotNull(value);
|
||
|
this.entries = value;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Put the given key and tag into the compound tag.
|
||
|
*
|
||
|
* @param key they key
|
||
|
* @param value the value
|
||
|
* @return this object
|
||
|
*/
|
||
|
public CompoundTagBuilder put(String key, Tag value) {
|
||
|
checkNotNull(key);
|
||
|
checkNotNull(value);
|
||
|
entries.put(key, value);
|
||
|
return this;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Put all the entries from the given map into this map.
|
||
|
*
|
||
|
* @param value the map of tags
|
||
|
* @return this object
|
||
|
*/
|
||
|
public CompoundTagBuilder putAll(Map<String, ? extends Tag> value) {
|
||
|
checkNotNull(value);
|
||
|
for (Map.Entry<String, ? extends Tag> entry : value.entrySet()) {
|
||
|
put(entry.getKey(), entry.getValue());
|
||
|
}
|
||
|
return this;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Build an unnamed compound tag with this builder's entries.
|
||
|
*
|
||
|
* @return the new compound tag
|
||
|
*/
|
||
|
public CompoundTag build() {
|
||
|
return new CompoundTag(new HashMap<String, Tag>(entries));
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Build a new compound tag with this builder's entries.
|
||
|
*
|
||
|
* @param name the name of the tag
|
||
|
* @return the created compound tag
|
||
|
*/
|
||
|
public CompoundTag build(String name) {
|
||
|
return new CompoundTag(name, new HashMap<String, Tag>(entries));
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Create a new builder instance.
|
||
|
*
|
||
|
* @return a new builder
|
||
|
*/
|
||
|
public static CompoundTagBuilder create() {
|
||
|
return new CompoundTagBuilder();
|
||
|
}
|
||
|
|
||
|
}
|