From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: William Blake Galbreath <blake.galbreath@gmail.com>
Date: Thu, 25 Jul 2019 18:07:37 -0500
Subject: [PATCH] Implement elytra settings


diff --git a/src/main/java/net/minecraft/world/entity/EntityLiving.java b/src/main/java/net/minecraft/world/entity/EntityLiving.java
index 6fb4b06df010c3099a1af3b145749ea439a4aa39..e2124f60b37436d2514f92e180e914b4d4a8470c 100644
--- a/src/main/java/net/minecraft/world/entity/EntityLiving.java
+++ b/src/main/java/net/minecraft/world/entity/EntityLiving.java
@@ -2955,7 +2955,16 @@ public abstract class EntityLiving extends Entity {
             if (itemstack.getItem() == Items.ELYTRA && ItemElytra.d(itemstack)) {
                 flag = true;
                 if (!this.world.isClientSide && (this.be + 1) % 20 == 0) {
-                    itemstack.damage(1, this, (entityliving) -> {
+                    // Purpur start
+                    int damage = world.purpurConfig.elytraDamagePerSecond;
+                    if (world.purpurConfig.elytraDamageMultiplyBySpeed > 0) {
+                        double speed = getMot().magnitudeSquared();
+                        if (speed > world.purpurConfig.elytraDamageMultiplyBySpeed) {
+                            damage *= (int) speed;
+                        }
+                    }
+                    itemstack.damage(damage, this, (entityliving) -> {
+                    // Purpur end
                         entityliving.broadcastItemBreak(EnumItemSlot.CHEST);
                     });
                 }
diff --git a/src/main/java/net/minecraft/world/item/ItemFireworks.java b/src/main/java/net/minecraft/world/item/ItemFireworks.java
index e7f958d137257da912ce9b83db017b4423959943..210b95f1d67ec12566d6fc93b8234e11ad132d1a 100644
--- a/src/main/java/net/minecraft/world/item/ItemFireworks.java
+++ b/src/main/java/net/minecraft/world/item/ItemFireworks.java
@@ -7,6 +7,7 @@ import net.minecraft.server.level.EntityPlayer;
 import net.minecraft.world.EnumHand;
 import net.minecraft.world.EnumInteractionResult;
 import net.minecraft.world.InteractionResultWrapper;
+import net.minecraft.world.entity.EnumItemSlot;
 import net.minecraft.world.entity.player.EntityHuman;
 import net.minecraft.world.entity.projectile.EntityFireworks;
 import net.minecraft.world.item.context.ItemActionContext;
@@ -53,6 +54,14 @@ public class ItemFireworks extends Item {
                 // Paper start
                 com.destroystokyo.paper.event.player.PlayerElytraBoostEvent event = new com.destroystokyo.paper.event.player.PlayerElytraBoostEvent((org.bukkit.entity.Player) entityhuman.getBukkitEntity(), org.bukkit.craftbukkit.inventory.CraftItemStack.asCraftMirror(itemstack), (org.bukkit.entity.Firework) entityfireworks.getBukkitEntity());
                 if (event.callEvent() && world.addEntity(entityfireworks)) {
+                    // Purpur start
+                    if (world.purpurConfig.elytraDamagePerFireworkBoost > 0) {
+                        ItemStack chestItem = entityhuman.getEquipment(EnumItemSlot.CHEST);
+                        if (chestItem.getItem() == Items.ELYTRA) {
+                            chestItem.damage(world.purpurConfig.elytraDamagePerFireworkBoost, entityhuman, (entityliving) -> entityliving.broadcastItemBreak(EnumItemSlot.CHEST));
+                        }
+                    }
+                    // Purpur end
                     if (event.shouldConsume() && !entityhuman.abilities.canInstantlyBuild) {
                         itemstack.subtract(1);
                     } else ((EntityPlayer) entityhuman).getBukkitEntity().updateInventory();
diff --git a/src/main/java/net/minecraft/world/item/ItemStack.java b/src/main/java/net/minecraft/world/item/ItemStack.java
index fcc6ee9481d577d39339cd0ac24dab06bd76e5c6..81e2ccfa4f6cf6a4ad9236cf0ce94df8dc3ec5b6 100644
--- a/src/main/java/net/minecraft/world/item/ItemStack.java
+++ b/src/main/java/net/minecraft/world/item/ItemStack.java
@@ -500,7 +500,7 @@ public final class ItemStack {
             int j;
 
             if (i > 0) {
-                j = EnchantmentManager.getEnchantmentLevel(Enchantments.DURABILITY, this);
+                j = (getItem() == Items.ELYTRA && entityplayer != null && entityplayer.world.purpurConfig.elytraIgnoreUnbreaking) ? 0 : EnchantmentManager.getEnchantmentLevel(Enchantments.DURABILITY, this); // Purpur
                 int k = 0;
 
                 for (int l = 0; j > 0 && l < i; ++l) {
@@ -546,6 +546,12 @@ public final class ItemStack {
                 if (this.isDamaged(i, t0.getRandom(), t0 instanceof EntityPlayer ? (EntityPlayer) t0 : null)) {
                     consumer.accept(t0);
                     Item item = this.getItem();
+                    // Purpur start
+                    if (item == Items.ELYTRA) {
+                        setDamage(item.getMaxDurability() - 1);
+                        return;
+                    }
+                    // Purpur end
                     // CraftBukkit start - Check for item breaking
                     if (this.count == 1 && t0 instanceof EntityHuman) {
                         org.bukkit.craftbukkit.event.CraftEventFactory.callPlayerItemBreakEvent((EntityHuman) t0, this);
diff --git a/src/main/java/net/minecraft/world/item/ItemTrident.java b/src/main/java/net/minecraft/world/item/ItemTrident.java
index 9896477b54cf91a88bdfc3d85018a59193b32859..0711d195c654edef5875f587e391bacfdea096da 100644
--- a/src/main/java/net/minecraft/world/item/ItemTrident.java
+++ b/src/main/java/net/minecraft/world/item/ItemTrident.java
@@ -123,6 +123,16 @@ public class ItemTrident extends Item implements ItemVanishable {
                         f2 *= f6 / f5;
                         f3 *= f6 / f5;
                         f4 *= f6 / f5;
+
+                        // Purpur start
+                        ItemStack chestItem = entityhuman.getEquipment(EnumItemSlot.CHEST);
+                        if (chestItem.getItem() == Items.ELYTRA && world.purpurConfig.elytraDamagePerTridentBoost > 0) {
+                            chestItem.damage(world.purpurConfig.elytraDamagePerTridentBoost, entityhuman, (entity) -> {
+                                entity.broadcastItemBreak(EnumItemSlot.CHEST);
+                            });
+                        }
+                        // Purpur end
+
                         entityhuman.i((double) f2, (double) f3, (double) f4);
                         entityhuman.r(20);
                         if (entityhuman.isOnGround()) {
diff --git a/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java b/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
index e66b79218e960d11da4759187e4473685ccb9a9e..7f6b028f32af113e5898a0f2f39e0ec6c4e4dd11 100644
--- a/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
+++ b/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
@@ -129,6 +129,19 @@ public class PurpurWorldConfig {
         voidDamageHeight = getDouble("gameplay-mechanics.void-damage-height", voidDamageHeight);
     }
 
+    public int elytraDamagePerSecond = 1;
+    public double elytraDamageMultiplyBySpeed = 0;
+    public boolean elytraIgnoreUnbreaking = false;
+    public int elytraDamagePerFireworkBoost = 0;
+    public int elytraDamagePerTridentBoost = 0;
+    private void elytraSettings() {
+        elytraDamagePerSecond = getInt("gameplay-mechanics.elytra.damage-per-second", elytraDamagePerSecond);
+        elytraDamageMultiplyBySpeed = getDouble("gameplay-mechanics.elytra.damage-multiplied-by-speed", elytraDamageMultiplyBySpeed);
+        elytraIgnoreUnbreaking = getBoolean("gameplay-mechanics.elytra.ignore-unbreaking", elytraIgnoreUnbreaking);
+        elytraDamagePerFireworkBoost = getInt("gameplay-mechanics.elytra.damage-per-boost.firework", elytraDamagePerFireworkBoost);
+        elytraDamagePerTridentBoost = getInt("gameplay-mechanics.elytra.damage-per-boost.trident", elytraDamagePerTridentBoost);
+    }
+
     public String playerDeathExpDropEquation = "expLevel * 7";
     public int playerDeathExpDropMax = 100;
     private void playerDeathExpSettings() {
