Enhance combattag hook

This commit is contained in:
Gabriele C 2015-09-15 21:11:56 +02:00
parent 5fb3542cea
commit f63fe5bc37
11 changed files with 59 additions and 141 deletions

18
pom.xml
View File

@ -412,24 +412,6 @@
</exclusions>
</dependency>
<!-- Anti PvPLogging plugin, http://www.spigotmc.org/resources/combat-tag.3182/ -->
<dependency>
<groupId>com.trc202</groupId>
<artifactId>CombatTag</artifactId>
<version>6.2.1-SNAPSHOT</version>
<scope>provided</scope>
<exclusions>
<exclusion>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
</exclusion>
<exclusion>
<groupId>org.bukkit</groupId>
<artifactId>craftbukkit</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- XAuth, another authentication plugin, required by the database converter -->
<dependency>
<groupId>de.luricos.bukkit</groupId>

View File

@ -16,7 +16,6 @@ import fr.xephi.authme.converter.ForceFlatToSqlite;
import fr.xephi.authme.datasource.*;
import fr.xephi.authme.listener.*;
import fr.xephi.authme.plugin.manager.BungeeCordMessage;
import fr.xephi.authme.plugin.manager.CombatTagComunicator;
import fr.xephi.authme.plugin.manager.EssSpawn;
import fr.xephi.authme.process.Management;
import fr.xephi.authme.settings.Messages;
@ -24,6 +23,8 @@ import fr.xephi.authme.settings.OtherAccounts;
import fr.xephi.authme.settings.Settings;
import fr.xephi.authme.settings.Spawn;
import net.milkbowl.vault.permission.Permission;
import net.minelink.ctplus.CombatTagPlus;
import org.apache.logging.log4j.LogManager;
import org.bukkit.Bukkit;
import org.bukkit.Location;
@ -62,7 +63,6 @@ public class AuthMe extends JavaPlugin {
private Messages m;
public DataManager dataManager;
public DataSource database;
private JsonCache playerBackup;
public OtherAccounts otherAccounts;
public Permission permission;
@ -70,7 +70,7 @@ public class AuthMe extends JavaPlugin {
public Location essentialsSpawn;
public MultiverseCore multiverse;
public LookupService lookupService;
public boolean combatTag = false;
public CombatTagPlus combatTagPlus = null;
public boolean legacyChestShop = false;
public boolean antibotMod = false;
public boolean delayedAntiBot = true;
@ -176,8 +176,8 @@ public class AuthMe extends JavaPlugin {
// Find Permissions
checkVault();
// Check Combat Tag Version
checkCombatTag();
// Check Combat Tag Plus Version
checkCombatTagPlus();
// Check Multiverse
checkMultiverse();
@ -501,8 +501,17 @@ public class AuthMe extends JavaPlugin {
}
// Check the presence of CombatTag
public void checkCombatTag() {
this.combatTag = server.getPluginManager().isPluginEnabled("CombatTag");
public void checkCombatTagPlus() {
if (server.getPluginManager().isPluginEnabled("CombatTagPlus")) {
try {
combatTagPlus = (CombatTagPlus) server.getPluginManager().getPlugin("CombatTagPlus");
ConsoleLogger.info("Hooked correctly with CombatTagPlus");
} catch (Exception | NoClassDefFoundError ingnored) {
combatTagPlus = null;
}
} else {
combatTagPlus = null;
}
}
// Check if a player/command sender have a permission
@ -526,7 +535,7 @@ public class AuthMe extends JavaPlugin {
// Save Player Data
public void savePlayer(Player player) {
if ((utils.isNPC(player)) || (Utils.getInstance().isUnrestricted(player)) || (CombatTagComunicator.isNPC(player))) {
if ((utils.isNPC(player)) || (Utils.getInstance().isUnrestricted(player))) {
return;
}
String name = player.getName().toLowerCase();

View File

@ -215,7 +215,14 @@ public class Utils {
public boolean isNPC(final Entity player) {
try {
return player.hasMetadata("NPC");
if (player.hasMetadata("NPC")) {
return true;
} else if(plugin.combatTagPlus != null
&& player instanceof Player
&& plugin.combatTagPlus.getNpcPlayerHelper().isNpc((Player) player)) {
return true;
}
return false;
} catch (Exception e) {
return false;
}

View File

@ -12,7 +12,6 @@ import fr.xephi.authme.AuthMe;
import fr.xephi.authme.Utils;
import fr.xephi.authme.cache.auth.PlayerAuth;
import fr.xephi.authme.cache.auth.PlayerCache;
import fr.xephi.authme.plugin.manager.CombatTagComunicator;
import fr.xephi.authme.security.PasswordSecurity;
import fr.xephi.authme.settings.Settings;
@ -66,9 +65,7 @@ public class API {
*/
@Deprecated
public boolean isaNPC(Player player) {
if (utils.isNPC(player))
return true;
return CombatTagComunicator.isNPC(player);
return utils.isNPC(player);
}
/**
@ -78,9 +75,7 @@ public class API {
*/
@Deprecated
public boolean isNPC(Player player) {
if (utils.isNPC(player))
return true;
return CombatTagComunicator.isNPC(player);
return utils.isNPC(player);
}
/**

View File

@ -14,7 +14,6 @@ import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.Utils;
import fr.xephi.authme.cache.auth.PlayerAuth;
import fr.xephi.authme.cache.auth.PlayerCache;
import fr.xephi.authme.plugin.manager.CombatTagComunicator;
import fr.xephi.authme.security.PasswordSecurity;
import fr.xephi.authme.settings.Settings;
@ -71,7 +70,7 @@ public class NewAPI {
* @return true if player is a npc
*/
public boolean isNPC(Player player) {
return utils.isNPC(player) || CombatTagComunicator.isNPC(player);
return utils.isNPC(player);
}
/**

View File

@ -3,7 +3,6 @@ package fr.xephi.authme.listener;
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.Utils;
import fr.xephi.authme.cache.auth.PlayerCache;
import fr.xephi.authme.plugin.manager.CombatTagComunicator;
import fr.xephi.authme.settings.Settings;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
@ -39,9 +38,6 @@ public class AuthMeEntityListener implements Listener {
Player player = (Player) entity;
String name = player.getName().toLowerCase();
if (CombatTagComunicator.isNPC(player))
return;
if (PlayerCache.getInstance().isAuthenticated(name)) {
return;
}
@ -171,11 +167,7 @@ public class AuthMeEntityListener implements Listener {
Player player = (Player) event.getEntity();
String name = player.getName().toLowerCase();
if (Utils.getInstance().isUnrestricted(player) || CombatTagComunicator.isNPC(player)) {
return;
}
if (utils.isNPC(player))
if (Utils.getInstance().isUnrestricted(player) || utils.isNPC(player))
return;
if (PlayerCache.getInstance().isAuthenticated(player.getName())) {
@ -199,11 +191,7 @@ public class AuthMeEntityListener implements Listener {
Player player = (Player) event.getEntity();
String name = player.getName().toLowerCase();
if (Utils.getInstance().isUnrestricted(player) || CombatTagComunicator.isNPC(player)) {
return;
}
if (utils.isNPC(player))
if (Utils.getInstance().isUnrestricted(player) || utils.isNPC(player))
return;
if (PlayerCache.getInstance().isAuthenticated(player.getName())) {

View File

@ -8,7 +8,6 @@ import fr.xephi.authme.cache.auth.PlayerCache;
import fr.xephi.authme.cache.limbo.LimboCache;
import fr.xephi.authme.cache.limbo.LimboPlayer;
import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.plugin.manager.CombatTagComunicator;
import fr.xephi.authme.settings.Messages;
import fr.xephi.authme.settings.Settings;
import org.bukkit.Bukkit;
@ -56,7 +55,7 @@ public class AuthMePlayerListener implements Listener {
Player player = event.getPlayer();
String name = player.getName().toLowerCase();
if (Utils.getInstance().isUnrestricted(player))
if (utils.isUnrestricted(player))
return;
if (PlayerCache.getInstance().isAuthenticated(name))
@ -90,7 +89,7 @@ public class AuthMePlayerListener implements Listener {
final Player player = event.getPlayer();
final String name = player.getName().toLowerCase();
if (Utils.getInstance().isUnrestricted(player))
if (utils.isUnrestricted(player))
return;
if (PlayerCache.getInstance().isAuthenticated(name))
@ -126,7 +125,7 @@ public class AuthMePlayerListener implements Listener {
final Player player = event.getPlayer();
final String name = player.getName().toLowerCase();
if (Utils.getInstance().isUnrestricted(player))
if (utils.isUnrestricted(player))
return;
if (PlayerCache.getInstance().isAuthenticated(name))
@ -162,7 +161,7 @@ public class AuthMePlayerListener implements Listener {
final Player player = event.getPlayer();
final String name = player.getName().toLowerCase();
if (Utils.getInstance().isUnrestricted(player))
if (utils.isUnrestricted(player))
return;
if (PlayerCache.getInstance().isAuthenticated(name))
@ -198,7 +197,7 @@ public class AuthMePlayerListener implements Listener {
final Player player = event.getPlayer();
final String name = player.getName().toLowerCase();
if (Utils.getInstance().isUnrestricted(player))
if (utils.isUnrestricted(player))
return;
if (PlayerCache.getInstance().isAuthenticated(name))
@ -234,7 +233,7 @@ public class AuthMePlayerListener implements Listener {
final Player player = event.getPlayer();
final String name = player.getName().toLowerCase();
if (Utils.getInstance().isUnrestricted(player))
if (utils.isUnrestricted(player))
return;
if (PlayerCache.getInstance().isAuthenticated(name)) {
@ -271,7 +270,7 @@ public class AuthMePlayerListener implements Listener {
final Player player = event.getPlayer();
final String name = player.getName().toLowerCase();
if (Utils.getInstance().isUnrestricted(player))
if (utils.isUnrestricted(player))
return;
if (PlayerCache.getInstance().isAuthenticated(name))
@ -306,7 +305,7 @@ public class AuthMePlayerListener implements Listener {
Player player = event.getPlayer();
String name = player.getName().toLowerCase();
if (utils.isNPC(player) || Utils.getInstance().isUnrestricted(player) || CombatTagComunicator.isNPC(player)) {
if (utils.isNPC(player) || utils.isUnrestricted(player)) {
return;
}
@ -424,7 +423,7 @@ public class AuthMePlayerListener implements Listener {
public void run() {
LimboPlayer limbo = LimboCache.getInstance().getLimboPlayer(player.getName().toLowerCase());
if (limbo != null && PlayerCache.getInstance().isAuthenticated(player.getName().toLowerCase())) {
Utils.getInstance().addNormal(player, limbo.getGroup());
utils.addNormal(player, limbo.getGroup());
LimboCache.getInstance().deleteLimboPlayer(player.getName().toLowerCase());
}
}
@ -441,7 +440,7 @@ public class AuthMePlayerListener implements Listener {
final String name = player.getName().toLowerCase();
boolean isAuthAvailable = plugin.database.isAuthAvailable(name);
if (utils.isNPC(player) || Utils.getInstance().isUnrestricted(player) || CombatTagComunicator.isNPC(player)) {
if (utils.isNPC(player) || utils.isUnrestricted(player)) {
return;
}
@ -605,7 +604,7 @@ public class AuthMePlayerListener implements Listener {
Player player = event.getPlayer();
String name = player.getName().toLowerCase();
if (Utils.getInstance().isUnrestricted(player)) {
if (utils.isUnrestricted(player)) {
return;
}
@ -633,7 +632,7 @@ public class AuthMePlayerListener implements Listener {
Player player = event.getPlayer();
String name = player.getName().toLowerCase();
if (Utils.getInstance().isUnrestricted(player)) {
if (utils.isUnrestricted(player)) {
return;
}
@ -664,7 +663,7 @@ public class AuthMePlayerListener implements Listener {
Player player = event.getPlayer();
String name = player.getName().toLowerCase();
if (Utils.getInstance().isUnrestricted(player)) {
if (utils.isUnrestricted(player)) {
return;
}
@ -691,7 +690,7 @@ public class AuthMePlayerListener implements Listener {
return;
final Player player = (Player) event.getPlayer();
String name = player.getName().toLowerCase();
if (Utils.getInstance().isUnrestricted(player)) {
if (utils.isUnrestricted(player)) {
return;
}
if (utils.isNPC(player))
@ -729,7 +728,7 @@ public class AuthMePlayerListener implements Listener {
Player player = (Player) event.getWhoClicked();
String name = player.getName().toLowerCase();
if (Utils.getInstance().isUnrestricted(player)) {
if (utils.isUnrestricted(player)) {
return;
}
@ -759,7 +758,7 @@ public class AuthMePlayerListener implements Listener {
Player player = (Player) damager;
String name = player.getName().toLowerCase();
if (Utils.getInstance().isUnrestricted(player)) {
if (utils.isUnrestricted(player)) {
return;
}
@ -787,7 +786,7 @@ public class AuthMePlayerListener implements Listener {
Player player = event.getPlayer();
String name = player.getName().toLowerCase();
if (utils.isNPC(player) || Utils.getInstance().isUnrestricted(player) || CombatTagComunicator.isNPC(player)) {
if (utils.isNPC(player) || utils.isUnrestricted(player)) {
return;
}
@ -811,11 +810,7 @@ public class AuthMePlayerListener implements Listener {
Player player = event.getPlayer();
String name = player.getName().toLowerCase();
if (Utils.getInstance().isUnrestricted(player) || CombatTagComunicator.isNPC(player)) {
return;
}
if (utils.isNPC(player))
if (utils.isUnrestricted(player) || utils.isNPC(player))
return;
if (PlayerCache.getInstance().isAuthenticated(player.getName().toLowerCase())) {
@ -838,7 +833,7 @@ public class AuthMePlayerListener implements Listener {
Player player = event.getPlayer();
String name = player.getName().toLowerCase();
if (Utils.getInstance().isUnrestricted(player)) {
if (utils.isUnrestricted(player)) {
return;
}
@ -861,7 +856,7 @@ public class AuthMePlayerListener implements Listener {
}
Player player = event.getPlayer();
String name = player.getName().toLowerCase();
if (Utils.getInstance().isUnrestricted(player)) {
if (utils.isUnrestricted(player)) {
return;
}
if (PlayerCache.getInstance().isAuthenticated(name)) {
@ -884,10 +879,7 @@ public class AuthMePlayerListener implements Listener {
Player player = event.getPlayer();
String name = player.getName().toLowerCase();
if (Utils.getInstance().isUnrestricted(player) || CombatTagComunicator.isNPC(player))
return;
if (utils.isNPC(player))
if (utils.isUnrestricted(player) || utils.isNPC(player))
return;
if (PlayerCache.getInstance().isAuthenticated(name))
@ -919,10 +911,7 @@ public class AuthMePlayerListener implements Listener {
String name = player.getName().toLowerCase();
if (Utils.getInstance().isUnrestricted(player) || CombatTagComunicator.isNPC(player))
return;
if (utils.isNPC(player))
if (utils.isUnrestricted(player) || utils.isNPC(player))
return;
if (PlayerCache.getInstance().isAuthenticated(name))

View File

@ -59,9 +59,9 @@ public class AuthMeServerListener implements Listener {
plugin.legacyChestShop = false;
ConsoleLogger.info("ChestShop has been disabled, unhook!");
}
if (pluginName.equalsIgnoreCase("CombatTag")) {
plugin.combatTag = false;
ConsoleLogger.info("CombatTag has been disabled, unhook!");
if (pluginName.equalsIgnoreCase("CombatTagPlus")) {
plugin.combatTagPlus = null;
ConsoleLogger.info("CombatTagPlus has been disabled, unhook!");
}
if (pluginName.equalsIgnoreCase("Vault")) {
plugin.permission = null;
@ -78,8 +78,8 @@ public class AuthMeServerListener implements Listener {
plugin.checkMultiverse();
if (pluginName.equalsIgnoreCase("ChestShop"))
plugin.checkChestShop();
if (pluginName.equalsIgnoreCase("CombatTag"))
plugin.checkCombatTag();
if (pluginName.equalsIgnoreCase("CombatTagPlus"))
plugin.checkCombatTagPlus();
if (pluginName.equalsIgnoreCase("Vault"))
plugin.checkVault();
}

View File

@ -1,49 +0,0 @@
package fr.xephi.authme.plugin.manager;
import org.bukkit.Bukkit;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import com.trc202.CombatTag.CombatTag;
import com.trc202.CombatTagApi.CombatTagApi;
import fr.xephi.authme.AuthMe;
import net.minelink.ctplus.CombatTagPlus;
public abstract class CombatTagComunicator {
public static CombatTagApi combatApi;
/**
* Returns if the entity is an NPC
*
* @param player
* @return true if the player is an NPC
*/
public static boolean isNPC(Entity player) {
if (!AuthMe.getInstance().combatTag)
return false;
try {
if (Bukkit.getServer().getPluginManager().getPlugin("CombatTag") != null) {
combatApi = new CombatTagApi((CombatTag) Bukkit.getServer().getPluginManager().getPlugin("CombatTag"));
try {
combatApi.getClass().getMethod("isNPC");
} catch (Exception e) {
return false;
}
return combatApi.isNPC(player);
} else {
Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin("CombatTagPlus");
return (plugin != null && plugin instanceof CombatTagPlus && player instanceof Player && ((CombatTagPlus) plugin).getNpcPlayerHelper().isNpc((Player) player));
}
} catch (ClassCastException ex) {
return false;
} catch (NullPointerException npe) {
return false;
} catch (NoClassDefFoundError ncdfe) {
return false;
}
}
}

View File

@ -27,7 +27,6 @@ import fr.xephi.authme.events.FirstSpawnTeleportEvent;
import fr.xephi.authme.events.ProtectInventoryEvent;
import fr.xephi.authme.events.SpawnTeleportEvent;
import fr.xephi.authme.listener.AuthMePlayerListener;
import fr.xephi.authme.plugin.manager.CombatTagComunicator;
import fr.xephi.authme.settings.Messages;
import fr.xephi.authme.settings.Settings;
import fr.xephi.authme.settings.Spawn;
@ -58,7 +57,7 @@ public class AsyncronousJoin {
AuthMePlayerListener.gameMode.putIfAbsent(name, player.getGameMode());
BukkitScheduler sched = plugin.getServer().getScheduler();
if (utils.isNPC(player) || Utils.getInstance().isUnrestricted(player) || CombatTagComunicator.isNPC(player)) {
if (utils.isNPC(player) || Utils.getInstance().isUnrestricted(player)) {
return;
}

View File

@ -15,7 +15,6 @@ import fr.xephi.authme.cache.limbo.LimboPlayer;
import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.events.RestoreInventoryEvent;
import fr.xephi.authme.listener.AuthMePlayerListener;
import fr.xephi.authme.plugin.manager.CombatTagComunicator;
import fr.xephi.authme.settings.Settings;
public class AsyncronousQuit {
@ -44,7 +43,7 @@ public class AsyncronousQuit {
public void process() {
if (player == null)
return;
if (utils.isNPC(player) || Utils.getInstance().isUnrestricted(player) || CombatTagComunicator.isNPC(player)) {
if (utils.isNPC(player) || Utils.getInstance().isUnrestricted(player)) {
return;
}