Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

[Fix] Removing deprecated method projectile.getShooter() #122

Merged
merged 2 commits into from

2 participants

@coegho

This method is deprecated and it prevents me to compile Towny. I fixed it, but it must be revised to ensure that dispensers can't cause damages when war time = false.

@ElgarL ElgarL merged commit 5705306 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 12, 2014
  1. @coegho
Commits on Feb 13, 2014
  1. @coegho
This page is out of date. Refresh to see the latest.
View
23 src/com/palmergames/bukkit/towny/listeners/TownyEntityListener.java
@@ -30,6 +30,7 @@
import org.bukkit.event.hanging.HangingBreakByEntityEvent;
import org.bukkit.event.hanging.HangingBreakEvent;
import org.bukkit.event.hanging.HangingPlaceEvent;
+import org.bukkit.projectiles.ProjectileSource;
import com.palmergames.bukkit.towny.Towny;
import com.palmergames.bukkit.towny.TownyMessaging;
@@ -140,8 +141,15 @@ public void onPotionSplashEvent(PotionSplashEvent event) {
List<LivingEntity> affectedEntities = (List<LivingEntity>) event.getAffectedEntities();
ThrownPotion potion = event.getPotion();
-
- Entity attacker = potion.getShooter();
+ Entity attacker;
+
+ ProjectileSource source = potion.getShooter();
+ if(!(source instanceof Entity)) {
+ return; //TODO: prevent damage from dispensers
+ }
+ else {
+ attacker = (Entity) source;
+ }
// Not Wartime
if (!TownyUniverse.isWarTime())
@@ -503,10 +511,15 @@ public void onEntityCombustByEntityEvent(EntityCombustByEntityEvent event) {
Entity combuster = event.getCombuster();
Entity defender = event.getEntity();
-
+ LivingEntity attacker;
if (combuster instanceof Projectile) {
-
- LivingEntity attacker = ((Projectile) combuster).getShooter();
+ ProjectileSource source = ((Projectile) combuster).getShooter();
+ if(!(source instanceof LivingEntity)) {
+ return; //TODO: prevent damage from dispensers
+ }
+ else {
+ attacker = (LivingEntity) source;
+ }
// There is an attacker and Not war time.
if ((attacker != null) && (!TownyUniverse.isWarTime())) {
View
10 src/com/palmergames/bukkit/towny/utils/CombatUtil.java
@@ -27,6 +27,7 @@
import com.palmergames.bukkit.towny.object.TownyUniverse;
import com.palmergames.bukkit.towny.object.TownyWorld;
import com.palmergames.bukkit.towny.object.WorldCoord;
+import org.bukkit.projectiles.ProjectileSource;
/**
*
@@ -62,7 +63,14 @@ public static boolean preventDamageCall(Towny plugin, Entity attacker, Entity de
*/
if (attacker instanceof Projectile) {
Projectile projectile = (Projectile) attacker;
- attacker = projectile.getShooter();
+ ProjectileSource source = projectile.getShooter();
+ if(source instanceof Entity) {
+ attacker = (Entity) source;
+ }
+ else {
+ return false; //TODO: prevent damage from dispensers
+ }
+
}
if (attacker instanceof Player)
Something went wrong with that request. Please try again.