Add editable names for effects/styles. Remove cos/sin caching

This commit is contained in:
Esophose 2020-01-14 13:37:22 -07:00
parent 2303696a09
commit 99b2e3796a
35 changed files with 339 additions and 354 deletions

View file

@ -7,10 +7,11 @@
* + Add setting to disable particles while in combat * + Add setting to disable particles while in combat
* + Add a command aliases section to the config * + Add a command aliases section to the config
* * /ppo now uses your permissions instead of the player you are targetting * * /ppo now uses your permissions instead of the player you are targetting
*
*/ */
/* /*
* * Fixed the 'swords' style so you have to be holding a sword/trident
* * Fixed several styles ignoring the disabled worlds setting
* + Added a setting 'dust-size' to change the size of dust particles in 1.13+ * + Added a setting 'dust-size' to change the size of dust particles in 1.13+
* * Cleaned up duplicated command parsing * * Cleaned up duplicated command parsing
* + Added command '/pp fixed teleport <id>' that requires the permission playerparticles.fixed.teleport * + Added command '/pp fixed teleport <id>' that requires the permission playerparticles.fixed.teleport
@ -43,6 +44,7 @@ import dev.esophose.playerparticles.hook.PlaceholderAPIHook;
import dev.esophose.playerparticles.manager.CommandManager; import dev.esophose.playerparticles.manager.CommandManager;
import dev.esophose.playerparticles.manager.ConfigurationManager; import dev.esophose.playerparticles.manager.ConfigurationManager;
import dev.esophose.playerparticles.manager.ConfigurationManager.Setting; import dev.esophose.playerparticles.manager.ConfigurationManager.Setting;
import dev.esophose.playerparticles.manager.DataManager;
import dev.esophose.playerparticles.manager.DataMigrationManager; import dev.esophose.playerparticles.manager.DataMigrationManager;
import dev.esophose.playerparticles.manager.LocaleManager; import dev.esophose.playerparticles.manager.LocaleManager;
import dev.esophose.playerparticles.manager.Manager; import dev.esophose.playerparticles.manager.Manager;
@ -54,7 +56,7 @@ import dev.esophose.playerparticles.manager.PluginUpdateManager;
import dev.esophose.playerparticles.particles.PPlayerMovementListener; import dev.esophose.playerparticles.particles.PPlayerMovementListener;
import dev.esophose.playerparticles.util.Metrics; import dev.esophose.playerparticles.util.Metrics;
import java.io.File; import java.io.File;
import java.util.HashMap; import java.util.LinkedHashMap;
import java.util.Map; import java.util.Map;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.PluginManager;
@ -75,15 +77,16 @@ public class PlayerParticles extends JavaPlugin {
*/ */
private Map<Class<?>, Manager> managers; private Map<Class<?>, Manager> managers;
public PlayerParticles() {
INSTANCE = this;
this.managers = new LinkedHashMap<>();
}
/** /**
* Executes essential tasks for starting up the plugin * Executes essential tasks for starting up the plugin
*/ */
@Override @Override
public void onEnable() { public void onEnable() {
INSTANCE = this;
this.managers = new HashMap<>();
this.reload(); this.reload();
PluginManager pm = Bukkit.getPluginManager(); PluginManager pm = Bukkit.getPluginManager();
@ -95,6 +98,8 @@ public class PlayerParticles extends JavaPlugin {
if (PlaceholderAPIHook.enabled()) if (PlaceholderAPIHook.enabled())
new ParticlePlaceholderExpansion(this).register(); new ParticlePlaceholderExpansion(this).register();
PlayerChatHook.setup();
} }
@Override @Override
@ -141,21 +146,19 @@ public class PlayerParticles extends JavaPlugin {
*/ */
public void reload() { public void reload() {
this.managers.values().forEach(Manager::disable); this.managers.values().forEach(Manager::disable);
this.managers.clear(); this.managers.values().forEach(Manager::reload);
this.getManager(CommandManager.class); this.getManager(CommandManager.class);
this.getManager(ParticleStyleManager.class); this.getManager(ParticleStyleManager.class);
this.getManager(ParticleGroupPresetManager.class); this.getManager(ParticleGroupPresetManager.class);
this.getManager(ConfigurationManager.class); this.getManager(ConfigurationManager.class);
this.getManager(DataManager.class);
this.getManager(DataMigrationManager.class); this.getManager(DataMigrationManager.class);
this.getManager(PluginUpdateManager.class);
this.getManager(ParticleManager.class); this.getManager(ParticleManager.class);
this.getManager(LocaleManager.class); this.getManager(LocaleManager.class);
this.getManager(ConfigurationManager.class); this.getManager(ConfigurationManager.class);
this.getManager(PermissionManager.class); this.getManager(PermissionManager.class);
this.getManager(PluginUpdateManager.class); this.getManager(PluginUpdateManager.class);
PlayerChatHook.setup();
} }
/** /**

View file

@ -36,7 +36,7 @@ public class GuiInventoryEditEffect extends GuiInventory {
ParticleEffect effect = effectsUserHasPermissionFor.get(i); ParticleEffect effect = effectsUserHasPermissionFor.get(i);
GuiActionButton selectButton = new GuiActionButton( GuiActionButton selectButton = new GuiActionButton(
slot, slot,
GuiIcon.EFFECT.get(effect.getName()), GuiIcon.EFFECT.get(effect.getInternalName()),
localeManager.getLocaleMessage("gui-color-icon-name") + ParticleUtils.formatName(effect.getName()), localeManager.getLocaleMessage("gui-color-icon-name") + ParticleUtils.formatName(effect.getName()),
new String[]{localeManager.getLocaleMessage("gui-color-info") + localeManager.getLocaleMessage("gui-select-effect-description", StringPlaceholders.single("effect", ParticleUtils.formatName(effect.getName())))}, new String[]{localeManager.getLocaleMessage("gui-color-info") + localeManager.getLocaleMessage("gui-select-effect-description", StringPlaceholders.single("effect", ParticleUtils.formatName(effect.getName())))},
(button, isShiftClick) -> { (button, isShiftClick) -> {

View file

@ -36,7 +36,7 @@ public class GuiInventoryEditStyle extends GuiInventory {
ParticleStyle style = stylesUserHasPermissionFor.get(i); ParticleStyle style = stylesUserHasPermissionFor.get(i);
GuiActionButton selectButton = new GuiActionButton( GuiActionButton selectButton = new GuiActionButton(
slot, slot,
GuiIcon.STYLE.get(style.getName()), GuiIcon.STYLE.get(style.getInternalName()),
localeManager.getLocaleMessage("gui-color-icon-name") + ParticleUtils.formatName(style.getName()), localeManager.getLocaleMessage("gui-color-icon-name") + ParticleUtils.formatName(style.getName()),
new String[]{localeManager.getLocaleMessage("gui-color-info") + localeManager.getLocaleMessage("gui-select-style-description", StringPlaceholders.single("style", ParticleUtils.formatName(style.getName())))}, new String[]{localeManager.getLocaleMessage("gui-color-info") + localeManager.getLocaleMessage("gui-select-style-description", StringPlaceholders.single("style", ParticleUtils.formatName(style.getName())))},
(button, isShiftClick) -> { (button, isShiftClick) -> {

View file

@ -146,8 +146,8 @@ public class DataManager extends Manager {
// Particle properties // Particle properties
int id = result.getInt("id"); int id = result.getInt("id");
ParticleEffect effect = ParticleEffect.fromName(result.getString("effect")); ParticleEffect effect = ParticleEffect.fromInternalName(result.getString("effect"));
ParticleStyle style = ParticleStyle.fromName(result.getString("style")); ParticleStyle style = ParticleStyle.fromInternalName(result.getString("style"));
Material itemMaterial = ParticleUtils.closestMatchWithFallback(true, result.getString("item_material")); Material itemMaterial = ParticleUtils.closestMatchWithFallback(true, result.getString("item_material"));
Material blockMaterial = ParticleUtils.closestMatchWithFallback(true, result.getString("block_material")); Material blockMaterial = ParticleUtils.closestMatchWithFallback(true, result.getString("block_material"));
NoteColor noteColor = new NoteColor(result.getInt("note")); NoteColor noteColor = new NoteColor(result.getInt("note"));
@ -211,8 +211,8 @@ public class DataManager extends Manager {
// Particle properties // Particle properties
int particleId = result.getInt("p_id"); int particleId = result.getInt("p_id");
ParticleEffect effect = ParticleEffect.fromName(result.getString("effect")); ParticleEffect effect = ParticleEffect.fromInternalName(result.getString("effect"));
ParticleStyle style = ParticleStyle.fromName(result.getString("style")); ParticleStyle style = ParticleStyle.fromInternalName(result.getString("style"));
Material itemMaterial = ParticleUtils.closestMatchWithFallback(true, result.getString("item_material")); Material itemMaterial = ParticleUtils.closestMatchWithFallback(true, result.getString("item_material"));
Material blockMaterial = ParticleUtils.closestMatchWithFallback(true, result.getString("block_material")); Material blockMaterial = ParticleUtils.closestMatchWithFallback(true, result.getString("block_material"));
NoteColor noteColor = new NoteColor(result.getInt("note")); NoteColor noteColor = new NoteColor(result.getInt("note"));
@ -341,8 +341,8 @@ public class DataManager extends Manager {
particlesStatement.setString(1, UUID.randomUUID().toString()); particlesStatement.setString(1, UUID.randomUUID().toString());
particlesStatement.setString(2, groupUUID); particlesStatement.setString(2, groupUUID);
particlesStatement.setInt(3, particle.getId()); particlesStatement.setInt(3, particle.getId());
particlesStatement.setString(4, particle.getEffect().getName()); particlesStatement.setString(4, particle.getEffect().getInternalName());
particlesStatement.setString(5, particle.getStyle().getName()); particlesStatement.setString(5, particle.getStyle().getInternalName());
particlesStatement.setString(6, particle.getItemMaterial().name()); particlesStatement.setString(6, particle.getItemMaterial().name());
particlesStatement.setString(7, particle.getBlockMaterial().name()); particlesStatement.setString(7, particle.getBlockMaterial().name());
particlesStatement.setInt(8, particle.getNoteColor().getNote()); particlesStatement.setInt(8, particle.getNoteColor().getNote());
@ -412,8 +412,8 @@ public class DataManager extends Manager {
ParticlePair particle = fixedEffect.getParticlePair(); ParticlePair particle = fixedEffect.getParticlePair();
statement.setString(1, particleUUID); statement.setString(1, particleUUID);
statement.setInt(2, fixedEffect.getId()); statement.setInt(2, fixedEffect.getId());
statement.setString(3, particle.getEffect().getName()); statement.setString(3, particle.getEffect().getInternalName());
statement.setString(4, particle.getStyle().getName()); statement.setString(4, particle.getStyle().getInternalName());
statement.setString(5, particle.getItemMaterial().name()); statement.setString(5, particle.getItemMaterial().name());
statement.setString(6, particle.getBlockMaterial().name()); statement.setString(6, particle.getBlockMaterial().name());
statement.setInt(7, particle.getNoteColor().getNote()); statement.setInt(7, particle.getNoteColor().getNote());
@ -461,8 +461,8 @@ public class DataManager extends Manager {
"WHERE uuid = (SELECT particle_uuid FROM " + this.getTablePrefix() + "fixed WHERE owner_uuid = ? AND id = ?)"; "WHERE uuid = (SELECT particle_uuid FROM " + this.getTablePrefix() + "fixed WHERE owner_uuid = ? AND id = ?)";
try (PreparedStatement statement = connection.prepareStatement(particleUpdateQuery)) { try (PreparedStatement statement = connection.prepareStatement(particleUpdateQuery)) {
ParticlePair particle = fixedEffect.getParticlePair(); ParticlePair particle = fixedEffect.getParticlePair();
statement.setString(1, particle.getEffect().getName()); statement.setString(1, particle.getEffect().getInternalName());
statement.setString(2, particle.getStyle().getName()); statement.setString(2, particle.getStyle().getInternalName());
statement.setString(3, particle.getItemMaterial().name()); statement.setString(3, particle.getItemMaterial().name());
statement.setString(4, particle.getBlockMaterial().name()); statement.setString(4, particle.getBlockMaterial().name());
statement.setInt(5, particle.getNoteColor().getNote()); statement.setInt(5, particle.getNoteColor().getNote());

View file

@ -155,7 +155,7 @@ public class ParticleGroupPresetManager extends Manager {
this.presetGroups.add(new ParticleGroupPreset(displayName, guiIcon, permission, allowPermissionOverride, new ParticleGroup(groupName, particles))); this.presetGroups.add(new ParticleGroupPreset(displayName, guiIcon, permission, allowPermissionOverride, new ParticleGroup(groupName, particles)));
} catch (Exception ex) { } catch (Exception ex) {
PlayerParticles.getInstance().getLogger().severe("An error occurred while parsing the groups.yml file!"); PlayerParticles.getInstance().getLogger().severe("An error occurred while parsing the " + FILE_NAME + " file!");
} }
} }
} }

View file

@ -173,10 +173,15 @@ public class ParticleManager extends Manager implements Listener, Runnable {
/** /**
* An alternative method used for event styles * An alternative method used for event styles
* *
* @param player The player the particles are spawning from
* @param particle The ParticlePair to use for getting particle settings * @param particle The ParticlePair to use for getting particle settings
* @param particles The particles to display * @param particles The particles to display
*/ */
public void displayParticles(ParticlePair particle, List<PParticle> particles) { public void displayParticles(Player player, ParticlePair particle, List<PParticle> particles) {
PermissionManager permissionManager = this.playerParticles.getManager(PermissionManager.class);
if (player.getGameMode() == GameMode.SPECTATOR || !permissionManager.isWorldEnabled(player.getWorld().getName()))
return;
for (PParticle pparticle : particles) for (PParticle pparticle : particles)
ParticleEffect.display(particle, pparticle, false, Bukkit.getPlayer(particle.getOwnerUniqueId())); ParticleEffect.display(particle, pparticle, false, Bukkit.getPlayer(particle.getOwnerUniqueId()));
} }

View file

@ -44,17 +44,17 @@ public class ParticleStyleManager extends Manager {
return; return;
} }
if (style.getName() == null || style.getName().trim().equals("")) { if (style.getInternalName() == null || style.getInternalName().trim().equals("")) {
PlayerParticles.getInstance().getLogger().severe("Tried to register a style with a null or empty name: '" + style.getName() + "'"); PlayerParticles.getInstance().getLogger().severe("Tried to register a style with a null or empty name: '" + style.getInternalName() + "'");
return; return;
} }
for (ParticleStyle testAgainst : this.styles) { for (ParticleStyle testAgainst : this.styles) {
if (testAgainst.equals(style)) { if (testAgainst.equals(style)) {
PlayerParticles.getInstance().getLogger().severe("Tried to register the same style twice: '" + style.getName() + "'"); PlayerParticles.getInstance().getLogger().severe("Tried to register the same style twice: '" + style.getInternalName() + "'");
return; return;
} else if (testAgainst.getName().equalsIgnoreCase(style.getName())) { } else if (testAgainst.getInternalName().equalsIgnoreCase(style.getInternalName())) {
PlayerParticles.getInstance().getLogger().severe("Tried to register two styles with the same name spelling: '" + style.getName() + "'"); PlayerParticles.getInstance().getLogger().severe("Tried to register two styles with the same internal name spelling: '" + style.getInternalName() + "'");
return; return;
} }
} }

View file

@ -177,7 +177,7 @@ public class PermissionManager extends Manager {
* @return True if the player has permission to use the effect * @return True if the player has permission to use the effect
*/ */
public boolean hasEffectPermission(Player player, ParticleEffect effect) { public boolean hasEffectPermission(Player player, ParticleEffect effect) {
return PPermission.EFFECT.check(player, effect.getName()); return PPermission.EFFECT.check(player, effect.getInternalName());
} }
/** /**
@ -189,7 +189,7 @@ public class PermissionManager extends Manager {
* @return If the player has permission to use the style * @return If the player has permission to use the style
*/ */
public boolean hasStylePermission(Player player, ParticleStyle style) { public boolean hasStylePermission(Player player, ParticleStyle style) {
return PPermission.STYLE.check(player, style.getName()); return PPermission.STYLE.check(player, style.getInternalName());
} }
/** /**

View file

@ -95,6 +95,8 @@ public enum ParticleEffect {
private CommentedFileConfiguration config; private CommentedFileConfiguration config;
private boolean enabledByDefault; private boolean enabledByDefault;
private String effectName;
private boolean enabled; private boolean enabled;
/** /**
@ -135,9 +137,10 @@ public enum ParticleEffect {
File directory = new File(PlayerParticles.getInstance().getDataFolder(), "effects"); File directory = new File(PlayerParticles.getInstance().getDataFolder(), "effects");
directory.mkdirs(); directory.mkdirs();
File file = new File(directory, this.getName() + ".yml"); File file = new File(directory, this.getInternalName() + ".yml");
this.config = CommentedFileConfiguration.loadConfiguration(PlayerParticles.getInstance(), file); this.config = CommentedFileConfiguration.loadConfiguration(PlayerParticles.getInstance(), file);
this.setIfNotExists("effect-name", this.getInternalName(), "The name the effect will display as");
this.setIfNotExists("enabled", this.enabledByDefault, "If the effect is enabled or not"); this.setIfNotExists("enabled", this.enabledByDefault, "If the effect is enabled or not");
this.config.save(); this.config.save();
@ -153,6 +156,7 @@ public enum ParticleEffect {
if (reloadConfig) if (reloadConfig)
this.config.reloadConfig(); this.config.reloadConfig();
this.effectName = this.config.getString("effect-name");
this.enabled = this.config.getBoolean("enabled"); this.enabled = this.config.getBoolean("enabled");
} }
@ -185,12 +189,17 @@ public enum ParticleEffect {
} }
/** /**
* Returns the name of this particle effect * @return the internal name of this particle effect that will never change
* */
* @return The name public String getInternalName() {
return this.name().toLowerCase();
}
/**
* @return the name that the style will display to the users as
*/ */
public String getName() { public String getName() {
return this.name().toLowerCase(); return this.effectName;
} }
/** /**
@ -239,7 +248,17 @@ public enum ParticleEffect {
* @return The particle effect * @return The particle effect
*/ */
public static ParticleEffect fromName(String name) { public static ParticleEffect fromName(String name) {
return Stream.of(values()).filter(x -> x.name().equalsIgnoreCase(name) && x.isSupported() && x.isEnabled()).findFirst().orElse(null); return Stream.of(values()).filter(x -> x.isSupported() && x.isEnabled() && x.getName().equalsIgnoreCase(name)).findFirst().orElse(null);
}
/**
* Returns the particle effect with the given name
*
* @param internalName Internal name of the particle effect
* @return The particle effect
*/
public static ParticleEffect fromInternalName(String internalName) {
return Stream.of(values()).filter(x -> x.isSupported() && x.isEnabled() && x.getInternalName().equalsIgnoreCase(internalName)).findFirst().orElse(null);
} }
/** /**

View file

@ -10,18 +10,19 @@ public abstract class DefaultParticleStyle implements ParticleStyle {
protected PlayerParticles playerParticles; protected PlayerParticles playerParticles;
private CommentedFileConfiguration config; private CommentedFileConfiguration config;
private String styleName; private String internalStyleName;
private boolean canBeFixedByDefault; private boolean canBeFixedByDefault;
private boolean canToggleWithMovementByDefault; private boolean canToggleWithMovementByDefault;
private double fixedEffectOffsetByDefault; private double fixedEffectOffsetByDefault;
private String styleName;
private boolean enabled; private boolean enabled;
private boolean canBeFixed; private boolean canBeFixed;
private boolean canToggleWithMovement; private boolean canToggleWithMovement;
private double fixedEffectOffset; private double fixedEffectOffset;
public DefaultParticleStyle(String styleName, boolean canBeFixedByDefault, boolean canToggleWithMovementByDefault, double fixedEffectOffsetByDefault) { public DefaultParticleStyle(String internalStyleName, boolean canBeFixedByDefault, boolean canToggleWithMovementByDefault, double fixedEffectOffsetByDefault) {
this.styleName = styleName; this.internalStyleName = internalStyleName;
this.canBeFixedByDefault = canBeFixedByDefault; this.canBeFixedByDefault = canBeFixedByDefault;
this.canToggleWithMovementByDefault = canToggleWithMovementByDefault; this.canToggleWithMovementByDefault = canToggleWithMovementByDefault;
this.fixedEffectOffsetByDefault = fixedEffectOffsetByDefault; this.fixedEffectOffsetByDefault = fixedEffectOffsetByDefault;
@ -38,9 +39,10 @@ public abstract class DefaultParticleStyle implements ParticleStyle {
File directory = new File(this.playerParticles.getDataFolder(), "styles"); File directory = new File(this.playerParticles.getDataFolder(), "styles");
directory.mkdirs(); directory.mkdirs();
File file = new File(directory, this.getName() + ".yml"); File file = new File(directory, this.internalStyleName + ".yml");
this.config = CommentedFileConfiguration.loadConfiguration(PlayerParticles.getInstance(), file); this.config = CommentedFileConfiguration.loadConfiguration(PlayerParticles.getInstance(), file);
this.setIfNotExists("style-name", this.internalStyleName, "The name the style will display as");
this.setIfNotExists("enabled", true, "If the style is enabled or not"); this.setIfNotExists("enabled", true, "If the style is enabled or not");
this.setIfNotExists("can-be-fixed", this.canBeFixedByDefault, "If the style can be used in /pp fixed"); this.setIfNotExists("can-be-fixed", this.canBeFixedByDefault, "If the style can be used in /pp fixed");
this.setIfNotExists("can-toggle-with-movement", this.canToggleWithMovementByDefault, "If the style will only be shown at the player's feet while moving"); this.setIfNotExists("can-toggle-with-movement", this.canToggleWithMovementByDefault, "If the style will only be shown at the player's feet while moving");
@ -57,6 +59,7 @@ public abstract class DefaultParticleStyle implements ParticleStyle {
if (reloadConfig) if (reloadConfig)
this.config.reloadConfig(); this.config.reloadConfig();
this.styleName = this.config.getString("style-name");
this.enabled = this.config.getBoolean("enabled"); this.enabled = this.config.getBoolean("enabled");
this.canBeFixed = this.config.getBoolean("can-be-fixed"); this.canBeFixed = this.config.getBoolean("can-be-fixed");
this.canToggleWithMovement = this.config.getBoolean("can-toggle-with-movement"); this.canToggleWithMovement = this.config.getBoolean("can-toggle-with-movement");
@ -95,6 +98,11 @@ public abstract class DefaultParticleStyle implements ParticleStyle {
return this.styleName; return this.styleName;
} }
@Override
public final String getInternalName() {
return this.internalStyleName;
}
@Override @Override
public final boolean canBeFixed() { public final boolean canBeFixed() {
return this.canBeFixed; return this.canBeFixed;

View file

@ -29,9 +29,12 @@ public interface ParticleStyle {
boolean isEnabled(); boolean isEnabled();
/** /**
* The name of the style * @return The style's internal name that will always remain constant
* */
* @return The style's name String getInternalName();
/**
* @return The name that the style will display to the users as
*/ */
String getName(); String getName();
@ -69,4 +72,17 @@ public interface ParticleStyle {
return null; return null;
} }
/**
* Gets the ParticleStyle with the internal name given, returns null if not found
*
* @param styleName The internal name of the style to search for
* @return The ParticleStyle with a matching name
*/
static ParticleStyle fromInternalName(String styleName) {
for (ParticleStyle style : PlayerParticles.getInstance().getManager(ParticleStyleManager.class).getStyles())
if (style.getInternalName().equalsIgnoreCase(styleName))
return style;
return null;
}
} }

View file

@ -21,7 +21,8 @@ public class ParticleStyleBatman extends DefaultParticleStyle {
public List<PParticle> getParticles(ParticlePair particle, Location location) { public List<PParticle> getParticles(ParticlePair particle, Location location) {
List<PParticle> particles = new ArrayList<>(); List<PParticle> particles = new ArrayList<>();
if (step != 0) return particles; if (this.step != 0)
return particles;
// Segment 1 // Segment 1
for (double x = -7; x <= -3; x += 0.05) { for (double x = -7; x <= -3; x += 0.05) {
@ -114,7 +115,7 @@ public class ParticleStyleBatman extends DefaultParticleStyle {
@Override @Override
public void updateTimers() { public void updateTimers() {
step = (step + 1) % 20; // Only spawn once per second this.step = (this.step + 1) % 20; // Only spawn once per second
} }
@Override @Override

View file

@ -9,35 +9,25 @@ import org.bukkit.Location;
public class ParticleStyleBeam extends DefaultParticleStyle { public class ParticleStyleBeam extends DefaultParticleStyle {
private static double[] cos, sin;
private static final int points = 16;
private int step = 0; private int step = 0;
private boolean reversed = false; private boolean reversed = false;
static {
cos = new double[points];
sin = new double[points];
int i = 0;
for (double n = 0; n < Math.PI * 2; n += Math.PI * 2 / points) {
cos[i] = Math.cos(n);
sin[i] = Math.sin(n);
i++;
}
}
public ParticleStyleBeam() { public ParticleStyleBeam() {
super("beam", true, true, 0.5); super("beam", true, true, 0.5);
} }
@Override @Override
public List<PParticle> getParticles(ParticlePair particle, Location location) { public List<PParticle> getParticles(ParticlePair particle, Location location) {
int points = 16;
double radius = 1; double radius = 1;
double slice = 2 * Math.PI / points;
List<PParticle> particles = new ArrayList<>(); List<PParticle> particles = new ArrayList<>();
for (int i = 0; i < points; i++) { for (int i = 0; i < points; i++) {
double newX = location.getX() + radius * cos[i]; double angle = slice * i;
double newY = location.getY() + (step / 10D) - 1; double newX = location.getX() + radius * Math.cos(angle);
double newZ = location.getZ() + radius * sin[i]; double newY = location.getY() + (this.step / 10D) - 1;
double newZ = location.getZ() + radius * Math.sin(angle);
particles.add(new PParticle(new Location(location.getWorld(), newX, newY, newZ))); particles.add(new PParticle(new Location(location.getWorld(), newX, newY, newZ)));
} }
return particles; return particles;
@ -45,13 +35,12 @@ public class ParticleStyleBeam extends DefaultParticleStyle {
@Override @Override
public void updateTimers() { public void updateTimers() {
if (!reversed) step++; this.step += this.reversed ? -1 : 1;
else step--;
if (step >= 30) { if (this.step >= 30) {
reversed = true; this.reversed = true;
} else if (step <= 0) { } else if (this.step <= 0) {
reversed = false; this.reversed = false;
} }
} }

View file

@ -58,7 +58,7 @@ public class ParticleStyleBlockBreak extends DefaultParticleStyle implements Lis
if (pplayer != null) { if (pplayer != null) {
for (ParticlePair particle : pplayer.getActiveParticlesForStyle(DefaultStyles.BLOCKBREAK)) { for (ParticlePair particle : pplayer.getActiveParticlesForStyle(DefaultStyles.BLOCKBREAK)) {
Location loc = event.getBlock().getLocation().clone(); Location loc = event.getBlock().getLocation().clone();
particleManager.displayParticles(particle, DefaultStyles.BLOCKBREAK.getParticles(particle, loc)); particleManager.displayParticles(player, particle, DefaultStyles.BLOCKBREAK.getParticles(particle, loc));
} }
} }
} }

View file

@ -58,7 +58,7 @@ public class ParticleStyleBlockPlace extends DefaultParticleStyle implements Lis
if (pplayer != null) { if (pplayer != null) {
for (ParticlePair particle : pplayer.getActiveParticlesForStyle(DefaultStyles.BLOCKPLACE)) { for (ParticlePair particle : pplayer.getActiveParticlesForStyle(DefaultStyles.BLOCKPLACE)) {
Location loc = event.getBlock().getLocation().clone(); Location loc = event.getBlock().getLocation().clone();
particleManager.displayParticles(particle, DefaultStyles.BLOCKPLACE.getParticles(particle, loc)); particleManager.displayParticles(player, particle, DefaultStyles.BLOCKPLACE.getParticles(particle, loc));
} }
} }
} }

View file

@ -77,6 +77,7 @@ public class ParticleStyleCelebration extends DefaultParticleStyle {
double dz = Math.cos(angle) * distanceFrom; double dz = Math.cos(angle) * distanceFrom;
final Location loc = location.clone().add(dx, 1, dz); final Location loc = location.clone().add(dx, 1, dz);
final int fuse = 3 + random.nextInt(3); final int fuse = 3 + random.nextInt(3);
Player player = pplayer.getPlayer();
ParticleManager particleManager = PlayerParticles.getInstance().getManager(ParticleManager.class); ParticleManager particleManager = PlayerParticles.getInstance().getManager(ParticleManager.class);
new BukkitRunnable() { new BukkitRunnable() {
@ -90,7 +91,7 @@ public class ParticleStyleCelebration extends DefaultParticleStyle {
trail.setEffect(ParticleEffect.FIREWORK); trail.setEffect(ParticleEffect.FIREWORK);
trail.setStyle(DefaultStyles.CELEBRATION); trail.setStyle(DefaultStyles.CELEBRATION);
particleManager.displayParticles(trail, Collections.singletonList(new PParticle(this.location))); particleManager.displayParticles(player, trail, Collections.singletonList(new PParticle(this.location)));
this.location.add(0, 0.25, 0); this.location.add(0, 0.25, 0);
} else { } else {
@ -107,7 +108,7 @@ public class ParticleStyleCelebration extends DefaultParticleStyle {
particles.add(new PParticle(this.location.clone().add(dx, dy, dz))); particles.add(new PParticle(this.location.clone().add(dx, dy, dz)));
} }
particleManager.displayParticles(particle, particles); particleManager.displayParticles(player, particle, particles);
this.cancel(); this.cancel();
} }

View file

@ -50,15 +50,15 @@ public class ParticleStyleCompanion extends DefaultParticleStyle {
Vector vector = new Vector(); Vector vector = new Vector();
double t = (Math.PI / numParticles) * step; double t = (Math.PI / this.numParticles) * this.step;
double r = Math.sin(t) * size; double r = Math.sin(t) * this.size;
double s = 2 * Math.PI * t; double s = 2 * Math.PI * t;
vector.setX(xFactor * r * Math.cos(s) + xOffset); vector.setX(this.xFactor * r * Math.cos(s) + this.xOffset);
vector.setZ(zFactor * r * Math.sin(s) + zOffset); vector.setZ(this.zFactor * r * Math.sin(s) + this.zOffset);
vector.setY(yFactor * size * Math.cos(t) + yOffset); vector.setY(this.yFactor * this.size * Math.cos(t) + this.yOffset);
for (int i = 0; i < particlesPerIteration; i++) { for (int i = 0; i < this.particlesPerIteration; i++) {
particles.add(new PParticle(location.clone().subtract(vector))); particles.add(new PParticle(location.clone().subtract(vector)));
} }
@ -67,7 +67,7 @@ public class ParticleStyleCompanion extends DefaultParticleStyle {
@Override @Override
public void updateTimers() { public void updateTimers() {
step++; this.step++;
} }
@Override @Override

View file

@ -55,21 +55,20 @@ public class ParticleStyleCube extends DefaultParticleStyle {
public List<PParticle> getParticles(ParticlePair particle, Location location) { public List<PParticle> getParticles(ParticlePair particle, Location location) {
List<PParticle> pparticles = new ArrayList<>(); List<PParticle> pparticles = new ArrayList<>();
if (!skipNextStep) { if (!this.skipNextStep) {
double xRotation = 0, yRotation = 0, zRotation = 0; double xRotation = this.step * this.angularVelocityX;
xRotation = step * angularVelocityX; double yRotation = this.step * this.angularVelocityY;
yRotation = step * angularVelocityY; double zRotation = this.step * this.angularVelocityZ;
zRotation = step * angularVelocityZ; double a = this.edgeLength / 2;
double a = edgeLength / 2;
double angleX, angleY; double angleX, angleY;
Vector v = new Vector(); Vector v = new Vector();
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
angleY = i * Math.PI / 2; angleY = i * Math.PI / 2;
for (int j = 0; j < 2; j++) { for (int j = 0; j < 2; j++) {
angleX = j * Math.PI; angleX = j * Math.PI;
for (int p = 0; p <= particles; p++) { for (int p = 0; p <= this.particles; p++) {
v.setX(a).setY(a); v.setX(a).setY(a);
v.setZ(edgeLength * p / particles - a); v.setZ(this.edgeLength * p / this.particles - a);
VectorUtils.rotateAroundAxisX(v, angleX); VectorUtils.rotateAroundAxisX(v, angleX);
VectorUtils.rotateAroundAxisY(v, angleY); VectorUtils.rotateAroundAxisY(v, angleY);
VectorUtils.rotateVector(v, xRotation, yRotation, zRotation); VectorUtils.rotateVector(v, xRotation, yRotation, zRotation);
@ -91,8 +90,8 @@ public class ParticleStyleCube extends DefaultParticleStyle {
@Override @Override
public void updateTimers() { public void updateTimers() {
skipNextStep = !skipNextStep; this.skipNextStep = !this.skipNextStep;
step++; this.step++;
} }
@Override @Override

View file

@ -9,37 +9,27 @@ import org.bukkit.Location;
public class ParticleStyleHalo extends DefaultParticleStyle { public class ParticleStyleHalo extends DefaultParticleStyle {
private static double[] cos, sin;
private static final int points = 16;
private int step = 0; private int step = 0;
static {
cos = new double[points];
sin = new double[points];
int i = 0;
for (double n = 0; n < Math.PI * 2; n += Math.PI * 2 / points) {
cos[i] = Math.cos(n);
sin[i] = Math.sin(n);
i++;
}
}
public ParticleStyleHalo() { public ParticleStyleHalo() {
super("halo", true, false, -0.5); super("halo", true, false, -0.5);
} }
@Override @Override
public List<PParticle> getParticles(ParticlePair particle, Location location) { public List<PParticle> getParticles(ParticlePair particle, Location location) {
if (step % 2 == 0) return new ArrayList<>(); List<PParticle> particles = new ArrayList<>();
if (this.step % 2 == 0)
return particles;
int points = 16; int points = 16;
double radius = .65; double radius = .65;
List<PParticle> particles = new ArrayList<>(); double slice = 2 * Math.PI / points;
for (int i = 0; i < points; i++) { for (int i = 0; i < points; i++) {
double dx = radius * cos[i]; double angle = slice * i;
double dx = radius * Math.cos(angle);
double dy = 1.5; double dy = 1.5;
double dz = radius * sin[i]; double dz = radius * Math.sin(angle);
particles.add(new PParticle(location.clone().add(dx, dy, dz))); particles.add(new PParticle(location.clone().add(dx, dy, dz)));
} }
return particles; return particles;
@ -47,10 +37,9 @@ public class ParticleStyleHalo extends DefaultParticleStyle {
@Override @Override
public void updateTimers() { public void updateTimers() {
step++; this.step++;
if (step > 30) { if (this.step > 30)
step = 0; this.step = 0;
}
} }
@Override @Override

View file

@ -50,7 +50,7 @@ public class ParticleStyleHurt extends DefaultParticleStyle implements Listener
if (pplayer != null) { if (pplayer != null) {
for (ParticlePair particle : pplayer.getActiveParticlesForStyle(DefaultStyles.HURT)) { for (ParticlePair particle : pplayer.getActiveParticlesForStyle(DefaultStyles.HURT)) {
Location loc = player.getLocation().clone().add(0, 1, 0); Location loc = player.getLocation().clone().add(0, 1, 0);
particleManager.displayParticles(particle, DefaultStyles.HURT.getParticles(particle, loc)); particleManager.displayParticles(player, particle, DefaultStyles.HURT.getParticles(particle, loc));
} }
} }
} }

View file

@ -22,23 +22,23 @@ public class ParticleStyleInvocation extends DefaultParticleStyle {
public List<PParticle> getParticles(ParticlePair particle, Location location) { public List<PParticle> getParticles(ParticlePair particle, Location location) {
List<PParticle> particles = new ArrayList<>(); List<PParticle> particles = new ArrayList<>();
double speed = getSpeedByEffect(particle.getEffect()); double speed = this.getSpeedByEffect(particle.getEffect());
// Circle around everything, spawn less often // Circle around everything, spawn less often
if (circleStep % 5 == 0) { if (this.circleStep % 5 == 0) {
for (int i = 0; i < numSteps; i++) { for (int i = 0; i < this.numSteps; i++) {
double dx = Math.cos(Math.PI * 2 * ((double)i / numSteps)) * radius; double dx = Math.cos(Math.PI * 2 * ((double) i / this.numSteps)) * this.radius;
double dy = -0.9; double dy = -0.9;
double dz = Math.sin(Math.PI * 2 * ((double)i / numSteps)) * radius; double dz = Math.sin(Math.PI * 2 * ((double) i / this.numSteps)) * this.radius;
particles.add(new PParticle(location.clone().add(dx, dy, dz))); particles.add(new PParticle(location.clone().add(dx, dy, dz)));
} }
} }
// Orbit going clockwise // Orbit going clockwise
for (int i = 0; i < points; i++) { for (int i = 0; i < this.points; i++) {
double dx = Math.cos(step + (Math.PI * 2 * ((double)i / points))) * radius; double dx = Math.cos(this.step + (Math.PI * 2 * ((double) i / this.points))) * this.radius;
double dy = -0.9; double dy = -0.9;
double dz = Math.sin(step + (Math.PI * 2 * ((double)i / points))) * radius; double dz = Math.sin(this.step + (Math.PI * 2 * ((double) i / this.points))) * this.radius;
double angle = Math.atan2(dz, dx); double angle = Math.atan2(dz, dx);
double xAng = -Math.cos(angle); double xAng = -Math.cos(angle);
double zAng = -Math.sin(angle); double zAng = -Math.sin(angle);
@ -46,10 +46,10 @@ public class ParticleStyleInvocation extends DefaultParticleStyle {
} }
// Orbit going counter-clockwise // Orbit going counter-clockwise
for (int i = 0; i > -points; i--) { for (int i = 0; i > -this.points; i--) {
double dx = Math.cos(-step + (Math.PI * 2 * ((double)i / points))) * radius; double dx = Math.cos(-this.step + (Math.PI * 2 * ((double) i / this.points))) * this.radius;
double dy = -0.9; double dy = -0.9;
double dz = Math.sin(-step + (Math.PI * 2 * ((double)i / points))) * radius; double dz = Math.sin(-this.step + (Math.PI * 2 * ((double) i / this.points))) * this.radius;
double angle = Math.atan2(dz, dx); double angle = Math.atan2(dz, dx);
double xAng = -Math.cos(angle); double xAng = -Math.cos(angle);
double zAng = -Math.sin(angle); double zAng = -Math.sin(angle);
@ -89,8 +89,8 @@ public class ParticleStyleInvocation extends DefaultParticleStyle {
} }
public void updateTimers() { public void updateTimers() {
step = (step + Math.PI * 2 / numSteps) % numSteps; this.step = (this.step + Math.PI * 2 / this.numSteps) % this.numSteps;
circleStep = (circleStep + 1) % numSteps; this.circleStep = (this.circleStep + 1) % this.numSteps;
} }
@Override @Override

View file

@ -41,15 +41,15 @@ public class ParticleStyleMove extends DefaultParticleStyle implements Listener
} }
@EventHandler(priority = EventPriority.MONITOR) @EventHandler(priority = EventPriority.MONITOR)
public void onPlayerMove(PlayerMoveEvent e) { public void onPlayerMove(PlayerMoveEvent event) {
ParticleManager particleManager = PlayerParticles.getInstance().getManager(ParticleManager.class); ParticleManager particleManager = PlayerParticles.getInstance().getManager(ParticleManager.class);
PPlayer pplayer = PlayerParticles.getInstance().getManager(DataManager.class).getPPlayer(e.getPlayer().getUniqueId()); PPlayer pplayer = PlayerParticles.getInstance().getManager(DataManager.class).getPPlayer(event.getPlayer().getUniqueId());
if (pplayer != null) { if (pplayer != null) {
for (ParticlePair particle : pplayer.getActiveParticlesForStyle(DefaultStyles.MOVE)) { for (ParticlePair particle : pplayer.getActiveParticlesForStyle(DefaultStyles.MOVE)) {
Location loc = e.getPlayer().getLocation().clone(); Location loc = event.getPlayer().getLocation().clone();
loc.setY(loc.getY() + 0.05); loc.setY(loc.getY() + 0.05);
particleManager.displayParticles(particle, DefaultStyles.MOVE.getParticles(particle, loc)); particleManager.displayParticles(event.getPlayer(), particle, DefaultStyles.MOVE.getParticles(particle, loc));
} }
} }
} }

View file

@ -9,23 +9,10 @@ import org.bukkit.Location;
public class ParticleStyleOrbit extends DefaultParticleStyle { public class ParticleStyleOrbit extends DefaultParticleStyle {
private static double[] cos, sin;
private static final int orbs = 3; private static final int orbs = 3;
private static final int numSteps = 120; private static final int numSteps = 120;
private int step = 0; private int step = 0;
static {
cos = new double[120];
sin = new double[120];
int i = 0;
for (double n = 0; n < numSteps; n++) {
cos[i] = -Math.cos(n / numSteps * Math.PI * 2);
sin[i] = -Math.sin(n / numSteps * Math.PI * 2);
i++;
}
}
public ParticleStyleOrbit() { public ParticleStyleOrbit() {
super("orbit", true, true, 0); super("orbit", true, true, 0);
} }
@ -34,8 +21,8 @@ public class ParticleStyleOrbit extends DefaultParticleStyle {
public List<PParticle> getParticles(ParticlePair particle, Location location) { public List<PParticle> getParticles(ParticlePair particle, Location location) {
List<PParticle> particles = new ArrayList<>(); List<PParticle> particles = new ArrayList<>();
for (int i = 0; i < orbs; i++) { for (int i = 0; i < orbs; i++) {
double dx = cos[(step + (numSteps / orbs * i)) % numSteps]; double dx = -(Math.cos((this.step / (double) numSteps) * (Math.PI * 2) + (((Math.PI * 2) / orbs) * i)));
double dz = sin[(step + (numSteps / orbs * i)) % numSteps]; double dz = -(Math.sin((this.step / (double) numSteps) * (Math.PI * 2) + (((Math.PI * 2) / orbs) * i)));
particles.add(new PParticle(location.clone().add(dx, 0, dz))); particles.add(new PParticle(location.clone().add(dx, 0, dz)));
} }
return particles; return particles;
@ -43,10 +30,7 @@ public class ParticleStyleOrbit extends DefaultParticleStyle {
@Override @Override
public void updateTimers() { public void updateTimers() {
step++; this.step = (this.step + 1) % numSteps;
if (step > numSteps) {
step = 0;
}
} }
@Override @Override

View file

@ -24,15 +24,15 @@ public class ParticleStylePopper extends DefaultParticleStyle {
public List<PParticle> getParticles(ParticlePair particle, Location location) { public List<PParticle> getParticles(ParticlePair particle, Location location) {
List<PParticle> particles = new ArrayList<>(); List<PParticle> particles = new ArrayList<>();
double radius = (1 - (double)step / maxStep); double radius = (1 - (double) this.step / this.maxStep);
for (int i = 0; i < helices; i++) { for (int i = 0; i < this.helices; i++) {
double angle = step * radials + (2 * Math.PI * i / helices); double angle = this.step * this.radials + (2 * Math.PI * i / this.helices);
Vector v = new Vector(Math.cos(angle) * radius, step * grow - 1, Math.sin(angle) * radius); Vector v = new Vector(Math.cos(angle) * radius, this.step * this.grow - 1, Math.sin(angle) * radius);
particles.add(new PParticle(location.clone().add(v))); particles.add(new PParticle(location.clone().add(v)));
} }
if (step == maxStep - 1) { if (this.step == this.maxStep - 1) {
for (int i = 0; i < 10; i++) { for (int i = 0; i < 10; i++) {
particles.add(new PParticle(location.clone().add(0, 1.5, 0), 0.5, 0.5, 0.5, 0.03)); particles.add(new PParticle(location.clone().add(0, 1.5, 0), 0.5, 0.5, 0.5, 0.03));
} }
@ -43,7 +43,7 @@ public class ParticleStylePopper extends DefaultParticleStyle {
@Override @Override
public void updateTimers() { public void updateTimers() {
step = (step + 1) % maxStep; this.step = (this.step + 1) % this.maxStep;
} }
@Override @Override

View file

@ -22,13 +22,13 @@ public class ParticleStylePulse extends DefaultParticleStyle {
@Override @Override
public List<PParticle> getParticles(ParticlePair particle, Location location) { public List<PParticle> getParticles(ParticlePair particle, Location location) {
List<PParticle> particles = new ArrayList<>(); List<PParticle> particles = new ArrayList<>();
double speed = getSpeedByEffect(particle.getEffect()); double speed = this.getSpeedByEffect(particle.getEffect());
if (step == 0) { if (this.step == 0) {
for (int i = 0; i < points; i++) { for (int i = 0; i < this.points; i++) {
double dx = Math.cos(Math.PI * 2 * ((double) i / points)) * radius; double dx = Math.cos(Math.PI * 2 * ((double) i / this.points)) * this.radius;
double dy = -0.9; double dy = -0.9;
double dz = Math.sin(Math.PI * 2 * ((double) i / points)) * radius; double dz = Math.sin(Math.PI * 2 * ((double) i / this.points)) * this.radius;
double angle = Math.atan2(dz, dx); double angle = Math.atan2(dz, dx);
double xAng = Math.cos(angle); double xAng = Math.cos(angle);
double zAng = Math.sin(angle); double zAng = Math.sin(angle);
@ -50,7 +50,7 @@ public class ParticleStylePulse extends DefaultParticleStyle {
case ENCHANT: case ENCHANT:
case NAUTILUS: case NAUTILUS:
case PORTAL: case PORTAL:
return radius; return 0.5;
case END_ROD: case END_ROD:
case SMOKE: case SMOKE:
case SQUID_INK: case SQUID_INK:
@ -70,7 +70,7 @@ public class ParticleStylePulse extends DefaultParticleStyle {
@Override @Override
public void updateTimers() { public void updateTimers() {
step = (step + 1) % numSteps; this.step = (this.step + 1) % this.numSteps;
} }
@Override @Override

View file

@ -9,7 +9,6 @@ import org.bukkit.Location;
public class ParticleStyleQuadhelix extends DefaultParticleStyle { public class ParticleStyleQuadhelix extends DefaultParticleStyle {
private static double[] cos, sin;
private static final int orbs = 4; private static final int orbs = 4;
private static int maxStepX = 80; private static int maxStepX = 80;
private static int maxStepY = 60; private static int maxStepY = 60;
@ -17,18 +16,6 @@ public class ParticleStyleQuadhelix extends DefaultParticleStyle {
private int stepY = 0; private int stepY = 0;
private boolean reverse = false; private boolean reverse = false;
static {
cos = new double[maxStepX];
sin = new double[maxStepX];
int i = 0;
for (double n = 0; n < maxStepX; n++) {
cos[i] = -Math.cos(n / maxStepX * Math.PI * 2);
sin[i] = -Math.sin(n / maxStepX * Math.PI * 2);
i++;
}
}
public ParticleStyleQuadhelix() { public ParticleStyleQuadhelix() {
super("quadhelix", true, true, 0); super("quadhelix", true, true, 0);
} }
@ -37,10 +24,9 @@ public class ParticleStyleQuadhelix extends DefaultParticleStyle {
public List<PParticle> getParticles(ParticlePair particle, Location location) { public List<PParticle> getParticles(ParticlePair particle, Location location) {
List<PParticle> particles = new ArrayList<>(); List<PParticle> particles = new ArrayList<>();
for (int i = 0; i < orbs; i++) { for (int i = 0; i < orbs; i++) {
int step = (stepX + (maxStepX / orbs) * i) % maxStepX; double dx = -(Math.cos((this.stepX / (double) maxStepX) * (Math.PI * 2) + (((Math.PI * 2) / orbs) * i))) * ((maxStepY - Math.abs(this.stepY)) / (double) maxStepY);
double dx = cos[step] * ((60 - Math.abs(stepY)) / (double)maxStepY); double dy = (this.stepY / (double) maxStepY) * 1.5;
double dy = (stepY / (double)maxStepY) * 1.5; double dz = -(Math.sin((this.stepX / (double) maxStepX) * (Math.PI * 2) + (((Math.PI * 2) / orbs) * i))) * ((maxStepY - Math.abs(this.stepY)) / (double) maxStepY);
double dz = sin[step] * ((60 - Math.abs(stepY)) / (double)maxStepY);
particles.add(new PParticle(location.clone().add(dx, dy, dz))); particles.add(new PParticle(location.clone().add(dx, dy, dz)));
} }
return particles; return particles;
@ -48,16 +34,18 @@ public class ParticleStyleQuadhelix extends DefaultParticleStyle {
@Override @Override
public void updateTimers() { public void updateTimers() {
stepX++; this.stepX++;
if (stepX > maxStepX) { if (this.stepX > maxStepX) {
stepX = 0; this.stepX = 0;
} }
if (reverse) { if (this.reverse) {
stepY++; this.stepY++;
if (stepY > maxStepY) reverse = false; if (this.stepY > maxStepY)
this.reverse = false;
} else { } else {
stepY--; this.stepY--;
if (stepY < -maxStepY) reverse = true; if (this.stepY < -maxStepY)
this.reverse = true;
} }
} }

View file

@ -9,20 +9,8 @@ import org.bukkit.Location;
public class ParticleStyleRings extends DefaultParticleStyle { public class ParticleStyleRings extends DefaultParticleStyle {
private static double[] cos, sin; private int step = 0;
private int index = 0; private final static int maxStep = 32;
static {
cos = new double[32];
sin = new double[32];
int i = 0;
for (double n = 0; n < Math.PI * 2; n += Math.PI / 16) {
cos[i] = Math.sin(n);
sin[i] = Math.cos(n);
i++;
}
}
public ParticleStyleRings() { public ParticleStyleRings() {
super("rings", true, true, 0); super("rings", true, true, 0);
@ -32,27 +20,20 @@ public class ParticleStyleRings extends DefaultParticleStyle {
public List<PParticle> getParticles(ParticlePair particle, Location location) { public List<PParticle> getParticles(ParticlePair particle, Location location) {
List<PParticle> particles = new ArrayList<>(); List<PParticle> particles = new ArrayList<>();
particles.add(new PParticle(location.clone().add(cos[index], sin[index], sin[index]))); double ring1 = Math.PI / (maxStep / 2D) * this.step;
particles.add(new PParticle(location.clone().add(cos[wrap(index + 16)], sin[wrap(index + 16)], sin[wrap(index + 16)]))); double ring2 = Math.PI / (maxStep / 2D) * (((this.step + maxStep / 2D) % maxStep));
particles.add(new PParticle(location.clone().add(cos[wrap(index + 16)], sin[index], sin[wrap(index + 16)])));
particles.add(new PParticle(location.clone().add(cos[index], sin[wrap(index + 16)], sin[index]))); particles.add(new PParticle(location.clone().add(Math.cos(ring1), Math.sin(ring1), Math.sin(ring1))));
particles.add(new PParticle(location.clone().add(Math.cos(ring1 + Math.PI), Math.sin(ring1), Math.sin(ring1 + Math.PI))));
particles.add(new PParticle(location.clone().add(Math.cos(ring2), Math.sin(ring2), Math.sin(ring2))));
particles.add(new PParticle(location.clone().add(Math.cos(ring2 + Math.PI), Math.sin(ring2), Math.sin(ring2 + Math.PI))));
return particles; return particles;
} }
/**
* Wraps an index around the cos/sin array length
*
* @param index The index to wrap
* @return The wrapped index
*/
private int wrap(int index) {
return index % cos.length;
}
@Override @Override
public void updateTimers() { public void updateTimers() {
index = (index + 1) % cos.length; this.step = (this.step + 1) % maxStep;
} }
@Override @Override

View file

@ -32,15 +32,15 @@ public class ParticleStyleSpin extends DefaultParticleStyle {
@Override @Override
public List<PParticle> getParticles(ParticlePair particle, Location location) { public List<PParticle> getParticles(ParticlePair particle, Location location) {
double radius = .5; double radius = .5;
double newX = location.getX() + radius * cos[step]; double newX = location.getX() + radius * cos[this.step];
double newY = location.getY() + 1.5; double newY = location.getY() + 1.5;
double newZ = location.getZ() + radius * sin[step]; double newZ = location.getZ() + radius * sin[this.step];
return Collections.singletonList(new PParticle(new Location(location.getWorld(), newX, newY, newZ))); return Collections.singletonList(new PParticle(new Location(location.getWorld(), newX, newY, newZ)));
} }
@Override @Override
public void updateTimers() { public void updateTimers() {
step = (step + 1) % maxSteps; this.step = (this.step + 1) % maxSteps;
} }
@Override @Override

View file

@ -19,9 +19,9 @@ public class ParticleStyleSpiral extends DefaultParticleStyle {
public List<PParticle> getParticles(ParticlePair particle, Location location) { public List<PParticle> getParticles(ParticlePair particle, Location location) {
List<PParticle> particles = new ArrayList<>(); List<PParticle> particles = new ArrayList<>();
for (int stepY = -60; stepY < 60; stepY += 10) { for (int stepY = -60; stepY < 60; stepY += 10) {
double dx = -(Math.cos(((stepX + stepY) / 90D) * Math.PI * 2)) * 0.8; double dx = -(Math.cos(((this.stepX + stepY) / 90D) * Math.PI * 2)) * 0.8;
double dy = stepY / 45D; double dy = stepY / 45D;
double dz = -(Math.sin(((stepX + stepY) / 90D) * Math.PI * 2)) * 0.8; double dz = -(Math.sin(((this.stepX + stepY) / 90D) * Math.PI * 2)) * 0.8;
particles.add(new PParticle(location.clone().add(dx, dy, dz))); particles.add(new PParticle(location.clone().add(dx, dy, dz)));
} }
return particles; return particles;
@ -29,7 +29,7 @@ public class ParticleStyleSpiral extends DefaultParticleStyle {
@Override @Override
public void updateTimers() { public void updateTimers() {
stepX++; this.stepX++;
} }
@Override @Override

View file

@ -67,10 +67,10 @@ public class ParticleStyleSwords extends DefaultParticleStyle implements Listene
Player player = (Player) event.getDamager(); Player player = (Player) event.getDamager();
LivingEntity entity = (LivingEntity) event.getEntity(); LivingEntity entity = (LivingEntity) event.getEntity();
PPlayer pplayer = PlayerParticles.getInstance().getManager(DataManager.class).getPPlayer(player.getUniqueId()); PPlayer pplayer = PlayerParticles.getInstance().getManager(DataManager.class).getPPlayer(player.getUniqueId());
if (pplayer != null) { if (pplayer != null && SWORD_NAMES.contains(player.getInventory().getItemInMainHand().getType().name())) {
for (ParticlePair particle : pplayer.getActiveParticlesForStyle(DefaultStyles.SWORDS)) { for (ParticlePair particle : pplayer.getActiveParticlesForStyle(DefaultStyles.SWORDS)) {
Location loc = entity.getLocation().clone().add(0, 1, 0); Location loc = entity.getLocation().clone().add(0, 1, 0);
particleManager.displayParticles(particle, DefaultStyles.SWORDS.getParticles(particle, loc)); particleManager.displayParticles(player, particle, DefaultStyles.SWORDS.getParticles(particle, loc));
} }
} }
} }

View file

@ -37,9 +37,9 @@ public class ParticleStyleTwins extends DefaultParticleStyle {
public List<PParticle> getParticles(ParticlePair particle, Location location) { public List<PParticle> getParticles(ParticlePair particle, Location location) {
List<PParticle> particles = new ArrayList<>(); List<PParticle> particles = new ArrayList<>();
for (int i = 0; i < orbs; i++) { for (int i = 0; i < orbs; i++) {
double dx = cos[(stepX + (numSteps / orbs * i)) % numSteps]; double dx = cos[(this.stepX + (numSteps / orbs * i)) % numSteps];
double dy = (stepY / (double)maxStepY); double dy = (this.stepY / (double) this.maxStepY);
double dz = sin[(stepX + (numSteps / orbs * i)) % numSteps]; double dz = sin[(this.stepX + (numSteps / orbs * i)) % numSteps];
particles.add(new PParticle(location.clone().add(dx, dy, dz))); particles.add(new PParticle(location.clone().add(dx, dy, dz)));
} }
return particles; return particles;
@ -47,17 +47,19 @@ public class ParticleStyleTwins extends DefaultParticleStyle {
@Override @Override
public void updateTimers() { public void updateTimers() {
stepX++; this.stepX++;
if (stepX > numSteps) { if (this.stepX > numSteps) {
stepX = 0; this.stepX = 0;
} }
if (reverse) { if (this.reverse) {
stepY++; this.stepY++;
if (stepY > maxStepY) reverse = false; if (this.stepY > this.maxStepY)
this.reverse = false;
} else { } else {
stepY--; this.stepY--;
if (stepY < -maxStepY) reverse = true; if (this.stepY < -this.maxStepY)
this.reverse = true;
} }
} }

View file

@ -1,18 +1,18 @@
/** /**
* The MIT License (MIT) * The MIT License (MIT)
* * <p>
* Copyright (c) 2014 Slikey * Copyright (c) 2014 Slikey
* * <p>
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights * in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is * copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions: * furnished to do so, subject to the following conditions:
* * <p>
* The above copyright notice and this permission notice shall be included in all * The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software. * copies or substantial portions of the Software.
* * <p>
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@ -47,10 +47,10 @@ public class ParticleStyleVortex extends DefaultParticleStyle {
public List<PParticle> getParticles(ParticlePair particle, Location location) { public List<PParticle> getParticles(ParticlePair particle, Location location) {
List<PParticle> particles = new ArrayList<>(); List<PParticle> particles = new ArrayList<>();
double radius = 2 * (1 - (double)step / maxStep); double radius = 2 * (1 - (double) this.step / this.maxStep);
for (int i = 0; i < helices; i++) { for (int i = 0; i < this.helices; i++) {
double angle = step * radials + (2 * Math.PI * i / helices); double angle = this.step * this.radials + (2 * Math.PI * i / this.helices);
Vector v = new Vector(Math.cos(angle) * radius, step * grow - 1, Math.sin(angle) * radius); Vector v = new Vector(Math.cos(angle) * radius, this.step * this.grow - 1, Math.sin(angle) * radius);
particles.add(new PParticle(location.clone().add(v))); particles.add(new PParticle(location.clone().add(v)));
} }
@ -60,7 +60,7 @@ public class ParticleStyleVortex extends DefaultParticleStyle {
@Override @Override
public void updateTimers() { public void updateTimers() {
step = (step + 1) % maxStep; this.step = (this.step + 1) % this.maxStep;
} }
@Override @Override

View file

@ -21,12 +21,12 @@ public class ParticleStyleWhirl extends DefaultParticleStyle {
@Override @Override
public List<PParticle> getParticles(ParticlePair particle, Location location) { public List<PParticle> getParticles(ParticlePair particle, Location location) {
List<PParticle> particles = new ArrayList<>(); List<PParticle> particles = new ArrayList<>();
double speed = getSpeedByEffect(particle.getEffect()); double speed = this.getSpeedByEffect(particle.getEffect());
for (int i = 0; i < points; i++) { for (int i = 0; i < this.points; i++) {
double dx = Math.cos(step + (Math.PI * 2 * ((double)i / points))); double dx = Math.cos(this.step + (Math.PI * 2 * ((double) i / this.points)));
double dy = -0.9; double dy = -0.9;
double dz = Math.sin(step + (Math.PI * 2 * ((double)i / points))); double dz = Math.sin(this.step + (Math.PI * 2 * ((double) i / this.points)));
double angle = Math.atan2(dz, dx); double angle = Math.atan2(dz, dx);
double xAng = Math.cos(angle); double xAng = Math.cos(angle);
double zAng = Math.sin(angle); double zAng = Math.sin(angle);
@ -67,7 +67,7 @@ public class ParticleStyleWhirl extends DefaultParticleStyle {
@Override @Override
public void updateTimers() { public void updateTimers() {
step = (step + Math.PI * 2 / numSteps) % numSteps; this.step = (this.step + Math.PI * 2 / this.numSteps) % this.numSteps;
} }
@Override @Override

View file

@ -21,13 +21,13 @@ public class ParticleStyleWhirlwind extends DefaultParticleStyle {
@Override @Override
public List<PParticle> getParticles(ParticlePair particle, Location location) { public List<PParticle> getParticles(ParticlePair particle, Location location) {
List<PParticle> particles = new ArrayList<>(); List<PParticle> particles = new ArrayList<>();
double speed = getSpeedByEffect(particle.getEffect()) * 2.5; double speed = this.getSpeedByEffect(particle.getEffect()) * 2.5;
// Orbit going clockwise // Orbit going clockwise
for (int i = 0; i < points; i++) { for (int i = 0; i < this.points; i++) {
double dx = Math.cos(step + (Math.PI * 2 * ((double)i / points))); double dx = Math.cos(this.step + (Math.PI * 2 * ((double) i / this.points)));
double dy = -0.9; double dy = -0.9;
double dz = Math.sin(step + (Math.PI * 2 * ((double)i / points))); double dz = Math.sin(this.step + (Math.PI * 2 * ((double) i / this.points)));
double angle = Math.atan2(dz, dx); double angle = Math.atan2(dz, dx);
double xAng = Math.cos(angle); double xAng = Math.cos(angle);
double zAng = Math.sin(angle); double zAng = Math.sin(angle);
@ -68,7 +68,7 @@ public class ParticleStyleWhirlwind extends DefaultParticleStyle {
@Override @Override
public void updateTimers() { public void updateTimers() {
step = (step + Math.PI * 2 / numSteps) % numSteps; this.step = (this.step + Math.PI * 2 / this.numSteps) % this.numSteps;
} }
@Override @Override

View file

@ -20,7 +20,7 @@ public class ParticleStyleWings extends DefaultParticleStyle {
@Override @Override
public List<PParticle> getParticles(ParticlePair particle, Location location) { public List<PParticle> getParticles(ParticlePair particle, Location location) {
List<PParticle> particles = new ArrayList<>(); List<PParticle> particles = new ArrayList<>();
if (spawnTimer == 0) { if (this.spawnTimer == 0) {
for (double t = 0; t < Math.PI * 2; t += Math.PI / 48) { for (double t = 0; t < Math.PI * 2; t += Math.PI / 48) {
double offset = (Math.pow(Math.E, Math.cos(t)) - 2 * Math.cos(t * 4) - Math.pow(Math.sin(t / 12), 5)) / 2; double offset = (Math.pow(Math.E, Math.cos(t)) - 2 * Math.cos(t * 4) - Math.pow(Math.sin(t / 12), 5)) / 2;
double x = Math.sin(t) * offset; double x = Math.sin(t) * offset;
@ -34,8 +34,8 @@ public class ParticleStyleWings extends DefaultParticleStyle {
@Override @Override
public void updateTimers() { public void updateTimers() {
spawnTimer++; this.spawnTimer++;
spawnTimer %= 3; this.spawnTimer %= 3;
} }
@Override @Override