예제 #1
0
 protected static void Log(Level loglevel, Exception err, boolean sendReport) {
   logger.log(
       loglevel,
       String.format("[%s] %s", name, err == null ? "? unknown exception ?" : err.getMessage()),
       err);
   if (config != null) {
     if (sendReport && loglevel.intValue() > Level.WARNING.intValue() && config.sendErrorReports) {
       sendErrorReport(null, err);
     }
     if (messenger != null
         && loglevel.intValue() > Level.INFO.intValue()
         && config.sendLogOnError) {
       messenger.sendNotify(
           String.format(
               "[%s] %s%n%s",
               name,
               err == null ? "? unknown exception ?" : err.getMessage(),
               Str.getStackStr(err)));
     }
   }
 }
예제 #2
0
 protected static void Log(Level loglevel, String txt, Exception params, boolean sendReport) {
   if (txt == null) {
     Log(loglevel, params);
   } else {
     logger.log(
         loglevel, String.format("[%s] %s", name, txt == null ? "" : txt), (Exception) params);
     if (config != null) {
       if (sendReport
           && loglevel.intValue() > Level.WARNING.intValue()
           && config.sendErrorReports) {
         sendErrorReport(txt, params);
       }
       if (messenger != null
           && loglevel.intValue() > Level.INFO.intValue()
           && config.sendLogOnError) {
         messenger.sendNotify(
             String.format(
                 "[%s] %s%n%s", name, txt, params.getMessage(), Str.getStackStr(params)));
       }
     }
   }
 }
예제 #3
0
  static void sendErrorReport(String txt, Exception err) {
    boolean allow = false;
    long now = (new Date()).getTime();
    for (int i = 0; i < sentErrors.length; ++i) {
      if (sentErrors[i] == null || (now - sentErrors[i].getTime()) / 1000 >= minSendWait) {
        sentErrors[i] = new Date();
        allow = true;
        break;
      }
    }
    if (allow) {
      int pcount = -1;
      if (pricelist != null) {
        try {
          pcount = pricelist.getItems(true).length;
        } catch (Exception ex) {
        }
      }

      String fname =
          FTPErrorReporter.SendNewText(
              "BetterShop Error Report at "
                  + (new Date()).toString()
                  + "\n"
                  + "SUID: "
                  + ServerInfo.serverUID(
                      config != null ? !config.unMaskErrorID : true, BSConfig.MAX_CUSTMSG_LEN)
                  + "\n"
                  + (config != null
                      ? (config.customErrorMessage.length() > 0
                          ? config.customErrorMessage + "\n"
                          : "")
                      : "")
                  + "Machine: "
                  + System.getProperty("os.name")
                  + " "
                  + System.getProperty("os.arch") /* + "," + System.getProperty("user.dir")*/
                  + "\n"
                  + "Bukkit: "
                  + ServerInfo.getBukkitVersion(true)
                  + "\n"
                  + "Version: "
                  + pdfFile.getVersion()
                  + "  ("
                  + lastUpdatedStr
                  + ")\n"
                  + "iConomy: "
                  + (iConomy != null ? ((Plugin) iConomy).getDescription().getVersion() : "none")
                  + "\n"
                  + "Permissions: "
                  + (Permissions != null ? "true" : "false")
                  + "\n"
                  + "Last executed command: "
                  + lastCommand
                  + "\n"
                  + (config != null ? config.condensedSettings() : "-")
                  + ","
                  + (pcount >= 0 ? pcount : "-")
                  + "\n"
                  + "Message: "
                  + (txt != null
                      ? txt
                      : err.getMessage() != null && err.getMessage().length() > 0
                          ? err.getMessage()
                          : "")
                  + "\n"
                  + (err.getLocalizedMessage() != null
                          && err.getLocalizedMessage().length() > 0
                          && (err.getMessage() == null
                              || !err.getMessage().equals(err.getLocalizedMessage()))
                      ? err.getLocalizedMessage() + "\n"
                      : "")
                  + Str.getStackStr(err)
                  + "\n");
      if (fname != null && fname.length() > 0) {
        System.out.println("report sent. id: " + fname);
      } else {
        System.out.println(
            "Error report unable to send.. is the server online & BetterShop up-to-date?");
        System.out.println("(if yes, then the error tracker is likely temporarily offline)");
      }
    } // else {  System.out.println("sending too fast.."); }
  }
예제 #4
0
  @Override
  public boolean onCommand(
      CommandSender sender, Command command, String commandLabel, String[] args) {
    String commandName = command.getName().toLowerCase();
    try {

      lastCommand =
          (sender instanceof Player ? "player:" : "console:")
              + commandName
              + " "
              + Str.argStr(args);

      // i don't like seeing these messages all the time..
      // Log(((Player) sender).getName() + " used command " + command.getName());

      if (BetterShop.iConomy == null && BetterShop.economy == null) {
        BSutils.sendMessage(
            sender, "\u00A74 BetterShop is missing a dependency. Check the console.");
        Log(Level.SEVERE, "Missing: iConomy or BOSEconomy", false);
        return true;
      }

      if (stock != null && config.useItemStock) {
        stock.checkStockRestock();
      }

      if (commandName.equals("shop")) {
        if (args.length > 0) {
          if (args[0].equalsIgnoreCase("list")) {
            commandName = "shoplist";
          } else if (args[0].equalsIgnoreCase("help") || args[0].equalsIgnoreCase("?")) {
            commandName = "shophelp";
          } else if (args[0].equalsIgnoreCase("buy")) {
            commandName = "shopbuy";
          } else if (args[0].equalsIgnoreCase("sell")) {
            commandName = "shopsell";
          } else if (args[0].equalsIgnoreCase("add")) {
            commandName = "shopadd";
          } else if (args[0].equalsIgnoreCase("remove")) {
            commandName = "shopremove";
          } else if (args[0].equalsIgnoreCase("load") || args[0].equalsIgnoreCase("reload")) {
            commandName = "shopload";
          } else if (args[0].equalsIgnoreCase("check")) {
            commandName = "shopcheck";
          } else if (args[0].equalsIgnoreCase("sellall")) {
            commandName = "shopsellall";
          } else if (args[0].equalsIgnoreCase("sellstack")) {
            commandName = "shopsellstack";
          } else if (args[0].equalsIgnoreCase("buystack")) {
            commandName = "shopbuystack";
          } else if (args[0].equalsIgnoreCase("buyall")) {
            commandName = "shopbuyall";
          } else if (args[0].equalsIgnoreCase("sellagain")) {
            commandName = "shopsellagain";
          } else if (args[0].equalsIgnoreCase("buyagain")) {
            commandName = "shopbuyagain";
          } else if (args[0].equalsIgnoreCase("listkits")) {
            commandName = "shoplistkits";
          } else if (args[0].equalsIgnoreCase("restock")) {
            if (BSutils.hasPermission(sender, BSutils.BetterShopPermission.ADMIN_RESTOCK, true)) {
              stock.Restock(true);
              sender.sendMessage("Stock set to initial values");
            }
          } else if (args[0].equalsIgnoreCase("backup")) {
            if (BSutils.hasPermission(sender, BSutils.BetterShopPermission.ADMIN_BACKUP, true)) {
              SimpleDateFormat formatter = new SimpleDateFormat("_yyyy_MM_dd_HH-mm-ss");
              String backFname =
                  BSConfig.pluginFolder.getPath()
                      + File.separatorChar
                      + config.tableName
                      + formatter.format(new java.util.Date())
                      + ".csv";
              try {
                if (pricelist.saveFile(new File(backFname))) {
                  sender.sendMessage("Backup saved as " + backFname);
                }
              } catch (IOException ex) {
                Log(Level.SEVERE, "Failed to save backup file " + backFname, ex);
                sender.sendMessage("\u00A74Failed to save backup file " + backFname);
              }
            }
            return true;
          } else if (args[0].equalsIgnoreCase("import")) {
            return bscommand.importDB(sender, args);
          } else if (args[0].equalsIgnoreCase("restore")) {
            return bscommand.restoreDB(sender, args);
          } else if (args[0].equalsIgnoreCase("update")) {
            if (sender.isOp()) {
              Log("Downloading & Installing Update");
              BSutils.sendMessage(sender, "Downloading & Installing Update");
              ServerReload sreload = new ServerReload(getServer());
              if (Updater.downloadUpdate()) {
                Log("Update Downloaded: Restarting Server..");
                BSutils.sendMessage(sender, "Download Successful.. reloading server");
                // this.setEnabled(false);
                // this.getServer().dispatchCommand((CommandSender) new CommanderSenderImpl(this),
                // "stop");
                // this.getServer().dispatchCommand(new AdminCommandSender(this), "stop");

                // this.getServer().reload();
                sreload.start(500);
              }
            } else {
              BSutils.sendMessage(sender, "Only an OP can update the shop plugin");
            }
            return true;
          } else if (args[0].equalsIgnoreCase("ver") || args[0].equalsIgnoreCase("version")) {
            // allow admin.info or developers access to plugin status (so if i find a bug i can see
            // if it's current)
            if (BSutils.hasPermission(sender, BSutils.BetterShopPermission.ADMIN_INFO, false)
                || (sender instanceof Player
                    && (((Player) sender).getDisplayName().equals("jascotty2")
                        || ((Player) sender).getDisplayName().equals("jjfs85")))) {
              BSutils.sendMessage(sender, "version " + pdfFile.getVersion());
              if (Updater.isUpToDate()) {
                BSutils.sendMessage(sender, "Version is up-to-date");
              } else {
                BSutils.sendMessage(sender, "Newer Version Avaliable");
              }
              return true;
            }
          } else {
            return false;
          }
          // now remove [0]
          if (args.length > 1) {
            String newArgs[] = new String[args.length - 1];
            for (int i = 1; i < args.length; ++i) {
              newArgs[i - 1] = args[i];
            }
            args = newArgs;
          } else {
            args = new String[0];
          }

        } else {
          return false;
        }
      }

      // check if using history
      if (commandName.equals("shopbuyagain") || commandName.equals("shopsellagain")) {
        if (args.length > 0 || BSutils.anonymousCheck(sender)) {
          return false;
        }
        if (commandName.equals("shopbuyagain")) {
          String action = bscommand.userbuyHistory.get(((Player) sender).getDisplayName());
          if (action == null) {
            BSutils.sendMessage(sender, "You have no recent buying history");
            return true;
          } else {
            // trim command & put into args
            String cm[] = action.split(" ");
            commandName = cm[0];
            args = new String[cm.length - 1];
            for (int i = 1; i < cm.length; ++i) {
              args[i - 1] = cm[i];
            }
          }
        } else { // if (commandName.equals("shopsellagain")) {
          String action = bscommand.usersellHistory.get(((Player) sender).getDisplayName());
          if (action == null) {
            BSutils.sendMessage(sender, "You have no recent sell history");
            return true;
          } else {
            // trim command & put into args
            String cm[] = action.split(" ");
            commandName = cm[0];
            args = new String[cm.length - 1];
            for (int i = 1; i < cm.length; ++i) {
              args[i - 1] = cm[i];
            }
          }
        }
        // System.out.println("new command: " + commandName);
        // System.out.println(BSCommand.argStr(args));
      }
      if (!config.useGlobalCommandShop()
          && Str.isIn(
              commandName,
              new String[] {
                "shopbuy", "shopbuyall", "shopbuystack",
                "shopsell", "shopsellall",
                    "shopsellstack", /*"shoplist", "shopitems", "shopcheck", "shoplistkits",
                                     "shopadd", "shopremove"*/
              })) {

        BSutils.sendMessage(sender, "Shop is disabled from here");
        return true;
      }

      if (commandName.equals("shoplist")) {
        return bscommand.list(sender, args);
      } else if (commandName.equals("shopitems")) {
        return bscommand.listitems(sender, args);
      } else if (commandName.equals("shophelp")) {
        return bscommand.help(sender, args);
      } else if (commandName.equals("shopbuy")) {
        return bscommand.buy(sender, args);
      } else if (commandName.equals("shopbuyall")) {
        ArrayList<String> arg = new ArrayList<String>();
        arg.addAll(Arrays.asList(args));
        arg.add("all");
        return bscommand.buy(sender, arg.toArray(new String[0]));
      } else if (commandName.equals("shopbuystack")) {
        return bscommand.buystack(sender, args);
      } else if (commandName.equals("shopsell")) {
        return bscommand.sell(sender, args);
      } else if (commandName.equals("shopsellall")) {
        return bscommand.sellall(sender, args);
      } else if (commandName.equals("shopsellstack")) {
        return bscommand.sellstack(sender, args);
      } else if (commandName.equals("shopadd")) {
        return bscommand.add(sender, args);
      } else if (commandName.equals("shopremove")) {
        return bscommand.remove(sender, args);
      } else if (commandName.equals("shopload")) {
        return bscommand.load(sender);
      } else if (commandName.equals("shopcheck")) {
        return bscommand.check(sender, args);
      } else if (commandName.equals("shoplistkits")) {
        return bscommand.listkits(sender, args);
      }

      return false;
    } catch (Exception e) {
      BSutils.sendMessage(sender, "Unexpected Error!");
      Log(Level.SEVERE, e);
    }
    return true;
  }