From bc6233541a2e0c9b56b33cf8bbaff0a2acdc058b Mon Sep 17 00:00:00 2001 From: GJ Date: Fri, 6 Jul 2012 09:14:25 -0400 Subject: [PATCH] Start changing PlayerProfile to use an OfflinePlayer --- .../commands/general/InspectCommand.java | 4 +- .../commands/general/MmoeditCommand.java | 38 +++++++++++-------- .../nossr50/datatypes/PlayerProfile.java | 7 ++-- src/main/java/com/gmail/nossr50/mcMMO.java | 2 +- .../java/com/gmail/nossr50/util/Users.java | 2 +- 5 files changed, 30 insertions(+), 23 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/commands/general/InspectCommand.java b/src/main/java/com/gmail/nossr50/commands/general/InspectCommand.java index b4f5f43b2..cc1d2cd2e 100644 --- a/src/main/java/com/gmail/nossr50/commands/general/InspectCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/general/InspectCommand.java @@ -35,6 +35,7 @@ public class InspectCommand implements CommandExecutor { switch (args.length) { case 1: target = plugin.getServer().getOfflinePlayer(args[0]); + profile = Users.getProfile(target); if (target.isOnline()) { Player player = (Player) target; @@ -59,8 +60,7 @@ public class InspectCommand implements CommandExecutor { return true; } - //Temporary profile, it would be better to be able to create it with an OfflinePlayer instead - profile = new PlayerProfile(null, target.getName(), false); + profile = new PlayerProfile(target, false); //Temporary Profile if (!profile.isLoaded()) { sender.sendMessage(LocaleLoader.getString("Commands.DoesNotExist")); diff --git a/src/main/java/com/gmail/nossr50/commands/general/MmoeditCommand.java b/src/main/java/com/gmail/nossr50/commands/general/MmoeditCommand.java index 267fa3982..9f3525c14 100644 --- a/src/main/java/com/gmail/nossr50/commands/general/MmoeditCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/general/MmoeditCommand.java @@ -7,6 +7,7 @@ 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; @@ -16,10 +17,16 @@ 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 playerProfile; + PlayerProfile orofile; int newValue; SkillType skill; String skillName; @@ -41,7 +48,7 @@ public class MmoeditCommand implements CommandExecutor { modifiedPlayer = (Player) sender; newValue = Integer.valueOf(args[1]); skill = Skills.getSkillType(args[0]); - playerProfile = Users.getProfile(modifiedPlayer); + orofile = Users.getProfile(modifiedPlayer); if (skill.equals(SkillType.ALL)) { skillName = "all skills"; @@ -50,7 +57,7 @@ public class MmoeditCommand implements CommandExecutor { skillName = Misc.getCapitalized(skill.toString()); } - playerProfile.modifySkill(skill, newValue); + orofile.modifySkill(skill, newValue); sender.sendMessage(ChatColor.GREEN + "Your level in " + skillName + " was set to " + newValue + "!"); //TODO: Needs more locale. } else { @@ -84,29 +91,28 @@ public class MmoeditCommand implements CommandExecutor { } newValue = Integer.valueOf(args[2]); - playerProfile = Users.getProfile(args[0]); + modifiedPlayer = plugin.getServer().getOfflinePlayer(args[0]); - if (playerProfile != null) { - Player player = playerProfile.getPlayer(); + if (modifiedPlayer.isOnline()) { + orofile = Users.getProfile(modifiedPlayer); - if (player.isOnline()) { - player.sendMessage(ChatColor.GREEN + "Your level in " + skillName + " was set to " + newValue + "!"); //TODO: Needs more locale. - } + ((Player) modifiedPlayer).sendMessage(ChatColor.GREEN + "Your level in " + skillName + " was set to " + newValue + "!"); //TODO: Needs more locale. + sender.sendMessage(ChatColor.RED + skillName + " has been modified for " + args[0] + "."); //TODO: Use locale + + orofile.modifySkill(skill, newValue); + orofile.save(); + return true; } else { - //Temporary profile, it would be better to be able to create it with an OfflinePlayer instead - playerProfile = new PlayerProfile(null, args[0], false); + orofile = new PlayerProfile(modifiedPlayer, false); //Temporary Profile - if (!playerProfile.isLoaded()) { + if (!orofile.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: sender.sendMessage(usage); diff --git a/src/main/java/com/gmail/nossr50/datatypes/PlayerProfile.java b/src/main/java/com/gmail/nossr50/datatypes/PlayerProfile.java index b75995ca9..efe5166a7 100644 --- a/src/main/java/com/gmail/nossr50/datatypes/PlayerProfile.java +++ b/src/main/java/com/gmail/nossr50/datatypes/PlayerProfile.java @@ -8,6 +8,7 @@ import java.util.ArrayList; import java.util.HashMap; import org.bukkit.GameMode; +import org.bukkit.OfflinePlayer; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; @@ -63,9 +64,9 @@ public class PlayerProfile { private String playerName; private final static String location = mcMMO.usersFile; - public PlayerProfile(Player player, String playerName, boolean addNew) { - this.player = player; - this.playerName = playerName; + public PlayerProfile(OfflinePlayer offlinePlayer, boolean addNew) { + this.player = player.getPlayer(); + this.playerName = player.getName(); party = PartyManager.getInstance().getPlayerParty(playerName); diff --git a/src/main/java/com/gmail/nossr50/mcMMO.java b/src/main/java/com/gmail/nossr50/mcMMO.java index f3823ba2e..c2c291c33 100644 --- a/src/main/java/com/gmail/nossr50/mcMMO.java +++ b/src/main/java/com/gmail/nossr50/mcMMO.java @@ -401,7 +401,7 @@ public class mcMMO extends JavaPlugin { } if (configInstance.getCommandMmoeditEnabled()) { - getCommand("mmoedit").setExecutor(new MmoeditCommand()); + getCommand("mmoedit").setExecutor(new MmoeditCommand(this)); } if (configInstance.getCommandInspectEnabled()) { diff --git a/src/main/java/com/gmail/nossr50/util/Users.java b/src/main/java/com/gmail/nossr50/util/Users.java index 7dd99cd54..525270422 100644 --- a/src/main/java/com/gmail/nossr50/util/Users.java +++ b/src/main/java/com/gmail/nossr50/util/Users.java @@ -44,7 +44,7 @@ public class Users { playerProfile.setPlayer(player); } else { - playerProfile = new PlayerProfile(player, playerName, true); + playerProfile = new PlayerProfile(player, true); profiles.put(playerName, playerProfile); }