Plugin not throwing errors, but not working

Discussion in 'Plugin Development' started by hostadam, Jan 15, 2017.

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

    hostadam

    Code:
    package me.hostadam.outhost;
    
    import java.util.ArrayList;
    
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerPickupItemEvent;
    import org.bukkit.inventory.ItemStack;
    
    public class NoCobblePickup implements Listener, CommandExecutor {
      
        public static ArrayList<String> cobble = new ArrayList();
      
        @EventHandler
        public void onCobblePickup(PlayerPickupItemEvent e) {
            Player p = e.getPlayer();
            if(cobble.contains(p.getName())) {      
            if (e.getItem() == new ItemStack(Material.COBBLESTONE)) {
                        e.setCancelled(true);
                    }
        } else {
            if(!cobble.contains(p.getName())) {
            e.setCancelled(false);
        }
        }
        }
            public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
            if (cmd.getName().equalsIgnoreCase("cobble")) {
                Player player = (Player) sender;
                player.sendMessage(ChatColor.RED + "You disabled cobblestone pickups!");
                cobble.add(player.getName());
    } else {
        Player player = (Player) sender;
        if(cobble.contains(player.getName())) {
            player.sendMessage(ChatColor.GREEN + "You enabled cobblestone pickups!");
            cobble.remove(player.getName());
    }
    }
            return false;
    }
    }
    
    
    The code doesn't put any errors in the Console, but it still doesn't work, what is the problem?
    I've tried debugging it for an hour, but can't come up with the issue.


    MAIN CLASS:
    Code:
    package me.hostadam.outhost;
    
    import java.awt.List;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Listener;
    import org.bukkit.plugin.Plugin;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Outhost extends JavaPlugin {
    
        private static Plugin plugin;
      
        public void onEnable() {
        plugin = this;
        //This is where we register our events/commands
        registerEvents(this, new CommandBlocker());
        registerEvents(this, new NoMiningBlazeSpawners());
        registerEvents(this, new AutoSmelt());
        registerEvents(this, new NoEnderchest());
        registerEvents(this, new NoCobblePickup());
        getCommand("help").setExecutor(new CustomHelp());
        getCommand("helpop").setExecutor(new Helpop());
        getCommand("list").setExecutor(new CustomList());
        getCommand("coords").setExecutor(new Coords());
        getCommand("report").setExecutor(new Report());
        getCommand("cobble").setExecutor(new NoCobblePickup());
        }
      
            // TODO Auto-generated method stub
         
     
    
            // TODO Auto-generated method stub
    
        public void onDisable() {
        plugin = null;//To stop memory leaks
      
        }
      
      
        //Much easier then registering events in 10 different methods
        public static void registerEvents(org.bukkit.plugin.Plugin plugin, Listener... listeners) {
        for (Listener listener : listeners) {
        Bukkit.getServer().getPluginManager().registerEvents(listener, plugin);
        }
        }
      
        //To access the plugin variable from other classes
        public static Plugin getPlugin() {
        return plugin;
        }
      
      
      
      
        }
    
    PLUGIN.YML
    
    Code:
    name: Outhost
    author: hostadam & Outfield
    description: Custom HCF Core
    version: 1.0
    main: me.hostadam.outhost.Outhost
    commands:
    list:
       description: Check how many players there is online.
       aliases: [glist]
    helpop:
       description: Sends a message to all online staff.
       aliases: [request]
    coords:
       description: Some useful coordinates.
       aliases: [coordinates]
    help:
       description: Some useful information.
       aliases: [?]
    report:
       description: Report a player.
       aliases: [hacker]
    cobble:
       description: Disable cobblestone pickups.
       aliases: [cobblestone]
    permissions:
    helpop.receive:
        description: Make it able to receive requests.
        default: op
    report.receive:
        description: Make it able to receive reports.
        default: op
    
     
    Last edited: Jan 15, 2017
  2. Offline

    JanTuck

    Did you register the event and executor? Did you register the command in the plugin.yml? Please provide the main calss and plugin.yml too.
     
  3. Offline

    hostadam

    Code:
    package me.hostadam.outhost;
    
    import java.awt.List;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Listener;
    import org.bukkit.plugin.Plugin;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Outhost extends JavaPlugin {
    
        private static Plugin plugin;
       
        public void onEnable() {
        plugin = this;
        //This is where we register our events/commands
        registerEvents(this, new CommandBlocker());
        registerEvents(this, new NoMiningBlazeSpawners());
        registerEvents(this, new AutoSmelt());
        registerEvents(this, new NoEnderchest());
        registerEvents(this, new NoCobblePickup());
        getCommand("help").setExecutor(new CustomHelp());
        getCommand("helpop").setExecutor(new Helpop());
        getCommand("list").setExecutor(new CustomList());
        getCommand("coords").setExecutor(new Coords());
        getCommand("report").setExecutor(new Report());
        getCommand("cobble").setExecutor(new NoCobblePickup());
        }
       
            // TODO Auto-generated method stub
          
      
    
            // TODO Auto-generated method stub
    
        public void onDisable() {
        plugin = null;//To stop memory leaks
       
        }
       
       
        //Much easier then registering events in 10 different methods
        public static void registerEvents(org.bukkit.plugin.Plugin plugin, Listener... listeners) {
        for (Listener listener : listeners) {
        Bukkit.getServer().getPluginManager().registerEvents(listener, plugin);
        }
        }
       
        //To access the plugin variable from other classes
        public static Plugin getPlugin() {
        return plugin;
        }
       
       
       
       
        }
    
    
    
    Code:
    name: Outhost
    author: hostadam & Outfield
    description: Custom HCF Core
    version: 1.0
    main: me.hostadam.outhost.Outhost
    commands:
    list:
       description: Check how many players there is online.
       aliases: [glist]
    helpop:
       description: Sends a message to all online staff.
       aliases: [request]
    coords:
       description: Some useful coordinates.
       aliases: [coordinates]
    help:
       description: Some useful information.
       aliases: [?]
    report:
       description: Report a player.
       aliases: [hacker]
    cobble:
       description: Disable cobblestone pickups.
       aliases: [cobblestone]
    permissions:
    helpop.receive:
        description: Make it able to receive requests.
        default: op
    report.receive:
        description: Make it able to receive reports.
        default: op
    
     
  4. Offline

    DinosaurKappa

    Everything is registered including the plugin.yml (I was helping him code through join.me, but was pretty confused reading it over join.me.)
     
  5. Offline

    hostadam

    ^^
     
  6. Offline

    RenditionsRule

    @hostadam Does the plugin not load? Or does it run and not do what you wanted? Try adding debug messages.
     
  7. Offline

    JanTuck

    Okay, in the onCobblePickup you are doing

    Code:java
    1.  
    2. if (e.getItem() == new ItemStack(Material.COBBLESTONE)) {
    3.  


    The e.getItem() returns an Item which wont be an itemstack.

    Instead use Item#getItemStack() after that you should compare the material with te material so.

    Code:java
    1.  
    2. if (ItemMaterial == Material.COBBLESTONE ) {
    3.  


    Get the material with ItemStack#getType()
     
    Zombie_Striker likes this.
  8. Offline

    RenditionsRule

    @JanTuck Don't use .equals() to compare enums?
     
  9. Offline

    JanTuck

    Fuck i did that wrong lol. I thought of strings when i wrote the upper part. Thx for noticing. Edited!
     
  10. Offline

    mythbusterma

    @RenditionsRule

    You can, or you can use ==, doesn't matter. Whichever looks better to you.
     
Thread Status:
Not open for further replies.

Share This Page