Not even broadcastMessage works now, help!

Discussion in 'Plugin Development' started by SpoinkX12, Jun 17, 2016.

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

    SpoinkX12

    I'm having a lot of trouble finding help on debugging my plugin. I've used youtube, google, and these forums trying to find a solution to my issues, to no avail.

    Code:
    package com.gino.heroica;
    
    import java.util.Set;
    import java.util.logging.Logger;
    
    import org.bukkit.Bukkit;
    import org.bukkit.Material;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.inventory.PlayerInventory;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Heroica extends JavaPlugin {
    
        public void onEnable() {
            PluginDescriptionFile pdfFile = getDescription();
            Logger logger = getLogger();
    
            logger.info(pdfFile.getName() + " version " + pdfFile.getVersion() + " has been enabled!");
            Bukkit.broadcastMessage("BROADCAST MESSAGE!!");
        }
    
        public void onDisable() {
            PluginDescriptionFile pdfFile = getDescription();
            Logger logger = getLogger();
    
            logger.info(pdfFile.getName() + " version " + pdfFile.getVersion() + " has been disabled!");
        }
    
        @EventHandler
        public void onPlayerInteractBlock(PlayerInteractEvent event) {
            Player player = event.getPlayer();
            PlayerInventory inventory = player.getInventory(); //the inventory of the player this event is referencing.
            if (inventory.getItemInMainHand().getType() == Material.FEATHER && inventory.getItemInOffHand().getType() == Material.GOLD_INGOT) {
                Bukkit.broadcastMessage("You have the proper items for this teleport");
                //Teleport a player to their target location up to 64 blocks away.
                player.teleport(player.getTargetBlock((Set<Material>) null, 64).getLocation());
            }
            else
                Bukkit.broadcastMessage("ASDF YOU FUCCCCDD");
        }
    }
    I can't even get the Bukkit.broadcastMessage to fire, and yet afaik, everything in my code is crispy. I know this is vague and most people will roll their eyes, but I have no idea what the problem is here when not even my debug lines will work!
     
  2. Online

    timtower Administrator Administrator Moderator

    @SpoinkX12 Try to register the event.
    And are you putting it in the right place etc?
     
  3. Offline

    Zombie_Striker

    Bukkit already logs your plugins for you, you do not need to do it twice. Remove all this code.

    The item in the player's hand can be null. Nullcheck the item before you get the type.

    The target block can be null if the chunk is not loaded. Nullcheck first.

    Main problem: You forgot to register your event.
     
  4. Offline

    SpoinkX12

    So here's the updated code, and I'm still having the exact same problems. the plugin is loaded, it says it in green when I type /pl . I have NO idea now where to go with this, absolutely nothing is working in this code.

    Code:
    package com.gino.heroica;
    
    import java.util.Set;
    
    import org.bukkit.Bukkit;
    import org.bukkit.Material;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.inventory.PlayerInventory;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Heroica extends JavaPlugin implements Listener {
    
        public void onEnable() {
            Bukkit.getServer().getPluginManager().registerEvents(this, this);
        }
    
        public void onDisable() {
    
        }
       
        @EventHandler
        public void onPlayerInteractBlock(PlayerInteractEvent event) {
            Player player = event.getPlayer();
            PlayerInventory inventory = player.getInventory(); //the inventory of the player this event is referencing.
            Bukkit.broadcastMessage("You clicked a block");
            if (inventory.getItemInMainHand().getType() == Material.FEATHER && inventory.getItemInOffHand().getType() == Material.GOLD_INGOT) {
                Bukkit.broadcastMessage("You have the proper items for this teleport");
                //Teleport a player to their target location up to 64 blocks away.
                player.teleport(player.getTargetBlock((Set<Material>) null, 64).getLocation());
            }
            else
                Bukkit.broadcastMessage("ASDF YOU FUCCCCDD");
        }
    }
     
  5. Offline

    Zombie_Striker

    @SpoinkX12
    Are there any errors in the console? Can you post the full log?
     
  6. Offline

    SpoinkX12

    There are none, but here

    Code:
    C:\Users\Gino Zaccardelli\Desktop\MCServer>java -Xmx1024M -Xmx2048M -jar craftbu
    kkit.jar nogui
    Loading libraries, please wait...
    [16:04:18 INFO]: Starting minecraft server version 1.10
    [16:04:18 INFO]: Loading properties
    [16:04:18 INFO]: Default game type: SURVIVAL
    [16:04:18 INFO]: Generating keypair
    [16:04:18 INFO]: Starting Minecraft server on *:25565
    [16:04:18 INFO]: Using default channel type
    [16:04:19 INFO]: This server is running CraftBukkit version git-Bukkit-02f4218 (
    MC: 1.10) (Implementing API version 1.10-R0.1-SNAPSHOT)
    [16:04:19 INFO]: [Heroica] Loading Heroica v1.0
    [16:04:19 INFO]: Preparing level "world"
    [16:04:19 INFO]: Preparing start region for level 0 (Seed: 8178025407074566661)
    [16:04:20 INFO]: Preparing spawn area: 60%
    [16:04:20 INFO]: Preparing start region for level 1 (Seed: 8178025407074566661)
    [16:04:21 INFO]: Preparing start region for level 2 (Seed: 8178025407074566661)
    [16:04:21 INFO]: [Heroica] Enabling Heroica v1.0
    [16:04:21 INFO]: Heroica version 1.0 has been enabled!
    [16:04:21 INFO]: Server permissions file permissions.yml is empty, ignoring it
    [16:04:21 INFO]: Done (2.251s)! For help, type "help" or "?"
    >reload
    [16:06:53 INFO]: CONSOLE: Please note that this command is not supported and may
    cause issues when using some plugins.
    [16:06:53 INFO]: CONSOLE: If you encounter any issues please use the /stop comma
    nd to restart your server.
    [16:06:53 INFO]: [Heroica] Disabling Heroica v1.0
    [16:06:53 INFO]: Heroica version 1.0 has been disabled!
    [16:06:53 INFO]: [Heroica] Loading Heroica v1.0
    [16:06:53 INFO]: [Heroica] Enabling Heroica v1.0
    [16:06:53 INFO]: Heroica version 1.0 has been enabled!
    [16:06:53 INFO]: Server permissions file permissions.yml is empty, ignoring it
    [16:06:53 INFO]: CONSOLE: Reload complete.
    [16:12:45 INFO]: UUID of player TaxmanBob is b9fed668-f7d2-48c8-a4d3-73391bf166d
    6
    [16:12:45 INFO]: TaxmanBob[/127.0.0.1:54422] logged in with entity id 317 at ([w
    orld]236.40845356215624, 77.0, 248.3064903428157)
    [16:12:50 INFO]: TaxmanBob issued server command: /pl
    [16:13:08 INFO]: TaxmanBob lost connection: Disconnected
    [16:13:08 INFO]: TaxmanBob left the game.
    >reload
    [16:15:03 INFO]: CONSOLE: Please note that this command is not supported and may
    cause issues when using some plugins.
    [16:15:03 INFO]: CONSOLE: If you encounter any issues please use the /stop comma
    nd to restart your server.
    [16:15:03 INFO]: [Heroica] Disabling Heroica v1.0
    [16:15:03 INFO]: Heroica version 1.0 has been disabled!
    [16:15:03 INFO]: [Heroica] Loading Heroica v1.0
    [16:15:03 INFO]: [Heroica] Enabling Heroica v1.0
    [16:15:03 INFO]: Heroica version 1.0 has been enabled!
    [16:15:03 INFO]: Server permissions file permissions.yml is empty, ignoring it
    [16:15:03 INFO]: CONSOLE: Reload complete.
    >reload
    [16:16:01 INFO]: CONSOLE: Please note that this command is not supported and may
    cause issues when using some plugins.
    [16:16:01 INFO]: CONSOLE: If you encounter any issues please use the /stop comma
    nd to restart your server.
    [16:16:01 INFO]: [Heroica] Disabling Heroica v1.0
    [16:16:01 INFO]: Heroica version 1.0 has been disabled!
    [16:16:01 INFO]: [Heroica] Loading Heroica v1.0
    [16:16:01 INFO]: [Heroica] Enabling Heroica v1.0
    [16:16:01 INFO]: Heroica version 1.0 has been enabled!
    [16:16:01 INFO]: Server permissions file permissions.yml is empty, ignoring it
    [16:16:01 INFO]: CONSOLE: Reload complete.
    >
    I reload a few times there though.
     
  7. @SpoinkX12 As far as I know you need to add @Override above the onEnable and onDisable, also, if you are not using the onDisable remove it.
     
  8. Offline

    Zombie_Striker

    This should not matter. This is more a convention which helps devs figure out which methods are being overwritten.

    @SpoinkX12
    It seems your plugin gets enabled without a problem. Do any other events work? Try debugging the PlayerMoveEvent to see if your classs is even being registered.
     
  9. Huh ok, I was always told that you should add @Override, even Eclipse will put in @Override when I auto complete them.
     
  10. Offline

    Zombie_Striker

    @ibc2244
    Yes. It convention and should be done, but is not necessary.
     
Thread Status:
Not open for further replies.

Share This Page