@@ -71,6 +71,168 @@ public TagType<CompoundTag> getType() {
7171 return subTagsByName .get (name );
7272 }
7373
74+ /// Returns the byte value of the byte tag with the given name.
75+ ///
76+ /// @throws NoSuchElementException if no byte tag with the given name exists.
77+ public byte getByte (String name ) throws NoSuchElementException {
78+ if (get (name ) instanceof ByteTag tag ) {
79+ return tag .get ();
80+ } else {
81+ throw new NoSuchElementException ("No byte tag with name " + name );
82+ }
83+ }
84+
85+ /// Returns the byte value of the byte tag with the given name, or `null` if no such tag exists.
86+ public @ Nullable Byte getByteOrNull (String name ) {
87+ return get (name ) instanceof ByteTag tag ? tag .get () : null ;
88+ }
89+
90+ /// Returns the byte value of the byte tag with the given name, or `0` if no such tag exists.
91+ public byte getByteOrZero (String name ) {
92+ return get (name ) instanceof ByteTag tag ? tag .get () : 0 ;
93+ }
94+
95+ /// Returns the byte value of the byte tag with the given name, or the default value if no such tag exists.
96+ public byte getByteOrElse (String name , byte defaultValue ) {
97+ return get (name ) instanceof ByteTag tag ? tag .get () : defaultValue ;
98+ }
99+
100+ /// Returns the short value of the short tag with the given name.
101+ ///
102+ /// @throws NoSuchElementException if no short tag with the given name exists.
103+ public short getShort (String name ) throws NoSuchElementException {
104+ if (get (name ) instanceof ShortTag tag ) {
105+ return tag .get ();
106+ } else {
107+ throw new NoSuchElementException ("No short tag with name " + name );
108+ }
109+ }
110+
111+ /// Returns the short value of the short tag with the given name, or `null` if no such tag exists.
112+ public @ Nullable Short getShortOrNull (String name ) {
113+ return get (name ) instanceof ShortTag tag ? tag .get () : null ;
114+ }
115+
116+ /// Returns the short value of the short tag with the given name, or `0` if no such tag exists.
117+ public short getShortOrZero (String name ) {
118+ return get (name ) instanceof ShortTag tag ? tag .get () : 0 ;
119+ }
120+
121+ /// Returns the short value of the short tag with the given name, or the default value if no such tag exists.
122+ public short getShortOrElse (String name , short defaultValue ) {
123+ return get (name ) instanceof ShortTag tag ? tag .get () : defaultValue ;
124+ }
125+
126+ /// Returns the int value of the int tag with the given name.
127+ ///
128+ /// @throws NoSuchElementException if no int tag with the given name exists.
129+ public int getInt (String name ) throws NoSuchElementException {
130+ if (get (name ) instanceof IntTag tag ) {
131+ return tag .get ();
132+ } else {
133+ throw new NoSuchElementException ("No int tag with name " + name );
134+ }
135+ }
136+
137+ /// Returns the int value of the int tag with the given name, or `null` if no such tag exists.
138+ public @ Nullable Integer getIntOrNull (String name ) {
139+ return get (name ) instanceof IntTag tag ? tag .get () : null ;
140+ }
141+
142+ /// Returns the int value of the int tag with the given name, or `0` if no such tag exists.
143+ public int getIntOrZero (String name ) {
144+ return get (name ) instanceof IntTag tag ? tag .get () : 0 ;
145+ }
146+
147+ /// Returns the int value of the int tag with the given name, or the default value if no such tag exists.
148+ public int getIntOrElse (String name , int defaultValue ) {
149+ return get (name ) instanceof IntTag tag ? tag .get () : defaultValue ;
150+ }
151+
152+ /// Returns the long value of the long tag with the given name.
153+ ///
154+ /// @throws NoSuchElementException if no long tag with the given name exists.
155+ public long getLong (String name ) throws NoSuchElementException {
156+ if (get (name ) instanceof LongTag tag ) {
157+ return tag .get ();
158+ } else {
159+ throw new NoSuchElementException ("No long tag with name " + name );
160+ }
161+ }
162+
163+ /// Returns the long value of the long tag with the given name, or `null` if no such tag exists.
164+ public @ Nullable Long getLongOrNull (String name ) {
165+ return get (name ) instanceof LongTag tag ? tag .get () : null ;
166+ }
167+
168+ /// Returns the long value of the long tag with the given name, or `0` if no such tag exists.
169+ public long getLongOrZero (String name ) {
170+ return get (name ) instanceof LongTag tag ? tag .get () : 0L ;
171+ }
172+
173+ /// Returns the long value of the long tag with the given name, or the default value if no such tag exists.
174+ public long getLongOrElse (String name , long defaultValue ) {
175+ return get (name ) instanceof LongTag tag ? tag .get () : defaultValue ;
176+ }
177+
178+ /// Returns the float value of the float tag with the given name.
179+ ///
180+ /// @throws NoSuchElementException if no float tag with the given name exists.
181+ public float getFloat (String name ) throws NoSuchElementException {
182+ if (get (name ) instanceof FloatTag tag ) {
183+ return tag .get ();
184+ } else {
185+ throw new NoSuchElementException ("No float tag with name " + name );
186+ }
187+ }
188+
189+ /// Returns the float value of the float tag with the given name, or `null` if no such tag exists.
190+ public @ Nullable Float getFloatOrNull (String name ) {
191+ return get (name ) instanceof FloatTag tag ? tag .get () : null ;
192+ }
193+
194+ /// Returns the double value of the double tag with the given name.
195+ ///
196+ /// @throws NoSuchElementException if no double tag with the given name exists.
197+ public double getDouble (String name ) throws NoSuchElementException {
198+ if (get (name ) instanceof DoubleTag tag ) {
199+ return tag .get ();
200+ } else {
201+ throw new NoSuchElementException ("No double tag with name " + name );
202+ }
203+ }
204+
205+ /// Returns the double value of the double tag with the given name, or `null` if no such tag exists.
206+ public @ Nullable Double getDoubleOrNull (String name ) {
207+ return get (name ) instanceof DoubleTag tag ? tag .get () : null ;
208+ }
209+
210+ /// Returns the string value of the string tag with the given name.
211+ ///
212+ /// @throws NoSuchElementException if no string tag with the given name exists.
213+ public String getString (String name ) throws NoSuchElementException {
214+ if (get (name ) instanceof StringTag tag ) {
215+ return tag .get ();
216+ } else {
217+ throw new NoSuchElementException ("No string tag with name " + name );
218+ }
219+ }
220+
221+ /// Returns the string value of the string tag with the given name, or `null` if no such tag exists.
222+ public @ Nullable String getStringOrNull (String name ) {
223+ return get (name ) instanceof StringTag tag ? tag .get () : null ;
224+ }
225+
226+ /// Returns the string value of the string tag with the given name, or an empty string if no such tag exists.
227+ public String getStringOrEmpty (String name ) {
228+ return get (name ) instanceof StringTag tag ? tag .get () : "" ;
229+ }
230+
231+ /// Returns the string value of the string tag with the given name, or the default value if no such tag exists.
232+ public String getStringOrDefault (String name , String defaultValue ) {
233+ return get (name ) instanceof StringTag tag ? tag .get () : defaultValue ;
234+ }
235+
74236 /// {@inheritDoc}
75237 ///
76238 /// If another tag with the same name already exists, the old tag will be removed.
@@ -207,123 +369,6 @@ public void putUUID(String name, UUID value) {
207369 addTag (new IntArrayTag (name , value ));
208370 }
209371
210- /// Returns the byte value of the byte tag with the given name.
211- ///
212- /// @throws NoSuchElementException if no byte tag with the given name exists.
213- public byte getByte (String name ) throws NoSuchElementException {
214- if (get (name ) instanceof ByteTag tag ) {
215- return tag .get ();
216- } else {
217- throw new NoSuchElementException ("No byte tag with name " + name );
218- }
219- }
220-
221- /// Returns the byte value of the byte tag with the given name, or `null` if no such tag exists.
222- public @ Nullable Byte getByteOrNull (String name ) {
223- return get (name ) instanceof ByteTag tag ? tag .get () : null ;
224- }
225-
226- /// Returns the short value of the short tag with the given name.
227- ///
228- /// @throws NoSuchElementException if no short tag with the given name exists.
229- public short getShort (String name ) throws NoSuchElementException {
230- if (get (name ) instanceof ShortTag tag ) {
231- return tag .get ();
232- } else {
233- throw new NoSuchElementException ("No short tag with name " + name );
234- }
235- }
236-
237- /// Returns the short value of the short tag with the given name, or `null` if no such tag exists.
238- public @ Nullable Short getShortOrNull (String name ) {
239- return get (name ) instanceof ShortTag tag ? tag .get () : null ;
240- }
241-
242- /// Returns the int value of the int tag with the given name.
243- ///
244- /// @throws NoSuchElementException if no int tag with the given name exists.
245- public int getInt (String name ) throws NoSuchElementException {
246- if (get (name ) instanceof IntTag tag ) {
247- return tag .get ();
248- } else {
249- throw new NoSuchElementException ("No int tag with name " + name );
250- }
251- }
252-
253- /// Returns the int value of the int tag with the given name, or `null` if no such tag exists.
254- public @ Nullable Integer getIntOrNull (String name ) {
255- return get (name ) instanceof IntTag tag ? tag .get () : null ;
256- }
257-
258- /// Returns the long value of the long tag with the given name.
259- ///
260- /// @throws NoSuchElementException if no long tag with the given name exists.
261- public long getLong (String name ) throws NoSuchElementException {
262- if (get (name ) instanceof LongTag tag ) {
263- return tag .get ();
264- } else {
265- throw new NoSuchElementException ("No long tag with name " + name );
266- }
267- }
268-
269- /// Returns the long value of the long tag with the given name, or `null` if no such tag exists.
270- public @ Nullable Long getLongOrNull (String name ) {
271- return get (name ) instanceof LongTag tag ? tag .get () : null ;
272- }
273-
274- /// Returns the float value of the float tag with the given name.
275- ///
276- /// @throws NoSuchElementException if no float tag with the given name exists.
277- public float getFloat (String name ) throws NoSuchElementException {
278- if (get (name ) instanceof FloatTag tag ) {
279- return tag .get ();
280- } else {
281- throw new NoSuchElementException ("No float tag with name " + name );
282- }
283- }
284-
285- /// Returns the float value of the float tag with the given name, or `null` if no such tag exists.
286- public @ Nullable Float getFloatOrNull (String name ) {
287- return get (name ) instanceof FloatTag tag ? tag .get () : null ;
288- }
289-
290- /// Returns the double value of the double tag with the given name.
291- ///
292- /// @throws NoSuchElementException if no double tag with the given name exists.
293- public double getDouble (String name ) throws NoSuchElementException {
294- if (get (name ) instanceof DoubleTag tag ) {
295- return tag .get ();
296- } else {
297- throw new NoSuchElementException ("No double tag with name " + name );
298- }
299- }
300-
301- /// Returns the double value of the double tag with the given name, or `null` if no such tag exists.
302- public @ Nullable Double getDoubleOrNull (String name ) {
303- return get (name ) instanceof DoubleTag tag ? tag .get () : null ;
304- }
305-
306- /// Returns the string value of the string tag with the given name.
307- ///
308- /// @throws NoSuchElementException if no string tag with the given name exists.
309- public String getString (String name ) throws NoSuchElementException {
310- if (get (name ) instanceof StringTag tag ) {
311- return tag .get ();
312- } else {
313- throw new NoSuchElementException ("No string tag with name " + name );
314- }
315- }
316-
317- /// Returns the string value of the string tag with the given name, or `null` if no such tag exists.
318- public @ Nullable String getStringOrNull (String name ) {
319- return get (name ) instanceof StringTag tag ? tag .get () : null ;
320- }
321-
322- /// Returns the string value of the string tag with the given name, or an empty string if no such tag exists.
323- public String getStringOrEmpty (String name ) {
324- return get (name ) instanceof StringTag tag ? tag .get () : "" ;
325- }
326-
327372 @ Override
328373 public Tag removeTagAt (int index ) throws IndexOutOfBoundsException {
329374 Objects .checkIndex (index , size );
0 commit comments