Java Code Examples for org.spongepowered.api.data.manipulator.mutable.tileentity.SignData#addElement()
The following examples show how to use
org.spongepowered.api.data.manipulator.mutable.tileentity.SignData#addElement() .
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: SignUtil.java From GriefDefender with MIT License | 6 votes |
private static Consumer<CommandSource> createSaleConfirmationConsumer(CommandSource src, Claim claim, Sign sign, double price) { return confirm -> { claim.getEconomyData().setSalePrice(price); claim.getEconomyData().setForSale(true); claim.getEconomyData().setSaleSignPosition(sign.getLocation().getBlockPosition()); claim.getData().save(); final List<Text> lines = createSellSignLines(claim.getEconomyData().getSalePrice()); final SignData signData = sign.getOrCreate(SignData.class).orElse(null); if (signData != null) { for (int i = 0; i < lines.size(); i++) { signData.addElement(i, lines.get(i)); } sign.offer(signData); } final Component message = GriefDefenderPlugin.getInstance().messageData.getMessage(MessageStorage.ECONOMY_CLAIM_SALE_CONFIRMED, ImmutableMap.of("amount", price)); GriefDefenderPlugin.sendMessage(src, message); }; }
Example 2
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(); final List<Text> lines = createRentSignLines(claim.getEconomyData().getRentRate(), paymentType); final SignData signData = sign.getOrCreate(SignData.class).orElse(null); if (signData != null) { for (int i = 0; i < lines.size(); i++) { signData.addElement(i, lines.get(i)); } sign.offer(signData); } }
Example 3
Source File: SignUtil.java From GriefDefender with MIT License | 4 votes |
private static Consumer<CommandSource> createRentConfirmationConsumer(CommandSource 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().getUniqueId()).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(rentSign.getLocation().getBlockPosition()); claim.getData().save(); final List<Text> lines = createRentSignLines(rate, paymentType); final SignData signData = rentSign.getOrCreate(SignData.class).orElse(null); if (signData != null) { for (int i = 0; i < lines.size(); i++) { signData.addElement(i, lines.get(i)); } sign.offer(signData); } } 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 4
Source File: SignUpdateTask.java From GriefDefender with MIT License | 4 votes |
@Override public void run() { for (World world : Sponge.getServer().getWorlds()) { final GDClaimManager claimManager = GriefDefenderPlugin.getInstance().dataStore.getClaimWorldManager(world.getUniqueId()); 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().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 List<Text> lines = sign.getSignData().asList(); final String header = lines.get(0).toPlain(); if (header == null) { // Should not happen but just in case continue; } 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.getLocation().setBlockType(BlockTypes.AIR); SignUtil.resetRentData(claim); claim.getData().save(); continue; } final String remainingTime = String.format("%02d:%02d:%02d", duration.toDays(), (seconds % 86400 ) / 3600, (seconds % 3600) / 60); final SignData signData = sign.getOrCreate(SignData.class).orElse(null); if (signData != null) { signData.addElement(3, Text.of(TextColors.DARK_AQUA, remainingTime)); sign.offer(signData); } } } } }