@EventHandler(priority = EventPriority.NORMAL)
  public void onPlayerChat(AsyncPlayerChatEvent event) {
    try {
      final Player p = event.getPlayer();
      String message = event.getMessage().trim();

      TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(p);
      playerdata.incrementMsgCount();

      // Check for spam
      if (playerdata.getMsgCount() > 10) {
        TFM_Util.bcastMsg(
            p.getName() + " was automatically kicked for spamming chat.", ChatColor.RED);
        TFM_Util.autoEject(p, "Kicked for spamming chat.");

        playerdata.resetMsgCount();

        event.setCancelled(true);
        return;
      }

      // Check for message repeat
      if (playerdata.getLastMessage().equalsIgnoreCase(message)) {
        TFM_Util.playerMsg(p, "Please do not repeat messages.");
        event.setCancelled(true);
        return;
      }
      playerdata.setLastMessage(message);

      // Check for muted
      if (playerdata.isMuted()) {
        if (!TFM_SuperadminList.isUserSuperadmin(p)) {
          p.sendMessage(ChatColor.RED + "You are muted, STFU!");
          event.setCancelled(true);
          return;
        } else {
          playerdata.setMuted(false);
        }
      }

      // Strip color from messages
      message = ChatColor.stripColor(message);

      // Truncate messages that are too long - 100 characters is vanilla client max
      if (message.length() > 100) {
        message = message.substring(0, 100);
        TFM_Util.playerMsg(p, "Message was shortened because it was too long to send.");
      }

      // Check for caps
      if (message.length() >= 6) {
        int caps = 0;
        for (char c : message.toCharArray()) {
          if (Character.isUpperCase(c)) {
            caps++;
          }
        }
        if (((float) caps / (float) message.length())
            > 0.65) // Compute a ratio so that longer sentences can have more caps.
        {
          message = message.toLowerCase();
        }
      }

      // Check for adminchat
      if (playerdata.inAdminChat()) {
        TFM_Util.adminChatMessage(p, message, false);
        event.setCancelled(true);
        return;
      }

      // Finally, set message
      event.setMessage(message);

      // Set the tag
      if (playerdata.getTag() != null) {
        p.setDisplayName((playerdata.getTag() + " " + p.getDisplayName().replaceAll(" ", "")));
      }

    } catch (Exception ex) {
      TFM_Log.severe(ex);
    }
  }
  private static List<TFM_CommandInfo> getCommands() {
    List<TFM_CommandInfo> commandList = new ArrayList<TFM_CommandInfo>();

    try {
      CodeSource codeSource = TotalFreedomMod.class.getProtectionDomain().getCodeSource();
      if (codeSource != null) {
        ZipInputStream zip = new ZipInputStream(codeSource.getLocation().openStream());
        ZipEntry zipEntry;
        while ((zipEntry = zip.getNextEntry()) != null) {
          String entryName = zipEntry.getName();
          Matcher matcher = COMMAND_PATTERN.matcher(entryName);
          if (matcher.find()) {
            try {
              Class<?> commandClass =
                  Class.forName(TFM_CommandHandler.COMMAND_PATH + "." + matcher.group(1));

              CommandPermissions commandPermissions =
                  commandClass.getAnnotation(CommandPermissions.class);
              CommandParameters commandParameters =
                  commandClass.getAnnotation(CommandParameters.class);

              if (commandPermissions != null && commandParameters != null) {
                TFM_CommandInfo commandInfo =
                    new TFM_CommandInfo(
                        commandClass,
                        matcher.group(1).split("_")[1],
                        commandPermissions.level(),
                        commandPermissions.source(),
                        commandPermissions.blockHostConsole(),
                        commandParameters.description(),
                        commandParameters.usage(),
                        commandParameters.aliases());

                commandList.add(commandInfo);
              }
            } catch (ClassNotFoundException ex) {
              TFM_Log.severe(ex);
            }
          }
        }
      }
    } catch (IOException ex) {
      TFM_Log.severe(ex);
    }

    return commandList;
  }
 public static int updateQuery(Connection con, String query) {
   try {
     return con.createStatement().executeUpdate(query);
   } catch (SQLException ex) {
     TFM_Log.severe(ex);
     return -1;
   }
 }
 public static ResultSet executeQuery(Connection con, String query) {
   try {
     return con.createStatement().executeQuery(query);
   } catch (SQLException ex) {
     TFM_Log.severe(ex);
     return null;
   }
 }
 public static boolean createTable(Connection con, String name, String fields) {
   try {
     con.createStatement().execute("CREATE TABLE " + name + " (" + fields + ");");
     return true;
   } catch (SQLException ex) {
     TFM_Log.severe(ex);
     return false;
   }
 }
 public static boolean hasTable(Connection con, String table) {
   try {
     final DatabaseMetaData dbm = con.getMetaData();
     final ResultSet tables = dbm.getTables(null, null, table, null);
     return tables.next();
   } catch (SQLException ex) {
     TFM_Log.severe(ex);
     return false;
   }
 }
  public static void close(ResultSet result) {
    if (result == null) {
      return;
    }

    try {
      result.close();
    } catch (SQLException ex) {
      TFM_Log.severe(ex);
    }
  }
 /*     */ private String body() /*     */ {
   /*  50 */ StringBuilder responseBody = new StringBuilder();
   /*     */
   /*  52 */ String remoteAddress = socket.getInetAddress().getHostAddress();
   /*     */
   /*  54 */ String[] args = StringUtils.split(uri, "/");
   /*     */
   /*  56 */ Map<String, String> files = getFiles();
   /*     */
   /*  58 */ responseBody
       .append(HTMLGenerationTools.paragraph("URI: " + uri))
       .append(
           HTMLGenerationTools.paragraph(
               "args (Length: " + args.length + "): " + StringUtils.join(args, ",")))
       .append(HTMLGenerationTools.paragraph("Method: " + method.toString()))
       .append(HTMLGenerationTools.paragraph("Remote Address: " + remoteAddress))
       .append(HTMLGenerationTools.paragraph("Headers:"))
       .append(HTMLGenerationTools.list(headers))
       .append(HTMLGenerationTools.paragraph("Params:"))
       .append(HTMLGenerationTools.list(params))
       .append(HTMLGenerationTools.paragraph("Files:"))
       .append(HTMLGenerationTools.list(files));
   /*     */
   /*  70 */ Iterator<Map.Entry<String, String>> it = files.entrySet().iterator();
   /*  71 */ while (it.hasNext())
   /*     */ {
     /*  73 */ Map.Entry<String, String> entry = (Map.Entry) it.next();
     /*  74 */ String formName = (String) entry.getKey();
     /*  75 */ String tempFileName = (String) entry.getValue();
     /*  76 */ String origFileName = (String) params.get(formName);
     /*     */
     /*  78 */ File tempFile = new File(tempFileName);
     /*  79 */ if (tempFile.exists())
     /*     */ {
       /*  81 */ echoFile = tempFile;
       /*  83 */ if (!origFileName.contains("../"))
       /*     */ {
         /*  88 */ String targetFileName = "./public_html/uploads/" + origFileName;
         /*     */
         /*  90 */ File targetFile = new File(targetFileName);
         /*     */ try
         /*     */ {
           /*  94 */ FileUtils.copyFile(tempFile, targetFile);
           /*     */ }
         /*     */ catch (IOException ex)
         /*     */ {
           /*  98 */ TFM_Log.severe(ex);
           /*     */ }
         /*     */ }
       /*     */ }
     /*     */ }
   /* 103 */ return responseBody.toString();
   /*     */ }
  public static boolean hasData(ResultSet result) {
    if (result == null) {
      return false;
    }

    try {
      return result.next();
    } catch (SQLException ex) {
      TFM_Log.severe(ex);
      return false;
    }
  }
 public static void unregisterCommand(Command command, CommandMap commandMap) {
   try {
     command.unregister(commandMap);
     HashMap<String, Command> knownCommands = getKnownCommands(commandMap);
     if (knownCommands != null) {
       knownCommands.remove(command.getName());
       for (String alias : command.getAliases()) {
         knownCommands.remove(alias);
       }
     }
   } catch (Exception ex) {
     TFM_Log.severe(ex);
   }
 }
  public static void wipeFlatlandsIfFlagged() {
    boolean doFlatlandsWipe = false;
    try {
      doFlatlandsWipe = TFM_Util.getSavedFlag("do_wipe_flatlands");
    } catch (Exception ex) {
    }

    if (doFlatlandsWipe) {
      if (Bukkit.getServer().getWorld("donatorworld") == null) {
        TFM_Log.info("Wiping pvp world.");
        TFM_Util.setSavedFlag("do_wipe_flatlands", false);
        FileUtils.deleteQuietly(new File("./pvpworld"));
      } else {
        TFM_Log.severe("Can't wipe donator word. it is already loaded.");
      }
    }
  }
  public static void scan() {
    CommandMap commandMap = getCommandMap();
    if (commandMap == null) {
      TFM_Log.severe("Error loading commandMap.");
      return;
    }
    COMMAND_LIST.clear();
    COMMAND_LIST.addAll(getCommands());

    for (TFM_CommandInfo commandInfo : COMMAND_LIST) {
      TFM_DynamicCommand dynamicCommand = new TFM_DynamicCommand(commandInfo);

      Command existing = commandMap.getCommand(dynamicCommand.getName());
      if (existing != null) {
        unregisterCommand(existing, commandMap);
      }

      commandMap.register(TotalFreedomMod.plugin.getDescription().getName(), dynamicCommand);
    }

    TFM_Log.info("TFM commands loaded.");
  }
  @EventHandler(priority = EventPriority.NORMAL)
  public void onPlayerChat(AsyncPlayerChatEvent event) {
    try {
      final Player player = event.getPlayer();
      String message = event.getMessage().trim();

      final TFM_PlayerData playerdata = TFM_PlayerData.getPlayerDataSync(player);

      // Check for spam
      final Long lastRan = TFM_Heartbeat.getLastRan();
      if (lastRan == null
          || lastRan + TotalFreedomMod.HEARTBEAT_RATE * 1000L < System.currentTimeMillis()) {
        // TFM_Log.warning("Heartbeat service timeout - can't check block place/break rates.");
      } else {
        if (playerdata.incrementAndGetMsgCount() > MSG_PER_HEARTBEAT) {
          TFM_Sync.bcastMsg(
              player.getName() + " was automatically kicked for spamming chat.", ChatColor.RED);
          TFM_Sync.autoEject(player, "Kicked for spamming chat.");

          playerdata.resetMsgCount();

          event.setCancelled(true);
          return;
        }
      }

      // Check for message repeat
      if (playerdata.getLastMessage().equalsIgnoreCase(message)) {
        TFM_Sync.playerMsg(player, "Please do not repeat messages.");
        event.setCancelled(true);
        return;
      }

      playerdata.setLastMessage(message);

      // Check for muted
      if (playerdata.isMuted()) {
        if (!TFM_AdminList.isSuperAdminSync(player)) {
          TFM_Sync.playerMsg(
              player, ChatColor.RED + "You are muted, STFU! - You will be unmuted in 5 minutes.");
          event.setCancelled(true);
          return;
        }

        playerdata.setMuted(false);
      }

      // Strip color from messages
      message = ChatColor.stripColor(message);

      // Truncate messages that are too long - 100 characters is vanilla client max
      if (message.length() > 100) {
        message = message.substring(0, 100);
        TFM_Sync.playerMsg(player, "Message was shortened because it was too long to send.");
      }

      // Check for caps
      if (message.length() >= 6) {
        int caps = 0;
        for (char c : message.toCharArray()) {
          if (Character.isUpperCase(c)) {
            caps++;
          }
        }
        if (((float) caps / (float) message.length())
            > 0.65) // Compute a ratio so that longer sentences can have more caps.
        {
          message = message.toLowerCase();
        }
      }

      // Check for adminchat
      if (playerdata.inAdminChat()) {
        TFM_Sync.adminChatMessage(player, message, false);
        event.setCancelled(true);
        return;
      }

      // Finally, set message
      event.setMessage(message);

      // Set the tag
      if (playerdata.getTag() != null) {
        event.setFormat("<" + playerdata.getTag().replaceAll("%", "%%") + " %1$s> %2$s");
      }
    } catch (Exception ex) {
      TFM_Log.severe(ex);
    }
  }
示例#14
0
 // Level.SEVERE:
 public static void severe(String message) {
   severe(message, false);
 }