Ejemplo n.º 1
0
 @Override
 public boolean onCommand(
     final CommandSender sender, final Command cmd, final String label, final String args[]) {
   if (cmd.getName().equalsIgnoreCase("punish")) {
     if (args.length < 2) {
       sender.sendMessage(ChatColor.RED + "Not enough parameters!");
       sender.sendMessage(ChatColor.RED + "Usage: /punish [@]<player> <reason>");
     } else {
       Boolean pOffline = false;
       String ofpl = "";
       if (args[0].startsWith("@")) {
         pOffline = true;
         StringBuilder sb = new StringBuilder();
         sb.append(args[0]);
         sb.deleteCharAt(0);
         ofpl = sb.toString();
         ofpl = StringEscapeUtils.escapeSql(ofpl);
       } else if (plugin.getServer().getPlayer(args[0]) == null) {
         sender.sendMessage(
             args[0] + " is not online! Use /p @<player> to punish offline players!");
         return true;
       }
       ArrayList<String> arguments = new ArrayList<String>();
       for (String s : args) {
         if (s != args[0]) arguments.add(s);
       }
       if (pOffline && sender instanceof Player) {
         Player player = (Player) sender;
         punishOffline(
             sender.getName(),
             StringEscapeUtils.escapeSql(player.getDisplayName()),
             ofpl,
             arguments);
       } else if (pOffline && sender instanceof ConsoleCommandSender) {
         punishOffline("(console)", ChatColor.GOLD + "(console)", ofpl, arguments);
       } else if (!pOffline && sender instanceof Player) {
         Player player = (Player) sender;
         punish(
             sender.getName(),
             StringEscapeUtils.escapeSql(player.getDisplayName()),
             plugin.getServer().getPlayer(args[0]).getName(),
             plugin.getServer().getPlayer(args[0]).getDisplayName(),
             arguments);
       } else if (!pOffline && sender instanceof ConsoleCommandSender) {
         punish(
             "(console)",
             ChatColor.GOLD + "(console)",
             plugin.getServer().getPlayer(args[0]).getName(),
             plugin.getServer().getPlayer(args[0]).getDisplayName(),
             arguments);
       }
     }
     return true;
   }
   return false;
 }
Ejemplo n.º 2
0
 public void permaBanOffline(
     String punisher, String punisherDisplay, String punished, ArrayList<String> arguments) {
   try {
     String reason = "";
     for (String s : arguments) {
       reason += s + " ";
     }
     long time = System.currentTimeMillis() / 1000L;
     UUID UUID = plugin.getServer().getOfflinePlayer(punished).getUniqueId();
     plugin.sqlite.insert(
         "INSERT INTO punishments (punisher, punished, reason, type, time, expiry, active, server, UUID) VALUES ('"
             + punisher
             + "','"
             + punished
             + "','"
             + StringEscapeUtils.escapeSql(reason)
             + "','ban','"
             + time
             + "','0','1','"
             + Bans.server
             + "','"
             + UUID
             + "');");
     for (Player plr : plugin.getServer().getOnlinePlayers()) {
       plr.sendMessage(
           ChatColor.DARK_AQUA
               + punisherDisplay
               + ChatColor.YELLOW
               + " -> "
               + ChatColor.GOLD
               + "Permanent ban"
               + ChatColor.YELLOW
               + " -> "
               + ChatColor.DARK_AQUA
               + punished
               + ChatColor.YELLOW
               + " -> "
               + ChatColor.GOLD
               + reason);
     }
     plugin.addBan(UUID, reason, time, 0);
   } catch (SQLException e) {
     plugin.getLogger().severe(e.getMessage());
   }
 }
Ejemplo n.º 3
0
  public void punishOffline(
      String punisher, String punisherDisplay, String punished, ArrayList<String> arguments) {
    String reason = "";
    for (String s : arguments) {
      reason += s + " ";
    }
    try {
      ResultSet result =
          plugin.sqlite.query(
              ("SELECT * FROM punishments WHERE punished='" + punished + "' AND active=1;"));
      Boolean kicked = false;
      Boolean banned = false;
      while (result.next()) {
        String type = result.getString("type");
        if (type.equals("ban") || type.equals("tempban")) {
          banned = true;
        } else if (type.equals("kick")) {
          kicked = true;
        }
      }
      long time = System.currentTimeMillis() / 1000L;
      long expiry = time + (86400 * 7);
      UUID UUID = plugin.getServer().getOfflinePlayer(punished).getUniqueId();
      if (banned) {

        plugin.sqlite.insert(
            "INSERT INTO punishments (punisher, punished, reason, type, time, expiry, active, server, UUID) VALUES ('"
                + punisher
                + "','"
                + punished
                + "','"
                + StringEscapeUtils.escapeSql(reason)
                + "','ban','"
                + time
                + "','0','1','"
                + Bans.server
                + "','"
                + UUID
                + "');");
        for (Player plr : plugin.getServer().getOnlinePlayers()) {
          plr.sendMessage(
              ChatColor.DARK_AQUA
                  + punisherDisplay
                  + ChatColor.YELLOW
                  + " -> "
                  + ChatColor.GOLD
                  + "Permanent ban"
                  + ChatColor.YELLOW
                  + " -> "
                  + ChatColor.DARK_AQUA
                  + punished
                  + ChatColor.YELLOW
                  + " -> "
                  + ChatColor.GOLD
                  + reason);
        }
        plugin.addBan(UUID, reason, time, 0);
      } else if (kicked) {
        plugin.sqlite.insert(
            "INSERT INTO punishments (punisher, punished, reason, type, time, expiry, active, server, UUID) VALUES ('"
                + punisher
                + "','"
                + punished
                + "','"
                + StringEscapeUtils.escapeSql(reason)
                + "','tempban','"
                + time
                + "','"
                + expiry
                + "','1','"
                + Bans.server
                + "','"
                + UUID
                + "');");
        for (Player plr : plugin.getServer().getOnlinePlayers()) {
          plr.sendMessage(
              ChatColor.DARK_AQUA
                  + punisherDisplay
                  + ChatColor.YELLOW
                  + " -> "
                  + ChatColor.GOLD
                  + "7 day ban"
                  + ChatColor.YELLOW
                  + " -> "
                  + ChatColor.DARK_AQUA
                  + punished
                  + ChatColor.YELLOW
                  + " -> "
                  + ChatColor.GOLD
                  + reason);
        }
        plugin.addBan(UUID, reason, time, expiry);
      } else {
        plugin.sqlite.insert(
            "INSERT INTO punishments (punisher, punished, reason, type, time, active, server, UUID) VALUES ('"
                + punisher
                + "','"
                + punished
                + "','"
                + StringEscapeUtils.escapeSql(reason)
                + "','kick','"
                + time
                + "','1','"
                + Bans.server
                + "','"
                + UUID
                + "');");
        for (Player plr : plugin.getServer().getOnlinePlayers()) {
          plr.sendMessage(
              punisherDisplay
                  + ChatColor.YELLOW
                  + " -> "
                  + ChatColor.GOLD
                  + "Kick"
                  + ChatColor.YELLOW
                  + " -> "
                  + ChatColor.DARK_AQUA
                  + punished
                  + ChatColor.YELLOW
                  + " -> "
                  + ChatColor.GOLD
                  + reason);
        }
      }
    } catch (SQLException e) {
      plugin.getLogger().severe(e.getMessage());
    }
  }