mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-26 23:26:45 +01:00
Start changing PlayerProfile to use an OfflinePlayer
This commit is contained in:
parent
18aef9d526
commit
bc6233541a
@ -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"));
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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()) {
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user