js802025 / calcmod

Calculator Mod

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Code duplication in command registering classes

kikugie opened this issue · comments

First of all, commands/CalcServerCommand.java and calcmod/commands/CalcCommand.java are same, except for registering on client and server. I'm not yet too experienced with how would you do this with fabric exactly, but general suggestion is to move calculation handling in a separate class. Then have command registering done with a loop given more compact data and removing redundant code.
Some more exact suggestions:

  • In getParsedExpression() put parsed exception into a variable at the start and replace all replaceAll calls with looping over a map.
  • executeHelp messages could also be put in a map to avoid if-spam

Write DRY code!

im not sure how to do the command registration loop but ill work on the others.

A place where you can look at can be clientcommands. Each command functionality is separated in its own class and you just register those. Also commands can be grouped into one with secondary argument dedicated for choosing them. (For example /calcutil sbToItem ....

thx