|
| 1 | +/* |
| 2 | + * Copyright 2026 Glavo |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | +package org.glavo.nbt.tag; |
| 17 | + |
| 18 | +import org.jetbrains.annotations.ApiStatus; |
| 19 | + |
| 20 | +import java.lang.invoke.MethodHandles; |
| 21 | + |
| 22 | +/// Internal access to the tag implementation. |
| 23 | +/// |
| 24 | +/// This class is **NOT** a public API and should not be used directly. |
| 25 | +@ApiStatus.Internal |
| 26 | +public final class TagAccess { |
| 27 | + private static final TagAccess INSTANCE = new TagAccess(); |
| 28 | + |
| 29 | + /// Get an instance of the internal operations. |
| 30 | + /// |
| 31 | + /// @param lookup A lookup object used to check whether a user has access rights to the [Tag]. |
| 32 | + /// @return An instance of the internal operations. |
| 33 | + /// @throws UnsupportedOperationException if the user does not have access rights to the [Tag]. |
| 34 | + public static TagAccess getInstance(MethodHandles.Lookup lookup) { |
| 35 | + try { |
| 36 | + MethodHandles.privateLookupIn(Tag.class, lookup); |
| 37 | + } catch (IllegalAccessException e) { |
| 38 | + throw new UnsupportedOperationException(e); |
| 39 | + } |
| 40 | + return INSTANCE; |
| 41 | + } |
| 42 | + |
| 43 | + private TagAccess() { |
| 44 | + } |
| 45 | + |
| 46 | + /// Returns the internal value of the tag without cloning. |
| 47 | + public byte[] getInternalArray(ByteArrayTag tag) { |
| 48 | + return tag.value; |
| 49 | + } |
| 50 | + |
| 51 | + /// Sets the internal value of the tag without cloning. |
| 52 | + public void setInternalArray(ByteArrayTag tag, byte[] value) { |
| 53 | + tag.value = value; |
| 54 | + } |
| 55 | + |
| 56 | + /// Returns the internal value of the tag without cloning. |
| 57 | + public int[] getInternalArray(IntArrayTag tag) { |
| 58 | + return tag.value; |
| 59 | + } |
| 60 | + |
| 61 | + /// Sets the internal value of the tag without cloning. |
| 62 | + public void setInternalArray(IntArrayTag tag, int[] value) { |
| 63 | + tag.value = value; |
| 64 | + } |
| 65 | + |
| 66 | + /// Returns the internal value of the tag without cloning. |
| 67 | + public long[] getInternalArray(LongArrayTag tag) { |
| 68 | + return tag.value; |
| 69 | + } |
| 70 | + |
| 71 | + /// Sets the internal value of the tag without cloning. |
| 72 | + public void setInternalArray(LongArrayTag tag, long[] value) { |
| 73 | + tag.value = value; |
| 74 | + } |
| 75 | +} |
0 commit comments