Skip to content

Commit

Permalink
ReflectedNBTWrapper 1.1 Alpha Revision 2
Browse files Browse the repository at this point in the history
- Added ReflectedNBTCompound#keyset()
- Now ReflectedNBTList implements Iterable<Object>
- Added LinearIterator
- Changed package name to v1_1_R2
  • Loading branch information
milkyway0308 committed Jan 4, 2020
1 parent 6902a62 commit f06a812
Show file tree
Hide file tree
Showing 23 changed files with 101 additions and 59 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ ReflectedNBTWrapper is NBT class wrapper using reflection for plugin version sup
1. Download last release of ReflectedNBTWrapper from git release history.
2. Add to dependency.
Be careful, ReflectedNBTWrapper use **difference package** to evade version collision.

3. Add to extract target.
ReflectNBTWrapper must have to extract or included in your plugin.
#### With Gradle
> Preparing.
#### With Maven
> Preparing.
## Example
##### <= 1.1
##### Before version 1.1 R2(1.1.2)
```java
// Simple nbt extract sample.
// Extract string from item nbt.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package skywolf46.NBTUtil.v1_1R1;
package skywolf46.NBTUtil.v1_1R2;

import org.bukkit.Bukkit;
import org.bukkit.Server;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package skywolf46.NBTUtil.v1_1R1.Exception;
package skywolf46.NBTUtil.v1_1R2.Exception;

public class CollectionMismatchedException extends RuntimeException {
public CollectionMismatchedException(Class bef, Class nex) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package skywolf46.NBTUtil.v1_1R1.Exception;
package skywolf46.NBTUtil.v1_1R2.Exception;

public class UndefinedNBTException extends RuntimeException {
public UndefinedNBTException(Class c) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package skywolf46.NBTUtil.v1_1R1.Interface;
package skywolf46.NBTUtil.v1_1R2.Interface;

public interface IReflectedNBTBase<T> {
T getValue();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package skywolf46.NBTUtil.v1_1R1.Interface;
package skywolf46.NBTUtil.v1_1R2.Interface;

import java.util.HashMap;
import java.util.List;

public interface IReflectedNBTCompound extends IReflectedNBTBase<HashMap<String, IReflectedNBTBase<?>>> {
Object get(String str);
IReflectedNBTBase<?> getNBT(String str);

IReflectedNBTCompound set(String str,Object o);
IReflectedNBTCompound setNBT(String str,IReflectedNBTBase<?> o);

List<String> keyset();
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package skywolf46.NBTUtil.v1_1R1.Interface;
package skywolf46.NBTUtil.v1_1R2.Interface;

import java.util.List;

public interface IReflectedNBTList extends IReflectedNBTBase<List<Object>> {
public interface IReflectedNBTList extends IReflectedNBTBase<List<Object>>, Iterable<Object> {

int size();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package skywolf46.NBTUtil.v1_1R1;
package skywolf46.NBTUtil.v1_1R2;

import org.bukkit.inventory.ItemStack;
import skywolf46.NBTUtil.v1_1R1.NBTData.ReflectedNBTCompound;
import skywolf46.NBTUtil.v1_1R2.NBTData.ReflectedNBTCompound;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package skywolf46.NBTUtil.v1_1R1;
package skywolf46.NBTUtil.v1_1R2;

import org.bukkit.inventory.ItemStack;
import skywolf46.NBTUtil.v1_1R1.NBTData.ReflectedNBTCompound;
import skywolf46.NBTUtil.v1_1R2.NBTData.ReflectedNBTCompound;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
Expand Down
22 changes: 22 additions & 0 deletions src/skywolf46/NBTUtil/v1_1R2/Iterator/LinearIterator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package skywolf46.NBTUtil.v1_1R2.Iterator;

import java.util.Iterator;

public class LinearIterator implements Iterator<Object> {
private Object[] data;
private int pointer;

public LinearIterator(Object[] data) {
this.data = data;
}

@Override
public boolean hasNext() {
return pointer >= data.length;
}

@Override
public Object next() {
return data[pointer++];
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package skywolf46.NBTUtil.v1_1R1.NBTData;
package skywolf46.NBTUtil.v1_1R2.NBTData;

import skywolf46.NBTUtil.v1_1R1.BukkitVersionUtil;
import skywolf46.NBTUtil.v1_1R1.Interface.IReflectedNBTBase;
import skywolf46.NBTUtil.v1_1R2.BukkitVersionUtil;
import skywolf46.NBTUtil.v1_1R2.Interface.IReflectedNBTBase;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package skywolf46.NBTUtil.v1_1R1.NBTData;
package skywolf46.NBTUtil.v1_1R2.NBTData;

import skywolf46.NBTUtil.v1_1R1.BukkitVersionUtil;
import skywolf46.NBTUtil.v1_1R1.Interface.IReflectedNBTBase;
import skywolf46.NBTUtil.v1_1R2.BukkitVersionUtil;
import skywolf46.NBTUtil.v1_1R2.Interface.IReflectedNBTBase;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
package skywolf46.NBTUtil.v1_1R1.NBTData;
package skywolf46.NBTUtil.v1_1R2.NBTData;

import skywolf46.NBTUtil.v1_1R1.BukkitVersionUtil;
import skywolf46.NBTUtil.v1_1R1.Exception.UndefinedNBTException;
import skywolf46.NBTUtil.v1_1R1.Interface.IReflectedNBTBase;
import skywolf46.NBTUtil.v1_1R1.Interface.IReflectedNBTCompound;
import skywolf46.NBTUtil.v1_1R1.ReflectedNBTStorage;
import skywolf46.NBTUtil.v1_1R2.BukkitVersionUtil;
import skywolf46.NBTUtil.v1_1R2.Exception.UndefinedNBTException;
import skywolf46.NBTUtil.v1_1R2.Interface.IReflectedNBTBase;
import skywolf46.NBTUtil.v1_1R2.Interface.IReflectedNBTCompound;
import skywolf46.NBTUtil.v1_1R2.ReflectedNBTStorage;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ReflectedNBTCompound implements IReflectedNBTCompound {
Expand Down Expand Up @@ -131,6 +133,11 @@ public IReflectedNBTCompound setNBT(String str, IReflectedNBTBase<?> o) {
return this;
}

@Override
public List<String> keyset() {
return new ArrayList<>(d.keySet());
}

public boolean containsKey(String key) {
return d.containsKey(key);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package skywolf46.NBTUtil.v1_1R1.NBTData;
package skywolf46.NBTUtil.v1_1R2.NBTData;

import skywolf46.NBTUtil.v1_1R1.BukkitVersionUtil;
import skywolf46.NBTUtil.v1_1R1.Interface.IReflectedNBTBase;
import skywolf46.NBTUtil.v1_1R2.BukkitVersionUtil;
import skywolf46.NBTUtil.v1_1R2.Interface.IReflectedNBTBase;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package skywolf46.NBTUtil.v1_1R1.NBTData;
package skywolf46.NBTUtil.v1_1R2.NBTData;

import skywolf46.NBTUtil.v1_1R1.BukkitVersionUtil;
import skywolf46.NBTUtil.v1_1R1.Interface.IReflectedNBTBase;
import skywolf46.NBTUtil.v1_1R2.BukkitVersionUtil;
import skywolf46.NBTUtil.v1_1R2.Interface.IReflectedNBTBase;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package skywolf46.NBTUtil.v1_1R1.NBTData;
package skywolf46.NBTUtil.v1_1R2.NBTData;

import skywolf46.NBTUtil.v1_1R1.BukkitVersionUtil;
import skywolf46.NBTUtil.v1_1R1.Interface.IReflectedNBTBase;
import skywolf46.NBTUtil.v1_1R2.BukkitVersionUtil;
import skywolf46.NBTUtil.v1_1R2.Interface.IReflectedNBTBase;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package skywolf46.NBTUtil.v1_1R1.NBTData;
package skywolf46.NBTUtil.v1_1R2.NBTData;

import skywolf46.NBTUtil.v1_1R1.BukkitVersionUtil;
import skywolf46.NBTUtil.v1_1R1.Interface.IReflectedNBTBase;
import skywolf46.NBTUtil.v1_1R2.BukkitVersionUtil;
import skywolf46.NBTUtil.v1_1R2.Interface.IReflectedNBTBase;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
package skywolf46.NBTUtil.v1_1R1.NBTData;
package skywolf46.NBTUtil.v1_1R2.NBTData;

import skywolf46.NBTUtil.v1_1R1.BukkitVersionUtil;
import skywolf46.NBTUtil.v1_1R1.Exception.CollectionMismatchedException;
import skywolf46.NBTUtil.v1_1R1.Exception.UndefinedNBTException;
import skywolf46.NBTUtil.v1_1R1.Interface.IReflectedNBTBase;
import skywolf46.NBTUtil.v1_1R1.Interface.IReflectedNBTList;
import skywolf46.NBTUtil.v1_1R1.ReflectedNBTStorage;
import skywolf46.NBTUtil.v1_1R2.BukkitVersionUtil;
import skywolf46.NBTUtil.v1_1R2.Exception.CollectionMismatchedException;
import skywolf46.NBTUtil.v1_1R2.Exception.UndefinedNBTException;
import skywolf46.NBTUtil.v1_1R2.Interface.IReflectedNBTBase;
import skywolf46.NBTUtil.v1_1R2.Interface.IReflectedNBTList;
import skywolf46.NBTUtil.v1_1R2.Iterator.LinearIterator;
import skywolf46.NBTUtil.v1_1R2.ReflectedNBTStorage;

import javax.annotation.Nonnull;
import java.lang.reflect.*;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class ReflectedNBTList implements IReflectedNBTList {
Expand Down Expand Up @@ -184,4 +187,10 @@ public Object getNBTBase() {
}
return null;
}

@Override
@Nonnull
public Iterator<Object> iterator() {
return new LinearIterator(getValue().toArray());
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package skywolf46.NBTUtil.v1_1R1.NBTData;
package skywolf46.NBTUtil.v1_1R2.NBTData;

import skywolf46.NBTUtil.v1_1R1.BukkitVersionUtil;
import skywolf46.NBTUtil.v1_1R1.Interface.IReflectedNBTBase;
import skywolf46.NBTUtil.v1_1R2.BukkitVersionUtil;
import skywolf46.NBTUtil.v1_1R2.Interface.IReflectedNBTBase;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package skywolf46.NBTUtil.v1_1R1.NBTData;
package skywolf46.NBTUtil.v1_1R2.NBTData;

import skywolf46.NBTUtil.v1_1R1.BukkitVersionUtil;
import skywolf46.NBTUtil.v1_1R1.Interface.IReflectedNBTBase;
import skywolf46.NBTUtil.v1_1R2.BukkitVersionUtil;
import skywolf46.NBTUtil.v1_1R2.Interface.IReflectedNBTBase;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package skywolf46.NBTUtil.v1_1R1.NBTData;
package skywolf46.NBTUtil.v1_1R2.NBTData;

import skywolf46.NBTUtil.v1_1R1.BukkitVersionUtil;
import skywolf46.NBTUtil.v1_1R1.Interface.IReflectedNBTBase;
import skywolf46.NBTUtil.v1_1R2.BukkitVersionUtil;
import skywolf46.NBTUtil.v1_1R2.Interface.IReflectedNBTBase;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package skywolf46.NBTUtil.v1_1R1.NBTData;
package skywolf46.NBTUtil.v1_1R2.NBTData;

import skywolf46.NBTUtil.v1_1R1.BukkitVersionUtil;
import skywolf46.NBTUtil.v1_1R1.Interface.IReflectedNBTBase;
import skywolf46.NBTUtil.v1_1R2.BukkitVersionUtil;
import skywolf46.NBTUtil.v1_1R2.Interface.IReflectedNBTBase;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package skywolf46.NBTUtil.v1_1R1;
package skywolf46.NBTUtil.v1_1R2;

import skywolf46.NBTUtil.v1_1R1.Interface.IReflectedNBTBase;
import skywolf46.NBTUtil.v1_1R1.NBTData.*;
import skywolf46.NBTUtil.v1_1R2.Interface.IReflectedNBTBase;
import skywolf46.NBTUtil.v1_1R2.NBTData.*;

import java.util.HashMap;
import java.util.function.Function;
Expand Down

0 comments on commit f06a812

Please sign in to comment.