diff --git a/pom.xml b/pom.xml
index e358b8f..b60bf10 100644
--- a/pom.xml
+++ b/pom.xml
@@ -2,7 +2,7 @@
4.0.0
com.hyperling.minecraft
CoderDojoEVV
- 0.1.6-SNAPSHOT
+ 0.1.7-SNAPSHOT
Coder Dojo Test
Test project written to learn how to do Minecraft plug-in for Coder Dojo.
diff --git a/src/main/java/com/hyperling/minecraft/coderdojoevv/DiamondItems.java b/src/main/java/com/hyperling/minecraft/coderdojoevv/DiamondItems.java
index 849b9fe..ac55e65 100644
--- a/src/main/java/com/hyperling/minecraft/coderdojoevv/DiamondItems.java
+++ b/src/main/java/com/hyperling/minecraft/coderdojoevv/DiamondItems.java
@@ -6,6 +6,7 @@ import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
+import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
import org.bukkit.plugin.java.JavaPlugin;
@@ -17,7 +18,18 @@ public class DiamondItems implements Listener{
this.plugin = plugin;
}
-
+ @EventHandler
+ public void onRespawn(PlayerRespawnEvent event) {
+ plugin.getLogger().info("Running onRespawn.");
+ Player player = event.getPlayer();
+ final PlayerInventory inv = player.getInventory();
+
+ if (plugin.getServer().getDefaultGameMode() != GameMode.CREATIVE) {
+ giveDiamondItems(inv);
+ plugin.getServer().broadcastMessage(player.getDisplayName() + " was given back items.");
+ }
+ plugin.getLogger().info("Finished onRespawn().");
+ }
@EventHandler
public void onJoin(PlayerJoinEvent event) {
@@ -30,49 +42,54 @@ public class DiamondItems implements Listener{
// Give diamond tools and food if not in creative
if (plugin.getServer().getDefaultGameMode() != GameMode.CREATIVE) {
+ giveDiamondItems(inv);
plugin.getServer().broadcastMessage("Enjoy your items!");
- ItemStack item;
- item = new ItemStack(Material.DIAMOND_SWORD);
- inv.remove(Material.DIAMOND_SWORD);
- inv.addItem(item);
- item = new ItemStack(Material.DIAMOND_AXE);
- inv.remove(Material.DIAMOND_AXE);
- inv.addItem(item);
- item = new ItemStack(Material.DIAMOND_PICKAXE);
- inv.remove(Material.DIAMOND_PICKAXE);
- inv.addItem(item);
- item = new ItemStack(Material.DIAMOND_SPADE);
- inv.remove(Material.DIAMOND_SPADE);
- /* For 1.13 API
- item = new ItemStack(Material.DIAMOND_SHOVEL);
- inv.remove(Material.DIAMOND_SHOVEL);
- */
- inv.addItem(item);
- item = new ItemStack(Material.DIAMOND_HOE);
- inv.remove(Material.DIAMOND_HOE);
- inv.addItem(item);
-
- // Give food
- item = new ItemStack(Material.GOLDEN_APPLE);
- inv.remove(Material.GOLDEN_APPLE);
- item.setAmount(64);
- inv.addItem(item);
-
- // These work
- item = new ItemStack(Material.DIAMOND_BOOTS);
- inv.setBoots(item);
- item = new ItemStack(Material.DIAMOND_LEGGINGS);
- inv.setLeggings(item);
- item = new ItemStack(Material.DIAMOND_CHESTPLATE);
- inv.setChestplate(item);
- item = new ItemStack(Material.DIAMOND_HELMET);
- inv.setHelmet(item);
}
else {
inv.clear();
- plugin.getServer().broadcastMessage("Inventory has been cleared for Creative mode.");
+ plugin.getLogger().info("Inventory has been cleared for Creative mode.");
}
plugin.getLogger().info("Finished onJoin().");
}
+
+ public void giveDiamondItems(PlayerInventory inv) {
+ ItemStack item;
+ item = new ItemStack(Material.DIAMOND_SWORD);
+ inv.remove(Material.DIAMOND_SWORD);
+ inv.addItem(item);
+ item = new ItemStack(Material.DIAMOND_AXE);
+ inv.remove(Material.DIAMOND_AXE);
+ inv.addItem(item);
+ item = new ItemStack(Material.DIAMOND_PICKAXE);
+ inv.remove(Material.DIAMOND_PICKAXE);
+ inv.addItem(item);
+ item = new ItemStack(Material.DIAMOND_SPADE);
+ inv.remove(Material.DIAMOND_SPADE);
+ /* For 1.13 API
+ item = new ItemStack(Material.DIAMOND_SHOVEL);
+ inv.remove(Material.DIAMOND_SHOVEL);
+ */
+ inv.addItem(item);
+ item = new ItemStack(Material.DIAMOND_HOE);
+ inv.remove(Material.DIAMOND_HOE);
+ inv.addItem(item);
+
+ // Give food
+ item = new ItemStack(Material.GOLDEN_APPLE);
+ inv.remove(Material.GOLDEN_APPLE);
+ item.setAmount(64);
+ inv.addItem(item);
+
+ // These work
+ item = new ItemStack(Material.DIAMOND_BOOTS);
+ inv.setBoots(item);
+ item = new ItemStack(Material.DIAMOND_LEGGINGS);
+ inv.setLeggings(item);
+ item = new ItemStack(Material.DIAMOND_CHESTPLATE);
+ inv.setChestplate(item);
+ item = new ItemStack(Material.DIAMOND_HELMET);
+ inv.setHelmet(item);
+ }
+
}
diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml
index 3c2a33f..0d5e01a 100644
--- a/src/main/resources/plugin.yml
+++ b/src/main/resources/plugin.yml
@@ -1,6 +1,6 @@
name: CoderDojoEVV
main: com.hyperling.minecraft.coderdojoevv.CoderDojoEVV
-version: 0.1.6
+version: 0.1.7
commands:
heal:
diff --git a/target/classes/plugin.yml b/target/classes/plugin.yml
index 3c2a33f..0d5e01a 100644
--- a/target/classes/plugin.yml
+++ b/target/classes/plugin.yml
@@ -1,6 +1,6 @@
name: CoderDojoEVV
main: com.hyperling.minecraft.coderdojoevv.CoderDojoEVV
-version: 0.1.6
+version: 0.1.7
commands:
heal:
diff --git a/target/maven-archiver/pom.properties b/target/maven-archiver/pom.properties
index b998ece..6514c76 100644
--- a/target/maven-archiver/pom.properties
+++ b/target/maven-archiver/pom.properties
@@ -1,5 +1,5 @@
#Generated by Maven
-#Fri Dec 28 11:40:41 CST 2018
-version=0.1.6-SNAPSHOT
+#Fri Dec 28 12:13:17 CST 2018
+version=0.1.7-SNAPSHOT
groupId=com.hyperling.minecraft
artifactId=CoderDojoEVV