Search in sources :

Example 21 with MCPlayer

use of com.laytonsmith.abstraction.MCPlayer in project CommandHelper by EngineHub.

the class Static method SendMessage.

/**
 * This function sends a message to the player. If the player is not online, a CRE is thrown.
 *
 * @param m
 * @param msg
 */
public static void SendMessage(final MCCommandSender m, String msg, final Target t) {
    if (m != null && !(m instanceof MCConsoleCommandSender)) {
        if (m instanceof MCPlayer) {
            MCPlayer p = (MCPlayer) m;
            if (!p.isOnline()) {
                throw new CREPlayerOfflineException("The player " + p.getName() + " is not online", t);
            }
        }
        m.sendMessage(msg);
    } else {
        msg = Static.MCToANSIColors(msg);
        if (msg.contains("\033")) {
            // We have terminal colors, we need to reset them at the end
            msg += TermColors.reset();
        }
        StreamUtils.GetSystemOut().println(msg);
    }
}
Also used : CREPlayerOfflineException(com.laytonsmith.core.exceptions.CRE.CREPlayerOfflineException) MCPlayer(com.laytonsmith.abstraction.MCPlayer) MCConsoleCommandSender(com.laytonsmith.abstraction.MCConsoleCommandSender)

Aggregations

MCPlayer (com.laytonsmith.abstraction.MCPlayer)21 BukkitMCPlayer (com.laytonsmith.abstraction.bukkit.entities.BukkitMCPlayer)6 CommandHelperEnvironment (com.laytonsmith.core.environments.CommandHelperEnvironment)5 ConfigRuntimeException (com.laytonsmith.core.exceptions.ConfigRuntimeException)4 CString (com.laytonsmith.core.constructs.CString)3 GlobalEnv (com.laytonsmith.core.environments.GlobalEnv)3 CREPlayerOfflineException (com.laytonsmith.core.exceptions.CRE.CREPlayerOfflineException)3 ArrayList (java.util.ArrayList)3 Player (org.bukkit.entity.Player)3 EventHandler (org.bukkit.event.EventHandler)3 MCCommandSender (com.laytonsmith.abstraction.MCCommandSender)2 MCEntity (com.laytonsmith.abstraction.MCEntity)2 MCServer (com.laytonsmith.abstraction.MCServer)2 Environment (com.laytonsmith.core.environments.Environment)2 AbstractCREException (com.laytonsmith.core.exceptions.CRE.AbstractCREException)2 IOException (java.io.IOException)2 Method (java.lang.reflect.Method)2 MCCommand (com.laytonsmith.abstraction.MCCommand)1 MCConsoleCommandSender (com.laytonsmith.abstraction.MCConsoleCommandSender)1 MCItemStack (com.laytonsmith.abstraction.MCItemStack)1