<commit_before>package de.philworld.bukkit.compassex;

import java.util.List;

import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

public class CompassExCommandExecutor implements CommandExecutor {

	private CompassEx plugin;

	public CompassExCommandExecutor(CompassEx plugin) {
		this.plugin = plugin;
	}

	@Override
	public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {

		// Determine if the sender is a player (and an op), or the console.
		boolean isPlayer  = (sender instanceof Player);

		// Cast the sender to Player if possible.
		Player p = (isPlayer) ? (Player) sender : null;

		// no usage from the console cuz we use the player all the time.
		if(!isPlayer) {
			sender.sendMessage("Please only use in game!");
			return true;
		}


		if (args.length == 0) {
			return false;
		}


		// Grab the command base and any arguments.
		String base = args[0].toLowerCase();
		String arg1 = (args.length > 1) ? args[1].toLowerCase() : "";
		String arg2 = (args.length > 2) ? args[2].toLowerCase() : "";
		String arg3 = (args.length > 3) ? args[3].toLowerCase() : "";


		// ------------------
		// RESET COMMAND
		// ------------------
		if(base.equalsIgnoreCase("reset") || base.equalsIgnoreCase("spawn")) {
			if(p.hasPermission("compassex.reset")) {

				CompassTrackerUpdater.removeWatcher(p);
				p.setCompassTarget(p.getWorld().getSpawnLocation());
				p.saveData();

				p.sendMessage(ChatColor.RED + "[CompassEx] Your compass has been reset to spawn.");
			} else {
				p.sendMessage(ChatColor.RED + "You don't have any permission to do that.");
			}

			return true;
		}

		// ------------------
		// HERE COMMAND
		// ------------------
		if(base.equalsIgnoreCase("here")) {

			if(p.hasPermission("compassex.here")) {

				CompassTrackerUpdater.removeWatcher(p);
				p.setCompassTarget(p.getLocation());
				p.saveData();

				p.sendMessage(ChatColor.RED + "[CompassEx] Your compass has been set to here.");
			} else {
				p.sendMessage(ChatColor.RED + "You don't have any permission to do that.");
			}

			return true;
		}


		// ------------------
		// LIVE COMMAND
		// ------------------
		if(base.equalsIgnoreCase("live")) {
			if(p.hasPermission("compassex.live")) {

				List<Player> foundPlayers = plugin.getServer().matchPlayer(arg1);

				if (foundPlayers.size() == 1)
				{
					Player target = foundPlayers.get(0);

					// If the player is hidden dont track it. But only if the
					// user has no admin rights.
					if (isHidden(target) && !(p.hasPermission("compassex.admin"))) {
						p.sendMessage(ChatColor.RED + "[CompassEx] Player cannot be found.");
						return true;
					}

					CompassTrackerUpdater.setWatcher(p, target);

					p.sendMessage(ChatColor.RED + "[CompassEx] Your compass is now pointing live to " + target.getDisplayName() + ".");

				}
				else
				{
					p.sendMessage(ChatColor.RED + "[CompassEx] Player cannot be found.");
				}
			} else {
				p.sendMessage(ChatColor.RED + "You don't have any permission to do that.");
			}

			return true;
		}

		// ------------------
		// HEIGHT COMMAND
		// ------------------
		if(base.equalsIgnoreCase("h") || base.equalsIgnoreCase("height")) {
			if(p.hasPermission("compassex.height")) {				
				int diff = (int) Math.ceil(p.getCompassTarget().getBlockY() - p.getLocation().getY());
				
				p.sendMessage(ChatColor.RED + "[CompassEx] Height difference between you and your compass target: " + diff + " blocks.");
			} else {
				p.sendMessage(ChatColor.RED + "You don't have any permission to do that.");
			}
			return true;
		}

		// ------------------
		// HIDE COMMAND
		// ------------------
		if(base.equalsIgnoreCase("hide")) {

			if(p.hasPermission("compassex.hide")) {
				if(!isHidden(p)) {
					hide(p);
					p.sendMessage(ChatColor.RED + "[CompassEx] You are now hidden.");
				} else {
					unHide(p);
					p.sendMessage(ChatColor.RED + "[CompassEx] You are now visible again.");
				}
			} else {
				p.sendMessage(ChatColor.RED + "You don't have any permission to do that.");
			}

			return true;
		}


		// ------------------
		// HIDDEN COMMAND
		// ------------------
		if(base.equalsIgnoreCase("hidden")) {
			if(p.hasPermission("compassex.hide")) {
				if(isHidden(p)) {
					p.sendMessage(ChatColor.RED + "[CompassEx] You are hidden right now.");
				} else {
					p.sendMessage(ChatColor.RED + "[CompassEx] You are trackable right now.");
				}
			} else {
				p.sendMessage(ChatColor.RED + "You don't have any permission to do that.");
			}

			return true;
		}
		
		// ------------------
		// DEATH POINT COMMAND
		// ------------------
		if(base.equalsIgnoreCase("deathpoint") || base.equalsIgnoreCase("dp") || base.equalsIgnoreCase("death")) {
			if(p.hasPermission("compassex.deathpoint")) {
				CompassTrackerUpdater.removeWatcher(p);
				Location deathPoint = plugin.deathPoints.get(p.getName());
				p.setCompassTarget(deathPoint);
				p.saveData();
			} else {
				p.sendMessage(ChatColor.RED + "You don't have any permission to do that.");
			}

			return true;
		}
		
		// ------------------
		// POS COMMAND
		// ------------------
		// in addition to /compass pos <x> <y> <z>, it also allows /compass <x> <y> <z>
		if(base.equalsIgnoreCase("pos") || arg2 != "") {

			if(p.hasPermission("compassex.pos")) {
				
				int x; int y; int z;
				try {
					if(base.equalsIgnoreCase("pos")) {
						
						if(arg3 == "") {<commit_msg>Fixed bug in deathpoint command<commit_after>package de.philworld.bukkit.compassex;

import java.util.List;

import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

public class CompassExCommandExecutor implements CommandExecutor {

	private CompassEx plugin;

	public CompassExCommandExecutor(CompassEx plugin) {
		this.plugin = plugin;
	}

	@Override
	public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {

		// Determine if the sender is a player (and an op), or the console.
		boolean isPlayer  = (sender instanceof Player);

		// Cast the sender to Player if possible.
		Player p = (isPlayer) ? (Player) sender : null;

		// no usage from the console cuz we use the player all the time.
		if(!isPlayer) {
			sender.sendMessage("Please only use in game!");
			return true;
		}


		if (args.length == 0) {
			return false;
		}


		// Grab the command base and any arguments.
		String base = args[0].toLowerCase();
		String arg1 = (args.length > 1) ? args[1].toLowerCase() : "";
		String arg2 = (args.length > 2) ? args[2].toLowerCase() : "";
		String arg3 = (args.length > 3) ? args[3].toLowerCase() : "";


		// ------------------
		// RESET COMMAND
		// ------------------
		if(base.equalsIgnoreCase("reset") || base.equalsIgnoreCase("spawn")) {
			if(p.hasPermission("compassex.reset")) {

				CompassTrackerUpdater.removeWatcher(p);
				p.setCompassTarget(p.getWorld().getSpawnLocation());
				p.saveData();

				p.sendMessage(ChatColor.RED + "[CompassEx] Your compass has been reset to spawn.");
			} else {
				p.sendMessage(ChatColor.RED + "You don't have any permission to do that.");
			}

			return true;
		}

		// ------------------
		// HERE COMMAND
		// ------------------
		if(base.equalsIgnoreCase("here")) {

			if(p.hasPermission("compassex.here")) {

				CompassTrackerUpdater.removeWatcher(p);
				p.setCompassTarget(p.getLocation());
				p.saveData();

				p.sendMessage(ChatColor.RED + "[CompassEx] Your compass has been set to here.");
			} else {
				p.sendMessage(ChatColor.RED + "You don't have any permission to do that.");
			}

			return true;
		}


		// ------------------
		// LIVE COMMAND
		// ------------------
		if(base.equalsIgnoreCase("live")) {
			if(p.hasPermission("compassex.live")) {

				List<Player> foundPlayers = plugin.getServer().matchPlayer(arg1);

				if (foundPlayers.size() == 1)
				{
					Player target = foundPlayers.get(0);

					// If the player is hidden dont track it. But only if the
					// user has no admin rights.
					if (isHidden(target) && !(p.hasPermission("compassex.admin"))) {
						p.sendMessage(ChatColor.RED + "[CompassEx] Player cannot be found.");
						return true;
					}

					CompassTrackerUpdater.setWatcher(p, target);

					p.sendMessage(ChatColor.RED + "[CompassEx] Your compass is now pointing live to " + target.getDisplayName() + ".");

				}
				else
				{
					p.sendMessage(ChatColor.RED + "[CompassEx] Player cannot be found.");
				}
			} else {
				p.sendMessage(ChatColor.RED + "You don't have any permission to do that.");
			}

			return true;
		}

		// ------------------
		// HEIGHT COMMAND
		// ------------------
		if(base.equalsIgnoreCase("h") || base.equalsIgnoreCase("height")) {
			if(p.hasPermission("compassex.height")) {				
				int diff = (int) Math.ceil(p.getCompassTarget().getBlockY() - p.getLocation().getY());
				
				p.sendMessage(ChatColor.RED + "[CompassEx] Height difference between you and your compass target: " + diff + " blocks.");
			} else {
				p.sendMessage(ChatColor.RED + "You don't have any permission to do that.");
			}
			return true;
		}

		// ------------------
		// HIDE COMMAND
		// ------------------
		if(base.equalsIgnoreCase("hide")) {

			if(p.hasPermission("compassex.hide")) {
				if(!isHidden(p)) {
					hide(p);
					p.sendMessage(ChatColor.RED + "[CompassEx] You are now hidden.");
				} else {
					unHide(p);
					p.sendMessage(ChatColor.RED + "[CompassEx] You are now visible again.");
				}
			} else {
				p.sendMessage(ChatColor.RED + "You don't have any permission to do that.");
			}

			return true;
		}


		// ------------------
		// HIDDEN COMMAND
		// ------------------
		if(base.equalsIgnoreCase("hidden")) {
			if(p.hasPermission("compassex.hide")) {
				if(isHidden(p)) {
					p.sendMessage(ChatColor.RED + "[CompassEx] You are hidden right now.");
				} else {
					p.sendMessage(ChatColor.RED + "[CompassEx] You are trackable right now.");
				}
			} else {
				p.sendMessage(ChatColor.RED + "You don't have any permission to do that.");
			}

			return true;
		}
		
		// ------------------
		// DEATH POINT COMMAND
		// ------------------
		if(base.equalsIgnoreCase("deathpoint") || base.equalsIgnoreCase("dp") || base.equalsIgnoreCase("death")) {
			if(p.hasPermission("compassex.deathpoint")) {
				CompassTrackerUpdater.removeWatcher(p);
				
				Location deathPoint = plugin.deathPoints.get(p.getName());
				if(deathPoint == null) {
					p.sendMessage(ChatColor.RED + "[CompassEx] Could not find your latest death point.");
					return true;
				}
				p.setCompassTarget(deathPoint);
				p.saveData();
			} else {
				p.sendMessage(ChatColor.RED + "You don't have any permission to do that.");
			}

			return true;
		}
		
		// ------------------
		// POS COMMAND
		// ------------------
		// in addition to /compass pos <x> <y> <z>, it also allows /compass <x> <y> <z>
		if(base.equalsIgnoreCase("pos") || arg2 != "") {

			if(p.hasPermission("compassex.pos")) {
				
				int x; int y; int z;
				try {
					if(base.equalsIgnoreCase("pos")) {
						
						if(arg3 == "") {
{'fraction_non_alphanumeric': 0.19082957858468064, 'fraction_numerical': 0.0028271048679211945, 'mean_word_length': 2.4916718075262185, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 23, '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': '4043554', 'n_tokens_mistral': 4313, 'n_tokens_neox': 3509, 'n_words': 829}