2020-05-06 09:48:49 +00:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
2019-08-07 21:06:08 +00:00
|
|
|
From: kickash32 <kickash32@gmail.com>
|
|
|
|
Date: Mon, 3 Jun 2019 02:02:39 -0400
|
|
|
|
Subject: [PATCH] Implement alternative item-despawn-rate
|
|
|
|
|
|
|
|
|
|
|
|
diff --git a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
|
2021-01-11 01:44:06 +00:00
|
|
|
index 1ee2cced100626e48eb36ee14f84b9257c79a2f8..b913cd2dd0cd1b369b3f7b5a9d8b1be73f6d7920 100644
|
2019-08-07 21:06:08 +00:00
|
|
|
--- a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
|
|
|
|
+++ b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
|
2020-05-06 08:35:20 +00:00
|
|
|
@@ -1,10 +1,15 @@
|
2019-08-07 21:06:08 +00:00
|
|
|
package com.destroystokyo.paper;
|
|
|
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
+import java.util.EnumMap;
|
|
|
|
+import java.util.HashMap;
|
|
|
|
import java.util.List;
|
|
|
|
+import java.util.Map;
|
|
|
|
|
|
|
|
import com.destroystokyo.paper.antixray.ChunkPacketBlockControllerAntiXray.EngineMode;
|
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
+import org.bukkit.Material;
|
|
|
|
+import org.bukkit.configuration.ConfigurationSection;
|
|
|
|
import org.bukkit.configuration.file.YamlConfiguration;
|
|
|
|
import org.spigotmc.SpigotWorldConfig;
|
|
|
|
|
2021-01-11 01:44:06 +00:00
|
|
|
@@ -512,4 +517,52 @@ public class PaperWorldConfig {
|
2019-08-07 21:06:08 +00:00
|
|
|
private void disableRelativeProjectileVelocity() {
|
|
|
|
disableRelativeProjectileVelocity = getBoolean("game-mechanics.disable-relative-projectile-velocity", false);
|
|
|
|
}
|
|
|
|
+
|
|
|
|
+ public boolean altItemDespawnRateEnabled;
|
|
|
|
+ public Map<Material, Integer> altItemDespawnRateMap;
|
|
|
|
+ private void altItemDespawnRate() {
|
|
|
|
+ String path = "alt-item-despawn-rate";
|
|
|
|
+
|
|
|
|
+ altItemDespawnRateEnabled = getBoolean(path + ".enabled", false);
|
|
|
|
+
|
|
|
|
+ Map<Material, Integer> altItemDespawnRateMapDefault = new EnumMap<>(Material.class);
|
|
|
|
+ altItemDespawnRateMapDefault.put(Material.COBBLESTONE, 300);
|
|
|
|
+ for (Material key : altItemDespawnRateMapDefault.keySet()) {
|
|
|
|
+ config.addDefault("world-settings.default." + path + ".items." + key, altItemDespawnRateMapDefault.get(key));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Map<String, Integer> rawMap = new HashMap<>();
|
|
|
|
+ try {
|
|
|
|
+ ConfigurationSection mapSection = config.getConfigurationSection("world-settings." + worldName + "." + path + ".items");
|
|
|
|
+ if (mapSection == null) {
|
|
|
|
+ mapSection = config.getConfigurationSection("world-settings.default." + path + ".items");
|
|
|
|
+ }
|
|
|
|
+ for (String key : mapSection.getKeys(false)) {
|
|
|
|
+ int val = mapSection.getInt(key);
|
|
|
|
+ rawMap.put(key, val);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ catch (Exception e) {
|
|
|
|
+ logError("alt-item-despawn-rate was malformatted");
|
|
|
|
+ altItemDespawnRateEnabled = false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ altItemDespawnRateMap = new EnumMap<>(Material.class);
|
|
|
|
+ if (!altItemDespawnRateEnabled) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ for(String key : rawMap.keySet()) {
|
|
|
|
+ try {
|
|
|
|
+ altItemDespawnRateMap.put(Material.valueOf(key), rawMap.get(key));
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ logError("Could not add item " + key + " to altItemDespawnRateMap: " + e.getMessage());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if(altItemDespawnRateEnabled) {
|
|
|
|
+ for(Material key : altItemDespawnRateMap.keySet()) {
|
|
|
|
+ log("Alternative item despawn rate of " + key + ": " + altItemDespawnRateMap.get(key));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
}
|
2021-03-16 07:19:45 +00:00
|
|
|
diff --git a/src/main/java/net/minecraft/world/entity/item/EntityItem.java b/src/main/java/net/minecraft/world/entity/item/EntityItem.java
|
|
|
|
index 02e4d6891adc902f73ed349f15dae3a429bd283a..0b2e6e72a85e05f239d56afb6785c91da5b25d55 100644
|
|
|
|
--- a/src/main/java/net/minecraft/world/entity/item/EntityItem.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/entity/item/EntityItem.java
|
|
|
|
@@ -33,6 +33,7 @@ import net.minecraft.world.phys.Vec3D;
|
2021-03-08 23:12:31 +00:00
|
|
|
|
2019-08-07 21:06:08 +00:00
|
|
|
// CraftBukkit start
|
2021-03-16 07:19:45 +00:00
|
|
|
import net.minecraft.server.MinecraftServer;
|
2019-08-07 21:06:08 +00:00
|
|
|
+import org.bukkit.Material; // Paper
|
|
|
|
import org.bukkit.event.entity.EntityPickupItemEvent;
|
|
|
|
import org.bukkit.event.player.PlayerPickupItemEvent;
|
|
|
|
// CraftBukkit end
|
2021-03-16 07:19:45 +00:00
|
|
|
@@ -161,7 +162,7 @@ public class EntityItem extends Entity {
|
2019-08-07 21:06:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- if (!this.world.isClientSide && this.age >= world.spigotConfig.itemDespawnRate) { // Spigot
|
|
|
|
+ if (!this.world.isClientSide && this.age >= this.getDespawnRate()) { // Spigot // Paper
|
|
|
|
// CraftBukkit start - fire ItemDespawnEvent
|
|
|
|
if (org.bukkit.craftbukkit.event.CraftEventFactory.callItemDespawnEvent(this).isCancelled()) {
|
|
|
|
this.age = 0;
|
2021-03-16 07:19:45 +00:00
|
|
|
@@ -185,7 +186,7 @@ public class EntityItem extends Entity {
|
2019-08-07 21:06:08 +00:00
|
|
|
this.lastTick = MinecraftServer.currentTick;
|
|
|
|
// CraftBukkit end
|
|
|
|
|
|
|
|
- if (!this.world.isClientSide && this.age >= world.spigotConfig.itemDespawnRate) { // Spigot
|
|
|
|
+ if (!this.world.isClientSide && this.age >= this.getDespawnRate()) { // Spigot // Paper
|
|
|
|
// CraftBukkit start - fire ItemDespawnEvent
|
|
|
|
if (org.bukkit.craftbukkit.event.CraftEventFactory.callItemDespawnEvent(this).isCancelled()) {
|
|
|
|
this.age = 0;
|
2021-03-16 07:19:45 +00:00
|
|
|
@@ -535,9 +536,16 @@ public class EntityItem extends Entity {
|
2019-08-07 21:06:08 +00:00
|
|
|
|
2019-12-12 16:20:43 +00:00
|
|
|
public void s() {
|
|
|
|
this.o();
|
2019-08-07 21:06:08 +00:00
|
|
|
- this.age = world.spigotConfig.itemDespawnRate - 1; // Spigot
|
|
|
|
+ this.age = this.getDespawnRate() - 1; // Spigot // Paper
|
|
|
|
}
|
|
|
|
|
|
|
|
+ // Paper start
|
|
|
|
+ public int getDespawnRate(){
|
|
|
|
+ Material material = this.getItemStack().getBukkitStack().getType();
|
|
|
|
+ return world.paperConfig.altItemDespawnRateMap.getOrDefault(material, world.spigotConfig.itemDespawnRate);
|
|
|
|
+ }
|
|
|
|
+ // Paper end
|
|
|
|
+
|
|
|
|
@Override
|
2020-08-25 02:22:08 +00:00
|
|
|
public Packet<?> P() {
|
2019-08-07 21:06:08 +00:00
|
|
|
return new PacketPlayOutSpawnEntity(this);
|