<commit_before>/*
 *  This file is part of RPG Items.
 *
 *  RPG Items is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  RPG Items is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with RPG Items.  If not, see <http://www.gnu.org/licenses/>.
 */
package think.rpgitems.support;

import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;

import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.protection.flags.DefaultFlag;
import com.sk89q.worldguard.protection.flags.StateFlag.State;

public class WorldGuard {

    private static Plugin plugin;
    private static WorldGuardPlugin wgPlugin;
    private static boolean hasSupport = false;
    private static int majorVersion;
    public static boolean useWorldGuard = true;

    public static void init(think.rpgitems.Plugin pl) {
        plugin = pl;
        Plugin wgPlugin = plugin.getServer().getPluginManager().getPlugin("WorldGuard");
        useWorldGuard = plugin.getConfig().getBoolean("support.worldguard", false);
        if (wgPlugin == null || !(wgPlugin instanceof WorldGuardPlugin)) {
            return;
        }
        hasSupport = true;
        WorldGuard.wgPlugin = (WorldGuardPlugin) wgPlugin;
        majorVersion = Character.digit(wgPlugin.getDescription().getVersion().charAt(0), 9);
        think.rpgitems.Plugin.logger.info("[RPGItems] WorldGuard version " + majorVersion + " found");
    }
    
    public static void reload() {
        useWorldGuard = plugin.getConfig().getBoolean("support.worldguard", false);
        if (wgPlugin == null || !(wgPlugin instanceof WorldGuardPlugin)) {
            return;
        }
        hasSupport = true;
        WorldGuard.wgPlugin = (WorldGuardPlugin) wgPlugin;
        majorVersion = Character.digit(wgPlugin.getDescription().getVersion().charAt(0), 9);
        think.rpgitems.Plugin.logger.info("[RPGItems] WorldGuard version " + majorVersion + " found");
    }

    public static boolean isEnabled() {
        return hasSupport;
    }

    public static boolean canBuild(Player player, Location location) {
        if (!hasSupport || !useWorldGuard)
            return true;
        return wgPlugin.canBuild(player, location);
    }

    @SuppressWarnings("deprecation")
    public static boolean canPvP(Player player) {
        if (!hasSupport || !useWorldGuard)
            return true;
        
        if(majorVersion >= 6)
            return wgPlugin.getRegionContainer().createQuery().queryState(player.getLocation(), player, DefaultFlag.PVP).equals(State.ALLOW);
        else
            return wgPlugin.getGlobalRegionManager().allows(DefaultFlag.PVP, player.getLocation(), wgPlugin.wrapPlayer(player));
    }
}
<commit_msg>try fixing NPE in WorldGuard.java<commit_after>/*
 *  This file is part of RPG Items.
 *
 *  RPG Items is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  RPG Items is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with RPG Items.  If not, see <http://www.gnu.org/licenses/>.
 */
package think.rpgitems.support;

import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;

import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.protection.flags.DefaultFlag;
import com.sk89q.worldguard.protection.flags.StateFlag.State;

public class WorldGuard {

    private static Plugin plugin;
    private static WorldGuardPlugin wgPlugin;
    private static boolean hasSupport = false;
    private static int majorVersion;
    public static boolean useWorldGuard = true;

    public static void init(think.rpgitems.Plugin pl) {
        plugin = pl;
        Plugin wgPlugin = plugin.getServer().getPluginManager().getPlugin("WorldGuard");
        useWorldGuard = plugin.getConfig().getBoolean("support.worldguard", false);
        if (wgPlugin == null || !(wgPlugin instanceof WorldGuardPlugin)) {
            return;
        }
        hasSupport = true;
        WorldGuard.wgPlugin = (WorldGuardPlugin) wgPlugin;
        majorVersion = Character.digit(wgPlugin.getDescription().getVersion().charAt(0), 9);
        think.rpgitems.Plugin.logger.info("[RPGItems] WorldGuard version " + majorVersion + " found");
    }
    
    public static void reload() {
        useWorldGuard = plugin.getConfig().getBoolean("support.worldguard", false);
        if (wgPlugin == null || !(wgPlugin instanceof WorldGuardPlugin)) {
            return;
        }
        hasSupport = true;
        WorldGuard.wgPlugin = (WorldGuardPlugin) wgPlugin;
        majorVersion = Character.digit(wgPlugin.getDescription().getVersion().charAt(0), 9);
        think.rpgitems.Plugin.logger.info("[RPGItems] WorldGuard version " + majorVersion + " found");
    }

    public static boolean isEnabled() {
        return hasSupport;
    }

    public static boolean canBuild(Player player, Location location) {
        if (!hasSupport || !useWorldGuard)
            return true;
        return wgPlugin.canBuild(player, location);
    }

    @SuppressWarnings("deprecation")
    public static boolean canPvP(Player player) {
        if (!hasSupport || !useWorldGuard)
            return true;
        
        if(majorVersion >= 6) {
            State stat = wgPlugin.getRegionContainer().createQuery().queryState(player.getLocation(), player, DefaultFlag.PVP);
            return stat == null || stat.equals(State.ALLOW);
        } else {
            return wgPlugin.getGlobalRegionManager().allows(DefaultFlag.PVP, player.getLocation(), wgPlugin.wrapPlayer(player));
        }
    }
}

{'fraction_non_alphanumeric': 0.09824615862176005, 'fraction_numerical': 0.0037249728387397174, 'mean_word_length': 3.1844155844155844, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '3134066', 'n_tokens_mistral': 1796, 'n_tokens_neox': 1731, 'n_words': 507}