Beispiel #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);
    }
  }
Beispiel #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
 }
Beispiel #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";
   }
 }
  /**
   * 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;
  }
Beispiel #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";
   }
 }
 /**
  * Record the right clicking a sign.
  *
  * @param event
  */
 @EventHandler
 public void onPlayerInteract(PlayerInteractEvent event) {
   if (this.plugin.getDisabled().contains(event.getPlayer().getName())) return;
   if (!event.getPlayer().hasPermission("signfix.enable")) return;
   if (event.getAction() != Action.LEFT_CLICK_BLOCK) return;
   if (!event.getClickedBlock().getType().equals(Material.SIGN)
       && !event.getClickedBlock().getType().equals(Material.SIGN_POST)
       && !event.getClickedBlock().getType().equals(Material.WALL_SIGN)) return;
   this.plugin
       .getClicked()
       .put(event.getPlayer().getName(), (Sign) event.getClickedBlock().getState());
   event
       .getPlayer()
       .sendMessage(ChatColor.AQUA.toString() + "[SignFix] Selected the sign you've hit.");
 }
Beispiel #7
0
  @Override
  public boolean onCommand(
      CommandSender sender, Command command, String commandLabel, String[] args) {
    String commandName = command.getName().toLowerCase();

    args = groupArgs(args);
    if (sender instanceof Player) {
      if (commandName.equals("bb")) {
        if (args.length == 0) return false;

        String subcommandName = args[0].toLowerCase();

        if (!executors.containsKey(subcommandName)) return false;

        return executors.get(subcommandName).onCommand(sender, command, commandLabel, args);
      }
    } else if (sender instanceof ConsoleCommandSender) {
      if (commandName.equals("bb")) {
        ConsoleCommandSender console = (ConsoleCommandSender) sender;
        if (args.length == 0) {
          return false;
        } else if (args[0].equalsIgnoreCase("version")) {
          console.sendMessage(
              "You're running: "
                  + ChatColor.AQUA.toString()
                  + BigBrother.name
                  + " "
                  + BigBrother.version);
        } else if (args[0].equalsIgnoreCase("update")) {
          Updatr.updateAvailable(console);
        }
        return true;
      }
      return false;
    }
    return false;
  }
Beispiel #8
0
public class Helper {
  /** Value of Color.AQUA.toString() */
  public static String aqua = ChatColor.AQUA.toString();
  /** Value of Color.RED.toString() */
  public static String red = ChatColor.RED.toString();
  /**
   * Converts a string into Metadata
   *
   * @param value String value of Metadata to set
   * @return Value as FixedMetadataValue
   */
  public static FixedMetadataValue meta(String value) {
    return new FixedMetadataValue(Quarrymain.plugin, value);
  }
  /**
   * Converts an integer into Metadata
   *
   * @param value Integer value of Metadata to set
   * @return Value as FixedMetadataValue
   */
  public static FixedMetadataValue meta(int value) {
    return new FixedMetadataValue(Quarrymain.plugin, value);
  }
  /**
   * Converts a boolean value Metadata
   *
   * @param value Boolean value of the Metadata to set
   * @return Value as FixedMetadataValue
   */
  public static FixedMetadataValue meta(boolean value) {
    return new FixedMetadataValue(Quarrymain.plugin, value);
  }
  /**
   * Gets the string value from the block's metadata
   *
   * @param block Block to access data from
   * @param key MetadataKey of the value to access
   * @return Value of the key as a string
   */
  public static String getString(Block block, String key) {
    if (block.hasMetadata(key)) return block.getMetadata(key).get(0).asString();
    else return "";
  }
  /**
   * Gets the string value from the player's metadata
   *
   * @param player Player to access data from
   * @param key MetadataKey of the value to access
   * @return Value of the key as a string
   */
  public static String getString(Player player, String key) {
    if (player.hasMetadata(key)) return player.getMetadata(key).get(0).asString();
    else return "";
  }
  /**
   * Gets the integer value from the block's metadata
   *
   * @param block Block to access data from
   * @param key MetadataKey of the value to access
   * @return Value of the key as an integer
   */
  public static int getInt(Block block, String key) {
    if (block.hasMetadata(key)) return block.getMetadata(key).get(0).asInt();
    else return -1;
  }
  /**
   * Gets the integer value from the player's metadata
   *
   * @param player Player to access data from
   * @param key MetadataKey of the value to access
   * @return Value of the key as a integer
   */
  public static int getInt(Player player, String key) {
    if (player.hasMetadata(key)) return player.getMetadata(key).get(0).asInt();
    else return -1;
  }
  /**
   * Creates a new ItemStack of a material with a displayName
   *
   * @param type Material of the item
   * @param name DisplayName of the item
   * @return ItemStack that was created
   */
  public static ItemStack item(Material type, String name) {
    ItemStack item = new ItemStack(type);
    ItemMeta meta = item.getItemMeta();
    meta.setDisplayName(name);
    item.setItemMeta(meta);
    return item;
  }
  /**
   * Sends a message to the console as info
   *
   * @param message Message to send
   */
  public static void log(String message) {
    Logger.getLogger("Minecraft").info(message);
  }
  /**
   * Sends a message to the console as a red warning
   *
   * @param message Warning message to send
   */
  public static void warn(String message) {
    Logger.getLogger("Minecraft").warning(Helper.red + message);
  }
  /**
   * Organizes locations and gets least x,z and most x,z locations: Does not organize by sum of
   * coords but by whether or not the coord checked is greater in both the x and the z
   *
   * @param locs All locations to compare
   * @return Organized locations as {least, greatest}
   */
  public static Location[] organizeXZ(Location... locs) {
    Location greatest = locs[0];
    Location least = locs[0];
    for (Location loc : locs) {
      if (loc.getBlockX() > greatest.getBlockX() && loc.getBlockZ() > greatest.getBlockZ())
        greatest = loc;
      else if (loc.getBlockX() < greatest.getBlockX() && loc.getBlockZ() < greatest.getBlockZ())
        least = loc;
    }
    Location[] returnLoc = {least, greatest};
    return returnLoc;
  }
  /**
   * Converts a given location as a whole block to a string that is easily writable and readable
   *
   * @param loc The location to convert
   * @return The converted string as {world,x,y,z}
   */
  public static String toReadable(Location loc) {
    return String.format(
        "{%s,%s,%s,%s}",
        loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
  }
}
Beispiel #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;
  }
Beispiel #10
0
  /** Server Selector Listener */
  @EventHandler
  public void onInventoryClick(final InventoryClickEvent event) {
    if (event
        .getInventory()
        .getName()
        .contains(
            ChatColor.DARK_GREEN
                + SubPlugin.lang.get("Lang.GUI.Server-List-Title").replace("$Int$", ""))) {
      Player player = (Player) event.getWhoClicked();
      if (event.getCurrentItem() != null
          && event.getCurrentItem().getType() != Material.AIR
          && event.getCurrentItem().hasItemMeta()) {
        if (event
            .getCurrentItem()
            .getItemMeta()
            .getDisplayName()
            .equals(ChatColor.DARK_RED.toString() + SubPlugin.lang.get("Lang.GUI.Exit"))) {
          player.closeInventory();
        } else if (event
            .getCurrentItem()
            .getItemMeta()
            .getDisplayName()
            .equals(ChatColor.YELLOW.toString() + SubPlugin.lang.get("Lang.GUI.Back"))) {
          new SubGUI(
              player,
              (Integer.parseInt(
                      event
                          .getClickedInventory()
                          .getName()
                          .replace(
                              ChatColor.DARK_GREEN.toString()
                                  + SubPlugin.lang
                                      .get("Lang.GUI.Server-List-Title")
                                      .replace("$Int$", ""),
                              ""))
                  - 2),
              null,
              SubPlugin);
        } else if (event
            .getCurrentItem()
            .getItemMeta()
            .getDisplayName()
            .equals(ChatColor.YELLOW.toString() + SubPlugin.lang.get("Lang.GUI.Next"))) {
          new SubGUI(
              player,
              Integer.parseInt(
                  event
                      .getClickedInventory()
                      .getName()
                      .replace(
                          ChatColor.DARK_GREEN.toString()
                              + SubPlugin.lang
                                  .get("Lang.GUI.Server-List-Title")
                                  .replace("$Int$", ""),
                          "")),
              null,
              SubPlugin);
        } else if (!event
            .getCurrentItem()
            .getItemMeta()
            .getDisplayName()
            .equals(
                ChatColor.GRAY
                    + SubPlugin.Plugin.getDescription().getName()
                    + " v"
                    + SubPlugin.Plugin.getDescription().getVersion())) {
          new SubGUI(
              player,
              0,
              event
                  .getCurrentItem()
                  .getItemMeta()
                  .getDisplayName()
                  .replace(ChatColor.YELLOW.toString(), ""),
              SubPlugin);
        }
      }
      event.setCancelled(true);
    }

    /** Server Editor Listener */
    if (event
        .getInventory()
        .getName()
        .contains(ChatColor.DARK_GREEN + SubPlugin.lang.get("Lang.GUI.Server-Admin-Title"))) {
      final Player player = (Player) event.getWhoClicked();
      if (event.getCurrentItem() != null
          && event.getCurrentItem().getType() != Material.AIR
          && event.getCurrentItem().hasItemMeta()) {
        String displayName = event.getCurrentItem().getItemMeta().getDisplayName();
        if ((ChatColor.DARK_GREEN.toString() + SubPlugin.lang.get("Lang.GUI.Start"))
            .equals(displayName)) {
          if (player.hasPermission("SubServer.Command.start.*")
              || player.hasPermission(
                  "SubServer.Command.start."
                      + event
                          .getClickedInventory()
                          .getName()
                          .replace(
                              ChatColor.DARK_GREEN
                                  + SubPlugin.lang.get("Lang.GUI.Server-Admin-Title")
                                  + ChatColor.YELLOW,
                              ""))) {
            SubAPI.getSubServer(
                    event
                        .getClickedInventory()
                        .getName()
                        .replace(
                            ChatColor.DARK_GREEN
                                + SubPlugin.lang.get("Lang.GUI.Server-Admin-Title")
                                + ChatColor.YELLOW,
                            ""))
                .start((Player) event.getWhoClicked());
            final SubGUI SubGUI;
            (SubGUI = new SubGUI(SubPlugin))
                .openLoader(
                    player,
                    event
                        .getClickedInventory()
                        .getName()
                        .replace(
                            ChatColor.DARK_GREEN
                                + SubPlugin.lang.get("Lang.GUI.Server-Admin-Title")
                                + ChatColor.YELLOW,
                            ""),
                    "openServerWindow");
            new BukkitRunnable() {
              @Override
              public void run() {
                try {
                  Thread.sleep(1500);
                } catch (InterruptedException e) {
                  e.printStackTrace();
                }
                SubAPI.getSubServer(
                            event
                                .getClickedInventory()
                                .getName()
                                .replace(
                                    ChatColor.DARK_GREEN
                                        + SubPlugin.lang.get("Lang.GUI.Server-Admin-Title")
                                        + ChatColor.YELLOW,
                                    ""))
                        .Running =
                    true;
                SubGUI.stopLoader = true;
              }
            }.runTaskAsynchronously(SubPlugin.Plugin);
          }
        } else if ((ChatColor.RED.toString() + SubPlugin.lang.get("Lang.GUI.Stop"))
            .equals(displayName)) {
          if (player.hasPermission("SubServer.Command.stop.*")
              || player.hasPermission(
                  "SubServer.Command.stop."
                      + event
                          .getClickedInventory()
                          .getName()
                          .replace(
                              ChatColor.DARK_GREEN
                                  + SubPlugin.lang.get("Lang.GUI.Server-Admin-Title")
                                  + ChatColor.YELLOW,
                              ""))) {
            SubAPI.getSubServer(
                    event
                        .getClickedInventory()
                        .getName()
                        .replace(
                            ChatColor.DARK_GREEN
                                + SubPlugin.lang.get("Lang.GUI.Server-Admin-Title")
                                + ChatColor.YELLOW,
                            ""))
                .stop((Player) event.getWhoClicked());
            final SubGUI SubGUI;
            (SubGUI = new SubGUI(SubPlugin))
                .openLoader(
                    player,
                    event
                        .getClickedInventory()
                        .getName()
                        .replace(
                            ChatColor.DARK_GREEN
                                + SubPlugin.lang.get("Lang.GUI.Server-Admin-Title")
                                + ChatColor.YELLOW,
                            ""),
                    "openServerWindow");
            new BukkitRunnable() {
              @Override
              public void run() {
                try {
                  Thread.sleep(1500);
                } catch (InterruptedException e) {
                  e.printStackTrace();
                }
                SubAPI.getSubServer(
                            event
                                .getClickedInventory()
                                .getName()
                                .replace(
                                    ChatColor.DARK_GREEN
                                        + SubPlugin.lang.get("Lang.GUI.Server-Admin-Title")
                                        + ChatColor.YELLOW,
                                    ""))
                        .Running =
                    false;
                SubGUI.stopLoader = true;
              }
            }.runTaskAsynchronously(SubPlugin.Plugin);
          }
        } else if ((ChatColor.DARK_RED.toString() + SubPlugin.lang.get("Lang.GUI.Terminate"))
            .equals(displayName)) {
          if (player.hasPermission("SubServer.Command.kill.*")
              || player.hasPermission(
                  "SubServer.Command.kill."
                      + event
                          .getClickedInventory()
                          .getName()
                          .replace(
                              ChatColor.DARK_GREEN
                                  + SubPlugin.lang.get("Lang.GUI.Server-Admin-Title")
                                  + ChatColor.YELLOW,
                              ""))) {
            SubAPI.getSubServer(
                    event
                        .getClickedInventory()
                        .getName()
                        .replace(
                            ChatColor.DARK_GREEN
                                + SubPlugin.lang.get("Lang.GUI.Server-Admin-Title")
                                + ChatColor.YELLOW,
                            ""))
                .terminate((Player) event.getWhoClicked());
            final SubGUI SubGUI;
            (SubGUI = new SubGUI(SubPlugin))
                .openLoader(
                    player,
                    event
                        .getClickedInventory()
                        .getName()
                        .replace(
                            ChatColor.DARK_GREEN
                                + SubPlugin.lang.get("Lang.GUI.Server-Admin-Title")
                                + ChatColor.YELLOW,
                            ""),
                    "openServerWindow");
            new BukkitRunnable() {
              @Override
              public void run() {
                try {
                  Thread.sleep(500);
                } catch (InterruptedException e) {
                  e.printStackTrace();
                }
                SubGUI.stopLoader = true;
                SubAPI.getSubServer(
                            event
                                .getClickedInventory()
                                .getName()
                                .replace(
                                    ChatColor.DARK_GREEN
                                        + SubPlugin.lang.get("Lang.GUI.Server-Admin-Title")
                                        + ChatColor.YELLOW,
                                    ""))
                        .Running =
                    false;
                new SubGUI(
                    player,
                    0,
                    event
                        .getClickedInventory()
                        .getName()
                        .replace(
                            ChatColor.DARK_GREEN
                                + SubPlugin.lang.get("Lang.GUI.Server-Admin-Title")
                                + ChatColor.YELLOW,
                            ""),
                    SubPlugin);
              }
            }.runTaskAsynchronously(SubPlugin.Plugin);
          }
        } else if ((ChatColor.RED.toString() + SubPlugin.lang.get("Lang.GUI.Back"))
            .equals(displayName)) {
          player.closeInventory();
          int i =
              (int)
                  Math.floor(
                      SubPlugin.SubServers.indexOf(
                              event
                                  .getClickedInventory()
                                  .getName()
                                  .replace(
                                      ChatColor.DARK_GREEN
                                          + SubPlugin.lang.get("Lang.GUI.Server-Admin-Title")
                                          + ChatColor.YELLOW,
                                      ""))
                          / 18);
          new SubGUI(player, i, null, SubPlugin);
        } else if ((ChatColor.DARK_RED.toString() + SubPlugin.lang.get("Lang.GUI.Exit"))
            .equals(displayName)) {
          player.closeInventory();
        } else if ((ChatColor.AQUA.toString() + SubPlugin.lang.get("Lang.GUI.Send-CMD"))
            .equals(displayName)) {
          if (player.hasPermission("SubServer.Command.send.*")
              || player.hasPermission(
                  "SubServer.Command.send."
                      + event
                          .getClickedInventory()
                          .getName()
                          .replace(
                              ChatColor.DARK_GREEN
                                  + SubPlugin.lang.get("Lang.GUI.Server-Admin-Title")
                                  + ChatColor.YELLOW,
                              ""))) {
            player.closeInventory();
            final SubGUIChat chat = new SubGUIChat(player, SubPlugin);
            chat.chatEnabled = false;
            player.sendMessage(
                ChatColor.AQUA + SubPlugin.lprefix + SubPlugin.lang.get("Lang.GUI.Enter-CMD"));
            new BukkitRunnable() {
              @Override
              public void run() {
                try {
                  do {
                    Thread.sleep(25);
                  } while (chat.chatEnabled == false);
                } catch (InterruptedException e) {
                  e.printStackTrace();
                }

                SubAPI.getSubServer(
                        event
                            .getClickedInventory()
                            .getName()
                            .replace(
                                ChatColor.DARK_GREEN
                                    + SubPlugin.lang.get("Lang.GUI.Server-Admin-Title")
                                    + ChatColor.YELLOW,
                                ""))
                    .sendCommand((Player) event.getWhoClicked(), chat.chatText);
                chat.chatText = "";
                new SubGUI(SubPlugin)
                    .openSentCommand(
                        player,
                        event
                            .getClickedInventory()
                            .getName()
                            .replace(
                                ChatColor.DARK_GREEN
                                    + SubPlugin.lang.get("Lang.GUI.Server-Admin-Title")
                                    + ChatColor.YELLOW,
                                ""));
              }
            }.runTaskAsynchronously(SubPlugin.Plugin);
          }
        } else if ((ChatColor.DARK_GREEN.toString() + SubPlugin.lang.get("Lang.GUI.Online"))
            .equals(displayName)) {
          String server =
              event
                  .getClickedInventory()
                  .getName()
                  .replace(
                      ChatColor.DARK_GREEN
                          + SubPlugin.lang.get("Lang.GUI.Server-Admin-Title")
                          + ChatColor.YELLOW,
                      "");
          if ((player.hasPermission("SubServer.Command.teleport." + server)
                  || player.hasPermission("SubServer.Command.teleport.*"))
              && !server.equalsIgnoreCase("~Proxy")) {
            player.closeInventory();
            SubAPI.getSubServer(server).sendPlayer(player);
          }
        }
      }
      event.setCancelled(true);
    }

    /** Other Listeners */
    if (event
        .getInventory()
        .getName()
        .contains(ChatColor.DARK_GREEN + SubPlugin.lang.get("Lang.GUI.Success"))) {
      final Player player = (Player) event.getWhoClicked();
      if (event.getCurrentItem() != null
          && event.getCurrentItem().getType() != Material.AIR
          && event.getCurrentItem().hasItemMeta()) {
        player.closeInventory();
        new SubGUI(
            player,
            0,
            event
                .getClickedInventory()
                .getName()
                .replace(
                    ChatColor.DARK_GREEN
                        + SubPlugin.lang.get("Lang.GUI.Success")
                        + ChatColor.YELLOW,
                    ""),
            SubPlugin);
      }
      event.setCancelled(true);
    }
    if (event.getInventory().getName().equals(SubPlugin.lang.get("Lang.GUI.Loading"))) {
      event.setCancelled(true);
    }

    /** Seecret Listener */
    if (event.getInventory().getName().contains(":S:")) {
      if (event.getCurrentItem() != null
          && event.getCurrentItem().getType() != Material.AIR
          && event.getClickedInventory().contains(event.getCurrentItem())) {
        new SubGUI(SubPlugin).openSeecretWindow((Player) event.getWhoClicked());
        event.setCancelled(true);
      }
    }
  }
Beispiel #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;
  }