Skocz do zawartości

Rekomendowane odpowiedzi

Cześć, dorobił by mi ktoś cooldown do tej classy?

    @EventHandler
    public void onPlayerInteract(final PlayerInteractEvent event) {
        final Player player = event.getPlayer();
        final Action action = event.getAction();
        player.getItemInHand();
        if (player.getItemInHand().getType() == Material.ENDER_PEARL && (action == Action.RIGHT_CLICK_AIR || action == Action.RIGHT_CLICK_BLOCK) && player.hasPermission("goodplay.enderpearl.ride")) {
            event.setCancelled(true);
            final EnderPearl pearl = player.launchProjectile((Class<? extends EnderPearl>) EnderPearl.class);
            pearl.setVelocity(player.getLocation().getDirection());
            pearl.setPassenger(player);
            final int pearlSlot = Main.config.getInt("PearlSlot");
            if (pearlSlot >= 0 && pearlSlot <= 8) {
                player.getInventory().setItem(pearlSlot, onJoin.custompearl);
            } else {
                player.getInventory().setItem(0, onJoin.custompearl);
            }
            final boolean throwSound = Main.config.getBoolean("ThrowSound");
            if (throwSound) {
                player.playSound(player.getLocation(), Sound.valueOf(Main.config.getString("Sound")), 1.0f, 1.0f);
            }
            final String throwMessage = Main.config.getString("ThrowMessage");
            assert throwMessage != null;
            if (!throwMessage.equals("")) {
                player.sendMessage(ChatColor.translateAlternateColorCodes('&', throwMessage));
                player.sendTitle("TEST", "TEST", 1, 20, 1);
            }
        }
    }

    @EventHandler
    public void onPlayerTeleport(final PlayerTeleportEvent event) {
        if (event.getCause() == PlayerTeleportEvent.TeleportCause.ENDER_PEARL) {
            event.setCancelled(true);
        }
    }
}

 

Nieaktywny

Przywracam treść.

Odnośnik do komentarza
https://skript.pl/temat/49318-temat-do-usuni%C4%99cia/
Udostępnij na innych stronach

private Map<Player, Long> cooldowns = new HashMap<>();

Stwórz sobie mapkę zawierającą plajera i long

 

if(cooldowns.containsKey(player))

Sprawdź czy ktoś jest w mapce

 

cooldowns.put(player, System.currentMillis() + 5*60*1000L);

Jeżeli nie ma go to dodaj go do mapki

 

if(cooldowns.get(player) < System.currentMillis())

Jeżeli jest to sprawdź czy czas zapisany w mapce jest mniejszy niż aktualny czas, jeżeli jest to pozwól mu rzucić perełką, jeżeli nie ma to nie pozwalaj

 

 

Do cooldownów polecam zrobić Ci osobny storage, bo musisz pamiętać, żeby usuwać ludzi z mapki, którzy wyszli z serwera. Btw czemu mam wrażenie, że inspirowałeś się kokscraftem? xd

Odnośnik do komentarza
https://skript.pl/temat/49318-temat-do-usuni%C4%99cia/#findComment-306308
Udostępnij na innych stronach

  • dziwakkolega zmienił(a) tytuł na Temat do usunięcia
Nieaktywny
Ten temat został zamknięty. Brak możliwości dodania odpowiedzi.
  • Ostatnio przeglądający   0 użytkowników

    • Brak zarejestrowanych użytkowników przeglądających tę stronę.
×
×
  • Dodaj nową pozycję...