Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ua.chromocat.reviews;
- import org.bukkit.plugin.java.*;
- import net.milkbowl.vault.chat.*;
- import org.bukkit.plugin.*;
- import org.bukkit.entity.*;
- import java.util.stream.*;
- import java.util.concurrent.*;
- import java.util.*;
- import org.bukkit.*;
- import org.bukkit.command.*;
- public class Main extends JavaPlugin
- {
- private Chat vaultChat;
- public void onEnable() {
- this.saveDefaultConfig();
- final RegisteredServiceProvider<Chat> chatProvider = (RegisteredServiceProvider<Chat>)this.getServer().getServicesManager().getRegistration((Class)Chat.class);
- if (chatProvider == null) {
- throw new RuntimeException("Vault or Permission plugin not loaded!");
- }
- this.vaultChat = (Chat)chatProvider.getProvider();
- this.getCommand("reviews").setExecutor((commandSender, command, s, args) -> {
- if (!(commandSender instanceof Player)) {
- return false;
- }
- this.perform((Player)commandSender);
- return false;
- });
- }
- public void perform(final Player player) {
- 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());
- Player donater = null;
- if (!donaters.isEmpty()) {
- donater = donaters.get(ThreadLocalRandom.current().nextInt(donaters.size()));
- }
- String donaterName = null;
- String donaterPrefix = null;
- String review = null;
- if (donater == null) {
- final List<String> reviews = (List<String>)this.getConfig().getStringList("offline-reviews");
- if (reviews.isEmpty()) {
- return;
- }
- review = reviews.get(ThreadLocalRandom.current().nextInt(reviews.size()));
- final List<String> names = (List<String>)this.getConfig().getStringList("offline-names");
- if (names.isEmpty()) {
- return;
- }
- final String[] offlineName = names.get(ThreadLocalRandom.current().nextInt(names.size())).split(";;");
- donaterName = offlineName[1];
- donaterPrefix = offlineName[0];
- }
- else {
- final List<String> reviews = (List<String>)this.getConfig().getStringList("reviews");
- if (reviews.isEmpty()) {
- return;
- }
- review = reviews.get(ThreadLocalRandom.current().nextInt(reviews.size()));
- donaterName = donater.getName();
- donaterPrefix = this.getPlayerPrefix(player);
- }
- this.performActions(player, donaterName, donaterPrefix, review);
- }
- public void performActions(final Player player, final String donater, final String prefix, final String review) {
- for (String action : this.getConfig().getStringList("actions")) {
- action = this.parseColor(action.replace("%prefix", prefix).replace("%name", donater).replace("%review", review).replace("%sender", player.getName()));
- if (action.startsWith("msg:")) {
- player.sendMessage(this.parseColor(action.substring(4)));
- }
- else if (action.startsWith("title:")) {
- final String[] titles = this.parseColor(action.substring(6)).split(";;");
- player.sendTitle(titles[0], (titles.length > 0) ? titles[1] : "");
- }
- else {
- if (!action.startsWith("command:")) {
- throw new RuntimeException("Unknown type of action - '" + action + "'");
- }
- Bukkit.dispatchCommand((CommandSender)Bukkit.getConsoleSender(), this.parseColor(action.substring(8)));
- }
- }
- }
- public String parseColor(final String arg0) {
- return ChatColor.translateAlternateColorCodes('&', arg0);
- }
- public String getPlayerGroup2(final Player player) {
- final String[] groups = this.vaultChat.getPlayerGroups(player);
- return (groups.length > 0) ? groups[0] : null;
- }
- public String getPlayerGroup(final Player player) {
- return BigGroups.INSTANCE.getGroup(player.getName());
- }
- public String getPlayerPrefix(final Player player) {
- return BigGroups.INSTANCE.getGroupPrefix(this.getPlayerGroup(player));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement