Consolidated staffMessage usages

master
Etzelia 2018-09-23 18:22:55 -05:00
parent 8ef9dff69f
commit 4388a1af85
3 changed files with 10 additions and 12 deletions

View File

@ -1,20 +1,19 @@
package xyz.etztech.minecraftmanager; package xyz.etztech.minecraftmanager;
import com.google.gson.JsonArray; import com.google.gson.JsonArray;
import net.md_5.bungee.api.chat.ComponentBuilder; import net.md_5.bungee.api.chat.*;
import net.md_5.bungee.api.chat.HoverEvent;
import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.TextComponent;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import javax.xml.soap.Text;
import java.io.FileWriter; import java.io.FileWriter;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
public class MCMUtil { public class MCMUtil {
@ -75,13 +74,13 @@ public class MCMUtil {
} }
public static void staffMessage(TextComponent message) { public static void staffMessage(TextComponent message) {
log(staffLog, message.getText()); log(staffLog, message.toPlainText());
for (Player player : Bukkit.getServer().getOnlinePlayers()) { for (Player player : Bukkit.getServer().getOnlinePlayers()) {
if (player.hasPermission("minecraftmanager.staff")) { if (player.hasPermission("minecraftmanager.staff")) {
player.spigot().sendMessage(message); player.spigot().sendMessage(message);
} }
} }
Bukkit.getConsoleSender().spigot().sendMessage(message); Bukkit.getConsoleSender().sendMessage(message.toPlainText());
} }
public static void globalMessage(String message) { public static void globalMessage(String message) {

View File

@ -70,12 +70,7 @@ public class AsyncPlayerChatListener implements Listener {
HoverEvent hover = new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("Staff Chat").create()); HoverEvent hover = new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("Staff Chat").create());
message.event(hover); message.event(hover);
message.append(chat).color(ChatColor.GREEN).event(hover); message.append(chat).color(ChatColor.GREEN).event(hover);
for (Player player : event.getRecipients()) { MCMUtil.staffMessage(new TextComponent(message.create()));
if (player.hasPermission("minecraftmanager.staff")) {
player.spigot().sendMessage(message.create());
}
}
MCMUtil.log(MCMUtil.staffLog, componentText(message.create()));
} else { } else {
message.append(chat); message.append(chat);
if (!MinecraftManager.getLogOverride()) { if (!MinecraftManager.getLogOverride()) {

View File

@ -93,6 +93,7 @@ public class MinecraftManagerThread extends Thread {
.color(ChatColor.GREEN) .color(ChatColor.GREEN)
.event(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/app info " + id)); .event(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/app info " + id));
TextComponent message = new TextComponent(builder.create()); TextComponent message = new TextComponent(builder.create());
message.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("Staff Chat").create()));
MCMUtil.staffMessage(message); MCMUtil.staffMessage(message);
} }
@ -101,6 +102,7 @@ public class MinecraftManagerThread extends Thread {
.color(ChatColor.GREEN) .color(ChatColor.GREEN)
.event(new ClickEvent(ClickEvent.Action.OPEN_URL, link)); .event(new ClickEvent(ClickEvent.Action.OPEN_URL, link));
TextComponent message = new TextComponent(builder.create()); TextComponent message = new TextComponent(builder.create());
message.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("Staff Chat").create()));
MCMUtil.staffMessage(message); MCMUtil.staffMessage(message);
} }
@ -140,6 +142,7 @@ public class MinecraftManagerThread extends Thread {
ComponentBuilder builder = new ComponentBuilder(username + " was " + (accepted ? "accepted" : "denied") + ".") ComponentBuilder builder = new ComponentBuilder(username + " was " + (accepted ? "accepted" : "denied") + ".")
.color(ChatColor.GREEN); .color(ChatColor.GREEN);
TextComponent staffMessage = new TextComponent(builder.create()); TextComponent staffMessage = new TextComponent(builder.create());
staffMessage.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("Staff Chat").create()));
MCMUtil.staffMessage(staffMessage); MCMUtil.staffMessage(staffMessage);
} }
@ -167,6 +170,7 @@ public class MinecraftManagerThread extends Thread {
.append(StringUtils.join(args, " "), ComponentBuilder.FormatRetention.NONE) .append(StringUtils.join(args, " "), ComponentBuilder.FormatRetention.NONE)
.color(ChatColor.GREEN); .color(ChatColor.GREEN);
TextComponent message = new TextComponent(builder.create()); TextComponent message = new TextComponent(builder.create());
message.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("Staff Chat").create()));
MCMUtil.staffMessage(message); MCMUtil.staffMessage(message);
} }