Exemple #1
0
  @CommandNode(
      name = "remove",
      permission = "mytown.cmd.assistant.ranks.remove",
      parentName = "mytown.cmd.everyone.ranks",
      completionKeys = {"rankCompletion"})
  public static void ranksRemoveCommand(ICommandSender sender, List<String> args) {

    if (args.size() < 1)
      throw new WrongUsageException(getLocal().getLocalization("mytown.cmd.usage.ranks"));
    Resident res = getDatasource().getOrMakeResident(sender);
    Town town = res.getSelectedTown();
    Rank rank = getRankFromTown(town, args.get(0));

    if (town.getDefaultRank().equals(rank))
      throw new CommandException(getLocal().getLocalization("mytown.cmd.err.rank.defaultDeletion"));

    if (getDatasource().deleteRank(rank)) {
      res.sendMessage(
          getLocal()
              .getLocalization("mytown.notification.town.ranks.rem", args.get(0), town.getName()));
    } else {
      res.sendMessage(
          getLocal().getLocalization("mytown.cmd.err.ranks.rem.notallowed", args.get(0)));
    }
  }
  @Command(
      name = "pass",
      permission = "mytown.cmd.mayor.pass",
      parentName = "mytown.cmd",
      syntax = "/town pass <resident>",
      completionKeys = {"residentCompletion"})
  public static CommandResponse passCommand(ICommandSender sender, List<String> args) {
    if (args.size() < 1) return CommandResponse.SEND_SYNTAX;

    Resident res = MyTownUniverse.instance.getOrMakeResident(sender);
    Resident target = getResidentFromName(args.get(0));

    if (res == target) {
      throw new MyTownCommandException("mytown.cmd.err.resident.same");
    }

    Town town = getTownFromResident(res);

    if (!town.residentsMap.containsKey(target)) {
      throw new MyTownCommandException(
          "mytown.cmd.err.resident.notsametown", target.getPlayerName(), town.getName());
    }
    if (town.residentsMap.get(res).getType() == Rank.Type.MAYOR) {
      getDatasource().updateResidentToTownLink(target, town, town.ranksContainer.getMayorRank());
      target.sendMessage(getLocal().getLocalization("mytown.notification.town.mayorShip.passed"));
      getDatasource().updateResidentToTownLink(res, town, town.ranksContainer.getDefaultRank());
      res.sendMessage(getLocal().getLocalization("mytown.notification.town.mayorShip.taken"));
    } else {
      // ...
    }
    return CommandResponse.DONE;
  }
Exemple #3
0
  @CommandNode(
      name = "promote",
      permission = "mytown.cmd.assistant.promote",
      parentName = "mytown.cmd",
      completionKeys = {"residentCompletion", "rankCompletion"})
  public static void promoteCommand(ICommandSender sender, List<String> args) {

    // /t promote <user> <rank>
    if (args.size() < 2)
      throw new WrongUsageException(getLocal().getLocalization("mytown.cmd.usage.promote"));
    Resident resSender = getDatasource().getOrMakeResident(sender);
    Resident resTarget = getResidentFromName(args.get(0));
    Town town = getTownFromResident(resSender);

    if (!resTarget.getTowns().contains(town))
      throw new CommandException(
          getLocal()
              .getLocalization("mytown.cmd.err.resident.notsametown", args.get(0), town.getName()));

    // TODO: implement this properly
    if (args.get(1).equalsIgnoreCase("mayor"))
      throw new CommandException(getLocal().getLocalization("mytown.cmd.err.promote.notMayor"));
    Rank rank = getRankFromTown(town, args.get(1));
    if (getDatasource().updateResidentToTownLink(resTarget, town, rank)) {
      resSender.sendMessage(getLocal().getLocalization("mytown.cmd.promote.success.sender"));
      resTarget.sendMessage(
          getLocal()
              .getLocalization(
                  "mytown.cmd.promote.success.target", rank.getName(), town.getName()));
    }
  }
  @Command(
      name = "promote",
      permission = "mytown.cmd.assistant.promote",
      parentName = "mytown.cmd",
      syntax = "/town promote <resident> <rank>",
      completionKeys = {"residentCompletion", "rankCompletion"})
  public static CommandResponse promoteCommand(ICommandSender sender, List<String> args) {
    if (args.size() < 2) return CommandResponse.SEND_SYNTAX;
    Resident resSender = MyTownUniverse.instance.getOrMakeResident(sender);
    Resident resTarget = getResidentFromName(args.get(0));
    Town town = getTownFromResident(resSender);

    if (!resTarget.townsContainer.contains(town))
      throw new MyTownCommandException(
          "mytown.cmd.err.resident.notsametown", args.get(0), town.getName());

    Rank mayorRank = town.ranksContainer.getMayorRank();
    if (args.get(1).equalsIgnoreCase(mayorRank.getName()))
      throw new MyTownCommandException("mytown.cmd.err.promote.notMayor");
    Rank rank = getRankFromTown(town, args.get(1));
    if (getDatasource().updateResidentToTownLink(resTarget, town, rank)) {
      resSender.sendMessage(
          getLocal()
              .getLocalization(
                  "mytown.cmd.promote.success.sender", resTarget.getPlayerName(), rank.getName()));
      resTarget.sendMessage(
          getLocal()
              .getLocalization(
                  "mytown.cmd.promote.success.target", rank.getName(), town.getName()));
    }
    return CommandResponse.DONE;
  }
Exemple #5
0
 public boolean hasPermission(Resident res, Segment segment, int dim, int x, int y, int z) {
   TownBlock townBlock = getDatasource().getBlock(dim, x >> 4, z >> 4);
   if (townBlock == null) {
     if (res == null) {
       return !Wild.instance.getValue(segment.getFlag()).equals(segment.getDenialValue());
     } else {
       if (!Wild.instance.hasPermission(res, segment.getFlag(), segment.getDenialValue())) {
         res.sendMessage(segment.getFlag().getLocalizedProtectionDenial());
         return false;
       }
     }
   } else {
     Town town = townBlock.getTown();
     if (res == null) {
       return !town.getValueAtCoords(dim, x, y, z, segment.getFlag())
           .equals(segment.getDenialValue());
     } else {
       if (!town.hasPermission(res, segment.getFlag(), segment.getDenialValue(), dim, x, y, z)) {
         res.protectionDenial(
             segment.getFlag().getLocalizedProtectionDenial(),
             Formatter.formatOwnersToString(town, dim, x, y, z));
         return false;
       }
     }
   }
   return true;
 }
    @Command(
        name = "reset",
        permission = "mytown.cmd.assistant.ranks.reset",
        parentName = "mytown.cmd.everyone.ranks",
        syntax = "/town ranks reset")
    public static CommandResponse ranksResetCommand(ICommandSender sender, List<String> args) {
      Resident res = MyTownUniverse.instance.getOrMakeResident(sender);
      Town town = getTownFromResident(res);

      for (Rank defaultRank : Rank.defaultRanks) {
        Rank rank = town.ranksContainer.get(defaultRank.getName());

        rank.permissionsContainer.clear();
        rank.permissionsContainer.addAll(defaultRank.permissionsContainer);
        rank.setType(defaultRank.getType());

        getDatasource().saveRank(rank);
      }

      for (int i = 0; i < town.ranksContainer.size(); i++) {
        Rank rank = town.ranksContainer.get(i);
        if (!Rank.defaultRanks.contains(rank.getName())) {
          getDatasource().deleteRank(rank);
          i--;
        }
      }

      res.sendMessage(getLocal().getLocalization("mytown.notification.ranks.reset"));

      return CommandResponse.DONE;
    }
Exemple #7
0
  @CommandNode(
      name = "add",
      permission = "mytown.cmd.assistant.ranks.add",
      parentName = "mytown.cmd.everyone.ranks",
      completionKeys = {"-", "ranksCompletion"})
  public static void ranksAddCommand(ICommandSender sender, List<String> args) {

    if (args.size() < 2)
      throw new WrongUsageException(getLocal().getLocalization("mytown.cmd.usage.ranks"));
    Resident res = getDatasource().getOrMakeResident(sender);
    Town town = getTownFromResident(res);

    if (town.hasRankName(args.get(0)))
      throw new CommandException(
          getLocal().getLocalization("mytown.cmd.err.ranks.add.already", args.get(0)));
    if (!town.hasRankName(args.get(1)))
      throw new CommandException(
          getLocal().getLocalization("mytown.cmd.err.ranks.add.notexist", args.get(1)));

    Rank rank = new Rank(args.get(0), town.getRank(args.get(1)).getPermissions(), town);
    getDatasource().saveRank(rank, false); // TODO: Set default properly?
    res.sendMessage(
        getLocal()
            .getLocalization("mytown.notification.town.ranks.add", args.get(0), town.getName()));
  }
    @Command(
        name = "remove",
        permission = "mytown.cmd.assistant.ranks.remove",
        parentName = "mytown.cmd.everyone.ranks",
        syntax = "/town ranks remove <rank>",
        completionKeys = {"rankCompletion"})
    public static CommandResponse ranksRemoveCommand(ICommandSender sender, List<String> args) {
      if (args.size() < 1) return CommandResponse.SEND_SYNTAX;

      Resident res = MyTownUniverse.instance.getOrMakeResident(sender);
      Town town = getTownFromResident(res);
      Rank rank = getRankFromTown(town, args.get(0));

      if (rank.getType().unique) {
        throw new MyTownCommandException("mytown.cmd.err.ranks.cantDelete");
      }

      for (Rank residentRank : town.residentsMap.values()) {
        if (residentRank == rank) {
          throw new MyTownCommandException("mytown.cmd.err.ranks.assigned");
        }
      }

      getDatasource().deleteRank(rank);
      res.sendMessage(
          getLocal()
              .getLocalization("mytown.notification.town.ranks.rem", args.get(0), town.getName()));

      return CommandResponse.DONE;
    }
    @Command(
        name = "add",
        permission = "mytown.cmd.assistant.ranks.add",
        parentName = "mytown.cmd.everyone.ranks",
        syntax = "/town ranks add <name> [templateRank]",
        completionKeys = {"-", "ranksCompletion"})
    public static CommandResponse ranksAddCommand(ICommandSender sender, List<String> args) {
      if (args.size() < 1) return CommandResponse.SEND_SYNTAX;

      Resident res = MyTownUniverse.instance.getOrMakeResident(sender);
      Town town = getTownFromResident(res);

      if (town.ranksContainer.contains(args.get(0)))
        throw new MyTownCommandException("mytown.cmd.err.ranks.add.already", args.get(0));

      Rank rank = new Rank(args.get(0), town, Rank.Type.REGULAR);
      if (args.size() == 2) {
        Rank template = getRankFromTown(town, args.get(1));
        rank.permissionsContainer.addAll(template.permissionsContainer);
      }

      getDatasource().saveRank(rank);

      res.sendMessage(
          getLocal()
              .getLocalization("mytown.notification.town.ranks.add", args.get(0), town.getName()));
      return CommandResponse.DONE;
    }
Exemple #10
0
  @CommandNode(
      name = "list",
      permission = "mytown.cmd.assistant.ranks.perm.list",
      parentName = "mytown.cmd.assistant.ranks.perm")
  public static void ranksPermListCommand(ICommandSender sender, List<String> args) {

    Rank rank;
    Resident res = getDatasource().getOrMakeResident(sender);
    Town town = getTownFromResident(res);
    if (args.size() == 0) {
      rank = getRankFromResident(res);
    } else {
      rank = getRankFromTown(town, args.get(0));
    }

    String msg = "";
    for (String s : rank.getPermissions()) {
      msg += '\n' + s;
    }

    res.sendMessage(
        getLocal()
            .getLocalization(
                "mytown.notification.town.ranks.perm.list",
                rank.getName(),
                rank.getTown().getName(),
                msg));
  }
Exemple #11
0
  @CommandNode(
      name = "remove",
      permission = "mytown.cmd.assistant.ranks.perm.remove",
      parentName = "mytown.cmd.assistant.ranks.perm")
  public static void ranksPermRemoveCommand(ICommandSender sender, List<String> args) {

    if (args.size() < 2)
      throw new WrongUsageException(getLocal().getLocalization("mytown.cmd.usage.ranks.perm"));

    Resident res = getDatasource().getOrMakeResident(sender);
    Town town = getTownFromResident(res);

    Rank rank = getRankFromTown(town, args.get(0));

    if (!CommandManager.commandList.keySet().contains(args.get(1)))
      throw new CommandException(
          getLocal().getLocalization("mytown.cmd.err.ranks.perm.notexist", args.get(1)));

    // Removing permission if everything is alright
    if (rank.removePermission(args.get(1))) {
      getDatasource().saveRank(rank, rank.getTown().getDefaultRank().equals(rank));
      res.sendMessage(
          getLocal()
              .getLocalization(
                  "mytown.notification.town.ranks.perm.remove", args.get(1), args.get(0)));
    } else
      throw new CommandException(
          getLocal().getLocalization("mytown.cmd.err.ranks.perm.remove.failed", args.get(1)));
  }
  @Command(
      name = "unclaim",
      permission = "mytown.cmd.assistant.unclaim",
      parentName = "mytown.cmd",
      syntax = "/town unclaim")
  public static CommandResponse unclaimCommand(ICommandSender sender, List<String> args) {
    EntityPlayer player = (EntityPlayer) sender;
    Resident res = MyTownUniverse.instance.getOrMakeResident(sender);
    TownBlock block = getBlockAtResident(res);
    Town town = getTownFromResident(res);

    if (town != block.getTown())
      throw new MyTownCommandException("mytown.cmd.err.unclaim.notInTown");
    if (block.isPointIn(town.getSpawn().getDim(), town.getSpawn().getX(), town.getSpawn().getZ()))
      throw new MyTownCommandException("mytown.cmd.err.unclaim.spawnPoint");
    if (!checkNearby(block.getDim(), block.getX(), block.getZ(), town)
        && town.townBlocksContainer.size() <= 1) {
      throw new MyTownCommandException("mytown.cmd.err.unclaim.lastClaim");
    }

    getDatasource().deleteBlock(block);
    res.sendMessage(
        getLocal()
            .getLocalization(
                "mytown.notification.block.removed",
                block.getX() << 4,
                block.getZ() << 4,
                block.getX() << 4 + 15,
                block.getZ() << 4 + 15,
                town.getName()));
    makeBankRefund(player, town, block.getPricePaid());
    return CommandResponse.DONE;
  }
Exemple #13
0
  @CommandNode(name = "claim", permission = "mytown.cmd.assistant.claim", parentName = "mytown.cmd")
  public static void claimCommand(ICommandSender sender, List<String> args) {
    EntityPlayer player = (EntityPlayer) sender;
    Resident res = getDatasource().getOrMakeResident(player);
    Town town = getTownFromResident(res);

    if (getDatasource().hasBlock(player.dimension, player.chunkCoordX, player.chunkCoordZ))
      throw new CommandException(getLocal().getLocalization("mytown.cmd.err.claim.already"));
    if (checkNearby(
        player.dimension,
        player.chunkCoordX,
        player.chunkCoordZ,
        town)) // Checks if the player can claim far
    Assert.Perm(player, "mytown.cmd.assistant.claim.far");
    Block block =
        getDatasource().newBlock(player.dimension, player.chunkCoordX, player.chunkCoordZ, town);
    if (block == null) throw new CommandException("Failed to create Block"); // TODO Localize
    getDatasource().saveBlock(block);
    res.sendMessage(
        getLocal()
            .getLocalization(
                "mytown.notification.block.added",
                block.getX() * 16,
                block.getZ() * 16,
                block.getX() * 16 + 15,
                block.getZ() * 16 + 15,
                town.getName()));
  }
  @Command(
      name = "kick",
      permission = "mytown.cmd.assistant.kick",
      parentName = "mytown.cmd",
      syntax = "/town kick <resident>",
      completionKeys = {"residentCompletion"})
  public static CommandResponse kickCommand(ICommandSender sender, List<String> args) {
    if (args.size() < 1) {
      return CommandResponse.SEND_SYNTAX;
    }
    Resident res = MyTownUniverse.instance.getOrMakeResident(sender);
    Resident target = getResidentFromName(args.get(0));
    Town town = getTownFromResident(res);
    if (!target.townsContainer.contains(town)) {
      throw new MyTownCommandException(
          "mytown.cmd.err.resident.notsametown", args.get(0), town.getName());
    }
    if (target == res) {
      throw new MyTownCommandException("mytown.cmd.err.kick.self");
    }

    if (town.residentsMap.get(target) == town.ranksContainer.getMayorRank()) {
      throw new MyTownCommandException("mytown.cmd.err.kick.mayor");
    }

    getDatasource().unlinkResidentFromTown(target, town);
    target.sendMessage(
        getLocal().getLocalization("mytown.notification.town.kicked", town.getName()));
    town.notifyEveryone(
        getLocal()
            .getLocalization(
                "mytown.notification.town.left", target.getPlayerName(), town.getName()));
    return CommandResponse.DONE;
  }
Exemple #15
0
  @CommandNode(
      name = "unclaim",
      permission = "mytown.cmd.assistant.unclaim",
      parentName = "mytown.cmd")
  public static void unclaimCommand(ICommandSender sender, List<String> args) {
    EntityPlayer pl = (EntityPlayer) sender;
    Resident res = getDatasource().getOrMakeResident(pl);
    Block block = getBlockAtResident(res);
    Town town = block.getTown();

    if (!block.isPointIn(
        town.getSpawn().getDim(), town.getSpawn().getX(), town.getSpawn().getZ())) {
      getDatasource().deleteBlock(block);
      res.sendMessage(
          getLocal()
              .getLocalization(
                  "mytown.notification.block.removed",
                  block.getX() << 4,
                  block.getZ() << 4,
                  block.getX() << 4 + 15,
                  block.getZ() << 4 + 15,
                  town.getName()));
    } else {
      throw new CommandException("§cYou cannot delete the Block containing the spawn point!");
    }
  }
Exemple #16
0
 public static void sendMessageBackToSender(ICommandSender sender, String message) {
   if (sender instanceof EntityPlayer) {
     Resident res = MyTownUniverse.instance.getOrMakeResident(sender);
     res.sendMessage(message);
   } else {
     sender.addChatMessage(new ChatComponentText(message));
   }
 }
Exemple #17
0
 public static void makeRefund(EntityPlayer player, int amount) {
   if (amount == 0) return;
   Resident res = MyTownUniverse.instance.getOrMakeResident(player);
   EconomyProxy.getEconomy().giveMoneyToPlayer(player, amount);
   res.sendMessage(
       getLocal()
           .getLocalization(
               "mytown.notification.resident.refund", EconomyProxy.getCurrency(amount)));
 }
Exemple #18
0
  @CommandNode(
      name = "invite",
      permission = "mytown.cmd.assistant.invite",
      parentName = "mytown.cmd",
      completionKeys = {"residentCompletion"})
  public static void inviteCommand(ICommandSender sender, List<String> args) {
    Resident res = getDatasource().getOrMakeResident(sender);
    Town town = getTownFromResident(res);
    if (args.size() < 1)
      throw new WrongUsageException(getLocal().getLocalization("mytown.cmd.usage.invite"));
    Resident target = getResidentFromName(args.get(0));
    if (town.hasResident(args.get(0)))
      throw new CommandException(
          getLocal().getLocalization("mytown.cmd.err.invite.already", args.get(0), town.getName()));

    target.addInvite(town);
    target.sendMessage(
        getLocal().getLocalization("mytown.notification.town.invited", town.getName()));
    res.sendMessage(
        getLocal().getLocalization("mytown.notification.town.invite.sent", args.get(0)));
  }
Exemple #19
0
 public static void makePayment(EntityPlayer player, int amount) {
   if (amount == 0) return;
   Resident res = MyTownUniverse.instance.getOrMakeResident(player);
   if (!EconomyProxy.getEconomy().takeMoneyFromPlayer(player, amount)) {
     throw new MyTownCommandException(
         "mytown.cmd.err.resident.payment", EconomyProxy.getCurrency(amount));
   }
   res.sendMessage(
       getLocal()
           .getLocalization(
               "mytown.notification.resident.payment", EconomyProxy.getCurrency(amount)));
 }
  @Command(
      name = "invite",
      permission = "mytown.cmd.assistant.invite",
      parentName = "mytown.cmd",
      syntax = "/town invite <resident>",
      completionKeys = {"residentCompletion"})
  public static CommandResponse inviteCommand(ICommandSender sender, List<String> args) {
    Resident res = MyTownUniverse.instance.getOrMakeResident(sender);
    Town town = getTownFromResident(res);
    if (args.size() < 1) return CommandResponse.SEND_SYNTAX;
    Resident target = getResidentFromName(args.get(0));
    if (town.residentsMap.contains(args.get(0)))
      throw new MyTownCommandException(
          "mytown.cmd.err.invite.already", args.get(0), town.getName());

    getDatasource().saveTownInvite(target, town);
    target.sendMessage(
        getLocal().getLocalization("mytown.notification.town.invited", town.getName()));
    res.sendMessage(
        getLocal().getLocalization("mytown.notification.town.invite.sent", args.get(0)));
    return CommandResponse.DONE;
  }
 @Command(
     name = "show",
     permission = "mytown.cmd.assistant.plot.limit.show",
     parentName = "mytown.cmd.assistant.plot.limit",
     syntax = "/town plot limit show")
 public static CommandResponse plotLimitShowCommand(ICommandSender sender, List<String> args) {
   Resident res = MyTownUniverse.instance.getOrMakeResident(sender);
   Town town = getTownFromResident(res);
   res.sendMessage(
       getLocal()
           .getLocalization(
               "mytown.notification.plot.limit", town.plotsContainer.getMaxPlots()));
   return CommandResponse.DONE;
 }
Exemple #22
0
  @CommandNode(
      name = "setspawn",
      permission = "mytown.cmd.assistant.setspawn",
      parentName = "mytown.cmd")
  public static void setSpawnCommand(ICommandSender sender, List<String> args) {
    EntityPlayer player = (EntityPlayer) sender;
    Resident res = getDatasource().getOrMakeResident(player);
    Town town = getTownFromResident(res);

    town.getSpawn()
        .setDim(player.dimension)
        .setPosition((float) player.posX, (float) player.posY, (float) player.posZ)
        .setRotation(player.cameraYaw, player.cameraPitch);

    getDatasource().saveTown(town);

    res.sendMessage(getLocal().getLocalization("mytown.notification.town.setspawn"));
  }
    @Command(
        name = "set",
        permission = "mytown.cmd.assistant.ranks.set",
        parentName = "mytown.cmd.everyone.ranks",
        syntax = "/town ranks set <rank> <type>",
        completionKeys = {"rankCompletion"})
    public static CommandResponse ranksSetCommand(ICommandSender sender, List<String> args) {
      if (args.size() < 2) {
        return CommandResponse.SEND_SYNTAX;
      }

      Resident res = MyTownUniverse.instance.getOrMakeResident(sender);
      Town town = getTownFromResident(res);
      Rank rank = getRankFromTown(town, args.get(0));
      Rank.Type type = getRankTypeFromString(args.get(1));

      if (type.unique) {
        Rank fromRank = town.ranksContainer.get(type);
        if (fromRank == rank) {
          throw new MyTownCommandException("mytown.cmd.err.ranks.set.already", type.toString());
        }

        fromRank.setType(Rank.Type.REGULAR);
        rank.setType(type);

        getDatasource().saveRank(rank);
        getDatasource().saveRank(fromRank);
      } else {
        if (rank.getType().unique) {
          throw new MyTownCommandException("mytown.cmd.err.ranks.set.unique", rank.getName());
        }

        rank.setType(type);

        getDatasource().saveRank(rank);
      }

      res.sendMessage(
          getLocal()
              .getLocalization(
                  "mytown.notification.ranks.set.successful", rank.getName(), type.toString()));
      return CommandResponse.DONE;
    }
  @Command(
      name = "rename",
      permission = "mytown.cmd.assistant.rename",
      parentName = "mytown.cmd",
      syntax = "/town rename <name>")
  public static CommandResponse renameCommand(ICommandSender sender, List<String> args) {
    if (args.size() < 1) return CommandResponse.SEND_SYNTAX;

    Resident res = MyTownUniverse.instance.getOrMakeResident(sender);
    Town town = getTownFromResident(res);

    if (getUniverse().towns.contains(args.get(0))) // Is the town name already in use?
    throw new MyTownCommandException("mytown.cmd.err.newtown.nameinuse", args.get(0));

    town.rename(args.get(0));
    getDatasource().saveTown(town);
    res.sendMessage(getLocal().getLocalization("mytown.notification.town.renamed"));
    return CommandResponse.DONE;
  }
    @Command(
        name = "remove",
        permission = "mytown.cmd.assistant.ranks.perm.remove",
        parentName = "mytown.cmd.assistant.ranks.perm",
        syntax = "/town ranks perm remove <rank> <perm>",
        completionKeys = {"rankCompletion"})
    public static CommandResponse ranksPermRemoveCommand(ICommandSender sender, List<String> args) {
      if (args.size() < 2) return CommandResponse.SEND_SYNTAX;

      Resident res = MyTownUniverse.instance.getOrMakeResident(sender);
      Town town = getTownFromResident(res);
      Rank rank = getRankFromTown(town, args.get(0));

      getDatasource().deleteRankPermission(rank, args.get(1));
      res.sendMessage(
          getLocal()
              .getLocalization(
                  "mytown.notification.town.ranks.perm.remove", args.get(1), args.get(0)));

      return CommandResponse.DONE;
    }
    @Command(
        name = "set",
        permission = "mytown.cmd.assistant.plot.limit.set",
        parentName = "mytown.cmd.assistant.plot.limit",
        syntax = "/town plot limit set <limit>")
    public static CommandResponse plotLimitSetCommand(ICommandSender sender, List<String> args) {
      if (args.size() < 1) return CommandResponse.SEND_SYNTAX;

      if (!StringUtils.tryParseInt(args.get(0)) || Integer.parseInt(args.get(0)) < 1) {
        throw new MyTownCommandException("mytown.cmd.err.notPositiveInteger", args.get(0));
      }
      int limit = Integer.parseInt(args.get(0));
      Resident res = MyTownUniverse.instance.getOrMakeResident(sender);
      Town town = getTownFromResident(res);
      town.plotsContainer.setMaxPlots(limit);
      getDatasource().saveTown(town);
      res.sendMessage(
          getLocal()
              .getLocalization(
                  "mytown.notification.plot.limit.set", town.plotsContainer.getMaxPlots()));
      return CommandResponse.DONE;
    }
  @Command(
      name = "setspawn",
      permission = "mytown.cmd.assistant.setspawn",
      parentName = "mytown.cmd",
      syntax = "/town setspawn")
  public static CommandResponse setSpawnCommand(ICommandSender sender, List<String> args) {
    EntityPlayer player = (EntityPlayer) sender;
    Resident res = MyTownUniverse.instance.getOrMakeResident(player);
    Town town = getTownFromResident(res);

    if (!town.isPointInTown(player.dimension, (int) player.posX, (int) player.posZ))
      throw new MyTownCommandException(
          getLocal().getLocalization("mytown.cmd.err.setspawn.notintown", town.getName()));

    makePayment(player, Config.instance.costAmountSetSpawn.get());

    town.getSpawn()
        .setDim(player.dimension)
        .setPosition((float) player.posX, (float) player.posY, (float) player.posZ)
        .setRotation(player.cameraYaw, player.cameraPitch);
    getDatasource().saveTown(town);
    res.sendMessage(getLocal().getLocalization("mytown.notification.town.setspawn"));
    return CommandResponse.DONE;
  }
  @Command(
      name = "list",
      permission = "mytown.cmd.assistant.ranks.perm.list",
      parentName = "mytown.cmd.assistant.ranks.perm",
      syntax = "/town ranks perm list [rank]")
  public static CommandResponse ranksPermListCommand(ICommandSender sender, List<String> args) {
    Rank rank;
    Resident res = MyTownUniverse.instance.getOrMakeResident(sender);
    Town town = getTownFromResident(res);
    if (args.isEmpty()) {
      rank = getRankFromResident(res);
    } else {
      rank = getRankFromTown(town, args.get(0));
    }

    res.sendMessage(
        getLocal()
            .getLocalization(
                "mytown.notification.town.ranks.perm.list",
                rank.getName(),
                town.getName(),
                rank.permissionsContainer.toString()));
    return CommandResponse.DONE;
  }
  @Command(
      name = "claim",
      permission = "mytown.cmd.assistant.claim",
      parentName = "mytown.cmd",
      syntax = "/town claim [range]")
  public static CommandResponse claimCommand(ICommandSender sender, List<String> args) {
    EntityPlayer player = (EntityPlayer) sender;
    Resident res = MyTownUniverse.instance.getOrMakeResident(player);
    Town town = getTownFromResident(res);

    boolean isFarClaim = false;

    if (args.size() < 1) {
      if (town.townBlocksContainer.size() >= town.getMaxBlocks())
        throw new MyTownCommandException("mytown.cmd.err.town.maxBlocks", 1);
      if (getUniverse().blocks.contains(player.dimension, player.chunkCoordX, player.chunkCoordZ))
        throw new MyTownCommandException("mytown.cmd.err.claim.already");
      if (!checkNearby(player.dimension, player.chunkCoordX, player.chunkCoordZ, town)) {
        if (town.townBlocksContainer.getFarClaims() >= town.getMaxFarClaims())
          throw new MyTownCommandException("mytown.cmd.err.claim.far.notAllowed");
        isFarClaim = true;
      }
      for (int x = player.chunkCoordX - Config.instance.distanceBetweenTowns.get();
          x <= player.chunkCoordX + Config.instance.distanceBetweenTowns.get();
          x++) {
        for (int z = player.chunkCoordZ - Config.instance.distanceBetweenTowns.get();
            z <= player.chunkCoordZ + Config.instance.distanceBetweenTowns.get();
            z++) {
          Town nearbyTown = MyTownUtils.getTownAtPosition(player.dimension, x, z);
          if (nearbyTown != null
              && nearbyTown != town
              && !(Boolean) nearbyTown.flagsContainer.getValue(FlagType.NEARBY))
            throw new MyTownCommandException(
                "mytown.cmd.err.claim.tooClose",
                nearbyTown.getName(),
                Config.instance.distanceBetweenTowns.get());
        }
      }

      if (isFarClaim && town.townBlocksContainer.getFarClaims() + 1 > town.getMaxFarClaims())
        throw new MyTownCommandException("mytown.cmd.err.claim.far.notAllowed");

      int price =
          (isFarClaim
                  ? Config.instance.costAmountClaimFar.get()
                  : Config.instance.costAmountClaim.get())
              + Config.instance.costAdditionClaim.get() * town.townBlocksContainer.size();

      makeBankPayment(player, town, price);

      TownBlock block =
          getUniverse()
              .newBlock(
                  player.dimension,
                  player.chunkCoordX,
                  player.chunkCoordZ,
                  isFarClaim,
                  price,
                  town);
      if (block == null) throw new MyTownCommandException("mytown.cmd.err.claim.failed");

      getDatasource().saveBlock(block);
      res.sendMessage(
          getLocal()
              .getLocalization(
                  "mytown.notification.block.added",
                  block.getX() * 16,
                  block.getZ() * 16,
                  block.getX() * 16 + 15,
                  block.getZ() * 16 + 15,
                  town.getName()));
    } else {
      if (!StringUtils.tryParseInt(args.get(0)))
        throw new MyTownCommandException("mytown.cmd.err.notPositiveInteger", args.get(0));

      int radius = Integer.parseInt(args.get(0));
      List<ChunkPos> chunks =
          WorldUtils.getChunksInBox(
              player.dimension,
              (int) (player.posX - radius * 16),
              (int) (player.posZ - radius * 16),
              (int) (player.posX + radius * 16),
              (int) (player.posZ + radius * 16));
      isFarClaim = true;

      for (Iterator<ChunkPos> it = chunks.iterator(); it.hasNext(); ) {
        ChunkPos chunk = it.next();
        if (checkNearby(player.dimension, chunk.getX(), chunk.getZ(), town)) {
          isFarClaim = false;
        }
        if (getUniverse().blocks.contains(player.dimension, chunk.getX(), chunk.getZ()))
          it.remove();

        for (int x = chunk.getX() - Config.instance.distanceBetweenTowns.get();
            x <= chunk.getX() + Config.instance.distanceBetweenTowns.get();
            x++) {
          for (int z = chunk.getZ() - Config.instance.distanceBetweenTowns.get();
              z <= chunk.getZ() + Config.instance.distanceBetweenTowns.get();
              z++) {
            Town nearbyTown = MyTownUtils.getTownAtPosition(player.dimension, x, z);
            if (nearbyTown != null
                && nearbyTown != town
                && !(Boolean) nearbyTown.flagsContainer.getValue(FlagType.NEARBY))
              throw new MyTownCommandException(
                  "mytown.cmd.err.claim.tooClose",
                  nearbyTown.getName(),
                  Config.instance.distanceBetweenTowns.get());
          }
        }
      }

      if (town.townBlocksContainer.size() + chunks.size() > town.getMaxBlocks())
        throw new MyTownCommandException("mytown.cmd.err.town.maxBlocks", chunks.size());

      if (isFarClaim && town.townBlocksContainer.getFarClaims() + 1 > town.getMaxFarClaims())
        throw new MyTownCommandException("mytown.cmd.err.claim.far.notAllowed");

      makeBankPayment(
          player,
          town,
          (isFarClaim
                  ? Config.instance.costAmountClaimFar.get()
                      + Config.instance.costAmountClaim.get() * (chunks.size() - 1)
                  : Config.instance.costAmountClaim.get() * chunks.size())
              + MathUtils.sumFromNtoM(
                      town.townBlocksContainer.size(),
                      town.townBlocksContainer.size() + chunks.size() - 1)
                  * Config.instance.costAdditionClaim.get());

      for (ChunkPos chunk : chunks) {
        int price =
            (isFarClaim
                    ? Config.instance.costAmountClaimFar.get()
                    : Config.instance.costAmountClaim.get())
                + Config.instance.costAdditionClaim.get() * town.townBlocksContainer.size();
        TownBlock block =
            getUniverse()
                .newBlock(player.dimension, chunk.getX(), chunk.getZ(), isFarClaim, price, town);
        // Only one of the block will be a farClaim, rest will be normal claim
        isFarClaim = false;
        getDatasource().saveBlock(block);
        res.sendMessage(
            getLocal()
                .getLocalization(
                    "mytown.notification.block.added",
                    block.getX() * 16,
                    block.getZ() * 16,
                    block.getX() * 16 + 15,
                    block.getZ() * 16 + 15,
                    town.getName()));
      }
    }
    return CommandResponse.DONE;
  }
Exemple #30
0
  public boolean hasPermission(Resident res, Segment segment, int dim, Volume area) {
    boolean inWild = false;

    for (int townBlockX = area.getMinX() >> 4; townBlockX <= area.getMaxX() >> 4; townBlockX++) {
      for (int townBlockZ = area.getMinZ() >> 4; townBlockZ <= area.getMaxZ() >> 4; townBlockZ++) {
        TownBlock townBlock = getDatasource().getBlock(dim, townBlockX, townBlockZ);

        if (townBlock == null) {
          inWild = true;
        } else {
          Town town = townBlock.getTown();
          Volume rangeBox = townBlock.getAreaLimit(area);
          int totalIntersectArea = 0;

          // Check every plot in the current TownBlock and sum all plot areas
          for (Plot plot : townBlock.getPlots()) {
            int plotIntersectArea = plot.getIntersectingArea(rangeBox);
            if (plotIntersectArea > 0) {
              if (res == null) {
                if (plot.getValue(segment.getFlag()).equals(segment.getDenialValue())) {
                  return false;
                }
              } else {
                if (!plot.hasPermission(res, segment.getFlag(), segment.getDenialValue())) {
                  res.protectionDenial(
                      segment.getFlag().getLocalizedProtectionDenial(),
                      LocalizationProxy.getLocalization()
                          .getLocalization(
                              "mytown.notification.town.owners",
                              town.getMayor() == null
                                  ? "SERVER ADMINS"
                                  : town.getMayor().getPlayerName()));
                  return false;
                }
              }
            }
            totalIntersectArea += plotIntersectArea;
          }

          // If plot area sum is not equal to range area, check town permission
          if (totalIntersectArea != getArea(rangeBox)) {
            if (res == null) {
              if (town.getValue(segment.getFlag()).equals(segment.getDenialValue())) {
                return false;
              }
            } else {
              if (!town.hasPermission(res, segment.getFlag(), segment.getDenialValue())) {
                res.protectionDenial(
                    segment.getFlag().getLocalizedProtectionDenial(),
                    LocalizationProxy.getLocalization()
                        .getLocalization(
                            "mytown.notification.town.owners",
                            town.getMayor() == null
                                ? "SERVER ADMINS"
                                : town.getMayor().getPlayerName()));
                return false;
              }
            }
          }
        }
      }
    }

    if (inWild) {
      if (res == null) {
        if (Wild.instance.getValue(segment.getFlag()).equals(segment.getDenialValue())) {
          return false;
        }
      } else {
        if (!Wild.instance.hasPermission(res, segment.getFlag(), segment.getDenialValue())) {
          res.sendMessage(segment.getFlag().getLocalizedProtectionDenial());
          return false;
        }
      }
    }

    return true;
  }