From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: William Blake Galbreath <Blake.Galbreath@GMail.com>
Date: Thu, 26 Dec 2019 22:08:37 -0600
Subject: [PATCH] Add player death exp control options


diff --git a/src/main/java/net/minecraft/world/entity/player/EntityHuman.java b/src/main/java/net/minecraft/world/entity/player/EntityHuman.java
index 8f9d0769e7855c3565a34927f3f3741c43e45f35..2ee7daa155d812af8f84ba646106d801d2fb0fec 100644
--- a/src/main/java/net/minecraft/world/entity/player/EntityHuman.java
+++ b/src/main/java/net/minecraft/world/entity/player/EntityHuman.java
@@ -183,6 +183,8 @@ public abstract class EntityHuman extends EntityLiving {
     // CraftBukkit end
 
     // Purpur start
+    private javax.script.ScriptEngine scriptEngine = new javax.script.ScriptEngineManager().getEngineByName("rhino");
+
     public void setAfk(boolean setAfk){
     }
 
@@ -1814,9 +1816,18 @@ public abstract class EntityHuman extends EntityLiving {
     @Override
     protected int getExpValue(EntityHuman entityhuman) {
         if (!this.world.getGameRules().getBoolean(GameRules.KEEP_INVENTORY) && !this.isSpectator()) {
-            int i = this.expLevel * 7;
-
-            return i > 100 ? 100 : i;
+            // Purpur start
+            int toDrop;
+            try {
+                scriptEngine.eval("expLevel = " + expLevel);
+                scriptEngine.eval("expTotal = " + expTotal);
+                scriptEngine.eval("exp = " + exp);
+                toDrop = (int) Math.round((Double) scriptEngine.eval(world.purpurConfig.playerDeathExpDropEquation));
+            } catch (Exception ignore) {
+                toDrop = expLevel * 7;
+            }
+            return Math.min(toDrop, world.purpurConfig.playerDeathExpDropMax);
+            // Purpur end
         } else {
             return 0;
         }
diff --git a/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java b/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
index d51ee6ff1b73f0bafec88fd5445df37a1182c5d0..e10aa8ddbcea3588b2da08de929eed18cb9f022c 100644
--- a/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
+++ b/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
@@ -123,6 +123,13 @@ public class PurpurWorldConfig {
         tridentLoyaltyVoidReturnHeight = getDouble("gameplay-mechanics.trident-loyalty-void-return-height", tridentLoyaltyVoidReturnHeight);
     }
 
+    public String playerDeathExpDropEquation = "expLevel * 7";
+    public int playerDeathExpDropMax = 100;
+    private void playerDeathExpSettings() {
+        playerDeathExpDropEquation = getString("gameplay-mechanics.player.exp-dropped-on-death.equation", playerDeathExpDropEquation);
+        playerDeathExpDropMax = getInt("gameplay-mechanics.player.exp-dropped-on-death.maximum", playerDeathExpDropMax);
+    }
+
     public int playerSpawnInvulnerableTicks = 60;
     public boolean playerInvulnerableWhileAcceptingResourcePack = false;
     private void playerInvulnerabilities() {
