Skip to content

Commit

Permalink
Update to 3.18.1
Browse files Browse the repository at this point in the history
  • Loading branch information
ChanceSD committed Apr 24, 2024
1 parent cf3ee0c commit 8ef4535
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 18 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<sonar.organization>chancesd</sonar.organization>
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
<revision>3.18</revision>
<revision>3.18.1</revision>
</properties>

<distributionManagement>
Expand Down
2 changes: 1 addition & 1 deletion pvpmanager/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@
<dependency>
<groupId>me.chancesd.sdutils</groupId>
<artifactId>sdutils</artifactId>
<version>1.1-SNAPSHOT</version>
<version>1.2-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import org.bukkit.event.player.PlayerItemConsumeEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.projectiles.ProjectileSource;

import com.google.common.cache.Cache;
Expand All @@ -37,7 +36,7 @@
public class EntityListener1_9 implements Listener {

private final PlayerHandler ph;
private final Cache<UUID, Set<AreaEffectCloud>> potionMessageCache = CacheBuilder.newBuilder().expireAfterAccess(5, TimeUnit.SECONDS).build();
private final Cache<UUID, Set<AreaEffectCloud>> potionMessageCache = CacheBuilder.newBuilder().expireAfterAccess(3, TimeUnit.SECONDS).build();

public EntityListener1_9(final PlayerHandler ph) {
this.ph = ph;
Expand All @@ -62,8 +61,7 @@ public final void onLingeringPotionSplash(final AreaEffectCloudApplyEvent event)
if (event.getAffectedEntities().isEmpty() || !(areaCloudSource instanceof Player))
return;

final PotionEffectType potionType = areaCloud.getBasePotionType().getEffectType();
if (potionType == null || !CombatUtils.isHarmfulPotion(potionType))
if (!CombatUtils.hasHarmfulPotion(areaCloud))
return;

final Player player = (Player) areaCloudSource;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ public DependencyManager() {
+ "Issues with those features often get wrongly blamed on PvPManager and cause conflicts due to the lack of GP feedback messages.");
}
if (Bukkit.getPluginManager().getPlugin("TAB") != null && Settings.useNameTag()) {
Log.warning("TAB detected. If you want nametags to change while in combat, set 'anti-override' to false in TAB's config."
Log.info("TAB detected. If you want nametags to change while in combat, set 'anti-override' to false in TAB's config."
+ " (Doing that will prevent TAB from changing nametags)");
Log.warning("Or use the premium version of PvPManager which hooks into TAB for nametag/tablist changes.");
Log.info("Or use the premium version of PvPManager which hooks into TAB for nametag/tablist changes.");
}
final List<Hook> failedHooks = setupHooks(Hook.values());
// Delayed check for hooks that do not use softdepend
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ private PvPlayer addUser(final PvPlayer p) {
if (save) {
players.put(p.getUUID(), p);
}
Log.debug("Adding " + p + " to online players. Saved: " + save);
Log.debug("Creating " + p + " Saved: " + save);
return p;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ private synchronized void loadData() {
}
this.loaded = true;
notifyAll();
Log.debug("Finished loading data for " + this);
Log.debug("Finished loading data for " + this + (nametag != null ? " with " + nametag.getClass().getSimpleName() : ""));
}

private void loadUserData(final Map<String, Object> userData) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package me.NoChance.PvPManager.Utils;

import java.lang.reflect.InvocationTargetException;
import java.text.DecimalFormat;
import java.util.List;
import java.util.Map;
Expand All @@ -19,13 +20,16 @@
import org.bukkit.event.entity.EntityCombustByEntityEvent;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.potion.PotionType;
import org.bukkit.projectiles.ProjectileSource;

import me.NoChance.PvPManager.Settings.Messages;
import me.NoChance.PvPManager.Settings.Settings;
import me.chancesd.pvpmanager.utils.ScheduleUtils;
import me.chancesd.sdutils.utils.Log;
import me.chancesd.sdutils.utils.ReflectionUtil;

public final class CombatUtils {

Expand Down Expand Up @@ -187,6 +191,23 @@ public static boolean isWorldExcluded(final String worldName) {
return Settings.getWorldsExcluded().contains(worldName);
}

public static boolean hasHarmfulPotion(final AreaEffectCloud areaCloud) {
if (isVersionAtLeast(Settings.getMinecraftVersion(), "1.20")) {
final PotionType basePotionType = areaCloud.getBasePotionType();
if (basePotionType == null)
return false;
final List<PotionEffect> potionTypes = basePotionType.getPotionEffects();
return !potionTypes.isEmpty() && potionTypes.stream().anyMatch(p -> isHarmfulPotion(p.getType()));
}
PotionEffectType potionEffectType = null;
try {
potionEffectType = (PotionEffectType) ReflectionUtil.invokeMethods(areaCloud, "getBasePotionData", "getType", "getEffectType");
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) {
Log.severe("Error getting potion type of lingering potion", e);
}
return potionEffectType != null && isHarmfulPotion(potionEffectType);
}

public static boolean isHarmfulPotion(final PotionEffectType type) {
return Settings.getHarmfulPotions().contains(type.getName());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import me.NoChance.PvPManager.PvPlayer;
import me.NoChance.PvPManager.Settings.Settings;
import me.NoChance.PvPManager.Utils.ChatUtils;
import me.chancesd.sdutils.utils.Log;

public abstract class NameTag {

Expand All @@ -19,7 +18,6 @@ protected NameTag(final PvPlayer p) {
this.combatSuffix = ChatUtils.colorize(Settings.getNameTagSuffix());
this.pvpOnPrefix = Settings.getToggleColorOn().equalsIgnoreCase("none") ? "" : ChatUtils.colorize(Settings.getToggleColorOn());
this.pvpOffPrefix = Settings.getToggleColorOff().equalsIgnoreCase("none") ? "" : ChatUtils.colorize(Settings.getToggleColorOff());
Log.debug("Creating " + this.getClass().getSimpleName() + " for " + p);
}

public abstract void setInCombat();
Expand Down
6 changes: 3 additions & 3 deletions pvpmanager/src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -258,9 +258,9 @@ Metrics:
# Potions considered harmful, players will be tagged by them and protected from them
# See list here https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/potion/PotionEffectType.html
Harmful Potions:
- SLOW
- SLOW_DIGGING
- CONFUSION
- SLOWNESS
- MINING_FATIGUE
- NAUSEA
- BLINDNESS
- HUNGER
- WEAKNESS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.RETURNS_MOCKS;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
Expand Down Expand Up @@ -209,8 +208,8 @@ final void failCancel() {
ph.get(defender).setPvP(true);
ph.get(attacker).setPvP(true);

doReturn(true).when(attacker).isFlying();
doReturn(true).when(defender).isFlying();
when(attacker.isFlying()).thenReturn(true);
when(defender.isFlying()).thenReturn(true);
assertTrue(attacker.isFlying());
assertTrue(defender.isFlying());
assertEquals(CancelResult.FAIL, ph.tryCancel(attacker, defender));
Expand Down

0 comments on commit 8ef4535

Please sign in to comment.