Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.gmail.filoghost.touchscreen.command.subs;
- import com.gmail.filoghost.holographicdisplays.api.line.TextLine;
- import com.gmail.filoghost.holographicdisplays.object.NamedHologram;
- import com.gmail.filoghost.holographicdisplays.object.NamedHologramManager;
- import com.gmail.filoghost.touchscreen.Command;
- import com.gmail.filoghost.touchscreen.Database;
- import com.gmail.filoghost.touchscreen.TouchHologram;
- import com.gmail.filoghost.touchscreen.TouchManager;
- import com.gmail.filoghost.touchscreen.command.CommandValidator;
- import com.gmail.filoghost.touchscreen.command.TouchSubCommand;
- import com.gmail.filoghost.touchscreen.command.TouchSubCommand.SubCommandType;
- import com.gmail.filoghost.touchscreen.exception.CommandException;
- import com.gmail.filoghost.touchscreen.utils.Format;
- import com.gmail.filoghost.touchscreen.utils.StringUtils;
- import java.util.Arrays;
- import java.util.List;
- import org.bukkit.ChatColor;
- import org.bukkit.command.CommandSender;
- public class AddCommand
- extends TouchSubCommand
- {
- public AddCommand()
- {
- super("add", new String[] { "addcmd", "addcommand" });
- setPermission("touchscreenholograms.admin");
- }
- public String getPossibleArguments()
- {
- return "<hologram> <command>";
- }
- public int getMinimumArguments()
- {
- return 2;
- }
- public void execute(CommandSender sender, String[] args)
- throws CommandException
- {
- TouchHologram touch = TouchManager.getByName(args[0].toLowerCase());
- if (touch == null)
- {
- NamedHologram hologram = NamedHologramManager.getHologram(args[0]);
- CommandValidator.notNull(hologram, "There's no hologram with that name. The name is case sensitive.");
- touch = new TouchHologram(hologram.getName());
- TouchManager.add(touch);
- TouchManager.refreshAll();
- if (hologram.size() == 0)
- {
- Format.sendWarning(sender, "The hologram has no lines!");
- }
- else
- {
- if (hologram.size() > 1) {
- Format.sendWarning(sender, "You selected a hologram that contains more than one line: it's recommanded to use holograms with a single line, because the click wouldn't be detected correctly in the other lines.");
- }
- if (((hologram.getLine(0) instanceof TextLine)) && (((TextLine)hologram.getLine(0)).getText().length() > 6)) {
- Format.sendWarning(sender, "You selected a hologram with the first line longer than 6 chars. Since the holograms rotate (client side), you should reduce the length, because the click wouldn't be detected correctly.");
- }
- }
- }
- String command = StringUtils.join(args, " ", 1, args.length);
- if (command.startsWith("/")) {
- Format.sendWarning(sender, "You used a slash before the command, is that an error? For normal commands, do not include the slash.");
- }
- touch.getCommands().add(Command.fromString(command));
- Database.saveTouchHologram(touch);
- Database.trySaveToDisk();
- sender.sendMessage(ChatColor.GREEN + "Command added to the hologram!");
- }
- public List<String> getTutorial()
- {
- return Arrays.asList(new String[] { "Adds a command to a hologram." });
- }
- public TouchSubCommand.SubCommandType getType()
- {
- return TouchSubCommand.SubCommandType.NORMAL;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment