com.quartercode.quarterbukkit.api.thread
Class ThreadUtil

java.lang.Object
  extended by com.quartercode.quarterbukkit.api.thread.ThreadUtil

public class ThreadUtil
extends java.lang.Object

This class is for handle the Bukkit-Thread-Errors. It will manage the called method with their actions.


Method Summary
static boolean check(WrongThreadAction wrongThreadAction)
          Checks if the current Thread is valid for Bukkit-API-functions and executes the WrongThreadAction if not.
static boolean check(WrongThreadAction wrongThreadAction, java.lang.reflect.Method method, java.lang.Object object, java.lang.Object... parameters)
          Checks if the current Thread is valid for Bukkit-API-functions and executes the WrongThreadAction if not.
static java.lang.Thread getBukkitThrad()
          Returns the initalized Bukkit-Main-Thread.
static java.lang.reflect.Method getMethod(java.lang.Class<?> c, java.lang.String name, java.lang.Class<?>... parameterTypes)
          Returns a refelction-Method and throws human exceptions (API Helper).
static void initalizeThread(org.bukkit.plugin.Plugin plugin)
          Initalizes the Thread management.
static boolean isInBukkitThread()
          Checks if the current Thread is the Bukkit-Main-Thread.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

initalizeThread

public static void initalizeThread(org.bukkit.plugin.Plugin plugin)
Initalizes the Thread management. This can only be called one time.

Parameters:
plugin - The QuarterBukkit plugin.

getBukkitThrad

public static java.lang.Thread getBukkitThrad()
Returns the initalized Bukkit-Main-Thread.

Returns:
The Bukkit-Main-Thread.

isInBukkitThread

public static boolean isInBukkitThread()
Checks if the current Thread is the Bukkit-Main-Thread.

Returns:
If the current Thread is valid for Bukkit-API-functions.

check

public static boolean check(WrongThreadAction wrongThreadAction)
Checks if the current Thread is valid for Bukkit-API-functions and executes the WrongThreadAction if not. You cannot use the WrongThreadAction.WAIT in this checking method.

Parameters:
wrongThreadAction - The action which executes when this is the wrong Thread.
Returns:
If the method can continue running.

check

public static boolean check(WrongThreadAction wrongThreadAction,
                            java.lang.reflect.Method method,
                            java.lang.Object object,
                            java.lang.Object... parameters)
Checks if the current Thread is valid for Bukkit-API-functions and executes the WrongThreadAction if not. To use the WrongThreadAction.WAIT in this checking method, you have to set the Method, Object (null for static access) and invoke parameters as an Object-array.

Parameters:
wrongThreadAction - The action which executes when this is the wrong thread.
Returns:
If the method can continue running.

getMethod

public static java.lang.reflect.Method getMethod(java.lang.Class<?> c,
                                                 java.lang.String name,
                                                 java.lang.Class<?>... parameterTypes)
Returns a refelction-Method and throws human exceptions (API Helper).

Parameters:
c - The Class with the method.
name - The name of the method.
parameterTypes - The parameter Classes of the method in the right order.
Returns:
The refelction-Method.