2020-02-11 05:35:46 +01:00
|
|
|
From fc4be0daa199c8716a12c431312350cd316a1445 Mon Sep 17 00:00:00 2001
|
2019-08-07 23:06:08 +02: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
|
2020-01-18 18:28:32 +01:00
|
|
|
index a09282e00..9d9260ad0 100644
|
2019-08-07 23:06:08 +02:00
|
|
|
--- a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
|
|
|
|
+++ b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
|
|
|
|
@@ -1,12 +1,17 @@
|
|
|
|
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.ChunkEdgeMode;
|
|
|
|
import com.destroystokyo.paper.antixray.ChunkPacketBlockControllerAntiXray.EngineMode;
|
|
|
|
import net.minecraft.server.MinecraftServer;
|
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
+import org.bukkit.Material;
|
|
|
|
+import org.bukkit.configuration.ConfigurationSection;
|
|
|
|
import org.bukkit.configuration.file.YamlConfiguration;
|
|
|
|
import org.spigotmc.SpigotWorldConfig;
|
|
|
|
|
2020-01-18 18:28:32 +01:00
|
|
|
@@ -560,4 +565,52 @@ public class PaperWorldConfig {
|
2019-08-07 23:06:08 +02: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));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
}
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/EntityItem.java b/src/main/java/net/minecraft/server/EntityItem.java
|
2020-02-11 05:35:46 +01:00
|
|
|
index ef2cf6565..507627a29 100644
|
2019-08-07 23:06:08 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/EntityItem.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/EntityItem.java
|
2019-12-12 17:20:43 +01:00
|
|
|
@@ -6,6 +6,7 @@ import java.util.Objects;
|
2019-08-07 23:06:08 +02:00
|
|
|
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
|
2019-12-12 17:20:43 +01:00
|
|
|
@@ -128,7 +129,7 @@ public class EntityItem extends Entity {
|
2019-08-07 23:06:08 +02: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;
|
2019-12-12 17:20:43 +01:00
|
|
|
@@ -152,7 +153,7 @@ public class EntityItem extends Entity {
|
2019-08-07 23:06:08 +02: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;
|
2019-12-12 17:20:43 +01:00
|
|
|
@@ -478,9 +479,16 @@ public class EntityItem extends Entity {
|
2019-08-07 23:06:08 +02:00
|
|
|
|
2019-12-12 17:20:43 +01:00
|
|
|
public void s() {
|
|
|
|
this.o();
|
2019-08-07 23:06:08 +02: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
|
2019-12-12 17:20:43 +01:00
|
|
|
public Packet<?> L() {
|
2019-08-07 23:06:08 +02:00
|
|
|
return new PacketPlayOutSpawnEntity(this);
|
|
|
|
--
|
2020-01-30 10:36:03 +01:00
|
|
|
2.25.0
|
2019-08-07 23:06:08 +02:00
|
|
|
|