about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--pom.xml2
-rw-r--r--src/main/java/dev/genbyte/sunfright/events/HelmetHandler.java29
2 files changed, 23 insertions, 8 deletions
diff --git a/pom.xml b/pom.xml
index fd07c3a..7e3c1b9 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
   <groupId>dev.genbyte.sunfright</groupId>
   <artifactId>sunfright</artifactId>
   <packaging>jar</packaging>
-  <version>0.3.0</version>
+  <version>0.3.1</version>
 
   <name>sunfright</name>
   <description>Burn me to a crisp, large glowing orb!</description>
diff --git a/src/main/java/dev/genbyte/sunfright/events/HelmetHandler.java b/src/main/java/dev/genbyte/sunfright/events/HelmetHandler.java
index c164536..a583f44 100644
--- a/src/main/java/dev/genbyte/sunfright/events/HelmetHandler.java
+++ b/src/main/java/dev/genbyte/sunfright/events/HelmetHandler.java
@@ -2,24 +2,28 @@ package dev.genbyte.sunfright.events;
 
 import org.bukkit.Material;
 import org.bukkit.enchantments.Enchantment;
+import org.bukkit.entity.Player;
 import org.bukkit.event.EventHandler;
 import org.bukkit.event.Listener;
 import org.bukkit.event.inventory.InventoryClickEvent;
 import org.bukkit.event.player.PlayerRespawnEvent;
+import org.bukkit.event.player.PlayerJoinEvent;
 import org.bukkit.inventory.ItemStack;
 import org.bukkit.inventory.PlayerInventory;
 
 public class HelmetHandler implements Listener {
 	@EventHandler
 	public void onPlayerRespawn(PlayerRespawnEvent event) {
-		PlayerInventory inv = event.getPlayer().getInventory();
+		setRespawnHelmet(event.getPlayer());
+	}
 
-		ItemStack stack = new ItemStack(Material.LEATHER_HELMET);
-		stack.addUnsafeEnchantment(Enchantment.BINDING_CURSE, 1);
-		stack.addUnsafeEnchantment(Enchantment.VANISHING_CURSE, 2);
-		stack.addEnchantment(Enchantment.PROTECTION_FIRE, 1);
+	@EventHandler
+	public void onPlayerJoin(PlayerJoinEvent event) {
+		Player player = event.getPlayer();
 
-		inv.setHelmet(stack);
+		if (!player.hasPlayedBefore()) {
+			setRespawnHelmet(player);
+		}
 	}
 
 	@EventHandler
@@ -31,4 +35,15 @@ public class HelmetHandler implements Listener {
 			event.getView().setItem(event.getRawSlot(), new ItemStack(Material.AIR));
 		}
 	}
-}
\ No newline at end of file
+
+	private void setRespawnHelmet(Player player) {
+		PlayerInventory inv = player.getInventory();
+
+		ItemStack stack = new ItemStack(Material.LEATHER_HELMET);
+		stack.addUnsafeEnchantment(Enchantment.BINDING_CURSE, 1);
+		stack.addUnsafeEnchantment(Enchantment.VANISHING_CURSE, 2);
+		stack.addEnchantment(Enchantment.PROTECTION_FIRE, 1);
+
+		inv.setHelmet(stack);
+	}
+}