Cactus Hopper Plugin

Discussion in 'Plugin Development' started by SnipesGaming, Mar 27, 2017.

Thread Status:
Not open for further replies.
  1. Offline

    SnipesGaming

    I'm in the process of making a plugin for when cactus breaks it gets picked up by a hopper but you have to do /cactushp first then place the hopper down. I got to the part of turning a regular hopper into a crop hopper but I need some help heres the code so far

    Code:
    package me.SBudzak.CropHopper;
    
    import org.bukkit.Bukkit;
    import org.bukkit.Material;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Listener;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.plugin.java.JavaPlugin;
    
    import net.md_5.bungee.api.ChatColor;
    
    public class CropHopper extends JavaPlugin implements Listener {
       
        public void onEnable(){
            getServer().getPluginManager().registerEvents(this, this);
            getConfig().options().copyDefaults(true);
            getServer().getLogger().info("CropHopper Enabled");
        }
        public void onDisable(){
            getServer().getLogger().info("CropHopper Disabled");
        }
        String Prefix = ChatColor.RED + "SepticCropHopper" + ">";
    
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
            Player p = (Player)sender;
            if (((cmd.getName().equalsIgnoreCase("CropHopper")) || (cmd.getName().equalsIgnoreCase("CH"))) &&
                      (p.hasPermission("ch.use")))
            {
               
                if (args.length == 1){
                    p.sendMessage(this.Prefix + ChatColor.GREEN + "/SD Reload");
                    p.sendMessage(this.Prefix + ChatColor.GREEN + "/SD Disable");
                    p.sendMessage(this.Prefix + ChatColor.GREEN + "/SD Page");
                    return true;
                }
                if (args[0].equalsIgnoreCase("reload")){
                    {
                    if (p.hasPermission("ch.relaod")){
                        Bukkit.getServer().getPluginManager().getPlugin("CropHopper").reloadConfig();
                        p.sendMessage(this.Prefix + ChatColor.GREEN + "Plugin (and Config) Reloaded");
                        return true;
                    }
                if (args[0].equalsIgnoreCase("page")){
                   
                }
                    if (p.hasPermission("ch.page")){
                        Bukkit.getPluginManager().enablePlugin(this);
                        p.sendMessage(this.Prefix + ChatColor.GREEN + "This Plugin Doesn't Have a Page");
                        return true; }       
                       
                if (args[0].equalsIgnoreCase("disable")){
                   
                }
                    if (p.hasPermission("ch.disable")){
                        p.sendMessage(this.Prefix + ChatColor.GREEN + "Plugin Has Been Disabled, To Enable The Plugin, Reload The Server!");
                        Bukkit.getPluginManager().disablePlugin(this);
                                return true;
                    }
                if (args[0].equalsIgnoreCase("CropHopper")){   
                }
                    if (p.hasPermission("ch.ch")){
                        p.sendMessage(this.Prefix + ChatColor.GREEN + "You Converted a Hopper to a CropHopper");
                        p.getOpenInventory().getCursor().getItemMeta().getLore();
                        ItemStack i = new  ItemStack(Material.HOPPER);
                       
                        }
                       
                       
                    }
                }
    return true;
    }
    }   
        return true;
    }
    }
    
       
    
    
    
     
  2. Offline

    yPedx

    @SnipesGaming
    What exactly do you need help with? Continuing the code?
     
  3. Offline

    SnipesGaming

    @yPedx
    Yes Im stuck with trying to first make it where when a player is holding a hopper and does the command /cactushp it will turn into a crop hopper and when you hover over it in your inv it says Cactus hopper instead of Hopper and when you place it it says its a Cactus hopper after clicking on it
     
  4. Offline

    SnipesGaming

    @timtower mind helping me out I fixed some minor stuff but not fully done how do I get it to where if a player is holding a hopper and does /cactushopper it takes the hopper and converts to a cactus hopper with a custom name and lore.

    Code:
    package me.SBudzak.CropHopper;
    
    import org.bukkit.Bukkit;
    import org.bukkit.Material;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Listener;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.plugin.java.JavaPlugin;
    
    import net.md_5.bungee.api.ChatColor;
    
    public class CropHopper extends JavaPlugin implements Listener {
       
        public void onEnable(){
            getServer().getPluginManager().registerEvents(this, this);
            getConfig().options().copyDefaults(true);
            getServer().getLogger().info("CHopper Enabled");
        }
        public void onDisable(){
            getServer().getLogger().info("CHopper Disabled");
        }
        String Prefix = ChatColor.RED + "SepticCropHopper" + ">";
    
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
            Player p = (Player)sender;
            if (((cmd.getName().equalsIgnoreCase("CropHopper")) || (cmd.getName().equalsIgnoreCase("CH"))) &&
                      (p.hasPermission("ch.use")))
            {
               
                if (args.length == 1){
                    p.sendMessage(this.Prefix + ChatColor.GREEN + "/CH Reload");
                    p.sendMessage(this.Prefix + ChatColor.GREEN + "/CH Disable");
                    p.sendMessage(this.Prefix + ChatColor.GREEN + "/CH Page");
                    return true;
                }
                if (args[0].equalsIgnoreCase("reload")){
                    {
                    if (p.hasPermission("ch.relaod")){
                        Bukkit.getServer().getPluginManager().getPlugin("CactusHopper").reloadConfig();
                        p.sendMessage(this.Prefix + ChatColor.GREEN + "Plugin (and Config) Reloaded");
                        return true;
                    }
                if (args[0].equalsIgnoreCase("page")){
                   
                }
                    if (p.hasPermission("ch.page")){
                        Bukkit.getPluginManager().enablePlugin(this);
                        p.sendMessage(this.Prefix + ChatColor.GREEN + "This Plugin Doesn't Have a Page");
                        return true; }       
                       
                if (args[0].equalsIgnoreCase("disable")){
                   
                }
                    if (p.hasPermission("ch.disable")){
                        p.sendMessage(this.Prefix + ChatColor.GREEN + "Plugin Has Been Disabled, To Enable The Plugin, Reload The Server!");
                        Bukkit.getPluginManager().disablePlugin(this);
                                return true;
                    }
                if (args[0].equalsIgnoreCase("CactusHopper")){   
                }
                    if (p.hasPermission("ch.ch")){
                        p.sendMessage(this.Prefix + ChatColor.GREEN + "You Converted a Hopper to a CactusHopper");
                        ItemStack i = new  ItemStack(Material.HOPPER, 1);
                       
                    }
                }
    return true;
    }   
        return true;
    }
            return true;
    }
    }
    
       
    
    
    
     
  5. Online

    timtower Administrator Administrator Moderator

  6. Offline

    SnipesGaming

    @timtower I don't understand change the item meta I tried
    ItemMeta m = new hopper.ItemMeta(lore)
    and it doesn't work
     
  7. Online

    timtower Administrator Administrator Moderator

  8. Offline

    SnipesGaming

    @timtower
    I got this error after doing this
    p.getItemInHand().getItemMeta().setLore(ChatColor.GREEN + ">>" + "CactusHopper" + "<<");
    The method setLore(List<String>) in the type ItemMeta is not applicable for the arguments (String)
    but I only get it on setlore

    Code:
    package me.SBudzak.CropHopper;
    
    import org.bukkit.Bukkit;
    import org.bukkit.Material;
    import org.bukkit.block.Hopper;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Listener;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    import org.bukkit.plugin.java.JavaPlugin;
    
    import net.md_5.bungee.api.ChatColor;
    
    public class CropHopper extends JavaPlugin implements Listener {
       
        public void onEnable(){
            getServer().getPluginManager().registerEvents(this, this);
            getConfig().options().copyDefaults(true);
            getServer().getLogger().info("CHopper Enabled");
        }
        public void onDisable(){
            getServer().getLogger().info("CHopper Disabled");
        }
        String Prefix = ChatColor.RED + "SepticCropHopper" + ">";
    
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
            Player p = (Player)sender;
            if (((cmd.getName().equalsIgnoreCase("CropHopper")) || (cmd.getName().equalsIgnoreCase("CH"))) &&
                      (p.hasPermission("ch.use")))
            {
               
                if (args.length == 1){
                    p.sendMessage(this.Prefix + ChatColor.GREEN + "/CH Reload");
                    p.sendMessage(this.Prefix + ChatColor.GREEN + "/CH Disable");
                    p.sendMessage(this.Prefix + ChatColor.GREEN + "/CH Page");
                    return true;
                }
                if (args[0].equalsIgnoreCase("reload")){
                    {
                    if (p.hasPermission("ch.relaod")){
                        Bukkit.getServer().getPluginManager().getPlugin("CactusHopper").reloadConfig();
                        p.sendMessage(this.Prefix + ChatColor.GREEN + "Plugin (and Config) Reloaded");
                        return true;
                    }
                if (args[0].equalsIgnoreCase("page")){
                   
                }
                    if (p.hasPermission("ch.page")){
                        Bukkit.getPluginManager().enablePlugin(this);
                        p.sendMessage(this.Prefix + ChatColor.GREEN + "This Plugin Doesn't Have a Page");
                        return true; }       
                       
                if (args[0].equalsIgnoreCase("disable")){
                   
                }
                    if (p.hasPermission("ch.disable")){
                        p.sendMessage(this.Prefix + ChatColor.GREEN + "Plugin Has Been Disabled, To Enable The Plugin, Reload The Server!");
                        Bukkit.getPluginManager().disablePlugin(this);
                                return true;
                    }
                if (args[0].equalsIgnoreCase("CactusHopper")){   
                }
                    if (p.hasPermission("ch.ch")){
                        p.sendMessage(this.Prefix + ChatColor.GREEN + "You Converted a Hopper to a CactusHopper");
                        ItemStack i = new ItemStack(Material.HOPPER, 1);
                        ItemMeta m = new ItemMeta(ChatColor.GREEN + ">>" + "CactusHopper" + "<<");
                        p.getItemInHand().getItemMeta().setLore(ChatColor.GREEN + ">>" + "CactusHopper" + "<<");
                    }
                   
                }
    return true;
    }   
        return true;
    }
            return true;
    }
    }
     
  9. Online

    timtower Administrator Administrator Moderator

    @SnipesGaming setLore needs a list, you only gave it a single string
     
  10. Offline

    SnipesGaming

    @timtower
    ok so it works when I do cactus hopper it converts now I need help setting it up to where if the cactus breaks with in the chunk of the cactus hopper is sitting it. it immediately drops into the hopper and doesn't cause entities like when you make a normal cactus farm. If you don't get what I'm trying to say let me know
    heres so far what I have in code wise
    Code:
    package me.SBudzak.CropHopper;
    
    import java.util.ArrayList;
    import java.util.List;
    import java.util.Random;
    
    import org.bukkit.Bukkit;
    import org.bukkit.Material;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.BlockBreakEvent;
    import org.bukkit.event.block.BlockPhysicsEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.plugin.java.JavaPlugin;
    
    import net.md_5.bungee.api.ChatColor;
    
    public class CropHopper extends JavaPlugin implements Listener {
       
        public void onEnable(){
            getServer().getPluginManager().registerEvents(this, this);
            getConfig().options().copyDefaults(true);
            getServer().getLogger().info("CHopper Enabled");
        }
        public void onDisable(){
            getServer().getLogger().info("CHopper Disabled");
        }
        String Prefix = ChatColor.RED + "SepticCropHopper" + ">";
    
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
            Player p = (Player)sender;
            if (((cmd.getName().equalsIgnoreCase("CHopper")) || (cmd.getName().equalsIgnoreCase("CH"))) &&
                      (p.hasPermission("ch.use")))
            {
               
                if (args.length == 1){
                    p.sendMessage(this.Prefix + ChatColor.GREEN + "/CH Reload");
                    p.sendMessage(this.Prefix + ChatColor.GREEN + "/CH Disable");
                    p.sendMessage(this.Prefix + ChatColor.GREEN + "/CH Page");
                    return true;
                }
                if (args[0].equalsIgnoreCase("reload")){
                    {
                    if (p.hasPermission("ch.relaod")){
                        Bukkit.getServer().getPluginManager().getPlugin("CactusHopper").reloadConfig();
                        p.sendMessage(this.Prefix + ChatColor.GREEN + "Plugin (and Config) Reloaded");
                        return true;
                    }
                if (args[0].equalsIgnoreCase("page")){
                   
                }
                    if (p.hasPermission("ch.page")){
                        Bukkit.getPluginManager().enablePlugin(this);
                        p.sendMessage(this.Prefix + ChatColor.GREEN + "This Plugin Doesn't Have a Page");
                        return true; }       
                       
                if (args[0].equalsIgnoreCase("disable")){
                   
                }
                    if (p.hasPermission("ch.disable")){
                        p.sendMessage(this.Prefix + ChatColor.GREEN + "Plugin Has Been Disabled, To Enable The Plugin, Reload The Server!");
                        Bukkit.getPluginManager().disablePlugin(this);
                                return true;
                    }
                if (args[0].equalsIgnoreCase("CactusHopper")){
                }
                    if (p.hasPermission("ch.ch")){
                        ItemStack I = new ItemStack(Material.HOPPER);
                        p.sendMessage(this.Prefix + ChatColor.GREEN + "You Converted a Hopper to a CactusHopper");
                        List<String> l = new ArrayList<String>();
                        l.add(ChatColor.GREEN + "This is a Cactus Hopper");
                        l.add(ChatColor.GRAY + "*If you don't see this then it's not a CactusHopper");
                        p.getItemInHand().getItemMeta().setLore(l);
                        p.getItemInHand().getItemMeta().setDisplayName(ChatColor.GREEN + ">>" + "Cactus Hopper" + "<<");
                                return true;
                    }
                        }
                        }   
                            return true;
                                    }
                    return true;
               
                            }
    
        @EventHandler
        public void onCactusBreak(BlockPhysicsEvent e){
            Random random = new Random();
            e.getBlock().breakNaturally().
            ItemStack i = new ItemStack(Material.CACTUS);
            ItemStack m = new ItemStack(Material.HOPPER);
            e.getBlock().getLocation().getBlock().getDrops(t);
            e.getPlayer().getLocation().getChunk().getEntities();
       
    }
    }
       
    
     
  11. Online

    timtower Administrator Administrator Moderator

    @SnipesGaming Get the drops that will be made.
    Add them to the hopper.
    Set the block to air.
     
  12. Offline

    Zombie_Striker

    @SnipesGaming
    I think I understand what you want. Try this:
    1. on BlockBreakEvent.
    2. If there is a hopper somewhere in the chunk (you will have to loop through the blocks in the chunk)
    3. Cast that hopper's state to a Hopper.
    4. Get it's inventory, add the cactus, and then clear the drops.
     
  13. Offline

    SnipesGaming

    @Zombie_Striker Yes Exactly what I'm trying to do but don't know where to start
    Should I do BlockBreakEvent or BlockPhysicsEvent?
     
  14. Offline

    Zombie_Striker

    @SnipesGaming
    https://hub.spigotmc.org/javadocs/bukkit/
    (Obligatory) All hail the Java Docs!

    From the docs for BlockBreakEvent:
    For PhysicsEvent
    If the block is broken by the player, use BlockBreakEvent. If you want to also detect when it gets broken by something else, you will need to use BlockPhysicsEvent. Just remember that for physics, you have to check if the cactus will break, since the event is called if the block updates in any way.
     
  15. Offline

    SnipesGaming

    @Zombie_Striker
    So I should do this
    this is what I have so far how do I check for break in PhysicsEvent
    Code:
        @EventHandler
        public void onCactusBreak(BlockPhysicsEvent e){
            ItemStack l = new ItemStack(Material.CACTUS);
            e.getBlock().getDrops(l);
    
     
  16. Offline

    Zombie_Striker

    @SnipesGaming
    After checking if the block is actually a cactus, check the four sides of the block and see if they are not air (using Block#getRelative(Blockface.XXX)). If any of them are not air, the cactus is most likely going to break, so then add the block to the hopper.

    BTW: You do not need to add it to the drops. Since you want to add the cactus to the hopper, clear the drops and add the cactus to the hopper.
     
  17. Offline

    SnipesGaming

    @Zombie_Striker
    You are confusing me does # mean .

    Block.getRelative(Blockface.North) doesn't work nor does it work with other directions

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Apr 9, 2017
  18. Offline

    Zombie_Striker

    @SnipesGaming
    The # means that the object before has should be the Instace, not the class. Do example,

    Player#sendMessage (with a #) means you have to get a player instance, and then call sendMessage on that instance.
    Bukkit.broadcastMessage (with a . )means you have to get the class, and call the method on the Class.

    Replace 'Block#' with e.getBlock().getRelative
     
  19. Offline

    SnipesGaming

    @Zombie_Striker
    Ok that works now how would I check if the block is broken and add it to the hopper would it be an if statement or just a normal e.getblock
    Code:
    package me.SBudzak.CropHopper;
    
    import java.util.ArrayList;
    import java.util.List;
    import java.util.Random;
    
    import org.bukkit.Bukkit;
    import org.bukkit.Material;
    import org.bukkit.block.BlockFace;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.BlockBreakEvent;
    import org.bukkit.event.block.BlockPhysicsEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.plugin.java.JavaPlugin;
    
    import net.md_5.bungee.api.ChatColor;
    
    public class CropHopper extends JavaPlugin implements Listener {
       
        public void onEnable(){
            getServer().getPluginManager().registerEvents(this, this);
            getConfig().options().copyDefaults(true);
            getServer().getLogger().info("CHopper Enabled");
        }
        public void onDisable(){
            getServer().getLogger().info("CHopper Disabled");
        }
        String Prefix = ChatColor.RED + "SepticCropHopper" + ">";
    
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
            Player p = (Player)sender;
            if (((cmd.getName().equalsIgnoreCase("CHopper")) || (cmd.getName().equalsIgnoreCase("CH"))) &&
                      (p.hasPermission("ch.use")))
            {
               
                if (args.length == 1){
                    p.sendMessage(this.Prefix + ChatColor.GREEN + "/CH Reload");
                    p.sendMessage(this.Prefix + ChatColor.GREEN + "/CH Disable");
                    p.sendMessage(this.Prefix + ChatColor.GREEN + "/CH Page");
                    return true;
                }
                if (args[0].equalsIgnoreCase("reload")){
                    {
                    if (p.hasPermission("ch.relaod")){
                        Bukkit.getServer().getPluginManager().getPlugin("CactusHopper").reloadConfig();
                        p.sendMessage(this.Prefix + ChatColor.GREEN + "Plugin (and Config) Reloaded");
                        return true;
                    }
                if (args[0].equalsIgnoreCase("page")){
                   
                }
                    if (p.hasPermission("ch.page")){
                        Bukkit.getPluginManager().enablePlugin(this);
                        p.sendMessage(this.Prefix + ChatColor.GREEN + "This Plugin Doesn't Have a Page");
                        return true; }       
                       
                if (args[0].equalsIgnoreCase("disable")){
                   
                }
                    if (p.hasPermission("ch.disable")){
                        p.sendMessage(this.Prefix + ChatColor.GREEN + "Plugin Has Been Disabled, To Enable The Plugin, Reload The Server!");
                        Bukkit.getPluginManager().disablePlugin(this);
                                return true;
                    }
                if (args[0].equalsIgnoreCase("CactusHopper")){
                }
                    if (p.hasPermission("ch.ch")){
                        ItemStack I = new ItemStack(Material.HOPPER);
                        p.sendMessage(this.Prefix + ChatColor.GREEN + "You Converted a Hopper to a CactusHopper");
                        List<String> l = new ArrayList<String>();
                        l.add(ChatColor.GREEN + "This is a Cactus Hopper");
                        l.add(ChatColor.GRAY + "*If you don't see this then it's not a CactusHopper");
                        p.getItemInHand().getItemMeta().setLore(l);
                        p.getItemInHand().getItemMeta().setDisplayName(ChatColor.GREEN + ">>" + "Cactus Hopper" + "<<");
                                return true;
                    }
                        }
                        }   
                            return true;
                                    }
                    return true;
               
                            }
    
        @EventHandler
        public void onCactusBreak(BlockPhysicsEvent e){
            e.getBlock().getChunk().isLoaded();
            ItemStack l = new ItemStack(Material.CACTUS);
            e.getBlock().getRelative(BlockFace.NORTH);
            e.getBlock().getRelative(BlockFace.SOUTH);
            e.getBlock().getRelative(BlockFace.EAST);
            e.getBlock().getRelative(BlockFace.WEST);
            e.getBlock().getState();
           
                   
           
    
       
    }
    }
       
    
     
  20. Offline

    Zombie_Striker

    @SnipesGaming
    Yes. You will need to set up if statements to check if the blocks around the cactus are solid. A 'normal e.getblock' (like what you currently have) would not do anything since you're just getting the block; you're not doing anything with that information.

    BTW: The chunk will always be loaded, so there is no need to check if it is loaded. Also, all the lines you currently have access information without doing anything with it. e.getBlock().getState() does nothing. ....chunk.isLoaded does nothing. You do not need those lines, so you can just delete them.
     
  21. Offline

    SnipesGaming

    @Zombie_Striker
    @timtower
    It won't let me make the e.getblock an if statement how can I fix it
    Code:
    package me.SBudzak.CropHopper;
    
    import java.util.ArrayList;
    import java.util.List;
    import java.util.Random;
    
    import org.bukkit.Bukkit;
    import org.bukkit.Material;
    import org.bukkit.block.BlockFace;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.BlockBreakEvent;
    import org.bukkit.event.block.BlockPhysicsEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.plugin.java.JavaPlugin;
    
    import net.md_5.bungee.api.ChatColor;
    
    public class CropHopper extends JavaPlugin implements Listener {
       
        public void onEnable(){
            getServer().getPluginManager().registerEvents(this, this);
            getConfig().options().copyDefaults(true);
            getServer().getLogger().info("CHopper Enabled");
        }
        public void onDisable(){
            getServer().getLogger().info("CHopper Disabled");
        }
        String Prefix = ChatColor.RED + "SepticCropHopper" + ">";
    
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
            Player p = (Player)sender;
            if (((cmd.getName().equalsIgnoreCase("CHopper")) || (cmd.getName().equalsIgnoreCase("CH"))) &&
                      (p.hasPermission("ch.use")))
            {
               
                if (args.length == 1){
                    p.sendMessage(this.Prefix + ChatColor.GREEN + "/CH Reload");
                    p.sendMessage(this.Prefix + ChatColor.GREEN + "/CH Disable");
                    p.sendMessage(this.Prefix + ChatColor.GREEN + "/CH Page");
                    return true;
                }
                if (args[0].equalsIgnoreCase("reload")){
                    {
                    if (p.hasPermission("ch.relaod")){
                        Bukkit.getServer().getPluginManager().getPlugin("CactusHopper").reloadConfig();
                        p.sendMessage(this.Prefix + ChatColor.GREEN + "Plugin (and Config) Reloaded");
                        return true;
                    }
                if (args[0].equalsIgnoreCase("page")){
                   
                }
                    if (p.hasPermission("ch.page")){
                        Bukkit.getPluginManager().enablePlugin(this);
                        p.sendMessage(this.Prefix + ChatColor.GREEN + "This Plugin Doesn't Have a Page");
                        return true; }       
                       
                if (args[0].equalsIgnoreCase("disable")){
                   
                }
                    if (p.hasPermission("ch.disable")){
                        p.sendMessage(this.Prefix + ChatColor.GREEN + "Plugin Has Been Disabled, To Enable The Plugin, Reload The Server!");
                        Bukkit.getPluginManager().disablePlugin(this);
                                return true;
                    }
                if (args[0].equalsIgnoreCase("CactusHopper")){
                }
                    if (p.hasPermission("ch.ch")){
                        ItemStack I = new ItemStack(Material.HOPPER);
                        p.sendMessage(this.Prefix + ChatColor.GREEN + "You Converted a Hopper to a CactusHopper");
                        List<String> l = new ArrayList<String>();
                        l.add(ChatColor.GREEN + "This is a Cactus Hopper");
                        l.add(ChatColor.GRAY + "*If you don't see this then it's not a CactusHopper");
                        p.getItemInHand().getItemMeta().setLore(l);
                        p.getItemInHand().getItemMeta().setDisplayName(ChatColor.GREEN + ">>" + "Cactus Hopper" + "<<");
                                return true;
                    }
                        }
                        }   
                            return true;
                                    }
                    return true;
               
                            }
    
        @EventHandler
        public void onCactusBreak(BlockPhysicsEvent e){
            ItemStack l = new ItemStack(Material.CACTUS);
            e.getBlock().getRelative(BlockFace.NORTH);
            e.getBlock().getRelative(BlockFace.SOUTH);
            e.getBlock().getRelative(BlockFace.EAST);
            e.getBlock().getRelative(BlockFace.WEST);
                   
           
    
       
    }
    }
       
    
     
    Last edited: Apr 10, 2017
  22. Offline

    Zombie_Striker

    @SnipesGaming
    If(
    e.getBlock().getRelative(BlockFace.XXXX).getType() != Material.AIR
    &&
    ....//Check for the other directions
    )
     
  23. Offline

    SnipesGaming

    @Zombie_Striker
    Is this ok
    Code:
    if (e.getBlock().getRelative(BlockFace.NORTH).getType()!=Material.AIR && e.getBlock().getRelative(BlockFace.SOUTH).getType()!=Material.AIR && e.getBlock().getRelative(BlockFace.EAST).getType()!=Material.AIR && e.getBlock().getRelative(BlockFace.WEST).getType()!=Material.AIR)
     
  24. Offline

    Zombie_Striker

    @SnipesGaming
    My mistake, Replace the And operator (&&) with an Or operator ( || )
     
  25. Offline

    SnipesGaming

    @Zombie_Striker
    @timtower
    ok I fixed that now how will I check if the hopper is place and make it drop into the hopper

    Code:
    package me.SBudzak.CropHopper;
    
    import java.util.ArrayList;
    import java.util.List;
    import org.bukkit.Bukkit;
    import org.bukkit.Material;
    import org.bukkit.block.BlockFace;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.BlockPhysicsEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.plugin.java.JavaPlugin;
    
    import net.md_5.bungee.api.ChatColor;
    
    public class CropHopper extends JavaPlugin implements Listener {
    
        public void onEnable(){
            getServer().getPluginManager().registerEvents(this, this);
            getConfig().options().copyDefaults(true);
            getServer().getLogger().info("CHopper Enabled");
        }
        public void onDisable(){
            getServer().getLogger().info("CHopper Disabled");
        }
        String Prefix = ChatColor.RED + "SepticCropHopper" + ">";
    
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
            Player p = (Player)sender;
            if (((cmd.getName().equalsIgnoreCase("CHopper")) || (cmd.getName().equalsIgnoreCase("CH"))) &&
                      (p.hasPermission("ch.use")))
            {
               
                if (args.length == 1){
                    p.sendMessage(this.Prefix + ChatColor.GREEN + "/CH Reload");
                    p.sendMessage(this.Prefix + ChatColor.GREEN + "/CH Disable");
                    p.sendMessage(this.Prefix + ChatColor.GREEN + "/CH Page");
                    return true;
                }
                if (args[0].equalsIgnoreCase("reload")){
                    {
                    if (p.hasPermission("ch.relaod")){
                        Bukkit.getServer().getPluginManager().getPlugin("CactusHopper").reloadConfig();
                        p.sendMessage(this.Prefix + ChatColor.GREEN + "Plugin (and Config) Reloaded");
                        return true;
                    }
                if (args[0].equalsIgnoreCase("page")){
                   
                }
                    if (p.hasPermission("ch.page")){
                        Bukkit.getPluginManager().enablePlugin(this);
                        p.sendMessage(this.Prefix + ChatColor.GREEN + "This Plugin Doesn't Have a Page");
                        return true; }       
                       
                if (args[0].equalsIgnoreCase("disable")){
                   
                }
                    if (p.hasPermission("ch.disable")){
                        p.sendMessage(this.Prefix + ChatColor.GREEN + "Plugin Has Been Disabled, To Enable The Plugin, Reload The Server!");
                        Bukkit.getPluginManager().disablePlugin(this);
                                return true;
                    }
                if (args[0].equalsIgnoreCase("CactusHopper")){
                }
                    if (p.getPlayer().getItemInHand().equals(Material.HOPPER)){
                        p.sendMessage(this.Prefix + ChatColor.GREEN + "You Converted a Hopper to a CactusHopper");
                        List<String> l = new ArrayList<String>();
                        l.add(ChatColor.GREEN + "This is a Cactus Hopper");
                        l.add(ChatColor.GRAY + "*If you don't see this then it's not a CactusHopper");
                        p.getItemInHand().getItemMeta().setLore(l);
                        p.getItemInHand().getItemMeta().setDisplayName(ChatColor.GREEN + ">>" + "Cactus Hopper" + "<<");
                                return true;
                    }
                        }
                        }   
                            return true;
                                    }
                    return true;
               
                            }
    
        @EventHandler
        public void onCactusBreak(BlockPhysicsEvent e){
            if (e.getBlock().getRelative(BlockFace.NORTH).getType()!=Material.AIR || e.getBlock().getRelative(BlockFace.SOUTH).getType()!=Material.AIR || e.getBlock().getRelative(BlockFace.EAST).getType()!=Material.AIR || e.getBlock().getRelative(BlockFace.WEST).getType()!=Material.AIR){}
           
        }
    }
     
    Last edited: Apr 11, 2017
  26. Offline

    Zombie_Striker

    @SnipesGaming
    1. Create one for loop; This will be the Y. The Y will be equal to the cactus Y, and loop down (subtract 1) until it is equal to 0.
    2. Create two for loops; For the X and for the Z. They will start at the XZ of the cactus minus 1, and loop Up until it is equal to the XZ Plus 1.
    3. (Note that the for loops need to be in that order)
    4. If the block at that XYZ is equal to a hopper.
    5. get the block state and cast it to a Hopper.
    6. Get the hopper's inventory using Hopper#getInventory and add the cactus.
     
  27. Offline

    SnipesGaming

  28. Online

    timtower Administrator Administrator Moderator

    @SnipesGaming Google it please.
    It is one of the most basic things that you can have in Java.
     
  29. Offline

    SnipesGaming

    @timtower
    Can you explain what Zombie_Striker said above in better detail I don't quite understand what hes trying to say

    is this it
    Code:
        @EventHandler
        public void onCactusBreak(BlockPhysicsEvent e){
            if (e.getBlock().getRelative(BlockFace.NORTH).getType()!=Material.AIR || e.getBlock().getRelative(BlockFace.SOUTH).getType()!=Material.AIR || e.getBlock().getRelative(BlockFace.EAST).getType()!=Material.AIR || e.getBlock().getRelative(BlockFace.WEST).getType()!=Material.AIR){}
            for (int Y = 1; Y < 1; Y--){
                for (int X = 1; X < 1; X--){
                    for (int Z = 1; Z < 1; Z--) {
                        e.getBlock().getX().equals(Material.HOPPER);
                        e.getBlock().getY().equals(Material.HOPPER);
                        e.getBlock().getZ().equals(Material.HOPPER);
                        e.getBlock().getState().equals(Material.HOPPER);
                        if e.getBlock().getState().equals(Material.HOPPER) && e.getBlock().getDrops().add(Material.HOPPER){
                
     
    Last edited: Apr 12, 2017
  30. Offline

    Zombie_Striker

    @SnipesGaming
    Please learn Java before working on bukkit. From what you posted, I can tell you do not fully understand what you are doing. If you do not have a tutorial already, please pick a tutorial from the following link.
    https://bukkit.org/threads/plugin-dev-sticky-learning-java-where-to-learn.395662/

    You can't check if it is a hopper by checking if a number is a Hopper, OR if the Cactus is equal to a Hopper. Instead, use World#getBlockAt(X,Y,Z) to get the block at that location. Then, check if the block's type is equal to a Hopper. If it is, you do not want to add it to the drops. Adding to the drops means an extra item will exist in the world, not in hopper. To add it to the hopper, get the hopper's state, cast that to a Hopper object, and add the item to its inventory.
     
    maved145 likes this.
Thread Status:
Not open for further replies.

Share This Page