package fr.aumgn.bukkitutils.util;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Locale;

import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;

import fr.aumgn.bukkitutils.itemtype.ItemTypeDataParser;

public final class Util {

    private static final Random RANDOM = new Random();

    private Util() {
    }

    public static Random getRandom() {
        return RANDOM;
    }

    public static <T> T pickRandom(List<T> from) {
        if (from.isEmpty()) {
            return null;
        }
        return from.get(getRandom().nextInt(from.size()));
    }

    public static void callEvent(Event event) {
        Bukkit.getPluginManager().callEvent(event);
    }

    public static void broadcast(String message) {
        for (Player player : Bukkit.getOnlinePlayers()) {
            player.sendMessage(message);
        }
    }

    public static void broadcast(String permission, String message) {
        for (Player player : Bukkit.getOnlinePlayers()) {
            if (player.hasPermission(permission)) {
                player.sendMessage(message);
            }
        }
    }

    public static List<Player> matchPlayer(String rawPattern) {
        String pattern = rawPattern.toLowerCase(Locale.ENGLISH);
        ArrayList<Player> players = new ArrayList<Player>();
        for (Player player : Bukkit.getOnlinePlayers()) {
            String name = player.getName().toLowerCase(Locale.ENGLISH);
            if (name.equals(pattern)) {
                return Collections.<Player>singletonList(player);
            } else if (name.startsWith(pattern)) {
                players.add(player);
            }
        }

        return players;
    }

    public static List<OfflinePlayer> matchOfflinePlayer(String rawPattern) {
        String pattern = rawPattern.toLowerCase(Locale.ENGLISH);
        ArrayList<OfflinePlayer> players = new ArrayList<OfflinePlayer>();
        for (OfflinePlayer player : Bukkit.getOfflinePlayers()) {
            String name = player.getName().toLowerCase(Locale.ENGLISH);
            if (name.equals(pattern)) {
                return Collections.<OfflinePlayer>singletonList(player);
            } else if (name.startsWith(pattern)) {
                players.add(player);
            }
        }

        return players;
    }

    public static Material matchMaterial(String pattern) {
        if (pattern.equalsIgnoreCase("dye")) {
            return Material.INK_SACK;
        }

        return Material.matchMaterial(pattern);
    }

    public static Short parseDataFor(Material material, String token) {
        try {
            return Short.parseShort(token);
        } catch (NumberFormatException exc) {
        }

        ItemTypeDataParser parser = ItemTypeDataParser.getFor(material);
        if (parser == null) {
            return null;
        }

        return parser.parse(token);
    }
}

@@ -50,96 +50,13 @@
 til.
-Array
 List;
-%0Aimport java.util.Collections;%0Aimport java.util.List;%0Aimport java.util.Locale;
 %0A%0Aim
@@ -111,41 +111,8 @@
 al;%0A
-import org.bukkit.OfflinePlayer;%0A
 impo
@@ -1097,32 +1097,32 @@
 ;%0A            %7D%0A
+
         %7D%0A    %7D%0A
@@ -1126,1191 +1126,8 @@
  %7D%0A%0A
-    public static List%3CPlayer%3E matchPlayer(String rawPattern) %7B%0A        String pattern = rawPattern.toLowerCase(Locale.ENGLISH);%0A        ArrayList%3CPlayer%3E players = new ArrayList%3CPlayer%3E();%0A        for (Player player : Bukkit.getOnlinePlayers()) %7B%0A            String name = player.getName().toLowerCase(Locale.ENGLISH);%0A            if (name.equals(pattern)) %7B%0A                return Collections.%3CPlayer%3EsingletonList(player);%0A            %7D else if (name.startsWith(pattern)) %7B%0A                players.add(player);%0A            %7D%0A        %7D%0A%0A        return players;%0A    %7D%0A%0A    public static List%3COfflinePlayer%3E matchOfflinePlayer(String rawPattern) %7B%0A        String pattern = rawPattern.toLowerCase(Locale.ENGLISH);%0A        ArrayList%3COfflinePlayer%3E players = new ArrayList%3COfflinePlayer%3E();%0A        for (OfflinePlayer player : Bukkit.getOfflinePlayers()) %7B%0A            String name = player.getName().toLowerCase(Locale.ENGLISH);%0A            if (name.equals(pattern)) %7B%0A                return Collections.%3COfflinePlayer%3EsingletonList(player);%0A            %7D else if (name.startsWith(pattern)) %7B%0A                players.add(player);%0A            %7D%0A        %7D%0A%0A        return players;%0A    %7D%0A%0A
     

Remove usuless methods