Added style 'teleport' (#37)

This commit is contained in:
HexedHero 2020-03-24 19:57:39 +00:00 committed by GitHub
parent 04abdfe208
commit 7971be1914
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 103 additions and 0 deletions

View file

@ -181,6 +181,7 @@ public class ConfigurationManager extends Manager {
GUI_ICON_STYLE_SPIN("gui-icon.style.spin", Collections.singletonList("BEACON")),
GUI_ICON_STYLE_SPIRAL("gui-icon.style.spiral", Collections.singletonList("HOPPER")),
GUI_ICON_STYLE_SWORDS("gui-icon.style.swords", Collections.singletonList("IRON_SWORD")),
GUI_ICON_STYLE_TELEPORT("gui-icon.style.teleport", Collections.singletonList("ENDER_PEARL")),
GUI_ICON_STYLE_THICK("gui-icon.style.thick", Arrays.asList("COBWEB", "WEB")),
GUI_ICON_STYLE_TRAIL("gui-icon.style.trail", Collections.singletonList("GHAST_TEAR")),
GUI_ICON_STYLE_TWINS("gui-icon.style.twins", Arrays.asList("OAK_FENCE", "FENCE")),

View file

@ -37,6 +37,7 @@ public class DefaultStyles {
public static final ParticleStyle SPIN = new ParticleStyleSpin();
public static final ParticleStyle SPIRAL = new ParticleStyleSpiral();
public static final ParticleStyle SWORDS = new ParticleStyleSwords();
public static final ParticleStyle TELEPORT = new ParticleStyleTeleport();
public static final ParticleStyle THICK = new ParticleStyleThick();
public static final ParticleStyle TRAIL = new ParticleStyleTrail();
public static final ParticleStyle TWINS = new ParticleStyleTwins();
@ -78,6 +79,7 @@ public class DefaultStyles {
particleStyleManager.registerStyle(SPIN);
particleStyleManager.registerStyle(SPIRAL);
particleStyleManager.registerEventStyle(SWORDS);
particleStyleManager.registerEventStyle(TELEPORT);
particleStyleManager.registerStyle(THICK);
particleStyleManager.registerEventStyle(TRAIL);
particleStyleManager.registerStyle(TWINS);
@ -95,6 +97,7 @@ public class DefaultStyles {
pluginManager.registerEvents((Listener) HURT, playerParticles);
pluginManager.registerEvents((Listener) MOVE, playerParticles);
pluginManager.registerEvents((Listener) SWORDS, playerParticles);
pluginManager.registerEvents((Listener) TELEPORT, playerParticles);
pluginManager.registerEvents((Listener) TRAIL, playerParticles);
}

View file

@ -0,0 +1,99 @@
package dev.esophose.playerparticles.styles;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.Bukkit;
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.player.PlayerTeleportEvent;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
import dev.esophose.playerparticles.PlayerParticles;
import dev.esophose.playerparticles.config.CommentedFileConfiguration;
import dev.esophose.playerparticles.manager.DataManager;
import dev.esophose.playerparticles.manager.ParticleManager;
import dev.esophose.playerparticles.particles.PParticle;
import dev.esophose.playerparticles.particles.PPlayer;
import dev.esophose.playerparticles.particles.ParticlePair;
public class ParticleStyleTeleport extends DefaultParticleStyle implements Listener {
private boolean before;
private boolean after;
private double amount;
private double spread;
private double speed;
public ParticleStyleTeleport() {
super("teleport", false, false, 0);
}
@Override
public List<PParticle> getParticles(ParticlePair particle, Location location) {
List<PParticle> particles = new ArrayList<>();
for (int i = 0; i < this.amount; i++)
particles.add(new PParticle(location, this.spread, this.spread, this.spread, this.speed));
return particles;
}
@Override
public void updateTimers() {
}
@Override
protected void setDefaultSettings(CommentedFileConfiguration config) {
this.setIfNotExists("before", true, "Spawn the particles at the teleporting position");
this.setIfNotExists("after", true, "Spawn the particles after the teleport in the new position");
this.setIfNotExists("amount", 25, "The number of particles to spawn");
this.setIfNotExists("spread", 0.5, "How much to spread the particles");
this.setIfNotExists("speed", 0.05, "If the particle supports speed, how much speed to apply");
}
@Override
protected void loadSettings(CommentedFileConfiguration config) {
this.before = config.getBoolean("before");
this.after = config.getBoolean("after");
this.amount = config.getDouble("amount");
this.spread = config.getDouble("spread");
this.speed = config.getDouble("speed");
}
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerTeleport(PlayerTeleportEvent event) {
TeleportCause cause = event.getCause();
if (cause == TeleportCause.UNKNOWN)
return;
ParticleManager particleManager = PlayerParticles.getInstance().getManager(ParticleManager.class);
Player player = event.getPlayer();
PPlayer pplayer = PlayerParticles.getInstance().getManager(DataManager.class).getPPlayer(player.getUniqueId());
if (pplayer != null) {
for (ParticlePair particle : pplayer.getActiveParticlesForStyle(DefaultStyles.TELEPORT)) {
if (this.before) {
Location loc1 = player.getLocation().clone();
loc1.setY(loc1.getY() + 1);
particleManager.displayParticles(player, player.getWorld(), particle, DefaultStyles.TELEPORT.getParticles(particle, loc1), false);
}
if (this.after) {
Bukkit.getScheduler().runTaskLater(PlayerParticles.getInstance(), () -> {
Location loc2 = player.getLocation().clone();
loc2.setY(loc2.getY() + 1);
particleManager.displayParticles(player, player.getWorld(), particle, DefaultStyles.TELEPORT.getParticles(particle, loc2), false);
}, 1);
}
}
}
}
}