mirror of
https://github.com/Melledy/LunarCore.git
synced 2025-12-13 05:44:36 +01:00
Add /lineup command
This commit is contained in:
@@ -0,0 +1,64 @@
|
|||||||
|
package emu.lunarcore.command.commands;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import emu.lunarcore.command.Command;
|
||||||
|
import emu.lunarcore.command.CommandArgs;
|
||||||
|
import emu.lunarcore.command.CommandHandler;
|
||||||
|
import emu.lunarcore.game.avatar.GameAvatar;
|
||||||
|
import emu.lunarcore.game.player.Player;
|
||||||
|
import emu.lunarcore.game.player.lineup.PlayerLineup;
|
||||||
|
import emu.lunarcore.util.Utils;
|
||||||
|
|
||||||
|
@Command(label = "lineup", permission = "player.lineup", requireTarget = true, desc = "/lineup [avatar ids]. USE AT YOUR OWN RISK. Sets your current lineup with the specified avatar ids.")
|
||||||
|
public class LineupCommand implements CommandHandler {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(Player sender, CommandArgs args) {
|
||||||
|
// Get target player
|
||||||
|
Player target = args.getTarget();
|
||||||
|
|
||||||
|
// Do not set lineup while the target player is in a battle
|
||||||
|
if (target.isInBattle()) {
|
||||||
|
this.sendMessage(sender, "Error: The targeted player is in a battle");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Temp avatar list
|
||||||
|
List<Integer> avatars = new ArrayList<>();
|
||||||
|
|
||||||
|
// Validate avatars in temp list
|
||||||
|
for (String arg : args.getList()) {
|
||||||
|
// Make sure the avatar actually exist
|
||||||
|
GameAvatar avatar = target.getAvatarById(Utils.parseSafeInt(arg));
|
||||||
|
if (avatar == null) continue;
|
||||||
|
|
||||||
|
avatars.add(avatar.getAvatarId());
|
||||||
|
|
||||||
|
// Soft cap check
|
||||||
|
if (avatars.size() >= 64) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Replace cleanly
|
||||||
|
if (avatars.size() > 0) {
|
||||||
|
// Only replace lineup if we have avatars to replace with
|
||||||
|
// The client wont like it if we have a lineup with 0 avatars.
|
||||||
|
PlayerLineup lineup = target.getCurrentLineup();
|
||||||
|
lineup.getAvatars().clear();
|
||||||
|
lineup.getAvatars().addAll(avatars);
|
||||||
|
lineup.save();
|
||||||
|
|
||||||
|
// Send client packets to sync lineup
|
||||||
|
lineup.refreshLineup();
|
||||||
|
target.getScene().syncLineup();
|
||||||
|
|
||||||
|
this.sendMessage(sender, "Set the lineup of " + target.getName() + " successfully");
|
||||||
|
} else {
|
||||||
|
this.sendMessage(sender, "No avatars could be added");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -47,7 +47,7 @@ public class GameAvatar implements GameEntity {
|
|||||||
private transient Player owner;
|
private transient Player owner;
|
||||||
private transient AvatarExcel excel;
|
private transient AvatarExcel excel;
|
||||||
|
|
||||||
private int avatarId; // Id of avatar
|
private int avatarId; // Id of avatar in the excels
|
||||||
private AvatarData data;
|
private AvatarData data;
|
||||||
@Setter private int level;
|
@Setter private int level;
|
||||||
@Setter private int exp;
|
@Setter private int exp;
|
||||||
|
|||||||
@@ -83,6 +83,9 @@ public class Utils {
|
|||||||
return Math.max(Math.min((int) ((level - 11) / 10D), 6), 0);
|
return Math.max(Math.min((int) ((level - 11) / 10D), 6), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses the string argument as a signed decimal integer. Returns a 0 if the string argument is not an integer.
|
||||||
|
*/
|
||||||
public static int parseSafeInt(String s) {
|
public static int parseSafeInt(String s) {
|
||||||
if (s == null) {
|
if (s == null) {
|
||||||
return 0;
|
return 0;
|
||||||
@@ -99,6 +102,9 @@ public class Utils {
|
|||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses the string argument as a signed decimal long. Returns a 0 if the string argument is not a long.
|
||||||
|
*/
|
||||||
public static long parseSafeLong(String s) {
|
public static long parseSafeLong(String s) {
|
||||||
if (s == null) {
|
if (s == null) {
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user