Java Code Examples for org.bukkit.entity.ItemFrame#getItem()

The following examples show how to use org.bukkit.entity.ItemFrame#getItem() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RegionMatchModule.java    From PGM with GNU Affero General Public License v3.0 7 votes vote down vote up
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void checkItemFrameRotate(PlayerInteractEntityEvent event) {
  if (event.getRightClicked() instanceof ItemFrame) {
    ItemFrame itemFrame = (ItemFrame) event.getRightClicked();
    if (itemFrame.getItem() != null) {
      // If frame contains an item, right-click will rotate it, which is handled as a "use" event
      this.handleUse(
          event, getHangingBlockState(itemFrame), this.match.getParticipant(event.getPlayer()));
    } else if (event.getPlayer().getItemInHand() != null) {
      // If the frame is empty and it's right clicked with an item, this will place the item in
      // the frame,
      // which is handled as a "place" event, with the placed item as the block world
      BlockState blockState =
          BlockStates.cloneWithMaterial(
              itemFrame.getLocation().getBlock(), event.getPlayer().getItemInHand().getData());
      this.handleHangingPlace(event, blockState, event.getPlayer());
    }
  }
}
 
Example 2
Source File: EventRuleMatchModule.java    From ProjectAres with GNU Affero General Public License v3.0 7 votes vote down vote up
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void checkItemFrameRotate(PlayerInteractEntityEvent event) {
    if(event.getRightClicked() instanceof ItemFrame) {
        ItemFrame itemFrame = (ItemFrame) event.getRightClicked();
        if(itemFrame.getItem() != null) {
            // If frame contains an item, right-click will rotate it, which is handled as a "use" event
            this.handleUse(event, getHangingBlockState(itemFrame), this.match.getParticipant(event.getPlayer()));
        } else if(event.getPlayer().getItemInHand() != null) {
            // If the frame is empty and it's right clicked with an item, this will place the item in the frame,
            // which is handled as a "place" event, with the placed item as the block material
            BlockState blockState = BlockStateUtils.cloneWithMaterial(itemFrame.getLocation().getBlock(),
                                                                      event.getPlayer().getItemInHand().getData());
            this.handleHangingPlace(event, blockState, event.getPlayer());
        }
    }
}
 
Example 3
Source File: ExhibitionListener.java    From NyaaUtils with MIT License 6 votes vote down vote up
@EventHandler(priority = HIGHEST, ignoreCancelled = true)
public void onPlayerInteractItemFrame(PlayerInteractEntityEvent ev) {
    if (!(ev.getRightClicked() instanceof ItemFrame)) return;
    ItemFrame f = (ItemFrame) ev.getRightClicked();
    if (f.getItem() == null || f.getItem().getType() == Material.AIR) return;
    ExhibitionFrame fr = ExhibitionFrame.fromItemFrame(f);
    if (fr.isSet()) {
        new Message(I18n.format("user.exhibition.looking_at")).append(fr.getItemInFrame()).send(ev.getPlayer());
        ev.getPlayer().sendMessage(I18n.format("user.exhibition.provided_by", fr.getOwnerName()));
        for (String line : fr.getDescriptions()) {
            ev.getPlayer().sendMessage(line);
        }
        ev.setCancelled(true);
        if (fr.hasItem() && fr.getItemInFrame().getType() == Material.WRITTEN_BOOK) {
            ev.getPlayer().openBook(fr.getItemInFrame());
        }
    }
}
 
Example 4
Source File: ExhibitionListener.java    From NyaaUtils with MIT License 5 votes vote down vote up
@EventHandler(priority = HIGHEST, ignoreCancelled = true)
public void onPlayerHitItemFrame(EntityDamageByEntityEvent ev) {
    if (!(ev.getEntity() instanceof ItemFrame)) return;
    ItemFrame f = (ItemFrame) ev.getEntity();
    if (f.getItem() == null || f.getItem().getType() == Material.AIR) return;
    if (ExhibitionFrame.fromItemFrame(f).isSet()) {
        ev.setCancelled(true);
        if (ev.getDamager() instanceof Player) {
            ev.getDamager().sendMessage(I18n.format("user.exhibition.frame_protected"));
        }
    }
}
 
Example 5
Source File: ExhibitionListener.java    From NyaaUtils with MIT License 5 votes vote down vote up
@EventHandler(priority = HIGHEST, ignoreCancelled = true)
public void onItemFrameBreak(HangingBreakEvent ev) {
    if (!(ev.getEntity() instanceof ItemFrame)) return;
    ItemFrame f = (ItemFrame) ev.getEntity();
    if (f.getItem() == null || f.getItem().getType() == Material.AIR) return;
    if (ExhibitionFrame.fromItemFrame(f).isSet()) {
        if (ev.getCause() == HangingBreakEvent.RemoveCause.EXPLOSION) { // Explosion protect
            ev.setCancelled(true);
        } else {
            plugin.getLogger().warning(String.format("Exhibition broken: Location: %s, item: %s", f.getLocation().toString(),
                    f.getItem().toString()));
            f.setItem(new ItemStack(Material.AIR));
        }
    }
}
 
Example 6
Source File: DefaultMapWrapper.java    From MapManager with MIT License 5 votes vote down vote up
@Override
public void showInFrame(Player player, ItemFrame frame, boolean force) {
	if (frame.getItem() == null || frame.getItem().getType() != MAP_MATERIAL) {
		if (!force) {//There's no map in the item frame: don't do anything
			return;
		}
	}
	showInFrame(player, frame.getEntityId());
}
 
Example 7
Source File: ItemFrameStorage.java    From civcraft with GNU General Public License v2.0 5 votes vote down vote up
public boolean isEmpty() throws CivException {
	ItemFrame frame = getItemFrame();
	
	if (frame == null) {
		throw new CivException("Bad frame. Could not be found.");
	}
	
	if (frame.getItem() == null || frame.getItem().getType().equals(Material.AIR)) {
		return true;
	}
	
	return false;
}
 
Example 8
Source File: CivGlobal.java    From civcraft with GNU General Public License v2.0 4 votes vote down vote up
public static void checkForEmptyDuplicateFrames(ItemFrameStorage frame) {
	
	if (frame.noFrame()) {
		return;
	}
	
	Chunk chunk = frame.getLocation().getChunk();
	ArrayList<Entity> removed = new ArrayList<Entity>();
	HashMap<Integer, Boolean> droppedItems = new HashMap<Integer, Boolean>();
	
	try {
		if (!frame.isEmpty()) {
			droppedItems.put(ItemManager.getId(frame.getItem()), true);
		}
	} catch (CivException e1) {
		e1.printStackTrace();
	}
	
	for (Entity entity : chunk.getEntities()) {
		if (entity instanceof ItemFrame) {
			if (frame.isOurEntity(entity)) {
				continue;
			}
			
			int x = frame.getLocation().getBlockX();
			int y = frame.getLocation().getBlockY();
			int z = frame.getLocation().getBlockZ();
			
			
			if (x == entity.getLocation().getBlockX() &&
				y == entity.getLocation().getBlockY() &&
				z == entity.getLocation().getBlockZ()) {
				// We have found a duplicate item frame here.

				ItemFrame eFrame = (ItemFrame)entity;
				boolean eFrameEmpty = (eFrame.getItem() == null || eFrame.getItem().getType().equals(Material.AIR));
			
				if (!eFrameEmpty) {
					Boolean droppedAlready = droppedItems.get(ItemManager.getId(eFrame.getItem()));
					if (droppedAlready == null || droppedAlready == false) {
						droppedItems.put(ItemManager.getId(eFrame.getItem()), true);
						eFrame.getLocation().getWorld().dropItemNaturally(eFrame.getLocation(), eFrame.getItem());
					}
				}
				
				removed.add(eFrame);
				
			}			
		}
	}
	
	for (Entity e : removed) {
		e.remove();
	}
	
	return;
}
 
Example 9
Source File: ItemFrameStorage.java    From civcraft with GNU General Public License v2.0 4 votes vote down vote up
public ItemStack getItem() {
	ItemFrame frame = getItemFrame();
	return frame.getItem();
}