diff options
Diffstat (limited to 'src/main/java')
5 files changed, 66 insertions, 6 deletions
diff --git a/src/main/java/de/cowtipper/cowlection/command/MooCommand.java b/src/main/java/de/cowtipper/cowlection/command/MooCommand.java index d9ed787..d2f433d 100644 --- a/src/main/java/de/cowtipper/cowlection/command/MooCommand.java +++ b/src/main/java/de/cowtipper/cowlection/command/MooCommand.java @@ -51,7 +51,11 @@ public class MooCommand extends CommandBase { @Override public List<String> getCommandAliases() { - return Collections.singletonList("m"); + if (StringUtils.isEmpty(MooConfig.mooCmdAlias)) { + return Collections.emptyList(); + } else { + return Collections.singletonList(MooConfig.mooCmdAlias); + } } @Override @@ -145,12 +149,12 @@ public class MooCommand extends CommandBase { if (cmdArgs.length() > 0) { cmdArgs = " " + cmdArgs; } - Minecraft.getMinecraft().thePlayer.sendChatMessage("/m" + cmdArgs); + Minecraft.getMinecraft().thePlayer.sendChatMessage("/" + MooConfig.mooCmdAlias + cmdArgs); } // "catch-all" remaining sub-commands else { - main.getChatHelper().sendMessage(EnumChatFormatting.RED, "Command " + EnumChatFormatting.DARK_RED + "/" + getCommandName() + " " + args[0] + EnumChatFormatting.RED + " doesn't exist. Use " + EnumChatFormatting.DARK_RED + "/" + getCommandName() + " help " + EnumChatFormatting.RED + "to show command usage.\n" - + EnumChatFormatting.RED + "Are you trying to use a server-side command " + EnumChatFormatting.DARK_RED + "/m" + EnumChatFormatting.RED + "? Use " + EnumChatFormatting.DARK_RED + "/m cmd [arguments] " + EnumChatFormatting.RED + "instead."); + main.getChatHelper().sendMessage(EnumChatFormatting.RED, "Command " + EnumChatFormatting.DARK_RED + "/" + getCommandName() + " " + args[0] + EnumChatFormatting.RED + " doesn't exist. Use " + EnumChatFormatting.DARK_RED + "/" + getCommandName() + " help " + EnumChatFormatting.RED + "to show command usage." + + (StringUtils.isNotEmpty(MooConfig.mooCmdAlias) ? "\n" + EnumChatFormatting.RED + "Are you trying to use a server-side command " + EnumChatFormatting.DARK_RED + "/" + MooConfig.mooCmdAlias + EnumChatFormatting.RED + "? Use " + EnumChatFormatting.DARK_RED + "/" + MooConfig.mooCmdAlias + " cmd [arguments] " + EnumChatFormatting.RED + "instead." : "")); } } diff --git a/src/main/java/de/cowtipper/cowlection/config/MooConfig.java b/src/main/java/de/cowtipper/cowlection/config/MooConfig.java index b89f4de..a522dce 100644 --- a/src/main/java/de/cowtipper/cowlection/config/MooConfig.java +++ b/src/main/java/de/cowtipper/cowlection/config/MooConfig.java @@ -1,6 +1,7 @@ package de.cowtipper.cowlection.config; import de.cowtipper.cowlection.Cowlection; +import de.cowtipper.cowlection.command.MooCommand; import de.cowtipper.cowlection.command.TabCompletableCommand; import de.cowtipper.cowlection.config.gui.MooConfigGui; import de.cowtipper.cowlection.config.gui.MooConfigPreview; @@ -46,6 +47,9 @@ import java.util.regex.Pattern; public class MooConfig { // Category: General private static String configGuiExplanations; + public static String mooCmdAlias; + public static boolean fixReplyCmd; + public static boolean enableCopyInventory; public static String[] tabCompletableNamesCommands; private static final String CATEGORY_LOGS_SEARCH = "logssearch"; public static String[] logsDirs; @@ -84,6 +88,7 @@ public class MooConfig { private static Configuration cfg = null; private static final List<MooConfigCategory> configCategories = new ArrayList<>(); private final Cowlection main; + private Property propMooCmdAlias; private Property propTabCompletableNamesCommands; private List<Property> logSearchProperties; @@ -196,6 +201,17 @@ public class MooConfig { "The API key is stored " + EnumChatFormatting.ITALIC + "locally " + EnumChatFormatting.ITALIC + "on your computer."); subCat.addConfigEntry(main.getMoo().getPropIsMooValid()); + // Sub-Category: Command settings + subCat = configCat.addSubCategory("Command settings"); + + propMooCmdAlias = subCat.addConfigEntry(cfg.get(configCat.getConfigName(), + "mooCmdAlias", "m", "Alias for /moo command") + .setValidationPattern(Pattern.compile("^[A-Za-z]*$"))); + Property propFixReplyCmd = subCat.addConfigEntry(cfg.get(configCat.getConfigName(), + "fixReplyCmd", true, "Auto-replace /r?")); + Property propEnableCopyInventory = subCat.addConfigEntry(cfg.get(configCat.getConfigName(), + "enableCopyInventory", false, "Enable copy inventory with CTRL + C?")); + // Sub-Category: Tab-completable names in commands subCat = configCat.addSubCategory("Tab-completable usernames"); subCat.addExplanations("For certain commands you can use " + EnumChatFormatting.YELLOW + "TAB " + EnumChatFormatting.RESET + "to autocomplete player names", @@ -410,11 +426,16 @@ public class MooConfig { Property propDungPartyFinderPlayerLookup = subCat.addConfigEntry(cfg.get(configCat.getConfigName(), "dungPartyFinderPlayerLookup", "as a tooltip", "Show armor + dungeons stats of player joining via party finder as a tooltip or in chat?", new String[]{"as a tooltip", "in chat", "disabled"})); + boolean modifiedMooCmdAlias = false; + String mooCmdAliasPreChange = mooCmdAlias; boolean modifiedTabCompletableCommandsList = false; String[] tabCompletableCommandsPreChange = tabCompletableNamesCommands != null ? tabCompletableNamesCommands.clone() : null; if (readFieldsFromConfig) { // Category: General configGuiExplanations = propConfigGuiExplanations.getString(); + mooCmdAlias = propMooCmdAlias.getString(); + fixReplyCmd = propFixReplyCmd.getBoolean(); + enableCopyInventory = propEnableCopyInventory.getBoolean(); tabCompletableNamesCommands = propTabCompletableNamesCommands.getStringList(); logsDirs = propLogsDirs.getStringList(); defaultStartDate = propDefaultStartDate.getString().trim(); @@ -450,6 +471,9 @@ public class MooConfig { dungPartyFinderPlayerLookup = propDungPartyFinderPlayerLookup.getString(); + if (!StringUtils.equals(mooCmdAliasPreChange, mooCmdAlias)) { + modifiedMooCmdAlias = true; + } if (!Arrays.equals(tabCompletableCommandsPreChange, tabCompletableNamesCommands)) { modifiedTabCompletableCommandsList = true; } @@ -457,6 +481,9 @@ public class MooConfig { // Category: General propConfigGuiExplanations.set(configGuiExplanations); + propMooCmdAlias.set(mooCmdAlias); + propFixReplyCmd.set(fixReplyCmd); + propEnableCopyInventory.set(enableCopyInventory); propTabCompletableNamesCommands.set(tabCompletableNamesCommands); propLogsDirs.set(logsDirs); propDefaultStartDate.set(defaultStartDate); @@ -493,6 +520,24 @@ public class MooConfig { if (saveToFile && cfg.hasChanged()) { boolean isPlayerIngame = Minecraft.getMinecraft().thePlayer != null; + if (modifiedMooCmdAlias) { + Map<String, ICommand> clientCommandsMap = ClientCommandHandler.instance.getCommands(); + ICommand possibleClientCommand = clientCommandsMap.get(mooCmdAlias); + if (possibleClientCommand != null && !(possibleClientCommand instanceof MooCommand)) { + // tried to use a command name which is already used by another client side command; however, this would overwrite the original command + if (isPlayerIngame) { + main.getChatHelper().sendMessage(EnumChatFormatting.GOLD, " ⚠ " + EnumChatFormatting.GOLD + "Client-side commands from other mods cannot be used as a command alias. " + EnumChatFormatting.RED + "This would overwrite the other command! Therefore the alias for " + EnumChatFormatting.DARK_RED + "/moo" + EnumChatFormatting.RED + " was not changed to " + EnumChatFormatting.DARK_RED + "/" + mooCmdAlias); + } + mooCmdAlias = mooCmdAliasPreChange; + propMooCmdAlias.set(mooCmdAlias); + } else if (isPlayerIngame) { + if (StringUtils.isEmpty(mooCmdAlias)) { + main.getChatHelper().sendMessage(EnumChatFormatting.RED, "Removed command alias for " + EnumChatFormatting.DARK_RED + "/moo " + EnumChatFormatting.RED + "which takes effect after a game restart."); + } else { + main.getChatHelper().sendMessage(EnumChatFormatting.RED, "Changed command alias for " + EnumChatFormatting.DARK_RED + "/moo " + EnumChatFormatting.RED + "to " + EnumChatFormatting.DARK_RED + "/" + mooCmdAlias + EnumChatFormatting.RED + " which takes effect after a game restart."); + } + } + } 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."); @@ -649,6 +694,10 @@ public class MooConfig { return configCategories; } + public Property getMooCmdAliasProperty() { + return propMooCmdAlias; + } + public Property getTabCompletableNamesCommandsProperty() { return propTabCompletableNamesCommands; } diff --git a/src/main/java/de/cowtipper/cowlection/config/gui/MooConfigCategoryScrolling.java b/src/main/java/de/cowtipper/cowlection/config/gui/MooConfigCategoryScrolling.java index c73e27e..4ffa9f0 100644 --- a/src/main/java/de/cowtipper/cowlection/config/gui/MooConfigCategoryScrolling.java +++ b/src/main/java/de/cowtipper/cowlection/config/gui/MooConfigCategoryScrolling.java @@ -126,6 +126,13 @@ public class MooConfigCategoryScrolling extends GuiListExtended { // special case: moo! this.listEntries.add(new BooleanConfigEntry(configEntry)); continue; + } else if (configEntry.equals(Cowlection.getInstance().getConfig().getMooCmdAliasProperty())) { + this.listEntries.add(new GuiSwitchEntry("mooCmdAlias", "➡ modify", () -> + mc.displayGuiScreen(new GuiConfig(MooConfigCategoryScrolling.this.parent, + Lists.newArrayList(new ConfigElement(Cowlection.getInstance().getConfig().getMooCmdAliasProperty())), + Cowlection.MODID, "cowlectionMooCmdAlias", false, false, + EnumChatFormatting.GOLD + "Press Done to save changes. " + EnumChatFormatting.RED + "Requires a game restart to take effect!")))); + continue; } else if (configEntry.getValidValues() != null && configEntry.getValidValues().length > 0) { this.listEntries.add(new CycleConfigEntry(configEntry)); continue; diff --git a/src/main/java/de/cowtipper/cowlection/listener/ChatListener.java b/src/main/java/de/cowtipper/cowlection/listener/ChatListener.java index 130c390..df1c673 100644 --- a/src/main/java/de/cowtipper/cowlection/listener/ChatListener.java +++ b/src/main/java/de/cowtipper/cowlection/listener/ChatListener.java @@ -128,7 +128,7 @@ public class ChatListener { @SubscribeEvent public void onReplyToMsg(GuiScreenEvent.KeyboardInputEvent.Pre e) { // TODO Switch to more reliable way: GuiTextField#writeText on GuiChat#inputField (protected field) via reflections [using "Open Command"-key isn't detected currently] - if (lastPMSender != null && e.gui instanceof GuiChat && lastTypedChars.length() < 3 && Keyboard.getEventKeyState()) { + if (MooConfig.fixReplyCmd && lastPMSender != null && e.gui instanceof GuiChat && lastTypedChars.length() < 3 && Keyboard.getEventKeyState()) { char eventCharacter = Keyboard.getEventCharacter(); if (!CharUtils.isAsciiControl(eventCharacter)) { lastTypedChars += eventCharacter; diff --git a/src/main/java/de/cowtipper/cowlection/listener/PlayerListener.java b/src/main/java/de/cowtipper/cowlection/listener/PlayerListener.java index b62782d..dcf3bbf 100644 --- a/src/main/java/de/cowtipper/cowlection/listener/PlayerListener.java +++ b/src/main/java/de/cowtipper/cowlection/listener/PlayerListener.java @@ -58,7 +58,7 @@ public class PlayerListener { @SubscribeEvent public void onKeyboardInput(GuiScreenEvent.KeyboardInputEvent.Pre e) { - if (Keyboard.getEventKeyState() && Keyboard.getEventKey() == Keyboard.KEY_C && GuiScreen.isCtrlKeyDown()) { + if (MooConfig.enableCopyInventory && Keyboard.getEventKeyState() && Keyboard.getEventKey() == Keyboard.KEY_C && GuiScreen.isCtrlKeyDown()) { // ctrl + C IInventory inventory; String inventoryName; |