Skip to content

Commit

Permalink
Moved the Prison File System Check to the PrisonStatsUtil class and g…
Browse files Browse the repository at this point in the history
…ot it out of the SpigotPlatform.
  • Loading branch information
rbluer committed Aug 30, 2024
1 parent 1b040fc commit ed50286
Showing 3 changed files with 95 additions and 88 deletions.
4 changes: 4 additions & 0 deletions docs/changelog_v3.3.x.md
Original file line number Diff line number Diff line change
@@ -17,6 +17,10 @@ These change logs represent the work that has been going on within prison.
# 3.3.0-alpha.18d 2024-08-30


* **Moved the Prison File System Check to the PrisonStatsUtil class and got it out of the SpigotPlatform.**



* **Player Cache: Fixed a problem with creating missing directories.... forgot to use the parent of the file, which is the current directory for the player cache files.**


Original file line number Diff line number Diff line change
@@ -132,6 +132,11 @@ public ChatDisplay displayVersion(String options) {
boolean showLaddersAndRanks = true;
Prison.get().getPlatform().prisonVersionFeatures(display, isBasic, showLaddersAndRanks);


// check directory structures:
checkDirectoryStructures( display );


return display;
}

@@ -141,6 +146,88 @@ public StringBuilder getSupportSubmitVersionData() {
return text;
}


private void checkDirectoryStructures(ChatDisplay display) {


display.addText(".");
display.addText("&7Prison File System Check:");

display.addText( checkDirectory( "/" ) );
display.addText( checkDirectory( "backpacks" ) );
display.addText( checkDirectory( "backups" ) );
display.addText( checkDirectory( "data_storage" ) );
display.addText( checkDirectory( "data_storage/mines" ) );
display.addText( checkDirectory( "data_storage/playerCache" ) );
display.addText( checkDirectory( "data_storage/ranksDb" ) );
display.addText( checkDirectory( "data_storage/ranksDb/ladders" ) );
display.addText( checkDirectory( "data_storage/ranksDb/players" ) );
display.addText( checkDirectory( "data_storage/ranksDb/ranks" ) );
display.addText( checkDirectory( "module_conf" ) );

}

private String checkDirectory( String dirPath ) {

String pathMask = Prison.get().getDataFolder().getParentFile().getAbsolutePath();

File path = new File( Prison.get().getDataFolder(), dirPath );
boolean pathCreated = path.mkdirs();

int countDirs = 0;
int countFiles = 0;
double fileSize = 0;
String fileSizeUnit = "";

File[] files = path.listFiles();
for (File f : files) {

if ( f.isDirectory() ) {
countDirs++;
}
else if ( f.isFile() ) {
countFiles++;
fileSize += f.length();
}
}

if ( fileSize > 0 ) {
fileSizeUnit = "bytes";

if ( fileSize >= 1024 ) {
fileSize /= 1024.0;
fileSizeUnit = "KB";

if ( fileSize >= 1024 ) {
fileSize /= 1024.0;
fileSizeUnit = "MB";

if ( fileSize >= 1024 ) {
fileSize /= 1024.0;
fileSizeUnit = "GB";

}
}
}
}



DecimalFormat iFmt = Prison.getDecimalFormatStaticInt();
DecimalFormat dFmt = Prison.getDecimalFormatStaticDouble();
String msg = String.format(
" &bplugins%-40s &2dirs: &b%3s &2files: &b%3s &2totalFileSize: &b%7s &3%s %s",
path.getAbsolutePath().replace(pathMask, ""),
(countDirs == 0 ? "&3" : "") + iFmt.format( countDirs ),
(countFiles == 0 ? "&3" : "") + iFmt.format( countFiles ),
(fileSize == 0 ? "&3" : "") + dFmt.format( fileSize ),
fileSizeUnit,
( pathCreated ? " &6DirCreated!" : "" )
);

return msg;
}


public StringBuilder getColorTest() {
StringBuilder sb = new StringBuilder();
Original file line number Diff line number Diff line change
@@ -2793,93 +2793,11 @@ else if ( !isBasic ) {
// new WorldGuardSettings();


// check directory structures:
checkDirectoryStructures( display );



}


private void checkDirectoryStructures(ChatDisplay display) {


display.addText(".");
display.addText("&7Prison File System Check:");

display.addText( checkDirectory( "/" ) );
display.addText( checkDirectory( "backpacks" ) );
display.addText( checkDirectory( "backups" ) );
display.addText( checkDirectory( "data_storage" ) );
display.addText( checkDirectory( "data_storage/mines" ) );
display.addText( checkDirectory( "data_storage/playerCache" ) );
display.addText( checkDirectory( "data_storage/ranksDb" ) );
display.addText( checkDirectory( "data_storage/ranksDb/ladders" ) );
display.addText( checkDirectory( "data_storage/ranksDb/players" ) );
display.addText( checkDirectory( "data_storage/ranksDb/ranks" ) );
display.addText( checkDirectory( "module_conf" ) );

}

private String checkDirectory( String dirPath ) {

String pathMask = Prison.get().getDataFolder().getParentFile().getAbsolutePath();

File path = new File( Prison.get().getDataFolder(), dirPath );
boolean pathCreated = path.mkdirs();

int countDirs = 0;
int countFiles = 0;
double fileSize = 0;
String fileSizeUnit = "";

File[] files = path.listFiles();
for (File f : files) {

if ( f.isDirectory() ) {
countDirs++;
}
else if ( f.isFile() ) {
countFiles++;
fileSize += f.length();
}
}

if ( fileSize > 0 ) {
fileSizeUnit = "bytes";

if ( fileSize >= 1024 ) {
fileSize /= 1024.0;
fileSizeUnit = "KB";

if ( fileSize >= 1024 ) {
fileSize /= 1024.0;
fileSizeUnit = "MB";

if ( fileSize >= 1024 ) {
fileSize /= 1024.0;
fileSizeUnit = "GB";

}
}
}
}



DecimalFormat iFmt = Prison.getDecimalFormatStaticInt();
DecimalFormat dFmt = Prison.getDecimalFormatStaticDouble();
String msg = String.format(
" plugins&b%-40s &2dirs: &b%3s &2files: &b%3s &2totalFileSize: &b%7s &3%s %s",
path.getAbsolutePath().replace(pathMask, ""),
iFmt.format( countDirs ),
iFmt.format( countFiles ),
dFmt.format( fileSize ),
fileSizeUnit,
( pathCreated ? " &6DirCreated!" : "" )
);

return msg;
}

@Override
public PlayerUtil getPlayerUtil( UUID playerUuid ) {
@@ -2905,14 +2823,12 @@ public String dumpEventListenersBlockBreakEvents() {
// NOTE: the use of '..==..' prevents these packages from being shortened. See end of this function.

sb.append( "\n" );
sb.append( "&2NOTE: Prison Block Event Listeners:\n" );
sb.append( "&2NOTE: Prison's Block-Event Listeners:\n" );

sb.append( "&2. . Prison Internal BlockBreakEvents: " +
sb.append( "&2. . Prison Internal BlockBreakEvents (non-auto features): " +
"tmps.SpigotListener\n" );
sb.append( "&2. . Auto Features: " +
"tmps.ae.AutoManagerBlockBreakEvents$AutoManagerBlockBreakEventListener\n" );
sb.append( "&2. . Prison's multi-block explosions (bombs): " +
"tmpsae.AutoManagerPrisonsExplosiveBlockBreakEvents$AutoManagerExplosiveBlockBreakEventListener\n" );
"tmps.ae.AutoManagerBlockBreakEvents$*]\n" );
sb.append( "&2. . Prison Abbrv: '&3tmps.&2' = '&3tech..==..mcprison.prison.spigot.&2' & " +
"'&3tmps.ae.&2' = '&3tmps..==..autofeatures.events.&2'\n" );

0 comments on commit ed50286

Please sign in to comment.