mirror of
https://github.com/Melledy/LunarCore.git
synced 2025-12-16 15:24:44 +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.avatar.GameAvatar;
|
||||||
import emu.lunarcore.game.player.Player;
|
import emu.lunarcore.game.player.Player;
|
||||||
import emu.lunarcore.server.packet.send.PacketPlayerSyncScNotify;
|
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")
|
@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 {
|
public class AvatarCommand implements CommandHandler {
|
||||||
@@ -37,6 +38,7 @@ public class AvatarCommand implements CommandHandler {
|
|||||||
// Try to set level
|
// Try to set level
|
||||||
if (args.getLevel() > 0) {
|
if (args.getLevel() > 0) {
|
||||||
avatar.setLevel(Math.min(args.getLevel(), 80));
|
avatar.setLevel(Math.min(args.getLevel(), 80));
|
||||||
|
avatar.setPromotion(Utils.getMinPromotionForLevel(avatar.getLevel()));
|
||||||
hasChanged = true;
|
hasChanged = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ public class GiveCommand implements CommandHandler {
|
|||||||
// Try to set level
|
// Try to set level
|
||||||
if (args.getLevel() > 0) {
|
if (args.getLevel() > 0) {
|
||||||
avatar.setLevel(Math.min(args.getLevel(), 80));
|
avatar.setLevel(Math.min(args.getLevel(), 80));
|
||||||
|
avatar.setPromotion(Utils.getMinPromotionForLevel(avatar.getLevel()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try to set promotion
|
// Try to set promotion
|
||||||
@@ -65,6 +66,7 @@ public class GiveCommand implements CommandHandler {
|
|||||||
// Try to set level
|
// Try to set level
|
||||||
if (args.getLevel() > 0) {
|
if (args.getLevel() > 0) {
|
||||||
item.setLevel(Math.min(args.getLevel(), 80));
|
item.setLevel(Math.min(args.getLevel(), 80));
|
||||||
|
item.setPromotion(Utils.getMinPromotionForLevel(item.getLevel()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try to set promotion
|
// Try to set promotion
|
||||||
|
|||||||
@@ -1,13 +1,11 @@
|
|||||||
package emu.lunarcore.util;
|
package emu.lunarcore.util;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.security.SecureRandom;
|
|
||||||
import java.util.Base64;
|
import java.util.Base64;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.ThreadLocalRandom;
|
import java.util.concurrent.ThreadLocalRandom;
|
||||||
|
|
||||||
public class Utils {
|
public class Utils {
|
||||||
private static final SecureRandom secureRandom = new SecureRandom();
|
|
||||||
private static final char[] HEX_ARRAY = "0123456789abcdef".toCharArray();
|
private static final char[] HEX_ARRAY = "0123456789abcdef".toCharArray();
|
||||||
|
|
||||||
public static final Object EMPTY_OBJECT = new Object();
|
public static final Object EMPTY_OBJECT = new Object();
|
||||||
@@ -78,14 +76,8 @@ public class Utils {
|
|||||||
return Math.floorDiv(System.currentTimeMillis(), 1000);
|
return Math.floorDiv(System.currentTimeMillis(), 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static byte[] generateRandomBytes(int length) {
|
public static int getMinPromotionForLevel(int level) {
|
||||||
byte[] bytes = new byte[length];
|
return Math.max(Math.min((int) ((level - 11) / 10D), 6), 0);
|
||||||
secureRandom.nextBytes(bytes);
|
|
||||||
return bytes;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String generateRandomString(int length) {
|
|
||||||
return bytesToHex(generateRandomBytes(length));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int parseSafeInt(String s) {
|
public static int parseSafeInt(String s) {
|
||||||
|
|||||||
Reference in New Issue
Block a user