Skocz do zawartości
  • 👋 Witaj na MPCForum!

    Przeglądasz forum jako gość, co oznacza, że wiele świetnych funkcji jest jeszcze przed Tobą! 😎

    • Pełny dostęp do działów i ukrytych treści
    • Możliwość pisania i odpowiadania w tematach
    • System prywatnych wiadomości
    • Zbieranie reputacji i rozwijanie swojego profilu
    • Członkostwo w jednej z największych społeczności graczy

    👉 Dołączenie zajmie Ci mniej niż minutę – a zyskasz znacznie więcej!

    Zarejestruj się teraz

Problem z wyświetlaniem czasu w opisie przedmiotu - autorski plugin


Pimpeek0321

Rekomendowane odpowiedzi

Opublikowano

Witam, piszę plugin na zestawy i mam problem z wyświetlaniem czasu pozostałego do odebrania zestawu w opisie przedmiotu w GUI. Na czacie wyświetla się normalnie lecz w lore  przedmiotu już go niestety nie ma. Z góry dzięki za pomoc :3 

Bez tytułusdsdsds.png

2018-12-05_20.26.52.png

Bez tytułu.png

  • Biter. zmienił(a) tytuł na Nie wyświetlany opis przedmiotu
Opublikowano

package pl.endrju.ytcore.utils;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.LinkedHashMap;
import java.util.Map.Entry;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class DataUtil
{
  public static String secondsToString(long l)
  {
    int seconds = (int)((l - System.currentTimeMillis()) / 1000L);
    StringBuilder sb = new StringBuilder();
    for (Map.Entry<Integer, String> e : values.entrySet())
    {
      int iDiv = seconds / ((Integer)e.getKey()).intValue();
      if (iDiv >= 1)
      {
        int x = (int)Math.floor(iDiv);
        sb.append(x + (String)e.getValue()).append("");
        seconds -= x * ((Integer)e.getKey()).intValue();
      }
    }
    return sb.toString();
  }
  
  public static String getDate(long time)
  {
    return dateFormat.format(new Date(time));
  }
  
  public static String getTime(long time)
  {
    return timeFormat.format(new Date(time));
  }
  
  public static long parseDateDiff(String time, boolean future)
  {
    try
    {
      Pattern timePattern = Pattern.compile("(?:([0-9]+)\\s*y[a-z]*[,\\s]*)?(?:([0-9]+)\\s*mo[a-z]*[,\\s]*)?(?:([0-9]+)\\s*w[a-z]*[,\\s]*)?(?:([0-9]+)\\s*d[a-z]*[,\\s]*)?(?:([0-9]+)\\s*h[a-z]*[,\\s]*)?(?:([0-9]+)\\s*m[a-z]*[,\\s]*)?(?:([0-9]+)\\s*(?:s[a-z]*)?)?", 2);
      Matcher m = timePattern.matcher(time);
      int years = 0;
      int months = 0;
      int weeks = 0;
      int days = 0;
      int hours = 0;
      int minutes = 0;
      int seconds = 0;
      boolean found = false;
      while (m.find()) {
        if ((m.group() != null) && (!m.group().isEmpty()))
        {
          for (int i = 0; i < m.groupCount(); i++) {
            if ((m.group(i) != null) && (!m.group(i).isEmpty()))
            {
              found = true;
              break;
            }
          }
          if (found)
          {
            if ((m.group(1) != null) && (!m.group(1).isEmpty())) {
              years = Integer.parseInt(m.group(1));
            }
            if ((m.group(2) != null) && (!m.group(2).isEmpty())) {
              months = Integer.parseInt(m.group(2));
            }
            if ((m.group(3) != null) && (!m.group(3).isEmpty())) {
              weeks = Integer.parseInt(m.group(3));
            }
            if ((m.group(4) != null) && (!m.group(4).isEmpty())) {
              days = Integer.parseInt(m.group(4));
            }
            if ((m.group(5) != null) && (!m.group(5).isEmpty())) {
              hours = Integer.parseInt(m.group(5));
            }
            if ((m.group(6) != null) && (!m.group(6).isEmpty())) {
              minutes = Integer.parseInt(m.group(6));
            }
            if (m.group(7) == null) {
              break;
            }
            if (m.group(7).isEmpty()) {
              break;
            }
            seconds = Integer.parseInt(m.group(7));
            break;
          }
        }
      }
      if (!found) {
        return -1L;
      }
      Calendar c = new GregorianCalendar();
      if (years > 0) {
        c.add(1, years * (future ? 1 : -1));
      }
      if (months > 0) {
        c.add(2, months * (future ? 1 : -1));
      }
      if (weeks > 0) {
        c.add(3, weeks * (future ? 1 : -1));
      }
      if (days > 0) {
        c.add(5, days * (future ? 1 : -1));
      }
      if (hours > 0) {
        c.add(11, hours * (future ? 1 : -1));
      }
      if (minutes > 0) {
        c.add(12, minutes * (future ? 1 : -1));
      }
      if (seconds > 0) {
        c.add(13, seconds * (future ? 1 : -1));
      }
      Calendar max = new GregorianCalendar();
      max.add(1, 10);
      if (c.after(max)) {
        return max.getTimeInMillis();
      }
      return c.getTimeInMillis();
    }
    catch (Exception e) {}
    return -1L;
  }
  
  private static final SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy, HH:mm:ss");
  private static final SimpleDateFormat timeFormat = new SimpleDateFormat("HH:mm:ss");
  private static final LinkedHashMap<Integer, String> values;
  
  static
  {
    (values = new LinkedHashMap(6)).put(Integer.valueOf(31104000), "y");
    values.put(Integer.valueOf(2592000), "msc");
    values.put(Integer.valueOf(86400), "d");
    values.put(Integer.valueOf(3600), "h");
    values.put(Integer.valueOf(60), "min");
    values.put(Integer.valueOf(1), "s");
  }
}
 

  • Marosking zmienił(a) tytuł na Problem z wyświetlaniem czasu w opisie przedmiotu - autorski plugin
Opublikowano

niee no nie , nie ma sensu dalej w to brnąć , dajesz srajshoty ... ekstra normalnie ekstra do tego jakies bakdory , w explorerze .... normalnie gosciu godny polecenia ...
skoro juz tak dajesz srajshoty to daj srajshota orginalnego kodu (tego z kad go ukradles/przekopiowales)...

tak sie zastanawiam , a dokladniej powroze z fusow , bo innej mozliowsci nie zostawiles , te cale valuues entry set jest pusty ,
albo czekaj , values ma keja bardzo bardzo dużego , choc nie to moze byc tez ten div < od 1 ...

proponuje sprawdzic jak dziala dzielenie w java (w tym wypadku na intach oraz magiczne dzielenie modulo %)

ogólnie pewno bym pomógł ale ten ss to działa mi na nerwy ...

czepial bym sie dalej ale kodu nie widzo

Opublikowano

package pl.endrju.ytcore.utils;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.LinkedHashMap;
import java.util.Map.Entry;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class DataUtil
{
  public static String secondsToString(long l)
  {
    int seconds = (int)((l - System.currentTimeMillis()) / 1000L);
    StringBuilder sb = new StringBuilder();
    for (Map.Entry<Integer, String> e : values.entrySet())
    {
      int iDiv = seconds / ((Integer)e.getKey()).intValue();
      if (iDiv >= 1)
      {
        int x = (int)Math.floor(iDiv);
        sb.append(x + (String)e.getValue()).append("");
        seconds -= x * ((Integer)e.getKey()).intValue();
      }
    }
    return sb.toString();
  }
  
  public static String getDate(long time)
  {
    return dateFormat.format(new Date(time));
  }
  
  public static String getTime(long time)
  {
    return timeFormat.format(new Date(time));
  }
  
  public static long parseDateDiff(String time, boolean future)
  {
    try
    {
      Pattern timePattern = Pattern.compile("(?:([0-9]+)\\s*y[a-z]*[,\\s]*)?(?:([0-9]+)\\s*mo[a-z]*[,\\s]*)?(?:([0-9]+)\\s*w[a-z]*[,\\s]*)?(?:([0-9]+)\\s*d[a-z]*[,\\s]*)?(?:([0-9]+)\\s*h[a-z]*[,\\s]*)?(?:([0-9]+)\\s*m[a-z]*[,\\s]*)?(?:([0-9]+)\\s*(?:s[a-z]*)?)?", 2);
      Matcher m = timePattern.matcher(time);
      int years = 0;
      int months = 0;
      int weeks = 0;
      int days = 0;
      int hours = 0;
      int minutes = 0;
      int seconds = 0;
      boolean found = false;
      while (m.find()) {
        if ((m.group() != null) && (!m.group().isEmpty()))
        {
          for (int i = 0; i < m.groupCount(); i++) {
            if ((m.group(i) != null) && (!m.group(i).isEmpty()))
            {
              found = true;
              break;
            }
          }
          if (found)
          {
            if ((m.group(1) != null) && (!m.group(1).isEmpty())) {
              years = Integer.parseInt(m.group(1));
            }
            if ((m.group(2) != null) && (!m.group(2).isEmpty())) {
              months = Integer.parseInt(m.group(2));
            }
            if ((m.group(3) != null) && (!m.group(3).isEmpty())) {
              weeks = Integer.parseInt(m.group(3));
            }
            if ((m.group(4) != null) && (!m.group(4).isEmpty())) {
              days = Integer.parseInt(m.group(4));
            }
            if ((m.group(5) != null) && (!m.group(5).isEmpty())) {
              hours = Integer.parseInt(m.group(5));
            }
            if ((m.group(6) != null) && (!m.group(6).isEmpty())) {
              minutes = Integer.parseInt(m.group(6));
            }
            if (m.group(7) == null) {
              break;
            }
            if (m.group(7).isEmpty()) {
              break;
            }
            seconds = Integer.parseInt(m.group(7));
            break;
          }
        }
      }
      if (!found) {
        return -1L;
      }
      Calendar c = new GregorianCalendar();
      if (years > 0) {
        c.add(1, years * (future ? 1 : -1));
      }
      if (months > 0) {
        c.add(2, months * (future ? 1 : -1));
      }
      if (weeks > 0) {
        c.add(3, weeks * (future ? 1 : -1));
      }
      if (days > 0) {
        c.add(5, days * (future ? 1 : -1));
      }
      if (hours > 0) {
        c.add(11, hours * (future ? 1 : -1));
      }
      if (minutes > 0) {
        c.add(12, minutes * (future ? 1 : -1));
      }
      if (seconds > 0) {
        c.add(13, seconds * (future ? 1 : -1));
      }
      Calendar max = new GregorianCalendar();
      max.add(1, 10);
      if (c.after(max)) {
        return max.getTimeInMillis();
      }
      return c.getTimeInMillis();
    }
    catch (Exception e) {}
    return -1L;
  }
  
  private static final SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy, HH:mm:ss");
  private static final SimpleDateFormat timeFormat = new SimpleDateFormat("HH:mm:ss");
  private static final LinkedHashMap<Integer, String> values;
  
  static
  {
    (values = new LinkedHashMap(6)).put(Integer.valueOf(31104000), "y");
    values.put(Integer.valueOf(2592000), "msc");
    values.put(Integer.valueOf(86400), "d");
    values.put(Integer.valueOf(3600), "h");
    values.put(Integer.valueOf(60), "min");
    values.put(Integer.valueOf(1), "s");
  }
}
 

Opublikowano
43 minuty temu, Pimpeek0321 napisał:

package pl.endrju.ytcore.utils;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.LinkedHashMap;
import java.util.Map.Entry;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class DataUtil
{
  public static String secondsToString(long l)
  {
    int seconds = (int)((l - System.currentTimeMillis()) / 1000L);
    StringBuilder sb = new StringBuilder();
    for (Map.Entry<Integer, String> e : values.entrySet())
    {
      int iDiv = seconds / ((Integer)e.getKey()).intValue();
      if (iDiv >= 1)
      {
        int x = (int)Math.floor(iDiv);
        sb.append(x + (String)e.getValue()).append("");
        seconds -= x * ((Integer)e.getKey()).intValue();
      }
    }
    return sb.toString();
  }
  
  public static String getDate(long time)
  {
    return dateFormat.format(new Date(time));
  }
  
  public static String getTime(long time)
  {
    return timeFormat.format(new Date(time));
  }
  
  public static long parseDateDiff(String time, boolean future)
  {
    try
    {
      Pattern timePattern = Pattern.compile("(?:([0-9]+)\\s*y[a-z]*[,\\s]*)?(?:([0-9]+)\\s*mo[a-z]*[,\\s]*)?(?:([0-9]+)\\s*w[a-z]*[,\\s]*)?(?:([0-9]+)\\s*d[a-z]*[,\\s]*)?(?:([0-9]+)\\s*h[a-z]*[,\\s]*)?(?:([0-9]+)\\s*m[a-z]*[,\\s]*)?(?:([0-9]+)\\s*(?:s[a-z]*)?)?", 2);
      Matcher m = timePattern.matcher(time);
      int years = 0;
      int months = 0;
      int weeks = 0;
      int days = 0;
      int hours = 0;
      int minutes = 0;
      int seconds = 0;
      boolean found = false;
      while (m.find()) {
        if ((m.group() != null) && (!m.group().isEmpty()))
        {
          for (int i = 0; i < m.groupCount(); i++) {
            if ((m.group(i) != null) && (!m.group(i).isEmpty()))
            {
              found = true;
              break;
            }
          }
          if (found)
          {
            if ((m.group(1) != null) && (!m.group(1).isEmpty())) {
              years = Integer.parseInt(m.group(1));
            }
            if ((m.group(2) != null) && (!m.group(2).isEmpty())) {
              months = Integer.parseInt(m.group(2));
            }
            if ((m.group(3) != null) && (!m.group(3).isEmpty())) {
              weeks = Integer.parseInt(m.group(3));
            }
            if ((m.group(4) != null) && (!m.group(4).isEmpty())) {
              days = Integer.parseInt(m.group(4));
            }
            if ((m.group(5) != null) && (!m.group(5).isEmpty())) {
              hours = Integer.parseInt(m.group(5));
            }
            if ((m.group(6) != null) && (!m.group(6).isEmpty())) {
              minutes = Integer.parseInt(m.group(6));
            }
            if (m.group(7) == null) {
              break;
            }
            if (m.group(7).isEmpty()) {
              break;
            }
            seconds = Integer.parseInt(m.group(7));
            break;
          }
        }
      }
      if (!found) {
        return -1L;
      }
      Calendar c = new GregorianCalendar();
      if (years > 0) {
        c.add(1, years * (future ? 1 : -1));
      }
      if (months > 0) {
        c.add(2, months * (future ? 1 : -1));
      }
      if (weeks > 0) {
        c.add(3, weeks * (future ? 1 : -1));
      }
      if (days > 0) {
        c.add(5, days * (future ? 1 : -1));
      }
      if (hours > 0) {
        c.add(11, hours * (future ? 1 : -1));
      }
      if (minutes > 0) {
        c.add(12, minutes * (future ? 1 : -1));
      }
      if (seconds > 0) {
        c.add(13, seconds * (future ? 1 : -1));
      }
      Calendar max = new GregorianCalendar();
      max.add(1, 10);
      if (c.after(max)) {
        return max.getTimeInMillis();
      }
      return c.getTimeInMillis();
    }
    catch (Exception e) {}
    return -1L;
  }
  
  private static final SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy, HH:mm:ss");
  private static final SimpleDateFormat timeFormat = new SimpleDateFormat("HH:mm:ss");
  private static final LinkedHashMap<Integer, String> values;
  
  static
  {
    (values = new LinkedHashMap(6)).put(Integer.valueOf(31104000), "y");
    values.put(Integer.valueOf(2592000), "msc");
    values.put(Integer.valueOf(86400), "d");
    values.put(Integer.valueOf(3600), "h");
    values.put(Integer.valueOf(60), "min");
    values.put(Integer.valueOf(1), "s");
  }
}
 

taa nie widzisz jak to razi ? dlugi dlugi post ktorego nie da rady czytac

https://pastebin.com/3p6w6sUg

tyle backdorow napisales :/ a 20 linijek kodu stwarza takie problemy

sorry ze sie tak czepiam ale w eksplolerze masz backdory napisane , chcesz pomocy i wstawiasz ss , zamiast kodu . do tego nikla znajomosc java , i prawdopodobnie brak proby rozwiazania problemu samemu

Zarchiwizowany

Ten temat przebywa obecnie w archiwum. Dodawanie nowych odpowiedzi zostało zablokowane.

×
×
  • Dodaj nową pozycję...