Skip to content

Commit

Permalink
fix: puke despawn rate
Browse files Browse the repository at this point in the history
  • Loading branch information
Jsinco committed Jan 11, 2025
1 parent 5c02ad3 commit ccfa0cb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 28 deletions.
9 changes: 5 additions & 4 deletions src/main/java/com/dre/brewery/BPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}

Expand Down
31 changes: 7 additions & 24 deletions src/main/java/com/dre/brewery/utility/BUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}


Expand Down

1 comment on commit ccfa0cb

@Nadwey
Copy link
Member

@Nadwey Nadwey commented on ccfa0cb Jan 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we cache this?

Please sign in to comment.