public
Last active

SayNoToBonemeal bukkit mod

  • Download Gist
SayNoToBonemeal.java
Java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
package com.github.kksym.saynotobonemeal;
 
import org.bukkit.Material;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
 
public class SayNoToBonemeal extends JavaPlugin {
 
private PluginDescriptionFile description;
 
private class PlayerInteractListener implements Listener {
 
// Disables Bone Meal for growing trees
@EventHandler(priority = EventPriority.NORMAL)
public void onPlayerInteract(PlayerInteractEvent event) {
if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
// Get the item involved in the event
ItemStack item = event.getItem();
// Check if the item is an Ink Sack with data as 15 (Bone Meal)
if (item.getType() == Material.INK_SACK
&& item.getData().getData() == 15) {
// When the event has a block and it's a sapling of some
// sort, cancel the event
if (event.hasBlock()
&& event.getClickedBlock().getType() == Material.SAPLING) {
event.setCancelled(true);
}
}
}
}
}
 
@Override
public void onEnable() {
description = getDescription();
PluginManager manager = getServer().getPluginManager();
 
manager.registerEvents(new PlayerInteractListener(), this);
 
getLogger().info(description.getName() + " v" + description.getVersion() + " enabled!");
}
 
@Override
public void onDisable() {
getLogger().info(description.getName() + " v" + description.getVersion() + " disabled!");
}
 
}
plugin.yml
YAML
1 2 3
name: SayNoToBonemeal
main: com.github.kksym.saynotobonemeal.SayNoToBonemeal
version: 1.0.0

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.