Java Code Examples for org.bukkit.block.Sign#setLine()
The following examples show how to use
org.bukkit.block.Sign#setLine() .
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: Cannon.java From civcraft with GNU General Public License v2.0 | 6 votes |
private void updateAngleSign(Block block) { Sign sign = (Sign)block.getState(); sign.setLine(0, "YAW"); sign.setLine(1, ""+this.angle); double a = this.angle; if (a > 0) { sign.setLine(2, "-->"); } else if (a < 0){ sign.setLine(2, "<--"); } else { sign.setLine(2, ""); } sign.setLine(3, ""); sign.update(); }
Example 2
Source File: SignListener.java From ChestCommands with GNU General Public License v3.0 | 6 votes |
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) public void onInteract(PlayerInteractEvent event) { if (event.getAction() == Action.RIGHT_CLICK_BLOCK && event.hasBlock() && event.getClickedBlock().getState() instanceof Sign) { Sign sign = (Sign) event.getClickedBlock().getState(); if (sign.getLine(0).equalsIgnoreCase(ChatColor.DARK_BLUE + "[menu]")) { sign.getLine(1); ExtendedIconMenu iconMenu = ChestCommands.getFileNameToMenuMap().get(BukkitUtils.addYamlExtension(sign.getLine(1))); if (iconMenu != null) { if (event.getPlayer().hasPermission(iconMenu.getPermission())) { iconMenu.open(event.getPlayer()); } else { iconMenu.sendNoPermissionMessage(event.getPlayer()); } } else { sign.setLine(0, ChatColor.RED + ChatColor.stripColor(sign.getLine(0))); event.getPlayer().sendMessage(ChestCommands.getLang().menu_not_found); } } } }
Example 3
Source File: SignUtil.java From GriefDefender with MIT License | 6 votes |
public static void updateSignRentable(Claim claim, Sign sign) { if (!isRentSign(claim, sign)) { return; } final PaymentType paymentType = claim.getEconomyData().getPaymentType(); List<String> colorLines = new ArrayList<>(4); colorLines.add(ChatColor.translateAlternateColorCodes('&', "&7[&bGD&7-&1rent&7]")); colorLines.add(ChatColor.translateAlternateColorCodes('&', LegacyComponentSerializer.legacy().serialize(MessageCache.getInstance().ECONOMY_SIGN_RENT_DESCRIPTION))); colorLines.add(ChatColor.translateAlternateColorCodes('&', "&4$" + claim.getEconomyData().getRentRate())); for (int i = 0; i < colorLines.size(); i++) { sign.setLine(i, colorLines.get(i)); } sign.update(); }
Example 4
Source File: BedWarsSignOwner.java From BedWars with GNU Lesser General Public License v3.0 | 6 votes |
private void updateLeaveSign(SignBlock sign) { List<String> texts = new ArrayList<>(Main.getConfigurator().config.getStringList("sign")); Block block = sign.getLocation().getBlock(); if (block.getState() instanceof Sign) { Sign state = (Sign) block.getState(); for (int i = 0; i < texts.size(); i++) { String text = texts.get(i); state.setLine(i, text.replaceAll("%arena%", i18nonly("leave_from_game_item")).replaceAll("%status%", "") .replaceAll("%players%", "")); } state.update(); } }
Example 5
Source File: DebugCommand.java From civcraft with GNU General Public License v2.0 | 5 votes |
public void restoresigns_cmd() { CivMessage.send(sender, "restoring...."); for (StructureSign sign : CivGlobal.getStructureSigns()) { BlockCoord bcoord = sign.getCoord(); Block block = bcoord.getBlock(); ItemManager.setTypeId(block, CivData.WALL_SIGN); ItemManager.setData(block, sign.getDirection()); Sign s = (Sign)block.getState(); String[] lines = sign.getText().split("\n"); if (lines.length > 0) { s.setLine(0, lines[0]); } if (lines.length > 1) { s.setLine(1, lines[1]); } if (lines.length > 2) { s.setLine(2, lines[2]); } if (lines.length > 3) { s.setLine(3, lines[3]); } s.update(); } }
Example 6
Source File: SignLayout.java From HeavySpleef with GNU General Public License v3.0 | 5 votes |
public boolean inflate(Sign sign, VariableSuppliable suppliable) { String[] result = generate(suppliable); for (int i = 0; i < result.length; i++) { sign.setLine(i, result[i]); } return sign.update(); }
Example 7
Source File: Door.java From ZombieEscape with GNU General Public License v2.0 | 5 votes |
/** * Activates the Door Open sequence. If the door is already * activated, it will notify the activator. Otherwise, it will * start a countdown provided by the timer. At the end, it will * open the door. * * @param player the player to activate the door * @param sign the sign that was interacted with * @param plugin the plugin instance */ public void activate(Player player, final Sign sign, final Plugin plugin) { if (isActivated()) { Messages.DOOR_ALREADY_ACTIVATED.send(player); return; } Messages.DOOR_ACTIVATED.send(player); activated = true; sign.setLine(2, Utils.color("&4&lACTIVATED")); sign.setLine(3, ""); task = new BukkitRunnable() { int countdown = seconds; @Override public void run() { if (countdown == 0) { open(plugin, sign); cancel(); task = -1; return; } sign.setLine(1, "Timer: " + countdown + "s"); sign.update(); countdown--; } }.runTaskTimer(plugin, 0, 20).getTaskId(); }
Example 8
Source File: SignLayout.java From HeavySpleef with GNU General Public License v3.0 | 5 votes |
public boolean inflate(Sign sign, Set<Variable> variables) { for (int i = 0; i < lines.size() && i < LINE_COUNT; i++) { CustomizableLine line = lines.get(i); String lineString = line.generate(variables); sign.setLine(i, lineString); } return sign.update(); }
Example 9
Source File: Buildable.java From civcraft with GNU General Public License v2.0 | 5 votes |
public synchronized void buildRepairTemplate(Template tpl, Block centerBlock) { HashMap<Chunk, Chunk> chunkUpdates = new HashMap<Chunk, Chunk>(); for (int x = 0; x < tpl.size_x; x++) { for (int y = 0; y < tpl.size_y; y++) { for (int z = 0; z < tpl.size_z; z++) { Block b = centerBlock.getRelative(x, y, z); //b.setTypeIdAndData(tpl.blocks[x][y][z].getType(), (byte)tpl.blocks[x][y][z].getData(), false); if (tpl.blocks[x][y][z].specialType == Type.COMMAND) { ItemManager.setTypeIdAndData(b, CivData.AIR, (byte)0, false); } else { ItemManager.setTypeIdAndData(b, tpl.blocks[x][y][z].getType(), (byte)tpl.blocks[x][y][z].getData(), false); } chunkUpdates.put(b.getChunk(), b.getChunk()); if (ItemManager.getId(b) == CivData.WALL_SIGN || ItemManager.getId(b) == CivData.SIGN) { Sign s2 = (Sign)b.getState(); s2.setLine(0, tpl.blocks[x][y][z].message[0]); s2.setLine(1, tpl.blocks[x][y][z].message[1]); s2.setLine(2, tpl.blocks[x][y][z].message[2]); s2.setLine(3, tpl.blocks[x][y][z].message[3]); s2.update(); } } } } }
Example 10
Source File: SignShop.java From Shopkeepers with GNU General Public License v3.0 | 5 votes |
public void updateSign() { Sign sign = this.getSign(); if (sign == null) { updateSign = true; // request update, once the sign is available again return; } // line 0: header sign.setLine(0, Settings.signShopFirstLine); // line 1: shop name String name = shopkeeper.getName(); String line1 = ""; if (name != null) { name = this.trimToNameLength(name); line1 = name; } sign.setLine(1, line1); // line 2: owner name String line2 = ""; if (shopkeeper instanceof PlayerShopkeeper) { line2 = ((PlayerShopkeeper) shopkeeper).getOwnerName(); } sign.setLine(2, line2); // line 3: empty sign.setLine(3, ""); // apply sign changes: sign.update(); }
Example 11
Source File: StructureSign.java From civcraft with GNU General Public License v2.0 | 5 votes |
public void update() { if (coord.getBlock().getState() instanceof Sign) { Sign sign = (Sign)coord.getBlock().getState(); String[] lines = this.text.split("\\n"); for (int i = 0; i < 4; i++) { if (i < lines.length) { sign.setLine(i, lines[i]); } else { sign.setLine(i, ""); } } sign.update(); } }
Example 12
Source File: PlayerListener.java From RedProtect with GNU General Public License v3.0 | 5 votes |
private void changeFlag(Region r, String flag, Player p, Sign s) { if (r.setFlag(p, flag, !r.getFlagBool(flag))) { RedProtect.get().lang.sendMessage(p, RedProtect.get().lang.get("cmdmanager.region.flag.set").replace("{flag}", "'" + flag + "'") + " " + r.getFlagBool(flag)); RedProtect.get().logger.addLog("(World " + r.getWorld() + ") Player " + p.getName() + " SET FLAG " + flag + " of region " + r.getName() + " to " + RedProtect.get().lang.translBool(r.getFlagString(flag))); s.setLine(3, ChatColor.translateAlternateColorCodes('&', RedProtect.get().lang.get("region.value") + " " + RedProtect.get().lang.translBool(r.getFlagString(flag)))); s.update(); if (!RedProtect.get().config.getSigns(r.getID()).contains(s.getLocation())) { RedProtect.get().config.putSign(r.getID(), s.getLocation()); } } }
Example 13
Source File: ContainerShop.java From QuickShop-Reremake with GNU General Public License v3.0 | 5 votes |
/** * Changes all lines of text on a sign near the shop * * @param lines The array of lines to change. Index is line number. */ @Override public void setSignText(@NotNull String[] lines) { for (Sign sign : this.getSigns()) { if (Arrays.equals(sign.getLines(), lines)) { Util.debugLog("Skipped new sign text setup: Same content"); continue; } for (int i = 0; i < lines.length; i++) { sign.setLine(i, lines[i]); } sign.update(true); } }
Example 14
Source File: Cannon.java From civcraft with GNU General Public License v2.0 | 5 votes |
private void updatePowerSign(Block block) { Sign sign = (Sign)block.getState(); sign.setLine(0, "PITCH"); sign.setLine(1, ""+this.power); sign.setLine(2, ""); sign.setLine(3, ""); sign.update(); }
Example 15
Source File: JoinSign.java From DungeonsXL with GNU General Public License v3.0 | 5 votes |
/** * Clears signs */ public void update() { int y = -1 * verticalSigns; while (startSign.getRelative(0, y + 1, 0).getState() instanceof Sign && y != 0) { Sign subsign = (Sign) startSign.getRelative(0, y + 1, 0).getState(); subsign.setLine(0, ""); subsign.setLine(1, ""); subsign.setLine(2, ""); subsign.setLine(3, ""); subsign.update(); y++; } }
Example 16
Source File: SiegeEffect.java From Civs with GNU General Public License v3.0 | 4 votes |
@EventHandler public void onCustomEvent(RegionTickEvent event) { if (!event.getRegion().getEffects().containsKey(KEY) || !event.isHasUpkeep()) { return; } Region region = event.getRegion(); Location l = region.getLocation(); String damageString = region.getEffects().get(KEY); int damage = 1; if (damageString != null) { damage = Integer.parseInt(damageString); } //Check if valid siege machine position if (l.getBlock().getY() + 2 < l.getWorld().getHighestBlockAt(l).getY()) { return; } Block b = l.getBlock().getRelative(BlockFace.UP); BlockState state = b.getState(); if (!(state instanceof Sign)) { return; } //Find target Super-region Sign sign = (Sign) state; String townName = sign.getLine(0); Town town = TownManager.getInstance().getTown(townName); if (town == null) { for (Town currentTown : TownManager.getInstance().getTowns()) { if (currentTown.getName().startsWith(townName)) { town = currentTown; break; } } if (town == null) { sign.setLine(2, "invalid name"); sign.update(); return; } } //Check if too far away TownType townType = (TownType) ItemManager.getInstance().getItemType(town.getType()); double rawRadius = townType.getBuildRadius(); try { if (town.getLocation().distance(l) - rawRadius > 150) { sign.setLine(2, "out of"); sign.setLine(3, "range"); sign.update(); return; } } catch (IllegalArgumentException iae) { sign.setLine(2, "out of"); sign.setLine(3, "range"); sign.update(); return; } if (town.getPower() < 1) { return; } Location spawnLoc = l.getBlock().getRelative(BlockFace.UP, 3).getLocation(); Location loc = new Location(spawnLoc.getWorld(), spawnLoc.getX(), spawnLoc.getY() + 15, spawnLoc.getZ()); final Location loc1 = new Location(spawnLoc.getWorld(), spawnLoc.getX(), spawnLoc.getY() + 20, spawnLoc.getZ()); final Location loc2 = new Location(spawnLoc.getWorld(), spawnLoc.getX(), spawnLoc.getY() + 25, spawnLoc.getZ()); final Location loc3 = new Location(spawnLoc.getWorld(), spawnLoc.getX(), spawnLoc.getY() + 30, spawnLoc.getZ()); l.getWorld().spawnParticle(Particle.EXPLOSION_HUGE, loc, 2); l.getWorld().playSound(loc, Sound.ENTITY_GENERIC_EXPLODE, 2, 1); Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Civs.getInstance(), new Runnable() { @Override public void run() { loc1.getWorld().spawnParticle(Particle.EXPLOSION_HUGE, loc1, 2); loc1.getWorld().playSound(loc1, Sound.ENTITY_GENERIC_EXPLODE, 2, 1); } }, 5L); Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Civs.getInstance(), new Runnable() { @Override public void run() { loc2.getWorld().spawnParticle(Particle.EXPLOSION_HUGE, loc2, 2); loc2.getWorld().playSound(loc2, Sound.ENTITY_GENERIC_EXPLODE, 2, 1); } }, 10L); Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Civs.getInstance(), new Runnable() { @Override public void run() { loc3.getWorld().spawnParticle(Particle.EXPLOSION_HUGE, loc3, 2); loc3.getWorld().playSound(loc3, Sound.ENTITY_GENERIC_EXPLODE, 2, 1); } }, 15L); TownManager.getInstance().setTownPower(town, town.getPower() - damage); }
Example 17
Source File: Game.java From BedWars with GNU Lesser General Public License v3.0 | 4 votes |
public void updateSigns() { List<SignBlock> gameSigns = Main.getSignManager().getSignsForName(this.name); if (gameSigns.isEmpty()) { return; } String statusLine = ""; String playersLine = ""; switch (status) { case DISABLED: statusLine = i18nonly("sign_status_disabled"); playersLine = i18nonly("sign_status_disabled_players"); break; case REBUILDING: statusLine = i18nonly("sign_status_rebuilding"); playersLine = i18nonly("sign_status_rebuilding_players"); break; case RUNNING: case GAME_END_CELEBRATING: statusLine = i18nonly("sign_status_running"); playersLine = i18nonly("sign_status_running_players"); break; case WAITING: statusLine = i18nonly("sign_status_waiting"); playersLine = i18nonly("sign_status_waiting_players"); break; } playersLine = playersLine.replace("%players%", Integer.toString(players.size())); playersLine = playersLine.replace("%maxplayers%", Integer.toString(calculatedMaxPlayers)); List<String> texts = new ArrayList<>(Main.getConfigurator().config.getStringList("sign")); for (int i = 0; i < texts.size(); i++) { String text = texts.get(i); texts.set(i, text.replaceAll("%arena%", this.getName()).replaceAll("%status%", statusLine) .replaceAll("%players%", playersLine)); } for (SignBlock sign : gameSigns) { if (sign.getLocation().getChunk().isLoaded()) { Block block = sign.getLocation().getBlock(); if (block.getState() instanceof Sign) { Sign state = (Sign) block.getState(); for (int i = 0; i < texts.size() && i < 4; i++) { state.setLine(i, texts.get(i)); } state.update(); } } } }
Example 18
Source File: SignUpdateTask.java From GriefDefender with MIT License | 4 votes |
@Override public void run() { for (World world : Bukkit.getServer().getWorlds()) { final GDClaimManager claimManager = GriefDefenderPlugin.getInstance().dataStore.getClaimWorldManager(world.getUID()); Set<Claim> claimList = claimManager.getWorldClaims(); if (claimList.size() == 0) { continue; } final Iterator<Claim> iterator = new HashSet<>(claimList).iterator(); while (iterator.hasNext()) { final GDClaim claim = (GDClaim) iterator.next(); final Vector3i pos = claim.getEconomyData() == null ? null : claim.getEconomyData().getRentSignPosition(); if (pos == null || claim.getEconomyData() == null || claim.getEconomyData().getRentEndDate() == null) { continue; } final Sign sign = SignUtil.getSign(world, pos); if (SignUtil.isRentSign(claim, sign)) { final String[] lines = sign.getLines(); final String header = lines[0]; if (header == null) { // Should not happen but just in case continue; } final String timeRemaining = sign.getLine(3); final Duration duration = Duration.between(Instant.now(), claim.getEconomyData().getRentEndDate()); final long seconds = duration.getSeconds(); if (seconds <= 0) { if (claim.getEconomyData().isRented()) { final UUID renterUniqueId = claim.getEconomyData().getRenters().get(0); final GDPermissionUser renter = PermissionHolderCache.getInstance().getOrCreateUser(renterUniqueId); if (renter != null && renter.getOnlinePlayer() != null) { GriefDefenderPlugin.sendMessage(renter.getOnlinePlayer(), MessageCache.getInstance().ECONOMY_CLAIM_RENT_CANCELLED); } } sign.getBlock().setType(Material.AIR); SignUtil.resetRentData(claim); claim.getData().save(); continue; } final String remainingTime = String.format("%02d:%02d:%02d", duration.toDays(), (seconds % 86400 ) / 3600, (seconds % 3600) / 60); sign.setLine(3, ChatColor.translateAlternateColorCodes('&', "&6" + remainingTime)); sign.update(); } } } }
Example 19
Source File: SignUtil.java From GriefDefender with MIT License | 4 votes |
private static Consumer<CommandSender> createRentConfirmationConsumer(CommandSender src, Claim claim, Sign sign, double rate, int min, int max, PaymentType paymentType) { return confirm -> { resetRentData(claim); claim.getEconomyData().setRentRate(rate); claim.getEconomyData().setPaymentType(paymentType); if (min > 0) { if (min > max) { claim.getEconomyData().setRentMinTime(max); } else { claim.getEconomyData().setRentMinTime(min); } } if (max > 0) { final int rentMaxLimit = GriefDefenderPlugin.getActiveConfig(((GDClaim) claim).getWorld()).getConfig().economy.rentMaxTimeLimit; if (max > rentMaxLimit) { claim.getEconomyData().setRentMaxTime(rentMaxLimit); } else { claim.getEconomyData().setRentMaxTime(max); } claim.getEconomyData().setRentEndDate(Instant.now().plus(max, paymentType == PaymentType.DAILY ? ChronoUnit.DAYS : ChronoUnit.HOURS)); } claim.getEconomyData().setForRent(true); Sign rentSign = sign; if (rentSign == null) { rentSign = SignUtil.getSign(((GDClaim) claim).getWorld(), claim.getEconomyData().getRentSignPosition()); } if (rentSign != null) { claim.getEconomyData().setRentSignPosition(VecHelper.toVector3i(sign.getLocation())); claim.getData().save(); List<String> lines = new ArrayList<>(4); lines.add(ChatColor.translateAlternateColorCodes('&', "&7[&bGD&7-&1rent&7]")); lines.add(ChatColor.translateAlternateColorCodes('&', LegacyComponentSerializer.legacy().serialize(MessageCache.getInstance().ECONOMY_SIGN_RENT_DESCRIPTION))); lines.add(ChatColor.translateAlternateColorCodes('&', "&4$" + String.format("%.2f", rate) + "/" + LegacyComponentSerializer.legacy().serialize((paymentType == PaymentType.DAILY ? MessageCache.getInstance().LABEL_DAY : MessageCache.getInstance().LABEL_HOUR)))); for (int i = 0; i < lines.size(); i++) { sign.setLine(i, lines.get(i)); } sign.update(); } final Component message = GriefDefenderPlugin.getInstance().messageData.getMessage(MessageStorage.ECONOMY_CLAIM_RENT_CONFIRMED, ImmutableMap.of( "amount", "$" + rate, "type", paymentType == PaymentType.DAILY ? MessageCache.getInstance().LABEL_DAY : MessageCache.getInstance().LABEL_HOUR)); GriefDefenderPlugin.sendMessage(src, message); }; }
Example 20
Source File: IslandBlock.java From askyblock with GNU General Public License v2.0 | 4 votes |
/** * Paste this block at blockLoc * @param nms * @param blockLoc */ //@SuppressWarnings("deprecation") @SuppressWarnings("deprecation") public void paste(NMSAbstraction nms, Location blockLoc, boolean usePhysics, Biome biome) { // Only paste air if it is below the sea level and in the overworld Block block = new Location(blockLoc.getWorld(), x, y, z).add(blockLoc).getBlock(); block.setBiome(biome); nms.setBlockSuperFast(block, typeId, data, usePhysics); if (signText != null) { if (block.getTypeId() != typeId) { block.setTypeId(typeId); } // Sign Sign sign = (Sign) block.getState(); int index = 0; for (String line : signText) { sign.setLine(index++, line); } sign.update(true, false); } else if (banner != null) { banner.set(block); } else if (skull != null){ skull.set(block); } else if (pot != null){ pot.set(nms, block); } else if (spawnerBlockType != null) { if (block.getTypeId() != typeId) { block.setTypeId(typeId); } CreatureSpawner cs = (CreatureSpawner)block.getState(); cs.setSpawnedType(spawnerBlockType); //Bukkit.getLogger().info("DEBUG: setting spawner"); cs.update(true, false); } else if (!chestContents.isEmpty()) { if (block.getTypeId() != typeId) { block.setTypeId(typeId); } //Bukkit.getLogger().info("DEBUG: inventory holder "+ block.getType()); // Check if this is a double chest InventoryHolder chestBlock = (InventoryHolder) block.getState(); //InventoryHolder iH = chestBlock.getInventory().getHolder(); if (chestBlock instanceof DoubleChest) { //Bukkit.getLogger().info("DEBUG: double chest"); DoubleChest doubleChest = (DoubleChest) chestBlock; for (ItemStack chestItem: chestContents.values()) { doubleChest.getInventory().addItem(chestItem); } } else { // Single chest for (Entry<Byte, ItemStack> en : chestContents.entrySet()) { //Bukkit.getLogger().info("DEBUG: " + en.getKey() + "," + en.getValue()); chestBlock.getInventory().setItem(en.getKey(), en.getValue()); } } } }