<commit_before>package com.archivesmc.archblock.api;

import com.archivesmc.archblock.Plugin;
import com.archivesmc.archblock.runnables.database.*;
import com.archivesmc.archblock.storage.entities.Friendship;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.hibernate.Query;
import org.hibernate.Session;

import java.util.List;
import java.util.UUID;

public class ArchBlock {
    // Class is named this in case there are plugins using multiple protection APIs

    private Plugin plugin;

    public ArchBlock(Plugin plugin) {
        this.plugin = plugin;
    }

    public Plugin getPlugin() {
        return plugin;
    }

    public UUID getOwnerUUID(Block block) {
        return this.getOwnerUUID(block.getWorld(), block.getX(), block.getY(), block.getZ());
    }

    public UUID getOwnerUUID(World world, Integer x, Integer y, Integer z) {
        return this.getOwnerUUID(world.getName(), x, y, z);
    }

    public UUID getOwnerUUID(String world, Integer x, Integer y, Integer z) {
        world = world.toLowerCase();

        Session s = this.plugin.getSession();
        Query q = s.createQuery("SELECT b.uuid FROM Block b WHERE world=? AND x=? AND y=? AND z=?");

        q.setString(0, world);
        q.setInteger(1, x);
        q.setInteger(2, y);
        q.setInteger(3, z);

        Object result = q.uniqueResult();

        s.close();

        if (result == null) {
            return null;
        }

        return UUID.fromString((String) result);
    }

    public void setOwnerUUID(Block block, UUID owner) {
        this.setOwnerUUID(block.getWorld(), block.getX(), block.getY(), block.getZ(), owner);
    }

    public void setOwnerUUID(World world, Integer x, Integer y, Integer z, UUID owner) {
        this.setOwnerUUID(world.getName(), x, y, z, owner);
    }

    public void setOwnerUUID(String world, Integer x, Integer y, Integer z, UUID owner) {
        world = world.toLowerCase();

        com.archivesmc.archblock.storage.entities.Block b = new com.archivesmc.archblock.storage.entities.Block(
                Long.valueOf(x), Long.valueOf(y), Long.valueOf(z), owner.toString(), world
        );

        new SetOwnerThread(this.plugin, b).start();
    }

    public void removeOwner(Block block){
        this.removeOwner(block.getWorld(), block.getX(), block.getY(), block.getZ());
    }

    public void removeOwner(World world, Integer x, Integer y, Integer z) {
        this.removeOwner(world.getName(), x, y, z);
    }

    public void removeOwner(String world, Integer x, Integer y, Integer z) {
        world = world.toLowerCase();

        new RemoveOwnerThread(this.plugin, world, x, y, z).start();
    }

    public Boolean hasFriendship(UUID left, UUID right) {
        Session s = this.plugin.getSession();
        Query q = s.createQuery("SELECT f FROM Friendship f WHERE playerUuid=? AND friendUuid=?");

        q.setString(0, left.toString());
        q.setString(1, right.toString());

        Object result = q.uniqueResult();

        s.close();

        return result != null;
    }

    public void createFriendship(UUID left, UUID right) {
        Friendship f = new Friendship(left.toString(), right.toString());

        new CreateFriendshipThread(this.plugin, f).start();
    }

    public void destroyFriendship(UUID left, UUID right) {
        new DestroyFriendshipThread(this.plugin, left, right).start();
    }

    public List getFriendships(UUID left) {
        Session s = this.plugin.getSession();

        Query q = s.createQuery(
                "SELECT p.username from Player p INNER JOIN Friendship f ON p.uuid=f.friendUuid WHERE f.playerUuid=:uuid"
        );

//        Query q = s.createQuery(
//                "SELECT p.username FROM Friendship f, Player p WHERE f.playerUuid=:uuid AND p.uuid=f.friendUuid"
//        );

        q.setString("uuid", left.toString());

        return q.list();
    }

    public List getFriendships(String username) {
        username = username.toLowerCase();

        Session s = this.plugin.getSession();
        Query q = s.createQuery(
                "SELECT p2.username FROM Friendship f, Player p1, Player p2 WHERE " +
                "p1.username=:username AND f.playerUuid=p1.uuid AND p2.uuid=f.friendUuid"
        );

        q.setString("username", username.toLowerCase());
<commit_msg>Attempt to fix /friends<commit_after>package com.archivesmc.archblock.api;

import com.archivesmc.archblock.Plugin;
import com.archivesmc.archblock.runnables.database.*;
import com.archivesmc.archblock.storage.entities.Friendship;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.hibernate.Query;
import org.hibernate.Session;

import java.util.List;
import java.util.UUID;

public class ArchBlock {
    // Class is named this in case there are plugins using multiple protection APIs

    private Plugin plugin;

    public ArchBlock(Plugin plugin) {
        this.plugin = plugin;
    }

    public Plugin getPlugin() {
        return plugin;
    }

    public UUID getOwnerUUID(Block block) {
        return this.getOwnerUUID(block.getWorld(), block.getX(), block.getY(), block.getZ());
    }

    public UUID getOwnerUUID(World world, Integer x, Integer y, Integer z) {
        return this.getOwnerUUID(world.getName(), x, y, z);
    }

    public UUID getOwnerUUID(String world, Integer x, Integer y, Integer z) {
        world = world.toLowerCase();

        Session s = this.plugin.getSession();
        Query q = s.createQuery("SELECT b.uuid FROM Block b WHERE world=? AND x=? AND y=? AND z=?");

        q.setString(0, world);
        q.setInteger(1, x);
        q.setInteger(2, y);
        q.setInteger(3, z);

        Object result = q.uniqueResult();

        s.close();

        if (result == null) {
            return null;
        }

        return UUID.fromString((String) result);
    }

    public void setOwnerUUID(Block block, UUID owner) {
        this.setOwnerUUID(block.getWorld(), block.getX(), block.getY(), block.getZ(), owner);
    }

    public void setOwnerUUID(World world, Integer x, Integer y, Integer z, UUID owner) {
        this.setOwnerUUID(world.getName(), x, y, z, owner);
    }

    public void setOwnerUUID(String world, Integer x, Integer y, Integer z, UUID owner) {
        world = world.toLowerCase();

        com.archivesmc.archblock.storage.entities.Block b = new com.archivesmc.archblock.storage.entities.Block(
                Long.valueOf(x), Long.valueOf(y), Long.valueOf(z), owner.toString(), world
        );

        new SetOwnerThread(this.plugin, b).start();
    }

    public void removeOwner(Block block){
        this.removeOwner(block.getWorld(), block.getX(), block.getY(), block.getZ());
    }

    public void removeOwner(World world, Integer x, Integer y, Integer z) {
        this.removeOwner(world.getName(), x, y, z);
    }

    public void removeOwner(String world, Integer x, Integer y, Integer z) {
        world = world.toLowerCase();

        new RemoveOwnerThread(this.plugin, world, x, y, z).start();
    }

    public Boolean hasFriendship(UUID left, UUID right) {
        Session s = this.plugin.getSession();
        Query q = s.createQuery("SELECT f FROM Friendship f WHERE playerUuid=? AND friendUuid=?");

        q.setString(0, left.toString());
        q.setString(1, right.toString());

        Object result = q.uniqueResult();

        s.close();

        return result != null;
    }

    public void createFriendship(UUID left, UUID right) {
        Friendship f = new Friendship(left.toString(), right.toString());

        new CreateFriendshipThread(this.plugin, f).start();
    }

    public void destroyFriendship(UUID left, UUID right) {
        new DestroyFriendshipThread(this.plugin, left, right).start();
    }

    public List getFriendships(UUID left) {
        Session s = this.plugin.getSession();

        Query q;

        q = s.createQuery(
                "SELECT f.friendUuid FROM Friend f WHERE f.playerUuid=:uuid"
        );
        q.setString("uuid", left.toString());

        List uuids = q.list();

        q = s.createQuery(
                "SELECT p.username FROM player p WHERE p.uuid IN (:uuids)"
        );
        q.setParameter("uuids", uuids);

        List result = q.list();

        s.close();

        return result;

//        Query q = s.createQuery(
//                "SELECT p.username from Player p INNER JOIN Friendship f WHERE f.playerUuid=:uuid"
//        );

//        Query q = s.createQuery(
//                "SELECT p.username FROM Friendship f, Player p WHERE f.playerUuid=:uuid AND p.uuid=f.friendUuid"
//        );
    }

    public List getFriendships(String username) {
        username = username.toLowerCase();

        Session s = this.plugin.getSession();
        Query q = s.createQuery(
                "SELECT p2.username FROM Friendship f, Player p1, Player p2 WHERE " +
                "p1.username=:username AND f.playerUuid=p1.uuid AND p2.uuid=f.friendUuid"
        );

        q.setString("username", username.toLowerCase());

{'fraction_non_alphanumeric': 0.12160527762506872, 'fraction_numerical': 0.0026388125343595383, 'mean_word_length': 2.5839243498817965, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '528709', 'n_tokens_mistral': 2742, 'n_tokens_neox': 2684, 'n_words': 720}