Commit 69cb03f4 authored by KingRainbow44's avatar KingRainbow44
Browse files

Command reformat

parent 2572d55c
...@@ -185,38 +185,29 @@ public final class PlayerCommands { ...@@ -185,38 +185,29 @@ public final class PlayerCommands {
} }
} }
@Command(label = "givechar", aliases = { "givec" }, usage = "Usage: givechar <playerId> <avatarId> [level]") @Command(label = "givechar", aliases = {"givec"},
usage = "Usage: givechar <player|avatarId> [avatarId] [level]")
public static class GiveCharCommand implements CommandHandler { public static class GiveCharCommand implements CommandHandler {
@Override public void execute(GenshinPlayer player, List<String> args) { @Override public void execute(GenshinPlayer player, List<String> args) {
int target, avatarID, level = 1, ascension = 1; int target, avatarId, level = 1, ascension = 1;
if(args.size() < 2) { if(args.size() < 2) {
CommandHandler.sendMessage(null, "Usage: givechar <player> <avatarId> [level]"); CommandHandler.sendMessage(player, "Usage: givechar <player> <avatarId> [level]");
return; return;
} }
switch(args.size()) { switch(args.size()) {
default: default:
CommandHandler.sendMessage(null, "Usage: givechar <player> <avatarId> [level]"); CommandHandler.sendMessage(player, "Usage: givechar <player> <avatarId> [level]");
return; return;
case 1:
try {
avatarID = Integer.parseInt(args.get(0));
target = player.getAccount().getPlayerId();
} catch (NumberFormatException ignored) {
// TODO: Parse from avatar name using GM Handbook.
CommandHandler.sendMessage(player, "Invalid avatar id.");
return;
}
break;
case 2: case 2:
try { try {
target = Integer.parseInt(args.get(0)); target = Integer.parseInt(args.get(0));
if(Grasscutter.getGameServer().getPlayerByUid(target) == null) { if(Grasscutter.getGameServer().getPlayerByUid(target) == null) {
target = player.getUid(); level = Integer.parseInt(args.get(1)); target = player.getUid(); level = Integer.parseInt(args.get(1));
avatarID = Integer.parseInt(args.get(0)); avatarId = Integer.parseInt(args.get(0));
} else { } else {
avatarID = Integer.parseInt(args.get(1)); avatarId = Integer.parseInt(args.get(1));
} }
} catch (NumberFormatException ignored) { } catch (NumberFormatException ignored) {
// TODO: Parse from avatar name using GM Handbook. // TODO: Parse from avatar name using GM Handbook.
...@@ -231,7 +222,7 @@ public final class PlayerCommands { ...@@ -231,7 +222,7 @@ public final class PlayerCommands {
CommandHandler.sendMessage(player, "Invalid player ID."); return; CommandHandler.sendMessage(player, "Invalid player ID."); return;
} }
avatarID = Integer.parseInt(args.get(1)); avatarId = Integer.parseInt(args.get(1));
level = Integer.parseInt(args.get(2)); level = Integer.parseInt(args.get(2));
} catch (NumberFormatException ignored) { } catch (NumberFormatException ignored) {
// TODO: Parse from avatar name using GM Handbook. // TODO: Parse from avatar name using GM Handbook.
...@@ -243,22 +234,22 @@ public final class PlayerCommands { ...@@ -243,22 +234,22 @@ public final class PlayerCommands {
GenshinPlayer targetPlayer = Grasscutter.getGameServer().getPlayerByUid(target); GenshinPlayer targetPlayer = Grasscutter.getGameServer().getPlayerByUid(target);
if(targetPlayer == null) { if(targetPlayer == null) {
CommandHandler.sendMessage(null, "Player not found."); return; CommandHandler.sendMessage(player, "Player not found."); return;
} }
AvatarData avatarData = GenshinData.getAvatarDataMap().get(avatarID); AvatarData avatarData = GenshinData.getAvatarDataMap().get(avatarId);
if(avatarData == null) { if(avatarData == null) {
CommandHandler.sendMessage(null, "Invalid avatar id."); return; CommandHandler.sendMessage(player, "Invalid avatar id."); return;
} }
// Calculate ascension level. // Calculate ascension level.
if (level <= 40) { if (level <= 40) {
ascension = (int)Math.ceil(level / 20); ascension = (int) Math.ceil(level / 20f);
} else if (level > 20) { } else {
ascension = (int)Math.ceil(level / 10) - 3; ascension = (int) Math.ceil(level / 10f) - 3;
} }
GenshinAvatar avatar = new GenshinAvatar(avatarID); GenshinAvatar avatar = new GenshinAvatar(avatarId);
avatar.setLevel(level); avatar.setLevel(level);
avatar.setPromoteLevel(ascension); avatar.setPromoteLevel(ascension);
...@@ -279,7 +270,7 @@ public final class PlayerCommands { ...@@ -279,7 +270,7 @@ public final class PlayerCommands {
int target = Integer.parseInt(args.get(0)); int target = Integer.parseInt(args.get(0));
int avatarID = Integer.parseInt(args.get(1)); int avatarID = Integer.parseInt(args.get(1));
int level = 1; if(args.size() > 2) level = Integer.parseInt(args.get(2)); int level = 1; if(args.size() > 2) level = Integer.parseInt(args.get(2));
int ascension = 1; int ascension;
GenshinPlayer targetPlayer = Grasscutter.getGameServer().getPlayerByUid(target); GenshinPlayer targetPlayer = Grasscutter.getGameServer().getPlayerByUid(target);
if(targetPlayer == null) { if(targetPlayer == null) {
...@@ -293,9 +284,9 @@ public final class PlayerCommands { ...@@ -293,9 +284,9 @@ public final class PlayerCommands {
// Calculate ascension level. // Calculate ascension level.
if (level <= 40) { if (level <= 40) {
ascension = (int)Math.ceil(level / 20); ascension = (int) Math.ceil(level / 20f);
} else if (level > 20) { } else {
ascension = (int)Math.ceil(level / 10) - 3; ascension = (int) Math.ceil(level / 10f) - 3;
} }
GenshinAvatar avatar = new GenshinAvatar(avatarID); GenshinAvatar avatar = new GenshinAvatar(avatarID);
...@@ -461,7 +452,7 @@ public final class PlayerCommands { ...@@ -461,7 +452,7 @@ public final class PlayerCommands {
@Override @Override
public void execute(GenshinPlayer player, List<String> args) { public void execute(GenshinPlayer player, List<String> args) {
if(args.size() < 1) { if(args.size() < 1) {
CommandHandler.sendMessage(null, "Usage: setworldlevel <level>"); return; CommandHandler.sendMessage(player, "Usage: setworldlevel <level>"); return;
} }
try { try {
...@@ -498,22 +489,19 @@ public final class PlayerCommands { ...@@ -498,22 +489,19 @@ public final class PlayerCommands {
@Override @Override
public void execute(GenshinPlayer player, List<String> args) { public void execute(GenshinPlayer player, List<String> args) {
if(args.size() < 1) { if(args.size() < 1) {
CommandHandler.sendMessage(null, "Usage: changescene <scene id>"); return; CommandHandler.sendMessage(player, "Usage: changescene <scene id>"); return;
} }
int sceneId = 0;
try { try {
sceneId = Integer.parseInt(args.get(0)); int sceneId = Integer.parseInt(args.get(0));
} catch (Exception e) {
return;
}
boolean result = player.getWorld().transferPlayerToScene(player, sceneId, player.getPos()); boolean result = player.getWorld().transferPlayerToScene(player, sceneId, player.getPos());
if (!result) { if (!result) {
CommandHandler.sendMessage(null, "Scene does not exist or you are already in it"); CommandHandler.sendMessage(null, "Scene does not exist or you are already in it");
} }
} catch (Exception e) {
CommandHandler.sendMessage(player, "Usage: changescene <scene id>"); return;
}
} }
} }
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment