about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorGenny <gen@nyble.dev>2020-02-03 16:08:55 -0600
committerGenny <gen@nyble.dev>2020-02-03 16:08:55 -0600
commit2fddf79291a79bb0fd0d26bc8e89d464754e16c7 (patch)
treeab7df56a1bb53b0c915d1341095db584c2af6e75 /src
parent85f8063a791a2e4db90fc5670f6742e50a9b3da5 (diff)
downloadsunfright-2fddf79291a79bb0fd0d26bc8e89d464754e16c7.tar.gz
sunfright-2fddf79291a79bb0fd0d26bc8e89d464754e16c7.zip
Add readme; fix bug where helmets wouldn't break
Diffstat (limited to 'src')
-rw-r--r--src/main/java/dev/genbyte/sunfright/Damager.java30
-rw-r--r--src/main/java/dev/genbyte/sunfright/events/HelmetHandler.java4
2 files changed, 26 insertions, 8 deletions
diff --git a/src/main/java/dev/genbyte/sunfright/Damager.java b/src/main/java/dev/genbyte/sunfright/Damager.java
index 39cdab1..6eb7c4d 100644
--- a/src/main/java/dev/genbyte/sunfright/Damager.java
+++ b/src/main/java/dev/genbyte/sunfright/Damager.java
@@ -1,7 +1,10 @@
 package dev.genbyte.sunfright;
 
 import java.util.Collection;
+import java.util.logging.Level;
 
+import org.bukkit.Material;
+import org.bukkit.enchantments.Enchantment;
 import org.bukkit.entity.Player;
 import org.bukkit.inventory.ItemStack;
 import org.bukkit.inventory.meta.Damageable;
@@ -19,10 +22,8 @@ public class Damager extends BukkitRunnable {
 		Collection<? extends Player> players = sf.getServer().getOnlinePlayers();
 		players.forEach((player) -> {
 			byte skylight = player.getLocation().getBlock().getLightFromSky();
-			if (skylight > 3 && skylight < 13) {
+			if (skylight > 3) {
 				new DoDamage(player, (byte) 1).runTask(sf);
-			} else if (skylight >= 13) {
-				new DoDamage(player, (byte) 2).runTask(sf);
 			}
 		});
 	}
@@ -44,13 +45,30 @@ public class Damager extends BukkitRunnable {
 
 				if (helmetMeta instanceof Damageable) {
 					Damageable helmetDamageable = (Damageable) helmetMeta;
+					int helmetDamage = helmetDamageable.getDamage();
 
-					helmetDamageable.setDamage(helmetDamageable.getDamage() + damage);
-					helmet.setItemMeta((ItemMeta) helmetDamageable);
+					if (helmetDamage + damage >= helmet.getType().getMaxDurability()) {
+						if (helmet.getEnchantmentLevel(Enchantment.VANISHING_CURSE) == 2) {
+							int bindLevel = helmet.getEnchantmentLevel(Enchantment.BINDING_CURSE);
+
+							if (bindLevel < 5) {
+								helmetDamageable.setDamage(0);
+								helmet.setItemMeta((ItemMeta) helmetDamageable);
+								helmet.addUnsafeEnchantment(Enchantment.BINDING_CURSE, bindLevel + 1);
+
+								return;
+							}
+						}
+
+						player.getInventory().setHelmet(new ItemStack(Material.AIR));
+					} else {
+						helmetDamageable.setDamage(helmetDamage + damage);
+						helmet.setItemMeta((ItemMeta) helmetDamageable);
+					}
 				}
 			} else {
 				player.damage(damage);
 			}
 		}
 	}
-}
\ No newline at end of file
+}
diff --git a/src/main/java/dev/genbyte/sunfright/events/HelmetHandler.java b/src/main/java/dev/genbyte/sunfright/events/HelmetHandler.java
index 47be317..5f57cef 100644
--- a/src/main/java/dev/genbyte/sunfright/events/HelmetHandler.java
+++ b/src/main/java/dev/genbyte/sunfright/events/HelmetHandler.java
@@ -14,8 +14,8 @@ public class HelmetHandler implements Listener {
 	public void onPlayerRespawn(PlayerRespawnEvent event) {
 		PlayerInventory inv = event.getPlayer().getInventory();
 
-		ItemStack stack = new ItemStack(Material.IRON_HELMET);
-		stack.addUnsafeEnchantment(Enchantment.BINDING_CURSE, 2);
+		ItemStack stack = new ItemStack(Material.LEATHER_HELMET);
+		stack.addUnsafeEnchantment(Enchantment.BINDING_CURSE, 1);
 		stack.addUnsafeEnchantment(Enchantment.VANISHING_CURSE, 2);
 
 		inv.setHelmet(stack);