<commit_before>/*
 * Copyright 2015 CrystalCraftMC
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */
 
 package com.crystalcraftmc.iceball;

import java.util.ArrayList;

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.entity.Snowball;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.entity.ProjectileLaunchEvent;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerLoginEvent;
import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;

public class IceBallListener implements Listener {
	private IceBall plugin;
	private String[] nonOpBuildPerms = {"todd5747"}; //will add Jwood and Teth after testing 4 testing
	private ArrayList<HitStreak> al = new ArrayList<HitStreak>();
	private ItemStack officialIceBall;
	public IceBallListener(IceBall ib) {
		plugin = ib;
		plugin.getServer().getPluginManager().registerEvents(this, plugin);
		
		officialIceBall = new ItemStack(Material.SNOW_BALL, 2);
		ItemMeta im = officialIceBall.getItemMeta();
		im.addEnchant(Enchantment.ARROW_INFINITE, 1, false);
		im.setDisplayName("Ice_Ball");
		ArrayList<String> alLore = new ArrayList<String>();
		alLore.add(ChatColor.RED + "Snow Dug From");
		alLore.add(ChatColor.GOLD + "Plastic Beach");
		im.setLore(alLore);
		officialIceBall.setItemMeta(im);
	}
	@EventHandler (priority=EventPriority.LOWEST)
	public void stopCommands(PlayerCommandPreprocessEvent e) {
		Player p = e.getPlayer();
		if(e.getMessage().equalsIgnoreCase("/snowfight")) {
			if(!this.isOutsideArena(p, 33, false)) {
				p.sendMessage(ChatColor.RED + "Error; you must be off the snowball-arena's premises " +
							"to use /snowfight");
			}
			else {
				if(this.hasEmptyInventory(p)) {
					new DelayedTeleport(plugin, p);
				}
				else {
					p.sendMessage(ChatColor.RED + "Error; your inventory must be empty in order to" +
							" use this command. Armor slots included.");
				}
			}
		}
		else if(e.getMessage().equalsIgnoreCase("/snowleave")) {
			if(!this.isOutsideArena(p, 21, true)) {
				p.getInventory().clear();
				for(int i = 0; i < al.size(); i++) {
					if(al.get(i).getName().equals(p.getName()))
						al.remove(i);
				}
				this.teleportToSpawn(p);
			}
			else {
				p.sendMessage(ChatColor.RED + "Error; you must be inside the snowball arena to use" +
						" this command.");
			}
		}
		else if(!this.isOutsideArena(p, 33, false) && !this.hasBuildPermission(p) && !p.isOp()) {
			p.sendMessage(ChatColor.RED + "Error; only command allowed at the " + ChatColor.AQUA +
					"CCMC " + ChatColor.RED + "SnowBall arena is: \"" +
					ChatColor.GOLD + "/snowleave" + ChatColor.RED + "\" which will tp you to spawn.");
			e.setCancelled(true);
		}
	}
	@EventHandler
	public void resetStatsOnLogIn(PlayerLoginEvent e) {
		Player p = e.getPlayer();
			for(int i = 0; i < al.size(); i++) {
				if(al.get(i).getName().equals(p.getName()))
					al.remove(i);
			}
		
	}
	@EventHandler
	public void cancelBlockPlace(BlockPlaceEvent e) {
		Player p = e.getPlayer();
		if(!this.isOutsideArena(p, 33, false)) {
			if(p.isOp() || this.hasBuildPermission(p)) {}
			else {
				e.getPlayer().sendMessage(ChatColor.GOLD + "You do not have permission to place a block" +
						" at the " + ChatColor.AQUA + "CCMC " + ChatColor.GOLD + "SnowBall arena.");
				e.setCancelled(true);
			}
		}
	}
	@EventHandler
	public void resetOnDeath(PlayerDeathEvent e) {
		Player p = e.getEntity();
		for(int i = 0; i < al.size(); i++) {
			if(al.get(i).getName().equals(p.getName())) {
				al.remove(i);
			}
		}
	}
	@EventHandler
	public void noFallDeath(EntityDamageEvent e) {
		if(e.getEntity() instanceof Player) {
			Player p = (Player)e.getEntity();
			if(!this.isOutsideArena(p, 18, true)) {
				if(e.getCause().equals(DamageCause.FALL))
					e.setCancelled(true);
			}
		}
	}
	@EventHandler
	public void cancelBlockBreak(BlockBreakEvent e) {
		Player p = e.getPlayer();
		if(!this.isOutsideArena(p, 33, false)) {
			if(p.isOp() || this.hasBuildPermission(p)) {}
			else {
				e.getPlayer().sendMessage(ChatColor.GOLD + "You do not have permission to break that.");
				e.setCancelled(true);
			}
		}
	}
	@EventHandler (priority=EventPriority.LOW)
	public void cancelTP(PlayerTeleportEvent e) {
		if(!this.isOutsideArena(e.getPlayer(), 28, false)) {
			if(this.isOutsideArena(e.getPlayer(), 18, true)) {
				if(!e.getPlayer().isOp()) {
					e.getPlayer().sendMessage(ChatColor.RED + "Error; you don't have permission to" +
							" teleport here. " + ChatColor.GREEN + "PowerTool protection.");
					e.setCancelled(true);
				}
				else {
					e.getPlayer().sendMessage(ChatColor.GOLD + "op- granted access to tp in this zone.");
				}
			}
		}
	}
	public boolean hasBuildPermission(Player p) {
		for(String name : nonOpBuildPerms) {
			if(name.equalsIgnoreCase(p.getName()))
				return true;
		}
		return false;
	}
	public boolean isOutsideArena(Player p, int constant, boolean checkY) {<commit_msg>PT protection - cancel left click<commit_after>/*
 * Copyright 2015 CrystalCraftMC
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */
 
 package com.crystalcraftmc.iceball;

import java.util.ArrayList;

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.entity.Snowball;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.entity.ProjectileLaunchEvent;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerLoginEvent;
import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;

public class IceBallListener implements Listener {
	private IceBall plugin;
	private String[] nonOpBuildPerms = {"todd5747"}; //will add Jwood and Teth after testing 4 testing
	private ArrayList<HitStreak> al = new ArrayList<HitStreak>();
	private ItemStack officialIceBall;
	public IceBallListener(IceBall ib) {
		plugin = ib;
		plugin.getServer().getPluginManager().registerEvents(this, plugin);
		
		officialIceBall = new ItemStack(Material.SNOW_BALL, 2);
		ItemMeta im = officialIceBall.getItemMeta();
		im.addEnchant(Enchantment.ARROW_INFINITE, 1, false);
		im.setDisplayName("Ice_Ball");
		ArrayList<String> alLore = new ArrayList<String>();
		alLore.add(ChatColor.RED + "Snow Dug From");
		alLore.add(ChatColor.GOLD + "Plastic Beach");
		im.setLore(alLore);
		officialIceBall.setItemMeta(im);
	}
	@EventHandler (priority=EventPriority.LOWEST)
	public void stopCommands(PlayerCommandPreprocessEvent e) {
		Player p = e.getPlayer();
		if(e.getMessage().equalsIgnoreCase("/snowfight")) {
			if(!this.isOutsideArena(p, 33, false)) {
				p.sendMessage(ChatColor.RED + "Error; you must be off the snowball-arena's premises " +
							"to use /snowfight");
			}
			else {
				if(this.hasEmptyInventory(p)) {
					new DelayedTeleport(plugin, p);
				}
				else {
					p.sendMessage(ChatColor.RED + "Error; your inventory must be empty in order to" +
							" use this command. Armor slots included.");
				}
			}
		}
		else if(e.getMessage().equalsIgnoreCase("/snowleave")) {
			if(!this.isOutsideArena(p, 21, true)) {
				p.getInventory().clear();
				for(int i = 0; i < al.size(); i++) {
					if(al.get(i).getName().equals(p.getName()))
						al.remove(i);
				}
				this.teleportToSpawn(p);
			}
			else {
				p.sendMessage(ChatColor.RED + "Error; you must be inside the snowball arena to use" +
						" this command.");
			}
		}
		else if(!this.isOutsideArena(p, 33, false) && !this.hasBuildPermission(p) && !p.isOp()) {
			p.sendMessage(ChatColor.RED + "Error; only command allowed at the " + ChatColor.AQUA +
					"CCMC " + ChatColor.RED + "SnowBall arena is: \"" +
					ChatColor.GOLD + "/snowleave" + ChatColor.RED + "\" which will tp you to spawn.");
			e.setCancelled(true);
		}
	}
	@EventHandler
	public void resetStatsOnLogIn(PlayerLoginEvent e) {
		Player p = e.getPlayer();
			for(int i = 0; i < al.size(); i++) {
				if(al.get(i).getName().equals(p.getName()))
					al.remove(i);
			}
		
	}
	@EventHandler
	public void cancelBlockPlace(BlockPlaceEvent e) {
		Player p = e.getPlayer();
		if(!this.isOutsideArena(p, 33, false)) {
			if(p.isOp() || this.hasBuildPermission(p)) {}
			else {
				e.getPlayer().sendMessage(ChatColor.GOLD + "You do not have permission to place a block" +
						" at the " + ChatColor.AQUA + "CCMC " + ChatColor.GOLD + "SnowBall arena.");
				e.setCancelled(true);
			}
		}
	}
	@EventHandler
	public void resetOnDeath(PlayerDeathEvent e) {
		Player p = e.getEntity();
		for(int i = 0; i < al.size(); i++) {
			if(al.get(i).getName().equals(p.getName())) {
				al.remove(i);
			}
		}
	}
	@EventHandler
	public void noFallDeath(EntityDamageEvent e) {
		if(e.getEntity() instanceof Player) {
			Player p = (Player)e.getEntity();
			if(!this.isOutsideArena(p, 18, true)) {
				if(e.getCause().equals(DamageCause.FALL))
					e.setCancelled(true);
			}
		}
	}
	@EventHandler
	public void cancelBlockBreak(BlockBreakEvent e) {
		Player p = e.getPlayer();
		if(!this.isOutsideArena(p, 33, false)) {
			if(p.isOp() || this.hasBuildPermission(p)) {}
			else {
				e.getPlayer().sendMessage(ChatColor.GOLD + "You do not have permission to break that.");
				e.setCancelled(true);
			}
		}
	}
	@EventHandler (priority=EventPriority.LOW)
	public void cancelTP(PlayerTeleportEvent e) {
		if(!this.isOutsideArena(e.getPlayer(), 40, false)) {
			if(this.isOutsideArena(e.getPlayer(), 18, true)) {
				if(!e.getPlayer().isOp()) {
					e.getPlayer().sendMessage(ChatColor.RED + "Error; you don't have permission to" +
							" teleport here. " + ChatColor.GREEN + "PowerTool protection.");
					e.setCancelled(true);
				}
				else {
					e.getPlayer().sendMessage(ChatColor.GOLD + "op- granted access to tp in this zone.");
				}
			}
		}
	}
	@EventHandler
	public void ptProtection(PlayerInteractEvent e) {
		if(!this.isOutsideArena(e.getPlayer(), 40, false) && !e.getPlayer().isOp() &&
				(e.getAction() == Action.LEFT_CLICK_AIR || e.getAction() == Action.LEFT_CLICK_BLOCK)) {
			e.getPlayer().sendMessage(ChatColor.RED + "Error; you don't have permission to" +
					" left-click here. " + ChatColor.GREEN + "PowerTool protection.");
			e.setCancelled(true);
		}
	}
	public boolean hasBuildPermission(Player p) {
		for(String name : nonOpBuildPerms) {
			if(name.equalsIgnoreCase(p.getName()))
				return true;
		}
		return false;
	}
	public boolean isOutsideArena(Player p, int constant, boolean checkY) {
{'fraction_non_alphanumeric': 0.1350170756889842, 'fraction_numerical': 0.005559526646016996, 'mean_word_length': 3.949685534591195, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 11, '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': '416148', 'n_tokens_mistral': 4850, 'n_tokens_neox': 4207, 'n_words': 940}