about summary refs log tree commit diff
path: root/src/main/java/dev/genbyte
diff options
context:
space:
mode:
authorGenny <gen@nyble.dev>2020-02-20 23:43:16 -0600
committerGenny <gen@nyble.dev>2020-02-20 23:43:16 -0600
commit2ada0604ae3dcaf608547ae642496c360ad53869 (patch)
tree8d1f5806471011094b7e77c8d979ab4663556094 /src/main/java/dev/genbyte
parent4f17a66fc19c970bc3ad24898c969526f4415472 (diff)
downloadsunfright-2ada0604ae3dcaf608547ae642496c360ad53869.tar.gz
sunfright-2ada0604ae3dcaf608547ae642496c360ad53869.zip
Fix bug where first players didn't get safe helmet
Diffstat (limited to 'src/main/java/dev/genbyte')
-rw-r--r--src/main/java/dev/genbyte/sunfright/events/HelmetHandler.java29
1 files changed, 22 insertions, 7 deletions
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);
+	}
+}