mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-03-07 17:28:03 +08:00
Implemented Velocity MessageBuilder
This commit is contained in:
parent
a6af091e89
commit
97fdc4646b
@ -95,7 +95,7 @@ class BukkitPartBuilder implements MessageBuilder {
|
||||
|
||||
@Override
|
||||
public MessageBuilder tabular(CharSequence charSequence) {
|
||||
sender.getFormatter().table(charSequence.toString(), ":");
|
||||
addPart(sender.getFormatter().table(charSequence.toString(), ":"));
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -96,7 +96,7 @@ class BungeePartBuilder implements MessageBuilder {
|
||||
|
||||
@Override
|
||||
public MessageBuilder tabular(CharSequence charSequence) {
|
||||
sender.getFormatter().table(charSequence.toString(), ":");
|
||||
addPart(sender.getFormatter().table(charSequence.toString(), ":"));
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -89,7 +89,7 @@ public class SpongeMessageBuilder implements MessageBuilder {
|
||||
|
||||
@Override
|
||||
public MessageBuilder tabular(CharSequence charSequence) {
|
||||
sender.getFormatter().table(charSequence.toString(), ":");
|
||||
addPart(sender.getFormatter().table(charSequence.toString(), ":"));
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,103 @@
|
||||
/*
|
||||
* This file is part of Player Analytics (Plan).
|
||||
*
|
||||
* Plan is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License v3 as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Plan is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Plan. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.djrapitops.plan.commands.use;
|
||||
|
||||
import net.kyori.text.TextComponent;
|
||||
import net.kyori.text.event.ClickEvent;
|
||||
import net.kyori.text.event.HoverEvent;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public class VelocityMessageBuilder implements MessageBuilder {
|
||||
|
||||
private final VelocityCMDSender sender;
|
||||
private final TextComponent.Builder builder;
|
||||
|
||||
public VelocityMessageBuilder(VelocityCMDSender sender) {
|
||||
this.sender = sender;
|
||||
builder = TextComponent.builder();
|
||||
}
|
||||
|
||||
@Override
|
||||
public MessageBuilder addPart(String content) {
|
||||
builder.content(content);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MessageBuilder newLine() {
|
||||
builder.content("\n");
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MessageBuilder link(String url) {
|
||||
builder.clickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, url));
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MessageBuilder command(String command) {
|
||||
builder.clickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, command));
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MessageBuilder hover(String s) {
|
||||
builder.hoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.of(s)));
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MessageBuilder hover(String... strings) {
|
||||
TextComponent.Builder hoverText = TextComponent.builder();
|
||||
for (String string : strings) {
|
||||
hoverText.content(string);
|
||||
}
|
||||
builder.hoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, hoverText.build()));
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MessageBuilder hover(Collection<String> collection) {
|
||||
TextComponent.Builder hoverText = TextComponent.builder();
|
||||
for (String string : collection) {
|
||||
hoverText.content(string);
|
||||
}
|
||||
builder.hoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, hoverText.build()));
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MessageBuilder indent(int amount) {
|
||||
for (int i = 0; i < amount; i++) {
|
||||
builder.content(" ");
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MessageBuilder tabular(CharSequence charSequence) {
|
||||
addPart(sender.getFormatter().table(charSequence.toString(), ":"));
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void send() {
|
||||
sender.commandSource.sendMessage(builder.build());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user