@Override
  public boolean execute(CommandSender sender, String currentAlias, String[] args) {
    if (!testPermission(sender)) return true;

    if (args.length == 1) {
      if (args[0].equalsIgnoreCase("reload")) {
        if (badPerm(sender, "reload")) return true;

        Bukkit.reloadWhitelist();
        Command.broadcastCommandMessage(sender, "Reloaded white-list from file");
        return true;
      } else if (args[0].equalsIgnoreCase("on")) {
        if (badPerm(sender, "enable")) return true;

        Bukkit.setWhitelist(true);
        Command.broadcastCommandMessage(sender, "Turned on white-listing");
        return true;
      } else if (args[0].equalsIgnoreCase("off")) {
        if (badPerm(sender, "disable")) return true;

        Bukkit.setWhitelist(false);
        Command.broadcastCommandMessage(sender, "Turned off white-listing");
        return true;
      } else if (args[0].equalsIgnoreCase("list")) {
        if (badPerm(sender, "list")) return true;

        StringBuilder result = new StringBuilder();

        for (OfflinePlayer player : Bukkit.getWhitelistedPlayers()) {
          if (result.length() > 0) {
            result.append(", ");
          }

          result.append(player.getName());
        }

        sender.sendMessage("White-listed players: " + result.toString());
        return true;
      }
    } else if (args.length == 2) {
      if (args[0].equalsIgnoreCase("add")) {
        if (badPerm(sender, "add")) return true;

        Bukkit.getOfflinePlayer(args[1]).setWhitelisted(true);

        Command.broadcastCommandMessage(sender, "Added " + args[1] + " to white-list");
        return true;
      } else if (args[0].equalsIgnoreCase("remove")) {
        if (badPerm(sender, "remove")) return true;

        Bukkit.getOfflinePlayer(args[1]).setWhitelisted(false);

        Command.broadcastCommandMessage(sender, "Removed " + args[1] + " from white-list");
        return true;
      }
    }

    sender.sendMessage(ChatColor.RED + "Correct command usage:\n" + usageMessage);
    return false;
  }
Esempio n. 2
0
  @Override
  public void runCommand(CommandSender sender, List<String> args) {
    String worldName = args.get(0);
    File worldFile = new File(this.plugin.getServer().getWorldContainer(), worldName);
    String env = args.get(1);
    String seed = CommandHandler.getFlag("-s", args);
    String generator = CommandHandler.getFlag("-g", args);
    boolean useSpawnAdjust = true;
    for (String s : args) {
      if (s.equalsIgnoreCase("-n")) {
        useSpawnAdjust = false;
      }
    }
    if (worldFile.exists() || this.worldManager.isMVWorld(worldName)) {
      sender.sendMessage(ChatColor.RED + "A Folder/World already exists with this name!");
      sender.sendMessage(
          ChatColor.RED + "If you are confident it is a world you can import with /mvimport");
      return;
    }

    Environment environment = this.plugin.getEnvFromString(env);
    if (environment == null) {
      sender.sendMessage(ChatColor.RED + "That is not a valid environment.");
      EnvironmentCommand.showEnvironments(sender);
      return;
    }

    Command.broadcastCommandMessage(sender, "Starting creation of world '" + worldName + "'...");

    if (this.worldManager.addWorld(worldName, environment, seed, generator, useSpawnAdjust)) {
      Command.broadcastCommandMessage(sender, "Complete!");
    } else {
      Command.broadcastCommandMessage(sender, "FAILED.");
    }
  }
Esempio n. 3
0
  @Override
  public boolean execute(CommandSender sender, String commandLabel, String[] args) {
    if (!testPermission(sender)) return true;
    if (args.length == 0) {
      sender.sendMessage("Usage: " + usageMessage);
      return false;
    }

    String modeArg = args[0];
    int value = -1;

    try {
      value = Integer.parseInt(modeArg);
    } catch (NumberFormatException ex) {
    }

    GameMode mode = GameMode.getByValue(value);

    if (mode == null) {
      if (modeArg.equalsIgnoreCase("creative") || modeArg.equalsIgnoreCase("c")) {
        mode = GameMode.CREATIVE;
      } else if (modeArg.equalsIgnoreCase("adventure") || modeArg.equalsIgnoreCase("a")) {
        mode = GameMode.ADVENTURE;
      } else {
        mode = GameMode.SURVIVAL;
      }
    }

    Bukkit.getServer().setDefaultGameMode(mode);
    Command.broadcastCommandMessage(
        sender, "Default game mode set to " + mode.toString().toLowerCase());

    return true;
  }
 @Override
 public void runCommand(CommandSender sender, List<String> args) {
   if (this.plugin.getMVWorldManager().unloadWorld(args.get(0))) {
     Command.broadcastCommandMessage(sender, "Unloaded world '" + args.get(0) + "'!");
   } else {
     sender.sendMessage("Error trying to unload world '" + args.get(0) + "'!");
   }
 }
Esempio n. 5
0
  @Override
  public boolean execute(CommandSender sender, String currentAlias, String[] args) {
    if (!testPermission(sender)) return true;

    for (World world : Bukkit.getWorlds()) {
      world.setAutoSave(true);
    }

    Command.broadcastCommandMessage(sender, "Автоматическое сохранение мира включено.");
    return true;
  }
Esempio n. 6
0
  @Override
  public boolean execute(CommandSender sender, String currentAlias, String[] args) {
    if (!testPermission(sender)) return true;

    for (World world : Bukkit.getWorlds()) {
      world.setAutoSave(true);
    }

    Command.broadcastCommandMessage(sender, "Enabled level saving..");
    return true;
  }
Esempio n. 7
0
  @Override
  public boolean execute(CommandSender sender, String currentAlias, String[] args) {
    if (!testPermission(sender)) return true;
    if (args.length == 0) {
      sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage);
      return false;
    }

    int duration = (300 + new Random().nextInt(600)) * 20;
    if (args.length >= 2) {
      duration = getInteger(sender, args[1], 1, 1000000) * 20;
    }

    World world = Bukkit.getWorlds().get(0);

    world.setWeatherDuration(duration);
    world.setThunderDuration(duration);

    if ("clear".equalsIgnoreCase(args[0])) {
      world.setStorm(false);
      world.setThundering(false);
      Command.broadcastCommandMessage(
          sender, "Changed weather to clear for " + (duration / 20) + " seconds.");
    } else if ("rain".equalsIgnoreCase(args[0])) {
      world.setStorm(true);
      world.setThundering(false);
      Command.broadcastCommandMessage(
          sender, "Changed weather to rainy for " + (duration / 20) + " seconds.");
    } else if ("thunder".equalsIgnoreCase(args[0])) {
      world.setStorm(true);
      world.setThundering(true);
      Command.broadcastCommandMessage(
          sender, "Changed weather to thundering " + (duration / 20) + " seconds.");
    }

    return true;
  }
Esempio n. 8
0
  public boolean execute(CommandSender sender, String currentAlias, String[] args) {
    if (!testPermission(sender)) {
      return true;
    }
    Command.broadcastCommandMessage(sender, "Stopping the server..");
    Bukkit.shutdown();

    String reason = createString(args, 0);
    if (StringUtils.isNotEmpty(reason)) {
      for (Player player : Bukkit.getOnlinePlayers()) {
        player.kickPlayer(reason);
      }
    }
    return true;
  }
Esempio n. 9
0
  @Override
  public boolean execute(CommandSender sender, String currentAlias, String[] args) {
    if (!testPermission(sender)) return true;
    if ((args.length < 2) || (args.length > 4)) {
      sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage);
      return false;
    }

    Player player = Bukkit.getPlayerExact(args[0]);

    if (player != null) {
      Material material = Material.matchMaterial(args[1]);

      if (material != null) {
        Command.broadcastCommandMessage(
            sender,
            "Giving " + player.getName() + " some " + material.getId() + " (" + material + ")");

        int amount = 1;
        short data = 0;

        if (args.length >= 3) {
          try {
            amount = Integer.parseInt(args[2]);
          } catch (NumberFormatException ex) {
          }

          if (amount < 1) amount = 1;
          if (amount > 64) amount = 64;
          if (args.length >= 4) {
            try {
              data = Short.parseShort(args[3]);
            } catch (NumberFormatException ex) {
            }
          }
        }

        player.getInventory().addItem(new ItemStack(material, amount, data));
      } else {
        sender.sendMessage("There's no item called " + args[1]);
      }
    } else {
      sender.sendMessage("Can't find user " + args[0]);
    }

    return true;
  }
Esempio n. 10
0
  @Override
  public boolean onCommand(
      CommandSender sender, Command command, String commandLabel, String[] args) {
    ConsoleCommandSender consoleSender = sender.getServer().getConsoleSender();
    String prefix =
        (ChatColor.BOLD + (ChatColor.BLUE + "["))
            + (ChatColor.RESET + (ChatColor.YELLOW + "Kustom Warn"))
            + (ChatColor.BOLD + (ChatColor.BLUE + "]"))
            + ChatColor.RESET;
    String kickMessage = plugin.getConfig().getString("Kick Message");
    String banMessage = plugin.getConfig().getString("Ban Message");
    String reason = " ";
    for (int i = 1; i < args.length; i++) {
      reason += args[i] + " ";
    }
    if (commandLabel.equalsIgnoreCase("kwarn")) {
      if (!(sender instanceof Player)) {
        if (args.length == 0) {
          consoleSender.sendMessage(prefix + ChatColor.RED + "Not enough arguments!");
          consoleSender.sendMessage(prefix + ChatColor.RED + "Usage: /kwarn [player] (reason)");
          return true;
        } else if (args.length == 1) {
          Player targetPlayer = consoleSender.getServer().getPlayer(args[0]);
          if (targetPlayer != null) {
            List warnings =
                plugin
                    .getDatabase()
                    .find(Warnings.class)
                    .where()
                    .ieq("playerName", targetPlayer.getName())
                    .findList();
            if (plugin.getConfig().getBoolean("Alert Admins")) {
              Command.broadcastCommandMessage(
                  sender,
                  prefix
                      + ChatColor.AQUA
                      + targetPlayer.getName()
                      + " has been warned by a console user");
            }
            if ((warnings.size() + 1) >= plugin.getConfig().getInt("Kick After")) {
              targetPlayer.setPlayerListName(ChatColor.AQUA + targetPlayer.getName());
            } else if ((warnings.size() + 1) >= plugin.getConfig().getInt("Ban After"))
              if (warnings.size() != 0) {
                consoleSender.sendMessage(
                    prefix
                        + ChatColor.AQUA
                        + targetPlayer.getName()
                        + " has been warned "
                        + String.valueOf(warnings.size() + 1)
                        + " times");
              } else {
                consoleSender.sendMessage(
                    prefix
                        + ChatColor.AQUA
                        + "This is "
                        + targetPlayer.getName()
                        + "\'s first warning");
              }
            targetPlayer.sendMessage(
                prefix + ChatColor.RED + plugin.getConfig().getString("Warning Message"));
            Warnings warning =
                plugin
                    .getDatabase()
                    .find(Warnings.class)
                    .where()
                    .ieq("playerName", targetPlayer.getName())
                    .ieq("warningNumber", String.valueOf(warnings.size() + 1))
                    .findUnique();
            if (warnings.size() < plugin.getConfig().getInt("Ban After")) {
              warning = new Warnings();
              warning.setWarningNumber(String.valueOf(warnings.size() + 1));
              warning.setPlayerName(targetPlayer.getName());
              warning.setAdminName("console user");
            }
            plugin.getDatabase().save(warning);

            if ((warnings.size() + 1) == plugin.getConfig().getInt("Kick After")) {
              targetPlayer.kickPlayer(plugin.getConfig().getString("Kick Message"));
            } else if ((warnings.size() + 1) == plugin.getConfig().getInt("Ban After")) {
              targetPlayer.kickPlayer(plugin.getConfig().getString("Ban Message"));
              targetPlayer.setBanned(true);
            }
            return true;
          } else {
            consoleSender.sendMessage(prefix + ChatColor.RED + "Player not found!");
            return true;
          }
        } else if (args.length >= 2) {
          Player targetPlayer = consoleSender.getServer().getPlayer(args[0]);
          if (targetPlayer != null) {
            List warnings =
                plugin
                    .getDatabase()
                    .find(Warnings.class)
                    .where()
                    .ieq("playerName", targetPlayer.getName())
                    .findList();
            if (plugin.getConfig().getBoolean("Alert Admins")) {
              Command.broadcastCommandMessage(
                  sender,
                  prefix
                      + ChatColor.AQUA
                      + targetPlayer.getName()
                      + " has been warned by a console user for "
                      + reason);
            }
            if (warnings.size() != 0) {
              consoleSender.sendMessage(
                  prefix
                      + ChatColor.AQUA
                      + targetPlayer.getName()
                      + " has been warned "
                      + String.valueOf(warnings.size() + 1)
                      + " times");
            } else {
              consoleSender.sendMessage(
                  prefix
                      + ChatColor.AQUA
                      + "This is "
                      + targetPlayer.getName()
                      + "\'s first warning");
            }
            if (plugin.getConfig().getBoolean("Alert Admins")) {
              Command.broadcastCommandMessage(
                  sender,
                  prefix
                      + ChatColor.AQUA
                      + targetPlayer.getName()
                      + " has been warned by a console user");
            }
            if ((warnings.size() + 1) >= plugin.getConfig().getInt("Kick After")) {
              targetPlayer.setPlayerListName(ChatColor.AQUA + targetPlayer.getName());
            }
            targetPlayer.sendMessage(
                prefix
                    + ChatColor.RED
                    + plugin.getConfig().getString("Warning For")
                    + " "
                    + reason);
            Warnings warning =
                plugin
                    .getDatabase()
                    .find(Warnings.class)
                    .where()
                    .ieq("playerName", targetPlayer.getName())
                    .ieq("warningNumber", String.valueOf(warnings.size() + 1))
                    .findUnique();
            if (warnings.size() < plugin.getConfig().getInt("Ban After")) {
              warning = new Warnings();
              warning.setWarningNumber(String.valueOf(warnings.size() + 1));
              warning.setPlayerName(targetPlayer.getName());
              warning.setAdminName("console user");
              warning.setWarningReason(reason);
            }
            plugin.getDatabase().save(warning);

            if ((warnings.size() + 1) == plugin.getConfig().getInt("Kick After")) {
              targetPlayer.kickPlayer(plugin.getConfig().getString("Kick Message"));
            } else if ((warnings.size() + 1) == plugin.getConfig().getInt("Ban After")) {
              targetPlayer.kickPlayer(plugin.getConfig().getString("Ban Message"));
              targetPlayer.setBanned(true);
            }
            return true;
          }
        }
      } else {
        Player player = (Player) sender;
        if (player.hasPermission("kustomwarn.warn") || player.isOp()) {
          if (args.length == 0) {
            if (plugin == null) {
              player.sendMessage(prefix + "Plugin is null");
            }
            player.sendMessage(prefix + ChatColor.RED + "Not enough arguments!");
            player.sendMessage(prefix + ChatColor.RED + "Usage: /kwarn [player] (reason)");
            return true;
          } else if (args.length == 1) {
            Player targetPlayer = player.getServer().getPlayer(args[0]);
            if (targetPlayer != null) {
              List warnings =
                  plugin
                      .getDatabase()
                      .find(Warnings.class)
                      .where()
                      .ieq("playerName", targetPlayer.getName())
                      .findList();
              if (plugin.getConfig().getBoolean("Alert Admins")) {
                Command.broadcastCommandMessage(
                    sender,
                    prefix
                        + ChatColor.AQUA
                        + targetPlayer.getName()
                        + " has been warned by "
                        + player.getName());
              }
              if (warnings.size() != 0) {
                player.sendMessage(
                    prefix
                        + ChatColor.AQUA
                        + targetPlayer.getName()
                        + " has been warned "
                        + String.valueOf(warnings.size() + 1)
                        + " times");
              } else {
                player.sendMessage(
                    prefix
                        + ChatColor.AQUA
                        + "This is "
                        + targetPlayer.getName()
                        + "\'s first warning");
              }
              targetPlayer.sendMessage(
                  prefix + ChatColor.RED + plugin.getConfig().getString("Warning Message"));
              Warnings warning =
                  plugin
                      .getDatabase()
                      .find(Warnings.class)
                      .where()
                      .ieq("playerName", targetPlayer.getName())
                      .ieq("warningNumber", String.valueOf(warnings.size() + 1))
                      .findUnique();
              if (warnings.size() < plugin.getConfig().getInt("Ban After")) {
                warning = new Warnings();
                warning.setWarningNumber(String.valueOf(warnings.size() + 1));
                warning.setPlayerName(targetPlayer.getName());
                warning.setAdminName(player.getName());
              }
              plugin.getDatabase().save(warning);

              if ((warnings.size() + 1) == plugin.getConfig().getInt("Kick After")) {
                targetPlayer.kickPlayer(plugin.getConfig().getString("Kick Message"));
              } else if ((warnings.size() + 1) == plugin.getConfig().getInt("Ban After")) {
                targetPlayer.kickPlayer(plugin.getConfig().getString("Ban Message"));
                targetPlayer.setBanned(true);
              }
              if (plugin.getConfig().getBoolean("Alert Admins")) {
                Command.broadcastCommandMessage(
                    sender,
                    prefix
                        + ChatColor.AQUA
                        + targetPlayer.getName()
                        + " has been warned by a console user");
              }
              if ((warnings.size() + 1) >= plugin.getConfig().getInt("Kick After")) {
                targetPlayer.setPlayerListName(ChatColor.AQUA + targetPlayer.getName());
              }
              return true;
            } else {
              player.sendMessage(prefix + ChatColor.RED + "Player not found!");
              return true;
            }
          } else if (args.length >= 2) {
            Player targetPlayer = player.getServer().getPlayer(args[0]);
            if (targetPlayer != null) {
              List warnings =
                  plugin
                      .getDatabase()
                      .find(Warnings.class)
                      .where()
                      .ieq("playerName", targetPlayer.getName())
                      .findList();
              if (plugin.getConfig().getBoolean("Alert Admins")) {
                Command.broadcastCommandMessage(
                    sender,
                    prefix
                        + ChatColor.AQUA
                        + targetPlayer.getName()
                        + " has been warned by "
                        + player.getName()
                        + " for "
                        + reason);
              }
              if (warnings.size() != 0) {
                player.sendMessage(
                    prefix
                        + ChatColor.AQUA
                        + targetPlayer.getName()
                        + " has been warned "
                        + String.valueOf(warnings.size() + 1)
                        + " times");
              }
              if (setKicked(targetPlayer.getName())) {
                targetPlayer.kickPlayer(plugin);
              } else {
                player.sendMessage(
                    prefix
                        + ChatColor.AQUA
                        + "This is "
                        + targetPlayer.getName()
                        + "\'s first warning");
              }
              targetPlayer.sendMessage(
                  prefix
                      + ChatColor.RED
                      + plugin.getConfig().getString("Warning For")
                      + " "
                      + reason);
              Warnings warning =
                  plugin
                      .getDatabase()
                      .find(Warnings.class)
                      .where()
                      .ieq("playerName", targetPlayer.getName())
                      .ieq("warningNumber", String.valueOf(warnings.size() + 1))
                      .findUnique();
              if (warnings.size() < plugin.getConfig().getInt("Ban After")) {
                warning = new Warnings();
                warning.setWarningNumber(String.valueOf(warnings.size() + 1));
                warning.setPlayerName(targetPlayer.getName());
                warning.setAdminName(player.getName());
                warning.setWarningReason(reason);
              }
              plugin.getDatabase().save(warning);

              if (plugin.getConfig().getBoolean("Alert Admins")) {
                Command.broadcastCommandMessage(
                    sender,
                    prefix
                        + ChatColor.AQUA
                        + targetPlayer.getName()
                        + " has been warned by a console user");
              }
              return true;
            } else {
              player.sendMessage(prefix + ChatColor.RED + "Player not found");
              return true;
            }
          }
        }
      }
    }
    return true;
  }
Esempio n. 11
0
  @Override
  public boolean execute(CommandSender sender, String currentAlias, String[] args) {
    if (!testPermission(sender)) return true;

    if (args.length < 2) {
      sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage);
      return false;
    }

    if (!args[0].equalsIgnoreCase("give")) {
      sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage);
      return false;
    }

    String statisticString = args[1];
    Player player = null;

    if (args.length > 2) {
      player = Bukkit.getPlayer(args[1]);
    } else if (sender instanceof Player) {
      player = (Player) sender;
    }

    if (player == null) {
      sender.sendMessage("You must specify which player you wish to perform this action on.");
      return true;
    }

    if (statisticString.equals("*")) {
      for (Achievement achievement : Achievement.values()) {
        if (player.hasAchievement(achievement)) {
          continue;
        }
        PlayerAchievementAwardedEvent event =
            new PlayerAchievementAwardedEvent(player, achievement);
        Bukkit.getServer().getPluginManager().callEvent(event);
        if (!event.isCancelled()) {
          player.awardAchievement(achievement);
        }
      }
      Command.broadcastCommandMessage(
          sender, String.format("Successfully given all achievements to %s", player.getName()));
      return true;
    }

    Achievement achievement = Bukkit.getUnsafe().getAchievementFromInternalName(statisticString);
    Statistic statistic = Bukkit.getUnsafe().getStatisticFromInternalName(statisticString);

    if (achievement != null) {
      if (player.hasAchievement(achievement)) {
        sender.sendMessage(
            String.format("%s already has achievement %s", player.getName(), statisticString));
        return true;
      }

      PlayerAchievementAwardedEvent event = new PlayerAchievementAwardedEvent(player, achievement);
      Bukkit.getServer().getPluginManager().callEvent(event);
      if (event.isCancelled()) {
        sender.sendMessage(
            String.format(
                "Unable to award %s the achievement %s", player.getName(), statisticString));
        return true;
      }
      player.awardAchievement(achievement);

      Command.broadcastCommandMessage(
          sender,
          String.format("Successfully given %s the stat %s", player.getName(), statisticString));
      return true;
    }

    if (statistic == null) {
      sender.sendMessage(String.format("Unknown achievement or statistic '%s'", statisticString));
      return true;
    }

    if (statistic.getType() == Type.UNTYPED) {
      PlayerStatisticIncrementEvent event =
          new PlayerStatisticIncrementEvent(
              player,
              statistic,
              player.getStatistic(statistic),
              player.getStatistic(statistic) + 1);
      Bukkit.getServer().getPluginManager().callEvent(event);
      if (event.isCancelled()) {
        sender.sendMessage(
            String.format("Unable to increment %s for %s", statisticString, player.getName()));
        return true;
      }
      player.incrementStatistic(statistic);
      Command.broadcastCommandMessage(
          sender,
          String.format("Successfully given %s the stat %s", player.getName(), statisticString));
      return true;
    }

    if (statistic.getType() == Type.ENTITY) {
      EntityType entityType =
          EntityType.fromName(statisticString.substring(statisticString.lastIndexOf(".") + 1));

      if (entityType == null) {
        sender.sendMessage(String.format("Unknown achievement or statistic '%s'", statisticString));
        return true;
      }

      PlayerStatisticIncrementEvent event =
          new PlayerStatisticIncrementEvent(
              player,
              statistic,
              player.getStatistic(statistic),
              player.getStatistic(statistic) + 1,
              entityType);
      Bukkit.getServer().getPluginManager().callEvent(event);
      if (event.isCancelled()) {
        sender.sendMessage(
            String.format("Unable to increment %s for %s", statisticString, player.getName()));
        return true;
      }

      try {
        player.incrementStatistic(statistic, entityType);
      } catch (IllegalArgumentException e) {
        sender.sendMessage(String.format("Unknown achievement or statistic '%s'", statisticString));
        return true;
      }
    } else {
      int id;
      try {
        id =
            getInteger(
                sender,
                statisticString.substring(statisticString.lastIndexOf(".") + 1),
                0,
                Integer.MAX_VALUE,
                true);
      } catch (NumberFormatException e) {
        sender.sendMessage(e.getMessage());
        return true;
      }

      Material material = Material.getMaterial(id);

      if (material == null) {
        sender.sendMessage(String.format("Unknown achievement or statistic '%s'", statisticString));
        return true;
      }

      PlayerStatisticIncrementEvent event =
          new PlayerStatisticIncrementEvent(
              player,
              statistic,
              player.getStatistic(statistic),
              player.getStatistic(statistic) + 1,
              material);
      Bukkit.getServer().getPluginManager().callEvent(event);
      if (event.isCancelled()) {
        sender.sendMessage(
            String.format("Unable to increment %s for %s", statisticString, player.getName()));
        return true;
      }

      try {
        player.incrementStatistic(statistic, material);
      } catch (IllegalArgumentException e) {
        sender.sendMessage(String.format("Unknown achievement or statistic '%s'", statisticString));
        return true;
      }
    }

    Command.broadcastCommandMessage(
        sender,
        String.format("Successfully given %s the stat %s", player.getName(), statisticString));
    return true;
  }
Esempio n. 12
0
  public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    if (cmd.getName().equalsIgnoreCase("give") && sender instanceof Player) {
      Player player = Bukkit.getPlayerExact(args[0]);
      Player p = (Player) sender;
      String user = Configuration.getString("settings.mysql.user");
      String pass = Configuration.getString("settings.mysql.pass");
      String url = "jdbc:mysql://localhost:3306/Fiery";
      String v = Configuration.getString("money.iscalled");
      boolean t = Configuration.getBoolean("money.isenabled");
      int cost = Configuration.getInt("commandcharge.give");
      int balance;

      try {
        Connection conn = DriverManager.getConnection(url, user, pass);
        Statement select = conn.createStatement();
        ResultSet rs =
            select.executeQuery("SELECT balance FROM money WHERE p_name ='" + p.getName() + "'");
        while (rs.next()) {
          balance = rs.getInt("balance");
          int nbalance;

          if (t && cost > 0 && cost < balance) {

            if (player != null) {
              Material material = Material.matchMaterial(args[1]);

              if (material != null) {
                int amount = 1;
                if (args.length >= 3) {

                  try {
                    amount = Integer.parseInt(args[2]);
                  } catch (NumberFormatException ex) {
                  }
                  if (amount < 1) amount = 1;
                  if (amount > 64) amount = 64;
                }

                player.getInventory().addItem(new ItemStack(material, amount));
                Command.broadcastCommandMessage(
                    sender, "Giving  " + player.getName() + "  " + args[2] + "  " + material);
                Command.broadcastCommandMessage(
                    player, sender.getName() + "  gave you  " + args[2] + "  " + material);
                nbalance = balance - cost;
                Statement select0 = conn.createStatement();
                select0.executeUpdate(
                    "UPDATE money SET balance = '"
                        + nbalance
                        + "'WHERE p_name ='"
                        + p.getName()
                        + "'");
                p.sendMessage(
                    "You have been charged "
                        + cost
                        + " "
                        + v
                        + " - your new balance is "
                        + nbalance
                        + " "
                        + v
                        + "");
                return true;

              } else {
                sender.sendMessage("There's no item called " + args[1]);
                return true;
              }

            } else {
              sender.sendMessage("Can't find user " + args[0]);
            }
            return true;
          }

          if (cost < 1) {
            if (player != null) {
              Material material = Material.matchMaterial(args[1]);

              if (material != null) {
                int amount = 1;
                if (args.length >= 3) {

                  try {
                    amount = Integer.parseInt(args[2]);
                  } catch (NumberFormatException ex) {
                  }
                  if (amount < 1) amount = 1;
                  if (amount > 64) amount = 64;
                }

                player.getInventory().addItem(new ItemStack(material, amount));
                Command.broadcastCommandMessage(
                    sender, "Giving  " + player.getName() + "  " + args[2] + "  " + material);
                Command.broadcastCommandMessage(
                    player, sender.getName() + "  gave you  " + args[2] + "  " + material);

              } else {
                sender.sendMessage("There's no item called " + args[1]);
              }
              return true;

            } else {
              sender.sendMessage("Can't find user " + args[0]);
            }
          } else {
            if (player != null) {
              Material material = Material.matchMaterial(args[1]);

              if (material != null) {
                int amount = 1;
                if (args.length >= 3) {

                  try {
                    amount = Integer.parseInt(args[2]);
                  } catch (NumberFormatException ex) {
                  }
                  if (amount < 1) amount = 1;
                  if (amount > 64) amount = 64;
                }

                player.getInventory().addItem(new ItemStack(material, amount));
                Command.broadcastCommandMessage(
                    sender, "Giving  " + player.getName() + "  " + args[2] + "  " + material);
                Command.broadcastCommandMessage(
                    player, sender.getName() + "  gave you  " + args[2] + "  " + material);

              } else {
                sender.sendMessage("There's no item called " + args[1]);
              }

            } else {
              sender.sendMessage("Can't find user " + args[0]);
            }
            return true;
          }
        }
      } catch (SQLException e1) {
        e1.printStackTrace();
      }
    }
    return false;
  }
Esempio n. 13
0
 public static void broadcastCommandMessage(CommandSender source, String message) {
   broadcastCommandMessage(source, message, true);
 }
  @Override
  public boolean execute(CommandSender sender, String currentAlias, String[] args) {
    if (!testPermission(sender)) return true;

    Player player;

    if (args.length == 0) {
      if (sender instanceof Player) {
        player = (Player) sender;
      } else {
        sender.sendMessage("Please provide a player!");
        return true;
      }
    } else {
      player = Bukkit.getPlayerExact(args[0]);
      if (player == null) {
        sender.sendMessage("Can't find player " + args[0]);
        return true;
      }
    }

    World world = player.getWorld();

    if (args.length == 4) {
      if (world != null) {
        int pos = 1;
        final int x, y, z;
        try {
          x = getInteger(sender, args[pos++], MIN_COORD, MAX_COORD, true);
          y = getInteger(sender, args[pos++], 0, world.getMaxHeight());
          z = getInteger(sender, args[pos], MIN_COORD, MAX_COORD, true);
        } catch (NumberFormatException ex) {
          sender.sendMessage(ex.getMessage());
          return true;
        }

        player.setBedSpawnLocation(new Location(world, x, y, z), true);
        Command.broadcastCommandMessage(
            sender,
            "Set " + player.getDisplayName() + "'s spawnpoint to " + x + ", " + y + ", " + z);
      }
    } else if (args.length <= 1) {
      Location location = player.getLocation();
      player.setBedSpawnLocation(location, true);
      Command.broadcastCommandMessage(
          sender,
          "Set "
              + player.getDisplayName()
              + "'s spawnpoint to "
              + location.getX()
              + ", "
              + location.getY()
              + ", "
              + location.getZ());
    } else {
      sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage);
      return false;
    }

    return true;
  }
  @SuppressWarnings("deprecation")
  @Override
  public boolean execute(CommandSender sender, String currentAlias, String[] args) {
    if (!testPermission(sender)) return true;
    if ((args.length < 2)) {
      sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage);
      return false;
    }

    Player player = Bukkit.getPlayerExact(args[0]);

    if (player != null) {
      Material material = Material.matchMaterial(args[1]);

      if (material == null) {
        material = Bukkit.getUnsafe().getMaterialFromInternalName(args[1]);
      }

      if (material != null) {
        int amount = 1;
        short data = 0;

        if (args.length >= 3) {
          amount = this.getInteger(sender, args[2], 1, 64);

          if (args.length >= 4) {
            try {
              data = Short.parseShort(args[3]);
            } catch (NumberFormatException ex) {
            }
          }
        }

        ItemStack stack = new ItemStack(material, amount, data);

        if (args.length >= 5) {
          try {
            stack =
                Bukkit.getUnsafe()
                    .modifyItemStack(
                        stack, Joiner.on(' ').join(Arrays.asList(args).subList(4, args.length)));
          } catch (Throwable t) {
            player.sendMessage("Not a valid tag");
            return true;
          }
        }

        player.getInventory().addItem(stack);

        Command.broadcastCommandMessage(
            sender,
            "Gave " + player.getName() + " some " + material.getId() + " (" + material + ")");
      } else {
        sender.sendMessage("There's no item called " + args[1]);
      }
    } else {
      sender.sendMessage("Can't find player " + args[0]);
    }

    return true;
  }