@Override
  public List<String> tabComplete(CommandSender sender, String alias, String[] args) {
    Validate.notNull(sender, "Sender cannot be null");
    Validate.notNull(args, "Arguments cannot be null");
    Validate.notNull(alias, "Alias cannot be null");

    if (args.length == 1) {
      return StringUtil.copyPartialMatches(
          args[0], WHITELIST_SUBCOMMANDS, new ArrayList<String>(WHITELIST_SUBCOMMANDS.size()));
    } else if (args.length == 2) {
      if (args[0].equalsIgnoreCase("add")) {
        List<String> completions = new ArrayList<String>();
        for (OfflinePlayer player : Bukkit.getOfflinePlayers()) {
          String name = player.getName();
          if (StringUtil.startsWithIgnoreCase(name, args[1]) && !player.isWhitelisted()) {
            completions.add(name);
          }
        }
        return completions;
      } else if (args[0].equalsIgnoreCase("remove")) {
        List<String> completions = new ArrayList<String>();
        for (OfflinePlayer player : Bukkit.getWhitelistedPlayers()) {
          String name = player.getName();
          if (StringUtil.startsWithIgnoreCase(name, args[1])) {
            completions.add(name);
          }
        }
        return completions;
      }
    }
    return ImmutableList.of();
  }
 public OfflinePlayer getOfflinePlayer(UUID playerUUID) {
   for (OfflinePlayer p : Bukkit.getOfflinePlayers()) {
     if (p.getUniqueId().equals(playerUUID)) {
       return p;
     }
   }
   return null;
 }
 @Override
 public OfflinePlotPlayer[] getOfflinePlayers() {
   OfflinePlayer[] ops = Bukkit.getOfflinePlayers();
   BukkitOfflinePlayer[] toReturn = new BukkitOfflinePlayer[ops.length];
   for (int i = 0; i < ops.length; i++) {
     toReturn[i] = new BukkitOfflinePlayer(ops[i]);
   }
   return toReturn;
 }
Esempio n. 4
0
  public List<OfflinePlayer> opList() {
    List<OfflinePlayer> ops = new ArrayList<OfflinePlayer>();

    for (OfflinePlayer p : Bukkit.getOfflinePlayers()) {
      if (p.isOp()) {
        ops.add(p);
      }
    }

    return ops;
  }
Esempio n. 5
0
 @SuppressWarnings("deprecation")
 public boolean isKnownPlayer(String playerName) {
   if (Bukkit.getPlayerExact(playerName) != null) {
     return true;
   }
   for (OfflinePlayer offlinePlayer : Bukkit.getOfflinePlayers()) {
     if (offlinePlayer.getName().equalsIgnoreCase(playerName)) {
       return true;
     }
   }
   return false;
 }
  /** Loads all existing chests from the data folder. */
  private void load() {
    dataFolder.mkdirs();

    FilenameFilter filter =
        new FilenameFilter() {
          public boolean accept(File dir, String name) {
            return name.endsWith(YAML_CHEST_EXTENSION);
          }
        };

    for (File chestFile : dataFolder.listFiles(filter)) {
      String chestFileName = chestFile.getName();
      try {
        try {
          UUID playerUUID =
              UUID.fromString(
                  chestFileName.substring(0, chestFileName.length() - YAML_EXTENSION_LENGTH));
          chests.put(playerUUID, InventoryIO.loadFromYaml(chestFile));
        } catch (IllegalArgumentException e) {
          // Assume that the filename isn't a UUID, and is therefore an old player-name chest
          String playerName =
              chestFileName.substring(0, chestFileName.length() - YAML_EXTENSION_LENGTH);
          boolean flagPlayerNotFound = true;

          for (OfflinePlayer player : Bukkit.getOfflinePlayers()) {
            // Search all the known players, load inventory, flag old file for deletion
            if (player.getName().equalsIgnoreCase(playerName)) {
              flagPlayerNotFound = false;
              chests.put(player.getUniqueId(), InventoryIO.loadFromYaml(chestFile));
              chestFile.deleteOnExit();
            }
          }

          if (flagPlayerNotFound) {
            logger.log(Level.WARNING, "Couldn't load chest file: " + chestFileName);
          }
        }
      } catch (Exception e) {
        logger.log(Level.WARNING, "Couldn't load chest file: " + chestFileName);
      }
    }

    logger.info("Loaded " + chests.size() + " chests");
  }
 @Override
 public OfflinePlotPlayer getOfflinePlayer(final UUID uuid) {
   final BiMap<UUID, StringWrapper> map = UUIDHandler.getUuidMap().inverse();
   String name;
   try {
     name = map.get(uuid).value;
   } catch (final NullPointerException e) {
     name = null;
   }
   if (name != null) {
     final OfflinePlayer op = Bukkit.getOfflinePlayer(name);
     if (op.hasPlayedBefore()) {
       return new BukkitOfflinePlayer(op);
     }
   }
   for (final OfflinePlayer player : Bukkit.getOfflinePlayers()) {
     if (getUUID(player).equals(uuid)) {
       return new BukkitOfflinePlayer(player);
     }
   }
   return null;
 }
Esempio n. 8
0
  @Override
  public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {

    File configDir = new File(XConomy.directory + "/config/");
    File configFile = new File(configDir + "/config.yml");

    YamlConfiguration yamlFile = YamlConfiguration.loadConfiguration(configFile);

    if (label.equalsIgnoreCase("money")) {
      if (!(sender instanceof Player)) {
        logger.info("xConomy - INFO - The console can't do this!");
        if (args[0].equalsIgnoreCase("add")) {
          accountActions.depositMoney(
              Bukkit.getOfflinePlayer(args[1]), Double.parseDouble(args[2]));
          System.out.println("blaa");
        }
        return true;
      }

      Player playerSender = null;
      Player player = null;
      Location pLoc = null;
      playerSender = (Player) sender;
      OfflinePlayer offPlayer = this.getServer().getOfflinePlayer(playerSender.getUniqueId());

      String CurrencySingular = yamlFile.getString("Currency.Name.Singular");
      String CurrencyPlural = yamlFile.getString("Currency.Name.Plural");

      player = offPlayer.getPlayer();

      if (args.length == 0) {
        Double balance = accountActions.getPlayerBalance(player);
        if (balance <= 1) {
          player.sendMessage("[BALANCE] " + balance + " " + CurrencySingular);
          return true;
        } else {
          player.sendMessage("[BALANCE] " + balance + " " + CurrencyPlural);
          return true;
        }
      }
      if (args.length == 3) {
        if (args[0].equalsIgnoreCase("add")) {
          System.out.println(this.getServer().getOfflinePlayers());
          OfflinePlayer targetPlayer = null;
          for (int i = 0; i < Bukkit.getOfflinePlayers().length; i++) {
            System.out.println("OfflinePlayer = " + Bukkit.getOfflinePlayers()[i]);
            if (Bukkit.getOfflinePlayers()[i].getPlayer().getName().equalsIgnoreCase(args[1])) {
              targetPlayer =
                  Bukkit.getOfflinePlayer(Bukkit.getOfflinePlayers()[i].getPlayer().getUniqueId());
              accountActions.depositMoney(targetPlayer, Double.parseDouble(args[2]));
              return true;
            }
          }
          if (targetPlayer == null) {
            player.sendMessage("The player " + args[1] + " was not found!");
            return true;
          }
        }
        if (args[0].equalsIgnoreCase("send")) {
          OfflinePlayer targetPlayer = null;
          for (int i = 0; i < Bukkit.getOfflinePlayers().length; i++) {
            if (!Bukkit.getOfflinePlayers()[i].isOnline()) {
              player.sendMessage("The Player is Offline, sorry!");
              return true;
            }
            if (Bukkit.getOfflinePlayers()[i].getPlayer().getName().equalsIgnoreCase(args[1])) {
              if (accountActions.getPlayerBalance(player) < Double.parseDouble(args[2])) {
                player.sendMessage("Sorry, but you haven't enough money to do this");
                return true;
              } else {
                targetPlayer =
                    Bukkit.getOfflinePlayer(
                        Bukkit.getOfflinePlayers()[i].getPlayer().getUniqueId());
                accountActions.depositMoney(targetPlayer, Double.parseDouble(args[2]));
                accountActions.withdrawMoney(player, Double.parseDouble(args[2]));
                if (targetPlayer.isOnline()) {
                  if (Double.parseDouble(args[2]) < 1) {
                    targetPlayer
                        .getPlayer()
                        .sendMessage(
                            "You received "
                                + args[2]
                                + " "
                                + CurrencySingular
                                + " from "
                                + player.getDisplayName());
                  } else {
                    targetPlayer
                        .getPlayer()
                        .sendMessage(
                            "You received "
                                + args[2]
                                + " "
                                + CurrencyPlural
                                + " from "
                                + player.getDisplayName());
                  }
                }
                if (Double.parseDouble(args[2]) < 1) {
                  player.sendMessage(
                      "You have send "
                          + args[2]
                          + " "
                          + CurrencySingular
                          + " to "
                          + targetPlayer.getPlayer().getDisplayName());
                } else {
                  player.sendMessage(
                      "You have send "
                          + args[2]
                          + " "
                          + CurrencyPlural
                          + " to "
                          + targetPlayer.getPlayer().getDisplayName());
                }
                return true;
              }
            }
          }
          if (targetPlayer == null) {
            player.sendMessage("The player " + args[1] + " was not found!");
            return true;
          }
        }
      }
    }

    if (label.equalsIgnoreCase("ecweb")) {
      if (!(sender instanceof Player)) {
        logger.info("xConomy - INFO - The console can't do this!");
      }

      Player playerSender = null;
      Player player = null;
      Location pLoc = null;
      playerSender = (Player) sender;
      OfflinePlayer offPlayer = this.getServer().getOfflinePlayer(playerSender.getUniqueId());

      player = offPlayer.getPlayer();

      if (args.length == 0) {
        player.sendMessage(
            "Nicht genug Parameter, benutze /ecweb help um weitere hilfe zu erhalten!");
        return true;
      }
      if (args[0].equalsIgnoreCase("register")) {
        if (args.length == 3) {
          if (database.createNewPlayer(offPlayer, args[1], args[2])) {
            player.sendMessage("Dein Account wurde im Webinterface angelegt");
          } else {
            player.sendMessage("Du hast bereits ein Account!");
          }
          return true;
        } else {
          player.sendMessage(
              "Um einen Account im Webinterface anlegen zu können, musst du den folgenden Befehlt nutzen");
          player.sendMessage("/ecweb register Username Password");
          return true;
        }
      }
    }
    return false;
  }