Guest User

Untitled

a guest
Sep 15th, 2020
43
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package me.premiering.takethel;
  2.  
  3. import org.bukkit.Bukkit;
  4. import org.bukkit.ChatColor;
  5. import org.bukkit.configuration.file.YamlConfiguration;
  6. import org.bukkit.event.EventHandler;
  7. import org.bukkit.event.Listener;
  8. import org.bukkit.event.entity.PlayerDeathEvent;
  9.  
  10. import java.io.File;
  11. import java.io.IOException;
  12. import java.util.ArrayList;
  13. import java.util.List;
  14. import java.util.Random;
  15.  
  16. public class DeathListener implements Listener {
  17.  
  18. @EventHandler
  19. public void onPlayerDeath(PlayerDeathEvent event) throws IOException {
  20.  
  21. List<String> deathMessages = new ArrayList<>();
  22. File dataFile = new File("plugins/TakeTheL/config.yml");
  23. YamlConfiguration yaml = YamlConfiguration.loadConfiguration(dataFile);
  24. if (!dataFile.exists()) {
  25. yaml.set("messageOne", "L! You died! You'll never be as good as me % :)");
  26. yaml.set("messageTwo", "% ur actually garbage at the game lol get gud");
  27. yaml.set("messageThree", "lmao u suck % L");
  28. yaml.set("messageFour", "ur so poopy fart at the game % lmao");
  29. yaml.set("messageFive", "dude ur so trash TAKE THE L %");
  30. yaml.set("COMMENT", "% will be replaced with the player's name in the code, so wherever you want to put the player's name, just put a '%'");
  31.  
  32. deathMessages.add("L! You died! You'll never be as good as me % :)");
  33. deathMessages.add("% ur actually garbage at the game lol get gud");
  34. deathMessages.add("lmao u suck % L");
  35. deathMessages.add("ur so poopy fart at the game % lmao");
  36. deathMessages.add("dude ur so trash TAKE THE L %");
  37.  
  38. yaml.save(dataFile);
  39. } else {
  40. deathMessages.add(yaml.getString("messageOne"));
  41. deathMessages.add(yaml.getString("messageTwo"));
  42. deathMessages.add(yaml.getString("messageThree"));
  43. deathMessages.add(yaml.getString("messageFour"));
  44. deathMessages.add(yaml.getString("messageFive"));
  45. }
  46.  
  47. Random rand = new Random();
  48. event.setDeathMessage(ChatColor.translateAlternateColorCodes('&', deathMessages.get(rand.nextInt(5)).replaceAll("%", event.getEntity().getName())));
  49. }
  50. }
  51.  
RAW Paste Data