Ejemplo n.º 1
0
 public ConfigManager() {
   this.plugin = JukeAlert.getInstance();
   this.config = plugin.getConfig();
   this.cleanConfig = new YamlConfiguration();
   this.main = new File(plugin.getDataFolder() + File.separator + "config.yml");
   this.load();
 }
Ejemplo n.º 2
0
 @EventHandler(priority = EventPriority.HIGHEST)
 public void onInventoryOpenEvent(InventoryOpenEvent e) {
   Player player = (Player) e.getPlayer();
   if (e.isCancelled()) {
     return;
   }
   if (vanishNoPacket.isPlayerInvisible(player)) {
     return;
   }
   Block block;
   if (e.getInventory().getHolder() instanceof Chest) {
     Chest chest = (Chest) e.getInventory().getHolder();
     block = chest.getBlock();
   } else if (e.getInventory().getHolder() instanceof DoubleChest) {
     DoubleChest chest = (DoubleChest) e.getInventory().getHolder();
     block = chest.getLocation().getBlock();
   } else {
     return;
   }
   Set<Snitch> snitches = snitchManager.findSnitches(player.getWorld(), player.getLocation());
   for (Snitch snitch : snitches) {
     if (!isOnSnitch(snitch, player.getName()) || isDebugging()) {
       if (checkProximity(snitch, player.getName())) {
         plugin.getJaLogger().logUsed(snitch, player, block);
       }
     }
   }
 }
Ejemplo n.º 3
0
  @EventHandler(priority = EventPriority.HIGH)
  public void enterSnitchProximity(PlayerMoveEvent event) {
    Location from = event.getFrom();
    Location to = event.getTo();

    if (from.getBlockX() == to.getBlockX()
        && from.getBlockY() == to.getBlockY()
        && from.getBlockZ() == to.getBlockZ()
        && from.getWorld().equals(to.getWorld())) {
      // Player didn't move by at least one block.
      return;
    }
    Player player = event.getPlayer();
    if (vanishNoPacket.isPlayerInvisible(player)) {
      return;
    }
    String playerName = player.getName();
    Location location = player.getLocation();
    World world = location.getWorld();
    Set<Snitch> inList = playersInSnitches.get(playerName);
    if (inList == null) {
      inList = new TreeSet<Snitch>();
      playersInSnitches.put(player.getName(), inList);
    }
    Set<Snitch> snitches = snitchManager.findSnitches(world, location);
    for (Snitch snitch : snitches) {
      if (!isOnSnitch(snitch, playerName) && doesSnitchExist(snitch, true) || isDebugging()) {
        if (!inList.contains(snitch)) {
          inList.add(snitch);
          for (Player remoteplayer : playerManager.getPlayers()) {
            String remoteName = remoteplayer.getName();
            if (isOnSnitch(snitch, remoteName)) {
              remoteplayer.sendMessage(
                  ChatColor.AQUA
                      + " * "
                      + playerName
                      + " entered snitch at "
                      + snitch.getName()
                      + " ["
                      + snitch.getX()
                      + " "
                      + snitch.getY()
                      + " "
                      + snitch.getZ()
                      + "]");
            }
          }
          plugin.getJaLogger().logSnitchEntry(snitch, location, player);
        }
      }
    }
    Set<Snitch> rmList = new TreeSet<Snitch>();
    for (Snitch snitch : inList) {
      if (snitches.contains(snitch)) {
        continue;
      }
      rmList.add(snitch);
    }
    inList.removeAll(rmList);
  }
Ejemplo n.º 4
0
 @EventHandler(priority = EventPriority.HIGH)
 public void onBlockIgniteEvent(BlockIgniteEvent event) {
   if (event.isCancelled()) {
     return;
   }
   if (event.getPlayer() == null) {
     return;
   }
   Player player = event.getPlayer();
   if (vanishNoPacket.isPlayerInvisible(player)) {
     return;
   }
   Block block = event.getBlock();
   Set<Snitch> snitches = snitchManager.findSnitches(block.getWorld(), block.getLocation());
   for (Snitch snitch : snitches) {
     if (!snitch.shouldLog()) {
       continue;
     }
     if (!isOnSnitch(snitch, player.getName()) || isDebugging()) {
       if (checkProximity(snitch, player.getName())) {
         plugin.getJaLogger().logSnitchIgnite(snitch, player, block);
       }
     }
   }
 }
Ejemplo n.º 5
0
 public static boolean doesSnitchExist(Snitch snitch, boolean shouldCleanup) {
   Location loc = snitch.getLoc();
   World world = loc.getWorld();
   int x = loc.getBlockX();
   int y = loc.getBlockY();
   int z = loc.getBlockZ();
   int type_id = world.getBlockAt(x, y, z).getType().getId();
   boolean exists = (type_id == 84 || type_id == 25);
   if (!exists && shouldCleanup) {
     System.out.println(
         "Removing ghost snitch '" + snitch.getName() + "' at x:" + x + " y:" + y + " z:" + z);
     JukeAlert.getInstance().getSnitchManager().removeSnitch(snitch);
     JukeAlert.getInstance().getJaLogger().logSnitchBreak(world.getName(), x, y, z);
   }
   return exists;
 }
Ejemplo n.º 6
0
 @EventHandler(priority = EventPriority.HIGH)
 public void playerKillEntity(EntityDeathEvent event) {
   LivingEntity entity = event.getEntity();
   LivingEntity killer = entity.getKiller();
   // TODO: This should never be true, bug?
   if (entity instanceof Player) {
     return;
   }
   if (!(killer instanceof Player)) {
     return;
   }
   if (vanishNoPacket.isPlayerInvisible((Player) killer)) {
     return;
   }
   Player player = (Player) killer;
   Set<Snitch> snitches = snitchManager.findSnitches(player.getWorld(), player.getLocation());
   for (Snitch snitch : snitches) {
     if (!snitch.shouldLog()) {
       continue;
     }
     if (!isOnSnitch(snitch, player.getName()) || isDebugging()) {
       if (checkProximity(snitch, player.getName())) {
         plugin.getJaLogger().logSnitchEntityKill(snitch, player, entity);
       }
     }
   }
 }
Ejemplo n.º 7
0
  @Override
  public boolean execute(CommandSender sender, String[] args) {
    if (sender instanceof Player) {
      Player player = (Player) sender;
      World world = player.getWorld();

      int offset = 1;
      if (args.length > 0) {
        offset = Integer.parseInt(args[0]);
      }
      if (offset < 1) {
        offset = 1;
      }

      List<Snitch> snitches = plugin.getSnitchManager().getSnitchesByWorld(world);
      for (Snitch snitch : snitches) {
        // Get only first snitch in cuboid
        if (JukeAlert.isOnSnitch(snitch, player.getName())) {
          if (snitch.isWithinCuboid(player.getLocation())) {
            sendLog(sender, snitch, offset);
            break;
          }
        }
      }

    } else {
      sender.sendMessage(ChatColor.RED + "You do not own any snitches nearby!");
      return false;
    }
    return false;
  }
Ejemplo n.º 8
0
 @EventHandler(priority = EventPriority.HIGH)
 public void onBlockBurnEvent(BlockBurnEvent event) {
   if (event.isCancelled()) {
     return;
   }
   Block block = event.getBlock();
   Set<Snitch> snitches = snitchManager.findSnitches(block.getWorld(), block.getLocation());
   for (Snitch snitch : snitches) {
     if (snitch.getGroup() != null) {
       continue;
     }
     plugin.getJaLogger().logSnitchBlockBurn(snitch, block);
   }
 }
Ejemplo n.º 9
0
 public static Snitch getSnitchUnderCursor(Player player) {
   SnitchManager manager = JukeAlert.getInstance().getSnitchManager();
   List<Block> lastTwo = player.getLastTwoTargetBlocks(null, 64);
   for (Block block : lastTwo) {
     Material mat = block.getType();
     if (mat != Material.JUKEBOX) {
       continue;
     }
     Snitch found = manager.getSnitch(block.getWorld(), block.getLocation());
     if (found != null) {
       return found;
     }
   }
   return null;
 }
Ejemplo n.º 10
0
 @EventHandler(priority = EventPriority.HIGH)
 public void playerFillBucket(PlayerBucketFillEvent event) {
   if (event.isCancelled()) {
     return;
   }
   Player player = event.getPlayer();
   if (vanishNoPacket.isPlayerInvisible(player)) {
     return;
   }
   Block block = event.getBlockClicked();
   Set<Snitch> snitches = snitchManager.findSnitches(block.getWorld(), block.getLocation());
   for (Snitch snitch : snitches) {
     if (!isOnSnitch(snitch, player.getName()) || isDebugging()) {
       if (checkProximity(snitch, player.getName())) {
         plugin.getJaLogger().logSnitchBucketFill(snitch, player, block);
       }
     }
   }
 }
Ejemplo n.º 11
0
 @EventHandler(priority = EventPriority.HIGH)
 public void playerKillPlayer(PlayerDeathEvent event) {
   if (!(event.getEntity().getKiller() instanceof Player)) {
     return;
   }
   Player killed = event.getEntity();
   Player killer = killed.getKiller();
   if (vanishNoPacket.isPlayerInvisible(killer)) {
     return;
   }
   Set<Snitch> snitches = snitchManager.findSnitches(killed.getWorld(), killed.getLocation());
   for (Snitch snitch : snitches) {
     if (!isOnSnitch(snitch, killer.getName()) || isDebugging()) {
       if (checkProximity(snitch, killed.getName()) || checkProximity(snitch, killer.getName())) {
         plugin.getJaLogger().logSnitchPlayerKill(snitch, killer, killed);
       }
     }
   }
 }
Ejemplo n.º 12
0
 public static Snitch findClosestOwnedSnitch(Player player) {
   Snitch closestSnitch = null;
   double closestDistance = Double.MAX_VALUE;
   Location playerLoc = player.getLocation();
   Set<Snitch> snitches =
       JukeAlert.getInstance()
           .getSnitchManager()
           .findSnitches(player.getWorld(), player.getLocation());
   for (final Snitch snitch : snitches) {
     if (doesSnitchExist(snitch, true) && isOnSnitch(snitch, player.getName())) {
       double distance = snitch.getLoc().distanceSquared(playerLoc);
       if (distance < closestDistance) {
         closestDistance = distance;
         closestSnitch = snitch;
       }
     }
   }
   return closestSnitch;
 }
Ejemplo n.º 13
0
 @EventHandler(priority = EventPriority.HIGHEST)
 public void breakSnitchBlock(BlockBreakEvent event) {
   if (event.isCancelled()) {
     return;
   }
   Block block = event.getBlock();
   if (!block.getType().equals(Material.JUKEBOX)) {
     return;
   }
   if (vanishNoPacket.isPlayerInvisible(event.getPlayer())) {
     return;
   }
   Location loc = block.getLocation();
   if (snitchManager.getSnitch(loc.getWorld(), loc) != null) {
     snitchManager.removeSnitch(snitchManager.getSnitch(loc.getWorld(), loc));
     plugin
         .getJaLogger()
         .logSnitchBreak(
             loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
   }
 }
Ejemplo n.º 14
0
 @EventHandler(ignoreCancelled = true)
 public void onGroupDeletion(GroupChangeEvent event) {
   if (event.getType() != GroupChangeType.DELETE) {
     return;
   }
   String groupName = event.getFactionName();
   Set<Snitch> removeSet = new TreeSet<Snitch>();
   for (Snitch snitch : snitchManager.getAllSnitches()) {
     if (snitch.getGroup().getName().equalsIgnoreCase(groupName)) {
       removeSet.add(snitch);
     }
   }
   for (Snitch snitch : removeSet) {
     Location loc = snitch.getLoc();
     plugin
         .getJaLogger()
         .logSnitchBreak(
             loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
     snitchManager.removeSnitch(snitch);
   }
 }
Ejemplo n.º 15
0
  @EventHandler(priority = EventPriority.HIGHEST)
  public void playerJoinEvent(PlayerJoinEvent event) {
    Player player = event.getPlayer();
    if (vanishNoPacket.isPlayerInvisible(player)) {
      return;
    }
    String playerName = player.getName();
    Set<Snitch> inList = new TreeSet<Snitch>();
    playersInSnitches.put(player.getName(), inList);

    Location location = player.getLocation();
    World world = location.getWorld();
    Set<Snitch> snitches = snitchManager.findSnitches(world, location);
    for (Snitch snitch : snitches) {
      if (!isOnSnitch(snitch, playerName)) {
        inList.add(snitch);
        for (Player remoteplayer : playerManager.getPlayers()) {
          String remoteName = remoteplayer.getName();
          if (isOnSnitch(snitch, remoteName)) {
            remoteplayer.sendMessage(
                ChatColor.AQUA
                    + " * "
                    + playerName
                    + " logged in to snitch at "
                    + snitch.getName()
                    + " ["
                    + snitch.getX()
                    + " "
                    + snitch.getY()
                    + " "
                    + snitch.getZ()
                    + "]");
          }
        }
        plugin.getJaLogger().logSnitchLogin(snitch, location, player);
      }
    }
  }
Ejemplo n.º 16
0
  public void handlePlayerExit(PlayerEvent event) {
    Player player = event.getPlayer();
    if (vanishNoPacket.isPlayerInvisible(player)) {
      return;
    }
    String playerName = player.getName();
    playersInSnitches.remove(playerName);

    Location location = player.getLocation();
    World world = location.getWorld();
    Set<Snitch> snitches = snitchManager.findSnitches(world, location);
    for (Snitch snitch : snitches) {
      if (!isOnSnitch(snitch, playerName)) {
        for (Player remoteplayer : playerManager.getPlayers()) {
          if (snitch.getGroup().isMember(remoteplayer.getName())
              || snitch.getGroup().isFounder(remoteplayer.getName())
              || snitch.getGroup().isModerator(remoteplayer.getName())) {
            remoteplayer.sendMessage(
                ChatColor.AQUA
                    + " * "
                    + playerName
                    + " logged out in snitch at "
                    + snitch.getName()
                    + " ["
                    + snitch.getX()
                    + " "
                    + snitch.getY()
                    + " "
                    + snitch.getZ()
                    + "]");
          }
        }
        plugin.getJaLogger().logSnitchLogout(snitch, location, player);
      }
    }
  }
Ejemplo n.º 17
0
  @EventHandler(priority = EventPriority.HIGHEST)
  public void reinforceSnitchBlock(CreateReinforcementEvent event) {
    if (event.isCancelled()) {
      return;
    }
    Block block = event.getBlock();
    if (block.getType().equals(Material.JUKEBOX)) {

      Player player = event.getPlayer();
      Location loc = block.getLocation();
      AccessDelegate access = AccessDelegate.getDelegate(block);
      IReinforcement rei = event.getReinforcement();
      if (rei instanceof PlayerReinforcement) {
        PlayerReinforcement reinforcement = (PlayerReinforcement) rei;
        Faction owner = reinforcement.getOwner();
        if (reinforcement.getSecurityLevel().equals(SecurityLevel.GROUP)) {
          Snitch snitch;
          if (snitchManager.getSnitch(loc.getWorld(), loc) != null) {
            snitch = snitchManager.getSnitch(loc.getWorld(), loc);
            plugin
                .getJaLogger()
                .updateSnitchGroup(snitchManager.getSnitch(loc.getWorld(), loc), owner.getName());
            snitchManager.removeSnitch(snitch);
            snitch.setGroup(owner);
          } else {
            snitch = new Snitch(loc, owner, true);
            plugin
                .getJaLogger()
                .logSnitchPlace(
                    player.getWorld().getName(),
                    owner.getName(),
                    "",
                    loc.getBlockX(),
                    loc.getBlockY(),
                    loc.getBlockZ(),
                    true);
            snitch.setId(plugin.getJaLogger().getLastSnitchID());
            plugin.getJaLogger().increaseLastSnitchID();
          }
          snitchManager.addSnitch(snitch);

          player.sendMessage(
              ChatColor.AQUA
                  + "You've created a snitch block registered to the group "
                  + owner.getName()
                  + ".  To name your snitch, type /janame.");
        } else {
          Snitch snitch;
          if (snitchManager.getSnitch(loc.getWorld(), loc) != null) {
            snitch = snitchManager.getSnitch(loc.getWorld(), loc);
            plugin
                .getJaLogger()
                .updateSnitchGroup(
                    snitchManager.getSnitch(loc.getWorld(), loc), owner.getFounder());
            snitchManager.removeSnitch(snitch);
            snitch.setGroup(owner);
          } else {
            snitch = new Snitch(loc, owner, true);
            plugin
                .getJaLogger()
                .logSnitchPlace(
                    player.getWorld().getName(),
                    owner.getFounder(),
                    "",
                    loc.getBlockX(),
                    loc.getBlockY(),
                    loc.getBlockZ(),
                    true);
            snitch.setId(plugin.getJaLogger().getLastSnitchID());
            plugin.getJaLogger().increaseLastSnitchID();
          }
          snitchManager.addSnitch(snitch);

          player.sendMessage(
              ChatColor.AQUA
                  + "You've created a private snitch block; reinforce it with a group to register members.  To name your snitch, type /janame.");
        }
      }
    } else if (block.getType().equals(Material.NOTE_BLOCK)) {
      Player player = event.getPlayer();
      Location loc = block.getLocation();
      AccessDelegate access = AccessDelegate.getDelegate(block);
      IReinforcement rei = event.getReinforcement();
      if (rei instanceof PlayerReinforcement) {
        PlayerReinforcement reinforcement = (PlayerReinforcement) rei;
        Faction owner = reinforcement.getOwner();
        if (reinforcement.getSecurityLevel().equals(SecurityLevel.GROUP)) {
          Snitch snitch;
          if (snitchManager.getSnitch(loc.getWorld(), loc) != null) {
            snitch = snitchManager.getSnitch(loc.getWorld(), loc);
            plugin
                .getJaLogger()
                .updateSnitchGroup(snitchManager.getSnitch(loc.getWorld(), loc), owner.getName());
            snitchManager.removeSnitch(snitch);
            snitch.setGroup(owner);
          } else {
            snitch = new Snitch(loc, owner, false);
            plugin
                .getJaLogger()
                .logSnitchPlace(
                    player.getWorld().getName(),
                    owner.getName(),
                    "",
                    loc.getBlockX(),
                    loc.getBlockY(),
                    loc.getBlockZ(),
                    false);
            snitch.setId(plugin.getJaLogger().getLastSnitchID());
            plugin.getJaLogger().increaseLastSnitchID();
          }
          snitchManager.addSnitch(snitch);

          player.sendMessage(
              ChatColor.AQUA
                  + "You've created an entry snitch registered to the group "
                  + owner.getName()
                  + ".  To name your entry snitch, type /janame.");
        } else {
          Snitch snitch;
          if (snitchManager.getSnitch(loc.getWorld(), loc) != null) {
            snitch = snitchManager.getSnitch(loc.getWorld(), loc);
            plugin
                .getJaLogger()
                .updateSnitchGroup(
                    snitchManager.getSnitch(loc.getWorld(), loc), owner.getFounder());
            snitchManager.removeSnitch(snitch);
            snitch.setGroup(owner);
          } else {
            snitch = new Snitch(loc, owner, false);
            plugin
                .getJaLogger()
                .logSnitchPlace(
                    player.getWorld().getName(),
                    owner.getFounder(),
                    "",
                    loc.getBlockX(),
                    loc.getBlockY(),
                    loc.getBlockZ(),
                    false);
            snitch.setId(plugin.getJaLogger().getLastSnitchID());
            plugin.getJaLogger().increaseLastSnitchID();
          }
          snitchManager.addSnitch(snitch);

          player.sendMessage(
              ChatColor.AQUA
                  + "You've created a private entry snitch; reinforce it with a group to register members.  To name your entry snitch, type /janame.");
        }
      }
    }
  }
Ejemplo n.º 18
0
public class JukeAlertListener implements Listener {

  private final JukeAlert plugin = JukeAlert.getInstance();
  SnitchManager snitchManager = plugin.getSnitchManager();
  PlayerManager playerManager = plugin.getPlayerManager();
  private final Map<String, Set<Snitch>> playersInSnitches = new TreeMap<String, Set<Snitch>>();
  private final ArrayList<Location> previousLocations = new ArrayList<Location>();
  private final VanishNoPacket vanishNoPacket = new VanishNoPacket();

  private boolean checkProximity(Snitch snitch, String playerName) {
    Set<Snitch> inList = playersInSnitches.get(playerName);
    if (inList == null) {
      inList = new TreeSet<Snitch>();
      playersInSnitches.put(playerName, inList);
    }
    return inList.contains(snitch);
  }

  @EventHandler(priority = EventPriority.HIGHEST)
  public void playerJoinEvent(PlayerJoinEvent event) {
    Player player = event.getPlayer();
    if (vanishNoPacket.isPlayerInvisible(player)) {
      return;
    }
    String playerName = player.getName();
    Set<Snitch> inList = new TreeSet<Snitch>();
    playersInSnitches.put(player.getName(), inList);

    Location location = player.getLocation();
    World world = location.getWorld();
    Set<Snitch> snitches = snitchManager.findSnitches(world, location);
    for (Snitch snitch : snitches) {
      if (!isOnSnitch(snitch, playerName)) {
        inList.add(snitch);
        for (Player remoteplayer : playerManager.getPlayers()) {
          String remoteName = remoteplayer.getName();
          if (isOnSnitch(snitch, remoteName)) {
            remoteplayer.sendMessage(
                ChatColor.AQUA
                    + " * "
                    + playerName
                    + " logged in to snitch at "
                    + snitch.getName()
                    + " ["
                    + snitch.getX()
                    + " "
                    + snitch.getY()
                    + " "
                    + snitch.getZ()
                    + "]");
          }
        }
        plugin.getJaLogger().logSnitchLogin(snitch, location, player);
      }
    }
  }

  public void handlePlayerExit(PlayerEvent event) {
    Player player = event.getPlayer();
    if (vanishNoPacket.isPlayerInvisible(player)) {
      return;
    }
    String playerName = player.getName();
    playersInSnitches.remove(playerName);

    Location location = player.getLocation();
    World world = location.getWorld();
    Set<Snitch> snitches = snitchManager.findSnitches(world, location);
    for (Snitch snitch : snitches) {
      if (!isOnSnitch(snitch, playerName)) {
        for (Player remoteplayer : playerManager.getPlayers()) {
          if (snitch.getGroup().isMember(remoteplayer.getName())
              || snitch.getGroup().isFounder(remoteplayer.getName())
              || snitch.getGroup().isModerator(remoteplayer.getName())) {
            remoteplayer.sendMessage(
                ChatColor.AQUA
                    + " * "
                    + playerName
                    + " logged out in snitch at "
                    + snitch.getName()
                    + " ["
                    + snitch.getX()
                    + " "
                    + snitch.getY()
                    + " "
                    + snitch.getZ()
                    + "]");
          }
        }
        plugin.getJaLogger().logSnitchLogout(snitch, location, player);
      }
    }
  }

  @EventHandler(ignoreCancelled = true)
  public void playerKickEvent(PlayerKickEvent event) {
    handlePlayerExit(event);
  }

  @EventHandler(ignoreCancelled = true)
  public void playerQuitEvent(PlayerQuitEvent event) {
    handlePlayerExit(event);
  }

  @EventHandler(priority = EventPriority.HIGHEST)
  public void placeSnitchBlock(BlockPlaceEvent event) {
    if (event.isCancelled()) {
      return;
    }
    Block block = event.getBlock();
    Player player = event.getPlayer();
    Location loc = block.getLocation();
    if (block.getType().equals(Material.JUKEBOX)) {
      if (!Utility.isReinforced(loc)) {
        player.sendMessage(
            ChatColor.YELLOW + "You've placed a jukebox; reinforce it to register it as a snitch.");
      }
    } else if (block.getType().equals(Material.NOTE_BLOCK)) {
      if (!Utility.isReinforced(loc)) {
        player.sendMessage(
            ChatColor.YELLOW
                + "You've placed a noteblock; reinforce it to register it as an entry snitch.");
      }
    }
  }

  @EventHandler(priority = EventPriority.HIGHEST)
  public void reinforceSnitchBlock(CreateReinforcementEvent event) {
    if (event.isCancelled()) {
      return;
    }
    Block block = event.getBlock();
    if (block.getType().equals(Material.JUKEBOX)) {

      Player player = event.getPlayer();
      Location loc = block.getLocation();
      AccessDelegate access = AccessDelegate.getDelegate(block);
      IReinforcement rei = event.getReinforcement();
      if (rei instanceof PlayerReinforcement) {
        PlayerReinforcement reinforcement = (PlayerReinforcement) rei;
        Faction owner = reinforcement.getOwner();
        if (reinforcement.getSecurityLevel().equals(SecurityLevel.GROUP)) {
          Snitch snitch;
          if (snitchManager.getSnitch(loc.getWorld(), loc) != null) {
            snitch = snitchManager.getSnitch(loc.getWorld(), loc);
            plugin
                .getJaLogger()
                .updateSnitchGroup(snitchManager.getSnitch(loc.getWorld(), loc), owner.getName());
            snitchManager.removeSnitch(snitch);
            snitch.setGroup(owner);
          } else {
            snitch = new Snitch(loc, owner, true);
            plugin
                .getJaLogger()
                .logSnitchPlace(
                    player.getWorld().getName(),
                    owner.getName(),
                    "",
                    loc.getBlockX(),
                    loc.getBlockY(),
                    loc.getBlockZ(),
                    true);
            snitch.setId(plugin.getJaLogger().getLastSnitchID());
            plugin.getJaLogger().increaseLastSnitchID();
          }
          snitchManager.addSnitch(snitch);

          player.sendMessage(
              ChatColor.AQUA
                  + "You've created a snitch block registered to the group "
                  + owner.getName()
                  + ".  To name your snitch, type /janame.");
        } else {
          Snitch snitch;
          if (snitchManager.getSnitch(loc.getWorld(), loc) != null) {
            snitch = snitchManager.getSnitch(loc.getWorld(), loc);
            plugin
                .getJaLogger()
                .updateSnitchGroup(
                    snitchManager.getSnitch(loc.getWorld(), loc), owner.getFounder());
            snitchManager.removeSnitch(snitch);
            snitch.setGroup(owner);
          } else {
            snitch = new Snitch(loc, owner, true);
            plugin
                .getJaLogger()
                .logSnitchPlace(
                    player.getWorld().getName(),
                    owner.getFounder(),
                    "",
                    loc.getBlockX(),
                    loc.getBlockY(),
                    loc.getBlockZ(),
                    true);
            snitch.setId(plugin.getJaLogger().getLastSnitchID());
            plugin.getJaLogger().increaseLastSnitchID();
          }
          snitchManager.addSnitch(snitch);

          player.sendMessage(
              ChatColor.AQUA
                  + "You've created a private snitch block; reinforce it with a group to register members.  To name your snitch, type /janame.");
        }
      }
    } else if (block.getType().equals(Material.NOTE_BLOCK)) {
      Player player = event.getPlayer();
      Location loc = block.getLocation();
      AccessDelegate access = AccessDelegate.getDelegate(block);
      IReinforcement rei = event.getReinforcement();
      if (rei instanceof PlayerReinforcement) {
        PlayerReinforcement reinforcement = (PlayerReinforcement) rei;
        Faction owner = reinforcement.getOwner();
        if (reinforcement.getSecurityLevel().equals(SecurityLevel.GROUP)) {
          Snitch snitch;
          if (snitchManager.getSnitch(loc.getWorld(), loc) != null) {
            snitch = snitchManager.getSnitch(loc.getWorld(), loc);
            plugin
                .getJaLogger()
                .updateSnitchGroup(snitchManager.getSnitch(loc.getWorld(), loc), owner.getName());
            snitchManager.removeSnitch(snitch);
            snitch.setGroup(owner);
          } else {
            snitch = new Snitch(loc, owner, false);
            plugin
                .getJaLogger()
                .logSnitchPlace(
                    player.getWorld().getName(),
                    owner.getName(),
                    "",
                    loc.getBlockX(),
                    loc.getBlockY(),
                    loc.getBlockZ(),
                    false);
            snitch.setId(plugin.getJaLogger().getLastSnitchID());
            plugin.getJaLogger().increaseLastSnitchID();
          }
          snitchManager.addSnitch(snitch);

          player.sendMessage(
              ChatColor.AQUA
                  + "You've created an entry snitch registered to the group "
                  + owner.getName()
                  + ".  To name your entry snitch, type /janame.");
        } else {
          Snitch snitch;
          if (snitchManager.getSnitch(loc.getWorld(), loc) != null) {
            snitch = snitchManager.getSnitch(loc.getWorld(), loc);
            plugin
                .getJaLogger()
                .updateSnitchGroup(
                    snitchManager.getSnitch(loc.getWorld(), loc), owner.getFounder());
            snitchManager.removeSnitch(snitch);
            snitch.setGroup(owner);
          } else {
            snitch = new Snitch(loc, owner, false);
            plugin
                .getJaLogger()
                .logSnitchPlace(
                    player.getWorld().getName(),
                    owner.getFounder(),
                    "",
                    loc.getBlockX(),
                    loc.getBlockY(),
                    loc.getBlockZ(),
                    false);
            snitch.setId(plugin.getJaLogger().getLastSnitchID());
            plugin.getJaLogger().increaseLastSnitchID();
          }
          snitchManager.addSnitch(snitch);

          player.sendMessage(
              ChatColor.AQUA
                  + "You've created a private entry snitch; reinforce it with a group to register members.  To name your entry snitch, type /janame.");
        }
      }
    }
  }

  @EventHandler(ignoreCancelled = true)
  public void onGroupDeletion(GroupChangeEvent event) {
    if (event.getType() != GroupChangeType.DELETE) {
      return;
    }
    String groupName = event.getFactionName();
    Set<Snitch> removeSet = new TreeSet<Snitch>();
    for (Snitch snitch : snitchManager.getAllSnitches()) {
      if (snitch.getGroup().getName().equalsIgnoreCase(groupName)) {
        removeSet.add(snitch);
      }
    }
    for (Snitch snitch : removeSet) {
      Location loc = snitch.getLoc();
      plugin
          .getJaLogger()
          .logSnitchBreak(
              loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
      snitchManager.removeSnitch(snitch);
    }
  }

  @EventHandler(priority = EventPriority.HIGHEST)
  public void breakSnitchBlock(BlockBreakEvent event) {
    if (event.isCancelled()) {
      return;
    }
    Block block = event.getBlock();
    if (!block.getType().equals(Material.JUKEBOX)) {
      return;
    }
    if (vanishNoPacket.isPlayerInvisible(event.getPlayer())) {
      return;
    }
    Location loc = block.getLocation();
    if (snitchManager.getSnitch(loc.getWorld(), loc) != null) {
      snitchManager.removeSnitch(snitchManager.getSnitch(loc.getWorld(), loc));
      plugin
          .getJaLogger()
          .logSnitchBreak(
              loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
    }
  }

  @EventHandler(priority = EventPriority.HIGH)
  public void enterSnitchProximity(PlayerMoveEvent event) {
    Location from = event.getFrom();
    Location to = event.getTo();

    if (from.getBlockX() == to.getBlockX()
        && from.getBlockY() == to.getBlockY()
        && from.getBlockZ() == to.getBlockZ()
        && from.getWorld().equals(to.getWorld())) {
      // Player didn't move by at least one block.
      return;
    }
    Player player = event.getPlayer();
    if (vanishNoPacket.isPlayerInvisible(player)) {
      return;
    }
    String playerName = player.getName();
    Location location = player.getLocation();
    World world = location.getWorld();
    Set<Snitch> inList = playersInSnitches.get(playerName);
    if (inList == null) {
      inList = new TreeSet<Snitch>();
      playersInSnitches.put(player.getName(), inList);
    }
    Set<Snitch> snitches = snitchManager.findSnitches(world, location);
    for (Snitch snitch : snitches) {
      if (doesSnitchExist(snitch, true) && (!isOnSnitch(snitch, playerName) || isDebugging())) {
        if (!inList.contains(snitch)) {
          inList.add(snitch);
          for (Player remoteplayer : playerManager.getPlayers()) {
            String remoteName = remoteplayer.getName();
            if (isOnSnitch(snitch, remoteName)) {
              remoteplayer.sendMessage(
                  ChatColor.AQUA
                      + " * "
                      + playerName
                      + " entered snitch at "
                      + snitch.getName()
                      + " ["
                      + snitch.getX()
                      + " "
                      + snitch.getY()
                      + " "
                      + snitch.getZ()
                      + "]");
            }
          }
          if (snitch.shouldLog()) {
            plugin.getJaLogger().logSnitchEntry(snitch, location, player);
          }
        }
      }
    }
    snitches = snitchManager.findSnitches(world, location, true);
    Set<Snitch> rmList = new TreeSet<Snitch>();
    for (Snitch snitch : inList) {
      if (snitches.contains(snitch)) {
        continue;
      }
      rmList.add(snitch);
    }
    inList.removeAll(rmList);
  }

  @EventHandler(priority = EventPriority.HIGHEST)
  public void onInventoryOpenEvent(InventoryOpenEvent e) {
    Player player = (Player) e.getPlayer();
    if (e.isCancelled()) {
      return;
    }
    if (vanishNoPacket.isPlayerInvisible(player)) {
      return;
    }
    Block block;
    if (e.getInventory().getHolder() instanceof Chest) {
      Chest chest = (Chest) e.getInventory().getHolder();
      block = chest.getBlock();
    } else if (e.getInventory().getHolder() instanceof DoubleChest) {
      DoubleChest chest = (DoubleChest) e.getInventory().getHolder();
      block = chest.getLocation().getBlock();
    } else {
      return;
    }
    Set<Snitch> snitches = snitchManager.findSnitches(player.getWorld(), player.getLocation());
    for (Snitch snitch : snitches) {
      if (!isOnSnitch(snitch, player.getName()) || isDebugging()) {
        if (checkProximity(snitch, player.getName())) {
          plugin.getJaLogger().logUsed(snitch, player, block);
        }
      }
    }
  }

  @EventHandler(priority = EventPriority.HIGH)
  public void playerKillEntity(EntityDeathEvent event) {
    LivingEntity entity = event.getEntity();
    LivingEntity killer = entity.getKiller();
    // TODO: This should never be true, bug?
    if (entity instanceof Player) {
      return;
    }
    if (!(killer instanceof Player)) {
      return;
    }
    if (vanishNoPacket.isPlayerInvisible((Player) killer)) {
      return;
    }
    Player player = (Player) killer;
    Set<Snitch> snitches = snitchManager.findSnitches(player.getWorld(), player.getLocation());
    for (Snitch snitch : snitches) {
      if (!snitch.shouldLog()) {
        continue;
      }
      if (!isOnSnitch(snitch, player.getName()) || isDebugging()) {
        if (checkProximity(snitch, player.getName())) {
          plugin.getJaLogger().logSnitchEntityKill(snitch, player, entity);
        }
      }
    }
  }

  @EventHandler(priority = EventPriority.HIGH)
  public void playerKillPlayer(PlayerDeathEvent event) {
    if (!(event.getEntity().getKiller() instanceof Player)) {
      return;
    }
    Player killed = event.getEntity();
    Player killer = killed.getKiller();
    if (vanishNoPacket.isPlayerInvisible(killer)) {
      return;
    }
    Set<Snitch> snitches = snitchManager.findSnitches(killed.getWorld(), killed.getLocation());
    for (Snitch snitch : snitches) {
      if (!snitch.shouldLog()) {
        continue;
      }
      if (!isOnSnitch(snitch, killer.getName()) || isDebugging()) {
        if (checkProximity(snitch, killed.getName()) || checkProximity(snitch, killer.getName())) {
          plugin.getJaLogger().logSnitchPlayerKill(snitch, killer, killed);
        }
      }
    }
  }

  @EventHandler(priority = EventPriority.HIGH)
  public void onBlockIgniteEvent(BlockIgniteEvent event) {
    if (event.isCancelled()) {
      return;
    }
    if (event.getPlayer() == null) {
      return;
    }
    Player player = event.getPlayer();
    if (vanishNoPacket.isPlayerInvisible(player)) {
      return;
    }
    Block block = event.getBlock();
    Set<Snitch> snitches = snitchManager.findSnitches(block.getWorld(), block.getLocation());
    for (Snitch snitch : snitches) {
      if (!snitch.shouldLog()) {
        continue;
      }
      if (!isOnSnitch(snitch, player.getName()) || isDebugging()) {
        if (checkProximity(snitch, player.getName())) {
          plugin.getJaLogger().logSnitchIgnite(snitch, player, block);
        }
      }
    }
  }

  @EventHandler(priority = EventPriority.HIGH)
  public void onBlockBurnEvent(BlockBurnEvent event) {
    if (event.isCancelled()) {
      return;
    }
    Block block = event.getBlock();
    Set<Snitch> snitches = snitchManager.findSnitches(block.getWorld(), block.getLocation());
    for (Snitch snitch : snitches) {
      if (!snitch.shouldLog()) {
        continue;
      }
      if (snitch.getGroup() != null) {
        continue;
      }
      plugin.getJaLogger().logSnitchBlockBurn(snitch, block);
    }
  }

  @EventHandler(priority = EventPriority.HIGH)
  public void playerBreakBlock(BlockBreakEvent event) {
    if (event.isCancelled()) {
      return;
    }
    Player player = event.getPlayer();
    if (vanishNoPacket.isPlayerInvisible(player)) {
      return;
    }
    Block block = event.getBlock();
    Set<Snitch> snitches = snitchManager.findSnitches(block.getWorld(), block.getLocation());
    for (Snitch snitch : snitches) {
      if (!snitch.shouldLog()) {
        continue;
      }
      if (!isOnSnitch(snitch, player.getName()) || isDebugging()) {
        if (checkProximity(snitch, player.getName())) {
          plugin.getJaLogger().logSnitchBlockBreak(snitch, player, block);
        }
      }
    }
  }

  @EventHandler(priority = EventPriority.HIGH)
  public void playerPlaceBlock(BlockPlaceEvent event) {
    if (event.isCancelled()) {
      return;
    }
    Player player = event.getPlayer();
    if (vanishNoPacket.isPlayerInvisible(player)) {
      return;
    }
    Block block = event.getBlock();
    Set<Snitch> snitches = snitchManager.findSnitches(block.getWorld(), block.getLocation());
    for (Snitch snitch : snitches) {
      if (!snitch.shouldLog()) {
        continue;
      }
      if (!isOnSnitch(snitch, player.getName()) || isDebugging()) {
        if (checkProximity(snitch, player.getName())) {
          plugin.getJaLogger().logSnitchBlockPlace(snitch, player, block);
        }
      }
    }
  }

  @EventHandler(priority = EventPriority.HIGH)
  public void playerFillBucket(PlayerBucketFillEvent event) {
    if (event.isCancelled()) {
      return;
    }
    Player player = event.getPlayer();
    if (vanishNoPacket.isPlayerInvisible(player)) {
      return;
    }
    Block block = event.getBlockClicked();
    Set<Snitch> snitches = snitchManager.findSnitches(block.getWorld(), block.getLocation());
    for (Snitch snitch : snitches) {
      if (!snitch.shouldLog()) {
        continue;
      }
      if (!isOnSnitch(snitch, player.getName()) || isDebugging()) {
        if (checkProximity(snitch, player.getName())) {
          plugin.getJaLogger().logSnitchBucketFill(snitch, player, block);
        }
      }
    }
  }

  @EventHandler(priority = EventPriority.HIGH)
  public void playerEmptyBucket(PlayerBucketEmptyEvent event) {
    if (event.isCancelled()) {
      return;
    }
    Player player = event.getPlayer();
    if (vanishNoPacket.isPlayerInvisible(player)) {
      return;
    }
    Block block = event.getBlockClicked();
    Set<Snitch> snitches = snitchManager.findSnitches(block.getWorld(), block.getLocation());
    for (Snitch snitch : snitches) {
      if (!snitch.shouldLog()) {
        continue;
      }
      if (!isOnSnitch(snitch, player.getName()) || isDebugging()) {
        if (checkProximity(snitch, player.getName())) {
          plugin
              .getJaLogger()
              .logSnitchBucketEmpty(snitch, player, block.getLocation(), player.getItemInHand());
        }
      }
    }
  }
}