Fixes to DataTag and small improvements to UI
This commit is contained in:
		
							parent
							
								
									306f20cd88
								
							
						
					
					
						commit
						3bc7dcdf44
					
				
							
								
								
									
										24
									
								
								build.gradle
									
									
									
									
									
								
							
							
						
						
									
										24
									
								
								build.gradle
									
									
									
									
									
								
							@ -21,6 +21,28 @@ repositories {
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
task srcJar(type: Jar) {
 | 
			
		||||
    from sourceSets.main.allSource
 | 
			
		||||
    classifier = 'sources'
 | 
			
		||||
   	from {
 | 
			
		||||
  	configurations.compile.collect { 
 | 
			
		||||
  		it.isDirectory() ? it : zipTree(it)
 | 
			
		||||
  	}
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
artifacts {
 | 
			
		||||
    archives srcJar
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
jar{
 | 
			
		||||
  from {
 | 
			
		||||
  	configurations.compile.collect { 
 | 
			
		||||
  		it.isDirectory() ? it : zipTree(it)
 | 
			
		||||
  	}
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
dependencies {
 | 
			
		||||
	//LWJGL 3
 | 
			
		||||
	compile platform("org.lwjgl:lwjgl-bom:$lwjglVersion")
 | 
			
		||||
@ -42,5 +64,5 @@ dependencies {
 | 
			
		||||
	compile 'com.google.code.gson:gson:2.8.6'
 | 
			
		||||
	
 | 
			
		||||
	//Primitive Collections
 | 
			
		||||
	compile 'de.speiger:Primitive-Collections:0.3.4'
 | 
			
		||||
	compile 'de.speiger:Primitive-Collections:0.3.5'
 | 
			
		||||
}
 | 
			
		||||
@ -11,6 +11,7 @@ import speiger.src.coreengine.rendering.gui.base.IKeyComponent;
 | 
			
		||||
import speiger.src.coreengine.rendering.gui.helper.Align;
 | 
			
		||||
import speiger.src.coreengine.rendering.gui.helper.box.IGuiBox;
 | 
			
		||||
import speiger.src.coreengine.rendering.gui.helper.constrains.ComponentConstrains;
 | 
			
		||||
import speiger.src.coreengine.rendering.gui.helper.constrains.Constrain;
 | 
			
		||||
import speiger.src.coreengine.rendering.gui.renderer.FontRenderer;
 | 
			
		||||
import speiger.src.coreengine.rendering.gui.renderer.UIRenderer;
 | 
			
		||||
import speiger.src.coreengine.rendering.input.events.MouseEvent;
 | 
			
		||||
@ -70,6 +71,16 @@ public abstract class GuiBase
 | 
			
		||||
		return addComponent(id, comp, null);
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	public <T extends GuiComponent> T addComponent(T comp, Constrain xPos, Constrain yPos, Constrain width, Constrain height)
 | 
			
		||||
	{
 | 
			
		||||
		return addComponent(comp, new ComponentConstrains(xPos, yPos, width, height));
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	public <T extends GuiComponent> T addComponent(int id, T comp, Constrain xPos, Constrain yPos, Constrain width, Constrain height)
 | 
			
		||||
	{
 | 
			
		||||
		return addComponent(id, comp, new ComponentConstrains(xPos, yPos, width, height));
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	public abstract <T extends GuiComponent> T addComponent(T comp, ComponentConstrains contrains);
 | 
			
		||||
	
 | 
			
		||||
	public abstract <T extends GuiComponent> T addComponent(int id, T comp, ComponentConstrains contrains);
 | 
			
		||||
 | 
			
		||||
@ -462,6 +462,11 @@ public abstract class GuiComponent extends FlagHolder
 | 
			
		||||
		return getGui().centerComponent(component);
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	public <T extends GuiComponent> T center()
 | 
			
		||||
	{
 | 
			
		||||
		return getGui().centerComponent(this).cast();
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	public <T extends GuiComponent> T addChild(T comp)
 | 
			
		||||
	{
 | 
			
		||||
		return addChild(comp, null);
 | 
			
		||||
 | 
			
		||||
@ -0,0 +1,76 @@
 | 
			
		||||
package speiger.src.coreengine.rendering.gui.components.tree;
 | 
			
		||||
 | 
			
		||||
import speiger.src.coreengine.rendering.gui.GuiComponent;
 | 
			
		||||
import speiger.src.coreengine.rendering.gui.base.IButtonComponent;
 | 
			
		||||
 | 
			
		||||
public class BaseClickableTreeEntry extends BaseTreeEntry implements IButtonComponent
 | 
			
		||||
{
 | 
			
		||||
	
 | 
			
		||||
	@Override
 | 
			
		||||
	public boolean isComponentColliding(int mouseX, int mouseY)
 | 
			
		||||
	{
 | 
			
		||||
		for(int i = 0,m=components.size();i<m;i++)
 | 
			
		||||
		{
 | 
			
		||||
			GuiComponent comp = components.get(i);
 | 
			
		||||
			if(comp instanceof IButtonComponent && ((IButtonComponent)comp).isComponentColliding(mouseX, mouseY)) return true;
 | 
			
		||||
		}
 | 
			
		||||
		return false;
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	@Override
 | 
			
		||||
	public boolean onClick(int button, int mouseX, int mouseY)
 | 
			
		||||
	{
 | 
			
		||||
		for(int i = 0,m=components.size();i<m;i++)
 | 
			
		||||
		{
 | 
			
		||||
			GuiComponent comp = components.get(i);
 | 
			
		||||
			if(!(comp instanceof IButtonComponent)) continue;
 | 
			
		||||
			IButtonComponent btn = (IButtonComponent)comp;
 | 
			
		||||
			if(btn.isComponentColliding(mouseX, mouseY) && btn.onClick(button, mouseX, mouseY)) return true;
 | 
			
		||||
		}
 | 
			
		||||
		return false;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	@Override
 | 
			
		||||
	public boolean onDrag(int mouseX, int mouseY)
 | 
			
		||||
	{
 | 
			
		||||
		for(int i = 0,m=components.size();i<m;i++)
 | 
			
		||||
		{
 | 
			
		||||
			GuiComponent comp = components.get(i);
 | 
			
		||||
			if(comp instanceof IButtonComponent && ((IButtonComponent)comp).onDrag(mouseX, mouseY)) return true;
 | 
			
		||||
		}
 | 
			
		||||
		return false;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	@Override
 | 
			
		||||
	public void onRelease(int button, int mouseX, int mouseY)
 | 
			
		||||
	{
 | 
			
		||||
		for(int i = 0,m=components.size();i<m;i++)
 | 
			
		||||
		{
 | 
			
		||||
			GuiComponent comp = components.get(i);
 | 
			
		||||
			if(comp instanceof IButtonComponent)
 | 
			
		||||
			{
 | 
			
		||||
				IButtonComponent btn = (IButtonComponent)comp;
 | 
			
		||||
				if(btn.isComponentColliding(mouseX, mouseY))
 | 
			
		||||
				{
 | 
			
		||||
					btn.onRelease(button, mouseX, mouseY);
 | 
			
		||||
					return;
 | 
			
		||||
				}
 | 
			
		||||
				btn.onFocusLost();
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	@Override
 | 
			
		||||
	public boolean onScroll(int scroll, int mouseX, int mouseY)
 | 
			
		||||
	{
 | 
			
		||||
		for(int i = 0,m=components.size();i<m;i++)
 | 
			
		||||
		{
 | 
			
		||||
			GuiComponent comp = components.get(i);
 | 
			
		||||
			if(!(comp instanceof IButtonComponent)) continue;
 | 
			
		||||
			IButtonComponent btn = (IButtonComponent)comp;
 | 
			
		||||
			if(btn.isComponentColliding(mouseX, mouseY) && btn.onScroll(scroll, mouseX, mouseY)) return true;
 | 
			
		||||
		}
 | 
			
		||||
		return false;
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
}
 | 
			
		||||
@ -0,0 +1,6 @@
 | 
			
		||||
package speiger.src.coreengine.utils.functions;
 | 
			
		||||
 | 
			
		||||
public interface IntObjectObjectFunction<T, V>
 | 
			
		||||
{
 | 
			
		||||
	public V apply(int k, T v);
 | 
			
		||||
}
 | 
			
		||||
@ -106,7 +106,7 @@ public class DataTagParser
 | 
			
		||||
				throw new IOException("Expected Key at " + last);
 | 
			
		||||
			}
 | 
			
		||||
			requirePresent(':');
 | 
			
		||||
			map.setTag(s, readTag());
 | 
			
		||||
			map.putTag(s, readTag());
 | 
			
		||||
			reader.skipEmpty();
 | 
			
		||||
			if(!reader.isPresent(','))
 | 
			
		||||
			{
 | 
			
		||||
 | 
			
		||||
@ -1,5 +1,6 @@
 | 
			
		||||
package speiger.src.coreengine.utils.io.dataTag.special;
 | 
			
		||||
 | 
			
		||||
import java.util.Arrays;
 | 
			
		||||
import java.util.UUID;
 | 
			
		||||
 | 
			
		||||
import speiger.src.coreengine.utils.io.dataTag.DataTag;
 | 
			
		||||
@ -23,97 +24,93 @@ import speiger.src.coreengine.utils.io.dataTag.simple.StringTag;
 | 
			
		||||
 | 
			
		||||
public interface IMapTag extends DataTag
 | 
			
		||||
{
 | 
			
		||||
	public void setTag(String id, DataTag tag);
 | 
			
		||||
	public default void setList(String id, ListTag tag) { if(!tag.isEmpty()) setTag(id, tag); }
 | 
			
		||||
	public default void setMap(String id, MapTag tag) { if(!tag.isEmpty()) setTag(id, tag); }
 | 
			
		||||
	public void putTag(String id, DataTag tag);
 | 
			
		||||
	public default void putList(String id, ListTag tag) { if(!tag.isEmpty()) putTag(id, tag); }
 | 
			
		||||
	public default void putMap(String id, MapTag tag) { if(!tag.isEmpty()) putTag(id, tag); }
 | 
			
		||||
	
 | 
			
		||||
	public default void setBoolean(String id, boolean value) {setByte(id, (byte)(value ? 1 : 0), (byte)0);}
 | 
			
		||||
	public default void setByte(String id, byte value) {setByte(id, value, (byte)0);}
 | 
			
		||||
	public default void setByte(String id, byte value, byte defaultValue)
 | 
			
		||||
	{
 | 
			
		||||
		if(value != defaultValue)
 | 
			
		||||
		{
 | 
			
		||||
			setTag(id, new ByteTag(value));
 | 
			
		||||
		}
 | 
			
		||||
	public default void putBoolean(String id, boolean value) {putByte(id, (byte)(value ? 1 : 0), (byte)0);}
 | 
			
		||||
	public default void putBoolean(String id, boolean value, boolean defaultValue) {putByte(id, (byte)(value ? 1 : 0), (byte)(defaultValue ? 1 : 0));}
 | 
			
		||||
	public default void putByte(String id, byte value) {putByte(id, value, (byte)0);}
 | 
			
		||||
	public default void putByte(String id, byte value, byte defaultValue) {
 | 
			
		||||
		if(value != defaultValue) putTag(id, new ByteTag(value));
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	public default void setShort(String id, short value) {setShort(id, value, (short)0);}
 | 
			
		||||
	public default void setShort(String id, short value, short defaultValue)
 | 
			
		||||
	{
 | 
			
		||||
		if(value != defaultValue)
 | 
			
		||||
		{
 | 
			
		||||
			setTag(id, new ShortTag(value));
 | 
			
		||||
		}
 | 
			
		||||
	public default void putShort(String id, short value) {putShort(id, value, (short)0);}
 | 
			
		||||
	public default void putShort(String id, short value, short defaultValue) {
 | 
			
		||||
		if(value != defaultValue) putTag(id, new ShortTag(value));
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	public default void setMedium(String id, int value) {setMedium(id, value, 0);}
 | 
			
		||||
	public default void setMedium(String id, int value, int defaultValue)
 | 
			
		||||
	{
 | 
			
		||||
		if(value != defaultValue)
 | 
			
		||||
		{
 | 
			
		||||
			setTag(id, new MediumTag(value));
 | 
			
		||||
		}
 | 
			
		||||
	public default void putMedium(String id, int value) {putMedium(id, value, 0);}
 | 
			
		||||
	public default void putMedium(String id, int value, int defaultValue) {
 | 
			
		||||
		if(value != defaultValue) putTag(id, new MediumTag(value));
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	public default void setInt(String id, int value) {setInt(id, value, 0);}
 | 
			
		||||
	public default void setInt(String id, int value, int defaultValue)
 | 
			
		||||
	{
 | 
			
		||||
		if(value != defaultValue)
 | 
			
		||||
		{
 | 
			
		||||
			setTag(id, new IntTag(value));
 | 
			
		||||
		}
 | 
			
		||||
	public default void putInt(String id, int value) {putInt(id, value, 0);}
 | 
			
		||||
	public default void putInt(String id, int value, int defaultValue) {
 | 
			
		||||
		if(value != defaultValue) putTag(id, new IntTag(value));
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	public default void setLong(String id, long value) {setLong(id, value, 0L);}
 | 
			
		||||
	public default void setLong(String id, long value, long defaultValue)
 | 
			
		||||
	{
 | 
			
		||||
		if(value != defaultValue)
 | 
			
		||||
		{
 | 
			
		||||
			setTag(id, new LongTag(value));
 | 
			
		||||
		}
 | 
			
		||||
	public default void putLong(String id, long value) {putLong(id, value, 0L);}
 | 
			
		||||
	public default void putLong(String id, long value, long defaultValue) {
 | 
			
		||||
		if(value != defaultValue) putTag(id, new LongTag(value));
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	public default void setFloat(String id, float value) {setFloat(id, value, 0F);}
 | 
			
		||||
	public default void setFloat(String id, float value, float defaultValue)
 | 
			
		||||
	{
 | 
			
		||||
		if(value != defaultValue)
 | 
			
		||||
		{
 | 
			
		||||
			setTag(id, new FloatTag(value));
 | 
			
		||||
		}
 | 
			
		||||
	public default void putFloat(String id, float value) {putFloat(id, value, 0F);}
 | 
			
		||||
	public default void putFloat(String id, float value, float defaultValue) {
 | 
			
		||||
		if(Float.floatToIntBits(value) == Float.floatToIntBits(defaultValue)) putTag(id, new FloatTag(value));
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	public default void setDouble(String id, double value) {setDouble(id, value, 0D);}
 | 
			
		||||
	public default void setDouble(String id, double value, double defaultValue)
 | 
			
		||||
	{
 | 
			
		||||
		if(value != defaultValue)
 | 
			
		||||
		{
 | 
			
		||||
			setTag(id, new DoubleTag(value));
 | 
			
		||||
		}
 | 
			
		||||
	public default void putDouble(String id, double value) {putDouble(id, value, 0D);}
 | 
			
		||||
	public default void putDouble(String id, double value, double defaultValue) {
 | 
			
		||||
		if(Double.doubleToLongBits(value) == Double.doubleToLongBits(defaultValue)) putTag(id, new DoubleTag(value));
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	public default void setString(String id, String value) {setString(id, value, "");}
 | 
			
		||||
	public default void setString(String id, String value, String defaultValue)
 | 
			
		||||
	{
 | 
			
		||||
		if(!value.equals(defaultValue))
 | 
			
		||||
		{
 | 
			
		||||
			setTag(id, new StringTag(value));
 | 
			
		||||
		}
 | 
			
		||||
	public default void putString(String id, String value) {putString(id, value, "");}
 | 
			
		||||
	public default void putString(String id, String value, String defaultValue) {
 | 
			
		||||
		if(!value.equals(defaultValue)) putTag(id, new StringTag(value));
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	public default void setByteArray(String id, byte[] data) {if(data.length > 0){setTag(id, new ByteArrayTag(data));}}
 | 
			
		||||
	public default void setShortArray(String id, short[] data) {if(data.length > 0){setTag(id, new ShortArrayTag(data));}}
 | 
			
		||||
	public default void setMediumArray(String id, int[] data) {if(data.length > 0){setTag(id, new MediumArrayTag(data));}}
 | 
			
		||||
	public default void setIntArray(String id, int[] data) {if(data.length > 0){setTag(id, new IntArrayTag(data));}}
 | 
			
		||||
	public default void setLongArray(String id, long[] data) {if(data.length > 0){setTag(id, new LongArrayTag(data));}}
 | 
			
		||||
	public default void setFloatArray(String id, float[] data) {if(data.length > 0){setTag(id, new FloatArrayTag(data));}}
 | 
			
		||||
	public default void setDoubleArray(String id, double[] data) {if(data.length > 0){setTag(id, new DoubleArrayTag(data));}}
 | 
			
		||||
	public default void setStringArray(String id, String[] data) {if(data.length > 0){setTag(id, new StringArrayTag(data));}}
 | 
			
		||||
	public default void putByteArray(String id, byte[] data) {if(data.length > 0){putTag(id, new ByteArrayTag(data));}}
 | 
			
		||||
	public default void putByteArray(String id, byte[] data, byte[] defaultValue) {if(!Arrays.equals(data, defaultValue)){putTag(id, new ByteArrayTag(data));}}
 | 
			
		||||
	public default void putShortArray(String id, short[] data) {if(data.length > 0){putTag(id, new ShortArrayTag(data));}}
 | 
			
		||||
	public default void putShortArray(String id, short[] data, short[] defaultValue) {if(!Arrays.equals(data, defaultValue)){putTag(id, new ShortArrayTag(data));}}
 | 
			
		||||
	public default void putMediumArray(String id, int[] data) {if(data.length > 0){putTag(id, new MediumArrayTag(data));}}
 | 
			
		||||
	public default void putMediumArray(String id, int[] data, int[] defaultValue) {if(!Arrays.equals(data, defaultValue)){putTag(id, new MediumArrayTag(data));}}
 | 
			
		||||
	public default void putIntArray(String id, int[] data) {if(data.length > 0){putTag(id, new IntArrayTag(data));}}
 | 
			
		||||
	public default void putIntArray(String id, int[] data, int[] defaultValue) {if(!Arrays.equals(data, defaultValue)){putTag(id, new IntArrayTag(data));}}
 | 
			
		||||
	public default void putLongArray(String id, long[] data) {if(data.length > 0){putTag(id, new LongArrayTag(data));}}
 | 
			
		||||
	public default void putLongArray(String id, long[] data, long[] defaultValue) {if(!Arrays.equals(data, defaultValue)){putTag(id, new LongArrayTag(data));}}
 | 
			
		||||
	public default void putFloatArray(String id, float[] data) {if(data.length > 0){putTag(id, new FloatArrayTag(data));}}
 | 
			
		||||
	public default void putFloatArray(String id, float[] data, float[] defaultValue) {if(!Arrays.equals(data, defaultValue)){putTag(id, new FloatArrayTag(data));}}
 | 
			
		||||
	public default void putDoubleArray(String id, double[] data) {if(data.length > 0){putTag(id, new DoubleArrayTag(data));}}
 | 
			
		||||
	public default void putDoubleArray(String id, double[] data, double[] defaultValue) {if(!Arrays.equals(data, defaultValue)){putTag(id, new DoubleArrayTag(data));}}
 | 
			
		||||
	public default void putStringArray(String id, String[] data) {if(data.length > 0){putTag(id, new StringArrayTag(data));}}
 | 
			
		||||
	public default void putStringArray(String id, String[] data, String[] defaultValue) {if(!Arrays.equals(data, defaultValue)){putTag(id, new StringArrayTag(data));}}
 | 
			
		||||
	
 | 
			
		||||
	public default void setUUID(String id, UUID data) { if(data != null) setLongArray(id, new long[]{data.getMostSignificantBits(), data.getLeastSignificantBits()});}
 | 
			
		||||
	public default void putUUID(String id, UUID data) { if(data != null) putLongArray(id, new long[]{data.getMostSignificantBits(), data.getLeastSignificantBits()});}
 | 
			
		||||
	
 | 
			
		||||
	public default <T extends Enum<T>> void putEnum(String id, T value)
 | 
			
		||||
	{
 | 
			
		||||
		int index = value == null ? 0 : value.ordinal()+1;
 | 
			
		||||
		if(index == 0) return;
 | 
			
		||||
		if(index < Byte.MAX_VALUE) putByte(id, (byte)index);
 | 
			
		||||
		else if(index < Short.MAX_VALUE) putShort(id, (short)index);
 | 
			
		||||
		else putInt(id, index);
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	public default <T extends Enum<T>> void putEnum(String id, T value, T defaultValue)
 | 
			
		||||
	{
 | 
			
		||||
		if(value == defaultValue || value == null) return;
 | 
			
		||||
		int index = value.ordinal()+1;
 | 
			
		||||
		if(index < Byte.MAX_VALUE) putByte(id, (byte)index);
 | 
			
		||||
		else if(index < Short.MAX_VALUE) putShort(id, (short)index);
 | 
			
		||||
		else putInt(id, index);
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	public DataTag get(String id);
 | 
			
		||||
	
 | 
			
		||||
	public default boolean getBoolean(String id) { return getByte(id, (byte)0) != 0;}
 | 
			
		||||
	public default boolean getBoolean(String id, boolean defaultValue) { return getByte(id, (byte)(defaultValue ? 1 : 0)) != 0;}
 | 
			
		||||
	public default byte getByte(String id) {return getByte(id, (byte)0);}
 | 
			
		||||
	public default byte getByte(String id, byte defaultValue)
 | 
			
		||||
	{
 | 
			
		||||
@ -160,7 +157,7 @@ public interface IMapTag extends DataTag
 | 
			
		||||
	public default double getDouble(String id, double defaultValue)
 | 
			
		||||
	{
 | 
			
		||||
		DataTag tag = get(id);
 | 
			
		||||
		return isPrimitve(tag) ? ((PrimitiveTag)tag).asByte() : defaultValue;
 | 
			
		||||
		return isPrimitve(tag) ? ((PrimitiveTag)tag).asDouble() : defaultValue;
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	public default String getString(String id) {return getString(id, "");}
 | 
			
		||||
@ -170,52 +167,60 @@ public interface IMapTag extends DataTag
 | 
			
		||||
		return isType(tag, 8) ? ((StringTag)tag).get() : defaultValue;
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	public default byte[] getByteArray(String id)
 | 
			
		||||
	public default byte[] getByteArray(String id) { return getByteArray(id, Defaults.EMPTY_BYTE); }
 | 
			
		||||
	public default byte[] getByteArray(String id, byte[] defaultValue)
 | 
			
		||||
	{
 | 
			
		||||
		DataTag tag = get(id);
 | 
			
		||||
		return isType(tag, 9) ? ((ByteArrayTag)tag).get() : new byte[0];
 | 
			
		||||
		return isType(tag, 9) ? ((ByteArrayTag)tag).get() : defaultValue;
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	public default short[] getShortArray(String id)
 | 
			
		||||
	public default short[] getShortArray(String id) { return getShortArray(id, Defaults.EMPTY_SHORT); }
 | 
			
		||||
	public default short[] getShortArray(String id, short[] defaultValue)
 | 
			
		||||
	{
 | 
			
		||||
		DataTag tag = get(id);
 | 
			
		||||
		return isType(tag, 10) ? ((ShortArrayTag)tag).get() : new short[0];
 | 
			
		||||
		return isType(tag, 10) ? ((ShortArrayTag)tag).get() : defaultValue;
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	public default int[] getMediumArray(String id)
 | 
			
		||||
	public default int[] getMediumArray(String id) { return getMediumArray(id, Defaults.EMPTY_INT); }
 | 
			
		||||
	public default int[] getMediumArray(String id, int[] defaultValue)
 | 
			
		||||
	{
 | 
			
		||||
		DataTag tag = get(id);
 | 
			
		||||
		return isType(tag, 11) ? ((MediumArrayTag)tag).get() : new int[0];
 | 
			
		||||
		return isType(tag, 11) ? ((MediumArrayTag)tag).get() : defaultValue;
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	public default int[] getIntArray(String id)
 | 
			
		||||
	public default int[] getIntArray(String id) { return getIntArray(id, Defaults.EMPTY_INT); }
 | 
			
		||||
	public default int[] getIntArray(String id, int[] defaultValue)
 | 
			
		||||
	{
 | 
			
		||||
		DataTag tag = get(id);
 | 
			
		||||
		return isType(tag, 12) ? ((IntArrayTag)tag).get() : new int[0];
 | 
			
		||||
		return isType(tag, 12) ? ((IntArrayTag)tag).get() : defaultValue;
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	public default long[] getLongArray(String id)
 | 
			
		||||
	public default long[] getLongArray(String id) { return getLongArray(id, Defaults.EMPTY_LONG); }
 | 
			
		||||
	public default long[] getLongArray(String id, long[] defaultValue)
 | 
			
		||||
	{
 | 
			
		||||
		DataTag tag = get(id);
 | 
			
		||||
		return isType(tag, 13) ? ((LongArrayTag)tag).get() : new long[0];
 | 
			
		||||
		return isType(tag, 13) ? ((LongArrayTag)tag).get() : defaultValue;
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	public default float[] getFloatArray(String id)
 | 
			
		||||
	public default float[] getFloatArray(String id) { return getFloatArray(id, Defaults.EMPTY_FLOAT); }
 | 
			
		||||
	public default float[] getFloatArray(String id, float[] defaultValue)
 | 
			
		||||
	{
 | 
			
		||||
		DataTag tag = get(id);
 | 
			
		||||
		return isType(tag, 14) ? ((FloatArrayTag)tag).get() : new float[0];
 | 
			
		||||
		return isType(tag, 14) ? ((FloatArrayTag)tag).get() : defaultValue;
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	public default double[] getDoubleArray(String id)
 | 
			
		||||
	public default double[] getDoubleArray(String id) { return getDoubleArray(id, Defaults.EMPTY_DOUBLE); }
 | 
			
		||||
	public default double[] getDoubleArray(String id, double[] defaultValue)
 | 
			
		||||
	{
 | 
			
		||||
		DataTag tag = get(id);
 | 
			
		||||
		return isType(tag, 15) ? ((DoubleArrayTag)tag).get() : new double[0];
 | 
			
		||||
		return isType(tag, 15) ? ((DoubleArrayTag)tag).get() : defaultValue;
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	public default String[] getStringArray(String id)
 | 
			
		||||
	public default String[] getStringArray(String id) { return getStringArray(id, Defaults.EMPTY_STRING); }
 | 
			
		||||
	public default String[] getStringArray(String id, String[] defaultValue)
 | 
			
		||||
	{
 | 
			
		||||
		DataTag tag = get(id);
 | 
			
		||||
		return isType(tag, 16) ? ((StringArrayTag)tag).get() : new String[0];
 | 
			
		||||
		return isType(tag, 16) ? ((StringArrayTag)tag).get() : defaultValue;
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	public default UUID getUUID(String id)
 | 
			
		||||
@ -224,6 +229,18 @@ public interface IMapTag extends DataTag
 | 
			
		||||
		return data == null || data.length != 2 ? null : new UUID(data[0], data[1]);
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	public default <T extends Enum<T>> T getEnum(String id, Class<T> clz)
 | 
			
		||||
	{
 | 
			
		||||
		int value = getInt(id);
 | 
			
		||||
		return value == 0 ? null : clz.getEnumConstants()[value-1];
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	public default <T extends Enum<T>> T getEnum(String id, Class<T> clz, T defaultValue)
 | 
			
		||||
	{
 | 
			
		||||
		int value = getInt(id);
 | 
			
		||||
		return value == 0 ? defaultValue : clz.getEnumConstants()[value-1];
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	public default MapTag getMap(String id)
 | 
			
		||||
	{
 | 
			
		||||
		DataTag tag = get(id);
 | 
			
		||||
@ -246,4 +263,15 @@ public interface IMapTag extends DataTag
 | 
			
		||||
	{
 | 
			
		||||
		return (tag == null ? 0 : tag.getId()) == type;
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	static class Defaults
 | 
			
		||||
	{
 | 
			
		||||
		private static final byte[] EMPTY_BYTE = new byte[0];
 | 
			
		||||
		private static final short[] EMPTY_SHORT = new short[0];
 | 
			
		||||
		private static final int[] EMPTY_INT = new int[0];
 | 
			
		||||
		private static final long[] EMPTY_LONG = new long[0];
 | 
			
		||||
		private static final float[] EMPTY_FLOAT = new float[0];
 | 
			
		||||
		private static final double[] EMPTY_DOUBLE = new double[0];
 | 
			
		||||
		private static final String[] EMPTY_STRING = new String[0];
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
@ -105,8 +105,9 @@ public class MapTag implements IMapTag
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	@Override
 | 
			
		||||
	public void setTag(String id, DataTag tag)
 | 
			
		||||
	public void putTag(String id, DataTag tag)
 | 
			
		||||
	{
 | 
			
		||||
		if(tag == null) return;
 | 
			
		||||
		tags.put(id, tag);
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user