aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/server/0364-Implement-alternative-item-despawn-rate.patch
blob: 74fb179ec77137ab0ddf386cf455a11f7e7c0272 (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
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 6b8f7fec3307bc643a1bdd1fb9f0572fdb9da560..5a1e82727e4861681736c2bb3ed01637c4c42e4d 100644
--- a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
+++ b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
@@ -565,5 +565,52 @@ public class PaperWorldConfig {
             Bukkit.getLogger().warning("You have enabled permission-based Anti-Xray checking - depending on your permission plugin, this may cause performance issues");
         }
     }
-}
 
+    public boolean altItemDespawnRateEnabled;
+    public java.util.Map<org.bukkit.Material, Integer> altItemDespawnRateMap;
+    private void altItemDespawnRate() {
+        String path = "alt-item-despawn-rate";
+
+        altItemDespawnRateEnabled = getBoolean(path + ".enabled", false);
+
+        java.util.Map<org.bukkit.Material, Integer> altItemDespawnRateMapDefault = new java.util.EnumMap<>(org.bukkit.Material.class);
+        altItemDespawnRateMapDefault.put(org.bukkit.Material.COBBLESTONE, 300);
+        for (org.bukkit.Material key : altItemDespawnRateMapDefault.keySet()) {
+            config.addDefault("world-settings.default." + path + ".items." + key, altItemDespawnRateMapDefault.get(key));
+        }
+
+        java.util.Map<String, Integer> rawMap = new java.util.HashMap<>();
+        try {
+            org.bukkit.configuration.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 java.util.EnumMap<>(org.bukkit.Material.class);
+        if (!altItemDespawnRateEnabled) {
+            return;
+        }
+
+        for(String key : rawMap.keySet()) {
+            try {
+                altItemDespawnRateMap.put(org.bukkit.Material.valueOf(key), rawMap.get(key));
+            } catch (Exception e) {
+                logError("Could not add item " + key + " to altItemDespawnRateMap: " + e.getMessage());
+            }
+        }
+        if(altItemDespawnRateEnabled) {
+            for(org.bukkit.Material key : altItemDespawnRateMap.keySet()) {
+                log("Alternative item despawn rate of " + key + ": " + altItemDespawnRateMap.get(key));
+            }
+        }
+    }
+}
diff --git a/src/main/java/net/minecraft/world/entity/item/ItemEntity.java b/src/main/java/net/minecraft/world/entity/item/ItemEntity.java
index 1378c8ab35b3828f7c0ad504e64bb72484a1026d..5a6534904e977b5ffbd55d05c4b65f02b3995910 100644
--- a/src/main/java/net/minecraft/world/entity/item/ItemEntity.java
+++ b/src/main/java/net/minecraft/world/entity/item/ItemEntity.java
@@ -174,7 +174,7 @@ public class ItemEntity extends Entity {
                 }
             }
 
-            if (!this.level.isClientSide && this.age >= level.spigotConfig.itemDespawnRate) { // Spigot
+            if (!this.level.isClientSide && this.age >= this.getDespawnRate()) { // Spigot // Paper
                 // CraftBukkit start - fire ItemDespawnEvent
                 if (org.bukkit.craftbukkit.event.CraftEventFactory.callItemDespawnEvent(this).isCancelled()) {
                     this.age = 0;
@@ -198,7 +198,7 @@ public class ItemEntity extends Entity {
         this.lastTick = MinecraftServer.currentTick;
         // CraftBukkit end
 
-        if (!this.level.isClientSide && this.age >= level.spigotConfig.itemDespawnRate) { // Spigot
+        if (!this.level.isClientSide && this.age >= this.getDespawnRate()) { // Spigot // Paper
             // CraftBukkit start - fire ItemDespawnEvent
             if (org.bukkit.craftbukkit.event.CraftEventFactory.callItemDespawnEvent(this).isCancelled()) {
                 this.age = 0;
@@ -558,9 +558,16 @@ public class ItemEntity extends Entity {
 
     public void makeFakeItem() {
         this.setNeverPickUp();
-        this.age = level.spigotConfig.itemDespawnRate - 1; // Spigot
+        this.age = this.getDespawnRate() - 1; // Spigot
     }
 
+    // Paper start
+    public int getDespawnRate(){
+        org.bukkit.Material material = this.getItem().getBukkitStack().getType();
+        return level.paperConfig.altItemDespawnRateMap.getOrDefault(material, level.spigotConfig.itemDespawnRate);
+    }
+    // Paper end
+
     public float getSpin(float tickDelta) {
         return ((float) this.getAge() + tickDelta) / 20.0F + this.bobOffs;
     }