Simple Plugin, need help.

Discussion in 'Plugin Development' started by desmin88, Mar 11, 2011.

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

    desmin88

    *snip*
     
  2. Offline

    Plague

    Yup, you are :)
    public abstract void save(); is a definition of the function, you cannot call it like that. Now I could just write everything here, but really this calls for some basic programming study first.
    You want to call getWorld().save(); I think

    Is that really the whole error? post the plugin.yml

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 11, 2016
  3. Offline

    eltorqiro

    You haven't specified the entry point for the plugin (the "main" parameter in plugin.yml). Try changing it to this:

    main: org.desmin88.simplesave.desmin88.simplesave.SimpleSave

    btw, from the above it looks like you followed the wiki entry on how to create a plugin, which unfortunately is very out of date and has some errors (like specifying author.plugin.author.plugin or something like that). To make it easier on the nice, refactor the package name to just org.desmin88.simplesave and then your main will be org.desmin88.simplesave.SimpleSave
     
  4. Offline

    Edward Hand

    Make sure you are using an up-to-date version of bukkit/craftbukkit as the functions you are calling are relatively new.

    1) its thread.interupt() now instead of thread.stop()
    2) you are missing an opening curly-bracket for your while loop
    3) your condition should be ==
    4) I don't think the SaveThread class will be able to access the 'run' property from SimpleSave like that. You may need to reference it more absolutely.
    [MERGETIME="1299876558"][/MERGETIME]
    Oh, and its a lot safer to use bukkit's built in Scheduler than it is to use separate threading as you have there (otherwise corruption can occur)

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 11, 2016
  5. Offline

    eltorqiro

    I think he is talking about a scope issue. You have a property of the SimpleSave class called run. You then have a method of the SaveThread class called run, inside which you are trying to reference the SimpleSave run property without specifying a scope.

    I'm not much good with java, but since "this." is needed to prefix class properties inside methods belonging to the same class, I can't see how java will be clever enough to know what particular run property you are trying to reference.

    If you are committed to extending the Thread class, I think you will want something like the below code. However, I have no idea with threads if my code is valid, just showing the possible scope issue:

    Code:
    package org.desmin88.simplesave;
    
    import java.util.HashMap;
    import org.bukkit.entity.Player;
    import org.bukkit.Server;
    import org.bukkit.event.Event.Priority;
    import org.bukkit.event.Event;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.PluginLoader;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.World;
    
    public class SimpleSave extends JavaPlugin {
        private SaveThread saveThread;
    
        public void onDisable() {
            this.saveThread.setRunning(false);
            this.saveThread.interrupt();
        }
    
        public void onEnable() {
            this.saveThread =  new SaveThread();
            this.saveThread.setRunning(true);
            this.saveThread.start();
        }
    
        class SaveThread extends Thread {
            private boolean running;
    
            public void setRunning(boolean running) {
               this.running = running;
            }
    
            public void run() {
                while(this.running==true){
    
                try {
                    Thread.sleep(10000);
                } catch (InterruptedException e) {
    
                    e.printStackTrace();
                }
                getServer().getWorld("world").save();
                   getServer().savePlayers();
                   getServer().broadcastMessage("World and players saved");
              }
            }
        }
    
    }
    
     
  6. Offline

    Edward Hand

    It looks like that number is coming with a new line character, which it may not like. Try discarding the last character of the string
     
Thread Status:
Not open for further replies.

Share This Page