Search in sources :

Example 1 with SenderEntity

use of com.massivecraft.massivecore.store.SenderEntity in project MassiveCore by MassiveCraft.

the class IdUtil method getUuid.

public static UUID getUuid(Object senderObject) {
    // Null Return
    if (senderObject == null)
        return null;
    // Already Done
    if (senderObject instanceof UUID)
        return (UUID) senderObject;
    // Console Type
    if (senderObject instanceof ConsoleCommandSender)
        return null;
    // Console Id/Name
    if (CONSOLE_ID.equals(senderObject))
        return null;
    // SenderEntity Recurse
    if (senderObject instanceof SenderEntity<?>) {
        SenderEntity<?> senderEntity = (SenderEntity<?>) senderObject;
        return getUuid(senderEntity.getId());
    }
    // Player
    if (senderObject instanceof Player)
        return ((Player) senderObject).getUniqueId();
    // CommandSender
    if (senderObject instanceof CommandSender) {
        CommandSender sender = (CommandSender) senderObject;
        String id = sender.getName();
        return MUtil.asUuid(id);
    }
    // String
    if (senderObject instanceof String) {
        // Is UUID
        String string = (String) senderObject;
        UUID uuid = MUtil.asUuid(string);
        if (uuid != null)
            return uuid;
    // Is Name
    // Handled at "Data"
    }
    // Data
    IdData data = getData(senderObject);
    if (data != null) {
        String id = data.getId();
        if (id == null)
            return null;
        UUID uuid = MUtil.asUuid(id);
        return uuid;
    }
    // Return Null
    return null;
}
Also used : Player(org.bukkit.entity.Player) SenderEntity(com.massivecraft.massivecore.store.SenderEntity) ConsoleCommandSender(org.bukkit.command.ConsoleCommandSender) CommandSender(org.bukkit.command.CommandSender) UUID(java.util.UUID) ConsoleCommandSender(org.bukkit.command.ConsoleCommandSender)

Example 2 with SenderEntity

use of com.massivecraft.massivecore.store.SenderEntity in project MassiveCore by MassiveCraft.

the class IdUtil method getSender.

public static CommandSender getSender(Object senderObject) {
    // Null Return
    if (senderObject == null)
        return null;
    // Already Done
    if (senderObject instanceof CommandSender)
        return (CommandSender) senderObject;
    // Console Id/Name
    if (CONSOLE_ID.equals(senderObject))
        return getConsole();
    // SenderEntity Recurse
    if (senderObject instanceof SenderEntity<?>) {
        SenderEntity<?> senderEntity = (SenderEntity<?>) senderObject;
        return getSender(senderEntity.getId());
    }
    // UUID
    if (senderObject instanceof UUID) {
        // Attempt finding player
        UUID uuid = (UUID) senderObject;
        Player player = Bukkit.getPlayer(uuid);
        if (player != null)
            return player;
        // Otherwise assume registered sender
        return registryIdToSender.get(uuid.toString());
    }
    // String
    if (senderObject instanceof String) {
        // Recurse as UUID
        String string = (String) senderObject;
        UUID uuid = MUtil.asUuid(string);
        if (uuid != null)
            return getSender(uuid);
        // Registry
        CommandSender sender = registryIdToSender.get(string);
        if (sender != null)
            return sender;
        // Bukkit API
        return Bukkit.getPlayerExact(string);
    }
    // Return Null
    return null;
}
Also used : Player(org.bukkit.entity.Player) SenderEntity(com.massivecraft.massivecore.store.SenderEntity) ConsoleCommandSender(org.bukkit.command.ConsoleCommandSender) CommandSender(org.bukkit.command.CommandSender) UUID(java.util.UUID)

Aggregations

SenderEntity (com.massivecraft.massivecore.store.SenderEntity)2 UUID (java.util.UUID)2 CommandSender (org.bukkit.command.CommandSender)2 ConsoleCommandSender (org.bukkit.command.ConsoleCommandSender)2 Player (org.bukkit.entity.Player)2