<commit_before>package uk.co.drnaylor.antipotionfield;

import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.ChatColor;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import uk.co.drnaylor.antipotionfield.worldguardapi.WorldGuardAPIException;
import uk.co.drnaylor.antipotionfield.worldguardapi.WorldGuardAPIException.WorldGuardExceptions;
import uk.co.drnaylor.antipotionfield.worldguardapi.WorldGuardInterface;

/**
 * This class is currently being renovated to account for new changes.
 */
@Deprecated
public class CommandsExecWG implements CommandExecutor {

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

		if (cmd.getName().equalsIgnoreCase("antipotionregion")) {
			//No parameters, 
			boolean perm;
			if (sender instanceof Player) {
				//Do we have config perms?
				if (sender.hasPermission("antipotionfield.regions") || sender.isOp()) {
					perm = true;
				} else {
					perm = false;
				}
			} 
			else {
				perm = true;
			} //console!

			if (!perm) {
				sender.sendMessage(ChatColor.RED + "Sorry, but you don't have permission to do that!");
				return true;
			}

			/*
			 * New command syntax:
			 * /antipotionregion <region> <allow|deny> <potion|positive|negative|all> [type]
			 * 
			 * <region> is the region name; <allow|deny> specifies whether to allow or deny the potion;
			 * <potion> is the effect type (or predefined list of types); [type] is optional and defines whether the potion is splash, drink, or effect.
			 * If [type] isn't provided, the plugin will assume that it must be allowed or denied for all types.
			 */

			if (args.length == 0) { // No arguments provided!
				sender.sendMessage(ChatColor.GREEN + "Usage: " + ChatColor.YELLOW + "/antipotionregion <region> <allow|deny>");	
			
			} else if (args.length == 1) { // They have written something like "/antipotionregion <region>".
				
				try {
					WorldGuardInterface wgi = new WorldGuardInterface();
					List<World> worlds;
					if (sender instanceof Player) {
						Player player = ((Player) sender).getPlayer();
						World world = player.getWorld();
						worlds = new ArrayList<World>();
						worlds.add(world);
					} else {
						worlds = AntiPotionField.plugin.getServer().getWorlds();
					}

					for (World world : worlds) {
						ProtectedRegion rg = wgi.getRegion(world, args[0]);
						if (rg != null) { // If the region exists...
							if (AntiPotionField.regions.getRegionConfig().getConfig().isConfigurationSection("no-potion-effect-regions." + args[0])) {
								// If a section for this region exists in the configuration file...
								sender.sendMessage(ChatColor.YELLOW + "This region denies the following effects and types:");

								String ef1 = ChatColor.YELLOW + "Denied effects: " + ChatColor.GRAY;
								String ef2 = ChatColor.YELLOW + "Denied potions: " + ChatColor.GRAY;
								String ef3 = ChatColor.YELLOW + "Denied splashes: " + ChatColor.GRAY;

								for (List<String> s1 : AntiPotionField.regions.getRegionConfig().getConfig().isConfigurationSection("no-potion-effect-regions." + args[0] + ".deny-effects")) {
									ef1.concat(s1 + ", ");
									// I realize this will end the list with a comma, but I can't be bothered to fix that right now...
								}
								for (List<String> s2 : AntiPotionField.regions.getRegionConfig().getConfig().isConfigurationSection("no-potion-effect-regions." + args[0] + ".deny-potions")) {
									ef2.concat(s2 + ", ");
								}
								for (List<String> s3 : AntiPotionField.regions.getRegionConfig().getConfig().isConfigurationSection("no-potion-effect-regions." + args[0] + ".deny-splashes")) {
									ef3.concat(s3 + ", ");
								}

								sender.sendMessage(ef1);
								sender.sendMessage(ef2);
								sender.sendMessage(ef3);

							} else {
								sender.sendMessage(ChatColor.YELLOW + "This region has no denied potions associated with it.");
							}
						} else {
							sender.sendMessage(ChatColor.YELLOW + "The region " + args[0] + " cannot be found.");
						}
					}


				} catch (WorldGuardAPIException e) {
					sender.sendMessage(ChatColor.YELLOW + "WorldGuard is not currently enabled!");
				}
			
			} else if (args.length == 2) {
				// /antipotionregion region allow? Not enough now!
				// For a player, anyways. I'll add console compatibilities for region checking later.
				
				if (!(sender instanceof Player)) {
					sender.sendMessage("Console usage isn't quite supported yet!");
					return true;
				} else {
					sender.sendMessage(ChatColor.RED + "Too few arguments!");
					sender.sendMessage(ChatColor.GREEN + "Usage: " + ChatColor.YELLOW + "/antipotionregion <region> <allow|deny> <potion|positive|negative|all> [type]");	
					return true;
				}
			} else if (args.length >= 3) { // If they provide the region, allow|deny, an effect, and a possible type
				
				// If there's a fourth argument, use it to get the effect type.
				// Otherwise, just apply it to every compatible list!
				<commit_msg>More command development.<commit_after>package uk.co.drnaylor.antipotionfield;

import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.ChatColor;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import uk.co.drnaylor.antipotionfield.worldguardapi.WorldGuardAPIException;
import uk.co.drnaylor.antipotionfield.worldguardapi.WorldGuardAPIException.WorldGuardExceptions;
import uk.co.drnaylor.antipotionfield.worldguardapi.WorldGuardInterface;

/**
 * This class is currently being renovated to account for new changes.
 */
@Deprecated
public class CommandsExecWG implements CommandExecutor {

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

		if (cmd.getName().equalsIgnoreCase("antipotionregion")) {
			//No parameters, 
			boolean perm;
			if (sender instanceof Player) {
				//Do we have config perms?
				if (sender.hasPermission("antipotionfield.regions") || sender.isOp()) {
					perm = true;
				} else {
					perm = false;
				}
			} 
			else {
				perm = true;
			} //console!

			if (!perm) {
				sender.sendMessage(ChatColor.RED + "Sorry, but you don't have permission to do that!");
				return true;
			}

			/*
			 * New command syntax:
			 * /antipotionregion <region> <allow|deny> <potion|positive|negative|all> [type]
			 * 
			 * <region> is the region name; <allow|deny> specifies whether to allow or deny the potion;
			 * <potion> is the effect type (or predefined list of types); [type] is optional and defines whether the potion is splash, drink, or effect.
			 * If [type] isn't provided, the plugin will assume that it must be allowed or denied for all types.
			 */

			if (args.length == 0) { // No arguments provided!
				sender.sendMessage(ChatColor.GREEN + "Usage: " + ChatColor.YELLOW + "/antipotionregion <region> <allow|deny>");	
			
			} else if (args.length == 1) { // They have written something like "/antipotionregion <region>".
				
				try {
					WorldGuardInterface wgi = new WorldGuardInterface();
					List<World> worlds;
					if (sender instanceof Player) {
						Player player = ((Player) sender).getPlayer();
						World world = player.getWorld();
						worlds = new ArrayList<World>();
						worlds.add(world);
					} else {
						worlds = AntiPotionField.plugin.getServer().getWorlds();
					}

					for (World world : worlds) {
						ProtectedRegion rg = wgi.getRegion(world, args[0]);
						if (rg != null) { // If the region exists...
							if (AntiPotionField.regions.getRegionConfig().getConfig().isConfigurationSection("no-potion-effect-regions." + args[0])) {
								// If a section for this region exists in the configuration file...
								sender.sendMessage(ChatColor.YELLOW + "This region denies the following effects and types:");

								String ef1 = ChatColor.YELLOW + "Denied effects: " + ChatColor.GRAY;
								String ef2 = ChatColor.YELLOW + "Denied potions: " + ChatColor.GRAY;
								String ef3 = ChatColor.YELLOW + "Denied splashes: " + ChatColor.GRAY;

								for (List<String> s1 : AntiPotionField.regions.getRegionConfig().getConfig().isConfigurationSection("no-potion-effect-regions." + args[0] + ".deny-effects")) {
									ef1.concat(s1 + ", ");
									// I realize this will end the list with a comma, but I can't be bothered to fix that right now...
								}
								for (List<String> s2 : AntiPotionField.regions.getRegionConfig().getConfig().isConfigurationSection("no-potion-effect-regions." + args[0] + ".deny-potions")) {
									ef2.concat(s2 + ", ");
								}
								for (List<String> s3 : AntiPotionField.regions.getRegionConfig().getConfig().isConfigurationSection("no-potion-effect-regions." + args[0] + ".deny-splashes")) {
									ef3.concat(s3 + ", ");
								}

								sender.sendMessage(ef1);
								sender.sendMessage(ef2);
								sender.sendMessage(ef3);

							} else {
								sender.sendMessage(ChatColor.YELLOW + "This region has no denied potions associated with it.");
							}
						} else {
							sender.sendMessage(ChatColor.YELLOW + "The region " + args[0] + " cannot be found.");
						}
					}


				} catch (WorldGuardAPIException e) {
					sender.sendMessage(ChatColor.YELLOW + "WorldGuard is not currently enabled!");
				}
			
			} else if (args.length == 2) {
				// /antipotionregion region allow? Not enough now!
				// For a player, anyways. I'll add console compatibilities for region checking later.
				
				if (!(sender instanceof Player)) {
					sender.sendMessage("Console usage isn't quite supported yet!");
					return true;
				} else {
					sender.sendMessage(ChatColor.RED + "Too few arguments!");
					sender.sendMessage(ChatColor.GREEN + "Usage: " + ChatColor.YELLOW + "/antipotionregion <region> <allow|deny> <potion|positive|negative|all> [type]");	
					return true;
				}
			} else if (args.length >= 3) { // If they provide the region, allow|deny, an effect, and a possible type
				
				try {
					WorldGuardInterface wgi = new WorldGuardInterface();
					World world = null;
					ProtectedRegion rg;
					int argsOffset = 0;
					
					if (!(sender instanceof Player)) {
						// The console must supply a world, so they must have four arguments (optionally five).
						// /antipotionregion worldName regionName potionEffect type
						if (args.length > 3) { // If the console provided at least four arguments...
							argsOffset = 0;
							
							// args[0] should be the world.
							world = sender.getServer().getWorld(args[0]);
							if (world == null) {
								sender.sendMessage(ChatColor.RED + "World " + args[0] + " doesn't exist!");
								return true;
							}
							
						} else {
							sender.sendMessage(ChatColor.YELLOW + "Hey, Console! We need the world name as well!");
							sender.sendMessage(ChatColor.GREEN + "/antipotionregion <world> <region> <allow|deny> <potion> [type]");
							return true;
						}
					} else { // The command sender is a Player.
						argsOffset = 1;
						Player player = (Player)sender;
						world = player.getWorld();
						if (world == null) { // Just in case.
							sender.sendMessage(ChatColor.RED + "You're apparently not in a world!");
							return true;
						}
					}
					
					rg = wgi.getRegion(world, args[1 - argsOffset]); // The region name is args[0] for the player, or args[1] for the console.
					
					if (rg != null) { // If the region exists...
						
						String configPath = "no-potion-effect-regions." + args[1 - argsOffset];
						if (!(AntiPotionField.regions.getRegionConfig().getConfig().isConfigurationSection(configPath))) {
							
							/*
							If this region has no configuration section in the config, set the following paths:
							
							"no-potion-effect-regions." + args[1 - argsOffset] + ".deny-effects"
							"no-potion-effect-regions." + args[1 - argsOffset] + ".deny-potions"
							"no-potion-effect-regions." + args[1 - argsOffset] + ".deny-splash"
							
							Then save the configuration.
							*/
							
						}
						
						// Get whether we're adding or removing from the list!
						boolean deny;
						if (args[2 - argsOffset].equalsIgnoreCase("allow") || args[2 - argsOffset].equalsIgnoreCase("a")) {
							deny = false;
						} else if (args[2 - argsOffset].equalsIgnoreCase("deny") || args[2 - argsOffset].equalsIgnoreCase("d")) {
							deny = true;
						}
						
						
						// Get the potion type through the Util class using args[3 - argsOffset]
						
						
						
						// If there's a fourth (or fifth) argument, use it to get the effect type. (args[4 - argsOffset])
						// Otherwise, just apply it to every compatible list!
						boolean addToAll;
						if (args.length == (4 - argsOffset)) {
							if (args[4 - argsOffset].equalsIgnoreCase("EFFECT")) {
								configPath.concat(".deny-effects");
								addToAll = false;
							} else if (args[4 - argsOffset].equalsIgnoreCase("POTION")) {
								configPath.concat(".deny-potions");
								addToAll = false;
							} else if (args[4 - argsOffset].equalsIgnoreCase("SPLASH")) {
								configPath.concat(".deny-splash");
								addToAll = false;
							}
						} else {
							addToAll = true; // Add it to every region.
						}
						
						
						// We should have everything we need at this point.
						
						
						
						
						
					} else {
						sender.sendMessage(ChatColor.RED + "The region " + args[1 - argsOffset] + " does not exist!");
						return true;
					}
					
					
					
				} catch (WorldGuardAPIException error) {
					sender.sendMessage(ChatColor.DARK_RED + "WorldGuard is not currently enabled!");
					return true;
				}
{'fraction_non_alphanumeric': 0.12367516470925237, 'fraction_numerical': 0.005657404755084503, 'mean_word_length': 2.8428728673637864, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 44, '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': '678076', 'n_tokens_mistral': 5514, 'n_tokens_neox': 4049, 'n_words': 1122}