예제 #1
0
  public void createControlPoint(BlockCoord absCoord) {

    Location centerLoc = absCoord.getLocation();

    /* Build the bedrock tower. */
    // for (int i = 0; i < 1; i++) {
    Block b = centerLoc.getBlock();
    ItemManager.setTypeId(b, CivData.FENCE);
    ItemManager.setData(b, 0);

    StructureBlock sb = new StructureBlock(new BlockCoord(b), this);
    this.addStructureBlock(sb.getCoord(), true);
    // }

    /* Build the control block. */
    b = centerLoc.getBlock().getRelative(0, 1, 0);
    ItemManager.setTypeId(b, CivData.OBSIDIAN);
    sb = new StructureBlock(new BlockCoord(b), this);
    this.addStructureBlock(sb.getCoord(), true);

    int townhallControlHitpoints;
    try {
      townhallControlHitpoints =
          CivSettings.getInteger(CivSettings.warConfig, "war.control_block_hitpoints_townhall");
    } catch (InvalidConfiguration e) {
      e.printStackTrace();
      townhallControlHitpoints = 100;
    }

    BlockCoord coord = new BlockCoord(b);
    this.controlPoints.put(coord, new ControlPoint(coord, this, townhallControlHitpoints));
  }
예제 #2
0
 private Sign getSign(Location l) {
   if (l == null) return null;
   Material t = l.getBlock().getType();
   return t == Material.SIGN || t == Material.SIGN_POST || t == Material.WALL_SIGN
       ? (Sign) l.getBlock().getState()
       : null;
 }
예제 #3
0
  private int spoutableWaterHeight(Location location) {

    Location loc = location.clone();
    if (loc.getBlock().getType() != Material.AIR && !BlockTools.isWaterBased(loc.getBlock())) {
      return -1;
    }
    int height = HEIGHT;
    if (Tools.isNight(loc.getWorld())) {
      height = (int) (Settings.NIGHT_FACTOR * HEIGHT) + 1;
    }
    for (int i = 0; i <= (height + 1); i++) {
      Location locToTest = loc.add(0, -1, 0);
      if (ProtectionManager.isRegionProtectedFromBending(
          this.player, BendingAbilities.WaterSpout, locToTest)) {
        return -1;
      }
      Block block = locToTest.getBlock();
      if (block.getType().equals(Material.AIR)) {
        this.height = i + 1;
        continue;
      }
      if (BlockTools.isWaterBased(block)) {
        // Valid source !
        return i + 1;
      } else {
        return -1;
        // Cannot waterspout
      }
    }
    return -2;
    // Can waterspout but too high
  }
예제 #4
0
 public void spawnLootChest() {
   chest.getBlock().setType(Material.CHEST);
   ItemStack randomItem = getRandomItem();
   Location l = chest.getBlock().getLocation();
   double y = l.getY() - 1;
   Location lf = new Location(l.getWorld(), l.getBlockX(), y, l.getBlockZ());
   Util.spawnFirework(lf);
   for (int i = 0; i < 5; i++) {}
   Chest c = (Chest) chest.getBlock().getState();
   Inventory inv = c.getBlockInventory();
   Random r = new Random();
   inv.setItem(r.nextInt(inv.getSize()), randomItem);
   if (lootItems > inv.getSize() - 2) {
     lootItems = inv.getSize() - 2;
   }
   for (int i = 0; i < lootItems; i++) {
     int slot = r.nextInt(inv.getSize());
     if (isEmpty(inv, slot)) {
       inv.setItem(slot, randomItem);
     } else {
       i--;
     }
   }
   for (int i = 0; i < ingots; i++) {
     int slot = r.nextInt(inv.getSize());
     ItemStack stack = inv.getItem(slot);
     if (isEmpty(inv, slot)) {
       inv.setItem(slot, new ItemStack(Material.IRON_INGOT));
     } else if (stack.getType() == Material.IRON_INGOT) {
       inv.getItem(slot).setAmount(stack.getAmount() + 1);
     } else {
       i--;
     }
   }
 }
예제 #5
0
  public boolean readBlocks(Location l1, World w) {
    try {
      FileInputStream fstream = new FileInputStream("plugins/NerdLocker/blocks.lock");
      DataInputStream in = new DataInputStream(fstream);
      BufferedReader br = new BufferedReader(new InputStreamReader(in));
      String strLine;
      while ((strLine = br.readLine()) != null) {
        String delims = ",";
        String[] cords = strLine.split(delims);

        int x = Integer.parseInt(cords[0]);
        int y = Integer.parseInt(cords[1]);
        int z = Integer.parseInt(cords[2]);

        Location l = w.getBlockAt(x, y, z).getLocation();

        if (l1.getBlock().getX() == l.getBlock().getX()
            && l1.getBlock().getY() == l.getBlock().getY()
            && l1.getBlock().getZ() == l.getBlock().getZ()) {
          return false;
        }
      }
      in.close();
      br.close();
      fstream.close();
      return true;
    } catch (Exception e) {
      System.err.println("Error1: " + e.getMessage());
    }
    return false;
  }
예제 #6
0
  // RŽcupŽration du Relative et ajout du SignManager dans le Set
  public static boolean registerSign(Location locsign) {
    try {
      locsign.getBlock();
    } catch (Exception e) {
      return false;
    } // VŽrifie sur la locsign est un block

    if (!(locsign.getBlock().getState() instanceof org.bukkit.block.Sign)) return false;

    Block bs = locsign.getBlock();
    org.bukkit.material.Sign signmat = (org.bukkit.material.Sign) bs.getState().getData();
    Location relative = null;

    if (!signmat.isWallSign()) relative = bs.getRelative(BlockFace.DOWN).getLocation();
    else if (signmat.getAttachedFace() == BlockFace.EAST)
      relative = bs.getRelative(BlockFace.EAST).getLocation();
    else if (signmat.getAttachedFace() == BlockFace.WEST)
      relative = bs.getRelative(BlockFace.WEST).getLocation();
    else if (signmat.getAttachedFace() == BlockFace.NORTH)
      relative = bs.getRelative(BlockFace.NORTH).getLocation();
    else if (signmat.getAttachedFace() == BlockFace.SOUTH)
      relative = bs.getRelative(BlockFace.SOUTH).getLocation();

    SignManager sm = new SignManager(locsign, relative);
    sm.RefreshSign();
    return true;
  }
예제 #7
0
  private boolean spawnMob() {
    if (myConfig.getDisabledWorlds().contains(world)) return false;
    final int maxHeight = 10;

    int x = this.radius - (int) (Math.random() * this.radius * 2.0D);
    int z = this.radius - (int) (Math.random() * this.radius * 2.0D);
    long d = x * x + z * z;
    if (d >= radius * radius) {
      x *= radius / (2 * d);
      z *= radius / (2 * d);
    }
    Location l1 =
        new Location(
            Bukkit.getWorld(this.world), this.m.getX() + x, this.m.getY(), this.m.getZ() + z);
    int p = l1.getBlock().getType().equals(Material.AIR) ? -1 : 1;
    for (int h = 0; h < maxHeight; h++) {
      l1.setY(this.m.getY() + h * p);
      if ((!l1.getBlock().getType().equals(Material.AIR))
          && (l1.getBlock().getRelative(BlockFace.UP).getType().equals(Material.AIR))) {
        l1.setY(l1.getY() + 2.0D);
        return Mob.spawnEntity(this.mob, l1, this.m) != null;
      }
    }
    return false;
  }
예제 #8
0
  public static void drop(Player p) {
    Location loc = new Location(Bukkit.getWorld("world"), 0, 0, 0);
    Random rand = new Random();
    loc.setX(rand.nextInt(8000));
    loc.setY(100);
    loc.setZ(rand.nextInt(8000));
    loc.setY(Bukkit.getWorld("world").getHighestBlockAt(loc.getBlockX(), loc.getBlockZ()).getY());
    loc.getBlock().setType(Material.CHEST);
    Block bb = loc.getBlock();
    bb.setType(Material.CHEST);
    Chest chest = (Chest) bb.getState();

    Inventory inv = chest.getInventory();

    for (ItemStack stack : items) {
      inv.addItem(stack);
    }

    Bukkit.broadcastMessage(
        ChatColor.RED + "A tornado has appeared in the world, and left valuble supplies!");
    Bukkit.broadcastMessage(
        ChatColor.translateAlternateColorCodes(
            '&',
            "&7Coords: X: &c"
                + loc.getBlockX()
                + "&7 Y:&c "
                + loc.getBlockY()
                + "&7 Z: &c"
                + loc.getBlockZ()));
  }
예제 #9
0
 public void sendToSpawn(Gamer gamer) {
   final Player p = gamer.getPlayer();
   Location originalSpawn = p.getWorld().getSpawnLocation();
   MainConfig main = HungergamesApi.getConfigManager().getMainConfig();
   int spawnRadius = main.getSpawnRadius();
   int spawnHeight = main.getSpawnHeight();
   if (spawns.size() > 0) {
     if (spawnItel == null || !spawnItel.hasNext()) spawnItel = spawns.keySet().iterator();
     originalSpawn = spawnItel.next();
     spawnRadius = Math.max(1, spawns.get(originalSpawn)[0]);
     spawnHeight = Math.max(1, spawns.get(originalSpawn)[1]);
   }
   Location spawn = originalSpawn.clone();
   int chances = 0;
   if (p.isInsideVehicle()) p.leaveVehicle();
   p.eject();
   while (chances < main.getTimesToCheckForValidSpawnPerPlayer()) {
     chances++;
     Location newLoc =
         new Location(
             p.getWorld(),
             spawn.getX() + returnChance(-spawnRadius, spawnRadius),
             spawn.getY() + new Random().nextInt(spawnHeight),
             spawn.getZ() + returnChance(-spawnRadius, spawnRadius));
     if (nonSolid.contains(newLoc.getBlock().getTypeId())
         && nonSolid.contains(newLoc.getBlock().getRelative(BlockFace.UP).getTypeId())) {
       while (newLoc.getBlockY() >= 1
           && nonSolid.contains(newLoc.getBlock().getRelative(BlockFace.DOWN).getTypeId())) {
         newLoc = newLoc.add(0, -1, 0);
       }
       if (newLoc.getBlockY() <= 1) continue;
       spawn = newLoc;
       break;
     }
   }
   if (spawn.equals(originalSpawn)) {
     spawn =
         new Location(
             p.getWorld(),
             spawn.getX() + returnChance(-spawnRadius, spawnRadius),
             0,
             spawn.getZ() + returnChance(-spawnRadius, spawnRadius));
     spawn.setY(spawn.getWorld().getHighestBlockYAt(spawn));
     if (gamer.isAlive() && spawn.getY() <= 1) {
       spawn.getBlock().setType(Material.GLASS);
       spawn.setY(spawn.getY() + 1);
     }
   }
   final Location destination = spawn.add(0.5, 0.1, 0.5);
   p.teleport(destination);
   Bukkit.getScheduler()
       .scheduleSyncDelayedTask(
           hg,
           new Runnable() {
             public void run() {
               p.teleport(destination);
             }
           });
 }
예제 #10
0
 public void cleanup() {
   for (Player player : plugin.store.stored) {
     Location storedLoc = plugin.store.placed.get(player);
     if (storedLoc.getBlock().getType().equals(Material.TNT)) {
       storedLoc.getBlock().setType(Material.AIR);
     }
   }
 }
예제 #11
0
 private Sign getSign(String loc) {
   Location l = SerializerUtil.getLocation(loc);
   if (l == null) return null;
   Material t = l.getBlock().getType();
   return t == Material.SIGN || t == Material.SIGN_POST || t == Material.WALL_SIGN
       ? (Sign) l.getBlock().getState()
       : null;
 }
 private Location getOtherDoorBlock(Location door) {
   BlockFace[] faces = new BlockFace[] {BlockFace.DOWN, BlockFace.UP};
   for (BlockFace face : faces) {
     if (door.getBlock().getRelative(face).getType().equals(Material.AIR)) {
       return door.getBlock().getRelative(face).getLocation();
     }
   }
   return null;
 }
예제 #13
0
 public boolean revertblocks() {
   Vector direction = new Vector(0, -1, 0);
   location
       .getBlock()
       .setType(Material.AIR); // .clone().add(direction).getBlock().setType(Material.AIR);
   location.add(direction);
   if (blockIsBase(location.getBlock())) return false;
   return true;
 }
예제 #14
0
  public static void resetHighlightRegion(Player player, NovaRegion region) {
    Location loc1 = region.getCorner(0).clone();
    Location loc2 = region.getCorner(1).clone();

    loc1.setY(player.getWorld().getHighestBlockAt(loc1.getBlockX(), loc1.getBlockZ()).getY() - 1);
    loc2.setY(player.getWorld().getHighestBlockAt(loc2.getBlockX(), loc2.getBlockZ()).getY() - 1);

    setCorner(player, loc1, loc1.getBlock().getType());
    setCorner(player, loc2, loc2.getBlock().getType());
  }
예제 #15
0
  private void progress() {
    if (!hasEmptyWaterBottle()) {
      remove();
      return;
    }

    if (player.isDead() || !player.isOnline()) {
      remove();
      return;
    }

    if (player.getWorld() != location.getWorld()) {
      remove();
      return;
    }

    if (System.currentTimeMillis() < time + interval) return;

    time = System.currentTimeMillis();

    Vector direction = Methods.getDirection(location, player.getEyeLocation()).normalize();
    location = location.clone().add(direction);

    if (location == null || block == null) {
      remove();
      return;
    }

    if (location.getBlock().equals(block.getLocation().getBlock())) return;

    if (Methods.isRegionProtectedFromBuild(player, "WaterManipulation", location)) {
      remove();
      return;
    }

    if (location.distance(player.getEyeLocation())
        > Methods.waterbendingNightAugment(range, player.getWorld())) {
      remove();
      return;
    }

    if (location.distance(player.getEyeLocation()) <= 1.5) {
      fillBottle();
      return;
    }

    Block newblock = location.getBlock();
    if (Methods.isTransparentToEarthbending(player, newblock) && !newblock.isLiquid()) {
      block.revertBlock();
      block = new TempBlock(newblock, Material.WATER, full);
    } else {
      remove();
      return;
    }
  }
 public boolean isEmpty(Location loc1, boolean liquidsNotSolid) {
   if (loc1.getBlock().isLiquid() && liquidsNotSolid) {
     return true;
   } else if (loc1.getBlock().isEmpty()) {
     return true;
   } else if (!isSolidBlock(loc1.getBlock())) {
     return true;
   } else {
     return false;
   }
 }
예제 #17
0
 private Block findAir(Location l) {
   if (l.getBlock().getRelative(BlockFace.DOWN).getType() != Material.AIR) {
     return l.getBlock();
   }
   for (int i = 2; i < 7; i++) {
     if (l.getBlock().getRelative(BlockFace.DOWN, i).getType() != Material.AIR) {
       return l.getBlock().getRelative(BlockFace.DOWN, i - 1);
     }
   }
   return l.getBlock().getRelative(BlockFace.DOWN, 3);
 }
예제 #18
0
  public void build_trade_outpost_tower() throws CivException {
    /* Add trade good to town. */

    /* this.good is set by the good's load function or by the onBuild function. */
    TradeGood good = this.good;
    if (good == null) {
      throw new CivException("Couldn't find trade good at location:" + good);
    }

    /* Build the 'trade good tower' */
    /* This is always set on post build using the post build sync task. */
    if (tradeOutpostTower == null) {
      throw new CivException("Couldn't find trade outpost tower.");
    }

    Location centerLoc = tradeOutpostTower.getLocation();

    /* Build the bedrock tower. */
    for (int i = 0; i < 3; i++) {
      Block b = centerLoc.getBlock().getRelative(0, i, 0);
      ItemManager.setTypeId(b, CivData.BEDROCK);
      ItemManager.setData(b, 0);

      StructureBlock sb = new StructureBlock(new BlockCoord(b), this);
      this.addStructureBlock(sb.getCoord(), false);
      // CivGlobal.addStructureBlock(sb.getCoord(), this);
    }

    /* Place the sign. */
    Block b = centerLoc.getBlock().getRelative(1, 2, 0);
    ItemManager.setTypeId(b, CivData.WALL_SIGN);
    ItemManager.setData(b, CivData.DATA_SIGN_EAST);
    Sign s = (Sign) b.getState();
    s.setLine(0, good.getInfo().name);
    s.update();
    StructureBlock sb = new StructureBlock(new BlockCoord(b), this);
    // CivGlobal.addStructureBlock(sb.getCoord(), this);
    this.addStructureBlock(sb.getCoord(), false);

    /* Place the itemframe. */
    b = centerLoc.getBlock().getRelative(1, 1, 0);
    this.addStructureBlock(new BlockCoord(b), false);
    Block b2 = b.getRelative(0, 0, 0);
    Entity entity = CivGlobal.getEntityAtLocation(b2.getLocation());
    this.addStructureBlock(new BlockCoord(b2), false);

    if (entity == null || (!(entity instanceof ItemFrame))) {
      this.frameStore = new ItemFrameStorage(b.getLocation(), BlockFace.EAST);
    } else {
      this.frameStore = new ItemFrameStorage((ItemFrame) entity, b.getLocation());
    }

    this.frameStore.setBuildable(this);
  }
예제 #19
0
  public boolean stock() {

    if (offset.getBlock().getState() instanceof InventoryHolder) {

      Chest c = (Chest) offset.getBlock().getState();
      if (c.getInventory().addItem(item.clone()).isEmpty()) {
        c.update();
        return true;
      }
    }
    return false;
  }
예제 #20
0
 public static void checkSecond() {
   for (Item i : Bukkit.getWorld("PrisonMap").getEntitiesByClass(Item.class)) {
     if (tnts.contains(i.getUniqueId())) {
       ParticleEffect.SMOKE_NORMAL.display(
           0.25f, 0.25f, 0.25f, 0.0001f, 5, i.getLocation().clone().add(0, 0.5, 0), 100);
       if (i.getTicksLived() > 30) {
         ParticleEffect.EXPLOSION_HUGE.display(
             0.5f, 0.5f, 0.5f, 0.1f, 5, i.getLocation().clone().add(0, 1, 0), 100);
         for (Entity e : i.getNearbyEntities(3.5, 3.5, 3.5)) {
           if (e instanceof Player) {
             Location midPoint = i.getLocation();
             Vector direction =
                 e.getLocation().toVector().subtract(midPoint.toVector()).normalize();
             direction.multiply(1.1).setY(0.7);
             e.setVelocity(direction);
             ((Player) e).damage(0.0);
           }
         }
         final List<Location> blocks = new ArrayList<Location>();
         int radius = 3;
         int bX = i.getLocation().getBlockX();
         int bY = i.getLocation().getBlockY();
         int bZ = i.getLocation().getBlockZ();
         for (int x = bX - radius; x <= bX + radius; x++) {
           for (int y = bY - radius; y <= bY + radius; y++) {
             for (int z = bZ - radius; z <= bZ + radius; z++) {
               double distance =
                   ((bX - x) * (bX - x) + ((bZ - z) * (bZ - z)) + ((bY - y) * (bY - y)));
               if (distance < radius * radius) {
                 Location loc = new Location(i.getWorld(), x, y, z);
                 if (loc.getBlock().getType() != Material.AIR) {
                   blocks.add(loc);
                 }
               }
             }
           }
         }
         for (Location loc : blocks) {
           Random r = new Random();
           int i1 = r.nextInt(3) + 1;
           if (Game.isBreakable(loc.getBlock().getType()) && (i1 == 1 || i1 == 2)) {
             loc.getBlock().setType(Material.AIR);
           }
         }
         Game.playSound(Sound.EXPLODE, i.getLocation(), 1f, 1f);
         tnts.remove(i.getUniqueId());
         i.teleport(i.getLocation().subtract(0, 500, 0));
       }
     }
   }
 }
예제 #21
0
 /*
  * updates sign at location
  */
 public void refreshSign(Location loc) {
   if (loc.getBlock().getType().equals(Material.SIGN)
       || loc.getBlock().getType().equals(Material.SIGN_POST)
       || loc.getBlock().getType().equals(Material.WALL_SIGN)) {
     Sign sign = (Sign) loc.getBlock().getState();
     if (sign.getLine(0) != null && sign.getLine(1) != null && sign.getLine(0).contains("[TAX]")) {
       Taxes taxes = TaxCollector.getTaxes();
       sign.setLine(2, Double.toString(taxes.getTaxesByAlias(sign.getLine(1))));
       sign.update(true);
     }
   } else {
     // this.removeLocation(loc);
   }
 }
예제 #22
0
  /**
   * Gets the shop a sign is attached to
   *
   * @param loc The location of the sign
   * @return The shop
   */
  private Shop getShopNextTo(Location loc) {
    Block[] blocks = new Block[4];
    blocks[0] = loc.getBlock().getRelative(1, 0, 0);
    blocks[1] = loc.getBlock().getRelative(-1, 0, 0);
    blocks[2] = loc.getBlock().getRelative(0, 0, 1);
    blocks[3] = loc.getBlock().getRelative(0, 0, -1);

    for (Block b : blocks) {
      if (b.getType() != Material.CHEST) continue;
      Shop shop = plugin.getShopManager().getShop(b.getLocation());
      if (shop != null && shop.isAttached(loc.getBlock())) return shop;
    }
    return null;
  }
예제 #23
0
  public static void smartLogFallables(Consumer consumer, String playerName, Block origin) {

    WorldConfig wcfg = getWorldConfig(origin.getWorld());
    if (wcfg == null) return;

    // Handle falling blocks
    Block checkBlock = origin.getRelative(BlockFace.UP);
    int up = 0;
    final int highestBlock = checkBlock.getWorld().getHighestBlockYAt(checkBlock.getLocation());
    while (BukkitUtils.getRelativeTopFallables().contains(checkBlock.getType())) {

      // Record this block as falling
      consumer.queueBlockBreak(playerName, checkBlock.getState());

      // Guess where the block is going (This could be thrown of by explosions, but it is better
      // than nothing)
      Location loc = origin.getLocation();
      int x = loc.getBlockX();
      int y = loc.getBlockY();
      int z = loc.getBlockZ();
      while (y > 0 && BukkitUtils.canFall(loc.getWorld(), x, (y - 1), z)) {
        y--;
      }
      // If y is 0 then the sand block fell out of the world :(
      if (y != 0) {
        Location finalLoc = new Location(loc.getWorld(), x, y, z);
        // Run this check to avoid false positives
        if (!BukkitUtils.getFallingEntityKillers().contains(finalLoc.getBlock().getType())) {
          finalLoc.add(0, up, 0); // Add this here after checking for block breakers
          if (finalLoc.getBlock().getType() == Material.AIR
              || BukkitUtils.getRelativeTopFallables().contains(finalLoc.getBlock().getType())) {
            consumer.queueBlockPlace(
                playerName, finalLoc, checkBlock.getTypeId(), checkBlock.getData());
          } else {
            consumer.queueBlockReplace(
                playerName,
                finalLoc,
                finalLoc.getBlock().getTypeId(),
                finalLoc.getBlock().getData(),
                checkBlock.getTypeId(),
                checkBlock.getData());
          }
          up++;
        }
      }
      if (checkBlock.getY() >= highestBlock) break;
      checkBlock = checkBlock.getRelative(BlockFace.UP);
    }
  }
예제 #24
0
  @Override
  public void deleteLightSource(Location fromPlayerLocation, Player player) {
    CraftWorld cWorld = (CraftWorld) fromPlayerLocation.getWorld();

    int xPrevious = fromPlayerLocation.getBlockX();
    int yPrevious = fromPlayerLocation.getBlockY() + 2;
    int zPrevious = fromPlayerLocation.getBlockZ();

    Location previousSource = new Location(cWorld, xPrevious, yPrevious, zPrevious);
    Material blockMaterial = previousSource.getBlock().getType();
    byte blockData = previousSource.getBlock().getData();
    previousSource.getBlock().setType(blockMaterial);
    previousSource.getBlock().setData(blockData);
    Chunks.sendClientChanges();
  }
예제 #25
0
  @EventHandler
  public void onMove(PlayerMoveEvent e) {
    Player p = e.getPlayer();
    double x = p.getLocation().getX();
    double y = p.getLocation().getY() - 1;
    double z = p.getLocation().getZ();
    Location loc = new Location(p.getWorld(), x, y, z);
    Block b1 = loc.getBlock();
    Block b2 = p.getLocation().getBlock();

    if (b1.getType().equals(Material.REDSTONE_BLOCK) && b2.getType().equals(Material.WOOD_PLATE)) {
      // p.sendMessage("ON " + b1.getType().toString() + " + " + b2.getType().toString());
      p.setVelocity(p.getLocation().getDirection().multiply(2).setY(p.getVelocity().getY() + 1));
      p.setFallDistance(0f);
      for (Player all : Bukkit.getOnlinePlayers()) {
        all.playSound(p.getLocation(), Sound.WITHER_SHOOT, 0.1f, 0.1f);
      }
    }

    p.setSaturation(100f);
    p.setFoodLevel(20);
    p.setHealth(20f);

    if (p.getLocation().getY() <= 80) {
      p.teleport(p.getWorld().getSpawnLocation());
      p.setGameMode(GameMode.ADVENTURE);
      p.setAllowFlight(true);
      p.setFlying(false);
    }
  }
예제 #26
0
  private boolean isCloseDoor(Location actual) {
    BlockFace[] blockFaces = {BlockFace.EAST, BlockFace.NORTH, BlockFace.WEST, BlockFace.SOUTH};
    actual.setY(actual.getY());
    Block base = actual.getBlock();
    for (BlockFace bf : blockFaces) {
      Block bu = base.getRelative(bf);
      if ((bu.getType() == Material.WOODEN_DOOR)) {
        byte openData = 0x4;
        byte doorData = (byte) (bu.getData());
        if ((doorData & 0x4) == 0x4) {
          doorData = (byte) (doorData & 0x3);
        } else {
          doorData = (byte) (doorData | 0x7);
        }
        bu.setData(doorData);

        if ((bu.getRelative(BlockFace.UP).getType() == Material.WOODEN_DOOR)) {
          doorData = (byte) (bu.getRelative(BlockFace.UP).getData());
          if ((doorData & 0x1) == 1) {
            doorData = 0x9;
          } else {
            doorData = 0x8;
          }
          bu.getRelative(BlockFace.UP).setData(doorData);
        }
        return true;
      }
    }
    return false;
  }
예제 #27
0
 @Override
 public SpellResult perform(CastContext context) {
   Entity entity = context.getEntity();
   if (entity == null) {
     return SpellResult.ENTITY_REQUIRED;
   }
   Location targetLocation = context.getLocation();
   for (int i = 0; i < 2; i++) {
     if (!context.allowPassThrough(targetLocation.getBlock().getType()))
       return SpellResult.NO_TARGET;
     targetLocation.setY(targetLocation.getY() + 1);
   }
   Location location = context.findPlaceToStand(targetLocation, verticalSearchDistance, true);
   if (location == null && !safe) {
     location = context.getTargetLocation();
     location.setPitch(targetLocation.getPitch());
     location.setYaw(targetLocation.getYaw());
     verticalSearchDistance = 0;
   }
   if (location != null) {
     teleport(context, entity, location);
     return SpellResult.CAST;
   }
   return SpellResult.NO_TARGET;
 }
예제 #28
0
 public boolean progress() {
   if (System.currentTimeMillis() - time >= interval) {
     location = location.clone().add(direction);
     time = System.currentTimeMillis();
     if (location.distance(origin) > range) {
       remove();
       return false;
     }
     Block block = location.getBlock();
     if (isIgnitable(player, block)) {
       ignite(block);
       return true;
     } else if (isIgnitable(player, block.getRelative(BlockFace.DOWN))) {
       ignite(block.getRelative(BlockFace.DOWN));
       location = block.getRelative(BlockFace.DOWN).getLocation();
       return true;
     } else if (isIgnitable(player, block.getRelative(BlockFace.UP))) {
       ignite(block.getRelative(BlockFace.UP));
       location = block.getRelative(BlockFace.UP).getLocation();
       return true;
     } else {
       remove();
       return false;
     }
   }
   return false;
 }
 public static void createItemContainers(
     MinecartManiaStorageCart minecart, HashSet<ComparableLocation> available) {
   ArrayList<ItemContainer> containers = new ArrayList<ItemContainer>();
   for (Location loc : available) {
     Sign sign = (Sign) loc.getBlock().getState();
     if (isItemCollectionSign(sign)) {
       MinecartManiaLogger.getInstance().debug("Found Collect Item Sign");
       bracketizeSign(sign);
       containers.addAll(
           getItemContainers(sign.getBlock().getLocation(), minecart.getDirection(), true));
     } else if (isItemDepositSign(sign)) {
       MinecartManiaLogger.getInstance().debug("Found Deposit Item Sign");
       bracketizeSign(sign);
       containers.addAll(
           getItemContainers(sign.getBlock().getLocation(), minecart.getDirection(), false));
     } else if (isTrashItemSign(sign)) {
       MinecartManiaLogger.getInstance().debug("Found Trash Item Sign");
       bracketizeSign(sign);
       containers.addAll(
           getTrashItemContainers(sign.getBlock().getLocation(), minecart.getDirection()));
     }
     containers.addAll(
         getFurnaceContainers(sign.getBlock().getLocation(), minecart.getDirection()));
   }
   minecart.setDataValue("ItemContainerList", containers);
 }
예제 #30
0
 public static boolean hasBed(Player player) {
   Location bedlocation = player.getBedSpawnLocation();
   if ((bedlocation != null) && (bedlocation.getBlock().getType() == Material.BED_BLOCK)) {
     return true;
   }
   return false;
 }