-
Notifications
You must be signed in to change notification settings - Fork 216
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactored the command classes that adds stats #265
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,10 @@ | |
package client.command; | ||
|
||
import client.Client; | ||
import client.command.commands.gm0.AddDexCommand; | ||
import client.command.commands.gm0.AddIntCommand; | ||
import client.command.commands.gm0.AddLukCommand; | ||
import client.command.commands.gm0.AddStrCommand; | ||
import client.command.commands.gm0.ChangeLanguageCommand; | ||
import client.command.commands.gm0.DisposeCommand; | ||
import client.command.commands.gm0.DropLimitCommand; | ||
|
@@ -42,10 +46,8 @@ | |
import client.command.commands.gm0.ReportBugCommand; | ||
import client.command.commands.gm0.ShowRatesCommand; | ||
import client.command.commands.gm0.StaffCommand; | ||
import client.command.commands.gm0.StatDexCommand; | ||
import client.command.commands.gm0.StatIntCommand; | ||
import client.command.commands.gm0.StatLukCommand; | ||
import client.command.commands.gm0.StatStrCommand; | ||
import client.command.commands.gm0.TimeCommand; | ||
import client.command.commands.gm0.ToggleExpCommand; | ||
import client.command.commands.gm0.UptimeCommand; | ||
|
@@ -340,6 +342,10 @@ private void addCommand(String syntax, int rank, Class<? extends Command> comman | |
private void registerLv0Commands() { | ||
levelCommandsCursor = new Pair<>(new ArrayList<String>(), new ArrayList<String>()); | ||
|
||
addCommand("dex", AddDexCommand.class); | ||
addCommand("int", AddIntCommand.class); | ||
addCommand("luk", AddLukCommand.class); | ||
addCommand("str", AddStrCommand.class); | ||
addCommand(new String[]{"help", "commands"}, HelpCommand.class); | ||
addCommand("droplimit", DropLimitCommand.class); | ||
addCommand("time", TimeCommand.class); | ||
|
@@ -358,10 +364,10 @@ private void registerLv0Commands() { | |
addCommand("joinevent", JoinEventCommand.class); | ||
addCommand("leaveevent", LeaveEventCommand.class); | ||
addCommand("ranks", RanksCommand.class); | ||
addCommand("str", StatStrCommand.class); | ||
addCommand("dex", StatDexCommand.class); | ||
addCommand("int", StatIntCommand.class); | ||
addCommand("luk", StatLukCommand.class); | ||
//addCommand("str", StatStrCommand.class); | ||
//addCommand("dex", StatDexCommand.class); | ||
//addCommand("int", StatIntCommand.class); | ||
//addCommand("luk", StatLukCommand.class); | ||
Comment on lines
+367
to
+370
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove these comments and delete the old commands since they are useless now. |
||
addCommand("enableauth", EnableAuthCommand.class); | ||
addCommand("toggleexp", ToggleExpCommand.class); | ||
addCommand("mylawn", MapOwnerClaimCommand.class); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package client.command; | ||
|
||
import client.Character; | ||
import client.Client; | ||
import config.YamlConfig; | ||
|
||
public abstract class StatCommand extends Command { | ||
|
||
protected enum Stat {DEX, INT, LUK, STR} | ||
protected Stat stat; | ||
|
||
public void execute(Client c, String[] params) { | ||
AssignStat(c, params, stat); | ||
} | ||
|
||
private void AssignStat(Client client, String[] params, Stat stat) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. camelCase method name is Java standard |
||
{ | ||
Character character = client.getPlayer(); | ||
if (params.length < 1) { | ||
character.dropMessage("Enter an amount of AP you want to assign."); | ||
} | ||
try { | ||
int amount = Integer.parseInt(params[0]); | ||
int remainingAp = character.getRemainingAp(); | ||
if (isValidAmount(amount, remainingAp)) { | ||
switch (stat) { | ||
case DEX -> character.assignDex(amount); | ||
case INT -> character.assignInt(amount); | ||
case LUK -> character.assignLuk(amount); | ||
case STR -> character.assignStr(amount); | ||
default -> throw new IllegalStateException("Unexpected value: " + stat); | ||
} | ||
character.dropMessage("Assigned " + amount + " into " + stat); | ||
} | ||
else { | ||
character.dropMessage("You have entered an invalid amount of AP."); | ||
} | ||
} | ||
catch (NumberFormatException ex) { | ||
character.dropMessage("Enter a valid number!"); | ||
} | ||
} | ||
private boolean isValidAmount(int amount, int remainingAp) { | ||
return amount > 0 | ||
&& amount <= remainingAp | ||
&& amount <= YamlConfig.config.server.MAX_AP; | ||
} | ||
|
||
protected void setStat(Stat stat) { | ||
this.stat = stat; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package client.command.commands.gm0; | ||
|
||
import client.Client; | ||
import client.command.StatCommand; | ||
|
||
public class AddDexCommand extends StatCommand { | ||
|
||
{ | ||
setStat(Stat.DEX); | ||
setDescription("Assigns AP into " + stat); | ||
} | ||
|
||
@Override | ||
public void execute(Client client, String[] params) { | ||
super.execute(client, params); | ||
} | ||
Comment on lines
+13
to
+16
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the point of these 4 identical |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package client.command.commands.gm0; | ||
|
||
import client.Client; | ||
import client.command.StatCommand; | ||
|
||
public class AddIntCommand extends StatCommand { | ||
|
||
{ | ||
setStat(Stat.INT); | ||
setDescription("Assigns AP into " + stat); | ||
} | ||
|
||
@Override | ||
public void execute(Client client, String[] params) { | ||
super.execute(client, params); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package client.command.commands.gm0; | ||
|
||
import client.Client; | ||
import client.command.StatCommand; | ||
|
||
public class AddLukCommand extends StatCommand { | ||
|
||
{ | ||
setStat(Stat.LUK); | ||
setDescription("Assigns AP into " + stat); | ||
} | ||
|
||
@Override | ||
public void execute(Client client, String[] params) { | ||
super.execute(client, params); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package client.command.commands.gm0; | ||
|
||
import client.Client; | ||
import client.command.StatCommand; | ||
|
||
public class AddStrCommand extends StatCommand { | ||
|
||
{ | ||
setStat(Stat.STR); | ||
setDescription("Assigns AP into " + stat); | ||
} | ||
|
||
@Override | ||
public void execute(Client client, String[] params) { | ||
super.execute(client, params); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to commit your own changes to
config.yaml
. Please revert all the changes to this file.