mirror of
https://github.com/Melledy/LunarCore.git
synced 2025-12-13 05:44:36 +01:00
Auto set promotion level when directly setting levels with commands
This commit is contained in:
@@ -7,6 +7,7 @@ import emu.lunarcore.data.GameData;
|
||||
import emu.lunarcore.game.avatar.GameAvatar;
|
||||
import emu.lunarcore.game.player.Player;
|
||||
import emu.lunarcore.server.packet.send.PacketPlayerSyncScNotify;
|
||||
import emu.lunarcore.util.Utils;
|
||||
|
||||
@Command(label = "avatar", aliases = {"a"}, permission = "player.avatar", desc = "/avatar lv(level) p(ascension) r(eidolon) s(skill levels). Sets the current avatar's properties")
|
||||
public class AvatarCommand implements CommandHandler {
|
||||
@@ -37,6 +38,7 @@ public class AvatarCommand implements CommandHandler {
|
||||
// Try to set level
|
||||
if (args.getLevel() > 0) {
|
||||
avatar.setLevel(Math.min(args.getLevel(), 80));
|
||||
avatar.setPromotion(Utils.getMinPromotionForLevel(avatar.getLevel()));
|
||||
hasChanged = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -45,6 +45,7 @@ public class GiveCommand implements CommandHandler {
|
||||
// Try to set level
|
||||
if (args.getLevel() > 0) {
|
||||
avatar.setLevel(Math.min(args.getLevel(), 80));
|
||||
avatar.setPromotion(Utils.getMinPromotionForLevel(avatar.getLevel()));
|
||||
}
|
||||
|
||||
// Try to set promotion
|
||||
@@ -65,6 +66,7 @@ public class GiveCommand implements CommandHandler {
|
||||
// Try to set level
|
||||
if (args.getLevel() > 0) {
|
||||
item.setLevel(Math.min(args.getLevel(), 80));
|
||||
item.setPromotion(Utils.getMinPromotionForLevel(item.getLevel()));
|
||||
}
|
||||
|
||||
// Try to set promotion
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
package emu.lunarcore.util;
|
||||
|
||||
import java.io.File;
|
||||
import java.security.SecureRandom;
|
||||
import java.util.Base64;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
public class Utils {
|
||||
private static final SecureRandom secureRandom = new SecureRandom();
|
||||
private static final char[] HEX_ARRAY = "0123456789abcdef".toCharArray();
|
||||
|
||||
public static final Object EMPTY_OBJECT = new Object();
|
||||
@@ -77,15 +75,9 @@ public class Utils {
|
||||
public static long getCurrentSeconds() {
|
||||
return Math.floorDiv(System.currentTimeMillis(), 1000);
|
||||
}
|
||||
|
||||
public static byte[] generateRandomBytes(int length) {
|
||||
byte[] bytes = new byte[length];
|
||||
secureRandom.nextBytes(bytes);
|
||||
return bytes;
|
||||
}
|
||||
|
||||
public static String generateRandomString(int length) {
|
||||
return bytesToHex(generateRandomBytes(length));
|
||||
|
||||
public static int getMinPromotionForLevel(int level) {
|
||||
return Math.max(Math.min((int) ((level - 11) / 10D), 6), 0);
|
||||
}
|
||||
|
||||
public static int parseSafeInt(String s) {
|
||||
|
||||
Reference in New Issue
Block a user