From 5776ad28e168e217555503f3bfcc580b8a98a4e7 Mon Sep 17 00:00:00 2001 From: MistPhizzle Date: Sat, 28 Jun 2014 16:25:27 -0400 Subject: [PATCH] isIgniteAbility() and isExplodeAbility() added For Region Protection. ProjectKorra respects explosion and fire flags in various plugins, so this will allow an ability to register as such. isIgnite() means the ability produces fire (Like Blaze) and isExplodeAbility() means the ability produces an explode (Like FireBlast and Lightning) --- .classpath | 7 ++ .../ProjectKorra/Ability/AbilityModule.java | 8 ++ .../Ability/AbilityModuleManager.java | 14 +++ .../ProjectKorra/ConfigManager.java | 7 ++ .../projectkorra/ProjectKorra/Methods.java | 94 +++++++++++++------ src/config.yml | 7 ++ 6 files changed, 107 insertions(+), 30 deletions(-) diff --git a/.classpath b/.classpath index e713abef..6b746735 100644 --- a/.classpath +++ b/.classpath @@ -4,5 +4,12 @@ + + + + + + + diff --git a/src/com/projectkorra/ProjectKorra/Ability/AbilityModule.java b/src/com/projectkorra/ProjectKorra/Ability/AbilityModule.java index 01d8a038..b06981b2 100644 --- a/src/com/projectkorra/ProjectKorra/Ability/AbilityModule.java +++ b/src/com/projectkorra/ProjectKorra/Ability/AbilityModule.java @@ -43,5 +43,13 @@ public class AbilityModule extends AbilityLoadable implements Cloneable { return ""; } + public boolean isIgniteAbility() { + return false; + } + + public boolean isExplodeAbility() { + return false; + } + } diff --git a/src/com/projectkorra/ProjectKorra/Ability/AbilityModuleManager.java b/src/com/projectkorra/ProjectKorra/Ability/AbilityModuleManager.java index 79a97e1b..fa2a97b6 100644 --- a/src/com/projectkorra/ProjectKorra/Ability/AbilityModuleManager.java +++ b/src/com/projectkorra/ProjectKorra/Ability/AbilityModuleManager.java @@ -25,6 +25,8 @@ public class AbilityModuleManager { public static HashSet shiftabilities; public static HashMap authors; public static HashSet harmlessabilities; + public static HashSet igniteabilities; + public static HashSet explodeabilities; public static HashMap descriptions; @@ -45,6 +47,8 @@ public class AbilityModuleManager { descriptions = new HashMap(); authors = new HashMap(); harmlessabilities = new HashSet(); + explodeabilities = new HashSet(); + igniteabilities = new HashSet(); ability = loader.load(AbilityModule.class); fill(); } @@ -57,6 +61,8 @@ public class AbilityModuleManager { abilities.add(a.name()); airbendingabilities.add(a.name()); descriptions.put(a.name(), ProjectKorra.plugin.getConfig().getString("Abilities.Air." + a.name() + ".Description")); + if (a == StockAbilities.AirScooter) harmlessabilities.add(a.name()); + if (a == StockAbilities.AirSpout) harmlessabilities.add(a.name()); } } else if (StockAbilities.isWaterbending(a)) { @@ -64,6 +70,8 @@ public class AbilityModuleManager { abilities.add(a.name()); waterbendingabilities.add(a.name()); descriptions.put(a.name(), ProjectKorra.plugin.getConfig().getString("Abilities.Water." + a.name() + ".Description")); + if (a == StockAbilities.WaterSpout) harmlessabilities.add(a.name()); + if (a == StockAbilities.HealingWaters) harmlessabilities.add(a.name()); } } else if (StockAbilities.isEarthbending(a)) { @@ -71,6 +79,7 @@ public class AbilityModuleManager { abilities.add(a.name()); earthbendingabilities.add(a.name()); descriptions.put(a.name(), ProjectKorra.plugin.getConfig().getString("Abilities.Earth." + a.name() + ".Description")); + if (a == StockAbilities.Tremorsense) harmlessabilities.add(a.name()); } } else if (StockAbilities.isFirebending(a)) { @@ -78,6 +87,10 @@ public class AbilityModuleManager { abilities.add(a.name()); firebendingabilities.add(a.name()); descriptions.put(a.name(), ProjectKorra.plugin.getConfig().getString("Abilities.Fire." + a.name() + ".Description")); + if (a == StockAbilities.Illumination) harmlessabilities.add(a.name()); + if (a == StockAbilities.Blaze) igniteabilities.add(a.name()); + if (a == StockAbilities.FireBlast) explodeabilities.add(a.name()); + if (a == StockAbilities.Lightning) explodeabilities.add(a.name()); } } else if (StockAbilities.isChiBlocking(a)) { @@ -85,6 +98,7 @@ public class AbilityModuleManager { abilities.add(a.name()); chiabilities.add(a.name()); descriptions.put(a.name(), ProjectKorra.plugin.getConfig().getString("Abilities.Chi." + a.name() + ".Description")); + if (a == StockAbilities.HighJump) harmlessabilities.add(a.name()); } } else { diff --git a/src/com/projectkorra/ProjectKorra/ConfigManager.java b/src/com/projectkorra/ProjectKorra/ConfigManager.java index 77f30aef..b86b2d2f 100644 --- a/src/com/projectkorra/ProjectKorra/ConfigManager.java +++ b/src/com/projectkorra/ProjectKorra/ConfigManager.java @@ -50,6 +50,13 @@ public class ConfigManager { plugin.getConfig().addDefault("Properties.GlobalCooldown", 500); plugin.getConfig().addDefault("Properties.SeaLevel", 62); + config.addDefault("Properties.RegionProtection.AllowHarmlessAbilities", true); + config.addDefault("Properties.RegionProtection.RespectWorldGuard", true); + config.addDefault("Properties.RegionProtection.RespectGriefPrevention", true); + config.addDefault("Properties.RegionProtection.RespectFactions", true); + config.addDefault("Properties.RegionProtection.RespectTowny", true); + config.addDefault("Properties.RegionProtection.RespectPreciousStones", true); + plugin.getConfig().addDefault("Properties.Air.CanBendWithWeapons", false); plugin.getConfig().addDefault("Properties.Water.CanBendWithWeapons", true); diff --git a/src/com/projectkorra/ProjectKorra/Methods.java b/src/com/projectkorra/ProjectKorra/Methods.java index 338741f0..9ab5414d 100644 --- a/src/com/projectkorra/ProjectKorra/Methods.java +++ b/src/com/projectkorra/ProjectKorra/Methods.java @@ -11,6 +11,10 @@ import java.util.List; import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; +import me.ryanhamshire.GriefPrevention.GriefPrevention; +import net.sacredlabyrinth.Phaed.PreciousStones.FieldFlag; +import net.sacredlabyrinth.Phaed.PreciousStones.PreciousStones; + import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Effect; @@ -28,8 +32,25 @@ import org.bukkit.entity.Player; import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageEvent.DamageCause; import org.bukkit.inventory.ItemStack; +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.PluginManager; import org.bukkit.util.Vector; +import com.massivecraft.factions.listeners.FactionsListenerMain; +import com.massivecraft.mcore.ps.PS; +import com.palmergames.bukkit.towny.Towny; +import com.palmergames.bukkit.towny.TownyMessaging; +import com.palmergames.bukkit.towny.TownySettings; +import com.palmergames.bukkit.towny.object.Coord; +import com.palmergames.bukkit.towny.object.PlayerCache; +import com.palmergames.bukkit.towny.object.PlayerCache.TownBlockStatus; +import com.palmergames.bukkit.towny.object.TownyPermission; +import com.palmergames.bukkit.towny.object.TownyUniverse; +import com.palmergames.bukkit.towny.object.TownyWorld; +import com.palmergames.bukkit.towny.object.WorldCoord; +import com.palmergames.bukkit.towny.utils.PlayerCacheUtil; +import com.palmergames.bukkit.towny.war.flagwar.TownyWar; +import com.palmergames.bukkit.towny.war.flagwar.TownyWarConfig; import com.projectkorra.ProjectKorra.Ability.AbilityModule; import com.projectkorra.ProjectKorra.Ability.AbilityModuleManager; import com.projectkorra.ProjectKorra.Ability.AvatarState; @@ -39,6 +60,7 @@ import com.projectkorra.ProjectKorra.earthbending.EarthPassive; import com.projectkorra.ProjectKorra.waterbending.FreezeMelt; import com.projectkorra.ProjectKorra.waterbending.WaterManipulation; import com.projectkorra.ProjectKorra.waterbending.WaterSpout; +import com.sk89q.worldguard.bukkit.WorldGuardPlugin; public class Methods { @@ -47,6 +69,13 @@ public class Methods { public Methods(ProjectKorra plugin) { Methods.plugin = plugin; } + + private static boolean allowharmless = plugin.getConfig().getBoolean("Properties.RegionProtection.AllowHarmlessAbilities"); + private static boolean respectWorldGuard = plugin.getConfig().getBoolean("Properties.RegionProtection.RespectWorldGuard"); + private static boolean respectPreciousStones = plugin.getConfig().getBoolean("Properties.RegionProtection.RespectPreciousStones"); + private static boolean respectFactions = plugin.getConfig().getBoolean("Properties.RegionProtection.RespectFactions"); + private static boolean respectTowny = plugin.getConfig().getBoolean("Properties.RegionProtection.RespectTowny"); + private static boolean respectGriefPrevention = plugin.getConfig().getBoolean("Properties.RegionProtection.RespectGriefPrevention"); private static final ItemStack pickaxe = new ItemStack( Material.DIAMOND_PICKAXE); @@ -1162,15 +1191,21 @@ public class Methods { return faces[besti]; } + + public static boolean isHarmlessAbility(String ability) { + return Arrays.asList(AbilityModuleManager.harmlessabilities).contains(ability); + } public static boolean isRegionProtectedFromBuild(Player player, String ability, Location loc) { - List ignite = new ArrayList(); - ignite.add(Abilities.Blaze); - List explode = new ArrayList(); - explode.add(Abilities.FireBlast); - explode.add(Abilities.Lightning); + Set ignite = AbilityModuleManager.igniteabilities; + Set explode = AbilityModuleManager.explodeabilities; +// List ignite = new ArrayList(); +// ignite.add(Abilities.Blaze); +// List explode = new ArrayList(); +// explode.add(Abilities.FireBlast); +// explode.add(Abilities.Lightning); if (ability == null && allowharmless) return false; @@ -1218,7 +1253,6 @@ public class Methods { } } - if (explode.contains(ability)) { if (wg.getGlobalStateManager().get(location.getWorld()).blockTNTExplosions) return true; @@ -1238,17 +1272,17 @@ public class Methods { if (psp != null && respectPreciousStones) { PreciousStones ps = (PreciousStones) psp; - if (ignite.contains(ability)) { - if (ps.getForceFieldManager().hasSourceField(location, - FieldFlag.PREVENT_FIRE)) - return true; - } +// if (ignite.contains(ability)) { +// if (ps.getForceFieldManager().hasSourceField(location, +// FieldFlag.PREVENT_FIRE)) +// return true; +// } - if (explode.contains(ability)) { - if (ps.getForceFieldManager().hasSourceField(location, - FieldFlag.PREVENT_EXPLOSIONS)) - return true; - } +// if (explode.contains(ability)) { +// if (ps.getForceFieldManager().hasSourceField(location, +// FieldFlag.PREVENT_EXPLOSIONS)) +// return true; +// } if (ps.getForceFieldManager().hasSourceField(location, FieldFlag.PREVENT_PLACE)) @@ -1256,13 +1290,13 @@ public class Methods { } if (fcp != null && mcore != null && respectFactions) { - if (ignite.contains(ability)) { - - } - - if (explode.contains(ability)) { - - } +// if (ignite.contains(ability)) { +// +// } +// +// if (explode.contains(ability)) { +// +// } if (!FactionsListenerMain.canPlayerBuildAt(player, PS.valueOf(loc.getBlock()), false)) { @@ -1290,13 +1324,13 @@ public class Methods { location, 3, (byte) 0, TownyPermission.ActionType.BUILD); - if (ignite.contains(ability)) { - - } - - if (explode.contains(ability)) { - - } +// if (ignite.contains(ability)) { +// +// } +// +// if (explode.contains(ability)) { +// +// } if (!bBuild) { PlayerCache cache = twn.getCache(player); diff --git a/src/config.yml b/src/config.yml index 5b30bb08..6d386c47 100644 --- a/src/config.yml +++ b/src/config.yml @@ -18,6 +18,13 @@ Properties: Water: AQUA Earth: GREEN Chi: GOLD + RegionProtection: + AllowHarmlessAbilities: true + RespectWorldGuard: true + RespectGriefPrevention: true + RespectFactions: true + RespectTowny: true + RespectPreciousStones: true Air: CanBendWithWeapons: false Water: