Skip to content

Commit

Permalink
Fix level setting so relog is not required
Browse files Browse the repository at this point in the history
  • Loading branch information
NotThorny committed Sep 20, 2022
1 parent 6128c6e commit be107ff
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 16 deletions.
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,10 @@ Place setLevel.jar into your `\grasscutter\plugins` folder and restart the serve

-Sets the level of all owned characters

**You must relog after using `/level all` for it to apply**

## Version

This uses the Grasscutters plugin template for 1.3.1.

## Issues

Promote level (max level within ascension) does not apply until relog.
I had it working and then it broke at some point and no amount of hours reverted fixed it, so now relog is required instead.
None yet.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import emu.grasscutter.database.DatabaseHelper;
import emu.grasscutter.game.avatar.Avatar;
import emu.grasscutter.game.player.Player;
import emu.grasscutter.server.packet.send.PacketAvatarAddNotify;
import emu.grasscutter.server.packet.send.PacketSceneEntityAppearNotify;
import emu.grasscutter.utils.Position;

Expand Down Expand Up @@ -58,11 +59,11 @@ public void teamLevel(Player sender, Player targetPlayer, List<String> args) {
int avatarId = entity.getAvatar().getAvatarId();
Avatar avatar = sender.getAvatars().getAvatarById(avatarId);
int level = Integer.parseInt(args.get(1));
int promoteLevel = Avatar.getMinPromoteLevel(level);
avatar.setPromoteLevel(promoteLevel);
avatar.setPromoteLevel(Avatar.getMinPromoteLevel(level));
avatar.setLevel(level);
avatar.recalcStats();
avatar.save();
sender.sendPacket(new PacketAvatarAddNotify(avatar,false));
});

reloadLevel(targetPlayer, scene, args);
Expand All @@ -76,11 +77,11 @@ private void setLevels(Player sender, Player targetPlayer, List<String> args) {
int level = Integer.parseInt(args.get(0));
if (level < 1) level = 1;
if (level > 90) level = 90;
int promoteLevel = Avatar.getMinPromoteLevel(level);
avatar.setPromoteLevel(promoteLevel);
avatar.setPromoteLevel(Avatar.getMinPromoteLevel(level));
avatar.setLevel(level);
avatar.recalcStats();
avatar.save();
sender.sendPacket(new PacketAvatarAddNotify(avatar,false));

reloadLevel(targetPlayer, scene, args);
}
Expand All @@ -93,11 +94,11 @@ public void allLevel(Player sender, Player targetPlayer, List<String> args) {
int avatarId = avatar.getAvatarId();
avatar = sender.getAvatars().getAvatarById(avatarId);
int level = Integer.parseInt(args.get(1));
int promoteLevel = Avatar.getMinPromoteLevel(level);
avatar.setPromoteLevel(promoteLevel);
avatar.setPromoteLevel(Avatar.getMinPromoteLevel(level));
avatar.setLevel(level);
avatar.recalcStats();
avatar.save();
sender.sendPacket(new PacketAvatarAddNotify(avatar,false));
}
reloadLevel(targetPlayer, scene, args);
}
Expand All @@ -111,16 +112,13 @@ public void reloadLevel(Player targetPlayer, int scene, List<String> args) {

switch (args.get(0)) {
case "all":
CommandHandler.sendMessage(targetPlayer, "Changed all character levels!"+
"\n*YOU MUST RELOG FOR ALL CHARACTER LEVELS TO APPLY*");
CommandHandler.sendMessage(targetPlayer, "Changed all character levels!");
break;
case "team":
CommandHandler.sendMessage(targetPlayer, "Changed team levels!"+
"\n*YOU MUST RELOG FOR PROMOTE LEVELS (MAX) TO APPLY*");
CommandHandler.sendMessage(targetPlayer, "Changed team levels!");
break;
default:
CommandHandler.sendMessage(targetPlayer, "Changed level!"+
"\n*YOU MUST RELOG FOR PROMOTE LEVEL (MAX) TO APPLY*");
CommandHandler.sendMessage(targetPlayer, "Changed level!");
}//switch
} catch (Exception e) {
CommandHandler.sendMessage(targetPlayer, "Failed to reload! Relog to apply changes.");
Expand Down

0 comments on commit be107ff

Please sign in to comment.