!Small cleanup

This commit is contained in:
Indyuce 2020-04-11 12:32:47 +02:00
parent 0efdd54802
commit 99949e8c6b
2 changed files with 17 additions and 35 deletions

View File

@ -8,46 +8,31 @@ import org.bukkit.scheduler.BukkitRunnable;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import net.Indyuce.mmoitems.MMOItems;
import net.mmogroup.mmolib.MMOLib;
import net.mmogroup.mmolib.api.item.NBTItem;
public class ArrowParticles extends BukkitRunnable {
private Arrow arrow;
private final Arrow arrow;
private Particle particle;
private int amount;
private float offset, speed;
private Color color;
private final Particle particle;
private final int amount;
private final float offset, speed;
private final Color color;
private boolean valid = true, colored = false;
public ArrowParticles(Arrow arrow) {
public ArrowParticles(Arrow arrow, NBTItem item) {
this.arrow = arrow;
}
public ArrowParticles load(NBTItem item) {
String tag = item.getString("MMOITEMS_ARROW_PARTICLES");
if (tag.equals("")) {
valid = false;
return this;
}
JsonObject object = new JsonParser().parse(tag).getAsJsonObject();
JsonObject object = new JsonParser().parse(item.getString("MMOITEMS_ARROW_PARTICLES")).getAsJsonObject();
particle = Particle.valueOf(object.get("Particle").getAsString());
amount = object.get("Amount").getAsInt();
offset = (float) object.get("Offset").getAsDouble();
if (colored = object.get("Colored").getAsBoolean())
color = Color.fromRGB(object.get("Red").getAsInt(), object.get("Green").getAsInt(), object.get("Blue").getAsInt());
else
speed = object.get("Speed").getAsFloat();
boolean colored = object.get("Colored").getAsBoolean();
color = colored ? Color.fromRGB(object.get("Red").getAsInt(), object.get("Green").getAsInt(), object.get("Blue").getAsInt()) : null;
speed = colored ? 0 : object.get("Speed").getAsFloat();
return this;
}
public boolean isValid() {
return valid;
runTaskTimer(MMOItems.plugin, 0, 1);
}
@Override
@ -57,8 +42,9 @@ public class ArrowParticles extends BukkitRunnable {
return;
}
if (colored)
MMOLib.plugin.getVersion().getWrapper().spawnParticle(particle, arrow.getLocation().add(0, .25, 0), amount, offset, offset, offset, 0, 1, color);
if (color != null)
MMOLib.plugin.getVersion().getWrapper().spawnParticle(particle, arrow.getLocation().add(0, .25, 0), amount, offset, offset, offset, 0, 1,
color);
else
arrow.getWorld().spawnParticle(particle, arrow.getLocation().add(0, .25, 0), amount, offset, offset, offset, speed);
}

View File

@ -54,11 +54,8 @@ public class EntityManager implements Listener {
* arrow particles. currently projectiles are only arrows so there is no
* problem with other projectiles like snowballs etc.
*/
if (entity instanceof Arrow) {
ArrowParticles particles = new ArrowParticles((Arrow) entity).load(sourceItem);
if (particles.isValid())
particles.runTaskTimer(MMOItems.plugin, 0, 1);
}
if (entity instanceof Arrow && sourceItem.hasTag("MMOITEMS_ARROW_PARTICLES"))
new ArrowParticles((Arrow) entity, sourceItem);
projectiles.put(entity.getEntityId(), new ProjectileData(sourceItem, stats, customWeapon));
}
@ -125,6 +122,5 @@ public class EntityManager implements Listener {
event.setDamage(result.getDamage());
unregisterCustomProjectile(projectile);
return;
}
}