Example #1
1
  private static final void mysqlFind(
      final Plugin plugin,
      final String playerName,
      final Location location,
      final int radius,
      final WorldManager manager,
      final ArrayList<Player> players) {

    BBPlayerInfo hunted = BBUsersTable.getInstance().getUserByName(playerName);

    PreparedStatement ps = null;
    ResultSet rs = null;

    HashMap<Integer, Integer> creations = new HashMap<Integer, Integer>();
    HashMap<Integer, Integer> destructions = new HashMap<Integer, Integer>();
    HashMap<Integer, Integer> explosions = new HashMap<Integer, Integer>();
    HashMap<Integer, Integer> burns = new HashMap<Integer, Integer>();

    Connection conn = null;

    try {
      conn = ConnectionManager.getConnection();
      if (conn == null) return;
      // TODO maybe more customizable actions?
      String actionString =
          "action IN('"
              + Action.BLOCK_BROKEN.ordinal()
              + "', '"
              + Action.BLOCK_PLACED.ordinal()
              + "', '"
              + Action.LEAF_DECAY.ordinal()
              + "', '"
              + Action.TNT_EXPLOSION.ordinal()
              + "', '"
              + Action.CREEPER_EXPLOSION.ordinal()
              + "', '"
              + Action.MISC_EXPLOSION.ordinal()
              + "', '"
              + Action.LAVA_FLOW.ordinal()
              + "', '"
              + Action.BLOCK_BURN.ordinal()
              + "')";
      ps =
          conn.prepareStatement(
              "SELECT action, type FROM "
                  + BBDataTable.getInstance().getTableName()
                  + " WHERE "
                  + actionString
                  + " AND rbacked = 0 AND x < ? AND x > ? AND y < ? AND y > ?  AND z < ? AND z > ? AND player = ? AND world = ? order by date desc");

      ps.setInt(1, location.getBlockX() + radius);
      ps.setInt(2, location.getBlockX() - radius);
      ps.setInt(3, location.getBlockY() + radius);
      ps.setInt(4, location.getBlockY() - radius);
      ps.setInt(5, location.getBlockZ() + radius);
      ps.setInt(6, location.getBlockZ() - radius);
      ps.setInt(7, hunted.getID());
      ps.setInt(8, manager.getWorld(location.getWorld().getName()));
      rs = ps.executeQuery();
      conn.commit();

      int size = 0;
      while (rs.next()) {
        Action action = Action.values()[rs.getInt("action")];
        int type = rs.getInt("type");

        switch (action) {
          case BLOCK_BROKEN:
          case LEAF_DECAY:
            if (destructions.containsKey(type)) {
              destructions.put(type, destructions.get(type) + 1);
              size++;
            } else {
              destructions.put(type, 1);
              size++;
            }
            break;
          case BLOCK_PLACED:
            if (creations.containsKey(type)) {
              creations.put(type, creations.get(type) + 1);
              size++;
            } else {
              creations.put(type, 1);
              size++;
            }
            break;
          case TNT_EXPLOSION:
          case CREEPER_EXPLOSION:
          case MISC_EXPLOSION:
            if (explosions.containsKey(type)) {
              explosions.put(type, explosions.get(type) + 1);
              size++;
            } else {
              explosions.put(type, 1);
              size++;
            }
          case BLOCK_BURN:
            if (burns.containsKey(type)) {
              burns.put(type, burns.get(type) + 1);
              size++;
            } else {
              burns.put(type, 1);
              size++;
            }
            break;
          case LAVA_FLOW:
            if (creations.containsKey(type)) {
              creations.put(type, creations.get(type) + 1);
              size++;
            } else {
              creations.put(type, 1);
              size++;
            }
            break;
        }
      }
      if (size > 0) {
        StringBuilder creationList = new StringBuilder();
        creationList.append(ChatColor.AQUA.toString());
        creationList.append("Placed Blocks: ");
        creationList.append(ChatColor.WHITE.toString());
        for (Entry<Integer, Integer> entry : creations.entrySet()) {
          creationList.append(Material.getMaterial(entry.getKey()));
          creationList.append(" (");
          creationList.append(entry.getValue());
          creationList.append("), ");
        }
        if (creationList.toString().contains(",")) {
          creationList.delete(creationList.lastIndexOf(","), creationList.length());
        }
        StringBuilder brokenList = new StringBuilder();
        brokenList.append(ChatColor.RED.toString());
        brokenList.append("Broken Blocks: ");
        brokenList.append(ChatColor.WHITE.toString());
        for (Entry<Integer, Integer> entry : destructions.entrySet()) {
          brokenList.append(Material.getMaterial(entry.getKey()));
          brokenList.append(" (");
          brokenList.append(entry.getValue());
          brokenList.append("), ");
        }
        if (brokenList.toString().contains(",")) {
          brokenList.delete(brokenList.lastIndexOf(","), brokenList.length());
        }
        StringBuilder explodeList = new StringBuilder();
        explodeList.append(ChatColor.RED.toString());
        explodeList.append("Exploded Blocks: ");
        explodeList.append(ChatColor.WHITE.toString());
        for (Entry<Integer, Integer> entry : explosions.entrySet()) {
          explodeList.append(Material.getMaterial(entry.getKey()));
          explodeList.append(" (");
          explodeList.append(entry.getValue());
          explodeList.append("), ");
        }
        if (explodeList.toString().contains(",")) {
          explodeList.delete(explodeList.lastIndexOf(","), explodeList.length());
        }

        StringBuilder burnList = new StringBuilder();
        burnList.append(ChatColor.RED.toString());
        burnList.append("Burned Blocks: ");
        burnList.append(ChatColor.WHITE.toString());
        for (Entry<Integer, Integer> entry : burns.entrySet()) {
          burnList.append(Material.getMaterial(entry.getKey()));
          burnList.append(" (");
          burnList.append(entry.getValue());
          burnList.append("), ");
        }
        if (burnList.toString().contains(",")) {
          burnList.delete(burnList.lastIndexOf(","), burnList.length());
        }
        for (Player player : players) {
          player.sendMessage(
              BigBrother.premessage + playerName + " has made " + size + " modifications");
          if (creations.entrySet().size() > 0) {
            player.sendMessage(creationList.toString());
          }
          if (destructions.entrySet().size() > 0) {
            player.sendMessage(brokenList.toString());
          }
          if (explosions.entrySet().size() > 0) {
            player.sendMessage(explodeList.toString());
          }
          if (burns.entrySet().size() > 0) {
            player.sendMessage(burnList.toString());
          }
        }
      } else {
        for (Player player : players) {
          player.sendMessage(
              BigBrother.premessage + playerName + " has no modifications in this area.");
        }
      }
    } catch (SQLException ex) {
      BBLogging.severe("Find SQL Exception", ex);
    } finally {
      ConnectionManager.cleanup("Find SQL", conn, ps, rs);
    }
  }
Example #2
0
 // Setup the irc <-> minecraft color mappings.
 static {
   ircToMinecraftColor.put(Colors.WHITE, ChatColor.WHITE.toString()); // black
   ircToMinecraftColor.put(Colors.BLACK, ChatColor.BLACK.toString()); // white
   ircToMinecraftColor.put(Colors.DARK_BLUE, ChatColor.DARK_BLUE.toString()); // dark_blue
   ircToMinecraftColor.put(Colors.DARK_GREEN, ChatColor.DARK_GREEN.toString()); // dark_green
   ircToMinecraftColor.put(Colors.RED, ChatColor.RED.toString()); // red
   ircToMinecraftColor.put(Colors.BROWN, ChatColor.DARK_RED.toString()); // brown
   ircToMinecraftColor.put(Colors.PURPLE, ChatColor.DARK_PURPLE.toString()); // purple
   ircToMinecraftColor.put(Colors.OLIVE, ChatColor.GOLD.toString()); // olive
   ircToMinecraftColor.put(Colors.YELLOW, ChatColor.YELLOW.toString()); // yellow
   ircToMinecraftColor.put(Colors.GREEN, ChatColor.GREEN.toString()); // green
   ircToMinecraftColor.put(Colors.TEAL, ChatColor.DARK_AQUA.toString()); // teal
   ircToMinecraftColor.put(Colors.CYAN, ChatColor.AQUA.toString()); // cyan
   ircToMinecraftColor.put(Colors.BLUE, ChatColor.BLUE.toString()); // blue
   ircToMinecraftColor.put(Colors.MAGENTA, ChatColor.LIGHT_PURPLE.toString()); // magenta
   ircToMinecraftColor.put(Colors.DARK_GRAY, ChatColor.DARK_GRAY.toString()); // dark_gray
   ircToMinecraftColor.put(Colors.LIGHT_GRAY, ChatColor.GRAY.toString()); // light_gray
   minecraftToIrcColor.put(ChatColor.WHITE.toString(), Colors.WHITE); // black
   minecraftToIrcColor.put(ChatColor.BLACK.toString(), Colors.BLACK); // white
   minecraftToIrcColor.put(ChatColor.DARK_BLUE.toString(), Colors.DARK_BLUE); // dark_blue
   minecraftToIrcColor.put(ChatColor.DARK_GREEN.toString(), Colors.DARK_GREEN); // dark_green
   minecraftToIrcColor.put(ChatColor.RED.toString(), Colors.RED); // red
   minecraftToIrcColor.put(ChatColor.DARK_RED.toString(), Colors.BROWN); // brown
   minecraftToIrcColor.put(ChatColor.DARK_PURPLE.toString(), Colors.PURPLE); // purple
   minecraftToIrcColor.put(ChatColor.GOLD.toString(), Colors.OLIVE); // olive
   minecraftToIrcColor.put(ChatColor.YELLOW.toString(), Colors.YELLOW); // yellow
   minecraftToIrcColor.put(ChatColor.GREEN.toString(), Colors.GREEN); // green
   minecraftToIrcColor.put(ChatColor.DARK_AQUA.toString(), Colors.TEAL); // teal
   minecraftToIrcColor.put(ChatColor.AQUA.toString(), Colors.CYAN); // cyan
   minecraftToIrcColor.put(ChatColor.BLUE.toString(), Colors.BLUE); // blue
   minecraftToIrcColor.put(ChatColor.LIGHT_PURPLE.toString(), Colors.MAGENTA); // magenta
   minecraftToIrcColor.put(ChatColor.DARK_GRAY.toString(), Colors.DARK_GRAY); // dark_gray
   minecraftToIrcColor.put(ChatColor.GRAY.toString(), Colors.LIGHT_GRAY); // light_gray
 }
Example #3
0
 private String colorize(String string) {
   if (string.indexOf(ChatColor.COLOR_CHAR) < 0) {
     return string; // no colors in the message
   } else if ((!jLine || !reader.getTerminal().isAnsiSupported()) && jTerminal == null) {
     return ChatColor.stripColor(string); // color not supported
   } else {
     return string
             .replace(ChatColor.RED.toString(), "\033[1;31m")
             .replace(ChatColor.YELLOW.toString(), "\033[1;33m")
             .replace(ChatColor.GREEN.toString(), "\033[1;32m")
             .replace(ChatColor.AQUA.toString(), "\033[1;36m")
             .replace(ChatColor.BLUE.toString(), "\033[1;34m")
             .replace(ChatColor.LIGHT_PURPLE.toString(), "\033[1;35m")
             .replace(ChatColor.BLACK.toString(), "\033[0;0m")
             .replace(ChatColor.DARK_GRAY.toString(), "\033[1;30m")
             .replace(ChatColor.DARK_RED.toString(), "\033[0;31m")
             .replace(ChatColor.GOLD.toString(), "\033[0;33m")
             .replace(ChatColor.DARK_GREEN.toString(), "\033[0;32m")
             .replace(ChatColor.DARK_AQUA.toString(), "\033[0;36m")
             .replace(ChatColor.DARK_BLUE.toString(), "\033[0;34m")
             .replace(ChatColor.DARK_PURPLE.toString(), "\033[0;35m")
             .replace(ChatColor.GRAY.toString(), "\033[0;37m")
             .replace(ChatColor.WHITE.toString(), "\033[1;37m")
         + "\033[0m";
   }
 }
Example #4
0
  /**
   * Replace color macros in a string. The macros are in the form of `[char] where char represents
   * the color. R is for red, Y is for yellow, G is for green, C is for cyan, B is for blue, and P
   * is for purple. The uppercase versions of those are the darker shades, while the lowercase
   * versions are the lighter shades. For white, it's 'w', and 0-2 are black, dark grey, and grey,
   * respectively.
   *
   * @param str
   * @return color-coded string
   */
  public static String replaceColorMacros(String str) {
    str = str.replace("&r", ChatColor.RED.toString());
    str = str.replace("&R", ChatColor.DARK_RED.toString());

    str = str.replace("&y", ChatColor.YELLOW.toString());
    str = str.replace("&Y", ChatColor.GOLD.toString());

    str = str.replace("&g", ChatColor.GREEN.toString());
    str = str.replace("&G", ChatColor.DARK_GREEN.toString());

    str = str.replace("&c", ChatColor.AQUA.toString());
    str = str.replace("&C", ChatColor.DARK_AQUA.toString());

    str = str.replace("&b", ChatColor.BLUE.toString());
    str = str.replace("&B", ChatColor.DARK_BLUE.toString());

    str = str.replace("&p", ChatColor.LIGHT_PURPLE.toString());
    str = str.replace("&P", ChatColor.DARK_PURPLE.toString());

    str = str.replace("&0", ChatColor.BLACK.toString());
    str = str.replace("&1", ChatColor.DARK_GRAY.toString());
    str = str.replace("&2", ChatColor.GRAY.toString());
    str = str.replace("&w", ChatColor.WHITE.toString());

    return str;
  }
Example #5
0
 public String colorize(String string) {
   if (!string.contains("\u00A7")) {
     return string;
   } else if ((!jLine || !reader.getTerminal().isANSISupported()) && jTerminal == null) {
     return ChatColor.stripColor(string);
   } else {
     return string
             .replace(ChatColor.RED.toString(), "\033[1;31m")
             .replace(ChatColor.YELLOW.toString(), "\033[1;33m")
             .replace(ChatColor.GREEN.toString(), "\033[1;32m")
             .replace(ChatColor.AQUA.toString(), "\033[1;36m")
             .replace(ChatColor.BLUE.toString(), "\033[1;34m")
             .replace(ChatColor.LIGHT_PURPLE.toString(), "\033[1;35m")
             .replace(ChatColor.BLACK.toString(), "\033[0;0m")
             .replace(ChatColor.DARK_GRAY.toString(), "\033[1;30m")
             .replace(ChatColor.DARK_RED.toString(), "\033[0;31m")
             .replace(ChatColor.GOLD.toString(), "\033[0;33m")
             .replace(ChatColor.DARK_GREEN.toString(), "\033[0;32m")
             .replace(ChatColor.DARK_AQUA.toString(), "\033[0;36m")
             .replace(ChatColor.DARK_BLUE.toString(), "\033[0;34m")
             .replace(ChatColor.DARK_PURPLE.toString(), "\033[0;35m")
             .replace(ChatColor.GRAY.toString(), "\033[0;37m")
             .replace(ChatColor.WHITE.toString(), "\033[1;37m")
         + "\033[0m";
   }
 }
Example #6
0
 public void listPlugins(Player player) {
   StringBuilder list = new StringBuilder();
   for (String plugin : pluginHelpList.keySet()) {
     list.append(ChatColor.GREEN.toString());
     list.append(plugin);
     list.append(ChatColor.WHITE.toString());
     list.append(", ");
   }
   list.delete(list.length() - 2, list.length());
   player.sendMessage(ChatColor.AQUA + "Plugins with Help entries:");
   player.sendMessage(list.toString());
 }
 @Override
 public ItemStack getItem() {
   return new Builder(Material.BOOK)
       .setName(
           ChatColor.WHITE.toString()
               + ChatColor.BOLD
               + "Teleport: "
               + ChatColor.WHITE
               + "Crestguard Keep")
       .setLore(
           Arrays.asList(
               ChatColor.GRAY
                   + "Spawn a teleportation book to "
                   + ChatColor.BOLD
                   + "Crestguard Keep"))
       .getItem();
 }
Example #8
0
  public static void onRemainingAirChange(Player player, int old) {
    if (player.getInventory().getHelmet().getType().getId() == 310) {
      int oldPercent = (old + 299) / 300;
      int remaining = (player.getRemainingAir() + 299) / 300;
      boolean ignore =
          old == 300 && player.getRemainingAir() == 3000
              || old == 3000 && player.getRemainingAir() == 300;
      if (oldPercent != remaining && !ignore) {

        String message = "[";
        for (int i = 0; i < 10; i++) {
          if (i < remaining) {
            message += ChatColor.BLUE.toString() + "|";
          } else {
            message += ChatColor.RED.toString() + "|";
          }
        }
        message += ChatColor.WHITE.toString() + "]";
        message += String.format(" %d%c Air Remaining.", remaining * 10, '%');
        player.sendMessage(message);
      }
    }
  }
Example #9
0
  @Override
  public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    Player p = null;

    if (sender instanceof Player) {
      p = (Player) sender;
    }

    if (p != null) {
      if (!(p.isOp())) {
        return true;
      }
    }

    if (args.length == 0) {
      if (p != null) {
        if (!(p.isOp())) {
          return true;
        }
        p.sendMessage(
            ChatColor.RED
                + "Invalid Syntax. Please use /isay <msg> to send a local world messsage.");
        return true;
      }
    }

    String msg = "";
    for (String s : args) {
      msg += s + " ";
    }
    msg = msg.substring(0, msg.lastIndexOf(" "));

    msg = msg.replaceAll("&0", ChatColor.BLACK.toString());
    msg = msg.replaceAll("&1", ChatColor.DARK_BLUE.toString());
    msg = msg.replaceAll("&2", ChatColor.DARK_GREEN.toString());
    msg = msg.replaceAll("&3", ChatColor.DARK_AQUA.toString());
    msg = msg.replaceAll("&4", ChatColor.DARK_RED.toString());
    msg = msg.replaceAll("&5", ChatColor.DARK_PURPLE.toString());
    msg = msg.replaceAll("&6", ChatColor.GOLD.toString());
    msg = msg.replaceAll("&7", ChatColor.GRAY.toString());
    msg = msg.replaceAll("&8", ChatColor.DARK_GRAY.toString());
    msg = msg.replaceAll("&9", ChatColor.BLUE.toString());
    msg = msg.replaceAll("&a", ChatColor.GREEN.toString());
    msg = msg.replaceAll("&b", ChatColor.AQUA.toString());
    msg = msg.replaceAll("&c", ChatColor.RED.toString());
    msg = msg.replaceAll("&d", ChatColor.LIGHT_PURPLE.toString());
    msg = msg.replaceAll("&e", ChatColor.YELLOW.toString());
    msg = msg.replaceAll("&f", ChatColor.WHITE.toString());

    msg = msg.replaceAll("&u", ChatColor.UNDERLINE.toString());
    msg = msg.replaceAll("&s", ChatColor.BOLD.toString());
    msg = msg.replaceAll("&i", ChatColor.ITALIC.toString());
    msg = msg.replaceAll("&m", ChatColor.MAGIC.toString());

    if (sender instanceof BlockCommandSender) {
      BlockCommandSender cb = (BlockCommandSender) sender;
      for (Player pl : cb.getBlock().getWorld().getPlayers()) {
        pl.sendMessage(msg);
      }
    } else if (sender instanceof Player) {
      for (Player pl : p.getWorld().getPlayers()) {
        pl.sendMessage(msg);
      }
    }
    return true;
  }
Example #10
0
 public String getPlayerName(Player p) {
   return ChatColor.WHITE.toString()
       + (getLeader().getName().equalsIgnoreCase(p.getName())
           ? ChatColor.BOLD.toString() + p.getName()
           : p.getName());
 }
Example #11
0
  /**
   * Converts color codes into the simoleon code. Sort of a HTML format color code tag and `[code]
   *
   * <p>Color codes allowed: black, navy, green, teal, red, purple, gold, silver, gray, blue, lime,
   * aqua, rose, pink, yellow, white. Example:
   *
   * <blockquote
   *
   * <pre>
   *
   * Messaging.colorize(&quot;Hello &lt;green&gt;world!&quot;); // returns: Hello $world! </pre>
   *
   * </blockquote>
   *
   * @param string Original string to be parsed against group of color names.
   * @return <code>String</code> - The parsed string after conversion.
   */
  public static String colorize(String string) {
    if (iConomy.TerminalSupport)
      if (!(sender instanceof Player))
        string =
            string
                    .replace("`r", "\033[1;31m")
                    .replace("`R", "\033[0;31m")
                    .replace("`y", "\033[1;33m")
                    .replace("`Y", "\033[0;33m")
                    .replace("`g", "\033[1;32m")
                    .replace("`G", "\033[0;32m")
                    .replace("`a", "\033[1;36m")
                    .replace("`A", "\033[0;36m")
                    .replace("`b", "\033[1;34m")
                    .replace("`B", "\033[0;34m")
                    .replace("`p", "\033[1;35m")
                    .replace("`P", "\033[0;35m")
                    .replace("`k", "\033[0;0m")
                    .replace("`s", "\033[0;37m")
                    .replace("`S", "\033[1;30m")
                    .replace("`w", "\033[1;37m")
                    .replace("<r>", "\033[0m")
                    .replace("`e", "\033[0m")
                    .replace("<silver>", "\033[0;37m")
                    .replace("<gray>", "\033[1;30m")
                    .replace("<rose>", "\033[1;31m")
                    .replace("<lime>", "\033[1;32m")
                    .replace("<aqua>", "\033[1;36m")
                    .replace("<pink>", "\033[1;35m")
                    .replace("<yellow>", "\033[1;33m")
                    .replace("<blue>", "\033[1;34m")
                    .replace("<black>", "\033[0;0m")
                    .replace("<red>", "\033[0;31m")
                    .replace("<green>", "\033[0;32m")
                    .replace("<teal>", "\033[0;36m")
                    .replace("<navy>", "\033[0;34m")
                    .replace("<purple>", "\033[0;35m")
                    .replace("<gold>", "\033[0;33m")
                    .replace("<white>", "\033[1;37m")
                + "\033[0m";

    string =
        string
            .replace("`e", "")
            .replace("`r", ChatColor.RED.toString())
            .replace("`R", ChatColor.DARK_RED.toString())
            .replace("`y", ChatColor.YELLOW.toString())
            .replace("`Y", ChatColor.GOLD.toString())
            .replace("`g", ChatColor.GREEN.toString())
            .replace("`G", ChatColor.DARK_GREEN.toString())
            .replace("`a", ChatColor.AQUA.toString())
            .replace("`A", ChatColor.DARK_AQUA.toString())
            .replace("`b", ChatColor.BLUE.toString())
            .replace("`B", ChatColor.DARK_BLUE.toString())
            .replace("`p", ChatColor.LIGHT_PURPLE.toString())
            .replace("`P", ChatColor.DARK_PURPLE.toString())
            .replace("`k", ChatColor.BLACK.toString())
            .replace("`s", ChatColor.GRAY.toString())
            .replace("`S", ChatColor.DARK_GRAY.toString())
            .replace("`w", ChatColor.WHITE.toString());

    string =
        string
            .replace("<r>", "")
            .replace("<black>", "\u00A70")
            .replace("<navy>", "\u00A71")
            .replace("<green>", "\u00A72")
            .replace("<teal>", "\u00A73")
            .replace("<red>", "\u00A74")
            .replace("<purple>", "\u00A75")
            .replace("<gold>", "\u00A76")
            .replace("<silver>", "\u00A77")
            .replace("<gray>", "\u00A78")
            .replace("<blue>", "\u00A79")
            .replace("<lime>", "\u00A7a")
            .replace("<aqua>", "\u00A7b")
            .replace("<rose>", "\u00A7c")
            .replace("<pink>", "\u00A7d")
            .replace("<yellow>", "\u00A7e")
            .replace("<white>", "\u00A7f");

    return string;
  }