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

Revert "Add #102 + Small refactor (#134)" #137

Merged
merged 1 commit into from
Aug 11, 2024
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -84,11 +84,11 @@ public void onEnable() {
AntiRadar.load(config);
ContactExplosives.load(config);
DurabilityOverride.load(config);
FireballBehaviour.load(config);
FireballLifespan.load(config);
FireballPenetration.load(config);
ReImplementTNTTranslocation.load(config);
BlockBehaviorOverride.load(config);

// Register event translation listeners
PluginManager pluginManager = getServer().getPluginManager();
pluginManager.registerEvents(new CraftCollisionExplosionListener(), this);
Expand Down Expand Up @@ -129,9 +129,10 @@ public void onEnable() {
pluginManager.registerEvents(contactExplosives, this);
contactExplosives.runTaskTimer(this, 0, 1); // Every tick
pluginManager.registerEvents(new DurabilityOverride(), this);
var fireballBehavior = new FireballBehaviour();
pluginManager.registerEvents(fireballBehavior, this);
fireballBehavior.runTaskTimer(this, 0, 20); // Every 1 second
var fireballLifespan = new FireballLifespan();
pluginManager.registerEvents(fireballLifespan, this);
fireballLifespan.runTaskTimer(this, 0, 20); // Every 1 second
pluginManager.registerEvents(new FireballLifespan(), this);
pluginManager.registerEvents(new FireballPenetration(), this);
pluginManager.registerEvents(new ReImplementTNTTranslocation(), this);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,19 @@
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 FireballBehaviour extends BukkitRunnable implements Listener {
public class FireballLifespan 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);
FireballSpeed = config.getDouble("FireballSpeed", 1.0);
FireballLifespan *= 1000; // Convert from seconds to milliseconds
FireballLifespan *= 20 * 50; // Convert from seconds to milliseconds
}

@Override
Expand All @@ -42,29 +39,11 @@ public void run() {

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

SmallFireball fireball = (SmallFireball) e.getEntity();
fireball.setMetadata(METADATA_KEY, new FixedMetadataValue(MovecraftCombat.getInstance(), System.currentTimeMillis()));
queue.add(fireball);

new BukkitRunnable() {
@Override
public void run() {
Vector fireballVector = fireball.getVelocity();
try {
fireballVector.checkFinite();
}
catch (IllegalArgumentException ignored) {
return;
}
double speed = fireballVector.length() * FireballSpeed;

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

fireball.setVelocity(fireballVector);
}
}.runTaskLater(MovecraftCombat.getInstance(), 1L);
}
}
2 changes: 1 addition & 1 deletion src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ BleedfixExplosion: true

# 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 @@ -53,6 +52,7 @@ 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