Package com.palmergames.bukkit.towny.object

Examples of com.palmergames.bukkit.towny.object.TownyWorld


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

    TownyWorld world;
    try {
      world = TownyUniverse.getDataSource().getWorld(player.getWorld().getName());
    } catch (NotRegisteredException e1) {
      TownyMessaging.sendErrorMsg(player, "You are not in a registered world.");
      return;
    }
    if (!world.isUsingTowny()) {
      TownyMessaging.sendErrorMsg(player, "This world is not using towny.");
      return;
    }
    Coord pos = Coord.parseCoord(plugin.getCache(player).getLastLocation());

    // Generate Map
    int halfLineHeight = lineHeight / 2;
    String[][] townyMap = new String[lineWidth][lineHeight];
    int x, y = 0;
    for (int tby = pos.getX() + (lineWidth-halfLineWidth-1); tby >= pos.getX() - halfLineWidth; tby--) {
      x = 0;
      for (int tbx = pos.getZ() - halfLineHeight; tbx <= pos.getZ() + (lineHeight-halfLineHeight-1); tbx++) {
        try {
          TownBlock townblock = world.getTownBlock(tby, tbx);
          //TODO: possibly claim outside of towns
          if (!townblock.hasTown())
            throw new TownyException();
          if (x == halfLineHeight && y == halfLineWidth)
            // location
            townyMap[y][x] = Colors.Gold;
          else if (hasTown) {
            if (resident.getTown() == townblock.getTown()) {
              // own town
              townyMap[y][x] = Colors.LightGreen;
              try {
                if (resident == townblock.getResident())
                  //own plot
                  townyMap[y][x] = Colors.Yellow;
              } catch(NotRegisteredException e) {
              }
            } else if (resident.hasNation()) {
              if (resident.getTown().getNation().hasTown(townblock.getTown()))
                // towns
                townyMap[y][x] = Colors.Green;
              else if (townblock.getTown().hasNation()) {
                Nation nation = resident.getTown().getNation();
                if (nation.hasAlly(townblock.getTown().getNation()))
                  townyMap[y][x] = Colors.Green;
                else if (nation.hasEnemy(townblock.getTown().getNation()))
                  // towns
                  townyMap[y][x] = Colors.Red;
                else
                  townyMap[y][x] = Colors.White;
              } else
                townyMap[y][x] = Colors.White;
            } else
              townyMap[y][x] = Colors.White;
          } else
            townyMap[y][x] = Colors.White;

          // Registered town block
          if (townblock.getPlotPrice() != -1) {
            // override the colour if it's a shop plot for sale
            if (townblock.getType().equals(TownBlockType.COMMERCIAL))
              townyMap[y][x] = Colors.Blue;
            townyMap[y][x] += "$";
          } else if (townblock.isHomeBlock())
            townyMap[y][x] += "H";
          else
            townyMap[y][x] += townblock.getType().getAsciiMapKey();
        } catch (TownyException e) {
          if (x == halfLineHeight && y == halfLineWidth)
            townyMap[y][x] = Colors.Gold;
          else
            townyMap[y][x] = Colors.Gray;

          // Unregistered town block
          townyMap[y][x] += "-";
        }
        x++;
      }
      y++;
    }
   
    String[] compass = generateCompass(player);
   
    // Output
    player.sendMessage(ChatTools.formatTitle("Towny Map " + Colors.White + "(" + pos.toString() + ")"));
    String line;
    int lineCount = 0;
    // Variables have been rotated to fit N/S/E/W properly
    for (int my = 0; my < lineHeight; my++) {
      line = compass[0];
      if (lineCount < compass.length)
        line = compass[lineCount];

      for (int mx = lineWidth-1; mx >= 0; mx--)
        line += townyMap[mx][my];
     
      if (lineCount < help.length)
        line += help[lineCount];
     
      player.sendMessage(line);
      lineCount++;
    }
   
    // Current town block data
    try {
      TownBlock townblock = world.getTownBlock(pos);
      TownyMessaging.sendMsg(player, ("Town: " + (townblock.hasTown() ? townblock.getTown().getName() : "None") + " : "
          + "Owner: " + (townblock.hasResident() ? townblock.getResident().getName() : "None")));
    } catch (TownyException e) {
      //plugin.sendErrorMsg(player, e.getError());
      // Send a blank line instead of an error, to keep the map position tidy.
View Full Code Here


    if (attacker != null) {
      //plugin.sendMsg("Attacker not null");

      TownyUniverse universe = plugin.getTownyUniverse();
      try {
        TownyWorld world = TownyUniverse.getDataSource().getWorld(defender.getWorld().getName());

        // Wartime
        if (universe.isWarTime()) {
          event.setCancelled(false);
          throw new Exception();
View Full Code Here

    Entity entity = event.getEntity();

    if (entity instanceof Monster) {

      Location loc = entity.getLocation();
      TownyWorld townyWorld = null;

      try {
        townyWorld = TownyUniverse.getDataSource().getWorld(loc.getWorld().getName());

        //remove drops from monster deaths if in an arena plot          
        if (townyWorld.isUsingTowny()) {
          if (townyWorld.getTownBlock(Coord.parseCoord(loc)).getType() == TownBlockType.ARENA)
            event.getDrops().clear();
        }

      } catch (NotRegisteredException e) {
        // Unknown world or not in a town
View Full Code Here

   
    if (event.getEntity() instanceof LivingEntity) {
      LivingEntity livingEntity = (LivingEntity) event.getEntity();
      Location loc = event.getLocation();
      Coord coord = Coord.parseCoord(loc);
      TownyWorld townyWorld = null;

      try {
        townyWorld = TownyUniverse.getDataSource().getWorld(loc.getWorld().getName());
      } catch (NotRegisteredException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }

      //remove from world if set to remove mobs globally
      if (townyWorld.isUsingTowny())
        if (!townyWorld.hasWorldMobs() && MobRemovalTimerTask.isRemovingWorldEntity(livingEntity)) {
          //TownyMessaging.sendDebugMsg("onCreatureSpawn world: Canceled " + event.getCreatureType() + " from spawning within "+coord.toString()+".");
          event.setCancelled(true);
        }

      //remove from towns if in the list and set to remove           
      try {
        TownBlock townBlock = townyWorld.getTownBlock(coord);
        if (townyWorld.isUsingTowny() && !townyWorld.isForceTownMobs()) {
          if (!townBlock.getTown().hasMobs() && !townBlock.getPermissions().mobs) {
            if (MobRemovalTimerTask.isRemovingTownEntity(livingEntity)) {
              //TownyMessaging.sendDebugMsg("onCreatureSpawn town: Canceled " + event.getCreatureType() + " from spawning within "+coord.toString()+".");
              event.setCancelled(true);
            }
View Full Code Here

    Block block = event.getBlock();
    Entity entity = event.getEntity();

    try {
      TownyWorld townyWorld = TownyUniverse.getDataSource().getWorld(block.getLocation().getWorld().getName());

      // Prevent creatures trampling crops
      if ((townyWorld.isUsingTowny()) && (townyWorld.isDisableCreatureTrample())) {
        if ((block.getType() == Material.SOIL) || (block.getType() == Material.CROPS)) {
          if (entity instanceof Creature)
            event.setCancelled(true);
          return;
        }
View Full Code Here

      return;
    }

    Block block = event.getBlock();

    TownyWorld townyWorld = null;
    TownBlock townBlock;

    try {
      townyWorld = TownyUniverse.getDataSource().getWorld(block.getLocation().getWorld().getName());
     
      if (!townyWorld.isUsingTowny())
        return;
     
      if (townyWorld.isEndermanProtect())
        try {
          townBlock = townyWorld.getTownBlock(new Coord(Coord.parseCoord(block)));
          if (!townyWorld.isForceTownMobs() && !townBlock.getPermissions().mobs && !townBlock.getTown().hasMobs())
            event.setCancelled(true);
        } catch (NotRegisteredException e) {
          // not in a townblock
          event.setCancelled(true);
        }
View Full Code Here

    if (event.isCancelled() || plugin.isError()) {
      event.setCancelled(true);
      return;
    }

    TownyWorld townyWorld = null;
    TownBlock townBlock;

    try {
      townyWorld = TownyUniverse.getDataSource().getWorld(event.getLocation().getWorld().getName());
     
      if (!townyWorld.isUsingTowny())
        return;
     
      if (townyWorld.isEndermanProtect())
        try {
          townBlock = townyWorld.getTownBlock(new Coord(Coord.parseCoord(event.getLocation())));
          if (!townyWorld.isForceTownMobs() && !townBlock.getPermissions().mobs && !townBlock.getTown().hasMobs())
            event.setCancelled(true);
        } catch (NotRegisteredException e) {
          // not in a townblock
          event.setCancelled(true);
        }
View Full Code Here

    for (Block block : blocks) {
      loc = block.getLocation();
      coord = Coord.parseCoord(loc);
      count++;
      TownyWorld townyWorld;

      try {
        townyWorld = TownyUniverse.getDataSource().getWorld(loc.getWorld().getName());
       
        if (!townyWorld.isUsingTowny())
          return;
       
      } catch (NotRegisteredException e) {
        // failed to get world so abort
        return;
      }

      // Warzones
      if (townyWorld.isWarZone(coord)) {
        if (!TownyWarConfig.isAllowingExplosionsInWarZone()) {
          if (event.getEntity() != null)
            TownyMessaging.sendDebugMsg("onEntityExplode: Canceled " + event.getEntity().getEntityId() + " from exploding within " + coord.toString() + ".");
          event.setCancelled(true);
          break;
        } else {
          if (TownyWarConfig.explosionsBreakBlocksInWarZone()) {
            if (TownyWarConfig.regenBlocksAfterExplosionInWarZone()) {
              // ***********************************
              // TODO

              // On completion, remove TODO from config.yml comments.

              /*
              if (!plugin.getTownyUniverse().hasProtectionRegenTask(new BlockLocation(block.getLocation()))) {
                ProtectionRegenTask task = new ProtectionRegenTask(plugin.getTownyUniverse(), block, false);
                task.setTaskId(plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, task, ((TownySettings.getPlotManagementWildRegenDelay() + count)*20)));
                plugin.getTownyUniverse().addProtectionRegenTask(task);
              }
              */

              // TODO
              // ***********************************
            }

            // Break the block
          } else {
            event.blockList().remove(block);
          }
        }
        return;
      }

      //TODO: expand to protect neutrals during a war
      try {
        TownBlock townBlock = townyWorld.getTownBlock(coord);

        // If explosions are off, or it's wartime and explosions are off and the towns has no nation
        if (townyWorld.isUsingTowny() && !townyWorld.isForceExpl()) {
          if ((!townBlock.getPermissions().explosion) || (plugin.getTownyUniverse().isWarTime() && TownySettings.isAllowWarBlockGriefing() && !townBlock.getTown().hasNation() && !townBlock.getTown().isBANG())) {
            if (event.getEntity() != null)
              TownyMessaging.sendDebugMsg("onEntityExplode: Canceled " + event.getEntity().getEntityId() + " from exploding within " + coord.toString() + ".");
            event.setCancelled(true);
          }
        }
      } catch (TownyException x) {
        // Wilderness explosion regeneration
        if (townyWorld.isUsingTowny())
          if (townyWorld.isExpl()) {
            if (townyWorld.isUsingPlotManagementWildRevert()) {
              if (entity instanceof Creature) {
                if (!plugin.getTownyUniverse().hasProtectionRegenTask(new BlockLocation(block.getLocation()))) {
                  ProtectionRegenTask task = new ProtectionRegenTask(plugin.getTownyUniverse(), block, false);
                  task.setTaskId(plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, task, ((TownySettings.getPlotManagementWildRegenDelay() + count) * 20)));
                  plugin.getTownyUniverse().addProtectionRegenTask(task);
 
View Full Code Here

      Painting painting = evt.getPainting();
      Object remover = evt.getRemover();
      WorldCoord worldCoord;
     
      try {
        TownyWorld townyWorld = TownyUniverse.getDataSource().getWorld(painting.getWorld().getName());
         
        if (!townyWorld.isUsingTowny())
          return;
       
        worldCoord = new WorldCoord(townyWorld, Coord.parseCoord(painting.getLocation()));
      } catch (NotRegisteredException e1) {
        //TownyMessaging.sendErrorMsg(player, TownySettings.getLangString("msg_err_not_configured"));
View Full Code Here

    Player player = event.getPlayer();
    Painting painting = event.getPainting();

    WorldCoord worldCoord;
    try {
      TownyWorld townyWorld = TownyUniverse.getDataSource().getWorld(painting.getWorld().getName());
     
      if (!townyWorld.isUsingTowny())
        return;
     
      worldCoord = new WorldCoord(townyWorld, Coord.parseCoord(painting.getLocation()));
    } catch (NotRegisteredException e1) {
      TownyMessaging.sendErrorMsg(player, TownySettings.getLangString("msg_err_not_configured"));
View Full Code Here

TOP

Related Classes of com.palmergames.bukkit.towny.object.TownyWorld

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