Beispiel #1
0
  @Override
  public void onRightClick(PlayerInteractEvent event) {

    LocalPlayer player = CraftBookPlugin.inst().wrapPlayer(event.getPlayer());

    if (!event.getAction().equals(Action.RIGHT_CLICK_BLOCK)) return;

    Block block = event.getClickedBlock().getRelative(event.getBlockFace());
    if (event.getPlayer().getItemInHand().getTypeId()
        == CraftBookPlugin.inst().getConfiguration().lightstoneItem) {
      String lightLevelLine = getLightLine(block.getLightLevel());
      player.print(
          ChatColor.YELLOW
              + "LightStone: ["
              + lightLevelLine
              + ChatColor.YELLOW
              + "] "
              + block.getLightLevel()
              + " L");
    }
  }
  @EventHandler(priority = EventPriority.LOW)
  public void onBlockPlace(BlockPlaceEvent event) {
    Player player = event.getPlayer();
    if (Expra.disabledPlayers.contains(player.getName())) return;
    World world = player.getWorld();
    if (Expra.disabledWorlds.contains(world.getName())) return;
    Block block = event.getBlockPlaced();
    if (Expra.defaultLightingAmount > 0 && Nekoyoubi.hasPermission(player, "expra.award.explore")) {
      byte newLight = block.getLightLevel();
      byte oldLight = event.getBlockReplacedState().getLightLevel();
      if (newLight > oldLight) {
        float diff = ((float) oldLight / (float) newLight);
        if (diff < .5f) {
          boolean award = true;
          if (Expra.playerLit.containsKey(player.getName() + ":" + player.getWorld().getName())) {
            Location lastLit =
                Expra.playerLit.get(player.getName() + ":" + player.getWorld().getName());
            if (lastLit.distance(block.getLocation()) < 5) award = false;
          }
          Expra.playerLit.put(
              player.getName() + ":" + player.getWorld().getName(), block.getLocation());
          if (award) processAward(player, Expra.defaultLightingRatio, Expra.defaultLightingAmount);
        }
      }
    }
    if (!Nekoyoubi.hasPermission(player, "expra.award.place")) return;

    Integer amount = Expra.defaultBlockPlaceAmount;
    Integer ratio = Expra.defaultBlockPlaceRatio;
    String[] keys =
        new String[] {
          String.valueOf(block.getTypeId()) + ":" + String.valueOf(block.getData()),
          String.valueOf(block.getTypeId())
        };
    if (Expra.overridePlace.containsKey(keys[0])) {
      amount = Integer.parseInt(Expra.overridePlace.get(keys[0]).split("@")[0]);
      ratio = Integer.parseInt(Expra.overridePlace.get(keys[0]).split("@")[1]);
    } else if (Expra.overridePlace.containsKey(keys[1])) {
      amount = Integer.parseInt(Expra.overridePlace.get(keys[1]).split("@")[0]);
      ratio = Integer.parseInt(Expra.overridePlace.get(keys[1]).split("@")[1]);
    }
    processAward(player, ratio, amount);
  }
  public byte getLight() {
    Block blk = spawner.getBlock();
    Location loc = spawner.getLoc();
    byte highest = 0;
    int x = blk.getX();
    int y = blk.getY();
    int z = blk.getZ();
    Block north = loc.getWorld().getBlockAt(x, y, z - 1);
    Block south = loc.getWorld().getBlockAt(x, y, z + 1);
    Block east = loc.getWorld().getBlockAt(x + 1, y, z);
    Block west = loc.getWorld().getBlockAt(x - 1, y, z);
    Block up = loc.getWorld().getBlockAt(x, y + 1, z);
    Block down = loc.getWorld().getBlockAt(x, y - 1, z);
    Block[] blocks = {north, south, east, west, up, down};
    for (Block b : blocks) {
      byte level = b.getLightLevel();
      if (level > highest) {
        highest = level;
      }
    }

    return highest;
  }