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.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import com.gmail.nossr50.mcMMO;
|
|
||||||
import com.gmail.nossr50.commands.CommandHelper;
|
import com.gmail.nossr50.commands.CommandHelper;
|
||||||
import com.gmail.nossr50.datatypes.PlayerProfile;
|
import com.gmail.nossr50.datatypes.PlayerProfile;
|
||||||
import com.gmail.nossr50.datatypes.SkillType;
|
import com.gmail.nossr50.datatypes.SkillType;
|
||||||
@ -17,16 +16,10 @@ import com.gmail.nossr50.util.Skills;
|
|||||||
import com.gmail.nossr50.util.Users;
|
import com.gmail.nossr50.util.Users;
|
||||||
|
|
||||||
public class MmoeditCommand implements CommandExecutor {
|
public class MmoeditCommand implements CommandExecutor {
|
||||||
private final mcMMO plugin;
|
|
||||||
|
|
||||||
public MmoeditCommand (mcMMO plugin) {
|
|
||||||
this.plugin = plugin;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||||
OfflinePlayer modifiedPlayer;
|
OfflinePlayer modifiedPlayer;
|
||||||
PlayerProfile PP;
|
PlayerProfile playerProfile;
|
||||||
int newValue;
|
int newValue;
|
||||||
SkillType skill;
|
SkillType skill;
|
||||||
String skillName;
|
String skillName;
|
||||||
@ -48,7 +41,7 @@ public class MmoeditCommand implements CommandExecutor {
|
|||||||
modifiedPlayer = (Player) sender;
|
modifiedPlayer = (Player) sender;
|
||||||
newValue = Integer.valueOf(args[1]);
|
newValue = Integer.valueOf(args[1]);
|
||||||
skill = Skills.getSkillType(args[0]);
|
skill = Skills.getSkillType(args[0]);
|
||||||
PP = Users.getProfile(modifiedPlayer);
|
playerProfile = Users.getProfile(modifiedPlayer);
|
||||||
|
|
||||||
if (skill.equals(SkillType.ALL)) {
|
if (skill.equals(SkillType.ALL)) {
|
||||||
skillName = "all skills";
|
skillName = "all skills";
|
||||||
@ -57,7 +50,7 @@ public class MmoeditCommand implements CommandExecutor {
|
|||||||
skillName = Misc.getCapitalized(skill.toString());
|
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.
|
sender.sendMessage(ChatColor.GREEN + "Your level in " + skillName + " was set to " + newValue + "!"); //TODO: Needs more locale.
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -71,46 +64,47 @@ public class MmoeditCommand implements CommandExecutor {
|
|||||||
return true;
|
return true;
|
||||||
|
|
||||||
case 3:
|
case 3:
|
||||||
modifiedPlayer = plugin.getServer().getOfflinePlayer(args[0]);
|
if (!Misc.isInt(args[2])) {
|
||||||
String playerName = modifiedPlayer.getName();
|
sender.sendMessage(usage);
|
||||||
PP = Users.getProfile(modifiedPlayer);
|
|
||||||
|
|
||||||
if (!PP.isLoaded()) {
|
|
||||||
sender.sendMessage(LocaleLoader.getString("Commands.DoesNotExist"));
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Skills.isSkill(args[1])) {
|
skill = Skills.getSkillType(args[1]);
|
||||||
|
|
||||||
|
if (skill == null) {
|
||||||
sender.sendMessage(LocaleLoader.getString("Commands.Skill.Invalid"));
|
sender.sendMessage(LocaleLoader.getString("Commands.Skill.Invalid"));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Misc.isInt(args[2])) {
|
if (skill.equals(SkillType.ALL)) {
|
||||||
newValue = Integer.valueOf(args[2]);
|
skillName = "all skills";
|
||||||
skill = Skills.getSkillType(args[1]);
|
}
|
||||||
String message;
|
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)) {
|
if (playerProfile != null) {
|
||||||
skillName = "all skills";
|
Player player = playerProfile.getPlayer();
|
||||||
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
|
|
||||||
}
|
|
||||||
|
|
||||||
sender.sendMessage(message);
|
if (player.isOnline()) {
|
||||||
|
player.sendMessage(ChatColor.GREEN + "Your level in " + skillName + " was set to " + newValue + "!"); //TODO: Needs more locale.
|
||||||
if (modifiedPlayer.isOnline()) {
|
|
||||||
((Player) modifiedPlayer).sendMessage(ChatColor.GREEN + "Your level in " + skillName + " was set to " + newValue + "!"); //TODO: Needs more locale.
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
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;
|
return true;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -63,10 +63,10 @@ public class PlayerProfile {
|
|||||||
private String playerName;
|
private String playerName;
|
||||||
private final static String location = mcMMO.usersFile;
|
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;
|
hud = SpoutConfig.getInstance().defaulthud;
|
||||||
this.player = player;
|
this.player = player;
|
||||||
this.playerName = player.getName();
|
this.playerName = playerName;
|
||||||
|
|
||||||
party = PartyManager.getInstance().getPlayerParty(playerName);
|
party = PartyManager.getInstance().getPlayerParty(playerName);
|
||||||
|
|
||||||
@ -109,7 +109,7 @@ public class PlayerProfile {
|
|||||||
public boolean loadMySQL() {
|
public boolean loadMySQL() {
|
||||||
userid = mcMMO.database.getInt("SELECT id FROM " + Config.getInstance().getMySQLTablePrefix() + "users WHERE user = '" + playerName + "'");
|
userid = mcMMO.database.getInt("SELECT id FROM " + Config.getInstance().getMySQLTablePrefix() + "users WHERE user = '" + playerName + "'");
|
||||||
|
|
||||||
if (userid <= 0) {
|
if (userid == 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -1067,8 +1067,6 @@ public class PlayerProfile {
|
|||||||
skills.put(skillType, newValue);
|
skills.put(skillType, newValue);
|
||||||
skillsXp.put(skillType, 0);
|
skillsXp.put(skillType, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
save();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -396,7 +396,7 @@ public class mcMMO extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (configInstance.getCommandMmoeditEnabled()) {
|
if (configInstance.getCommandMmoeditEnabled()) {
|
||||||
getCommand("mmoedit").setExecutor(new MmoeditCommand(this));
|
getCommand("mmoedit").setExecutor(new MmoeditCommand());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (configInstance.getCommandInspectEnabled()) {
|
if (configInstance.getCommandInspectEnabled()) {
|
||||||
|
@ -56,7 +56,7 @@ public class Users {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//New player, or already removed from the list
|
//New player, or already removed from the list
|
||||||
PlayerProfile playerProfile = new PlayerProfile(player, true);
|
PlayerProfile playerProfile = new PlayerProfile(player, playerName, true);
|
||||||
|
|
||||||
profiles.add(playerProfile);
|
profiles.add(playerProfile);
|
||||||
return playerProfile;
|
return playerProfile;
|
||||||
@ -78,29 +78,6 @@ public class Users {
|
|||||||
return profiles;
|
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.
|
* Get the profile of a player.
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user