Move #isNpc method to PlayerUtils

- After dropping our hook to CombatTagPlus it is not relevant for it to be in PluginHooksService anymore
This commit is contained in:
ljacqu
2017-10-21 12:08:23 +02:00
parent 58657f5d3f
commit 4e8deec258
11 changed files with 49 additions and 51 deletions
@@ -9,8 +9,8 @@ import fr.xephi.authme.process.register.executors.ApiPasswordRegisterParams;
import fr.xephi.authme.process.register.executors.RegistrationMethod;
import fr.xephi.authme.security.PasswordSecurity;
import fr.xephi.authme.security.crypts.HashedPassword;
import fr.xephi.authme.service.PluginHookService;
import fr.xephi.authme.service.ValidationService;
import fr.xephi.authme.util.PlayerUtils;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Player;
@@ -35,7 +35,6 @@ public class NewAPI {
private static NewAPI singleton;
private final AuthMe plugin;
private final PluginHookService pluginHookService;
private final DataSource dataSource;
private final PasswordSecurity passwordSecurity;
private final Management management;
@@ -46,10 +45,9 @@ public class NewAPI {
* Constructor for NewAPI.
*/
@Inject
NewAPI(AuthMe plugin, PluginHookService pluginHookService, DataSource dataSource, PasswordSecurity passwordSecurity,
NewAPI(AuthMe plugin, DataSource dataSource, PasswordSecurity passwordSecurity,
Management management, ValidationService validationService, PlayerCache playerCache) {
this.plugin = plugin;
this.pluginHookService = pluginHookService;
this.dataSource = dataSource;
this.passwordSecurity = passwordSecurity;
this.management = management;
@@ -108,7 +106,7 @@ public class NewAPI {
* @return true if the player is an npc
*/
public boolean isNPC(Player player) {
return pluginHookService.isNpc(player);
return PlayerUtils.isNpc(player);
}
/**
@@ -10,8 +10,8 @@ import fr.xephi.authme.process.register.executors.RegistrationMethod;
import fr.xephi.authme.security.PasswordSecurity;
import fr.xephi.authme.security.crypts.HashedPassword;
import fr.xephi.authme.service.GeoIpService;
import fr.xephi.authme.service.PluginHookService;
import fr.xephi.authme.service.ValidationService;
import fr.xephi.authme.util.PlayerUtils;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Player;
@@ -33,7 +33,6 @@ public class AuthMeApi {
private static AuthMeApi singleton;
private final AuthMe plugin;
private final PluginHookService pluginHookService;
private final DataSource dataSource;
private final PasswordSecurity passwordSecurity;
private final Management management;
@@ -45,11 +44,9 @@ public class AuthMeApi {
* Constructor for AuthMeApi.
*/
@Inject
AuthMeApi(AuthMe plugin, PluginHookService pluginHookService, DataSource dataSource, PlayerCache playerCache,
PasswordSecurity passwordSecurity, Management management, ValidationService validationService,
GeoIpService geoIpService) {
AuthMeApi(AuthMe plugin, DataSource dataSource, PlayerCache playerCache, PasswordSecurity passwordSecurity,
Management management, ValidationService validationService, GeoIpService geoIpService) {
this.plugin = plugin;
this.pluginHookService = pluginHookService;
this.dataSource = dataSource;
this.passwordSecurity = passwordSecurity;
this.management = management;
@@ -109,7 +106,7 @@ public class AuthMeApi {
* @return true if the player is an npc
*/
public boolean isNpc(Player player) {
return pluginHookService.isNpc(player);
return PlayerUtils.isNpc(player);
}
/**
@@ -5,11 +5,11 @@ import fr.xephi.authme.data.auth.PlayerCache;
import fr.xephi.authme.data.limbo.LimboService;
import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.service.BukkitService;
import fr.xephi.authme.service.PluginHookService;
import fr.xephi.authme.service.ValidationService;
import fr.xephi.authme.settings.Settings;
import fr.xephi.authme.settings.SpawnLoader;
import fr.xephi.authme.settings.properties.RestrictionSettings;
import fr.xephi.authme.util.PlayerUtils;
import org.bukkit.Location;
import org.bukkit.entity.Player;
@@ -31,8 +31,6 @@ public class OnShutdownPlayerSaver {
@Inject
private SpawnLoader spawnLoader;
@Inject
private PluginHookService pluginHookService;
@Inject
private PlayerCache playerCache;
@Inject
private LimboService limboService;
@@ -51,7 +49,7 @@ public class OnShutdownPlayerSaver {
private void savePlayer(Player player) {
final String name = player.getName().toLowerCase();
if (pluginHookService.isNpc(player) || validationService.isUnrestricted(name)) {
if (PlayerUtils.isNpc(player) || validationService.isUnrestricted(name)) {
return;
}
if (limboService.hasLimboPlayer(name)) {
@@ -2,11 +2,11 @@ package fr.xephi.authme.listener;
import fr.xephi.authme.data.auth.PlayerCache;
import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.service.PluginHookService;
import fr.xephi.authme.initialization.SettingsDependent;
import fr.xephi.authme.service.ValidationService;
import fr.xephi.authme.settings.Settings;
import fr.xephi.authme.settings.properties.RegistrationSettings;
import fr.xephi.authme.service.ValidationService;
import fr.xephi.authme.util.PlayerUtils;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityEvent;
@@ -20,17 +20,15 @@ import javax.inject.Inject;
class ListenerService implements SettingsDependent {
private final DataSource dataSource;
private final PluginHookService pluginHookService;
private final PlayerCache playerCache;
private final ValidationService validationService;
private boolean isRegistrationForced;
@Inject
ListenerService(Settings settings, DataSource dataSource, PluginHookService pluginHookService,
PlayerCache playerCache, ValidationService validationService) {
ListenerService(Settings settings, DataSource dataSource, PlayerCache playerCache,
ValidationService validationService) {
this.dataSource = dataSource;
this.pluginHookService = pluginHookService;
this.playerCache = playerCache;
this.validationService = validationService;
reload(settings);
@@ -79,7 +77,7 @@ class ListenerService implements SettingsDependent {
* @return true if the associated event should be canceled, false otherwise
*/
public boolean shouldCancelEvent(Player player) {
return player != null && !checkAuth(player.getName()) && !pluginHookService.isNpc(player);
return player != null && !checkAuth(player.getName()) && !PlayerUtils.isNpc(player);
}
@Override
@@ -76,16 +76,6 @@ public class PluginHookService {
return null;
}
/**
* Checks whether the player is an NPC.
*
* @param player The player to process
* @return True if player is NPC, false otherwise
*/
public boolean isNpc(Player player) {
return player.hasMetadata("NPC");
}
// ------
// "Is plugin available" methods
@@ -39,4 +39,15 @@ public final class PlayerUtils {
public static String getPlayerIp(Player p) {
return p.getAddress().getAddress().getHostAddress();
}
/**
* Returns if the player is an NPC or not.
*
* @param player The player to check
*
* @return True if the player is an NPC, false otherwise
*/
public static boolean isNpc(Player player) {
return player.hasMetadata("NPC");
}
}