Esempio n. 1
0
 @Command("kits")
 public void kits(final CommandSender cs, final String[] args) {
   String message = "Verfügbare Kits: ";
   for (final Entry<String, Kit> entry : this.module.getKits()) {
     if (cs.hasPermission(entry.getValue().getPermission())) {
       message += entry.getKey() + ", ";
     }
   }
   CraftoMessenger.sendMessage(cs, message.substring(0, message.length() - 2));
 }
Esempio n. 2
0
  @Command("kit")
  @Aliases({"kits"})
  public boolean onCommand(final CommandSender cs, final String command, final String[] args) {
    if (command.equalsIgnoreCase("kit")) {
      if (cs instanceof Player) {
        if (args.length > 0 && args.length < 2) {
          if (this.module.containsKit(args[0].toLowerCase())) {
            final Kit kit = this.module.getKit(args[0].toLowerCase());
            if (kit.isEnabled()) {
              final Player p = (Player) cs;
              final CraftoPlayer cp = CraftoPlayer.getPlayer(p);
              if (cs.hasPermission(kit.getPermission())) {
                final Timestamp updated_at =
                    (Timestamp)
                        CraftoDatabase.getValue(
                            "SELECT `updated_at` FROM `cp_kits` WHERE `player` = " + cp.getId(),
                            "updated_at",
                            true);
                if (updated_at != null) {
                  try {
                    final long lastTimeUse = updated_at.getTime();

                    if (kit.isOnetimeuse()) {
                      CraftoMessenger.sendFailed(cs, "KIT_ALREADY_USED");
                      return true;
                    } else {
                      if (lastTimeUse + kit.getInterval() > System.currentTimeMillis()) {
                        CraftoMessenger.sendFailed(cs, "KIT_NOT_YET");
                        CraftoMessenger.sendMessage(
                            cs,
                            "§7Verwendung in: "
                                + (((lastTimeUse + kit.getInterval()) - System.currentTimeMillis())
                                        / 1000
                                    + " Sekunden."));
                        return true;
                      }
                    }
                  } catch (final Exception e) {
                    CraftoMessenger.exception(
                        "KitCommands/onCommand()", "Failed to lookup last time use", e);
                  }
                }

                for (final ItemStack item : kit.getItems()) {
                  p.getInventory().addItem(item);
                }

                this.module
                    .getPlugin()
                    .getScheduler()
                    .registerQuery(
                        ""
                            + "INSERT INTO `cp_kits` (`player`, `kit`, `updated_at`, `count`) "
                            + "VALUES ("
                            + cp.getId()
                            + ", '"
                            + kit.getName()
                            + "', '"
                            + new Timestamp(System.currentTimeMillis())
                            + "', 1) "
                            + "ON DUPLICATE KEY UPDATE `updated_at`='"
                            + new Timestamp(System.currentTimeMillis())
                            + "', `count`=count+1;");
              } else {
                CraftoMessenger.sendFailed(cs, "KIT_NO_ACCESS");
              }
            } else {
              CraftoMessenger.sendFailed(cs, "KIT_DOESNT_EXIST");
            }
          } else {
            CraftoMessenger.sendFailed(cs, "KIT_DOESNT_EXIST");
          }
        } else if (cs.hasPermission("craftoplugin.kits.admin")) {
          if (args[0].equalsIgnoreCase("create")) {
            final String kit = args[1].toLowerCase();
            if (!this.module.getPlugin().getConfig().contains("kits." + kit)) {
              final Player p = (Player) cs;
              Boolean oneTimeUse = true;
              Long interval = 1000L;

              if (args.length == 3) { // kit create name true
                try {
                  oneTimeUse = Boolean.parseBoolean(args[3]);
                } catch (final Exception e) {
                }
              } else if (args.length == 4) { // kit name create
                // true 1000
                try {
                  oneTimeUse = Boolean.parseBoolean(args[3]);
                } catch (final Exception e) {
                }
                try {
                  interval = Long.parseLong(args[4]);
                } catch (final Exception e) {
                }
              }

              final FileConfiguration cfg = this.module.getPlugin().getConfig();
              cfg.createSection("kits." + kit);
              cfg.set("kits." + kit + ".onetimeuse", oneTimeUse.toString());
              cfg.set("kits." + kit + ".interval", interval.toString());

              final List<String> enabledKits = cfg.getStringList("kits.enabled");
              enabledKits.add(kit);
              cfg.set("kits.enabled", enabledKits);

              final List<ItemStack> items = new ArrayList<ItemStack>();

              for (final ItemStack item : p.getInventory().getContents()) {
                if (item != null && !item.getType().equals(Material.AIR)) {
                  items.add(item);
                }
              }

              cfg.set("kits." + kit + ".items", items);
              this.module.getPlugin().saveConfig();
              CraftoMessenger.sendSuccess(cs, "KIT_CREATED_SUCCESS");
            } else {
              CraftoMessenger.sendFailed(cs, "KIT_ALREADY_EXISTS");
            }
          } else if (args[0].equalsIgnoreCase("reload")) {
            this.module.reload();
            CraftoMessenger.sendSuccess(cs, "KITS_RELOADED");
          } else {
            CraftoMessenger.sendFailed(cs, "INVALID_COMMAND");
          }
        } else {
          CraftoMessenger.sendFailed(cs, "NO_GIVEN_KIT");
        }
      }
    } else if (command.equalsIgnoreCase("kits")) {
      String text = "Verfügbare Kits: ";
      for (final Entry<String, Kit> entry : this.module.getKits()) {
        if (cs.hasPermission(entry.getValue().getPermission())) {
          text += entry.getKey() + ", ";
        }
      }

      CraftoMessenger.sendMessage(cs, text.substring(0, text.length() - 2));
    }
    return true;
  }
  @Command(
      value = "akte",
      perm = "craftoplugin.moderator",
      desc = "Verwaltet gemerkte Dinge zu Spielern")
  public void onCommand(final CommandSender cs, final String[] args) {
    if (args.length < 1) {
      CraftoMessenger.sendMessage(cs, "Anwendung: /akte <spieler> [add]");
    } else {
      final CraftoPlayer p = CraftoPlayer.getPlayer(args[0]);
      final List<Record> records = this.getRecords(p);
      if (p != null && records != null) {
        if (args.length < 2) {
          if (records.size() > 0) {
            final Json header =
                new Json()
                    .add("CraftoPlugin // ", Format.GOLD)
                    .add("Alle Einträge zu " + p.getIdName() + ": ", Format.YELLOW);
            header.add("[", Format.GRAY);
            header.add(
                "+",
                "Neuen Eintrag erstellen...",
                "suggest_command",
                "/akte " + p.getName() + " add ",
                Format.WHITE);
            header.add("]", Format.GRAY);
            header.sendTo(cs.getName());
            for (final Record r : records) {
              final CraftoPlayer creator = CraftoPlayer.getPlayer(r.getCreated_by());
              // Format: + [456] Von Fear837: Hat eine ganz tolle Stadt aufgebaut.
              final Json json = new Json().s();
              if (r.getType().equals(RecordType.POSITIVE)) {
                json.add(
                        "+",
                        this.getStartHover(p, r),
                        "run_command",
                        "/record " + r.getId(),
                        Format.GREEN)
                    .s();
              } else if (r.getType().equals(RecordType.NEGATIVE)) {
                json.add(
                        "-",
                        this.getStartHover(p, r),
                        "run_command",
                        "/record " + r.getId(),
                        Format.RED)
                    .s();
              } else {
                json.add(
                        "*",
                        this.getStartHover(p, r),
                        "run_command",
                        "/record " + r.getId(),
                        Format.AQUA)
                    .s();
              }
              json.add("[", Format.GRAY);
              json.add(
                  "" + r.getId(),
                  this.getStartHover(p, r),
                  "run_command",
                  "/tp " + r.getLocation(),
                  Format.GRAY);
              json.add("]", Format.GRAY).s();

              if (creator != null) {
                json.add(
                    creator.getName(), this.getPlayerHover(creator, r.getId()), Format.DARK_AQUA);
              } else {
                json.add("Craftobot", Format.DARK_AQUA);
              }
              json.add(" schrieb: ", Format.WHITE);

              json.add(r.getInfo(), Format.GRAY);
              // json.add("[", Format.GRAY);
              // json.add(">>", "Teleportieren zu "+r.getLocation(), "run_command", "/tp
              // "+r.getLocation(), Format.WHITE);
              // json.add("]", Format.GRAY);
              json.sendTo(cs.getName());
            }
          } else {
            CraftoMessenger.sendFailed(
                cs, "Der angegebene Spieler hat noch keine Einträge in seiner Akte.");
          }
        } else if (cs instanceof Player) {
          final Player pSender = (Player) cs;
          final CraftoPlayer cSender = CraftoPlayer.getPlayer(pSender.getUniqueId());
          if (args[1].equalsIgnoreCase("add")
              || args[0].equalsIgnoreCase("new")) { // /akte <name> add <type> <text>
            if (args.length > 3) {
              RecordType type = null;
              String text = null;

              if (args[2].equalsIgnoreCase("+")) {
                type = RecordType.POSITIVE;
              } else if (args[2].equalsIgnoreCase("-")) {
                type = RecordType.NEGATIVE;
              } else if (args[2].equalsIgnoreCase("*")) {
                type = RecordType.NEUTRAL;
              } else {
                CraftoMessenger.sendFailed(cs, "Ungültiger Typ! (+, -, *)");
                return;
              }

              final StringBuilder b = new StringBuilder();
              for (int i = 3; i < args.length; i++) {
                b.append(args[i] + " ");
              }
              text = b.toString();

              if (text != null && !text.isEmpty()) {
                final Record r = p.addRecord(type, text, cSender.getId(), pSender.getLocation());
                if (r != null) {
                  CraftoMessenger.sendSuccess(
                      cs, "Der Akteneintrag wurde erfolgreich erstellt. (#" + r.getId() + ")");
                } else {
                  CraftoMessenger.sendFailed(
                      cs, "Ein Fehler ist beim Erstellen des Eintrags aufgetreten.");
                }
              } else {
                CraftoMessenger.sendFailed(cs, "Es wurde kein Text zu dem Eintrag angegeben.");
              }
            } else {
              CraftoMessenger.sendFailed(
                  cs, "Zu wenige Argumente! (/akte <name> add <type> <text>");
              return;
            }
          } else if (args[1].equalsIgnoreCase("+")
              || args[1].equalsIgnoreCase("-")
              || args[1].equalsIgnoreCase("*")) {
            // /akte <name> <type> <text>
            if (args.length > 2) {
              RecordType type = null;
              String text = null;

              if (args[1].equalsIgnoreCase("+")) {
                type = RecordType.POSITIVE;
              } else if (args[1].equalsIgnoreCase("-")) {
                type = RecordType.NEGATIVE;
              } else if (args[1].equalsIgnoreCase("*")) {
                type = RecordType.NEUTRAL;
              } else {
                CraftoMessenger.sendFailed(cs, "Ungültiger Typ! (+, -, *)");
                return;
              }

              final StringBuilder b = new StringBuilder();
              for (int i = 2; i < args.length; i++) {
                b.append(args[i] + " ");
              }
              text = b.toString();

              if (text != null && !text.isEmpty()) {
                final Record r = p.addRecord(type, text, cSender.getId(), pSender.getLocation());
                if (r != null) {
                  CraftoMessenger.sendSuccess(
                      cs, "Der Akteneintrag wurde erfolgreich erstellt. (#" + r.getId() + ")");
                } else {
                  CraftoMessenger.sendFailed(
                      cs, "Ein Fehler ist beim Erstellen des Eintrags aufgetreten.");
                }
              } else {
                CraftoMessenger.sendFailed(cs, "Es wurde kein Text zu dem Eintrag angegeben.");
              }
            } else {
              CraftoMessenger.sendFailed(
                  cs, "Zu wenige Argumente! (/akte <name> add <type> <text>");
              return;
            }
          } else {
            // TODO? Eintrag anlegen auch ohne +-*
            CraftoMessenger.sendFailed(cs, "Ungültige Argumente angegeben.");
          }
        } else {
          CraftoMessenger.sendFailed(
              cs, "Dieses Kommando kann nur von Spielern ausgeführt werden.");
        }
      } else {
        CraftoMessenger.sendFailed(cs, "Es wurde keine Akte zu dem angegebenen Spieler gefunden.");
      }
    }
  }