Package simpleserver.config.data

Examples of simpleserver.config.data.Homes


  public HomeCommand() {
    super("home [help|set|delete|public|private|ilist|list|invite|uninvite|inspect] [name]", "Teleport to and manage your home");
  }

  public void execute(Player player, String message) {
    Homes homes = player.getServer().data.players.homes;
    String playerName = player.getName();
    String arguments[] = extractArguments(message);
    if (arguments.length == 0) {
      teleportHome(player);
      return;
    }
    String command = arguments[0];
    if (command.equals("help")) {
      usage(player);
    } else if (command.equals("set")) {
      if (homes.get(playerName) != null) {
        player.addTMessage(Color.RED, "You must delete your old home before saving a new one!");
        return;
      }

      homes.set(playerName, homes.makeHomePoint(player.position));
      player.getServer().data.save();
      player.addTMessage(Color.GRAY, "Your home has been saved.");
    } else if (command.equals("delete")) {
      if (homes.get(playerName) == null) {
        player.addTMessage(Color.GRAY, "You don't have a home to delete!");
        return;
      }

      homes.remove(playerName);
      player.getServer().data.save();
      player.addTMessage(Color.GRAY, "Your home has been deleted.");
    } else if (command.equals("public")) {
      HomePoint home = homes.get(playerName);
      if (home == null) {
        player.addTMessage(Color.RED, "You don't have a home to manage!");
        return;
      }
      if (home.isPublic == true) {
        player.addTMessage(Color.GRAY, "Your home is already public!");
        return;
      }
      home.isPublic = true;
      homes.set(playerName, home);
      player.getServer().data.save();
      player.addTMessage(Color.GRAY, "Your home is now public!");
    } else if (command.equals("private")) {
      HomePoint home = homes.get(playerName);
      if (home == null) {
        player.addTMessage(Color.RED, "You don't have a home to manage!");
        return;
      }
      if (home.isPublic == false) {
        player.addTMessage(Color.GRAY, "Your home is already private!");
        return;
      }
      home.isPublic = false;
      homes.set(playerName, home);
      player.getServer().data.save();
      player.addTMessage(Color.GRAY, "Your home is now private!");
    } else if (command.equals("ilist")) {
      List<String> inviteList = new LinkedList<String>();
      List<String> publicList = new LinkedList<String>();
      homes.getVisitableHomes(playerName, inviteList, publicList);
      if (inviteList.isEmpty() && publicList.isEmpty()) {
        player.addTMessage(Color.GRAY, "You cannot visit any home.");
        return;
      }

      player.addTMessage(Color.GRAY, "Public homes: %s", join(publicList).trim());
      player.addTMessage(Color.GRAY, "Homes you are invited to: %s", join(inviteList).trim());

    } else if (command.equals("list")) {
      HomePoint home = homes.get(playerName);
      if (home == null) {
        player.addTMessage(Color.RED, "You don't have a home to manage!");
        return;
      }
      if (home.isPublic) {
        player.addTMessage(Color.GRAY, "Your home is public; everyone can visit it.");
        return;
      }
      Set<String> list = home.getPlayersInvited();
      if (list.isEmpty()) {
        player.addTMessage(Color.GRAY, "You haven't invited anyone.");
        return;
      }
      player.addTMessage(Color.GRAY, "You have invited %s.", join(list).trim());
    } else if (command.equals("invite")) {
      HomePoint home = homes.get(playerName);
      if (home == null) {
        player.addTMessage(Color.RED, "You don't have a home to manage!");
        return;
      }
      if (arguments.length == 1) {
        player.addTMessage(Color.RED, "Invalid argument!");
        usage(player);
        return;
      }
      String iPlayer = arguments[1];
      Player onlineTarget = player.getServer().findPlayer(iPlayer);
      if (onlineTarget != null) {
        iPlayer = onlineTarget.getName();
      }
      if (!home.invites.contains(new NBTString(iPlayer))) {
        home.invites.add(new NBTString(iPlayer));
        player.addTMessage(Color.GRAY, "You just invited %s.", iPlayer);
        if (onlineTarget != null) {
          onlineTarget.addTMessage(Color.GRAY, "You were just invited to visit %s's home.", player.getName());
        }
      } else {
        player.addTMessage(Color.GRAY, "Player has already been invited.");
      }
    } else if (command.equals("uninvite")) {
      HomePoint home = homes.get(playerName);
      if (home == null) {
        player.addTMessage(Color.RED, "You don't have a home to manage!");
        return;
      }
      if (arguments.length == 1) {
        player.addTMessage(Color.RED, "Invalid argument!");
        usage(player);
        return;
      }
      String uiPlayer = home.getInvitedPlayer(arguments[1]);
      if (home.invites.contains(new NBTString(uiPlayer))) {
        home.invites.remove(new NBTString(uiPlayer));
        player.addTMessage(Color.GRAY, "You just uninvited %s.", uiPlayer);
      } else {
        player.addTMessage(Color.GRAY, "Player wasn't invited.");
      }
    } else if (command.equals("inspect")) {
      if (arguments.length < 2) {
        player.addTMessage(Color.GRAY, "No player name given!");
        return;
      }
      String vPlayer = arguments[1];
      HomePoint home = homes.get(vPlayer);
      if (home == null) {
        player.addTMessage(Color.GRAY, "Player doesn't have a home set!");
        return;
      }
      player.teleportWithWarmup(home.position);
    } else {
      if (command.toLowerCase().equals(playerName.toLowerCase())) {
        teleportHome(player);
        return;
      }
      String target = command;
      String onlinePlayer = player.getServer().findName(target);
      if (onlinePlayer != null) {
        target = onlinePlayer;
      } else {
        Set<String> list = homes.getHomesPlayerInvitedTo(playerName);
        for (String p : list) {
          if (p.startsWith(target)) {
            target = p;
            break;
          }
        }
      }
      HomePoint home = homes.get(target);
      if (home == null) {
        usage(player);
        return;
      }
      if ((home.isPublic && player.getServer().findPlayer(target) != null) ||
View Full Code Here

TOP

Related Classes of simpleserver.config.data.Homes

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.