use of org.bukkit.command.ConsoleCommandSender in project AuthMeReloaded by AuthMe.
the class BukkitServiceTest method shouldDispatchConsoleCommand.
@Test
public void shouldDispatchConsoleCommand() {
// given
ConsoleCommandSender consoleSender = mock(ConsoleCommandSender.class);
given(server.getConsoleSender()).willReturn(consoleSender);
String command = "my command";
// when
bukkitService.dispatchConsoleCommand(command);
// then
verify(server).dispatchCommand(consoleSender, command);
}
use of org.bukkit.command.ConsoleCommandSender in project EliteMobs by MagmaGuy.
the class StatsCommandHandler method statsHandler.
public void statsHandler(CommandSender commandSender) {
int mobLevelSavingsCount = 0;
int totalMobCount = 0;
int aggressiveCount = 0;
int passiveCount = 0;
int blazeCount = 0;
int caveSpiderCount = 0;
int creeperCount = 0;
int endermanCount = 0;
int endermiteCount = 0;
int huskCount = 0;
int ironGolemCount = 0;
int pigZombieCount = 0;
int polarBearCount = 0;
int silverfishCount = 0;
int skeletonCount = 0;
int spiderCount = 0;
int strayCount = 0;
int witchCount = 0;
int witherSkeletonCount = 0;
int zombieCount = 0;
int zombieVillagerCount = 0;
int chickenCount = 0;
int cowCount = 0;
int mushroomCowCount = 0;
int pigCount = 0;
int sheepCount = 0;
for (World world : worldList) {
for (LivingEntity livingEntity : world.getLivingEntities()) {
if (livingEntity.hasMetadata(MetadataHandler.ELITE_MOB_MD) || livingEntity.hasMetadata(MetadataHandler.PASSIVE_ELITE_MOB_MD)) {
totalMobCount++;
if (livingEntity.hasMetadata(MetadataHandler.ELITE_MOB_MD)) {
mobLevelSavingsCount += livingEntity.getMetadata(MetadataHandler.ELITE_MOB_MD).get(0).asInt();
aggressiveCount++;
switch(livingEntity.getType()) {
case ZOMBIE:
zombieCount++;
break;
case HUSK:
huskCount++;
break;
case ZOMBIE_VILLAGER:
zombieVillagerCount++;
break;
case SKELETON:
skeletonCount++;
break;
case WITHER_SKELETON:
witherSkeletonCount++;
break;
case STRAY:
strayCount++;
break;
case PIG_ZOMBIE:
pigZombieCount++;
break;
case CREEPER:
creeperCount++;
break;
case SPIDER:
spiderCount++;
break;
case ENDERMAN:
endermanCount++;
break;
case CAVE_SPIDER:
caveSpiderCount++;
break;
case SILVERFISH:
silverfishCount++;
break;
case BLAZE:
blazeCount++;
break;
case WITCH:
witchCount++;
break;
case ENDERMITE:
endermiteCount++;
break;
case POLAR_BEAR:
polarBearCount++;
break;
case IRON_GOLEM:
ironGolemCount++;
break;
default:
getLogger().info("Error: Couldn't assign custom mob name due to unexpected aggressive boss mob (talk to the dev!)");
getLogger().info("Missing mob type: " + livingEntity.getType());
break;
}
} else if (livingEntity.hasMetadata(MetadataHandler.PASSIVE_ELITE_MOB_MD)) {
//passive EliteMobs only stack at 50 right now
//TODO: redo this count at some other stage of this plugin's development
mobLevelSavingsCount += ConfigValues.defaultConfig.getInt("Passive EliteMob stack amount");
passiveCount++;
switch(livingEntity.getType()) {
case CHICKEN:
chickenCount++;
break;
case COW:
cowCount++;
break;
case MUSHROOM_COW:
mushroomCowCount++;
break;
case PIG:
pigCount++;
break;
case SHEEP:
sheepCount++;
break;
default:
getLogger().info("Error: Couldn't assign custom mob name due to unexpected passive boss mob (talk to the dev!)");
getLogger().info("Missing mob type: " + livingEntity.getType());
break;
}
}
}
}
}
if (commandSender instanceof Player) {
Player player = (Player) commandSender;
player.sendMessage("§5§m-----------------------------------------------------");
player.sendMessage("§a§lEliteMobs stats:");
player.sendMessage("There are currently §l§6" + totalMobCount + " §f§rEliteMobs replacing §l§e" + mobLevelSavingsCount + " §f§rregular mobs.");
if (aggressiveCount > 0) {
String aggressiveCountMessage = "§c" + aggressiveCount + " §4Aggressive EliteMobs: §f";
HashMap unsortedMobCount = new HashMap();
unsortedMobCountFilter(unsortedMobCount, blazeCount, "blazes");
unsortedMobCountFilter(unsortedMobCount, caveSpiderCount, "cave spiders");
unsortedMobCountFilter(unsortedMobCount, creeperCount, "creepers");
unsortedMobCountFilter(unsortedMobCount, endermanCount, "endermen");
unsortedMobCountFilter(unsortedMobCount, endermiteCount, "endermites");
unsortedMobCountFilter(unsortedMobCount, huskCount, "husks");
unsortedMobCountFilter(unsortedMobCount, pigZombieCount, "zombiepigmen");
unsortedMobCountFilter(unsortedMobCount, polarBearCount, "polar bears");
unsortedMobCountFilter(unsortedMobCount, silverfishCount, "silverfish");
unsortedMobCountFilter(unsortedMobCount, skeletonCount, "skeletons");
unsortedMobCountFilter(unsortedMobCount, spiderCount, "spiders");
unsortedMobCountFilter(unsortedMobCount, strayCount, "strays");
unsortedMobCountFilter(unsortedMobCount, witchCount, "witches");
unsortedMobCountFilter(unsortedMobCount, witherSkeletonCount, "wither skeletons");
unsortedMobCountFilter(unsortedMobCount, zombieCount, "zombie");
unsortedMobCountFilter(unsortedMobCount, zombieVillagerCount, "zombie villagers");
player.sendMessage(messageStringAppender(aggressiveCountMessage, unsortedMobCount));
}
if (passiveCount > 0) {
String passiveCountMessage = "§b" + passiveCount + " §3Passive EliteMobs: §f";
HashMap unsortedMobCount = new HashMap();
unsortedMobCountFilter(unsortedMobCount, chickenCount, "chickens");
unsortedMobCountFilter(unsortedMobCount, cowCount, "cows");
unsortedMobCountFilter(unsortedMobCount, ironGolemCount, "iron golems");
unsortedMobCountFilter(unsortedMobCount, mushroomCowCount, "mushroom cows");
unsortedMobCountFilter(unsortedMobCount, pigCount, "pigs");
unsortedMobCountFilter(unsortedMobCount, sheepCount, "sheep");
player.sendMessage(messageStringAppender(passiveCountMessage, unsortedMobCount));
}
player.sendMessage("§5§m-----------------------------------------------------");
} else if (commandSender instanceof ConsoleCommandSender) {
getServer().getConsoleSender().sendMessage("§5§m-------------------------------------------------------------");
getServer().getConsoleSender().sendMessage("§a§lEliteMobs stats:");
getServer().getConsoleSender().sendMessage("There are currently §l§6" + totalMobCount + " §f§rEliteMobs replacing §l§e" + mobLevelSavingsCount + " §f§rregular mobs.");
if (aggressiveCount > 0) {
String aggressiveCountMessage = "§c" + aggressiveCount + " §4Aggressive EliteMobs: §f";
HashMap unsortedMobCount = new HashMap();
unsortedMobCountFilter(unsortedMobCount, blazeCount, "blazes");
unsortedMobCountFilter(unsortedMobCount, caveSpiderCount, "cave spiders");
unsortedMobCountFilter(unsortedMobCount, creeperCount, "creepers");
unsortedMobCountFilter(unsortedMobCount, endermanCount, "endermen");
unsortedMobCountFilter(unsortedMobCount, endermiteCount, "endermites");
unsortedMobCountFilter(unsortedMobCount, huskCount, "husks");
unsortedMobCountFilter(unsortedMobCount, ironGolemCount, "iron golems");
unsortedMobCountFilter(unsortedMobCount, pigZombieCount, "zombiepigmen");
unsortedMobCountFilter(unsortedMobCount, polarBearCount, "polar bears");
unsortedMobCountFilter(unsortedMobCount, silverfishCount, "silverfish");
unsortedMobCountFilter(unsortedMobCount, skeletonCount, "skeletons");
unsortedMobCountFilter(unsortedMobCount, spiderCount, "spiders");
unsortedMobCountFilter(unsortedMobCount, strayCount, "strays");
unsortedMobCountFilter(unsortedMobCount, witchCount, "witches");
unsortedMobCountFilter(unsortedMobCount, witherSkeletonCount, "wither skeletons");
unsortedMobCountFilter(unsortedMobCount, zombieCount, "zombie");
unsortedMobCountFilter(unsortedMobCount, zombieVillagerCount, "zombie villagers");
getServer().getConsoleSender().sendMessage(messageStringAppender(aggressiveCountMessage, unsortedMobCount));
}
if (passiveCount > 0) {
String passiveCountMessage = "§b" + passiveCount + " §3Passive EliteMobs: §f";
HashMap unsortedMobCount = new HashMap();
unsortedMobCountFilter(unsortedMobCount, chickenCount, "chickens");
unsortedMobCountFilter(unsortedMobCount, cowCount, "cows");
unsortedMobCountFilter(unsortedMobCount, mushroomCowCount, "mushroom cows");
unsortedMobCountFilter(unsortedMobCount, pigCount, "pigs");
unsortedMobCountFilter(unsortedMobCount, sheepCount, "sheep");
getServer().getConsoleSender().sendMessage(messageStringAppender(passiveCountMessage, unsortedMobCount));
}
getServer().getConsoleSender().sendMessage("§5§m-------------------------------------------------------------");
}
}
use of org.bukkit.command.ConsoleCommandSender in project EliteMobs by MagmaGuy.
the class CommandHandler method validCommands.
private void validCommands(CommandSender commandSender) {
if (commandSender instanceof Player) {
Player player = (Player) commandSender;
player.sendMessage("Valid commands:");
player.sendMessage("/elitemobs stats");
player.sendMessage("/elitemobs reload configs");
player.sendMessage("/elitemobs reload loot");
player.sendMessage("/elitemobs getloot (alone to get GUI)");
player.sendMessage("/elitemobs getloot [loot name]");
player.sendMessage("/elitemobs giveloot [player name] random/[loot_name_underscore_for_spaces]");
player.sendMessage("/elitemobs SpawnMob [mobType] [mobLevel] [mobPower] [mobPower2(keep adding as many as you'd like)]");
} else if (commandSender instanceof ConsoleCommandSender) {
getLogger().info("Command not recognized. Valid commands:");
getLogger().info("elitemobs stats");
getLogger().info("elitemobs reload configs");
getLogger().info("elitemobs reload loot");
getLogger().info("elitemobs giveloot [player name] random/[loot_name_underscore_for_spaces]");
getLogger().info("elitemobs SpawnMob [worldName] [x] [y] [z] [mobType] [mobLevel] [mobPower] [mobPower2(keep adding as many as you'd like)]");
}
}
use of org.bukkit.command.ConsoleCommandSender in project Bukkit by Bukkit.
the class HelpCommand method execute.
@Override
public boolean execute(CommandSender sender, String currentAlias, String[] args) {
if (!testPermission(sender))
return true;
String command;
int pageNumber;
int pageHeight;
int pageWidth;
if (args.length == 0) {
command = "";
pageNumber = 1;
} else if (NumberUtils.isDigits(args[args.length - 1])) {
command = StringUtils.join(ArrayUtils.subarray(args, 0, args.length - 1), " ");
try {
pageNumber = NumberUtils.createInteger(args[args.length - 1]);
} catch (NumberFormatException exception) {
pageNumber = 1;
}
if (pageNumber <= 0) {
pageNumber = 1;
}
} else {
command = StringUtils.join(args, " ");
pageNumber = 1;
}
if (sender instanceof ConsoleCommandSender) {
pageHeight = ChatPaginator.UNBOUNDED_PAGE_HEIGHT;
pageWidth = ChatPaginator.UNBOUNDED_PAGE_WIDTH;
} else {
pageHeight = ChatPaginator.CLOSED_CHAT_PAGE_HEIGHT - 1;
pageWidth = ChatPaginator.GUARANTEED_NO_WRAP_CHAT_PAGE_WIDTH;
}
HelpMap helpMap = Bukkit.getServer().getHelpMap();
HelpTopic topic = helpMap.getHelpTopic(command);
if (topic == null) {
topic = helpMap.getHelpTopic("/" + command);
}
if (topic == null) {
topic = findPossibleMatches(command);
}
if (topic == null || !topic.canSee(sender)) {
sender.sendMessage(ChatColor.RED + "No help for " + command);
return true;
}
ChatPaginator.ChatPage page = ChatPaginator.paginate(topic.getFullText(sender), pageNumber, pageWidth, pageHeight);
StringBuilder header = new StringBuilder();
header.append(ChatColor.YELLOW);
header.append("--------- ");
header.append(ChatColor.WHITE);
header.append("Help: ");
header.append(topic.getName());
header.append(" ");
if (page.getTotalPages() > 1) {
header.append("(");
header.append(page.getPageNumber());
header.append("/");
header.append(page.getTotalPages());
header.append(") ");
}
header.append(ChatColor.YELLOW);
for (int i = header.length(); i < ChatPaginator.GUARANTEED_NO_WRAP_CHAT_PAGE_WIDTH; i++) {
header.append("-");
}
sender.sendMessage(header.toString());
sender.sendMessage(page.getLines());
return true;
}
use of org.bukkit.command.ConsoleCommandSender in project Denizen-For-Bukkit by DenizenScript.
the class CommandManager method executeMethod.
// Attempt to execute a command.
private void executeMethod(String[] args, CommandSender sender, Object[] methodArgs) throws CommandException {
String cmdName = CoreUtilities.toLowerCase(args[0]);
String modifier = args.length > 1 ? args[1] : "";
boolean help = CoreUtilities.toLowerCase(modifier).equals("help");
Method method = commands.get(cmdName + " " + CoreUtilities.toLowerCase(modifier));
if (method == null && !help) {
method = commands.get(cmdName + " *");
}
if (method == null && help) {
executeHelp(args, sender);
return;
}
if (method == null) {
throw new UnhandledCommandException();
}
if (!serverCommands.contains(method) && sender instanceof ConsoleCommandSender) {
throw new ServerCommandException();
}
if (!hasPermission(method, sender)) {
throw new NoPermissionsException();
}
Command cmd = method.getAnnotation(Command.class);
CommandContext context = new CommandContext(sender, args);
if (context.argsLength() < cmd.min()) {
throw new CommandUsageException("Too few arguments.", getUsage(args, cmd));
}
if (cmd.max() != -1 && context.argsLength() > cmd.max()) {
throw new CommandUsageException("Too many arguments.", getUsage(args, cmd));
}
if (!cmd.flags().contains("*")) {
for (char flag : context.getFlags()) {
if (cmd.flags().indexOf(String.valueOf(flag)) == -1) {
throw new CommandUsageException("Unknown flag: " + flag, getUsage(args, cmd));
}
}
}
methodArgs[0] = context;
for (Annotation annotation : registeredAnnotations.get(method)) {
CommandAnnotationProcessor processor = annotationProcessors.get(annotation.annotationType());
processor.process(sender, context, annotation, methodArgs);
}
Object instance = instances.get(method);
try {
method.invoke(instance, methodArgs);
} catch (IllegalArgumentException e) {
dB.echoError(e);
} catch (IllegalAccessException e) {
dB.echoError(e);
} catch (InvocationTargetException e) {
if (e.getCause() instanceof CommandException) {
throw (CommandException) e.getCause();
}
throw new WrappedCommandException(e.getCause());
}
}
Aggregations