Skip to content

Commit

Permalink
Code has been formated
Browse files Browse the repository at this point in the history
  • Loading branch information
robotman3000 committed Oct 3, 2015
1 parent bf79a13 commit 477aaf0
Show file tree
Hide file tree
Showing 4 changed files with 563 additions and 551 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,71 +13,74 @@

public class CommonLogic {

public static void dirDelete(File file) throws IOException {
if (file.isDirectory()) {
if (file.list().length == 0)
file.delete();
else {
String files[] = file.list();
public static void dirDelete(File file) throws IOException {
if (file.isDirectory()) {
if (file.list().length == 0) {
file.delete();
} else {
String files[] = file.list();

for (String temp : files)
dirDelete(new File(file, temp));
for (String temp : files) {
CommonLogic.dirDelete(new File(file, temp));
}

if (file.list().length == 0)
file.delete();
}
} else
file.delete();
}

public static String loadJsonAsString(File theJsonFile) {
StringBuffer str = new StringBuffer();
try {
theJsonFile.createNewFile();
BufferedReader read = new BufferedReader(new FileReader(theJsonFile));
String v = "";
while((v = read.readLine()) != null){
str.append(v);
}
read.close();
} catch (IOException e) {
Bukkit.getLogger().warning("Error reading config file");
e.printStackTrace();
}
if (file.list().length == 0) {
file.delete();
}
}
} else {
file.delete();
}
}

String config = str.toString();
return config;
}
public static String loadJsonAsString(File theJsonFile) {
StringBuffer str = new StringBuffer();
try {
theJsonFile.createNewFile();
BufferedReader read = new BufferedReader(new FileReader(theJsonFile));
String v = "";
while ((v = read.readLine()) != null) {
str.append(v);
}
read.close();
} catch (IOException e) {
Bukkit.getLogger().warning("Error reading config file");
e.printStackTrace();
}

public static void saveJsonAsFile(File theJsonFile, String fileContents){
try {
theJsonFile.createNewFile(); // This only makes a new file if one doesnt already exist
BufferedWriter write = new BufferedWriter(new FileWriter(theJsonFile));
write.write(fileContents);
write.flush();
write.close();
} catch (IOException e) {
Bukkit.getLogger().warning("Error saving config file");
e.printStackTrace();
}
}
String config = str.toString();
return config;
}

public static ChatColor printEnvColor(Environment environment) {
if(environment.equals(Environment.NORMAL)){
return ChatColor.GREEN;
} else if(environment.equals(Environment.NETHER)){
return ChatColor.RED;
} else if(environment.equals(Environment.THE_END)){
return ChatColor.BLACK;
}
return ChatColor.WHITE;
}

public static void printDebug(String message){
if(message == null){
message = "";
}

Bukkit.getLogger().warning(message);
}
public static void printDebug(String message) {
if (message == null) {
message = "";
}

Bukkit.getLogger().warning(message);
}

public static ChatColor printEnvColor(Environment environment) {
if (environment.equals(Environment.NORMAL)) {
return ChatColor.GREEN;
} else if (environment.equals(Environment.NETHER)) {
return ChatColor.RED;
} else if (environment.equals(Environment.THE_END)) {
return ChatColor.BLACK;
}
return ChatColor.WHITE;
}

public static void saveJsonAsFile(File theJsonFile, String fileContents) {
try {
theJsonFile.createNewFile(); // This only makes a new file if one doesn't already exist
BufferedWriter write = new BufferedWriter(new FileWriter(theJsonFile));
write.write(fileContents);
write.flush();
write.close();
} catch (IOException e) {
Bukkit.getLogger().warning("Error saving config file");
e.printStackTrace();
}
}
}
Loading

0 comments on commit 477aaf0

Please sign in to comment.