mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-23 05:36:46 +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) {
|
switch (args.length) {
|
||||||
case 1:
|
case 1:
|
||||||
target = plugin.getServer().getOfflinePlayer(args[0]);
|
target = plugin.getServer().getOfflinePlayer(args[0]);
|
||||||
|
profile = Users.getProfile(target);
|
||||||
|
|
||||||
if (target.isOnline()) {
|
if (target.isOnline()) {
|
||||||
Player player = (Player) target;
|
Player player = (Player) target;
|
||||||
@ -59,8 +60,7 @@ public class InspectCommand implements CommandExecutor {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Temporary profile, it would be better to be able to create it with an OfflinePlayer instead
|
profile = new PlayerProfile(target, false); //Temporary Profile
|
||||||
profile = new PlayerProfile(null, target.getName(), false);
|
|
||||||
|
|
||||||
if (!profile.isLoaded()) {
|
if (!profile.isLoaded()) {
|
||||||
sender.sendMessage(LocaleLoader.getString("Commands.DoesNotExist"));
|
sender.sendMessage(LocaleLoader.getString("Commands.DoesNotExist"));
|
||||||
|
@ -7,6 +7,7 @@ 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;
|
||||||
@ -16,10 +17,16 @@ 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 playerProfile;
|
PlayerProfile orofile;
|
||||||
int newValue;
|
int newValue;
|
||||||
SkillType skill;
|
SkillType skill;
|
||||||
String skillName;
|
String skillName;
|
||||||
@ -41,7 +48,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]);
|
||||||
playerProfile = Users.getProfile(modifiedPlayer);
|
orofile = Users.getProfile(modifiedPlayer);
|
||||||
|
|
||||||
if (skill.equals(SkillType.ALL)) {
|
if (skill.equals(SkillType.ALL)) {
|
||||||
skillName = "all skills";
|
skillName = "all skills";
|
||||||
@ -50,7 +57,7 @@ public class MmoeditCommand implements CommandExecutor {
|
|||||||
skillName = Misc.getCapitalized(skill.toString());
|
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.
|
sender.sendMessage(ChatColor.GREEN + "Your level in " + skillName + " was set to " + newValue + "!"); //TODO: Needs more locale.
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -84,29 +91,28 @@ public class MmoeditCommand implements CommandExecutor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
newValue = Integer.valueOf(args[2]);
|
newValue = Integer.valueOf(args[2]);
|
||||||
playerProfile = Users.getProfile(args[0]);
|
modifiedPlayer = plugin.getServer().getOfflinePlayer(args[0]);
|
||||||
|
|
||||||
if (playerProfile != null) {
|
if (modifiedPlayer.isOnline()) {
|
||||||
Player player = playerProfile.getPlayer();
|
orofile = Users.getProfile(modifiedPlayer);
|
||||||
|
|
||||||
if (player.isOnline()) {
|
((Player) modifiedPlayer).sendMessage(ChatColor.GREEN + "Your level in " + skillName + " was set to " + newValue + "!"); //TODO: Needs more locale.
|
||||||
player.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 {
|
else {
|
||||||
//Temporary profile, it would be better to be able to create it with an OfflinePlayer instead
|
orofile = new PlayerProfile(modifiedPlayer, false); //Temporary Profile
|
||||||
playerProfile = new PlayerProfile(null, args[0], false);
|
|
||||||
|
|
||||||
if (!playerProfile.isLoaded()) {
|
if (!orofile.isLoaded()) {
|
||||||
sender.sendMessage(LocaleLoader.getString("Commands.DoesNotExist"));
|
sender.sendMessage(LocaleLoader.getString("Commands.DoesNotExist"));
|
||||||
return true;
|
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:
|
default:
|
||||||
sender.sendMessage(usage);
|
sender.sendMessage(usage);
|
||||||
|
@ -8,6 +8,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
|
import org.bukkit.OfflinePlayer;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
@ -63,9 +64,9 @@ 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, String playerName, boolean addNew) {
|
public PlayerProfile(OfflinePlayer offlinePlayer, boolean addNew) {
|
||||||
this.player = player;
|
this.player = player.getPlayer();
|
||||||
this.playerName = playerName;
|
this.playerName = player.getName();
|
||||||
|
|
||||||
party = PartyManager.getInstance().getPlayerParty(playerName);
|
party = PartyManager.getInstance().getPlayerParty(playerName);
|
||||||
|
|
||||||
|
@ -401,7 +401,7 @@ public class mcMMO extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (configInstance.getCommandMmoeditEnabled()) {
|
if (configInstance.getCommandMmoeditEnabled()) {
|
||||||
getCommand("mmoedit").setExecutor(new MmoeditCommand());
|
getCommand("mmoedit").setExecutor(new MmoeditCommand(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (configInstance.getCommandInspectEnabled()) {
|
if (configInstance.getCommandInspectEnabled()) {
|
||||||
|
@ -44,7 +44,7 @@ public class Users {
|
|||||||
playerProfile.setPlayer(player);
|
playerProfile.setPlayer(player);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
playerProfile = new PlayerProfile(player, playerName, true);
|
playerProfile = new PlayerProfile(player, true);
|
||||||
|
|
||||||
profiles.put(playerName, playerProfile);
|
profiles.put(playerName, playerProfile);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user