aboutsummaryrefslogtreecommitdiffhomepage
path: root/Spigot-Server-Patches/0393-Implement-alternative-item-despawn-rate.patch
blob: 1479d50390d3d4ef7291264c523020cbc90e583b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
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
index 7101ef0912221bdb1c32d2cafbac5d9d53e7037d..9b43b4172ae5df253479a412ec0d83fed08d70f1 100644
--- a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
+++ b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
@@ -1,10 +1,15 @@
 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;
 
@@ -546,4 +551,52 @@ public class PaperWorldConfig {
     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));
+            }
+        }
+    }
 }
diff --git a/src/main/java/net/minecraft/server/EntityItem.java b/src/main/java/net/minecraft/server/EntityItem.java
index ef2cf6565b5935b1f1a80f12670609017aebb2c8..507627a29f67c380314d2fa8ee56807ced8ee56a 100644
--- a/src/main/java/net/minecraft/server/EntityItem.java
+++ b/src/main/java/net/minecraft/server/EntityItem.java
@@ -6,6 +6,7 @@ import java.util.Objects;
 import java.util.UUID;
 import javax.annotation.Nullable;
 // CraftBukkit start
+import org.bukkit.Material; // Paper
 import org.bukkit.event.entity.EntityPickupItemEvent;
 import org.bukkit.event.player.PlayerPickupItemEvent;
 // CraftBukkit end
@@ -128,7 +129,7 @@ public class EntityItem extends Entity {
                 }
             }
 
-            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;
@@ -152,7 +153,7 @@ public class EntityItem extends Entity {
         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;
@@ -478,9 +479,16 @@ public class EntityItem extends Entity {
 
     public void s() {
         this.o();
-        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
     public Packet<?> L() {
         return new PacketPlayOutSpawnEntity(this);