jayhillx

onPlayerTick01

Aug 16th, 2021 (edited)
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. @SubscribeEvent
  2. public void onPlayerTick(TickEvent.PlayerTickEvent event) {
  3. PlayerEntity player = (PlayerEntity)event.player.getEntity();
  4. if (event.phase == TickEvent.Phase.END) {
  5.  
  6. for (Runnable runnable : delayedTasks) {
  7. runnable.run();
  8. delayedTasks.clear();
  9. }
  10. }
  11. }
  12.  
  13. static final List<Runnable> delayedTasks = new ArrayList<>();
  14.  
  15. delayedTasks.add(() -> {
  16. for (PlayerEntity players : player.getServer().getPlayerList().getPlayers()) {
  17. int lives = (int) (10 - (player.getMaxHealth() / 2));
  18.  
  19. if (lives >= 2) {
  20. players.sendMessage(HealthMessages.getRemainingLives(player, player.getScoreboardName() + " has " + lives + "
  21. lives remaining . . ."), player.getUniqueID());
  22. } else if (lives == 1) {
  23. players.sendMessage(HealthMessages.getRemainingLives(player, player.getScoreboardName() + " has one life
  24. remaining!"), player.getUniqueID());
  25. } else {
  26. players.sendMessage(HealthMessages.getRemainingLives(player, player.getScoreboardName() + " has been
  27. eliminated!"), player.getUniqueID());
  28. }
  29. }
  30. });
Add Comment
Please, Sign In to add comment