Convert all configs

This commit is contained in:
Norbi Peti 2020-10-26 19:56:22 +01:00
parent 77b5a069c5
commit 8e9989caee
No known key found for this signature in database
GPG key ID: DBA4C4549A927E56
21 changed files with 68 additions and 165 deletions

View file

@ -1,71 +0,0 @@
# For most projects, this workflow file will not need changing; you simply need
# to commit it to your repository.
#
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
name: "CodeQL"
on:
push:
branches: [master]
pull_request:
# The branches below must be a subset of the branches above
branches: [master]
schedule:
- cron: '0 10 * * 1'
jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
# Override automatic language detection by changing the below list
# Supported options are ['csharp', 'cpp', 'go', 'java', 'javascript', 'python']
language: ['java']
# Learn more...
# https://docs.github.com/en/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#overriding-automatic-language-detection
steps:
- name: Checkout repository
uses: actions/checkout@v2
with:
# We must fetch at least the immediate parents so that if this is
# a pull request then we can checkout the head.
fetch-depth: 2
# If this run was triggered by a pull request event, then checkout
# the head of the pull request instead of the merge commit.
- run: git checkout HEAD^2
if: ${{ github.event_name == 'pull_request' }}
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
# queries: ./path/to/local/query, your-org/your-repo/queries@main
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v1
# Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
# and modify them (or add more) to build your code if your project
# uses a compiled language
#- run: |
# make bootstrap
# make release
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1

View file

@ -56,7 +56,7 @@ public final class ChatUtils {
} }
public static String getMessageString(Channel channel, CommandSender sender, String message) { public static String getMessageString(Channel channel, CommandSender sender, String message) {
return "§c!§r[" + channel.DisplayName().get() + "] <" return "§c!§r[" + channel.DisplayName.get() + "] <"
+ ChromaUtils.getDisplayName(sender) + "> " + message; + ChromaUtils.getDisplayName(sender) + "> " + message;
} }

View file

@ -40,9 +40,7 @@ public class PluginMain extends ButtonPlugin { // Translated to Java: 2015.07.15
* If enabled, stores and displays the last 10 messages the player can see (public, their town chat etc.) * 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. * 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() { public ConfigData<Boolean> storeChatHistory = getIConfig().getData("storeChatHistory", true);
return getIConfig().getData("storeChatHistory", true);
}
// Fired when plugin is first enabled // Fired when plugin is first enabled
@Override @Override

View file

@ -31,7 +31,7 @@ public class HistoryCommand extends UCommandBase {
} }
public static boolean showHistory(CommandSender sender, String channel) { public static boolean showHistory(CommandSender sender, String channel) {
if (!PluginMain.Instance.storeChatHistory().get()) { if (!PluginMain.Instance.storeChatHistory.get()) {
sender.sendMessage("§6Chat history is disabled"); sender.sendMessage("§6Chat history is disabled");
return true; return true;
} }
@ -55,7 +55,7 @@ public class HistoryCommand extends UCommandBase {
for (int i = Math.max(0, arr.length - 10); i < arr.length; i++) { for (int i = Math.max(0, arr.length - 10); i < arr.length; i++) {
HistoryEntry e = arr[i]; HistoryEntry e = arr[i];
val cm = e.chatMessage; val cm = e.chatMessage;
sender.sendMessage("[" + e.channel.DisplayName().get() + "] " + cm.getSender().getName() + ": " + cm.getMessage()); sender.sendMessage("[" + e.channel.DisplayName.get() + "] " + cm.getSender().getName() + ": " + cm.getMessage());
sent.set(true); sent.set(true);
} }
} }
@ -80,7 +80,7 @@ public class HistoryCommand extends UCommandBase {
} }
public static void addChatMessage(ChatMessage chatMessage, Channel channel) { public static void addChatMessage(ChatMessage chatMessage, Channel channel) {
if (!PluginMain.Instance.storeChatHistory().get()) return; if (!PluginMain.Instance.storeChatHistory.get()) return;
val groupID = channel.getGroupID(chatMessage.getPermCheck()); val groupID = channel.getGroupID(chatMessage.getPermCheck());
if (groupID == null) return; //Just to be sure if (groupID == null) return; //Just to be sure
synchronized (messages) { synchronized (messages) {

View file

@ -24,7 +24,7 @@ public class AnnounceCommand extends UCommandBase {
}) })
public boolean add(CommandSender sender, @Command2.TextArg String text) { public boolean add(CommandSender sender, @Command2.TextArg String text) {
String finalmessage = text.replace('&', '§'); String finalmessage = text.replace('&', '§');
component.announceMessages().get().add(finalmessage); component.announceMessages.get().add(finalmessage);
sender.sendMessage("§bAnnouncement added.§r"); sender.sendMessage("§bAnnouncement added.§r");
return true; return true;
} }
@ -38,9 +38,9 @@ public class AnnounceCommand extends UCommandBase {
String finalmessage1 = text.replace('&', '§'); String finalmessage1 = text.replace('&', '§');
if (index > 100) if (index > 100)
return false; return false;
while (component.announceMessages().get().size() <= index) while (component.announceMessages.get().size() <= index)
component.announceMessages().get().add(""); component.announceMessages.get().add("");
component.announceMessages().get().set(index, finalmessage1); component.announceMessages.get().set(index, finalmessage1);
sender.sendMessage("Announcement edited."); sender.sendMessage("Announcement edited.");
return true; return true;
} }
@ -53,7 +53,7 @@ public class AnnounceCommand extends UCommandBase {
sender.sendMessage("§bList of announce messages:§r"); sender.sendMessage("§bList of announce messages:§r");
sender.sendMessage("§bFormat: [index] message§r"); sender.sendMessage("§bFormat: [index] message§r");
int i = 0; int i = 0;
for (String message : component.announceMessages().get()) { for (String message : component.announceMessages.get()) {
String msg = "[" + i++ + "] " + message; String msg = "[" + i++ + "] " + message;
//noinspection SuspiciousMethodCalls //noinspection SuspiciousMethodCalls
if (!ComponentManager.isEnabled(FormatterComponent.class) || !Bukkit.getOnlinePlayers().contains(sender)) { if (!ComponentManager.isEnabled(FormatterComponent.class) || !Bukkit.getOnlinePlayers().contains(sender)) {
@ -67,7 +67,7 @@ public class AnnounceCommand extends UCommandBase {
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "tellraw " + sender.getName() + " " + json); Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "tellraw " + sender.getName() + " " + json);
} }
sender.sendMessage("§bCurrent wait time between announcements: " sender.sendMessage("§bCurrent wait time between announcements: "
+ component.announceTime().get() / 60 / 1000 + " minute(s)§r"); + component.announceTime.get() / 60 / 1000 + " minute(s)§r");
return true; return true;
} }
@ -76,7 +76,7 @@ public class AnnounceCommand extends UCommandBase {
"This command removes an announcement" "This command removes an announcement"
}) })
public boolean remove(CommandSender sender, int index) { public boolean remove(CommandSender sender, int index) {
val msgs = component.announceMessages().get(); val msgs = component.announceMessages.get();
if (index < 0 || index > msgs.size()) return false; if (index < 0 || index > msgs.size()) return false;
msgs.remove(index); msgs.remove(index);
sender.sendMessage("Announcement removed."); sender.sendMessage("Announcement removed.");
@ -88,7 +88,7 @@ public class AnnounceCommand extends UCommandBase {
"This command sets the time between the announcements" "This command sets the time between the announcements"
}) })
public boolean settime(CommandSender sender, int minutes) { public boolean settime(CommandSender sender, int minutes) {
component.announceTime().set(minutes * 60 * 1000); component.announceTime.set(minutes * 60 * 1000);
sender.sendMessage("Time set between announce messages to " + minutes + " minutes"); sender.sendMessage("Time set between announce messages to " + minutes + " minutes");
return true; return true;
} }

View file

@ -16,16 +16,12 @@ public class AnnouncerComponent extends Component<PluginMain> implements Runnabl
/** /**
* The messages to display to players. * The messages to display to players.
*/ */
public ListConfigData<String> announceMessages() { public ListConfigData<String> announceMessages = getConfig().getListData("announceMessages");
return getConfig().getListData("announceMessages");
}
/** /**
* The time in milliseconds between the messages. Use /u announce settime to set minutes. * The time in milliseconds between the messages. Use /u announce settime to set minutes.
*/ */
public ConfigData<Integer> announceTime() { public ConfigData<Integer> announceTime = getConfig().getData("announceTime", 15 * 60 * 1000);
return getConfig().getData("announceTime", 15 * 60 * 1000);
}
private TBMCSystemChatEvent.BroadcastTarget target; private TBMCSystemChatEvent.BroadcastTarget target;
@ -35,15 +31,15 @@ public class AnnouncerComponent extends Component<PluginMain> implements Runnabl
public void run() { public void run() {
while (isEnabled()) { while (isEnabled()) {
try { try {
Thread.sleep(announceTime().get()); Thread.sleep(announceTime.get());
} catch (InterruptedException ex) { } catch (InterruptedException ex) {
Thread.currentThread().interrupt(); Thread.currentThread().interrupt();
} }
if (Bukkit.getOnlinePlayers().size() == 0) continue; //Don't post to Discord if nobody is on if (Bukkit.getOnlinePlayers().size() == 0) continue; //Don't post to Discord if nobody is on
if (announceMessages().get().size() > AnnounceMessageIndex) { if (announceMessages.get().size() > AnnounceMessageIndex) {
TBMCChatAPI.SendSystemMessage(Channel.GlobalChat, Channel.RecipientTestResult.ALL, announceMessages().get().get(AnnounceMessageIndex), target); TBMCChatAPI.SendSystemMessage(Channel.GlobalChat, Channel.RecipientTestResult.ALL, announceMessages.get().get(AnnounceMessageIndex), target);
AnnounceMessageIndex++; AnnounceMessageIndex++;
if (AnnounceMessageIndex == announceMessages().get().size()) if (AnnounceMessageIndex == announceMessages.get().size())
AnnounceMessageIndex = 0; AnnounceMessageIndex = 0;
} }
} }

View file

@ -35,7 +35,7 @@ public class AcceptCommand extends UCommandBase {
} }
if (p.FlairState.get().equals(FlairStates.NoComment) || p.UserNames.get().size() == 0) { if (p.FlairState.get().equals(FlairStates.NoComment) || p.UserNames.get().size() == 0) {
player.sendMessage("§cError: You need to write your username to the reddit thread§r"); player.sendMessage("§cError: You need to write your username to the reddit thread§r");
player.sendMessage(component.flairThreadURL().get()); player.sendMessage(component.flairThreadURL.get());
return true; return true;
} }
if (username != null && !p.UserNames.get().contains(username)) { if (username != null && !p.UserNames.get().contains(username)) {

View file

@ -27,9 +27,7 @@ public class FlairComponent extends Component<PluginMain> {
/** /**
* The Reddit thread to check for account connections. Re-enable the component if this was empty. * The Reddit thread to check for account connections. Re-enable the component if this was empty.
*/ */
ConfigData<String> flairThreadURL() { ConfigData<String> flairThreadURL = getConfig().getData("flairThreadURL", "");
return getConfig().getData("flairThreadURL", "");
}
/** /**
* <p> * <p>
@ -39,7 +37,7 @@ public class FlairComponent extends Component<PluginMain> {
* It's used because normally it has to load all associated player files every time to read the flair state * It's used because normally it has to load all associated player files every time to read the flair state
* </p> * </p>
*/ */
private Set<String> PlayersWithFlairs = new HashSet<>(); private final Set<String> PlayersWithFlairs = new HashSet<>();
@Override @Override
protected void enable() { protected void enable() {
@ -56,9 +54,9 @@ public class FlairComponent extends Component<PluginMain> {
private void FlairGetterThreadMethod() { private void FlairGetterThreadMethod() {
int errorcount = 0; int errorcount = 0;
while (isEnabled() && flairThreadURL().get().length() > 0) { while (isEnabled() && flairThreadURL.get().length() > 0) {
try { try {
String body = TBMCCoreAPI.DownloadString(flairThreadURL().get() + ".json?limit=1000"); String body = TBMCCoreAPI.DownloadString(flairThreadURL.get() + ".json?limit=1000");
JsonArray json = new JsonParser().parse(body).getAsJsonArray().get(1).getAsJsonObject().get("data") JsonArray json = new JsonParser().parse(body).getAsJsonArray().get(1).getAsJsonObject().get("data")
.getAsJsonObject().get("children").getAsJsonArray(); .getAsJsonObject().get("children").getAsJsonArray();
for (Object obj : json) { for (Object obj : json) {
@ -147,7 +145,7 @@ public class FlairComponent extends Component<PluginMain> {
} catch (Exception e) { } catch (Exception e) {
p.FlairState.set(FlairStates.Commented); // Flair unknown p.FlairState.set(FlairStates.Commented); // Flair unknown
p.SetFlair(ChatPlayer.FlairTimeNone); p.SetFlair(ChatPlayer.FlairTimeNone);
TBMCCoreAPI.SendException("Error while checking join date for player " + p.PlayerName() + "!", e, this); TBMCCoreAPI.SendException("Error while checking join date for player " + p.PlayerName + "!", e, this);
} }
return; return;
default: default:

View file

@ -50,7 +50,7 @@ public class SetFlairCommand extends AdminCommandBase {
mp.UserNames.get().add(username); mp.UserNames.get().add(username);
} }
sender.sendMessage( sender.sendMessage(
"§bThe flair has been set. Player: " + mp.PlayerName() + " Flair: " + mp.GetFormattedFlair() + "§r"); "§bThe flair has been set. Player: " + mp.PlayerName + " Flair: " + mp.GetFormattedFlair() + "§r");
return true; return true;
} }

View file

@ -122,7 +122,7 @@ public class ChatProcessing {
mp = e.getUser().getAs(ChatPlayer.class); //May be null mp = e.getUser().getAs(ChatPlayer.class); //May be null
if (mp != null) { if (mp != null) {
if (System.nanoTime() - mp.LastMessageTime < 1000 * 1000 * component.minTimeBetweenMessages().get()) { //0.1s by default if (System.nanoTime() - mp.LastMessageTime < 1000 * 1000 * component.minTimeBetweenMessages.get()) { //0.1s by default
sender.sendMessage("§cYou are sending messages too quickly!"); sender.sendMessage("§cYou are sending messages too quickly!");
return true; return true;
} }
@ -144,14 +144,14 @@ public class ChatProcessing {
if (Bukkit.getOnlinePlayers().size() == 0) return false; //Don't try to send to nobody (errors on 1.14) if (Bukkit.getOnlinePlayers().size() == 0) return false; //Don't try to send to nobody (errors on 1.14)
Color colormode = channel.Color().get(); Color colormode = channel.Color.get();
if (mp != null && mp.OtherColorMode != null) if (mp != null && mp.OtherColorMode != null)
colormode = mp.OtherColorMode; colormode = mp.OtherColorMode;
ArrayList<MatchProviderBase> formatters; ArrayList<MatchProviderBase> formatters;
if (component.allowFormatting().get()) { if (component.allowFormatting.get()) {
formatters = addFormatters(e::shouldSendTo, component); formatters = addFormatters(e::shouldSendTo, component);
if (colormode == channel.Color().get() && mp != null && mp.RainbowPresserColorMode) { // Only overwrite channel color if (colormode == channel.Color.get() && mp != null && mp.RainbowPresserColorMode) { // Only overwrite channel color
createRPC(colormode, formatters); createRPC(colormode, formatters);
} }
pingedconsole = false; // Will set it to true onmatch (static constructor) pingedconsole = false; // Will set it to true onmatch (static constructor)
@ -256,7 +256,7 @@ public class ChatProcessing {
} }
static String getChannelID(Channel channel, String origin) { static String getChannelID(Channel channel, String origin) {
return ("[" + (ChatUtils.MCORIGIN.equals(origin) ? "" : "§8" + origin.substring(0, 1) + "§r|") + channel.DisplayName().get()) return ("[" + (ChatUtils.MCORIGIN.equals(origin) ? "" : "§8" + origin.charAt(0) + "§r|") + channel.DisplayName.get())
+ "]"; + "]";
} }
@ -323,11 +323,11 @@ public class ChatProcessing {
} }
private static void playPingSound(Player p, @Nullable FormatterComponent component) { private static void playPingSound(Player p, @Nullable FormatterComponent component) {
if (component == null || component.notificationSound().get().length() == 0) if (component == null || component.notificationSound.get().length() == 0)
p.playSound(p.getLocation(), Sound.ENTITY_ARROW_HIT_PLAYER, 1.0f, 0.5f); // TODO: Airhorn p.playSound(p.getLocation(), Sound.ENTITY_ARROW_HIT_PLAYER, 1.0f, 0.5f); // TODO: Airhorn
else else
p.playSound(p.getLocation(), component.notificationSound().get(), 1.0f, p.playSound(p.getLocation(), component.notificationSound.get(), 1.0f,
component.notificationPitch().get()); component.notificationPitch.get());
} }
static void doFunStuff(CommandSender sender, TBMCChatEventBase event, String message) { static void doFunStuff(CommandSender sender, TBMCChatEventBase event, String message) {

View file

@ -16,30 +16,22 @@ public class FormatterComponent extends Component<PluginMain> {
/** /**
* Determines whether Markdown formatting, name mentioning and similar features are enabled. * Determines whether Markdown formatting, name mentioning and similar features are enabled.
*/ */
ConfigData<Boolean> allowFormatting() { ConfigData<Boolean> allowFormatting = getConfig().getData("allowFormatting", true);
return getConfig().getData("allowFormatting", true);
}
/** /**
* The sound to play when a player is mentioned. Leave empty to use default. * The sound to play when a player is mentioned. Leave empty to use default.
*/ */
public ConfigData<String> notificationSound() { public ConfigData<String> notificationSound = getConfig().getData("notificationSound", "");
return getConfig().getData("notificationSound", "");
}
/** /**
* The pitch of the notification sound. * The pitch of the notification sound.
*/ */
public ConfigData<Float> notificationPitch() { public ConfigData<Float> notificationPitch = getConfig().getData("notificationPitch", 1.0f);
return getConfig().getData("notificationPitch", 1.0f);
}
/** /**
* The minimum time between messages in milliseconds. * The minimum time between messages in milliseconds.
*/ */
public ConfigData<Integer> minTimeBetweenMessages() { public ConfigData<Integer> minTimeBetweenMessages = getConfig().getData("minTimeBetweenMessages", 100);
return getConfig().getData("minTimeBetweenMessages", 100);
}
@Override @Override
protected void enable() { protected void enable() {

View file

@ -55,7 +55,7 @@ public class FTopCommand extends ICommand2MC {
val ai = new AtomicInteger(); val ai = new AtomicInteger();
sender.sendMessage("§6---- Top Fs ----"); sender.sendMessage("§6---- Top Fs ----");
sender.sendMessage(Arrays.stream(cached).skip((i - 1) * 10).limit(i * 10) sender.sendMessage(Arrays.stream(cached).skip((i - 1) * 10).limit(i * 10)
.map(cp -> String.format("%d. %s - %f.2", ai.incrementAndGet(), cp.PlayerName().get(), cp.getF())) .map(cp -> String.format("%d. %s - %f.2", ai.incrementAndGet(), cp.PlayerName.get(), cp.getF()))
.collect(Collectors.joining("\n"))); .collect(Collectors.joining("\n")));
}); });
return true; return true;

View file

@ -36,7 +36,7 @@ public class FunComponent extends Component<PluginMain> implements Listener {
private boolean ActiveF = false; private boolean ActiveF = false;
private ChatPlayer FPlayer = null; private ChatPlayer FPlayer = null;
private BukkitTask Ftask = null; private BukkitTask Ftask = null;
private HashSet<CommandSender> Fs = new HashSet<>(); private final HashSet<CommandSender> Fs = new HashSet<>();
private UnlolCommand command; private UnlolCommand command;
private TBMCSystemChatEvent.BroadcastTarget unlolTarget; private TBMCSystemChatEvent.BroadcastTarget unlolTarget;
private TBMCSystemChatEvent.BroadcastTarget fTarget; private TBMCSystemChatEvent.BroadcastTarget fTarget;
@ -44,26 +44,20 @@ public class FunComponent extends Component<PluginMain> implements Listener {
/** /**
* The strings that count as laughs, see unlol. * The strings that count as laughs, see unlol.
*/ */
private ConfigData<String[]> laughStrings() { private final ConfigData<String[]> laughStrings = getConfig().getData("laughStrings", () -> new String[]{"xd", "lel", "lawl", "kek", "lmao", "hue", "hah", "rofl"});
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. * 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. * You can hover over a player's name to see their respect.
*/ */
private ConfigData<Boolean> respect() { private final ConfigData<Boolean> respect = getConfig().getData("respect", true);
return getConfig().getData("respect", true);
}
/** /**
* This is an inside joke on our server. * This is an inside joke on our server.
* 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. * 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.
* Which also blinds the laughing person for a few seconds. This action can only be performed once per laugh. * Which also blinds the laughing person for a few seconds. This action can only be performed once per laugh.
*/ */
private ConfigData<Boolean> unlol() { private final ConfigData<Boolean> unlol = getConfig().getData("unlol", true);
return getConfig().getData("unlol", true);
}
@Override @Override
protected void enable() { protected void enable() {
@ -89,14 +83,14 @@ public class FunComponent extends Component<PluginMain> implements Listener {
if (ActiveF && !Fs.contains(sender) && message.equalsIgnoreCase("F")) if (ActiveF && !Fs.contains(sender) && message.equalsIgnoreCase("F"))
Fs.add(sender); Fs.add(sender);
if (unlol().get()) { if (unlol.get()) {
String msg = message.toLowerCase(); String msg = message.toLowerCase();
val lld = new UnlolCommand.LastlolData(sender, event, System.nanoTime()); val lld = new UnlolCommand.LastlolData(sender, event, System.nanoTime());
boolean add; boolean add;
if (add = msg.contains("lol")) if (add = msg.contains("lol"))
lld.setLolornot(true); lld.setLolornot(true);
else { else {
String[] laughs = laughStrings().get(); String[] laughs = laughStrings.get();
for (String laugh : laughs) { for (String laugh : laughs) {
if (add = msg.contains(laugh)) { if (add = msg.contains(laugh)) {
lld.setLolornot(false); lld.setLolornot(false);
@ -112,7 +106,7 @@ public class FunComponent extends Component<PluginMain> implements Listener {
@EventHandler @EventHandler
public void onPlayerDeath(PlayerDeathEvent e) { public void onPlayerDeath(PlayerDeathEvent e) {
// MinigamePlayer mgp = Minigames.plugin.pdata.getMinigamePlayer(e.getEntity()); // MinigamePlayer mgp = Minigames.plugin.pdata.getMinigamePlayer(e.getEntity());
if (e.getDeathMessage().length() > 0 && respect().get() && new Random().nextBoolean()) { // Don't store Fs for NPCs if (e.getDeathMessage().length() > 0 && respect.get() && new Random().nextBoolean()) { // Don't store Fs for NPCs
Runnable tt = () -> { Runnable tt = () -> {
if (ActiveF) { if (ActiveF) {
ActiveF = false; ActiveF = false;
@ -140,14 +134,14 @@ public class FunComponent extends Component<PluginMain> implements Listener {
@EventHandler @EventHandler
public void onPlayerLeave(PlayerQuitEvent event) { public void onPlayerLeave(PlayerQuitEvent event) {
if (unlol().get()) if (unlol.get())
command.Lastlol.values().removeIf(lld -> lld.getLolowner().equals(event.getPlayer())); command.Lastlol.values().removeIf(lld -> lld.getLolowner().equals(event.getPlayer()));
} }
@EventHandler(priority = EventPriority.LOWEST) @EventHandler(priority = EventPriority.LOWEST)
public void onCommandPreprocess(TBMCCommandPreprocessEvent event) { public void onCommandPreprocess(TBMCCommandPreprocessEvent event) {
if (event.isCancelled()) return; if (event.isCancelled()) return;
if (!unlol().get()) return; if (!unlol.get()) return;
final String cmd = event.getMessage(); final String cmd = event.getMessage();
// We don't care if we have arguments // We don't care if we have arguments
if (cmd.toLowerCase().startsWith("/un")) { if (cmd.toLowerCase().startsWith("/un")) {

View file

@ -50,7 +50,7 @@ public class NColorCommand extends UCommandBase {
return true; return true;
} }
var component = TownColorComponent.getComponent(); var component = TownColorComponent.getComponent();
byte nationColors = (byte) (component.useNationColors().get() ? 1 : 0); byte nationColors = (byte) (component.useNationColors.get() ? 1 : 0);
if (nameparts.length < towncolors.length + nationColors) { //+1: Nation color if (nameparts.length < towncolors.length + nationColors) { //+1: Nation color
player.sendMessage("§cYou need more vertical lines (|) or colons (:) in your name. (Should have " + (towncolors.length - 1 + 1) + ")"); //Nation color player.sendMessage("§cYou need more vertical lines (|) or colons (:) in your name. (Should have " + (towncolors.length - 1 + 1) + ")"); //Nation color
return true; return true;

View file

@ -31,7 +31,7 @@ public class TownColorCommand extends UCommandBase {
player.sendMessage(msg); player.sendMessage(msg);
return true; return true;
} }
val cc = component.colorCount().get(); val cc = component.colorCount.get();
if (colornames.length > cc) { if (colornames.length > cc) {
player.sendMessage("You can only use " + cc + " color" + (cc > 1 ? "s" : "") + "."); player.sendMessage("You can only use " + cc + " color" + (cc > 1 ? "s" : "") + ".");
return true; return true;

View file

@ -53,17 +53,13 @@ public class TownColorComponent extends Component<PluginMain> implements Listene
/** /**
* 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. * 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() { public ConfigData<Byte> colorCount = getConfig().getData("colorCount", (byte) 1, cc -> ((Integer) cc).byteValue(), Byte::intValue);
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. * 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. * They can change how much of each color they want with this as well.
*/ */
public ConfigData<Boolean> useNationColors() { public ConfigData<Boolean> useNationColors = getConfig().getData("useNationColors", true);
return getConfig().getData("useNationColors", true);
}
@Getter @Getter
private static TownColorComponent component; private static TownColorComponent component;
@ -75,7 +71,7 @@ public class TownColorComponent extends Component<PluginMain> implements Listene
Consumer<ConfigurationSection> loadTC = cs -> TownColorComponent.TownColors.putAll(cs.getValues(true).entrySet().stream() Consumer<ConfigurationSection> loadTC = cs -> TownColorComponent.TownColors.putAll(cs.getValues(true).entrySet().stream()
.collect(Collectors.toMap(Map.Entry::getKey, v -> ((List<String>) v.getValue()).stream() .collect(Collectors.toMap(Map.Entry::getKey, v -> ((List<String>) v.getValue()).stream()
.map(Color::valueOf).toArray(Color[]::new)))); .map(Color::valueOf).toArray(Color[]::new))));
boolean usenc = useNationColors().get(); boolean usenc = useNationColors.get();
Consumer<ConfigurationSection> loadNC = ncs -> Consumer<ConfigurationSection> loadNC = ncs ->
TownColorComponent.NationColor.putAll(ncs.getValues(true).entrySet().stream() TownColorComponent.NationColor.putAll(ncs.getValues(true).entrySet().stream()
.collect(Collectors.toMap(Map.Entry::getKey, v -> Color.valueOf((String) v.getValue())))); .collect(Collectors.toMap(Map.Entry::getKey, v -> Color.valueOf((String) v.getValue()))));
@ -95,10 +91,10 @@ public class TownColorComponent extends Component<PluginMain> implements Listene
initDynmap(); initDynmap();
registerCommand(new TownColorCommand(this)); registerCommand(new TownColorCommand(this));
if (useNationColors().get()) if (useNationColors.get())
registerCommand(new NationColorCommand()); registerCommand(new NationColorCommand());
registerCommand(new buttondevteam.chat.components.towncolors.admin.TownColorCommand()); registerCommand(new buttondevteam.chat.components.towncolors.admin.TownColorCommand());
if (useNationColors().get()) if (useNationColors.get())
registerCommand(new buttondevteam.chat.components.towncolors.admin.NationColorCommand()); registerCommand(new buttondevteam.chat.components.towncolors.admin.NationColorCommand());
registerCommand(new TCCount()); registerCommand(new TCCount());
registerCommand(new NColorCommand()); registerCommand(new NColorCommand());
@ -110,7 +106,7 @@ public class TownColorComponent extends Component<PluginMain> implements Listene
protected void disable() { protected void disable() {
getConfig().getConfig().createSection("towncolors", TownColors.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, getConfig().getConfig().createSection("towncolors", TownColors.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey,
v -> Arrays.stream(v.getValue()).map(Enum::toString).toArray(String[]::new)))); v -> Arrays.stream(v.getValue()).map(Enum::toString).toArray(String[]::new))));
if (useNationColors().get()) if (useNationColors.get())
getConfig().getConfig().createSection("nationcolors", NationColor.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, getConfig().getConfig().createSection("nationcolors", NationColor.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey,
v -> v.getValue().toString()))); v -> v.getValue().toString())));
getConfig().signalChange(); getConfig().signalChange();
@ -126,7 +122,7 @@ public class TownColorComponent extends Component<PluginMain> implements Listene
val town = TownyComponent.dataSource.getTown(entry.getKey()); val town = TownyComponent.dataSource.getTown(entry.getKey());
Nation nation; Nation nation;
Color nc; Color nc;
if (!useNationColors().get()) if (!useNationColors.get())
nc = null; nc = null;
else if (!town.hasNation() || (nation = town.getNation()) == null || (nc = NationColor.get(nation.getName().toLowerCase())) == null) else if (!town.hasNation() || (nation = town.getNation()) == null || (nc = NationColor.get(nation.getName().toLowerCase())) == null)
nc = Color.White; nc = Color.White;
@ -187,7 +183,7 @@ public class TownColorComponent extends Component<PluginMain> implements Listene
len = name.length() / (clrs.length+1); len = name.length() / (clrs.length+1);
else else
len = name.length() / clrs.length;*/ len = name.length() / clrs.length;*/
boolean usenc = component.useNationColors().get(); boolean usenc = component.useNationColors.get();
val nclar = cp.NameColorLocations.get(); val nclar = cp.NameColorLocations.get();
int[] ncl = nclar == null ? null : nclar.stream().mapToInt(Integer::intValue).toArray(); int[] ncl = nclar == null ? null : nclar.stream().mapToInt(Integer::intValue).toArray();
if (ncl != null && (Arrays.stream(ncl).sum() != name.length() || ncl.length != clrs.length + (usenc ? 1 : 0))) //+1: Nation color if (ncl != null && (Arrays.stream(ncl).sum() != name.length() || ncl.length != clrs.length + (usenc ? 1 : 0))) //+1: Nation color

View file

@ -61,7 +61,7 @@ public class TownyListener implements Listener {
@EventHandler @EventHandler
public void onNationRename(RenameNationEvent event) { public void onNationRename(RenameNationEvent event) {
if (!TownColorComponent.getComponent().useNationColors().get()) return; if (!TownColorComponent.getComponent().useNationColors.get()) return;
val clrs = TownColorComponent.NationColor.remove(event.getOldName().toLowerCase()); val clrs = TownColorComponent.NationColor.remove(event.getOldName().toLowerCase());
if (clrs != null) if (clrs != null)
TownColorComponent.NationColor.put(event.getNation().getName().toLowerCase(), clrs); TownColorComponent.NationColor.put(event.getNation().getName().toLowerCase(), clrs);
@ -69,25 +69,25 @@ public class TownyListener implements Listener {
@EventHandler //Gets called on town load as well @EventHandler //Gets called on town load as well
public void onNationJoin(NationAddTownEvent event) { public void onNationJoin(NationAddTownEvent event) {
if (!TownColorComponent.getComponent().useNationColors().get()) return; if (!TownColorComponent.getComponent().useNationColors.get()) return;
updateTownMembers(event.getTown()); updateTownMembers(event.getTown());
} }
@EventHandler @EventHandler
public void onNationLeave(NationRemoveTownEvent event) { public void onNationLeave(NationRemoveTownEvent event) {
if (!TownColorComponent.getComponent().useNationColors().get()) return; if (!TownColorComponent.getComponent().useNationColors.get()) return;
updateTownMembers(event.getTown()); //The town still has it's colours updateTownMembers(event.getTown()); //The town still has it's colours
} }
@EventHandler @EventHandler
public void onNationDelete(DeleteNationEvent event) { public void onNationDelete(DeleteNationEvent event) {
if (!TownColorComponent.getComponent().useNationColors().get()) return; if (!TownColorComponent.getComponent().useNationColors.get()) return;
TownColorComponent.NationColor.remove(event.getNationName().toLowerCase()); TownColorComponent.NationColor.remove(event.getNationName().toLowerCase());
} }
@EventHandler @EventHandler
public void onNationCreate(NewNationEvent event) { public void onNationCreate(NewNationEvent event) {
if (!TownColorComponent.getComponent().useNationColors().get()) return; if (!TownColorComponent.getComponent().useNationColors.get()) return;
Player p = Bukkit.getPlayer(event.getNation().getCapital().getMayor().getName()); Player p = Bukkit.getPlayer(event.getNation().getCapital().getMayor().getName());
if (p != null) if (p != null)
p.sendMessage("§6Use /u nationcolor to set a color for the nation."); p.sendMessage("§6Use /u nationcolor to set a color for the nation.");

View file

@ -15,7 +15,7 @@ public class TCCount extends AdminCommandBase {
@Command2.Subcommand @Command2.Subcommand
public boolean def(CommandSender sender, byte count) { public boolean def(CommandSender sender, byte count) {
val comp = TownColorComponent.getComponent(); val comp = TownColorComponent.getComponent();
comp.colorCount().set(count); comp.colorCount.set(count);
sender.sendMessage("Color count set to " + count); sender.sendMessage("Color count set to " + count);
return true; return true;
} }

View file

@ -61,7 +61,7 @@ public class TownColorCommand extends AdminCommandBase { //TODO: Command path al
clrs[i] = c.get(); clrs[i] = c.get();
} }
Color tnc; Color tnc;
boolean usenc = TownColorComponent.getComponent().useNationColors().get(); boolean usenc = TownColorComponent.getComponent().useNationColors.get();
if (usenc) { if (usenc) {
try { try {
tnc = TownColorComponent.NationColor.get(town.getNation().getName().toLowerCase()); tnc = TownColorComponent.NationColor.get(town.getNation().getName().toLowerCase());

View file

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

View file

@ -56,7 +56,7 @@ public class PlayerListener implements Listener {
ChatPlayer cp = e.getPlayer().getAs(ChatPlayer.class); ChatPlayer cp = e.getPlayer().getAs(ChatPlayer.class);
if (cp == null) if (cp == null)
return; return;
e.addInfo("Minecraft name: " + cp.PlayerName().get()); e.addInfo("Minecraft name: " + cp.PlayerName.get());
if (cp.UserName.get() != null && cp.UserName.get().length() > 0) if (cp.UserName.get() != null && cp.UserName.get().length() > 0)
e.addInfo("Reddit name: " + cp.UserName.get()); e.addInfo("Reddit name: " + cp.UserName.get());
if (ComponentManager.isEnabled(FlairComponent.class)) { if (ComponentManager.isEnabled(FlairComponent.class)) {
@ -82,7 +82,7 @@ public class PlayerListener implements Listener {
lastError = System.nanoTime(); //I put the whole thing in the if to protect against race conditions lastError = System.nanoTime(); //I put the whole thing in the if to protect against race conditions
for (Player p : Bukkit.getOnlinePlayers()) for (Player p : Bukkit.getOnlinePlayers())
if (e.shouldSendTo(p)) if (e.shouldSendTo(p))
p.sendMessage("[" + e.getChannel().DisplayName().get() + "] §cSome features in the message below might be unavailable due to an error."); p.sendMessage("[" + e.getChannel().DisplayName.get() + "] §cSome features in the message below might be unavailable due to an error.");
} }
ChatUtils.sendChatMessage(e); ChatUtils.sendChatMessage(e);
TBMCCoreAPI.SendException("An error occured while processing a chat message!", ex, PluginMain.Instance); TBMCCoreAPI.SendException("An error occured while processing a chat message!", ex, PluginMain.Instance);