[LIB] Tester - Create and administer multiple-choice tests for your plugins

Discussion in 'Resources' started by kaiser_czar, Jan 1, 2012.

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

    kaiser_czar

    What is it?
    This plugin is somewhat similar to the Questioner plugin used with Towny, except that Tester offers more than one question. Alone, it does nothing; you need other plugins to use it. Tester is designed not to be directly imported into your plugin; rather, it is a dependency similar to how Vault and Register work.

    How does it work?
    Basically, in your plugin, you can hook into Tester and tell it to administer a test to a player (will cover how that is done in a moment). That player will be given questions sequentially from a test you either created in your plugin or that is saved in the Tests.yml file that comes with Tester. Said player will be able to submit a numerical answer for each question. Tester will track responses to each answer; after the player has answered every question, Tester will send an event back to your plugin that contains all the info from the player's test. Specifically, correct or not for each individual question. Your plugin then decides what to do with the info. You could decide that you want to give the player a non-guest rank after they've completed a rules test, or you might want to give them some money for finishing an about-Minecraft test (don't judge me; I'm not that creative!).

    How do I hook into Tester? (we'll be looking at code to the TesterTest plugin I included)
    Firstly, be sure your plugin.yml has Tester marked as a dependency, and be sure to import Tester to your build path:
    Code:
    name: TesterTest
    main: net.moderncraft.kaiser_czar.testertest.TesterTest
    version: 0.01
    author: kaiser_czar
    depend: [Tester]
    commands:
      testertest:
        Description: Handles all the TesterTest commands.
        Usage: /testertest
      tt:
        Description: Alias to testertest.
        Usage: /tt
    Then, in your onEnable(), you need to grab the Tester plugin object:

    PHP:
    Tester tester = (TestergetServer().getPluginManager().getPlugin("Tester");
    if(
    tester == null){
        
    log.severe("You need Tester installed!");
        
    getServer().getPluginManager().disablePlugin(this);
    }
    If there's a better way to do this, I'm all ears!


    Now, this Tester object has some fun methods:

    PHP:
    public boolean administerTest(Player pTest tTesterListener listener); //Start the Test t for Player p, with results sent to TesterListener listener. Returns if successful.
    public Set<TesttestSet(); //Returns all registered Test's in Tester (registered as in, in the Tests.yml file)
    public Set<TestTakertestTakerSet(); //Returns all currently testing TestTakers.
    public boolean registerTest(Test t); //Add your own Test object to Tester's Tests.yml. Returns if successful.
    public boolean isTestTaker(Player p); //Tests whether a Player p is currently taking a test.
    public TestTaker getTestTaker(Player p); //Get the TestTaker object associated with Player p. Will return void if the player is not taking a test.


    You may notice you need a TesterListener object. TesterListener is an interface with one method:
    PHP:
    public void onTestComplete(TestCompleteEvent e);
    You need to implement this somewhere. The TestCompleteEvent has some fun methods for you:

    PHP:
    public Test getTest(); // Get the test completed
    public Player getPlayer(); //Get the Player
    public HashMap<IntegerBooleangetAnswers(); //The Integer value represents the question number; the boolean indicates a correct (true) or an incorrect (false) response.
    public double getPercentage(); //Returns the percentage correct in a value 0 <= percentage <= 1.

    Using that event, you can then decide what you want to do with the test. For more advanced topics, such as creating your own tests within you plugin, I recommend just decompiling Tester and checking it out yourself.

    Tests.yml setup:
    The Tests.yml file is what houses all the Tester registered tests. The default looks like so:
    Code:
    tests:
      Test1:
        Question1:
          CorrectAnswer: 1
          QuestionText: What is the name of the game you are playing?
          Answers:
            Answer1: Minecraft
            Answer2: Derp
        Question2:
          CorrectAnswer: 3
          QuestionText: What is 99 + 0?
          Answers:
            Answer1: '0'
            Answer2: Derp
            Answer3: '99'
    
    Tester will go in order of questions, and will also display answers in order. Any more tests can just be added on. Be sure not to allow tests: to be blank, or Tester will start throwing all sorts of NPEs.

    Command Documentation:
    All commands can be used with either /tester or /test.
    • /tester help - Lists all the commands ingame. Can also use /tester h.
    • /tester answer [#] - Answers your current question with answer number #. Can also use /tester a.
    • /tester repeat - Repeat the current question and answers. Can also use /tester r.
    • /tester reload - Reloads the Tests.yml file.
    For TesterTest, there's only one command. It's designed to give you the minimum you need to test Tester:
    • /testertest or /tt - Starts the default Test1 test. Will give you the results when you finish.
    Give me the damn files already!
    Here you go!

    Tester
    TesterTest

    Other stuff:
    I do hope I haven't forgotten to mention anything. Just ask here if I did. Also, if you want to see the source, I fully encourage you to decompile it and check it out. I can't claim to be a programming master, so I'd always welcome suggestions as how to improve. And, I look forward to seeing what people make with Tester!

    Following some comments from a friend, I will probably be adding support for non-multiple choice questions as well as multiple choice questions without a definite correct answer soon.

    Changelog:
    0.01: Initial Release
     
Thread Status:
Not open for further replies.

Share This Page