Use newer Java features in places where it makes sense and more (#1009)
This commit is contained in:
1 parent
28cb136c6b
commit
7fb5e47da5
34 files changed
+338
-399
No files matched your search
@@ -8,7 +8,7 @@ import java.util.List;
|
||||
|
||||
public abstract class AbstractListValue extends Value implements Iterable<Value>
|
||||
{
|
||||
public abstract Iterator<Value> iterator();
|
||||
@Override public abstract Iterator<Value> iterator();
|
||||
public List<Value> unpack() { return Lists.newArrayList(iterator()); }
|
||||
public void fatality() { }
|
||||
public void append(Value v)
|
||||
|
||||
@@ -12,7 +12,7 @@ public class BooleanValue extends NumericValue
|
||||
|
||||
boolean boolValue;
|
||||
private BooleanValue(boolean boolval) {
|
||||
super(boolval);
|
||||
super(boolval ? 1L : 0L);
|
||||
boolValue = boolval;
|
||||
}
|
||||
|
||||
|
||||
@@ -412,14 +412,14 @@ public class EntityValue extends Value
|
||||
throw new InternalExpressionException("Cannot fetch '"+what+"' with these arguments");
|
||||
}
|
||||
}
|
||||
private static final Map<String, EquipmentSlot> inventorySlots = new HashMap<String, EquipmentSlot>(){{
|
||||
put("mainhand", EquipmentSlot.MAINHAND);
|
||||
put("offhand", EquipmentSlot.OFFHAND);
|
||||
put("head", EquipmentSlot.HEAD);
|
||||
put("chest", EquipmentSlot.CHEST);
|
||||
put("legs", EquipmentSlot.LEGS);
|
||||
put("feet", EquipmentSlot.FEET);
|
||||
}};
|
||||
private static final Map<String, EquipmentSlot> inventorySlots = Map.of(
|
||||
"mainhand", EquipmentSlot.MAINHAND,
|
||||
"offhand", EquipmentSlot.OFFHAND,
|
||||
"head", EquipmentSlot.HEAD,
|
||||
"chest", EquipmentSlot.CHEST,
|
||||
"legs", EquipmentSlot.LEGS,
|
||||
"feet", EquipmentSlot.FEET
|
||||
);
|
||||
|
||||
private static final Map<String, BiFunction<Entity, Value, Value>> featureAccessors = new HashMap<String, BiFunction<Entity, Value, Value>>() {{
|
||||
//put("test", (e, a) -> a == null ? Value.NULL : new StringValue(a.getString()));
|
||||
|
||||
@@ -109,9 +109,9 @@ public abstract class LazyListValue extends AbstractListValue implements Iterato
|
||||
{
|
||||
return hasNext();
|
||||
}
|
||||
public abstract boolean hasNext();
|
||||
@Override public abstract boolean hasNext();
|
||||
|
||||
public abstract Value next();
|
||||
@Override public abstract Value next();
|
||||
|
||||
@Override
|
||||
public void fatality() {reset();}
|
||||
|
||||
@@ -149,6 +149,8 @@ public class ListValue extends AbstractListValue implements ContainerValueInterf
|
||||
{
|
||||
items.add(v);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Value subtract(Value other)
|
||||
{
|
||||
ListValue output = new ListValue();
|
||||
@@ -182,6 +184,7 @@ public class ListValue extends AbstractListValue implements ContainerValueInterf
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Value multiply(Value other)
|
||||
{
|
||||
ListValue output = new ListValue();
|
||||
@@ -209,6 +212,8 @@ public class ListValue extends AbstractListValue implements ContainerValueInterf
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Value divide(Value other)
|
||||
{
|
||||
ListValue output = new ListValue();
|
||||
@@ -272,8 +277,10 @@ public class ListValue extends AbstractListValue implements ContainerValueInterf
|
||||
return items;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<Value> iterator() { return new ArrayList<>(items).iterator(); } // should be thread safe
|
||||
|
||||
@Override
|
||||
public List<Value> unpack()
|
||||
{
|
||||
return new ArrayList<>(items);
|
||||
|
||||
@@ -633,26 +633,12 @@ public class NBTSerializableValue extends Value implements ContainerValueInterfa
|
||||
return false;
|
||||
}
|
||||
|
||||
public static class InventoryLocator
|
||||
public static record InventoryLocator(Object owner, BlockPos position, Inventory inventory, int offset, boolean isEnder)
|
||||
{
|
||||
public Object owner;
|
||||
public BlockPos position;
|
||||
public Inventory inventory;
|
||||
public int offset;
|
||||
public boolean isEnder;
|
||||
InventoryLocator(Object owner, BlockPos pos, Inventory i, int o)
|
||||
{
|
||||
this(owner, pos, i, o, false);
|
||||
}
|
||||
|
||||
InventoryLocator(Object owner, BlockPos pos, Inventory i, int o, boolean isEnder)
|
||||
{
|
||||
this.owner = owner;
|
||||
position = pos;
|
||||
inventory = i;
|
||||
offset = o;
|
||||
this.isEnder = isEnder;
|
||||
}
|
||||
}
|
||||
|
||||
private static Map<String, NbtPathArgumentType.NbtPath> pathCache = new HashMap<>();
|
||||
|
||||
@@ -33,7 +33,7 @@ public class NullValue extends NumericValue // TODO check nonsingleton code
|
||||
{
|
||||
return new NullValue();
|
||||
}
|
||||
private NullValue() {super(false);}
|
||||
private NullValue() {super(0);}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object o)
|
||||
|
||||
@@ -120,6 +120,8 @@ public class NumericValue extends Value
|
||||
}
|
||||
return super.add(v);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Value subtract(Value v) { // TODO test if definintn add(NumericVlaue) woud solve the casting
|
||||
if (v instanceof NumericValue nv)
|
||||
{
|
||||
@@ -131,6 +133,8 @@ public class NumericValue extends Value
|
||||
}
|
||||
return super.subtract(v);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Value multiply(Value v)
|
||||
{
|
||||
if (v instanceof NumericValue nv)
|
||||
@@ -147,6 +151,8 @@ public class NumericValue extends Value
|
||||
}
|
||||
return new StringValue(StringUtils.repeat(v.getString(), (int) getLong()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Value divide(Value v)
|
||||
{
|
||||
//if (1+2==3) throw new ArithmeticException("Booyah");
|
||||
@@ -223,17 +229,6 @@ public class NumericValue extends Value
|
||||
this.value = (double)value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a legacy {@link NumericValue} for a {@code boolean}.
|
||||
* @param boolval The boolean to set 1 or 0 for this {@link NumericValue}
|
||||
* @deprecated Use {@link BooleanValue#of(boolean)} instead
|
||||
*/
|
||||
@Deprecated
|
||||
public NumericValue(boolean boolval)
|
||||
{
|
||||
this(boolval?1L:0L);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int length()
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user