Add ChatMessageBuilder
Dieser Commit ist enthalten in:
Ursprung
e2f02e7192
Commit
6d8c4b411d
@ -0,0 +1,88 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2021 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.bausystem.utils;
|
||||
|
||||
import de.steamwar.bausystem.config.ColorConfig;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ChatMessageBuilder {
|
||||
|
||||
private List<StringBuilder> messages = new ArrayList<>();
|
||||
private String[] strings = new String[0];
|
||||
|
||||
public ChatMessageBuilder() {
|
||||
messages.add(new StringBuilder());
|
||||
}
|
||||
|
||||
public ChatMessageBuilder highlight(String s) {
|
||||
messages.get(messages.size() - 1).append(ColorConfig.HIGHLIGHT).append(s);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ChatMessageBuilder base(String s) {
|
||||
messages.get(messages.size() - 1).append(ColorConfig.BASE).append(s);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ChatMessageBuilder other(String s) {
|
||||
messages.get(messages.size() - 1).append(ColorConfig.OTHER).append(s);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ChatMessageBuilder enable(String s) {
|
||||
messages.get(messages.size() - 1).append(ColorConfig.ENABLE).append(s);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ChatMessageBuilder disable(String s) {
|
||||
messages.get(messages.size() - 1).append(ColorConfig.DISABLE).append(s);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ChatMessageBuilder error(String s) {
|
||||
messages.get(messages.size() - 1).append(ColorConfig.ERROR).append(s);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ChatMessageBuilder append(String s) {
|
||||
messages.get(messages.size() - 1).append(s);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ChatMessageBuilder newLine() {
|
||||
messages.add(new StringBuilder());
|
||||
return this;
|
||||
}
|
||||
|
||||
public ChatMessageBuilder finish() {
|
||||
strings = messages.stream().map(StringBuilder::toString).toArray(String[]::new);
|
||||
return this;
|
||||
}
|
||||
|
||||
public void send(Player player) {
|
||||
for (String message : strings) {
|
||||
player.sendMessage(message);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
In neuem Issue referenzieren
Einen Benutzer sperren