예제 #1
0
  public void collision(Entity entity) {
    if (entity.getType() == LEVEL_CHANGER && getController() instanceof PlayerController) {
      getWorld().changeLevel(entity.getValue());
      digesting = true;
      mouth.setClosed(true);
      timer.start();
      prevTime = timer.milliTime();
    }

    for (int x = 0; x < getBodyParts().size(); x++) if (entity == getBodyParts().get(x)) return;

    if (entity.getType() == FAT) {
      addValue(entity.removeValue());
      setValue(getValue());
      digesting = true;
      mouth.setClosed(true);
      timer.start();
      prevTime = timer.milliTime();
    } else if (entity.getType() == FOOD) {
      addValue(entity.removeValue());
      setValue(getValue());
      digesting = true;
      mouth.setClosed(true);
      timer.start();
      prevTime = timer.milliTime();
    } else if (entity.getType() == EVOLVER) {
      if (entity.getValue() == EvolverEntity.EVOLVER_VAL) evolve();
      else if (entity.getValue() == EvolverEntity.MOUTH_VAL) enlargeMouth();
    }
  }
예제 #2
0
 @EventHandler
 public void onDammange(EntityDamageByEntityEvent event) {
   Entity dammage = event.getEntity();
   if (dammage.getType() == EntityType.ENDER_CRYSTAL) {
     event.setCancelled(true);
   }
 }
예제 #3
0
파일: ATSHook.java 프로젝트: apache/hive
 protected List<String> getTablesFromEntitySet(Set<? extends Entity> entities) {
   List<String> tableNames = new ArrayList<String>();
   for (Entity entity : entities) {
     if (entity.getType() == Entity.Type.TABLE) {
       tableNames.add(entity.getTable().getDbName() + "." + entity.getTable().getTableName());
     }
   }
   return tableNames;
 }
예제 #4
0
  @EventHandler(priority = EventPriority.HIGH)
  public void removeItemFromFrame(EntityDamageByEntityEvent event) {
    Entity victim = event.getEntity();

    if (!victim.getType().equals(EntityType.ITEM_FRAME)) {
      return;
    }
    Player p;
    Entity attacker = event.getDamager();
    // System.out.println("Attacker: "+attacker.getType().toString());
    if (attacker.getType().toString().equals("PLAYER")) {
      p = (Player) attacker;

      OwnedLand land = OwnedLand.getApplicableLand(victim.getLocation());
      if (land == null) {
        return;
      }
      if (!land.hasPermTo(p, this)) {
        p.sendMessage(
            ChatColor.RED
                + getPlugin().getMessageConfig().getString("event.build.itemFrameRemoveWithMelee"));
        event.setCancelled(true);
      }

    } else if (attacker.getType().toString().equals("ARROW")) {
      Arrow a = (Arrow) attacker;
      if (a.getShooter() instanceof Player) {
        p = (Player) a.getShooter();
      } else {
        return;
      }

      OwnedLand land = OwnedLand.getApplicableLand(victim.getLocation());
      if (land == null) {
        return;
      }
      if (!land.hasPermTo(p, this)) {
        p.sendMessage(
            ChatColor.RED
                + getPlugin().getMessageConfig().getString("event.build.itemFrameRemoveWithArrow"));
        event.setCancelled(true);
      }
    }
  }
예제 #5
0
 /** @see de.unika.ipd.grgen.ir.Expression#collectNeededEntities() */
 public void collectNeededEntities(NeededEntities needs) {
   if (owner != null) {
     if (!isGlobalVariable(owner) && !(owner.getType() instanceof MatchType)) {
       if (owner instanceof GraphEntity) needs.addAttr((GraphEntity) owner, member);
       else needs.add((Variable) owner);
     }
   } else {
     ownerExpr.collectNeededEntities(needs);
   }
 }
예제 #6
0
 public List<Entity> getEntitiesByType(String type) {
   if (entitiesByType != null) {
     return entitiesByType.get(type);
   }
   getEntities();
   if (entities == null) {
     return null;
   }
   List<Entity> l = null;
   entitiesByType = new LinkedHashMap<String, List<Entity>>();
   for (Entity entity : entities) {
     l = entitiesByType.get(entity.getType());
     if (l == null) {
       l = new ArrayList<Entity>();
       entitiesByType.put(entity.getType(), l);
     }
     l.add(entity);
   }
   return l;
 }
예제 #7
0
 public List<EntityRef> getEntityRefsByType(String type) {
   if (entitiesByType != null) {
     return refsByType.get(type);
   }
   List<EntityRef> l = cast(getEntitiesByType(type));
   if (l != null) {
     return l;
   }
   getRefs();
   if (refs == null) {
     return null;
   }
   refsByType = new LinkedHashMap<String, List<EntityRef>>();
   for (Entity entity : entities) {
     l = refsByType.get(entity.getType());
     if (l == null) {
       l = new ArrayList<EntityRef>();
       refsByType.put(entity.getType(), l);
     }
     l.add(entity);
   }
   return l;
 }
예제 #8
0
 @EventHandler(priority = EventPriority.HIGH)
 public void removeItemFromFrame(PlayerInteractEntityEvent event) {
   Entity entity = event.getRightClicked();
   Player p = event.getPlayer();
   if (!entity.getType().equals(EntityType.ITEM_FRAME)) {
     return;
   }
   ItemFrame iFrame = (ItemFrame) entity;
   if (iFrame.getItem() != null && !iFrame.getItem().getType().equals(Material.AIR)) return;
   OwnedLand land = OwnedLand.getApplicableLand(entity.getLocation());
   if (land == null) {
     return;
   }
   if (!land.hasPermTo(p, this)) {
     p.sendMessage(
         ChatColor.RED
             + getPlugin().getMessageConfig().getString("event.build.itemFrameRemoveDirectly"));
     event.setCancelled(true);
   }
 }
예제 #9
0
  @EventHandler(priority = EventPriority.HIGH)
  public void destroyArmorStand(EntityDamageByEntityEvent event) {
    Entity victim = event.getEntity();
    // System.out.println("Victim: "+victim);
    if (!victim.getType().equals(EntityType.ARMOR_STAND)) {
      return;
    }

    OwnedLand land = OwnedLand.getApplicableLand(victim.getLocation());
    if (land == null) {
      return;
    }

    if (event.getDamager().getType().equals(EntityType.PLAYER)) {
      Player attacker = (Player) event.getDamager();
      // System.out.println(attacker.getName());
      if (!land.hasPermTo(attacker, this)) {
        attacker.sendMessage(
            ChatColor.RED
                + getPlugin().getMessageConfig().getString("event.build.breakArmorStandWithMelee"));
        event.setCancelled(true);
      }
    }
    if (event.getDamager().getType().equals(EntityType.ARROW)) {
      Arrow projectile = (Arrow) event.getDamager();
      if (projectile.getShooter() instanceof Player) {
        Player attacker = (Player) projectile.getShooter();
        if (!land.hasPermTo(attacker, this)) {
          attacker.sendMessage(
              ChatColor.RED
                  + getPlugin()
                      .getMessageConfig()
                      .getString("event.build.breakArmorStandWithArrow"));
          event.setCancelled(true);
        }
      }
    }
    // System.out.println(event.getDamager().getType());

  }
예제 #10
0
 private static void addEntityToCache(Entity e) {
   entityCache.put(e.getType(), e);
   LOGGER.debug("Added entity with type " + e.getType() + " to cache");
 }
예제 #11
0
 public Qualification(Expression ownerExpr, Entity member) {
   super("qual", member.getType());
   this.owner = null;
   this.ownerExpr = ownerExpr;
   this.member = member;
 }
예제 #12
0
  /** Updates the enitities position depending on nearest food and attacking */
  public void update() {
    radarEntity.setX(entity.getX());
    radarEntity.setY(entity.getY());
    Entity target = entity.getWorld().getNearbyFood(radarEntity, entity);

    if (entity.getSizeValue() * entity.getBodyParts().size()
        < prevEntityValue * entity.getBodyParts().size()) runAway = true;

    if (!runAway) {
      if (target != null) {

        int xTarget = target.getX();
        int yTarget = target.getY();
        if (target.getType() < 3) {
          entity.setColor(Color.orange);
          entity.setVelocity(MAX_ATTACK_VELOCITY);
          entity.setAcceleration(MAX_ATTACK_ACCELERATION);
          entity.setDeceleration(MAX_ATTACK_ACCELERATION / 2);
          entity.setTarget(xTarget, yTarget);
        } else {
          entity.setColor(Color.white);
          entity.setVelocity(MAX_VELOCITY);
          entity.setAcceleration(MAX_ACCELERATION);
          entity.setDeceleration(MAX_ACCELERATION / 2);
          entity.setTarget(xTarget, yTarget);
        }
      } else {
        entity.setColor(Color.white);
        entity.setVelocity(MAX_VELOCITY);
        entity.setAcceleration(MAX_ACCELERATION);
        entity.setDeceleration(MAX_ACCELERATION / 2);
        currTime = timer.milliTime(); // get the time we are at
        accumulator += currTime - prevTime; // add time taken since last loop to accumulator

        prevTime = currTime; // set new previous time

        if (accumulator >= TIMESTEP_MILLIS) { // while there is an update rate in the accumulator

          boolean bx = rbooleanx.nextBoolean();
          boolean by = rbooleany.nextBoolean();

          int xTarget = entity.getX();
          int yTarget = entity.getY();

          if (bx == true) xTarget += rx.nextInt(RANGE);
          else xTarget += (rx.nextInt(RANGE)) * -1;

          if (by == true) yTarget += ry.nextInt(RANGE);
          else yTarget += (ry.nextInt(RANGE)) * -1;

          entity.setTarget(xTarget, yTarget);
          accumulator = 0;
        }
      }
      prevEntityValue = entity.getSizeValue();
    } else // we're running away
    {
      entity.setColor(Color.blue);
      entity.setVelocity(MAX_ATTACK_VELOCITY);
      entity.setAcceleration(MAX_ATTACK_ACCELERATION);
      currTime = timer.milliTime(); // get the time we are at
      accumulator += currTime - prevTime; // add time taken since last loop to accumulator
      runningTime += currTime - prevTime;
      prevTime = currTime; // set new previous time

      if (accumulator >= TIMESTEP_MILLIS) { // while there is an update rate in the accumulator

        int xTarget = entity.getX();
        int yTarget = entity.getY();

        if (xTarget < 0) xTarget -= FLEE_RANGE;
        else xTarget += FLEE_RANGE;

        if (yTarget < 0) yTarget -= FLEE_RANGE;
        else yTarget += FLEE_RANGE;

        entity.setTarget(xTarget, yTarget);
        accumulator = 0;
      }

      if (runningTime > 10000) {
        runAway = false;
        runningTime = 0;
        prevEntityValue = entity.getSizeValue();
        accumulator = TIMESTEP_MILLIS;
      }
    }
  }
예제 #13
0
  @EventHandler
  public void onDrop(EntityDamageEvent event) {
    if (!event.getEntity().getWorld().getName().equals(name)) return;
    if (event.getEntity() instanceof Player) return;

    final Entity e = event.getEntity();
    EntityType et = e.getType();
    final Location loc = e.getLocation();
    if (event.getCause() == EntityDamageEvent.DamageCause.FALL) {
      if (et == EntityType.CREEPER) {
        Bukkit.getScheduler()
            .runTaskLater(
                MapsPlugin.getInstance(),
                new Runnable() {
                  public void run() {
                    loc.getWorld().createExplosion(loc, (float) 4);
                  }
                },
                30);
      } else if (et == EntityType.COW) {
        Random rdom = new Random();

        for (int i = 0; i <= 3; i++) {
          loc.getWorld()
              .spawnEntity(loc, EntityType.PRIMED_TNT)
              .setVelocity(new Vector(rdom.nextDouble() - 0.5, 1.5, rdom.nextDouble() - 0.5));
        }

      } else if (et == EntityType.PIG) {
        Random rdom = new Random();
        loc.getWorld()
            .spawnEntity(loc, EntityType.PIG_ZOMBIE)
            .setVelocity(new Vector(rdom.nextDouble(), 3, rdom.nextDouble()));
      } else if (et == EntityType.PIG_ZOMBIE) {
        Bukkit.getScheduler()
            .runTaskLater(
                MapsPlugin.getInstance(),
                new Runnable() {
                  public void run() {
                    loc.getWorld().createExplosion(loc, (float) 6);
                  }
                },
                30);
      } else if (et == EntityType.SHEEP) {
        Random rdom = new Random();

        for (int i = 0; i <= 10; i++) {
          loc.getWorld()
              .spawnFallingBlock(loc, Material.WOOL, (byte) 0)
              .setVelocity(new Vector(rdom.nextDouble() - 0.5, 2, rdom.nextDouble() - 0.5));
        }

      } else if (et == EntityType.SQUID) {
        Random rdom = new Random();
        loc.getWorld()
            .spawnFallingBlock(loc, Material.WATER, (byte) 0)
            .setVelocity(new Vector(rdom.nextDouble() - 0.5, 1, rdom.nextDouble() - 0.5));
      } else if (et == EntityType.WOLF) {
        Random rdom = new Random();
        List<Entity> l = e.getNearbyEntities(3, 3, 3);

        for (Entity ee : l) {
          if (ee instanceof Player) {
            Player p = (Player) ee;
            p.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 5, 1));
          }
        }
      } else if (et == EntityType.OCELOT) {
        Random rdom = new Random();
        List<Entity> l = e.getNearbyEntities(3, 3, 3);
        for (Entity ee : l) {
          if (ee instanceof Player) {
            Player p = (Player) ee;
            p.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 5, 1));
          }
        }
      } else if (et == EntityType.SPIDER) {
        Random rdom = new Random();

        for (int i = 0; i <= 4; i++) {
          loc.getWorld()
              .spawnFallingBlock(loc, Material.WEB, (byte) 0)
              .setVelocity(new Vector(rdom.nextDouble() - 0.5, 1, rdom.nextDouble() - 0.5));
        }
      } else if (et == EntityType.HORSE) {
        Random rdom = new Random();
        List<Entity> l = e.getNearbyEntities(10, 10, 10);
        for (Entity ee : l) {
          if (ee instanceof Player) {
            Player p = (Player) ee;
            p.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, 5, 2));
            p.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, 20, 2));
          }
        }
      } else if (et == EntityType.SKELETON) {
        Random rdom = new Random();

        for (int i = 0; i <= 4; i++) {
          loc.getWorld()
              .spawnEntity(loc, EntityType.ZOMBIE)
              .setVelocity(new Vector(rdom.nextDouble() - 0.5, 3, rdom.nextDouble() - 0.5));
        }

      } else if (et == EntityType.SILVERFISH) {
        Random rdom = new Random();
        loc.getWorld()
            .spawnFallingBlock(loc, Material.MONSTER_EGGS, (byte) 0)
            .setVelocity(new Vector(rdom.nextDouble() - 0.5, 3, rdom.nextDouble() - 0.5));
        Bukkit.getScheduler()
            .runTaskLater(
                MapsPlugin.getInstance(),
                new Runnable() {
                  public void run() {
                    loc.getWorld().createExplosion(loc, (float) 2);
                  }
                },
                30);
      } else if (et == EntityType.CAVE_SPIDER) {
        Random rdom = new Random();
        for (int i = 0; i <= 3; i++) {
          loc.getWorld()
              .spawnEntity(loc, EntityType.SPIDER)
              .setVelocity(new Vector(rdom.nextDouble() - 0.5, 3, rdom.nextDouble() - 0.5));
        }
      } else if (et == EntityType.WITHER_SKULL) {
        Random rdom = new Random();
      }
      if (et == EntityType.ZOMBIE) {
        Bukkit.getScheduler()
            .runTaskLater(
                MapsPlugin.getInstance(),
                new Runnable() {
                  public void run() {
                    loc.getWorld().strikeLightning(loc);
                  }
                },
                30);
      } else if (et == EntityType.IRON_GOLEM) {
        Random rdom = new Random();
        for (int i = 0; i <= 3; i++) {
          loc.getWorld()
              .spawnEntity(loc, EntityType.VILLAGER)
              .setVelocity(new Vector(rdom.nextDouble() - 0.5, 3, rdom.nextDouble() - 0.5));
        }
      } else if (et == EntityType.VILLAGER) {
        Random rdom = new Random();

        for (int i = 0; i <= 3; i++) {
          loc.getWorld()
              .spawnFallingBlock(loc, Material.ANVIL, (byte) 0)
              .setVelocity(new Vector(rdom.nextDouble() - 0.5, 1.5, rdom.nextDouble() - 0.5));
        }
      } else if (et == EntityType.MUSHROOM_COW) {
        Random rdom = new Random();
        for (int i = 0; i <= 5; i++) {
          loc.getWorld()
              .spawnEntity(loc, EntityType.PRIMED_TNT)
              .setVelocity(new Vector(rdom.nextDouble() - 0.5, 1.5, rdom.nextDouble() - 0.5));
        }
      }
      if (et == EntityType.SLIME) {
        Bukkit.getScheduler()
            .runTaskLater(
                MapsPlugin.getInstance(),
                new Runnable() {
                  public void run() {
                    loc.getWorld().createExplosion(loc, (float) 6);
                  }
                },
                30);
      } else if (et == EntityType.SKELETON) {
        Random rdom = new Random();
        loc.getWorld()
            .spawnFallingBlock(loc, Material.LAVA, (byte) 0)
            .setVelocity(new Vector(rdom.nextDouble() - 0.5, 1, rdom.nextDouble() - 0.5));
      }
    }
  }
예제 #14
0
  @Test
  public void testCreateAndGet() throws Exception {
    LOG.info("EntityDaoTest.testCreateAndGet");

    UUID applicationId = setup.createApplication("testOrganization", "testCreateAndGet");

    EntityManager em = setup.getEmf().getEntityManager(applicationId);

    int i = 0;
    List<Entity> things = new ArrayList<Entity>();
    for (i = 0; i < 10; i++) {
      Map<String, Object> properties = new LinkedHashMap<String, Object>();
      properties.put("name", "thing" + i);

      Entity thing = em.create("thing", properties);
      assertNotNull("thing should not be null", thing);
      assertFalse("thing id not valid", thing.getUuid().equals(new UUID(0, 0)));
      assertEquals("name not expected value", "thing" + i, thing.getProperty("name"));

      things.add(thing);
    }
    assertEquals("should be ten entities", 10, things.size());

    i = 0;
    for (Entity entity : things) {

      Entity thing = em.get(entity.getUuid());
      assertNotNull("thing should not be null", thing);
      assertFalse("thing id not valid", thing.getUuid().equals(new UUID(0, 0)));
      assertEquals("name not expected value", "thing" + i, thing.getProperty("name"));

      i++;
    }

    List<UUID> ids = new ArrayList<UUID>();
    for (Entity entity : things) {
      ids.add(entity.getUuid());

      Entity en = em.get(entity.getUuid());
      String type = en.getType();
      assertEquals("type not expected value", "thing", type);

      Object property = en.getProperty("name");
      assertNotNull("thing name property should not be null", property);
      assertTrue("thing name should start with \"thing\"", property.toString().startsWith("thing"));

      Map<String, Object> properties = en.getProperties();
      assertEquals("number of properties wrong", 5, properties.size());
    }

    i = 0;
    Results results = em.get(ids, Results.Level.CORE_PROPERTIES);
    for (Entity thing : results) {
      assertNotNull("thing should not be null", thing);

      assertFalse("thing id not valid", thing.getUuid().equals(new UUID(0, 0)));

      assertEquals("wrong type", "thing", thing.getType());

      assertNotNull("thing name should not be null", thing.getProperty("name"));
      String name = thing.getProperty("name").toString();
      assertEquals("unexpected name", "thing" + i, name);

      i++;
    }

    assertEquals("entities unfound entity name count incorrect", 10, i);
  }
예제 #15
0
  public DeathDetail(EntityDeathEvent event) {
    player = (Player) event.getEntity();
    entityDeathEvent = event;
    // Support for setHealth(0) which is used by essentials to do a suicide
    try {
      EntityDamageEvent damageEvent = event.getEntity().getLastDamageCause();
      if (damageEvent instanceof EntityDamageByEntityEvent) {
        Entity damager = ((EntityDamageByEntityEvent) damageEvent).getDamager();
        log.debug("damager", damager.toString());
        if (damager instanceof Player) {
          log.debug("Killed by an other player");
          if (((Player) damager).getItemInHand().getType().equals(Material.AIR)) {
            causeOfDeath = DeathEventType.PVP_FISTS;
          } else {
            causeOfDeath = DeathEventType.PVP;
          }
          murderWeapon = ((Player) damager).getItemInHand().getType().toString();
          killer = (Player) damager;
        } else if (damager instanceof Creature || damager instanceof Slime) {
          log.debug("We have a creature or slime");
          if (damager instanceof Tameable && ((Tameable) damager).isTamed()) {
            causeOfDeath = DeathEventType.PVP_TAMED;
            murderWeapon = damager.getType().toString();
            killer = (Player) ((Tameable) damager).getOwner();
          } else {
            try {
              causeOfDeath = DeathEventType.valueOf(damager.getType().toString());
              if (damager instanceof Skeleton) {
                Skeleton skeleton = (Skeleton) damager;
                causeOfDeath =
                    skeleton.getSkeletonType() == SkeletonType.WITHER
                        ? DeathEventType.WITHER_SKELETON
                        : DeathEventType.SKELETON;
              } else if (damager instanceof Zombie) {
                Zombie zombie = (Zombie) damager;
                causeOfDeath =
                    zombie.isVillager() ? DeathEventType.ZOMBIE_VILLAGER : DeathEventType.ZOMBIE;
              }
            } catch (IllegalArgumentException iae) {
              log.severe("Please notify the developer of the following Error:");
              log.severe(
                  "The following damager is not correctly implemented: "
                      + damager.getType().toString());
              causeOfDeath = DeathEventType.UNKNOWN;
            }
            log.debug("and it is: " + causeOfDeath);
          }
        } else if (damager instanceof Projectile) {
          log.debug("this is a projectile");
          log.debug("shooter", ((Projectile) damager).getShooter());
          if (((Projectile) damager).getShooter() instanceof Player) {
            causeOfDeath = DeathEventType.PVP;
            murderWeapon = ((Projectile) damager).toString().replace("Craft", "");
            killer = (Player) ((Projectile) damager).getShooter();
          }
          if (((Projectile) damager).getShooter() == null) {
            // let's assume that null will only be caused by a dispenser!
            causeOfDeath = DeathEventType.DISPENSER;
            murderWeapon = ((Projectile) damager).toString().replace("Craft", "");
          }
          if (((Projectile) damager).getShooter().toString().equalsIgnoreCase("CraftSkeleton")) {
            causeOfDeath = DeathEventType.SKELETON;
            murderWeapon = ((Projectile) damager).toString().replace("Craft", "");
          }

        } else if (damager instanceof TNTPrimed) {
          causeOfDeath = DeathEventType.BLOCK_EXPLOSION;
        } else {
          log.info("unknown enitity damager" + damager);
        }
      } else if (damageEvent != null) {
        log.debug("DamageEvent is not by Entity");
        try {
          causeOfDeath = DeathEventType.valueOf(damageEvent.getCause().toString());
        } catch (IllegalArgumentException e) {
          causeOfDeath = DeathEventType.UNKNOWN;
        }
      }
    } catch (NullPointerException npe) {
      log.debug("normal detection of damageevent failed", npe);
      log.debug("assuming you did use essentials or similar");
      log.debug("which uses setHealth(0) to kill people");
      log.info("Deathcause is being set to SUICIDE!");
      causeOfDeath = DeathEventType.SUICIDE;
      murderWeapon = "Essentials";
    }

    if (causeOfDeath == null) {
      causeOfDeath = DeathEventType.UNKNOWN;
      murderWeapon = "unknown";
    }
    log.debug("causeOfDeath", causeOfDeath);
    log.debug("murderWeapon", murderWeapon);
    log.debug("killer", killer);
  }
예제 #16
0
  protected SpellResult alterEntity(Entity entity) {
    EntityType entityType = entity.getType();
    switch (entityType) {
      case PAINTING:
        registerModified(entity);
        Painting painting = (Painting) entity;
        Art[] artValues = Art.values();
        Art oldArt = painting.getArt();
        Art newArt = oldArt;
        int ordinal = (oldArt.ordinal() + 1);
        for (int i = 0; i < artValues.length; i++) {
          newArt = artValues[ordinal++ % artValues.length];
          painting.setArt(newArt);
          newArt = painting.getArt();
          if (oldArt != newArt) {
            break;
          }
        }
        if (oldArt == newArt) {
          return SpellResult.FAIL;
        }
        mage.sendDebugMessage("Altering art from " + oldArt + " to " + newArt);
        break;
      case ITEM_FRAME:
        ItemFrame itemFrame = (ItemFrame) entity;
        ItemStack frameItem = itemFrame.getItem();
        if (frameItem == null || frameItem.getType() != Material.MAP) {
          return SpellResult.NO_TARGET;
        }
        short data = frameItem.getDurability();
        data++;
        MapView mapView = DeprecatedUtils.getMap(data);
        if (mapView == null) {
          data = 0;
          mapView = DeprecatedUtils.getMap(data);
          if (mapView == null) {
            return SpellResult.NO_TARGET;
          }
        }
        registerModified(entity);
        frameItem.setDurability(data);
        itemFrame.setItem(frameItem);
        break;
      case HORSE:
        registerModified(entity);
        Horse horse = (Horse) entity;

        Color color = horse.getColor();
        Color[] colorValues = Color.values();
        color = colorValues[(color.ordinal() + 1) % colorValues.length];

        Variant variant = horse.getVariant();
        Variant[] variantValues = Variant.values();
        variant = variantValues[(variant.ordinal() + 1) % variantValues.length];

        Style horseStyle = horse.getStyle();
        Style[] styleValues = Style.values();
        horseStyle = styleValues[(horseStyle.ordinal() + 1) % styleValues.length];

        horse.setStyle(horseStyle);
        horse.setColor(color);
        horse.setVariant(variant);
        break;
      case OCELOT:
        registerModified(entity);
        Ocelot ocelot = (Ocelot) entity;
        Type catType = ocelot.getCatType();
        Type[] typeValues = Type.values();
        catType = typeValues[(catType.ordinal() + 1) % typeValues.length];
        ocelot.setCatType(catType);
        break;
      case VILLAGER:
        registerModified(entity);
        Villager villager = (Villager) entity;
        Profession profession = villager.getProfession();
        Profession[] professionValues = Profession.values();
        profession = professionValues[(profession.ordinal() + 1) % professionValues.length];
        villager.setProfession(profession);
        break;
      case WOLF:
        registerModified(entity);
        Wolf wolf = (Wolf) entity;
        DyeColor wolfColor = wolf.getCollarColor();
        DyeColor[] wolfColorValues = DyeColor.values();
        wolfColor = wolfColorValues[(wolfColor.ordinal() + 1) % wolfColorValues.length];
        wolf.setCollarColor(wolfColor);
        break;
      case SHEEP:
        registerModified(entity);
        Sheep sheep = (Sheep) entity;
        DyeColor dyeColor = sheep.getColor();
        DyeColor[] dyeColorValues = DyeColor.values();
        dyeColor = dyeColorValues[(dyeColor.ordinal() + 1) % dyeColorValues.length];
        sheep.setColor(dyeColor);
        break;
      case SKELETON:
        registerModified(entity);
        Skeleton skeleton = (Skeleton) entity;
        SkeletonType skeletonType = skeleton.getSkeletonType();
        SkeletonType[] skeletonTypeValues = SkeletonType.values();
        skeletonType = skeletonTypeValues[(skeletonType.ordinal() + 1) % skeletonTypeValues.length];
        skeleton.setSkeletonType(skeletonType);
        break;
      default:
        return SpellResult.NO_TARGET;
    }
    ;
    registerForUndo();
    return SpellResult.CAST;
  }
예제 #17
0
  /*
   * collect some information needed for code gen process of the graph
   * type model data structures
   *
   */
  protected void collectGraphTypeModelInfo() {
    /* overall number of node and edge types */
    n_node_types = getIDs(true).length;
    n_edge_types = getIDs(false).length;

    /* overall number of enum types */
    n_enum_types = enumMap.size();

    /* overall number of node and edge attributes declared in the grg file */
    n_node_attrs = nodeAttrMap.size();
    n_edge_attrs = edgeAttrMap.size();

    /* get the inheritance information of the node and edge types */
    node_is_a_matrix = getIsAMatrix(true);
    edge_is_a_matrix = getIsAMatrix(false);

    /* count the number of attrs a node type has */
    n_attr_of_node_type = new int[n_node_types];
    // fill that array with 0
    for (int i = 0; i < n_node_types; i++) n_attr_of_node_type[i] = 0;
    // count number of attributes
    for (Entity attr : nodeAttrMap.keySet()) {
      assert attr.hasOwner()
          : "Thought, that the Entity represented a node class attr and that\n"
              + "thus there had to be a type that owned the entity, but there was non.";
      Type node_type = attr.getOwner();
      // get the id of the node type, where the attr is declared in
      int node_type_id = nodeTypeMap.get(node_type).intValue();
      assert node_type_id < n_node_types
          : "Tried to use a node-type-id as array index, "
              + "but the id exceeded the number of node types";
      // increment the number of attributes for the declaring type...
      n_attr_of_node_type[node_type_id]++;
      // ...but the attr is also contained in all sub types, i.e. increment there too
      for (int nt_id = 0; nt_id < n_node_types; nt_id++)
        if (node_is_a_matrix[nt_id][node_type_id] > 0) n_attr_of_node_type[nt_id]++;
    }

    /* count the number of attrs an edge type has */
    n_attr_of_edge_type = new int[n_edge_types];
    // fill that array with 0
    for (int i = 0; i < n_edge_types; i++) n_attr_of_edge_type[i] = 0;
    // count number of attributes
    for (Entity attr : edgeAttrMap.keySet()) {
      assert attr.hasOwner()
          : "Thought, that the Entity represented an edge class attr and that\n"
              + "thus there had to be a type that owned the entity, but there was non.";
      Type edge_type = attr.getOwner();
      // get the id of the edge type, where the attr is declared in
      int edge_type_id = edgeTypeMap.get(edge_type).intValue();
      assert edge_type_id < n_edge_types
          : "Tried to use an edge-type-id as array index,"
              + "but the id exceeded the number of edge types";
      // increment the number of attributes for the declaring type...
      n_attr_of_edge_type[edge_type_id]++;
      // ...but the attr is also contained in all sub types, i.e. increment there too
      for (int et_id = 0; et_id < n_edge_types; et_id++)
        if (edge_is_a_matrix[et_id][edge_type_id] > 0) n_attr_of_edge_type[et_id]++;
    }

    /* collect all needed information about node attributes */
    node_attr_info = new AttrTypeDescriptor[n_node_attrs];
    for (Entity attr : nodeAttrMap.keySet()) {
      assert attr.hasOwner()
          : "Thought, that the Entity represented an node attr and that thus\n"
              + "there had to be a type that owned the entity, but there was non.";
      NodeType node_type = (NodeType) attr.getOwner();
      int node_type_id = nodeTypeMap.get(node_type).intValue();
      int attr_id = nodeAttrMap.get(attr).intValue();

      node_attr_info[attr_id] = new AttrTypeDescriptor();
      // set the attr id
      node_attr_info[attr_id].attr_id = attr_id;
      // get the attributes name
      node_attr_info[attr_id].name = attr.getIdent().toString();
      // get the owners type id
      node_attr_info[attr_id].decl_owner_type_id = node_type_id;
      // get the attributes kind
      if (attr.getType() instanceof IntType)
        node_attr_info[attr_id].kind = AttrTypeDescriptor.INTEGER;
      else if (attr.getType() instanceof BooleanType)
        node_attr_info[attr_id].kind = AttrTypeDescriptor.BOOLEAN;
      else if (attr.getType() instanceof StringType)
        node_attr_info[attr_id].kind = AttrTypeDescriptor.STRING;
      else if (attr.getType() instanceof EnumType) {
        node_attr_info[attr_id].kind = AttrTypeDescriptor.ENUM;
        node_attr_info[attr_id].enum_id = enumMap.get(attr.getType()).intValue();
      } else {
        System.err.println(
            "Key element of AttrNodeMap has a type, which is "
                + "neither one of 'int', 'boolean', 'string' nor an enumeration type.");
        System.exit(0);
      }
    }

    /* collect all needed information about edge attributes */
    edge_attr_info = new AttrTypeDescriptor[n_edge_attrs];
    for (Entity attr : edgeAttrMap.keySet()) {
      assert attr.hasOwner()
          : "Thought, that the Entity represented an edge attr and that thus\n"
              + "there had to be a type that owned the entity, but there was non.";
      EdgeType edge_type = (EdgeType) attr.getOwner();
      int edge_type_id = edgeTypeMap.get(edge_type).intValue();
      int attr_id = edgeAttrMap.get(attr).intValue();

      edge_attr_info[attr_id] = new AttrTypeDescriptor();
      // set the attr id
      edge_attr_info[attr_id].attr_id = attr_id;
      // get the attributes name
      edge_attr_info[attr_id].name = attr.getIdent().toString();
      // get the owners type id
      edge_attr_info[attr_id].decl_owner_type_id = edge_type_id;
      // get the attributes kind
      if (attr.getType() instanceof IntType)
        edge_attr_info[attr_id].kind = AttrTypeDescriptor.INTEGER;
      else if (attr.getType() instanceof BooleanType)
        edge_attr_info[attr_id].kind = AttrTypeDescriptor.BOOLEAN;
      else if (attr.getType() instanceof StringType)
        edge_attr_info[attr_id].kind = AttrTypeDescriptor.STRING;
      else if (attr.getType() instanceof EnumType) {
        edge_attr_info[attr_id].kind = AttrTypeDescriptor.ENUM;
        edge_attr_info[attr_id].enum_id = enumMap.get(attr.getType()).intValue();
      } else {
        System.err.println(
            "Key element of AttrEdgeMap has a type, which is "
                + "neither one of 'int', 'boolean', 'string' nor an enumeration type.");
        System.exit(0);
      }
    }

    /* compute the attr layout of the node types given in the grg file */
    node_attr_index = new int[n_node_types][n_node_attrs];
    // for all node types...
    for (int nt = 0; nt < n_node_types; nt++) {
      // the index the current attr will get in the current node layout, if it's a member
      int attr_index = 0;
      // ...and all node attribute IDs...
      for (int attr_id = 0; attr_id < n_node_attrs; attr_id++) {
        // ...check whether the attr is owned by the node type or one of its supertype
        int owner = node_attr_info[attr_id].decl_owner_type_id;
        if (owner == nt || node_is_a_matrix[nt][owner] > 0)
          // setup the attrs index in the layout of the current node type
          node_attr_index[nt][attr_id] = attr_index++;
        else
          // -1 means that the current attr is not a member of the current node type
          node_attr_index[nt][attr_id] = -1;
      }
    }

    /* compute the attr layout of the edge types given in the grg file */
    edge_attr_index = new int[n_edge_types][n_edge_attrs];
    // for all edge types...
    for (int et = 0; et < n_edge_types; et++) {
      // the index the current attr will get in the current edge layout, if it's a member
      int attr_index = 0;
      // ...and all edge attribute IDs...
      for (int attr_id = 0; attr_id < n_edge_attrs; attr_id++) {
        // ...check whether the attr is owned by the edge type or one of its supertype
        int owner = edge_attr_info[attr_id].decl_owner_type_id;
        if (owner == et || edge_is_a_matrix[et][owner] > 0)
          // setup the attrs index in the layout of the current node type
          edge_attr_index[et][attr_id] = attr_index++;
        else
          // -1 means that the current attr is not a member of the current node type
          edge_attr_index[et][attr_id] = -1;
      }
    }

    // collect the information about the enumeration types
    enum_type_descriptors = new EnumDescriptor[n_enum_types];
    for (int et = 0; et < n_enum_types; et++) enum_type_descriptors[et] = new EnumDescriptor();

    for (EnumType enum_type : enumMap.keySet()) {
      // store the info about the current enum type in an array...
      // ...type id
      int enum_type_id = enumMap.get(enum_type).intValue();
      enum_type_descriptors[enum_type_id].type_id = enum_type_id;
      // ...the identifier used in the grg-file to declare thar enum type
      enum_type_descriptors[enum_type_id].name = enum_type.getIdent().toString();
      // ..the items in this enumeration type
      for (EnumItem item : enum_type.getItems()) {
        enum_type_descriptors[enum_type_id].items.add(item);
      }
      // ...the number of items
      enum_type_descriptors[enum_type_id].n_items =
          enum_type_descriptors[enum_type_id].items.size();
    }
  }