mirror of
https://github.com/GTNewHorizons/CraftTweaker.git
synced 2026-11-19 11:49:05 +00:00
- Refactored code into different packages
- Fixed some non-static expansion methods - Fixed scripts not reloading properly - Implemented mod support build system - Fixed recipe removal breaking on recipes without predefined output - Fixed NPE on parsing a bracket expression that doesn't exist - now prints an appropriate error
This commit is contained in:
1 parent
1789aa74b5
commit
2de467d7d8
93 files changed
+321
-262
No files matched your search
@@ -0,0 +1,187 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.api.data;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class DataBool implements IData {
|
||||
private final boolean value;
|
||||
|
||||
public DataBool(boolean value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean asBool() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte asByte() {
|
||||
return (byte) (value ? 1 : 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public short asShort() {
|
||||
return (short) (value ? 1 : 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int asInt() {
|
||||
return value ? 1 : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long asLong() {
|
||||
return value ? 1 : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float asFloat() {
|
||||
return value ? 1 : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double asDouble() {
|
||||
return value ? 1 : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String asString() {
|
||||
return Boolean.toString(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IData> asList() {
|
||||
throw new UnsupportedOperationException("Cannot cast a bool to a list");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, IData> asMap() {
|
||||
throw new UnsupportedOperationException("Cannot cast a bool to a map");
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] asByteArray() {
|
||||
throw new RuntimeException("cannot cast a bool to a byte array");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] asIntArray() {
|
||||
throw new RuntimeException("cannot cast a bool to an int array");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData getAt(int i) {
|
||||
throw new RuntimeException("a bool is not indexable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAt(int i, IData value) {
|
||||
throw new RuntimeException("a bool is not indexable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData memberGet(String name) {
|
||||
throw new RuntimeException("a bool is not indexable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void memberSet(String name, IData data) {
|
||||
throw new RuntimeException("a bool is not indexable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int length() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(IData data) {
|
||||
return data.asBool() == value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(IData other) {
|
||||
return value == other.asBool();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot compare bool values");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData immutable() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData update(IData data) {
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T convert(IDataConverter<T> converter) {
|
||||
return converter.fromBool(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData add(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot add bool values");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData sub(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot subtract bool values");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData mul(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot multiply bool values");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData div(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot divide bool values");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData mod(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot perform modulo on bool values");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData and(IData other) {
|
||||
return new DataBool(value & other.asBool());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData or(IData other) {
|
||||
return new DataBool(value | other.asBool());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData xor(IData other) {
|
||||
return new DataBool(value ^ other.asBool());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData neg() {
|
||||
throw new UnsupportedOperationException("Cannot negate a bool value");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData not() {
|
||||
return new DataBool(!value);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,187 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.api.data;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class DataByte implements IData {
|
||||
private final byte value;
|
||||
|
||||
public DataByte(byte value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean asBool() {
|
||||
throw new RuntimeException("Cannot cast a byte to a bool");
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte asByte() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public short asShort() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int asInt() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long asLong() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float asFloat() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double asDouble() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String asString() {
|
||||
return Byte.toString(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IData> asList() {
|
||||
throw new UnsupportedOperationException("Cannot convert a byte to a list");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, IData> asMap() {
|
||||
throw new UnsupportedOperationException("Cannot convert a byte to a map");
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] asByteArray() {
|
||||
throw new RuntimeException("Cannot cast a byte to a byte array");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] asIntArray() {
|
||||
throw new RuntimeException("Cannot cast a byte to an int array");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData getAt(int i) {
|
||||
throw new RuntimeException("A byte is not indexable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAt(int i, IData value) {
|
||||
throw new RuntimeException("A byte is not indexable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData memberGet(String name) {
|
||||
throw new RuntimeException("A byte is not indexable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void memberSet(String name, IData data) {
|
||||
throw new RuntimeException("A byte is not indexable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int length() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(IData data) {
|
||||
return data.asByte() == value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(IData data) {
|
||||
return value == data.asByte();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(IData data) {
|
||||
return Byte.compare(value, data.asByte());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData immutable() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData update(IData data) {
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T convert(IDataConverter<T> converter) {
|
||||
return converter.fromByte(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData add(IData other) {
|
||||
return new DataByte((byte) (value + other.asByte()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData sub(IData other) {
|
||||
return new DataByte((byte) (value - other.asByte()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData mul(IData other) {
|
||||
return new DataByte((byte) (value * other.asByte()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData div(IData other) {
|
||||
return new DataByte((byte) (value / other.asByte()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData mod(IData other) {
|
||||
return new DataByte((byte) (value % other.asByte()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData and(IData other) {
|
||||
return new DataByte((byte) (value & other.asByte()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData or(IData other) {
|
||||
return new DataByte((byte) (value | other.asByte()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData xor(IData other) {
|
||||
return new DataByte((byte) (value ^ other.asByte()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData neg() {
|
||||
return new DataByte((byte) (- value));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData not() {
|
||||
return new DataByte((byte) (~ value));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,220 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.api.data;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class DataByteArray implements IData {
|
||||
private final byte[] data;
|
||||
private final boolean immutable;
|
||||
|
||||
public DataByteArray(byte[] data, boolean immutable) {
|
||||
this.data = data;
|
||||
this.immutable = immutable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData add(IData other) {
|
||||
byte[] otherData = other.asByteArray();
|
||||
byte[] result = Arrays.copyOf(data, data.length + otherData.length);
|
||||
System.arraycopy(otherData, 0, result, data.length, otherData.length);
|
||||
return new DataByteArray(result, immutable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData sub(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot subtract from a byte array");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData mul(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot multiply with an arary");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData div(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot divide an array");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData mod(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot perform modulo on an array");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData and(IData other) {
|
||||
throw new UnsupportedOperationException("Arrays don't support bitwise operations");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData or(IData other) {
|
||||
throw new UnsupportedOperationException("Arrays don't support bitwise operations");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData xor(IData other) {
|
||||
throw new UnsupportedOperationException("Arrays don't support bitwise operations");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData neg() {
|
||||
throw new UnsupportedOperationException("Cannot negate arrays");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData not() {
|
||||
throw new UnsupportedOperationException("Arrays don't support bitwise operations");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean asBool() {
|
||||
throw new UnsupportedOperationException("Cannot cast an array to bool");
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte asByte() {
|
||||
throw new UnsupportedOperationException("Cannot cast an array to byte");
|
||||
}
|
||||
|
||||
@Override
|
||||
public short asShort() {
|
||||
throw new UnsupportedOperationException("Cannot cast an array to short");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int asInt() {
|
||||
throw new UnsupportedOperationException("Cannot cast an array to int");
|
||||
}
|
||||
|
||||
@Override
|
||||
public long asLong() {
|
||||
throw new UnsupportedOperationException("Cannot cast an array to long");
|
||||
}
|
||||
|
||||
@Override
|
||||
public float asFloat() {
|
||||
throw new UnsupportedOperationException("Cannot cast an array to float");
|
||||
}
|
||||
|
||||
@Override
|
||||
public double asDouble() {
|
||||
throw new UnsupportedOperationException("Cannot cast an array to double");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String asString() {
|
||||
StringBuilder result = new StringBuilder();
|
||||
result.append("X\"");
|
||||
for (byte value : data) {
|
||||
String str = Integer.toHexString(value);
|
||||
if (str.length() == 1) {
|
||||
result.append('0');
|
||||
}
|
||||
result.append(str);
|
||||
}
|
||||
result.append('"');
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IData> asList() {
|
||||
List<IData> result = new ArrayList<IData>();
|
||||
for (byte value : data) {
|
||||
result.add(new DataByte(value));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, IData> asMap() {
|
||||
throw new UnsupportedOperationException("Cannot convert list to map");
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] asByteArray() {
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] asIntArray() {
|
||||
int[] result = new int[data.length];
|
||||
for (int i = 0; i < result.length; i++) {
|
||||
result[i] = data[i];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData getAt(int i) {
|
||||
return new DataByte(data[i]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAt(int i, IData value) {
|
||||
if (immutable) {
|
||||
throw new UnsupportedOperationException("Cannot modify this byte array");
|
||||
} else {
|
||||
data[i] = value.asByte();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData memberGet(String name) {
|
||||
throw new UnsupportedOperationException("byte[] doesn't have members");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void memberSet(String name, IData data) {
|
||||
throw new UnsupportedOperationException("cannot set byte[] members");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int length() {
|
||||
return data.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(IData data) {
|
||||
return equals(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(IData data) {
|
||||
throw new UnsupportedOperationException("Cannot compare arrays");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(IData data) {
|
||||
return Arrays.equals(this.data, data.asByteArray());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData immutable() {
|
||||
if (immutable) {
|
||||
return this;
|
||||
} else {
|
||||
return new DataByteArray(Arrays.copyOf(this.data, this.data.length), true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData update(IData data) {
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T convert(IDataConverter<T> converter) {
|
||||
return converter.fromByteArray(this.data);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,187 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.api.data;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class DataDouble implements IData {
|
||||
private final double value;
|
||||
|
||||
public DataDouble(double value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean asBool() {
|
||||
throw new RuntimeException("Cannot cast a double to a bool");
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte asByte() {
|
||||
return (byte) value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public short asShort() {
|
||||
return (short) value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int asInt() {
|
||||
return (int) value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long asLong() {
|
||||
return (long) value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float asFloat() {
|
||||
return (float) value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double asDouble() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String asString() {
|
||||
return Double.toString(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IData> asList() {
|
||||
throw new UnsupportedOperationException("Cannot cast a double to a list");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, IData> asMap() {
|
||||
throw new UnsupportedOperationException("Cannot cast a double to a map");
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] asByteArray() {
|
||||
throw new RuntimeException("Cannot cast a double to a byte array");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] asIntArray() {
|
||||
throw new RuntimeException("Cannot cast a double to an int array");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData getAt(int i) {
|
||||
throw new RuntimeException("A double is not indexable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAt(int i, IData value) {
|
||||
throw new RuntimeException("A double is not indexable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData memberGet(String name) {
|
||||
throw new RuntimeException("A double is not indexable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void memberSet(String name, IData data) {
|
||||
throw new RuntimeException("A double is not indexable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int length() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(IData data) {
|
||||
return data.asDouble() == value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(IData other) {
|
||||
return value == other.asDouble();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(IData other) {
|
||||
return Double.compare(value, other.asDouble());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData immutable() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData update(IData data) {
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T convert(IDataConverter<T> converter) {
|
||||
return converter.fromDouble(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData add(IData other) {
|
||||
return new DataDouble(value + other.asDouble());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData sub(IData other) {
|
||||
return new DataDouble(value - other.asDouble());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData mul(IData other) {
|
||||
return new DataDouble(value * other.asDouble());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData div(IData other) {
|
||||
return new DataDouble(value / other.asDouble());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData mod(IData other) {
|
||||
return new DataDouble(value % other.asDouble());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData and(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot perform bitwise operations on double");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData or(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot perform bitwise operations on double");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData xor(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot perform bitwise operations on double");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData neg() {
|
||||
return new DataDouble(- value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData not() {
|
||||
throw new UnsupportedOperationException("Cannot perform bitwise operations on double");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,187 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.api.data;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class DataFloat implements IData {
|
||||
private final float value;
|
||||
|
||||
public DataFloat(float value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean asBool() {
|
||||
throw new RuntimeException("Cannot cast a float to a bool");
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte asByte() {
|
||||
return (byte) value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public short asShort() {
|
||||
return (short) value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int asInt() {
|
||||
return (int) value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long asLong() {
|
||||
return (long) value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float asFloat() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double asDouble() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String asString() {
|
||||
return Float.toString(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IData> asList() {
|
||||
throw new UnsupportedOperationException("Cannot cast a float to a list");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, IData> asMap() {
|
||||
throw new UnsupportedOperationException("Cannot cast a float to a map");
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] asByteArray() {
|
||||
throw new RuntimeException("Cannot cast a float to a byte array");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] asIntArray() {
|
||||
throw new RuntimeException("Cannot cast a float to an int array");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData getAt(int i) {
|
||||
throw new RuntimeException("A float is not indexable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAt(int i, IData value) {
|
||||
throw new RuntimeException("A float is not indexable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData memberGet(String name) {
|
||||
throw new RuntimeException("A float is not indexable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void memberSet(String name, IData data) {
|
||||
throw new RuntimeException("A float is not indexable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int length() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(IData data) {
|
||||
return data.asFloat() == value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(IData data) {
|
||||
return value == data.asFloat();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(IData data) {
|
||||
return Float.compare(value, data.asFloat());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData immutable() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData update(IData data) {
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T convert(IDataConverter<T> converter) {
|
||||
return converter.fromFloat(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData add(IData other) {
|
||||
return new DataFloat(value + other.asFloat());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData sub(IData other) {
|
||||
return new DataFloat(value - other.asFloat());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData mul(IData other) {
|
||||
return new DataFloat(value * other.asFloat());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData div(IData other) {
|
||||
return new DataFloat(value / other.asFloat());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData mod(IData other) {
|
||||
return new DataFloat(value % other.asFloat());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData and(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot perform bitwise operations on float");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData or(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot perform bitwise operations on float");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData xor(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot perform bitwise operations on float");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData neg() {
|
||||
return new DataFloat(- value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData not() {
|
||||
throw new UnsupportedOperationException("Cannot perform bitwise operations on float");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,187 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.api.data;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class DataInt implements IData {
|
||||
private final int value;
|
||||
|
||||
public DataInt(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean asBool() {
|
||||
throw new RuntimeException("Cannot cast an int to a bool");
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte asByte() {
|
||||
return (byte) value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public short asShort() {
|
||||
return (short) value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int asInt() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long asLong() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float asFloat() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double asDouble() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String asString() {
|
||||
return Integer.toString(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IData> asList() {
|
||||
throw new UnsupportedOperationException("Cannot cast an int to a list");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, IData> asMap() {
|
||||
throw new UnsupportedOperationException("Cannot cast an int to a map");
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] asByteArray() {
|
||||
throw new RuntimeException("Cannot cast an int to a byte array");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] asIntArray() {
|
||||
throw new RuntimeException("Cannot cast an int to an int array");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData getAt(int i) {
|
||||
throw new RuntimeException("An int is not indexable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAt(int i, IData value) {
|
||||
throw new RuntimeException("An int is not indexable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData memberGet(String name) {
|
||||
throw new RuntimeException("An int is not indexable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void memberSet(String name, IData data) {
|
||||
throw new RuntimeException("An int is not indexable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int length() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(IData data) {
|
||||
return data.asInt() == value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(IData data) {
|
||||
return value == data.asInt();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(IData data) {
|
||||
return Integer.compare(value, data.asInt());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData immutable() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData update(IData data) {
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T convert(IDataConverter<T> converter) {
|
||||
return converter.fromInt(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData add(IData other) {
|
||||
return new DataInt(value + other.asInt());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData sub(IData other) {
|
||||
return new DataInt(value - other.asInt());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData mul(IData other) {
|
||||
return new DataInt(value * other.asInt());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData div(IData other) {
|
||||
return new DataInt(value / other.asInt());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData mod(IData other) {
|
||||
return new DataInt(value % other.asInt());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData and(IData other) {
|
||||
return new DataInt(value & other.asInt());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData or(IData other) {
|
||||
return new DataInt(value | other.asInt());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData xor(IData other) {
|
||||
return new DataInt(value ^ other.asInt());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData neg() {
|
||||
return new DataInt(- value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData not() {
|
||||
return new DataInt(~ value);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,222 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.api.data;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class DataIntArray implements IData {
|
||||
private final int[] data;
|
||||
private final boolean immutable;
|
||||
|
||||
public DataIntArray(int[] data, boolean immutable) {
|
||||
this.data = data;
|
||||
this.immutable = immutable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData add(IData other) {
|
||||
int[] otherData = other.asIntArray();
|
||||
int[] result = Arrays.copyOf(data, data.length + otherData.length);
|
||||
System.arraycopy(otherData, 0, result, data.length, otherData.length);
|
||||
return new DataIntArray(result, immutable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData sub(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot subtract from an int array");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData mul(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot multiply with an arary");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData div(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot divide an array");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData mod(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot perform modulo on an array");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData and(IData other) {
|
||||
throw new UnsupportedOperationException("Arrays don't support bitwise operations");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData or(IData other) {
|
||||
throw new UnsupportedOperationException("Arrays don't support bitwise operations");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData xor(IData other) {
|
||||
throw new UnsupportedOperationException("Arrays don't support bitwise operations");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData neg() {
|
||||
throw new UnsupportedOperationException("Cannot negate arrays");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData not() {
|
||||
throw new UnsupportedOperationException("Arrays don't support bitwise operations");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean asBool() {
|
||||
throw new UnsupportedOperationException("Cannot cast an array to bool");
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte asByte() {
|
||||
throw new UnsupportedOperationException("Cannot cast an array to byte");
|
||||
}
|
||||
|
||||
@Override
|
||||
public short asShort() {
|
||||
throw new UnsupportedOperationException("Cannot cast an array to short");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int asInt() {
|
||||
throw new UnsupportedOperationException("Cannot cast an array to int");
|
||||
}
|
||||
|
||||
@Override
|
||||
public long asLong() {
|
||||
throw new UnsupportedOperationException("Cannot cast an array to long");
|
||||
}
|
||||
|
||||
@Override
|
||||
public float asFloat() {
|
||||
throw new UnsupportedOperationException("Cannot cast an array to float");
|
||||
}
|
||||
|
||||
@Override
|
||||
public double asDouble() {
|
||||
throw new UnsupportedOperationException("Cannot cast an array to double");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String asString() {
|
||||
StringBuilder result = new StringBuilder();
|
||||
result.append('[');
|
||||
boolean first = true;
|
||||
for (int value : data) {
|
||||
if (first) {
|
||||
first = false;
|
||||
} else {
|
||||
result.append(", ");
|
||||
}
|
||||
result.append(value);
|
||||
}
|
||||
result.append(']');
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IData> asList() {
|
||||
List<IData> result = new ArrayList<IData>();
|
||||
for (int value : data) {
|
||||
result.add(new DataInt(value));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, IData> asMap() {
|
||||
throw new UnsupportedOperationException("Cannot convert list to map");
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] asByteArray() {
|
||||
byte[] result = new byte[data.length];
|
||||
for (int i = 0; i < result.length; i++) {
|
||||
result[i] = (byte) data[i];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] asIntArray() {
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData getAt(int i) {
|
||||
return new DataInt(data[i]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAt(int i, IData value) {
|
||||
if (immutable) {
|
||||
throw new UnsupportedOperationException("Cannot modify this byte array");
|
||||
} else {
|
||||
data[i] = value.asInt();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData memberGet(String name) {
|
||||
throw new UnsupportedOperationException("int[] doesn't have members");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void memberSet(String name, IData data) {
|
||||
throw new UnsupportedOperationException("cannot set int[] members");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int length() {
|
||||
return data.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(IData data) {
|
||||
return equals(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(IData data) {
|
||||
throw new UnsupportedOperationException("Cannot compare arrays");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(IData data) {
|
||||
return Arrays.equals(this.data, data.asIntArray());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData immutable() {
|
||||
if (immutable) {
|
||||
return this;
|
||||
} else {
|
||||
return new DataIntArray(Arrays.copyOf(this.data, this.data.length), true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData update(IData data) {
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T convert(IDataConverter<T> converter) {
|
||||
return converter.fromIntArray(this.data);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,243 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.api.data;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class DataList implements IData {
|
||||
private final List<IData> values;
|
||||
private final boolean immutable;
|
||||
|
||||
public DataList(List<IData> values, boolean immutable) {
|
||||
this.values = values;
|
||||
this.immutable = immutable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean asBool() {
|
||||
throw new RuntimeException("Cannot convert a list to a bool");
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte asByte() {
|
||||
throw new RuntimeException("Cannot convert a list to a byte");
|
||||
}
|
||||
|
||||
@Override
|
||||
public short asShort() {
|
||||
throw new RuntimeException("Cannot convert a list to a short");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int asInt() {
|
||||
throw new RuntimeException("Cannot convert a list to an int");
|
||||
}
|
||||
|
||||
@Override
|
||||
public long asLong() {
|
||||
throw new RuntimeException("Cannot convert a list to a long");
|
||||
}
|
||||
|
||||
@Override
|
||||
public float asFloat() {
|
||||
throw new RuntimeException("Cannot convert a list to a float");
|
||||
}
|
||||
|
||||
@Override
|
||||
public double asDouble() {
|
||||
throw new RuntimeException("Cannot convert a list to a double");
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IData> asList() {
|
||||
if (immutable) {
|
||||
return Collections.unmodifiableList(values);
|
||||
} else {
|
||||
return values;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, IData> asMap() {
|
||||
throw new RuntimeException("Cannot convert a list to a map");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String asString() {
|
||||
StringBuilder output = new StringBuilder();
|
||||
output.append('[');
|
||||
boolean first = true;
|
||||
for (IData value : values) {
|
||||
if (first) {
|
||||
first = false;
|
||||
} else {
|
||||
output.append(", ");
|
||||
}
|
||||
output.append(value.asString());
|
||||
}
|
||||
output.append(']');
|
||||
return output.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] asByteArray() {
|
||||
byte[] result = new byte[values.size()];
|
||||
for (int i = 0; i < values.size(); i++) {
|
||||
result[i] = values.get(i).asByte();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] asIntArray() {
|
||||
int[] result = new int[values.size()];
|
||||
for (int i = 0; i < values.size(); i++) {
|
||||
result[i] = values.get(i).asInt();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData getAt(int i) {
|
||||
return values.get(i);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAt(int i, IData value) {
|
||||
if (immutable) {
|
||||
throw new RuntimeException("this list is immutable");
|
||||
} else {
|
||||
values.set(i, value);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData memberGet(String name) {
|
||||
throw new RuntimeException("Lists don't have members");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void memberSet(String name, IData data) {
|
||||
throw new RuntimeException("Lists don't have members");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int length() {
|
||||
return values.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(IData data) {
|
||||
for (IData value : values) {
|
||||
if (value.equals(data)) return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(IData data) {
|
||||
List<IData> otherValues = data.asList();
|
||||
if (otherValues.size() != values.size()) return false;
|
||||
|
||||
for (int i = 0; i < values.size(); i++) {
|
||||
if (!values.get(i).equals(otherValues.get(i))) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(IData data) {
|
||||
throw new UnsupportedOperationException("Cannot compare with a list");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData immutable() {
|
||||
if (immutable) {
|
||||
return this;
|
||||
} else {
|
||||
List<IData> copy = new ArrayList<IData>();
|
||||
for (IData value : values) {
|
||||
copy.add(value.immutable());
|
||||
}
|
||||
return new DataList(copy, true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData update(IData data) {
|
||||
if (immutable) data = data.immutable();
|
||||
|
||||
List<IData> result = new ArrayList<IData>();
|
||||
result.addAll(values);
|
||||
result.addAll(data.asList());
|
||||
return new DataList(result, immutable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T convert(IDataConverter<T> converter) {
|
||||
return converter.fromList(values);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData add(IData other) {
|
||||
return update(other);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData sub(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot subtract from a list");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData mul(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot multiply a list");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData div(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot divide a list");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData mod(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot perform modulo on a list");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData and(IData other) {
|
||||
throw new UnsupportedOperationException("Lists don't support bitwise operators");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData or(IData other) {
|
||||
throw new UnsupportedOperationException("Lists don't support bitwise operators");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData xor(IData other) {
|
||||
throw new UnsupportedOperationException("Lists don't support bitwise operators");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData neg() {
|
||||
throw new UnsupportedOperationException("Cannot negate a list");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData not() {
|
||||
throw new UnsupportedOperationException("Lists don't support bitwise operators");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,187 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.api.data;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class DataLong implements IData {
|
||||
private final long value;
|
||||
|
||||
public DataLong(long value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean asBool() {
|
||||
throw new RuntimeException("Cannot cast a long to a bool");
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte asByte() {
|
||||
return (byte) value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public short asShort() {
|
||||
return (short) value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int asInt() {
|
||||
return (int) value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long asLong() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float asFloat() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double asDouble() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String asString() {
|
||||
return Long.toString(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IData> asList() {
|
||||
throw new UnsupportedOperationException("Cannot cast a long to a list");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, IData> asMap() {
|
||||
throw new UnsupportedOperationException("Cannot cast a long to a map");
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] asByteArray() {
|
||||
throw new RuntimeException("Cannot cast a long to a byte array");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] asIntArray() {
|
||||
throw new RuntimeException("Cannot cast a long to an int array");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData getAt(int i) {
|
||||
throw new RuntimeException("A long is not indexable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAt(int i, IData value) {
|
||||
throw new RuntimeException("A long is not indexable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData memberGet(String name) {
|
||||
throw new RuntimeException("A long is not indexable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void memberSet(String name, IData data) {
|
||||
throw new RuntimeException("A long is not indexable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int length() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(IData data) {
|
||||
return data.asLong() == value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(IData data) {
|
||||
return value == data.asLong();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(IData data) {
|
||||
return Long.compare(value, data.asLong());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData immutable() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData update(IData data) {
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T convert(IDataConverter<T> converter) {
|
||||
return converter.fromLong(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData add(IData other) {
|
||||
return new DataLong(value + other.asLong());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData sub(IData other) {
|
||||
return new DataLong(value - other.asLong());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData mul(IData other) {
|
||||
return new DataLong(value * other.asLong());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData div(IData other) {
|
||||
return new DataLong(value / other.asLong());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData mod(IData other) {
|
||||
return new DataLong(value % other.asLong());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData and(IData other) {
|
||||
return new DataLong(value & other.asLong());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData or(IData other) {
|
||||
return new DataLong(value | other.asLong());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData xor(IData other) {
|
||||
return new DataLong(value ^ other.asLong());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData neg() {
|
||||
return new DataLong(- value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData not() {
|
||||
return new DataLong(~ value);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,272 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.api.data;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class DataMap implements IData {
|
||||
private final Map<String, IData> data;
|
||||
private final boolean immutable;
|
||||
|
||||
public DataMap(Map<String, IData> data, boolean immutable) {
|
||||
this.data = data;
|
||||
this.immutable = immutable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData add(IData other) {
|
||||
Map<String, IData> result = new HashMap<String, IData>();
|
||||
Map<String, IData> otherMap = other.asMap();
|
||||
|
||||
for (Map.Entry<String, IData> entry : data.entrySet()) {
|
||||
result.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
for (Map.Entry<String, IData> entry : otherMap.entrySet()) {
|
||||
result.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
|
||||
return new DataMap(result, immutable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData sub(IData other) {
|
||||
Map<String, IData> result = new HashMap<String, IData>();
|
||||
Map<String, IData> otherMap = other.asMap();
|
||||
|
||||
for (Map.Entry<String, IData> entry : data.entrySet()) {
|
||||
result.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
for (String key : otherMap.keySet()) {
|
||||
result.remove(key);
|
||||
}
|
||||
|
||||
return new DataMap(result, immutable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData mul(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot multiply maps");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData div(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot divide maps");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData mod(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot perform modulo with maps");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData and(IData other) {
|
||||
throw new UnsupportedOperationException("Maps do not support bitwise operations");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData or(IData other) {
|
||||
throw new UnsupportedOperationException("Maps do not support bitwise operations");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData xor(IData other) {
|
||||
throw new UnsupportedOperationException("Maps do not support bitwise operations");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData neg() {
|
||||
throw new UnsupportedOperationException("Cannot negate maps.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData not() {
|
||||
throw new UnsupportedOperationException("Maps do not support bitwise operations");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean asBool() {
|
||||
throw new UnsupportedOperationException("Cannot cast map to bool");
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte asByte() {
|
||||
throw new UnsupportedOperationException("Cannot cast map to byte");
|
||||
}
|
||||
|
||||
@Override
|
||||
public short asShort() {
|
||||
throw new UnsupportedOperationException("Cannot cast map to short");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int asInt() {
|
||||
throw new UnsupportedOperationException("Cannot cast map to int");
|
||||
}
|
||||
|
||||
@Override
|
||||
public long asLong() {
|
||||
throw new UnsupportedOperationException("Cannot cast map to long");
|
||||
}
|
||||
|
||||
@Override
|
||||
public float asFloat() {
|
||||
throw new UnsupportedOperationException("Cannot cast map to float");
|
||||
}
|
||||
|
||||
@Override
|
||||
public double asDouble() {
|
||||
throw new UnsupportedOperationException("Cannot cast map to double");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String asString() {
|
||||
StringBuilder result = new StringBuilder();
|
||||
result.append('{');
|
||||
boolean first = false;
|
||||
for (Map.Entry<String, IData> entry : data.entrySet()) {
|
||||
if (first) {
|
||||
first = false;
|
||||
} else {
|
||||
result.append(", ");
|
||||
}
|
||||
result.append(entry.getKey());
|
||||
result.append(": ");
|
||||
result.append(entry.getValue().asString());
|
||||
}
|
||||
result.append('}');
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IData> asList() {
|
||||
throw new UnsupportedOperationException("Cannot cast map to list");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, IData> asMap() {
|
||||
if (immutable) {
|
||||
return Collections.unmodifiableMap(data);
|
||||
} else {
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] asByteArray() {
|
||||
throw new UnsupportedOperationException("Cannot cast map to byte[]");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] asIntArray() {
|
||||
throw new UnsupportedOperationException("Cannot cast map to int[]");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData getAt(int i) {
|
||||
throw new UnsupportedOperationException("Cannot index maps with integers");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAt(int i, IData value) {
|
||||
throw new UnsupportedOperationException("Cannot index maps with integers");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData memberGet(String name) {
|
||||
return data.get(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void memberSet(String name, IData data) {
|
||||
if (immutable) {
|
||||
throw new UnsupportedOperationException("this map is not modifiable");
|
||||
} else {
|
||||
this.data.put(name, data);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int length() {
|
||||
return data.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(IData data) {
|
||||
Map<String, IData> dataMap = data.asMap();
|
||||
for (Map.Entry<String, IData> dataEntry : dataMap.entrySet()) {
|
||||
if (!this.data.containsKey(dataEntry.getKey())) {
|
||||
return false;
|
||||
} else if (!this.data.get(dataEntry.getKey()).contains(data)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(IData data) {
|
||||
throw new UnsupportedOperationException("Cannot compare maps");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(IData data) {
|
||||
if (this == data) return true;
|
||||
|
||||
Map<String, IData> dataMap = data.asMap();
|
||||
if (dataMap.size() != this.data.size()) return false;
|
||||
|
||||
for (Map.Entry<String, IData> dataEntry : this.data.entrySet()) {
|
||||
if (!dataMap.containsKey(dataEntry.getKey())) {
|
||||
return false;
|
||||
} else if (!dataMap.get(dataEntry.getKey()).equals(dataEntry.getValue())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData immutable() {
|
||||
if (immutable) {
|
||||
return this;
|
||||
} else {
|
||||
Map<String, IData> result = new HashMap<String, IData>();
|
||||
for (Map.Entry<String, IData> entry : this.data.entrySet()) {
|
||||
result.put(entry.getKey(), entry.getValue().immutable());
|
||||
}
|
||||
return new DataMap(result, true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData update(IData data) {
|
||||
if (immutable) data = data.immutable();
|
||||
|
||||
Map<String, IData> result = new HashMap<String, IData>();
|
||||
for (Map.Entry<String, IData> entry : this.data.entrySet()) {
|
||||
result.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
for (Map.Entry<String, IData> entry : data.asMap().entrySet()) {
|
||||
result.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
return new DataMap(result, immutable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T convert(IDataConverter<T> converter) {
|
||||
return converter.fromMap(data);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,187 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.api.data;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class DataShort implements IData {
|
||||
private final short value;
|
||||
|
||||
public DataShort(short value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean asBool() {
|
||||
throw new RuntimeException("Cannot cast a short to a bool");
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte asByte() {
|
||||
return (byte) value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public short asShort() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int asInt() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long asLong() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float asFloat() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double asDouble() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String asString() {
|
||||
return Short.toString(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IData> asList() {
|
||||
throw new UnsupportedOperationException("Cannot cast a short to a list");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, IData> asMap() {
|
||||
throw new UnsupportedOperationException("Cannot cast a short to a map");
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] asByteArray() {
|
||||
throw new RuntimeException("Cannot cast a short to a byte array");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] asIntArray() {
|
||||
throw new RuntimeException("Cannot cast a short to an int array");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData getAt(int i) {
|
||||
throw new RuntimeException("A short is not indexable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAt(int i, IData value) {
|
||||
throw new RuntimeException("A short is not indexable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData memberGet(String name) {
|
||||
throw new RuntimeException("A short is not indexable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void memberSet(String name, IData data) {
|
||||
throw new RuntimeException("A short is not indexable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int length() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(IData data) {
|
||||
return data.asShort() == value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(IData data) {
|
||||
return value == data.asShort();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(IData data) {
|
||||
return Short.compare(value, data.asShort());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData immutable() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData update(IData data) {
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T convert(IDataConverter<T> converter) {
|
||||
return converter.fromShort(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData add(IData other) {
|
||||
return new DataShort((short) (value + other.asShort()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData sub(IData other) {
|
||||
return new DataShort((short) (value - other.asShort()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData mul(IData other) {
|
||||
return new DataShort((short) (value * other.asShort()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData div(IData other) {
|
||||
return new DataShort((short) (value / other.asShort()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData mod(IData other) {
|
||||
return new DataShort((short) (value % other.asShort()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData and(IData other) {
|
||||
return new DataShort((short) (value & other.asShort()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData or(IData other) {
|
||||
return new DataShort((short) (value | other.asShort()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData xor(IData other) {
|
||||
return new DataShort((short) (value ^ other.asShort()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData neg() {
|
||||
return new DataShort((short) (- value));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData not() {
|
||||
return new DataShort((short) (~ value));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,191 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.api.data;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class DataString implements IData {
|
||||
private final String value;
|
||||
|
||||
public DataString(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean asBool() {
|
||||
return Boolean.parseBoolean(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte asByte() {
|
||||
return Byte.parseByte(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public short asShort() {
|
||||
return Short.parseShort(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int asInt() {
|
||||
return Integer.parseInt(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long asLong() {
|
||||
return Long.parseLong(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float asFloat() {
|
||||
return Float.parseFloat(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double asDouble() {
|
||||
return Double.parseDouble(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String asString() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IData> asList() {
|
||||
throw new UnsupportedOperationException("Cannot cast a string to a list");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, IData> asMap() {
|
||||
throw new UnsupportedOperationException("Cannot cast a string to a map");
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] asByteArray() {
|
||||
throw new RuntimeException("Cannot cast a string to a byte array");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] asIntArray() {
|
||||
throw new RuntimeException("Cannot cast a string to an int array");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData getAt(int i) {
|
||||
return new DataString(value.substring(i, i + 1));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAt(int i, IData value) {
|
||||
throw new RuntimeException("Strings are immutable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData memberGet(String name) {
|
||||
if (name.equals("length")) {
|
||||
return new DataInt(value.length());
|
||||
} else {
|
||||
throw new RuntimeException("no such member: " + name);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void memberSet(String name, IData data) {
|
||||
throw new RuntimeException("Strings are immutable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int length() {
|
||||
return value.length();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(IData data) {
|
||||
return data.asString().equals(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(IData data) {
|
||||
return value.equals(data.asString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(IData data) {
|
||||
return value.compareTo(data.asString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData immutable() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData update(IData data) {
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T convert(IDataConverter<T> converter) {
|
||||
return converter.fromString(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData add(IData other) {
|
||||
return new DataString(value + other.asString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData sub(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot subtract from a string");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData mul(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot multiply a string");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData div(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot divide a string");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData mod(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot perform modulo on a string");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData and(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot perform bitwise arithmetic on a string");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData or(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot perform bitwise arithmetic on a string");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData xor(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot perform bitwise arithmetic on a string");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData neg() {
|
||||
throw new UnsupportedOperationException("Cannot negate a string");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData not() {
|
||||
throw new UnsupportedOperationException("Cannot perform bitwise arithmetic on a string");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.api.data;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import stanhebben.zenscript.annotations.ZenCaster;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenGetter;
|
||||
import stanhebben.zenscript.annotations.ZenMemberGetter;
|
||||
import stanhebben.zenscript.annotations.ZenMemberSetter;
|
||||
import stanhebben.zenscript.annotations.ZenOperator;
|
||||
import stanhebben.zenscript.annotations.OperatorType;
|
||||
import stanhebben.zenscript.annotations.ZenMethod;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.data.IData")
|
||||
public interface IData {
|
||||
@ZenOperator(OperatorType.ADD)
|
||||
public IData add(IData other);
|
||||
|
||||
@ZenOperator(OperatorType.SUB)
|
||||
public IData sub(IData other);
|
||||
|
||||
@ZenOperator(OperatorType.MUL)
|
||||
public IData mul(IData other);
|
||||
|
||||
@ZenOperator(OperatorType.DIV)
|
||||
public IData div(IData other);
|
||||
|
||||
@ZenOperator(OperatorType.MOD)
|
||||
public IData mod(IData other);
|
||||
|
||||
@ZenOperator(OperatorType.AND)
|
||||
public IData and(IData other);
|
||||
|
||||
@ZenOperator(OperatorType.OR)
|
||||
public IData or(IData other);
|
||||
|
||||
@ZenOperator(OperatorType.XOR)
|
||||
public IData xor(IData other);
|
||||
|
||||
@ZenOperator(OperatorType.NEG)
|
||||
public IData neg();
|
||||
|
||||
@ZenOperator(OperatorType.NOT)
|
||||
public IData not();
|
||||
|
||||
@ZenCaster
|
||||
public boolean asBool();
|
||||
|
||||
@ZenCaster
|
||||
public byte asByte();
|
||||
|
||||
@ZenCaster
|
||||
public short asShort();
|
||||
|
||||
@ZenCaster
|
||||
public int asInt();
|
||||
|
||||
@ZenCaster
|
||||
public long asLong();
|
||||
|
||||
@ZenCaster
|
||||
public float asFloat();
|
||||
|
||||
@ZenCaster
|
||||
public double asDouble();
|
||||
|
||||
@ZenCaster
|
||||
public String asString();
|
||||
|
||||
@ZenCaster
|
||||
public List<IData> asList();
|
||||
|
||||
@ZenCaster
|
||||
public Map<String, IData> asMap();
|
||||
|
||||
@ZenCaster
|
||||
public byte[] asByteArray();
|
||||
|
||||
@ZenCaster
|
||||
public int[] asIntArray();
|
||||
|
||||
@ZenOperator(OperatorType.INDEXGET)
|
||||
public IData getAt(int i);
|
||||
|
||||
@ZenOperator(OperatorType.INDEXSET)
|
||||
public void setAt(int i, IData value);
|
||||
|
||||
@ZenMemberGetter
|
||||
public IData memberGet(String name);
|
||||
|
||||
@ZenMemberSetter
|
||||
public void memberSet(String name, IData data);
|
||||
|
||||
@ZenGetter
|
||||
public int length();
|
||||
|
||||
@ZenOperator(OperatorType.CONTAINS)
|
||||
public boolean contains(IData data);
|
||||
|
||||
@ZenOperator(OperatorType.COMPARE)
|
||||
public int compareTo(IData data);
|
||||
|
||||
@ZenOperator(OperatorType.EQUALS)
|
||||
public boolean equals(IData data);
|
||||
|
||||
@ZenGetter
|
||||
public IData immutable();
|
||||
|
||||
@ZenMethod
|
||||
public IData update(IData data);
|
||||
|
||||
public <T> T convert(IDataConverter<T> converter);
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.api.data;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
* @param <T> output type
|
||||
*/
|
||||
public interface IDataConverter<T> {
|
||||
public T fromBool(boolean value);
|
||||
|
||||
public T fromByte(byte value);
|
||||
|
||||
public T fromShort(short value);
|
||||
|
||||
public T fromInt(int value);
|
||||
|
||||
public T fromLong(long value);
|
||||
|
||||
public T fromFloat(float value);
|
||||
|
||||
public T fromDouble(double value);
|
||||
|
||||
public T fromString(String value);
|
||||
|
||||
public T fromList(List<IData> values);
|
||||
|
||||
public T fromMap(Map<String, IData> values);
|
||||
|
||||
public T fromByteArray(byte[] value);
|
||||
|
||||
public T fromIntArray(int[] value);
|
||||
}
|
||||
Reference in new issue
Block a user