org.spongepowered.api.data.manipulator.mutable.tileentity.SignData Java Examples
The following examples show how to use
org.spongepowered.api.data.manipulator.mutable.tileentity.SignData.
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: SignChangeListener.java From EssentialCmds with MIT License | 5 votes |
@Listener public void onSignChange(ChangeSignEvent event, @First Player player) { SignData signData = event.getText(); if (signData.getValue(Keys.SIGN_LINES).isPresent()) { String line0 = signData.getValue(Keys.SIGN_LINES).get().get(0).toPlain(); String line1 = signData.getValue(Keys.SIGN_LINES).get().get(1).toPlain(); String line2 = signData.getValue(Keys.SIGN_LINES).get().get(2).toPlain(); String line3 = signData.getValue(Keys.SIGN_LINES).get().get(3).toPlain(); if (line0.equals("[Warp]")) { if (Utils.getWarps().contains(line1)) { signData = signData.set(signData.getValue(Keys.SIGN_LINES).get().set(0, Text.of(TextColors.DARK_BLUE, "[Warp]"))); } else { signData = signData.set(signData.getValue(Keys.SIGN_LINES).get().set(0, Text.of(TextColors.DARK_RED, "[Warp]"))); } } else if (player != null && player.hasPermission("essentialcmds.color.sign.use")) { signData = signData.set(signData.getValue(Keys.SIGN_LINES).get().set(0, TextSerializers.formattingCode('&').deserialize(line0))); signData = signData.set(signData.getValue(Keys.SIGN_LINES).get().set(1, TextSerializers.formattingCode('&').deserialize(line1))); signData = signData.set(signData.getValue(Keys.SIGN_LINES).get().set(2, TextSerializers.formattingCode('&').deserialize(line2))); signData = signData.set(signData.getValue(Keys.SIGN_LINES).get().set(3, TextSerializers.formattingCode('&').deserialize(line3))); } } }
Example #4
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 #5
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); } } } } }
Example #6
Source File: PlayerInteractListener.java From EssentialCmds with MIT License | 4 votes |
@Listener public void onPlayerInteractBlock(InteractBlockEvent event, @Root Player player) { if (EssentialCmds.frozenPlayers.contains(player.getUniqueId())) { player.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "You cannot interact while frozen.")); event.setCancelled(true); return; } if (EssentialCmds.jailedPlayers.contains(player.getUniqueId())) { player.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "You cannot interact while jailed.")); event.setCancelled(true); return; } Optional<Location<World>> optLocation = event.getTargetBlock().getLocation(); if (optLocation.isPresent() && optLocation.get().getTileEntity().isPresent()) { Location<World> location = optLocation.get(); TileEntity clickedEntity = location.getTileEntity().get(); if (event.getTargetBlock().getState().getType().equals(BlockTypes.STANDING_SIGN) || event.getTargetBlock().getState().getType().equals(BlockTypes.WALL_SIGN)) { Optional<SignData> signData = clickedEntity.getOrCreate(SignData.class); if (signData.isPresent()) { SignData data = signData.get(); CommandManager cmdService = Sponge.getGame().getCommandManager(); String line0 = data.getValue(Keys.SIGN_LINES).get().get(0).toPlain(); String line1 = data.getValue(Keys.SIGN_LINES).get().get(1).toPlain(); String command = "warp " + line1; if (line0.equals("[Warp]")) { if (player.hasPermission("essentialcmds.warps.use.sign")) { cmdService.process(player, command); } else { player.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "You do not have permission to use Warp Signs!")); } } } } } }
Example #7
Source File: RegionBuilder.java From RedProtect with GNU General Public License v3.0 | 4 votes |
protected void setErrorSign(ChangeSignEvent e, String error) { SignData sign = e.getText(); sign.set(sign.getValue(Keys.SIGN_LINES).get().set(0, RedProtect.get().getUtil().toText(RedProtect.get().lang.get("regionbuilder.signerror")))); this.setError(e.getCause().first(Player.class).get(), error); }