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;
|
|
|
|
import com.plotsquared.config.Captions;
|
|
|
|
import com.plotsquared.config.Settings;
|
|
|
|
import com.plotsquared.player.ConsolePlayer;
|
|
|
|
import com.plotsquared.plot.message.PlotMessage;
|
|
|
|
import com.plotsquared.player.PlotPlayer;
|
|
|
|
import com.plotsquared.util.ChatManager;
|
2016-02-14 02:01:18 +01:00
|
|
|
import org.bukkit.ChatColor;
|
|
|
|
|
2019-02-13 18:05:28 +01:00
|
|
|
import java.util.Arrays;
|
2016-02-14 02:01:18 +01:00
|
|
|
import java.util.List;
|
2019-02-13 18:05:28 +01:00
|
|
|
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> {
|
2016-02-14 02:01:18 +01:00
|
|
|
|
2018-08-10 17:01:10 +02:00
|
|
|
@Override public FancyMessage builder() {
|
2015-08-26 00:35:32 +02:00
|
|
|
return new FancyMessage("");
|
|
|
|
}
|
2016-02-14 02:01:18 +01:00
|
|
|
|
2018-08-10 17:01:10 +02:00
|
|
|
@Override public void color(PlotMessage message, String color) {
|
2019-02-22 17:51:06 +01:00
|
|
|
message.$(this).color(ChatColor.getByChar(Captions.color(color).substring(1)));
|
2015-08-26 00:35:32 +02:00
|
|
|
}
|
2016-02-14 02:01:18 +01:00
|
|
|
|
2018-08-10 17:01:10 +02:00
|
|
|
@Override public void tooltip(PlotMessage message, PlotMessage... tooltips) {
|
2019-02-13 18:05:28 +01:00
|
|
|
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
|
|
|
}
|
2016-02-14 02:01:18 +01: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
|
|
|
}
|
2016-02-14 02:01:18 +01: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
|
|
|
}
|
2016-02-14 02:01:18 +01: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
|
|
|
}
|
|
|
|
}
|
2016-02-14 02:01:18 +01: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
|
|
|
}
|
2016-02-14 02:01:18 +01:00
|
|
|
|
2015-08-26 00:35:32 +02:00
|
|
|
}
|