Exemplo n.º 1
0
  @Override
  public void onPlayerTeleport(PlayerTeleportEvent event) {
    if (Permissions.TELEPORT.has(event.getPlayer())) return;
    if (event.getFrom().getWorld().equals(event.getTo().getWorld())
        && event.getFrom().distance(event.getTo()) < 5) return;

    ChunkyResident chunkyResident = new ChunkyResident(event.getPlayer());
    ChunkyTown myTown = chunkyResident.getTown();

    if (myTown == null) return;

    TownChunk fromChunk = new TownChunk(ChunkyManager.getChunkyChunk(event.getFrom()));
    TownChunk toChunk = new TownChunk(ChunkyManager.getChunkyChunk(event.getTo()));

    ChunkyTown fromTown = fromChunk.getTown();

    if (fromTown != null && fromTown.getEffectiveStance(myTown) != ChunkyTown.Stance.ALLY) {
      Strings.NO_TELEPORT.bad(chunkyResident);
      event.setCancelled(true);
      return;
    }

    ChunkyTown toTown = toChunk.getTown();

    if (toTown != null && toTown.getEffectiveStance(myTown) != ChunkyTown.Stance.ALLY) {
      Strings.NO_TELEPORT.bad(chunkyResident);
      event.setCancelled(true);
      return;
    }
  }
Exemplo n.º 2
0
  public void onCommand(
      CommandSender sender, ChunkyCommand chunkyCommand, String s, String[] strings) {
    if (!(sender instanceof Player)) {
      Language.IN_GAME_ONLY.bad(sender);
      return;
    }
    Player player = (Player) sender;
    ChunkyResident chunkyResident = new ChunkyResident(player);
    ChunkyChunk chunkyChunk = chunkyResident.getChunkyPlayer().getCurrentChunk();
    ChunkyTown chunkyTown = chunkyResident.getTown();
    if (chunkyTown == null) {
      Strings.NO_TOWN.bad(chunkyResident);
      return;
    }

    if (!chunkyTown.isOwnerOf(chunkyChunk)) {
      Strings.NOT_TOWN_LAND.bad(chunkyResident);
      return;
    }

    if (!chunkyResident.owns(chunkyChunk) && !chunkyResident.isAssistantOrMayor()) {
      Strings.NOT_OWNED.bad(chunkyResident);
      return;
    }

    double cost = 100;

    if (strings.length > 0) {
      cost = Tools.parseDouble(strings[0]);
      if (cost < 0) Strings.SPECIFY_NUMBER.bad(chunkyResident);
    }

    new TownChunk(chunkyChunk).setForSale(cost);
    Strings.FORSALE.good(chunkyResident, Chunky.getMethod().format(cost));
  }
Exemplo n.º 3
0
  @Override
  public void onPlayerRespawn(PlayerRespawnEvent event) {

    // Try to re-spawn at town.
    ChunkyResident chunkyResident = new ChunkyResident(event.getPlayer());
    ChunkyTown chunkyTown = chunkyResident.getTown();
    if (chunkyTown == null) return;
    chunkyResident.subtractPlayTime(Config.Options.DEATH_TOLL.getInt());
    event.setRespawnLocation(chunkyTown.getHome().getCoord().toLocation());
  }
Exemplo n.º 4
0
  public void onCommand(
      CommandSender sender, ChunkyCommand chunkyCommand, String s, String[] strings) {
    if (!(sender instanceof Player)) {
      Language.IN_GAME_ONLY.bad(sender);
      return;
    }
    Player player = (Player) sender;
    ChunkyResident chunkyResident = new ChunkyResident(player.getName());
    ChunkyChunk chunkyChunk = chunkyResident.getChunkyPlayer().getCurrentChunk();
    ChunkyTown chunkyTown = chunkyResident.getTown();
    if (chunkyTown == null) {
      Language.sendBad(chunkyResident.getChunkyPlayer(), "You do not belong to a town.");
      return;
    }

    if (!chunkyTown.isOwnerOf(chunkyChunk)) {
      Language.sendBad(chunkyResident.getChunkyPlayer(), "This is not town land.");
      return;
    }

    if (!chunkyResident.owns(chunkyChunk) && !chunkyResident.isAssistantOrMayor()) {
      Language.sendBad(chunkyResident.getChunkyPlayer(), "You do not own this land.");
      return;
    }

    new TownChunk(chunkyChunk).setNotForSale();
    Language.sendGood(chunkyResident.getChunkyPlayer(), "This plot is no longer for sale");
  }
Exemplo n.º 5
0
  @Override
  public void onPlayerJoin(PlayerJoinEvent event) {
    // Log join time
    ChunkyResident chunkyResident = new ChunkyResident(event.getPlayer());
    chunkyResident.login();

    // Apply title
    chunkyResident.applyTitle();

    // Add to starting town.
    if (chunkyResident.getTown() != null) return;
    ChunkyTown town = ChunkyTownManager.getTown(Config.Options.STARTING_TOWN.getString());
    if (town == null) return;
    town.addResident(chunkyResident);
  }
Exemplo n.º 6
0
 public void onCommand(
     CommandSender sender, ChunkyCommand chunkyCommand, String s, String[] strings) {
   if (!(sender instanceof Player)) {
     Language.IN_GAME_ONLY.bad(sender);
     return;
   }
   if (!Permissions.CREATE_TOWN.has(sender)) {
     Language.NO_COMMAND_PERMISSION.bad(sender);
     return;
   }
   Player player = (Player) sender;
   ChunkyResident chunkyResident = new ChunkyResident(player);
   if (chunkyResident.getTown() != null) {
     Language.sendBad(chunkyResident.getChunkyPlayer(), "You are already part of a town.");
     return;
   }
   if (strings.length < 1) {
     Language.sendBad(chunkyResident.getChunkyPlayer(), "Please specify the town name.");
     return;
   }
   ChunkyChunk chunkyChunk = chunkyResident.getChunkyPlayer().getCurrentChunk();
   if (chunkyChunk.isOwned()) {
     Language.sendBad(chunkyResident.getChunkyPlayer(), "This chunk is already owned.");
     return;
   }
   String id = strings[0];
   ChunkyTown chunkyTown = new ChunkyTown();
   chunkyTown.setId(ChunkyManager.getUniqueId());
   chunkyTown.setMayor(chunkyResident).setHome(chunkyChunk).setName(id);
   chunkyChunk.setOwner(chunkyTown, true, true);
   chunkyChunk.save();
   Language.sendGood(
       chunkyResident.getChunkyPlayer(),
       "You've just created a town called " + chunkyTown.getName());
 }