001package net.tnemc.plugincore.core.utils; 002 003/* 004 * The New Plugin Core 005 * Copyright (C) 2022 - 2024 Daniel "creatorfromhell" Vidmar 006 * 007 * This program is free software: you can redistribute it and/or modify 008 * it under the terms of the GNU Affero General Public License as published by 009 * the Free Software Foundation, either version 3 of the License, or 010 * (at your option) any later version. 011 * 012 * This program is distributed in the hope that it will be useful, 013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 015 * GNU Affero General Public License for more details. 016 * 017 * You should have received a copy of the GNU Affero General Public License 018 * along with this program. If not, see <http://www.gnu.org/licenses/>. 019 */ 020 021import net.tnemc.menu.core.compatibility.MenuPlayer; 022import net.tnemc.plugincore.PluginCore; 023import net.tnemc.plugincore.core.compatibility.PlayerProvider; 024import net.tnemc.plugincore.core.io.message.MessageData; 025 026import java.util.Optional; 027import java.util.regex.Pattern; 028 029/** 030 * PlayerHelper - Utilities relating to all things player-related. 031 * 032 * @author creatorfromhell 033 * @since 0.1.2.0 034 */ 035public class PlayerHelper { 036 037 /** 038 * Returns the {@link Pattern pattern} utilized to determine if a string is a valid 039 * player username. 040 * 041 * @return The {@link Pattern pattern} to use for determining if a string is a valid 042 * player username. 043 * 044 * @see Pattern 045 */ 046 public static Pattern playerMatcher() { 047 return Pattern.compile("^\\w*$"); 048 } 049 050 public static void message(MenuPlayer player, final MessageData data) { 051 052 final Optional<PlayerProvider> provider = PluginCore.server().findPlayer(player.identifier()); 053 provider.ifPresent(playerProvider->playerProvider.message(data)); 054 } 055}