001/* 002 * PlotSquared, a land and world management plugin for Minecraft. 003 * Copyright (C) IntellectualSites <https://intellectualsites.com> 004 * Copyright (C) IntellectualSites team and contributors 005 * 006 * This program is free software: you can redistribute it and/or modify 007 * it under the terms of the GNU General Public License as published by 008 * the Free Software Foundation, either version 3 of the License, or 009 * (at your option) any later version. 010 * 011 * This program is distributed in the hope that it will be useful, 012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 014 * GNU General Public License for more details. 015 * 016 * You should have received a copy of the GNU General Public License 017 * along with this program. If not, see <https://www.gnu.org/licenses/>. 018 */ 019package com.plotsquared.core.util; 020 021import com.plotsquared.core.PlotSquared; 022 023public final class ThreadUtils { 024 025 private ThreadUtils() { 026 throw new UnsupportedOperationException( 027 "This is a utility class and cannot be instantiated"); 028 } 029 030 /** 031 * Throws {@link IllegalStateException} if the method 032 * is called from the server main thread 033 * 034 * @param message Message describing the issue 035 */ 036 public static void catchSync(final String message) { 037 if (PlotSquared.get().isMainThread(Thread.currentThread())) { 038 throw new IllegalStateException(message); 039 } 040 } 041 042 /** 043 * Throws {@link IllegalStateException} if the method 044 * is not called from the server main thread 045 * 046 * @param message Message describing the issue 047 */ 048 public static void catchAsync(final String message) { 049 if (!PlotSquared.get().isMainThread(Thread.currentThread())) { 050 throw new IllegalStateException(message); 051 } 052 } 053 054}