Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add #102 + Small refactor #134

Merged
merged 7 commits into from
Aug 10, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public void onEnable() {
AntiRadar.load(getConfig());
ContactExplosives.load(getConfig());
DurabilityOverride.load(getConfig());
FireballLifespan.load(getConfig());
FireballBehaviour.load(getConfig());
FireballPenetration.load(getConfig());
ReImplementTNTTranslocation.load(getConfig());
BlockBehaviorOverride.load(getConfig());
Expand Down Expand Up @@ -126,10 +126,10 @@ public void onEnable() {
getServer().getPluginManager().registerEvents(contactExplosives, this);
contactExplosives.runTaskTimer(this, 0, 1); // Every tick
getServer().getPluginManager().registerEvents(new DurabilityOverride(), this);
var fireballLifespan = new FireballLifespan();
var fireballLifespan = new FireballBehaviour();
getServer().getPluginManager().registerEvents(fireballLifespan, this);
fireballLifespan.runTaskTimer(this, 0, 20); // Every 1 second
getServer().getPluginManager().registerEvents(new FireballLifespan(), this);
getServer().getPluginManager().registerEvents(new FireballBehaviour(), this);
getServer().getPluginManager().registerEvents(new FireballPenetration(), this);
getServer().getPluginManager().registerEvents(new ReImplementTNTTranslocation(), this);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,22 @@
import org.bukkit.event.entity.ProjectileLaunchEvent;
import org.bukkit.metadata.FixedMetadataValue;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.util.Vector;
import org.jetbrains.annotations.NotNull;

import java.util.Deque;
import java.util.LinkedList;

public class FireballLifespan extends BukkitRunnable implements Listener {
public class FireballBehaviour extends BukkitRunnable implements Listener {
private static final String METADATA_KEY = "MCC-Expiry";
public static int FireballLifespan = 0;
private static double FireballSpeed = 1.0;
private final Deque<SmallFireball> queue = new LinkedList<>();

public static void load(@NotNull FileConfiguration config) {
FireballLifespan = config.getInt("FireballLifespan", 6);
FireballLifespan *= 20 * 50; // Convert from seconds to milliseconds
FireballSpeed = config.getDouble("FireballSpeed", 1.0);
FireballLifespan *= 1000; // Convert from seconds to milliseconds
}

@Override
Expand All @@ -39,9 +42,22 @@ public void run() {

@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onProjectileLaunch(@NotNull ProjectileLaunchEvent e) {
if (!(e.getEntity() instanceof SmallFireball))
if (!(e.getEntity() instanceof SmallFireball fireball))
return;
SmallFireball fireball = (SmallFireball) e.getEntity();

new BukkitRunnable() {
@Override
public void run() {
Vector fireballVector = fireball.getVelocity();
double speed = fireballVector.length() * FireballSpeed;

fireballVector = fireballVector.normalize();
fireballVector.multiply(speed);

fireball.setVelocity(fireballVector);
}
}.runTaskTimer(MovecraftCombat.getInstance(), 1L, 1L);

fireball.setMetadata(METADATA_KEY, new FixedMetadataValue(MovecraftCombat.getInstance(), System.currentTimeMillis()));
queue.add(fireball);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import net.countercraft.movecraft.util.MathUtils;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.World;
import org.bukkit.block.Block;
Expand Down Expand Up @@ -95,12 +94,13 @@ private void processFireball(@NotNull SmallFireball fireball) {
fireball.setShooter(p);

Vector fireballVector = fireball.getVelocity();
double speed = fireballVector.length(); // store the speed to add it back in later, since all the values we will be using are "normalized", IE: have a speed of 1
double speed = fireballVector.length() ; // store the speed to add it back in later, since all the values we will be using are "normalized", IE: have a speed of 1
fireballVector = fireballVector.normalize(); // you normalize it for comparison with the new direction to see if we are trying to steer too far

Block targetBlock = DirectorUtils.getDirectorBlock(p, AADirectorRange);
Vector targetVector;
if (targetBlock == null || targetBlock.getType().equals(Material.AIR)) // the player is looking at nothing, shoot in that general direction

if (targetBlock == null || targetBlock.getType().isAir()) // the player is looking at nothing, shoot in that general direction
targetVector = p.getLocation().getDirection();
else { // shoot directly at the block the player is looking at (IE: with convergence)
targetVector = targetBlock.getLocation().toVector().subtract(fireball.getLocation().toVector());
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ DurabilityOverride: # List of block IDs: ignore percent

# Fireball Lifespan
FireballLifespan: 6 # Lifespan of fireballs in seconds
FireballSpeed: 1.0 # Speed multiplier for fireballs

# TNT Tracers
TracerRateTicks: 5.0 # Rate at which tracers are spawned on the path of flying TNT
Expand All @@ -51,7 +52,6 @@ ExplosionBlock: GLOWSTONE # Block to use to indicate tracer explosions
TracerParticles: FIREWORKS_SPARK # Particle to use for particle tracers See https://hub.spigotmc.org/javadocs/spigot/org/bukkit/Particle.html for options.
ExplosionParticles: VILLAGER_ANGRY # Particle to use for particle tracer explosions


### Custom features

# Damage Tracking
Expand Down