mirror of
https://github.com/Crazy-Crew/CrazyAuctions.git
synced 2025-01-07 19:28:10 +01:00
Fixed core issue of book errors.
Fixed: - Writable and written books that contained illegal unicode that SnakeYAML (inside Spigot/Bukkit) could not save caused an big error. This fixes it by saving to a new Test-File.yml and checks if it was able to be saved and if not denies that book.
This commit is contained in:
parent
8aa9db1fcb
commit
07ae647303
2
pom.xml
2
pom.xml
@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>me.badbones69</groupId>
|
||||
<artifactId>crazyauctions</artifactId>
|
||||
<version>1.2.14</version>
|
||||
<version>1.2.15</version>
|
||||
<name>CrazyAuctions</name>
|
||||
|
||||
<properties>
|
||||
|
@ -19,6 +19,7 @@ import org.bukkit.inventory.meta.BookMeta;
|
||||
import org.bukkit.permissions.PermissionAttachmentInfo;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.yaml.snakeyaml.error.YAMLException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
@ -466,6 +467,15 @@ public class Main extends JavaPlugin implements Listener {
|
||||
|
||||
private boolean allowBook(ItemStack item) {
|
||||
if (item != null && item.hasItemMeta() && item.getItemMeta() instanceof BookMeta) {
|
||||
System.out.println("[Crazy Auctions] Checking " + item.getType() + " for illegal unicode.");
|
||||
try {
|
||||
Files.TEST_FILE.getFile().set("Test", item);
|
||||
Files.TEST_FILE.saveFile();
|
||||
System.out.println("[Crazy Auctions] " + item.getType() + " has passed unicode checks.");
|
||||
} catch (YAMLException e) {
|
||||
System.out.println("[Crazy Auctions] " + item.getType() + " has failed unicode checks and has been denied.");
|
||||
return false;
|
||||
}
|
||||
return ((BookMeta) item.getItemMeta()).getPages().stream().mapToInt(String :: length).sum() < 2000;
|
||||
}
|
||||
return true;
|
||||
|
@ -54,7 +54,7 @@ public class FileManager {
|
||||
String fileLocation = file.getFileLocation();
|
||||
//Switch between 1.12.2- and 1.13+ config version.
|
||||
if (file == Files.CONFIG) {
|
||||
if (Version.getCurrentVersion().isOlder(Version.v1_13_R2)) {
|
||||
if (Version.isOlder(Version.v1_13_R2)) {
|
||||
fileLocation = "config1.12.2-Down.yml";
|
||||
} else {
|
||||
fileLocation = "config1.13-Up.yml";
|
||||
@ -292,7 +292,8 @@ public class FileManager {
|
||||
//ENUM_NAME("FileName.yml", "FilePath.yml"),
|
||||
CONFIG("config.yml", "config.yml"),
|
||||
DATA("Data.yml", "Data.yml"),
|
||||
MESSAGES("Messages.yml", "Messages.yml");
|
||||
MESSAGES("Messages.yml", "Messages.yml"),
|
||||
TEST_FILE("Test-File.yml", "Test-File.yml");
|
||||
|
||||
private String fileName;
|
||||
private String fileLocation;
|
||||
|
2
src/main/resources/Test-File.yml
Normal file
2
src/main/resources/Test-File.yml
Normal file
@ -0,0 +1,2 @@
|
||||
#!!DO NOT DELETE!!
|
||||
#Used for unicode checking in books.
|
Loading…
Reference in New Issue
Block a user