Temporarily 'disable' plugin.

Discussion in 'Plugin Development' started by itsatacoshop247, Mar 22, 2011.

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

    itsatacoshop247

    Basically, my plugin does stuff on a BlockBreakEvent. It displays a server-wide message that would get annoying when people find a couple couple of diamonds together as it spams the chat. I tried to use
    Code:
    "long startTime = System.currentTimeMillis();"
    "long endTime = System.currentTimeMillis();" 
    but it does not save the difference in time, so I could not have
    Code:
    if(endTime-startTime <= 60000)
    Basically, is there a way I can make the plugin not do anything for 60 seconds after it goes into the if statement?

    Heres the source on github: https://github.com/itsatacoshop247/FoundDiamonds
     
  2. Offline

    Sammy

    Yes we can !!
    You can simplify everything just by using the bukkit schedule
    Code:
    int Schedule = plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin,disablePlugin() , (x* 20L));


    The int Schedule is only used if you want to track your schedule

    Code:
    disablePlugin()
    plugin.getServer().getPluginManager().disablePlugin(arg0)
    Use this ideas to make some kind of on and off switch =)
     
  3. Offline

    itsatacoshop247

    So technically I could use
    Code:
    disablePlugin();
    sleep(60000);
    enablePlugin();
    
    However, it tells me there is no method for disablePlugin(), or if i need parameters like disablePlugin(PluginName); it also doesn't work.
     
  4. Offline

    Sammy

    no no no never use sleep() in the main thread it will stop the server and destroy the world as we know it ^^
    Here try this, I haven't tried it myself and I don't know if you can enable the plugin within the same plugin:

    Code:
    
                    plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
    
                        @Override
                        public void run() {
                            plugin.getServer().getPluginManager().disablePlugin("your plugin");
                            plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
    
                                @Override
                                public void run() {
                                    plugin.getServer().getPluginManager().enablePlugin(plugin);
                                }
                            }, (60 * 20L));
                        }
                    });
    EDIT: Now that I'm thinking, you may only need the nested Scheduler not the first one =X

    Code:
    plugin.getServer().getPluginManager().disablePlugin("your plugin");
    
                            plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
    
    
                                @Override
    
                                public void run() {
    
                                    plugin.getServer().getPluginManager().enablePlugin(plugin);
    
                                }
    
                            }, (60 * 20L));
    Try both though'
     
  5. Offline

    itsatacoshop247

    They both worked the same - when I broke the block, it said plugin disabled. However, it would still run when i broke another block. After 60 seconds it would re-enable a second copy of the plugin and then disable it again. I'm thinking that I would need to have it be disabled in the FoundDiamonds Class and the FoundDiamondsBlockListener Class, but I'm not sure how to go about that. But otherwise it was working.

    Also, disablePlugin("FoundDiamonds"); / disablePlugin(FoundDiamonds); etc. wasn't giving an error and not working, but when i changed it to disablePlugin(plugin); it worked as stated above.
     
  6. Offline

    Sammy

    No, if you disable a plugin it should stop the resisted events (BlockListener in this case) no mater the class you do it
    Don't forget to declare the plugin 'though:

    Code:
    FoundDiamonds plugin;
    public TheClassThereTheScheduleIs(sdC plugin) {
            this.plugin = plugin;
        }
    and refer it onEnable()
    Code:
       public void onEnable() {
    TheClassThereTheScheduleIs CT = new TheClassThereTheScheduleIs(this)
     
  7. Offline

    itsatacoshop247

    If you can't tell I'm really new to this. I'm not sure where it goes, I tried everywhere I could think of but I had to change a lot to get rid of errors and then it just wouldn't work. I feel bad for asking, but If you have the time I would apperciate if you could look at my source code and tell me where to put what. :) https://github.com/itsatacoshop247/FoundDiamonds
     
  8. Offline

    Sammy

    Sorry I can't tell you whats wrong =/
    Try asking @Edward Hand to help you, is the code ninja around here ^^
     
  9. Offline

    Edward Hand

    :eek:

    Would you mind if I suggested an entirely different method?
    Code:
    private long lastTime=0;
    
    public void onBlockBreak(BlockBreakEvent event)
    {
        //quit the function if the function was last successfully called less than 30 seconds ago
        if(System.currentTimeMillis()-lastTime < 30000)
            return;
        else
            lastTime = System.currentTimeMillis();
    
        //your other stuff here
    }
    It's slightly less involved than using the scheduler.
    It also has the added advantage that if you want to change it so that the plugin won't show text for individual players for 30 seconds (but if two separate players mine diamonds <30 seconds apart it will do its thing twice) then this can easily be achieved.

    Just for the record, disabling a plugin wont do very much unless you actually put some code in the onDissable function.
     
  10. Offline

    Sammy

    Wait, the idea was to make some-kind of chat filter them someone catch diamonds ? wow i got it all wrong than, I thought he wanted to do something OnDisable :(
    Sorry man
     
  11. Offline

    itsatacoshop247

    Thanks to both of you! Its working fine now. I must ask, where do you learn all this stuff about the Minecraft code? Is there a huge list somewhere, or what? I really only have found things from the Plugin Development Resources area.
     
  12. Offline

    Edward Hand

    The minecraft source code is obfuscated and therefore would be considered quite...advanced.
    You're best doing what most people do and sticking to the proper bukkit api stuff and asking in the dev forum if there's something not possible with that.
     
  13. Offline

    Sammy

    It takes a while, but the best way is really like Edward said, bukkit api and being a active member on the plugin development forum.
     
  14. Offline

    itsatacoshop247

    Okay cool. My friend wants me to make a Blackjack Plugin for his server, so expect me back with questions about that :D
     
Thread Status:
Not open for further replies.

Share This Page