bug fixes for previous commits
All checks were successful
Build and Publish / build-and-publish (push) Successful in 2m32s

This commit is contained in:
Ivy Collective 2025-01-16 16:38:42 -05:00
parent dd04b6b100
commit e82d500f2d
9 changed files with 31 additions and 19 deletions

View file

@ -22,6 +22,8 @@ import com.caoccao.javet.interop.V8Runtime;
import com.caoccao.javet.interop.options.V8RuntimeOptions;
import com.caoccao.javet.values.reference.IV8ValueObject;
import com.caoccao.javet.values.reference.V8ValueObject;
import de.blazemcworld.blazinggames.BlazingGames;
import de.blazemcworld.blazinggames.computing.functions.GlobalFunctions;
import de.blazemcworld.blazinggames.computing.functions.JSFunctionalClass;
import de.blazemcworld.blazinggames.computing.motor.IComputerMotor;
@ -31,6 +33,7 @@ import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.Entity;
@ -242,18 +245,20 @@ public class BootedComputer {
);
}
void updateMetadata(ComputerMetadata metadata) {
if (metadata.location.equals(this.location) && metadata.location != null) {
IComputerMotor motor = this.type.getType().getMotor();
if (motor.usesBlock()) {
this.location.getBlock().setType(Material.AIR);
metadata.location.getBlock().setType(motor.blockMaterial());
motor.applyPropsToBlock(metadata.location.getBlock());
}
if (motor.usesActor()) {
motor.moveActor(this.location.getWorld().getEntity(this.motorRuntimeEntityUUID), metadata.location);
}
void updateMetadata(final ComputerMetadata metadata) {
if (!metadata.location.equals(this.location) && metadata.location != null) {
Bukkit.getScheduler().runTask(BlazingGames.get(), () -> {
IComputerMotor motor = this.type.getType().getMotor();
if (motor.usesBlock()) {
this.location.getBlock().setType(Material.AIR);
metadata.location.getBlock().setType(motor.blockMaterial());
motor.applyPropsToBlock(metadata.location.getBlock());
}
if (motor.usesActor()) {
motor.moveActor(this.location.getWorld().getEntity(this.motorRuntimeEntityUUID), metadata.location);
}
});
}
this.location = metadata.location;
this.address = metadata.address;

View file

@ -53,7 +53,7 @@ public class ComputerEditor {
return false;
}
return metadata.owner == user || Arrays.asList(metadata.collaborators).contains(user);
return metadata.owner.equals(user) || Arrays.asList(metadata.collaborators).contains(user);
}
public static ComputerMetadata getMetadata(final String computer) {
@ -71,6 +71,9 @@ public class ComputerEditor {
return ComputerRegistry.getComputerById(computer).getCode();
}
if (!ComputerRegistry.codeStorage.hasData(computer)) {
return ComputerRegistry.defaultCode;
}
return ComputerRegistry.codeStorage.getData(computer);
}

View file

@ -62,7 +62,7 @@ public class ComputerMetadata {
this.upgrades = GetGson.getString(json, "upgrades", e).split(",");
this.location = TextLocation.deserialize(GetGson.getString(json, "location", e));
this.owner = UUID.fromString(GetGson.getString(json, "owner", e));
this.collaborators = Arrays.stream(GetGson.getString(json, "collaborators", e).split(",")).map(UUID::fromString).toArray(UUID[]::new);
this.collaborators = Arrays.stream(GetGson.getString(json, "collaborators", e).split(",")).filter(s -> !s.isEmpty()).map(UUID::fromString).toArray(UUID[]::new);
this.shouldRun = GetGson.getBoolean(json, "shouldRun", e);
this.frozenTicks = GetGson.getNumber(json, "frozenTicks", e).intValue();
}

View file

@ -47,7 +47,7 @@ public class ComputerRegistry {
private static int tick = 0;
private static final int loopOnTick = 100;
private static final int hitsThreshold = 5;
private static final String defaultCode = "// welcome to the editor!\n" +
public static final String defaultCode = "// welcome to the editor!\n" +
"// this uses JavaScript along with our custom methods to control computers\n// learn more in the documentation: ______";
private static final String NAMESPACE = "blazingcomputing";
public static final NamespacedKey NAMESPACEDKEY_COMPUTER_TYPE = new NamespacedKey(NAMESPACE, "_computer_type");

View file

@ -33,6 +33,7 @@ public enum EndpointList {
COMPUTER_LIST("Computers", new ComputersListEndpoint()),
COMPUTER_CODE_READ("Computers", new ViewCodeEndpoint()),
COMPUTER_RENAME("Computers", new RenameEndpoint()),
;
public final String category;

View file

@ -98,7 +98,9 @@ public record RequestContext(JsonElement body, Map<String, List<String>> headers
}
public String requireCleanCustom(String paramName, String in, int min, int max) throws EarlyResponse {
if (in.length() < min) {
if (in == null) {
throw new EarlyResponse(EndpointResponse.of400("Missing " + paramName));
} else if (in.length() < min) {
throw new EarlyResponse(EndpointResponse.of400("Parameter " + paramName + " is too short (at least 3 chars)"));
} else if (in.length() > max) {
throw new EarlyResponse(EndpointResponse.of400("Parameter " + paramName + " is too long (at most 80 chars)"));

View file

@ -29,7 +29,6 @@ import de.blazemcworld.blazinggames.computing.api.Permission;
import de.blazemcworld.blazinggames.computing.api.RequestContext;
import de.blazemcworld.blazinggames.computing.api.RequestMethod;
import de.blazemcworld.blazinggames.utils.GZipToolkit;
import de.blazemcworld.blazinggames.utils.GetGson;
public class ViewCodeEndpoint implements Endpoint {
@Override
@ -42,8 +41,8 @@ public class ViewCodeEndpoint implements Endpoint {
LinkedUser linked = context.requireAuthentication();
context.requirePermission(Permission.COMPUTER_CODE_READ);
JsonObject body = GetGson.getAsObject(context.requireBody(), EarlyResponse.of(EndpointResponse.of400("Missing query parameters")));
String id = context.requireClean("id", GetGson.getString(body, "id", EarlyResponse.of(EndpointResponse.of400("Missing id argument"))));
var body = context.useBodyWrapper();
String id = context.requireClean("id", body.getString("id"));
if (!ComputerEditor.hasAccessToComputer(linked.uuid(), id)) {
return EndpointResponse.of403();

View file

@ -28,6 +28,7 @@ import org.bukkit.inventory.meta.EnchantmentStorageMeta;
public class PrepareAnvilEventListener implements Listener {
@EventHandler
public void onAnvilPrepare(PrepareAnvilEvent event) {
event.getView().setMaximumRepairCost(Integer.MAX_VALUE);
if (event.getView().getRepairCost() > 10) {
event.getView().setRepairCost(10);
}

View file

@ -31,6 +31,7 @@ public class PlayerConfig {
);
public static PlayerConfig forPlayer(UUID uuid) {
if (dataStorage.getData(uuid) == null) dataStorage.storeData(uuid, new Properties());
return new PlayerConfig(dataStorage.getData(uuid), uuid);
}