mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-22 21:26:46 +01:00
FFS Leaderboard rewrites, and new mcrank command.
This commit is contained in:
parent
bbbd12d461
commit
6bbdbee669
@ -10,10 +10,12 @@ Key:
|
|||||||
Version 1.3.13-dev
|
Version 1.3.13-dev
|
||||||
! Overall SQL query improvements
|
! Overall SQL query improvements
|
||||||
! Reduced number of SQL queries for mcTop command from 11 to 1, speeding it up immensely
|
! Reduced number of SQL queries for mcTop command from 11 to 1, speeding it up immensely
|
||||||
|
! Changed FFS Leaderboards to hold information in memory rather than doing IO work (optimizations)
|
||||||
+ Added task to prune old and powerless users from the SQL database.
|
+ Added task to prune old and powerless users from the SQL database.
|
||||||
*** WARNING: THIS WILL RUN AUTOMATICALLY ON YOUR DB. IF YOU ARE WORRIED ***
|
*** WARNING: THIS WILL RUN AUTOMATICALLY ON YOUR DB. IF YOU ARE WORRIED ***
|
||||||
*** ABOUT DATA LOSS, BACK UP YOUR SQL DATA BEFORE INSTALLING THIS BUILD ***
|
*** ABOUT DATA LOSS, BACK UP YOUR SQL DATA BEFORE INSTALLING THIS BUILD ***
|
||||||
+ Added Craftbukkit 1.4.6 compatibility
|
+ Added Craftbukkit 1.4.6 compatibility
|
||||||
|
+ Added new /mcrank command for showing a players leader board ranking for all skills in one place
|
||||||
+ Added a configurable durability cap for ArmorImpact to advanced.yml
|
+ Added a configurable durability cap for ArmorImpact to advanced.yml
|
||||||
+ Added the version number to /mcmmo
|
+ Added the version number to /mcmmo
|
||||||
+ Added bats, giants, witches, withers, and wither skeletons to the mcMMO combat experience list, and makes their experience drops configurable
|
+ Added bats, giants, witches, withers, and wither skeletons to the mcMMO combat experience list, and makes their experience drops configurable
|
||||||
|
@ -10,6 +10,7 @@ import org.bukkit.command.CommandSender;
|
|||||||
|
|
||||||
import com.gmail.nossr50.mcMMO;
|
import com.gmail.nossr50.mcMMO;
|
||||||
import com.gmail.nossr50.config.Config;
|
import com.gmail.nossr50.config.Config;
|
||||||
|
import com.gmail.nossr50.datatypes.SkillType;
|
||||||
import com.gmail.nossr50.locale.LocaleLoader;
|
import com.gmail.nossr50.locale.LocaleLoader;
|
||||||
import com.gmail.nossr50.util.Database;
|
import com.gmail.nossr50.util.Database;
|
||||||
import com.gmail.nossr50.util.Leaderboard;
|
import com.gmail.nossr50.util.Leaderboard;
|
||||||
@ -105,7 +106,9 @@ public class MctopCommand implements CommandExecutor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void flatfileDisplay(int page, String skill, CommandSender sender) {
|
private void flatfileDisplay(int page, String skill, CommandSender sender) {
|
||||||
String[] info = Leaderboard.retrieveInfo(skill, page);
|
Leaderboard.updateLeaderboards(); //Make sure we have the latest information
|
||||||
|
SkillType skillType = SkillType.getSkill(skill);
|
||||||
|
String[] info = Leaderboard.retrieveInfo(skillType, page);
|
||||||
|
|
||||||
if (skill.equals("ALL")) {
|
if (skill.equals("ALL")) {
|
||||||
sender.sendMessage(LocaleLoader.getString("Commands.PowerLevel.Leaderboard"));
|
sender.sendMessage(LocaleLoader.getString("Commands.PowerLevel.Leaderboard"));
|
||||||
|
@ -80,6 +80,7 @@ public class Config extends ConfigLoader {
|
|||||||
public boolean getCommandXPLockEnabled() { return config.getBoolean("Commands.xplock.Enabled", true); }
|
public boolean getCommandXPLockEnabled() { return config.getBoolean("Commands.xplock.Enabled", true); }
|
||||||
public boolean getCommandXPRateEnabled() { return config.getBoolean("Commands.xprate.Enabled", true); }
|
public boolean getCommandXPRateEnabled() { return config.getBoolean("Commands.xprate.Enabled", true); }
|
||||||
public boolean getCommandMCTopEnabled() { return config.getBoolean("Commands.mctop.Enabled", true); }
|
public boolean getCommandMCTopEnabled() { return config.getBoolean("Commands.mctop.Enabled", true); }
|
||||||
|
public boolean getCommandMCRankEnabled() { return config.getBoolean("Commands.mcrank.Enabled", true); }
|
||||||
public boolean getCommandAddXPEnabled() { return config.getBoolean("Commands.addxp.Enabled", true); }
|
public boolean getCommandAddXPEnabled() { return config.getBoolean("Commands.addxp.Enabled", true); }
|
||||||
public boolean getCommandAddLevelsEnabled() { return config.getBoolean("Commands.addlevels.Enabled", true); }
|
public boolean getCommandAddLevelsEnabled() { return config.getBoolean("Commands.addlevels.Enabled", true); }
|
||||||
public boolean getCommandMCAbilityEnabled() { return config.getBoolean("Commands.mcability.Enabled", true); }
|
public boolean getCommandMCAbilityEnabled() { return config.getBoolean("Commands.mcability.Enabled", true); }
|
||||||
|
@ -117,6 +117,19 @@ public enum SkillType {
|
|||||||
public double getXpModifier() {
|
public double getXpModifier() {
|
||||||
return xpModifier;
|
return xpModifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static SkillType getSkill(String skillName) {
|
||||||
|
if(skillName.equalsIgnoreCase("powerlevel") || skillName.equalsIgnoreCase("all")) {
|
||||||
|
return SkillType.ALL;
|
||||||
|
} else {
|
||||||
|
for(SkillType st : SkillType.values()) {
|
||||||
|
if(st.name().equalsIgnoreCase(skillName))
|
||||||
|
return st;
|
||||||
|
}
|
||||||
|
System.out.println("[DEBUG] Invalid mcMMO skill ("+skillName+")");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the skill level for this skill.
|
* Get the skill level for this skill.
|
||||||
|
@ -27,6 +27,7 @@ import com.gmail.nossr50.commands.mc.MccCommand;
|
|||||||
import com.gmail.nossr50.commands.mc.McgodCommand;
|
import com.gmail.nossr50.commands.mc.McgodCommand;
|
||||||
import com.gmail.nossr50.commands.mc.McmmoCommand;
|
import com.gmail.nossr50.commands.mc.McmmoCommand;
|
||||||
import com.gmail.nossr50.commands.mc.McpurgeCommand;
|
import com.gmail.nossr50.commands.mc.McpurgeCommand;
|
||||||
|
import com.gmail.nossr50.commands.mc.McrankCommand;
|
||||||
import com.gmail.nossr50.commands.mc.McrefreshCommand;
|
import com.gmail.nossr50.commands.mc.McrefreshCommand;
|
||||||
import com.gmail.nossr50.commands.mc.McremoveCommand;
|
import com.gmail.nossr50.commands.mc.McremoveCommand;
|
||||||
import com.gmail.nossr50.commands.mc.MctopCommand;
|
import com.gmail.nossr50.commands.mc.MctopCommand;
|
||||||
@ -172,13 +173,13 @@ public class mcMMO extends JavaPlugin {
|
|||||||
|
|
||||||
PluginDescriptionFile pdfFile = getDescription();
|
PluginDescriptionFile pdfFile = getDescription();
|
||||||
|
|
||||||
//Setup the leaderboards
|
//Setup the leader boards
|
||||||
if (configInstance.getUseMySQL()) {
|
if (configInstance.getUseMySQL()) {
|
||||||
database = new Database(this);
|
database = new Database(this);
|
||||||
database.createStructure();
|
database.createStructure();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Leaderboard.makeLeaderboards();
|
Leaderboard.updateLeaderboards();
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Player player : getServer().getOnlinePlayers()) {
|
for (Player player : getServer().getOnlinePlayers()) {
|
||||||
@ -260,7 +261,6 @@ public class mcMMO extends JavaPlugin {
|
|||||||
mainDirectory = getDataFolder().getPath() + File.separator;
|
mainDirectory = getDataFolder().getPath() + File.separator;
|
||||||
flatFileDirectory = mainDirectory + "FlatFileStuff" + File.separator;
|
flatFileDirectory = mainDirectory + "FlatFileStuff" + File.separator;
|
||||||
usersFile = flatFileDirectory + "mcmmo.users";
|
usersFile = flatFileDirectory + "mcmmo.users";
|
||||||
leaderboardDirectory = flatFileDirectory + "Leaderboards" + File.separator;
|
|
||||||
modDirectory = mainDirectory + "ModConfigs" + File.separator;
|
modDirectory = mainDirectory + "ModConfigs" + File.separator;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -392,6 +392,10 @@ public class mcMMO extends JavaPlugin {
|
|||||||
if (configInstance.getCommandMCTopEnabled()) {
|
if (configInstance.getCommandMCTopEnabled()) {
|
||||||
getCommand("mctop").setExecutor(new MctopCommand());
|
getCommand("mctop").setExecutor(new MctopCommand());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(configInstance.getCommandMCRankEnabled()) {
|
||||||
|
getCommand("mcrank").setExecutor(new McrankCommand());
|
||||||
|
}
|
||||||
|
|
||||||
if (configInstance.getCommandMCStatsEnabled()) {
|
if (configInstance.getCommandMCStatsEnabled()) {
|
||||||
getCommand("mcstats").setExecutor(new McstatsCommand());
|
getCommand("mcstats").setExecutor(new McstatsCommand());
|
||||||
@ -528,10 +532,6 @@ public class mcMMO extends JavaPlugin {
|
|||||||
return usersFile;
|
return usersFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getLeaderboardDirectory() {
|
|
||||||
return leaderboardDirectory;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getModDirectory() {
|
public static String getModDirectory() {
|
||||||
return modDirectory;
|
return modDirectory;
|
||||||
}
|
}
|
||||||
|
@ -1,45 +1,44 @@
|
|||||||
package com.gmail.nossr50.util;
|
package com.gmail.nossr50.util;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileReader;
|
import java.io.FileReader;
|
||||||
import java.io.FileWriter;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import com.gmail.nossr50.mcMMO;
|
import com.gmail.nossr50.mcMMO;
|
||||||
import com.gmail.nossr50.config.Config;
|
|
||||||
import com.gmail.nossr50.datatypes.PlayerStat;
|
import com.gmail.nossr50.datatypes.PlayerStat;
|
||||||
import com.gmail.nossr50.datatypes.SkillType;
|
import com.gmail.nossr50.datatypes.SkillType;
|
||||||
|
|
||||||
public class Leaderboard {
|
public class Leaderboard {
|
||||||
private static mcMMO plugin = mcMMO.p;
|
private static mcMMO plugin = mcMMO.p;
|
||||||
private static String leaderboardsDirectory = mcMMO.getLeaderboardDirectory();
|
|
||||||
private final static String location = mcMMO.getUsersFile();
|
private final static String location = mcMMO.getUsersFile();
|
||||||
|
private static HashMap<SkillType, List<PlayerStat>> playerStatHash = new HashMap<SkillType, List<PlayerStat>>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create the leaderboards.
|
* Update the leader boards.
|
||||||
*/
|
*/
|
||||||
public static void makeLeaderboards() {
|
public static void updateLeaderboards() {
|
||||||
//Make Lists
|
//Initialize lists
|
||||||
List<PlayerStat> Mining = new ArrayList<PlayerStat>();
|
List<PlayerStat> mining, woodcutting, herbalism, excavation, acrobatics, repair, swords, axes, archery, unarmed, taming, fishing, powerlevel;
|
||||||
List<PlayerStat> WoodCutting = new ArrayList<PlayerStat>();
|
|
||||||
List<PlayerStat> Herbalism = new ArrayList<PlayerStat>();
|
|
||||||
List<PlayerStat> Excavation = new ArrayList<PlayerStat>();
|
|
||||||
List<PlayerStat> Acrobatics = new ArrayList<PlayerStat>();
|
|
||||||
List<PlayerStat> Repair = new ArrayList<PlayerStat>();
|
|
||||||
List<PlayerStat> Swords = new ArrayList<PlayerStat>();
|
|
||||||
List<PlayerStat> Axes = new ArrayList<PlayerStat>();
|
|
||||||
List<PlayerStat> Archery = new ArrayList<PlayerStat>();
|
|
||||||
List<PlayerStat> Unarmed = new ArrayList<PlayerStat>();
|
|
||||||
List<PlayerStat> Taming = new ArrayList<PlayerStat>();
|
|
||||||
List<PlayerStat> Fishing = new ArrayList<PlayerStat>();
|
|
||||||
List<PlayerStat> PowerLevel = new ArrayList<PlayerStat>();
|
|
||||||
|
|
||||||
//Add Data To Lists
|
mining = new ArrayList<PlayerStat>();
|
||||||
|
woodcutting = new ArrayList<PlayerStat>();
|
||||||
|
herbalism = new ArrayList<PlayerStat>();
|
||||||
|
excavation = new ArrayList<PlayerStat>();
|
||||||
|
acrobatics = new ArrayList<PlayerStat>();
|
||||||
|
repair = new ArrayList<PlayerStat>();
|
||||||
|
swords = new ArrayList<PlayerStat>();
|
||||||
|
axes = new ArrayList<PlayerStat>();
|
||||||
|
archery = new ArrayList<PlayerStat>();
|
||||||
|
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 {
|
try {
|
||||||
FileReader file = new FileReader(location);
|
FileReader file = new FileReader(location);
|
||||||
BufferedReader in = new BufferedReader(file);
|
BufferedReader in = new BufferedReader(file);
|
||||||
@ -52,7 +51,7 @@ public class Leaderboard {
|
|||||||
String p = character[0];
|
String p = character[0];
|
||||||
int powerLevel = 0;
|
int powerLevel = 0;
|
||||||
|
|
||||||
//Prevent the same player from being added multiple times
|
//Prevent the same player from being added multiple times (I'd like to note that this shouldn't happen...)
|
||||||
if (players.contains(p)) {
|
if (players.contains(p)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -60,66 +59,66 @@ public class Leaderboard {
|
|||||||
players.add(p);
|
players.add(p);
|
||||||
|
|
||||||
if (character.length > 1 && Misc.isInt(character[1])) {
|
if (character.length > 1 && Misc.isInt(character[1])) {
|
||||||
Mining.add(new PlayerStat(p, Integer.valueOf(character[1])));
|
mining.add(new PlayerStat(p, Integer.valueOf(character[1])));
|
||||||
powerLevel += Integer.valueOf(character[1]);
|
powerLevel += Integer.valueOf(character[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (character.length > 5 && Misc.isInt(character[5])) {
|
if (character.length > 5 && Misc.isInt(character[5])) {
|
||||||
WoodCutting.add(new PlayerStat(p, Integer.valueOf(character[5])));
|
woodcutting.add(new PlayerStat(p, Integer.valueOf(character[5])));
|
||||||
powerLevel += Integer.valueOf(character[5]);
|
powerLevel += Integer.valueOf(character[5]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (character.length > 7 && Misc.isInt(character[7])) {
|
if (character.length > 7 && Misc.isInt(character[7])) {
|
||||||
Repair.add(new PlayerStat(p, Integer.valueOf(character[7])));
|
repair.add(new PlayerStat(p, Integer.valueOf(character[7])));
|
||||||
powerLevel += Integer.valueOf(character[7]);
|
powerLevel += Integer.valueOf(character[7]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (character.length > 8 && Misc.isInt(character[8])) {
|
if (character.length > 8 && Misc.isInt(character[8])) {
|
||||||
Unarmed.add(new PlayerStat(p, Integer.valueOf(character[8])));
|
unarmed.add(new PlayerStat(p, Integer.valueOf(character[8])));
|
||||||
powerLevel += Integer.valueOf(character[8]);
|
powerLevel += Integer.valueOf(character[8]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (character.length > 9 && Misc.isInt(character[9])) {
|
if (character.length > 9 && Misc.isInt(character[9])) {
|
||||||
Herbalism.add(new PlayerStat(p, Integer.valueOf(character[9])));
|
herbalism.add(new PlayerStat(p, Integer.valueOf(character[9])));
|
||||||
powerLevel += Integer.valueOf(character[9]);
|
powerLevel += Integer.valueOf(character[9]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (character.length > 10 && Misc.isInt(character[10])) {
|
if (character.length > 10 && Misc.isInt(character[10])) {
|
||||||
Excavation.add(new PlayerStat(p, Integer.valueOf(character[10])));
|
excavation.add(new PlayerStat(p, Integer.valueOf(character[10])));
|
||||||
powerLevel += Integer.valueOf(character[10]);
|
powerLevel += Integer.valueOf(character[10]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (character.length > 11 && Misc.isInt(character[11])) {
|
if (character.length > 11 && Misc.isInt(character[11])) {
|
||||||
Archery.add(new PlayerStat(p, Integer.valueOf(character[11])));
|
archery.add(new PlayerStat(p, Integer.valueOf(character[11])));
|
||||||
powerLevel += Integer.valueOf(character[11]);
|
powerLevel += Integer.valueOf(character[11]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (character.length > 12 && Misc.isInt(character[12])) {
|
if (character.length > 12 && Misc.isInt(character[12])) {
|
||||||
Swords.add(new PlayerStat(p, Integer.valueOf(character[12])));
|
swords.add(new PlayerStat(p, Integer.valueOf(character[12])));
|
||||||
powerLevel += Integer.valueOf(character[12]);
|
powerLevel += Integer.valueOf(character[12]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (character.length > 13 && Misc.isInt(character[13])) {
|
if (character.length > 13 && Misc.isInt(character[13])) {
|
||||||
Axes.add(new PlayerStat(p, Integer.valueOf(character[13])));
|
axes.add(new PlayerStat(p, Integer.valueOf(character[13])));
|
||||||
powerLevel += Integer.valueOf(character[13]);
|
powerLevel += Integer.valueOf(character[13]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (character.length > 14 && Misc.isInt(character[14])) {
|
if (character.length > 14 && Misc.isInt(character[14])) {
|
||||||
Acrobatics.add(new PlayerStat(p, Integer.valueOf(character[14])));
|
acrobatics.add(new PlayerStat(p, Integer.valueOf(character[14])));
|
||||||
powerLevel += Integer.valueOf(character[14]);
|
powerLevel += Integer.valueOf(character[14]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (character.length > 24 && Misc.isInt(character[24])) {
|
if (character.length > 24 && Misc.isInt(character[24])) {
|
||||||
Taming.add(new PlayerStat(p, Integer.valueOf(character[24])));
|
taming.add(new PlayerStat(p, Integer.valueOf(character[24])));
|
||||||
powerLevel += Integer.valueOf(character[24]);
|
powerLevel += Integer.valueOf(character[24]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (character.length > 34 && Misc.isInt(character[34])) {
|
if (character.length > 34 && Misc.isInt(character[34])) {
|
||||||
Fishing.add(new PlayerStat(p, Integer.valueOf(character[34])));
|
fishing.add(new PlayerStat(p, Integer.valueOf(character[34])));
|
||||||
powerLevel += Integer.valueOf(character[34]);
|
powerLevel += Integer.valueOf(character[34]);
|
||||||
}
|
}
|
||||||
|
|
||||||
PowerLevel.add(new PlayerStat(p, powerLevel));
|
powerlevel.add(new PlayerStat(p, powerLevel));
|
||||||
}
|
}
|
||||||
in.close();
|
in.close();
|
||||||
}
|
}
|
||||||
@ -127,101 +126,34 @@ public class Leaderboard {
|
|||||||
plugin.getLogger().severe(("Exception while reading " + location + " (Are you sure you formatted it correctly?)" + e.toString()));
|
plugin.getLogger().severe(("Exception while reading " + location + " (Are you sure you formatted it correctly?)" + e.toString()));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(PowerLevel.isEmpty())
|
|
||||||
return;
|
|
||||||
|
|
||||||
//Sort the leader boards
|
|
||||||
SkillComparator c = new SkillComparator();
|
SkillComparator c = new SkillComparator();
|
||||||
Collections.sort(Mining, c);
|
Collections.sort(mining, c);
|
||||||
Collections.sort(WoodCutting, c);
|
Collections.sort(woodcutting, c);
|
||||||
Collections.sort(Repair, c);
|
Collections.sort(repair, c);
|
||||||
Collections.sort(Unarmed, c);
|
Collections.sort(unarmed, c);
|
||||||
Collections.sort(Herbalism, c);
|
Collections.sort(herbalism, c);
|
||||||
Collections.sort(Excavation, c);
|
Collections.sort(excavation, c);
|
||||||
Collections.sort(Archery, c);
|
Collections.sort(archery, c);
|
||||||
Collections.sort(Swords, c);
|
Collections.sort(swords, c);
|
||||||
Collections.sort(Axes, c);
|
Collections.sort(axes, c);
|
||||||
Collections.sort(Acrobatics, c);
|
Collections.sort(acrobatics, c);
|
||||||
Collections.sort(Taming, c);
|
Collections.sort(taming, c);
|
||||||
Collections.sort(Fishing, c);
|
Collections.sort(fishing, c);
|
||||||
Collections.sort(PowerLevel, c);
|
Collections.sort(powerlevel, c);
|
||||||
|
|
||||||
//Write the leader board files
|
playerStatHash.put(SkillType.MINING, mining);
|
||||||
PlayerStat[] a = new PlayerStat[1];
|
playerStatHash.put(SkillType.WOODCUTTING, woodcutting);
|
||||||
leaderWrite(Mining.toArray(a), SkillType.MINING);
|
playerStatHash.put(SkillType.REPAIR, repair);
|
||||||
leaderWrite(WoodCutting.toArray(a), SkillType.WOODCUTTING);
|
playerStatHash.put(SkillType.UNARMED, unarmed);
|
||||||
leaderWrite(Repair.toArray(a), SkillType.REPAIR);
|
playerStatHash.put(SkillType.HERBALISM, herbalism);
|
||||||
leaderWrite(Unarmed.toArray(a), SkillType.UNARMED);
|
playerStatHash.put(SkillType.EXCAVATION, excavation);
|
||||||
leaderWrite(Herbalism.toArray(a), SkillType.HERBALISM);
|
playerStatHash.put(SkillType.ARCHERY, archery);
|
||||||
leaderWrite(Excavation.toArray(a), SkillType.EXCAVATION);
|
playerStatHash.put(SkillType.SWORDS, swords);
|
||||||
leaderWrite(Archery.toArray(a), SkillType.ARCHERY);
|
playerStatHash.put(SkillType.AXES, axes);
|
||||||
leaderWrite(Swords.toArray(a), SkillType.SWORDS);
|
playerStatHash.put(SkillType.ACROBATICS, acrobatics);
|
||||||
leaderWrite(Axes.toArray(a), SkillType.AXES);
|
playerStatHash.put(SkillType.TAMING, taming);
|
||||||
leaderWrite(Acrobatics.toArray(a), SkillType.ACROBATICS);
|
playerStatHash.put(SkillType.FISHING, fishing);
|
||||||
leaderWrite(Taming.toArray(a), SkillType.TAMING);
|
playerStatHash.put(SkillType.ALL, powerlevel);
|
||||||
leaderWrite(Fishing.toArray(a), SkillType.FISHING);
|
|
||||||
leaderWrite(PowerLevel.toArray(a), SkillType.ALL);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Write to the leaderboards.
|
|
||||||
*
|
|
||||||
* @param ps Stats to write to the leaderboard
|
|
||||||
* @param skillType Skill type to write the leaderboard of
|
|
||||||
*/
|
|
||||||
private static void leaderWrite(PlayerStat[] ps, SkillType skillType) {
|
|
||||||
String theLocation = leaderboardsDirectory + skillType.toString().toLowerCase() + ".mcmmo";
|
|
||||||
File theDir = new File(theLocation);
|
|
||||||
|
|
||||||
//CHECK IF THE FILE EXISTS
|
|
||||||
if (!theDir.exists()) {
|
|
||||||
FileWriter writer = null;
|
|
||||||
|
|
||||||
try {
|
|
||||||
writer = new FileWriter(theLocation);
|
|
||||||
}
|
|
||||||
catch (Exception e) {
|
|
||||||
plugin.getLogger().severe(("Exception while creating " + theLocation + e.toString()));
|
|
||||||
}
|
|
||||||
finally {
|
|
||||||
try {
|
|
||||||
if (writer != null) {
|
|
||||||
writer.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (IOException e) {
|
|
||||||
plugin.getLogger().severe("Exception while closing writer for " + theLocation + e.toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
try {
|
|
||||||
FileReader file = new FileReader(theLocation);
|
|
||||||
BufferedReader in = new BufferedReader(file);
|
|
||||||
StringBuilder writer = new StringBuilder();
|
|
||||||
|
|
||||||
for (PlayerStat p : ps) {
|
|
||||||
if (p.name.equals("$mcMMO_DummyInfo")) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (p.statVal == 0) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
writer.append(p.name + ":" + p.statVal);
|
|
||||||
writer.append("\r\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
in.close();
|
|
||||||
FileWriter out = new FileWriter(theLocation);
|
|
||||||
out.write(writer.toString());
|
|
||||||
out.close();
|
|
||||||
}
|
|
||||||
catch (Exception e) {
|
|
||||||
plugin.getLogger().severe("Exception while writing to " + theLocation + " (Are you sure you formatted it correctly?)" + e.toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -231,95 +163,63 @@ public class Leaderboard {
|
|||||||
* @param pagenumber Which page in the leaderboards to retrieve
|
* @param pagenumber Which page in the leaderboards to retrieve
|
||||||
* @return the requested leaderboard information
|
* @return the requested leaderboard information
|
||||||
*/
|
*/
|
||||||
public static String[] retrieveInfo(String skillName, int pagenumber) {
|
public static String[] retrieveInfo(SkillType skillType, int pagenumber) {
|
||||||
String theLocation = leaderboardsDirectory + skillName.toLowerCase() + ".mcmmo";
|
String[] info = new String[10];
|
||||||
|
|
||||||
try {
|
List<PlayerStat> statsList = playerStatHash.get(skillType);
|
||||||
FileReader file = new FileReader(theLocation);
|
|
||||||
BufferedReader in = new BufferedReader(file);
|
if(statsList != null) {
|
||||||
int destination;
|
int destination;
|
||||||
|
|
||||||
//How many lines to skip through
|
//How many lines to skip through
|
||||||
if (pagenumber == 1) {
|
if (pagenumber == 1) {
|
||||||
destination = 0;
|
destination = 0;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
destination = (pagenumber * 10) - 9;
|
destination = (pagenumber * 10) - 9;
|
||||||
}
|
}
|
||||||
|
|
||||||
int x = 0; //how many lines we've gone through
|
int currentPos = 0;
|
||||||
int y = 0; //going through the lines
|
|
||||||
String line = "";
|
for(PlayerStat ps : statsList) {
|
||||||
String[] info = new String[10]; //what to return
|
if(currentPos == 10)
|
||||||
|
break;
|
||||||
while ((line = in.readLine()) != null && y < 10) {
|
if(destination > 1) {
|
||||||
x++;
|
destination--;
|
||||||
|
continue;
|
||||||
if (x >= destination && y < 10) {
|
}
|
||||||
info[y] = line.toString();
|
|
||||||
y++;
|
info[currentPos] = ps.name+":"+ps.statVal;
|
||||||
}
|
currentPos++;
|
||||||
}
|
}
|
||||||
|
|
||||||
in.close();
|
} else {
|
||||||
return info;
|
info[0] = "DummyPlayer:0"; //Coming up with a better solution soon...
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
|
||||||
plugin.getLogger().severe("Exception while reading " + theLocation + " (Are you sure you formatted it correctly?)" + e.toString());
|
return info;
|
||||||
}
|
|
||||||
|
|
||||||
return null; //Shouldn't get here
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public static int getPlayerRank(String playerName, SkillType skillType) {
|
||||||
* Update the leaderboards.
|
int currentPos = 1;
|
||||||
*
|
List<PlayerStat> statsList = playerStatHash.get(skillType);
|
||||||
* @param ps Stats to update the leaderboard with.
|
|
||||||
* @param skillType Skill whose leaderboard is being updated.
|
if(statsList != null) {
|
||||||
*/
|
for(PlayerStat ps : statsList) {
|
||||||
public static void updateLeaderboard(PlayerStat ps, SkillType skillType) {
|
if(ps.name.equalsIgnoreCase(playerName)) {
|
||||||
if (Config.getInstance().getUseMySQL()) {
|
return currentPos;
|
||||||
return;
|
} else {
|
||||||
}
|
currentPos++;
|
||||||
|
continue;
|
||||||
String theLocation = leaderboardsDirectory + skillType.toString().toLowerCase() + ".mcmmo";
|
}
|
||||||
|
}
|
||||||
try {
|
|
||||||
FileReader file = new FileReader(theLocation);
|
return 0;
|
||||||
BufferedReader in = new BufferedReader(file);
|
} else {
|
||||||
StringBuilder writer = new StringBuilder();
|
return 0;
|
||||||
String line = "";
|
|
||||||
Boolean inserted = false;
|
|
||||||
|
|
||||||
while ((line = in.readLine()) != null) {
|
|
||||||
|
|
||||||
//Insert the player into the line before it finds a smaller one
|
|
||||||
if (Integer.valueOf(line.split(":")[1]) < ps.statVal && !inserted) {
|
|
||||||
writer.append(ps.name + ":" + ps.statVal).append("\r\n");
|
|
||||||
inserted = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Write anything that isn't the player already in the file so we remove the duplicate
|
|
||||||
if (!line.split(":")[0].equalsIgnoreCase(ps.name)) {
|
|
||||||
writer.append(line).append("\r\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!inserted) {
|
|
||||||
writer.append(ps.name + ":" + ps.statVal).append("\r\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
in.close();
|
|
||||||
|
|
||||||
//Write the new file
|
|
||||||
FileWriter out = new FileWriter(theLocation);
|
|
||||||
out.write(writer.toString());
|
|
||||||
out.close();
|
|
||||||
}
|
|
||||||
catch (Exception e) {
|
|
||||||
plugin.getLogger().severe("Exception while writing to " + theLocation + " (Are you sure you formatted it correctly?)" + e.toString());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class SkillComparator implements Comparator<PlayerStat> {
|
private static class SkillComparator implements Comparator<PlayerStat> {
|
||||||
@Override
|
@Override
|
||||||
public int compare(PlayerStat o1, PlayerStat o2) {
|
public int compare(PlayerStat o1, PlayerStat o2) {
|
||||||
|
@ -189,28 +189,6 @@ public class Skills {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Update the leaderboards.
|
|
||||||
*
|
|
||||||
* @param skillType The skill to update the leaderboards for
|
|
||||||
* @param player The player whose skill to update
|
|
||||||
*/
|
|
||||||
public static void processLeaderboardUpdate(SkillType skillType, Player player) {
|
|
||||||
McMMOPlayer mcMMOPlayer = Users.getPlayer(player);
|
|
||||||
PlayerProfile profile = mcMMOPlayer.getProfile();
|
|
||||||
PlayerStat ps = new PlayerStat();
|
|
||||||
|
|
||||||
if (skillType != SkillType.ALL) {
|
|
||||||
ps.statVal = profile.getSkillLevel(skillType);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
ps.statVal = mcMMOPlayer.getPowerLevel();
|
|
||||||
}
|
|
||||||
|
|
||||||
ps.name = player.getName();
|
|
||||||
Leaderboard.updateLeaderboard(ps, skillType);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check the XP of a skill.
|
* Check the XP of a skill.
|
||||||
*
|
*
|
||||||
@ -237,11 +215,6 @@ public class Skills {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Config.getInstance().getUseMySQL()) {
|
|
||||||
processLeaderboardUpdate(skillType, player);
|
|
||||||
processLeaderboardUpdate(SkillType.ALL, player);
|
|
||||||
}
|
|
||||||
|
|
||||||
String capitalized = Misc.getCapitalized(skillType.toString());
|
String capitalized = Misc.getCapitalized(skillType.toString());
|
||||||
|
|
||||||
/* Spout Stuff */
|
/* Spout Stuff */
|
||||||
|
@ -20,7 +20,6 @@ public class Users {
|
|||||||
*/
|
*/
|
||||||
public static void loadUsers() {
|
public static void loadUsers() {
|
||||||
new File(mcMMO.getFlatFileDirectory()).mkdir();
|
new File(mcMMO.getFlatFileDirectory()).mkdir();
|
||||||
new File(mcMMO.getLeaderboardDirectory()).mkdir();
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
new File(mcMMO.getUsersFile()).createNewFile();
|
new File(mcMMO.getUsersFile()).createNewFile();
|
||||||
|
@ -23,7 +23,6 @@ public class ZipLibrary {
|
|||||||
private static File UsersFile = new File(mcMMO.getUsersFile());
|
private static File UsersFile = new File(mcMMO.getUsersFile());
|
||||||
private static File ConfigFile = new File(mcMMO.getMainDirectory() + "config.yml");
|
private static File ConfigFile = new File(mcMMO.getMainDirectory() + "config.yml");
|
||||||
private static File TreasuresFile = new File(mcMMO.getMainDirectory() + "treasures.yml");
|
private static File TreasuresFile = new File(mcMMO.getMainDirectory() + "treasures.yml");
|
||||||
private static File Leaderboards = new File(mcMMO.getLeaderboardDirectory());
|
|
||||||
|
|
||||||
public static void mcMMObackup() throws IOException {
|
public static void mcMMObackup() throws IOException {
|
||||||
if (Config.getInstance().getUseMySQL()) {
|
if (Config.getInstance().getUseMySQL()) {
|
||||||
@ -50,7 +49,6 @@ public class ZipLibrary {
|
|||||||
sources.add(UsersFile);
|
sources.add(UsersFile);
|
||||||
sources.add(ConfigFile);
|
sources.add(ConfigFile);
|
||||||
sources.add(TreasuresFile);
|
sources.add(TreasuresFile);
|
||||||
sources.add(Leaderboards);
|
|
||||||
|
|
||||||
if (ModFileDirectory.exists()) {
|
if (ModFileDirectory.exists()) {
|
||||||
sources.add(ModFileDirectory);
|
sources.add(ModFileDirectory);
|
||||||
|
@ -301,6 +301,8 @@ Commands:
|
|||||||
Enabled: true
|
Enabled: true
|
||||||
mctop:
|
mctop:
|
||||||
Enabled: true
|
Enabled: true
|
||||||
|
mcrank:
|
||||||
|
Enabled: true
|
||||||
xplock:
|
xplock:
|
||||||
Enabled: true
|
Enabled: true
|
||||||
inspect:
|
inspect:
|
||||||
|
@ -38,6 +38,9 @@ commands:
|
|||||||
mctop:
|
mctop:
|
||||||
aliases: []
|
aliases: []
|
||||||
description: Shows leader boards for mcMMO
|
description: Shows leader boards for mcMMO
|
||||||
|
mcrank:
|
||||||
|
aliases: []
|
||||||
|
description: Show your individual ranking in mcMMO
|
||||||
addxp:
|
addxp:
|
||||||
aliases: []
|
aliases: []
|
||||||
description: Add XP to a user
|
description: Add XP to a user
|
||||||
|
Loading…
Reference in New Issue
Block a user