Java Code Examples for org.bukkit.ChatColor

The following code examples are extracted from open source projects. You can click to vote up the examples that are useful to you.

Example 1

From project AntiCheat, under directory /src/main/java/net/h31ix/anticheat/xray/.

Source file: XRayTracker.java

  22 
vote

public void calculate(CommandSender cs,String player,double x,double b,String type){
  ChatColor color=WHITE;
  if (x >= b / RATIO_DIVISOR) {
    color=RED;
  }
  cs.sendMessage(GRAY + "Percent " + type+ " ore: "+ color+ round(x)+ "%");
}
 

Example 2

From project BanHammer, under directory /src/main/java/name/richardson/james/bukkit/banhammer/ban/.

Source file: LimitsCommand.java

  22 
vote

public void execute(final CommandSender sender) throws CommandArgumentException, CommandPermissionException, CommandUsageException {
  sender.sendMessage(this.formatter.getMessage());
  for (  final Entry<String,Long> limit : limits.entrySet()) {
    ChatColor colour;
    if (sender.hasPermission("banhammer.ban." + limit.getKey())) {
      colour=ChatColor.GREEN;
    }
 else {
      colour=ChatColor.RED;
    }
    sender.sendMessage(colour + this.getLocalisation().getMessage(this,"list-item",limit.getKey(),TimeFormatter.millisToLongDHMS(limit.getValue())));
  }
}
 

Example 3

From project Buildr, under directory /src/me/simplex/buildr/util/.

Source file: Buildr_Manager_Command_Super.java

  21 
vote

private static String BuildMsg(MsgType type,String msg){
  String PREFIX="[Buildr] ";
  ChatColor MsgColor=ChatColor.WHITE;
switch (type) {
case INFO:
    MsgColor=ChatColor.WHITE;
  break;
case WARNING:
MsgColor=ChatColor.YELLOW;
break;
case ERROR:
MsgColor=ChatColor.RED;
break;
default :
break;
}
return ChatColor.BLUE + PREFIX + MsgColor+ msg;
}
 

Example 4

From project Catacombs, under directory /src/net/steeleyes/catacombs/.

Source file: Monsters.java

  21 
vote

public void playerHeals(CatConfig cnf,Player healer,Player healee){
  if (!healee.isDead()) {
    WildResp resp=isWild(healer,HEAL_PLAYER,null);
    if (!resp.wild) {
      int health=healee.getHealth();
      if (health < 20) {
        CatUtils.improveDurability(healer,2);
        healee.setHealth(Math.min(20,health + 2));
        healee.sendMessage(healer.getName() + " heals you");
        splashThreat(healee,healer,0,10,5,2);
        ChatColor col=(resp.delta - HEAL_PLAYER > 500) ? ChatColor.YELLOW : ChatColor.GREEN;
        healer.sendMessage(String.format(col + "%.3f" + ChatColor.WHITE+ " %.1f %s(%d%%)",(float)resp.delta / 1000.0,(float)HEAL_PLAYER / 1000.0,healee.getName(),(healee.getHealth() * 5)));
      }
 else {
        CatUtils.improveDurability(healer,3);
        healer.sendMessage(healee.getName() + " is on full health");
      }
    }
 else {
      CatUtils.improveDurability(healer,2);
      healer.sendMessage(String.format(ChatColor.RED + "%.3f" + ChatColor.DARK_GRAY+ " %.1f WILD %s(%d%%)"+ ChatColor.WHITE,(float)resp.delta / 1000.0,(float)HEAL_PLAYER / 1000.0,healee.getName(),(healee.getHealth() * 5)));
    }
  }
}
 

Example 5

From project Citizens, under directory /src/core/net/citizensnpcs/resources/npclib/.

Source file: NPCManager.java

  21 
vote

public static void register(int UID,String owner,NPCCreateReason reason){
  Location loc=PropertyManager.getBasic().getLocation(UID);
  ChatColor colour=PropertyManager.getBasic().getColour(UID);
  String name=PropertyManager.getBasic().getName(UID);
  name=ChatColor.stripColor(name);
  if (!Settings.getString("SpaceChar").isEmpty()) {
    name=name.replace(Settings.getString("SpaceChar")," ");
  }
  String npcName=name;
  if (colour != null && colour != ChatColor.WHITE) {
    npcName=colour + name;
  }
  HumanNPC npc=NPCSpawner.spawnNPC(UID,npcName,loc);
  NPCCreateEvent event=new NPCCreateEvent(npc,reason,loc);
  Bukkit.getServer().getPluginManager().callEvent(event);
  npc.setNPCData(new NPCData(npcName,UID,loc,colour,PropertyManager.getBasic().getItems(UID),NPCDataManager.NPCTexts.get(UID),PropertyManager.getBasic().isTalk(UID),PropertyManager.getBasic().isLookWhenClose(UID),PropertyManager.getBasic().isTalkWhenClose(UID),owner));
  PropertyManager.getBasic().saveOwner(UID,owner);
  PropertyManager.load(npc);
  registerUID(UID,npcName);
  list.put(UID,npc);
  PropertyManager.save(npc);
  npc.getPlayer().setSleepingIgnored(true);
}
 

Example 6

From project 16Blocks, under directory /src/main/java/de/minestar/sixteenblocks/Commands/.

Source file: cmdCreateRow.java

  19 
vote

@Override public void execute(String[] arguments,Player player){
  if (Core.shutdownServer) {
    TextUtils.sendError(player,"/createrow is not possible at this moment. Server will reload or restart in a few moments.");
    TextUtils.sendLine(player,ChatColor.GRAY,"Please try again in a few moments.");
    return;
  }
  if (!Core.isSupporter(player) || Core.isVip(player)) {
    TextUtils.sendError(player,"You are not allowed to do this!");
    return;
  }
  try {
    int row=Integer.valueOf(arguments[0]);
    TextUtils.sendInfo(player,"Recreating rowstructures: " + row);
    Core.getInstance().getAreaManager().createRowStructures(row);
  }
 catch (  Exception e) {
    TextUtils.sendError(player,"Wrong Syntax! Please use /createrow <Number>");
    TextUtils.sendInfo(player,"Example: /createrow 5");
  }
}
 

Example 7

From project 16Blocks, under directory /src/main/java/de/minestar/sixteenblocks/Commands/.

Source file: cmdDeleteArea.java

  19 
vote

@Override public void execute(String[] arguments,Player player){
  if (Core.shutdownServer) {
    TextUtils.sendError(player,"/delete is not possible at this moment. Server will reload or restart in a few moments.");
    TextUtils.sendLine(player,ChatColor.GRAY,"Please try again in a few moments.");
    return;
  }
  if (!Core.isSupporter(player) || Core.isVip(player)) {
    TextUtils.sendError(player,"You are not allowed to do this!");
    return;
  }
  if (arguments.length > 0) {
    SkinArea thisArea=this.areaManager.getExactPlayerArea(arguments[0]);
    if (thisArea == null) {
      TextUtils.sendError(player,"No area for player '" + arguments[0] + "' found!");
      return;
    }
    if (this.areaManager.isAreaBlocked(thisArea.getZoneXZ())) {
      TextUtils.sendError(player,"This area is currently blocked by another process.");
      return;
    }
    this.areaManager.deletePlayerArea(thisArea,player);
    TextUtils.sendSuccess(player,"Starting deletion of '" + thisArea.getAreaOwner() + "'.");
  }
 else {
    ZoneXZ thisZone=ZoneXZ.fromPoint(player.getLocation().getBlockX(),player.getLocation().getBlockZ());
    SkinArea thisArea=this.areaManager.getPlayerArea(thisZone);
    if (thisArea == null) {
      TextUtils.sendError(player,"No area found at this position!");
      return;
    }
    if (this.areaManager.isAreaBlocked(thisArea.getZoneXZ())) {
      TextUtils.sendError(player,"This area is currently blocked by another process.");
      return;
    }
    this.areaManager.deletePlayerArea(thisArea,player);
    TextUtils.sendSuccess(player,"Starting deletion of '" + thisArea.getAreaOwner() + "'.");
  }
}
 

Example 8

From project AdminCmd, under directory /src/main/java/be/Balor/bukkit/AdminCmd/.

Source file: ACHelper.java

  19 
vote

private void addLocaleFromFile(){
  String locale=fManager.getTextFile("motd.txt");
  if (locale == null) {
    ACLogger.info("Could not read motd.txt. Using default values for the MotD!");
    Utils.addLocale("MOTD",ChatColor.GOLD + "Welcome " + ChatColor.WHITE+ "%player"+ ChatColor.GOLD+ ", there is currently "+ ChatColor.DARK_RED+ "%nb players connected : //n"+ ChatColor.GOLD+ "%connected //n"+ ChatColor.DARK_GREEN+ "You've played so far : "+ ChatColor.AQUA+ "#elapsedTotalTime# //n"+ ChatColor.DARK_GREEN+ "Your last login was: "+ ChatColor.AQUA+ "%lastlogin",true);
  }
 else {
    ACLogger.info("motd.txt loaded");
    Utils.addLocale("MOTD",Utils.colorParser(locale),true);
  }
  locale=fManager.getTextFile("motdNewUser.txt");
  if (locale == null) {
    ACLogger.info("Could not read motdNewUser.txt. Using default values for the MotDNewUser!");
    Utils.addLocale("MOTDNewUser",ChatColor.GOLD + "Welcome " + ChatColor.WHITE+ "%player"+ ChatColor.GOLD+ ", there is currently "+ ChatColor.DARK_RED+ "%nb players connected : //n"+ ChatColor.GOLD+ "%connected //n"+ ChatColor.DARK_GREEN+ "You've played so far : "+ ChatColor.AQUA+ "#elapsedTotalTime#",true);
  }
 else {
    ACLogger.info("motdNewUser.txt loaded");
    Utils.addLocale("MOTDNewUser",Utils.colorParser(locale),true);
  }
  locale=fManager.getTextFile("news.txt");
  if (locale == null) {
    ACLogger.info("Could not read news.txt. Using default values for the MotD!");
    Utils.addLocale("NEWS",ChatColor.DARK_GREEN + "News : AdminCmd Plugin has been installed",true);
  }
 else {
    ACLogger.info("news.txt loaded");
    Utils.addLocale("NEWS",Utils.colorParser(locale),true);
  }
  locale=fManager.getTextFile("rules.txt");
  if (locale == null) {
    ACLogger.info("Could not read motdNewUser.txt. Using default values for the MotD!");
    Utils.addLocale("Rules","1. Do not grief! //n" + "2. Do not use strong language! //n" + "3. Be friendly to other players!",true);
  }
 else {
    ACLogger.info("rules.txt loaded");
    Utils.addLocale("Rules",Utils.colorParser(locale),true);
  }
  LocaleManager.getInstance().save();
}
 

Example 9

From project AdminCmd, under directory /src/main/java/be/Balor/bukkit/AdminCmd/.

Source file: ACHelper.java

  19 
vote

public boolean alias(final CommandSender sender,final CommandArgs args){
  final MaterialContainer m=checkMaterial(sender,args.getString(1));
  if (m.isNull()) {
    return true;
  }
  final String alias=args.getString(0);
  this.alias.put(alias,m);
  this.fManager.addAlias(alias,m);
  sender.sendMessage(ChatColor.BLUE + "You can now use " + ChatColor.GOLD+ alias+ ChatColor.BLUE+ " for the item "+ ChatColor.GOLD+ m.display());
  return true;
}
 

Example 10

From project AdminStuff, under directory /src/main/java/de/minestar/AdminStuff/commands/.

Source file: cmdButcher.java

  19 
vote

@Override public void execute(String[] args,Player player){
  if (args.length == 0) {
    Long lastTime=recentUser.get(player);
    if (lastTime == null || (System.currentTimeMillis() - lastTime >= TimeUnit.MINUTES.toMillis(5))) {
      PlayerUtils.sendMessage(player,ChatColor.MAGIC,"-------------------------------------------");
      PlayerUtils.sendError(player,pluginName,"Wenn du wirklich alle Tiere ?er den Jordan schicken willst,");
      PlayerUtils.sendError(player,pluginName,"(Das sind ca. " + countMobs(player.getWorld()) + " Tiere! Denk mal an deren Kinder!)");
      PlayerUtils.sendError(player,pluginName,"Dann gebe bitte den Befehl ein 2. Mal ein und lebe mit den Folgen!");
      PlayerUtils.sendMessage(player,ChatColor.MAGIC,"-------------------------------------------");
      recentUser.put(player,System.currentTimeMillis());
    }
 else {
      killAll(player);
      recentUser.remove(player);
    }
  }
 else   if (args.length == 1) {
    int radius=0;
    try {
      radius=Integer.parseInt(args[0]);
    }
 catch (    Exception e) {
      PlayerUtils.sendError(player,pluginName,args[0] + " ist keine Zahl!");
      return;
    }
    killRadius(player,radius);
  }
 else   PlayerUtils.sendError(player,pluginName,getHelpMessage());
}
 

Example 11

From project AdminStuff, under directory /src/main/java/de/minestar/AdminStuff/commands/.

Source file: cmdFlash.java

  19 
vote

private void flashPlayer(String[] targetNames,CommandSender sender){
  Player target=null;
  for (  String name : targetNames) {
    target=PlayerUtils.getOnlinePlayer(name);
    if (target == null)     ChatUtils.writeError(sender,pluginName,"Spieler '" + name + "' wurde nicht gefunden!");
 else     if (target.isDead() || !target.isOnline())     ChatUtils.writeError(sender,pluginName,"Spieler '" + target.getName() + "' ist tot oder offline!");
 else {
      target.getInventory().clear();
      target.getWorld().strikeLightning(target.getLocation());
      target.damage(9001);
      Bukkit.broadcastMessage(ChatColor.LIGHT_PURPLE + getRandomMessage(target.getName()));
    }
  }
}
 

Example 12

From project AntiCheat, under directory /src/main/java/net/h31ix/anticheat/.

Source file: Anticheat.java

  19 
vote

private void setupXray(){
  final XRayTracker xtracker=manager.getXRayTracker();
  if (config.logXRay()) {
    eventList.add(new XRayListener());
    if (config.alertXRay()) {
      getServer().getScheduler().scheduleAsyncRepeatingTask(this,new Runnable(){
        @Override public void run(){
          for (          Player player : getServer().getOnlinePlayers()) {
            String name=player.getName();
            if (!xtracker.hasAlerted(name) && xtracker.sufficientData(name) && xtracker.hasAbnormal(name)) {
              List<String> alert=new ArrayList<String>();
              alert.add(ChatColor.YELLOW + "[ALERT] " + ChatColor.WHITE+ name+ ChatColor.YELLOW+ " might be using xray.");
              alert.add(ChatColor.YELLOW + "[ALERT] Please check their xray stats using " + ChatColor.WHITE+ "/anticheat xray "+ name+ ChatColor.YELLOW+ ".");
              Utilities.alert(alert);
              xtracker.logAlert(name);
            }
          }
        }
      }
,XRAY_TIME,XRAY_TIME);
      if (verbose) {
        getLogger().log(Level.INFO,"Scheduled the XRay checker.");
      }
    }
  }
}
 

Example 13

From project Armageddon, under directory /src/main/java/com/iminurnetz/bukkit/plugin/armageddon/.

Source file: ArmageddonPlugin.java

  19 
vote

public PlayerSettings getPlayerSettings(Player player,boolean alertPlayer){
  if (playerSettings == null) {
    log(Level.SEVERE,"player settings corrupted, starting over");
    playerSettings=new Hashtable<String,PlayerSettings>();
  }
synchronized (playerSettings) {
    String name=player.getName();
    if (!playerSettings.containsKey(name)) {
      playerSettings.put(name,new PlayerSettings(getDefaultCannon(),getDefaultGun()));
      if (alertPlayer) {
        MessageUtils.send(player,ChatColor.RED,"Default cannon settings used!\n" + getHelpText());
      }
    }
    return playerSettings.get(name);
  }
}
 

Example 14

From project BetterMechanics, under directory /src/net/edoxile/bettermechanics/mechanics/.

Source file: Ammeter.java

  19 
vote

@Override public void onBlockRightClick(PlayerEvent event){
  String msg="The current is: [" + ChatColor.GREEN;
  for (byte i=0; i < event.getBlock().getData(); i++) {
    msg+="|";
  }
  msg+=ChatColor.DARK_RED;
  for (byte i=event.getBlock().getData(); i < 15; i++) {
    msg+="|";
  }
  msg+=ChatColor.WHITE + "] " + ChatColor.RED+ Byte.toString(event.getBlock().getData())+ ChatColor.WHITE+ " A.";
  event.getPlayer().sendMessage(msg);
}
 

Example 15

From project BetterMechanics, under directory /src/net/edoxile/bettermechanics/mechanics/.

Source file: Bridge.java

  19 
vote

@Override public void onPlayerRightClickSign(PlayerEvent event){
  try {
    String node=SignUtil.getMechanicsIdentifier(SignUtil.getSign(event.getBlock()));
    if (!PermissionHandler.getInstance().hasPermission(event.getPlayer(),event.getBlock(),node,PermissionHandler.Checks.HIT))     throw new PlayerNotifier("Seems like you don't have permission to do this!",PlayerNotifier.Level.INFO,event.getBlock().getLocation());
    loadData(SignUtil.getSign(event.getBlock()));
    if (isOpen()) {
      close();
      event.getPlayer().sendMessage(ChatColor.GOLD + "Bridge closed!");
    }
 else {
      open();
      event.getPlayer().sendMessage(ChatColor.GOLD + "Bridge opened!");
    }
  }
 catch (  PlayerNotifier playerNotifier) {
    playerNotifier.notify(event.getPlayer());
    playerNotifier.log();
  }
}
 

Example 16

From project BetterShop_1, under directory /src/me/jascotty2/bettershop/commands/.

Source file: AdminCommands.java

  19 
vote

@Command(commands={"shopremove","sremove"},aliases={"remove","rm"},desc="Remove an item from the price list",usage="[item]",min=1,max=1,permissions={"BetterShop.admin.remove"}) public static boolean remove(CommandSender player,String[] s){
  if ((!BSPermissions.hasPermission(player,BetterShopPermission.ADMIN_REMOVE,true))) {
    return true;
  }
 else   if (s == null || s.length != 1) {
    return false;
  }
  JItem toRem=JItemDB.findItem(s[0]);
  if (toRem != null) {
    try {
      Shop shop=BetterShop.getShop(player instanceof Player ? ((Player)player).getLocation() : null);
      shop.pricelist.remove(toRem);
      shop.stock.remove(toRem);
      BSutils.sendMessage(player,BetterShop.getSettings().getString("removemsg").replace("<item>",toRem.coloredName()),BetterShop.getSettings().publicmarket);
      return true;
    }
 catch (    Exception ex) {
      BetterShopLogger.Log(Level.SEVERE,ex);
    }
    BSutils.sendMessage(player,ChatColor.RED + "Error removing item");
  }
 else {
    BSutils.sendMessage(player,BetterShop.getSettings().getString("unkitem").replace("<item>",s[0]));
  }
  return true;
}
 

Example 17

From project BetterShop_1, under directory /src/me/jascotty2/bettershop/commands/.

Source file: AdminCommands.java

  19 
vote

@Command(commands={},aliases={"backup"},desc="Backup the pricelist to a csv file",usage="[filename]",permissions={"BetterShop.admin.backup"}) public static void backupDB(CommandSender sender,String[] s){
  String fn;
  if (s.length >= 1) {
    fn=Str.concatStr(s,1," ");
    if (fn.toLowerCase().endsWith(".csv")) {
      fn=fn.substring(0,fn.length() - 5);
    }
  }
 else {
    fn=dateFormatter.format(new java.util.Date());
  }
  if (s.length >= 1) {
    Shop sh=BetterShop.getShop(s[0]);
    if (sh != null) {
      if (backupDB(sh,fn)) {
        BSutils.sendMessage(sender,ChatColor.GREEN + "Backup saved as " + fn);
      }
 else {
        BSutils.sendMessage(sender,ChatColor.RED + "Failed to save backup file " + fn);
      }
      return;
    }
  }
  for (  Shop shop : BetterShop.getShops()) {
    String filename;
    if (s.length > 1) {
      filename=fn + "_" + shop.config.tableName;
    }
 else {
      filename=shop.config.tableName + "_" + fn;
    }
    if (backupDB(shop,filename)) {
      BSutils.sendMessage(sender,ChatColor.GREEN + "Backup saved as " + filename);
    }
 else {
      BSutils.sendMessage(sender,ChatColor.RED + "Failed to save backup file " + filename);
    }
  }
}
 

Example 18

From project Buildr, under directory /src/me/simplex/buildr/.

Source file: Buildr.java

  19 
vote

public boolean playerClickedBuildingBlock(Player player,Block clickedBlock){
  if (!checkPlayerHasStartedBuilding(player)) {
    return false;
  }
  Buildr_Interface_Building wallbuilder=giveBuilderManager(player);
  if (!wallbuilder.isCoordinate1Placed()) {
    wallbuilder.addCoordinate1(clickedBlock);
    player.sendMessage("Got positon 1 of your " + wallbuilder.getBuildingName() + " at ["+ ChatColor.BLUE+ clickedBlock.getX()+ ChatColor.WHITE+ ", "+ ChatColor.BLUE+ clickedBlock.getY()+ ChatColor.WHITE+ ", "+ ChatColor.BLUE+ clickedBlock.getZ()+ ChatColor.WHITE+ "]");
    player.sendMessage("Now rightclick on block 2 (again with a stick) to continue");
  }
 else {
    player.sendMessage("Got positon 2 of your" + wallbuilder.getBuildingName() + " at ["+ ChatColor.BLUE+ clickedBlock.getX()+ ChatColor.WHITE+ ", "+ ChatColor.BLUE+ clickedBlock.getY()+ ChatColor.WHITE+ ", "+ ChatColor.BLUE+ clickedBlock.getZ()+ ChatColor.WHITE+ "]");
    wallbuilder.addCoordinate2(clickedBlock);
    if (wallbuilder.checkCoordinates()) {
      player.sendMessage("Positions OK, build " + wallbuilder.getBuildingName() + "..");
      wallbuilder.startBuild();
      removeStartedBuilding(player);
    }
 else {
      removeStartedBuilding(player);
      player.sendMessage(ChatColor.RED + "ERROR: " + ChatColor.WHITE+ wallbuilder.getCoordinateCheckFailed());
    }
  }
  return true;
}
 

Example 19

From project Bukkit-Plugin-Utilties, under directory /src/main/java/de/xzise/commands/.

Source file: CommonHelpCommand.java

  19 
vote

private String[] getFullHelp(FullHelpable helpable){
  List<String> lines=new ArrayList<String>();
  lines.add(this.name + " help: " + ChatColor.GREEN+ helpable.getCommand());
  for (  String string : helpable.getFullHelpText()) {
    lines.add(string);
  }
  String[] aliases=helpable.getCommands();
  if (aliases.length > 1) {
    String aliasString="Aliases: ";
    for (int i=1; i < aliases.length; i++) {
      aliasString+=ChatColor.GREEN + aliases[i];
      if (i < aliases.length - 1) {
        aliasString+=ChatColor.WHITE + ", ";
      }
    }
    lines.add(aliasString);
  }
  return lines.toArray(new String[0]);
}
 

Example 20

From project Bukkit-Plugin-Utilties, under directory /src/main/java/de/xzise/wrappers/economy/.

Source file: EconomyHandler.java

  19 
vote

/** 
 * Pays for an action if the sender has enough money. If the sender is not a player no money will be transfered.
 * @param sender The paying sender.
 * @param reciever Optional reciever of the price. If null only the basic price is to pay.
 * @param price The amount of money which the reciever get.
 * @param basic The basic price like an tax.
 * @return If the price could be paid or if there was nothing to pay.
 */
public PayResult pay(CommandSender sender,String reciever,double price,double basic){
  if (this.getWrapper() != null) {
    Player player=MinecraftUtil.getPlayer(sender);
    if (player != null) {
      AccountWrapper executor=this.getAccount(player.getName());
      if (executor.hasEnough(price + basic)) {
        executor.add(-price - basic);
        this.tax.add(basic);
        if (MinecraftUtil.isSet(reciever)) {
          AccountWrapper owner=this.getAccount(reciever);
          owner.add(price);
        }
        return PayResult.PAID;
      }
 else {
        return PayResult.NOT_ENOUGH;
      }
    }
 else {
      this.logger.info("Couldn't pay action, because the executor is not a player.");
    }
  }
 else   if (price > 0) {
    sender.sendMessage(ChatColor.RED + "You should pay for this warp. But no economy plugin found.");
  }
  return PayResult.UNABLE;
}
 

Example 21

From project BukkitUtilities, under directory /src/main/java/name/richardson/james/bukkit/utilities/command/.

Source file: AbstractCommand.java

  19 
vote

public boolean onCommand(final CommandSender sender,final org.bukkit.command.Command command,final String label,final String[] args){
  if (!this.getClass().isAnnotationPresent(ConsoleCommand.class) && (sender instanceof ConsoleCommandSender)) {
    final String message=this.localisation.getMessage(AbstractCommand.class,"not-allowed-from-console");
    sender.sendMessage(message);
    return true;
  }
  if (!this.testPermission(sender)) {
    final String message=this.localisation.getMessage(AbstractCommand.class,"not-permitted");
    sender.sendMessage(message);
    return true;
  }
  try {
    this.parseArguments(args,sender);
    this.execute(sender);
  }
 catch (  final CommandArgumentException exception) {
    sender.sendMessage(exception.getMessage());
    if (exception.getHelp() != null) {
      sender.sendMessage(exception.getHelp());
    }
  }
catch (  final CommandPermissionException exception) {
    final String message=this.localisation.getMessage(AbstractCommand.class,"not-permitted");
    sender.sendMessage(message);
    if (exception.getMessage() != null) {
      sender.sendMessage(exception.getMessage());
    }
    if (this.logger.isDebugging()) {
      sender.sendMessage(this.localisation.getMessage(AbstractCommand.class,"permission-required",exception.getPermission().getName()));
    }
  }
catch (  final CommandUsageException exception) {
    sender.sendMessage(ChatColor.RED + exception.getMessage());
  }
  return true;
}
 

Example 22

From project BukkitUtilities, under directory /src/main/java/name/richardson/james/bukkit/utilities/command/.

Source file: CommandManager.java

  19 
vote

public boolean onCommand(final CommandSender sender,final org.bukkit.command.Command cmd,final String label,final String[] args){
  if (args.length == 0) {
    sender.sendMessage(ChatColor.LIGHT_PURPLE + this.pluginName);
    sender.sendMessage(ChatColor.AQUA + this.pluginDescription);
    sender.sendMessage(this.localisation.getMessage(this,"help-usage",cmd.getName(),this.helpCommand));
    for (    final Command command : this.commands.values()) {
      if (command.testPermission(sender)) {
        sender.sendMessage(this.getCommandHelpEntry(label,command));
      }
    }
    return true;
  }
  if ((args.length != 0) && this.commands.containsKey(args[0].toLowerCase())) {
    final Command command=this.commands.get(args[0]);
    final String[] arguments=this.prepareArguments(args,args[0]);
    command.onCommand(sender,cmd,null,arguments);
    return true;
  }
 else   if ((args.length == 2) && args[0].equalsIgnoreCase(this.helpCommand)) {
    if (this.commands.containsKey(args[1]) && this.commands.get(args[1]).testPermission(sender)) {
      final Command command=this.commands.get(args[1]);
      sender.sendMessage(ChatColor.LIGHT_PURPLE + command.getDescription());
      sender.sendMessage(this.getCommandHelpEntry(label,command));
    }
 else {
      sender.sendMessage(this.localisation.getMessage(this,"invalid-command"));
      sender.sendMessage(this.localisation.getMessage(this,"list-commands",cmd.getName()));
    }
    return true;
  }
 else {
    sender.sendMessage(this.localisation.getMessage(this,"invalid-command"));
    sender.sendMessage(this.localisation.getMessage(this,"list-commands",cmd.getName()));
    return true;
  }
}
 

Example 23

From project ChessCraft, under directory /src/main/java/me/desht/chesscraft/chess/.

Source file: BoardView.java

  19 
vote

public void showBoardDetail(CommandSender sender){
  String bullet=ChatColor.LIGHT_PURPLE + "* " + ChatColor.AQUA;
  Cuboid bounds=getOuterBounds();
  String gameName=getGame() != null ? getGame().getName() : Messages.getString("ChessCommandExecutor.noGame");
  MessagePager pager=MessagePager.getPager(sender).clear();
  pager.add(Messages.getString("ChessCommandExecutor.boardDetail.board",getName()));
  pager.add(bullet + Messages.getString("ChessCommandExecutor.boardDetail.boardExtents",MiscUtil.formatLocation(bounds.getLowerNE()),MiscUtil.formatLocation(bounds.getUpperSW())));
  pager.add(bullet + Messages.getString("ChessCommandExecutor.boardDetail.game",gameName));
  pager.add(bullet + Messages.getString("ChessCommandExecutor.boardDetail.boardOrientation",getRotation().toString()));
  pager.add(bullet + Messages.getString("ChessCommandExecutor.boardDetail.boardStyle",getBoardStyleName()));
  pager.add(bullet + Messages.getString("ChessCommandExecutor.boardDetail.pieceStyle",getPieceStyleName()));
  pager.add(bullet + Messages.getString("ChessCommandExecutor.boardDetail.squareSize",getSquareSize(),getWhiteSquareMaterial(),getBlackSquareMaterial()));
  pager.add(bullet + Messages.getString("ChessCommandExecutor.boardDetail.frameWidth",getFrameWidth(),getFrameMaterial()));
  pager.add(bullet + Messages.getString("ChessCommandExecutor.boardDetail.enclosure",getEnclosureMaterial()));
  pager.add(bullet + Messages.getString("ChessCommandExecutor.boardDetail.struts",getStrutsMaterial()));
  pager.add(bullet + Messages.getString("ChessCommandExecutor.boardDetail.height",getHeight()));
  pager.add(bullet + Messages.getString("ChessCommandExecutor.boardDetail.lightLevel",getLightLevel()));
  String lockStakeStr=getLockStake() ? Messages.getString("ChessCommandExecutor.boardDetail.locked") : "";
  pager.add(bullet + Messages.getString("ChessCommandExecutor.boardDetail.defaultStake",ChessUtils.formatStakeStr(getDefaultStake()),lockStakeStr));
  String lockTcStr=getLockTcSpec() ? Messages.getString("ChessCommandExecutor.boardDetail.locked") : "";
  pager.add(bullet + Messages.getString("ChessCommandExecutor.boardDetail.defaultTimeControl",getDefaultTcSpec(),lockTcStr));
  if (chessBoard.getDesigner() != null) {
    pager.add(bullet + Messages.getString("ChessCommandExecutor.designMode",chessBoard.getDesigner().getSetName()));
  }
  String setComment=getChessBoard().getChessSet().getComment();
  if (setComment != null && !setComment.isEmpty()) {
    for (    String s : setComment.split("\n")) {
      pager.add(ChatColor.YELLOW + s);
    }
  }
  pager.showPage();
}
 

Example 24

From project ChessCraft, under directory /src/main/java/me/desht/chesscraft/chess/.

Source file: ChessGame.java

  19 
vote

/** 
 * Display details for the game to the given player.
 * @param player
 */
public void showGameDetail(CommandSender sender){
  String white=getPlayerWhite().isEmpty() ? "?" : getPlayerWhite();
  String black=getPlayerBlack().isEmpty() ? "?" : getPlayerBlack();
  String bullet=ChatColor.DARK_PURPLE + "* " + ChatColor.AQUA;
  MessagePager pager=MessagePager.getPager(sender).clear();
  pager.add(Messages.getString("ChessCommandExecutor.gameDetail.name",getName(),getState()));
  pager.add(bullet + Messages.getString("ChessCommandExecutor.gameDetail.players",white,black,getView().getName()));
  pager.add(bullet + Messages.getString("ChessCommandExecutor.gameDetail.halfMoves",getHistory().size()));
  if (ChessCraft.economy != null) {
    pager.add(bullet + Messages.getString("ChessCommandExecutor.gameDetail.stake",ChessUtils.formatStakeStr(getStake())));
  }
  pager.add(bullet + (getPosition().getToPlay() == Chess.WHITE ? Messages.getString("ChessCommandExecutor.gameDetail.whiteToPlay") : Messages.getString("ChessCommandExecutor.gameDetail.blackToPlay")));
  pager.add(bullet + Messages.getString("ChessCommandExecutor.gameDetail.timeControlType",tcWhite.toString()));
  if (getState() == GameState.RUNNING) {
    pager.add(bullet + Messages.getString("ChessCommandExecutor.gameDetail.clock",tcWhite.getClockString(),tcBlack.getClockString()));
  }
  if (getInvited().equals("*")) {
    pager.add(bullet + Messages.getString("ChessCommandExecutor.gameDetail.openInvitation"));
  }
 else   if (!getInvited().isEmpty()) {
    pager.add(bullet + Messages.getString("ChessCommandExecutor.gameDetail.invitation",getInvited()));
  }
  pager.add(Messages.getString("ChessCommandExecutor.gameDetail.moveHistory"));
  List<Short> h=getHistory();
  for (int i=0; i < h.size(); i+=2) {
    StringBuilder sb=new StringBuilder(String.format("&f%1$d. &-",(i / 2) + 1));
    sb.append(Move.getString(h.get(i)));
    if (i < h.size() - 1) {
      sb.append("  ").append(Move.getString(h.get(i + 1)));
    }
    pager.add(sb.toString());
  }
  pager.showPage();
}
 

Example 25

From project Citizens, under directory /src/blacksmith/net/citizensnpcs/blacksmiths/.

Source file: BlacksmithCommands.java

  19 
vote

@Command(aliases="blacksmith",usage="status",desc="view the status of your in-hand item",modifiers="status",min=1,max=1) @CommandPermissions("blacksmith.use.status") public static void status(CommandContext args,Player player,HumanNPC npc){
  ItemStack item=player.getItemInHand();
  String repairType="";
  if (InventoryUtils.isArmor(item.getTypeId())) {
    repairType="armorrepair";
  }
 else   if (InventoryUtils.isTool(item.getTypeId())) {
    repairType="toolrepair";
  }
 else {
    Messaging.sendError(player,MessageUtils.getMaterialName(item.getTypeId()) + " is not a repairable item.");
    return;
  }
  player.sendMessage(ChatColor.GREEN + "Item: " + StringUtils.wrap(MessageUtils.getMaterialName(item.getTypeId())));
  if (Economy.useEconPlugin()) {
    player.sendMessage(ChatColor.GREEN + "Cost: " + StringUtils.wrap(Economy.format(BlacksmithManager.getBlacksmithPrice(player,repairType))));
  }
  player.sendMessage(ChatColor.GREEN + "Durability Remaining: " + StringUtils.wrap(Material.getMaterial(item.getTypeId()).getMaxDurability() - item.getDurability()));
}
 

Example 26

From project commandbook, under directory /src/main/java/com/sk89q/commandbook/bans/.

Source file: BansComponent.java

  19 
vote

@Command(aliases={"kick"},usage="<target> [reason...]",desc="Kick a user",flags="os",min=1,max=-1) @CommandPermissions({"commandbook.kick"}) public void kick(CommandContext args,CommandSender sender) throws CommandException {
  Iterable<Player> targets=PlayerUtil.matchPlayers(sender,args.getString(0));
  String message=args.argsLength() >= 2 ? args.getJoinedStrings(1) : "Kicked!";
  String broadcastPlayers="";
  for (  Player player : targets) {
    if (CommandBook.inst().hasPermission(player,"commandbook.kick.exempt") && !(args.hasFlag('o') && CommandBook.inst().hasPermission(sender,"commandbook.kick.exempt.override"))) {
      sender.sendMessage(ChatColor.RED + "Player " + player.getName()+ ChatColor.RED+ " is exempt from being kicked!");
      continue;
    }
    player.kickPlayer(message);
    broadcastPlayers+=player.getName() + " ";
    getBanDatabase().logKick(player,sender,message);
  }
  if (broadcastPlayers.length() > 0) {
    sender.sendMessage(ChatColor.YELLOW + "Player(s) kicked.");
    if (config.broadcastKicks && !args.hasFlag('s')) {
      CommandBook.server().broadcastMessage(ChatColor.YELLOW + PlayerUtil.toColoredName(sender,ChatColor.YELLOW) + " has kicked "+ broadcastPlayers+ " - "+ message);
    }
  }
}
 

Example 27

From project commandbook, under directory /src/main/java/com/sk89q/commandbook/bans/.

Source file: BansComponent.java

  19 
vote

@Command(aliases={"ban"},usage="[-t end ] <target> [reason...]",desc="Ban a user",flags="set:o",min=1,max=-1) @CommandPermissions({"commandbook.bans.ban"}) public void ban(CommandContext args,CommandSender sender) throws CommandException {
  String banName;
  String banAddress=null;
  long endDate=args.hasFlag('t') ? CommandBookUtil.matchFutureDate(args.getFlag('t')) : 0L;
  String message=args.argsLength() >= 2 ? args.getJoinedStrings(1) : "Banned!";
  final boolean hasExemptOverride=args.hasFlag('o') && CommandBook.inst().hasPermission(sender,"commandbook.bans.exempt.override");
  try {
    Player player;
    if (args.hasFlag('e')) {
      player=PlayerUtil.matchPlayerExactly(sender,args.getString(0));
    }
 else {
      player=PlayerUtil.matchSinglePlayer(sender,args.getString(0));
    }
    if (CommandBook.inst().hasPermission(player,"commandbook.bans.exempt") && !hasExemptOverride) {
      throw new CommandException("This player is exempt from being banned! " + "(use -o flag to override if you have commandbook.bans.exempt.override)");
    }
    player.kickPlayer(message);
    getBanDatabase().logKick(player,sender,message);
    banName=player.getName();
    sender.sendMessage(ChatColor.YELLOW + player.getName() + " ("+ player.getDisplayName()+ ChatColor.YELLOW+ ") banned and kicked.");
  }
 catch (  CommandException e) {
    banName=args.getString(0).replace("\r","").replace("\n","").replace("\0","").replace("\b","");
    sender.sendMessage(ChatColor.YELLOW + banName + " banned.");
  }
  if (config.broadcastBans && !args.hasFlag('s')) {
    CommandBook.server().broadcastMessage(ChatColor.YELLOW + PlayerUtil.toColoredName(sender,ChatColor.YELLOW) + " has banned "+ banName+ " - "+ message);
  }
  getBanDatabase().ban(banName,banAddress,sender,message,endDate);
  if (!getBanDatabase().save()) {
    sender.sendMessage(ChatColor.RED + "Bans database failed to save. See console.");
  }
}