From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: William Blake Galbreath 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 afa14eddb6a21d4747689af6d70551f10d304be7..f9ce15aa4a2b1ee07f9c31b793410a4ff27ec829 100644 --- a/src/main/java/net/minecraft/world/entity/player/EntityHuman.java +++ b/src/main/java/net/minecraft/world/entity/player/EntityHuman.java @@ -182,6 +182,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){ } @@ -1825,9 +1827,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 21ecfc0a1ee6d39e0b824aa3ce146a8833bd20ce..32087bcc02c20448988c76e04dbc0dcc3db48641 100644 --- a/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java +++ b/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java @@ -157,6 +157,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() {