001/* 002 * Trident - A Multithreaded Server Alternative 003 * Copyright 2014 The TridentSDK Team 004 * 005 * Licensed under the Apache License, Version 2.0 (the "License"); 006 * you may not use this file except in compliance with the License. 007 * You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 018package net.tridentsdk.meta.nbt; 019 020/** 021 * @author The TridentSDK Team 022 * @since 0.3-alpha-DP 023 */ 024public class CompoundTagBuilder<B> { 025 private final CompoundTag current; 026 private final B parentBuilder; 027 028 protected CompoundTagBuilder(CompoundTag tag, B parentBuilder) { 029 this.parentBuilder = parentBuilder; 030 this.current = tag; 031 } 032 033 public CompoundTagBuilder(String name, TagContainer parent, B parentBuilder) { 034 this.parentBuilder = parentBuilder; 035 this.current = new CompoundTag(name); 036 parent.addTag(this.current); 037 } 038 039 public CompoundTagBuilder<CompoundTagBuilder<B>> beginCompoundTag(String name) { 040 return new CompoundTagBuilder<>(name, this.current, this); 041 } 042 043 public B endCompoundTag() { 044 return this.parentBuilder; 045 } 046 047 public ListTagBuilder<CompoundTagBuilder<B>> beginListTag(String name, TagType type) { 048 return new ListTagBuilder<>(name, this.current, this, type); 049 } 050 051 public CompoundTagBuilder<B> compoundTag(CompoundTag value) { 052 this.current.addTag(value); 053 return this; 054 } 055 056 public CompoundTagBuilder<B> listTag(ListTag tag) { 057 this.current.addTag(tag); 058 return this; 059 } 060 061 public CompoundTagBuilder<B> nullTag(String name) { 062 this.current.addTag(new NullTag(name)); 063 return this; 064 } 065 066 public CompoundTagBuilder<B> byteArrayTag(String name, byte... value) { 067 this.current.addTag(new ByteArrayTag(name).setValue(value)); 068 return this; 069 } 070 071 public CompoundTagBuilder<B> byteTag(String name, byte value) { 072 this.current.addTag(new ByteTag(name).setValue(value)); 073 return this; 074 } 075 076 public CompoundTagBuilder<B> doubleTag(String name, double value) { 077 this.current.addTag(new DoubleTag(name).setValue(value)); 078 return this; 079 } 080 081 public CompoundTagBuilder<B> floatTag(String name, float value) { 082 this.current.addTag(new FloatTag(name).setValue(value)); 083 return this; 084 } 085 086 public CompoundTagBuilder<B> intArrayTag(String name, int... value) { 087 this.current.addTag(new IntArrayTag(name).setValue(value)); 088 return this; 089 } 090 091 public CompoundTagBuilder<B> intTag(String name, int value) { 092 this.current.addTag(new IntTag(name).setValue(value)); 093 return this; 094 } 095 096 public CompoundTagBuilder<B> longTag(String name, long value) { 097 this.current.addTag(new LongTag(name).setValue(value)); 098 return this; 099 } 100 101 public CompoundTagBuilder<B> shortTag(String name, short value) { 102 this.current.addTag(new ShortTag(name).setValue(value)); 103 return this; 104 } 105 106 public CompoundTagBuilder<B> stringTag(String name, String value) { 107 this.current.addTag(new StringTag(name).setValue(value)); 108 return this; 109 } 110}