Get player via BukkitService; add unit tests for commands
This commit is contained in:
@@ -2,6 +2,11 @@ package fr.xephi.authme.util;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Service for operations requiring server entities, such as for scheduling.
|
||||
@@ -44,6 +49,33 @@ public class BukkitService {
|
||||
return Bukkit.getScheduler().scheduleSyncDelayedTask(authMe, task, delay);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a task that will run on the next server tick.
|
||||
*
|
||||
* @param task the task to be run
|
||||
* @return a BukkitTask that contains the id number
|
||||
* @throws IllegalArgumentException if plugin is null
|
||||
* @throws IllegalArgumentException if task is null
|
||||
*/
|
||||
public BukkitTask runTask(Runnable task) {
|
||||
return Bukkit.getScheduler().runTask(authMe, task);
|
||||
}
|
||||
|
||||
/**
|
||||
* <b>Asynchronous tasks should never access any API in Bukkit. Great care
|
||||
* should be taken to assure the thread-safety of asynchronous tasks.</b>
|
||||
* <p>
|
||||
* Returns a task that will run asynchronously.
|
||||
*
|
||||
* @param task the task to be run
|
||||
* @return a BukkitTask that contains the id number
|
||||
* @throws IllegalArgumentException if plugin is null
|
||||
* @throws IllegalArgumentException if task is null
|
||||
*/
|
||||
public BukkitTask runTaskAsynchronously(Runnable task) {
|
||||
return Bukkit.getScheduler().runTaskAsynchronously(authMe, task);
|
||||
}
|
||||
|
||||
/**
|
||||
* Broadcast a message to all players.
|
||||
*
|
||||
@@ -54,4 +86,24 @@ public class BukkitService {
|
||||
return Bukkit.broadcastMessage(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the player with the exact given name, case insensitive.
|
||||
*
|
||||
* @param name Exact name of the player to retrieve
|
||||
* @return a player object if one was found, null otherwise
|
||||
*/
|
||||
public Player getPlayerExact(String name) {
|
||||
return authMe.getServer().getPlayerExact(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a set containing all banned players.
|
||||
*
|
||||
* @return a set containing banned players
|
||||
*/
|
||||
public Set<OfflinePlayer> getBannedPlayers() {
|
||||
Bukkit.getBannedPlayers();
|
||||
return authMe.getServer().getBannedPlayers();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -232,10 +232,6 @@ public final class Utils {
|
||||
}
|
||||
}
|
||||
|
||||
public static Player getPlayer(String name) {
|
||||
return wrapper.getServer().getPlayerExact(name); // bukkit will lowercase the input
|
||||
}
|
||||
|
||||
public static boolean isNPC(Player player) {
|
||||
return player.hasMetadata("NPC") || plugin.getPluginHooks().isNpcInCombatTagPlus(player);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user