testserver/patches/server/0365-Implement-alternative-...

119 lines
5.1 KiB
Diff
Raw Normal View History

2021-06-11 12:02:28 +00:00
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
2021-06-14 02:41:44 +00:00
2021-06-11 12:02:28 +00:00
diff --git a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
2021-06-14 02:41:44 +00:00
index 3cd8895adecd345c3bdfb8b5e3e9fdf0ef9097db..be4a36df28d4f16727daad1270d5c3a84ae94613 100644
2021-06-11 12:02:28 +00:00
--- a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
+++ b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
2021-06-14 02:41:44 +00:00
@@ -1,8 +1,13 @@
2021-06-11 12:02:28 +00:00
package com.destroystokyo.paper;
+import java.util.EnumMap;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import org.bukkit.Bukkit;
+import org.bukkit.Material;
+import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration;
import org.spigotmc.SpigotWorldConfig;
2021-06-14 02:41:44 +00:00
@@ -450,5 +455,53 @@ public class PaperWorldConfig {
private void viewDistance() {
this.noTickViewDistance = this.getInt("viewdistances.no-tick-view-distance", -1);
2021-06-11 12:02:28 +00:00
}
+
+ 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-06-14 02:41:44 +00:00
2021-06-11 12:02:28 +00:00
diff --git a/src/main/java/net/minecraft/world/entity/item/ItemEntity.java b/src/main/java/net/minecraft/world/entity/item/ItemEntity.java
2021-06-14 02:41:44 +00:00
index 9ee1dc89dd4c6b9453e1f6f92208d454877d23c9..e0c13a112c95eed9867d4608e18dc797b0c9c9cf 100644
2021-06-11 12:02:28 +00:00
--- a/src/main/java/net/minecraft/world/entity/item/ItemEntity.java
+++ b/src/main/java/net/minecraft/world/entity/item/ItemEntity.java
2021-06-14 02:41:44 +00:00
@@ -175,7 +175,7 @@ public class ItemEntity extends Entity {
2021-06-11 12:02:28 +00:00
}
}
- 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;
2021-06-14 02:41:44 +00:00
@@ -199,7 +199,7 @@ public class ItemEntity extends Entity {
2021-06-11 12:02:28 +00:00
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;
2021-06-14 02:41:44 +00:00
@@ -559,9 +559,16 @@ public class ItemEntity extends Entity {
2021-06-11 12:02:28 +00:00
public void makeFakeItem() {
this.setNeverPickUp();
- this.age = level.spigotConfig.itemDespawnRate - 1; // Spigot
2021-06-14 02:41:44 +00:00
+ this.age = this.getDespawnRate() - 1; // Spigot
2021-06-11 12:02:28 +00:00
}
+ // Paper start
+ public int getDespawnRate(){
2021-06-14 02:41:44 +00:00
+ org.bukkit.Material material = this.getItem().getBukkitStack().getType();
2021-06-11 12:02:28 +00:00
+ return level.paperConfig.altItemDespawnRateMap.getOrDefault(material, level.spigotConfig.itemDespawnRate);
+ }
+ // Paper end
+
2021-06-14 02:41:44 +00:00
public float getSpin(float tickDelta) {
return ((float) this.getAge() + tickDelta) / 20.0F + this.bobOffs;
}