- Fixed some wrongs in data matching, causing crashes with onlyWithTag in some cases

- Fixed a variable check when resolving variables
This commit is contained in:
Stan Hebben committed 2014-10-14 23:33:10 +02:00
1 parent f20af21fef
commit 59ef38877f
15 files changed
+119 -44

No files matched your search

@@ -57,22 +57,22 @@ public class DataBool implements IData {
@Override
public List<IData> asList() {
throw new UnsupportedOperationException("Cannot cast a bool to a list");
return null;
}
@Override
public Map<String, IData> asMap() {
throw new UnsupportedOperationException("Cannot cast a bool to a map");
return null;
}
@Override
public byte[] asByteArray() {
throw new RuntimeException("cannot cast a bool to a byte array");
return null;
}
@Override
public int[] asIntArray() {
throw new RuntimeException("cannot cast a bool to an int array");
return null;
}
@Override
@@ -57,22 +57,22 @@ public class DataByte implements IData {
@Override
public List<IData> asList() {
throw new UnsupportedOperationException("Cannot convert a byte to a list");
return null;
}
@Override
public Map<String, IData> asMap() {
throw new UnsupportedOperationException("Cannot convert a byte to a map");
return null;
}
@Override
public byte[] asByteArray() {
throw new RuntimeException("Cannot cast a byte to a byte array");
return null;
}
@Override
public int[] asIntArray() {
throw new RuntimeException("Cannot cast a byte to an int array");
return null;
}
@Override
@@ -133,7 +133,7 @@ public class DataByteArray implements IData {
@Override
public Map<String, IData> asMap() {
throw new UnsupportedOperationException("Cannot convert list to map");
return null;
}
@Override
@@ -57,22 +57,22 @@ public class DataDouble implements IData {
@Override
public List<IData> asList() {
throw new UnsupportedOperationException("Cannot cast a double to a list");
return null;
}
@Override
public Map<String, IData> asMap() {
throw new UnsupportedOperationException("Cannot cast a double to a map");
return null;
}
@Override
public byte[] asByteArray() {
throw new RuntimeException("Cannot cast a double to a byte array");
return null;
}
@Override
public int[] asIntArray() {
throw new RuntimeException("Cannot cast a double to an int array");
return null;
}
@Override
@@ -57,22 +57,22 @@ public class DataFloat implements IData {
@Override
public List<IData> asList() {
throw new UnsupportedOperationException("Cannot cast a float to a list");
return null;
}
@Override
public Map<String, IData> asMap() {
throw new UnsupportedOperationException("Cannot cast a float to a map");
return null;
}
@Override
public byte[] asByteArray() {
throw new RuntimeException("Cannot cast a float to a byte array");
return null;
}
@Override
public int[] asIntArray() {
throw new RuntimeException("Cannot cast a float to an int array");
return null;
}
@Override
@@ -57,22 +57,22 @@ public class DataInt implements IData {
@Override
public List<IData> asList() {
throw new UnsupportedOperationException("Cannot cast an int to a list");
return null;
}
@Override
public Map<String, IData> asMap() {
throw new UnsupportedOperationException("Cannot cast an int to a map");
return null;
}
@Override
public byte[] asByteArray() {
throw new RuntimeException("Cannot cast an int to a byte array");
return null;
}
@Override
public int[] asIntArray() {
throw new RuntimeException("Cannot cast an int to an int array");
return null;
}
@Override
@@ -135,7 +135,7 @@ public class DataIntArray implements IData {
@Override
public Map<String, IData> asMap() {
throw new UnsupportedOperationException("Cannot convert list to map");
return null;
}
@Override
@@ -65,7 +65,7 @@ public class DataList implements IData {
@Override
public Map<String, IData> asMap() {
throw new RuntimeException("Cannot convert a list to a map");
return null;
}
@Override
@@ -87,20 +87,28 @@ public class DataList implements IData {
@Override
public byte[] asByteArray() {
byte[] result = new byte[values.size()];
for (int i = 0; i < values.size(); i++) {
result[i] = values.get(i).asByte();
try {
byte[] result = new byte[values.size()];
for (int i = 0; i < values.size(); i++) {
result[i] = values.get(i).asByte();
}
return result;
} catch (IllegalDataException ex) {
return null;
}
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();
try {
int[] result = new int[values.size()];
for (int i = 0; i < values.size(); i++) {
result[i] = values.get(i).asInt();
}
return result;
} catch (IllegalDataException ex) {
return null;
}
return result;
}
@Override
@@ -134,13 +142,31 @@ public class DataList implements IData {
@Override
public boolean contains(IData data) {
List<IData> dataValues = data.asList();
if (dataValues != null && containsList(dataValues))
return true;
for (IData value : values) {
if (value.equals(data)) return true;
if (value.contains(data))
return true;
}
return false;
}
private boolean containsList(List<IData> dataValues) {
outer: for (IData dataValue : dataValues) {
for (IData value : values) {
if (value.contains(dataValue))
continue outer;
}
return false;
}
return true;
}
@Override
public boolean equals(IData data) {
List<IData> otherValues = data.asList();
@@ -153,7 +153,7 @@ public class DataMap implements IData {
@Override
public List<IData> asList() {
throw new UnsupportedOperationException("Cannot cast map to list");
return null;
}
@Override
@@ -167,12 +167,12 @@ public class DataMap implements IData {
@Override
public byte[] asByteArray() {
throw new UnsupportedOperationException("Cannot cast map to byte[]");
return null;
}
@Override
public int[] asIntArray() {
throw new UnsupportedOperationException("Cannot cast map to int[]");
return null;
}
@Override
@@ -211,6 +211,9 @@ public class DataMap implements IData {
}
Map<String, IData> dataMap = data.asMap();
if (dataMap == null)
return false;
for (Map.Entry<String, IData> dataEntry : dataMap.entrySet()) {
if (!this.data.containsKey(dataEntry.getKey())) {
return false;
@@ -57,22 +57,22 @@ public class DataShort implements IData {
@Override
public List<IData> asList() {
throw new UnsupportedOperationException("Cannot cast a short to a list");
return null;
}
@Override
public Map<String, IData> asMap() {
throw new UnsupportedOperationException("Cannot cast a short to a map");
return null;
}
@Override
public byte[] asByteArray() {
throw new RuntimeException("Cannot cast a short to a byte array");
return null;
}
@Override
public int[] asIntArray() {
throw new RuntimeException("Cannot cast a short to an int array");
return null;
}
@Override
@@ -57,22 +57,22 @@ public class DataString implements IData {
@Override
public List<IData> asList() {
throw new UnsupportedOperationException("Cannot cast a string to a list");
return null;
}
@Override
public Map<String, IData> asMap() {
throw new UnsupportedOperationException("Cannot cast a string to a map");
return null;
}
@Override
public byte[] asByteArray() {
throw new RuntimeException("Cannot cast a string to a byte array");
return null;
}
@Override
public int[] asIntArray() {
throw new RuntimeException("Cannot cast a string to an int array");
return null;
}
@Override
@@ -74,15 +74,39 @@ public interface IData {
@ZenCaster
public String asString();
/**
* Attempts to convert this value to a List. Returns null if this value
* cannot be converted to a list.
*
* @return list data of this value, if any
*/
@ZenCaster
public List<IData> asList();
/**
* Attempts to convert this value to a Map. Returns null if this value
* cannot be converted to a map.
*
* @return map data of this value, if any
*/
@ZenCaster
public Map<String, IData> asMap();
/**
* Attempts to convert this value to a byte array. Returns null if this
* value cannot be converted to a byte array.
*
* @return byte array data of this value, if any
*/
@ZenCaster
public byte[] asByteArray();
/**
* Attempts to convert this value to an int array. Returns null if this
* value cannot be converted to an int array.
*
* @return int array data of this value, if any
*/
@ZenCaster
public int[] asIntArray();
@@ -0,0 +1,17 @@
/*
* This file is part of MineTweaker API, licensed under the MIT License (MIT).
*
* Copyright (c) 2014 MineTweaker <http://minetweaker3.powerofbytes.com>
*/
package minetweaker.api.data;
/**
*
* @author Stan
*/
public class IllegalDataException extends RuntimeException
{
public IllegalDataException(String message) {
super(message);
}
}