diff --git a/BauSystem_Main/src/de/steamwar/bausystem/utils/ChatMessageBuilder.java b/BauSystem_Main/src/de/steamwar/bausystem/utils/ChatMessageBuilder.java new file mode 100644 index 00000000..f8c819f4 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/utils/ChatMessageBuilder.java @@ -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 . + */ + +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 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); + } + } + +}