html format works somewhat (needs a prettier solution) + correct time format

This commit is contained in:
LunarAkai 2024-07-14 16:02:05 +02:00
commit 54d7d3bdc1
3 changed files with 36 additions and 4 deletions

View file

@ -12,11 +12,14 @@ import de.iani.cubesideutils.bukkit.commands.exceptions.RequiresPlayerException;
import de.iani.cubesideutils.commands.ArgsParser;
import de.lunarakai.blockfox.BlockFoxPlugin;
import de.lunarakai.blockfox.utils.HTMLUtils;
import de.lunarakai.blockfox.utils.TimeUtils;
import de.lunarakai.lunarutils.StringUtils;
import de.lunarakai.lunarutils.chat.MessageUtils;
import java.io.IOException;
import java.util.List;
import java.util.Optional;
import net.kyori.adventure.text.format.NamedTextColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@ -83,7 +86,10 @@ public class TestRSSCommand extends SubCommand {
optionalLink.ifPresent(string -> sender.sendMessage(NamedChatColor.AQUA + string));
Optional<String> optionalDate = items.getFirst().getPubDate();
optionalDate.ifPresent(string -> sender.sendMessage(NamedChatColor.GRAY + string));
if(optionalDate.isPresent()) {
String time = TimeUtils.convertStringTime(optionalDate.get());
MessageUtils.sendSimpleSpecialMessage(player, time, NamedTextColor.GRAY);
}
} catch (IOException e) {
throw new RuntimeException(e);
}

View file

@ -12,10 +12,14 @@ public class HTMLUtils {
// todo: with current method ul li inside another ul li are duplicated
List<String> list = new ArrayList<>();
Elements elements = document.select("ul");
Elements li = elements.select("li");
for (Element element : elements) {
list.add("- " + element.html() + "\n");
for (Element element : li) {
if(element.html().contains("ul")) {
list.add("- " + element.html().split("<ul>")[0].trim() + "\n");
continue;
}
list.add("- " + element.text() + "\n");

View file

@ -0,0 +1,22 @@
package de.lunarakai.blockfox.utils;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;
public class TimeUtils {
public static String convertStringTime(String time) {
SimpleDateFormat sdf = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss ZZZZZ");
try {
Date date = sdf.parse(time);
SimpleDateFormat outputFormat = new SimpleDateFormat("dd.MM.yyyy HH:mm");
outputFormat.setTimeZone(TimeZone.getTimeZone("Europe/Berlin"));
return outputFormat.format(date);
} catch (ParseException e) {
throw new RuntimeException(e);
}
}
}