Exemplo n.º 1
0
 private void changeMobData(String type, Entity spawned, String data, User user) throws Exception {
   if ("Slime".equalsIgnoreCase(type)) {
     try {
       ((Slime) spawned).setSize(Integer.parseInt(data));
     } catch (Exception e) {
       throw new Exception(Util.i18n("slimeMalformedSize"), e);
     }
   }
   if ("Sheep".equalsIgnoreCase(type)) {
     try {
       if (data.equalsIgnoreCase("random")) {
         Random rand = new Random();
         ((Sheep) spawned).setColor(DyeColor.values()[rand.nextInt(DyeColor.values().length)]);
       } else {
         ((Sheep) spawned).setColor(DyeColor.valueOf(data.toUpperCase()));
       }
     } catch (Exception e) {
       throw new Exception(Util.i18n("sheepMalformedColor"), e);
     }
   }
   if ("Wolf".equalsIgnoreCase(type) && data.equalsIgnoreCase("tamed")) {
     Wolf wolf = ((Wolf) spawned);
     wolf.setTamed(true);
     wolf.setOwner(user);
     wolf.setSitting(true);
   }
   if ("Wolf".equalsIgnoreCase(type) && data.equalsIgnoreCase("angry")) {
     ((Wolf) spawned).setAngry(true);
   }
   if ("Creeper".equalsIgnoreCase(type) && data.equalsIgnoreCase("powered")) {
     ((Creeper) spawned).setPowered(true);
   }
 }
Exemplo n.º 2
0
  @Override
  public void run(Server server, CommandSender sender, String commandLabel, String[] args)
      throws Exception {
    if (args.length < 1) {
      throw new NotEnoughArgumentsException();
    }

    if (server.matchPlayer(args[0]).isEmpty()) {
      ((CraftServer) server).getHandle().a(args[0]);
      sender.sendMessage(Util.format("playerBanned", args[0]));
    } else {
      final User player = ess.getUser(server.matchPlayer(args[0]).get(0));
      String banReason;
      if (args.length > 1) {
        banReason = getFinalArg(args, 1);
        player.setBanReason(commandLabel);
      } else {
        banReason = Util.i18n("defaultBanReason");
      }
      player.kickPlayer(banReason);
      ((CraftServer) server).getHandle().a(player.getName());
      sender.sendMessage(Util.format("playerBanned", player.getName()));
    }
    ess.loadBanList();
  }
Exemplo n.º 3
0
	@Override
	protected void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception
	{
		if (args.length < 1)
		{
			throw new NotEnoughArgumentsException();
		}
		final String whois = args[0].toLowerCase(Locale.ENGLISH);
		for (Player onlinePlayer : server.getOnlinePlayers())
		{
			final User u = ess.getUser(onlinePlayer);
			if (u.isHidden())
			{
				continue;
			}
			final String displayName = Util.stripColor(u.getDisplayName()).toLowerCase(Locale.ENGLISH);
			if (!whois.equals(displayName)
				&& !displayName.equals(Util.stripColor(ess.getSettings().getNicknamePrefix()) + whois)
				&& !whois.equalsIgnoreCase(u.getName()))
			{
				continue;
			}
			sender.sendMessage(u.getDisplayName() + " " + _("is") + " " + u.getName());
		}
	}
Exemplo n.º 4
0
  @Override
  public void run(Server server, CommandSender sender, String commandLabel, String[] args)
      throws Exception {

    User user = null;
    if (sender instanceof Player) {
      user = ess.getUser(((Player) sender));
    }
    if (args.length < 1 & user != null) {
      user.getWorld().strikeLightning(user.getTargetBlock(null, 600).getLocation());
      return;
    }

    if (server.matchPlayer(args[0]).isEmpty()) {
      throw new Exception(Util.i18n("playerNotFound"));
    }

    for (Player p : server.matchPlayer(args[0])) {
      sender.sendMessage(Util.format("lightningUse", p.getDisplayName()));
      p.getWorld().strikeLightning(p.getLocation());
      if (!ess.getUser(p).isGodModeEnabled()) {
        p.setHealth(p.getHealth() < 5 ? 0 : p.getHealth() - 5);
      }
      if (ess.getSettings().warnOnSmite()) {
        p.sendMessage(Util.i18n("lightningSmited"));
      }
    }
  }
Exemplo n.º 5
0
  private void repairItem(final ItemStack item) throws Exception {
    final Material material = Material.getMaterial(item.getTypeId());
    if (material.isBlock() || material.getMaxDurability() < 0) {
      throw new Exception(Util.i18n("repairInvalidType"));
    }

    if (item.getDurability() == 0) {
      throw new Exception(Util.i18n("repairAlreadyFixed"));
    }

    item.setDurability((short) 0);
  }
Exemplo n.º 6
0
  @Override
  public void run(Server server, User user, String commandLabel, String[] args) throws Exception {
    charge(user);

    if (!user.toggleAfk()) {
      user.sendMessage(Util.i18n("markedAsNotAway"));
      ess.broadcastMessage(user.getName(), Util.format("userIsNotAway", user.getDisplayName()));
    } else {
      user.sendMessage(Util.i18n("markedAsAway"));
      ess.broadcastMessage(user.getName(), Util.format("userIsAway", user.getDisplayName()));
    }
  }
  @Override
  public void onPlayerChat(final PlayerChatEvent event) {
    if (isAborted(event)) {
      return;
    }

    /**
     * This file should handle detection of the local chat features... if local chat is enabled, we
     * need to handle it here
     */
    final User user = ess.getUser(event.getPlayer());
    final String chatType = getChatType(event.getMessage());
    long radius = ess.getSettings().getChatRadius();
    if (radius < 1) {
      return;
    }
    radius *= radius;
    try {
      if (event.getMessage().length() > 0 && chatType.length() > 0) {
        StringBuilder permission = new StringBuilder();
        permission.append("essentials.chat.").append(chatType);

        StringBuilder command = new StringBuilder();
        command.append("chat-").append(chatType);

        StringBuilder format = new StringBuilder();
        format.append(chatType).append("Format");

        StringBuilder errorMsg = new StringBuilder();
        errorMsg
            .append("notAllowedTo")
            .append(chatType.substring(0, 1).toUpperCase())
            .append(chatType.substring(1));

        if (user.isAuthorized(permission.toString())) {
          charge(user, command.toString());
          event.setMessage(event.getMessage().substring(1));
          event.setFormat(Util.format(format.toString(), event.getFormat()));
          return;
        }

        user.sendMessage(Util.i18n(errorMsg.toString()));
        event.setCancelled(true);
        return;
      }
    } catch (ChargeException ex) {
      ess.showError(user, ex, "Shout");
      event.setCancelled(true);
      return;
    }
    sendLocalChat(user, radius, event);
  }
Exemplo n.º 8
0
 protected final Double getDoublePositive(final String line) throws SignException {
   final double quantity = getDouble(line);
   if (Math.round(quantity * 100.0) < 1.0) {
     throw new SignException(Util.i18n("moreThanZero"));
   }
   return quantity;
 }
Exemplo n.º 9
0
  @Override
  protected void run(Server server, User user, String commandLabel, String[] args)
      throws Exception {
    int page = 1;
    String match = args[0].toLowerCase();
    try {
      if (args.length > 0) {
        page = Integer.parseInt(args[args.length - 1]);
        if (args.length == 1) {
          match = "";
        }
      }

    } catch (Exception ex) {
    }

    List<String> lines = getHelpLines(user, match);
    int start = (page - 1) * 9;
    int pages = lines.size() / 9 + (lines.size() % 9 > 0 ? 1 : 0);

    user.sendMessage(Util.format("helpPages", page, pages));
    for (int i = start; i < lines.size() && i < start + 9; i++) {
      user.sendMessage(lines.get(i));
    }
  }
Exemplo n.º 10
0
 protected final int getIntegerPositive(final String line) throws SignException {
   final int quantity = getInteger(line);
   if (quantity < 1) {
     throw new SignException(Util.i18n("moreThanZero"));
   }
   return quantity;
 }
Exemplo n.º 11
0
  protected final Trade getTrade(
      final ISign sign, final int index, final int decrement, final IEssentials ess)
      throws SignException {
    final String line = sign.getLine(index).trim();
    if (line.isEmpty()) {
      return new Trade(signName.toLowerCase() + "sign", ess);
    }

    final Double money = getMoney(line);
    if (money == null) {
      final String[] split = line.split("[ :]+", 2);
      if (split.length != 2) {
        throw new SignException(Util.i18n("invalidCharge"));
      }
      final int quantity = getIntegerPositive(split[0]);

      final String item = split[1].toLowerCase();
      if (item.equalsIgnoreCase("times")) {
        sign.setLine(index, (quantity - decrement) + " times");
        return new Trade(signName.toLowerCase() + "sign", ess);
      } else {
        final ItemStack stack = getItemStack(item, quantity, ess);
        sign.setLine(index, quantity + " " + item);
        return new Trade(stack, ess);
      }
    } else {
      return new Trade(money, ess);
    }
  }
Exemplo n.º 12
0
 @Override
 protected void run(Server server, User user, String commandLabel, String[] args)
     throws Exception {
   Trade charge = new Trade(this.getName(), ess);
   charge.isAffordableFor(user);
   user.sendMessage(Util.i18n("backUsageMsg"));
   user.getTeleport().back(charge);
 }
Exemplo n.º 13
0
	@Override
	protected void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception
	{
		if (args.length < 1)
		{
			throw new NotEnoughArgumentsException();
		}
		sender.sendMessage(_("balance", Util.displayCurrency(getPlayer(server, args, 0, true).getMoney(), ess)));
	}
Exemplo n.º 14
0
	@Override
	public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception
	{
		final double bal = (args.length < 1
							|| !(user.isAuthorized("essentials.balance.others")
								 || user.isAuthorized("essentials.balance.other"))
							? user
							: getPlayer(server, args, 0, true)).getMoney();
		user.sendMessage(_("balance", Util.displayCurrency(bal, ess)));
	}
Exemplo n.º 15
0
  @Override
  public void run(Server server, User user, String commandLabel, String[] args) throws Exception {

    if (args.length < 1) {
      throw new NotEnoughArgumentsException();
    }
    charge(user);
    ess.getJail().setJail(user.getLocation(), args[0]);
    user.sendMessage(Util.format("jailSet", args[0]));
  }
Exemplo n.º 16
0
  public void onEnable() {
    final PluginManager pm = this.getServer().getPluginManager();
    ess = (IEssentials) pm.getPlugin("Essentials");

    final EssentialsProtectPlayerListener playerListener =
        new EssentialsProtectPlayerListener(this);
    pm.registerEvent(Type.PLAYER_INTERACT, playerListener, Priority.Low, this);

    final EssentialsProtectBlockListener blockListener = new EssentialsProtectBlockListener(this);
    pm.registerEvent(Type.BLOCK_PLACE, blockListener, Priority.Highest, this);
    pm.registerEvent(Type.BLOCK_FROMTO, blockListener, Priority.Highest, this);
    pm.registerEvent(Type.BLOCK_IGNITE, blockListener, Priority.Highest, this);
    pm.registerEvent(Type.BLOCK_BURN, blockListener, Priority.Highest, this);
    pm.registerEvent(Type.BLOCK_BREAK, blockListener, Priority.Highest, this);
    pm.registerEvent(Type.BLOCK_PISTON_EXTEND, blockListener, Priority.Highest, this);
    pm.registerEvent(Type.BLOCK_PISTON_RETRACT, blockListener, Priority.Highest, this);

    final EssentialsProtectEntityListener entityListener =
        new EssentialsProtectEntityListener(this);
    pm.registerEvent(Type.ENTITY_EXPLODE, entityListener, Priority.Highest, this);
    pm.registerEvent(Type.ENTITY_DAMAGE, entityListener, Priority.Highest, this);
    pm.registerEvent(Type.CREATURE_SPAWN, entityListener, Priority.Highest, this);
    pm.registerEvent(Type.ENTITY_TARGET, entityListener, Priority.Highest, this);
    pm.registerEvent(Type.EXPLOSION_PRIME, entityListener, Priority.Highest, this);

    final EssentialsProtectWeatherListener weatherListener =
        new EssentialsProtectWeatherListener(this);
    pm.registerEvent(Type.LIGHTNING_STRIKE, weatherListener, Priority.Highest, this);
    pm.registerEvent(Type.THUNDER_CHANGE, weatherListener, Priority.Highest, this);
    pm.registerEvent(Type.WEATHER_CHANGE, weatherListener, Priority.Highest, this);

    reloadConfig();
    ess.addReloadListener(this);
    if (!this.getDescription().getVersion().equals(ess.getDescription().getVersion())) {
      LOGGER.log(Level.WARNING, Util.i18n("versionMismatchAll"));
    }
    LOGGER.info(
        Util.format(
            "loadinfo",
            this.getDescription().getName(),
            this.getDescription().getVersion(),
            "essentials team"));
  }
Exemplo n.º 17
0
  @Override
  public void run(Server server, CommandSender sender, String commandLabel, String[] args)
      throws Exception {
    if (args.length < 1) {
      throw new NotEnoughArgumentsException();
    }

    ((CraftServer) server).getHandle().c(args[0]);
    sender.sendMessage(Util.i18n("banIpAddress"));
    ess.loadBanList();
  }
Exemplo n.º 18
0
  public void onEnable() {
    final PluginManager pluginManager = getServer().getPluginManager();

    EssentialsChatPlayerListener.checkFactions(pluginManager);

    final EssentialsChatPlayerListener playerListener =
        new EssentialsChatPlayerListener(getServer());
    pluginManager.registerEvent(Type.PLAYER_JOIN, playerListener, Priority.Lowest, this);
    pluginManager.registerEvent(Type.PLAYER_CHAT, playerListener, Priority.Highest, this);
    if (!this.getDescription()
        .getVersion()
        .equals(Essentials.getStatic().getDescription().getVersion())) {
      LOGGER.log(Level.WARNING, Util.i18n("versionMismatchAll"));
    }
    LOGGER.info(
        Util.format(
            "loadinfo",
            this.getDescription().getName(),
            this.getDescription().getVersion(),
            Essentials.AUTHORS));
  }
Exemplo n.º 19
0
 protected final void validateTrade(final ISign sign, final int index, final IEssentials ess)
     throws SignException {
   final String line = sign.getLine(index).trim();
   if (line.isEmpty()) {
     return;
   }
   final Trade trade = getTrade(sign, index, 0, ess);
   final Double money = trade.getMoney();
   if (money != null) {
     sign.setLine(index, Util.formatCurrency(money, ess));
   }
 }
Exemplo n.º 20
0
  @Override
  public void run(
      final Server server, final User user, final String commandLabel, final String[] args)
      throws Exception {
    if (args.length < 1) {
      throw new NotEnoughArgumentsException();
    }

    if (args[0].equalsIgnoreCase("hand")) {
      final ItemStack item = user.getItemInHand();
      if (item == null) {
        throw new Exception(Util.i18n("repairInvalidType"));
      }
      final String itemName = item.getType().toString().toLowerCase();
      final Trade charge = new Trade("repair-" + itemName.replace('_', '-'), ess);

      charge.isAffordableFor(user);

      repairItem(item);

      charge.charge(user);

      user.sendMessage(Util.format("repair", itemName.replace('_', ' ')));
    } else if (args[0].equalsIgnoreCase("all")) {
      final List<String> repaired = new ArrayList<String>();
      repairItems(user.getInventory().getContents(), user, repaired);

      repairItems(user.getInventory().getArmorContents(), user, repaired);

      if (repaired.isEmpty()) {
        throw new Exception(Util.format("repairNone"));
      } else {
        user.sendMessage(Util.format("repair", Util.joinList(repaired)));
      }

    } else {
      throw new NotEnoughArgumentsException();
    }
  }
Exemplo n.º 21
0
  @Override
  public void run(Server server, User user, String commandLabel, String[] args) throws Exception {
    if (args.length < 3) {
      throw new NotEnoughArgumentsException();
    }

    int x = Integer.parseInt(args[0]);
    int y = Integer.parseInt(args[1]);
    int z = Integer.parseInt(args[2]);
    Location l = new Location(user.getWorld(), x, y, z);
    Charge charge = new Charge(this.getName(), ess);
    charge.isAffordableFor(user);
    user.sendMessage(Util.i18n("teleporting"));
    user.getTeleport().teleport(l, charge);
  }
Exemplo n.º 22
0
  protected final Trade getTrade(
      final ISign sign,
      final int amountIndex,
      final int itemIndex,
      final User player,
      final IEssentials ess)
      throws SignException {

    final ItemStack item = getItemStack(sign.getLine(itemIndex), 1, ess);
    final int amount =
        Math.min(
            getIntegerPositive(sign.getLine(amountIndex)),
            item.getType().getMaxStackSize() * player.getInventory().getSize());
    if (item.getTypeId() == 0 || amount < 1) {
      throw new SignException(Util.i18n("moreThanZero"));
    }
    item.setAmount(amount);
    return new Trade(item, ess);
  }
Exemplo n.º 23
0
  @Override
  public void run(Server server, CommandSender sender, String commandLabel, String[] args)
      throws Exception {
    if (args.length < 2 || args[0].trim().isEmpty() || args[1].trim().isEmpty()) {
      throw new NotEnoughArgumentsException();
    }

    String message = getFinalArg(args, 1);
    String translatedMe = Util.i18n("me");

    IReplyTo replyTo =
        sender instanceof Player ? ess.getUser((Player) sender) : Console.getConsoleReplyTo();
    String senderName =
        sender instanceof Player ? ((Player) sender).getDisplayName() : Console.NAME;

    if (args[0].equalsIgnoreCase(Console.NAME)) {
      sender.sendMessage(Util.format("msgFormat", translatedMe, Console.NAME, message));
      CommandSender cs = Console.getCommandSender(server);
      cs.sendMessage(Util.format("msgFormat", senderName, translatedMe, message));
      replyTo.setReplyTo(cs);
      Console.getConsoleReplyTo().setReplyTo(sender);
      return;
    }

    List<Player> matches = server.matchPlayer(args[0]);

    if (matches.isEmpty()) {
      sender.sendMessage(Util.i18n("playerNotFound"));
      return;
    }

    charge(sender);
    for (Player p : matches) {
      sender.sendMessage(Util.format("msgFormat", translatedMe, p.getDisplayName(), message));
      final User u = ess.getUser(p);
      if (sender instanceof Player
          && (u.isIgnoredPlayer(((Player) sender).getName()) || u.isHidden())) {
        continue;
      }
      p.sendMessage(Util.format("msgFormat", senderName, translatedMe, message));
      replyTo.setReplyTo(ess.getUser(p));
      ess.getUser(p).setReplyTo(sender);
    }
  }
Exemplo n.º 24
0
 public final boolean onSignCreate(final SignChangeEvent event, final IEssentials ess) {
   final ISign sign = new EventSign(event);
   final User user = ess.getUser(event.getPlayer());
   if (!(user.isAuthorized("essentials.signs." + signName.toLowerCase() + ".create")
       || user.isAuthorized("essentials.signs.create." + signName.toLowerCase()))) {
     // Return true, so other plugins can use the same sign title, just hope
     // they won't change it to §1[Signname]
     return true;
   }
   sign.setLine(0, Util.format("signFormatFail", this.signName));
   try {
     final boolean ret = onSignCreate(sign, user, getUsername(user), ess);
     if (ret) {
       sign.setLine(0, getSuccessName());
     }
     return ret;
   } catch (ChargeException ex) {
     ess.showError(user, ex, signName);
   } catch (SignException ex) {
     ess.showError(user, ex, signName);
   }
   // Return true, so the player sees the wrong sign.
   return true;
 }
Exemplo n.º 25
0
 @Override
 public void alert(final User user, final String item, final String type) {
   final Location loc = user.getLocation();
   final String warnMessage =
       Util.format(
           "alertFormat",
           user.getName(),
           type,
           item,
           loc.getWorld().getName()
               + ","
               + loc.getBlockX()
               + ","
               + loc.getBlockY()
               + ","
               + loc.getBlockZ());
   LOGGER.log(Level.WARNING, warnMessage);
   for (Player p : this.getServer().getOnlinePlayers()) {
     final User alertUser = ess.getUser(p);
     if (alertUser.isAuthorized("essentials.protect.alerts")) {
       alertUser.sendMessage(warnMessage);
     }
   }
 }
Exemplo n.º 26
0
  @Override
  public void run(Server server, User user, String commandLabel, String[] args) throws Exception {
    if (args.length < 1) {
      throw new NotEnoughArgumentsException();
      // TODO: user.sendMessage("§7Mobs: Zombie PigZombie Skeleton Slime Chicken Pig Monster Spider
      // Creeper Ghast Squid Giant Cow Sheep Wolf");
    }

    String[] mountparts = args[0].split(",");
    String[] parts = mountparts[0].split(":");
    String mobType = parts[0];
    mobType = mobType.equalsIgnoreCase("PigZombie") ? "PigZombie" : Util.capitalCase(mobType);
    String mobData = null;
    if (parts.length == 2) {
      mobData = parts[1];
    }
    String mountType = null;
    String mountData = null;
    if (mountparts.length > 1) {
      parts = mountparts[1].split(":");
      mountType = parts[0];
      mountType =
          mountType.equalsIgnoreCase("PigZombie") ? "PigZombie" : Util.capitalCase(mountType);
      if (parts.length == 2) {
        mountData = parts[1];
      }
    }

    if (ess.getSettings().getProtectPreventSpawn(mobType.toLowerCase())
        || (mountType != null
            && ess.getSettings().getProtectPreventSpawn(mountType.toLowerCase()))) {
      throw new Exception(Util.i18n("unableToSpawnMob"));
    }

    Entity spawnedMob = null;
    Mob mob = null;
    Entity spawnedMount = null;
    Mob mobMount = null;

    mob = Mob.fromName(mobType);
    if (mob == null) {
      throw new Exception(Util.i18n("invalidMob"));
    }
    int[] ignore = {8, 9};
    Block block = (new TargetBlock(user, 300, 0.2, ignore)).getTargetBlock();
    if (block == null) {
      user.sendMessage(Util.i18n("unableToSpawnMob"));
      return;
    }
    Location loc = block.getLocation();
    Location sloc = Util.getSafeDestination(loc);
    try {
      spawnedMob = mob.spawn(user, server, sloc);
    } catch (MobException e) {
      user.sendMessage(Util.i18n("unableToSpawnMob"));
      return;
    }

    if (mountType != null) {
      mobMount = Mob.fromName(mountType);
      if (mobMount == null) {
        user.sendMessage(Util.i18n("invalidMob"));
        return;
      }
      try {
        spawnedMount = mobMount.spawn(user, server, loc);
      } catch (MobException e) {
        user.sendMessage(Util.i18n("unableToSpawnMob"));
        return;
      }
      spawnedMob.setPassenger(spawnedMount);
    }
    if (mobData != null) {
      changeMobData(mob.name, spawnedMob, mobData, user);
    }
    if (spawnedMount != null && mountData != null) {
      changeMobData(mobMount.name, spawnedMount, mountData, user);
    }
    if (args.length == 2) {
      int mobCount = Integer.parseInt(args[1]);
      int serverLimit = ess.getSettings().getSpawnMobLimit();
      if (mobCount > serverLimit) {
        mobCount = serverLimit;
        user.sendMessage(Util.i18n("mobSpawnLimit"));
      }

      try {
        for (int i = 1; i < mobCount; i++) {
          spawnedMob = mob.spawn(user, server, loc);
          if (mobMount != null) {
            try {
              spawnedMount = mobMount.spawn(user, server, loc);
            } catch (MobException e) {
              user.sendMessage(Util.i18n("unableToSpawnMob"));
              return;
            }
            spawnedMob.setPassenger(spawnedMount);
          }
          if (mobData != null) {
            changeMobData(mob.name, spawnedMob, mobData, user);
          }
          if (spawnedMount != null && mountData != null) {
            changeMobData(mobMount.name, spawnedMount, mountData, user);
          }
        }
        user.sendMessage(
            args[1] + " " + mob.name.toLowerCase() + mob.suffix + " " + Util.i18n("spawned"));
      } catch (MobException e1) {
        throw new Exception(Util.i18n("unableToSpawnMob"), e1);
      } catch (NumberFormatException e2) {
        throw new Exception(Util.i18n("numberRequired"), e2);
      } catch (NullPointerException np) {
        throw new Exception(Util.i18n("soloMob"), np);
      }
    } else {
      user.sendMessage(mob.name + " " + Util.i18n("spawned"));
    }
  }
Exemplo n.º 27
0
  @SuppressWarnings("CallToThreadDumpStack")
  private List<String> getHelpLines(User user, String match) throws Exception {
    List<String> retval = new ArrayList<String>();
    File helpFile =
        new File(ess.getDataFolder(), "help_" + Util.sanitizeFileName(user.getName()) + ".txt");
    if (!helpFile.exists()) {
      helpFile =
          new File(ess.getDataFolder(), "help_" + Util.sanitizeFileName(user.getGroup()) + ".txt");
    }
    if (!helpFile.exists()) {
      helpFile = new File(ess.getDataFolder(), "help.txt");
    }
    if (helpFile.exists()) {
      final BufferedReader bufferedReader = new BufferedReader(new FileReader(helpFile));
      try {

        while (bufferedReader.ready()) {
          final String line = bufferedReader.readLine();
          retval.add(line.replace('&', '§'));
        }
      } finally {
        bufferedReader.close();
      }
      return retval;
    }

    boolean reported = false;
    String pluginName = "";
    for (Plugin p : ess.getServer().getPluginManager().getPlugins()) {
      try {
        final PluginDescriptionFile desc = p.getDescription();
        final HashMap<String, HashMap<String, String>> cmds =
            (HashMap<String, HashMap<String, String>>) desc.getCommands();
        for (Entry<String, HashMap<String, String>> k : cmds.entrySet()) {
          if ((!match.equalsIgnoreCase(""))
              && (!p.getDescription().getName().toLowerCase().contains(match))
              && (!p.getDescription().getDescription().toLowerCase().contains(match))) {
            continue;
          }

          if (p.getDescription().getName().toLowerCase().contains("essentials")) {
            final String node = "essentials." + k.getKey();
            if (!ess.getSettings().isCommandDisabled(k.getKey()) && user.isAuthorized(node)) {
              retval.add("§c" + k.getKey() + "§7: " + k.getValue().get("description"));
            }
          } else {
            if (ess.getSettings().showNonEssCommandsInHelp()) {
              pluginName = p.getDescription().getName();
              final HashMap<String, String> value = k.getValue();
              if (value.containsKey("permission")
                  && value.get("permission") != null
                  && !(value.get("permission").equals(""))) {
                if (user.isAuthorized(value.get("permission"))) {
                  retval.add("§c" + k.getKey() + "§7: " + value.get("description"));
                }
              } else {
                if (!ess.getSettings().hidePermissionlessHelp()) {
                  retval.add("§c" + k.getKey() + "§7: " + value.get("description"));
                }
              }
            }
          }
        }
      } catch (NullPointerException ex) {
        continue;
      } catch (Exception ex) {
        if (!reported) {
          logger.log(Level.WARNING, "Error getting help for:" + pluginName, ex);
        }
        reported = true;
        continue;
      }
    }
    return retval;
  }
Exemplo n.º 28
0
 @Override
 protected void run(Server server, CommandSender sender, String commandLabel, String[] args)
     throws Exception {
   sender.sendMessage(Util.i18n("helpConsole"));
 }
Exemplo n.º 29
0
 public String getSuccessName() {
   return Util.format("signFormatSuccess", this.signName);
 }
Exemplo n.º 30
0
 public String getTemplateName() {
   return Util.format("signFormatTemplate", this.signName);
 }