<commit_before>/**
 * Jobs Plugin for Bukkit
 * Copyright (C) 2011 <NAME> <<EMAIL>>
 * 
 * This program 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.
 * 
 * This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package com.gamingmesh.jobs.listeners;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.regex.Pattern;

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.Sign;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockGrowEvent;
import org.bukkit.event.block.SignChangeEvent;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.event.player.PlayerChangedWorldEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.world.WorldLoadEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.permissions.Permission;
import org.bukkit.permissions.PermissionDefault;
import org.bukkit.plugin.PluginManager;

import com.gamingmesh.jobs.Jobs;
import com.gamingmesh.jobs.Gui.GuiInfoList;
import com.gamingmesh.jobs.api.JobsChunkChangeEvent;
import com.gamingmesh.jobs.container.Job;
import com.gamingmesh.jobs.container.JobLimitedItems;
import com.gamingmesh.jobs.container.JobProgression;
import com.gamingmesh.jobs.container.JobsPlayer;
import com.gamingmesh.jobs.stuff.Debug;

public class JobsListener implements Listener {
    // hook to the main plugin
    private Jobs plugin;

    public JobsListener(Jobs plugin) {
	this.plugin = plugin;
    }

    @EventHandler(priority = EventPriority.LOWEST)
    public void onShopClick(InventoryClickEvent event) {
	if (Jobs.getShopManager().GuiList.isEmpty())
	    return;

	Player player = (Player) event.getWhoClicked();

	if (!Jobs.getShopManager().GuiList.containsKey(player.getName()))
	    return;

	event.setCancelled(true);

	int tsize = player.getOpenInventory().getTopInventory().getSize();

	if (event.getRawSlot() < 0 || event.getRawSlot() >= tsize)
	    return;

	Jobs.getShopManager().checkSlot(player, event.getRawSlot(), Jobs.getShopManager().GuiList.get(player.getName()));

    }

    @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = false)
    public void onShopClose(InventoryCloseEvent event) {
	if (Jobs.getShopManager().GuiList.isEmpty())
	    return;

	Player player = (Player) event.getPlayer();

	if (Jobs.getShopManager().GuiList.containsKey(player.getName()))
	    Jobs.getShopManager().GuiList.remove(player.getName());
    }

    @EventHandler(priority = EventPriority.LOWEST)
    public void onGuiLeftClick(InventoryClickEvent event) {

	if (Jobs.getGUIManager().GuiList.isEmpty())
	    return;

	Player player = (Player) event.getWhoClicked();

	if (!Jobs.getGUIManager().GuiList.containsKey(player.getName()))
	    return;

	event.setCancelled(true);

	GuiInfoList joblist = Jobs.getGUIManager().GuiList.get(player.getName());

	int slot = event.getRawSlot();

	if (slot >= 0) {
	    if (!joblist.isJobInfo() && (!Jobs.getGCManager().JobsGUISwitcheButtons && event.getClick() == ClickType.LEFT ||
		Jobs.getGCManager().JobsGUISwitcheButtons && event.getClick() == ClickType.RIGHT)) {
		Job job = Jobs.getGUIManager().getJobBySlot(player, slot);
		if (job != null) {

		    Inventory inv = Jobs.getGUIManager().CreateJobsSubGUI(player, job);
//		    player.closeInventory(); 
		    Inventory top = player.getOpenInventory().getTopInventory();
		    if (top.getSize() == 54)
			top.setContents(inv.getContents());
//		    player.openInventory(inv);
		}
	    } else if (joblist.isJobInfo()) {
		if (slot == joblist.getbackButton()) {

		    Inventory inv = Jobs.getGUIManager().CreateJobsGUI(player);
//		    player.closeInventory(); 
		    Inventory top = player.getOpenInventory().getTopInventory();
		    if (top.getSize() == 54)
			top.setContents(inv.getContents());

		    Debug.D("back");
//		    player.closeInventory();
//		    player.openInventory(Jobs.getGUIManager().CreateJobsGUI(player));
		}
	    } else if (!Jobs.getGCManager().JobsGUISwitcheButtons && event.getClick() == ClickType.RIGHT ||
		Jobs.getGCManager().JobsGUISwitcheButtons && event.getClick() == ClickType.LEFT) {
		if (!joblist.isJobInfo() && slot < joblist.getJobList().size()) {
		    Bukkit.dispatchCommand(player, "jobs join " + joblist.getJobList().get(slot).getName());
		    player.getOpenInventory().getTopInventory().setContents(Jobs.getGUIManager().CreateJobsGUI(player).getContents());
		}
	    }
	}
    }

    @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = false)
    public void onGuiClose(InventoryCloseEvent event) {
	if (Jobs.getGUIManager().GuiList.isEmpty())
	    return;

	Player player = (Player) event.getPlayer();<commit_msg>Check for correct job when pressing in GUI to join<commit_after>/**
 * Jobs Plugin for Bukkit
 * Copyright (C) 2011 <NAME> <<EMAIL>>
 * 
 * This program 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.
 * 
 * This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package com.gamingmesh.jobs.listeners;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.regex.Pattern;

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.Sign;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockGrowEvent;
import org.bukkit.event.block.SignChangeEvent;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.event.player.PlayerChangedWorldEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.world.WorldLoadEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.permissions.Permission;
import org.bukkit.permissions.PermissionDefault;
import org.bukkit.plugin.PluginManager;

import com.gamingmesh.jobs.Jobs;
import com.gamingmesh.jobs.Gui.GuiInfoList;
import com.gamingmesh.jobs.api.JobsChunkChangeEvent;
import com.gamingmesh.jobs.container.Job;
import com.gamingmesh.jobs.container.JobLimitedItems;
import com.gamingmesh.jobs.container.JobProgression;
import com.gamingmesh.jobs.container.JobsPlayer;
import com.gamingmesh.jobs.stuff.Debug;

public class JobsListener implements Listener {
    // hook to the main plugin
    private Jobs plugin;

    public JobsListener(Jobs plugin) {
	this.plugin = plugin;
    }

    @EventHandler(priority = EventPriority.LOWEST)
    public void onShopClick(InventoryClickEvent event) {
	if (Jobs.getShopManager().GuiList.isEmpty())
	    return;

	Player player = (Player) event.getWhoClicked();

	if (!Jobs.getShopManager().GuiList.containsKey(player.getName()))
	    return;

	event.setCancelled(true);

	int tsize = player.getOpenInventory().getTopInventory().getSize();

	if (event.getRawSlot() < 0 || event.getRawSlot() >= tsize)
	    return;

	Jobs.getShopManager().checkSlot(player, event.getRawSlot(), Jobs.getShopManager().GuiList.get(player.getName()));

    }

    @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = false)
    public void onShopClose(InventoryCloseEvent event) {
	if (Jobs.getShopManager().GuiList.isEmpty())
	    return;

	Player player = (Player) event.getPlayer();

	if (Jobs.getShopManager().GuiList.containsKey(player.getName()))
	    Jobs.getShopManager().GuiList.remove(player.getName());
    }

    @EventHandler(priority = EventPriority.LOWEST)
    public void onGuiLeftClick(InventoryClickEvent event) {

	if (Jobs.getGUIManager().GuiList.isEmpty())
	    return;

	Player player = (Player) event.getWhoClicked();

	if (!Jobs.getGUIManager().GuiList.containsKey(player.getName()))
	    return;

	event.setCancelled(true);

	GuiInfoList joblist = Jobs.getGUIManager().GuiList.get(player.getName());

	int slot = event.getRawSlot();

	if (slot >= 0) {
	    if (!joblist.isJobInfo() && (!Jobs.getGCManager().JobsGUISwitcheButtons && event.getClick() == ClickType.LEFT ||
		Jobs.getGCManager().JobsGUISwitcheButtons && event.getClick() == ClickType.RIGHT)) {
		Job job = Jobs.getGUIManager().getJobBySlot(player, slot);
		if (job != null) {

		    Inventory inv = Jobs.getGUIManager().CreateJobsSubGUI(player, job);
//		    player.closeInventory(); 
		    Inventory top = player.getOpenInventory().getTopInventory();
		    if (top.getSize() == 54)
			top.setContents(inv.getContents());
//		    player.openInventory(inv);
		}
	    } else if (joblist.isJobInfo()) {
		if (slot == joblist.getbackButton()) {

		    Inventory inv = Jobs.getGUIManager().CreateJobsGUI(player);
//		    player.closeInventory(); 
		    Inventory top = player.getOpenInventory().getTopInventory();
		    if (top.getSize() == 54)
			top.setContents(inv.getContents());

		    Debug.D("back");
//		    player.closeInventory();
//		    player.openInventory(Jobs.getGUIManager().CreateJobsGUI(player));
		}
	    } else if (!Jobs.getGCManager().JobsGUISwitcheButtons && event.getClick() == ClickType.RIGHT ||
		Jobs.getGCManager().JobsGUISwitcheButtons && event.getClick() == ClickType.LEFT) {
		Job job = Jobs.getGUIManager().getJobBySlot(player, slot);
		if (job != null) {
		    Bukkit.dispatchCommand(player, "jobs join " + job.getName());
		    player.getOpenInventory().getTopInventory().setContents(Jobs.getGUIManager().CreateJobsGUI(player).getContents());
		}
	    }
	}
    }

    @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = false)
    public void onGuiClose(InventoryCloseEvent event) {
	if (Jobs.getGUIManager().GuiList.isEmpty())
	    return;

	Player player = (Player) event.getPlayer();
{'fraction_non_alphanumeric': 0.12579140286571142, 'fraction_numerical': 0.0018327224258580473, 'mean_word_length': 4.684185606060606, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 15, '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': '5387741', 'n_tokens_mistral': 3999, 'n_tokens_neox': 3767, 'n_words': 759}