@EventHandler(ignoreCancelled = true) public void onSignChange(SignChangeEvent event) { final Block b = event.getBlock(); Sign sign = (Sign) b.getState().getData(); Block attachedTo = b.getRelative(sign.getAttachedFace()); BaseSTBBlock item = LocationManager.getManager().get(attachedTo.getLocation()); if (item != null) { boolean ret = item.onSignChange(event); if (ret) { // pop the sign off next tick; it's done its job Bukkit.getScheduler().runTask(plugin, new Runnable() { @Override public void run() { b.setType(Material.AIR); b.getWorld().dropItemNaturally(b.getLocation(), new ItemStack(Material.SIGN)); } }); } } }
@EventHandler public void onCreate(SignChangeEvent e) { if(e.getLine(0).equalsIgnoreCase("[dispense]") || e.getLine(0).equalsIgnoreCase("[dispenser]")) { if(e.getPlayer().hasPermission(PermissionKey.SIGN_DISPENSER_CREATE.getPermission())) { Sign sign = (Sign) e.getBlock().getState().getData(); if(e.getBlock().getRelative(sign.getAttachedFace()).getType() == Material.DISPENSER) { e.setLine(0, ChatColor.BLUE + "[Dispense]"); sendMessage(e.getPlayer(), ChatColor.GREEN + "you successfully placed a dispense sign!"); } else { sendMessage(e.getPlayer(), ChatColor.RED + "your sign has to be attached to a dispenser!"); e.setCancelled(true); } } else { sendMessage(e.getPlayer(), ChatColor.RED + "you are not allowed to make dispense signs!"); e.setCancelled(true); } } }
@EventHandler public void onPower(BlockDispenseEvent e) { if(e.getBlock().getType() == Material.DISPENSER) { if(hasNearbySign(e.getBlock())) { org.bukkit.block.Sign sign = getSign(e.getBlock()); if(sign.getLine(0).equalsIgnoreCase(ChatColor.BLUE + "[Dispense]")) { Dispenser disp = (Dispenser) e.getBlock().getState(); for(ItemStack stack : disp.getInventory().getContents()) { if(stack != null) { ItemStack clone = stack.clone(); clone.setAmount(64); disp.getInventory().addItem(clone); } } } } } }
public boolean placeLeaderboard(Block leaderboardBlock) { if (leaderboardBlock.getType() != Material.WALL_SIGN) { return false; } MaterialData signData = leaderboardBlock.getState().getData(); if (!(signData instanceof Sign)) { controller.getPlugin().getLogger().warning("Block at " + leaderboardBlock.getLocation() + " has no sign data! " + signData.getClass()); return false; } Sign sign = (Sign)signData; BlockFace signDirection = sign.getFacing(); BlockFace rightDirection = goLeft(signDirection); Block checkBlock = leaderboardBlock; for (int y = 0; y <= leaderboardSize; y++) { Block neighborBlock = checkBlock.getRelative(rightDirection); if (!canReplace(neighborBlock)) { return false; } if (y != 0 && !canReplace(checkBlock)) { return false; } checkBlock = checkBlock.getRelative(BlockFace.UP); } removeLeaderboard(); leaderboardLocation = leaderboardBlock.getLocation(); leaderboardFacing = signDirection; updateLeaderboard(); return true; }
/** * Block physics event handler<br> * remove detached death chest signs from game to prevent players gaining additional signs * @param event */ @EventHandler public void signDetachCheck(BlockPhysicsEvent event) { Block block = event.getBlock(); // if event is cancelled, do nothing and return if (event.isCancelled()) { return; } // if block is not a DeathChestBlock, do nothing and return if (!DeathChestBlock.isDeathChestBlock(block)) { return; } // if block is not a sign, do nothing and return if (block.getType() != Material.WALL_SIGN && block.getType() != Material.SIGN_POST) { return; } Sign sign = (Sign)block.getState().getData(); Block attached_block = block.getRelative(sign.getAttachedFace()); // if attached block is still there, do nothing and return if (attached_block.getType() != Material.AIR) { return; } // cancel event event.setCancelled(true); // destroy DeathChestBlock plugin.chestManager.destroyDeathChestBlock(block); }
public static void openInventory(Player player, Block block) { // if block is null or not a death chest block, do nothing and return if (block == null || ! isDeathChestBlock(block)) { return; } // if block is wall sign, set block to attached block if (block.getType().equals(Material.WALL_SIGN)) { Sign sign = (Sign)block.getState().getData(); block = block.getRelative(sign.getAttachedFace()); } // if block is sign post, set block to one block below else if (block.getType().equals(Material.SIGN_POST)) { block = block.getRelative(0, 1, 0); } // confirm block is a death chest if (! block.getType().equals(Material.CHEST) || ! DeathChestBlock.isDeathChestBlock(block)) { return; } // open chest inventory BlockState state = block.getState(); Chest chest = (Chest)state; Inventory inventory = chest.getInventory(); player.openInventory(inventory); }
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR) public void onLabelSignBroken(BlockBreakEvent event) { if (event.getBlock().getType() == Material.WALL_SIGN) { Sign sign = (Sign) event.getBlock().getState().getData(); Block b2 = event.getBlock().getRelative(sign.getAttachedFace()); BaseSTBBlock stb = LocationManager.getManager().get(b2.getLocation()); if (stb != null) { stb.detachLabelSign(sign.getAttachedFace().getOppositeFace()); } } }
/** * Get the STB block at the given location, or if the location contains a * sign, possibly at the location the sign is attached to. * * @param loc the location to check at * @param checkSigns if true, and the location contains a sign, check at * the location that the sign is attached to * @return the STB block at the given location, or null if no matching item */ public BaseSTBBlock get(Location loc, boolean checkSigns) { Block b = loc.getBlock(); if (checkSigns && (b.getType() == Material.WALL_SIGN || b.getType() == Material.SIGN_POST)) { Sign sign = (Sign) b.getState().getData(); b = b.getRelative(sign.getAttachedFace()); } BaseSTBBlock stb = (BaseSTBBlock) STBUtil.getMetadataValue(b, BaseSTBBlock.STB_BLOCK); if (stb != null) { return stb; } else { // perhaps it's part of a multi-block structure return (BaseSTBBlock) STBUtil.getMetadataValue(b, BaseSTBBlock.STB_MULTI_BLOCK); } }
@Override public void execute(CommandSender sender, String[] args) { if(!sender.hasPermission("areashop.addsign")) { plugin.message(sender, "addsign-noPermission"); return; } if(!(sender instanceof Player)) { plugin.message(sender, "cmd-onlyByPlayer"); return; } Player player = (Player)sender; // Get the sign Block block = null; BlockIterator blockIterator = new BlockIterator(player, 100); while(blockIterator.hasNext() && block == null) { Block next = blockIterator.next(); if(next.getType() != Material.AIR) { block = next; } } if(block == null || !(block.getType() == Material.WALL_SIGN || block.getType() == Material.SIGN_POST)) { plugin.message(sender, "addsign-noSign"); return; } GeneralRegion region; if(args.length > 1) { // Get region by argument region = plugin.getFileManager().getRegion(args[1]); if(region == null) { plugin.message(sender, "cmd-notRegistered", args[1]); return; } } else { // Get region by sign position List<GeneralRegion> regions = Utils.getRegionsInSelection(new CuboidSelection(block.getWorld(), block.getLocation(), block.getLocation())); if(regions.isEmpty()) { plugin.message(sender, "addsign-noRegions"); return; } else if(regions.size() > 1) { plugin.message(sender, "addsign-couldNotDetect", regions.get(0).getName(), regions.get(1).getName()); return; } region = regions.get(0); } Sign sign = (Sign)block.getState().getData(); String profile = null; if(args.length > 2) { profile = args[2]; Set<String> profiles = plugin.getConfig().getConfigurationSection("signProfiles").getKeys(false); if(!profiles.contains(profile)) { plugin.message(sender, "addsign-wrongProfile", Utils.createCommaSeparatedList(profiles), region); return; } } RegionSign regionSign = SignsFeature.getSignByLocation(block.getLocation()); if(regionSign != null) { plugin.message(sender, "addsign-alreadyRegistered", regionSign.getRegion()); return; } region.getSignsFeature().addSign(block.getLocation(), block.getType(), sign.getFacing(), profile); if(profile == null) { plugin.message(sender, "addsign-success", region); } else { plugin.message(sender, "addsign-successProfile", profile, region); } region.update(); }
public Sign() { }
@Deprecated public Sign(int type) { }
public Sign(Material type) { }
@Deprecated public Sign(int type, byte data) { }
@Deprecated public Sign(Material type, byte data) { }
public Sign clone() { return null; }
@EventHandler(priority = EventPriority.LOWEST) public void onEditSign(SignChangeEvent e) { Sign sign = (Sign)e.getBlock().getState().getData(); Block other = e.getBlock().getRelative(sign.getFacing().getOppositeFace()); if(other.getType() == Material.WALL_SIGN || other.getType() == Material.SIGN_POST) { org.bukkit.block.Sign signn = (org.bukkit.block.Sign)other.getState(); XPlayer xp = pl.getManagers().getPlayerManager().getPlayer(e.getPlayer().getName()); if(xp.isEditSignEnabled()) { if(pl.getConfiguration().getProtectionConfig().isProtectionEnabled()) { ProtectedBlock pblock = new ProtectedBlock(pl, e.getBlock()); if(pblock.isMember(e.getPlayer().getUniqueId())) { signn.setLine(0, e.getLine(0)); signn.setLine(1, e.getLine(1)); signn.setLine(2, e.getLine(2)); signn.setLine(3, e.getLine(3)); signn.update(true); sendMessage(e.getPlayer(), ChatColor.GREEN + "successfully edited sign."); pblock.removeProtection(e.getPlayer().getUniqueId()); e.getBlock().setType(Material.AIR); Bukkit.getPluginManager().callEvent(new BlockPlaceEvent(signn.getBlock(), signn, signn.getBlock(), new ItemStack(Material.SIGN, 1), e.getPlayer(), true)); } else { e.getBlock().setType(Material.AIR); e.setCancelled(true); sendMessage(e.getPlayer(), ChatColor.RED + "cannot modify sign, this sign does not belongs to you"); } } else if(Hooks.isLWCEnabled()) { if(LWCHook.isOwner(e.getPlayer(), signn.getBlock())) { signn.setLine(0, e.getLine(0)); signn.setLine(1, e.getLine(1)); signn.setLine(2, e.getLine(2)); signn.setLine(3, e.getLine(3)); signn.update(true); sendMessage(e.getPlayer(), ChatColor.GREEN + "successfully edited sign."); LWCHook.removeProtection(e.getBlock()); e.getBlock().setType(Material.AIR); Bukkit.getPluginManager().callEvent(new BlockPlaceEvent(signn.getBlock(), signn, signn.getBlock(), new ItemStack(Material.SIGN, 1), e.getPlayer(), true)); } else { e.getBlock().setType(Material.AIR); e.setCancelled(true); sendMessage(e.getPlayer(), ChatColor.RED + "cannot modify sign, this sign does not belongs to you"); } } } } }