Exemplo n.º 1
0
  public void deleteLot(BytecraftPlayer player, String[] args) {
    ZoneWorld world = plugin.getWorld(player.getWorld());
    if (world == null) {
      return;
    }

    if (args.length < 2) {
      player.sendMessage("syntax: /lot delete [name]");
      return;
    }

    String name = args[1];

    Lot lot = world.getLot(name);
    if (lot == null) {
      player.sendMessage(RED + "No lot named " + name + " found.");
      return;
    }

    Zone zone = plugin.getZone(lot.getZoneName());

    Zone.Permission perm = zone.getUser(player);
    if (perm == Permission.OWNER) {
      // Zone owners can do this
    } else if (lot.isOwner(player)) {
      // Lot owners can always do it
    } else if (player.getRank().canEditZones()) {
      // Admins etc.
    } else {
      player.sendMessage(RED + "You are not an owner of lot " + lot.getName() + ".");
      return;
    }

    try (IContext ctx = plugin.createContext()) {
      IZoneDAO dao = ctx.getZoneDAO();
      dao.deleteLot(lot.getId());
      dao.deleteLotUsers(lot.getId());

      world.deleteLot(lot.getName());

      player.sendMessage(GREEN + lot.getName() + " has been deleted.");
    } catch (DAOException e) {
      throw new RuntimeException(e);
    }
  }
Exemplo n.º 2
0
  public void setLotOwner(BytecraftPlayer player, String[] args) {
    ZoneWorld world = plugin.getWorld(player.getWorld());
    if (world == null) {
      return;
    }

    if (args.length < 3) {
      player.sendMessage("syntax: /lot addowner [name] [player]");
      return;
    }

    String name = args[1];

    Lot lot = world.getLot(name);
    if (lot == null) {
      player.sendMessage(RED + "No lot named " + name + " found.");
      return;
    }

    Zone zone = plugin.getZone(lot.getZoneName());

    Permission perm = zone.getUser(player);
    if (perm == Zone.Permission.OWNER) {
      // Zone owners can do this in communist zones
    } else if (lot.isOwner(player)) {
      // Lot owners can always do it
    } else if (player.getRank().canEditZones()) {
      // Admins etc.
    } else {
      player.sendMessage(RED + "You are not an owner of lot " + lot.getName() + ".");
      return;
    }

    // try partial matching
    List<BytecraftPlayer> candidates = plugin.matchPlayer(args[2]);
    BytecraftPlayer candidate = null;
    if (candidates.size() != 1) {
      // try exact matching
      candidate = plugin.getPlayerOffline(args[2]);
      if (candidate == null) {
        // give up
        player.sendMessage(RED + "Player " + args[2] + " was not found.");
        return;
      }
    } else {
      candidate = candidates.get(0);
    }

    try (IContext ctx = plugin.createContext()) {
      IZoneDAO dao = ctx.getZoneDAO();

      if ("addowner".equals(args[0])) {

        if (lot.isOwner(candidate)) {
          player.sendMessage(
              RED + candidate.getDisplayName() + RED + " is already an owner of lot " + name + ".");
          return;
        } else {
          lot.addOwner(candidate);
          dao.addLotUser(lot.getId(), candidate.getName());
          player.sendMessage(
              GREEN
                  + candidate.getDisplayName()
                  + GREEN
                  + " has been added as owner of "
                  + lot.getName()
                  + ".");
        }
      } else if ("delowner".equals(args[0])) {
        if (!lot.isOwner(candidate)) {
          player.sendMessage(
              RED + candidate.getDisplayName() + RED + " is not an owner of lot " + name + ".");
          return;
        } else {
          lot.deleteOwner(candidate);
          dao.deleteLotUser(lot.getId(), candidate.getName());

          player.sendMessage(
              GREEN
                  + candidate.getDisplayName()
                  + GREEN
                  + " is no longer an owner of "
                  + lot.getName()
                  + ".");
        }
      }
    } catch (DAOException e) {
      throw new RuntimeException(e);
    }
  }