com.gmail.gkovalechyn.automaticevents.cmds.Info.java Source code

Java tutorial

Introduction

Here is the source code for com.gmail.gkovalechyn.automaticevents.cmds.Info.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.gmail.gkovalechyn.automaticevents.cmds;

import com.gmail.gkovalechyn.automaticevents.AutomaticEvents;
import com.gmail.gkovalechyn.automaticevents.MessageHandler;
import com.gmail.gkovalechyn.automaticevents.events.Event;
import com.gmail.gkovalechyn.automaticevents.events.Objective;
import com.gmail.gkovalechyn.automaticevents.parsing.Variable;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang.StringUtils;
import org.bukkit.command.CommandSender;

/**
 *
 * @author Gabriel K
 */
public class Info {
    //ae info Event
    public static boolean command(AutomaticEvents plugin, CommandSender sender, String[] args) {
        if (args.length < 2) {
            plugin.mh.displayCommandUsage(sender, MessageHandler.Message.CMD_INFO);
            return true;
        } else {
            Event evt = plugin.manager.getEvent(args[1]);
            if (evt != null) {
                Map<String, Variable> vars = evt.getVariables();
                List<Objective> o = evt.getObjectives();
                sender.sendMessage("Open: " + plugin.manager.isEventOpen(args[1]));
                sender.sendMessage("Running: " + evt.isRunning());
                sender.sendMessage("Broken: " + evt.isBroken());
                sender.sendMessage("Event file: " + evt.getYamlFileName());
                sender.sendMessage("Objectives: ");

                for (Objective obj : o) {
                    sender.sendMessage("- " + obj.getName());
                }

                sender.sendMessage("Variables: ");

                for (Map.Entry<String, Variable> entry : vars.entrySet()) {
                    sender.sendMessage(
                            "- " + entry.getKey() + ": " + StringUtils.join(entry.getValue().toArgs(), " "));
                }

                return true;
            } else {
                sender.sendMessage("That event does not exist.");
                return true;
            }
        }
    }
}