Writable and Written books now have a 2k character limit.

Fixed:
- When trying to sell a book that has a huge character amount it causes an error in console and creates a dup bug. A limit of 2k characters has been added to help prevent this. 
Note: If this seems to high or low it will be changed later.

Added:
- New Book-Not-Allowed message in the Messages.yml.

Removed:
- Written book was removed from the blacklist as this should fix any issue they caused.
This commit is contained in:
BadBones69 2020-05-21 03:49:47 -04:00
parent 67ed9a04e0
commit 4e11b2b302
6 changed files with 43 additions and 24 deletions

View File

@ -132,11 +132,10 @@ public class Main extends JavaPlugin implements Listener {
} else {
item.setAmount(item.getAmount() - amount);
}
return true;
} else {
sender.sendMessage(Messages.DOSENT_HAVE_ITEM_IN_HAND.getMessage());
return true;
}
return true;
}
if (args[0].equalsIgnoreCase("Reload")) {// CA Reload
if (!Methods.hasPermission(sender, "Admin")) return true;
@ -308,6 +307,10 @@ public class Main extends JavaPlugin implements Listener {
}
}
}
if (!allowBook(item)) {
player.sendMessage(Messages.BOOK_NOT_ALLOWED.getMessage());
return true;
}
String seller = player.getName();
// For testing as another player
//String seller = "Test-Account";
@ -341,6 +344,7 @@ public class Main extends JavaPlugin implements Listener {
Files.DATA.getFile().set("Items." + num + ".TopBidder", "None");
ItemStack I = item.clone();
I.setAmount(amount);
System.out.println(I.toString().length());
Files.DATA.getFile().set("Items." + num + ".Item", I);
Files.DATA.saveFile();
Bukkit.getPluginManager().callEvent(new AuctionListEvent(player, type, I, price));
@ -388,7 +392,7 @@ public class Main extends JavaPlugin implements Listener {
private ArrayList<Material> getDamageableItems() {
ArrayList<Material> ma = new ArrayList<>();
if (Version.getCurrentVersion().isNewer(Version.v1_12_R1)) {
if (Version.isNewer(Version.v1_12_R1)) {
ma.add(Material.matchMaterial("GOLDEN_HELMET"));
ma.add(Material.matchMaterial("GOLDEN_CHESTPLATE"));
ma.add(Material.matchMaterial("GOLDEN_LEGGINGS"));
@ -460,4 +464,15 @@ public class Main extends JavaPlugin implements Listener {
return ma;
}
private boolean allowBook(ItemStack item) {
if (item.getType() == Material.WRITTEN_BOOK || item.getType() == getMaterial("WRITABLE_BOOK", "BOOK_AND_QUILL")) {
return item.toString().length() > 2000;
}
return true;
}
public Material getMaterial(String newMaterial, String oldMaterial) {
return Material.matchMaterial(Version.isNewer(Version.v1_12_R1) ? newMaterial : oldMaterial);
}
}

View File

@ -45,6 +45,7 @@ public enum Messages {
CRAZYAUCTIONS_HELP("CrazyAuctions-Help", "&c/ah help"),
CRAZYAUCTIONS_VIEW("CrazyAuctions-View", "&c/ah view <player>"),
CRAZYAUCTIONS_SELL_BID("CrazyAuctions-Sell-Bid", "&c/ah sell/bid <price> [amount of items]"),
BOOK_NOT_ALLOWED("Book-Not-Allowed", "&cThat book is not able to be sold in this auction house!"),
HELP("Help-Menu", Arrays.asList(
"&e-- &6Crazy Auctions Help &e--",
"&9/Ah - &eOpens the crazy auction.",

View File

@ -15,9 +15,9 @@ public enum Version {
v1_14_R1(1141),
TOO_NEW(-2);
public static Version currentVersion;
private static Version currentVersion;
private static Version latest;
private Integer versionInteger;
private int versionInteger;
private Version(int versionInteger) {
this.versionInteger = versionInteger;
@ -30,7 +30,7 @@ public enum Version {
public static Version getCurrentVersion() {
if (currentVersion == null) {
String ver = Bukkit.getServer().getClass().getPackage().getName();
int v = Integer.parseInt(ver.substring(ver.lastIndexOf('.') + 1).replaceAll("_", "").replaceAll("R", "").replaceAll("v", ""));
int v = Integer.parseInt(ver.substring(ver.lastIndexOf('.') + 1).replace("_", "").replace("R", "").replace("v", ""));
for (Version version : values()) {
if (version.getVersionInteger() == v) {
currentVersion = version;
@ -62,6 +62,7 @@ public enum Version {
return v;
} else {
return latest;
}
}
@ -69,7 +70,7 @@ public enum Version {
*
* @return The server's minecraft version as an integer.
*/
public Integer getVersionInteger() {
public int getVersionInteger() {
return this.versionInteger;
}
@ -78,18 +79,18 @@ public enum Version {
* @param version The version you are checking.
* @return -1 if older, 0 if the same, and 1 if newer.
*/
public Integer comparedTo(Version version) {
int resault = -1;
public int comparedTo(Version version) {
int result = -1;
int current = this.getVersionInteger();
int check = version.getVersionInteger();
if (current > check || check == -2) {// check is newer then current
resault = 1;
result = 1;
} else if (current == check) {// check is the same as current
resault = 0;
} else if (current < check || check == -1) {// check is older then current
resault = -1;
result = 0;
} else if (check == -1) {// check is older then current
result = -1;
}
return resault;
return result;
}
/**
@ -97,8 +98,9 @@ public enum Version {
* @param version The version you are checking.
* @return True if newer then the checked version and false if the same or older.
*/
public Boolean isNewer(Version version) {
return this.versionInteger > version.versionInteger || this.versionInteger == -2;
public static boolean isNewer(Version version) {
if (currentVersion == null) getCurrentVersion();
return currentVersion.versionInteger > version.versionInteger || currentVersion.versionInteger == -2;
}
/**
@ -106,8 +108,9 @@ public enum Version {
* @param version The version you are checking.
* @return True if both the current and checked version is the same and false if otherwise.
*/
public Boolean isSame(Version version) {
return this.versionInteger.equals(version.versionInteger);
public static boolean isSame(Version version) {
if (currentVersion == null) getCurrentVersion();
return currentVersion.versionInteger == version.versionInteger;
}
/**
@ -115,8 +118,9 @@ public enum Version {
* @param version The version you are checking.
* @return True if older then the checked version and false if the same or newer.
*/
public Boolean isOlder(Version version) {
return this.versionInteger < version.versionInteger || this.versionInteger == -1;
public static boolean isOlder(Version version) {
if (currentVersion == null) getCurrentVersion();
return currentVersion.versionInteger < version.versionInteger || currentVersion.versionInteger == -1;
}
}

View File

@ -34,6 +34,7 @@ Messages:
CrazyAuctions-Help: '&c/ah help'
CrazyAuctions-View: '&c/ah view <player>'
CrazyAuctions-Sell-Bid: '&c/ah sell/bid <price> [amount of items]'
Book-Not-Allowed: '&cThat book is not able to be sold in this auction house!'
Help-Menu:
- '&e-- &6Crazy Auctions Help &e--'
- '&9/Ah - &eOpens the crazy auction.'

View File

@ -302,4 +302,3 @@ Settings:
BlackList:
- '7'
- '120'
- 'WRITTEN_BOOK'

View File

@ -301,4 +301,3 @@ Settings:
BlackList:
- 'BEDROCK'
- 'END_PORTAL_FRAME'
- 'WRITTEN_BOOK'