Search in sources :

Example 1 with CRELengthException

use of com.laytonsmith.core.exceptions.CRE.CRELengthException in project CommandHelper by EngineHub.

the class Static method GetPlayer.

/**
 * Returns the player specified by name. Injected players also are returned in this list. If provided a string
 * between 1 and 16 characters, the lookup will be name-based. If provided a string that is 32 or 36 characters, the
 * lookup will be uuid-based.
 *
 * @param player
 * @param t
 * @return
 * @throws ConfigRuntimeException
 */
public static MCPlayer GetPlayer(String player, Target t) throws ConfigRuntimeException {
    MCCommandSender m;
    if (player == null) {
        throw new CREPlayerOfflineException("No player was specified!", t);
    }
    if (player.length() > 0 && player.length() <= 16) {
        m = GetCommandSender(player, t);
    } else {
        try {
            m = getServer().getPlayer(GetUUID(player, t));
        } catch (ConfigRuntimeException cre) {
            if (cre instanceof CRELengthException) {
                throw new CRELengthException("The given string was the wrong size to identify a player." + " A player name is expected to be between 1 and 16 characters. " + cre.getMessage(), t);
            } else {
                throw cre;
            }
        }
    }
    if (m == null) {
        throw new CREPlayerOfflineException("The specified player (" + player + ") is not online", t);
    }
    if (!(m instanceof MCPlayer)) {
        throw new CREPlayerOfflineException("Expecting a player name, but \"" + player + "\" was found.", t);
    }
    MCPlayer p = (MCPlayer) m;
    if (!p.isOnline()) {
        throw new CREPlayerOfflineException("The specified player (" + player + ") is not online", t);
    }
    return p;
}
Also used : CREPlayerOfflineException(com.laytonsmith.core.exceptions.CRE.CREPlayerOfflineException) CRELengthException(com.laytonsmith.core.exceptions.CRE.CRELengthException) MCPlayer(com.laytonsmith.abstraction.MCPlayer) ConfigRuntimeException(com.laytonsmith.core.exceptions.ConfigRuntimeException) MCCommandSender(com.laytonsmith.abstraction.MCCommandSender)

Aggregations

MCCommandSender (com.laytonsmith.abstraction.MCCommandSender)1 MCPlayer (com.laytonsmith.abstraction.MCPlayer)1 CRELengthException (com.laytonsmith.core.exceptions.CRE.CRELengthException)1 CREPlayerOfflineException (com.laytonsmith.core.exceptions.CRE.CREPlayerOfflineException)1 ConfigRuntimeException (com.laytonsmith.core.exceptions.ConfigRuntimeException)1