mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-22 21:26:46 +01:00
Fixed /addlevels not working on offline players
Fixed /addlevels all throwing NPE because of Smelting Removed use of Users.getProfile()
This commit is contained in:
parent
ef775f1c24
commit
137864dc04
@ -21,6 +21,7 @@ Version 1.4.00-dev
|
||||
+ Added ability to config Hylian Luck drops through treasures.yml
|
||||
+ Added party XP sharing
|
||||
+ Added vanilla XP boost for Fishing - includes permissions, config options, etc
|
||||
= Fixed /addlevels not working properly on offline players
|
||||
= Fixed /mmoedit not giving feedback when modifying another players stats
|
||||
= Fixed the guide usage string showing up every time /skillname was called
|
||||
= Fixed Spout not being able to precache our resources properly, and therefore making our XP bars fail
|
||||
|
@ -1,13 +1,12 @@
|
||||
package com.gmail.nossr50.commands.general;
|
||||
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.commands.CommandHelper;
|
||||
import com.gmail.nossr50.datatypes.McMMOPlayer;
|
||||
import com.gmail.nossr50.datatypes.PlayerProfile;
|
||||
import com.gmail.nossr50.locale.LocaleLoader;
|
||||
import com.gmail.nossr50.skills.utilities.SkillTools;
|
||||
@ -19,7 +18,7 @@ import com.gmail.nossr50.util.Users;
|
||||
public class AddlevelsCommand implements CommandExecutor{
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
OfflinePlayer modifiedPlayer;
|
||||
Player player;
|
||||
PlayerProfile profile;
|
||||
int levels;
|
||||
SkillType skill;
|
||||
@ -38,10 +37,10 @@ public class AddlevelsCommand implements CommandExecutor{
|
||||
}
|
||||
|
||||
if (Misc.isInt(args[1])) {
|
||||
modifiedPlayer = (Player) sender;
|
||||
player = (Player) sender;
|
||||
levels = Integer.valueOf(args[1]);
|
||||
skill = SkillTools.getSkillType(args[0]);
|
||||
profile = Users.getProfile(modifiedPlayer);
|
||||
profile = Users.getPlayer(player).getProfile();
|
||||
|
||||
if (skill.equals(SkillType.ALL)) {
|
||||
sender.sendMessage(LocaleLoader.getString("Commands.addlevels.AwardAll.1", new Object[] {levels}));
|
||||
@ -64,44 +63,56 @@ public class AddlevelsCommand implements CommandExecutor{
|
||||
return true;
|
||||
}
|
||||
|
||||
modifiedPlayer = mcMMO.p.getServer().getOfflinePlayer(args[0]);
|
||||
profile = Users.getProfile(modifiedPlayer);
|
||||
|
||||
// TODO:Not sure if we actually need a null check here
|
||||
if (profile == null || !profile.isLoaded()) {
|
||||
sender.sendMessage(LocaleLoader.getString("Commands.DoesNotExist"));
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!SkillTools.isSkill(args[1])) {
|
||||
sender.sendMessage(LocaleLoader.getString("Commands.Skill.Invalid"));
|
||||
return true;
|
||||
}
|
||||
|
||||
if (Misc.isInt(args[2])) {
|
||||
levels = Integer.valueOf(args[2]);
|
||||
skill = SkillTools.getSkillType(args[1]);
|
||||
if (!Misc.isInt(args[2])) {
|
||||
sender.sendMessage(usage);
|
||||
return true;
|
||||
}
|
||||
|
||||
Users.getProfile(modifiedPlayer).addLevels(skill, levels);
|
||||
McMMOPlayer mcMMOPlayer = Users.getPlayer(args[0]);
|
||||
levels = Integer.valueOf(args[2]);
|
||||
skill = SkillTools.getSkillType(args[1]);
|
||||
|
||||
if (skill.equals(SkillType.ALL)) {
|
||||
sender.sendMessage(LocaleLoader.getString("Commands.addlevels.AwardAll.2", new Object[] {args[0]}));
|
||||
}
|
||||
else {
|
||||
sender.sendMessage(LocaleLoader.getString("Commands.addlevels.AwardSkill.2", new Object[] {Misc.getCapitalized(skill.toString()), args[0]}));
|
||||
// If the mcMMOPlayer doesn't exists, create a temporary profile and check if it's present in the database, if not abort the process
|
||||
if (mcMMOPlayer == null) {
|
||||
profile = new PlayerProfile(args[0], false);
|
||||
|
||||
if (!profile.isLoaded()) {
|
||||
sender.sendMessage(LocaleLoader.getString("Commands.DoesNotExist"));
|
||||
return true;
|
||||
}
|
||||
|
||||
if (modifiedPlayer.isOnline()) {
|
||||
if (skill.equals(SkillType.ALL)) {
|
||||
((Player) modifiedPlayer).sendMessage(LocaleLoader.getString("Commands.addlevels.AwardAll.1", new Object[] {levels}));
|
||||
}
|
||||
else {
|
||||
((Player) modifiedPlayer).sendMessage(LocaleLoader.getString("Commands.addlevels.AwardSkill.1", new Object[] {levels, Misc.getCapitalized(skill.toString())}));
|
||||
}
|
||||
}
|
||||
profile.addLevels(skill, levels);
|
||||
profile.save(); // Since this is a temporary profile, we save it here.
|
||||
}
|
||||
else {
|
||||
sender.sendMessage(usage);
|
||||
profile = mcMMOPlayer.getProfile();
|
||||
player = mcMMOPlayer.getPlayer();
|
||||
|
||||
profile.addLevels(skill, levels);
|
||||
|
||||
// This is actually not necessary but it can avoid a string building
|
||||
if (!player.isOnline()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (skill.equals(SkillType.ALL)) {
|
||||
player.sendMessage(LocaleLoader.getString("Commands.addlevels.AwardAll.1", new Object[] {levels}));
|
||||
}
|
||||
else {
|
||||
player.sendMessage(LocaleLoader.getString("Commands.addlevels.AwardSkill.1", new Object[] {levels, Misc.getCapitalized(skill.toString())}));
|
||||
}
|
||||
}
|
||||
|
||||
if (skill.equals(SkillType.ALL)) {
|
||||
sender.sendMessage(LocaleLoader.getString("Commands.addlevels.AwardAll.2", new Object[] {args[0]}));
|
||||
}
|
||||
else {
|
||||
sender.sendMessage(LocaleLoader.getString("Commands.addlevels.AwardSkill.2", new Object[] {Misc.getCapitalized(skill.toString()), args[0]}));
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -1111,9 +1111,9 @@ public class PlayerProfile {
|
||||
return;
|
||||
}
|
||||
|
||||
if (skillType.equals(SkillType.ALL)) {
|
||||
if (skillType == SkillType.ALL) {
|
||||
for (SkillType skill : SkillType.values()) {
|
||||
if (skill.equals(SkillType.ALL)) {
|
||||
if (skill == SkillType.ALL || skill.isChildSkill()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -144,6 +144,7 @@ public enum SkillType {
|
||||
return Users.getProfile(player).getSkillLevel(this);
|
||||
}
|
||||
|
||||
// TODO: This is a little "hacky", we probably need to add something to distinguish child skills in the enum, or to use another enum for them
|
||||
public boolean isChildSkill() {
|
||||
switch (this) {
|
||||
case SMELTING:
|
||||
|
Loading…
Reference in New Issue
Block a user