<commit_before>#pylint: disable=F0401
import org.bukkit.event.block.BlockPlaceEvent as BlockPlaceEvent
from helpers import *

tilehelpers = [
  {"owner": "ae795aa8-6327-408e-92ab-25c8a59f3ba1", "area": [[90, 90], [70, 70], [90, 90]], "world": "b0385345-4803-4522-a06a-75fbd692928d", "directions": "n"}
]
dirmap = {
  #    [x, y, z]
  "n": [0, 0, -1],
  "e": [+1, 0, 0],
  "s": [0, 0, +1],
  "w": [-1, 0, 0],
  "u": [0, +1, 0],
  "d": [0, -1, 0]
}

# FIXME: disallow multiple regions by single person.
# FIXME: could lead to two regions updating each other forever -> server freezes

lastevent = None

@hook.event("block.BlockPlaceEvent", "monitor")
def onBlockPlaceDebug(event):
  global lastevent
  lastevent = event
  msg(event.getPlayer(), event.getBlockPlaced(), basecolor = "a")
  msg(event.getPlayer(), event.getBlockReplacedState().getBlock(), basecolor = "a")

@hook.event("block.BlockPlaceEvent", "high")
def onPlaceBlockInRegion(event):
  if not event.isCancelled():
    player = event.getPlayer()
    block  = event.getBlockPlaced()
    for th in tilehelpers:
      area = th.get("area")
      if th.get("owner") == str(player.getUniqueId()) and str(block.getWorld().getUID()) == th.get("world") and block.getX() in range(area[0][0], area[0][1]+1) and block.getY() in range(area[1][0], area[1][1]+1) and block.getZ() in range(area[2][0], area[2][1]+1) and event.canBuild():

        # stack block in directions
        msg(player, "&aplaced block in region")

        for direction in th.get("directions"):
          directions = dirmap[direction]
          size       = [
            1 + abs(area[0][1] - area[0][0]),
            1 + abs(area[1][1] - area[1][0]),
            1 + abs(area[2][1] - area[2][0])
          ]
          against = event.getBlockAgainst()

          newblock = block.getWorld().getBlockAt(
            block.getX() + size[0] * directions[0],
            block.getY() + size[1] * directions[1],
            block.getZ() + size[2] * directions[2]
          )

          newagainst = against.getWorld().getBlockAt(
            against.getX() + size[0] * directions[0],
            against.getY() + size[1] * directions[1],
            against.getZ() + size[2] * directions[2]
          )
          newstate = newblock.getState()
          newstate.setType(block.getType())

          event = BlockPlaceEvent(newstate.getBlock(), newblock.getState(), newagainst, event.getItemInHand(), player, event.canBuild())
          server.getPluginManager().callEvent(event)
          msg(player, "Direction %s: %s" % (direction, not event.isCancelled()))
          msg(player, "Position before: %s -- after: %s" % ([block.getX(), block.getY(), block.getZ()], [newstate.getX(), newstate.getY(), newstate.getZ()]))
          if not event.isCancelled():
            newblock.setType(block.getType())<commit_msg>added BlockBrakeEvent<commit_after>#pylint: disable=F0401
import org.bukkit.event.block.BlockPlaceEvent as BlockPlaceEvent
import org.bukkit.event.block.BlockBrakeEvent as BlockBrakeEvent
from helpers import *

tilehelpers = [
  {"owner": "ae795aa8-6327-408e-92ab-25c8a59f3ba1", "area": [[90, 95], [70, 72], [90, 95]], "world": "b0385345-4803-4522-a06a-75fbd692928d", "directions": "neswud"}
]
dirmap = {
  #    [x, y, z]
  "n": [0, 0, -1],
  "e": [+1, 0, 0],
  "s": [0, 0, +1],
  "w": [-1, 0, 0],
  "u": [0, +1, 0],
  "d": [0, -1, 0]
}

# FIXME: disallow multiple regions by single person.
# FIXME: could lead to two regions updating each other forever -> server freezes

@hook.event("block.BlockPlaceEvent", "low")
def onPlaceBlockInRegion(event):
  if not event.isCancelled():
    player = event.getPlayer()
    block  = event.getBlockPlaced()
    for th in tilehelpers:
      area = th.get("area")
      if th.get("owner") == str(player.getUniqueId()) and str(block.getWorld().getUID()) == th.get("world") and block.getX() in range(area[0][0], area[0][1]+1) and block.getY() in range(area[1][0], area[1][1]+1) and block.getZ() in range(area[2][0], area[2][1]+1) and event.canBuild():

        # stack block in directions
        msg(player, "&aplaced block in region")

        for direction in th.get("directions"):
          directions = dirmap[direction]
          size       = [
            1 + abs(area[0][1] - area[0][0]),
            1 + abs(area[1][1] - area[1][0]),
            1 + abs(area[2][1] - area[2][0])
          ]
          against = event.getBlockAgainst()

          newblock = block.getWorld().getBlockAt(
            block.getX() + size[0] * directions[0],
            block.getY() + size[1] * directions[1],
            block.getZ() + size[2] * directions[2]
          )

          newagainst = against.getWorld().getBlockAt(
            against.getX() + size[0] * directions[0],
            against.getY() + size[1] * directions[1],
            against.getZ() + size[2] * directions[2]
          )
          newstate = newblock.getState()
          newstate.setType(block.getType())

          event = BlockPlaceEvent(newstate.getBlock(), newblock.getState(), newagainst, event.getItemInHand(), player, event.canBuild())
          server.getPluginManager().callEvent(event)
          if not event.isCancelled():
            newblock.setType(block.getType())


@hook.event("block.BlockBrakeEvent", "low")
def onPlaceBlockInRegion(event):
  if not event.isCancelled():
    player = event.getPlayer()
    block  = event.getBlockPlaced()
    for th in tilehelpers:
      area = th.get("area")
      if th.get("owner") == str(player.getUniqueId()) and str(block.getWorld().getUID()) == th.get("world") and block.getX() in range(area[0][0], area[0][1]+1) and block.getY() in range(area[1][0], area[1][1]+1) and block.getZ() in range(area[2][0], area[2][1]+1) and event.canBuild():

        # stack block in directions
        msg(player, "&abroke block in region")

        for direction in th.get("directions"):
          directions = dirmap[direction]
          size       = [
            1 + abs(area[0][1] - area[0][0]),
            1 + abs(area[1][1] - area[1][0]),
            1 + abs(area[2][1] - area[2][0])
          ]

          newblock = block.getWorld().getBlockAt(
            block.getX() + size[0] * directions[0],
            block.getY() + size[1] * directions[1],
            block.getZ() + size[2] * directions[2]
          )

          event = BlockBrakeEvent(newblock, player)
          server.getPluginManager().callEvent(event)
          if not event.isCancelled():
            newblock.setTypeId(0)
{'fraction_non_alphanumeric': 0.17721518987341772, 'fraction_numerical': 0.04306884841000309, 'mean_word_length': 2.838270142180095, 'pattern_counts': {'":': 20, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2702836', 'n_tokens_mistral': 2311, 'n_tokens_neox': 2230, 'n_words': 473}