need to send message in time delays

Discussion in 'Plugin Development' started by ZiemniakZPieca, Jan 26, 2022.

Thread Status:
Not open for further replies.
  1. Offline

    ZiemniakZPieca

    Good day. I wanted to make a plugin for logging in, but when I want to display the text every three seconds, it is still displayed without any break. I'm new and don't really know what to do.
    My code is there:
    Code:
    @EventHandler(priority = EventPriority.HIGHEST)
        public void onPlayerJoin(PlayerJoinEvent e) {
            Player p = e.getPlayer();
            YamlConfiguration yamlFile = YamlConfiguration.loadConfiguration(f);
            boolean czyZalogowany = false;
            yamlFile.set(p.getName() + ".czyZalogowany", false);
            boolean czyPremium;
            if (yamlFile.contains(p.getName() + ".czyPremium")) {
                czyPremium = yamlFile.getBoolean(p.getName() + ".czyPremium");
            } else {
                yamlFile.set(p.getName() + ".czyPremium", false);
                czyPremium = false;
            }
            boolean czyZarejestrowany;
            if (yamlFile.contains(p.getName() + ".haslo")) {
                czyZarejestrowany = true;
            } else {
                czyZarejestrowany = false;
            }
    
            if (czyPremium) {
                yamlFile.set(p.getName() + ".czyZalogowany", true);
                p.sendMessage("§4§mLogowanie przez premium działa");
            } else if (czyZarejestrowany) {
                while (!yamlFile.getBoolean(p.getName() + ".czyZalogowany")) {
                    p.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 3, 255));
                    p.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, 3, 250));
                    p.sendMessage("§cAby sie zalogowac wpisz komende: /login <haslo>");
                    Delay(3);
                }
            } else {
                while (!yamlFile.getBoolean(p.getName() + ".czyZalogowany")) {
                    p.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 3, 255));
                    p.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, 3, 250));
                    p.sendMessage("§cAby sie zarejestrowac wpisz komende: /register <nowe haslo> <nowe haslo>");
                    Delay(3);
                }
            }
            if (yamlFile.getBoolean(p.getName() + "czyZalogowany")) {
                p.removePotionEffect(PotionEffectType.SLOW);
                p.removePotionEffect(PotionEffectType.JUMP);
            }
            try {
                yamlFile.save(f);
            } catch (IOException eo) {
                eo.printStackTrace();
            }
        }
    
        public void Delay(int time) {
            boolean isDone = false;
            Date now = new Date();
            SimpleDateFormat format = new SimpleDateFormat("ss");
            int oldSeconds = Short.parseShort(format.format(now));
            int newSeconds;
            while (isDone) {
                newSeconds = Short.parseShort(format.format(now));
                if(newSeconds == oldSeconds + time) {
                    isDone = true;
                    return;
                }
            }
        }
     
  2. Online

    timtower Administrator Administrator Moderator

    @ZiemniakZPieca Yeah, don't use a sleep or similar constructions in Bukkit.
    While loops are generally bad.
     
  3. Offline

    ZiemniakZPieca

    Ok, so is there any way to replace it by something else?
     
  4. Online

    timtower Administrator Administrator Moderator

  5. Offline

    ZiemniakZPieca

    That is paper plugin
     
  6. Online

    timtower Administrator Administrator Moderator

  7. Offline

    ZiemniakZPieca

    Plugin is for logging to the server witch /login command, and i want to send message to login every 3 seconds while player isn't logged in.
     
  8. Online

    timtower Administrator Administrator Moderator

    Why do you need a login plugin?
     
  9. Offline

    ZiemniakZPieca

    I'm learning to proggraming, and i need it to my server, but i don't wanna get it from internet.
     
  10. Online

    timtower Administrator Administrator Moderator

    Why do you need it for your server? I don't see any reason that you would need one with the minecraft authentication.
     
  11. Offline

    ZiemniakZPieca

    But i making that server for my friends and they don't have minecraft premium.
     
  12. Online

    timtower Administrator Administrator Moderator

Thread Status:
Not open for further replies.

Share This Page