2019-10-17 16:04:43 -06:00
|
|
|
package dev.esophose.playerparticles.styles;
|
2018-03-04 03:02:02 -07:00
|
|
|
|
2019-12-09 12:04:06 -07:00
|
|
|
import dev.esophose.playerparticles.manager.DataManager;
|
|
|
|
import dev.esophose.playerparticles.manager.ParticleManager;
|
2020-01-05 17:26:45 -07:00
|
|
|
import dev.esophose.playerparticles.particles.PParticle;
|
2019-12-09 12:04:06 -07:00
|
|
|
import dev.esophose.playerparticles.particles.PPlayer;
|
|
|
|
import dev.esophose.playerparticles.particles.ParticlePair;
|
2020-05-11 13:04:11 -06:00
|
|
|
import dev.esophose.playerparticles.PlayerParticles;
|
|
|
|
import dev.esophose.playerparticles.config.CommentedFileConfiguration;
|
2019-12-12 19:32:53 -07:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
2018-03-04 03:02:02 -07:00
|
|
|
import org.bukkit.Location;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.bukkit.event.EventHandler;
|
|
|
|
import org.bukkit.event.EventPriority;
|
|
|
|
import org.bukkit.event.Listener;
|
|
|
|
import org.bukkit.event.block.BlockBreakEvent;
|
|
|
|
|
2020-01-10 05:05:22 -07:00
|
|
|
public class ParticleStyleBlockBreak extends DefaultParticleStyle implements Listener {
|
2018-03-04 03:02:02 -07:00
|
|
|
|
2020-01-16 19:09:11 -07:00
|
|
|
private int particleAmount;
|
2020-05-11 13:04:11 -06:00
|
|
|
private float particleSpread;
|
|
|
|
private float particleSpeed;
|
2020-01-16 19:09:11 -07:00
|
|
|
|
2020-01-10 05:05:22 -07:00
|
|
|
public ParticleStyleBlockBreak() {
|
|
|
|
super("blockbreak", false, false, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-09-23 20:42:52 -06:00
|
|
|
public List<PParticle> getParticles(ParticlePair particle, Location location) {
|
2019-12-12 19:32:53 -07:00
|
|
|
List<PParticle> particles = new ArrayList<>();
|
2018-10-06 13:53:31 -06:00
|
|
|
|
|
|
|
location.add(0.5, 0.5, 0.5); // Center around the block
|
2018-03-04 03:02:02 -07:00
|
|
|
|
2020-01-16 19:09:11 -07:00
|
|
|
for (int i = 0; i < this.particleAmount; i++)
|
|
|
|
particles.add(new PParticle(location, this.particleSpread, this.particleSpread, this.particleSpread, this.particleSpeed));
|
2018-03-04 03:02:02 -07:00
|
|
|
|
2018-09-23 20:42:52 -06:00
|
|
|
return particles;
|
2018-03-04 03:02:02 -07:00
|
|
|
}
|
|
|
|
|
2020-01-10 05:05:22 -07:00
|
|
|
@Override
|
2018-03-04 03:02:02 -07:00
|
|
|
public void updateTimers() {
|
2018-09-27 18:16:50 -06:00
|
|
|
|
2018-03-04 03:02:02 -07:00
|
|
|
}
|
|
|
|
|
2020-01-10 05:05:22 -07:00
|
|
|
@Override
|
|
|
|
protected void setDefaultSettings(CommentedFileConfiguration config) {
|
2020-01-16 19:09:11 -07:00
|
|
|
this.setIfNotExists("particle-amount", 10, "The number of particles to spawn");
|
|
|
|
this.setIfNotExists("particle-spread", 0.5, "The distance to spread particles");
|
|
|
|
this.setIfNotExists("particle-speed", 0.05, "The speed of the particles");
|
2018-03-04 03:02:02 -07:00
|
|
|
}
|
2020-01-10 05:05:22 -07:00
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void loadSettings(CommentedFileConfiguration config) {
|
2020-01-16 19:09:11 -07:00
|
|
|
this.particleAmount = config.getInt("particle-amount");
|
|
|
|
this.particleSpread = config.getInt("particle-spread");
|
2020-05-11 13:04:11 -06:00
|
|
|
this.particleSpeed = config.getFloat("particle-speed");
|
2018-12-01 19:34:01 -07:00
|
|
|
}
|
2018-09-27 18:16:50 -06:00
|
|
|
|
2018-03-04 03:02:02 -07:00
|
|
|
@EventHandler(priority = EventPriority.MONITOR)
|
|
|
|
public void onBlockBreak(BlockBreakEvent event) {
|
2019-12-09 12:04:06 -07:00
|
|
|
ParticleManager particleManager = PlayerParticles.getInstance().getManager(ParticleManager.class);
|
|
|
|
|
2018-03-04 03:02:02 -07:00
|
|
|
Player player = event.getPlayer();
|
2019-12-09 12:04:06 -07:00
|
|
|
PPlayer pplayer = PlayerParticles.getInstance().getManager(DataManager.class).getPPlayer(player.getUniqueId());
|
2018-09-23 20:42:52 -06:00
|
|
|
if (pplayer != null) {
|
2018-09-27 18:16:50 -06:00
|
|
|
for (ParticlePair particle : pplayer.getActiveParticlesForStyle(DefaultStyles.BLOCKBREAK)) {
|
2018-10-05 21:01:28 -06:00
|
|
|
Location loc = event.getBlock().getLocation().clone();
|
2020-02-14 19:10:52 -07:00
|
|
|
particleManager.displayParticles(player, player.getWorld(), particle, DefaultStyles.BLOCKBREAK.getParticles(particle, loc), false);
|
2018-09-27 18:16:50 -06:00
|
|
|
}
|
2018-03-04 03:02:02 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|