diff options
| author | Roman / Nea <roman.graef@gmail.com> | 2022-07-07 18:07:08 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-07-07 18:07:08 +0200 |
| commit | a2ad09ee13cee2ef70268336b9df41368574f45a (patch) | |
| tree | e813f2efc671941b8fe57c9b880aa5a2abb49c47 /src/main/java/io/github/moulberry/notenoughupdates/commands | |
| parent | 1ed053c9a8bbbbbe9b34c61fcdcc1a43d78118fd (diff) | |
| download | notenoughupdates-a2ad09ee13cee2ef70268336b9df41368574f45a.tar.gz notenoughupdates-a2ad09ee13cee2ef70268336b9df41368574f45a.tar.bz2 notenoughupdates-a2ad09ee13cee2ef70268336b9df41368574f45a.zip | |
Added a calculator (#180)
* Added a calculator
* Remove stuff
* also add t
* Update Misc.java
* On by default
* add x for multiplication, fixed - not working and quick math solver
Co-authored-by: nopo <noahogno@gmail.com>
Diffstat (limited to 'src/main/java/io/github/moulberry/notenoughupdates/commands')
3 files changed, 75 insertions, 0 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/commands/Commands.java b/src/main/java/io/github/moulberry/notenoughupdates/commands/Commands.java index 86411f4f..b152bc09 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/commands/Commands.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/commands/Commands.java @@ -37,6 +37,7 @@ import io.github.moulberry.notenoughupdates.commands.help.LinksCommand; import io.github.moulberry.notenoughupdates.commands.help.SettingsCommand; import io.github.moulberry.notenoughupdates.commands.help.StorageViewerWhyCommand; import io.github.moulberry.notenoughupdates.commands.misc.AhCommand; +import io.github.moulberry.notenoughupdates.commands.misc.CalculatorCommand; import io.github.moulberry.notenoughupdates.commands.misc.CalendarCommand; import io.github.moulberry.notenoughupdates.commands.misc.CosmeticsCommand; import io.github.moulberry.notenoughupdates.commands.misc.CustomizeCommand; @@ -91,6 +92,7 @@ public class Commands { ClientCommandHandler.instance.registerCommand(new ScreenCommand("neuoverlay", NEUOverlayPlacements::new)); //ClientCommandHandler.instance.registerCommand(new ScreenCommand("neututorial", NeuTutorial::new)); ClientCommandHandler.instance.registerCommand(new AhCommand()); + ClientCommandHandler.instance.registerCommand(new CalculatorCommand()); ClientCommandHandler.instance.registerCommand(new CalendarCommand()); // Fairy Soul Commands diff --git a/src/main/java/io/github/moulberry/notenoughupdates/commands/help/HelpCommand.java b/src/main/java/io/github/moulberry/notenoughupdates/commands/help/HelpCommand.java index ba49221e..a52fcd1d 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/commands/help/HelpCommand.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/commands/help/HelpCommand.java @@ -52,6 +52,7 @@ public class HelpCommand extends ClientCommandBase { "\u00a76/neuah \u00a7r\u00a77- Opens neu's custom ah GUI.", "\u00a76/neumap \u00a7r\u00a77- Opens the dungeon map GUI.", "\u00a76/neucalendar \u00a7r\u00a77- Opens neu's custom calendar GUI.", + "\u00a76/neucalc \u00a7r\u00a77- Run calculations.", "", "\u00a76\u00a7lOld commands:", "\u00a76/peek \u00a7b?{user} \u00a72\u2D35 \u00a7r\u00a77- Shows quickly stats for a user.", diff --git a/src/main/java/io/github/moulberry/notenoughupdates/commands/misc/CalculatorCommand.java b/src/main/java/io/github/moulberry/notenoughupdates/commands/misc/CalculatorCommand.java new file mode 100644 index 00000000..e73e3b32 --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/commands/misc/CalculatorCommand.java @@ -0,0 +1,72 @@ +/* + * Copyright (C) 2022 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * NotEnoughUpdates is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>. + */ + +package io.github.moulberry.notenoughupdates.commands.misc; + +import io.github.moulberry.notenoughupdates.commands.ClientCommandBase; +import io.github.moulberry.notenoughupdates.util.Calculator; +import net.minecraft.command.CommandException; +import net.minecraft.command.ICommandSender; +import net.minecraft.util.ChatComponentText; +import net.minecraft.util.EnumChatFormatting; + +import java.math.BigDecimal; +import java.util.Arrays; +import java.util.List; +import java.util.Objects; + +public class CalculatorCommand extends ClientCommandBase { + public CalculatorCommand() { + super("neucalc"); + } + + @Override + public List<String> getCommandAliases() { + return Arrays.asList("neucalculator"); + } + + @Override + public void processCommand(ICommandSender sender, String[] args) throws CommandException { + if ((args.length == 1 && Objects.equals(args[0], "help")) || args.length == 0) { + sender.addChatMessage(new ChatComponentText( + "\n§e[NEU] §5Its a calculator.\n" + + "§eFor Example §b/neucalc 3m*7k§e.\n" + + "§eYou can also use suffixes (k, m, b, t, s)§e.\n" + + "§eThe \"s\" suffix acts as 64.\n" + + "§eTurn on Sign Calculator in /neu misc to also support this in sign popups.\n")); + return; + } + String source = String.join(" ", args); + try { + BigDecimal calculate = Calculator.calculate(source); + sender.addChatMessage(new ChatComponentText( + EnumChatFormatting.YELLOW + "[NEU] " + EnumChatFormatting.WHITE + source + " = " + EnumChatFormatting.GREEN + + calculate.toPlainString() + )); + } catch (Calculator.CalculatorException e) { + sender.addChatMessage(new ChatComponentText( + EnumChatFormatting.YELLOW + "[NEU] " + EnumChatFormatting.RED + "Error during calculation: " + + e.getMessage() + "\n" + + EnumChatFormatting.WHITE + source.substring(0, e.getOffset()) + EnumChatFormatting.DARK_RED + + source.substring(e.getOffset(), e.getLength() + e.getOffset()) + EnumChatFormatting.GRAY + + source.substring(e.getLength() + e.getOffset()) + )); + } + } +} |
