lists are now properly mutable

This commit is contained in:
gnembon committed 2021-04-24 01:13:33 -03:00
1 parent d388c406fd
commit 28101e716b
3 files changed
+26 -13

No files matched your search

@@ -114,9 +114,11 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@@ -323,7 +325,7 @@ public class Auxiliary {
CarpetContext cc = (CarpetContext)c;
ServerWorld world = cc.s.getWorld();
MinecraftServer server = world.getServer();
ServerPlayerEntity player[] = {null};
Set<ServerPlayerEntity> playerTargets = new HashSet<>();
List<Pair<ShapeDispatcher.ExpiringShape, Map<String,Value>>> shapes = new ArrayList<>();
if (lv.size() == 1) // bulk
{
@@ -332,16 +334,16 @@ public class Auxiliary {
for (Value list : ((ListValue) specLoad).getItems())
{
if (!(list instanceof ListValue)) throw new InternalExpressionException("In bulk mode - shapes need to be provided as a list of shape specs");
shapes.add( ShapeDispatcher.fromFunctionArgs(server, world, ((ListValue) list).getItems(), player));
shapes.add( ShapeDispatcher.fromFunctionArgs(server, world, ((ListValue) list).getItems(), playerTargets));
}
}
else
{
shapes.add(ShapeDispatcher.fromFunctionArgs(server, world, lv, player));
shapes.add(ShapeDispatcher.fromFunctionArgs(server, world, lv, playerTargets));
}
ShapeDispatcher.sendShape(
(player[0]==null)?cc.s.getWorld().getPlayers():Collections.singletonList(player[0]),
(playerTargets.isEmpty())?cc.s.getWorld().getPlayers():playerTargets,
shapes
);
return Value.TRUE;
@@ -47,6 +47,7 @@ import net.minecraft.util.registry.RegistryKey;
import org.apache.commons.lang3.tuple.Pair;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
@@ -65,7 +66,7 @@ public class ShapeDispatcher
public static Pair<ExpiringShape,Map<String, Value>> fromFunctionArgs(
MinecraftServer server, ServerWorld world,
List<Value> lv,
ServerPlayerEntity[] playerRef
Set<ServerPlayerEntity> playerSet
)
{
if (lv.size() < 3) throw new InternalExpressionException("'draw_shape' takes at least three parameters, shape name, duration, and its params");
@@ -97,16 +98,25 @@ public class ShapeDispatcher
if (params.containsKey("player"))
{
ServerPlayerEntity player = EntityValue.getPlayerByValue(server, params.get("player"));
if (player == null)
throw new InternalExpressionException("'player' parameter needs to represent an existing player");
Value players = params.get("player");
List<Value> playerVals;
if (players instanceof ListValue)
playerVals = ((ListValue) players).getItems();
else
playerVals = Collections.singletonList(players);
for (Value pVal : playerVals)
{
ServerPlayerEntity player = EntityValue.getPlayerByValue(server, pVal);
if (player == null)
throw new InternalExpressionException("'player' parameter needs to represent an existing player, not "+pVal.getString());
playerSet.add(player);
}
params.remove("player");
playerRef[0] = player;
}
return Pair.of(ShapeDispatcher.create(server, shapeType, params), params);
}
public static void sendShape(List<ServerPlayerEntity> players, List<Pair<ExpiringShape,Map<String, Value>>> shapes)
public static void sendShape(Collection<ServerPlayerEntity> players, List<Pair<ExpiringShape,Map<String, Value>>> shapes)
{
List<ServerPlayerEntity> clientPlayers = new ArrayList<>();
List<ServerPlayerEntity> alternativePlayers = new ArrayList<>();