<commit_before>package com.ekstemicraft.plugin.echorses;

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Server;
import org.bukkit.entity.AnimalTamer;
import org.bukkit.entity.Arrow;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Horse;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.event.entity.EntityTameEvent;
import org.bukkit.event.entity.ProjectileHitEvent;
import org.bukkit.event.vehicle.VehicleEnterEvent;

public class ECHorsesListeners implements Listener {
		
@EventHandler
	public void horseEnter(VehicleEnterEvent event){
	
	if(event.getVehicle() instanceof Horse){

      EntityType entered = (EntityType)event.getEntered().getType();
      if(entered == EntityType.PLAYER){ //Playercheck
    	  
    	  Player p = (Player)event.getEntered();
    	  String playername = p.getName();
    	  @SuppressWarnings("unused")
		Server server = p.getServer(); //Not used for now
          Horse h = (Horse)event.getVehicle();
          AnimalTamer owner = h.getOwner();
          if(!(owner == null)){
        	  
        	  if(p.isOp() && p.hasPermission("echorse.override")){ //Overriding the protection if player is OP
        		  return;
        	  }
        	  if(h.getOwner().getName() == p.getName()){ //Checking if entering player is the owner
        	  return;
        	  }
        	  else {
        		  p.sendMessage(ChatColor.AQUA + "[ECHorses]" + ChatColor.RED + " This horse is owned by " + h.getOwner().getName());
        		  Bukkit.getLogger().info("[ECHorses] " + playername + "tried entering someone elses horse");
        		  event.setCancelled(true);
        		  return;
        	  }
          } 
       p.sendMessage(ChatColor.AQUA + "[ECHorses]" + ChatColor.GREEN + " This horse is untamed!"); 
      }	
		
	}
}
@EventHandler
public void horseTameEvent(EntityTameEvent event){
     
	 if(event.getEntityType() == EntityType.HORSE){
		 Player p = (Player)event.getOwner();
		 p.sendMessage(ChatColor.AQUA + "[ECHorses]" + ChatColor.GREEN + " You have succesfully protected this horse!");
		 
	 }	
}
@EventHandler
public void horseDamageByEntity(EntityDamageByEntityEvent event){
	if(event.getEntityType() == EntityType.HORSE){
		Player p = (Player)event.getDamager();
		Horse h = (Horse)event.getEntity();				
		if(event.getDamager().getType() == EntityType.PLAYER){ //Playercheck

			if(p.isOp() || p.hasPermission("echorse.override") || h.getOwner() == null){ //Op & permission check & if horse isnt tamed.
				return;
			}
			 if(!(h.getOwner().getName() == p.getName())){ //If its not the horse owner, cancel the event
				 event.setCancelled(true);
				 p.sendMessage(ChatColor.AQUA + "[ECHorses]" + ChatColor.RED + " You dont have permission to hurt " + h.getOwner().getName() + "s horse!" );
			 }
		}		
	return;	
	}	
}
@EventHandler
public void horseDamageByProjectile(EntityDamageEvent event){
	if (event instanceof EntityDamageByEntityEvent){
	if(((EntityDamageByEntityEvent) event).getDamager() instanceof Arrow && event.getEntity() instanceof Horse){
		Arrow a = (Arrow)((EntityDamageByEntityEvent) event).getDamager();
		if(a.getShooter() instanceof Player){
			Player p = (Player)a.getShooter();
			Horse h = (Horse)event.getEntity();
			
		}
		
	}
  }
	
}





}<commit_msg>Add protection from player shot arrows<commit_after>package com.ekstemicraft.plugin.echorses;

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Server;
import org.bukkit.entity.AnimalTamer;
import org.bukkit.entity.Arrow;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Horse;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.event.entity.EntityTameEvent;
import org.bukkit.event.entity.ProjectileHitEvent;
import org.bukkit.event.vehicle.VehicleEnterEvent;

public class ECHorsesListeners implements Listener {
		
@EventHandler
	public void horseEnter(VehicleEnterEvent event){
	
	if(event.getVehicle() instanceof Horse){

      EntityType entered = (EntityType)event.getEntered().getType();
      if(entered == EntityType.PLAYER){ //Playercheck
    	  
    	  Player p = (Player)event.getEntered();
    	  String playername = p.getName();
    	  @SuppressWarnings("unused")
		Server server = p.getServer(); //Not used for now
          Horse h = (Horse)event.getVehicle();
          AnimalTamer owner = h.getOwner();
          if(!(owner == null)){
        	  
        	  if(p.isOp() && p.hasPermission("echorse.override")){ //Overriding the protection if player is OP
        		  return;
        	  }
        	  if(h.getOwner().getName() == p.getName()){ //Checking if entering player is the owner
        	  return;
        	  }
        	  else {
        		  p.sendMessage(ChatColor.AQUA + "[ECHorses]" + ChatColor.RED + " This horse is owned by " + h.getOwner().getName());
        		  Bukkit.getLogger().info("[ECHorses] " + playername + "tried entering someone elses horse");
        		  event.setCancelled(true);
        		  return;
        	  }
          } 
       p.sendMessage(ChatColor.AQUA + "[ECHorses]" + ChatColor.GREEN + " This horse is untamed!"); 
      }	
		
	}
}
@EventHandler
public void horseTameEvent(EntityTameEvent event){
     
	 if(event.getEntityType() == EntityType.HORSE){
		 Player p = (Player)event.getOwner();
		 p.sendMessage(ChatColor.AQUA + "[ECHorses]" + ChatColor.GREEN + " You have succesfully protected this horse!");
		 
	 }	
}
@EventHandler
public void horseDamageByEntity(EntityDamageByEntityEvent event){
	if(event.getEntityType() == EntityType.HORSE){
		Horse h = (Horse)event.getEntity();
		
		//Handle arrow shots from players
		if(event.getDamager().getType() == EntityType.ARROW){ //Arrowcheck
			Arrow a = (Arrow)event.getDamager();
			if(a.getShooter() instanceof Player){
				if(h.getOwner() == null){
					return;
				}
				event.setCancelled(true);
				return;
			}
		}
		
		//Handle melee attack direct from player
		if(event.getDamager().getType() == EntityType.PLAYER){ //Playercheck
			Player p = (Player)event.getDamager();
             
			if(p.isOp() || p.hasPermission("echorse.override") || h.getOwner() == null){ //Op & permission check & if horse isnt tamed.
				return;
			}
			 if(!(h.getOwner().getName() == p.getName())){ //If its not the horse owner, cancel the event
				 event.setCancelled(true);
				 p.sendMessage(ChatColor.AQUA + "[ECHorses]" + ChatColor.RED + " You dont have permission to hurt " + h.getOwner().getName() + "s horse!" );
				 return;
			 }
		}		
	return;	
	}	
}






}
{'fraction_non_alphanumeric': 0.13320135746606335, 'fraction_numerical': 0.0, 'mean_word_length': 3.3499384993849937, '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': '3140784', 'n_tokens_mistral': 2470, 'n_tokens_neox': 2277, 'n_words': 454}