Nullable casting particles

This commit is contained in:
Indyuce 2022-10-14 12:58:25 +02:00
parent 817d28c602
commit fa953f890f
3 changed files with 19 additions and 13 deletions

View File

@ -25,6 +25,7 @@ import net.Indyuce.mmocore.api.util.MMOCoreUtils;
import net.Indyuce.mmocore.api.util.math.formula.LinearValue; import net.Indyuce.mmocore.api.util.math.formula.LinearValue;
import net.Indyuce.mmocore.experience.EXPSource; import net.Indyuce.mmocore.experience.EXPSource;
import net.Indyuce.mmocore.experience.ExpCurve; import net.Indyuce.mmocore.experience.ExpCurve;
import net.Indyuce.mmocore.experience.ExperienceObject;
import net.Indyuce.mmocore.experience.droptable.ExperienceTable; import net.Indyuce.mmocore.experience.droptable.ExperienceTable;
import net.Indyuce.mmocore.loot.chest.particle.CastingParticle; import net.Indyuce.mmocore.loot.chest.particle.CastingParticle;
import net.Indyuce.mmocore.player.stats.StatInfo; import net.Indyuce.mmocore.player.stats.StatInfo;
@ -32,7 +33,6 @@ import net.Indyuce.mmocore.skill.ClassSkill;
import net.Indyuce.mmocore.skill.RegisteredSkill; import net.Indyuce.mmocore.skill.RegisteredSkill;
import net.Indyuce.mmocore.skill.cast.KeyCombo; import net.Indyuce.mmocore.skill.cast.KeyCombo;
import net.Indyuce.mmocore.skill.cast.PlayerKey; import net.Indyuce.mmocore.skill.cast.PlayerKey;
import net.Indyuce.mmocore.experience.ExperienceObject;
import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.ChatColor;
import org.apache.commons.lang.Validate; import org.apache.commons.lang.Validate;
import org.bukkit.Location; import org.bukkit.Location;
@ -65,7 +65,7 @@ public class PlayerClass extends PostLoadObject implements ExperienceObject {
@Nullable @Nullable
private final ExperienceTable expTable; private final ExperienceTable expTable;
@NotNull @Nullable
private final CastingParticle castParticle; private final CastingParticle castParticle;
private final int maxBoundActiveSkills, maxBoundPassiveSkills; private final int maxBoundActiveSkills, maxBoundPassiveSkills;
@ -193,9 +193,7 @@ public class PlayerClass extends PostLoadObject implements ExperienceObject {
+ id + "': " + exception.getMessage()); + id + "': " + exception.getMessage());
} }
castParticle = config.contains("cast-particle") castParticle = config.contains("cast-particle") ? new CastingParticle(config.getConfigurationSection("cast-particle")) : null;
? new CastingParticle(config.getConfigurationSection("cast-particle"))
: new CastingParticle(Particle.SPELL_INSTANT);
if (config.contains("options")) if (config.contains("options"))
for (String key : config.getConfigurationSection("options").getKeys(false)) for (String key : config.getConfigurationSection("options").getKeys(false))
@ -337,6 +335,7 @@ public class PlayerClass extends PostLoadObject implements ExperienceObject {
return icon.clone(); return icon.clone();
} }
@Nullable
public CastingParticle getCastParticle() { public CastingParticle getCastParticle() {
return castParticle; return castParticle;
} }

View File

@ -12,6 +12,7 @@ public abstract class SkillCastingHandler extends BukkitRunnable implements List
private final PlayerData caster; private final PlayerData caster;
private boolean open = true; private boolean open = true;
private int j;
public SkillCastingHandler(PlayerData caster, int runnablePeriod) { public SkillCastingHandler(PlayerData caster, int runnablePeriod) {
this.caster = caster; this.caster = caster;
@ -40,8 +41,19 @@ public abstract class SkillCastingHandler extends BukkitRunnable implements List
public void run() { public void run() {
if (!caster.isOnline() || caster.getPlayer().isDead()) if (!caster.isOnline() || caster.getPlayer().isDead())
caster.leaveCastingMode(); caster.leaveCastingMode();
else else {
// Apply casting particles
if (caster.getProfess().getCastParticle() != null)
for (int k = 0; k < 2; k++) {
double a = (double) j++ / 5;
caster.getProfess().getCastParticle()
.display(caster.getPlayer().getLocation().add(Math.cos(a), 1 + Math.sin(a / 3) / 1.3, Math.sin(a)));
}
// Apply casting mode-specific effects
onTick(); onTick();
}
} }
public abstract void onTick(); public abstract void onTick();

View File

@ -8,6 +8,7 @@ import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.player.PlayerData; import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.api.event.PlayerKeyPressEvent; import net.Indyuce.mmocore.api.event.PlayerKeyPressEvent;
import net.Indyuce.mmocore.api.SoundEvent; import net.Indyuce.mmocore.api.SoundEvent;
import net.Indyuce.mmocore.loot.chest.particle.CastingParticle;
import net.Indyuce.mmocore.skill.ClassSkill; import net.Indyuce.mmocore.skill.ClassSkill;
import net.Indyuce.mmocore.skill.RegisteredSkill; import net.Indyuce.mmocore.skill.RegisteredSkill;
import net.Indyuce.mmocore.skill.cast.PlayerKey; import net.Indyuce.mmocore.skill.cast.PlayerKey;
@ -137,13 +138,7 @@ public class SkillBar implements Listener {
@Override @Override
public void onTick() { public void onTick() {
if (j % 20 == 0) getCaster().displayActionBar(getFormat(getCaster())); if (j++ % 20 == 0) getCaster().displayActionBar(getFormat(getCaster()));
for (int k = 0; k < 2; k++) {
double a = (double) j++ / 5;
getCaster().getProfess().getCastParticle()
.display(getCaster().getPlayer().getLocation().add(Math.cos(a), 1 + Math.sin(a / 3) / 1.3, Math.sin(a)));
}
} }
} }
} }