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);
}
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;
}
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;
}
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);
}
}
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);
}
Aggregations