@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
  public void onEntityDamage(EntityDamageEvent event) {
    if (event.getEntity() instanceof ItemFrame) {
      ItemFrame frame = (ItemFrame) event.getEntity();

      // is the block below a shop block?
      if (scs.getShopHandler().isKnownItemFrame(frame)) {
        frame.setItem(null);
      }
    }
  }
示例#2
0
  public FrameInfo(Frame type, ItemFrame frame) {
    this.type = type;
    id = frame.getUniqueId();

    Location loc = frame.getLocation();
    Chunk chunk = loc.getChunk();

    worldId = chunk.getWorld().getUID();
    chunk_x = chunk.getX();
    chunk_z = chunk.getZ();

    instance = new WeakReference<ItemFrame>(frame);
  }
示例#3
0
  public ItemFrame getFrame(boolean force) {
    ItemFrame frame = (instance != null) ? instance.get() : null;
    if (frame == null || !frame.isValid()) {
      final World world = (worldId != null) ? Bukkit.getWorld(worldId) : null;
      if (world != null) {
        Chunk chunk = world.getChunkAt(chunk_x, chunk_z);
        if (!chunk.isLoaded() && force) chunk.load();

        if (chunk.isLoaded())
          for (Entity entity : chunk.getEntities())
            if (entity.getUniqueId().equals(id)) {
              frame = (ItemFrame) entity;
              instance = new WeakReference<ItemFrame>(frame);
              break;
            }
      }
    }

    return frame;
  }
示例#4
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);
   }
 }
示例#5
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;
  }
示例#6
0
 public final void removeFrame(final ItemFrame frame) {
   final UUID uid = frame.getUniqueId();
   if (portalFrames.containsKey(uid)) portalFrames.remove(uid);
 }
示例#7
0
  public final void addFrame(final ABPortal portal, final ItemFrame frame) {
    if (!allPortals.containsKey(portal.uid)) return;

    final UUID uid = frame.getUniqueId();
    if (!portalFrames.containsKey(uid)) portalFrames.put(uid, portal.uid);
  }