001package net.tnemc.plugincore.core.compatibility;
002
003/*
004 * The New Plugin Core
005 * Copyright (C) 2022 - 2024 Daniel "creatorfromhell" Vidmar
006 *
007 * This program is free software: you can redistribute it and/or modify
008 * it under the terms of the GNU Affero General Public License as published by
009 * the Free Software Foundation, either version 3 of the License, or
010 * (at your option) any later version.
011 *
012 * This program is distributed in the hope that it will be useful,
013 * but WITHOUT ANY WARRANTY; without even the implied warranty of
014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
015 * GNU Affero General Public License for more details.
016 *
017 * You should have received a copy of the GNU Affero General Public License
018 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
019 */
020
021import net.tnemc.plugincore.core.io.message.MessageData;
022import revxrsal.commands.command.CommandActor;
023
024import java.util.Optional;
025import java.util.UUID;
026
027/**
028 * CmdSource
029 *
030 * @author creatorfromhell
031 * @since 0.1.2.0
032 * @see PlayerProvider
033 */
034public abstract class CmdSource<T extends CommandActor> {
035
036  protected final T actor;
037
038  public CmdSource(final T actor) {
039    this.actor = actor;
040  }
041
042  /**
043   * The UUID of this command source.
044   * @return The UUID of this command source.
045   */
046  public Optional<UUID> identifier() {
047    if(!isPlayer()) {
048      return Optional.empty();
049    }
050    return Optional.of(actor.uniqueId());
051  }
052
053  /**
054   * The name of this command source.
055   * @return The name of this command source.
056   */
057  public String name() {
058    return actor.name();
059  }
060
061  /**
062   * Determines if this {@link CmdSource} is an instance of a player.
063   * @return True if this represents a player, otherwise false if it's a non-player such as the console.
064   */
065  public abstract boolean isPlayer();
066
067  /**
068   * Used to get the related {@link PlayerProvider} for this command source.
069   * @return An optional containing the related {@link PlayerProvider} if this command source is a
070   * player, otherwise an empty {@link Optional}.
071   */
072  public abstract Optional<PlayerProvider> player();
073
074  /**
075   * Used to send a message to this command source.
076   * @param messageData The message data to utilize for this translation.
077   */
078  public abstract void message(final MessageData messageData);
079
080  public T getActor() {
081    return actor;
082  }
083}