Fix issue with 'swords' and 'fishing' styles

This commit is contained in:
Esophose 2020-04-30 11:51:54 -06:00
parent 3bd7b5b9e9
commit 2afb90c669
4 changed files with 30 additions and 9 deletions

View file

@ -10,7 +10,7 @@ sourceCompatibility = 1.8
targetCompatibility = 1.8
compileJava.options.encoding = 'UTF-8'
group = 'dev.esophose'
version = '7.9'
version = '7.10'
java {
withJavadocJar()

View file

@ -1,3 +1,7 @@
=== v7.10 ===
* The 'swords' style now lets you edit what is considered a sword in its settings file
* Fixed wooden swords not being counted with the 'swords' style in 1.13+
* Fixed the 'fishing' style causing particles to spawn for users who don't even have it applied
=== v7.9 ===
+ Added options DISPLAY_NORMAL and DISPLAY_OVERHEAD to toggle-on-move
+ Added setting in each style setting file for can-toggle-on-combat

View file

@ -8,16 +8,16 @@ import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerFishEvent;
import org.bukkit.projectiles.ProjectileSource;
public class ParticleStyleFishing extends DefaultParticleStyle implements Listener {
@ -47,8 +47,11 @@ public class ParticleStyleFishing extends DefaultParticleStyle implements Listen
List<PParticle> particles = new ArrayList<>();
List<Projectile> listCopy = new ArrayList<>(this.projectiles); // Copy in case of modification while looping due to async
for (Projectile projectile : listCopy)
particles.add(new PParticle(projectile.getLocation(), 0.05F, 0.05F, 0.05F, 0.0F));
for (Projectile projectile : listCopy) {
ProjectileSource shooter = projectile.getShooter();
if (shooter instanceof Player && ((Player) shooter).getUniqueId().equals(particle.getOwnerUniqueId()))
particles.add(new PParticle(projectile.getLocation(), 0.05F, 0.05F, 0.05F, 0.0F));
}
return particles;
}

View file

@ -18,16 +18,18 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.inventory.ItemStack;
public class ParticleStyleSwords extends DefaultParticleStyle implements Listener {
private static final List<String> SWORD_NAMES;
private static final List<String> DEFAULT_SWORD_NAMES;
private int multiplier;
private List<String> swordNames;
static {
SWORD_NAMES = new ArrayList<>();
SWORD_NAMES.addAll(Arrays.asList("WOOD_SWORD", "WOODEN_SWORD", "STONE_SWORD", "IRON_SWORD", "GOLD_SWORD", "GOLDEN_SWORD", "DIAMOND_SWORD", "TRIDENT"));
DEFAULT_SWORD_NAMES = new ArrayList<>();
DEFAULT_SWORD_NAMES.addAll(Arrays.asList("WOOD_SWORD", "WOODEN_SWORD", "STONE_SWORD", "IRON_SWORD", "GOLD_SWORD", "GOLDEN_SWORD", "DIAMOND_SWORD", "TRIDENT"));
}
public ParticleStyleSwords() {
@ -57,11 +59,13 @@ public class ParticleStyleSwords extends DefaultParticleStyle implements Listene
@Override
protected void setDefaultSettings(CommentedFileConfiguration config) {
this.setIfNotExists("multiplier", 15, "The multiplier for the number of particles to spawn", "This style uses the same spawning as the 'normal' style");
this.setIfNotExists("sword-materials", DEFAULT_SWORD_NAMES, "The materails that are considered swords", "Set to [] to allow everything to be considered a sword", "Use AIR to allow a bare hand to be considered a sword");
}
@Override
protected void loadSettings(CommentedFileConfiguration config) {
this.multiplier = config.getInt("multiplier");
this.swordNames = config.getStringList("sword-materials");
}
@EventHandler(priority = EventPriority.MONITOR)
@ -72,7 +76,7 @@ public class ParticleStyleSwords extends DefaultParticleStyle implements Listene
Player player = (Player) event.getDamager();
LivingEntity entity = (LivingEntity) event.getEntity();
PPlayer pplayer = PlayerParticles.getInstance().getManager(DataManager.class).getPPlayer(player.getUniqueId());
if (pplayer == null || !SWORD_NAMES.contains(player.getInventory().getItemInMainHand().getType().name()))
if (pplayer == null || !this.isSword(player.getInventory().getItemInMainHand()))
return;
for (ParticlePair particle : pplayer.getActiveParticlesForStyle(DefaultStyles.SWORDS)) {
@ -82,4 +86,14 @@ public class ParticleStyleSwords extends DefaultParticleStyle implements Listene
}
}
private boolean isSword(ItemStack itemStack) {
if (this.swordNames.isEmpty())
return true;
if (itemStack == null)
return this.swordNames.contains("AIR");
return this.swordNames.contains(itemStack.getType().name());
}
}