diff --git a/src/main/java/me/badbones69/crazyauctions/Main.java b/src/main/java/me/badbones69/crazyauctions/Main.java index 10b1154..7fd7445 100644 --- a/src/main/java/me/badbones69/crazyauctions/Main.java +++ b/src/main/java/me/badbones69/crazyauctions/Main.java @@ -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 getDamageableItems() { ArrayList 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); + } + } \ No newline at end of file diff --git a/src/main/java/me/badbones69/crazyauctions/api/Messages.java b/src/main/java/me/badbones69/crazyauctions/api/Messages.java index 908f2fe..6fd619b 100644 --- a/src/main/java/me/badbones69/crazyauctions/api/Messages.java +++ b/src/main/java/me/badbones69/crazyauctions/api/Messages.java @@ -45,6 +45,7 @@ public enum Messages { CRAZYAUCTIONS_HELP("CrazyAuctions-Help", "&c/ah help"), CRAZYAUCTIONS_VIEW("CrazyAuctions-View", "&c/ah view "), CRAZYAUCTIONS_SELL_BID("CrazyAuctions-Sell-Bid", "&c/ah sell/bid [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.", diff --git a/src/main/java/me/badbones69/crazyauctions/api/Version.java b/src/main/java/me/badbones69/crazyauctions/api/Version.java index 1e8d810..a77b03d 100644 --- a/src/main/java/me/badbones69/crazyauctions/api/Version.java +++ b/src/main/java/me/badbones69/crazyauctions/api/Version.java @@ -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; } } \ No newline at end of file diff --git a/src/main/resources/Messages.yml b/src/main/resources/Messages.yml index 35bd150..7f58e74 100644 --- a/src/main/resources/Messages.yml +++ b/src/main/resources/Messages.yml @@ -34,6 +34,7 @@ Messages: CrazyAuctions-Help: '&c/ah help' CrazyAuctions-View: '&c/ah view ' CrazyAuctions-Sell-Bid: '&c/ah sell/bid [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.' diff --git a/src/main/resources/config1.12.2-Down.yml b/src/main/resources/config1.12.2-Down.yml index abd2793..cf8cb37 100644 --- a/src/main/resources/config1.12.2-Down.yml +++ b/src/main/resources/config1.12.2-Down.yml @@ -301,5 +301,4 @@ Settings: - '&7Click here to Bid Now.' BlackList: - '7' - - '120' - - 'WRITTEN_BOOK' \ No newline at end of file + - '120' \ No newline at end of file diff --git a/src/main/resources/config1.13-Up.yml b/src/main/resources/config1.13-Up.yml index 18bbfc3..d68ffde 100644 --- a/src/main/resources/config1.13-Up.yml +++ b/src/main/resources/config1.13-Up.yml @@ -300,5 +300,4 @@ Settings: - '&7Click here to Bid Now.' BlackList: - 'BEDROCK' - - 'END_PORTAL_FRAME' - - 'WRITTEN_BOOK' + - 'END_PORTAL_FRAME' \ No newline at end of file