<commit_before>package com.untamedears.JukeAlert.util;

import java.sql.SQLException;
import java.util.Iterator;
import java.util.Set;
import java.util.UUID;
import java.util.logging.Level;

import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.util.BlockIterator;

import vg.civcraft.mc.namelayer.GroupManager.PlayerType;
import vg.civcraft.mc.namelayer.NameAPI;
import vg.civcraft.mc.namelayer.group.Group;
import vg.civcraft.mc.namelayer.permission.GroupPermission;
import vg.civcraft.mc.namelayer.permission.PermissionType;

import com.untamedears.JukeAlert.JukeAlert;
import com.untamedears.JukeAlert.manager.SnitchManager;
import com.untamedears.JukeAlert.model.Snitch;

// Static methods only
public class Utility {
    private static boolean debugging_ = false;

    public static boolean isDebugging() {
        return debugging_;
    }

    public static void setDebugging(boolean debugging) {
        debugging_ = debugging;
    }
    
    public static void notifyGroup(Group g, String message) throws SQLException{
        if (g == null) return;
        final JukeAlert plugin = JukeAlert.getInstance();
        Set<String> skipUUID = plugin.getJaLogger().getIgnoreUUIDs(g.getName());
        if(skipUUID == null){
        	//this should be fine as it is how it used to be done
        	skipUUID = null;
        }
        OnlineGroupMembers iter = OnlineGroupMembers
            .get(g.getName())
            .skipList(skipUUID);
        for (Player player : iter) {
            RateLimiter.sendMessage(player, message);
        }
    }

    public static void notifyGroup(Snitch snitch, String message) throws SQLException {
        Group sG = snitch.getGroup();
        if (sG == null) return;
        final JukeAlert plugin = JukeAlert.getInstance();
        Set<String> skipUUID = plugin.getJaLogger().getIgnoreUUIDs(sG.getName());
        if(skipUUID == null){
        	//this should be fine as it is how it used to be done
        	skipUUID = null;
        }
        OnlineGroupMembers iter = OnlineGroupMembers
            .get(sG.getName())
            .reference(snitch.getLoc())
            .skipList(skipUUID);
        if (!snitch.shouldLog()) {
            iter.maxDistance(JukeAlert.getInstance().getConfigManager().getMaxAlertDistanceNs());
        }
        for (Player player : iter) {
            RateLimiter.sendMessage(player, message);
        }
    }

    public static boolean isOnSnitch(Snitch snitch, UUID accountId) {
        Group faction = snitch.getGroup();
        if (faction == null) return false;
        return faction.isMember(accountId);
    }
    
    private static long failureReportDelay = 10000l;
    private static long lastNotifyPOSFailure = System.currentTimeMillis() - failureReportDelay;
    
    public static boolean isPartialOwnerOfSnitch(Snitch snitch, UUID accountId) {
        Group faction = snitch.getGroup();
        if (faction == null) return false;
		if (faction.getOwner() == null) return false; // no owner at all?
        PlayerType type = faction.getPlayerType(accountId);
        GroupPermission perm = NameAPI.getGroupManager().getPermissionforGroup(faction);
        if (perm == null && System.currentTimeMillis() - lastNotifyPOSFailure > failureReportDelay) {
            JukeAlert.getInstance().getLogger().log(Level.WARNING, 
                    "isPartialOwnerOfSnitch unable to find permissions for group {0}", faction.getName());
            lastNotifyPOSFailure = System.currentTimeMillis();
        }
        return faction.isOwner(accountId) || (type != null && perm != null && perm.isAccessible(type, PermissionType.BLOCKS));
    }

    public static Snitch getSnitchUnderCursor(Player player) {
        SnitchManager manager = JukeAlert.getInstance().getSnitchManager();
        Iterator<Block> itr = new BlockIterator(player, 40); // Within 2.5 chunks
        while (itr.hasNext()) {
            final Block block = itr.next();
            final Material mat = block.getType();
            if (mat != Material.JUKEBOX) {
                continue;
            }
            final Snitch found = manager.getSnitch(block.getWorld(), block.getLocation());
            if (found != null) {
                return found;
            }
        }
        return null;<commit_msg>Adding logging to this particular null trap<commit_after>package com.untamedears.JukeAlert.util;

import java.sql.SQLException;
import java.util.Iterator;
import java.util.Set;
import java.util.UUID;
import java.util.logging.Level;

import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.util.BlockIterator;

import vg.civcraft.mc.namelayer.GroupManager.PlayerType;
import vg.civcraft.mc.namelayer.NameAPI;
import vg.civcraft.mc.namelayer.group.Group;
import vg.civcraft.mc.namelayer.permission.GroupPermission;
import vg.civcraft.mc.namelayer.permission.PermissionType;

import com.untamedears.JukeAlert.JukeAlert;
import com.untamedears.JukeAlert.manager.SnitchManager;
import com.untamedears.JukeAlert.model.Snitch;

// Static methods only
public class Utility {
    private static boolean debugging_ = false;

    public static boolean isDebugging() {
        return debugging_;
    }

    public static void setDebugging(boolean debugging) {
        debugging_ = debugging;
    }
    
    public static void notifyGroup(Group g, String message) throws SQLException{
        if (g == null) return;
        final JukeAlert plugin = JukeAlert.getInstance();
        Set<String> skipUUID = plugin.getJaLogger().getIgnoreUUIDs(g.getName());
        if(skipUUID == null){
        	//this should be fine as it is how it used to be done
        	skipUUID = null;
        }
        OnlineGroupMembers iter = OnlineGroupMembers
            .get(g.getName())
            .skipList(skipUUID);
        for (Player player : iter) {
            RateLimiter.sendMessage(player, message);
        }
    }

    public static void notifyGroup(Snitch snitch, String message) throws SQLException {
        Group sG = snitch.getGroup();
        if (sG == null) return;
        final JukeAlert plugin = JukeAlert.getInstance();
        Set<String> skipUUID = plugin.getJaLogger().getIgnoreUUIDs(sG.getName());
        if(skipUUID == null){
        	//this should be fine as it is how it used to be done
        	skipUUID = null;
        }
        OnlineGroupMembers iter = OnlineGroupMembers
            .get(sG.getName())
            .reference(snitch.getLoc())
            .skipList(skipUUID);
        if (!snitch.shouldLog()) {
            iter.maxDistance(JukeAlert.getInstance().getConfigManager().getMaxAlertDistanceNs());
        }
        for (Player player : iter) {
            RateLimiter.sendMessage(player, message);
        }
    }

    public static boolean isOnSnitch(Snitch snitch, UUID accountId) {
        Group faction = snitch.getGroup();
        if (faction == null) return false;
        return faction.isMember(accountId);
    }
    
    private static long failureReportDelay = 10000l;
    private static long lastNotifyPOSFailure = System.currentTimeMillis() - failureReportDelay;
    
    public static boolean isPartialOwnerOfSnitch(Snitch snitch, UUID accountId) {
        Group faction = snitch.getGroup();
        if (faction == null) return false;
		if (faction.getOwner() == null) {
			if (System.currentTimeMillis() - lastNotifyPOSFailure > failureReportDelay) {
				JukeAlert.getInstance().getLogger().log(Level.WARNING, 
						"isPartialOwnerOfSnitch called on ownerless group {0} {1}", 
						faction.getName(), faction.getGroupId());
				lastNotifyPOSFailure = System.currentTimeMillis();
			}
			return false; // no owner at all?
		}
        PlayerType type = faction.getPlayerType(accountId);
        GroupPermission perm = NameAPI.getGroupManager().getPermissionforGroup(faction);
        if (perm == null && System.currentTimeMillis() - lastNotifyPOSFailure > failureReportDelay) {
            JukeAlert.getInstance().getLogger().log(Level.WARNING, 
                    "isPartialOwnerOfSnitch unable to find permissions for group {0}", faction.getName());
            lastNotifyPOSFailure = System.currentTimeMillis();
        }
        return faction.isOwner(accountId) || (type != null && perm != null && perm.isAccessible(type, PermissionType.BLOCKS));
    }

    public static Snitch getSnitchUnderCursor(Player player) {
        SnitchManager manager = JukeAlert.getInstance().getSnitchManager();
        Iterator<Block> itr = new BlockIterator(player, 40); // Within 2.5 chunks
        while (itr.hasNext()) {
            final Block block = itr.next();
            final Material mat = block.getType();
            if (mat != Material.JUKEBOX) {
                continue;
            }
            final Snitch found = manager.getSnitch(block.getWorld(), block.getLocation());
            if (found != null) {
                return found;
            }
        }
        return null;
{'fraction_non_alphanumeric': 0.1022764764104256, 'fraction_numerical': 0.0024194435279885624, 'mean_word_length': 2.776578073089701, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 12, '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': '4884611', 'n_tokens_mistral': 2624, 'n_tokens_neox': 2538, 'n_words': 607}