Determine whether Ice Prison target is valid. Fixes PC-281

This commit is contained in:
samczsun 2016-05-11 22:52:39 -04:00 committed by cnr
parent 1497662b2e
commit 1fc4239b89
5 changed files with 70 additions and 3 deletions

View File

@ -325,6 +325,14 @@ public class ClansManager extends MiniClientPlugin<ClientClan>implements IRelati
skillManager.RemoveSkill("Dwarf Toss", "Block Toss"); skillManager.RemoveSkill("Dwarf Toss", "Block Toss");
skillManager.removeSkill("Whirlwind Axe"); skillManager.removeSkill("Whirlwind Axe");
skillManager.removeSkill("Shield Smash"); 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); _worldEvent.setFactory(skillManager);
_classManager = new ClassManager(plugin, _clientManager, donationManager, skillManager, itemFactory, webServerAddress); _classManager = new ClassManager(plugin, _clientManager, donationManager, skillManager, itemFactory, webServerAddress);

View File

@ -39,4 +39,7 @@ public interface ISkill
int getMaxLevel(); int getMaxLevel();
boolean isAchievementSkill(); boolean isAchievementSkill();
void setLocationFilter(LocationFilter locationFilter);
LocationFilter getLocationFilter();
} }

View File

@ -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);
}

View File

@ -1,6 +1,8 @@
package mineplex.minecraft.game.classcombat.Skill.Mage; package mineplex.minecraft.game.classcombat.Skill.Mage;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
import org.bukkit.Effect; import org.bukkit.Effect;
import org.bukkit.Material; import org.bukkit.Material;
@ -118,6 +120,9 @@ public class IcePrison extends SkillActive implements IThrown
//Sphere //Sphere
HashMap<Block, Double> blocks = UtilBlock.getInRadius(block, 3.8d); HashMap<Block, Double> blocks = UtilBlock.getInRadius(block, 3.8d);
// To save having to calculate everything again
Set<Block> acceptable = new HashSet<>();
boolean failed = false;
for (Block cur : blocks.keySet()) for (Block cur : blocks.keySet())
{ {
if (!UtilBlock.airFoliage(cur)) if (!UtilBlock.airFoliage(cur))
@ -130,8 +135,28 @@ public class IcePrison extends SkillActive implements IThrown
if (cur.getX() == block.getX() && cur.getZ() == block.getZ() && cur.getY() > block.getY()) if (cur.getX() == block.getX() && cur.getZ() == block.getZ() && cur.getY() > block.getY())
continue; continue;
if (getLocationFilter().accept(cur.getLocation()))
{
acceptable.add(cur);
}
else
{
failed = true;
break;
}
}
if (!failed)
{
for (Block cur : acceptable)
{
FreezeBlock(cur, block, level); FreezeBlock(cur, block, level);
} }
}
else
{
UtilPlayer.message(player, F.main("Skill", "You cannot use " + F.skill(GetName()) + " here."));
}
/* /*
FreezeBlock(block.getRelative(3, 0, 3), block, level); FreezeBlock(block.getRelative(3, 0, 3), block, level);

View File

@ -12,7 +12,6 @@ import mineplex.core.common.util.UtilTextBottom;
import mineplex.minecraft.game.classcombat.Class.IPvpClass.ClassType; import mineplex.minecraft.game.classcombat.Class.IPvpClass.ClassType;
import mineplex.minecraft.game.classcombat.Skill.repository.token.SkillToken; import mineplex.minecraft.game.classcombat.Skill.repository.token.SkillToken;
import org.bukkit.ChatColor;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.Sound; import org.bukkit.Sound;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
@ -43,6 +42,8 @@ public abstract class Skill implements ISkill, Listener
private boolean _isAchievementSkill = false; private boolean _isAchievementSkill = false;
private LocationFilter _locationFilter = LocationFilter.ACCEPT_ALL;
public SkillFactory Factory; public SkillFactory Factory;
public Skill(SkillFactory skills, String name, ClassType classType, SkillType skillType, int cost, int maxLevel) 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; return _isAchievementSkill;
} }
@Override
public void setLocationFilter(LocationFilter filter)
{
this._locationFilter = filter;
}
@Override
public LocationFilter getLocationFilter()
{
return this._locationFilter;
}
} }