Skip to content

Commit

Permalink
add nbt utils (experimental)
Browse files Browse the repository at this point in the history
  • Loading branch information
Brokkonaut committed Aug 14, 2023
1 parent 5360474 commit f7e48b2
Show file tree
Hide file tree
Showing 20 changed files with 1,192 additions and 0 deletions.
10 changes: 10 additions & 0 deletions nmsutils-core/src/main/java/de/cubeside/nmsutils/NMSUtils.java
@@ -1,5 +1,6 @@
package de.cubeside.nmsutils;

import de.cubeside.nmsutils.nbt.NbtUtils;
import org.bukkit.Bukkit;
import org.bukkit.Server;
import org.bukkit.plugin.Plugin;
Expand Down Expand Up @@ -35,6 +36,15 @@ public default BiomeUtils getBiomeUtils() {
throw new UnsupportedOperationException();
}

/**
* Gets an instance of NbtUtils for manipulating nbt.
*
* @return the NbtUtils
*/
public default NbtUtils getNbtUtils() {
throw new UnsupportedOperationException();
}

/**
* Gets an instance of MiscUtils for various features.
*
Expand Down
@@ -0,0 +1,37 @@
package de.cubeside.nmsutils.nbt;

import com.google.common.base.Preconditions;
import java.util.Arrays;

public final class ByteArrayTag extends Tag {
private byte[] value;

public ByteArrayTag(byte[] value) {
Preconditions.checkNotNull(value);
this.value = value;
}

public byte[] getValue() {
return value;
}

public void setValue(byte[] value) {
Preconditions.checkNotNull(value);
this.value = value;
}

@Override
public TagType getType() {
return TagType.BYTE_ARRAY;
}

@Override
public int hashCode() {
return Arrays.hashCode(this.value);
}

@Override
public boolean equals(Object obj) {
return obj instanceof ByteArrayTag o && Arrays.equals(value, o.value);
}
}
47 changes: 47 additions & 0 deletions nmsutils-core/src/main/java/de/cubeside/nmsutils/nbt/ByteTag.java
@@ -0,0 +1,47 @@
package de.cubeside.nmsutils.nbt;

public final class ByteTag extends Tag implements NumericTag {
private byte value;

public ByteTag(byte value) {
this.value = value;
}

public byte getValue() {
return value;
}

public void setValue(byte value) {
this.value = value;
}

@Override
public int getValueAsInt() {
return value;
}

@Override
public long getValueAsLong() {
return value;
}

@Override
public double getValueAsDouble() {
return value;
}

@Override
public TagType getType() {
return TagType.BYTE;
}

@Override
public int hashCode() {
return this.value;
}

@Override
public boolean equals(Object obj) {
return obj instanceof ByteTag o && value == o.value;
}
}

0 comments on commit f7e48b2

Please sign in to comment.