From 3a23f4745affbe700038490911690a6a9f419f14 Mon Sep 17 00:00:00 2001 From: alisolarflare Date: Fri, 9 Dec 2016 20:27:58 -0500 Subject: [PATCH] Made Long Grass drop carrots and potatoes Temporary fix for the lack of carrots and potatoes in the server --- src/alisolarflare/AliPresents.java | 2 + .../components/fruit/FruitComponent.java | 15 +++++++ .../components/fruit/GrassBreakListener.java | 42 +++++++++++++++++++ 3 files changed, 59 insertions(+) create mode 100644 src/alisolarflare/components/fruit/FruitComponent.java create mode 100644 src/alisolarflare/components/fruit/GrassBreakListener.java diff --git a/src/alisolarflare/AliPresents.java b/src/alisolarflare/AliPresents.java index 7d0716e..297bbcd 100644 --- a/src/alisolarflare/AliPresents.java +++ b/src/alisolarflare/AliPresents.java @@ -11,6 +11,7 @@ import alisolarflare.components.bankchest.BankChestComponent; import alisolarflare.components.cashmob.CashMobComponent; import alisolarflare.components.creativeboundaries.CreativeBoundariesComponent; import alisolarflare.components.flaircolouring.FlairColouringComponent; +import alisolarflare.components.fruit.FruitComponent; import alisolarflare.components.gpowers.GPowerComponent; import alisolarflare.components.insurance.InsuranceComponent; import alisolarflare.components.magic.MagicComponent; @@ -29,6 +30,7 @@ public class AliPresents extends JavaPlugin{ new CashMobComponent().register(this); new CreativeBoundariesComponent().register(this); new FlairColouringComponent().register(this); + new FruitComponent().register(this); new GPowerComponent().register(this); new InsuranceComponent().register(this); new MagicComponent().register(this); diff --git a/src/alisolarflare/components/fruit/FruitComponent.java b/src/alisolarflare/components/fruit/FruitComponent.java new file mode 100644 index 0000000..c4a99ed --- /dev/null +++ b/src/alisolarflare/components/fruit/FruitComponent.java @@ -0,0 +1,15 @@ +package alisolarflare.components.fruit; + +import org.bukkit.plugin.java.JavaPlugin; + +import alisolarflare.architecture.Component; + +public class FruitComponent extends Component{ + + @Override + public void register(JavaPlugin plugin) { + registerListener(plugin, new GrassBreakListener()); + + } + +} diff --git a/src/alisolarflare/components/fruit/GrassBreakListener.java b/src/alisolarflare/components/fruit/GrassBreakListener.java new file mode 100644 index 0000000..ee3659d --- /dev/null +++ b/src/alisolarflare/components/fruit/GrassBreakListener.java @@ -0,0 +1,42 @@ +package alisolarflare.components.fruit; + +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.World; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.block.BlockBreakEvent; +import org.bukkit.inventory.ItemStack; + +public class GrassBreakListener implements Listener { + @EventHandler + public void onGrassBreak(BlockBreakEvent event){ + + + if (event.getBlock().getType().equals(Material.LONG_GRASS)){ + + Location location = event.getBlock().getLocation(); + World world = event.getBlock().getWorld(); + + switch((int) (Math.random()* 50)){ + case 1: // 2% chance + world.dropItem(location, new ItemStack(Material.CARROT)); + break; + case 2: // 2% chance + world.dropItem(location, new ItemStack(Material.BEETROOT_SEEDS)); + break; + case 3: // 2% chance + world.dropItem(location, new ItemStack(Material.POTATO)); + break; + case 4: // 2% chance + world.dropItem(location, new ItemStack(Material.FEATHER)); + break; + case 5: // 2% chance + world.dropItem(location, new ItemStack(Material.YELLOW_FLOWER)); + break; + default: + break; + } + } + } +}