2015-08-26 00:35:32 +02:00
|
|
|
package com.plotsquared.sponge.util;
|
|
|
|
|
|
|
|
import org.spongepowered.api.text.TextBuilder;
|
|
|
|
import org.spongepowered.api.text.Texts;
|
|
|
|
import org.spongepowered.api.text.action.TextActions;
|
|
|
|
|
|
|
|
import com.intellectualcrafters.plot.object.ConsolePlayer;
|
|
|
|
import com.intellectualcrafters.plot.object.PlotMessage;
|
|
|
|
import com.intellectualcrafters.plot.object.PlotPlayer;
|
|
|
|
import com.intellectualcrafters.plot.util.ChatManager;
|
|
|
|
import com.plotsquared.sponge.object.SpongePlayer;
|
|
|
|
|
2015-09-13 06:04:31 +02:00
|
|
|
public class SpongeChatManager extends ChatManager<TextBuilder> {
|
|
|
|
|
2015-08-26 00:35:32 +02:00
|
|
|
@Override
|
2015-09-13 06:04:31 +02:00
|
|
|
public TextBuilder builder() {
|
2015-08-26 00:35:32 +02:00
|
|
|
return Texts.builder();
|
|
|
|
}
|
2015-09-13 06:04:31 +02:00
|
|
|
|
2015-08-26 00:35:32 +02:00
|
|
|
@Override
|
2015-09-13 06:04:31 +02:00
|
|
|
public void color(final PlotMessage m, final String color) {
|
2015-08-26 00:35:32 +02:00
|
|
|
m.$(this).color(Texts.of(color).getColor());
|
|
|
|
}
|
2015-09-13 06:04:31 +02:00
|
|
|
|
2015-08-26 00:35:32 +02:00
|
|
|
@Override
|
2015-09-13 06:04:31 +02:00
|
|
|
public void tooltip(final PlotMessage m, final PlotMessage... tooltips) {
|
2015-09-11 12:09:22 +02:00
|
|
|
final TextBuilder builder = Texts.builder();
|
2015-08-26 00:35:32 +02:00
|
|
|
boolean lb = false;
|
2015-09-13 06:04:31 +02:00
|
|
|
for (final PlotMessage tooltip : tooltips) {
|
|
|
|
if (lb) {
|
2015-08-26 00:35:32 +02:00
|
|
|
builder.append(Texts.of("\n"));
|
|
|
|
}
|
|
|
|
builder.append(tooltip.$(this).build());
|
|
|
|
lb = true;
|
|
|
|
}
|
2015-09-11 12:09:22 +02:00
|
|
|
// AchievementBuilder builder = SpongeMain.THIS.getGame().getRegistry().createAchievementBuilder();
|
2015-08-26 00:35:32 +02:00
|
|
|
m.$(this).onHover(TextActions.showText(builder.toText()));
|
|
|
|
}
|
2015-09-13 06:04:31 +02:00
|
|
|
|
2015-08-26 00:35:32 +02:00
|
|
|
@Override
|
2015-09-13 06:04:31 +02:00
|
|
|
public void command(final PlotMessage m, final String command) {
|
2015-08-26 00:35:32 +02:00
|
|
|
m.$(this).onClick(TextActions.runCommand(command));
|
|
|
|
}
|
2015-09-13 06:04:31 +02:00
|
|
|
|
2015-08-26 00:35:32 +02:00
|
|
|
@Override
|
2015-09-13 06:04:31 +02:00
|
|
|
public void text(final PlotMessage m, final String text) {
|
2015-08-26 00:35:32 +02:00
|
|
|
m.$(this).append(Texts.of(text));
|
|
|
|
}
|
2015-09-13 06:04:31 +02:00
|
|
|
|
2015-08-26 00:35:32 +02:00
|
|
|
@Override
|
2015-09-13 06:04:31 +02:00
|
|
|
public void send(final PlotMessage m, final PlotPlayer player) {
|
|
|
|
if (ConsolePlayer.isConsole(player)) {
|
2015-08-26 00:35:32 +02:00
|
|
|
player.sendMessage(Texts.legacy().to(m.$(this).build()));
|
2015-09-13 06:04:31 +02:00
|
|
|
} else {
|
2015-08-26 00:35:32 +02:00
|
|
|
((SpongePlayer) player).player.sendMessage(m.$(this).build());
|
|
|
|
}
|
|
|
|
}
|
2015-09-13 06:04:31 +02:00
|
|
|
|
2015-08-26 00:35:32 +02:00
|
|
|
@Override
|
2015-09-13 06:04:31 +02:00
|
|
|
public void suggest(final PlotMessage m, final String command) {
|
2015-08-26 00:35:32 +02:00
|
|
|
m.$(this).onClick(TextActions.suggestCommand(command));
|
|
|
|
}
|
2015-09-13 06:04:31 +02:00
|
|
|
|
2015-08-26 00:35:32 +02:00
|
|
|
}
|