コード例 #1
0
  /**
   * Delete a resident and it's data file (if not online) Available Only to players with the
   * 'towny.admin' permission node.
   *
   * @param player
   * @param split
   */
  public void residentDelete(Player player, String[] split) {

    if (split.length == 0)
      TownyMessaging.sendErrorMsg(player, TownySettings.getLangString("msg_invalid_name"));
    else
      try {
        if (!TownyUniverse.getPermissionSource().isTownyAdmin(player))
          throw new TownyException(TownySettings.getLangString("msg_err_admin_only_delete"));

        for (String name : split) {
          try {
            Resident resident = TownyUniverse.getDataSource().getResident(name);
            if (!resident.isNPC() && !BukkitTools.isOnline(resident.getName())) {
              TownyUniverse.getDataSource().removeResident(resident);
              TownyUniverse.getDataSource().removeResidentList(resident);
              TownyMessaging.sendGlobalMessage(TownySettings.getDelResidentMsg(resident));
            } else
              TownyMessaging.sendErrorMsg(
                  player,
                  String.format(TownySettings.getLangString("msg_err_online_or_npc"), name));
          } catch (NotRegisteredException x) {
            // This name isn't registered as a resident
            TownyMessaging.sendErrorMsg(
                player, String.format(TownySettings.getLangString("msg_err_invalid_name"), name));
          }
        }
      } catch (TownyException x) {
        // Admin only escape
        TownyMessaging.sendErrorMsg(player, x.getMessage());
        return;
      }
  }
コード例 #2
0
ファイル: TownyUniverse.java プロジェクト: MrNaikito/towny
 public List<Resident> getValidatedResidents(Object sender, String[] names) {
   List<Resident> invited = new ArrayList<Resident>();
   for (String name : names) {
     List<Player> matches = plugin.getServer().matchPlayer(name);
     if (matches.size() > 1) {
       String line = "Multiple players selected";
       for (Player p : matches) line += ", " + p.getName();
       TownyMessaging.sendErrorMsg(sender, line);
     } else if (matches.size() == 1) {
       // Match found online
       try {
         Resident target = getDataSource().getResident(matches.get(0).getName());
         invited.add(target);
       } catch (TownyException x) {
         TownyMessaging.sendErrorMsg(sender, x.getMessage());
       }
     } else {
       // No online matches so test for offline.
       Resident target;
       try {
         target = getDataSource().getResident(name);
         invited.add(target);
       } catch (NotRegisteredException x) {
         TownyMessaging.sendErrorMsg(sender, x.getMessage());
       }
     }
   }
   return invited;
 }
コード例 #3
0
  public void parseAdminUnclaimCommand(String[] split) {

    if (split.length == 1 && split[0].equalsIgnoreCase("?")) {
      for (String line : ta_unclaim) ((CommandSender) getSender()).sendMessage(line);
    } else {

      if (isConsole) {
        sender.sendMessage("[Towny] InputError: This command was designed for use in game only.");
        return;
      }

      try {
        if (TownyUniverse.isWarTime())
          throw new TownyException(TownySettings.getLangString("msg_war_cannot_do"));

        List<WorldCoord> selection;
        selection =
            AreaSelectionUtil.selectWorldCoordArea(
                null, new WorldCoord(player.getWorld().getName(), Coord.parseCoord(player)), split);
        selection = AreaSelectionUtil.filterWildernessBlocks(selection);

        new TownClaim(plugin, player, null, selection, false, false, true).start();

      } catch (TownyException x) {
        TownyMessaging.sendErrorMsg(player, x.getMessage());
        return;
      }
    }
  }
コード例 #4
0
  @Override
  public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {

    this.sender = sender;

    if (sender instanceof Player) {
      player = (Player) sender;
      isConsole = false;
      System.out.println(
          "[PLAYER_COMMAND] "
              + player.getName()
              + ": /"
              + commandLabel
              + " "
              + StringMgmt.join(args));

    } else {
      isConsole = true;
      this.player = null;
    }

    try {
      return parseTownyAdminCommand(args);
    } catch (TownyException e) {
      TownyMessaging.sendErrorMsg(sender, e.getMessage());
    }

    return true;
  }
コード例 #5
0
ファイル: War.java プロジェクト: adegie/Towny
  public void start() {
    warTime = true;

    // Announce

    // Seed spoils of war
    try {
      warSpoils.pay(TownySettings.getBaseSpoilsOfWar(), "Start of War - Base Spoils");
      TownyMessaging.sendMsg(
          "[War] Seeding spoils of war with " + TownySettings.getBaseSpoilsOfWar());
    } catch (EconomyException e) {
      TownyMessaging.sendErrorMsg("[War] Could not seed spoils of war.");
    }

    // Gather all nations at war
    for (Nation nation : TownyUniverse.getDataSource().getNations()) {
      if (!nation.isNeutral()) {
        add(nation);
        TownyMessaging.sendGlobalMessage(
            String.format(TownySettings.getLangString("msg_war_join_nation"), nation.getName()));
      } else if (!TownySettings.isDeclaringNeutral()) {
        try {
          nation.setNeutral(false);
          add(nation);
          TownyMessaging.sendGlobalMessage(
              String.format(TownySettings.getLangString("msg_war_join_forced"), nation.getName()));
        } catch (TownyException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }
      }
    }
    // warTimer.scheduleAtFixedRate(new WarTimerTask(this), 0, 1000);
    int id =
        plugin
            .getServer()
            .getScheduler()
            .scheduleAsyncRepeatingTask(
                getPlugin(), new WarTimerTask(this), 0, TimeTools.convertToTicks(5));
    if (id == -1) {
      TownyMessaging.sendErrorMsg("Could not schedule war event loop.");
      end();
    } else addTaskId(id);
    checkEnd();
  }
コード例 #6
0
ファイル: TownyUniverse.java プロジェクト: MrNaikito/towny
 public List<Resident> getOnlineResidents(Player player, String[] names) {
   List<Resident> invited = new ArrayList<Resident>();
   for (String name : names) {
     List<Player> matches = plugin.getServer().matchPlayer(name);
     if (matches.size() > 1) {
       String line = "Multiple players selected";
       for (Player p : matches) line += ", " + p.getName();
       TownyMessaging.sendErrorMsg(player, line);
     } else if (matches.size() == 1)
       try {
         Resident target = getDataSource().getResident(matches.get(0).getName());
         invited.add(target);
       } catch (TownyException x) {
         TownyMessaging.sendErrorMsg(player, x.getMessage());
       }
   }
   return invited;
 }
コード例 #7
0
ファイル: TownyUniverse.java プロジェクト: MrNaikito/towny
 public void newDay() {
   if (!isDailyTimerRunning()) toggleDailyTimer(true);
   // dailyTimer.schedule(new DailyTimerTask(this), 0);
   if (getPlugin()
           .getServer()
           .getScheduler()
           .scheduleAsyncDelayedTask(getPlugin(), new DailyTimerTask(this))
       == -1) TownyMessaging.sendErrorMsg("Could not schedule newDay.");
   setChangedNotify(NEW_DAY);
 }
コード例 #8
0
ファイル: TownyUniverse.java プロジェクト: MrNaikito/towny
  public void requestTeleport(Player player, Town town, double cost) {
    try {
      TeleportWarmupTimerTask.requestTeleport(
          getDataSource().getResident(player.getName().toLowerCase()), town, cost);
    } catch (TownyException x) {
      TownyMessaging.sendErrorMsg(player, x.getMessage());
    }

    setChangedNotify(TELEPORT_REQUEST);
  }
コード例 #9
0
ファイル: War.java プロジェクト: adegie/Towny
 public void eliminate(Town town) {
   remove(town);
   try {
     checkNation(town.getNation());
   } catch (NotRegisteredException e) {
     TownyMessaging.sendErrorMsg("[War] Error checking " + town.getName() + "'s nation.");
   }
   TownyMessaging.sendGlobalMessage(TownySettings.getWarTimeEliminatedMsg(town.getName()));
   checkEnd();
 }
コード例 #10
0
ファイル: TownyUniverse.java プロジェクト: MrNaikito/towny
  public void onLogin(Player player) throws AlreadyRegisteredException, NotRegisteredException {

    if (!player.isOnline()) return;

    // Test and kick any players with invalid names.
    if ((player.getName().trim() == null) || (player.getName().contains(" "))) {
      player.kickPlayer("Invalid name!");
      return;
    }

    Resident resident;

    if (!getDataSource().hasResident(player.getName())) {
      getDataSource().newResident(player.getName());
      resident = getDataSource().getResident(player.getName());

      TownyMessaging.sendMessage(player, TownySettings.getRegistrationMsg(player.getName()));
      resident.setRegistered(System.currentTimeMillis());
      if (!TownySettings.getDefaultTownName().equals(""))
        try {
          Town town = getDataSource().getTown(TownySettings.getDefaultTownName());
          town.addResident(resident);
          getDataSource().saveTown(town);
        } catch (NotRegisteredException e) {
        } catch (AlreadyRegisteredException e) {
        }

      getDataSource().saveResident(resident);
      getDataSource().saveResidentList();

    } else {
      resident = getDataSource().getResident(player.getName());
      resident.setLastOnline(System.currentTimeMillis());

      getDataSource().saveResident(resident);
    }

    try {
      TownyMessaging.sendTownBoard(player, resident.getTown());
    } catch (NotRegisteredException e) {
    }

    if (isWarTime()) getWarEvent().sendScores(player, 3);

    // Schedule to setup default modes when the player has finished loading
    if (getPlugin()
            .getServer()
            .getScheduler()
            .scheduleSyncDelayedTask(getPlugin(), new SetDefaultModes(this, player, false), 1)
        == -1)
      TownyMessaging.sendErrorMsg("Could not set default modes for " + player.getName() + ".");

    setChangedNotify(PLAYER_LOGIN);
  }
コード例 #11
0
ファイル: War.java プロジェクト: adegie/Towny
 public void setupDelay(int delay) {
   if (delay <= 0) start();
   else {
     for (Long t : TimeMgmt.getCountdownDelays(delay, TimeMgmt.defaultCountdownDelays)) {
       // Schedule the warnings leading up to the start of the war event
       // warTimer.schedule(
       //              new ServerBroadCastTimerTask(plugin,
       //                              String.format("War starts in %s",
       // TimeMgmt.formatCountdownTime(t))),
       //                              (delay-t)*1000);
       int id =
           plugin
               .getServer()
               .getScheduler()
               .scheduleAsyncDelayedTask(
                   getPlugin(),
                   new ServerBroadCastTimerTask(
                       plugin, String.format("War starts in %s", TimeMgmt.formatCountdownTime(t))),
                   TimeTools.convertToTicks((delay - t)));
       if (id == -1) {
         TownyMessaging.sendErrorMsg("Could not schedule a countdown message for war event.");
         end();
       } else addTaskId(id);
     }
     // warTimer.schedule(new StartWarTimerTask(universe), delay*1000);
     int id =
         plugin
             .getServer()
             .getScheduler()
             .scheduleAsyncDelayedTask(
                 getPlugin(), new StartWarTimerTask(universe), TimeTools.convertToTicks(delay));
     if (id == -1) {
       TownyMessaging.sendErrorMsg("Could not schedule setup delay for war event.");
       end();
     } else addTaskId(id);
   }
 }
コード例 #12
0
ファイル: TownyUniverse.java プロジェクト: MrNaikito/towny
 public void toggleTeleportWarmup(boolean on) {
   if (on && !isTeleportWarmupRunning()) {
     teleportWarmupTask =
         getPlugin()
             .getServer()
             .getScheduler()
             .scheduleSyncRepeatingTask(getPlugin(), new TeleportWarmupTimerTask(this), 0, 20);
     if (teleportWarmupTask == -1)
       TownyMessaging.sendErrorMsg("Could not schedule teleport warmup loop.");
   } else if (!on && isTeleportWarmupRunning()) {
     getPlugin().getServer().getScheduler().cancelTask(teleportWarmupTask);
     teleportWarmupTask = -1;
   }
   setChangedNotify(TOGGLE_TELEPORT_WARMUP);
 }
コード例 #13
0
ファイル: TownyUniverse.java プロジェクト: MrNaikito/towny
 public void toggleMobRemoval(boolean on) {
   if (on && !isMobRemovalRunning()) {
     mobRemoveTask =
         getPlugin()
             .getServer()
             .getScheduler()
             .scheduleSyncRepeatingTask(
                 getPlugin(),
                 new MobRemovalTimerTask(this, plugin.getServer()),
                 0,
                 MinecraftTools.convertToTicks(TownySettings.getMobRemovalSpeed()));
     if (mobRemoveTask == -1) TownyMessaging.sendErrorMsg("Could not schedule mob removal loop.");
   } else if (!on && isMobRemovalRunning()) {
     getPlugin().getServer().getScheduler().cancelTask(mobRemoveTask);
     mobRemoveTask = -1;
   }
   setChangedNotify(TOGGLE_MOB_REMOVAL);
 }
コード例 #14
0
ファイル: TownyUniverse.java プロジェクト: MrNaikito/towny
 public void toggleHealthRegen(boolean on) {
   if (on && !isHealthRegenRunning()) {
     healthRegenTask =
         getPlugin()
             .getServer()
             .getScheduler()
             .scheduleSyncRepeatingTask(
                 getPlugin(),
                 new HealthRegenTimerTask(this, plugin.getServer()),
                 0,
                 MinecraftTools.convertToTicks(TownySettings.getHealthRegenSpeed()));
     if (healthRegenTask == -1)
       TownyMessaging.sendErrorMsg("Could not schedule health regen loop.");
   } else if (!on && isHealthRegenRunning()) {
     getPlugin().getServer().getScheduler().cancelTask(healthRegenTask);
     healthRegenTask = -1;
   }
   setChangedNotify(TOGGLE_HEALTH_REGEN);
 }
コード例 #15
0
ファイル: TownyUniverse.java プロジェクト: MrNaikito/towny
 public void toggleTownyRepeatingTimer(boolean on) {
   if (on && !isTownyRepeatingTaskRunning()) {
     townyRepeatingTask =
         getPlugin()
             .getServer()
             .getScheduler()
             .scheduleSyncRepeatingTask(
                 getPlugin(),
                 new RepeatingTimerTask(this),
                 0,
                 MinecraftTools.convertToTicks(TownySettings.getPlotManagementSpeed()));
     if (townyRepeatingTask == -1)
       TownyMessaging.sendErrorMsg("Could not schedule Towny Timer Task.");
   } else if (!on && isTownyRepeatingTaskRunning()) {
     getPlugin().getServer().getScheduler().cancelTask(townyRepeatingTask);
     townyRepeatingTask = -1;
   }
   setChanged();
 }
コード例 #16
0
ファイル: TownyUniverse.java プロジェクト: MrNaikito/towny
 public void toggleDailyTimer(boolean on) {
   if (on && !isDailyTimerRunning()) {
     long timeTillNextDay = TownyUtil.townyTime();
     TownyMessaging.sendMsg(
         "Time until a New Day: " + TimeMgmt.formatCountdownTime(timeTillNextDay));
     dailyTask =
         getPlugin()
             .getServer()
             .getScheduler()
             .scheduleAsyncRepeatingTask(
                 getPlugin(),
                 new DailyTimerTask(this),
                 MinecraftTools.convertToTicks(timeTillNextDay),
                 MinecraftTools.convertToTicks(TownySettings.getDayInterval()));
     if (dailyTask == -1) TownyMessaging.sendErrorMsg("Could not schedule new day loop.");
   } else if (!on && isDailyTimerRunning()) {
     getPlugin().getServer().getScheduler().cancelTask(dailyTask);
     dailyTask = -1;
   }
   setChangedNotify(TOGGLE_DAILY_TIMER);
 }
コード例 #17
0
  public void parseToggleCommand(String[] split) throws TownyException {

    boolean choice;

    if (split.length == 0) {
      // command was '/townyadmin toggle'
      player.sendMessage(ChatTools.formatTitle("/townyadmin toggle"));
      player.sendMessage(ChatTools.formatCommand("", "/townyadmin toggle", "war", ""));
      player.sendMessage(ChatTools.formatCommand("", "/townyadmin toggle", "neutral", ""));
      player.sendMessage(ChatTools.formatCommand("", "/townyadmin toggle", "devmode", ""));
      player.sendMessage(ChatTools.formatCommand("", "/townyadmin toggle", "debug", ""));
      player.sendMessage(
          ChatTools.formatCommand("", "/townyadmin toggle", "townwithdraw/nationwithdraw", ""));
      player.sendMessage(ChatTools.formatCommand("", "/townyadmin toggle npc", "[resident]", ""));
      return;
    }

    if (!TownyUniverse.getPermissionSource()
        .testPermission(
            player,
            PermissionNodes.TOWNY_COMMAND_TOWNYADMIN_TOGGLE.getNode(split[0].toLowerCase())))
      throw new TownyException(TownySettings.getLangString("msg_err_command_disable"));

    if (split[0].equalsIgnoreCase("war")) {
      choice = TownyUniverse.isWarTime();

      if (!choice) {
        plugin.getTownyUniverse().startWarEvent();
        TownyMessaging.sendMsg(getSender(), TownySettings.getLangString("msg_war_started"));
      } else {
        plugin.getTownyUniverse().endWarEvent();
        TownyMessaging.sendMsg(getSender(), TownySettings.getLangString("msg_war_ended"));
      }
    } else if (split[0].equalsIgnoreCase("neutral")) {

      try {
        choice = !TownySettings.isDeclaringNeutral();
        TownySettings.setDeclaringNeutral(choice);
        TownyMessaging.sendMsg(
            getSender(),
            String.format(
                TownySettings.getLangString("msg_nation_allow_neutral"),
                choice ? "Enabled" : "Disabled"));

      } catch (Exception e) {
        TownyMessaging.sendErrorMsg(
            getSender(), TownySettings.getLangString("msg_err_invalid_choice"));
        return;
      }

    } else if (split[0].equalsIgnoreCase("devmode")) {
      try {
        choice = !TownySettings.isDevMode();
        TownySettings.setDevMode(choice);
        TownyMessaging.sendMsg(
            getSender(),
            "Dev Mode " + (choice ? Colors.Green + "Enabled" : Colors.Red + "Disabled"));
      } catch (Exception e) {
        TownyMessaging.sendErrorMsg(
            getSender(), TownySettings.getLangString("msg_err_invalid_choice"));
      }
    } else if (split[0].equalsIgnoreCase("debug")) {
      try {
        choice = !TownySettings.getDebug();
        TownySettings.setDebug(choice);
        TownyMessaging.sendMsg(
            getSender(),
            "Debug Mode " + (choice ? Colors.Green + "Enabled" : Colors.Red + "Disabled"));
      } catch (Exception e) {
        TownyMessaging.sendErrorMsg(
            getSender(), TownySettings.getLangString("msg_err_invalid_choice"));
      }
    } else if (split[0].equalsIgnoreCase("townwithdraw")) {
      try {
        choice = !TownySettings.getTownBankAllowWithdrawls();
        TownySettings.SetTownBankAllowWithdrawls(choice);
        TownyMessaging.sendMsg(
            getSender(),
            "Town Withdrawls " + (choice ? Colors.Green + "Enabled" : Colors.Red + "Disabled"));
      } catch (Exception e) {
        TownyMessaging.sendErrorMsg(
            getSender(), TownySettings.getLangString("msg_err_invalid_choice"));
      }
    } else if (split[0].equalsIgnoreCase("nationwithdraw")) {
      try {
        choice = !TownySettings.geNationBankAllowWithdrawls();
        TownySettings.SetNationBankAllowWithdrawls(choice);
        TownyMessaging.sendMsg(
            getSender(),
            "Nation Withdrawls " + (choice ? Colors.Green + "Enabled" : Colors.Red + "Disabled"));
      } catch (Exception e) {
        TownyMessaging.sendErrorMsg(
            getSender(), TownySettings.getLangString("msg_err_invalid_choice"));
      }

    } else if (split[0].equalsIgnoreCase("npc")) {

      if (split.length != 2)
        throw new TownyException(
            String.format(
                TownySettings.getLangString("msg_err_invalid_input"), "Eg: toggle npc [resident]"));

      try {
        Resident resident = TownyUniverse.getDataSource().getResident(split[1]);
        resident.setNPC(!resident.isNPC());

        TownyUniverse.getDataSource().saveResident(resident);

        TownyMessaging.sendMessage(
            sender,
            String.format(
                TownySettings.getLangString("msg_npc_flag"), resident.isNPC(), resident.getName()));

      } catch (NotRegisteredException x) {
        throw new TownyException(
            String.format(TownySettings.getLangString("msg_err_not_registered_1"), split[1]));
      }

    } else {
      // parameter error message
      // neutral/war/townmobs/worldmobs
      TownyMessaging.sendErrorMsg(
          getSender(), TownySettings.getLangString("msg_err_invalid_choice"));
    }
  }
コード例 #18
0
  public void adminSet(String[] split) throws TownyException {

    if (split.length == 0) {
      sender.sendMessage(ChatTools.formatTitle("/townyadmin set"));
      // TODO: player.sendMessage(ChatTools.formatCommand("",
      // "/townyadmin set", "king [nation] [king]", ""));
      sender.sendMessage(
          ChatTools.formatCommand(
              "",
              "/townyadmin set",
              "mayor [town] " + TownySettings.getLangString("town_help_2"),
              ""));
      sender.sendMessage(ChatTools.formatCommand("", "/townyadmin set", "mayor [town] npc", ""));
      // player.sendMessage(ChatTools.formatCommand("", "/townyadmin set",
      // "debugmode [on/off]", ""));
      // player.sendMessage(ChatTools.formatCommand("", "/townyadmin set",
      // "devmode [on/off]", ""));

      return;
    }

    if (!TownyUniverse.getPermissionSource()
        .testPermission(
            player, PermissionNodes.TOWNY_COMMAND_TOWNYADMIN_SET.getNode(split[0].toLowerCase())))
      throw new TownyException(TownySettings.getLangString("msg_err_command_disable"));

    if (split[0].equalsIgnoreCase("mayor")) {
      if (split.length < 3) {

        sender.sendMessage(ChatTools.formatTitle("/townyadmin set mayor"));
        sender.sendMessage(
            ChatTools.formatCommand(
                "Eg",
                "/townyadmin set mayor",
                "[town] " + TownySettings.getLangString("town_help_2"),
                ""));
        sender.sendMessage(
            ChatTools.formatCommand("Eg", "/townyadmin set mayor", "[town] npc", ""));

      } else
        try {
          Resident newMayor = null;
          Town town = TownyUniverse.getDataSource().getTown(split[1]);

          if (split[2].equalsIgnoreCase("npc")) {
            String name = nextNpcName();
            TownyUniverse.getDataSource().newResident(name);

            newMayor = TownyUniverse.getDataSource().getResident(name);

            newMayor.setRegistered(System.currentTimeMillis());
            newMayor.setLastOnline(0);
            newMayor.setNPC(true);

            TownyUniverse.getDataSource().saveResident(newMayor);
            TownyUniverse.getDataSource().saveResidentList();

            // set for no upkeep as an NPC mayor is assigned
            town.setHasUpkeep(false);

          } else {
            newMayor = TownyUniverse.getDataSource().getResident(split[2]);

            // set upkeep again
            town.setHasUpkeep(true);
          }

          if (!town.hasResident(newMayor)) TownCommand.townAddResident(town, newMayor);
          // Delete the resident if the old mayor was an NPC.
          Resident oldMayor = town.getMayor();

          town.setMayor(newMayor);

          if (oldMayor.isNPC()) {
            try {
              town.removeResident(oldMayor);
              TownyUniverse.getDataSource().removeResident(oldMayor);

              TownyUniverse.getDataSource().removeResidentList(oldMayor);

            } catch (EmptyTownException e) {
              // Should never reach here as we are setting a new
              // mayor before removing the old one.
              e.printStackTrace();
            }
          }
          TownyUniverse.getDataSource().saveTown(town);
          String[] msg = TownySettings.getNewMayorMsg(newMayor.getName());
          TownyMessaging.sendTownMessage(town, msg);
          // TownyMessaging.sendMessage(player, msg);
        } catch (TownyException e) {
          TownyMessaging.sendErrorMsg(getSender(), e.getMessage());
        }

    } else if (split[0].equalsIgnoreCase("capital")) {

      if (split.length < 2) {

        sender.sendMessage(ChatTools.formatTitle("/townyadmin set capital"));
        sender.sendMessage(ChatTools.formatCommand("Eg", "/ta set capital", "[town name]", ""));

      } else {

        try {
          Town newCapital = TownyUniverse.getDataSource().getTown(split[1]);
          Nation nation = newCapital.getNation();

          nation.setCapital(newCapital);
          plugin.resetCache();

          TownyMessaging.sendNationMessage(
              nation,
              TownySettings.getNewKingMsg(newCapital.getMayor().getName(), nation.getName()));

          TownyUniverse.getDataSource().saveNation(nation);
          TownyUniverse.getDataSource().saveNationList();

        } catch (TownyException e) {
          TownyMessaging.sendErrorMsg(player, e.getMessage());
        }
      }

    } else {
      TownyMessaging.sendErrorMsg(
          getSender(),
          String.format(TownySettings.getLangString("msg_err_invalid_property"), "administrative"));
      return;
    }
  }
コード例 #19
0
  /**
   * Remove residents who havn't logged in for X amount of days.
   *
   * @param split
   */
  public void purge(String[] split) {

    if (split.length == 0) {
      // command was '/townyadmin purge'
      player.sendMessage(ChatTools.formatTitle("/townyadmin purge"));
      player.sendMessage(ChatTools.formatCommand("", "/townyadmin purge", "[number of days]", ""));
      player.sendMessage(
          ChatTools.formatCommand(
              "", "", "Removes offline residents not seen for this duration.", ""));

      return;
    }

    int days = 1;

    try {
      days = Integer.parseInt(split[0]);
    } catch (NumberFormatException e) {
      TownyMessaging.sendErrorMsg(
          getSender(), TownySettings.getLangString("msg_error_must_be_int"));
      return;
    }

    // Use questioner to confirm.
    Plugin test = BukkitTools.getServer().getPluginManager().getPlugin("Questioner");

    if (this.sender instanceof Player
        && TownySettings.isUsingQuestioner()
        && test != null
        && test instanceof Questioner
        && test.isEnabled()) {
      Questioner questioner = (Questioner) test;
      questioner.loadClasses();

      List<Option> options = new ArrayList<Option>();
      options.add(
          new Option(
              TownySettings.questionerAccept(),
              new PurgeQuestionTask(plugin, this.sender, TimeTools.getMillis(days + "d"))));
      options.add(
          new Option(
              TownySettings.questionerDeny(),
              new PurgeQuestionTask(plugin, this.sender, TimeTools.getMillis(days + "d")) {

                @Override
                public void run() {

                  TownyMessaging.sendMessage(getSender(), "Purge Aborted!");
                }
              }));

      Question question =
          new Question(this.sender.getName(), "Do you really want to perform this purge", options);

      try {
        plugin.appendQuestion(questioner, question);
      } catch (Exception e) {
        System.out.println(e.getMessage());
      }
    } else {

      // Run a purge in it's own thread
      new ResidentPurge(plugin, this.sender, TimeTools.getMillis(days + "d")).start();
    }
  }
コード例 #20
0
  public void parseAdminNationCommand(String[] split) throws TownyException {

    if (split.length == 0 || split[0].equalsIgnoreCase("?")) {

      sender.sendMessage(ChatTools.formatTitle("/townyadmin nation"));
      sender.sendMessage(
          ChatTools.formatCommand(
              TownySettings.getLangString("admin_sing"), "/townyadmin nation", "[nation]", ""));
      sender.sendMessage(
          ChatTools.formatCommand(
              TownySettings.getLangString("admin_sing"),
              "/townyadmin nation",
              "[nation] add [] .. []",
              ""));
      sender.sendMessage(
          ChatTools.formatCommand(
              TownySettings.getLangString("admin_sing"),
              "/townyadmin nation",
              "[nation] rename [newname]",
              ""));
      sender.sendMessage(
          ChatTools.formatCommand(
              TownySettings.getLangString("admin_sing"),
              "/townyadmin nation",
              "[nation] delete",
              ""));

      return;
    }
    try {
      Nation nation = TownyUniverse.getDataSource().getNation(split[0]);
      if (split.length == 1) {
        TownyMessaging.sendMessage(getSender(), TownyFormatter.getStatus(nation));
        return;
      }

      if (!TownyUniverse.getPermissionSource()
          .testPermission(
              player,
              PermissionNodes.TOWNY_COMMAND_TOWNYADMIN_NATION.getNode(split[1].toLowerCase())))
        throw new TownyException(TownySettings.getLangString("msg_err_command_disable"));

      if (split[1].equalsIgnoreCase("add")) {
        /*
         * if (isConsole) { sender.sendMessage(
         * "[Towny] InputError: This command was designed for use in game only."
         * ); return; }
         */
        NationCommand.nationAdd(
            nation, TownyUniverse.getDataSource().getTowns(StringMgmt.remArgs(split, 2)));

      } else if (split[1].equalsIgnoreCase("delete")) {

        TownyUniverse.getDataSource().removeNation(nation);

      } else if (split[1].equalsIgnoreCase("rename")) {

        if (!NameValidation.isBlacklistName(split[2])) {
          TownyUniverse.getDataSource().renameNation(nation, split[2]);
          TownyMessaging.sendNationMessage(
              nation,
              String.format(
                  TownySettings.getLangString("msg_nation_set_name"),
                  ((getSender() instanceof Player) ? player.getName() : "CONSOLE"),
                  nation.getName()));
        } else
          TownyMessaging.sendErrorMsg(getSender(), TownySettings.getLangString("msg_invalid_name"));
      }

    } catch (NotRegisteredException e) {
      TownyMessaging.sendErrorMsg(getSender(), e.getMessage());
    } catch (AlreadyRegisteredException e) {
      TownyMessaging.sendErrorMsg(getSender(), e.getMessage());
    }
  }
コード例 #21
0
  public void parseAdminTownCommand(String[] split) throws TownyException {

    // TODO Make this use the actual town command procedually.

    if (split.length == 0 || split[0].equalsIgnoreCase("?")) {
      sender.sendMessage(ChatTools.formatTitle("/townyadmin town"));
      sender.sendMessage(
          ChatTools.formatCommand(
              TownySettings.getLangString("admin_sing"), "/townyadmin town", "[town]", ""));
      sender.sendMessage(
          ChatTools.formatCommand(
              TownySettings.getLangString("admin_sing"),
              "/townyadmin town",
              "[town] add/kick [] .. []",
              ""));
      sender.sendMessage(
          ChatTools.formatCommand(
              TownySettings.getLangString("admin_sing"),
              "/townyadmin town",
              "[town] rename [newname]",
              ""));
      sender.sendMessage(
          ChatTools.formatCommand(
              TownySettings.getLangString("admin_sing"), "/townyadmin town", "[town] delete", ""));
      sender.sendMessage(
          ChatTools.formatCommand(
              TownySettings.getLangString("admin_sing"), "/townyadmin town", "[town] spawn", ""));
      sender.sendMessage(
          ChatTools.formatCommand(
              TownySettings.getLangString("admin_sing"),
              "/townyadmin town",
              "[town] outpost #",
              ""));

      return;
    }

    try {

      Town town = TownyUniverse.getDataSource().getTown(split[0]);

      if (split.length == 1) {
        TownyMessaging.sendMessage(getSender(), TownyFormatter.getStatus(town));
        return;
      }

      if (!TownyUniverse.getPermissionSource()
          .testPermission(
              player,
              PermissionNodes.TOWNY_COMMAND_TOWNYADMIN_TOWN.getNode(split[1].toLowerCase())))
        throw new TownyException(TownySettings.getLangString("msg_err_command_disable"));

      if (split[1].equalsIgnoreCase("add")) {
        /*
         * if (isConsole) { sender.sendMessage(
         * "[Towny] InputError: This command was designed for use in game only."
         * ); return; }
         */
        TownCommand.townAdd(getSender(), town, StringMgmt.remArgs(split, 2));

      } else if (split[1].equalsIgnoreCase("kick")) {

        TownCommand.townKickResidents(
            getSender(),
            town.getMayor(),
            town,
            TownyUniverse.getValidatedResidents(getSender(), StringMgmt.remArgs(split, 2)));

      } else if (split[1].equalsIgnoreCase("delete")) {

        TownyUniverse.getDataSource().removeTown(town);

      } else if (split[1].equalsIgnoreCase("rename")) {

        if (!NameValidation.isBlacklistName(split[2])) {
          TownyUniverse.getDataSource().renameTown(town, split[2]);
          TownyMessaging.sendTownMessage(
              town,
              String.format(
                  TownySettings.getLangString("msg_town_set_name"),
                  ((getSender() instanceof Player) ? player.getName() : "CONSOLE"),
                  town.getName()));
        } else
          TownyMessaging.sendErrorMsg(getSender(), TownySettings.getLangString("msg_invalid_name"));

      } else if (split[1].equalsIgnoreCase("spawn")) {

        TownCommand.townSpawn(player, StringMgmt.remArgs(split, 2), town, "", false);

      } else if (split[1].equalsIgnoreCase("outpost")) {

        TownCommand.townSpawn(player, StringMgmt.remArgs(split, 2), town, "", true);
      }

    } catch (NotRegisteredException e) {
      TownyMessaging.sendErrorMsg(getSender(), e.getMessage());
    } catch (TownyException e) {
      TownyMessaging.sendErrorMsg(getSender(), e.getMessage());
    }
  }
コード例 #22
0
ファイル: CachePermissions.java プロジェクト: pjsw007/Towny
  public boolean getPermission(
      Player player,
      TownBlockStatus status,
      WorldCoord pos,
      TownyPermission.ActionType actionType) {
    if (status == TownBlockStatus.OFF_WORLD
        || status == TownBlockStatus.WARZONE
        || status == TownBlockStatus.PLOT_OWNER
        || status
            == TownBlockStatus
                .TOWN_OWNER) // || plugin.isTownyAdmin(player)) // status == TownBlockStatus.ADMIN
                             // ||
    return true;

    if (status == TownBlockStatus.NOT_REGISTERED) {
      cacheBlockErrMsg(player, TownySettings.getLangString("msg_cache_block_error"));
      return false;
    }

    if (status == TownBlockStatus.LOCKED) {
      cacheBlockErrMsg(player, TownySettings.getLangString("msg_cache_block_error_locked"));
      return false;
    }

    TownBlock townBlock;
    // Town town;
    try {
      townBlock = pos.getTownBlock();
      // town = townBlock.getTown();
    } catch (NotRegisteredException e) {

      // Wilderness Permissions
      if (status == TownBlockStatus.UNCLAIMED_ZONE)
        if (TownyUniverse.getPermissionSource()
            .hasPermission(player, PermissionNodes.TOWNY_WILD_ALL.getNode(actionType.toString()))) {
          return true;

        } else if (!TownyPermission.getUnclaimedZonePerm(actionType, pos.getWorld())) {
          // Don't have permission to build/destroy/switch/item_use here
          cacheBlockErrMsg(
              player,
              String.format(
                  TownySettings.getLangString("msg_cache_block_error_wild"),
                  actionType.toString()));
          return false;
        } else return true;
      else {
        TownyMessaging.sendErrorMsg(player, "Error updating destroy permission.");
        return false;
      }
    }

    // Allow admins to have ALL permissions over towns.
    if (TownyUniverse.getPermissionSource().isTownyAdmin(player)) return true;

    // Plot Permissions
    // try {
    //        Resident owner = townBlock.getResident();
    if (townBlock.hasResident()) {
      if (status == TownBlockStatus.PLOT_FRIEND) {
        if (townBlock.getPermissions().getResidentPerm(actionType)) return true;
        else {
          cacheBlockErrMsg(
              player,
              String.format(
                  TownySettings.getLangString("msg_cache_block_error_plot"),
                  "friends",
                  actionType.toString()));
          return false;
        }
      } else if (status == TownBlockStatus.PLOT_ALLY)
        if (townBlock.getPermissions().getAllyPerm(actionType)) return true;
        else {
          cacheBlockErrMsg(
              player,
              String.format(
                  TownySettings.getLangString("msg_cache_block_error_plot"),
                  "allies",
                  actionType.toString()));
          return false;
        }
      else { // TODO: (Remove) if (status == TownBlockStatus.OUTSIDER)

        if (townBlock.getPermissions().getOutsiderPerm(actionType)) {
          // System.out.print("Outsider true");
          return true;
        } else {
          cacheBlockErrMsg(
              player,
              String.format(
                  TownySettings.getLangString("msg_cache_block_error_plot"),
                  "outsiders",
                  actionType.toString()));
          return false;
        }
      }
    }
    // } catch (NotRegisteredException x) {
    // }

    // Town Permissions
    if (status == TownBlockStatus.TOWN_RESIDENT) {
      if (townBlock.getPermissions().getResidentPerm(actionType)) return true;
      else {
        cacheBlockErrMsg(
            player,
            String.format(
                TownySettings.getLangString("msg_cache_block_error_town_resident"),
                actionType.toString()));
        return false;
      }
    } else if (status == TownBlockStatus.TOWN_ALLY)
      if (townBlock.getPermissions().getAllyPerm(actionType)) return true;
      else {
        cacheBlockErrMsg(
            player,
            String.format(
                TownySettings.getLangString("msg_cache_block_error_town_allies"),
                actionType.toString()));
        return false;
      }
    else if (status == TownBlockStatus.OUTSIDER || status == TownBlockStatus.ENEMY)
      if (townBlock.getPermissions().getOutsiderPerm(actionType)) return true;
      else {
        cacheBlockErrMsg(
            player,
            String.format(
                TownySettings.getLangString("msg_cache_block_error_town_outsider"),
                actionType.toString()));
        return false;
      }

    TownyMessaging.sendErrorMsg(player, "Error updating " + actionType.toString() + " permission.");
    return false;
  }
コード例 #23
0
  public boolean parseTownyAdminCommand(String[] split) throws TownyException {

    if (split.length == 0) {
      buildTAPanel();
      for (String line : ta_panel) {
        sender.sendMessage(line);
      }

    } else if (split[0].equalsIgnoreCase("?") || split[0].equalsIgnoreCase("help")) {
      for (String line : ta_help) {
        sender.sendMessage(line);
      }
    } else {

      if (split[0].equalsIgnoreCase("set")) {

        adminSet(StringMgmt.remFirstArg(split));
        return true;

      } else if (split[0].equalsIgnoreCase("town")) {

        parseAdminTownCommand(StringMgmt.remFirstArg(split));
        return true;

      } else if (split[0].equalsIgnoreCase("nation")) {

        parseAdminNationCommand(StringMgmt.remFirstArg(split));
        return true;

      } else if (split[0].equalsIgnoreCase("toggle")) {

        parseToggleCommand(StringMgmt.remFirstArg(split));
        return true;
      }

      if ((!isConsole)
          && (!TownyUniverse.getPermissionSource()
              .testPermission(
                  player,
                  PermissionNodes.TOWNY_COMMAND_TOWNYADMIN.getNode(split[0].toLowerCase()))))
        throw new TownyException(TownySettings.getLangString("msg_err_command_disable"));

      if (split[0].equalsIgnoreCase("givebonus")) {

        giveBonus(StringMgmt.remFirstArg(split));

      } else if (split[0].equalsIgnoreCase("reload")) {

        reloadTowny(false);

      } else if (split[0].equalsIgnoreCase("reset")) {

        reloadTowny(true);

      } else if (split[0].equalsIgnoreCase("backup")) {

        try {
          TownyUniverse.getDataSource().backup();
          TownyMessaging.sendMsg(getSender(), TownySettings.getLangString("mag_backup_success"));

        } catch (IOException e) {
          TownyMessaging.sendErrorMsg(getSender(), "Error: " + e.getMessage());
        }

      } else if (split[0].equalsIgnoreCase("newday")) {

        TownyTimerHandler.newDay();

      } else if (split[0].equalsIgnoreCase("purge")) {

        purge(StringMgmt.remFirstArg(split));

      } else if (split[0].equalsIgnoreCase("delete")) {
        String[] newSplit = StringMgmt.remFirstArg(split);
        residentDelete(player, newSplit);
      } else if (split[0].equalsIgnoreCase("unclaim")) {

        parseAdminUnclaimCommand(StringMgmt.remFirstArg(split));
        /*
         * else if (split[0].equalsIgnoreCase("seed") &&
         * TownySettings.getDebug()) seedTowny(); else if
         * (split[0].equalsIgnoreCase("warseed") &&
         * TownySettings.getDebug()) warSeed(player);
         */

      } else {
        TownyMessaging.sendErrorMsg(
            getSender(), TownySettings.getLangString("msg_err_invalid_sub"));
        return false;
      }
    }

    return true;
  }
コード例 #24
0
ファイル: CombatUtil.java プロジェクト: hsyyid/Towny
  /**
   * Tests the attacker against defender to see if we need to cancel the damage event due to world
   * PvP, Plot PvP or Friendly Fire settings. Only allow a Wolves owner to cause it damage, and
   * residents with destroy permissions to damage passive animals and villagers while in a town.
   *
   * @param world
   * @param attackingEntity
   * @param defendingEntity
   * @param attackingPlayer
   * @param defendingPlayer
   * @return true if we should cancel.
   */
  public static boolean preventDamageCall(
      Towny plugin,
      TownyWorld world,
      Entity attackingEntity,
      Entity defendingEntity,
      Player attackingPlayer,
      Player defendingPlayer) {

    // World using Towny
    if (!world.isUsingTowny()) return false;

    /*
     * We have an attacking player
     */
    if (attackingPlayer != null) {

      Coord coord = Coord.parseCoord(defendingEntity);
      TownBlock defenderTB = null;
      TownBlock attackerTB = null;

      try {
        attackerTB = world.getTownBlock(Coord.parseCoord(attackingEntity));
      } catch (NotRegisteredException ex) {
      }

      try {
        defenderTB = world.getTownBlock(coord);
      } catch (NotRegisteredException ex) {
      }

      /*
       * If another player is the target
       * or
       * The target is in a TownBlock and...
       * the target is a tame wolf and we are not it's owner
       */
      if ((defendingPlayer != null)
          || ((defenderTB != null)
              && ((defendingEntity instanceof Wolf)
                  && ((Wolf) defendingEntity).isTamed()
                  && !((Wolf) defendingEntity).getOwner().equals((AnimalTamer) attackingEntity)))) {

        /*
         * Defending player is in a warzone
         */
        if (world.isWarZone(coord)) return false;

        /*
         * Check for special pvp plots (arena)
         */
        if (isPvPPlot(attackingPlayer, defendingPlayer)) return false;

        /*
         * Check if we are preventing friendly fire between allies
         * Check the attackers TownBlock and it's Town for their PvP
         * status, else the world.
         * Check the defenders TownBlock and it's Town for their PvP
         * status, else the world.
         */
        if (preventFriendlyFire(attackingPlayer, defendingPlayer)
            || preventPvP(world, attackerTB)
            || preventPvP(world, defenderTB)) {

          DisallowedPVPEvent event = new DisallowedPVPEvent(attackingPlayer, defendingPlayer);
          plugin.getServer().getPluginManager().callEvent(event);

          return !event.isCancelled();
        }

      } else {

        /*
         * Remove animal killing prevention start
         */

        /*
         * Defender is not a player so check for PvM
         */
        if (defenderTB != null) {
          List<Class<?>> prots =
              EntityTypeUtil.parseLivingEntityClassNames(
                  TownySettings.getEntityTypes(), "TownMobPVM:");
          if (EntityTypeUtil.isInstanceOfAny(prots, defendingEntity)) {
            /*
             * Only allow the player to kill protected entities etc,
             * if they are from the same town
             * and have destroy permissions (grass) in the defending
             * TownBlock
             */
            if (!PlayerCacheUtil.getCachePermission(
                attackingPlayer, attackingPlayer.getLocation(), 3, (byte) 0, ActionType.DESTROY))
              return true;
          }
        }

        /*
         * Remove prevention end
         */

        /*
         * Protect specific entity interactions (faked with block ID's).
         */
        int blockID = 0;

        switch (defendingEntity.getType()) {
          case ITEM_FRAME:
            blockID = 389;
            break;

          case PAINTING:
            blockID = 321;

            break;

          case MINECART:
            if (defendingEntity instanceof org.bukkit.entity.minecart.StorageMinecart) {

              blockID = 342;

            } else if (defendingEntity instanceof org.bukkit.entity.minecart.RideableMinecart) {

              blockID = 328;

            } else if (defendingEntity instanceof org.bukkit.entity.minecart.PoweredMinecart) {

              blockID = 343;

            } else if (defendingEntity instanceof org.bukkit.entity.minecart.HopperMinecart) {

              blockID = 408;

            } else {

              blockID = 321;
            }
          default:
            break;
        }

        if (blockID != 0) {
          // Get permissions (updates if none exist)
          boolean bDestroy =
              PlayerCacheUtil.getCachePermission(
                  attackingPlayer,
                  defendingEntity.getLocation(),
                  blockID,
                  (byte) 0,
                  TownyPermission.ActionType.DESTROY);

          if (!bDestroy) {

            /*
             * Fetch the players cache
             */
            PlayerCache cache = plugin.getCache(attackingPlayer);

            if (cache.hasBlockErrMsg())
              TownyMessaging.sendErrorMsg(attackingPlayer, cache.getBlockErrMsg());

            return true;
          }
        }
      }
    }

    return false;
  }