Advertisement
Guest User

Untitled

a guest
Apr 20th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.44 KB | None | 0 0
  1. package ua.chromocat.reviews;
  2.  
  3. import org.bukkit.plugin.java.*;
  4. import net.milkbowl.vault.chat.*;
  5. import org.bukkit.plugin.*;
  6. import org.bukkit.entity.*;
  7. import java.util.stream.*;
  8. import java.util.concurrent.*;
  9. import java.util.*;
  10. import org.bukkit.*;
  11. import org.bukkit.command.*;
  12.  
  13. public class Main extends JavaPlugin
  14. {
  15. private Chat vaultChat;
  16.  
  17. public void onEnable() {
  18. this.saveDefaultConfig();
  19. final RegisteredServiceProvider<Chat> chatProvider = (RegisteredServiceProvider<Chat>)this.getServer().getServicesManager().getRegistration((Class)Chat.class);
  20. if (chatProvider == null) {
  21. throw new RuntimeException("Vault or Permission plugin not loaded!");
  22. }
  23. this.vaultChat = (Chat)chatProvider.getProvider();
  24. this.getCommand("reviews").setExecutor((commandSender, command, s, args) -> {
  25. if (!(commandSender instanceof Player)) {
  26. return false;
  27. }
  28. this.perform((Player)commandSender);
  29. return false;
  30. });
  31. }
  32.  
  33. public void perform(final Player player) {
  34. final List<Player> donaters = Bukkit.getOnlinePlayers().parallelStream().filter(p -> player != p && !this.getConfig().getString("default-group").equals(this.getPlayerGroup(p))).collect((Collector<? super Object, ?, List<Player>>)Collectors.toList());
  35. Player donater = null;
  36. if (!donaters.isEmpty()) {
  37. donater = donaters.get(ThreadLocalRandom.current().nextInt(donaters.size()));
  38. }
  39. String donaterName = null;
  40. String donaterPrefix = null;
  41. String review = null;
  42. if (donater == null) {
  43. final List<String> reviews = (List<String>)this.getConfig().getStringList("offline-reviews");
  44. if (reviews.isEmpty()) {
  45. return;
  46. }
  47. review = reviews.get(ThreadLocalRandom.current().nextInt(reviews.size()));
  48. final List<String> names = (List<String>)this.getConfig().getStringList("offline-names");
  49. if (names.isEmpty()) {
  50. return;
  51. }
  52. final String[] offlineName = names.get(ThreadLocalRandom.current().nextInt(names.size())).split(";;");
  53. donaterName = offlineName[1];
  54. donaterPrefix = offlineName[0];
  55. }
  56. else {
  57. final List<String> reviews = (List<String>)this.getConfig().getStringList("reviews");
  58. if (reviews.isEmpty()) {
  59. return;
  60. }
  61. review = reviews.get(ThreadLocalRandom.current().nextInt(reviews.size()));
  62. donaterName = donater.getName();
  63. donaterPrefix = this.getPlayerPrefix(player);
  64. }
  65. this.performActions(player, donaterName, donaterPrefix, review);
  66. }
  67.  
  68. public void performActions(final Player player, final String donater, final String prefix, final String review) {
  69. for (String action : this.getConfig().getStringList("actions")) {
  70. action = this.parseColor(action.replace("%prefix", prefix).replace("%name", donater).replace("%review", review).replace("%sender", player.getName()));
  71. if (action.startsWith("msg:")) {
  72. player.sendMessage(this.parseColor(action.substring(4)));
  73. }
  74. else if (action.startsWith("title:")) {
  75. final String[] titles = this.parseColor(action.substring(6)).split(";;");
  76. player.sendTitle(titles[0], (titles.length > 0) ? titles[1] : "");
  77. }
  78. else {
  79. if (!action.startsWith("command:")) {
  80. throw new RuntimeException("Unknown type of action - '" + action + "'");
  81. }
  82. Bukkit.dispatchCommand((CommandSender)Bukkit.getConsoleSender(), this.parseColor(action.substring(8)));
  83. }
  84. }
  85. }
  86.  
  87. public String parseColor(final String arg0) {
  88. return ChatColor.translateAlternateColorCodes('&', arg0);
  89. }
  90.  
  91. public String getPlayerGroup2(final Player player) {
  92. final String[] groups = this.vaultChat.getPlayerGroups(player);
  93. return (groups.length > 0) ? groups[0] : null;
  94. }
  95.  
  96. public String getPlayerGroup(final Player player) {
  97. return BigGroups.INSTANCE.getGroup(player.getName());
  98. }
  99.  
  100. public String getPlayerPrefix(final Player player) {
  101. return BigGroups.INSTANCE.getGroupPrefix(this.getPlayerGroup(player));
  102. }
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement