Skip to content

Commit

Permalink
Fixed bug causing potions to work incorrectly
Browse files Browse the repository at this point in the history
Issue Reference: #226
  • Loading branch information
booksaw committed Sep 18, 2021
1 parent cf9c716 commit e92f85a
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 12 deletions.
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,7 @@ Bug Fixes:

Bug Fixes:
- Fixed bug with OfflinePlayer name being null (#230)
- Fixed bug which caused potions to not damage players when they should (#226)

TODO (any TODO which is not specifically code), mainly used for reminders to update documentation

Expand Down
1 change: 0 additions & 1 deletion src/com/booksaw/betterTeams/Team.java
Original file line number Diff line number Diff line change
Expand Up @@ -1221,7 +1221,6 @@ public boolean canDamage(Player player, Player source) {
*/
public boolean canDamage(Team team, Player source) {
if (team.isAlly(getID()) || team == this) {

if (pvp && team.pvp) {
return true;
}
Expand Down
15 changes: 4 additions & 11 deletions src/com/booksaw/betterTeams/events/DamageManagement.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,9 @@ public DamageManagement() {
*
* @param e the damage event
*/
@EventHandler
@EventHandler(ignoreCancelled = true)
public void onDamage(EntityDamageByEntityEvent e) {

if (e.isCancelled()) {
return;
}

if (!(e.getEntity() instanceof Player)) {
return;
}
Expand Down Expand Up @@ -91,12 +87,11 @@ public void onDamage(EntityDamageByEntityEvent e) {
*
* @param e the potion splash event
*/
@EventHandler
@EventHandler(ignoreCancelled = true)
public void onPotion(PotionSplashEvent e) {
if (!(e.getEntity().getShooter() instanceof Player) || e.isCancelled() || !disablePotions) {
if (!(e.getEntity().getShooter() instanceof Player) || !disablePotions) {
return;
}

Player thrower = (Player) e.getEntity().getShooter();
Team team = Team.getTeam(thrower);
// thrower is not in team
Expand All @@ -105,9 +100,7 @@ public void onPotion(PotionSplashEvent e) {
}

Collection<PotionEffect> effects = e.getPotion().getEffects();

boolean cancel = false;

for (PotionEffect effect : effects) {
String type = effect.getType().getName();
if (type.equals(PotionEffectType.BAD_OMEN.getName()) || type.equals(PotionEffectType.BLINDNESS.getName())
Expand All @@ -126,7 +119,7 @@ public void onPotion(PotionSplashEvent e) {
for (LivingEntity entity : affectedEntities) {
try {
if (entity instanceof Player
&& Objects.requireNonNull(Team.getTeam((Player) entity)).canDamage(team, thrower)) {
&& !Objects.requireNonNull(Team.getTeam((Player) entity)).canDamage(team, thrower)) {
if (disableSelf && entity == thrower) {
continue;
}
Expand Down

0 comments on commit e92f85a

Please sign in to comment.