Search in sources :

Example 26 with CommandSender

use of org.bukkit.command.CommandSender in project MassiveCore by MassiveCraft.

the class EngineMassiveCoreDestination method destinationArg.

@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void destinationArg(EventMassiveCoreDestination event) {
    final String arg = event.getArg().toLowerCase();
    final CommandSender sender = event.getSender();
    try {
        Destination destination = destinationArg(arg, sender);
        if (destination == null)
            return;
        event.setDestination(destination);
    } catch (MassiveException e) {
        event.setException(e);
    } catch (Exception e) {
        event.setException(new MassiveException().addMsg("<b>%s", e.getMessage()));
    }
    event.setCancelled(true);
}
Also used : EventMassiveCoreDestination(com.massivecraft.massivecore.event.EventMassiveCoreDestination) Destination(com.massivecraft.massivecore.teleport.Destination) MassiveException(com.massivecraft.massivecore.MassiveException) CommandSender(org.bukkit.command.CommandSender) MassiveException(com.massivecraft.massivecore.MassiveException) EventHandler(org.bukkit.event.EventHandler)

Example 27 with CommandSender

use of org.bukkit.command.CommandSender 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 28 with CommandSender

use of org.bukkit.command.CommandSender 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)

Example 29 with CommandSender

use of org.bukkit.command.CommandSender in project MassiveCore by MassiveCraft.

the class CleaningUtil method considerClean.

public static void considerClean(long now, final Coll<?> coll, final Iterable<CommandSender> recipients) {
    final long start = System.nanoTime();
    int count = 0;
    final Collection<? extends Entity<?>> entities = coll.getAll();
    // For each entity ...
    for (Entity<?> entity : entities) {
        // ... see if they should be cleaned.
        boolean result = considerClean(now, entity);
        if (result)
            count++;
    }
    long nano = System.nanoTime() - start;
    int current = coll.getIds().size();
    int total = current + count;
    double percentage = (((double) count) / total) * 100D;
    if (!MUtil.isFinite(percentage))
        percentage = 0D;
    String message = Txt.parse("<i>Removed <h>%d<i>/<h>%d (%.2f%%) <i>entities from <h>%s <i>took <v>%.2fms<i>.", count, total, percentage, coll.getName(), nano / 1000D);
    for (CommandSender recipient : recipients) {
        MixinMessage.get().messageOne(recipient, message);
    }
}
Also used : CommandSender(org.bukkit.command.CommandSender)

Example 30 with CommandSender

use of org.bukkit.command.CommandSender in project MassiveCore by MassiveCraft.

the class ExtractorLogic method senderNameFromObject.

// -------------------------------------------- //
// SENDER NAME
// -------------------------------------------- //
public static String senderNameFromObject(Object o) {
    if (o == null)
        return null;
    String name = IdUtil.getName(o);
    if (name != null)
        return name;
    CommandSender sender = senderFromObject(o);
    if (sender == null)
        return null;
    return IdUtil.getName(sender);
}
Also used : CommandSender(org.bukkit.command.CommandSender)

Aggregations

CommandSender (org.bukkit.command.CommandSender)295 Test (org.junit.Test)171 Player (org.bukkit.entity.Player)94 Matchers.containsString (org.hamcrest.Matchers.containsString)68 ConsoleCommandSender (org.bukkit.command.ConsoleCommandSender)50 CoreStateInitException (com.solinia.solinia.Exceptions.CoreStateInitException)43 PlayerAuth (fr.xephi.authme.data.auth.PlayerAuth)30 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)29 PermissionNode (fr.xephi.authme.permission.PermissionNode)17 BlockCommandSender (org.bukkit.command.BlockCommandSender)16 ValidationResult (fr.xephi.authme.service.ValidationService.ValidationResult)12 Location (org.bukkit.Location)10 HashedPassword (fr.xephi.authme.security.crypts.HashedPassword)9 ArrayList (java.util.ArrayList)9 List (java.util.List)9 FoundCommandResult (fr.xephi.authme.command.FoundCommandResult)8 IOException (java.io.IOException)7 Entity (org.bukkit.entity.Entity)7 IEssentialsCommand (com.earth2me.essentials.commands.IEssentialsCommand)6 NoChargeException (com.earth2me.essentials.commands.NoChargeException)6