import { system, world } from "@minecraft/server";

// Event listener for ScriptEventCommand
system.afterEvents.scriptEventReceive.subscribe((eventData) => {
  const { id, sourceEntity } = eventData;
  if (id === "pb_plane:remove_color_single") {
    let dimension = sourceEntity.dimension.id;
    world
      .getDimension(dimension)
      .spawnParticle("pb_plane:wash_color", sourceEntity.location);
    world.playSound("random.splash", sourceEntity.location);
    system.runTimeout(() => {
      sourceEntity.setProperty("pb_plane:colored_1", false);
    }, 20);
  }
  if (id === "pb_plane:remove_color_double") {
    let dimension = sourceEntity.dimension.id;
    world
      .getDimension(dimension)
      .spawnParticle("pb_plane:wash_color", sourceEntity.location);
    world.playSound("random.splash", sourceEntity.location);
    system.runTimeout(() => {
      sourceEntity.setProperty("pb_plane:colored_1", false);
      sourceEntity.setProperty("pb_plane:colored_2", false);
    }, 20);
  }
  if (id === "pb_plane:color_1_red") {
    let dimension = sourceEntity.dimension.id;
    world
      .getDimension(dimension)
      .spawnParticle("pb_plane:spray_can_red", sourceEntity.location);
    world.playSound("random.fizz", sourceEntity.location);
    system.runTimeout(() => {
      sourceEntity.setProperty("pb_plane:red_1", 0.7);
      sourceEntity.setProperty("pb_plane:green_1", 0.2);
      sourceEntity.setProperty("pb_plane:blue_1", 0.1);
      sourceEntity.setProperty("pb_plane:alpha_1", 0.7);
      sourceEntity.setProperty("pb_plane:colored_1", true);
    }, 20);
  }
  if (id === "pb_plane:color_1_orange") {
    let dimension = sourceEntity.dimension.id;
    world
      .getDimension(dimension)
      .spawnParticle("pb_plane:spray_can_orange", sourceEntity.location);
    world.playSound("random.fizz", sourceEntity.location);
    system.runTimeout(() => {
      sourceEntity.setProperty("pb_plane:red_1", 1);
      sourceEntity.setProperty("pb_plane:green_1", 0.5);
      sourceEntity.setProperty("pb_plane:blue_1", 0.1);
      sourceEntity.setProperty("pb_plane:alpha_1", 0.7);
      sourceEntity.setProperty("pb_plane:colored_1", true);
    }, 20);
  }
  if (id === "pb_plane:color_1_yellow") {
    let dimension = sourceEntity.dimension.id;
    world
      .getDimension(dimension)
      .spawnParticle("pb_plane:spray_can_yellow", sourceEntity.location);
    world.playSound("random.fizz", sourceEntity.location);
    system.runTimeout(() => {
      sourceEntity.setProperty("pb_plane:red_1", 1);
      sourceEntity.setProperty("pb_plane:green_1", 0.8);
      sourceEntity.setProperty("pb_plane:blue_1", 0.2);
      sourceEntity.setProperty("pb_plane:alpha_1", 0.7);
      sourceEntity.setProperty("pb_plane:colored_1", true);
    }, 20);
  }
  if (id === "pb_plane:color_1_lime") {
    let dimension = sourceEntity.dimension.id;
    world
      .getDimension(dimension)
      .spawnParticle("pb_plane:spray_can_lime", sourceEntity.location);
    world.playSound("random.fizz", sourceEntity.location);
    system.runTimeout(() => {
      sourceEntity.setProperty("pb_plane:red_1", 0.5);
      sourceEntity.setProperty("pb_plane:green_1", 0.8);
      sourceEntity.setProperty("pb_plane:blue_1", 0.1);
      sourceEntity.setProperty("pb_plane:alpha_1", 0.7);
      sourceEntity.setProperty("pb_plane:colored_1", true);
    }, 20);
  }
  if (id === "pb_plane:color_1_green") {
    let dimension = sourceEntity.dimension.id;
    world
      .getDimension(dimension)
      .spawnParticle("pb_plane:spray_can_green", sourceEntity.location);
    world.playSound("random.fizz", sourceEntity.location);
    system.runTimeout(() => {
      sourceEntity.setProperty("pb_plane:red_1", 0.4);
      sourceEntity.setProperty("pb_plane:green_1", 0.5);
      sourceEntity.setProperty("pb_plane:blue_1", 0.1);
      sourceEntity.setProperty("pb_plane:alpha_1", 0.7);
      sourceEntity.setProperty("pb_plane:colored_1", true);
    }, 20);
  }
  if (id === "pb_plane:color_1_cyan") {
    let dimension = sourceEntity.dimension.id;
    world
      .getDimension(dimension)
      .spawnParticle("pb_plane:spray_can_cyan", sourceEntity.location);
    world.playSound("random.fizz", sourceEntity.location);
    system.runTimeout(() => {
      sourceEntity.setProperty("pb_plane:red_1", 0.1);
      sourceEntity.setProperty("pb_plane:green_1", 0.6);
      sourceEntity.setProperty("pb_plane:blue_1", 0.6);
      sourceEntity.setProperty("pb_plane:alpha_1", 0.7);
      sourceEntity.setProperty("pb_plane:colored_1", true);
    }, 20);
  }
  if (id === "pb_plane:color_1_light_blue") {
    let dimension = sourceEntity.dimension.id;
    world
      .getDimension(dimension)
      .spawnParticle("pb_plane:spray_can_light_blue", sourceEntity.location);
    world.playSound("random.fizz", sourceEntity.location);
    system.runTimeout(() => {
      sourceEntity.setProperty("pb_plane:red_1", 0.2);
      sourceEntity.setProperty("pb_plane:green_1", 0.7);
      sourceEntity.setProperty("pb_plane:blue_1", 0.9);
      sourceEntity.setProperty("pb_plane:alpha_1", 0.7);
      sourceEntity.setProperty("pb_plane:colored_1", true);
    }, 20);
  }
  if (id === "pb_plane:color_1_blue") {
    let dimension = sourceEntity.dimension.id;
    world
      .getDimension(dimension)
      .spawnParticle("pb_plane:spray_can_blue", sourceEntity.location);
    world.playSound("random.fizz", sourceEntity.location);
    system.runTimeout(() => {
      sourceEntity.setProperty("pb_plane:red_1", 0.2);
      sourceEntity.setProperty("pb_plane:green_1", 0.3);
      sourceEntity.setProperty("pb_plane:blue_1", 0.6);
      sourceEntity.setProperty("pb_plane:alpha_1", 0.7);
      sourceEntity.setProperty("pb_plane:colored_1", true);
    }, 20);
  }
  if (id === "pb_plane:color_1_purple") {
    let dimension = sourceEntity.dimension.id;
    world
      .getDimension(dimension)
      .spawnParticle("pb_plane:spray_can_purple", sourceEntity.location);
    world.playSound("random.fizz", sourceEntity.location);
    system.runTimeout(() => {
      sourceEntity.setProperty("pb_plane:red_1", 0.5);
      sourceEntity.setProperty("pb_plane:green_1", 0.2);
      sourceEntity.setProperty("pb_plane:blue_1", 0.7);
      sourceEntity.setProperty("pb_plane:alpha_1", 0.7);
      sourceEntity.setProperty("pb_plane:colored_1", true);
    }, 20);
  }
  if (id === "pb_plane:color_1_magenta") {
    let dimension = sourceEntity.dimension.id;
    world
      .getDimension(dimension)
      .spawnParticle("pb_plane:spray_can_magenta", sourceEntity.location);
    world.playSound("random.fizz", sourceEntity.location);
    system.runTimeout(() => {
      sourceEntity.setProperty("pb_plane:red_1", 0.8);
      sourceEntity.setProperty("pb_plane:green_1", 0.3);
      sourceEntity.setProperty("pb_plane:blue_1", 0.7);
      sourceEntity.setProperty("pb_plane:alpha_1", 0.7);
      sourceEntity.setProperty("pb_plane:colored_1", true);
    }, 20);
  }
  if (id === "pb_plane:color_1_pink") {
    let dimension = sourceEntity.dimension.id;
    world
      .getDimension(dimension)
      .spawnParticle("pb_plane:spray_can_pink", sourceEntity.location);
    world.playSound("random.fizz", sourceEntity.location);
    system.runTimeout(() => {
      sourceEntity.setProperty("pb_plane:red_1", 1);
      sourceEntity.setProperty("pb_plane:green_1", 0.5);
      sourceEntity.setProperty("pb_plane:blue_1", 0.6);
      sourceEntity.setProperty("pb_plane:alpha_1", 0.7);
      sourceEntity.setProperty("pb_plane:colored_1", true);
    }, 20);
  }
  if (id === "pb_plane:color_1_brown") {
    let dimension = sourceEntity.dimension.id;
    world
      .getDimension(dimension)
      .spawnParticle("pb_plane:spray_can_brown", sourceEntity.location);
    world.playSound("random.fizz", sourceEntity.location);
    system.runTimeout(() => {
      sourceEntity.setProperty("pb_plane:red_1", 0.5);
      sourceEntity.setProperty("pb_plane:green_1", 0.3);
      sourceEntity.setProperty("pb_plane:blue_1", 0.2);
      sourceEntity.setProperty("pb_plane:alpha_1", 0.7);
      sourceEntity.setProperty("pb_plane:colored_1", true);
    }, 20);
  }
  if (id === "pb_plane:color_1_black") {
    let dimension = sourceEntity.dimension.id;
    world
      .getDimension(dimension)
      .spawnParticle("pb_plane:spray_can_black", sourceEntity.location);
    world.playSound("random.fizz", sourceEntity.location);
    system.runTimeout(() => {
      sourceEntity.setProperty("pb_plane:red_1", 0.1);
      sourceEntity.setProperty("pb_plane:green_1", 0.1);
      sourceEntity.setProperty("pb_plane:blue_1", 0.1);
      sourceEntity.setProperty("pb_plane:alpha_1", 0.9);
      sourceEntity.setProperty("pb_plane:colored_1", true);
    }, 20);
  }
  if (id === "pb_plane:color_1_gray") {
    let dimension = sourceEntity.dimension.id;
    world
      .getDimension(dimension)
      .spawnParticle("pb_plane:spray_can_gray", sourceEntity.location);
    world.playSound("random.fizz", sourceEntity.location);
    system.runTimeout(() => {
      sourceEntity.setProperty("pb_plane:red_1", 0.3);
      sourceEntity.setProperty("pb_plane:green_1", 0.3);
      sourceEntity.setProperty("pb_plane:blue_1", 0.3);
      sourceEntity.setProperty("pb_plane:alpha_1", 0.7);
      sourceEntity.setProperty("pb_plane:colored_1", true);
    }, 20);
  }
  if (id === "pb_plane:color_1_light_gray") {
    let dimension = sourceEntity.dimension.id;
    world
      .getDimension(dimension)
      .spawnParticle("pb_plane:spray_can_light_gray", sourceEntity.location);
    world.playSound("random.fizz", sourceEntity.location);
    system.runTimeout(() => {
      sourceEntity.setProperty("pb_plane:red_1", 0.6);
      sourceEntity.setProperty("pb_plane:green_1", 0.6);
      sourceEntity.setProperty("pb_plane:blue_1", 0.6);
      sourceEntity.setProperty("pb_plane:alpha_1", 0.7);
      sourceEntity.setProperty("pb_plane:colored_1", true);
    }, 20);
  }
  if (id === "pb_plane:color_1_white") {
    let dimension = sourceEntity.dimension.id;
    world
      .getDimension(dimension)
      .spawnParticle("pb_plane:spray_can_white", sourceEntity.location);
    world.playSound("random.fizz", sourceEntity.location);
    system.runTimeout(() => {
      sourceEntity.setProperty("pb_plane:red_1", 0.9);
      sourceEntity.setProperty("pb_plane:green_1", 0.9);
      sourceEntity.setProperty("pb_plane:blue_1", 0.9);
      sourceEntity.setProperty("pb_plane:alpha_1", 0.7);
      sourceEntity.setProperty("pb_plane:colored_1", true);
    }, 20);
  }

  if (id === "pb_plane:color_2_red") {
    let dimension = sourceEntity.dimension.id;
    world
      .getDimension(dimension)
      .spawnParticle("pb_plane:spray_can_red", sourceEntity.location);
    world.playSound("random.fizz", sourceEntity.location);
    system.runTimeout(() => {
      sourceEntity.setProperty("pb_plane:red_2", 0.7);
      sourceEntity.setProperty("pb_plane:green_2", 0.2);
      sourceEntity.setProperty("pb_plane:blue_2", 0.1);
      sourceEntity.setProperty("pb_plane:alpha_2", 0.7);
      sourceEntity.setProperty("pb_plane:colored_2", true);
    }, 20);
  }
  if (id === "pb_plane:color_2_orange") {
    let dimension = sourceEntity.dimension.id;
    world
      .getDimension(dimension)
      .spawnParticle("pb_plane:spray_can_orange", sourceEntity.location);
    world.playSound("random.fizz", sourceEntity.location);
    system.runTimeout(() => {
      sourceEntity.setProperty("pb_plane:red_2", 1);
      sourceEntity.setProperty("pb_plane:green_2", 0.5);
      sourceEntity.setProperty("pb_plane:blue_2", 0.1);
      sourceEntity.setProperty("pb_plane:alpha_2", 0.7);
      sourceEntity.setProperty("pb_plane:colored_2", true);
    }, 20);
  }
  if (id === "pb_plane:color_2_yellow") {
    let dimension = sourceEntity.dimension.id;
    world
      .getDimension(dimension)
      .spawnParticle("pb_plane:spray_can_yellow", sourceEntity.location);
    world.playSound("random.fizz", sourceEntity.location);
    system.runTimeout(() => {
      sourceEntity.setProperty("pb_plane:red_2", 1);
      sourceEntity.setProperty("pb_plane:green_2", 0.8);
      sourceEntity.setProperty("pb_plane:blue_2", 0.2);
      sourceEntity.setProperty("pb_plane:alpha_2", 0.7);
      sourceEntity.setProperty("pb_plane:colored_2", true);
    }, 20);
  }
  if (id === "pb_plane:color_2_lime") {
    let dimension = sourceEntity.dimension.id;
    world
      .getDimension(dimension)
      .spawnParticle("pb_plane:spray_can_lime", sourceEntity.location);
    world.playSound("random.fizz", sourceEntity.location);
    system.runTimeout(() => {
      sourceEntity.setProperty("pb_plane:red_2", 0.5);
      sourceEntity.setProperty("pb_plane:green_2", 0.8);
      sourceEntity.setProperty("pb_plane:blue_2", 0.1);
      sourceEntity.setProperty("pb_plane:alpha_2", 0.7);
      sourceEntity.setProperty("pb_plane:colored_2", true);
    }, 20);
  }
  if (id === "pb_plane:color_2_green") {
    let dimension = sourceEntity.dimension.id;
    world
      .getDimension(dimension)
      .spawnParticle("pb_plane:spray_can_green", sourceEntity.location);
    world.playSound("random.fizz", sourceEntity.location);
    system.runTimeout(() => {
      sourceEntity.setProperty("pb_plane:red_2", 0.4);
      sourceEntity.setProperty("pb_plane:green_2", 0.5);
      sourceEntity.setProperty("pb_plane:blue_2", 0.1);
      sourceEntity.setProperty("pb_plane:alpha_2", 0.7);
      sourceEntity.setProperty("pb_plane:colored_2", true);
    }, 20);
  }
  if (id === "pb_plane:color_2_cyan") {
    let dimension = sourceEntity.dimension.id;
    world
      .getDimension(dimension)
      .spawnParticle("pb_plane:spray_can_cyan", sourceEntity.location);
    world.playSound("random.fizz", sourceEntity.location);
    system.runTimeout(() => {
      sourceEntity.setProperty("pb_plane:red_2", 0.1);
      sourceEntity.setProperty("pb_plane:green_2", 0.6);
      sourceEntity.setProperty("pb_plane:blue_2", 0.6);
      sourceEntity.setProperty("pb_plane:alpha_2", 0.7);
      sourceEntity.setProperty("pb_plane:colored_2", true);
    }, 20);
  }
  if (id === "pb_plane:color_2_light_blue") {
    let dimension = sourceEntity.dimension.id;
    world
      .getDimension(dimension)
      .spawnParticle("pb_plane:spray_can_light_blue", sourceEntity.location);
    world.playSound("random.fizz", sourceEntity.location);
    system.runTimeout(() => {
      sourceEntity.setProperty("pb_plane:red_2", 0.2);
      sourceEntity.setProperty("pb_plane:green_2", 0.7);
      sourceEntity.setProperty("pb_plane:blue_2", 0.9);
      sourceEntity.setProperty("pb_plane:alpha_2", 0.7);
      sourceEntity.setProperty("pb_plane:colored_2", true);
    }, 20);
  }
  if (id === "pb_plane:color_2_blue") {
    let dimension = sourceEntity.dimension.id;
    world
      .getDimension(dimension)
      .spawnParticle("pb_plane:spray_can_blue", sourceEntity.location);
    world.playSound("random.fizz", sourceEntity.location);
    system.runTimeout(() => {
      sourceEntity.setProperty("pb_plane:red_2", 0.2);
      sourceEntity.setProperty("pb_plane:green_2", 0.3);
      sourceEntity.setProperty("pb_plane:blue_2", 0.6);
      sourceEntity.setProperty("pb_plane:alpha_2", 0.7);
      sourceEntity.setProperty("pb_plane:colored_2", true);
    }, 20);
  }
  if (id === "pb_plane:color_2_purple") {
    let dimension = sourceEntity.dimension.id;
    world
      .getDimension(dimension)
      .spawnParticle("pb_plane:spray_can_purple", sourceEntity.location);
    world.playSound("random.fizz", sourceEntity.location);
    system.runTimeout(() => {
      sourceEntity.setProperty("pb_plane:red_2", 0.5);
      sourceEntity.setProperty("pb_plane:green_2", 0.2);
      sourceEntity.setProperty("pb_plane:blue_2", 0.7);
      sourceEntity.setProperty("pb_plane:alpha_2", 0.7);
      sourceEntity.setProperty("pb_plane:colored_2", true);
    }, 20);
  }
  if (id === "pb_plane:color_2_magenta") {
    let dimension = sourceEntity.dimension.id;
    world
      .getDimension(dimension)
      .spawnParticle("pb_plane:spray_can_magenta", sourceEntity.location);
    world.playSound("random.fizz", sourceEntity.location);
    system.runTimeout(() => {
      sourceEntity.setProperty("pb_plane:red_2", 0.8);
      sourceEntity.setProperty("pb_plane:green_2", 0.3);
      sourceEntity.setProperty("pb_plane:blue_2", 0.7);
      sourceEntity.setProperty("pb_plane:alpha_2", 0.7);
      sourceEntity.setProperty("pb_plane:colored_2", true);
    }, 20);
  }
  if (id === "pb_plane:color_2_pink") {
    let dimension = sourceEntity.dimension.id;
    world
      .getDimension(dimension)
      .spawnParticle("pb_plane:spray_can_pink", sourceEntity.location);
    world.playSound("random.fizz", sourceEntity.location);
    system.runTimeout(() => {
      sourceEntity.setProperty("pb_plane:red_2", 1);
      sourceEntity.setProperty("pb_plane:green_2", 0.5);
      sourceEntity.setProperty("pb_plane:blue_2", 0.6);
      sourceEntity.setProperty("pb_plane:alpha_2", 0.7);
      sourceEntity.setProperty("pb_plane:colored_2", true);
    }, 20);
  }
  if (id === "pb_plane:color_2_brown") {
    let dimension = sourceEntity.dimension.id;
    world
      .getDimension(dimension)
      .spawnParticle("pb_plane:spray_can_brown", sourceEntity.location);
    world.playSound("random.fizz", sourceEntity.location);
    system.runTimeout(() => {
      sourceEntity.setProperty("pb_plane:red_2", 0.5);
      sourceEntity.setProperty("pb_plane:green_2", 0.3);
      sourceEntity.setProperty("pb_plane:blue_2", 0.2);
      sourceEntity.setProperty("pb_plane:alpha_2", 0.7);
      sourceEntity.setProperty("pb_plane:colored_2", true);
    }, 20);
  }
  if (id === "pb_plane:color_2_black") {
    let dimension = sourceEntity.dimension.id;
    world
      .getDimension(dimension)
      .spawnParticle("pb_plane:spray_can_black", sourceEntity.location);
    world.playSound("random.fizz", sourceEntity.location);
    system.runTimeout(() => {
      sourceEntity.setProperty("pb_plane:red_2", 0.1);
      sourceEntity.setProperty("pb_plane:green_2", 0.1);
      sourceEntity.setProperty("pb_plane:blue_2", 0.1);
      sourceEntity.setProperty("pb_plane:alpha_2", 0.9);
      sourceEntity.setProperty("pb_plane:colored_2", true);
    }, 20);
  }
  if (id === "pb_plane:color_2_gray") {
    let dimension = sourceEntity.dimension.id;
    world
      .getDimension(dimension)
      .spawnParticle("pb_plane:spray_can_gray", sourceEntity.location);
    world.playSound("random.fizz", sourceEntity.location);
    system.runTimeout(() => {
      sourceEntity.setProperty("pb_plane:red_2", 0.3);
      sourceEntity.setProperty("pb_plane:green_2", 0.3);
      sourceEntity.setProperty("pb_plane:blue_2", 0.3);
      sourceEntity.setProperty("pb_plane:alpha_2", 0.7);
      sourceEntity.setProperty("pb_plane:colored_2", true);
    }, 20);
  }
  if (id === "pb_plane:color_2_light_gray") {
    let dimension = sourceEntity.dimension.id;
    world
      .getDimension(dimension)
      .spawnParticle("pb_plane:spray_can_light_gray", sourceEntity.location);
    world.playSound("random.fizz", sourceEntity.location);
    system.runTimeout(() => {
      sourceEntity.setProperty("pb_plane:red_2", 0.6);
      sourceEntity.setProperty("pb_plane:green_2", 0.6);
      sourceEntity.setProperty("pb_plane:blue_2", 0.6);
      sourceEntity.setProperty("pb_plane:alpha_2", 0.7);
      sourceEntity.setProperty("pb_plane:colored_2", true);
    }, 20);
  }
  if (id === "pb_plane:color_2_white") {
    let dimension = sourceEntity.dimension.id;
    world
      .getDimension(dimension)
      .spawnParticle("pb_plane:spray_can_white", sourceEntity.location);
    world.playSound("random.fizz", sourceEntity.location);
    system.runTimeout(() => {
      sourceEntity.setProperty("pb_plane:red_2", 0.9);
      sourceEntity.setProperty("pb_plane:green_2", 0.9);
      sourceEntity.setProperty("pb_plane:blue_2", 0.9);
      sourceEntity.setProperty("pb_plane:alpha_2", 0.7);
      sourceEntity.setProperty("pb_plane:colored_2", true);
    }, 20);
  }
});
