Example #1
0
  @Override
  public boolean run(CommandSender _sender, String[] _args) {
    if (_sender instanceof Player) {
      if (_args.length > 0) {
        Player invoker = (Player) _sender;
        UUID invokerID = invoker.getUniqueId();
        String joinedName = Empires.m_playerHandler.getPlayerJoinedCivilization(invokerID);

        // default does not have a desc!
        if (joinedName.equals(PlayerHandler.m_defaultCiv)) {
          setError("You cannot change " + PlayerHandler.m_defaultCiv + " description");
          return false;
        }

        try {
          // do we have permission?
          Role invokerRole = Empires.m_playerHandler.getPlayerRole(invokerID);
          if (Empires.m_joinableHandler.getJoinableHasPermissionForRole(
              joinedName, GroupPermission.SET_DESC, invokerRole)) {
            // build description
            String desc = "";
            for (int i = 0; i < _args.length; i++) {
              desc = desc + " " + _args[i];
            }

            desc = desc.substring(1);

            // set description
            Empires.m_joinableHandler.setJoinableDescription(joinedName, desc);

            // inform everyone
            Empires.m_joinableHandler.invokeJoinableBroadcastToJoined(
                joinedName,
                ChatColor.YELLOW
                    + invoker.getDisplayName()
                    + " updated the civilization description!");

            return true; // success!
          }

          setError("You don't have permission to change the description!");
          return false;
        } catch (EmpiresJoinableDoesNotExistException e) {
          e.printStackTrace();
        }
      }

      setError("Invalid arguments!");
      return false;
    }

    setError("Only players can invoke the 'desc' command");
    return false;
  }
Example #2
0
  @Override
  public boolean run(CommandSender _sender, String[] _args) {
    if (_sender instanceof Player) {
      Player invoker = (Player) _sender;
      UUID invokerID = invoker.getUniqueId();
      String joinedName = Empires.m_playerHandler.getPlayerJoinedCivilization(invokerID);

      if (joinedName.equals(PlayerHandler.m_defaultCiv)) {
        setError("You cannot claim for wilderness!");
        return false;
      }

      Role invokerRole = Empires.m_playerHandler.getPlayerRole(invokerID);

      // do we have permission to claim land?
      try {
        if (!Empires.m_joinableHandler.getJoinableHasPermissionForRole(
            joinedName, GroupPermission.CLAIM, invokerRole)) {
          setError("You do not have permission to claim land!");
          return false;
        }
      } catch (EmpiresJoinableDoesNotExistException e) {
        e.printStackTrace();

        setError("Something went wrong!");
        return false;
      }

      boolean val = !Empires.m_playerHandler.getPlayerAutoClaiming(invokerID);

      Empires.m_playerHandler.setPlayerAutoClaiming(invokerID, val);

      invoker.sendMessage(ChatColor.YELLOW + "Auto-claiming: " + val);

      return true;
    }

    setError("Only players can invoke the 'autoclaim' command");
    return false;
  }
Example #3
0
  @Override
  public boolean run(CommandSender _sender, String[] _args) {
    if (_sender instanceof Player) {
      Player invoker = (Player) _sender;
      UUID invokerID = invoker.getUniqueId();
      String joinedName = Empires.m_playerHandler.getPlayerJoinedCivilization(invokerID);

      try {
        if (_args.length == 0) { // we are teleporting to our home
          Location homeLoc = Empires.m_joinableHandler.getJoinableHome(joinedName);

          if (homeLoc != null) {
            teleport(invoker, homeLoc);
            return true;
          }

          setError("You're homeless!");
          return false;
        } else if (_args.length == 1) { // we are attempting to teleport elsewhere
          // does the joinable exist?
          if (Empires.m_joinableHandler.getJoinableExists(_args[0])) {

            if (Empires.m_joinableHandler.getJoinableEmpireStatus(joinedName)) {
              // we are an empire
              setError("You cannot teleport there!");
              return false;
            } else {
              // we are NOT an empire
              // is this joinable our empire?
              if (Empires.m_joinableHandler
                  .getKingdomEmpire(joinedName)
                  .equalsIgnoreCase(_args[0])) {
                // allow teleportation
                // gather location
                Location homeLoc = Empires.m_joinableHandler.getJoinableHome(_args[0]);

                if (homeLoc != null) {
                  teleport(invoker, homeLoc);
                  return true;
                }

                setError(_args[0] + " does not have a home set!");
                return false;
              }
            }
          }

          setError("Could not find a civilization named '" + _args[0] + "'");
          return false;
        }

      } catch (EmpiresJoinableDoesNotExistException e) {
        e.printStackTrace();

        setError("Something went wrong!");
        return false;
      }
    }

    setError("Only players can invoke the 'home' command");
    return false;
  }
Example #4
0
  @Override
  public boolean run(CommandSender _sender, String[] _args) {
    if (_sender instanceof Player) {
      if (_args.length == 1) {
        Player invoker = (Player) _sender;
        UUID invokerID = invoker.getUniqueId();
        String joinedName = Empires.m_playerHandler.getPlayerJoinedCivilization(invokerID);

        if (joinedName.equals(PlayerHandler.m_defaultCiv)) {
          setError("You cannot rename " + PlayerHandler.m_defaultCiv + "!");
          return false;
        }

        try {
          Role invokerRole = Empires.m_playerHandler.getPlayerRole(invokerID);
          if (!Empires.m_joinableHandler.getJoinableHasPermissionForRole(
              joinedName, GroupPermission.RENAME, invokerRole)) {
            setError("You do not have permission to rename your civilization!");
            return false;
          }
        } catch (EmpiresJoinableDoesNotExistException e) {
          e.printStackTrace();

          setError("Something went wrong!");
          return false;
        }

        if (Empires.m_joinableHandler.getJoinableExists(_args[0])) {
          setError("A civilization with the name '" + _args[0] + "' already exists!");
          return false;
        }

        // check for colors and permission
        if (!invoker.hasPermission("Empires.colors.joinable")) {
          if (_args[0].contains("&")) {
            setError("You do not have permission to put colors in civilization names!");
            return false;
          }
        }

        try {
          // update name
          Empires.m_joinableHandler.setJoinableName(joinedName, _args[0]);

          // inform
          Empires.m_joinableHandler.invokeJoinableBroadcastToJoined(
              _args[0],
              ChatColor.YELLOW
                  + invoker.getCustomName()
                  + " renamed the civilization to '"
                  + _args[0]
                  + "!");

          return true;
        } catch (EmpiresJoinableDoesNotExistException e) {
          e.printStackTrace();

          setError("Something went wrong!");
          return false;
        } catch (EmpiresJoinableInvalidCharacterException e) {
          e.printStackTrace();

          setError("Invalid characters found in name! Try a different name.");
          return true;
        }
      }

      setError("Invalid arguments!");
      return false;
    }

    setError("Only players can invoke the 'name' command");
    return false;
  }