Made Long Grass drop carrots and potatoes

Temporary fix for the lack of carrots and potatoes in the server
This commit is contained in:
alisolarflare 2016-12-09 20:27:58 -05:00
parent 8bad0a97f4
commit 3a23f4745a
3 changed files with 59 additions and 0 deletions

View file

@ -11,6 +11,7 @@ import alisolarflare.components.bankchest.BankChestComponent;
import alisolarflare.components.cashmob.CashMobComponent; import alisolarflare.components.cashmob.CashMobComponent;
import alisolarflare.components.creativeboundaries.CreativeBoundariesComponent; import alisolarflare.components.creativeboundaries.CreativeBoundariesComponent;
import alisolarflare.components.flaircolouring.FlairColouringComponent; import alisolarflare.components.flaircolouring.FlairColouringComponent;
import alisolarflare.components.fruit.FruitComponent;
import alisolarflare.components.gpowers.GPowerComponent; import alisolarflare.components.gpowers.GPowerComponent;
import alisolarflare.components.insurance.InsuranceComponent; import alisolarflare.components.insurance.InsuranceComponent;
import alisolarflare.components.magic.MagicComponent; import alisolarflare.components.magic.MagicComponent;
@ -29,6 +30,7 @@ public class AliPresents extends JavaPlugin{
new CashMobComponent().register(this); new CashMobComponent().register(this);
new CreativeBoundariesComponent().register(this); new CreativeBoundariesComponent().register(this);
new FlairColouringComponent().register(this); new FlairColouringComponent().register(this);
new FruitComponent().register(this);
new GPowerComponent().register(this); new GPowerComponent().register(this);
new InsuranceComponent().register(this); new InsuranceComponent().register(this);
new MagicComponent().register(this); new MagicComponent().register(this);

View file

@ -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());
}
}

View file

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