69 lines
1.9 KiB
Java
Raw Normal View History

2018-05-31 11:56:19 +01:00
/*
* ItemCase is free software: you can redistribute it and/or modify
* it under the terms of the GNU 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/gpl.html>.
*/
package com.gmail.bleedobsidian.itemcase;
import net.md_5.bungee.api.ChatColor;
2018-05-31 12:32:36 +01:00
import org.bukkit.entity.Player;
2018-05-31 11:56:19 +01:00
/**
2018-05-31 14:23:22 +01:00
* Utility class used for communicating to players in game with a translator.
2018-05-31 11:56:19 +01:00
*
* @author Jesse Prescott (BleedObsidian).
*/
public final class ChatLogger {
/**
* The prefix placed before all messages.
*/
private final static String PREFIX =
ChatColor.BLUE + "[ItemCase]: " + ChatColor.RESET;
/**
* Language translator.
*/
2018-05-31 14:23:22 +01:00
private final LanguageTranslator translator;
2018-05-31 11:56:19 +01:00
/**
* Constructor.
*
* @param translator language translator.
*/
public ChatLogger(LanguageTranslator translator) {
// Set translator.
this.translator = translator;
}
/**
2018-05-31 12:32:36 +01:00
* Send given Player a message.
2018-05-31 11:56:19 +01:00
*
2018-05-31 12:32:36 +01:00
* @param player Player to send message.
* @param string Message key or message.
2018-05-31 11:56:19 +01:00
*/
2018-05-31 12:32:36 +01:00
public void message(Player player, String string) {
2018-05-31 11:56:19 +01:00
// If string is a message key.
if(this.translator.isKey(string)) {
// Translate.
string = this.translator.getTranslation(string);
}
// Send message.
2018-05-31 12:32:36 +01:00
player.sendMessage(ChatLogger.PREFIX + string);
2018-05-31 11:56:19 +01:00
}
}