From 498df70a1fbf30ae45d7da5179de7b6be2556278 Mon Sep 17 00:00:00 2001 From: samczsun Date: Thu, 9 Mar 2017 17:56:53 -0500 Subject: [PATCH] Implement basic canDamage --- .../core/antihack/MineplexLinkImpl.java | 6 ++++- .../core/antihack/RelationProvider.java | 9 +++++++ .../src/nautilus/game/arcade/Arcade.java | 25 +++++++++++++++++++ 3 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/antihack/RelationProvider.java diff --git a/Plugins/Mineplex.Core/src/mineplex/core/antihack/MineplexLinkImpl.java b/Plugins/Mineplex.Core/src/mineplex/core/antihack/MineplexLinkImpl.java index f2e450e7f..4294d1988 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/antihack/MineplexLinkImpl.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/antihack/MineplexLinkImpl.java @@ -3,10 +3,12 @@ package mineplex.core.antihack; import net.minecraft.server.v1_8_R3.MinecraftServer; import net.minecraft.server.v1_8_R3.MobEffect; +import org.bukkit.Bukkit; import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer; import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; +import org.bukkit.plugin.RegisteredServiceProvider; import org.bukkit.potion.PotionEffectType; import com.mineplex.anticheat.api.MineplexLink; @@ -21,6 +23,8 @@ public class MineplexLinkImpl implements MineplexLink { private final DisguiseManager _disguiseManager = Managers.require(DisguiseManager.class); + private final RegisteredServiceProvider _relationProvider = Bukkit.getServicesManager().getRegistration(RelationProvider.class); + @Override public EntityType getActiveDisguise(Player player) { @@ -74,6 +78,6 @@ public class MineplexLinkImpl implements MineplexLink @Override public boolean canDamage(Player attacker, Entity target) { - return true; + return _relationProvider != null && _relationProvider.getProvider().canDamage(attacker, target); } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/antihack/RelationProvider.java b/Plugins/Mineplex.Core/src/mineplex/core/antihack/RelationProvider.java new file mode 100644 index 000000000..0a4b741d1 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/antihack/RelationProvider.java @@ -0,0 +1,9 @@ +package mineplex.core.antihack; + +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; + +public interface RelationProvider +{ + boolean canDamage(Player player, Entity target); +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/Arcade.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/Arcade.java index 68e92af90..26a762345 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/Arcade.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/Arcade.java @@ -7,7 +7,10 @@ import mineplex.core.aprilfools.AprilFoolsManager; import net.minecraft.server.v1_8_R3.MinecraftServer; import org.bukkit.Bukkit; +import org.bukkit.entity.Entity; +import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; +import org.bukkit.plugin.ServicePriority; import org.bukkit.plugin.java.JavaPlugin; import org.spigotmc.SpigotConfig; @@ -19,6 +22,7 @@ import mineplex.core.TwitchIntegrationFix; import mineplex.core.account.CoreClientManager; import mineplex.core.achievement.AchievementManager; import mineplex.core.antihack.AntiHack; +import mineplex.core.antihack.RelationProvider; import mineplex.core.antihack.logging.AntihackLogger; import mineplex.core.blockrestore.BlockRestore; import mineplex.core.blood.Blood; @@ -80,6 +84,7 @@ import mineplex.minecraft.game.core.combat.CombatManager; import mineplex.minecraft.game.core.damage.DamageManager; import nautilus.game.arcade.anticheatmetadata.GameInfoMetadata; +import nautilus.game.arcade.game.Game; import nautilus.game.arcade.game.GameServerConfig; import static mineplex.core.Managers.require; @@ -97,6 +102,26 @@ public class Arcade extends JavaPlugin @Override public void onEnable() { + getServer().getServicesManager().register(RelationProvider.class, new RelationProvider() + { + @Override + public boolean canDamage(Player player, Entity target) + { + if (target instanceof Player) + { + return _gameManager.canHurt(player, (Player) target); + } + else if (target instanceof LivingEntity) + { + return _gameManager.GetGame() != null && _gameManager.GetGame().GetState() == Game.GameState.Live; + } + else + { + return false; + } + } + }, this, ServicePriority.Normal); + Bukkit.setSpawnRadius(0); //Delete Old Games Folders DeleteFolders();