<commit_before>package me.jacobcrofts.simplestructureloader.commands;

import java.io.IOException;

import org.bukkit.GameMode;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

import me.jacobcrofts.simplestructureloader.api.StructureAPI;
import me.jacobcrofts.simplestructureloader.managers.SelectionManager;
import me.jacobcrofts.simplestructureloader.util.Selection;

public class CmdSave implements CommandExecutor {
	
	private SelectionManager manager;
	
	public CmdSave(SelectionManager manager) {
		this.manager = manager;
	}

	@Override
	public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
		
		if (sender instanceof Player) {
			Player player = (Player) sender;
			
			if (player.getGameMode() != GameMode.CREATIVE) {
				return false;
			}
			
			if (!(player.isOp() || player.hasPermission("simple-structures.ALL"))) {
				return false;
				// TODO: custom error messages
			}
			
			Selection selection = this.manager.getSelection(player);
			selection.saveCurrentSelection();
			try {
				StructureAPI.writeToFile(args[0], selection);
			} catch (IOException e) {
				e.printStackTrace();
				return false;
			}
			
			return true;
			
		}
		
		return false;
	}

}<commit_msg>Add feature: custom error messages<commit_after>package me.jacobcrofts.simplestructureloader.commands;

import java.io.IOException;

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

import me.jacobcrofts.simplestructureloader.api.StructureAPI;
import me.jacobcrofts.simplestructureloader.managers.SelectionManager;
import me.jacobcrofts.simplestructureloader.util.Selection;

public class CmdSave implements CommandExecutor {
	
	private SelectionManager manager;
	
	public CmdSave(SelectionManager manager) {
		this.manager = manager;
	}

	@Override
	public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
		
		if (sender instanceof Player) {
			Player player = (Player) sender;
			
			if (player.getGameMode() != GameMode.CREATIVE) {
				player.sendMessage(ChatColor.RED + "You must be in creative mode to execute this command.");
				return true;
			}
			
			if (!(player.isOp() || player.hasPermission("simple-structures.ALL"))) {
				player.sendMessage(ChatColor.RED + "You do not have permission to perform this command.");
				return true;
			}
			
			Selection selection = this.manager.getSelection(player);
			selection.saveCurrentSelection();
			
			try {
				StructureAPI.writeToFile(args[0], selection);
			} catch (IOException e) {
				e.printStackTrace();
				player.sendMessage(ChatColor.RED + "Something went wrong whe we tried to write your structure to a file.");
			}
			
			return true;
			
		}
		
		System.out.println("Command must be executed by a Player.");
		return false;
	}

}
{'fraction_non_alphanumeric': 0.10105332455562871, 'fraction_numerical': 0.0006583278472679394, 'mean_word_length': 4.248704663212435, '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': '936470', 'n_tokens_mistral': 1060, 'n_tokens_neox': 866, 'n_words': 208}