Ping sound config, chat history config, lot of descriptions

Moved ping sound configs to the FormatterComponent
Made an option to disable the chat history
Added descriptions for each config option
This commit is contained in:
Norbi Peti 2020-01-25 03:52:25 +01:00
parent d5f500aece
commit cda2a36da1
No known key found for this signature in database
GPG key ID: DBA4C4549A927E56
13 changed files with 103 additions and 25 deletions

View file

@ -16,7 +16,6 @@ import buttondevteam.chat.components.towncolors.TownColorComponent;
import buttondevteam.chat.components.towny.TownyComponent;
import buttondevteam.chat.listener.PlayerJoinLeaveListener;
import buttondevteam.chat.listener.PlayerListener;
import buttondevteam.core.MainPlugin;
import buttondevteam.core.component.channel.Channel;
import buttondevteam.lib.TBMCCoreAPI;
import buttondevteam.lib.architecture.ButtonPlugin;
@ -37,12 +36,12 @@ public class PluginMain extends ButtonPlugin { // Translated to Java: 2015.07.15
public static PluginMain Instance;
public static ConsoleCommandSender Console;
public ConfigData<String> notificationSound() {
return getIConfig().getData("notificationSound", "");
}
public ConfigData<Float> notificationPitch() {
return getIConfig().getData("notificationPitch", 1.0f);
/**
* If enabled, stores and displays the last 10 messages the player can see (public, their town chat etc.)
* Can be used with the Discord plugin so players can see some of the conversation they missed that's visible on Discord anyways.
*/
public ConfigData<Boolean> storeChatHistory() {
return getIConfig().getData("storeChatHistory", true);
}
// Fired when plugin is first enabled

View file

@ -1,5 +1,6 @@
package buttondevteam.chat.commands.ucmds;
import buttondevteam.chat.PluginMain;
import buttondevteam.core.component.channel.Channel;
import buttondevteam.lib.chat.ChatMessage;
import buttondevteam.lib.chat.Command2;
@ -29,6 +30,10 @@ public class HistoryCommand extends UCommandBase {
}
public static boolean showHistory(CommandSender sender, String channel) {
if (!PluginMain.Instance.storeChatHistory().get()) {
sender.sendMessage("§6Chat history is disabled");
return true;
}
Function<Channel, LinkedList<HistoryEntry>> getThem = ch -> messages.get(ch.ID + "_" + ch.getGroupID(sender)); //If can't see, groupID is null, and that shouldn't be in the map
sender.sendMessage("§6---- Chat History ----");
Stream<Channel> stream;
@ -69,6 +74,7 @@ public class HistoryCommand extends UCommandBase {
}
public static void addChatMessage(ChatMessage chatMessage, Channel channel) {
if (!PluginMain.Instance.storeChatHistory().get()) return;
val groupID = channel.getGroupID(chatMessage.getPermCheck());
if (groupID == null) return; //Just to be sure
synchronized (messages) {

View file

@ -10,18 +10,27 @@ import org.bukkit.Bukkit;
import java.util.ArrayList;
/**
* Displays the configured messages at the set interval when someone is online.
*/
public class AnnouncerComponent extends Component<PluginMain> implements Runnable {
/**
* The messages to display to players.
*/
public ConfigData<ArrayList<String>> announceMessages() {
return getConfig().getData("announceMessages", new ArrayList<>(0));
}
/**
* The time in milliseconds between the messages. Use /u announce settime to set minutes.
*/
public ConfigData<Integer> announceTime() {
return getConfig().getData("announceTime", 15 * 60 * 1000);
}
private TBMCSystemChatEvent.BroadcastTarget target;
private static int AnnounceMessageIndex = 0;
private int AnnounceMessageIndex = 0;
@Override
public void run() {

View file

@ -15,8 +15,12 @@ import java.util.Map;
import java.util.NoSuchElementException;
import java.util.function.Consumer;
/**
* Allows players to append tableflips and other things to their messages. Everything is configurable here.
*/
public class AppendTextComponent extends Component<PluginMain> {
private Map<String, IHaveConfig> appendTexts;
private ConfigData<String[]> helpText(IHaveConfig config) {
return config.getData("helpText", () -> new String[]{
"Tableflip", //

View file

@ -15,6 +15,9 @@ import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerTeleportEvent;
/**
* Allows players to enter chat-only mode which puts them into spectator mode and disallows everything besides chatting.
*/
public class ChatOnlyComponent extends Component implements Listener {
@Override
protected void enable() {

View file

@ -22,9 +22,16 @@ import java.net.UnknownHostException;
import java.text.SimpleDateFormat;
import java.util.*;
/**
* This component checks a specific Reddit thread every 10 seconds for comments such as "IGN: NorbiPeti" to link Reddit accounts and to determine their /r/thebutton flair.
* This was the original goal of this plugin when it was made.
*/
public class FlairComponent extends Component<PluginMain> {
/**
* The Reddit thread to check for account connections. Re-enable the component if this was empty.
*/
ConfigData<String> flairThreadURL() {
return getConfig().getData("flairThreadURL", "https://www.reddit.com/r/Chromagamers/comments/51ys94/flair_thread_for_the_mc_server/");
return getConfig().getData("flairThreadURL", "");
}
/**
@ -52,7 +59,7 @@ public class FlairComponent extends Component<PluginMain> {
private void FlairGetterThreadMethod() {
int errorcount = 0;
while (isEnabled()) {
while (isEnabled() && flairThreadURL().get().length() > 0) {
try {
String body = TBMCCoreAPI.DownloadString(flairThreadURL().get() + ".json?limit=1000");
JsonArray json = new JsonParser().parse(body).getAsJsonArray().get(1).getAsJsonObject().get("data")

View file

@ -107,7 +107,7 @@ public class ChatProcessing {
var players = ImmutableList.copyOf(Bukkit.getOnlinePlayers());
var playerC = new Random().nextInt(players.size());
var player = players.get(playerC);
playPingSound(player);
playPingSound(player, ComponentManager.getIfEnabled(FormatterComponent.class));
return "@someone (" + player.getDisplayName() + ")";
}).build());
private static Gson gson = new GsonBuilder()
@ -157,7 +157,7 @@ public class ChatProcessing {
ArrayList<ChatFormatter> formatters;
if (component.allowFormatting().get()) {
formatters = addFormatters(colormode, e::shouldSendTo);
formatters = addFormatters(colormode, e::shouldSendTo, component);
if (colormode == channel.Color().get() && mp != null && mp.RainbowPresserColorMode) { // Only overwrite channel color
final AtomicInteger rpc = new AtomicInteger(0);
formatters.add(ChatFormatter.builder("word", WORD_PATTERN).color(colormode).onmatch((match, cf, s) -> {
@ -260,7 +260,7 @@ public class ChatProcessing {
+ "]";
}
static ArrayList<ChatFormatter> addFormatters(Color colormode, Predicate<Player> canSee) {
static ArrayList<ChatFormatter> addFormatters(Color colormode, Predicate<Player> canSee, @Nullable FormatterComponent component) {
@SuppressWarnings("unchecked")
ArrayList<ChatFormatter> formatters = (ArrayList<ChatFormatter>) commonFormatters.clone();
@ -317,7 +317,7 @@ public class ChatProcessing {
}
ChatPlayer mpp = TBMCPlayer.getPlayer(nottest ? p.getUniqueId() : new UUID(0, 0), ChatPlayer.class);
if (nottest) {
playPingSound(p);
playPingSound(p, component);
}
String color = String.format("§%x", (mpp.GetFlairColor() == 0x00 ? 0xb : mpp.GetFlairColor()));
return color + (nottest ? p.getName() : pn.get()) + "§r"; //Fix name casing, except when testing
@ -333,7 +333,7 @@ public class ChatProcessing {
+ match.toLowerCase() + " but was reported as online.");
return "§c" + match + "§r";
}
playPingSound(p);
playPingSound(p, component);
return PluginMain.essentials.getUser(p).getNickname();
}
error.accept("Player nicknamed " + match.toLowerCase()
@ -344,12 +344,12 @@ public class ChatProcessing {
return formatters;
}
private static void playPingSound(Player p) {
if (PluginMain.Instance.notificationSound().get().length() == 0)
private static void playPingSound(Player p, @Nullable FormatterComponent component) {
if (component == null || component.notificationSound().get().length() == 0)
p.playSound(p.getLocation(), Sound.ENTITY_ARROW_HIT_PLAYER, 1.0f, 0.5f); // TODO: Airhorn
else
p.playSound(p.getLocation(), PluginMain.Instance.notificationSound().get(), 1.0f,
PluginMain.Instance.notificationPitch().get());
p.playSound(p.getLocation(), component.notificationSound().get(), 1.0f,
component.notificationPitch().get());
}
static void doFunStuff(CommandSender sender, TBMCChatEventBase event, String message) {

View file

@ -8,14 +8,33 @@ import buttondevteam.lib.architecture.Component;
import buttondevteam.lib.architecture.ConfigData;
/**
* This component handles the custom processing of chat messages. If this component is disabled channels won't be supported either in Minecraft.
* This component handles the custom processing of chat messages. If this component is disabled channels won't be supported in Minecraft.
* If you only want to disable the formatting features, set allowFormatting to false.
* If you're using another chat plugin, you should disable the whole component.
*/
public class FormatterComponent extends Component<PluginMain> {
/**
* Determines whether Markdown formatting, name mentioning and similar features are enabled.
*/
ConfigData<Boolean> allowFormatting() {
return getConfig().getData("allowFormatting", true);
}
/**
* The sound to play when a player is mentioned. Leave empty to use default.
*/
public ConfigData<String> notificationSound() {
return getConfig().getData("notificationSound", "");
}
/**
* The pitch of the notification sound.
*/
public ConfigData<Float> notificationPitch() {
return getConfig().getData("notificationPitch", 1.0f);
}
@Override
protected void enable() {
MainPlugin.Instance.setChatHandlerEnabled(false); //Disable Core chat handler - if this component is disabled then let it do it's job

View file

@ -29,6 +29,9 @@ import org.bukkit.scheduler.BukkitTask;
import java.util.HashSet;
import java.util.Random;
/**
* Random things I added over the years.
*/
public class FunComponent extends Component<PluginMain> implements Listener {
private boolean ActiveF = false;
private ChatPlayer FPlayer = null;
@ -38,14 +41,26 @@ public class FunComponent extends Component<PluginMain> implements Listener {
private TBMCSystemChatEvent.BroadcastTarget unlolTarget;
private TBMCSystemChatEvent.BroadcastTarget fTarget;
/**
* The strings that count as laughs, see unlol.
*/
private ConfigData<String[]> laughStrings() {
return getConfig().getData("laughStrings", () -> new String[]{"xd", "lel", "lawl", "kek", "lmao", "hue", "hah", "rofl"});
}
/**
* The "Press F to pay respects" meme in Minecraft. It will randomly appear on player death and keep track of how many "F"s are said in chat.
* You can hover over a player's name to see their respect.
*/
private ConfigData<Boolean> respect() {
return getConfig().getData("respect", true);
}
/**
* This is a sort of inside joke between me and Ghostise, who said "no, it was very unlol" after I said lol.
* It keeps track of laughs (lols and what's defined in laughStrings) and if someone does /unlol or /unlaugh it will unlaugh the last person who laughed.
* This action can only be performed once per laugh.
*/
private ConfigData<Boolean> unlol() {
return getConfig().getData("unlol", true);
}
@ -122,6 +137,7 @@ public class FunComponent extends Component<PluginMain> implements Listener {
Ftask = Bukkit.getScheduler().runTaskLaterAsynchronously(PluginMain.Instance, tt, 15 * 20);
}
}
@EventHandler
public void onPlayerLeave(PlayerQuitEvent event) {
if (unlol().get())

View file

@ -34,6 +34,10 @@ import java.util.function.Consumer;
import java.util.function.Function;
import java.util.stream.Collectors;
/**
* Town colors for Towny. It allows mayors and kings to set a color for their town/nation (nation can be disabled).
* This color is applied to the player names in chat and on Dynmap, if used.
*/
@ComponentMetadata(depends = TownyComponent.class)
public class TownColorComponent extends Component<PluginMain> implements Listener {
/**
@ -45,10 +49,17 @@ public class TownColorComponent extends Component<PluginMain> implements Listene
*/
public static Map<String, Color> NationColor = new HashMap<>();
/**
* The amount of town colors allowed. If more than one is used, players can change how many letters to be in a specific color using /u ncolor.
*/
public ConfigData<Byte> colorCount() {
return getConfig().getData("colorCount", (byte) 1, cc -> ((Integer) cc).byteValue(), Byte::intValue);
}
/**
* If enabled, players will have a nation-defined color in addition to town colors, white by default.
* They can change how much of each color they want with this as well.
*/
public ConfigData<Boolean> useNationColors() {
return getConfig().getData("useNationColors", true);
}
@ -60,7 +71,6 @@ public class TownColorComponent extends Component<PluginMain> implements Listene
@Override
protected void enable() {
component = this;
//TODO: Don't register all commands automatically (welp)
Consumer<ConfigurationSection> loadTC = cs -> TownColorComponent.TownColors.putAll(cs.getValues(true).entrySet().stream()
.collect(Collectors.toMap(Map.Entry::getKey, v -> ((List<String>) v.getValue()).stream()
.map(Color::valueOf).toArray(Color[]::new))));

View file

@ -22,6 +22,10 @@ import java.util.Optional;
import java.util.function.Function;
import java.util.stream.Collectors;
/**
* This component manages the town and nation chat. It's also needed for the TownColorComponent.
* It provides the TC and NC channels, and posts Towny messages (global, town, nation) to the correct channels for other platforms like Discord.
*/
public class TownyComponent extends Component<PluginMain> {
public static TownyUniverse TU;
private static ArrayList<String> Towns;

View file

@ -57,6 +57,7 @@ public class PlayerJoinLeaveListener implements Listener {
nwithoutformatting = p.getName();
PlayerListener.nicknames.forcePut(nwithoutformatting.toLowerCase(), p.getUniqueId()); //TODO: FormatterComponent
if (PluginMain.Instance.storeChatHistory().get())
HistoryCommand.showHistory(e.getPlayer(), null);
}

View file

@ -98,7 +98,7 @@ public class ChatFormatIT {
@Test
public void testMessage() {
ArrayList<ChatFormatter> cfs = ChatProcessing.addFormatters(Color.White, p -> true);
ArrayList<ChatFormatter> cfs = ChatProcessing.addFormatters(Color.White, p -> true, null);
final String chid = ChatProcessing.getChannelID(Channel.GlobalChat, ChatUtils.MCORIGIN);
final TellrawPart tp = ChatProcessing.createTellraw(sender, message, null, null, null, chid, ChatUtils.MCORIGIN);
ChatFormatter.Combine(cfs, message, tp, null);