about summary refs log tree commit diff
diff options
context:
space:
mode:
authorGenny <gen@nyble.dev>2020-06-02 17:34:20 -0500
committerGenny <gen@nyble.dev>2020-06-02 17:34:20 -0500
commit5ee4c899940675d28a4494aef9748e01f949c608 (patch)
treec557bc8327b6acc9856f19360f7418a7bfdd4e9f
parent9afff6f780bdde6f6259b30a4844fdd6d271db57 (diff)
downloadsunfright-5ee4c899940675d28a4494aef9748e01f949c608.tar.gz
sunfright-5ee4c899940675d28a4494aef9748e01f949c608.zip
Change damage conditions
-rw-r--r--README.md22
-rw-r--r--docs/clear_end_safe.pngbin0 -> 1792 bytes
-rw-r--r--docs/clear_start_safe.pngbin0 -> 1798 bytes
-rw-r--r--docs/stormy_end_safe.pngbin0 -> 1813 bytes
-rw-r--r--docs/stormy_start_safe.pngbin0 -> 1822 bytes
-rw-r--r--docs/thunder_end_safe.pngbin0 -> 1811 bytes
-rw-r--r--docs/thunder_start_safe.pngbin0 -> 1826 bytes
-rw-r--r--src/main/java/dev/genbyte/sunfright/Damager.java51
-rw-r--r--src/main/java/dev/genbyte/sunfright/Sunfright.java38
-rw-r--r--src/main/java/dev/genbyte/sunfright/events/HelmetHandler.java12
-rw-r--r--src/main/resources/config.yml2
11 files changed, 95 insertions, 30 deletions
diff --git a/README.md b/README.md
index a7d0f37..1fbda84 100644
--- a/README.md
+++ b/README.md
@@ -14,10 +14,13 @@ supplies before you can shield yourself from the sunlight, but if you try to
 take it off, it'll 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.
+In order for the sun not to damage you, you must have equipped a helmet with
+Fire Protection. If you were to take damage (according to the rules below), but
+you have a Fire Protection helmet on, the helmet takes half the damage you would
+be dealt and you don't take any damage. There is a table below listing the
+types of helmets, their durability, and the time it would take for this helmet
+to break on the default damage value. Data is pulled from the
+[Minecraft Gamepedia page on Helmets][mcwiki-helmets].
 
 | Material     | Durability | Time Exposed to Sunlight  |
 | ------------ | ---------- | ------------------------- |
@@ -30,8 +33,17 @@ from the [Minecraft wiki][mcwiki-helmets], is listed below.
 
 [mcwiki-helmets]: https://minecraft.gamepedia.com/Helmet#Durability
 
+## Damage Conditions
+You will be damaged if you are in skylight greater than 3 and it is not during
+this time of day.
+
+| Weather Condition | Time Start/End | Clock Start/End |
+| ----------------- | -------------- | --------------- |
+| Clear             | 13026 - 22973  | ![](docs/clear_start_safe.png) ![](docs/clear_end_safe.png) |
+| Raining           | 12733 - 23266  | ![](docs/stormy_start_safe.png) ![](docs/stormy_end_safe.png) |
+| Thunder Storm     | 12299 - 23699  | ![](docs/thunder_start_safe.png) ![](docs/thunder_end_safe.png) |
+
 ### Notes
-- Black glass can shield you from the sun if it is directly above you.
 - Respawn helmets disappear when you are safe.
 - You must have at least Fire Protection I on a helmet to stay safe from
   sunlight above level 3.
diff --git a/docs/clear_end_safe.png b/docs/clear_end_safe.png
new file mode 100644
index 0000000..eb37489
--- /dev/null
+++ b/docs/clear_end_safe.png
Binary files differdiff --git a/docs/clear_start_safe.png b/docs/clear_start_safe.png
new file mode 100644
index 0000000..7d83980
--- /dev/null
+++ b/docs/clear_start_safe.png
Binary files differdiff --git a/docs/stormy_end_safe.png b/docs/stormy_end_safe.png
new file mode 100644
index 0000000..f606279
--- /dev/null
+++ b/docs/stormy_end_safe.png
Binary files differdiff --git a/docs/stormy_start_safe.png b/docs/stormy_start_safe.png
new file mode 100644
index 0000000..2f7f016
--- /dev/null
+++ b/docs/stormy_start_safe.png
Binary files differdiff --git a/docs/thunder_end_safe.png b/docs/thunder_end_safe.png
new file mode 100644
index 0000000..3519ed6
--- /dev/null
+++ b/docs/thunder_end_safe.png
Binary files differdiff --git a/docs/thunder_start_safe.png b/docs/thunder_start_safe.png
new file mode 100644
index 0000000..2ea0589
--- /dev/null
+++ b/docs/thunder_start_safe.png
Binary files differdiff --git a/src/main/java/dev/genbyte/sunfright/Damager.java b/src/main/java/dev/genbyte/sunfright/Damager.java
index cdee7c1..28420d4 100644
--- a/src/main/java/dev/genbyte/sunfright/Damager.java
+++ b/src/main/java/dev/genbyte/sunfright/Damager.java
@@ -1,10 +1,9 @@
 package dev.genbyte.sunfright;
 
 import java.util.Collection;
-import java.util.logging.Level;
 
 import org.bukkit.Material;
-import org.bukkit.block.Block;
+import org.bukkit.World;
 import org.bukkit.enchantments.Enchantment;
 import org.bukkit.entity.Player;
 import org.bukkit.inventory.ItemStack;
@@ -20,13 +19,14 @@ public class Damager extends BukkitRunnable {
 	}
 
 	public void run() {
-		Collection<? extends Player> players = sf.getServer().getOnlinePlayers();
+		World sunnedWorld = sf.sunnedWorld;
+		Collection<? extends Player> players = sunnedWorld.getPlayers();
 
 		players.forEach((player) -> {
 			byte skylight = player.getLocation().getBlock().getLightFromSky();
 
-			if (skylight > 3) {
-				new DoDamage(player, (byte) 1).runTask(sf);
+			if (skylight > 3 && timeShouldDamage()) {
+				new DoDamage(player, sf.damagaPerSecond).runTask(sf);
 			} else if (player.getInventory().getHelmet() != null
 					&& player.getInventory().getHelmet().getEnchantmentLevel(Enchantment.VANISHING_CURSE) == 2) {
 				player.getInventory().setHelmet(new ItemStack(Material.AIR));
@@ -34,24 +34,43 @@ public class Damager extends BukkitRunnable {
 		});
 	}
 
+	private boolean timeShouldDamage() {
+		World sunnedWorld = sf.sunnedWorld;
+
+		long time = sunnedWorld.getTime();
+		boolean storming = sunnedWorld.hasStorm();
+		boolean thundering = sunnedWorld.isThundering();
+
+		// Times are pulled from Minecraft Gamepedia page on Light, specifically the internal light
+		// level section. https://minecraft.gamepedia.com/Light
+		// Times correspond to when the light level is over 8.
+		if (!storming && !thundering) {
+			if (time >= 13027 && time <= 22973) {
+				return false;
+			}
+		} else if (storming && !thundering) {
+			if (time >= 12734 && time <= 23266) {
+				return false;
+			}
+		} else if (storming && thundering) {
+			if (time >= 12300 && time <= 23700) {
+				return false;
+			}
+		}
+		return true;
+	}
+
 	private class DoDamage extends BukkitRunnable {
 		private final Player player;
-		private final byte damage;
+		private final int damage;
 
-		public DoDamage(Player player, byte damage) {
+		public DoDamage(Player player, int damage) {
 			this.player = player;
 			this.damage = damage;
 		}
 
 		public void run() {
 			ItemStack helmet = player.getInventory().getHelmet();
-			Block topBlock = player.getWorld().getBlockAt(
-					player.getWorld().getHighestBlockAt(player.getLocation()).getLocation().subtract(0, 1, 0));
-
-			if (topBlock.getLocation().getY() > player.getLocation().getY()
-					&& topBlock.getType().equals(Material.BLACK_STAINED_GLASS)) {
-				return;
-			}
 
 			if (helmet != null) {
 				ItemMeta helmetMeta = helmet.getItemMeta();
@@ -80,7 +99,7 @@ public class Damager extends BukkitRunnable {
 
 						player.getInventory().setHelmet(new ItemStack(Material.AIR));
 					} else {
-						helmetDamageable.setDamage(helmetDamage + damage);
+						helmetDamageable.setDamage(helmetDamage + (damage/2));
 						helmet.setItemMeta((ItemMeta) helmetDamageable);
 					}
 				}
@@ -90,7 +109,7 @@ public class Damager extends BukkitRunnable {
 		}
 
 		private void applyDamage() {
-			player.damage(damage * 2);
+			player.damage(damage);
 		}
 	}
 }
diff --git a/src/main/java/dev/genbyte/sunfright/Sunfright.java b/src/main/java/dev/genbyte/sunfright/Sunfright.java
index 87ab46b..051ac13 100644
--- a/src/main/java/dev/genbyte/sunfright/Sunfright.java
+++ b/src/main/java/dev/genbyte/sunfright/Sunfright.java
@@ -3,32 +3,52 @@ package dev.genbyte.sunfright;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
+import org.bukkit.World;
 import org.bukkit.plugin.java.JavaPlugin;
 import org.bukkit.scheduler.BukkitTask;
 
 import dev.genbyte.sunfright.events.HelmetHandler;
 
 public class Sunfright extends JavaPlugin {
-    private Logger logger;
+    public World sunnedWorld;
+    public int damagaPerSecond;
     private BukkitTask damager;
 
     @Override
-    public void onLoad() {
-        logger = this.getLogger();
-    }
-
-    @Override
     public void onEnable() {
+        if (!loadConfig()) {
+            getLogger().log(Level.SEVERE, "Could not load config file, aborting load. Plugin not active!");
+            getPluginLoader().disablePlugin(this);
+            return;
+        }
+
         int time = 20;
         damager = new Damager(this).runTaskTimerAsynchronously(this, time, time);
-        logger.log(Level.INFO, "Damager task started. and will run every " + (time / 20) + " seconds");
 
-        this.getServer().getPluginManager().registerEvents(new HelmetHandler(), this);
+        this.getServer().getPluginManager().registerEvents(new HelmetHandler(this), this);
     }
 
     @Override
     public void onDisable() {
         damager.cancel();
-        logger.log(Level.INFO, "Damager task stopped.");
+    }
+
+    private boolean loadConfig() {
+        this.saveDefaultConfig();
+
+        String world = getConfig().getString("world");
+        damagaPerSecond = getConfig().getInt("damagePerSecond");
+
+        sunnedWorld = getServer().getWorld(world);
+        if (sunnedWorld == null) {
+            getLogger().log(Level.SEVERE, "World '" + world + "' is not valid! Aborting loading config!");
+            return false;
+        }
+
+        if (damagaPerSecond == 0) {
+            getLogger().log(Level.WARNING, "damagePerSecond is 0. Was this intended?");
+        }
+
+        return true;
     }
 }
\ 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 a583f44..739ee78 100644
--- a/src/main/java/dev/genbyte/sunfright/events/HelmetHandler.java
+++ b/src/main/java/dev/genbyte/sunfright/events/HelmetHandler.java
@@ -11,7 +11,15 @@ import org.bukkit.event.player.PlayerJoinEvent;
 import org.bukkit.inventory.ItemStack;
 import org.bukkit.inventory.PlayerInventory;
 
+import dev.genbyte.sunfright.Sunfright;
+
 public class HelmetHandler implements Listener {
+	private final Sunfright sf;
+
+	public HelmetHandler(Sunfright sf) {
+		this.sf = sf;
+	}
+
 	@EventHandler
 	public void onPlayerRespawn(PlayerRespawnEvent event) {
 		setRespawnHelmet(event.getPlayer());
@@ -37,6 +45,10 @@ public class HelmetHandler implements Listener {
 	}
 
 	private void setRespawnHelmet(Player player) {
+		if (!player.getWorld().equals(sf.sunnedWorld)) {
+			return;
+		}
+
 		PlayerInventory inv = player.getInventory();
 
 		ItemStack stack = new ItemStack(Material.LEATHER_HELMET);
diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml
new file mode 100644
index 0000000..9f7bcd9
--- /dev/null
+++ b/src/main/resources/config.yml
@@ -0,0 +1,2 @@
+world: world
+damagePerSecond: 2
\ No newline at end of file