Removed needs for SkillType.ALL

Also apparently made /Skillreset work on offline players and fixed
missing permissions check
This commit is contained in:
bm01 2013-02-04 16:33:34 +01:00
parent 458f7f5f5b
commit 35cdcb62b7
17 changed files with 379 additions and 346 deletions

View File

@ -21,7 +21,7 @@ Version 1.4.00-dev
+ Added ability to config Hylian Luck drops through treasures.yml
+ Added party XP sharing
+ Added vanilla XP boost for Fishing - includes permissions, config options, etc
= Fixed /addlevels not working properly on offline players
= Fixed multiple commands not working properly on offline players
= Fixed /mmoedit not giving feedback when modifying another players stats
= Fixed the guide usage string showing up every time /skillname was called
= Fixed Spout not being able to precache our resources properly, and therefore making our XP bars fail

View File

@ -18,13 +18,8 @@ public final class ExperienceAPI {
* @deprecated Calling this function is no longer needed and should be avoided
*/
private static void checkXP(Player player, SkillType skillType) {
if (skillType.equals(SkillType.ALL)) {
SkillTools.xpCheckAll(player, Users.getProfile(player));
}
else {
SkillTools.xpCheckSkill(skillType, player, Users.getProfile(player));
}
}
/**
* Adds raw XP to the player.

View File

@ -35,7 +35,6 @@ public final class CommandRegistrationHelper {
public static void registerSkillCommands() {
for (SkillType skill : SkillType.values()) {
if (skill != SkillType.ALL) {
String commandName = skill.toString().toLowerCase();
String localizedName = LocaleLoader.getString(Misc.getCapitalized(commandName) + ".SkillName").toLowerCase();
@ -115,7 +114,6 @@ public final class CommandRegistrationHelper {
}
}
}
}
public static void registerAddlevelsCommand() {
PluginCommand command = mcMMO.p.getCommand("addlevels");

View File

@ -19,7 +19,7 @@ public class AddlevelsCommand implements CommandExecutor{
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
PlayerProfile profile;
int levels;
SkillType skill;
boolean allSkills = false;
switch (args.length) {
case 2:
@ -27,7 +27,10 @@ public class AddlevelsCommand implements CommandExecutor{
return false;
}
if (!SkillTools.isSkill(args[0])) {
if (args[0].equalsIgnoreCase("all")) {
allSkills = true;
}
else if (!SkillTools.isSkill(args[0])) {
sender.sendMessage(LocaleLoader.getString("Commands.Skill.Invalid"));
return true;
}
@ -37,17 +40,28 @@ public class AddlevelsCommand implements CommandExecutor{
}
levels = Integer.valueOf(args[1]);
skill = SkillTools.getSkillType(args[0]);
profile = Users.getPlayer((Player) sender).getProfile();
if (skill.equals(SkillType.ALL)) {
if (allSkills) {
for (SkillType skillType : SkillType.values()) {
if (skillType.isChildSkill()) {
continue;
}
profile.addLevels(skillType, levels);
}
}
else {
profile.addLevels(SkillTools.getSkillType(args[0]), levels);
}
if (allSkills) {
sender.sendMessage(LocaleLoader.getString("Commands.addlevels.AwardAll.1", levels));
}
else {
sender.sendMessage(LocaleLoader.getString("Commands.addlevels.AwardSkill.1", levels, Misc.getCapitalized(skill.toString())));
sender.sendMessage(LocaleLoader.getString("Commands.addlevels.AwardSkill.1", levels, Misc.getCapitalized(args[0])));
}
profile.addLevels(skill, levels);
return true;
case 3:
@ -56,7 +70,10 @@ public class AddlevelsCommand implements CommandExecutor{
return true;
}
if (!SkillTools.isSkill(args[1])) {
if (args[1].equalsIgnoreCase("all")) {
allSkills = true;
}
else if (!SkillTools.isSkill(args[1])) {
sender.sendMessage(LocaleLoader.getString("Commands.Skill.Invalid"));
return true;
}
@ -67,7 +84,6 @@ public class AddlevelsCommand implements CommandExecutor{
McMMOPlayer mcMMOPlayer = Users.getPlayer(args[0]);
levels = Integer.valueOf(args[2]);
skill = SkillTools.getSkillType(args[1]);
// If the mcMMOPlayer doesn't exist, create a temporary profile and check if it's present in the database. If it's not, abort the process.
if (mcMMOPlayer == null) {
@ -78,31 +94,46 @@ public class AddlevelsCommand implements CommandExecutor{
return true;
}
profile.addLevels(skill, levels);
if (allSkills) {
for (SkillType skillType : SkillType.values()) {
if (skillType.isChildSkill()) {
continue;
}
profile.addLevels(skillType, levels);
}
}
else {
profile.addLevels(SkillTools.getSkillType(args[1]), levels);
}
profile.save(); // Since this is a temporary profile, we save it here.
}
else {
profile = mcMMOPlayer.getProfile();
Player player = mcMMOPlayer.getPlayer();
profile.addLevels(skill, levels);
if (allSkills) {
for (SkillType skillType : SkillType.values()) {
if (skillType.isChildSkill()) {
continue;
}
// Check if the player is online before we try to send them a message.
if (player.isOnline()) {
if (skill.equals(SkillType.ALL)) {
player.sendMessage(LocaleLoader.getString("Commands.addlevels.AwardAll.1", levels));
profile.addLevels(skillType, levels);
}
mcMMOPlayer.getPlayer().sendMessage(LocaleLoader.getString("Commands.addlevels.AwardAll.1", levels));
}
else {
player.sendMessage(LocaleLoader.getString("Commands.addlevels.AwardSkill.1", levels, Misc.getCapitalized(skill.toString())));
}
profile.addLevels(SkillTools.getSkillType(args[1]), levels);
mcMMOPlayer.getPlayer().sendMessage(LocaleLoader.getString("Commands.addlevels.AwardSkill.1", levels, Misc.getCapitalized(args[1])));
}
}
if (skill.equals(SkillType.ALL)) {
if (allSkills) {
sender.sendMessage(LocaleLoader.getString("Commands.addlevels.AwardAll.2", args[0]));
}
else {
sender.sendMessage(LocaleLoader.getString("Commands.addlevels.AwardSkill.2", Misc.getCapitalized(skill.toString()), args[0]));
sender.sendMessage(LocaleLoader.getString("Commands.addlevels.AwardSkill.2", Misc.getCapitalized(args[1]), args[0]));
}
return true;

View File

@ -17,11 +17,10 @@ import com.gmail.nossr50.util.Users;
public class AddxpCommand implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
Player modifiedPlayer;
int xp;
SkillType skill;
McMMOPlayer mcMMOPlayer;
PlayerProfile profile;
boolean allSkills = false;
switch (args.length) {
case 2:
@ -29,7 +28,10 @@ public class AddxpCommand implements CommandExecutor {
return false;
}
if (!SkillTools.isSkill(args[0])) {
if (args[0].equalsIgnoreCase("all")) {
allSkills = true;
}
else if (!SkillTools.isSkill(args[0])) {
sender.sendMessage(LocaleLoader.getString("Commands.Skill.Invalid"));
return true;
}
@ -39,25 +41,23 @@ public class AddxpCommand implements CommandExecutor {
}
xp = Integer.valueOf(args[1]);
skill = SkillTools.getSkillType(args[0]);
modifiedPlayer = (Player) sender;
mcMMOPlayer = Users.getPlayer(modifiedPlayer);
mcMMOPlayer = Users.getPlayer((Player) sender);
profile = mcMMOPlayer.getProfile();
if (skill.equals(SkillType.ALL)) {
for (SkillType type : SkillType.values()) {
if (type.equals(SkillType.ALL) || type.isChildSkill()) {
if (allSkills) {
for (SkillType skillType : SkillType.values()) {
if (skillType.isChildSkill()) {
continue;
}
mcMMOPlayer.applyXpGain(type, xp);
mcMMOPlayer.applyXpGain(skillType, xp);
}
sender.sendMessage(LocaleLoader.getString("Commands.addxp.AwardAll", xp));
}
else {
mcMMOPlayer.applyXpGain(skill, xp);
sender.sendMessage(LocaleLoader.getString("Commands.addxp.AwardSkill", xp, Misc.getCapitalized(skill.toString())));
mcMMOPlayer.applyXpGain(SkillTools.getSkillType(args[0]), xp);
sender.sendMessage(LocaleLoader.getString("Commands.addxp.AwardSkill", xp, Misc.getCapitalized(args[0])));
}
return true;
@ -68,7 +68,10 @@ public class AddxpCommand implements CommandExecutor {
return true;
}
if (!SkillTools.isSkill(args[1])) {
if (args[1].equalsIgnoreCase("all")) {
allSkills = true;
}
else if (!SkillTools.isSkill(args[1])) {
sender.sendMessage(LocaleLoader.getString("Commands.Skill.Invalid"));
return true;
}
@ -79,7 +82,6 @@ public class AddxpCommand implements CommandExecutor {
mcMMOPlayer = Users.getPlayer(args[0]);
xp = Integer.valueOf(args[2]);
skill = SkillTools.getSkillType(args[1]);
// If the mcMMOPlayer doesn't exist, create a temporary profile and check if it's present in the database. If it's not, abort the process.
if (mcMMOPlayer == null) {
@ -91,53 +93,44 @@ public class AddxpCommand implements CommandExecutor {
}
// TODO: Currently the offline player doesn't level up automatically
if (skill.equals(SkillType.ALL)) {
for (SkillType type : SkillType.values()) {
if (type.equals(SkillType.ALL) || type.isChildSkill()) {
if (allSkills) {
for (SkillType skillType : SkillType.values()) {
if (skillType.isChildSkill()) {
continue;
}
profile.setSkillXpLevel(type, profile.getSkillXpLevel(type) + xp);
profile.setSkillXpLevel(skillType, xp);
}
}
else {
profile.setSkillXpLevel(skill, profile.getSkillXpLevel(skill) + xp);
profile.setSkillXpLevel(SkillTools.getSkillType(args[1]), xp);
}
profile.save(); // Since this is a temporary profile, we save it here.
}
else {
if (skill.equals(SkillType.ALL)) {
for (SkillType type : SkillType.values()) {
if (type.equals(SkillType.ALL) || type.isChildSkill()) {
if (allSkills) {
for (SkillType skillType : SkillType.values()) {
if (skillType.isChildSkill()) {
continue;
}
mcMMOPlayer.applyXpGain(type, xp);
mcMMOPlayer.applyXpGain(skillType, xp);
}
mcMMOPlayer.getPlayer().sendMessage(LocaleLoader.getString("Commands.addxp.AwardAll", xp));
}
else {
mcMMOPlayer.applyXpGain(skill, xp);
}
modifiedPlayer = mcMMOPlayer.getPlayer();
if (modifiedPlayer.isOnline()) {
if (skill.equals(SkillType.ALL)) {
modifiedPlayer.sendMessage(LocaleLoader.getString("Commands.addxp.AwardAll", xp));
}
else {
modifiedPlayer.sendMessage(LocaleLoader.getString("Commands.addxp.AwardSkill", xp, Misc.getCapitalized(skill.toString())));
}
mcMMOPlayer.applyXpGain(SkillTools.getSkillType(args[1]), xp);
mcMMOPlayer.getPlayer().sendMessage(LocaleLoader.getString("Commands.addxp.AwardSkill", xp, Misc.getCapitalized(args[1])));
}
}
if (skill.equals(SkillType.ALL)) {
if (allSkills) {
sender.sendMessage(LocaleLoader.getString("Commands.addlevels.AwardAll.2", args[0]));
}
else {
sender.sendMessage(LocaleLoader.getString("Commands.addlevels.AwardSkill.2", Misc.getCapitalized(skill.toString()), args[0]));
sender.sendMessage(LocaleLoader.getString("Commands.addlevels.AwardSkill.2", Misc.getCapitalized(args[1]), args[0]));
}
return true;

View File

@ -19,7 +19,7 @@ public class MmoeditCommand implements CommandExecutor {
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
PlayerProfile profile;
int newValue;
SkillType skill;
boolean allSkills = false;
switch (args.length) {
case 2:
@ -27,7 +27,10 @@ public class MmoeditCommand implements CommandExecutor {
return false;
}
if (!SkillTools.isSkill(args[0])) {
if (args[0].equalsIgnoreCase("all")) {
allSkills = true;
}
else if (!SkillTools.isSkill(args[0])) {
sender.sendMessage(LocaleLoader.getString("Commands.Skill.Invalid"));
return true;
}
@ -37,26 +40,36 @@ public class MmoeditCommand implements CommandExecutor {
}
newValue = Integer.valueOf(args[1]);
skill = SkillTools.getSkillType(args[0]);
profile = Users.getPlayer((Player) sender).getProfile();
if (skill == SkillType.ALL) {
if (allSkills) {
for (SkillType skillType : SkillType.values()) {
if (skillType.isChildSkill()) {
continue;
}
profile.modifySkill(skillType, newValue);
}
sender.sendMessage(LocaleLoader.getString("Commands.mmoedit.AllSkills.1", newValue));
}
else {
sender.sendMessage(LocaleLoader.getString("Commands.mmoedit.Modified.1", Misc.getCapitalized(skill.toString()), newValue));
profile.modifySkill(SkillTools.getSkillType(args[0]), newValue);
sender.sendMessage(LocaleLoader.getString("Commands.mmoedit.Modified.1", Misc.getCapitalized(args[0]), newValue));
}
profile.modifySkill(skill, newValue);
return true;
case 3:
if (Permissions.hasPermission(sender, "mcmmo.commands.mmoedit.others")) {
if (!Permissions.hasPermission(sender, "mcmmo.commands.mmoedit.others")) {
sender.sendMessage(command.getPermissionMessage());
return true;
}
if (!SkillTools.isSkill(args[1])) {
if (args[1].equalsIgnoreCase("all")) {
allSkills = true;
}
else if (!SkillTools.isSkill(args[1])) {
sender.sendMessage(LocaleLoader.getString("Commands.Skill.Invalid"));
return true;
}
@ -66,43 +79,57 @@ public class MmoeditCommand implements CommandExecutor {
}
newValue = Integer.valueOf(args[2]);
skill = SkillTools.getSkillType(args[1]);
McMMOPlayer mcMMOPlayer = Users.getPlayer(args[0]);
// If the mcMMOPlayer doesn't exist, create a temporary profile and check if it's present in the database. If it's not, abort the process.
if (mcMMOPlayer == null) {
profile = new PlayerProfile(args[0], false); //Temporary Profile
profile = new PlayerProfile(args[0], false);
if (!profile.isLoaded()) {
sender.sendMessage(LocaleLoader.getString("Commands.DoesNotExist"));
return true;
}
profile.modifySkill(skill, newValue);
if (allSkills) {
for (SkillType skillType : SkillType.values()) {
if (skillType.isChildSkill()) {
continue;
}
profile.modifySkill(skillType, newValue);
}
}
else {
profile.modifySkill(SkillTools.getSkillType(args[1]), newValue);
}
profile.save(); // Since this is a temporary profile, we save it here.
}
else {
profile = mcMMOPlayer.getProfile();
Player player = mcMMOPlayer.getPlayer();
profile.modifySkill(skill, newValue);
if (allSkills) {
for (SkillType skillType : SkillType.values()) {
if (skillType.isChildSkill()) {
continue;
}
// Check if the player is online before we try to send them a message.
if (player.isOnline()) {
if (skill == SkillType.ALL) {
player.sendMessage(LocaleLoader.getString("Commands.mmoedit.AllSkills.1", newValue));
profile.modifySkill(skillType, newValue);
}
mcMMOPlayer.getPlayer().sendMessage(LocaleLoader.getString("Commands.mmoedit.AllSkills.1", newValue));
}
else {
player.sendMessage(LocaleLoader.getString("Commands.mmoedit.Modified.1", Misc.getCapitalized(skill.toString()), newValue));
}
profile.modifySkill(SkillTools.getSkillType(args[1]), newValue);
mcMMOPlayer.getPlayer().sendMessage(LocaleLoader.getString("Commands.mmoedit.Modified.1", Misc.getCapitalized(args[1]), newValue));
}
}
if (skill == SkillType.ALL) {
if (allSkills) {
sender.sendMessage(LocaleLoader.getString("Commands.addlevels.AwardAll.2", args[0]));
}
else {
sender.sendMessage(LocaleLoader.getString("Commands.mmoedit.Modified.2", Misc.getCapitalized(skill.toString()), args[0]));
sender.sendMessage(LocaleLoader.getString("Commands.mmoedit.Modified.2", Misc.getCapitalized(args[1]), args[0]));
}
return true;

View File

@ -18,7 +18,7 @@ public class SkillresetCommand implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
PlayerProfile profile;
SkillType skill;
boolean allSkills = false;
switch (args.length) {
case 1:
@ -26,49 +26,80 @@ public class SkillresetCommand implements CommandExecutor {
return false;
}
if (!SkillTools.isSkill(args[0])) {
if (args[0].equalsIgnoreCase("all")) {
allSkills = true;
}
else if (!SkillTools.isSkill(args[0])) {
sender.sendMessage(LocaleLoader.getString("Commands.Skill.Invalid"));
return true;
}
skill = SkillTools.getSkillType(args[0]);
if (allSkills) {
for (SkillType skillType : SkillType.values()) {
if (skillType.isChildSkill()) {
continue;
}
if (skill != SkillType.ALL && !Permissions.hasPermission(sender, "mcmmo.commands.skillreset." + skill.toString().toLowerCase())) {
if (!Permissions.hasPermission(sender, "mcmmo.commands.skillreset." + args[0].toLowerCase())) {
sender.sendMessage(command.getPermissionMessage());
return true;
}
profile = Users.getPlayer((Player) sender).getProfile();
if (skill == SkillType.ALL) {
for (SkillType type : SkillType.values()) {
if (type != SkillType.ALL) {
if (Permissions.hasPermission(sender, "mcmmo.commands.skillreset." + type.toString().toLowerCase())) {
profile.modifySkill(type, 0);
sender.sendMessage(LocaleLoader.getString("Commands.Reset.Single", Misc.getCapitalized(type.toString())));
}
}
}
}
else {
profile.modifySkill(skill, 0);
sender.sendMessage(LocaleLoader.getString("Commands.Reset.Single", Misc.getCapitalized(skill.toString())));
if (!Permissions.hasPermission(sender, "mcmmo.commands.skillreset." + args[0].toLowerCase())) {
sender.sendMessage(command.getPermissionMessage());
return true;
}
}
profile = Users.getPlayer((Player) sender).getProfile();
if (allSkills) {
for (SkillType skillType : SkillType.values()) {
if (skillType.isChildSkill()) {
continue;
}
profile.modifySkill(skillType, 0);
}
sender.sendMessage(LocaleLoader.getString("Commands.Reset.All"));
}
else {
profile.modifySkill(SkillTools.getSkillType(args[0]), 0);
sender.sendMessage(LocaleLoader.getString("Commands.Reset.Single", Misc.getCapitalized(args[0])));
}
return true;
case 2:
if (!SkillTools.isSkill(args[1])) {
if (args[1].equalsIgnoreCase("all")) {
allSkills = true;
}
else if (!SkillTools.isSkill(args[1])) {
sender.sendMessage(LocaleLoader.getString("Commands.Skill.Invalid"));
return true;
}
skill = SkillTools.getSkillType(args[1]);
if (allSkills) {
for (SkillType skillType : SkillType.values()) {
if (skillType.isChildSkill()) {
continue;
}
if (skill != SkillType.ALL && !Permissions.hasPermission(sender, "mcmmo.commands.skillreset.others." + skill.toString().toLowerCase())) {
if (!Permissions.hasPermission(sender, "mcmmo.commands.skillreset." + args[1].toLowerCase())) {
sender.sendMessage(command.getPermissionMessage());
return true;
}
}
}
else {
if (!Permissions.hasPermission(sender, "mcmmo.commands.skillreset." + args[1].toLowerCase())) {
sender.sendMessage(command.getPermissionMessage());
return true;
}
}
McMMOPlayer mcMMOPlayer = Users.getPlayer(args[0]);
@ -81,45 +112,48 @@ public class SkillresetCommand implements CommandExecutor {
return true;
}
if (skill == SkillType.ALL) {
for (SkillType type : SkillType.values()) {
if (type != SkillType.ALL) {
if (Permissions.hasPermission(sender, "mcmmo.commands.skillreset.others" + type.toString().toLowerCase())) {
profile.modifySkill(type, 0);
sender.sendMessage(LocaleLoader.getString("Commands.mmoedit.Modified.2", Misc.getCapitalized(type.toString()), args[0]));
}
if (allSkills) {
for (SkillType skillType : SkillType.values()) {
if (skillType.isChildSkill()) {
continue;
}
profile.modifySkill(skillType, 0);
}
}
else {
profile.modifySkill(skill, 0);
sender.sendMessage(LocaleLoader.getString("Commands.mmoedit.Modified.2", Misc.getCapitalized(skill.toString()), args[0]));
profile.modifySkill(SkillTools.getSkillType(args[1]), 0);
}
profile.save(); // Since this is a temporary profile, we save it here.
}
else {
profile = mcMMOPlayer.getProfile();
Player player = mcMMOPlayer.getPlayer();
if (skill == SkillType.ALL) {
for (SkillType type : SkillType.values()) {
if (type != SkillType.ALL) {
if (Permissions.hasPermission(sender, "mcmmo.commands.skillreset.others" + type.toString().toLowerCase())) {
profile.modifySkill(type, 0);
sender.sendMessage(LocaleLoader.getString("Commands.mmoedit.Modified.2", Misc.getCapitalized(type.toString()), args[0]));
player.sendMessage(LocaleLoader.getString("Commands.Reset.Single", Misc.getCapitalized(type.toString())));
}
if (allSkills) {
for (SkillType skillType : SkillType.values()) {
if (skillType.isChildSkill()) {
continue;
}
profile.modifySkill(skillType, 0);
}
mcMMOPlayer.getPlayer().sendMessage(LocaleLoader.getString("Commands.Reset.All"));
}
else {
profile.modifySkill(skill, 0);
sender.sendMessage(LocaleLoader.getString("Commands.mmoedit.Modified.2", Misc.getCapitalized(skill.toString()), args[0]));
player.sendMessage(LocaleLoader.getString("Commands.Reset.Single", Misc.getCapitalized(skill.toString())));
profile.modifySkill(SkillTools.getSkillType(args[1]), 0);
mcMMOPlayer.getPlayer().sendMessage(LocaleLoader.getString("Commands.Reset.Single", Misc.getCapitalized(args[1])));
}
}
if (allSkills) {
sender.sendMessage(LocaleLoader.getString("Commands.addlevels.AwardAll.2", args[0]));
}
else {
sender.sendMessage(LocaleLoader.getString("Commands.mmoedit.Modified.2", Misc.getCapitalized(args[1]), args[0]));
}
return true;
default:

View File

@ -6,6 +6,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.config.Config;
import com.gmail.nossr50.datatypes.McMMOPlayer;
@ -21,10 +22,9 @@ import com.gmail.nossr50.util.Users;
public class McrankCommand implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
//TODO: Better input handling, add usage string
// TODO: Better input handling, add usage string
if (!Config.getInstance().getUseMySQL()) {
Leaderboard.updateLeaderboards(); //Make sure the information is up to date
Leaderboard.updateLeaderboards(); // Make sure the information is up to date
}
if (CommandHelper.noConsoleUsage(sender)) {
@ -37,6 +37,7 @@ public class McrankCommand implements CommandExecutor {
Player player = (Player) sender;
String playerName;
switch (args.length) {
case 0:
playerName = player.getName();
@ -48,7 +49,6 @@ public class McrankCommand implements CommandExecutor {
}
playerName = args[0];
McMMOPlayer mcmmoPlayer = Users.getPlayer(playerName);
if (mcmmoPlayer != null) {
@ -83,29 +83,27 @@ public class McrankCommand implements CommandExecutor {
public void flatfileDisplay(CommandSender sender, String playerName) {
sender.sendMessage(LocaleLoader.getString("Commands.mcrank.Heading"));
sender.sendMessage(LocaleLoader.getString("Commands.mcrank.Player", playerName));
for (SkillType skillType : SkillType.values()) {
int[] rankInts = Leaderboard.getPlayerRank(playerName, skillType);
if (skillType.isChildSkill()) {
continue;
}
if (skillType.equals(SkillType.ALL)) {
continue; // We want the overall ranking to be at the bottom
}
if (rankInts[1] == 0) {
sender.sendMessage(LocaleLoader.getString("Commands.mcrank.Skill", SkillTools.localizeSkillName(skillType), LocaleLoader.getString("Commands.mcrank.Unranked"))); //Don't bother showing ranking for players without skills
sender.sendMessage(LocaleLoader.getString("Commands.mcrank.Skill", SkillTools.localizeSkillName(skillType), LocaleLoader.getString("Commands.mcrank.Unranked"))); // Don't bother showing ranking for players without skills
}
else {
sender.sendMessage(LocaleLoader.getString("Commands.mcrank.Skill", SkillTools.localizeSkillName(skillType), String.valueOf(rankInts[0])));
}
}
//Show the powerlevel ranking
int[] rankInts = Leaderboard.getPlayerRank(playerName, SkillType.ALL);
// Show the powerlevel ranking
int[] rankInts = Leaderboard.getPlayerRank(playerName);
if (rankInts[1] == 0) {
sender.sendMessage(LocaleLoader.getString("Commands.mcrank.Overalll", LocaleLoader.getString("Commands.mcrank.Unranked"))); //Don't bother showing ranking for players without skills
sender.sendMessage(LocaleLoader.getString("Commands.mcrank.Overalll", LocaleLoader.getString("Commands.mcrank.Unranked"))); // Don't bother showing ranking for players without skills
}
else {
sender.sendMessage(LocaleLoader.getString("Commands.mcrank.Overall", String.valueOf(rankInts[0])));
@ -113,6 +111,6 @@ public class McrankCommand implements CommandExecutor {
}
private void sqlDisplay(CommandSender sender, String playerName) {
Bukkit.getScheduler().runTaskAsynchronously(Bukkit.getPluginManager().getPlugin("mcMMO"), new McRankAsync(playerName, sender));
Bukkit.getScheduler().runTaskAsynchronously(mcMMO.p, new McRankAsync(playerName, sender));
}
}

View File

@ -13,7 +13,6 @@ import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.database.Database;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.skills.utilities.SkillTools;
import com.gmail.nossr50.skills.utilities.SkillType;
import com.gmail.nossr50.util.Leaderboard;
import com.gmail.nossr50.util.Misc;
@ -125,10 +124,10 @@ public class MctopCommand implements CommandExecutor {
}
Leaderboard.updateLeaderboards(); //Make sure we have the latest information
SkillType skillType = SkillType.getSkill(skill);
String[] info = Leaderboard.retrieveInfo(skillType, page);
if (skill.equalsIgnoreCase("ALL")) {
String[] info = Leaderboard.retrieveInfo(skill, page);
if (skill.equalsIgnoreCase("all")) {
sender.sendMessage(LocaleLoader.getString("Commands.PowerLevel.Leaderboard"));
}
else {

View File

@ -473,44 +473,43 @@ public final class Database {
public static Map<String, Integer> readSQLRank(String playerName) {
ResultSet resultSet;
Map<String, Integer> skills = new HashMap<String, Integer>();
if (checkConnected()) {
try {
for (SkillType skillType: SkillType.values()) {
if (skillType.isChildSkill()) continue;
String sql;
if (skillType != SkillType.ALL) {
sql = "SELECT COUNT(*) AS rank FROM " + tablePrefix + "users JOIN " + tablePrefix + "skills ON user_id = id WHERE " + skillType.name().toLowerCase() + " > 0 AND " + skillType.name().toLowerCase() + " > (SELECT " + skillType.name().toLowerCase() + " FROM " + tablePrefix + "users JOIN " + tablePrefix + "skills ON user_id = id WHERE user = '" + playerName + "')";
}
else {
sql = "SELECT COUNT(*) AS rank FROM " + tablePrefix + "users JOIN " + tablePrefix + "skills ON user_id = id WHERE taming+mining+woodcutting+repair+unarmed+herbalism+excavation+archery+swords+axes+acrobatics+fishing > 0 AND taming+mining+woodcutting+repair+unarmed+herbalism+excavation+archery+swords+axes+acrobatics+fishing > (SELECT taming+mining+woodcutting+repair+unarmed+herbalism+excavation+archery+swords+axes+acrobatics+fishing FROM " + tablePrefix + "users JOIN " + tablePrefix + "skills ON user_id = id WHERE user = '" + playerName + "')";
if (skillType.isChildSkill()) {
continue;
}
String sql = "SELECT COUNT(*) AS rank FROM " + tablePrefix + "users JOIN " + tablePrefix + "skills ON user_id = id WHERE " + skillType.name().toLowerCase() + " > 0 AND " + skillType.name().toLowerCase() + " > (SELECT " + skillType.name().toLowerCase() + " FROM " + tablePrefix + "users JOIN " + tablePrefix + "skills ON user_id = id WHERE user = '" + playerName + "')";
PreparedStatement statement = connection.prepareStatement(sql);
resultSet = statement.executeQuery();
resultSet.next();
int rank = resultSet.getInt("rank");
if (skillType != SkillType.ALL) {
sql = "SELECT user, " + skillType.name().toLowerCase() + " FROM " + tablePrefix + "users JOIN " + tablePrefix + "skills ON user_id = id WHERE " + skillType.name().toLowerCase() + " > 0 AND " + skillType.name().toLowerCase() + " = (SELECT " + skillType.name().toLowerCase() + " FROM " + tablePrefix + "users JOIN " + tablePrefix + "skills ON user_id = id WHERE user = '" + playerName + "') ORDER BY user";
}
else {
sql = "SELECT user, taming+mining+woodcutting+repair+unarmed+herbalism+excavation+archery+swords+axes+acrobatics+fishing FROM " + tablePrefix + "users JOIN " + tablePrefix + "skills ON user_id = id WHERE taming+mining+woodcutting+repair+unarmed+herbalism+excavation+archery+swords+axes+acrobatics+fishing > 0 AND taming+mining+woodcutting+repair+unarmed+herbalism+excavation+archery+swords+axes+acrobatics+fishing = (SELECT taming+mining+woodcutting+repair+unarmed+herbalism+excavation+archery+swords+axes+acrobatics+fishing FROM " + tablePrefix + "users JOIN " + tablePrefix + "skills ON user_id = id WHERE user = '" + playerName + "') ORDER BY user";
}
statement = connection.prepareStatement(sql);
resultSet = statement.executeQuery();
while (resultSet.next()) {
if (resultSet.getString("user").equalsIgnoreCase(playerName)) {
skills.put(skillType.name(), rank + resultSet.getRow());
break;
}
}
statement.close();
}
}
catch (SQLException ex) {
printErrors(ex);
}
}
return skills;
}

View File

@ -66,7 +66,7 @@ public class PlayerProfile {
}
for (SkillType skillType : SkillType.values()) {
if (skillType != SkillType.ALL && !skillType.isChildSkill()) {
if (!skillType.isChildSkill()) {
skills.put(skillType, 0);
skillsXp.put(skillType, 0);
}
@ -1012,19 +1012,8 @@ public class PlayerProfile {
return;
}
if (skillType.equals(SkillType.ALL)) {
for (SkillType skill : SkillType.values()) {
if (skill.equals(SkillType.ALL)) {
continue;
}
skillsXp.put(skill, skillsXp.get(skill) - xp);
}
}
else {
skillsXp.put(skillType, skillsXp.get(skillType) - xp);
}
}
/**
* Modify a skill level.
@ -1037,21 +1026,9 @@ public class PlayerProfile {
return;
}
if (skillType.equals(SkillType.ALL)) {
for (SkillType skill : SkillType.values()) {
if (skill.equals(SkillType.ALL)) {
continue;
}
skills.put(skill, newValue);
skillsXp.put(skill, 0);
}
}
else {
skills.put(skillType, newValue);
skillsXp.put(skillType, 0);
}
}
/**
* Add levels to a skill.
@ -1064,21 +1041,9 @@ public class PlayerProfile {
return;
}
if (skillType == SkillType.ALL) {
for (SkillType skill : SkillType.values()) {
if (skill == SkillType.ALL || skill.isChildSkill()) {
continue;
}
skills.put(skill, skills.get(skill) + levels);
skillsXp.put(skill, 0);
}
}
else {
skills.put(skillType, skills.get(skillType) + levels);
skillsXp.put(skillType, 0);
}
}
/**
* Get the amount of Xp remaining before the next level.
@ -1133,8 +1098,4 @@ public class PlayerProfile {
//
// return bonusModifier;
// }
/*
* Party Stuff
*/
}

View File

@ -5,6 +5,7 @@ import java.util.Map;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.database.Database;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.skills.utilities.SkillTools;
@ -22,7 +23,8 @@ public class McRankAsync implements Runnable {
@Override
public void run() {
final Map<String, Integer> skills = Database.readSQLRank(playerName);
Bukkit.getScheduler().scheduleSyncDelayedTask(Bukkit.getPluginManager().getPlugin("mcMMO"), new Runnable() {
Bukkit.getScheduler().scheduleSyncDelayedTask(mcMMO.p, new Runnable() {
@Override
public void run() {
sender.sendMessage(LocaleLoader.getString("Commands.mcrank.Heading"));
@ -33,9 +35,6 @@ public class McRankAsync implements Runnable {
continue;
}
if (skillType.equals(SkillType.ALL))
continue; // We want the overall ranking to be at the bottom
if (skills.get(skillType.name()) == null) {
sender.sendMessage(LocaleLoader.getString("Commands.mcrank.Skill", SkillTools.localizeSkillName(skillType), LocaleLoader.getString("Commands.mcrank.Unranked")));
}

View File

@ -275,23 +275,6 @@ public class SkillTools {
}
}
/**
* Check XP of all skills.
*
* @param player The player to check XP for.
* @param profile The profile of the player whose skill to check
*/
public static void xpCheckAll(Player player, PlayerProfile profile) {
for (SkillType skillType : SkillType.values()) {
//Don't want to do anything with this one
if (skillType == SkillType.ALL || skillType.isChildSkill()) {
continue;
}
xpCheckSkill(skillType, player, profile);
}
}
/**
* Get the skill represented by the given string
*

View File

@ -8,7 +8,6 @@ import com.gmail.nossr50.util.Users;
public enum SkillType {
ACROBATICS(Config.getInstance().getLevelCapAcrobatics(), Config.getInstance().getFormulaMultiplierAcrobatics()),
ALL, //This one is just for convenience
ARCHERY(Config.getInstance().getLevelCapArchery(), Config.getInstance().getFormulaMultiplierArchery()),
AXES(AbilityType.SKULL_SPLIITER, Config.getInstance().getLevelCapAxes(), ToolType.AXE, Config.getInstance().getFormulaMultiplierAxes()),
EXCAVATION(AbilityType.GIGA_DRILL_BREAKER, Config.getInstance().getLevelCapExcavation(), ToolType.SHOVEL, Config.getInstance().getFormulaMultiplierExcavation()),
@ -120,10 +119,6 @@ public enum SkillType {
}
public static SkillType getSkill(String skillName) {
if (skillName.equalsIgnoreCase("powerlevel") || skillName.equalsIgnoreCase("all")) {
return SkillType.ALL;
}
for (SkillType type : SkillType.values()) {
if (type.name().equalsIgnoreCase(skillName)) {
return type;
@ -141,6 +136,7 @@ public enum SkillType {
* @return the player's skill level
*/
public int getSkillLevel(Player player) {
// TODO: Child skills aren't handled here
return Users.getPlayer(player).getProfile().getSkillLevel(this);
}

View File

@ -116,15 +116,14 @@ public class SpoutTools {
* Extract Spout files to the Resources directory.
*/
public static void extractFiles() {
//Setup directories
// Setup directories
new File(spoutDirectory).mkdir();
new File(hudDirectory).mkdir();
new File(hudStandardDirectory).mkdir();
new File(hudRetroDirectory).mkdir();
new File(soundDirectory).mkdir();
//XP Bar images
// XP Bar images
for (int x = 0; x < 255; x++) {
String theFileName;
@ -141,24 +140,25 @@ public class SpoutTools {
writeFile(theFileName, hudStandardDirectory);
}
//Standard XP Icons
for (SkillType y : SkillType.values()) {
if (y.equals(SkillType.ALL) || y.isChildSkill()) {
// Standard XP Icons
for (SkillType skillType : SkillType.values()) {
if (skillType.isChildSkill()) {
continue;
}
String standardFileName = Misc.getCapitalized(y.toString())+".png";
String retroFileName = Misc.getCapitalized(y.toString())+"_r.png";
String skillTypeString = skillType.toString();
String standardFileName = Misc.getCapitalized(skillTypeString)+".png";
String retroFileName = Misc.getCapitalized(skillTypeString)+"_r.png";
writeFile(standardFileName, hudStandardDirectory);
writeFile(retroFileName, hudRetroDirectory);
}
//Blank icons
// Blank icons
writeFile("Icon.png", hudStandardDirectory);
writeFile("Icon_r.png", hudRetroDirectory);
//Sound FX
// Sound FX
writeFile("level.wav", soundDirectory);
}
@ -189,7 +189,7 @@ public class SpoutTools {
public static ArrayList<File> getFiles() {
ArrayList<File> files = new ArrayList<File>();
/* XP BAR */
// XP BAR
for (int x = 0; x < 255; x++) {
if (x < 10) {
files.add(new File(hudStandardDirectory + "xpbar_inc00" + x + ".png"));
@ -202,21 +202,23 @@ public class SpoutTools {
}
}
/* Standard XP Icons */
for (SkillType y : SkillType.values()) {
if (y.equals(SkillType.ALL) || y.isChildSkill()) {
// Standard XP Icons
for (SkillType skillType : SkillType.values()) {
if (skillType.isChildSkill()) {
continue;
}
files.add(new File(hudStandardDirectory + Misc.getCapitalized(y.toString()) + ".png"));
files.add(new File(hudRetroDirectory + Misc.getCapitalized(y.toString()) + "_r.png"));
String skillTypeString = skillType.toString();
files.add(new File(hudStandardDirectory + Misc.getCapitalized(skillTypeString) + ".png"));
files.add(new File(hudRetroDirectory + Misc.getCapitalized(skillTypeString) + "_r.png"));
}
/* Blank icons */
// Blank icons
files.add(new File(hudStandardDirectory + "Icon.png"));
files.add(new File(hudRetroDirectory + "Icon_r.png"));
//Level SFX
// Level SFX
files.add(new File(soundDirectory + "level.wav"));
return files;

View File

@ -24,13 +24,12 @@ public final class Hardcore {
int totalLost = 0;
for (SkillType skillType : SkillType.values()) {
if (skillType.equals(SkillType.ALL) || skillType.isChildSkill()) {
if (skillType.isChildSkill()) {
continue;
}
int playerSkillLevel = playerProfile.getSkillLevel(skillType);
//Should we really care about negative skill levels?
if (playerSkillLevel <= 0) {
continue;
}
@ -54,14 +53,13 @@ public final class Hardcore {
int totalStolen = 0;
for (SkillType skillType : SkillType.values()) {
if (skillType.equals(SkillType.ALL) || skillType.isChildSkill()) {
if (skillType.isChildSkill()) {
continue;
}
int killerSkillLevel = killerProfile.getSkillLevel(skillType);
int victimSkillLevel = victimProfile.getSkillLevel(skillType);
//Should we really care about negative skill levels?
if (victimSkillLevel <= 0 || victimSkillLevel < killerSkillLevel / 2) {
continue;
}

View File

@ -14,6 +14,7 @@ import com.gmail.nossr50.skills.utilities.SkillType;
public final class Leaderboard {
private static HashMap<SkillType, List<PlayerStat>> playerStatHash = new HashMap<SkillType, List<PlayerStat>>();
private static List<PlayerStat> powerLevels = new ArrayList<PlayerStat>();
private static long lastUpdate = 0;
private Leaderboard() {}
@ -29,7 +30,7 @@ public final class Leaderboard {
lastUpdate = System.currentTimeMillis(); //Log when the last update was run
//Initialize lists
List<PlayerStat> mining, woodcutting, herbalism, excavation, acrobatics, repair, swords, axes, archery, unarmed, taming, fishing, powerlevel;
List<PlayerStat> mining, woodcutting, herbalism, excavation, acrobatics, repair, swords, axes, archery, unarmed, taming, fishing;
mining = new ArrayList<PlayerStat>();
woodcutting = new ArrayList<PlayerStat>();
@ -43,7 +44,6 @@ public final class Leaderboard {
unarmed = new ArrayList<PlayerStat>();
taming = new ArrayList<PlayerStat>();
fishing = new ArrayList<PlayerStat>();
powerlevel = new ArrayList<PlayerStat>();
//Read from the FlatFile database and fill our arrays with information
try {
@ -125,7 +125,7 @@ public final class Leaderboard {
powerLevel += Integer.valueOf(character[34]);
}
powerlevel.add(new PlayerStat(p, powerLevel));
powerLevels.add(new PlayerStat(p, powerLevel));
}
in.close();
}
@ -146,7 +146,7 @@ public final class Leaderboard {
Collections.sort(acrobatics, c);
Collections.sort(taming, c);
Collections.sort(fishing, c);
Collections.sort(powerlevel, c);
Collections.sort(powerLevels, c);
playerStatHash.put(SkillType.MINING, mining);
playerStatHash.put(SkillType.WOODCUTTING, woodcutting);
@ -160,7 +160,6 @@ public final class Leaderboard {
playerStatHash.put(SkillType.ACROBATICS, acrobatics);
playerStatHash.put(SkillType.TAMING, taming);
playerStatHash.put(SkillType.FISHING, fishing);
playerStatHash.put(SkillType.ALL, powerlevel);
}
/**
@ -170,15 +169,20 @@ public final class Leaderboard {
* @param pageNumber Which page in the leaderboards to retrieve
* @return the requested leaderboard information
*/
public static String[] retrieveInfo(SkillType skillType, int pageNumber) {
public static String[] retrieveInfo(String skillType, int pageNumber) {
String[] info = new String[10];
List<PlayerStat> statsList;
List<PlayerStat> statsList = playerStatHash.get(skillType);
if (skillType.equalsIgnoreCase("all")) {
statsList = powerLevels;
}
else {
statsList = playerStatHash.get(SkillType.getSkill(skillType));
}
if(statsList != null) {
int destination;
//How many lines to skip through
// How many lines to skip through
if (pageNumber == 1) {
destination = 0;
}
@ -188,23 +192,39 @@ public final class Leaderboard {
int currentPos = 0;
for(PlayerStat ps : statsList) {
if(currentPos == 10)
for (PlayerStat ps : statsList) {
if (currentPos == 10) {
break;
if(destination > 1) {
}
if (destination > 1) {
destination--;
continue;
}
info[currentPos] = ps.name+":"+ps.statVal;
info[currentPos] = ps.name + ":" + ps.statVal;
currentPos++;
}
} else {
info[0] = "DummyPlayer:0"; //Coming up with a better solution soon...
return info;
}
return info;
public static int[] getPlayerRank(String playerName) {
int currentPos = 1;
if (powerLevels != null) {
for (PlayerStat stat : powerLevels) {
if (stat.name.equalsIgnoreCase(playerName)) {
return new int[] {currentPos, stat.statVal};
}
currentPos++;
continue;
}
return new int[] {0, 0};
}
return new int[] {0, 0};
}
public static int[] getPlayerRank(String playerName, SkillType skillType) {