コード例 #1
0
    @Command(
        aliases = {"banip", "ipban"},
        usage = "<target> [reason...]",
        desc = "Ban an IP address",
        flags = "st:",
        min = 1,
        max = -1)
    @CommandPermissions({"commandbook.bans.ban.ip"})
    public void banIP(CommandContext args, CommandSender sender) throws CommandException {

      String message = args.argsLength() >= 2 ? args.getJoinedStrings(1) : "Banned!";
      long endDate = args.hasFlag('t') ? CommandBookUtil.matchFutureDate(args.getFlag('t')) : 0L;

      String addr =
          args.getString(0).replace("\r", "").replace("\n", "").replace("\0", "").replace("\b", "");

      // Need to kick + log
      for (Player player : CommandBook.server().getOnlinePlayers()) {
        if (player.getAddress().getAddress().getHostAddress().equals(addr)) {
          player.kickPlayer(message);
          getBanDatabase().logKick(player, sender, message);
        }
      }

      getBanDatabase().ban(null, addr, sender, message, endDate);

      sender.sendMessage(ChatColor.YELLOW + addr + " banned.");

      if (!getBanDatabase().save()) {
        sender.sendMessage(ChatColor.RED + "Bans database failed to save. See console.");
      }
    }
コード例 #2
0
 public synchronized void lock(World world) {
   long time = world.getFullTime();
   unlock(world);
   int id =
       CommandBook.server()
           .getScheduler()
           .scheduleSyncRepeatingTask(
               CommandBook.inst(), new TimeLocker(world, time), 20, config.timeLockDelay);
   tasks.put(world.getName(), id);
 }
コード例 #3
0
 public void updateWorlds() {
   for (Iterator<Map.Entry<String, List<NamedLocation>>> i = unloadedLocs.entrySet().iterator();
       i.hasNext(); ) {
     Map.Entry<String, List<NamedLocation>> entry = i.next();
     World world = CommandBook.server().getWorld(entry.getKey());
     if (world == null) continue;
     i.remove();
     for (NamedLocation warp : entry.getValue()) {
       warp.getLocation().setWorld(world);
       locs.put(warp.getName().toLowerCase(), warp);
     }
   }
   for (Iterator<NamedLocation> i = locs.values().iterator(); i.hasNext(); ) {
     NamedLocation loc = i.next();
     if (CommandBook.server().getWorld(loc.getWorldName()) == null) {
       i.remove();
       getNestedList(unloadedLocs, loc.getWorldName()).add(loc);
     }
   }
 }
コード例 #4
0
  @Override
  public void enable() {
    CommandBook.inst().createDefaultConfiguration("kits.txt");

    // Setup kits
    kits = new FlatFileKitsManager(new File(CommandBook.inst().getDataFolder(), "kits.txt"));
    kits.load();

    CommandBook.server()
        .getScheduler()
        .scheduleAsyncRepeatingTask(
            CommandBook.inst(),
            new GarbageCollector(this),
            GarbageCollector.CHECK_FREQUENCY,
            GarbageCollector.CHECK_FREQUENCY);
    registerCommands(Commands.class);
  }
コード例 #5
0
  private void configureWorldLocks() {
    config = configure(new LocalConfiguration());

    if (config.timeLocks != null) {
      for (Map.Entry<String, Object> entry : config.timeLocks.entrySet()) {
        int time = 0;

        try {
          time = matchTime(String.valueOf(entry.getValue()));
        } catch (CommandException e) {
          CommandBook.logger()
              .warning("Time lock: Failed to parse time '" + entry.getValue() + "'");
          continue;
        }

        lockedTimes.put(entry.getKey(), time);

        World world = CommandBook.server().getWorld(entry.getKey());

        if (world == null) {
          CommandBook.logger().info("Could not time-lock unknown world '" + entry.getKey() + "'");
          continue;
        }

        world.setTime(time);
        lock(world);
        CommandBook.logger()
            .info(
                "Time locked to '"
                    + CommandBookUtil.getTimeString(time)
                    + "' for world '"
                    + world.getName()
                    + "'");
      }
    }
  }
コード例 #6
0
  public void load() throws IOException {
    FileInputStream input = null;
    Map<String, NamedLocation> locs = new HashMap<String, NamedLocation>();

    file.getParentFile().mkdirs();
    if (!file.exists()) {
      file.createNewFile();
    }

    try {
      input = new FileInputStream(file);
      InputStreamReader streamReader = new InputStreamReader(input, "utf-8");
      BufferedReader reader = new BufferedReader(streamReader);

      CSVReader csv = new CSVReader(reader);
      String[] line;
      while ((line = csv.readNext()) != null) {
        if (line.length < 7) {
          logger.warning("CommandBook: " + type + " data file has an invalid line with < 7 fields");
        } else {
          try {
            String name = line[0].trim().replace(" ", "");
            String worldName = line[1]; // Set to null if the world exists
            String creator = line[2];
            double x = Double.parseDouble(line[3]);
            double y = Double.parseDouble(line[4]);
            double z = Double.parseDouble(line[5]);
            float pitch = Float.parseFloat(line[6]);
            float yaw = Float.parseFloat(line[7]);

            World world = CommandBook.server().getWorld(worldName);

            if (world != null) {
              // We shouldn't have this warp
              if (castWorld != null && !castWorld.equals(world)) {
                continue;
              }
            }

            Location loc = new Location(world, x, y, z, yaw, pitch);
            NamedLocation warp = new NamedLocation(name, loc);
            warp.setWorldName(worldName);
            warp.setCreatorName(creator);
            if (world == null) {
              getNestedList(unloadedLocs, worldName).add(warp);
            } else {
              locs.put(name.toLowerCase(), warp);
            }
          } catch (NumberFormatException e) {
            logger.warning(
                "CommandBook: "
                    + type
                    + " data file has an invalid line with non-numeric numeric fields");
          }
        }
      }

      this.locs = locs;

      if (castWorld != null) {
        logger.info(
            "CommandBook: " + locs.size() + " " + type + "(s) loaded for " + castWorld.getName());
      } else {
        logger.info("CommandBook: " + locs.size() + " " + type + "(s) loaded");
      }
    } finally {
      if (input != null) {
        try {
          input.close();
        } catch (IOException e) {
        }
      }
    }
  }
コード例 #7
0
    @Command(
        aliases = {"time"},
        usage = "[world] <time|\"current\">",
        desc = "Get/change the world time",
        flags = "l",
        min = 0,
        max = 2)
    public void time(CommandContext args, CommandSender sender) throws CommandException {

      World world;
      String timeStr;
      boolean onlyLock = false;

      // Easy way to get the time
      if (args.argsLength() == 0) {
        world = PlayerUtil.checkPlayer(sender).getWorld();
        timeStr = "current";
        // If no world was specified, get the world from the sender, but
        // fail if the sender isn't player
      } else if (args.argsLength() == 1) {
        world = PlayerUtil.checkPlayer(sender).getWorld();
        timeStr = args.getString(0);
      } else { // A world was specified!
        world = LocationUtil.matchWorld(sender, args.getString(0));
        timeStr = args.getString(1);
      }

      // Let the player get the time
      if (timeStr.equalsIgnoreCase("current")
          || timeStr.equalsIgnoreCase("cur")
          || timeStr.equalsIgnoreCase("now")) {

        // We want to lock to the current time
        if (!args.hasFlag('l')) {
          CommandBook.inst().checkPermission(sender, "commandbook.time.check");
          sender.sendMessage(
              ChatColor.YELLOW + "Time: " + CommandBookUtil.getTimeString(world.getTime()));
          return;
        }

        onlyLock = true;
      }

      CommandBook.inst().checkPermission(sender, "commandbook.time");

      if (!onlyLock) {
        unlock(world);
        world.setTime(matchTime(timeStr));
      }

      String verb = "set";

      // Locking
      if (args.hasFlag('l')) {
        CommandBook.inst().checkPermission(sender, "commandbook.time.lock");
        lock(world);
        verb = "locked";
      }

      if (CommandBook.inst().broadcastChanges) {
        CommandBook.server()
            .broadcastMessage(
                ChatColor.YELLOW
                    + PlayerUtil.toName(sender)
                    + " "
                    + verb
                    + " the time of '"
                    + world.getName()
                    + "' to "
                    + CommandBookUtil.getTimeString(world.getTime())
                    + ".");
      } else {
        sender.sendMessage(
            ChatColor.YELLOW
                + "Time "
                + verb
                + " to "
                + CommandBookUtil.getTimeString(world.getTime())
                + ".");
      }
    }
コード例 #8
0
 public synchronized void unlock(World world) {
   Integer id = tasks.get(world.getName());
   if (id != null) {
     CommandBook.server().getScheduler().cancelTask(id);
   }
 }
コード例 #9
0
    @Command(
        aliases = {"ban"},
        usage = "[-t end ] <target> [reason...]",
        desc = "Ban a user or IP address (with the -i flag)",
        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");
      // Check if it's a player in the server right now
      try {
        Player player;

        // Exact mode matches names exactly
        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)");
        }

        // Need to kick + log
        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.");
      }

      // Broadcast the Message
      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.");
      }
    }