org.bukkit.entity.ItemFrame Java Examples

The following examples show how to use org.bukkit.entity.ItemFrame. 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: IslandGuard.java    From askyblock with GNU General Public License v2.0 7 votes vote down vote up
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onItemFrameDamage(final EntityDamageByEntityEvent e) {
    // Check world
    if (!inWorld(e.getEntity()) || !(e.getEntity() instanceof ItemFrame)) {
        return;
    }
    if (e.getDamager() instanceof Projectile) {
        if (DEBUG)
            plugin.getLogger().info("DEBUG: Projectile damage to itemframe");
        // Find out who fired the arrow
        Projectile p = (Projectile) e.getDamager();
        if (DEBUG)
            plugin.getLogger().info("DEBUG: Shooter is " + p.getShooter().toString());
        if (p.getShooter() instanceof Skeleton || p.getShooter() instanceof Golem) {
            if (DEBUG)
                plugin.getLogger().info("DEBUG: Shooter is mob");
            if (!Settings.allowMobDamageToItemFrames) {
                if (DEBUG)
                    plugin.getLogger().info("DEBUG: Damage not allowed, cancelling");
                e.setCancelled(true);
            }
        }
    }
}
 
Example #4
Source File: FrameManager.java    From AnimatedFrames with MIT License 6 votes vote down vote up
@Synchronized
public AnimatedFrame createFrame(String name, String source, ItemFrame firstFrame, ItemFrame secondFrame) {
	if (frameMap.containsKey(name)) {
		throw new IllegalArgumentException("Frame '" + name + "' already exists");
	}
	JsonObject meta = new JsonObject();
	AsyncFrameCreationEvent creationEvent = new AsyncFrameCreationEvent(name, source, firstFrame, secondFrame, meta);
	Bukkit.getPluginManager().callEvent(creationEvent);
	name = creationEvent.getName();
	source = creationEvent.getSource();

	AnimatedFrame frame = new AnimatedFrame(firstFrame, new Vector3DDouble(firstFrame.getLocation().toVector()), new Vector3DDouble(secondFrame.getLocation().toVector()), name, source);
	frameMap.put(frame.getName(), frame);
	frame.setMeta(meta);

	return frame;
}
 
Example #5
Source File: MapInteractEvent.java    From MapManager with MIT License 6 votes vote down vote up
/**
 * @return the {@link MapWrapper} of the clicked frame
 */
public MapWrapper getMapWrapper() {
	if (this.mapWrapper != null) { return this.mapWrapper; }
	ItemFrame itemFrame = getItemFrame();
	if (itemFrame != null) {
		if (itemFrame.hasMetadata("MAP_WRAPPER_REF")) {
			List<MetadataValue> metadataValues = itemFrame.getMetadata("MAP_WRAPPER_REF");
			for (MetadataValue value : metadataValues) {
				MapWrapper wrapper = (MapWrapper) value.value();
				if (wrapper != null) {
					return this.mapWrapper = wrapper;
				}
			}
		}
	}
	return null;
}
 
Example #6
Source File: DefaultMapWrapper.java    From MapManager with MIT License 6 votes vote down vote up
@Override
public void showInFrame(Player player, int entityId, String debugInfo) {
	if (!isViewing(player)) {
		return;
	}
	//Create the ItemStack with the player's map ID
	ItemStack itemStack = new ItemStack(MAP_MATERIAL, 1, getMapId(player));
	if (debugInfo != null) {
		//Add the debug info to the display
		ItemMeta itemMeta = itemStack.getItemMeta();
		itemMeta.setDisplayName(debugInfo);
		itemStack.setItemMeta(itemMeta);
	}

	ItemFrame itemFrame = MapManagerPlugin.getItemFrameById(player.getWorld(), entityId);
	if (itemFrame != null) {
		//Add a reference to this MapWrapper (can be used in MapWrapper#getWrapperForId)
		itemFrame.removeMetadata("MAP_WRAPPER_REF", MapManagerPlugin.instance);
		itemFrame.setMetadata("MAP_WRAPPER_REF", new FixedMetadataValue(MapManagerPlugin.instance, DefaultMapWrapper.this));
	}

	sendItemFramePacket(player, entityId, itemStack);
}
 
Example #7
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 #8
Source File: QuestItemHandler.java    From BetonQuest with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onItemFrameClick(final PlayerInteractEntityEvent event) {
    if (event.getPlayer().getGameMode() == GameMode.CREATIVE) {
        return;
    }
    // this prevents the journal from being placed inside of item frame
    if (event.getRightClicked() instanceof ItemFrame) {
        ItemStack item = null;
        item = (event.getHand() == EquipmentSlot.HAND) ? event.getPlayer().getInventory().getItemInMainHand()
                : event.getPlayer().getInventory().getItemInOffHand();

        final String playerID = PlayerConverter.getID(event.getPlayer());
        if (Journal.isJournal(playerID, item) || Utils.isQuestItem(item)) {
            event.setCancelled(true);
        }
    }
}
 
Example #9
Source File: ItemFrameStorage.java    From civcraft with GNU General Public License v2.0 6 votes vote down vote up
public ItemFrameStorage(ItemFrame frame, Location attachedLoc) throws CivException {
		if (frame != null) {
			this.frameID = frame.getUniqueId();
			this.location = frame.getLocation();
			this.attachedBlock = new BlockCoord(attachedLoc);
			CivGlobal.addProtectedItemFrame(this);
		} else {
			throw new CivException("Passed a null item frame to storage constructor.");
		}
		
//		this.frame = frame;
//		if (this.frame != null) {
//			CivGlobal.addProtectedItemFrame(this);
//		} else {
//			CivLog.error("Passed a null item frame!!!");
//			throw new CivException("Passed a null item frame.");
//		}
	}
 
Example #10
Source File: ItemFrameStorage.java    From civcraft with GNU General Public License v2.0 6 votes vote down vote up
public ItemFrame getItemFrame() {
	// Gets the item frame by loading in the chunk where it is supposed to reside.
	// Then searching for it's UUID.
	
	if (!this.location.getChunk().isLoaded()) {
		if (!this.location.getChunk().load()) {
			CivLog.error("Could not load chunk to get item frame at:"+this.location);
			return null;
		}
	}
	
	Entity ent = CivGlobal.getEntityClassFromUUID(this.location.getWorld(), ItemFrame.class, this.frameID);
	if (ent == null) {
		CivLog.error("Could not find frame from frame ID:"+this.frameID.toString());
		return null;
	}
	
	if (!(ent instanceof ItemFrame)) {
		CivLog.error("Could not get a frame with ID:"+this.frameID+" ... it was not a frame.");
		return null;
	}
	
	//TODO try and use a cache and isValid()?
	
	return (ItemFrame)ent;
}
 
Example #11
Source File: AnimatedFrame.java    From AnimatedFrames with MIT License 6 votes vote down vote up
public void clearFrames() {
	if (this.mapWrappers != null) {
		for (MapWrapper wrapper : this.mapWrappers) {
			for (UUID uuid : worldPlayers) {
				Player player = Bukkit.getPlayer(uuid);
				if (player != null) {
					((MultiMapController) wrapper.getController()).clearFrames(player, this.itemFrameIds);
				}
			}
			wrapper.getController().clearViewers();
		}
		for (int[] iA : this.itemFrameIds) {
			for (int i : iA) {
				ItemFrame itemFrame = MapManagerPlugin.getItemFrameById(getWorld(), i);
				if (itemFrame != null) {
					itemFrame.removeMetadata("ANIMATED_FRAMES_META", plugin);
				}
			}
		}
	}
}
 
Example #12
Source File: DebugCommand.java    From civcraft with GNU General Public License v2.0 6 votes vote down vote up
public void moveframes_cmd() throws CivException {
	Player player = getPlayer();
	Chunk chunk = player.getLocation().getChunk();
	
//	int x = this.getNamedInteger(1);
//	int y = this.getNamedInteger(2);
//	int z = this.getNamedInteger(3);
	
//	Location loc = new Location(player.getWorld(), x, y, z);
	
	for (Entity entity : chunk.getEntities()) {
		if (entity instanceof ItemFrame) {
			CivMessage.send(sender, "Teleported...");
			entity.teleport(entity.getLocation());
		}
	}
	
}
 
Example #13
Source File: IslandGuard.java    From askyblock with GNU General Public License v2.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onItemFrameDamage(final HangingBreakByEntityEvent e) {
    if (DEBUG) {
        plugin.getLogger().info("DEBUG: Hanging break by entity event");
        plugin.getLogger().info("DEBUG: cause = " + e.getCause());
        plugin.getLogger().info("DEBUG: entity = " + e.getEntity());
        plugin.getLogger().info("DEBUG: remover = " + e.getRemover());
    }
    // Check world
    if (!inWorld(e.getEntity()) || !(e.getEntity() instanceof ItemFrame)) {
        return;
    }
    if (e.getRemover() instanceof Skeleton || e.getRemover() instanceof Golem) {
        if (DEBUG)
            plugin.getLogger().info("DEBUG: Remover is mob");
        if (!Settings.allowMobDamageToItemFrames) {
            if (DEBUG)
                plugin.getLogger().info("DEBUG: Damage not allowed, cancelling");
            e.setCancelled(true);
        }
    }
}
 
Example #14
Source File: BlockBreakRegion.java    From CardinalPGM with MIT License 5 votes vote down vote up
@EventHandler
public void onPlayerAttackEntity(PlayerAttackEntityEvent event) {
    if (event.getLeftClicked() instanceof ItemFrame) {
        if (region.contains(event.getLeftClicked().getLocation().toVector()) && filter.evaluate(event.getLeftClicked(), event.getPlayer(), event).equals(FilterState.DENY)) {
            event.setCancelled(true);
        }
    }
}
 
Example #15
Source File: AnimatedFrame.java    From AnimatedFrames with MIT License 5 votes vote down vote up
public AnimatedFrame(ItemFrame baseFrame, Vector3DDouble firstCorner, Vector3DDouble secondCorner, String name, String imageSource, int width, int height) {
	super(baseFrame, firstCorner, secondCorner);
	this.name = name;
	this.imageSource = imageSource;
	this.width = width;
	this.height = height;
}
 
Example #16
Source File: AsyncFrameCreationEvent.java    From AnimatedFrames with MIT License 5 votes vote down vote up
public AsyncFrameCreationEvent(String name, String source, ItemFrame firstFrame, ItemFrame secondFrame, JsonObject meta) {
	super(true);
	this.name = name;
	this.source = source;
	this.firstFrame = firstFrame;
	this.secondFrame = secondFrame;
	this.meta = meta;
}
 
Example #17
Source File: AnimatedFrame.java    From AnimatedFrames with MIT License 5 votes vote down vote up
public AnimatedFrame(ItemFrame baseFrame, Vector3DDouble firstCorner, Vector3DDouble secondCorner, String name, String imageSource) {
	super(baseFrame, firstCorner, secondCorner);
	this.name = name;
	this.imageSource = imageSource;
	this.width = getBlockWidth();
	this.height = getBlockHeight();
}
 
Example #18
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 #19
Source File: MultiMapWrapper.java    From MapManager with MIT License 5 votes vote down vote up
@Override
public void showInFrames(Player player, ItemFrame[][] itemFrameMatrix, boolean force) {
	for (int x = 0; x < itemFrameMatrix.length; x++) {
		for (int y = 0; y < itemFrameMatrix[x].length; y++) {
			wrapperMatrix[y][x].getController().showInFrame(player, itemFrameMatrix[x][wrapperMatrix.length - 1 - y], force);
		}
	}
}
 
Example #20
Source File: MultiMapWrapper.java    From MapManager with MIT License 5 votes vote down vote up
@Override
public void clearFrames(Player player, ItemFrame[][] itemFrameMatrix) {
	for (int x = 0; x < itemFrameMatrix.length; x++) {
		for (int y = 0; y < itemFrameMatrix[x].length; y++) {
			wrapperMatrix[y][x].getController().clearFrame(player, itemFrameMatrix[x][y]);
		}
	}
}
 
Example #21
Source File: RegionMatchModule.java    From PGM with GNU Affero General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void checkItemFrameItemRemove(EntityDamageByEntityEvent event) {
  // This event is fired when popping an item out of an item frame, without breaking the frame
  // itself
  if (event.getEntity() instanceof ItemFrame
      && ((ItemFrame) event.getEntity()).getItem() != null) {
    this.handleHangingBreak(event, (Hanging) event.getEntity(), event.getDamager());
  }
}
 
Example #22
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 #23
Source File: BlockEventRegion.java    From CardinalPGM with MIT License 5 votes vote down vote up
@EventHandler
public void onPlayerAttackEntity(PlayerAttackEntityEvent event) {
    if (event.getLeftClicked() instanceof ItemFrame) {
        if (region.contains(event.getLeftClicked().getLocation().toVector()) && filter.evaluate(event.getLeftClicked(), event.getPlayer(), event).equals(FilterState.DENY)) {
            event.setCancelled(true);
        }
    }
}
 
Example #24
Source File: ItemFrameStorage.java    From civcraft with GNU General Public License v2.0 5 votes vote down vote up
public void setItem(ItemStack stack) {

		ItemFrame frame = getItemFrame();
		if (frame != null) {
			ItemStack newStack = new ItemStack(stack.getType(), 1, stack.getDurability());
			newStack.setData(stack.getData());
			newStack.setItemMeta(stack.getItemMeta());
			frame.setItem(newStack);
		} else {
			CivLog.warning("Frame:"+this.frameID+" was null when trying to set to "+stack.getType().name());
		}
		
	}
 
Example #25
Source File: DefaultMapWrapper.java    From MapManager with MIT License 5 votes vote down vote up
@Override
public void clearFrame(Player player, int entityId) {
	sendItemFramePacket(player, entityId, null);
	ItemFrame itemFrame = MapManagerPlugin.getItemFrameById(player.getWorld(), entityId);
	if (itemFrame != null) {
		//Remove the reference
		itemFrame.removeMetadata("MAP_WRAPPER_REF", MapManagerPlugin.instance);
	}
}
 
Example #26
Source File: BukkitImageViewer.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
private ItemFrame[][] find(Location pos1, Location pos2, BlockFace facing) {
    try {
        Location distance = pos2.clone().subtract(pos1).add(1, 1, 1);
        int width = Math.max(distance.getBlockX(), distance.getBlockZ());
        ItemFrame[][] frames = new ItemFrame[width][distance.getBlockY()];

        World world = pos1.getWorld();

        this.reverse = (facing == BlockFace.NORTH || facing == BlockFace.EAST);
        int v = 0;
        for (double y = pos1.getY(); y <= pos2.getY(); y++, v++) {
            int h = 0;
            for (double z = pos1.getZ(); z <= pos2.getZ(); z++) {
                for (double x = pos1.getX(); x <= pos2.getX(); x++, h++) {
                    Location pos = new Location(world, x, y, z);
                    Collection<Entity> entities = world.getNearbyEntities(pos, 0.1, 0.1, 0.1);
                    boolean contains = false;
                    for (Entity ent : entities) {
                        if (ent instanceof ItemFrame && ((ItemFrame) ent).getFacing() == facing) {
                            ItemFrame itemFrame = (ItemFrame) ent;
                            itemFrame.setRotation(Rotation.NONE);
                            contains = true;
                            frames[reverse ? width - 1 - h : h][v] = (ItemFrame) ent;
                            break;
                        }
                    }
                    if (!contains) return null;
                }
            }
        }
        return frames;
    } catch (Throwable e) {
        e.printStackTrace();
    }
    return null;
}
 
Example #27
Source File: MainListener.java    From ArmorStandTools with MIT License 5 votes vote down vote up
@EventHandler
public void onPlayerInteractEntity(PlayerInteractEntityEvent event) {
    if (event.getRightClicked() instanceof ItemFrame && ArmorStandTool.isHoldingTool(event.getPlayer())) {
        event.setCancelled(true);
        //noinspection deprecation
        event.getPlayer().updateInventory();
    }
}
 
Example #28
Source File: ObserverModule.java    From CardinalPGM with MIT License 5 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onPlayerInteractEntity(PlayerInteractEntityEvent event) {
    if (testObserver(event.getPlayer())) {
        if (event.getRightClicked() instanceof Player && !event.getPlayer().isSneaking()){
            if (event.getHand().equals(EquipmentSlot.HAND)) openInventory(event.getPlayer(), (Player) event.getRightClicked(), false);
        } else if (event.getRightClicked() instanceof ItemFrame) {
            event.setCancelled(true);
        }
    }
}
 
Example #29
Source File: ItemFrameStorage.java    From civcraft with GNU General Public License v2.0 5 votes vote down vote up
public ItemFrameStorage(Location location, BlockFace blockface) {
		
	ItemFrame frame = (ItemFrame)location.getWorld().spawnEntity(location, EntityType.ITEM_FRAME);
	//frame.setItem(new ItemStack(Material.BAKED_POTATO));
	
	this.frameID = frame.getUniqueId();
	this.location = frame.getLocation();
	this.attachedBlock = new BlockCoord(location);
	CivGlobal.addProtectedItemFrame(this);
	
}
 
Example #30
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;
}