示例#1
0
 @Override
 public Hostage spawnHostage(Location loc, Profession prof) {
   World world = ((CraftWorld) loc.getWorld()).getHandle();
   CraftHostage hostage = new CraftHostage(world, prof.getId());
   hostage.setLocation(loc);
   world.addEntity(hostage);
   return hostage;
 }
 @Override
 public void setVillagerProfession(Villager villager, int profession) {
   try {
     Profession prof = Profession.getProfession(profession);
     if (prof != null) {
       villager.setProfession(prof);
     } else {
       villager.setProfession(Profession.FARMER);
     }
   } catch (Exception e) {
   }
 }
示例#3
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;
  }
示例#4
0
  public void setData(LivingPet pet, PetData pd, boolean b) {
    PetType petType = pet.getPetType();
    if (petType.isDataAllowed(pd)) {
      if (pd == PetData.BABY) {
        if (petType == PetType.ZOMBIE) {
          ((ZombiePet) pet).setBaby(b);
        } else if (petType == PetType.PIGZOMBIE) {
          ((PigZombiePet) pet).setBaby(b);
        } else {
          ((IAgeablePet) pet).setBaby(b);
        }
      }

      if (pd == PetData.POWER) {
        ((CreeperPet) pet).setPowered(b);
      }

      if (pd.isType(PetData.Type.SIZE)) {
        int i = 1;
        if (pd == PetData.MEDIUM) {
          i = 2;
        } else if (pd == PetData.LARGE) {
          i = 4;
        }
        if (petType == PetType.SLIME) {
          ((SlimePet) pet).setSize(i);
        }
        if (petType == PetType.MAGMACUBE) {
          ((MagmaCubePet) pet).setSize(i);
        }
      }

      if (pd.isType(PetData.Type.CAT) && petType == PetType.OCELOT) {
        try {
          org.bukkit.entity.Ocelot.Type t =
              org.bukkit.entity.Ocelot.Type.valueOf(
                  pd.toString() + (pd == PetData.WILD ? "_OCELOT" : "_CAT"));
          if (t != null) {
            ((OcelotPet) pet).setCatType(t);
          }
        } catch (Exception e) {
          Logger.log(
              Logger.LogLevel.SEVERE,
              "Encountered exception whilst attempting to convert PetData to Ocelot.Type.",
              e,
              true);
        }
      }

      if (pd == PetData.ANGRY) {
        ((WolfPet) pet).setAngry(b);
      }

      if (pd == PetData.TAMED) {
        ((WolfPet) pet).setTamed(b);
      }

      if (pd.isType(PetData.Type.PROF)) {
        Profession p = Profession.valueOf(pd.toString());
        if (p != null) {
          ((VillagerPet) pet).setProfession(p);
        }
      }

      if (pd.isType(PetData.Type.COLOUR) && (petType == PetType.SHEEP || petType == PetType.WOLF)) {
        String s = pd == PetData.LIGHTBLUE ? "LIGHT_BLUE" : pd.toString();
        try {
          DyeColor dc = DyeColor.valueOf(s);
          if (dc != null) {
            if (petType == PetType.SHEEP) {
              ((SheepPet) pet).setColor(dc);
            } else if (petType == PetType.WOLF) {
              ((WolfPet) pet).setCollarColor(dc);
            }
          }
        } catch (Exception e) {
          Logger.log(
              Logger.LogLevel.SEVERE,
              "Encountered exception whilst attempting to convert PetData to DyeColor.",
              e,
              true);
        }
      }

      if (pd == PetData.WITHER) {
        ((SkeletonPet) pet).setWither(b);
      }

      if (pd == PetData.VILLAGER) {
        if (petType == PetType.ZOMBIE) {
          ((ZombiePet) pet).setVillager(b);
        } else if (petType == PetType.PIGZOMBIE) {
          ((PigZombiePet) pet).setVillager(b);
        }
      }

      if (pd == PetData.FIRE) {
        ((BlazePet) pet).setOnFire(b);
      }

      if (pd == PetData.SADDLE) {
        if (petType == PetType.PIG) {
          ((PigPet) pet).setSaddle(b);
        } else if (petType == PetType.HORSE) {
          ((HorsePet) pet).setSaddled(b);
        }
      }

      if (pd == PetData.SHEARED) {
        ((SheepPet) pet).setSheared(b);
      }

      if (pd == PetData.SCREAMING) {
        ((EndermanPet) pet).setScreaming(b);
      }

      if (pd == PetData.SHIELD) {
        ((WitherPet) pet).setShielded(b);
      }

      if (petType == PetType.HORSE) {
        if (pd == PetData.CHESTED) {
          ((HorsePet) pet).setChested(b);
        }

        if (pd.isType(PetData.Type.HORSE_TYPE)) {
          try {
            HorseType h = HorseType.valueOf(pd.toString());
            if (h != null) {
              ((HorsePet) pet).setHorseType(h);
            }
          } catch (Exception e) {
            Logger.log(
                Logger.LogLevel.WARNING,
                "Encountered exception whilst attempting to convert PetData to Horse.Type.",
                e,
                true);
          }
        }

        if (pd.isType(PetData.Type.HORSE_VARIANT)) {
          try {
            HorseVariant v = HorseVariant.valueOf(pd.toString());
            if (v != null) {
              HorseMarking m = ((HorsePet) pet).getMarking();
              if (m == null) {
                m = HorseMarking.NONE;
              }
              ((HorsePet) pet).setVariant(v, m);
            }
          } catch (Exception e) {
            Logger.log(
                Logger.LogLevel.WARNING,
                "Encountered exception whilst attempting to convert PetData to Horse.Variant.",
                e,
                true);
          }
        }

        if (pd.isType(PetData.Type.HORSE_MARKING)) {
          try {
            HorseMarking m;
            if (pd == PetData.WHITEPATCH) {
              m = HorseMarking.WHITE_PATCH;
            } else if (pd == PetData.WHITESPOT) {
              m = HorseMarking.WHITE_SPOTS;
            } else if (pd == PetData.BLACKSPOT) {
              m = HorseMarking.BLACK_SPOTS;
            } else {
              m = HorseMarking.valueOf(pd.toString());
            }
            if (m != null) {
              HorseVariant v = ((HorsePet) pet).getVariant();
              if (v == null) {
                v = HorseVariant.WHITE;
              }
              ((HorsePet) pet).setVariant(v, m);
            }
          } catch (Exception e) {
            Logger.log(
                Logger.LogLevel.WARNING,
                "Encountered exception whilst attempting to convert PetData to Horse.Marking.",
                e,
                true);
          }
        }

        if (pd.isType(PetData.Type.HORSE_ARMOUR)) {
          try {
            HorseArmour a;
            if (pd == PetData.NOARMOUR) {
              a = HorseArmour.NONE;
            } else {
              a = HorseArmour.valueOf(pd.toString());
            }
            if (a != null) {
              ((HorsePet) pet).setArmour(a);
            }
          } catch (Exception e) {
            Logger.log(
                Logger.LogLevel.WARNING,
                "Encountered exception whilst attempting to convert PetData to Horse.Armour.",
                e,
                true);
          }
        }
      }
      ListIterator<PetData> i = pet.getActiveData().listIterator();
      while (i.hasNext()) {
        PetData petData = i.next();
        if (petData != pd) {
          ListIterator<PetData.Type> i2 = pd.getTypes().listIterator();
          while (i2.hasNext()) {
            PetData.Type type = i2.next();
            if (type != PetData.Type.BOOLEAN && petData.isType(type)) {
              i.remove();
              break;
            }
          }
        }
      }

      if (b) {
        if (!pet.getActiveData().contains(pd)) {
          pet.getActiveData().add(pd);
        }
      } else {
        if (pet.getActiveData().contains(pd)) {
          pet.getActiveData().remove(pd);
        }
      }
    }
  }
 @SuppressWarnings("deprecation")
 @Override
 public void setProfession(Profession profession) {
   this.setProfession(profession.getId());
 }