Added onRespawn event to DiamondItems.
This commit is contained in:
Hyperling 2018-12-28 12:14:33 -06:00
parent 220df1269b
commit 3282950e62
5 changed files with 60 additions and 43 deletions

View File

@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.hyperling.minecraft</groupId>
<artifactId>CoderDojoEVV</artifactId>
<version>0.1.6-SNAPSHOT</version>
<version>0.1.7-SNAPSHOT</version>
<name>Coder Dojo Test</name>
<description>Test project written to learn how to do Minecraft plug-in for Coder Dojo.</description>

View File

@ -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,7 +42,18 @@ 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!");
}
else {
inv.clear();
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);
@ -68,11 +91,5 @@ public class DiamondItems implements Listener{
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("Finished onJoin().");
}
}

View File

@ -1,6 +1,6 @@
name: CoderDojoEVV
main: com.hyperling.minecraft.coderdojoevv.CoderDojoEVV
version: 0.1.6
version: 0.1.7
commands:
heal:

View File

@ -1,6 +1,6 @@
name: CoderDojoEVV
main: com.hyperling.minecraft.coderdojoevv.CoderDojoEVV
version: 0.1.6
version: 0.1.7
commands:
heal:

View File

@ -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