Check argument types

Discussion in 'Plugin Development' started by Molten, Jan 9, 2014.

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

    Molten

    I'm trying to make a plugin that takes a lot of different arguments of different types but I don't know how to check to see if they are valid types with what I need.

    Here is the code I have for my type that I need, but I don't know how to do the argument checks other than String.


    This is the data type that I'm using.
    Code:java
    1. package com.gmail.betorages.drawbridge;
    2.  
    3. public class DrawBridges {
    4. private double[] coordinates;
    5. private String name;
    6. private int length;
    7. private int width;
    8. private String direction;
    9. private int blockID;
    10.  
    11. public void DrawBridges(String name, double[] coordinates, int length, int width, String direction, int blockID){
    12. this.coordinates = coordinates;
    13. this.name = name;
    14. this.length = length;
    15. this.width = width;
    16. this.direction = direction;
    17. this.blockID = blockID;
    18. }
    19. }
    20.  



    And here is the command where I try and parse to see if they are the correct types before sending them through.
    Code:java
    1. @Override
    2. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    3. boolean create = false;
    4. if (args.length == 2) {
    5. sender.sendMessage("Deleting Drawbridge.");
    6.  
    7. return true;
    8. }
    9. else if(args.length == 6){
    10. sender.sendMessage("Creating Drawbridge.");
    11. if (args[0] instanceof String){
    12. if(args[1] )
    13. }
    14. }
    15.  
    16. return false;
    17. }
    18.  
    19.  
    20. //Below is where it's sending, so you know what types I need in case that helps.
    21. public void create(String sender, String name, double[] coordinates, int length, int width, String direction, int blockID)
     
  2. Offline

    nuclearmissile

    You could possibly just skip checking if they're the right data types, but you won't get to put a custom message when the player messes it up, it'll just say An error has occurred. Also, console might get error spammed.
     
Thread Status:
Not open for further replies.

Share This Page