Skip to content

Commit

Permalink
v0.9.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Focusvity committed Apr 25, 2020
1 parent dbba558 commit 5a9a297
Show file tree
Hide file tree
Showing 8 changed files with 301 additions and 11 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

<groupId>me.dpohvar.powernbt</groupId>
<artifactId>PowerNBT</artifactId>
<version>0.9</version>
<version>0.9.1</version>
<packaging>jar</packaging>

<description>Powerful NBT editor for CraftBukkit 1.5 and later</description>
Expand Down
1 change: 0 additions & 1 deletion src/main/java/me/dpohvar/powernbt/api/NBTManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -656,5 +656,4 @@ public ItemStack createCraftItemStack(NBTCompound compound)
if (compound == null) return new ItemStack(Material.AIR);
return itemStackUtils.createCraftItemStackFromNBT(compound.getHandle());
}

}
24 changes: 19 additions & 5 deletions src/main/java/me/dpohvar/powernbt/completer/CompleterNBT.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public void fillTabs(Caller caller, TabFormer former) throws Exception
String word = former.poll(); // object
if (word.isEmpty())
{
former.addIfStarts("buffer", "list", "compound", "byte[]", "int[]", "debug", "file:", "gz:", "sch:");
former.addIfStarts("buffer", "list", "compound", "byte[]", "int[]", "long[]", "debug", "file:", "gz:", "sch:");
if (caller.getOwner() instanceof Entity) former.addIfStarts("block", "inventory", "hand", "hand:");
if (caller.getOwner() instanceof Entity && former.getQuery().startsWith("id"))
{
Expand Down Expand Up @@ -145,7 +145,7 @@ public void fillTabs(Caller caller, TabFormer former) throws Exception
former.addIfStarts("float", "double");
} else if (val1.matches("\\[((-?[0-9]+|#-?[0-9a-fA-F]+)(,(?!\\])|(?=\\])))*\\]"))
{
former.addIfStarts("byte[]", "int[]");
former.addIfStarts("byte[]", "int[]", "long[]");
}
} else
{
Expand Down Expand Up @@ -240,6 +240,7 @@ public void fillTabs(Caller caller, TabFormer former) throws Exception
case DOUBLE:
case BYTEARRAY:
case INTARRAY:
case LONGARRAY:
String s = NBTViewer.getShortValue(base, false);
former.add(s);
return;
Expand Down Expand Up @@ -271,6 +272,7 @@ public void fillTabs(Caller caller, TabFormer former) throws Exception
case DOUBLE:
case BYTEARRAY:
case INTARRAY:
case LONGARRAY:
String s = NBTViewer.getShortValue(b, false);
former.add(s);
return;
Expand All @@ -288,7 +290,7 @@ public void fillTabs(Caller caller, TabFormer former) throws Exception
}
}
}
former.addIfStarts("me", "item", "buffer", "list", "compound", "byte[]", "int[]");
former.addIfStarts("me", "item", "buffer", "list", "compound", "byte[]", "int[]", "long[]");
if (caller.getOwner() instanceof Entity) former.addIfStarts("block", "inventory", "hand", "hand:");
if (caller.getOwner() instanceof Entity && former.getQuery().startsWith("id"))
{
Expand Down Expand Up @@ -394,7 +396,7 @@ public void fillTabs(Caller caller, TabFormer former) throws Exception
former.addIfStarts("float", "double");
} else if (val2.matches("\\[((-?[0-9]+|#-?[0-9a-fA-F]+)(,(?!\\])|(?=\\])))*\\]"))
{
former.addIfStarts("byte[]", "int[]");
former.addIfStarts("byte[]", "int[]", "long[]");
}
} else
{
Expand Down Expand Up @@ -447,6 +449,12 @@ private void completeTag(NBTContainer<?> container, TabFormer former) throws Exc
{
former.addIfStarts("[" + i + "]");
}
} else if (base instanceof NBTTagLongArray)
{
for (int i = 0; i < ((NBTTagLongArray) base).size(); i++)
{
former.addIfStarts("[" + i + "]");
}
}
}
for (String type : container.getTypes())
Expand Down Expand Up @@ -503,6 +511,13 @@ private void completeTag(NBTContainer<?> container, TabFormer former) throws Exc
String s = "[" + i + "]";
if (s.toUpperCase().startsWith(qu.toUpperCase())) former.add(option + s);
}
} else if (base instanceof NBTTagLongArray)
{
for (int i = 0; i < ((NBTTagLongArray) base).size(); i++)
{
String s = "[" + i + "]";
if (s.toUpperCase().startsWith(qu.toUpperCase())) former.add(option + s);
}
}
}
for (String type : container.getTypes())
Expand All @@ -519,7 +534,6 @@ private void completeTag(NBTContainer<?> container, TabFormer former) throws Exc
}
}
}

}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,5 +120,4 @@ private Object getObjectByQueue(String key, Queue<Object> queue)
return r;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -101,5 +101,4 @@ public void inventory(InventoryClickEvent event)
caller.handleException(t);
}
}

}
5 changes: 5 additions & 0 deletions src/main/java/me/dpohvar/powernbt/nbt/NBTBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ public static NBTBase wrap(Object handle)
return new NBTTagCompound(true, handle);
case 11:
return new NBTTagIntArray(true, handle);
case 12:
return new NBTTagLongArray(true, handle);
default:
return null;
}
Expand Down Expand Up @@ -85,6 +87,8 @@ public static NBTBase getDefault(byte type)
return new NBTTagCompound();
case 11:
return new NBTTagIntArray();
case 12:
return new NBTTagLongArray();
default:
return null;
}
Expand All @@ -109,6 +113,7 @@ public static NBTBase getByValue(Object o)
if (o instanceof byte[]) return new NBTTagByteArray((byte[]) o);
if (o instanceof CharSequence) return new NBTTagString(o.toString());
if (o instanceof int[]) return new NBTTagIntArray((int[]) o);
if (o instanceof long[]) return new NBTTagLongArray((long[]) o);
if (o instanceof Map)
{
NBTTagCompound tag = new NBTTagCompound();
Expand Down
233 changes: 233 additions & 0 deletions src/main/java/me/dpohvar/powernbt/nbt/NBTTagLongArray.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,233 @@
package me.dpohvar.powernbt.nbt;

import java.util.*;

import static me.dpohvar.powernbt.utils.NBTUtils.nbtUtils;

public class NBTTagLongArray extends NBTTagNumericArray<Long>
{

public static final byte typeId = 12;

public NBTTagLongArray()
{
super(new long[0]);
}

public NBTTagLongArray(String ignored)
{
super(new long[0]);
}

public NBTTagLongArray(long[] l)
{
super(nbtUtils.createTag(l, typeId));
}

public NBTTagLongArray(String ignored, long[] l)
{
this(l);
}

public NBTTagLongArray(boolean ignored, Object tag)
{
super(tag);
if (nbtUtils.getTagType(handle) != typeId)
{
throw new IllegalArgumentException();
}
}

public static ArrayList<Long> longArrToList(long[] ln)
{
ArrayList<Long> temp = new ArrayList<Long>(ln.length);
for (long anLn : ln)
{
temp.add(anLn);
}
return temp;
}

public static long[] listToLongArr(Collection<Long> ln)
{
long[] temp = new long[ln.size()];
int i = 0;
for (Long anLn : ln)
{
temp[i++] = anLn;
}
return temp;
}

public boolean equals(Object o)
{
if (o instanceof NBTBase)
{
((NBTBase) o).getHandle();
}
return handle.equals(o);
}

public int hashCode()
{
return handle.hashCode();
}

public long[] get()
{
return (long[]) super.get();
}

public void set(long[] value)
{
super.set(value);
}

public int size()
{
return get().length;
}

@Override
public boolean contains(Object o)
{
return longArrToList(get()).contains(o);
}

public Long get(int i)
{
long[] array = get();
if (i >= array.length) return null;
return array[i];
}

public Long set(int i, Number value)
{
Long res = get(i);
long[] array = get();
List<Long> list = new LinkedList<Long>();
for (long b : array) list.add(b);
while (list.size() <= i)
{
list.add(0L);
}
list.set(i, value.longValue());
long[] result = new long[list.size()];
int t = 0;
for (long b : list) result[t++] = b;
set(result);
return res;
}

public Long remove(int i)
{
Long res = get(i);
long[] array = get();
if (i < 0 || i >= array.length) return res;
List<Long> list = new LinkedList<Long>();
for (long b : array) list.add(b);
while (list.size() <= i)
{
list.add((long) 0);
}
list.remove(i);
long[] result = new long[list.size()];
int t = 0;
for (long b : list) result[t++] = b;
set(result);
return res;
}

@Override
public int indexOf(Object o)
{
return longArrToList(get()).indexOf(o);
}

@Override
public int lastIndexOf(Object o)
{
return longArrToList(get()).lastIndexOf(o);
}

@Override
public List<Long> subList(int fromIndex, int toIndex)
{
long[] r = new long[toIndex - fromIndex];
int t = 0;
long[] s = get();
for (int i = fromIndex; i < toIndex; i++)
{
r[t++] = s[i];
}
return new NBTTagLongArray(r);
}

@Override
public boolean add(Number value)
{
long[] array = get();
List<Long> list = new LinkedList<Long>();
for (long b : array) list.add(b);
list.add(value.longValue());
long[] result = new long[list.size()];
int t = 0;
for (long b : list) result[t++] = b;
set(result);
return false;
}

@Override
public boolean remove(Object o)
{
List<Long> longs = longArrToList(get());
boolean result = longs.remove(o);
if (result)
{
set(listToLongArr(longs));
}
return result;
}

@Override
public boolean removeAll(Collection<?> c)
{
List<Long> longs = longArrToList(get());
boolean result = longs.removeAll(c);
if (result)
{
set(listToLongArr(longs));
}
return result;
}

@Override
public boolean retainAll(Collection<?> c)
{
List<Long> longs = longArrToList(get());
boolean result = longs.retainAll(c);
if (result)
{
set(listToLongArr(longs));
}
return result;
}

@Override
public void clear()
{
set(new long[0]);
}

@Override
public String toString()
{
return Arrays.toString(get());
}

@Override
public byte getTypeId()
{
return 12;
}
}
Loading

0 comments on commit 5a9a297

Please sign in to comment.