mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-12-21 05:50:18 +08:00
Fixes sonar bugs & vulnerabilities:
createNewFile not required with Files.write "In other words, it opens the file for writing, creating the file if it doesn't exist, --" https://docs.oracle.com/javase/7/docs/api/java/nio/file/Files.html#write(java.nio.file.Path,%20byte[],%20java.nio.file.OpenOption...)
This commit is contained in:
parent
156aef8ce4
commit
6a29bfae16
@ -22,6 +22,7 @@ import java.nio.file.Files;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@ -83,11 +84,15 @@ public class Locale {
|
||||
}
|
||||
|
||||
private void writeNewDefaultLocale() throws IOException {
|
||||
final int length = messages.keySet().stream()
|
||||
|
||||
Optional<String> key = messages.keySet().stream()
|
||||
.map(Msg::getIdentifier)
|
||||
.sorted(new StringLengthComparator())
|
||||
.findFirst()
|
||||
.get().length() + 2;
|
||||
.findFirst();
|
||||
if (!key.isPresent()) {
|
||||
throw new IllegalStateException("Locale has not been loaded.");
|
||||
}
|
||||
final int length = key.get().length() + 2;
|
||||
List<String> lines = messages.entrySet().stream()
|
||||
.sorted(new LocaleEntryComparator())
|
||||
.map(entry -> getSpacedIdentifier(entry.getKey().getIdentifier(), length) + "|| " + entry.getValue().toString())
|
||||
|
@ -80,11 +80,4 @@ public enum Html {
|
||||
}
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param html Sets the HTML String
|
||||
*/
|
||||
public void setHtml(String html) {
|
||||
this.html = html;
|
||||
}
|
||||
}
|
||||
|
@ -124,8 +124,6 @@ public class ExportUtility {
|
||||
playerFolder.mkdirs();
|
||||
|
||||
File inspectHtmlFile = new File(playerFolder, "index.html");
|
||||
inspectHtmlFile.createNewFile();
|
||||
|
||||
Files.write(inspectHtmlFile.toPath(), Collections.singletonList(inspectHtml));
|
||||
} catch (IOException e) {
|
||||
Log.toLog("Export.writeInspectHtml: " + name, e);
|
||||
@ -148,7 +146,6 @@ public class ExportUtility {
|
||||
.replace(HtmlUtils.getInspectUrl(""), "../player/");
|
||||
File analysisHtmlFile = new File(serverFolder, "index.html");
|
||||
Log.debug("Export", "Analysis Page File: " + analysisHtmlFile.getAbsolutePath());
|
||||
analysisHtmlFile.createNewFile();
|
||||
Files.write(analysisHtmlFile.toPath(), Collections.singletonList(analysisHtml));
|
||||
}
|
||||
|
||||
@ -157,7 +154,6 @@ public class ExportUtility {
|
||||
playersFolder.mkdirs();
|
||||
File playersHtmlFile = new File(playersFolder, "index.html");
|
||||
Log.debug("Export", "Players Page File: " + playersHtmlFile.getAbsolutePath());
|
||||
playersHtmlFile.createNewFile();
|
||||
Files.write(playersHtmlFile.toPath(), Collections.singletonList(playersHtml));
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
package main.java.com.djrapitops.plan.utilities.metrics;
|
||||
|
||||
import com.djrapitops.plugin.api.TimeAmount;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -203,7 +204,7 @@ public class Metrics {
|
||||
// Don't be afraid! The connection to the bStats server is still async, only the stats collection is sync ;)
|
||||
Bukkit.getScheduler().runTask(plugin, () -> submitData());
|
||||
}
|
||||
}, 1000 * 60 * 5, 1000 * 60 * 30);
|
||||
}, TimeAmount.MINUTE.ms() * 5, TimeAmount.MINUTE.ms() * 30);
|
||||
// Submit the data every 30 minutes, first time after 5 minutes to give other plugins enough time to start
|
||||
// WARNING: Changing the frequency has no effect but your plugin WILL be blocked/deleted!
|
||||
// WARNING: Just don't do it!
|
||||
|
@ -44,18 +44,6 @@ public class HtmlTest {
|
||||
assertEquals(expResult, result);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void testSetHtml() {
|
||||
Html instance = Html.SPAN;
|
||||
String expResult = "Test</span>";
|
||||
instance.setHtml(expResult);
|
||||
String result = instance.parse();
|
||||
assertEquals(expResult, result);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user