Java Code Examples for org.bukkit.block.Sign#update()

The following examples show how to use org.bukkit.block.Sign#update() . 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: Door.java    From ZombieEscape with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Opens the Door Open at a given sign. The
 * door will stay open for 10 seconds, then
 * will close once more.
 *
 * @param plugin the plugin instance
 * @param sign   the sign that was interacted with
 */
public void open(Plugin plugin, final Sign sign) {
    section.clear();
    sign.setLine(2, Utils.color("&4&lRUN!"));
    sign.update();

    if (nukeroom) {
        Messages.NUKEROOM_OPEN_FOR.broadcast();
    } else {
        Messages.DOOR_OPENED.broadcast();
    }

    new BukkitRunnable() {
        @Override
        public void run() {
            activated = false;
            section.restore();
            sign.setLine(1, "Timer: " + seconds + "s");
            sign.setLine(2, "CLICK TO");
            sign.setLine(3, "ACTIVATE");
            sign.update();
        }
    }.runTaskLater(plugin, 20 * 10);
}
 
Example 2
Source File: ExtensionLeaderboardWall.java    From HeavySpleef with GNU General Public License v3.0 6 votes vote down vote up
@Override
public LoopReturn loop(int rowIndex, SignRow.WrappedMetadataSign sign) {
          Sign bukkitSign = sign.getBukkitSign();
	if (!iterator.hasNext()) {
		return LoopReturn.RETURN;
	}
	
	Entry<String, Statistic> entry = iterator.next();
	Set<Variable> variables = Sets.newHashSet();
	entry.getValue().supply(variables, null);
	variables.add(new Variable("player", entry.getKey()));
	variables.add(new Variable("rank", index + 1));
	layoutConfig.getLayout().inflate(bukkitSign, variables);
          bukkitSign.update();

          sign.setMetadata(METADATA_ID, entry);
	
	++index;
	return LoopReturn.DEFAULT;
}
 
Example 3
Source File: SignUtil.java    From GriefDefender with MIT License 6 votes vote down vote up
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: ContainerShop.java    From QuickShop-Reremake with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Changes the owner of this shop to the given player.
 *
 * @param owner the new owner
 */
@Override
public void setOwner(@NotNull UUID owner) {
    OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(owner);
    //Get the sign at first
    List<Sign> signs = this.getSigns();
    //then setOwner
    this.moderator.setOwner(owner);
    //then change the sign
    for (Sign shopSign : signs) {
        shopSign.setLine(0, MsgUtil.getMessageOfflinePlayer("signs.header", offlinePlayer, ownerName(false)));
        //Don't forgot update it
        shopSign.update(true);
    }
    //Event
    Bukkit.getPluginManager().callEvent(new ShopModeratorChangedEvent(this, this.moderator));
    update();
}
 
Example 5
Source File: Region.java    From RedProtect with GNU General Public License v3.0 6 votes vote down vote up
public void updateSigns(String fname) {
    if (!RedProtect.get().config.configRoot().region_settings.enable_flag_sign) {
        return;
    }
    List<Location> locs = RedProtect.get().config.getSigns(this.getID());
    if (locs.size() > 0) {
        for (Location loc : locs) {
            if (loc.getBlock().getState() instanceof Sign) {
                Sign s = (Sign) loc.getBlock().getState();
                String[] lines = s.getLines();
                if (lines[0].equalsIgnoreCase("[flag]")) {
                    if (lines[1].equalsIgnoreCase(fname) && this.name.equalsIgnoreCase(ChatColor.stripColor(lines[2]))) {
                        s.setLine(3, RedProtect.get().lang.get("region.value") + " " + ChatColor.translateAlternateColorCodes('&', RedProtect.get().lang.translBool(getFlagString(fname))));
                        s.update();
                        RedProtect.get().config.putSign(this.getID(), loc);
                    }
                } else {
                    RedProtect.get().config.removeSign(this.getID(), loc);
                }
            } else {
                RedProtect.get().config.removeSign(this.getID(), loc);
            }
        }
    }
}
 
Example 6
Source File: Cannon.java    From civcraft with GNU General Public License v2.0 6 votes vote down vote up
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 7
Source File: SignPlaceholders.java    From VoxelGamesLibv2 with MIT License 6 votes vote down vote up
@EventHandler
public void handleInteract(@Nonnull PlayerInteractEvent event) {
    if (event.getAction() == org.bukkit.event.block.Action.RIGHT_CLICK_BLOCK && event.getClickedBlock() != null) {
        if (event.getClickedBlock().getState() instanceof Sign) {
            Sign sign = (Sign) event.getClickedBlock().getState();
            if (sign.hasMetadata("UpdateCooldown")) {
                long cooldown = sign.getMetadata("UpdateCooldown").get(0).asLong();
                if (cooldown > System.currentTimeMillis() - 1 * 1000) {
                    return;
                }
            }
            sign.update();
            sign.setMetadata("UpdateCooldown", new FixedMetadataValue(voxelGamesLib, System.currentTimeMillis()));
        }
    }
}
 
Example 8
Source File: JoinSign.java    From DungeonsXL with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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 9
Source File: GameJoinSign.java    From BedwarsRel with GNU General Public License v3.0 5 votes vote down vote up
public void updateSign() {
  Sign sign = (Sign) this.signLocation.getBlock().getState();

  String[] signLines = this.getSignLines();
  for (int i = 0; i < signLines.length; i++) {
    sign.setLine(i, signLines[i]);
  }

  sign.update(true, true);
}
 
Example 10
Source File: PlayerListener.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
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 11
Source File: LobbyWall.java    From Survival-Games with GNU General Public License v3.0 5 votes vote down vote up
public void clear() {
    for (Sign s: signs) {
        for (int a = 0; a < 4; a++) {
            s.setLine(a, "");
        }
        s.update();
    }
}
 
Example 12
Source File: SignManager.java    From factions-top with MIT License 5 votes vote down vote up
@Override
public void run() {
    SplaySet<FactionWorth> factions = plugin.getWorthManager().getOrderedFactions();

    for (Map.Entry<Integer, Collection<BlockPos>> entry : signs.asMap().entrySet()) {
        // Do nothing if rank is higher than factions size.
        if (entry.getKey() >= factions.size()) continue;

        // Get the faction worth.
        FactionWorth worth = factions.byIndex(entry.getKey());

        // Do not update signs if previous value is unchanged.
        double previousWorth = previous.getOrDefault(entry.getKey(), 0d);
        if (previousWorth == worth.getTotalWorth()) {
            continue;
        }

        previous.put(entry.getKey(), worth.getTotalWorth());

        // Update all signs.
        for (BlockPos pos : entry.getValue()) {
            Block block = pos.getBlock(plugin.getServer());
            if (block == null || !(block.getState() instanceof Sign)) {
                plugin.getServer().getScheduler().runTask(plugin, () -> removeSign(pos));
                continue;
            }

            Sign sign = (Sign) block.getState();
            sign.setLine(2, worth.getName());
            sign.setLine(3, plugin.getSettings().getCurrencyFormat().format(worth.getTotalWorth()));
            sign.update();
        }
    }
}
 
Example 13
Source File: ContainerShop.java    From QuickShop-Reremake with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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: SignShop.java    From Shopkeepers with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean spawn() {
	Location signLocation = this.getActualLocation();
	if (signLocation == null) return false;

	Block signBlock = signLocation.getBlock();
	if (signBlock.getType() != Material.AIR) {
		return false;
	}

	// place sign: // TODO maybe also allow non-wall signs?
	// cancel block physics for this placed sign if needed:
	ShopkeepersPlugin.getInstance().cancelNextBlockPhysics(signLocation);
	signBlock.setType(Material.WALL_SIGN);
	// cleanup state if no block physics were triggered:
	ShopkeepersPlugin.getInstance().cancelNextBlockPhysics(null);

	// in case sign placement has failed for some reason:
	if (!Utils.isSign(signBlock.getType())) {
		return false;
	}

	// set sign facing:
	if (signFacing != null) {
		Sign signState = (Sign) signBlock.getState();
		((Attachable) signState.getData()).setFacingDirection(signFacing);
		// apply facing:
		signState.update();
	}

	// init sign content:
	updateSign = false;
	this.updateSign();

	return true;
}
 
Example 15
Source File: SiegeEffect.java    From Civs with GNU General Public License v3.0 4 votes vote down vote up
@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 16
Source File: SiegeEffect.java    From Civs with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean createRegionHandler(Block block, Player player, RegionType regionType) {
    if (!regionType.getEffects().containsKey(KEY) &&
            !regionType.getEffects().containsKey(CHARGING_KEY)) {
        return true;
    }
    Location l = Region.idToLocation(Region.blockLocationToString(block.getLocation()));
    Civilian civilian = CivilianManager.getInstance().getCivilian(player.getUniqueId());

    Block b = l.getBlock().getRelative(BlockFace.UP);
    BlockState state = b.getState();
    if (!(state instanceof Sign)) {
        player.sendMessage(Civs.getPrefix() + LocaleManager.getInstance()
                .getTranslation(civilian.getLocale(), "raid-sign"));
        return false;
    }

    if (l.getBlock().getY() + 2 < l.getWorld().getHighestBlockAt(l).getY()) {
        player.sendMessage(Civs.getPrefix() + LocaleManager.getInstance().getTranslation(civilian.getLocale(),
                "no-blocks-above-chest").replace("$1", regionType.getName()));
        return false;
    }

    //Find target Super-region
    Sign sign = (Sign) state;
    String townName = sign.getLine(0);
    Town town = TownManager.getInstance().getTown(townName);
    if (town == null) {
        for (Town cTown : TownManager.getInstance().getTowns()) {
            if (cTown.getName().toLowerCase().startsWith(sign.getLine(0))) {
                town = cTown;
                break;
            }
        }
    }
    if (town == null) {
        sign.setLine(0, "invalid target");
        sign.update();
        player.sendMessage(Civs.getPrefix() + LocaleManager.getInstance()
                .getTranslation(civilian.getLocale(), "raid-sign"));
        return false;
    } else {
        sign.setLine(0, town.getName());
        sign.update();
    }
    TownType townType = (TownType) ItemManager.getInstance().getItemType(town.getType());
    double rawRadius = townType.getBuildRadius();
    if (town.getLocation().distance(l) - rawRadius >  150) {
        sign.setLine(2, "out of");
        sign.setLine(3, "range");
        sign.update();
        return false;
    }
    for (Player p : Bukkit.getOnlinePlayers()) {
        Civilian civ = CivilianManager.getInstance().getCivilian(p.getUniqueId());
        String siegeMachineLocalName = LocaleManager.getInstance().getTranslation(civ.getLocale(), regionType.getProcessedName() + "-name");
        p.sendMessage(Civs.getPrefix() + ChatColor.RED + LocaleManager.getInstance().getTranslation(
                civ.getLocale(), "siege-built").replace("$1", player.getDisplayName())
                .replace("$2", siegeMachineLocalName).replace("$3", town.getName()));
    }
    if (Civs.discordSRV != null) {
        String siegeLocalName = LocaleManager.getInstance().getTranslation(ConfigManager.getInstance().getDefaultLanguage(),
                regionType.getProcessedName() + "-name");
        String defaultMessage = Civs.getPrefix() + ChatColor.RED + LocaleManager.getInstance().getTranslation(
                ConfigManager.getInstance().getDefaultLanguage(), "siege-built").replace("$1", player.getDisplayName())
                .replace("$2", siegeLocalName).replace("$3", town.getName());
        defaultMessage += DiscordUtil.atAllTownOwners(town);
        DiscordUtil.sendMessageToMainChannel(defaultMessage);
    }
    return true;
}
 
Example 17
Source File: IslandBlock.java    From askyblock with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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());
            }
        }
    }
}
 
Example 18
Source File: WarRegen.java    From civcraft with GNU General Public License v2.0 4 votes vote down vote up
private static void restoreBlockFromString(String line) {
	String[] split = line.split(":");
	
	int type = Integer.valueOf(split[0]);
	byte data = Byte.valueOf(split[1]);
	int x = Integer.valueOf(split[2]);
	int y = Integer.valueOf(split[3]);
	int z = Integer.valueOf(split[4]);
	String world = split[5];
	
	Block block = BukkitObjects.getWorld(world).getBlockAt(x,y,z);
	
	ItemManager.setTypeId(block, type);
	ItemManager.setData(block, data, false);

	// End of basic block info, try to get more now.
	Inventory inv = null;
	switch (block.getType()) {
	case TRAPPED_CHEST:
		inv = ((Chest)block.getState()).getBlockInventory();
		InventorySerializer.StringToInventory(inv, split[6]);
		break;
	case CHEST:
		inv = ((Chest)block.getState()).getBlockInventory();
		InventorySerializer.StringToInventory(inv, split[6]);
		break;
	case DISPENSER:			
		inv = ((Dispenser)block.getState()).getInventory();
		InventorySerializer.StringToInventory(inv, split[6]);
		break;
	case BURNING_FURNACE:
	case FURNACE:
		inv = ((Furnace)block.getState()).getInventory();
		InventorySerializer.StringToInventory(inv, split[6]);
		break;
	case DROPPER:
		inv = ((Dropper)block.getState()).getInventory();
		InventorySerializer.StringToInventory(inv, split[6]);
		break;
	case HOPPER:
		inv = ((Hopper)block.getState()).getInventory();
		InventorySerializer.StringToInventory(inv, split[6]);
		break;
	case SIGN:
	case SIGN_POST:
	case WALL_SIGN:
		Sign sign = (Sign)block.getState();
		String[] messages = split[6].split(",");
		for (int i = 0; i < 4; i++) {
			if (messages[i] != null) {
				sign.setLine(i, messages[i]);
			}
		}
		sign.update();
		break;
	default:
		break;
	}
	
	
}
 
Example 19
Source File: SignLogic.java    From uSkyBlock with GNU General Public License v3.0 4 votes vote down vote up
private void updateSignFromChestSync(Location chestLoc, Location signLoc, Challenge challenge, List<ItemStack> requiredItems, boolean challengeLocked) {
    Block chestBlock = chestLoc.getBlock();
    Block signBlock = signLoc != null ? signLoc.getBlock() : null;
    if (chestBlock != null && signBlock != null
            && isChest(chestBlock)
            && signBlock.getType() == SkyBlockMenu.WALL_SIGN_MATERIAL && signBlock.getState() instanceof Sign
            ) {
        Sign sign = (Sign) signBlock.getState();
        Chest chest = (Chest) chestBlock.getState();
        int missing = -1;
        if (!requiredItems.isEmpty() && !challengeLocked) {
            missing = 0;
            for (ItemStack required : requiredItems) {
                if (!chest.getInventory().containsAtLeast(required, required.getAmount())) {
                    // Max shouldn't be needed, provided containsAtLeast matches getCountOf... but it might not
                    missing += Math.max(0, required.getAmount() - plugin.getChallengeLogic().getCountOf(chest.getInventory(), required));
                }
            }
        }
        String format = "\u00a72\u00a7l";
        if (missing > 0) {
            format = "\u00a74\u00a7l";
        }
        List<String> lines = wordWrap(challenge.getDisplayName(), SIGN_LINE_WIDTH, SIGN_LINE_WIDTH);
        if (challengeLocked) {
            lines.add(tr("\u00a74\u00a7lLocked Challenge"));
        } else {
            lines.addAll(wordWrap(challenge.getDescription(), SIGN_LINE_WIDTH, SIGN_LINE_WIDTH));
        }
        for (int i = 0; i < 3; i++) {
            if (i < lines.size()) {
                sign.setLine(i, lines.get(i));
            } else {
                sign.setLine(i, "");
            }
        }
        if (missing > 0) {
            sign.setLine(3, format + missing);
        } else if (missing == 0) {
            sign.setLine(3, format + tr("READY"));
        } else if (lines.size() > 3) {
            sign.setLine(3, lines.get(3));
        } else {
            sign.setLine(3, "");
        }
        if (!sign.update()) {
            log.info("Unable to update sign at " + LocationUtil.asString(signLoc));
        }
    }
}
 
Example 20
Source File: ExtensionLeaderboardPodium.java    From HeavySpleef with GNU General Public License v3.0 4 votes vote down vote up
@SuppressWarnings("deprecation")
public void update(Map<String, Statistic> statistics, boolean forceBlocks, boolean delete) {
	BlockFace2D rightDir = direction.right();
	BlockFace2D leftDir = direction.left();
	
	BlockFace rightFace = rightDir.getBlockFace3D();
	BlockFace leftFace = leftDir.getBlockFace3D();
	
	Block baseBlock = baseLocation.getBlock();
	if (delete) {
		baseBlock.setType(Material.AIR);
	}
	
	SignLayout layout = layoutConfig.getLayout();
	
	Iterator<Entry<String, Statistic>> iterator = statistics != null ? statistics.entrySet().iterator() : null;
	for (int i = 0; i < size.getStatisticAmount(); i++) {
		Entry<String, Statistic> entry = iterator != null && iterator.hasNext() ? iterator.next() : null;
		
		Block position = null;
		Material type = null;
		
		switch (i) {
		case 0:
			//Top
			position = baseBlock.getRelative(BlockFace.UP);
			type = Material.DIAMOND_BLOCK;
			break;
		case 1:
			//First left
			position = baseBlock.getRelative(leftFace);
			type = Material.GOLD_BLOCK;
			break;
		case 2:
			//First right
			position = baseBlock.getRelative(rightFace);
			type = Material.IRON_BLOCK;
			break;
		case 3:
			//Second left
			position = baseBlock.getRelative(leftFace, 2);
			type = Material.DOUBLE_STEP;
			break;
		case 4:
			//Second right
			position = baseBlock.getRelative(rightFace, 2);
			type = Material.DOUBLE_STEP;
			break;
		}
		
		if (position == null) {
			continue;
		}
		
		Block signBlock = position.getRelative(direction.getBlockFace3D());
		Block skullBlock = position.getRelative(BlockFace.UP);
		
		if (delete) {
			signBlock.setType(Material.AIR);
			skullBlock.setType(Material.AIR);
			position.setType(Material.AIR);
			continue;
		}
		
		if (baseBlock.getType() == Material.AIR || forceBlocks) {
			baseBlock.setType(Material.DOUBLE_STEP);
		}
		
		if (position.getType() == Material.AIR || forceBlocks) {
			position.setType(type);
		}
		
		if (entry == null) {
			continue;
		}
		
		/* For legacy reasons and compatibility */
		signBlock.setTypeId(Material.WALL_SIGN.getId(), false);
		skullBlock.setTypeId(Material.SKULL.getId(), false);
		
		Skull skull = (Skull) skullBlock.getState();
		skull.setRotation(direction.getBlockFace3D());
		skull.setSkullType(SkullType.PLAYER);
		skull.setOwner(entry.getKey());
		skull.setRawData(SKULL_ON_FLOOR);
		skull.update(true, false);
		
		Sign sign = (Sign) signBlock.getState();
		
		Set<Variable> variables = Sets.newHashSet();
		entry.getValue().supply(variables, null);
		variables.add(new Variable("player", entry.getKey()));
		variables.add(new Variable("rank", i + 1));
		
		layout.inflate(sign, variables);
		org.bukkit.material.Sign data = new org.bukkit.material.Sign(Material.WALL_SIGN);
		data.setFacingDirection(direction.getBlockFace3D());
		sign.setData(data);
		sign.update();
	}
}