diff --git a/src/main/java/com/dre/brewery/BPlayer.java b/src/main/java/com/dre/brewery/BPlayer.java index 0c993f24..a6923276 100644 --- a/src/main/java/com/dre/brewery/BPlayer.java +++ b/src/main/java/com/dre/brewery/BPlayer.java @@ -670,20 +670,21 @@ public static void puke(Player player) { if (VERSION.isOrLater(MinecraftVersion.V1_14)) item.setPersistent(false); // No need to save Puke items int pukeDespawntime = config.getPukeDespawntime(); - if (pukeDespawntime >= 5800) { + int despawnRate = BUtil.getItemDespawnRate(player.getWorld()); + if (pukeDespawntime >= (despawnRate - 200)) { return; } // Setting the age determines when an item is despawned. At age 6000 it is removed. if (pukeDespawntime <= 0) { // Just show the item for a few ticks - item.setTicksLived(5996); + item.setTicksLived(despawnRate - 4); } else if (pukeDespawntime <= 120) { // it should despawn in less than 6 sec. Add up to half of that randomly - item.setTicksLived(6000 - pukeDespawntime + pukeRand.nextInt((int) (pukeDespawntime / 2F))); + item.setTicksLived(despawnRate - pukeDespawntime + pukeRand.nextInt((int) (pukeDespawntime / 2F))); } else { // Add up to 5 sec randomly - item.setTicksLived(6000 - pukeDespawntime + pukeRand.nextInt(100)); + item.setTicksLived(despawnRate - pukeDespawntime + pukeRand.nextInt(100)); } } diff --git a/src/main/java/com/dre/brewery/utility/BUtil.java b/src/main/java/com/dre/brewery/utility/BUtil.java index 9bff415e..43776963 100644 --- a/src/main/java/com/dre/brewery/utility/BUtil.java +++ b/src/main/java/com/dre/brewery/utility/BUtil.java @@ -36,6 +36,7 @@ import org.bukkit.block.Block; import org.bukkit.command.CommandSender; import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.Player; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.inventory.EquipmentSlot; @@ -475,32 +476,14 @@ public static String getDxlName(String worldName) { return worldName; } - @SuppressWarnings("ResultOfMethodCallIgnored") - public static void saveFile(InputStream in, File dest, String name, boolean overwrite) throws IOException { - if (in == null) return; - if (!dest.exists()) { - dest.mkdirs(); - } - File result = new File(dest, name); - if (result.exists()) { - if (overwrite) { - result.delete(); - } else { - return; - } - } - - OutputStream out = new FileOutputStream(result); - byte[] buffer = new byte[1024]; + public static int getItemDespawnRate(World world) { + YamlConfiguration spigotConfig = Bukkit.spigot().getConfig(); - int length; - //copy the file content in bytes - while ((length = in.read(buffer)) > 0) { - out.write(buffer, 0, length); + int worldDespawnRate = spigotConfig.getInt("world-settings." + world.getName() + ".item-despawn-rate", -1); + if (worldDespawnRate < 0) { + return spigotConfig.getInt("world-settings.default.item-despawn-rate", 6000); } - - in.close(); - out.close(); + return worldDespawnRate; }