Need a little bit Help with a Plugin

Discussion in 'Plugin Development' started by Crosant, Jun 14, 2011.

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

    Crosant

    I need to make a plugin which make that players must pay iconomy money whan they go through
    certain doors.
    But i dont have an idear how to set the doors...
    and how to make that the player must pay money.
    Do someone have idears if yes thank you :)
     
  2. Offline

    chronopolis

    So you're basically asking us to write you the plugin :p Why don't you just use Turnstile?
     
  3. Offline

    Taco

    This is a bit vague, but I'll give it a shot.

    Have the plugin use OnPlayerMove to check if the block they're in is a door. If so, bill them once and start a short timer that will trigger a boolean saying that they can be billed again to prevent them from being billed again. The timer is because OnPlayerMove is fired every time a player takes a step, looks around, or anything that could be called movement. So a bill of $10 to go through a door could end up being $200 without that timer.

    After you've determined that they did indeed walk through the door, you'd use something like this:

    Code:
    //Bill them here
    hasPaidForDoor = true;
    doorTimer timer = new doorTimer(); //Set the boolean hasPaidForDoor to false after this timer is over.
     
  4. Offline

    Crosant

    Ty i think with that i can make the plugin :)
     
  5. Offline

    chronopolis

    This. Also if you want to only charge for certain doors, you will need to pick an item as a "selector". You would use the onPlayerInteract to do this, and check if the event.getAction() = Action.LEFTCLICK. Then check if the event.getClickedBlock()!=null and event.getClickedBlock().getTypeId()==(whatever item number you choose).

    Then add the door to an ArrayList (at least I would use an arraylist). Now every time you walk through a door, check that door against that arraylist. I'm not sure if doors have unique ids, you may have to attach one to it yourself.

    Or, instead of adding the Door itself to the ArrayList, you could add the Locations and check the Location of the door you are walking through against the locations of each door in the list. That would be easier now that I think about it.
     
  6. Offline

    Taco

    Adding the door itself to an arraylist would work as you're referencing that door directly. To load it from a db, it may be easier to store the locations and then check the locations in the db when the server's loaded to make sure the doors are still there. Also you'll probably want a check in OnBlockDestroy or whatever it is now to remove the door from the arraylist if it's destroyed.
     
  7. Offline

    chronopolis

    Will it work? I knew you could add it to the ArrayList, but I can't think of any unique variable to distinguish it from other doors besides the Location. So I figured storing the door when your only checking the location would be silly. And good catch on the OnBlockDestroy thing.

    I think between all of us this dude is gonna have a nicely working plugin pretty soon :p
     
  8. Offline

    Taco

    Well the location would work, I was more of thinking of declaring an ArrayList of doors so you don't have to reference the current world and location and whatnot, rather it would reference each door directly which would be less work for the server. I'm not sure if there's a door object or not, so it may have to be stored in a block ArrayList instead.
     
  9. Offline

    Crosant

    So need help again i bacome an failure if i want to test the first aprt of the plugin its just the loading of the properties...
    MY Failure
    Code:
    
    
    C:\Users\Florian\Desktop\MC server>java -Xmx2G -Xms1024M -jar minecraft_server.j
    ar gui
    148 recipes
    16 achievements
    16:57:54 [INFO] Starting minecraft server version Beta 1.6.6
    16:57:54 [INFO] Loading properties
    16:57:54 [INFO] Starting Minecraft server on *:25565
    16:57:54 [INFO] This server is running Craftbukkit version git-Bukkit-0.0.0-766-
    g3fc0460-b818jnks (MC: 1.6.6)
    16:57:54 [INFO] Preparing level "world"
    16:57:54 [INFO] Preparing start region for level 0
    16:57:55 [INFO] Preparing spawn area: 52%
    16:57:56 [INFO] Preparing spawn area: 73%
    16:57:57 [INFO] Preparing start region for level 1
    16:57:57 [INFO] Preparing spawn area: 8%
    16:57:58 [SCHWERWIEGEND] Could not load 'plugins\Doorpay.jar' in folder 'plugins
    ':
    java.lang.reflect.InvocationTargetException
            at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    
            at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    
            at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Sou
    rce)
            at java.lang.reflect.Constructor.newInstance(Unknown Source)
            at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.j
    ava:172)
            at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.
    java:194)
            at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager
    .java:117)
            at org.bukkit.craftbukkit.CraftServer.loadPlugins(CraftServer.java:103)
            at net.minecraft.server.MinecraftServer.e(MinecraftServer.java:232)
            at net.minecraft.server.MinecraftServer.a(MinecraftServer.java:219)
            at net.minecraft.server.MinecraftServer.init(MinecraftServer.java:146)
            at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:285)
            at net.minecraft.server.ThreadServerApplication.run(SourceFile:422)
    Caused by: java.lang.NullPointerException
            at me.Crosant.Doorpay.Doorpay.<init>(Doorpay.java:23)
            ... 13 more
    16:57:58 [INFO] Done (0,404s)! For help, type "help" or "?"
    >
    And my Doorpay.java
    Code:
    package me.Crosant.Doorpay;
    
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.util.Properties;
    import java.util.logging.Logger;
    
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;
      
    public class Doorpay extends JavaPlugin {
        static String mainDirectory = "plugins/Zones"; //sets the main directory for easy reference
         static File Zones = new File(mainDirectory + File.separator + "Zones.dat"); //the file separator is the / sign, this will create a new Zones.dat files in the mainDirectory variable listed above, if no Zones directory exists then it will automatically be made along with the file.
         static Properties prop = new Properties(); //creates a new properties file
      
        private static final Logger log = Logger.getLogger("Minecraft");
        PluginManager pm = this.getServer().getPluginManager();
    
        public void onEnable() {
    
             new File(mainDirectory).mkdir(); //makes the Zones directory/folder in the plugins directory
             if(!Zones.exists()){ //Checks to see if the zones file exists, defined above, if it doesn't exist then it will do the following. the&nbsp;! turns the whole statement around, checking that the file doesn't exist instead of if it exists.
                 try { //try catch clause explained below in tutorial
                     Zones.createNewFile(); //creates the file zones.dat
                     FileOutputStream out = new FileOutputStream(Zones); //creates a new output steam needed to write to the file
                     prop.put("ZoneCount", "0"); //put the property ZoneCount with a value of 0 into the properties file, this will show up as ZoneCount=0 in the properties file.
                     prop.store(out, "Do NOT edit this config!"); //You need this line! It stores what you just put into the file and adds a comment.
                     out.flush();  //Explained below in tutorial
                     out.close(); //Closes the output stream as it is not needed anymore.
                 } catch (IOException ex) {
                     ex.printStackTrace(); //explained below.
                 }
    
        } else {
    
            loadProcedure();
    
        }
     
            log.info("Doors Online");
        }
    
        public void loadProcedure(){
    
        FileInputStream in = new FileInputStream(Zones); //Creates the input stream
         prop.load(in); //loads the file contents of zones ("in" which references to the zones file) from the input stream.
         Stone = Integer.parseInteger(prop.getProperty("Stone")); //explained below
    
     in.close(); //Closes the input stream.
        }
     
        public void onDisable() {
            log.info("Doors Offline");
        }
    }
    Idears?
    The load is copied by the huge tutorial

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

    Crosant

    No idears?
     
  11. Offline

    Paah

    Scanning every player's position and comparing it to specific list of doors every time they move is quite resource expensive.
    May I suggest that opening doors cost money and they automatically close after few seconds, instead of the original idea?

    About the error:
    The plugin manager is unable to load your plugin. Do you have your plugin.yml set correctly?
    I also suggest you try to learn the stuff, instead of just copy/pasting from tutorial and then asking for someone else to repair it when it doesn't work.
     
  12. Offline

    Crosant

    :)
    I just wanted to test if the loading of a resurce from a propertys is like in the toturial.
     
Thread Status:
Not open for further replies.

Share This Page