diff options
-rw-r--r-- | README.md | 32 | ||||
-rw-r--r-- | pom.xml | 2 | ||||
-rw-r--r-- | src/main/java/dev/genbyte/sunfright/Damager.java | 30 | ||||
-rw-r--r-- | src/main/java/dev/genbyte/sunfright/events/HelmetHandler.java | 4 |
4 files changed, 59 insertions, 9 deletions
diff --git a/README.md b/README.md new file mode 100644 index 0000000..a21775d --- /dev/null +++ b/README.md @@ -0,0 +1,32 @@ +# Sunfright +Inspired by the [404 challenge][404], this is a Spigot plugin that restricts +your ability to be in sunlight. + +[404]: https://www.minecraftforum.net/forums/minecraft-java-edition/seeds/298932-ironman-challenge-series-404 + +Every time you spawn, you're given a leather helmet with Curse of Binding and +Curse of Vanishing. This gives you some time to gather supplies before you can +shield yourself from the sunlight. If you try to take it off, it will vanish. +This leather helmet gives you around 5 minutes to gather everything you need to +live a good life underground, or return home. + +Normal helmets give you resistance to the sunlight too. Every second you are +exposed to skylight greater than 3, your helmet takes one damage, or if you +don't have a helmet, you loose a heart. The table of helmet durability, taken +from the [Minecraft wiki][mcwiki-helmets], is listed below. + +| Material | Durability | Time Exposed to Sunlight | +| ------------ | ---------- | ------------------------- | +| Leather | 56 | 56 seconds | +| Gold | 78 | 1 minute, 18 seconds | +| Iron | 166 | 2 minutes, 46 seconds | +| Chainmail | 166 | 2 minutes, 46 seconds | +| Turtle Shell | 276 | 4 minutes, 36 seconds | +| Diamond | 364 | 6 minutes, 4 seconds | + +[mcwiki-helmets]: https://minecraft.gamepedia.com/Helmet#Durability + +### TODO: +[] Black Stained Glass to shield the sun +[] Fire Protection to act like unbreaking +[] Respawn helmet disappears when no longer exposed to sunlight. diff --git a/pom.xml b/pom.xml index 70a8287..81695c7 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ <groupId>dev.genbyte.sunfright</groupId> <artifactId>sunfright</artifactId> <packaging>jar</packaging> - <version>0.2.0</version> + <version>0.2.1</version> <name>sunfright</name> <description>Burn me to a cript, large glowing orb!</description> 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); |