!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>
<systemPath>${basedir}/lib/PlaceholderAPI.jar</systemPath>
</dependency>
<dependency>
<groupId>me.vagdedes</groupId>
<artifactId>spartan</artifactId>
<version>Univsersal</version>
<scope>system</scope>
<systemPath>${basedir}/lib/SpartanAPI.jar</systemPath>
</dependency>
</dependencies>
</project>

View File

@ -32,6 +32,8 @@ import net.Indyuce.mmocore.command.QuestsCommand;
import net.Indyuce.mmocore.command.SkillsCommand;
import net.Indyuce.mmocore.command.WaypointsCommand;
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.CitizensMMOLoader;
import net.Indyuce.mmocore.comp.flags.DefaultFlags;
@ -98,7 +100,7 @@ import net.mmogroup.mmolib.version.SpigotPlugin;
public class MMOCore extends JavaPlugin {
public static MMOCore plugin;
public ConfigManager configManager;
public WaypointManager waypointManager;
public RestrictionManager restrictionManager;
@ -106,6 +108,7 @@ public class MMOCore extends JavaPlugin {
public ConfigItemManager configItems;
public VaultEconomy economy;
public HologramSupport hologramSupport;
public AntiCheatSupport antiCheatSupport;
public InventoryManager inventoryManager;
public RegionHandler regionHandler = new DefaultRegionHandler();
public FlagPlugin flagPlugin = new DefaultFlags();
@ -151,12 +154,12 @@ public class MMOCore extends JavaPlugin {
if (Bukkit.getPluginManager().getPlugin("MythicMobs") != null)
loadManager.registerLoader(new MythicMobsMMOLoader());
/*
* WorldGuard closes the flag registry after 'onLoad()',
* so it must be registered here or it will throw an IllegalStateException
* WorldGuard closes the flag registry after 'onLoad()', so it must be
* registered here or it will throw an IllegalStateException
*/
if(Bukkit.getPluginManager().getPlugin("WorldGuard") != null)
if (Bukkit.getPluginManager().getPlugin("WorldGuard") != null)
flagPlugin = new WorldGuardFlags();
}
@ -164,11 +167,11 @@ public class MMOCore extends JavaPlugin {
new SpigotPlugin(70575, this).checkForUpdate();
new Metrics(this);
saveDefaultConfig();
if (getConfig().isConfigurationSection("mysql") && getConfig().getBoolean("mysql.enabled"))
dataProvider = new MySQLDataProvider(getConfig());
if(getConfig().isConfigurationSection("default-playerdata"))
if (getConfig().isConfigurationSection("default-playerdata"))
dataProvider.getDataManager().loadDefaultData(getConfig().getConfigurationSection("default-playerdata"));
if (Bukkit.getPluginManager().getPlugin("Vault") != null)
@ -203,14 +206,19 @@ public class MMOCore extends JavaPlugin {
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) {
Bukkit.getServer().getPluginManager().registerEvents(new MythicMobsDrops(), this);
MMOCore.plugin.getLogger().log(Level.INFO, "Hooked onto MythicMobs");
}
/*
* resource regeneration. must check if entity is dead otherwise regen
* will make the 'respawn' button glitched plus HURT entity effect bug
* resource regeneration. must check if entity is dead otherwise regen will make
* the 'respawn' button glitched plus HURT entity effect bug
*/
new BukkitRunnable() {
public void run() {
@ -225,9 +233,8 @@ public class MMOCore extends JavaPlugin {
}.runTaskTimer(MMOCore.plugin, 100, 20);
/*
* clean active loot chests every 5 minutes. cannot register this
* runnable in the loot chest manager because it is instanced when the
* plugin loads
* clean active loot chests every 5 minutes. cannot register this runnable in
* the loot chest manager because it is instanced when the plugin loads
*/
new BukkitRunnable() {
public void run() {
@ -238,14 +245,16 @@ public class MMOCore extends JavaPlugin {
}.runTaskTimer(this, 5 * 60 * 20, 5 * 60 * 20);
/*
* For the sake of the lord, make sure they aren't using MMOItems Mana
* and Stamina Addon...This should prevent a couple error reports
* produced by people not reading the installation guide...
* For the sake of the lord, make sure they aren't using MMOItems Mana and
* Stamina Addon...This should prevent a couple error reports produced by people
* not reading the installation guide...
*/
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!");
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!");
return;
}
@ -253,7 +262,8 @@ public class MMOCore extends JavaPlugin {
reloadPlugin();
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.
@ -285,10 +295,9 @@ public class MMOCore extends JavaPlugin {
Bukkit.getPluginManager().registerEvents(new PlayerCollectStats(), this);
/*
* initialize player data from all online players. this is very
* important to do that after registering all the professses otherwise
* the player datas can't recognize what profess the player has and
* professes will be lost
* initialize player data from all online players. this is very important to do
* that after registering all the professses otherwise the player datas can't
* recognize what profess the player has and professes will be lost
*/
Bukkit.getOnlinePlayers().forEach(player -> dataProvider.getDataManager().setup(player));
@ -364,7 +373,7 @@ public class MMOCore extends JavaPlugin {
for (Guild guild : dataProvider.getGuildManager().getAll())
dataProvider.getGuildManager().save(guild);
dataProvider.close();
mineManager.resetRemainingBlocks();
lootChests.getActive().forEach(chest -> chest.unregister(false));
@ -372,7 +381,7 @@ public class MMOCore extends JavaPlugin {
public void reloadPlugin() {
reloadConfig();
configManager = new ConfigManager();
skillManager.reload();
@ -392,7 +401,7 @@ public class MMOCore extends JavaPlugin {
// experience must be loaded before professions and classes
experience.reload();
// drop tables must be loaded before professions
dropTableManager.clear();
dropTableManager.reload();
@ -415,7 +424,7 @@ public class MMOCore extends JavaPlugin {
requestManager = new RequestManager();
configItems = new ConfigItemManager(new ConfigFile("items").getConfig());
if(getConfig().isConfigurationSection("action-bar"))
if (getConfig().isConfigurationSection("action-bar"))
actionBarManager.reload(getConfig().getConfigurationSection("action-bar"));
StatType.load();
@ -434,7 +443,7 @@ public class MMOCore extends JavaPlugin {
}
public static void debug(int value, Level level, String message) {
if(DebugMode.level > (value - 1))
if (DebugMode.level > (value - 1))
plugin.getLogger().log(level, message);
}
@ -442,6 +451,10 @@ public class MMOCore extends JavaPlugin {
return getFile();
}
public boolean hasAntiCheat() {
return antiCheatSupport != null;
}
public boolean hasHolograms() {
return hologramSupport != null;
}

View File

@ -128,7 +128,7 @@ public class PlayerProfessions {
// display hologram
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.configManager.getSimpleMessage("exp-hologram", "exp", "" + value).message(), playerData.getPlayer());

View File

@ -448,7 +448,7 @@ public class PlayerData extends OfflinePlayerData {
// display hologram
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.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;
import java.util.ArrayList;
import java.util.HashMap;
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.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Entity;
import com.google.common.base.Enums;
import com.google.common.base.Optional;
import io.lumine.xikage.mythicmobs.MythicMobs;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.api.skill.Skill;
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.math.formula.IntegerLinearValue;
import net.Indyuce.mmocore.api.util.math.formula.LinearValue;
import net.Indyuce.mmocore.comp.anticheat.CheatType;
public class MythicMobSkill extends 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;
@ -29,7 +37,7 @@ public class MythicMobSkill extends Skill {
String mmId = config.getString("mythicmobs-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);
skill = opt.get();
@ -46,6 +54,14 @@ public class MythicMobSkill extends Skill {
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
// TargetSkillResult(data, info, def(config.getDouble("range"), 50)) :
// (data, info) -> new SkillResult(data, info);
@ -71,12 +87,13 @@ public class MythicMobSkill extends Skill {
targets.add(data.getPlayer());
/*
* cache placeholders so they can be retrieved later by MythicMobs math
* formulas
* cache placeholders so they can be retrieved later by MythicMobs math formulas
*/
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);
return cast;