diff options
-rw-r--r-- | CHANGELOG.md | 2 | ||||
-rw-r--r-- | src/main/java/de/cowtipper/cowlection/config/MooConfig.java | 32 | ||||
-rw-r--r-- | src/main/java/de/cowtipper/cowlection/listener/skyblock/DungeonsListener.java | 7 |
3 files changed, 33 insertions, 8 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index dbb6353..7ae2631 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -32,6 +32,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Remove ": " when copying chat messages - Fix dungeon tooltip cleaner cleaning a little bit too much - Temporary work-around to fix crash with other mods which are not able to handle offline messages +- Prevent adding client-side commands to commands with Tab-completable usernames + - This would either overwrite the existing command, or wouldn't do anything at all. Only *one* client-side command can be registered for a command name. ## [1.8.9-0.9.0] - 23.07.2020 ### Added diff --git a/src/main/java/de/cowtipper/cowlection/config/MooConfig.java b/src/main/java/de/cowtipper/cowlection/config/MooConfig.java index 628850b..010a3a8 100644 --- a/src/main/java/de/cowtipper/cowlection/config/MooConfig.java +++ b/src/main/java/de/cowtipper/cowlection/config/MooConfig.java @@ -1,10 +1,13 @@ package de.cowtipper.cowlection.config; import de.cowtipper.cowlection.Cowlection; +import de.cowtipper.cowlection.command.TabCompletableCommand; import de.cowtipper.cowlection.util.Utils; import net.minecraft.client.Minecraft; +import net.minecraft.command.ICommand; import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.Util; +import net.minecraftforge.client.ClientCommandHandler; import net.minecraftforge.common.ForgeModContainer; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.config.Configuration; @@ -13,6 +16,7 @@ import net.minecraftforge.fml.client.FMLConfigGuiFactory; import net.minecraftforge.fml.client.event.ConfigChangedEvent; import net.minecraftforge.fml.common.eventhandler.EventPriority; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import org.apache.commons.lang3.ArrayUtils; import java.io.File; import java.time.LocalDate; @@ -21,6 +25,7 @@ import java.time.temporal.ChronoUnit; import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Map; import java.util.regex.Pattern; /** @@ -237,13 +242,30 @@ public class MooConfig { propDefaultStartDate.set(defaultStartDate); if (cfg.hasChanged()) { - if (Minecraft.getMinecraft().thePlayer != null) { - if (modifiedTabCompletableCommandsList) { - main.getChatHelper().sendMessage(EnumChatFormatting.RED, "Added or removed commands with tab-completable usernames take effect after a game restart!"); + boolean isPlayerIngame = Minecraft.getMinecraft().thePlayer != null; + if (modifiedTabCompletableCommandsList) { + if (isPlayerIngame) { + main.getChatHelper().sendMessage(EnumChatFormatting.RED, "Added or removed commands with tab-completable usernames take effect after a game restart! If player names cannot be tab-completed for a command after a game restart, check the capitalization of the command name."); } - if (dungClassRange[0] > -1 && dungClassRange[1] > -1 && dungClassRange[0] > dungClassRange[1]) { - main.getChatHelper().sendMessage(EnumChatFormatting.RED, "Dungeon class range minimum value cannot be higher than the maximum value."); + Map<String, ICommand> clientCommandsMap = ClientCommandHandler.instance.getCommands(); + List<String> removedCommands = new ArrayList<>(); + for (String tabCompletableCommandName : tabCompletableNamesCommands) { + ICommand possibleClientCommand = clientCommandsMap.get(tabCompletableCommandName); + if (possibleClientCommand != null && !(possibleClientCommand instanceof TabCompletableCommand)) { + // tried to add a client side command to tab-completable commands; however, this would overwrite the original command + removedCommands.add(tabCompletableCommandName); + } } + if (removedCommands.size() > 0) { + if (isPlayerIngame) { + main.getChatHelper().sendMessage(EnumChatFormatting.GOLD, " ⚠ " + EnumChatFormatting.GOLD + "Client-side commands from other mods cannot be added to commands with tab-completable usernames. " + EnumChatFormatting.RED + "This would overwrite the other command! Therefore the following commands have been removed from the list of commands with tab-completable usernames: " + EnumChatFormatting.GOLD + String.join(EnumChatFormatting.RED + ", " + EnumChatFormatting.GOLD, removedCommands)); + } + tabCompletableNamesCommands = (String[]) ArrayUtils.removeElements(tabCompletableNamesCommands, removedCommands.toArray()); + propTabCompletableNamesCommands.set(tabCompletableNamesCommands); + } + } + if (isPlayerIngame && dungClassRange[0] > -1 && dungClassRange[1] > -1 && dungClassRange[0] > dungClassRange[1]) { + main.getChatHelper().sendMessage(EnumChatFormatting.RED, "Dungeon class range minimum value cannot be higher than the maximum value."); } cfg.save(); } diff --git a/src/main/java/de/cowtipper/cowlection/listener/skyblock/DungeonsListener.java b/src/main/java/de/cowtipper/cowlection/listener/skyblock/DungeonsListener.java index 8ba2354..7ac627d 100644 --- a/src/main/java/de/cowtipper/cowlection/listener/skyblock/DungeonsListener.java +++ b/src/main/java/de/cowtipper/cowlection/listener/skyblock/DungeonsListener.java @@ -407,7 +407,6 @@ public class DungeonsListener { } } - @SubscribeEvent public void onPlayerTick(TickEvent.PlayerTickEvent e) { if (e.phase != TickEvent.Phase.END && e.side != Side.CLIENT && e.type != TickEvent.Type.PLAYER) { @@ -455,8 +454,10 @@ public class DungeonsListener { } else if (elapsedMinutes > 15) { color = EnumChatFormatting.YELLOW; } - dungeonPerformanceEntries.add("Elapsed Minutes: " + color + elapsedMinutes + (elapsedMinutes > 15 && elapsedMinutes <= 20 ? EnumChatFormatting.RED + " (> 20 mins = point penalty)" : "")); - if (elapsedMinutes > 20) { + dungeonPerformanceEntries.add("Elapsed Minutes: " + color + elapsedMinutes); + if (elapsedMinutes > 15 && elapsedMinutes <= 20) { + dungeonPerformanceEntries.add(EnumChatFormatting.RED + " ⚠ slower than 20 mins = point penalty"); + } else if (elapsedMinutes > 20) { dungeonPerformanceEntries.add(EnumChatFormatting.GOLD + " Time penalty: " + EnumChatFormatting.RED + ((int) (2.2 * (elapsedMinutes - 20))) + " points"); } |