Пример #1
0
  @SuppressWarnings("deprecation")
  public static void setCorner(Player player, Location location, Material material) {
    if (material == null) {
      material = player.getWorld().getBlockAt(location).getType();
    }

    player.sendBlockChange(location, material, (byte) 0);
  }
Пример #2
0
 @Override
 public void remove(Hero hero) {
   super.remove(hero);
   Player p = hero.getPlayer();
   broadcast(p.getLocation(), expireText, p.getDisplayName());
   if (lastLoc != null) {
     p.sendBlockChange(lastLoc, lastMat, lastData);
   }
 }
Пример #3
0
 @Override
 public void tick(Hero hero) {
   super.tick(hero);
   Player p = hero.getPlayer();
   Block thisBlock = p.getLocation().getBlock().getRelative(BlockFace.DOWN);
   if (thisBlock.getLocation().equals(lastLoc)) {
     return;
   } else if (allowedBlocks.contains(thisBlock.getType())) {
     if (lastLoc != null) {
       p.sendBlockChange(lastLoc, lastMat, lastData);
     }
     lastLoc = thisBlock.getLocation();
     lastMat = thisBlock.getType();
     lastData = thisBlock.getData();
     p.sendBlockChange(lastLoc, Material.GLOWSTONE, (byte) 0);
   } else if (lastLoc != null) {
     p.sendBlockChange(lastLoc, lastMat, lastData);
   }
 }
  /**
   * Revert a single a visualized block to the player
   *
   * @param player
   * @param block
   */
  public void revertSingle(Player player, Block block) {
    Visualization vis = visualizations.get(player.getName());

    if (vis == null) {
      vis = new Visualization();
    }

    vis.addBlock(block);
    visualizations.put(player.getName(), vis);

    player.sendBlockChange(block.getLocation(), block.getType(), (byte) 0);
  }
  /**
   * Adds and displays a visualized block to the player
   *
   * @param player
   * @param material
   * @param block
   */
  public void displaySingle(Player player, Material material, Block block) {
    Visualization vis = visualizations.get(player.getName());

    if (vis == null) {
      vis = new Visualization();
    }

    vis.addBlock(block);
    visualizations.put(player.getName(), vis);

    player.sendBlockChange(block.getLocation(), material, (byte) 0);
  }
Пример #6
0
  @Override
  public void showBorder(final Player player) {

    final Location min = getMinimumLocation().toLocation();
    final Location max = getMaximumLocation().toLocation();
    final World w = Bukkit.getWorld(getRegion().getWorldName());

    border.clear();

    // move along exclusive x, create miny+maxy+minz+maxz
    for (int x = min.getBlockX() + 1; x < max.getBlockX(); x++) {
      border.add(new Location(w, x, min.getBlockY(), min.getBlockZ()).getBlock());
      border.add(new Location(w, x, min.getBlockY(), max.getBlockZ()).getBlock());
      border.add(new Location(w, x, max.getBlockY(), min.getBlockZ()).getBlock());
      border.add(new Location(w, x, max.getBlockY(), max.getBlockZ()).getBlock());
    }
    // move along exclusive y, create minx+maxx+minz+maxz
    for (int y = min.getBlockY() + 1; y < max.getBlockY(); y++) {
      border.add(new Location(w, min.getBlockX(), y, min.getBlockZ()).getBlock());
      border.add(new Location(w, min.getBlockX(), y, max.getBlockZ()).getBlock());
      border.add(new Location(w, max.getBlockX(), y, min.getBlockZ()).getBlock());
      border.add(new Location(w, max.getBlockX(), y, max.getBlockZ()).getBlock());
    }
    // move along inclusive z, create minx+maxx+miny+maxy
    for (int z = min.getBlockZ(); z <= max.getBlockZ(); z++) {
      border.add(new Location(w, min.getBlockX(), min.getBlockY(), z).getBlock());
      border.add(new Location(w, min.getBlockX(), max.getBlockY(), z).getBlock());
      border.add(new Location(w, max.getBlockX(), min.getBlockY(), z).getBlock());
      border.add(new Location(w, max.getBlockX(), max.getBlockY(), z).getBlock());
    }

    for (Block b : border) {
      if (!getRegion().isInNoWoolSet(b)) {
        player.sendBlockChange(b.getLocation(), Material.WOOL, (byte) 0);
      }
    }

    Bukkit.getScheduler()
        .scheduleSyncDelayedTask(
            PVPArena.instance,
            new Runnable() {

              @Override
              public void run() {
                for (Block b : border) {
                  player.sendBlockChange(b.getLocation(), b.getTypeId(), b.getData());
                }
                border.clear();
              }
            },
            100L);
  }
Пример #7
0
 @Override
 public void apply(Hero hero) {
   super.apply(hero);
   Player p = hero.getPlayer();
   broadcast(p.getLocation(), applyText, p.getDisplayName());
   Block thisBlock = p.getLocation().getBlock().getRelative(BlockFace.DOWN);
   if (allowedBlocks.contains(thisBlock.getType())) {
     lastLoc = thisBlock.getLocation();
     lastMat = thisBlock.getType();
     lastData = thisBlock.getData();
     p.sendBlockChange(lastLoc, Material.GLOWSTONE, (byte) 0);
   }
 }
  // reverts a visualization by sending another block change list, this time with the real world
  // block values
  public static void Revert(Player player) {
    PlayerData playerData = GriefPrevention.instance.dataStore.getPlayerData(player.getName());

    // Visualization visualization = playerData.currentVisualization;

    if (playerData.ActiveVisualizations.size() > 0) {
      if (player.isOnline()) {
        for (Visualization visualization : playerData.ActiveVisualizations) {
          for (int i = 0; i < visualization.elements.size(); i++) {
            VisualizationElement element = visualization.elements.get(i);
            Block block = element.location.getBlock();
            player.sendBlockChange(element.location, block.getType(), block.getData());
          }
        }
      }

      playerData.ActiveVisualizations.clear();
    }
  }
Пример #9
0
  public void run() {

    try {
      if (delay > 0) {
        Thread.sleep(delay);
      }

      // Create a fake note block
      player.sendBlockChange(loc, 25, (byte) 0);
      Thread.sleep(100);

      try {
        sequencer.run(this);
      } catch (Throwable t) {
        t.printStackTrace();
      }

      Thread.sleep(500);

      if (!keepMusicBlock) {
        // Restore music block
        CircuitsPlugin.server
            .getScheduler()
            .scheduleSyncDelayedTask(
                CircuitsPlugin.getInst(),
                new Runnable() {

                  public void run() {

                    int prevId = player.getWorld().getBlockTypeIdAt(loc);
                    byte prevData = player.getWorld().getBlockAt(loc).getData();
                    player.sendBlockChange(loc, prevId, prevData);
                  }
                });
      }
    } catch (InterruptedException e) {
      e.printStackTrace();
    } finally {
      sequencer.stop();
      sequencer = null;
    }
  }
Пример #10
0
  public void run() {
    while (!this.isInterrupted() && !kill.get()) {
      try {
        // Wait until necessary
        long timeWait =
            lastExecute + OrebfuscatorConfig.ProximityHiderRate - System.currentTimeMillis();
        lastExecute = System.currentTimeMillis();
        if (timeWait > 0) {
          Thread.sleep(timeWait);
        }

        if (!OrebfuscatorConfig.UseProximityHider) {
          running = false;
          return;
        }

        HashMap<Player, Location> checkPlayers = new HashMap<Player, Location>();

        synchronized (playersToCheck) {
          checkPlayers.putAll(playersToCheck);
          playersToCheck.clear();
        }

        int distance = OrebfuscatorConfig.ProximityHiderDistance;
        int distanceSquared = distance * distance;

        for (Player p : checkPlayers.keySet()) {

          if (p == null) {
            continue;
          }

          synchronized (proximityHiderTracker) {
            if (!proximityHiderTracker.containsKey(p)) {
              continue;
            }
          }

          Location loc1 = p.getLocation();
          Location loc2 = checkPlayers.get(p);

          // If player changed world
          if (!loc1.getWorld().equals(loc2.getWorld())) {
            synchronized (proximityHiderTracker) {
              proximityHiderTracker.remove(p);
              proximityHiderTrackerLocal.remove(p);
            }
            continue;
          }

          // Player didn't actually move
          if (loc1.getBlockX() == loc2.getBlockX()
              && loc1.getBlockY() == loc2.getBlockY()
              && loc1.getBlockZ() == loc2.getBlockZ()) {
            continue;
          }

          Set<Block> blocks = proximityHiderTrackerLocal.get(p);
          Set<Block> removedBlocks = new HashSet<Block>();
          if (blocks == null) {
            blocks = new HashSet<Block>();
            proximityHiderTrackerLocal.put(p, blocks);
          }

          int y = (int) Math.floor(p.getLocation().getY());

          boolean skip = OrebfuscatorConfig.skipProximityHiderCheck(y);

          synchronized (proximityHiderTracker) {
            Set<Block> synchronizedBlocks = proximityHiderTracker.get(p);
            if (synchronizedBlocks != null) {
              blocks.addAll(synchronizedBlocks);
              synchronizedBlocks.clear();
            }
          }

          if (!skip) {
            for (Block b : blocks) {
              if (b == null || b.getWorld() == null || p.getWorld() == null) {
                removedBlocks.add(b);
                continue;
              }

              if (!p.getWorld().equals(b.getWorld())) {
                removedBlocks.add(b);
                continue;
              }

              if (OrebfuscatorConfig.proximityHiderDeobfuscate(y, b)
                  || p.getLocation().distanceSquared(b.getLocation()) < distanceSquared) {
                removedBlocks.add(b);

                if (CalculationsUtil.isChunkLoaded(
                    b.getWorld(), b.getChunk().getX(), b.getChunk().getZ())) {
                  p.sendBlockChange(b.getLocation(), b.getTypeId(), b.getData());
                  final Block block = b;
                  final Player player = p;
                  Orebfuscator.instance.runTask(
                      new Runnable() {
                        @Override
                        public void run() {
                          OrebfuscatorConfig.blockAccess.updateBlockTileEntity(block, player);
                        }
                      });
                }
              }
            }

            for (Block b : removedBlocks) {
              blocks.remove(b);
            }
          }
        }
      } catch (Exception e) {
        Orebfuscator.log(e);
      }
    }

    running = false;
  }
Пример #11
0
 public void manageDeath(PlayerKilledEvent event) {
   Gamer killed = event.getKilled();
   final Player p = killed.getPlayer();
   p.setHealth(20);
   if (event.isCancelled()) return;
   for (HumanEntity human : p.getInventory().getViewers()) human.closeInventory();
   p.leaveVehicle();
   p.eject();
   p.setLevel(0);
   p.setExp(0F);
   if (event.getDeathMessage().equals(ChatColor.stripColor(event.getDeathMessage())))
     event.setDeathMessage(ChatColor.DARK_RED + event.getDeathMessage());
   event.setDeathMessage(
       this.formatDeathMessage(
           event.getDeathMessage().replace("%Remaining%", "" + (getAliveGamers().size() - 1)), p));
   if (event.getKillerPlayer() != null) {
     event.getKillerPlayer().addKill();
     event.setDeathMessage(
         this.formatDeathMessage(event.getDeathMessage(), event.getKillerPlayer().getPlayer()));
   }
   Bukkit.broadcastMessage(event.getDeathMessage());
   int reward = hg.getPrize(getAliveGamers().size());
   if (reward > 0) killed.addBalance(reward);
   hg.cannon();
   killed.clearInventory();
   World world = p.getWorld();
   for (ItemStack item : event.getDrops()) {
     if (item == null
         || item.getType() == Material.AIR
         || item.containsEnchantment(EnchantmentManager.UNLOOTABLE)) continue;
     else if (item.hasItemMeta())
       world
           .dropItemNaturally(event.getDropsLocation(), item.clone())
           .getItemStack()
           .setItemMeta(item.getItemMeta());
     else world.dropItemNaturally(event.getDropsLocation(), item);
   }
   setSpectator(killed);
   ScoreboardManager.makeScore(
       "Main", DisplaySlot.SIDEBAR, cm.getScoreboardPlayersLength(), getAliveGamers().size());
   hg.checkWinner();
   p.setVelocity(new Vector());
   for (PotionEffect effect : p.getActivePotionEffects()) p.removePotionEffect(effect.getType());
   p.teleport(p.getWorld().getHighestBlockAt(p.getLocation()).getLocation().clone().add(0, 10, 0));
   p.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 40, 9), true);
   p.sendBlockChange(p.getLocation(), Material.PORTAL.getId(), (byte) 0);
   p.sendBlockChange(p.getLocation(), Material.AIR.getId(), (byte) 0);
   for (Entity entity : p.getWorld().getEntities()) {
     if (entity instanceof Tameable
         && ((Tameable) entity).isTamed()
         && ((Tameable) entity).getOwner().getName().equals(p.getName())) {
       if (entity instanceof Wolf) ((Wolf) entity).setSitting(true);
       else if (entity instanceof Ocelot) ((Ocelot) entity).setSitting(true);
       else entity.remove();
     }
     if (entity instanceof Creature && ((Creature) entity).getTarget() == p)
       ((Creature) entity).setTarget(null);
   }
   if (HungergamesApi.getConfigManager().getMainConfig().isKickOnDeath()
       && !p.hasPermission("hungergames.spectate"))
     p.kickPlayer(String.format(cm.getKickDeathMessage(), event.getDeathMessage()));
   HungergamesApi.getAbilityManager().unregisterPlayer(p);
   HungergamesApi.getInventoryManager().updateSpectatorHeads();
 }
Пример #12
0
 @Override
 public void sendBlockChange(Location loc, int material, byte data) {
   caller.sendBlockChange(loc, material, data);
 }
Пример #13
0
  public static void playerLeaveArena(Player player, boolean message, boolean cleanup) {
    Arena arena = null;
    for (Arena arena2 : W.arenaList) {
      if (arena2.playersInArena != null) {
        if (arena2.playersInArena.contains(player)) {
          arena = arena2;
        }
      }
    }

    if (arena != null) {
      if (cleanup) {
        arena.playersInArena.remove(player);
        if (arena.seekers.contains(player)) {
          arena.seekers.remove(player);
        }
        if (arena.playersInArena.size() <= arena.minPlayers) {
          if (arena.gameState.equals(ArenaState.STARTING)) {
            arena.gameState = ArenaState.WAITING;
            arena.timer = 0;

            ArenaHandler.sendFMessage(
                arena, ConfigC.warning_lobbyNeedAtleast, true, "1-" + arena.minPlayers);
          } else {
            ArenaHandler.seekersWin(arena);
          }
        } else if (arena.seekers.size() <= 0 && arena.gameState == ArenaState.INGAME) {
          Player seeker = arena.playersInArena.get(W.random.nextInt(arena.playersInArena.size()));
          ArenaHandler.sendFMessage(
              arena, ConfigC.warning_ingameNEWSeekerChoosen, true, "seeker-" + seeker.getName());
          ArenaHandler.sendFMessage(
              arena, ConfigC.normal_ingameSeekerChoosen, true, "seeker-" + seeker.getName());
          W.dcAPI.undisguisePlayer(seeker);
          seeker.getInventory().clear();
          arena.seekers.add(seeker);
          seeker.teleport(arena.seekersWarp);
          W.seekertime.put(seeker, arena.waitingTimeSeeker);
        }
      }

      player.getInventory().clear();
      player.getInventory().setContents(W.pInventory.get(player));
      player.updateInventory();
      W.pInventory.remove(player);
      player.getInventory().setArmorContents(W.pArmor.get(player));
      W.pArmor.remove(player);
      player.setExp(W.pEXP.get(player));
      W.pEXP.remove(player);
      player.setLevel(W.pEXPL.get(player));
      W.pEXPL.remove(player);
      player.setHealth(W.pHealth.get(player));
      W.pHealth.remove(player);
      player.setFoodLevel(W.pFood.get(player));
      W.pFood.remove(player);
      W.pBlock.remove(player);

      player.teleport(W.pLocation.get(player));

      player.setGameMode(W.pGameMode.get(player));
      W.pGameMode.remove(player);
      W.pLocation.remove(player);

      for (Player pl : Bukkit.getOnlinePlayers()) {
        pl.showPlayer(player);
        if (W.hiddenLoc.get(player) != null) {
          Block pBlock = W.hiddenLoc.get(player).getBlock();
          pl.sendBlockChange(pBlock.getLocation(), Material.AIR, (byte) 0);
        }

        if (W.dcAPI.isDisguised(player)) {
          W.dcAPI.undisguisePlayer(player);
        }
      }

      ScoreboardHandler.removeScoreboard(player);

      MessageM.sendFMessage(player, ConfigC.normal_leaveYouLeft, true);
      if (message) {
        ArenaHandler.sendFMessage(
            arena,
            ConfigC.normal_leaveLeftArena,
            true,
            "playername-" + player.getName(),
            "1-" + arena.playersInArena.size(),
            "2-" + arena.maxPlayers);
      }
    } else {
      if (message) {
        MessageM.sendFMessage(player, ConfigC.error_leaveNotInArena, true);
      }
      return;
    }

    SignsHandler.updateSigns();
  }
Пример #14
0
  @SuppressWarnings("deprecation")
  public static void sendSquare(
      Player player, Location l1, Location l2, Material material, byte data) {
    if (player == null || l1 == null || l2 == null) {
      return;
    }

    Material material1 = null;
    Material material2 = null;

    Byte data1 = null;
    Byte data2 = null;

    if (material != null) {
      material1 = material2 = material;
      data1 = data2 = data;
    }

    int x;
    int z;

    int xs;
    int zs;

    int x1 = l1.getBlockX();
    int x2 = l2.getBlockX();
    int z1 = l1.getBlockZ();
    int z2 = l2.getBlockZ();

    int t;

    int dif_x = Math.abs(x1 - x2) + 1;
    int dif_z = Math.abs(z1 - z2) + 1;

    if (l1.getBlockX() < l2.getBlockX()) {
      xs = l1.getBlockX();
    } else {
      xs = l2.getBlockX();
    }

    if (l1.getBlockZ() < l2.getBlockZ()) {
      zs = l1.getBlockZ();
    } else {
      zs = l2.getBlockZ();
    }

    for (t = 0; t < dif_x; t++) {
      x = xs + t;
      int highest1 = player.getWorld().getHighestBlockYAt(x, z1) - 1;
      int highest2 = player.getWorld().getHighestBlockYAt(x, z2) - 1;
      Location loc1 = player.getWorld().getBlockAt(x, highest1, z1).getLocation();
      Location loc2 = player.getWorld().getBlockAt(x, highest2, z2).getLocation();

      if (material == null) {
        material1 = player.getWorld().getBlockAt(loc1).getType();
        material2 = player.getWorld().getBlockAt(loc2).getType();

        data1 = player.getWorld().getBlockAt(loc1).getData();
        data2 = player.getWorld().getBlockAt(loc2).getData();
      }

      player.sendBlockChange(loc1, material1, data1);
      player.sendBlockChange(loc2, material2, data2);
    }

    for (t = 0; t < dif_z; t++) {
      z = zs + t;
      int highest1 = player.getWorld().getHighestBlockYAt(x1, z) - 1;
      int highest2 = player.getWorld().getHighestBlockYAt(x2, z) - 1;
      Location loc1 = player.getWorld().getBlockAt(x1, highest1, z).getLocation();
      Location loc2 = player.getWorld().getBlockAt(x2, highest2, z).getLocation();

      if (material == null) {
        material1 = player.getWorld().getBlockAt(loc1).getType();
        material2 = player.getWorld().getBlockAt(loc2).getType();

        data1 = player.getWorld().getBlockAt(loc1).getData();
        data2 = player.getWorld().getBlockAt(loc2).getData();
      }

      player.sendBlockChange(loc1, material1, data1);
      player.sendBlockChange(loc2, material2, data2);
    }
  }
Пример #15
0
 @SuppressWarnings("deprecation")
 public static void setCorner(Player player, Location location) {
   player.sendBlockChange(location, Material.EMERALD_BLOCK, (byte) 0);
 }
Пример #16
0
 @SuppressWarnings("deprecation")
 public static void resetCorner(Player player, Location location) {
   player.sendBlockChange(location, player.getWorld().getBlockAt(location).getType(), (byte) 0);
 }