All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.plotsquared.core.command.Argument Maven / Gradle / Ivy

There is a newer version: 6.11.2
Show newest version
/*
 *       _____  _       _    _____                                _
 *      |  __ \| |     | |  / ____|                              | |
 *      | |__) | | ___ | |_| (___   __ _ _   _  __ _ _ __ ___  __| |
 *      |  ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
 *      | |    | | (_) | |_ ____) | (_| | |_| | (_| | | |  __/ (_| |
 *      |_|    |_|\___/ \__|_____/ \__, |\__,_|\__,_|_|  \___|\__,_|
 *                                    | |
 *                                    |_|
 *            PlotSquared plot management system for Minecraft
 *               Copyright (C) 2014 - 2022 IntellectualSites
 *
 *     This program is free software: you can redistribute it and/or modify
 *     it under the terms of the GNU General Public License as published by
 *     the Free Software Foundation, either version 3 of the License, or
 *     (at your option) any later version.
 *
 *     This program is distributed in the hope that it will be useful,
 *     but WITHOUT ANY WARRANTY; without even the implied warranty of
 *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *     GNU General Public License for more details.
 *
 *     You should have received a copy of the GNU General Public License
 *     along with this program.  If not, see .
 */
package com.plotsquared.core.command;

import com.plotsquared.core.plot.PlotId;

public abstract class Argument {

    public static final Argument Integer = new Argument<>("int", 16) {
        @Override
        public Integer parse(String in) {
            Integer value = null;
            try {
                value = java.lang.Integer.parseInt(in);
            } catch (Exception ignored) {
            }
            return value;
        }
    };
    public static final Argument Boolean = new Argument<>("boolean", true) {
        @Override
        public Boolean parse(String in) {
            Boolean value = null;
            if (in.equalsIgnoreCase("true") || in.equalsIgnoreCase("Yes") || in
                    .equalsIgnoreCase("1")) {
                value = true;
            } else if (in.equalsIgnoreCase("false") || in.equalsIgnoreCase("No") || in
                    .equalsIgnoreCase("0")) {
                value = false;
            }
            return value;
        }
    };
    public static final Argument String = new Argument<>("String", "Example") {
        @Override
        public String parse(String in) {
            return in;
        }
    };
    public static final Argument PlayerName =
            new Argument<>("PlayerName", "") {
                @Override
                public String parse(String in) {
                    return in.length() <= 16 ? in : null;
                }
            };
    public static final Argument PlotID =
            new Argument<>("PlotID", PlotId.of(-6, 3)) {
                @Override
                public PlotId parse(String in) {
                    return PlotId.fromString(in);
                }
            };
    private final String name;
    private final T example;

    public Argument(String name, T example) {
        this.name = name;
        this.example = example;
    }

    public abstract T parse(String in);

    @Override
    public final String toString() {
        return this.getName();
    }

    public final String getName() {
        return this.name;
    }

    public final T getExample() {
        return this.example;
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy