!anti-cheat support

This commit is contained in:
ASangarin 2020-10-11 16:25:49 +02:00
parent 239d70117d
commit 0bf926eba3
9 changed files with 145 additions and 34 deletions

BIN
lib/SpartanAPI.jar Normal file

Binary file not shown.

View File

@ -201,5 +201,12 @@
<scope>system</scope> <scope>system</scope>
<systemPath>${basedir}/lib/PlaceholderAPI.jar</systemPath> <systemPath>${basedir}/lib/PlaceholderAPI.jar</systemPath>
</dependency> </dependency>
<dependency>
<groupId>me.vagdedes</groupId>
<artifactId>spartan</artifactId>
<version>Univsersal</version>
<scope>system</scope>
<systemPath>${basedir}/lib/SpartanAPI.jar</systemPath>
</dependency>
</dependencies> </dependencies>
</project> </project>

View File

@ -32,6 +32,8 @@ import net.Indyuce.mmocore.command.QuestsCommand;
import net.Indyuce.mmocore.command.SkillsCommand; import net.Indyuce.mmocore.command.SkillsCommand;
import net.Indyuce.mmocore.command.WaypointsCommand; import net.Indyuce.mmocore.command.WaypointsCommand;
import net.Indyuce.mmocore.command.WithdrawCommand; import net.Indyuce.mmocore.command.WithdrawCommand;
import net.Indyuce.mmocore.comp.anticheat.AntiCheatSupport;
import net.Indyuce.mmocore.comp.anticheat.SpartanPlugin;
import net.Indyuce.mmocore.comp.citizens.CitizenInteractEventListener; import net.Indyuce.mmocore.comp.citizens.CitizenInteractEventListener;
import net.Indyuce.mmocore.comp.citizens.CitizensMMOLoader; import net.Indyuce.mmocore.comp.citizens.CitizensMMOLoader;
import net.Indyuce.mmocore.comp.flags.DefaultFlags; import net.Indyuce.mmocore.comp.flags.DefaultFlags;
@ -106,6 +108,7 @@ public class MMOCore extends JavaPlugin {
public ConfigItemManager configItems; public ConfigItemManager configItems;
public VaultEconomy economy; public VaultEconomy economy;
public HologramSupport hologramSupport; public HologramSupport hologramSupport;
public AntiCheatSupport antiCheatSupport;
public InventoryManager inventoryManager; public InventoryManager inventoryManager;
public RegionHandler regionHandler = new DefaultRegionHandler(); public RegionHandler regionHandler = new DefaultRegionHandler();
public FlagPlugin flagPlugin = new DefaultFlags(); public FlagPlugin flagPlugin = new DefaultFlags();
@ -153,8 +156,8 @@ public class MMOCore extends JavaPlugin {
loadManager.registerLoader(new MythicMobsMMOLoader()); loadManager.registerLoader(new MythicMobsMMOLoader());
/* /*
* WorldGuard closes the flag registry after 'onLoad()', * WorldGuard closes the flag registry after 'onLoad()', so it must be
* so it must be registered here or it will throw an IllegalStateException * registered here or it will throw an IllegalStateException
*/ */
if (Bukkit.getPluginManager().getPlugin("WorldGuard") != null) if (Bukkit.getPluginManager().getPlugin("WorldGuard") != null)
flagPlugin = new WorldGuardFlags(); flagPlugin = new WorldGuardFlags();
@ -203,14 +206,19 @@ public class MMOCore extends JavaPlugin {
getLogger().log(Level.INFO, "Hooked onto Holograms"); getLogger().log(Level.INFO, "Hooked onto Holograms");
} }
if (Bukkit.getPluginManager().getPlugin("Spartan") != null) {
antiCheatSupport = new SpartanPlugin();
getLogger().log(Level.INFO, "Hooked onto Spartan");
}
if (Bukkit.getPluginManager().getPlugin("MythicMobs") != null) { if (Bukkit.getPluginManager().getPlugin("MythicMobs") != null) {
Bukkit.getServer().getPluginManager().registerEvents(new MythicMobsDrops(), this); Bukkit.getServer().getPluginManager().registerEvents(new MythicMobsDrops(), this);
MMOCore.plugin.getLogger().log(Level.INFO, "Hooked onto MythicMobs"); MMOCore.plugin.getLogger().log(Level.INFO, "Hooked onto MythicMobs");
} }
/* /*
* resource regeneration. must check if entity is dead otherwise regen * resource regeneration. must check if entity is dead otherwise regen will make
* will make the 'respawn' button glitched plus HURT entity effect bug * the 'respawn' button glitched plus HURT entity effect bug
*/ */
new BukkitRunnable() { new BukkitRunnable() {
public void run() { public void run() {
@ -225,9 +233,8 @@ public class MMOCore extends JavaPlugin {
}.runTaskTimer(MMOCore.plugin, 100, 20); }.runTaskTimer(MMOCore.plugin, 100, 20);
/* /*
* clean active loot chests every 5 minutes. cannot register this * clean active loot chests every 5 minutes. cannot register this runnable in
* runnable in the loot chest manager because it is instanced when the * the loot chest manager because it is instanced when the plugin loads
* plugin loads
*/ */
new BukkitRunnable() { new BukkitRunnable() {
public void run() { public void run() {
@ -238,14 +245,16 @@ public class MMOCore extends JavaPlugin {
}.runTaskTimer(this, 5 * 60 * 20, 5 * 60 * 20); }.runTaskTimer(this, 5 * 60 * 20, 5 * 60 * 20);
/* /*
* For the sake of the lord, make sure they aren't using MMOItems Mana * For the sake of the lord, make sure they aren't using MMOItems Mana and
* and Stamina Addon...This should prevent a couple error reports * Stamina Addon...This should prevent a couple error reports produced by people
* produced by people not reading the installation guide... * not reading the installation guide...
*/ */
if (Bukkit.getPluginManager().getPlugin("MMOItemsMana") != null) { if (Bukkit.getPluginManager().getPlugin("MMOItemsMana") != null) {
getLogger().log(Level.SEVERE, ChatColor.DARK_RED + "MMOCore is not meant to be used with MMOItems ManaAndStamina"); getLogger().log(Level.SEVERE,
ChatColor.DARK_RED + "MMOCore is not meant to be used with MMOItems ManaAndStamina");
getLogger().log(Level.SEVERE, ChatColor.DARK_RED + "Please read the installation guide!"); getLogger().log(Level.SEVERE, ChatColor.DARK_RED + "Please read the installation guide!");
Bukkit.broadcastMessage(ChatColor.DARK_RED + "[MMOCore] MMOCore is not meant to be used with MMOItems ManaAndStamina"); Bukkit.broadcastMessage(
ChatColor.DARK_RED + "[MMOCore] MMOCore is not meant to be used with MMOItems ManaAndStamina");
Bukkit.broadcastMessage(ChatColor.DARK_RED + "[MMOCore] Please read the installation guide!"); Bukkit.broadcastMessage(ChatColor.DARK_RED + "[MMOCore] Please read the installation guide!");
return; return;
} }
@ -253,7 +262,8 @@ public class MMOCore extends JavaPlugin {
reloadPlugin(); reloadPlugin();
if (getConfig().getBoolean("vanilla-exp-redirection.enabled")) if (getConfig().getBoolean("vanilla-exp-redirection.enabled"))
Bukkit.getPluginManager().registerEvents(new RedirectVanillaExp(getConfig().getDouble("vanilla-exp-redirection.ratio")), this); Bukkit.getPluginManager().registerEvents(
new RedirectVanillaExp(getConfig().getDouble("vanilla-exp-redirection.ratio")), this);
/* /*
* enable debug mode for extra debug tools. * enable debug mode for extra debug tools.
@ -285,10 +295,9 @@ public class MMOCore extends JavaPlugin {
Bukkit.getPluginManager().registerEvents(new PlayerCollectStats(), this); Bukkit.getPluginManager().registerEvents(new PlayerCollectStats(), this);
/* /*
* initialize player data from all online players. this is very * initialize player data from all online players. this is very important to do
* important to do that after registering all the professses otherwise * that after registering all the professses otherwise the player datas can't
* the player datas can't recognize what profess the player has and * recognize what profess the player has and professes will be lost
* professes will be lost
*/ */
Bukkit.getOnlinePlayers().forEach(player -> dataProvider.getDataManager().setup(player)); Bukkit.getOnlinePlayers().forEach(player -> dataProvider.getDataManager().setup(player));
@ -442,6 +451,10 @@ public class MMOCore extends JavaPlugin {
return getFile(); return getFile();
} }
public boolean hasAntiCheat() {
return antiCheatSupport != null;
}
public boolean hasHolograms() { public boolean hasHolograms() {
return hologramSupport != null; return hologramSupport != null;
} }

View File

@ -128,7 +128,7 @@ public class PlayerProfessions {
// display hologram // display hologram
if (MMOCore.plugin.getConfig().getBoolean("display-exp-holograms") && playerData.isOnline()) if (MMOCore.plugin.getConfig().getBoolean("display-exp-holograms") && playerData.isOnline())
if (loc != null && MMOCore.plugin.hologramSupport != null) if (loc != null && MMOCore.plugin.hasHolograms())
MMOCore.plugin.hologramSupport.displayIndicator(loc.add(.5, 1.5, .5), MMOCore.plugin.hologramSupport.displayIndicator(loc.add(.5, 1.5, .5),
MMOCore.plugin.configManager.getSimpleMessage("exp-hologram", "exp", "" + value).message(), playerData.getPlayer()); MMOCore.plugin.configManager.getSimpleMessage("exp-hologram", "exp", "" + value).message(), playerData.getPlayer());

View File

@ -448,7 +448,7 @@ public class PlayerData extends OfflinePlayerData {
// display hologram // display hologram
if (MMOCore.plugin.getConfig().getBoolean("display-exp-holograms") && isOnline()) if (MMOCore.plugin.getConfig().getBoolean("display-exp-holograms") && isOnline())
if (loc != null && MMOCore.plugin.hologramSupport != null) if (loc != null && MMOCore.plugin.hasHolograms())
MMOCore.plugin.hologramSupport.displayIndicator(loc.add(.5, 1.5, .5), MMOCore.plugin.hologramSupport.displayIndicator(loc.add(.5, 1.5, .5),
MMOCore.plugin.configManager.getSimpleMessage("exp-hologram", "exp", "" + value).message(), getPlayer()); MMOCore.plugin.configManager.getSimpleMessage("exp-hologram", "exp", "" + value).message(), getPlayer());

View File

@ -0,0 +1,9 @@
package net.Indyuce.mmocore.comp.anticheat;
import java.util.Map;
import org.bukkit.entity.Player;
public abstract class AntiCheatSupport {
public abstract void disableAntiCheat(Player player, Map<CheatType, Integer> map);
}

View File

@ -0,0 +1,44 @@
package net.Indyuce.mmocore.comp.anticheat;
public enum CheatType {
GENERAL_EXPLOITS("Exploits"),
NO_SWING("NoSwing"),
MOVEMENT("IrregularMovements"),
CLIPPING("Clip"),
IMPOSSIBLE_ACTION("ImpossibleActions"),
INVENTORY_CLEAR("ItemDrops"),
INVENTORY_CLICKS("InventoryClicks"),
AUTO_SPRINT("Sprint"),
JESUS("Jesus"),
NO_SLOWDOWN("NoSlowdown"),
CRITICAL_HITS("Criticals"),
NUKER("Nuker"),
GHOST_HAND("GhostHand"),
LIQUIDS("Liquids"),
BLOCK_REACH("BlockReach"),
ELYTRA("ElytraMove"),
BOAT("BoatMove"),
FAST_BOW("FastBow"),
FAST_CLICK("FastClicks"),
FAST_HEAL("FastHeal"),
FLYING("Fly"),
HIT_REACH("HitReach"),
FAST_BREAK("FastBreak"),
FAST_PLACE("FastPlace"),
SPEED("Speed"),
NO_FALL("NoFall"),
ILLEGAL_POS("IllegalPosition"),
FAST_EAT("FastEat"),
VELOCITY("Velocity"),
KILLAURA("KillAura");
private final String spartan;
CheatType(String spartan) {
this.spartan = spartan;
}
public String toSpartan() {
return spartan;
}
}

View File

@ -0,0 +1,21 @@
package net.Indyuce.mmocore.comp.anticheat;
import java.util.Map;
import java.util.Map.Entry;
import org.bukkit.entity.Player;
import me.vagdedes.spartan.api.API;
import me.vagdedes.spartan.system.Enums.HackType;
public class SpartanPlugin extends AntiCheatSupport {
@Override
public void disableAntiCheat(Player player, Map<CheatType, Integer> map) {
for(Entry<CheatType, Integer> entry : map.entrySet())
API.cancelCheck(player, fromCheatType(entry.getKey()), entry.getValue());
}
private HackType fromCheatType(CheatType ct) {
return HackType.valueOf(ct.toSpartan());
}
}

View File

@ -1,15 +1,21 @@
package net.Indyuce.mmocore.comp.mythicmobs; package net.Indyuce.mmocore.comp.mythicmobs;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Map;
import java.util.logging.Level;
import org.apache.commons.lang.Validate; import org.apache.commons.lang.Validate;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import com.google.common.base.Enums;
import com.google.common.base.Optional;
import io.lumine.xikage.mythicmobs.MythicMobs; import io.lumine.xikage.mythicmobs.MythicMobs;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.player.PlayerData; import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.api.skill.Skill; import net.Indyuce.mmocore.api.skill.Skill;
import net.Indyuce.mmocore.api.skill.SkillResult; import net.Indyuce.mmocore.api.skill.SkillResult;
@ -17,9 +23,11 @@ import net.Indyuce.mmocore.api.skill.SkillResult.CancelReason;
import net.Indyuce.mmocore.api.util.MMOCoreUtils; import net.Indyuce.mmocore.api.util.MMOCoreUtils;
import net.Indyuce.mmocore.api.util.math.formula.IntegerLinearValue; import net.Indyuce.mmocore.api.util.math.formula.IntegerLinearValue;
import net.Indyuce.mmocore.api.util.math.formula.LinearValue; import net.Indyuce.mmocore.api.util.math.formula.LinearValue;
import net.Indyuce.mmocore.comp.anticheat.CheatType;
public class MythicMobSkill extends Skill { public class MythicMobSkill extends Skill {
private final io.lumine.xikage.mythicmobs.skills.Skill skill; private final io.lumine.xikage.mythicmobs.skills.Skill skill;
private final Map<CheatType, Integer> antiCheat = new HashMap<>();
// private final BiFunction<PlayerDataManager, SkillInfo, SkillResult> cast; // private final BiFunction<PlayerDataManager, SkillInfo, SkillResult> cast;
@ -29,7 +37,7 @@ public class MythicMobSkill extends Skill {
String mmId = config.getString("mythicmobs-skill-id"); String mmId = config.getString("mythicmobs-skill-id");
Validate.notNull(mmId, "Could not find MM skill ID"); Validate.notNull(mmId, "Could not find MM skill ID");
Optional<io.lumine.xikage.mythicmobs.skills.Skill> opt = MythicMobs.inst().getSkillManager().getSkill(mmId); java.util.Optional<io.lumine.xikage.mythicmobs.skills.Skill> opt = MythicMobs.inst().getSkillManager().getSkill(mmId);
Validate.isTrue(opt.isPresent(), "Could not find MM skill " + mmId); Validate.isTrue(opt.isPresent(), "Could not find MM skill " + mmId);
skill = opt.get(); skill = opt.get();
@ -46,6 +54,14 @@ public class MythicMobSkill extends Skill {
addModifier(key, readLinearValue((ConfigurationSection) mod)); addModifier(key, readLinearValue((ConfigurationSection) mod));
} }
if (config.isConfigurationSection("disable-anti-cheat"))
for(String key : config.getConfigurationSection("").getKeys(false)) {
Optional<CheatType> optional = Enums.getIfPresent(CheatType.class, "");
if(optional.isPresent() && config.isInt("disable-anti-cheat." + key))
antiCheat.put(optional.get(), config.getInt("disable-anti-cheat." + key));
else MMOCore.log(Level.WARNING, "Invalid Anti-Cheat configuration for '" + id + "'!");
}
// cast = config.getBoolean("target") ? (data, info) -> new // cast = config.getBoolean("target") ? (data, info) -> new
// TargetSkillResult(data, info, def(config.getDouble("range"), 50)) : // TargetSkillResult(data, info, def(config.getDouble("range"), 50)) :
// (data, info) -> new SkillResult(data, info); // (data, info) -> new SkillResult(data, info);
@ -71,12 +87,13 @@ public class MythicMobSkill extends Skill {
targets.add(data.getPlayer()); targets.add(data.getPlayer());
/* /*
* cache placeholders so they can be retrieved later by MythicMobs math * cache placeholders so they can be retrieved later by MythicMobs math formulas
* formulas
*/ */
data.getSkillData().cacheModifiers(this, cast); data.getSkillData().cacheModifiers(this, cast);
if (!MythicMobs.inst().getAPIHelper().castSkill(data.getPlayer(), this.skill.getInternalName(), data.getPlayer(), data.getPlayer().getEyeLocation(), targets, null, 1)) if(MMOCore.plugin.hasAntiCheat()) MMOCore.plugin.antiCheatSupport.disableAntiCheat(data.getPlayer(), antiCheat);
if (!MythicMobs.inst().getAPIHelper().castSkill(data.getPlayer(), this.skill.getInternalName(),
data.getPlayer(), data.getPlayer().getEyeLocation(), targets, null, 1))
cast.abort(CancelReason.OTHER); cast.abort(CancelReason.OTHER);
return cast; return cast;