diff options
author | Matthew Lemon <lemon@matthewlemon.com> | 2020-09-30 14:28:36 +0100 |
---|---|---|
committer | Matthew Lemon <lemon@matthewlemon.com> | 2020-09-30 14:28:36 +0100 |
commit | 83aa1c52cdf4d0fb132da0218ba40e0b898bddf4 (patch) | |
tree | 8f1d3ea5b8679c73b6504de917125f7119a902d2 | |
parent | 0b8d42bccae4b3ca6e888f5d4294bd15777cdda1 (diff) |
progress
-rw-r--r-- | src/main/java/com/yulqen/test/EventListening.java | 172 | ||||
-rw-r--r-- | src/main/java/com/yulqen/test/KillZombies.java | 1 | ||||
-rw-r--r-- | src/main/java/com/yulqen/test/Test.java | 5 | ||||
-rw-r--r-- | src/main/resources/plugin.yml | 2 |
4 files changed, 149 insertions, 31 deletions
diff --git a/src/main/java/com/yulqen/test/EventListening.java b/src/main/java/com/yulqen/test/EventListening.java index f800656..a0f3c58 100644 --- a/src/main/java/com/yulqen/test/EventListening.java +++ b/src/main/java/com/yulqen/test/EventListening.java @@ -1,8 +1,11 @@ package com.yulqen.test; +import java.util.concurrent.TimeUnit; + import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.World; +import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.*; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -10,6 +13,7 @@ import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityPickupItemEvent; import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerRespawnEvent; import org.bukkit.inventory.ItemStack; @@ -29,13 +33,14 @@ public class EventListening implements Listener { public void joinMessage(PlayerJoinEvent event) { event.setJoinMessage("Welcome to the Server! Please behave and fun! (By the way, we have plugins and strange things might " + "happen"); + event.setJoinMessage("Please report bugs to the server."); } @EventHandler public void sophieMinesIron(BlockBreakEvent e) { Player player = e.getPlayer(); if (player.getName().equals("SophieLemLem")) { - if (e.getBlock().getType().equals(Material.IRON_ORE)) { + if (checkBlockMaterial(e.getBlock().getType(), Material.IRON_ORE)) { player.getInventory().addItem(new ItemStack(Material.IRON_INGOT, 8)); player.sendMessage("Sophie mines magic iron!"); } @@ -46,41 +51,63 @@ public class EventListening implements Listener { public void joeTiresWithCoalAndIron(BlockBreakEvent e) { Player player = e.getPlayer(); if (player.getName().equals("_Joex")) { - if (e.getBlock().getType().equals(Material.IRON_ORE) || e.getBlock().getType().equals(Material.COAL_ORE)) { + Material block = e.getBlock().getType(); + if (checkBlockMaterial(block, Material.IRON_ORE) || checkBlockMaterial(block, Material.COAL_ORE)) { player.setHealth(player.getHealth() / 1.2); } } } + private boolean checkBlockMaterial(Material block, Material material) { + return block.equals(material); + } + @EventHandler public void chickenDefender(EntityDamageByEntityEvent e) { Entity damager = e.getDamager(); - if (damager instanceof Player && (e.getEntity().getType().equals(EntityType.CHICKEN) || - (e.getEntity().getType().equals(EntityType.COW)) || - (e.getEntity().getType().equals(EntityType.PIG)))) { + EntityType type = e.getEntity().getType(); + if (damager instanceof Player && (type.equals(EntityType.CHICKEN) || + (type.equals(EntityType.COW)) || + (type.equals(EntityType.PIG)))) { + ((Player) damager).setHealth(2.0); Entity animal = e.getEntity(); Location loc = damager.getLocation(); damager.sendMessage("You damaged " + animal.getName()); damager.sendMessage(e.getEntity().getName() + " will be defended!"); World world = damager.getWorld(); - if (e.getEntity().getType().equals(EntityType.CHICKEN)) { + if (type.equals(EntityType.CHICKEN)) { Zombie zombie = world.spawn(new Location(world, loc.getX()+2.0, loc.getY(), loc.getZ()), Zombie.class); - Zombie zombie2 = world.spawn(new Location(world, loc.getX()-8.0, loc.getY(), loc.getZ()), Zombie.class); zombie.setBaby(); zombie.setInvulnerable(true); zombie.setCustomName("Chicken Defender"); + + Zombie zombie2 = world.spawn(new Location(world, loc.getX()-3.0, loc.getY(), loc.getZ()), Zombie.class); zombie2.setBaby(); zombie2.setInvulnerable(true); zombie2.setCustomName("Chicken Defender"); + + ItemStack zSword = new ItemStack(Material.DIAMOND_SWORD); + zSword.addEnchantment(Enchantment.DAMAGE_ALL, 5); + + ItemStack zHelmet = new ItemStack(Material.DIAMOND_HELMET, 3); + zHelmet.addEnchantment(Enchantment.OXYGEN, 3); + + ItemStack[] zombieArmour = {zHelmet}; + zombie.getEquipment().setItemInMainHand(zSword); + + zombie.getEquipment().setArmorContents(zombieArmour); + zombie2.getEquipment().setArmorContents(zombieArmour); + + // Give them what they want world.dropItemNaturally(loc, new ItemStack(Material.DIAMOND)); - } else if (e.getEntity().getType().equals(EntityType.COW)) { + } else if (type.equals(EntityType.COW)) { Slime slime = world.spawn(new Location(world, loc.getX()+6, loc.getY(), loc.getZ()), Slime.class); slime.setSize(4); slime.setCustomName("Moo blob"); slime.attack(damager); - } else if (e.getEntity().getType().equals(EntityType.PIG)) { - Creeper creeper = world.spawn(new Location(world, loc.getX()-10, loc.getY(), loc.getZ()), Creeper.class); - Creeper creeper2 = world.spawn(new Location(world, loc.getX()+10, loc.getY(), loc.getZ()), Creeper.class); + } else { // it's a Pig + Creeper creeper = world.spawn(new Location(world, loc.getX()-6, loc.getY(), loc.getZ()), Creeper.class); + Creeper creeper2 = world.spawn(new Location(world, loc.getX()+6, loc.getY(), loc.getZ()), Creeper.class); creeper.setCustomName("Pig Protector"); creeper2.setCustomName("Pig Protector"); } @@ -88,26 +115,121 @@ public class EventListening implements Listener { } @EventHandler + public void boomIfPickUpDiamondGear(EntityPickupItemEvent e) throws InterruptedException { + LivingEntity player = e.getEntity(); + World world = player.getWorld(); + Location loc = player.getLocation(); + if ((e.getItem().getItemStack().getType().equals(Material.DIAMOND_BOOTS)) || e.getItem().getItemStack().getType().equals(Material.DIAMOND_CHESTPLATE) + || e.getItem().getItemStack().getType().equals(Material.DIAMOND_HELMET) + || e.getItem().getItemStack().getType().equals(Material.DIAMOND_LEGGINGS)) + { + player.sendMessage("Sorry! You that stuff isn't for you... Boom!"); + TimeUnit.SECONDS.sleep(2); + world.createExplosion(loc, 4f); + } + } + + @EventHandler + public void harveySpawnsWithDiamondArmour(PlayerRespawnEvent e) { + Player player = e.getPlayer(); + if (player.getName().equals("HarveyL")) { + ItemStack chestPlate = new ItemStack(Material.DIAMOND_CHESTPLATE); + ItemStack pants = new ItemStack(Material.DIAMOND_LEGGINGS); + ItemStack helmet = new ItemStack(Material.DIAMOND_HELMET); + ItemStack boots = new ItemStack(Material.DIAMOND_BOOTS); + + chestPlate.addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 4); + chestPlate.addEnchantment(Enchantment.DURABILITY, 3); + chestPlate.addEnchantment(Enchantment.BINDING_CURSE, 1); + pants.addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 4); + pants.addEnchantment(Enchantment.DURABILITY, 3); + pants.addEnchantment(Enchantment.BINDING_CURSE, 1); + helmet.addEnchantment(Enchantment.PROTECTION_EXPLOSIONS, 4); + helmet.addEnchantment(Enchantment.DURABILITY, 3); + helmet.addEnchantment(Enchantment.BINDING_CURSE, 1); + boots.addEnchantment(Enchantment.DURABILITY, 3); + boots.addEnchantment(Enchantment.PROTECTION_FALL, 4); + boots.addEnchantment(Enchantment.BINDING_CURSE, 1); + + player.getInventory().addItem(chestPlate); + player.getInventory().addItem(pants); + player.getInventory().addItem(helmet); + player.getInventory().addItem(boots); + } + } + + @EventHandler + public void sophieSpawnsWithDiamondArmour(PlayerRespawnEvent e) { + Player player = e.getPlayer(); + if (player.getName().equals("SophieLemLem")) { + ItemStack chestPlate = new ItemStack(Material.DIAMOND_CHESTPLATE); + ItemStack pants = new ItemStack(Material.DIAMOND_LEGGINGS); + ItemStack helmet = new ItemStack(Material.DIAMOND_HELMET); + ItemStack boots = new ItemStack(Material.DIAMOND_BOOTS); + ItemStack sword = new ItemStack(Material.DIAMOND_SWORD); + ItemStack pick = new ItemStack(Material.DIAMOND_PICKAXE); + + chestPlate.addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 4); + chestPlate.addEnchantment(Enchantment.DURABILITY, 3); + chestPlate.addEnchantment(Enchantment.BINDING_CURSE, 1); + pants.addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 4); + pants.addEnchantment(Enchantment.DURABILITY, 3); + pants.addEnchantment(Enchantment.BINDING_CURSE, 1); + helmet.addEnchantment(Enchantment.PROTECTION_EXPLOSIONS, 4); + helmet.addEnchantment(Enchantment.DURABILITY, 3); + helmet.addEnchantment(Enchantment.BINDING_CURSE, 1); + boots.addEnchantment(Enchantment.DURABILITY, 3); + boots.addEnchantment(Enchantment.PROTECTION_FALL, 4); + boots.addEnchantment(Enchantment.BINDING_CURSE, 1); + sword.addEnchantment(Enchantment.KNOCKBACK, 2); + sword.addEnchantment(Enchantment.DAMAGE_ALL, 5); + sword.addEnchantment(Enchantment.FIRE_ASPECT, 2); + pick.addEnchantment(Enchantment.DIG_SPEED, 5); + + player.getInventory().addItem(chestPlate); + player.getInventory().addItem(pants); + player.getInventory().addItem(helmet); + player.getInventory().addItem(boots); + player.getInventory().addItem(sword); + player.getInventory().addItem(pick); + } + } + + @EventHandler public void boomIfPickupOak(EntityPickupItemEvent e) { LivingEntity player = e.getEntity(); Location loc = player.getLocation(); World world = player.getWorld(); // Block block = world.getBlockAt(loc); // block.setType(Material.STONE); - if (e.getItem().getItemStack().getType().equals(Material.SPRUCE_LOG)) { - player.sendMessage("Clank! Be careful collecting spruce logs."); -// world.createExplosion(new Location(world, loc.getX(), loc.getY(), loc.getZ()-5.0), 4f); - world.spawn(new Location(world, loc.getX() + 5, loc.getY(), loc.getZ()), Skeleton.class); - world.spawn(new Location(world, loc.getX() -5, loc.getY(), loc.getZ()), Skeleton.class); - } -// if (e.getItem().getItemStack().getType().equals(Material.DIRT)) { -// player.sendMessage("Collecting dirt is a bad thing..."); -// world.spawn(new Location(world, loc.getX(), loc.getY(), loc.getZ() + 2.0), Wolf.class); -// } -// e.getItem().getItemStack().setType(Material.ANVIL); -// double playerHealth = player.getHealth(); -// player.setHealth(playerHealth / 1.2); -// player.sendMessage("You have lost some health.... "); + Material material = e.getItem().getItemStack().getType(); + if (player.getType().equals(EntityType.PLAYER)) { + if (checkBlockMaterial(material, Material.SPRUCE_LOG) || checkBlockMaterial(material, Material.OAK_LOG) + || checkBlockMaterial(material, Material.BIRCH_LOG) + || checkBlockMaterial(material, Material.DARK_OAK_LOG) + || checkBlockMaterial(material, Material.JUNGLE_LOG) + || checkBlockMaterial(material, Material.STRIPPED_ACACIA_LOG) + || checkBlockMaterial(material, Material.STRIPPED_SPRUCE_LOG) + || checkBlockMaterial(material, Material.STRIPPED_DARK_OAK_LOG) + || checkBlockMaterial(material, Material.STRIPPED_BIRCH_LOG) + || checkBlockMaterial(material, Material.STRIPPED_JUNGLE_LOG) + || checkBlockMaterial(material, Material.STRIPPED_OAK_LOG) + || checkBlockMaterial(material, Material.WARPED_HYPHAE)) { + player.setHealth(2.0); + player.sendMessage("Clank! Be careful collecting logs."); + // world.createExplosion(new Location(world, loc.getX(), loc.getY(), loc.getZ()-5.0), 4f); + world.spawn(new Location(world, loc.getX() + 5, loc.getY(), loc.getZ()), Skeleton.class); + world.spawn(new Location(world, loc.getX() - 5, loc.getY(), loc.getZ()), Skeleton.class); + } + // if (e.getItem().getItemStack().getType().equals(Material.DIRT)) { + // player.sendMessage("Collecting dirt is a bad thing..."); + // world.spawn(new Location(world, loc.getX(), loc.getY(), loc.getZ() + 2.0), Wolf.class); + // } + // e.getItem().getItemStack().setType(Material.ANVIL); + // double playerHealth = player.getHealth(); + // player.setHealth(playerHealth / 1.2); + // player.sendMessage("You have lost some health.... "); + } } } diff --git a/src/main/java/com/yulqen/test/KillZombies.java b/src/main/java/com/yulqen/test/KillZombies.java index beea25e..2e1f9f8 100644 --- a/src/main/java/com/yulqen/test/KillZombies.java +++ b/src/main/java/com/yulqen/test/KillZombies.java @@ -1,6 +1,5 @@ package com.yulqen.test; -import com.sun.source.tree.Tree; import org.bukkit.World; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; diff --git a/src/main/java/com/yulqen/test/Test.java b/src/main/java/com/yulqen/test/Test.java index ddca478..1c553af 100644 --- a/src/main/java/com/yulqen/test/Test.java +++ b/src/main/java/com/yulqen/test/Test.java @@ -1,11 +1,8 @@ package com.yulqen.test; import org.bukkit.World; -import org.bukkit.entity.Player; import org.bukkit.plugin.java.JavaPlugin; -import java.util.List; - public final class Test extends JavaPlugin { @Override @@ -18,7 +15,7 @@ public final class Test extends JavaPlugin { // } getServer().getWorld("mad_march_hare").setFullTime(1000); getServer().getPluginManager().registerEvents(new EventListening(), this); - this.getCommand("toss").setExecutor(new GiveMeDiamond()); + this.getCommand("diamonds").setExecutor(new GiveMeDiamond()); this.getCommand("killzombies").setExecutor(new KillZombies()); } diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 6a97cbf..ec599ee 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -3,7 +3,7 @@ version: ${project.version} main: com.yulqen.test.Test api-version: 1.16 commands: - toss: + diamonds: description: Give me 64 diamonds useage: /diamonds permission: chickendefender.enablediamonds |