aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCow <cow@volloeko.de>2020-07-31 17:02:24 +0200
committerCow <cow@volloeko.de>2020-07-31 17:02:24 +0200
commit86737c14f70bd5936e9492d9f3b53c4702f5aa55 (patch)
tree6d10fcb626912aa7034f866c624a0861d7e02d05 /src
parent18b212830420d8160b1e8b3076211cf1748229bf (diff)
downloadCowlection-86737c14f70bd5936e9492d9f3b53c4702f5aa55.tar.gz
Cowlection-86737c14f70bd5936e9492d9f3b53c4702f5aa55.tar.bz2
Cowlection-86737c14f70bd5936e9492d9f3b53c4702f5aa55.zip
Prevent adding other client-side commands to the list of commands with Tab-completable usernames
- Only one client-side command can be registered for a command name; they would overwrite each other
Diffstat (limited to 'src')
-rw-r--r--src/main/java/de/cowtipper/cowlection/config/MooConfig.java32
-rw-r--r--src/main/java/de/cowtipper/cowlection/listener/skyblock/DungeonsListener.java7
2 files changed, 31 insertions, 8 deletions
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");
}