Пример #1
0
  @Command(
      name = "withdraw",
      permission = "mytown.cmd.assistant.bank.withdraw",
      parentName = "mytown.cmd.everyone.bank",
      syntax = "/town bank withdraw <amount>")
  public static CommandResponse bankWithdrawCommand(ICommandSender sender, List<String> args) {
    if (args.size() < 1) return CommandResponse.SEND_SYNTAX;

    if (!StringUtils.tryParseInt(args.get(0)))
      throw new MyTownCommandException("mytown.cmd.err.notPositiveInteger", args.get(0));

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

    if (town instanceof AdminTown)
      throw new MyTownCommandException("mytown.cmd.err.adminTown", town.getName());

    int amount = Integer.parseInt(args.get(0));
    if (town.bank.getAmount() < amount)
      throw new MyTownCommandException(
          "mytown.cmd.err.bank.withdraw", EconomyProxy.getCurrency(town.bank.getAmount()));

    makeRefund(res.getPlayer(), amount);
    town.bank.addAmount(-amount);
    getDatasource().saveTownBank(town.bank);
    return CommandResponse.DONE;
  }
Пример #2
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!");
    }
  }
Пример #3
0
  @Command(
      name = "delete",
      permission = "mytown.cmd.mayor.leave.delete",
      parentName = "mytown.cmd.everyone.leave",
      syntax = "/town leave delete")
  public static CommandResponse leaveDeleteCommand(ICommandSender sender, List<String> args) {
    Resident res = MyTownUniverse.instance.getOrMakeResident(sender);
    Town town = getTownFromResident(res);
    EntityPlayer player = (EntityPlayer) sender;

    if (town.residentsMap.get(res).getType() == Rank.Type.MAYOR) {
      town.notifyEveryone(
          getLocal()
              .getLocalization(
                  "mytown.notification.town.deleted", town.getName(), res.getPlayerName()));
      int refund = 0;
      for (TownBlock block : town.townBlocksContainer) {
        refund += block.getPricePaid();
      }
      refund += town.bank.getAmount();
      makeRefund(player, refund);
      getDatasource().deleteTown(town);
    }
    return CommandResponse.DONE;
  }
Пример #4
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;
 }
Пример #5
0
  @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;
  }
Пример #6
0
    @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;
    }
Пример #7
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;
  }
Пример #8
0
    @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;
    }
Пример #9
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()));
  }
Пример #10
0
    @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;
    }
Пример #11
0
  @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;
  }
Пример #12
0
  @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;
  }
Пример #13
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));
  }
Пример #14
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)));
  }
Пример #15
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()));
    }
  }
Пример #16
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()));
  }
Пример #17
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)));
    }
  }
Пример #18
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));
   }
 }
Пример #19
0
  /**
   * Removes a Town from the Datasource
   *
   * @param town
   */
  public boolean removeTown(Town town) {
    boolean result = towns.remove(town.getName()) != null;

    for (Nation n : nations.values()) if (n.hasTown(town)) n.removeTown(town);

    for (Resident r : town.getResidents()) r.removeResidentFromTown(town);

    return result;
  }
Пример #20
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)));
 }
Пример #21
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)));
 }
Пример #22
0
 public static TownBlock getBlockAtResident(Resident res) {
   TownBlock block =
       getUniverse()
           .blocks
           .get(
               res.getPlayer().dimension,
               ((int) res.getPlayer().posX) >> 4,
               ((int) res.getPlayer().posZ >> 4));
   if (block == null)
     throw new MyTownCommandException(
         "mytown.cmd.err.claim.notexist", res.townsContainer.getMainTown().getName());
   return block;
 }
Пример #23
0
 @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;
 }
Пример #24
0
  /**
   * Removes a Resident from the Datasource
   *
   * @param resident
   */
  public boolean removeResident(Resident resident) {
    boolean result = residents.remove(resident.getUUID()) != null;

    for (Town t : towns.values()) if (t.hasResident(resident)) t.removeResident(resident);

    return result;
  }
Пример #25
0
  /** Checking item usage for right click on entity */
  public boolean checkEntityRightClick(ItemStack item, Resident res, Entity entity) {
    for (Iterator<SegmentEntity> it = segmentsEntities.iterator(); it.hasNext(); ) {
      SegmentEntity segment = it.next();
      if (segment.getType() == EntityType.PROTECT
          && segment.getCheckClass().isAssignableFrom(entity.getClass())) {
        int dim = entity.dimension;
        int x = (int) Math.floor(entity.posX);
        int y = (int) Math.floor(entity.posY);
        int z = (int) Math.floor(entity.posZ);

        if (!hasPermission(res, segment, dim, x, y, z)) {
          return true;
        }
      }
    }

    if (item == null) return false;

    for (Iterator<SegmentItem> it = segmentsItems.iterator(); it.hasNext(); ) {
      SegmentItem segment = it.next();
      if (segment.getType() == ItemType.RIGHT_CLICK_ENTITY
          && segment.getCheckClass().isAssignableFrom(item.getItem().getClass())) {
        try {
          if (segment.checkCondition(item)) {
            int range = segment.getRange(item);
            int dim = entity.dimension;
            int x = (int) Math.floor(entity.posX);
            int y = (int) Math.floor(entity.posY);
            int z = (int) Math.floor(entity.posZ);

            if (range == 0) {
              if (!hasPermission(res, segment, dim, x, y, z)) {
                return true;
              }
            } else {
              Volume rangeBox =
                  new Volume(x - range, y - range, z - range, x + range, y + range, z + range);
              if (!hasPermission(res, segment, dim, rangeBox)) {
                return true;
              }
            }
          }
        } catch (Exception ex) {
          MyTown.instance.LOG.error(
              "Failed to check item use on {} at the player {} ({}, {}, {} | Dim: {})",
              item.getDisplayName(),
              res.getPlayerName(),
              entity.posX,
              entity.posY,
              entity.posZ,
              entity.dimension);
          MyTown.instance.LOG.error(ExceptionUtils.getStackTrace(ex));
          if (ex instanceof GetterException || ex instanceof ConditionException) {
            this.disableSegment(it, segment, ex.getMessage());
          }
        }
      }
    }
    return false;
  }
Пример #26
0
  /** Checking right click actions on blocks. */
  public boolean checkBlockInteraction(
      Resident res, BlockPos bp, PlayerInteractEvent.Action action) {
    Block blockType =
        DimensionManager.getWorld(bp.getDim()).getBlock(bp.getX(), bp.getY(), bp.getZ());
    for (SegmentBlock segment : segmentsBlocks) {
      if (segment.getCheckClass().isAssignableFrom(blockType.getClass())
          && (segment.getMeta() == -1
              || segment.getMeta()
                  == DimensionManager.getWorld(bp.getDim())
                      .getBlockMetadata(bp.getX(), bp.getY(), bp.getZ()))
          && (segment.getType() == BlockType.ANY_CLICK
              || segment.getType() == BlockType.RIGHT_CLICK
                  && action == PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK
              || segment.getType() == BlockType.LEFT_CLICK
                  && action == PlayerInteractEvent.Action.LEFT_CLICK_BLOCK)) {
        int dim = bp.getDim();
        int x = bp.getX();
        int y = bp.getY();
        int z = bp.getZ();

        if (!hasPermission(res, segment, dim, x, y, z)) {
          if (segment.hasClientUpdate())
            sendClientUpdate(
                segment.getClientUpdateCoords(), bp, (EntityPlayerMP) res.getPlayer(), null);
          return true;
        }
      }
    }

    return false;
  }
Пример #27
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"));
  }
Пример #28
0
    @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;
    }
Пример #29
0
  @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;
  }
Пример #30
0
  @CommandNode(
      name = "whitelist",
      permission = "mytown.cmd.assistant.perm.town.whitelist",
      parentName = "mytown.cmd.assistant.perm.town",
      completionKeys = {"flagCompletionWhitelist"})
  public static void permTownWhitelistCommand(
      ICommandSender sender, List<String> args, List<String> subCommands) {
    if (args.size() == 0)
      throw new CommandException(getLocal().getLocalization("mytown.cmd.usage.plot.whitelist.add"));

    Resident res = getDatasource().getOrMakeResident(sender);
    Town town = getTownFromResident(res);
    String flagName = args.get(0);

    if (Flag.flagsForWhitelist.contains(flagName))
      res.startBlockSelection(flagName, town.getName(), false);
    else
      throw new CommandException(getLocal().getLocalization("mytown.cmd.err.flag.notForWhitelist"));
  }