2013-02-05 12:56:31 -05:00
package com.gmail.nossr50.database ;
2012-04-27 02:47:11 -07:00
2019-02-16 16:09:48 -08:00
import com.gmail.nossr50.config.MainConfig ;
2013-06-04 12:14:43 -04:00
import com.gmail.nossr50.datatypes.MobHealthbarType ;
2013-08-22 09:11:33 -04:00
import com.gmail.nossr50.datatypes.database.DatabaseType ;
2013-03-01 00:52:01 -05:00
import com.gmail.nossr50.datatypes.database.PlayerStat ;
2013-06-04 12:14:43 -04:00
import com.gmail.nossr50.datatypes.player.PlayerProfile ;
2019-01-14 22:11:58 -08:00
import com.gmail.nossr50.datatypes.player.UniqueDataType ;
import com.gmail.nossr50.datatypes.skills.PrimarySkillType ;
import com.gmail.nossr50.datatypes.skills.SuperAbilityType ;
import com.gmail.nossr50.mcMMO ;
2013-06-04 12:14:43 -04:00
import com.gmail.nossr50.util.Misc ;
2014-02-22 09:52:36 -05:00
import com.gmail.nossr50.util.StringUtils ;
2019-01-14 22:11:58 -08:00
import org.bukkit.OfflinePlayer ;
import java.io.* ;
import java.util.* ;
2013-01-21 17:22:54 -05:00
2013-06-04 12:14:43 -04:00
public final class FlatfileDatabaseManager implements DatabaseManager {
2019-01-12 23:54:53 -08:00
private final HashMap < PrimarySkillType , List < PlayerStat > > playerStatHash = new HashMap < PrimarySkillType , List < PlayerStat > > ( ) ;
2013-06-04 12:14:43 -04:00
private final List < PlayerStat > powerLevels = new ArrayList < PlayerStat > ( ) ;
private long lastUpdate = 0 ;
2013-03-01 00:52:01 -05:00
2013-06-04 12:14:43 -04:00
private final long UPDATE_WAIT_TIME = 600000L ; // 10 minutes
private final File usersFile ;
2013-06-28 15:02:58 -07:00
private static final Object fileWritingLock = new Object ( ) ;
2013-01-26 23:01:55 +01:00
2013-06-06 18:01:43 -04:00
protected FlatfileDatabaseManager ( ) {
2013-06-04 12:14:43 -04:00
usersFile = new File ( mcMMO . getUsersFilePath ( ) ) ;
2013-07-01 01:37:24 -04:00
checkStructure ( ) ;
2013-06-04 12:14:43 -04:00
updateLeaderboards ( ) ;
2014-08-01 20:17:15 +02:00
2019-02-25 16:39:49 -08:00
/ * if ( mcMMO . getUpgradeManager ( ) . shouldUpgrade ( UpgradeType . ADD_UUIDS ) ) {
2014-08-01 20:17:15 +02:00
new UUIDUpdateAsyncTask ( mcMMO . p , getStoredUsers ( ) ) . runTaskAsynchronously ( mcMMO . p ) ;
2019-02-25 16:39:49 -08:00
} * /
2013-06-04 12:14:43 -04:00
}
2013-03-01 00:52:01 -05:00
2013-06-04 12:14:43 -04:00
public void purgePowerlessUsers ( ) {
int purgedUsers = 0 ;
2013-03-01 00:52:01 -05:00
2013-06-04 12:14:43 -04:00
mcMMO . p . getLogger ( ) . info ( " Purging powerless users... " ) ;
2012-04-27 02:47:11 -07:00
2013-06-28 15:02:58 -07:00
BufferedReader in = null ;
FileWriter out = null ;
String usersFilePath = mcMMO . getUsersFilePath ( ) ;
// This code is O(n) instead of O(n²)
synchronized ( fileWritingLock ) {
try {
in = new BufferedReader ( new FileReader ( usersFilePath ) ) ;
StringBuilder writer = new StringBuilder ( ) ;
2014-01-20 13:58:40 -08:00
String line ;
2013-06-28 15:02:58 -07:00
while ( ( line = in . readLine ( ) ) ! = null ) {
String [ ] character = line . split ( " : " ) ;
2019-01-12 23:54:53 -08:00
Map < PrimarySkillType , Integer > skills = getSkillMapFromLine ( character ) ;
2013-06-28 15:02:58 -07:00
boolean powerless = true ;
for ( int skill : skills . values ( ) ) {
2019-03-13 13:09:27 -07:00
if ( skill > mcMMO . getPlayerLevelingSettings ( ) . getStartingLevel ( ) ) {
2013-06-28 15:02:58 -07:00
powerless = false ;
break ;
}
}
// If they're still around, rewrite them to the file.
if ( ! powerless ) {
writer . append ( line ) . append ( " \ r \ n " ) ;
}
else {
purgedUsers + + ;
}
}
// Write the new file
out = new FileWriter ( usersFilePath ) ;
out . write ( writer . toString ( ) ) ;
}
catch ( IOException e ) {
mcMMO . p . getLogger ( ) . severe ( " Exception while reading " + usersFilePath + " (Are you sure you formatted it correctly?) " + e . toString ( ) ) ;
}
finally {
2014-08-01 13:35:36 -04:00
if ( in ! = null ) {
try {
in . close ( ) ;
}
catch ( IOException e ) {
// Ignore
}
}
if ( out ! = null ) {
try {
out . close ( ) ;
}
catch ( IOException e ) {
// Ignore
}
}
2013-06-04 12:14:43 -04:00
}
}
2013-01-14 13:09:11 -08:00
2013-06-04 12:14:43 -04:00
mcMMO . p . getLogger ( ) . info ( " Purged " + purgedUsers + " users from the database. " ) ;
}
2012-04-27 02:47:11 -07:00
2013-06-04 12:14:43 -04:00
public void purgeOldUsers ( ) {
int removedPlayers = 0 ;
long currentTime = System . currentTimeMillis ( ) ;
2013-01-09 22:43:21 -05:00
2013-06-04 12:14:43 -04:00
mcMMO . p . getLogger ( ) . info ( " Purging old users... " ) ;
2012-04-27 02:47:11 -07:00
2013-06-28 15:02:58 -07:00
BufferedReader in = null ;
FileWriter out = null ;
String usersFilePath = mcMMO . getUsersFilePath ( ) ;
// This code is O(n) instead of O(n²)
synchronized ( fileWritingLock ) {
try {
in = new BufferedReader ( new FileReader ( usersFilePath ) ) ;
StringBuilder writer = new StringBuilder ( ) ;
2014-01-20 13:58:40 -08:00
String line ;
2013-06-28 15:02:58 -07:00
while ( ( line = in . readLine ( ) ) ! = null ) {
String [ ] character = line . split ( " : " ) ;
2015-11-12 19:10:09 -05:00
String name = character [ USERNAME ] ;
2013-07-31 15:02:01 -07:00
long lastPlayed = 0 ;
boolean rewrite = false ;
try {
lastPlayed = Long . parseLong ( character [ 37 ] ) * Misc . TIME_CONVERSION_FACTOR ;
2013-06-28 15:02:58 -07:00
}
2013-10-06 10:25:28 +02:00
catch ( NumberFormatException e ) {
2019-01-15 01:11:33 -08:00
e . printStackTrace ( ) ;
2013-10-06 10:25:28 +02:00
}
2013-07-31 15:02:01 -07:00
if ( lastPlayed = = 0 ) {
2013-10-18 15:14:10 +02:00
OfflinePlayer player = mcMMO . p . getServer ( ) . getOfflinePlayer ( name ) ;
2013-07-31 15:02:01 -07:00
lastPlayed = player . getLastPlayed ( ) ;
rewrite = true ;
2013-06-28 15:02:58 -07:00
}
2013-07-31 15:02:01 -07:00
if ( currentTime - lastPlayed > PURGE_TIME ) {
2013-06-28 15:02:58 -07:00
removedPlayers + + ;
}
2013-07-31 15:02:01 -07:00
else {
if ( rewrite ) {
// Rewrite their data with a valid time
character [ 37 ] = Long . toString ( lastPlayed ) ;
String newLine = org . apache . commons . lang . StringUtils . join ( character , " : " ) ;
writer . append ( newLine ) . append ( " \ r \ n " ) ;
}
else {
writer . append ( line ) . append ( " \ r \ n " ) ;
}
}
2013-06-28 15:02:58 -07:00
}
// Write the new file
out = new FileWriter ( usersFilePath ) ;
out . write ( writer . toString ( ) ) ;
}
catch ( IOException e ) {
mcMMO . p . getLogger ( ) . severe ( " Exception while reading " + usersFilePath + " (Are you sure you formatted it correctly?) " + e . toString ( ) ) ;
}
finally {
2014-08-01 13:35:36 -04:00
if ( in ! = null ) {
try {
in . close ( ) ;
}
catch ( IOException e ) {
// Ignore
}
}
if ( out ! = null ) {
try {
out . close ( ) ;
}
catch ( IOException e ) {
// Ignore
}
}
2012-04-27 02:47:11 -07:00
}
}
2013-06-04 12:14:43 -04:00
mcMMO . p . getLogger ( ) . info ( " Purged " + removedPlayers + " users from the database. " ) ;
2012-04-27 02:47:11 -07:00
}
2013-06-04 12:14:43 -04:00
public boolean removeUser ( String playerName ) {
2013-02-05 15:29:57 -05:00
boolean worked = false ;
BufferedReader in = null ;
FileWriter out = null ;
String usersFilePath = mcMMO . getUsersFilePath ( ) ;
2013-06-28 15:02:58 -07:00
synchronized ( fileWritingLock ) {
try {
in = new BufferedReader ( new FileReader ( usersFilePath ) ) ;
StringBuilder writer = new StringBuilder ( ) ;
2014-01-20 13:58:40 -08:00
String line ;
2013-06-04 12:14:43 -04:00
2013-06-28 15:02:58 -07:00
while ( ( line = in . readLine ( ) ) ! = null ) {
// Write out the same file but when we get to the player we want to remove, we skip his line.
2015-11-12 19:10:09 -05:00
if ( ! worked & & line . split ( " : " ) [ USERNAME ] . equalsIgnoreCase ( playerName ) ) {
2013-06-28 15:02:58 -07:00
mcMMO . p . getLogger ( ) . info ( " User found, removing... " ) ;
worked = true ;
continue ; // Skip the player
}
2013-02-05 15:29:57 -05:00
2013-06-28 15:02:58 -07:00
writer . append ( line ) . append ( " \ r \ n " ) ;
2013-02-05 15:29:57 -05:00
}
2013-06-28 15:02:58 -07:00
out = new FileWriter ( usersFilePath ) ; // Write out the new file
out . write ( writer . toString ( ) ) ;
}
catch ( Exception e ) {
mcMMO . p . getLogger ( ) . severe ( " Exception while reading " + usersFilePath + " (Are you sure you formatted it correctly?) " + e . toString ( ) ) ;
}
finally {
2014-08-01 13:35:36 -04:00
if ( in ! = null ) {
try {
in . close ( ) ;
}
catch ( IOException e ) {
// Ignore
}
}
if ( out ! = null ) {
try {
out . close ( ) ;
}
catch ( IOException e ) {
// Ignore
}
}
2013-02-05 15:29:57 -05:00
}
}
2013-06-04 12:14:43 -04:00
Misc . profileCleanup ( playerName ) ;
2013-03-14 10:25:54 -04:00
2013-06-04 12:14:43 -04:00
return worked ;
2013-02-05 15:29:57 -05:00
}
2013-10-05 15:18:10 -07:00
public boolean saveUser ( PlayerProfile profile ) {
2013-06-04 12:14:43 -04:00
String playerName = profile . getPlayerName ( ) ;
2014-08-01 20:17:15 +02:00
UUID uuid = profile . getUniqueId ( ) ;
2013-02-05 15:29:57 -05:00
BufferedReader in = null ;
FileWriter out = null ;
String usersFilePath = mcMMO . getUsersFilePath ( ) ;
2013-06-28 15:02:58 -07:00
synchronized ( fileWritingLock ) {
try {
// Open the file
in = new BufferedReader ( new FileReader ( usersFilePath ) ) ;
StringBuilder writer = new StringBuilder ( ) ;
String line ;
2019-01-11 02:17:03 -08:00
boolean wroteUser = false ;
2013-06-28 15:02:58 -07:00
// While not at the end of the file
while ( ( line = in . readLine ( ) ) ! = null ) {
2014-08-01 20:17:15 +02:00
// Read the line in and copy it to the output if it's not the player we want to edit
String [ ] character = line . split ( " : " ) ;
2015-11-12 19:10:09 -05:00
if ( ! ( uuid ! = null & & character [ UUID_INDEX ] . equalsIgnoreCase ( uuid . toString ( ) ) ) & & ! character [ USERNAME ] . equalsIgnoreCase ( playerName ) ) {
2013-06-28 15:02:58 -07:00
writer . append ( line ) . append ( " \ r \ n " ) ;
}
else {
// Otherwise write the new player information
2019-01-11 02:17:03 -08:00
writeUserToLine ( profile , playerName , uuid , writer ) ;
wroteUser = true ;
2013-06-28 15:02:58 -07:00
}
2013-02-05 15:29:57 -05:00
}
2019-01-11 02:17:03 -08:00
/ *
* If we couldn ' t find the user in the DB we need to add him
* /
if ( ! wroteUser )
{
writeUserToLine ( profile , playerName , uuid , writer ) ;
}
2013-06-28 15:02:58 -07:00
// Write the new file
out = new FileWriter ( usersFilePath ) ;
out . write ( writer . toString ( ) ) ;
2013-10-05 15:18:10 -07:00
return true ;
2013-02-05 15:29:57 -05:00
}
2013-06-28 15:02:58 -07:00
catch ( Exception e ) {
e . printStackTrace ( ) ;
2013-10-05 15:18:10 -07:00
return false ;
2013-06-28 15:02:58 -07:00
}
finally {
2014-08-01 13:35:36 -04:00
if ( in ! = null ) {
try {
in . close ( ) ;
}
catch ( IOException e ) {
// Ignore
}
}
if ( out ! = null ) {
try {
out . close ( ) ;
}
catch ( IOException e ) {
// Ignore
}
}
2013-02-05 15:29:57 -05:00
}
}
2013-06-04 12:14:43 -04:00
}
2019-01-11 02:17:03 -08:00
private void writeUserToLine ( PlayerProfile profile , String playerName , UUID uuid , StringBuilder writer ) {
writer . append ( playerName ) . append ( " : " ) ;
2019-01-12 23:54:53 -08:00
writer . append ( profile . getSkillLevel ( PrimarySkillType . MINING ) ) . append ( " : " ) ;
2019-01-11 02:17:03 -08:00
writer . append ( " : " ) ;
writer . append ( " : " ) ;
2019-01-12 23:54:53 -08:00
writer . append ( profile . getSkillXpLevel ( PrimarySkillType . MINING ) ) . append ( " : " ) ;
writer . append ( profile . getSkillLevel ( PrimarySkillType . WOODCUTTING ) ) . append ( " : " ) ;
writer . append ( profile . getSkillXpLevel ( PrimarySkillType . WOODCUTTING ) ) . append ( " : " ) ;
writer . append ( profile . getSkillLevel ( PrimarySkillType . REPAIR ) ) . append ( " : " ) ;
writer . append ( profile . getSkillLevel ( PrimarySkillType . UNARMED ) ) . append ( " : " ) ;
writer . append ( profile . getSkillLevel ( PrimarySkillType . HERBALISM ) ) . append ( " : " ) ;
writer . append ( profile . getSkillLevel ( PrimarySkillType . EXCAVATION ) ) . append ( " : " ) ;
writer . append ( profile . getSkillLevel ( PrimarySkillType . ARCHERY ) ) . append ( " : " ) ;
writer . append ( profile . getSkillLevel ( PrimarySkillType . SWORDS ) ) . append ( " : " ) ;
writer . append ( profile . getSkillLevel ( PrimarySkillType . AXES ) ) . append ( " : " ) ;
writer . append ( profile . getSkillLevel ( PrimarySkillType . ACROBATICS ) ) . append ( " : " ) ;
writer . append ( profile . getSkillXpLevel ( PrimarySkillType . REPAIR ) ) . append ( " : " ) ;
writer . append ( profile . getSkillXpLevel ( PrimarySkillType . UNARMED ) ) . append ( " : " ) ;
writer . append ( profile . getSkillXpLevel ( PrimarySkillType . HERBALISM ) ) . append ( " : " ) ;
writer . append ( profile . getSkillXpLevel ( PrimarySkillType . EXCAVATION ) ) . append ( " : " ) ;
writer . append ( profile . getSkillXpLevel ( PrimarySkillType . ARCHERY ) ) . append ( " : " ) ;
writer . append ( profile . getSkillXpLevel ( PrimarySkillType . SWORDS ) ) . append ( " : " ) ;
writer . append ( profile . getSkillXpLevel ( PrimarySkillType . AXES ) ) . append ( " : " ) ;
writer . append ( profile . getSkillXpLevel ( PrimarySkillType . ACROBATICS ) ) . append ( " : " ) ;
2019-01-11 02:17:03 -08:00
writer . append ( " : " ) ;
2019-01-12 23:54:53 -08:00
writer . append ( profile . getSkillLevel ( PrimarySkillType . TAMING ) ) . append ( " : " ) ;
writer . append ( profile . getSkillXpLevel ( PrimarySkillType . TAMING ) ) . append ( " : " ) ;
2019-01-12 19:56:54 -08:00
writer . append ( ( int ) profile . getAbilityDATS ( SuperAbilityType . BERSERK ) ) . append ( " : " ) ;
writer . append ( ( int ) profile . getAbilityDATS ( SuperAbilityType . GIGA_DRILL_BREAKER ) ) . append ( " : " ) ;
writer . append ( ( int ) profile . getAbilityDATS ( SuperAbilityType . TREE_FELLER ) ) . append ( " : " ) ;
writer . append ( ( int ) profile . getAbilityDATS ( SuperAbilityType . GREEN_TERRA ) ) . append ( " : " ) ;
writer . append ( ( int ) profile . getAbilityDATS ( SuperAbilityType . SERRATED_STRIKES ) ) . append ( " : " ) ;
writer . append ( ( int ) profile . getAbilityDATS ( SuperAbilityType . SKULL_SPLITTER ) ) . append ( " : " ) ;
writer . append ( ( int ) profile . getAbilityDATS ( SuperAbilityType . SUPER_BREAKER ) ) . append ( " : " ) ;
2019-01-11 02:17:03 -08:00
writer . append ( " : " ) ;
2019-01-12 23:54:53 -08:00
writer . append ( profile . getSkillLevel ( PrimarySkillType . FISHING ) ) . append ( " : " ) ;
writer . append ( profile . getSkillXpLevel ( PrimarySkillType . FISHING ) ) . append ( " : " ) ;
2019-01-12 19:56:54 -08:00
writer . append ( ( int ) profile . getAbilityDATS ( SuperAbilityType . BLAST_MINING ) ) . append ( " : " ) ;
2019-01-11 02:17:03 -08:00
writer . append ( System . currentTimeMillis ( ) / Misc . TIME_CONVERSION_FACTOR ) . append ( " : " ) ;
MobHealthbarType mobHealthbarType = profile . getMobHealthbarType ( ) ;
2019-02-16 16:09:48 -08:00
writer . append ( mobHealthbarType = = null ? MainConfig . getInstance ( ) . getMobHealthbarDefault ( ) . toString ( ) : mobHealthbarType . toString ( ) ) . append ( " : " ) ;
2019-01-12 23:54:53 -08:00
writer . append ( profile . getSkillLevel ( PrimarySkillType . ALCHEMY ) ) . append ( " : " ) ;
writer . append ( profile . getSkillXpLevel ( PrimarySkillType . ALCHEMY ) ) . append ( " : " ) ;
2019-01-11 02:17:03 -08:00
writer . append ( uuid ! = null ? uuid . toString ( ) : " NULL " ) . append ( " : " ) ;
writer . append ( profile . getScoreboardTipsShown ( ) ) . append ( " : " ) ;
writer . append ( profile . getUniqueData ( UniqueDataType . CHIMAERA_WING_DATS ) ) . append ( " : " ) ;
writer . append ( " \ r \ n " ) ;
}
2019-01-12 23:54:53 -08:00
public List < PlayerStat > readLeaderboard ( PrimarySkillType skill , int pageNumber , int statsPerPage ) {
2013-06-04 12:14:43 -04:00
updateLeaderboards ( ) ;
2013-09-11 19:42:27 -07:00
List < PlayerStat > statsList = skill = = null ? powerLevels : playerStatHash . get ( skill ) ;
2013-06-04 12:14:43 -04:00
int fromIndex = ( Math . max ( pageNumber , 1 ) - 1 ) * statsPerPage ;
2013-02-05 15:29:57 -05:00
2013-06-04 12:14:43 -04:00
return statsList . subList ( Math . min ( fromIndex , statsList . size ( ) ) , Math . min ( fromIndex + statsPerPage , statsList . size ( ) ) ) ;
2013-02-05 15:29:57 -05:00
}
2019-01-12 23:54:53 -08:00
public Map < PrimarySkillType , Integer > readRank ( String playerName ) {
2013-06-04 12:14:43 -04:00
updateLeaderboards ( ) ;
2013-03-14 10:25:54 -04:00
2019-01-12 23:54:53 -08:00
Map < PrimarySkillType , Integer > skills = new HashMap < PrimarySkillType , Integer > ( ) ;
2013-06-04 12:14:43 -04:00
2019-01-12 23:54:53 -08:00
for ( PrimarySkillType skill : PrimarySkillType . NON_CHILD_SKILLS ) {
2013-09-11 19:42:27 -07:00
skills . put ( skill , getPlayerRank ( playerName , playerStatHash . get ( skill ) ) ) ;
2013-03-14 10:25:54 -04:00
}
2013-09-11 19:42:27 -07:00
skills . put ( null , getPlayerRank ( playerName , powerLevels ) ) ;
2013-06-04 12:14:43 -04:00
return skills ;
}
2014-08-07 13:54:28 -04:00
public void newUser ( String playerName , UUID uuid ) {
2013-06-28 15:02:58 -07:00
BufferedWriter out = null ;
synchronized ( fileWritingLock ) {
try {
// Open the file to write the player
out = new BufferedWriter ( new FileWriter ( mcMMO . getUsersFilePath ( ) , true ) ) ;
2019-03-13 13:09:27 -07:00
String startingLevel = mcMMO . getPlayerLevelingSettings ( ) . getStartingLevel ( ) + " : " ;
2019-01-18 13:10:45 -08:00
2013-06-28 15:02:58 -07:00
// Add the player to the end
out . append ( playerName ) . append ( " : " ) ;
2019-01-18 13:10:45 -08:00
out . append ( startingLevel ) ; // Mining
2013-06-28 15:02:58 -07:00
out . append ( " : " ) ;
out . append ( " : " ) ;
out . append ( " 0: " ) ; // Xp
2019-01-18 13:10:45 -08:00
out . append ( startingLevel ) ; // Woodcutting
2013-06-28 15:02:58 -07:00
out . append ( " 0: " ) ; // WoodCuttingXp
2019-01-18 13:10:45 -08:00
out . append ( startingLevel ) ; // Repair
out . append ( startingLevel ) ; // Unarmed
out . append ( startingLevel ) ; // Herbalism
out . append ( startingLevel ) ; // Excavation
out . append ( startingLevel ) ; // Archery
out . append ( startingLevel ) ; // Swords
out . append ( startingLevel ) ; // Axes
out . append ( startingLevel ) ; // Acrobatics
2013-06-28 15:02:58 -07:00
out . append ( " 0: " ) ; // RepairXp
out . append ( " 0: " ) ; // UnarmedXp
out . append ( " 0: " ) ; // HerbalismXp
out . append ( " 0: " ) ; // ExcavationXp
out . append ( " 0: " ) ; // ArcheryXp
out . append ( " 0: " ) ; // SwordsXp
out . append ( " 0: " ) ; // AxesXp
out . append ( " 0: " ) ; // AcrobaticsXp
out . append ( " : " ) ;
2019-01-18 13:10:45 -08:00
out . append ( startingLevel ) ; // Taming
2013-06-28 15:02:58 -07:00
out . append ( " 0: " ) ; // TamingXp
out . append ( " 0: " ) ; // DATS
out . append ( " 0: " ) ; // DATS
out . append ( " 0: " ) ; // DATS
out . append ( " 0: " ) ; // DATS
out . append ( " 0: " ) ; // DATS
out . append ( " 0: " ) ; // DATS
out . append ( " 0: " ) ; // DATS
2013-09-18 09:57:28 -04:00
out . append ( " : " ) ;
2019-01-18 13:10:45 -08:00
out . append ( startingLevel ) ; // Fishing
2013-06-28 15:02:58 -07:00
out . append ( " 0: " ) ; // FishingXp
out . append ( " 0: " ) ; // Blast Mining
out . append ( String . valueOf ( System . currentTimeMillis ( ) / Misc . TIME_CONVERSION_FACTOR ) ) . append ( " : " ) ; // LastLogin
2019-02-16 16:09:48 -08:00
out . append ( MainConfig . getInstance ( ) . getMobHealthbarDefault ( ) . toString ( ) ) . append ( " : " ) ; // Mob Healthbar HUD
2019-01-18 13:10:45 -08:00
out . append ( startingLevel ) ; // Alchemy
2013-11-15 18:21:00 -05:00
out . append ( " 0: " ) ; // AlchemyXp
2014-08-20 22:18:50 -04:00
out . append ( uuid ! = null ? uuid . toString ( ) : " NULL " ) . append ( " : " ) ; // UUID
2019-03-13 09:42:57 -07:00
out . append ( " 0: " ) ; // ConfigScoreboard tips shown
2013-06-28 15:02:58 -07:00
// Add more in the same format as the line above
out . newLine ( ) ;
}
catch ( Exception e ) {
e . printStackTrace ( ) ;
}
finally {
2014-08-01 13:35:36 -04:00
if ( out ! = null ) {
try {
out . close ( ) ;
}
catch ( IOException e ) {
// Ignore
}
}
2013-06-28 15:02:58 -07:00
}
2013-06-04 12:14:43 -04:00
}
}
2014-08-01 20:17:15 +02:00
@Deprecated
2013-06-28 15:02:58 -07:00
public PlayerProfile loadPlayerProfile ( String playerName , boolean create ) {
2014-08-07 13:54:28 -04:00
return loadPlayerProfile ( playerName , null , false ) ;
2014-08-01 20:17:15 +02:00
}
2014-08-01 13:35:36 -04:00
public PlayerProfile loadPlayerProfile ( UUID uuid ) {
2014-08-07 13:54:28 -04:00
return loadPlayerProfile ( " " , uuid , false ) ;
2014-08-01 20:17:15 +02:00
}
public PlayerProfile loadPlayerProfile ( String playerName , UUID uuid , boolean create ) {
2013-06-28 15:02:58 -07:00
BufferedReader in = null ;
String usersFilePath = mcMMO . getUsersFilePath ( ) ;
2013-06-04 12:14:43 -04:00
2013-06-28 15:02:58 -07:00
synchronized ( fileWritingLock ) {
try {
// Open the user file
in = new BufferedReader ( new FileReader ( usersFilePath ) ) ;
String line ;
2013-06-04 12:14:43 -04:00
2013-06-28 15:02:58 -07:00
while ( ( line = in . readLine ( ) ) ! = null ) {
// Find if the line contains the player we want.
String [ ] character = line . split ( " : " ) ;
2013-06-04 12:14:43 -04:00
2014-09-03 00:05:48 -04:00
// Compare names because we don't have a valid uuid for that player even
// if input uuid is not null
2015-11-12 19:10:09 -05:00
if ( character [ UUID_INDEX ] . equalsIgnoreCase ( " NULL " ) ) {
if ( ! character [ USERNAME ] . equalsIgnoreCase ( playerName ) ) {
2014-09-03 00:05:48 -04:00
continue ;
}
2014-08-24 23:20:01 +04:00
}
// If input uuid is not null then we should compare uuids
2015-11-12 19:10:09 -05:00
else if ( ( uuid ! = null & & ! character [ UUID_INDEX ] . equalsIgnoreCase ( uuid . toString ( ) ) ) | | ( uuid = = null & & ! character [ USERNAME ] . equalsIgnoreCase ( playerName ) ) ) {
2013-06-28 15:02:58 -07:00
continue ;
}
2013-03-14 10:25:54 -04:00
2014-08-01 20:17:15 +02:00
// Update playerName in database after name change
2015-11-12 19:10:09 -05:00
if ( ! character [ USERNAME ] . equalsIgnoreCase ( playerName ) ) {
mcMMO . p . debug ( " Name change detected: " + character [ USERNAME ] + " => " + playerName ) ;
character [ USERNAME ] = playerName ;
2014-08-01 20:17:15 +02:00
}
2014-01-20 13:58:40 -08:00
return loadFromLine ( character ) ;
2013-06-28 15:02:58 -07:00
}
2013-10-05 16:14:46 -07:00
// Didn't find the player, create a new one
if ( create ) {
2014-08-07 13:54:28 -04:00
if ( uuid = = null ) {
2014-08-01 20:17:15 +02:00
newUser ( playerName , uuid ) ;
return new PlayerProfile ( playerName , true ) ;
}
newUser ( playerName , uuid ) ;
2014-08-07 13:54:28 -04:00
return new PlayerProfile ( playerName , uuid , true ) ;
2013-10-05 16:14:46 -07:00
}
2013-06-28 15:02:58 -07:00
}
catch ( Exception e ) {
e . printStackTrace ( ) ;
}
finally {
2013-09-11 19:42:27 -07:00
// I have no idea why it's necessary to inline tryClose() here, but it removes
// a resource leak warning, and I'm trusting the compiler on this one.
if ( in ! = null ) {
try {
in . close ( ) ;
}
catch ( IOException e ) {
2014-08-01 13:35:36 -04:00
// Ignore
2013-09-11 19:42:27 -07:00
}
}
2013-06-28 15:02:58 -07:00
}
2013-03-14 10:25:54 -04:00
}
2013-10-05 16:14:46 -07:00
// Return unloaded profile
2014-08-07 13:54:28 -04:00
if ( uuid = = null ) {
2014-08-01 20:17:15 +02:00
return new PlayerProfile ( playerName ) ;
}
2014-08-07 13:54:28 -04:00
return new PlayerProfile ( playerName , uuid ) ;
2013-04-18 17:37:36 -04:00
}
2013-06-28 15:02:58 -07:00
public void convertUsers ( DatabaseManager destination ) {
BufferedReader in = null ;
String usersFilePath = mcMMO . getUsersFilePath ( ) ;
2013-10-15 18:32:54 -07:00
int convertedUsers = 0 ;
long startMillis = System . currentTimeMillis ( ) ;
2013-06-28 15:02:58 -07:00
synchronized ( fileWritingLock ) {
try {
// Open the user file
in = new BufferedReader ( new FileReader ( usersFilePath ) ) ;
String line ;
while ( ( line = in . readLine ( ) ) ! = null ) {
String [ ] character = line . split ( " : " ) ;
try {
destination . saveUser ( loadFromLine ( character ) ) ;
}
catch ( Exception e ) {
e . printStackTrace ( ) ;
}
2013-10-15 18:32:54 -07:00
convertedUsers + + ;
2013-10-18 16:43:37 +02:00
Misc . printProgress ( convertedUsers , progressInterval , startMillis ) ;
2013-06-28 15:02:58 -07:00
}
}
catch ( Exception e ) {
e . printStackTrace ( ) ;
}
finally {
2014-08-01 13:35:36 -04:00
if ( in ! = null ) {
try {
in . close ( ) ;
}
catch ( IOException e ) {
// Ignore
}
}
2013-06-28 15:02:58 -07:00
}
}
2013-06-04 12:14:43 -04:00
}
2013-04-18 17:37:36 -04:00
2014-08-01 20:17:15 +02:00
public boolean saveUserUUID ( String userName , UUID uuid ) {
boolean worked = false ;
2015-03-09 14:20:52 -04:00
int i = 0 ;
2014-08-01 20:17:15 +02:00
BufferedReader in = null ;
FileWriter out = null ;
String usersFilePath = mcMMO . getUsersFilePath ( ) ;
synchronized ( fileWritingLock ) {
try {
in = new BufferedReader ( new FileReader ( usersFilePath ) ) ;
StringBuilder writer = new StringBuilder ( ) ;
String line ;
while ( ( line = in . readLine ( ) ) ! = null ) {
String [ ] character = line . split ( " : " ) ;
2015-11-12 19:10:09 -05:00
if ( ! worked & & character [ USERNAME ] . equalsIgnoreCase ( userName ) ) {
2014-08-01 20:17:15 +02:00
if ( character . length < 42 ) {
mcMMO . p . getLogger ( ) . severe ( " Could not update UUID for " + userName + " ! " ) ;
mcMMO . p . getLogger ( ) . severe ( " Database entry is invalid. " ) ;
2015-03-09 14:20:52 -04:00
continue ;
2014-08-01 20:17:15 +02:00
}
2015-11-12 19:10:09 -05:00
line = line . replace ( character [ UUID_INDEX ] , uuid . toString ( ) ) ;
2014-08-01 20:17:15 +02:00
worked = true ;
}
2015-03-09 14:20:52 -04:00
i + + ;
2014-08-01 20:17:15 +02:00
writer . append ( line ) . append ( " \ r \ n " ) ;
}
out = new FileWriter ( usersFilePath ) ; // Write out the new file
out . write ( writer . toString ( ) ) ;
}
catch ( Exception e ) {
mcMMO . p . getLogger ( ) . severe ( " Exception while reading " + usersFilePath + " (Are you sure you formatted it correctly?) " + e . toString ( ) ) ;
}
finally {
2015-03-09 14:20:52 -04:00
mcMMO . p . getLogger ( ) . info ( i + " entries written while saving UUID for " + userName ) ;
2014-08-01 13:35:36 -04:00
if ( in ! = null ) {
try {
in . close ( ) ;
}
catch ( IOException e ) {
// Ignore
}
}
if ( out ! = null ) {
try {
out . close ( ) ;
}
catch ( IOException e ) {
// Ignore
}
}
2014-08-01 20:17:15 +02:00
}
}
return worked ;
}
public boolean saveUserUUIDs ( Map < String , UUID > fetchedUUIDs ) {
BufferedReader in = null ;
FileWriter out = null ;
String usersFilePath = mcMMO . getUsersFilePath ( ) ;
2015-03-09 14:20:52 -04:00
int i = 0 ;
2014-08-01 20:17:15 +02:00
synchronized ( fileWritingLock ) {
try {
in = new BufferedReader ( new FileReader ( usersFilePath ) ) ;
StringBuilder writer = new StringBuilder ( ) ;
String line ;
2015-01-31 14:38:49 -05:00
while ( ( ( line = in . readLine ( ) ) ! = null ) ) {
2014-08-01 20:17:15 +02:00
String [ ] character = line . split ( " : " ) ;
2015-11-12 19:10:09 -05:00
if ( ! fetchedUUIDs . isEmpty ( ) & & fetchedUUIDs . containsKey ( character [ USERNAME ] ) ) {
2014-08-01 20:17:15 +02:00
if ( character . length < 42 ) {
2015-11-12 19:10:09 -05:00
mcMMO . p . getLogger ( ) . severe ( " Could not update UUID for " + character [ USERNAME ] + " ! " ) ;
2014-08-01 20:17:15 +02:00
mcMMO . p . getLogger ( ) . severe ( " Database entry is invalid. " ) ;
2014-08-17 19:57:37 -04:00
continue ;
2014-08-01 20:17:15 +02:00
}
2015-11-12 19:10:09 -05:00
character [ UUID_INDEX ] = fetchedUUIDs . remove ( character [ USERNAME ] ) . toString ( ) ;
2014-08-17 19:57:37 -04:00
line = new StringBuilder ( org . apache . commons . lang . StringUtils . join ( character , " : " ) ) . append ( " : " ) . toString ( ) ;
2014-08-01 20:17:15 +02:00
}
2015-03-09 14:20:52 -04:00
i + + ;
2014-08-01 20:17:15 +02:00
writer . append ( line ) . append ( " \ r \ n " ) ;
}
out = new FileWriter ( usersFilePath ) ; // Write out the new file
out . write ( writer . toString ( ) ) ;
}
catch ( Exception e ) {
mcMMO . p . getLogger ( ) . severe ( " Exception while reading " + usersFilePath + " (Are you sure you formatted it correctly?) " + e . toString ( ) ) ;
}
finally {
2015-03-09 14:20:52 -04:00
mcMMO . p . getLogger ( ) . info ( i + " entries written while saving UUID batch " ) ;
2014-08-01 13:35:36 -04:00
if ( in ! = null ) {
try {
in . close ( ) ;
}
catch ( IOException e ) {
// Ignore
}
}
if ( out ! = null ) {
try {
out . close ( ) ;
}
catch ( IOException e ) {
// Ignore
}
}
2014-08-01 20:17:15 +02:00
}
}
return true ;
}
2013-06-28 15:02:58 -07:00
public List < String > getStoredUsers ( ) {
ArrayList < String > users = new ArrayList < String > ( ) ;
BufferedReader in = null ;
String usersFilePath = mcMMO . getUsersFilePath ( ) ;
synchronized ( fileWritingLock ) {
try {
// Open the user file
in = new BufferedReader ( new FileReader ( usersFilePath ) ) ;
String line ;
while ( ( line = in . readLine ( ) ) ! = null ) {
String [ ] character = line . split ( " : " ) ;
2015-11-12 19:10:09 -05:00
users . add ( character [ USERNAME ] ) ;
2013-06-28 15:02:58 -07:00
}
}
catch ( Exception e ) {
e . printStackTrace ( ) ;
}
finally {
2014-08-01 13:35:36 -04:00
if ( in ! = null ) {
try {
in . close ( ) ;
}
catch ( IOException e ) {
// Ignore
}
}
2013-06-28 15:02:58 -07:00
}
}
return users ;
2013-06-04 12:14:43 -04:00
}
2013-04-18 17:37:36 -04:00
2013-06-04 12:14:43 -04:00
/ * *
2013-06-28 15:02:58 -07:00
* Update the leader boards .
* /
2013-06-04 12:14:43 -04:00
private void updateLeaderboards ( ) {
// Only update FFS leaderboards every 10 minutes.. this puts a lot of strain on the server (depending on the size of the database) and should not be done frequently
if ( System . currentTimeMillis ( ) < lastUpdate + UPDATE_WAIT_TIME ) {
return ;
2013-04-18 17:37:36 -04:00
}
2013-06-04 12:14:43 -04:00
String usersFilePath = mcMMO . getUsersFilePath ( ) ;
lastUpdate = System . currentTimeMillis ( ) ; // Log when the last update was run
powerLevels . clear ( ) ; // Clear old values from the power levels
2013-04-18 17:37:36 -04:00
2013-06-04 12:14:43 -04:00
// Initialize lists
List < PlayerStat > mining = new ArrayList < PlayerStat > ( ) ;
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 > ( ) ;
2013-11-15 18:21:00 -05:00
List < PlayerStat > alchemy = new ArrayList < PlayerStat > ( ) ;
2013-06-04 12:14:43 -04:00
2013-06-28 15:02:58 -07:00
BufferedReader in = null ;
2013-10-13 20:29:53 -07:00
String playerName = null ;
2013-06-04 12:14:43 -04:00
// Read from the FlatFile database and fill our arrays with information
2013-06-28 15:02:58 -07:00
synchronized ( fileWritingLock ) {
try {
in = new BufferedReader ( new FileReader ( usersFilePath ) ) ;
2014-01-20 13:58:40 -08:00
String line ;
2013-06-28 15:02:58 -07:00
while ( ( line = in . readLine ( ) ) ! = null ) {
String [ ] data = line . split ( " : " ) ;
2015-11-12 19:10:09 -05:00
playerName = data [ USERNAME ] ;
2013-06-28 15:02:58 -07:00
int powerLevel = 0 ;
2019-01-12 23:54:53 -08:00
Map < PrimarySkillType , Integer > skills = getSkillMapFromLine ( data ) ;
powerLevel + = putStat ( acrobatics , playerName , skills . get ( PrimarySkillType . ACROBATICS ) ) ;
powerLevel + = putStat ( alchemy , playerName , skills . get ( PrimarySkillType . ALCHEMY ) ) ;
powerLevel + = putStat ( archery , playerName , skills . get ( PrimarySkillType . ARCHERY ) ) ;
powerLevel + = putStat ( axes , playerName , skills . get ( PrimarySkillType . AXES ) ) ;
powerLevel + = putStat ( excavation , playerName , skills . get ( PrimarySkillType . EXCAVATION ) ) ;
powerLevel + = putStat ( fishing , playerName , skills . get ( PrimarySkillType . FISHING ) ) ;
powerLevel + = putStat ( herbalism , playerName , skills . get ( PrimarySkillType . HERBALISM ) ) ;
powerLevel + = putStat ( mining , playerName , skills . get ( PrimarySkillType . MINING ) ) ;
powerLevel + = putStat ( repair , playerName , skills . get ( PrimarySkillType . REPAIR ) ) ;
powerLevel + = putStat ( swords , playerName , skills . get ( PrimarySkillType . SWORDS ) ) ;
powerLevel + = putStat ( taming , playerName , skills . get ( PrimarySkillType . TAMING ) ) ;
powerLevel + = putStat ( unarmed , playerName , skills . get ( PrimarySkillType . UNARMED ) ) ;
powerLevel + = putStat ( woodcutting , playerName , skills . get ( PrimarySkillType . WOODCUTTING ) ) ;
2013-06-28 15:02:58 -07:00
putStat ( powerLevels , playerName , powerLevel ) ;
2013-06-04 12:14:43 -04:00
}
}
2013-06-28 15:02:58 -07:00
catch ( Exception e ) {
2013-10-13 20:29:53 -07:00
mcMMO . p . getLogger ( ) . severe ( " Exception while reading " + usersFilePath + " during user " + playerName + " (Are you sure you formatted it correctly?) " + e . toString ( ) ) ;
2013-06-28 15:02:58 -07:00
}
finally {
2014-08-01 13:35:36 -04:00
if ( in ! = null ) {
try {
in . close ( ) ;
}
catch ( IOException e ) {
// Ignore
}
}
2013-06-28 15:02:58 -07:00
}
2013-06-04 12:14:43 -04:00
}
SkillComparator c = new SkillComparator ( ) ;
Collections . sort ( mining , c ) ;
Collections . sort ( woodcutting , c ) ;
Collections . sort ( repair , c ) ;
Collections . sort ( unarmed , c ) ;
Collections . sort ( herbalism , c ) ;
Collections . sort ( excavation , c ) ;
Collections . sort ( archery , c ) ;
Collections . sort ( swords , c ) ;
Collections . sort ( axes , c ) ;
Collections . sort ( acrobatics , c ) ;
Collections . sort ( taming , c ) ;
Collections . sort ( fishing , c ) ;
2013-11-15 18:21:00 -05:00
Collections . sort ( alchemy , c ) ;
2013-06-04 12:14:43 -04:00
Collections . sort ( powerLevels , c ) ;
2019-01-12 23:54:53 -08:00
playerStatHash . put ( PrimarySkillType . MINING , mining ) ;
playerStatHash . put ( PrimarySkillType . WOODCUTTING , woodcutting ) ;
playerStatHash . put ( PrimarySkillType . REPAIR , repair ) ;
playerStatHash . put ( PrimarySkillType . UNARMED , unarmed ) ;
playerStatHash . put ( PrimarySkillType . HERBALISM , herbalism ) ;
playerStatHash . put ( PrimarySkillType . EXCAVATION , excavation ) ;
playerStatHash . put ( PrimarySkillType . ARCHERY , archery ) ;
playerStatHash . put ( PrimarySkillType . SWORDS , swords ) ;
playerStatHash . put ( PrimarySkillType . AXES , axes ) ;
playerStatHash . put ( PrimarySkillType . ACROBATICS , acrobatics ) ;
playerStatHash . put ( PrimarySkillType . TAMING , taming ) ;
playerStatHash . put ( PrimarySkillType . FISHING , fishing ) ;
playerStatHash . put ( PrimarySkillType . ALCHEMY , alchemy ) ;
2013-04-18 17:37:36 -04:00
}
2013-07-01 01:37:24 -04:00
/ * *
* Checks that the file is present and valid
* /
private void checkStructure ( ) {
2013-06-04 12:14:43 -04:00
if ( usersFile . exists ( ) ) {
2013-07-01 01:37:24 -04:00
BufferedReader in = null ;
FileWriter out = null ;
String usersFilePath = mcMMO . getUsersFilePath ( ) ;
synchronized ( fileWritingLock ) {
try {
in = new BufferedReader ( new FileReader ( usersFilePath ) ) ;
StringBuilder writer = new StringBuilder ( ) ;
2014-01-20 13:58:40 -08:00
String line ;
2014-08-01 20:17:15 +02:00
HashSet < String > usernames = new HashSet < String > ( ) ;
2013-07-31 16:12:59 -07:00
HashSet < String > players = new HashSet < String > ( ) ;
2013-07-01 01:37:24 -04:00
while ( ( line = in . readLine ( ) ) ! = null ) {
2013-09-18 08:34:47 -04:00
// Remove empty lines from the file
if ( line . isEmpty ( ) ) {
continue ;
}
2013-07-31 16:12:59 -07:00
// Length checks depend on last character being ':'
if ( line . charAt ( line . length ( ) - 1 ) ! = ':' ) {
2014-02-21 11:38:22 -05:00
line = line . concat ( " : " ) ;
2013-07-31 16:12:59 -07:00
}
2015-11-12 19:10:09 -05:00
boolean updated = false ;
2013-07-01 01:37:24 -04:00
String [ ] character = line . split ( " : " ) ;
2014-08-01 20:17:15 +02:00
// Prevent the same username from being present multiple times
2015-11-12 19:10:09 -05:00
if ( ! usernames . add ( character [ USERNAME ] ) ) {
character [ USERNAME ] = " _INVALID_OLD_USERNAME_' " ;
updated = true ;
if ( character . length < UUID_INDEX + 1 | | character [ UUID_INDEX ] . equals ( " NULL " ) ) {
continue ;
}
2014-08-01 20:17:15 +02:00
}
2013-07-31 16:12:59 -07:00
// Prevent the same player from being present multiple times
2015-11-12 19:10:09 -05:00
if ( character . length > = 42 & & ( ! character [ UUID_INDEX ] . isEmpty ( ) & & ! character [ UUID_INDEX ] . equals ( " NULL " ) & & ! players . add ( character [ UUID_INDEX ] ) ) ) {
2013-07-31 16:12:59 -07:00
continue ;
}
2013-09-18 11:54:23 -04:00
if ( character . length < 33 ) {
// Before Version 1.0 - Drop
mcMMO . p . getLogger ( ) . warning ( " Dropping malformed or before version 1.0 line from database - " + line ) ;
continue ;
}
String oldVersion = null ;
2015-11-12 19:10:09 -05:00
if ( character . length > 33 & & ! character [ 33 ] . isEmpty ( ) ) {
2013-09-18 11:54:23 -04:00
// Removal of Spout Support
// Version 1.4.07-dev2
// commit 7bac0e2ca5143bce84dc160617fed97f0b1cb968
2015-11-12 19:10:09 -05:00
character [ 33 ] = " " ;
2014-02-21 11:38:22 -05:00
if ( oldVersion = = null ) {
oldVersion = " 1.4.07 " ;
}
2015-11-12 19:10:09 -05:00
updated = true ;
}
2019-03-13 15:44:35 -07:00
if ( mcMMO . getPlayerLevelingSettings ( ) . getConfigSectionLevelCaps ( ) . getReducePlayerSkillsAboveCap ( ) ) {
2019-01-12 23:54:53 -08:00
for ( PrimarySkillType skill : PrimarySkillType . NON_CHILD_SKILLS ) {
2015-11-12 19:10:09 -05:00
int index = getSkillIndex ( skill ) ;
if ( index > = character . length ) {
continue ;
}
2019-03-13 15:44:35 -07:00
//Level Cap
if ( mcMMO . getPlayerLevelingSettings ( ) . isLevelCapEnabled ( skill ) )
{
int cap = mcMMO . getPlayerLevelingSettings ( ) . getLevelCap ( skill ) ;
if ( Integer . valueOf ( character [ index ] ) > cap ) {
mcMMO . p . getLogger ( ) . warning ( " Truncating " + skill . getName ( ) + " to configured max level for player " + character [ USERNAME ] ) ;
character [ index ] = cap + " " ;
updated = true ;
}
2015-11-12 19:10:09 -05:00
}
}
2013-09-18 11:54:23 -04:00
}
2013-07-01 01:37:24 -04:00
// If they're valid, rewrite them to the file.
2015-11-12 19:10:09 -05:00
if ( ! updated & & character . length = = 43 ) {
2013-07-01 01:37:24 -04:00
writer . append ( line ) . append ( " \ r \ n " ) ;
2013-09-18 11:54:23 -04:00
continue ;
2013-08-07 19:58:49 +02:00
}
2013-09-18 11:54:23 -04:00
2015-11-12 19:10:09 -05:00
if ( character . length < = 33 ) {
// Introduction of HUDType
// Version 1.1.06
// commit 78f79213cdd7190cd11ae54526f3b4ea42078e8a
character = Arrays . copyOf ( character , character . length + 1 ) ;
character [ character . length - 1 ] = " " ;
oldVersion = " 1.1.06 " ;
}
2013-09-18 11:54:23 -04:00
if ( character . length < = 35 ) {
// Introduction of Fishing
// Version 1.2.00
// commit a814b57311bc7734661109f0e77fc8bab3a0bd29
2015-11-12 19:10:09 -05:00
character = Arrays . copyOf ( character , character . length + 2 ) ;
character [ character . length - 1 ] = " 0 " ;
character [ character . length - 2 ] = " 0 " ;
2013-09-18 11:54:23 -04:00
if ( oldVersion = = null ) {
oldVersion = " 1.2.00 " ;
2013-07-31 15:02:01 -07:00
}
2013-09-18 11:54:23 -04:00
}
if ( character . length < = 36 ) {
// Introduction of Blast Mining cooldowns
// Version 1.3.00-dev
// commit fadbaf429d6b4764b8f1ad0efaa524a090e82ef5
2015-11-12 19:10:09 -05:00
character = Arrays . copyOf ( character , character . length + 1 ) ;
character [ character . length - 1 ] = " 0 " ;
2013-09-18 11:54:23 -04:00
if ( oldVersion = = null ) {
oldVersion = " 1.3.00 " ;
2013-07-31 15:02:01 -07:00
}
2013-09-18 11:54:23 -04:00
}
if ( character . length < = 37 ) {
// Making old-purge work with flatfile
// Version 1.4.00-dev
// commmit 3f6c07ba6aaf44e388cc3b882cac3d8f51d0ac28
// XXX Cannot create an OfflinePlayer at startup, use 0 and fix in purge
2015-11-12 19:10:09 -05:00
character = Arrays . copyOf ( character , character . length + 1 ) ;
character [ character . length - 1 ] = " 0 " ;
2013-09-18 11:54:23 -04:00
if ( oldVersion = = null ) {
oldVersion = " 1.4.00 " ;
2013-07-31 15:02:01 -07:00
}
2013-09-18 11:54:23 -04:00
}
if ( character . length < = 38 ) {
// Addition of mob healthbars
// Version 1.4.06
// commit da29185b7dc7e0d992754bba555576d48fa08aa6
2015-11-12 19:10:09 -05:00
character = Arrays . copyOf ( character , character . length + 1 ) ;
2019-02-16 16:09:48 -08:00
character [ character . length - 1 ] = MainConfig . getInstance ( ) . getMobHealthbarDefault ( ) . toString ( ) ;
2013-09-18 11:54:23 -04:00
if ( oldVersion = = null ) {
oldVersion = " 1.4.06 " ;
2013-07-31 15:02:01 -07:00
}
2013-09-18 11:54:23 -04:00
}
2014-02-22 09:52:36 -05:00
if ( character . length < = 39 ) {
2013-11-15 18:21:00 -05:00
// Addition of Alchemy
// Version 1.4.08
2015-11-12 19:10:09 -05:00
character = Arrays . copyOf ( character , character . length + 2 ) ;
character [ character . length - 1 ] = " 0 " ;
character [ character . length - 2 ] = " 0 " ;
2013-11-15 18:21:00 -05:00
if ( oldVersion = = null ) {
oldVersion = " 1.4.08 " ;
}
}
2014-08-01 20:17:15 +02:00
if ( character . length < = 41 ) {
// Addition of UUIDs
// Version 1.5.01
2014-08-20 22:18:50 -04:00
// Add a value because otherwise it gets removed
2015-11-12 19:10:09 -05:00
character = Arrays . copyOf ( character , character . length + 1 ) ;
character [ character . length - 1 ] = " NULL " ;
2014-08-01 20:17:15 +02:00
if ( oldVersion = = null ) {
oldVersion = " 1.5.01 " ;
}
}
2014-02-09 18:12:00 +01:00
if ( character . length < = 42 ) {
// Addition of scoreboard tips auto disable
// Version 1.5.02
2015-11-12 19:10:09 -05:00
character = Arrays . copyOf ( character , character . length + 1 ) ;
character [ character . length - 1 ] = " 0 " ;
2014-02-09 18:12:00 +01:00
if ( oldVersion = = null ) {
oldVersion = " 1.5.02 " ;
}
}
2013-07-31 16:12:59 -07:00
2014-02-22 09:52:36 -05:00
boolean corrupted = false ;
2015-11-12 19:10:09 -05:00
for ( int i = 0 ; i < character . length ; i + + ) {
if ( character [ i ] . isEmpty ( ) & & ! ( i = = 2 | | i = = 3 | | i = = 23 | | i = = 33 | | i = = 41 ) ) {
2014-02-22 09:52:36 -05:00
corrupted = true ;
2015-11-12 19:10:09 -05:00
if ( i = = 37 ) {
character [ i ] = String . valueOf ( System . currentTimeMillis ( ) / Misc . TIME_CONVERSION_FACTOR ) ;
}
else if ( i = = 38 ) {
2019-02-16 16:09:48 -08:00
character [ i ] = MainConfig . getInstance ( ) . getMobHealthbarDefault ( ) . toString ( ) ;
2014-02-22 09:52:36 -05:00
}
else {
2015-11-12 19:10:09 -05:00
character [ i ] = " 0 " ;
2014-02-22 09:52:36 -05:00
}
}
2015-11-12 19:10:09 -05:00
if ( StringUtils . isInt ( character [ i ] ) & & i = = 38 ) {
2014-02-22 09:52:36 -05:00
corrupted = true ;
2019-02-16 16:09:48 -08:00
character [ i ] = MainConfig . getInstance ( ) . getMobHealthbarDefault ( ) . toString ( ) ;
2014-02-22 09:52:36 -05:00
}
2015-11-12 19:10:09 -05:00
if ( ! StringUtils . isInt ( character [ i ] ) & & ! ( i = = 0 | | i = = 2 | | i = = 3 | | i = = 23 | | i = = 33 | | i = = 38 | | i = = 41 ) ) {
2014-02-22 09:52:36 -05:00
corrupted = true ;
2015-11-12 19:10:09 -05:00
character [ i ] = " 0 " ;
2014-02-22 09:52:36 -05:00
}
}
if ( corrupted ) {
2015-11-12 19:10:09 -05:00
mcMMO . p . debug ( " Updating corrupted database line for player " + character [ USERNAME ] ) ;
2014-02-22 09:52:36 -05:00
}
2013-09-18 11:54:23 -04:00
if ( oldVersion ! = null ) {
2015-11-12 19:10:09 -05:00
mcMMO . p . debug ( " Updating database line from before version " + oldVersion + " for player " + character [ USERNAME ] ) ;
2013-07-01 01:37:24 -04:00
}
2013-09-18 11:54:23 -04:00
2015-11-12 19:10:09 -05:00
updated | = corrupted ;
updated | = oldVersion ! = null ;
2019-03-13 15:44:35 -07:00
if ( mcMMO . getPlayerLevelingSettings ( ) . getConfigSectionLevelCaps ( ) . getReducePlayerSkillsAboveCap ( ) ) {
2019-01-12 23:54:53 -08:00
Map < PrimarySkillType , Integer > skills = getSkillMapFromLine ( character ) ;
for ( PrimarySkillType skill : PrimarySkillType . NON_CHILD_SKILLS ) {
2019-03-13 15:44:35 -07:00
int cap = Integer . MAX_VALUE ;
2015-11-12 19:10:09 -05:00
if ( skills . get ( skill ) > cap ) {
updated = true ;
}
}
}
if ( updated ) {
line = new StringBuilder ( org . apache . commons . lang . StringUtils . join ( character , " : " ) ) . append ( " : " ) . toString ( ) ;
2014-07-12 13:58:36 +02:00
}
2015-11-12 19:10:09 -05:00
writer . append ( line ) . append ( " \ r \ n " ) ;
2013-07-01 01:37:24 -04:00
}
// Write the new file
out = new FileWriter ( usersFilePath ) ;
out . write ( writer . toString ( ) ) ;
}
catch ( IOException e ) {
mcMMO . p . getLogger ( ) . severe ( " Exception while reading " + usersFilePath + " (Are you sure you formatted it correctly?) " + e . toString ( ) ) ;
}
finally {
2014-08-01 13:35:36 -04:00
if ( in ! = null ) {
try {
in . close ( ) ;
}
catch ( IOException e ) {
// Ignore
}
}
if ( out ! = null ) {
try {
out . close ( ) ;
}
catch ( IOException e ) {
// Ignore
}
}
2013-07-01 01:37:24 -04:00
}
}
2014-07-22 20:01:26 -04:00
2019-02-25 16:39:49 -08:00
/ * mcMMO . getUpgradeManager ( ) . setUpgradeCompleted ( UpgradeType . ADD_FISHING ) ;
2014-07-22 20:01:26 -04:00
mcMMO . getUpgradeManager ( ) . setUpgradeCompleted ( UpgradeType . ADD_BLAST_MINING_COOLDOWN ) ;
mcMMO . getUpgradeManager ( ) . setUpgradeCompleted ( UpgradeType . ADD_SQL_INDEXES ) ;
mcMMO . getUpgradeManager ( ) . setUpgradeCompleted ( UpgradeType . ADD_MOB_HEALTHBARS ) ;
mcMMO . getUpgradeManager ( ) . setUpgradeCompleted ( UpgradeType . DROP_SQL_PARTY_NAMES ) ;
mcMMO . getUpgradeManager ( ) . setUpgradeCompleted ( UpgradeType . DROP_SPOUT ) ;
2019-02-25 16:39:49 -08:00
mcMMO . getUpgradeManager ( ) . setUpgradeCompleted ( UpgradeType . ADD_ALCHEMY ) ; * /
2013-06-04 12:14:43 -04:00
return ;
}
usersFile . getParentFile ( ) . mkdir ( ) ;
try {
mcMMO . p . debug ( " Creating mcmmo.users file... " ) ;
new File ( mcMMO . getUsersFilePath ( ) ) . createNewFile ( ) ;
}
catch ( IOException e ) {
e . printStackTrace ( ) ;
}
mcMMO - Now with 100% more scoreboards!
mcMMO now allows for the use of scoreboards to display information in
several instances. By default, all scoreboards are enabled in the config,
and will only display for 10 seconds. After 10 seconds, the scoreboard
will go away and revert to the previously displayed scoreboard, if one
exists.
A global scoreboard now exists for tracking all player stats, and will be
displayed when /mctop is used. Your name will be highlighted in gold when
looking through the scoreboard. Additionally, the scoreboard will display
players in groups of 15, rather than groups of 10 like in chat.
Unfortunately, due to the limitations of scoreboards, the player's rank
will not be displayed in front of their name.
The scoreboard area is now also used for displaying data for /mcrank,
/inspect. and /mcstats. Due to the way scoreboards are handled, the power
level is not guarenteed to show up at any given location in the
scoreboard, but is instead displayed in gold so that it can be easily
found.
Lastly, the scoreboard area is also now used for displaying current data
on skills when the relevant /<skillname> command is used. The effects and
ability stats will still be shown in chat, but the current level, xp, and
remaining xp will be shown in the scoreboard.
2013-04-13 23:16:25 -04:00
}
2013-06-04 12:14:43 -04:00
private Integer getPlayerRank ( String playerName , List < PlayerStat > statsList ) {
if ( statsList = = null ) {
return null ;
}
int currentPos = 1 ;
for ( PlayerStat stat : statsList ) {
if ( stat . name . equalsIgnoreCase ( playerName ) ) {
return currentPos ;
}
currentPos + + ;
}
2013-04-18 17:37:36 -04:00
2013-06-04 12:14:43 -04:00
return null ;
}
2013-06-28 15:02:58 -07:00
private int putStat ( List < PlayerStat > statList , String playerName , int statValue ) {
2013-06-04 12:14:43 -04:00
statList . add ( new PlayerStat ( playerName , statValue ) ) ;
return statValue ;
2013-03-14 10:25:54 -04:00
}
2013-06-04 12:14:43 -04:00
private class SkillComparator implements Comparator < PlayerStat > {
2013-03-01 00:52:01 -05:00
@Override
public int compare ( PlayerStat o1 , PlayerStat o2 ) {
return ( o2 . statVal - o1 . statVal ) ;
}
}
2013-06-28 15:02:58 -07:00
2014-02-27 10:56:21 -05:00
private PlayerProfile loadFromLine ( String [ ] character ) {
2019-01-12 23:54:53 -08:00
Map < PrimarySkillType , Integer > skills = getSkillMapFromLine ( character ) ; // Skill levels
Map < PrimarySkillType , Float > skillsXp = new EnumMap < PrimarySkillType , Float > ( PrimarySkillType . class ) ; // Skill & XP
2019-01-12 19:56:54 -08:00
Map < SuperAbilityType , Integer > skillsDATS = new EnumMap < SuperAbilityType , Integer > ( SuperAbilityType . class ) ; // Ability & Cooldown
2019-01-10 23:52:11 -08:00
Map < UniqueDataType , Integer > uniquePlayerDataMap = new EnumMap < UniqueDataType , Integer > ( UniqueDataType . class ) ;
2013-06-28 15:02:58 -07:00
MobHealthbarType mobHealthbarType ;
2014-02-09 18:12:00 +01:00
int scoreboardTipsShown ;
2013-06-28 15:02:58 -07:00
// TODO on updates, put new values in a try{} ?
2019-01-12 23:54:53 -08:00
skillsXp . put ( PrimarySkillType . TAMING , ( float ) Integer . valueOf ( character [ EXP_TAMING ] ) ) ;
skillsXp . put ( PrimarySkillType . MINING , ( float ) Integer . valueOf ( character [ EXP_MINING ] ) ) ;
skillsXp . put ( PrimarySkillType . REPAIR , ( float ) Integer . valueOf ( character [ EXP_REPAIR ] ) ) ;
skillsXp . put ( PrimarySkillType . WOODCUTTING , ( float ) Integer . valueOf ( character [ EXP_WOODCUTTING ] ) ) ;
skillsXp . put ( PrimarySkillType . UNARMED , ( float ) Integer . valueOf ( character [ EXP_UNARMED ] ) ) ;
skillsXp . put ( PrimarySkillType . HERBALISM , ( float ) Integer . valueOf ( character [ EXP_HERBALISM ] ) ) ;
skillsXp . put ( PrimarySkillType . EXCAVATION , ( float ) Integer . valueOf ( character [ EXP_EXCAVATION ] ) ) ;
skillsXp . put ( PrimarySkillType . ARCHERY , ( float ) Integer . valueOf ( character [ EXP_ARCHERY ] ) ) ;
skillsXp . put ( PrimarySkillType . SWORDS , ( float ) Integer . valueOf ( character [ EXP_SWORDS ] ) ) ;
skillsXp . put ( PrimarySkillType . AXES , ( float ) Integer . valueOf ( character [ EXP_AXES ] ) ) ;
skillsXp . put ( PrimarySkillType . ACROBATICS , ( float ) Integer . valueOf ( character [ EXP_ACROBATICS ] ) ) ;
skillsXp . put ( PrimarySkillType . FISHING , ( float ) Integer . valueOf ( character [ EXP_FISHING ] ) ) ;
skillsXp . put ( PrimarySkillType . ALCHEMY , ( float ) Integer . valueOf ( character [ EXP_ALCHEMY ] ) ) ;
2013-06-28 15:02:58 -07:00
// Taming - Unused
2019-01-12 19:56:54 -08:00
skillsDATS . put ( SuperAbilityType . SUPER_BREAKER , Integer . valueOf ( character [ COOLDOWN_SUPER_BREAKER ] ) ) ;
2013-06-28 15:02:58 -07:00
// Repair - Unused
2019-01-12 19:56:54 -08:00
skillsDATS . put ( SuperAbilityType . TREE_FELLER , Integer . valueOf ( character [ COOLDOWN_TREE_FELLER ] ) ) ;
skillsDATS . put ( SuperAbilityType . BERSERK , Integer . valueOf ( character [ COOLDOWN_BERSERK ] ) ) ;
skillsDATS . put ( SuperAbilityType . GREEN_TERRA , Integer . valueOf ( character [ COOLDOWN_GREEN_TERRA ] ) ) ;
skillsDATS . put ( SuperAbilityType . GIGA_DRILL_BREAKER , Integer . valueOf ( character [ COOLDOWN_GIGA_DRILL_BREAKER ] ) ) ;
2013-06-28 15:02:58 -07:00
// Archery - Unused
2019-01-12 19:56:54 -08:00
skillsDATS . put ( SuperAbilityType . SERRATED_STRIKES , Integer . valueOf ( character [ COOLDOWN_SERRATED_STRIKES ] ) ) ;
skillsDATS . put ( SuperAbilityType . SKULL_SPLITTER , Integer . valueOf ( character [ COOLDOWN_SKULL_SPLITTER ] ) ) ;
2013-06-28 15:02:58 -07:00
// Acrobatics - Unused
2019-01-12 19:56:54 -08:00
skillsDATS . put ( SuperAbilityType . BLAST_MINING , Integer . valueOf ( character [ COOLDOWN_BLAST_MINING ] ) ) ;
2013-06-28 15:02:58 -07:00
try {
2015-11-12 19:10:09 -05:00
mobHealthbarType = MobHealthbarType . valueOf ( character [ HEALTHBAR ] ) ;
2013-06-28 15:02:58 -07:00
}
catch ( Exception e ) {
2019-02-16 16:09:48 -08:00
mobHealthbarType = MainConfig . getInstance ( ) . getMobHealthbarDefault ( ) ;
2013-06-28 15:02:58 -07:00
}
2014-08-01 20:17:15 +02:00
UUID uuid ;
try {
2015-11-12 19:10:09 -05:00
uuid = UUID . fromString ( character [ UUID_INDEX ] ) ;
2014-08-01 20:17:15 +02:00
}
catch ( Exception e ) {
uuid = null ;
}
2014-12-23 18:49:06 +01:00
2014-02-09 18:12:00 +01:00
try {
2015-11-12 19:10:09 -05:00
scoreboardTipsShown = Integer . valueOf ( character [ SCOREBOARD_TIPS ] ) ;
2014-02-09 18:12:00 +01:00
}
catch ( Exception e ) {
scoreboardTipsShown = 0 ;
}
2014-08-01 20:17:15 +02:00
2019-01-10 23:52:11 -08:00
try {
uniquePlayerDataMap . put ( UniqueDataType . CHIMAERA_WING_DATS , Integer . valueOf ( character [ COOLDOWN_CHIMAERA_WING ] ) ) ;
}
catch ( Exception e ) {
uniquePlayerDataMap . put ( UniqueDataType . CHIMAERA_WING_DATS , 0 ) ;
}
return new PlayerProfile ( character [ USERNAME ] , uuid , skills , skillsXp , skillsDATS , mobHealthbarType , scoreboardTipsShown , uniquePlayerDataMap ) ;
2013-06-28 15:02:58 -07:00
}
2019-01-12 23:54:53 -08:00
private Map < PrimarySkillType , Integer > getSkillMapFromLine ( String [ ] character ) {
Map < PrimarySkillType , Integer > skills = new EnumMap < PrimarySkillType , Integer > ( PrimarySkillType . class ) ; // Skill & Level
skills . put ( PrimarySkillType . TAMING , Integer . valueOf ( character [ SKILLS_TAMING ] ) ) ;
skills . put ( PrimarySkillType . MINING , Integer . valueOf ( character [ SKILLS_MINING ] ) ) ;
skills . put ( PrimarySkillType . REPAIR , Integer . valueOf ( character [ SKILLS_REPAIR ] ) ) ;
skills . put ( PrimarySkillType . WOODCUTTING , Integer . valueOf ( character [ SKILLS_WOODCUTTING ] ) ) ;
skills . put ( PrimarySkillType . UNARMED , Integer . valueOf ( character [ SKILLS_UNARMED ] ) ) ;
skills . put ( PrimarySkillType . HERBALISM , Integer . valueOf ( character [ SKILLS_HERBALISM ] ) ) ;
skills . put ( PrimarySkillType . EXCAVATION , Integer . valueOf ( character [ SKILLS_EXCAVATION ] ) ) ;
skills . put ( PrimarySkillType . ARCHERY , Integer . valueOf ( character [ SKILLS_ARCHERY ] ) ) ;
skills . put ( PrimarySkillType . SWORDS , Integer . valueOf ( character [ SKILLS_SWORDS ] ) ) ;
skills . put ( PrimarySkillType . AXES , Integer . valueOf ( character [ SKILLS_AXES ] ) ) ;
skills . put ( PrimarySkillType . ACROBATICS , Integer . valueOf ( character [ SKILLS_ACROBATICS ] ) ) ;
skills . put ( PrimarySkillType . FISHING , Integer . valueOf ( character [ SKILLS_FISHING ] ) ) ;
skills . put ( PrimarySkillType . ALCHEMY , Integer . valueOf ( character [ SKILLS_ALCHEMY ] ) ) ;
2013-06-28 15:02:58 -07:00
return skills ;
}
2013-08-22 09:11:33 -04:00
public DatabaseType getDatabaseType ( ) {
return DatabaseType . FLATFILE ;
}
2014-08-01 13:35:36 -04:00
@Override
public void onDisable ( ) { }
2015-11-12 19:10:09 -05:00
2019-01-12 23:54:53 -08:00
private int getSkillIndex ( PrimarySkillType skill ) {
2015-11-12 19:10:09 -05:00
switch ( skill ) {
case ACROBATICS :
return SKILLS_ACROBATICS ;
case ALCHEMY :
return SKILLS_ALCHEMY ;
case ARCHERY :
return SKILLS_ARCHERY ;
case AXES :
return SKILLS_AXES ;
case EXCAVATION :
return SKILLS_EXCAVATION ;
case FISHING :
return SKILLS_FISHING ;
case HERBALISM :
return SKILLS_HERBALISM ;
case MINING :
return SKILLS_MINING ;
case REPAIR :
return SKILLS_REPAIR ;
case SWORDS :
return SKILLS_SWORDS ;
case TAMING :
return SKILLS_TAMING ;
case UNARMED :
return SKILLS_UNARMED ;
case WOODCUTTING :
return SKILLS_WOODCUTTING ;
default :
throw new RuntimeException ( " Primary Skills only " ) ;
}
}
public static int USERNAME = 0 ;
public static int SKILLS_MINING = 1 ;
public static int EXP_MINING = 4 ;
public static int SKILLS_WOODCUTTING = 5 ;
public static int EXP_WOODCUTTING = 6 ;
public static int SKILLS_REPAIR = 7 ;
public static int SKILLS_UNARMED = 8 ;
public static int SKILLS_HERBALISM = 9 ;
public static int SKILLS_EXCAVATION = 10 ;
public static int SKILLS_ARCHERY = 11 ;
public static int SKILLS_SWORDS = 12 ;
public static int SKILLS_AXES = 13 ;
public static int SKILLS_ACROBATICS = 14 ;
public static int EXP_REPAIR = 15 ;
public static int EXP_UNARMED = 16 ;
public static int EXP_HERBALISM = 17 ;
public static int EXP_EXCAVATION = 18 ;
public static int EXP_ARCHERY = 19 ;
public static int EXP_SWORDS = 20 ;
public static int EXP_AXES = 21 ;
public static int EXP_ACROBATICS = 22 ;
public static int SKILLS_TAMING = 24 ;
public static int EXP_TAMING = 25 ;
public static int COOLDOWN_BERSERK = 26 ;
public static int COOLDOWN_GIGA_DRILL_BREAKER = 27 ;
public static int COOLDOWN_TREE_FELLER = 28 ;
public static int COOLDOWN_GREEN_TERRA = 29 ;
public static int COOLDOWN_SERRATED_STRIKES = 30 ;
public static int COOLDOWN_SKULL_SPLITTER = 31 ;
public static int COOLDOWN_SUPER_BREAKER = 32 ;
public static int SKILLS_FISHING = 34 ;
public static int EXP_FISHING = 35 ;
public static int COOLDOWN_BLAST_MINING = 36 ;
public static int LAST_LOGIN = 37 ;
public static int HEALTHBAR = 38 ;
public static int SKILLS_ALCHEMY = 39 ;
public static int EXP_ALCHEMY = 40 ;
public static int UUID_INDEX = 41 ;
public static int SCOREBOARD_TIPS = 42 ;
2019-01-10 23:52:11 -08:00
public static int COOLDOWN_CHIMAERA_WING = 43 ;
2016-04-23 00:24:05 -04:00
public void resetMobHealthSettings ( ) {
BufferedReader in = null ;
FileWriter out = null ;
String usersFilePath = mcMMO . getUsersFilePath ( ) ;
synchronized ( fileWritingLock ) {
try {
in = new BufferedReader ( new FileReader ( usersFilePath ) ) ;
StringBuilder writer = new StringBuilder ( ) ;
String line ;
while ( ( line = in . readLine ( ) ) ! = null ) {
// Remove empty lines from the file
if ( line . isEmpty ( ) ) {
continue ;
}
String [ ] character = line . split ( " : " ) ;
2019-02-16 16:09:48 -08:00
character [ HEALTHBAR ] = MainConfig . getInstance ( ) . getMobHealthbarDefault ( ) . toString ( ) ;
2016-04-23 00:24:05 -04:00
line = new StringBuilder ( org . apache . commons . lang . StringUtils . join ( character , " : " ) ) . append ( " : " ) . toString ( ) ;
writer . append ( line ) . append ( " \ r \ n " ) ;
}
// Write the new file
out = new FileWriter ( usersFilePath ) ;
out . write ( writer . toString ( ) ) ;
}
catch ( IOException e ) {
mcMMO . p . getLogger ( ) . severe ( " Exception while reading " + usersFilePath + " (Are you sure you formatted it correctly?) " + e . toString ( ) ) ;
}
finally {
if ( in ! = null ) {
try {
in . close ( ) ;
}
catch ( IOException e ) {
// Ignore
}
}
if ( out ! = null ) {
try {
out . close ( ) ;
}
catch ( IOException e ) {
// Ignore
}
}
}
}
}
2012-04-27 02:47:11 -07:00
}