PlotSquared/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitChatManager.java

54 lines
1.8 KiB
Java
Raw Normal View History

2020-04-11 02:19:18 +02:00
package com.plotsquared.bukkit.util;
2015-08-26 00:35:32 +02:00
2020-04-11 02:19:18 +02:00
import com.plotsquared.bukkit.chat.FancyMessage;
import com.plotsquared.bukkit.player.BukkitPlayer;
2020-04-15 21:26:54 +02:00
import com.plotsquared.core.config.Captions;
import com.plotsquared.core.config.Settings;
import com.plotsquared.core.player.ConsolePlayer;
import com.plotsquared.core.plot.message.PlotMessage;
import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.util.ChatManager;
import org.bukkit.ChatColor;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
2015-08-26 00:35:32 +02:00
2015-09-13 06:04:31 +02:00
public class BukkitChatManager extends ChatManager<FancyMessage> {
2018-08-10 17:01:10 +02:00
@Override public FancyMessage builder() {
2015-08-26 00:35:32 +02:00
return new FancyMessage("");
}
2018-08-10 17:01:10 +02:00
@Override public void color(PlotMessage message, String color) {
message.$(this).color(ChatColor.getByChar(Captions.color(color).substring(1)));
2015-08-26 00:35:32 +02:00
}
2018-08-10 17:01:10 +02:00
@Override public void tooltip(PlotMessage message, PlotMessage... tooltips) {
List<FancyMessage> lines =
Arrays.stream(tooltips).map(tooltip -> tooltip.$(this)).collect(Collectors.toList());
2016-04-19 22:59:10 +02:00
message.$(this).formattedTooltip(lines);
2015-08-26 00:35:32 +02:00
}
2018-08-10 17:01:10 +02:00
@Override public void command(PlotMessage message, String command) {
2016-04-19 22:59:10 +02:00
message.$(this).command(command);
2015-08-26 00:35:32 +02:00
}
2018-08-10 17:01:10 +02:00
@Override public void text(PlotMessage message, String text) {
2016-04-19 22:59:10 +02:00
message.$(this).then(ChatColor.stripColor(text));
2015-08-26 00:35:32 +02:00
}
2018-08-10 17:01:10 +02:00
@Override public void send(PlotMessage plotMessage, PlotPlayer player) {
2016-06-13 06:47:50 +02:00
if (player instanceof ConsolePlayer || !Settings.Chat.INTERACTIVE) {
2016-04-19 22:59:10 +02:00
player.sendMessage(plotMessage.$(this).toOldMessageFormat());
2015-09-13 06:04:31 +02:00
} else {
2016-04-19 22:59:10 +02:00
plotMessage.$(this).send(((BukkitPlayer) player).player);
2015-08-26 00:35:32 +02:00
}
}
2018-08-10 17:01:10 +02:00
@Override public void suggest(PlotMessage plotMessage, String command) {
2016-04-19 22:59:10 +02:00
plotMessage.$(this).suggest(command);
2015-08-26 00:35:32 +02:00
}
2015-08-26 00:35:32 +02:00
}