<commit_before>package net.simpvp.Misc;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;

public class DisableCmd implements Listener {
	/* Disables all commands in the disabled.txt file
	 * Adapted from PlgDisableCmd by Plague
	 */

	private static List<String> disabledCmds;

	private static List<String> opOnlyCmds;

	private Player player;

	@EventHandler(priority=EventPriority.HIGHEST,ignoreCancelled=true)
	public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
		String[] split = event.getMessage().split(" ");
		if (split.length < 1)
			return;

		String cmd = split[0].trim().substring(1).toLowerCase();

		player = event.getPlayer();

		if (Collections.binarySearch(disabledCmds, cmd) >= 0 ) {
			disable_event(event, "Blocked command found in disabledCmds.txt");

		} else if (Collections.binarySearch(opOnlyCmds, cmd) >= 0 && !player.isOp()) {
			disable_event(event, "Blocked command found in opOnlyCmds.txt");
		} else if (cmd.contains(":")) {
			disable_event(event, "Blocked command that contained :");
		}

	}

	private void disable_event(PlayerCommandPreprocessEvent event, String blocked_message) {
		event.getPlayer().sendMessage("Unknown command. Type \"/help\" for help.");
		Misc.instance.getLogger().info(blocked_message);
		event.setCancelled(true);
	}

	public static void loadDisabledCmds() {

		/* Adds disabled cmds to disabledCmds array <commit_msg>DisableCmd: Also block Commnad Blocks<commit_after>package net.simpvp.Misc;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import org.bukkit.Bukkit;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.server.ServerCommandEvent;

public class DisableCmd implements Listener {
	/* Disables all commands in the disabled.txt file
	 * Adapted from PlgDisableCmd by Plague
	 */

	private static List<String> disabledCmds;

	private static List<String> opOnlyCmds;

	private Player player;

	@EventHandler(priority=EventPriority.HIGHEST,ignoreCancelled=true)
	public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
		String[] split = event.getMessage().split(" ");
		if (split.length < 1)
			return;

		String cmd = split[0].trim().substring(1).toLowerCase();

		player = event.getPlayer();

		if (Collections.binarySearch(disabledCmds, cmd) >= 0 ) {
			disable_event(event, "Blocked command found in disabledCmds.txt");

		} else if (Collections.binarySearch(opOnlyCmds, cmd) >= 0 && !player.isOp()) {
			disable_event(event, "Blocked command found in opOnlyCmds.txt");
		} else if (cmd.contains(":")) {
			disable_event(event, "Blocked command that contained :");
		}

	}

	@EventHandler(priority=EventPriority.HIGHEST,ignoreCancelled=true)
	public void onServerCommandEvent(ServerCommandEvent event) {
		if (event.getSender() instanceof ConsoleCommandSender) {
			Misc.instance.getLogger().info("console");
			return;
		}

		String[] split = event.getCommand().split(" ");
		if (split.length < 1) {
			return;
		}

		String cmd = split[0].trim().toLowerCase();

		if (Collections.binarySearch(disabledCmds, cmd) >= 0) {
			event.getSender().sendMessage("You do not have permission to use this command.");
			Misc.instance.getLogger().info("Blocked commanad '" + cmd + "' found in disabledCmds.txt");
			event.setCancelled(true);
		} else if (cmd.contains(":")) {
			event.getSender().sendMessage("You do not have permission to use this command.");
			Misc.instance.getLogger().info("Blocked commanad '" + cmd + "' that contained :");
			event.setCancelled(true);
		}
	}

	private void disable_event(PlayerCommandPreprocessEvent event, String blocked_message) {
		event.getPlayer().sendMessage("Unknown command. Type \"/help\" for help.");
		Misc.instance.getLogger().info(blocked_message);
		event.setCancelled(true);
	}

	public static void loadDisabledCmds() {

		/* Adds disabled cmds to disabledCmds array 
{'fraction_non_alphanumeric': 0.12322695035460993, 'fraction_numerical': 0.002881205673758865, 'mean_word_length': 5.165300546448087, 'pattern_counts': {'":': 3, '<': 10, '<?xml version=': 0, '>': 12, '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': '3511859', 'n_tokens_mistral': 1488, 'n_tokens_neox': 1394, 'n_words': 317}