<commit_before>package com.eharrison.canary.zown.listener;

import net.canarymod.api.entity.Entity;
import net.canarymod.hook.HookHandler;
import net.canarymod.hook.entity.DamageHook;
import net.canarymod.hook.entity.EntityLightningStruckHook;
import net.canarymod.hook.entity.ProjectileHitHook;
import net.canarymod.plugin.PluginListener;
import net.canarymod.plugin.Priority;

import com.eharrison.canary.zown.Flag;
import com.eharrison.canary.zown.api.IZown;
import com.eharrison.canary.zown.api.IZownManager;
import com.eharrison.canary.zown.api.impl.Tree;

public class PlayerListener implements PluginListener {
	private final IZownManager zownManager;
	
	public PlayerListener(final IZownManager zownManager) {
		this.zownManager = zownManager;
	}
	
	@HookHandler(priority = Priority.CRITICAL)
	public void onProjectileHit(final ProjectileHitHook hook) {
		final Entity target = hook.getEntityHit();
		
		if (target != null && target.isPlayer()) {
			final Tree<? extends IZown> zownTree = zownManager.getZown(target.getLocation());
			final Boolean flag = zownTree.getData().getConfiguration().getFlag(Flag.playerimmune.name());
			if (flag != null && flag) {
				hook.setCanceled();
			}
		}
	}
	<commit_msg>Added initial player location zown management.<commit_after>package com.eharrison.canary.zown.listener;

import java.util.HashMap;
import java.util.Map;

import net.canarymod.api.entity.Entity;
import net.canarymod.api.entity.living.humanoid.Player;
import net.canarymod.hook.HookHandler;
import net.canarymod.hook.entity.DamageHook;
import net.canarymod.hook.entity.EntityLightningStruckHook;
import net.canarymod.hook.entity.ProjectileHitHook;
import net.canarymod.hook.player.PlayerMoveHook;
import net.canarymod.plugin.PluginListener;
import net.canarymod.plugin.Priority;

import com.eharrison.canary.zown.Flag;
import com.eharrison.canary.zown.api.IZown;
import com.eharrison.canary.zown.api.IZownManager;
import com.eharrison.canary.zown.api.impl.Tree;

public class PlayerListener implements PluginListener {
	private final IZownManager zownManager;
	// TODO: Use this map for player location
	private final Map<String, Tree<? extends IZown>> playerZownMap;
	
	public PlayerListener(final IZownManager zownManager) {
		this.zownManager = zownManager;
		playerZownMap = new HashMap<String, Tree<? extends IZown>>();
	}
	
	@HookHandler(priority = Priority.CRITICAL)
	public void onPlayerMove(final PlayerMoveHook hook) {
		final Player player = hook.getPlayer();
		
		Tree<? extends IZown> zownTree = playerZownMap.get(player.getUUIDString());
		if (zownTree == null) {
			zownTree = zownManager.getZown(player.getLocation());
			playerZownMap.put(player.getUUIDString(), zownTree);
		} else {
			final Tree<? extends IZown> targetZownTree = zownManager.getZown(hook.getTo());
			if (zownTree != targetZownTree) {
				// TODO check if the player is authorized to enter the zown
				
				// Changed zown
				playerZownMap.put(player.getUUIDString(), targetZownTree);
				player.message("Zown " + zownTree.getData().getName() + " to "
						+ targetZownTree.getData().getName());
				// TODO send PlayerZownExit and PlayerZownEntry
				// TODO allow for cancel of player move
			}
		}
	}
	
	// TODO observe tp and connect for zown change
	
	@HookHandler(priority = Priority.CRITICAL)
	public void onProjectileHit(final ProjectileHitHook hook) {
		final Entity target = hook.getEntityHit();
		
		if (target != null && target.isPlayer()) {
			final Tree<? extends IZown> zownTree = zownManager.getZown(target.getLocation());
			final Boolean flag = zownTree.getData().getConfiguration().getFlag(Flag.playerimmune.name());
			if (flag != null && flag) {
				hook.setCanceled();
			}
		}
	}
	
{'fraction_non_alphanumeric': 0.11269884065785926, 'fraction_numerical': 0.0, 'mean_word_length': 4.870253164556962, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '2770172', 'n_tokens_mistral': 1288, 'n_tokens_neox': 1185, 'n_words': 243}