Calc

Calc

27.1k Downloads

Code duplication in command registering classes

kikugie opened this issue ยท 3 comments

commented

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!

commented

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 ....

commented

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

commented

thx