001/* 002 * PlotSquared, a land and world management plugin for Minecraft. 003 * Copyright (C) IntellectualSites <https://intellectualsites.com> 004 * Copyright (C) IntellectualSites team and contributors 005 * 006 * This program is free software: you can redistribute it and/or modify 007 * it under the terms of the GNU General Public License as published by 008 * the Free Software Foundation, either version 3 of the License, or 009 * (at your option) any later version. 010 * 011 * This program is distributed in the hope that it will be useful, 012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 014 * GNU General Public License for more details. 015 * 016 * You should have received a copy of the GNU General Public License 017 * along with this program. If not, see <https://www.gnu.org/licenses/>. 018 */ 019package com.plotsquared.core.configuration.caption; 020 021import com.plotsquared.core.player.PlotPlayer; 022import org.checkerframework.checker.nullness.qual.NonNull; 023import org.checkerframework.checker.nullness.qual.Nullable; 024 025import java.util.ArrayList; 026import java.util.Collection; 027import java.util.Collections; 028 029@FunctionalInterface 030public interface ChatFormatter { 031 032 Collection<ChatFormatter> formatters = new ArrayList<>(Collections.singletonList(new PlotSquaredChatFormatter())); 033 034 /** 035 * Format a message using all registered formatters 036 * 037 * @param context Message to format 038 */ 039 void format(@NonNull ChatContext context); 040 041 final class ChatContext { 042 043 private final PlotPlayer<?> recipient; 044 private final boolean rawOutput; 045 private String message; 046 047 /** 048 * Create a new chat context 049 * 050 * @param recipient Message recipient 051 * @param message Message 052 * @param rawOutput Whether or not formatting keys should be included in the 053 * final message 054 */ 055 public ChatContext( 056 final @Nullable PlotPlayer<?> recipient, final @NonNull String message, 057 final boolean rawOutput 058 ) { 059 this.recipient = recipient; 060 this.message = message; 061 this.rawOutput = rawOutput; 062 } 063 064 /** 065 * Get the message recipient 066 * 067 * @return Recipient 068 */ 069 public @Nullable PlotPlayer<?> getRecipient() { 070 return this.recipient; 071 } 072 073 /** 074 * Get the message stored in the context 075 * 076 * @return Stored message 077 */ 078 public @NonNull String getMessage() { 079 return this.message; 080 } 081 082 /** 083 * Set the new message 084 * 085 * @param message Message 086 */ 087 public void setMessage(final @NonNull String message) { 088 this.message = message; 089 } 090 091 /** 092 * Whether or not the output should escape 093 * any formatting keys 094 * 095 * @return {@code true} if raw output is to be used 096 */ 097 public boolean isRawOutput() { 098 return this.rawOutput; 099 } 100 101 } 102 103}