@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();
  }
示例#2
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()));
    }
  }
示例#3
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));
    }
  }
  @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"));
      }
    }
  }
示例#5
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);
    }
  }
  @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]));
  }
  @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);
  }
示例#8
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();
    }
  }
  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"));
  }
示例#10
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));
  }
 @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);
     }
   }
 }
示例#12
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;
 }
示例#13
0
 public String getTemplateName() {
   return Util.format("signFormatTemplate", this.signName);
 }
示例#14
0
 public String getSuccessName() {
   return Util.format("signFormatSuccess", this.signName);
 }
  @Override
  public void run(Server server, User user, String commandLabel, String[] args) throws Exception {
    if (args.length < 1) {
      throw new NotEnoughArgumentsException();
    }

    User target = user;

    if (args.length > 1 && user.isAuthorized("essentials.unlimited.others")) {
      target = getPlayer(server, args, 1);
    }

    if (args[0].equalsIgnoreCase("list")) {
      StringBuilder sb = new StringBuilder();
      sb.append(Util.i18n("unlimitedItems")).append(" ");
      boolean first = true;
      List<Integer> items = target.getUnlimited();
      if (items.isEmpty()) {
        sb.append(Util.i18n("none"));
      }
      for (Integer integer : items) {
        if (!first) {
          sb.append(", ");
        }
        first = false;
        String matname = Material.getMaterial(integer).toString().toLowerCase().replace("_", "");
        sb.append(matname);
      }
      user.sendMessage(sb.toString());
      return;
    }

    final ItemStack stack = ess.getItemDb().get(args[0], 1);
    stack.setAmount(Math.min(stack.getType().getMaxStackSize(), 2));

    String itemname = stack.getType().toString().toLowerCase().replace("_", "");
    if (!user.isAuthorized("essentials.unlimited.item-all")
        && !user.isAuthorized("essentials.unlimited.item-" + itemname)
        && !user.isAuthorized("essentials.unlimited.item-" + stack.getTypeId())
        && !((stack.getType() == Material.WATER_BUCKET || stack.getType() == Material.LAVA_BUCKET)
            && user.isAuthorized("essentials.unlimited.item-bucket"))) {
      user.sendMessage(Util.format("unlimitedItemPermission", itemname));
      return;
    }

    if (target.hasUnlimited(stack)) {
      if (user != target) {
        user.sendMessage(Util.format("disableUnlimited", itemname, target.getDisplayName()));
      }
      target.sendMessage(Util.format("disableUnlimited", itemname, target.getDisplayName()));
      target.setUnlimited(stack, false);
      return;
    }
    charge(user);
    if (user != target) {
      user.sendMessage(Util.format("enableUnlimited", itemname, target.getDisplayName()));
    }
    target.sendMessage(Util.format("enableUnlimited", itemname, target.getDisplayName()));
    if (!InventoryWorkaround.containsItem(target.getInventory(), true, stack)) {
      target.getInventory().addItem(stack);
    }
    target.setUnlimited(stack, true);
  }