Solved Plugin works only on reload

Discussion in 'Plugin Development' started by 97WaterPolo, Mar 20, 2014.

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

    97WaterPolo

    Basically I have a plugin that has multiple listeners and a repeating task. Problem is, it says it loads on start up, no errors, no stacktrace, etc, yet nothing happens. However, when I use a 3rd party plugin like plugman to reload the plugin from in game, it starts to work and sends the debug messages. Does anyone have any ideas to how this is even possible as I am really stumped. Any help would be greatly appreciated.

    Code:

    Code:
    import org.bukkit.Bukkit;
    import org.bukkit.Material;
    import org.bukkit.entity.Player;
    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.entity.EntityDamageByEntityEvent;
    import org.bukkit.event.entity.EntityShootBowEvent;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.event.player.PlayerRespawnEvent;
    import org.bukkit.plugin.java.JavaPlugin;
     
     
     
    public class Main extends JavaPlugin implements Listener {
        public void onEnable()
        {
     
            getServer().getPluginManager().registerEvents(this, this);
     
            getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable()
            {
                public void run()
                {
                    for (Player player : Bukkit.getOnlinePlayers())
                    {
                        if ((!player.isSprinting()))
                        {
                            if(player.getLevel() < 100)
                            {
                                player.setLevel(player.getLevel() + 1);
                                player.sendMessage("Test 1");
                            }
                        }else
                        {
                            if (player.getLevel() > 0)
                            {
                                player.sendMessage("Test 2");
                            }
                            }
                        }
                    }
                }
            }
            ,0, 20L);
        }
        @EventHandler(priority = EventPriority.HIGHEST)
        public void onRespawn(PlayerRespawnEvent event)
        {
            final Player player = event.getPlayer();
            getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable()
            {
     
                @Override
                public void run()
                {player.sendMessage("test);}
            }, 5L);
     
        }
        @EventHandler(priority = EventPriority.HIGHEST)
        public void onSwing(PlayerInteractEvent event)
        {
            Player player = event.getPlayer();
            player.sendMessage("Test 1 sword");
            if(event.getAction().equals(Action.LEFT_CLICK_AIR) || event.getAction().equals(Action.LEFT_CLICK_BLOCK))
            {
                if(isSword(player.getItemInHand().getType())) //isSword is a method far below
                {
                    player.sendMessage("Test 3 sword");
                }
            }
        }
    Not sure why, but on SagaciousZed's suggestion I removed all plugins in folder, then I made a new project and just copied the code over and it seemed to work.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  2. Offline

    Barinade

    You may have extracted a plugin to the wrong plugin file name and added them both
    For instance, SomePlugin as SumPlugin.jar, OtherPlugin as OtherPlugin.jar, but now you tweak SomePlugin and go to export, but by default the OtherPlugin's file name is there, and you may have missed that

    I do that all the time because I'm too lazy to find a way to prevent myself from doing that, I usually catch myself right when I do it though
     
  3. Offline

    97WaterPolo

    Barinade
    I didn't really understand that! :p

    When I export, I highlight the project itself in eclipse, then right click > export > etc. I don't go through File > Export > select project > etc.?
     
  4. Offline

    Barinade

    The file name you choose to export it as is the previous file you exported, so if you export plugin1 then plugin2 and don't change the file name then plugin2 will use plugin1's name

    Basically, maybe you extracted Plugin1 with name Plugin1, and Plugin2 with the same name (Plugin1)
     
  5. Offline

    97WaterPolo

    Barinade
    And that makes more sense as to when I created a new project it worked :L Thank you so much for the explanation!
     
  6. Offline

    SGrayMe

    It's easier to understand after having done that a couple times lol. Though, I've not had that problem since I learned to use Maven (or at least the basics of Maven). :p

    97WaterPolo The code you posted has typos in it. I'm guessing you accidentally over-edited your paste (?) Though perhaps you are distracted :) and had a typo somewhere else in your plugin causing the unusual behavior.
     
  7. Offline

    97WaterPolo

    SGrayMe
    Yea, probably, was making this in hastebin :L Can only do so much from it! :p When I moved it to my IDE i fixed all the simple errors like extra brackets, etc! Thanks for pointing it out though! :D

    What exactly is maven? My general understanding of it is a way to have all your external jars in one place, and instead of adding them all to your project, you just reference the Maven whatever?
     
  8. Offline

    Barinade

  9. Offline

    SGrayMe

    You tell Maven where to find the jars and how your project should be packed and Maven puts your (metaphorical) ducks in a row with the plugin resources/dependencies. Once you get past the initial learning hump, Maven makes building a project extremely convenient.

    Here is a guide with a bunch of information
    http://maven.apache.org/guides/getting-started/

    And an example of a pom.xml (this is one of my projects)
    http://pastebin.com/bypg6Avw

    I have Eclipse set up to recognize the project as a Maven project and I only have to tell it to "Run as" "Maven install" to build a proper plugin jar. :)
     
  10. Offline

    Barinade

    Where can I find the Ducks class source code?
     
  11. Offline

    97WaterPolo

    Thanks for the help! Will look into this when I get home!
     
Thread Status:
Not open for further replies.

Share This Page