mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-23 05:36:46 +01:00
Fixed NPE with /mmoedit
This commit is contained in:
parent
89b5f8c275
commit
050b794b42
@ -7,7 +7,6 @@ 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.PlayerProfile;
|
||||
import com.gmail.nossr50.datatypes.SkillType;
|
||||
@ -17,16 +16,10 @@ import com.gmail.nossr50.util.Skills;
|
||||
import com.gmail.nossr50.util.Users;
|
||||
|
||||
public class MmoeditCommand implements CommandExecutor {
|
||||
private final mcMMO plugin;
|
||||
|
||||
public MmoeditCommand (mcMMO plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
OfflinePlayer modifiedPlayer;
|
||||
PlayerProfile PP;
|
||||
PlayerProfile playerProfile;
|
||||
int newValue;
|
||||
SkillType skill;
|
||||
String skillName;
|
||||
@ -48,7 +41,7 @@ public class MmoeditCommand implements CommandExecutor {
|
||||
modifiedPlayer = (Player) sender;
|
||||
newValue = Integer.valueOf(args[1]);
|
||||
skill = Skills.getSkillType(args[0]);
|
||||
PP = Users.getProfile(modifiedPlayer);
|
||||
playerProfile = Users.getProfile(modifiedPlayer);
|
||||
|
||||
if (skill.equals(SkillType.ALL)) {
|
||||
skillName = "all skills";
|
||||
@ -57,7 +50,7 @@ public class MmoeditCommand implements CommandExecutor {
|
||||
skillName = Misc.getCapitalized(skill.toString());
|
||||
}
|
||||
|
||||
PP.modifySkill(skill, newValue);
|
||||
playerProfile.modifySkill(skill, newValue);
|
||||
sender.sendMessage(ChatColor.GREEN + "Your level in " + skillName + " was set to " + newValue + "!"); //TODO: Needs more locale.
|
||||
}
|
||||
else {
|
||||
@ -71,46 +64,47 @@ public class MmoeditCommand implements CommandExecutor {
|
||||
return true;
|
||||
|
||||
case 3:
|
||||
modifiedPlayer = plugin.getServer().getOfflinePlayer(args[0]);
|
||||
String playerName = modifiedPlayer.getName();
|
||||
PP = Users.getProfile(modifiedPlayer);
|
||||
|
||||
if (!PP.isLoaded()) {
|
||||
sender.sendMessage(LocaleLoader.getString("Commands.DoesNotExist"));
|
||||
if (!Misc.isInt(args[2])) {
|
||||
sender.sendMessage(usage);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!Skills.isSkill(args[1])) {
|
||||
skill = Skills.getSkillType(args[1]);
|
||||
|
||||
if (skill == null) {
|
||||
sender.sendMessage(LocaleLoader.getString("Commands.Skill.Invalid"));
|
||||
return true;
|
||||
}
|
||||
|
||||
if (Misc.isInt(args[2])) {
|
||||
newValue = Integer.valueOf(args[2]);
|
||||
skill = Skills.getSkillType(args[1]);
|
||||
String message;
|
||||
if (skill.equals(SkillType.ALL)) {
|
||||
skillName = "all skills";
|
||||
}
|
||||
else {
|
||||
skillName = Misc.getCapitalized(skill.toString());
|
||||
}
|
||||
|
||||
Users.getProfile(modifiedPlayer).modifySkill(skill, newValue);
|
||||
newValue = Integer.valueOf(args[2]);
|
||||
playerProfile = Users.getProfile(args[0]);
|
||||
|
||||
if (skill.equals(SkillType.ALL)) {
|
||||
skillName = "all skills";
|
||||
message = ChatColor.RED + "All skills have been modified for " + playerName + "."; //TODO: Use locale
|
||||
}
|
||||
else {
|
||||
skillName = Misc.getCapitalized(skill.toString());
|
||||
message = ChatColor.RED + skillName + " has been modified for " + playerName + "."; //TODO: Use locale
|
||||
}
|
||||
if (playerProfile != null) {
|
||||
Player player = playerProfile.getPlayer();
|
||||
|
||||
sender.sendMessage(message);
|
||||
|
||||
if (modifiedPlayer.isOnline()) {
|
||||
((Player) modifiedPlayer).sendMessage(ChatColor.GREEN + "Your level in " + skillName + " was set to " + newValue + "!"); //TODO: Needs more locale.
|
||||
if (player.isOnline()) {
|
||||
player.sendMessage(ChatColor.GREEN + "Your level in " + skillName + " was set to " + newValue + "!"); //TODO: Needs more locale.
|
||||
}
|
||||
}
|
||||
else {
|
||||
sender.sendMessage(usage);
|
||||
playerProfile = new PlayerProfile(null, args[0], false);
|
||||
|
||||
if (!playerProfile.isLoaded()) {
|
||||
sender.sendMessage(LocaleLoader.getString("Commands.DoesNotExist"));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
sender.sendMessage(ChatColor.RED + skillName + " has been modified for " + args[0] + "."); //TODO: Use locale
|
||||
playerProfile.modifySkill(skill, newValue);
|
||||
playerProfile.save();
|
||||
return true;
|
||||
|
||||
default:
|
||||
|
@ -63,10 +63,10 @@ public class PlayerProfile {
|
||||
private String playerName;
|
||||
private final static String location = mcMMO.usersFile;
|
||||
|
||||
public PlayerProfile(Player player, boolean addNew) {
|
||||
public PlayerProfile(Player player, String playerName, boolean addNew) {
|
||||
hud = SpoutConfig.getInstance().defaulthud;
|
||||
this.player = player;
|
||||
this.playerName = player.getName();
|
||||
this.playerName = playerName;
|
||||
|
||||
party = PartyManager.getInstance().getPlayerParty(playerName);
|
||||
|
||||
@ -109,7 +109,7 @@ public class PlayerProfile {
|
||||
public boolean loadMySQL() {
|
||||
userid = mcMMO.database.getInt("SELECT id FROM " + Config.getInstance().getMySQLTablePrefix() + "users WHERE user = '" + playerName + "'");
|
||||
|
||||
if (userid <= 0) {
|
||||
if (userid == 0) {
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
@ -1067,8 +1067,6 @@ public class PlayerProfile {
|
||||
skills.put(skillType, newValue);
|
||||
skillsXp.put(skillType, 0);
|
||||
}
|
||||
|
||||
save();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -396,7 +396,7 @@ public class mcMMO extends JavaPlugin {
|
||||
}
|
||||
|
||||
if (configInstance.getCommandMmoeditEnabled()) {
|
||||
getCommand("mmoedit").setExecutor(new MmoeditCommand(this));
|
||||
getCommand("mmoedit").setExecutor(new MmoeditCommand());
|
||||
}
|
||||
|
||||
if (configInstance.getCommandInspectEnabled()) {
|
||||
|
@ -56,7 +56,7 @@ public class Users {
|
||||
}
|
||||
|
||||
//New player, or already removed from the list
|
||||
PlayerProfile playerProfile = new PlayerProfile(player, true);
|
||||
PlayerProfile playerProfile = new PlayerProfile(player, playerName, true);
|
||||
|
||||
profiles.add(playerProfile);
|
||||
return playerProfile;
|
||||
@ -78,29 +78,6 @@ public class Users {
|
||||
return profiles;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a user from the database.
|
||||
*
|
||||
* @param player The player to remove
|
||||
*/
|
||||
public static void removeUser(OfflinePlayer player) {
|
||||
removeUser(player.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a user from the DB by name.
|
||||
*
|
||||
* @param playerName The name of the player to remove
|
||||
*/
|
||||
public static void removeUser(String playerName) {
|
||||
for (Iterator<PlayerProfile> it = profiles.iterator() ; it.hasNext() ; ) {
|
||||
if (it.next().getPlayerName().equals(playerName)) {
|
||||
it.remove();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the profile of a player.
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user