From 1fc4239b89be3bc441abab124b5bc7e335fb72a9 Mon Sep 17 00:00:00 2001 From: samczsun Date: Wed, 11 May 2016 22:52:39 -0400 Subject: [PATCH] Determine whether Ice Prison target is valid. Fixes PC-281 --- .../game/clans/clans/ClansManager.java | 8 +++++ .../game/classcombat/Skill/ISkill.java | 3 ++ .../classcombat/Skill/LocationFilter.java | 18 ++++++++++++ .../classcombat/Skill/Mage/IcePrison.java | 29 +++++++++++++++++-- .../game/classcombat/Skill/Skill.java | 15 +++++++++- 5 files changed, 70 insertions(+), 3 deletions(-) create mode 100644 Plugins/Mineplex.Minecraft.Game.ClassCombat/src/mineplex/minecraft/game/classcombat/Skill/LocationFilter.java diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansManager.java index 11264d80b..b44710510 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansManager.java @@ -325,6 +325,14 @@ public class ClansManager extends MiniClientPluginimplements IRelati skillManager.RemoveSkill("Dwarf Toss", "Block Toss"); skillManager.removeSkill("Whirlwind Axe"); skillManager.removeSkill("Shield Smash"); + // Check if any Ice Prison blocks will be placed inside a safe zone + // fixme Is there any way of checking the destination beforehand? + // Although if the user is trying to launch an Ice Prison into a safezone they should know better + skillManager.GetSkill("Ice Prison").setLocationFilter(location -> + { + ClanTerritory territory = _clanUtility.getClaim(location); + return territory == null || !territory.Safe; + }); _worldEvent.setFactory(skillManager); _classManager = new ClassManager(plugin, _clientManager, donationManager, skillManager, itemFactory, webServerAddress); diff --git a/Plugins/Mineplex.Minecraft.Game.ClassCombat/src/mineplex/minecraft/game/classcombat/Skill/ISkill.java b/Plugins/Mineplex.Minecraft.Game.ClassCombat/src/mineplex/minecraft/game/classcombat/Skill/ISkill.java index 31ca861ab..225f6cea9 100644 --- a/Plugins/Mineplex.Minecraft.Game.ClassCombat/src/mineplex/minecraft/game/classcombat/Skill/ISkill.java +++ b/Plugins/Mineplex.Minecraft.Game.ClassCombat/src/mineplex/minecraft/game/classcombat/Skill/ISkill.java @@ -39,4 +39,7 @@ public interface ISkill int getMaxLevel(); boolean isAchievementSkill(); + + void setLocationFilter(LocationFilter locationFilter); + LocationFilter getLocationFilter(); } diff --git a/Plugins/Mineplex.Minecraft.Game.ClassCombat/src/mineplex/minecraft/game/classcombat/Skill/LocationFilter.java b/Plugins/Mineplex.Minecraft.Game.ClassCombat/src/mineplex/minecraft/game/classcombat/Skill/LocationFilter.java new file mode 100644 index 000000000..63c609116 --- /dev/null +++ b/Plugins/Mineplex.Minecraft.Game.ClassCombat/src/mineplex/minecraft/game/classcombat/Skill/LocationFilter.java @@ -0,0 +1,18 @@ +package mineplex.minecraft.game.classcombat.Skill; + +import org.bukkit.Location; + +/* + * Determines whether a location is acceptable for an action to be performed + */ +public interface LocationFilter +{ + LocationFilter ACCEPT_ALL = location -> true; + + /* + * Check if the given location is acceptable + * @param location The location to check + * @return Whether the location is valid, or invalid + */ + boolean accept(Location location); +} diff --git a/Plugins/Mineplex.Minecraft.Game.ClassCombat/src/mineplex/minecraft/game/classcombat/Skill/Mage/IcePrison.java b/Plugins/Mineplex.Minecraft.Game.ClassCombat/src/mineplex/minecraft/game/classcombat/Skill/Mage/IcePrison.java index fcfd35c26..f2201330b 100644 --- a/Plugins/Mineplex.Minecraft.Game.ClassCombat/src/mineplex/minecraft/game/classcombat/Skill/Mage/IcePrison.java +++ b/Plugins/Mineplex.Minecraft.Game.ClassCombat/src/mineplex/minecraft/game/classcombat/Skill/Mage/IcePrison.java @@ -1,6 +1,8 @@ package mineplex.minecraft.game.classcombat.Skill.Mage; import java.util.HashMap; +import java.util.HashSet; +import java.util.Set; import org.bukkit.Effect; import org.bukkit.Material; @@ -118,6 +120,9 @@ public class IcePrison extends SkillActive implements IThrown //Sphere HashMap blocks = UtilBlock.getInRadius(block, 3.8d); + // To save having to calculate everything again + Set acceptable = new HashSet<>(); + boolean failed = false; for (Block cur : blocks.keySet()) { if (!UtilBlock.airFoliage(cur)) @@ -129,8 +134,28 @@ public class IcePrison extends SkillActive implements IThrown //Leave roof hole if (cur.getX() == block.getX() && cur.getZ() == block.getZ() && cur.getY() > block.getY()) continue; - - FreezeBlock(cur, block, level); + + if (getLocationFilter().accept(cur.getLocation())) + { + acceptable.add(cur); + } + else + { + failed = true; + break; + } + } + + if (!failed) + { + for (Block cur : acceptable) + { + FreezeBlock(cur, block, level); + } + } + else + { + UtilPlayer.message(player, F.main("Skill", "You cannot use " + F.skill(GetName()) + " here.")); } /* diff --git a/Plugins/Mineplex.Minecraft.Game.ClassCombat/src/mineplex/minecraft/game/classcombat/Skill/Skill.java b/Plugins/Mineplex.Minecraft.Game.ClassCombat/src/mineplex/minecraft/game/classcombat/Skill/Skill.java index ac73feaa2..c8985c538 100644 --- a/Plugins/Mineplex.Minecraft.Game.ClassCombat/src/mineplex/minecraft/game/classcombat/Skill/Skill.java +++ b/Plugins/Mineplex.Minecraft.Game.ClassCombat/src/mineplex/minecraft/game/classcombat/Skill/Skill.java @@ -12,7 +12,6 @@ import mineplex.core.common.util.UtilTextBottom; import mineplex.minecraft.game.classcombat.Class.IPvpClass.ClassType; import mineplex.minecraft.game.classcombat.Skill.repository.token.SkillToken; -import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.Sound; import org.bukkit.entity.Entity; @@ -43,6 +42,8 @@ public abstract class Skill implements ISkill, Listener private boolean _isAchievementSkill = false; + private LocationFilter _locationFilter = LocationFilter.ACCEPT_ALL; + public SkillFactory Factory; public Skill(SkillFactory skills, String name, ClassType classType, SkillType skillType, int cost, int maxLevel) @@ -357,4 +358,16 @@ public abstract class Skill implements ISkill, Listener { return _isAchievementSkill; } + + @Override + public void setLocationFilter(LocationFilter filter) + { + this._locationFilter = filter; + } + + @Override + public LocationFilter getLocationFilter() + { + return this._locationFilter; + } }