<commit_before>package com.censoredsoftware.Demigods.Demo.Quest.Passive;

import java.util.ArrayList;
import java.util.List;

import org.bukkit.*;
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.inventory.InventoryCloseEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;

import com.censoredsoftware.Demigods.Engine.Deity.Deity;
import com.censoredsoftware.Demigods.Engine.Demigods;
import com.censoredsoftware.Demigods.Engine.DemigodsData;
import com.censoredsoftware.Demigods.Engine.PlayerCharacter.PlayerCharacter;
import com.censoredsoftware.Demigods.Engine.Quest.Quest;
import com.censoredsoftware.Demigods.Engine.Quest.Task;
import com.censoredsoftware.Demigods.Engine.Quest.TaskInfo;
import com.censoredsoftware.Demigods.Engine.Structure.Shrine;
import com.censoredsoftware.Demigods.Engine.Tracked.TrackedPlayer;
import com.censoredsoftware.Demigods.Engine.Utility.ValueUtility;

public class ShrineQuest extends Quest
{
	private static String name = "Shrine", permission = "demigods.shrine";
	private static Type type = Type.PASSIVE;

	private static List<String> about = new ArrayList<String>()
	{
		{
			add("Shrines are an integral part of Demigods.");
			add("Right-click a gold block with a book to create one.");
			add("With your Shrine you can tribute to your Deity!");
		}
	}, accepted = new ArrayList<String>()
	{
		{
			add("Accepted.");
		}
	}, complete = new ArrayList<String>()
	{
		{
			add("Complete.");
		}
	}, failed = new ArrayList<String>()
	{
		{
			add("Failed.");
		}
	};

	private static List<Task> tasks = new ArrayList<Task>()
	{
		{
			add(new Tribute(name, permission, about, accepted, complete, failed, type));
		}
	};

	public ShrineQuest()
	{
		super(name, permission, about, accepted, complete, failed, type, tasks);
	}
}

class Tribute extends Task
{
	// Define required task variables
	private static String name = "Tributing";
	private static int order = 0;
	private static double reward = 0.0, penalty = 0.0;

	private static Listener listener = new Listener()
	{
		@EventHandler(priority = EventPriority.HIGHEST)
		public void onShrineInteract(PlayerInteractEvent event)
		{
			// Return if the player is mortal
			if(!TrackedPlayer.isImmortal(event.getPlayer())) return;
			if(event.getAction() != Action.RIGHT_CLICK_BLOCK) return;

			// Define variables
			Location location = event.getClickedBlock().getLocation();
			Player player = event.getPlayer();
			PlayerCharacter character = TrackedPlayer.getTracked(player).getCurrent();

			if(Shrine.isShrine(location))
			{
				// Cancel the interaction
				event.setCancelled(true);

				// Define the shrine
				Shrine shrine = Shrine.getShrine(location);

				// Return if they aren't clicking the gold block
				if(!event.getClickedBlock().getType().equals(Material.GOLD_BLOCK)) return;

				// Return if the player is mortal
				if(character == null || !character.isImmortal())
				{
					player.sendMessage(ChatColor.RED + "You must be immortal to use that!");
					return;
				}

				if(character.getDeity().equals(shrine.getDeity()))
				{
					useShrine(character, shrine);
				}
				else
				{
					player.sendMessage(ChatColor.YELLOW + "You must be allied to " + shrine.getDeity().getInfo().getName() + " in order to tribute here.");
				}
			}
		}

		@EventHandler(priority = EventPriority.MONITOR)
		public void onPlayerTribute(InventoryCloseEvent event)
		{
			// Return if it's not a player
			if(!(event.getPlayer() instanceof Player)) return;

			// Define player and character
			Player player = (Player) event.getPlayer();
			PlayerCharacter character = TrackedPlayer.getTracked(player).getCurrent();

			// Make sure they have a character and are immortal
			if(character == null || !character.isImmortal()) return;

			// If it isn't a tribute chest then break the method
			if(!event.getInventory().getName().contains("Shrine") || !Shrine.isShrine(player.getTargetBlock(null, 10).getLocation())) return;

			// Get the creator of the shrine
			PlayerCharacter shrineOwner = PlayerCharacter.getCharacterByName(DemigodsData.getValueTemp(player.getName(), character.getName()).toString());

			// Calculate the tribute value
			int tributeValue = 0, items = 0;
			for(ItemStack item : event.getInventory().getContents())
			{
				if(item != null)
				{
					tributeValue += ValueUtility.getTributeValue(item);
					items += item.getAmount();
				}
			}

			// Return if it's empty
			if(items == 0) return;

			// Handle the multiplier
			tributeValue *= Demigods.config.getSettingDouble("multipliers.favor");

			// Get the current favor for comparison
			int favorBefore = character.getMeta().getMaxFavor();

			// Update the character's favor
			character.getMeta().addFavor(tributeValue / 3);
			character.getMeta().addMaxFavor(tributeValue);

			// Define the shrine owner
			OfflinePlayer shrineOwnerPlayer = shrineOwner.getOfflinePlayer();

			// Handle messaging and Shrine owner updating
			if(character.getMeta().getMaxFavor() >= Demigods.config.getSettingInt("caps.favor"))
			{
				// They already have the maximum allowed favor
				player.sendMessage(ChatColor.YELLOW + character.getDeity().getInfo().getName() + " is pleased!");
				player.sendMessage(ChatColor.GRAY + "You have been given " + ChatColor.GREEN + (tributeValue / 3) + ChatColor.GRAY + " favor.");

				if(!player.getName().equals(shrineOwnerPlayer.getName()))
				{
					// Give them some of the blessings
					shrineOwner.getMeta().addMaxFavor(tributeValue / 5);

					// Message them
					if(shrineOwnerPlayer.isOnline() && TrackedPlayer.getTracked(shrineOwner.getOfflinePlayer()).getCurrent().getId().equals(shrineOwner.getId()))
					{
						((Player) shrineOwnerPlayer).sendMessage(ChatColor.YELLOW + "Someone just tributed at your shrine!");
						((Player) shrineOwnerPlayer).sendMessage(ChatColor.GRAY + "Your favor cap is now " + ChatColor.GREEN + shrineOwner.getMeta().getMaxFavor() + ChatColor.GRAY + "!");
					}
				}
			}
			else if(character.getMeta().getMaxFavor() > favorBefore || items > 0)
			{
				// Message the tributer
				player.sendMessage(ChatColor.YELLOW + character.getDeity().getInfo().getName() + " is pleased!");
				player.sendMessage(ChatColor.GRAY + "Your favor cap is now " + ChatColor.GREEN + character.getMeta().getMaxFavor() + ChatColor.GRAY + ".");
<commit_msg>Another tributing update.<commit_after>package com.censoredsoftware.Demigods.Demo.Quest.Passive;

import java.util.ArrayList;
import java.util.List;

import org.bukkit.*;
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.inventory.InventoryCloseEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;

import com.censoredsoftware.Demigods.Engine.Deity.Deity;
import com.censoredsoftware.Demigods.Engine.Demigods;
import com.censoredsoftware.Demigods.Engine.DemigodsData;
import com.censoredsoftware.Demigods.Engine.PlayerCharacter.PlayerCharacter;
import com.censoredsoftware.Demigods.Engine.Quest.Quest;
import com.censoredsoftware.Demigods.Engine.Quest.Task;
import com.censoredsoftware.Demigods.Engine.Quest.TaskInfo;
import com.censoredsoftware.Demigods.Engine.Structure.Shrine;
import com.censoredsoftware.Demigods.Engine.Tracked.TrackedPlayer;
import com.censoredsoftware.Demigods.Engine.Utility.ValueUtility;

public class ShrineQuest extends Quest
{
	private static String name = "Shrine", permission = "demigods.shrine";
	private static Type type = Type.PASSIVE;

	private static List<String> about = new ArrayList<String>()
	{
		{
			add("Shrines are an integral part of Demigods.");
			add("Right-click a gold block with a book to create one.");
			add("With your Shrine you can tribute to your Deity!");
		}
	}, accepted = new ArrayList<String>()
	{
		{
			add("Accepted.");
		}
	}, complete = new ArrayList<String>()
	{
		{
			add("Complete.");
		}
	}, failed = new ArrayList<String>()
	{
		{
			add("Failed.");
		}
	};

	private static List<Task> tasks = new ArrayList<Task>()
	{
		{
			add(new Tribute(name, permission, about, accepted, complete, failed, type));
		}
	};

	public ShrineQuest()
	{
		super(name, permission, about, accepted, complete, failed, type, tasks);
	}
}

class Tribute extends Task
{
	// Define required task variables
	private static String name = "Tributing";
	private static int order = 0;
	private static double reward = 0.0, penalty = 0.0;

	private static Listener listener = new Listener()
	{
		@EventHandler(priority = EventPriority.HIGHEST)
		public void onShrineInteract(PlayerInteractEvent event)
		{
			// Return if the player is mortal
			if(!TrackedPlayer.isImmortal(event.getPlayer())) return;
			if(event.getAction() != Action.RIGHT_CLICK_BLOCK) return;

			// Define variables
			Location location = event.getClickedBlock().getLocation();
			Player player = event.getPlayer();
			PlayerCharacter character = TrackedPlayer.getTracked(player).getCurrent();

			if(Shrine.isShrine(location))
			{
				// Cancel the interaction
				event.setCancelled(true);

				// Define the shrine
				Shrine shrine = Shrine.getShrine(location);

				// Return if they aren't clicking the gold block
				if(!event.getClickedBlock().getType().equals(Material.GOLD_BLOCK)) return;

				// Return if the player is mortal
				if(character == null || !character.isImmortal())
				{
					player.sendMessage(ChatColor.RED + "You must be immortal to use that!");
					return;
				}

				if(character.getDeity().equals(shrine.getDeity()))
				{
					useShrine(character, shrine);
				}
				else
				{
					player.sendMessage(ChatColor.YELLOW + "You must be allied to " + shrine.getDeity().getInfo().getName() + " in order to tribute here.");
				}
			}
		}

		@EventHandler(priority = EventPriority.MONITOR)
		public void onPlayerTribute(InventoryCloseEvent event)
		{
			// Return if it's not a player
			if(!(event.getPlayer() instanceof Player)) return;

			// Define player and character
			Player player = (Player) event.getPlayer();
			PlayerCharacter character = TrackedPlayer.getTracked(player).getCurrent();

			// Make sure they have a character and are immortal
			if(character == null || !character.isImmortal()) return;

			// If it isn't a tribute chest then break the method
			if(!event.getInventory().getName().contains("Shrine") || !Shrine.isShrine(player.getTargetBlock(null, 10).getLocation())) return;

			// Get the creator of the shrine
			PlayerCharacter shrineOwner = PlayerCharacter.getCharacterByName(DemigodsData.getValueTemp(player.getName(), character.getName()).toString());

			// Calculate the tribute value
			int tributeValue = 0, items = 0;
			for(ItemStack item : event.getInventory().getContents())
			{
				if(item != null)
				{
					tributeValue += ValueUtility.getTributeValue(item);
					items += item.getAmount();
				}
			}

			// Return if it's empty
			if(items == 0) return;

			// Handle the multiplier
			tributeValue *= Demigods.config.getSettingDouble("multipliers.favor");

			// Get the current favor for comparison
			int favorBefore = character.getMeta().getFavor();
			int maxFavorBefore = character.getMeta().getMaxFavor();

			// Update the character's favor
			character.getMeta().addFavor(tributeValue / 3);
			character.getMeta().addMaxFavor(tributeValue);

			// Define the shrine owner
			OfflinePlayer shrineOwnerPlayer = shrineOwner.getOfflinePlayer();

			// Handle messaging and Shrine owner updating
			if(character.getMeta().getMaxFavor() >= Demigods.config.getSettingInt("caps.favor"))
			{
				// They already have the maximum allowed favor
				player.sendMessage(ChatColor.YELLOW + character.getDeity().getInfo().getName() + " is pleased!");
				if(character.getMeta().getFavor() > favorBefore) player.sendMessage(ChatColor.GRAY + "You have been given " + ChatColor.GREEN + (tributeValue / 3) + ChatColor.GRAY + " favor.");

				if(!player.getName().equals(shrineOwnerPlayer.getName()))
				{
					// Give them some of the blessings
					shrineOwner.getMeta().addMaxFavor(tributeValue / 5);

					// Message them
					if(shrineOwnerPlayer.isOnline() && TrackedPlayer.getTracked(shrineOwner.getOfflinePlayer()).getCurrent().getId().equals(shrineOwner.getId()))
					{
						((Player) shrineOwnerPlayer).sendMessage(ChatColor.YELLOW + "Someone just tributed at your shrine!");
						((Player) shrineOwnerPlayer).sendMessage(ChatColor.GRAY + "Your favor cap is now " + ChatColor.GREEN + shrineOwner.getMeta().getMaxFavor() + ChatColor.GRAY + "!");
					}
				}
			}
			else if(character.getMeta().getMaxFavor() > maxFavorBefore || items > 0)
			{
				// Message the tributer
				player.sendMessage(ChatColor.YELLOW + character.getDeity().getInfo().getName() + " is pleased!");
				player.sendMessage(ChatColor.GRAY + "Your favor cap is now " + ChatColor.GREEN + character.getMeta().getMaxFavor() + ChatColor.GRAY + ".");

{'fraction_non_alphanumeric': 0.12613705275924803, 'fraction_numerical': 0.002122498483929654, 'mean_word_length': 4.145475819032761, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 24, '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': '2407640', 'n_tokens_mistral': 4746, 'n_tokens_neox': 3933, 'n_words': 893}