pattern framework
This commit is contained in:
3
.vscode/settings.json
vendored
Normal file
3
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"java.compile.nullAnalysis.mode": "automatic"
|
||||||
|
}
|
@ -203,16 +203,11 @@ public class Fireworkshow implements CommandExecutor, TabCompleter {
|
|||||||
case "start":
|
case "start":
|
||||||
Fireworks_Mc.show.start();
|
Fireworks_Mc.show.start();
|
||||||
return true;
|
return true;
|
||||||
case "generate":
|
|
||||||
Message.sendInfo(player, "Generating firework show...");
|
|
||||||
Fireworks_Mc.show.generate();
|
|
||||||
Message.sendInfo(player, "Firework show successfully generated!");
|
|
||||||
return true;
|
|
||||||
case "debug":
|
case "debug":
|
||||||
Fireworks_Mc.config.print();
|
Fireworks_Mc.config.print();
|
||||||
return true;
|
return true;
|
||||||
case "reload":
|
case "reload":
|
||||||
Fireworks_Mc.config.reload();
|
Fireworks_Mc.getPlugin().reload();
|
||||||
return true;
|
return true;
|
||||||
default:
|
default:
|
||||||
Message.sendWarning(player, "Invalid command!");
|
Message.sendWarning(player, "Invalid command!");
|
||||||
@ -232,7 +227,6 @@ public class Fireworkshow implements CommandExecutor, TabCompleter {
|
|||||||
completions.add("setduration");
|
completions.add("setduration");
|
||||||
completions.add("setseed");
|
completions.add("setseed");
|
||||||
completions.add("start");
|
completions.add("start");
|
||||||
completions.add("generate");
|
|
||||||
completions.add("debug");
|
completions.add("debug");
|
||||||
completions.add("reload");
|
completions.add("reload");
|
||||||
completions.add("highlights");
|
completions.add("highlights");
|
||||||
|
@ -0,0 +1,57 @@
|
|||||||
|
package org.aleabodo.fireworksmc.Commands;
|
||||||
|
|
||||||
|
import org.aleabodo.fireworksmc.Fireworks_Mc;
|
||||||
|
import org.bukkit.Color;
|
||||||
|
import org.bukkit.FireworkEffect;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.EntityType;
|
||||||
|
import org.bukkit.entity.Firework;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.inventory.meta.FireworkMeta;
|
||||||
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
public class SpawnRocket implements CommandExecutor {
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||||
|
if (!(sender instanceof Player)) {
|
||||||
|
sender.sendMessage("This command is reserved for players only!");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Player player = ((Player) sender).getPlayer();
|
||||||
|
|
||||||
|
this.spawnRocket(player.getLocation());
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void spawnRocket(Location location) {
|
||||||
|
Firework firework = (Firework) location.getWorld().spawnEntity(location, EntityType.FIREWORK);
|
||||||
|
FireworkMeta fireworkMeta = firework.getFireworkMeta();
|
||||||
|
|
||||||
|
// Create a firework effect
|
||||||
|
FireworkEffect effect = FireworkEffect.builder()
|
||||||
|
.flicker(true)
|
||||||
|
.trail(true)
|
||||||
|
.withColor(Color.RED)
|
||||||
|
.withFade(Color.YELLOW)
|
||||||
|
.with(FireworkEffect.Type.BALL_LARGE)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
fireworkMeta.addEffect(effect);
|
||||||
|
fireworkMeta.setPower(10); // Number of times the firework will explode
|
||||||
|
firework.setFireworkMeta(fireworkMeta);
|
||||||
|
|
||||||
|
// Schedule the firework to be removed after a delay
|
||||||
|
new BukkitRunnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
firework.detonate();
|
||||||
|
}
|
||||||
|
}.runTaskLater(Fireworks_Mc.getPlugin(), 60); // 20 ticks = 1 second
|
||||||
|
}
|
||||||
|
}
|
@ -12,7 +12,7 @@ import java.util.logging.Level;
|
|||||||
public class Config {
|
public class Config {
|
||||||
public int bpm;
|
public int bpm;
|
||||||
public String seed;
|
public String seed;
|
||||||
public int duration;
|
public int duration; //In game-ticks
|
||||||
public Location location;
|
public Location location;
|
||||||
public Direction direction;
|
public Direction direction;
|
||||||
public SortedSet<Integer> highlights;
|
public SortedSet<Integer> highlights;
|
||||||
|
@ -3,6 +3,7 @@ package org.aleabodo.fireworksmc;
|
|||||||
import com.github.fierioziy.particlenativeapi.api.ParticleNativeAPI;
|
import com.github.fierioziy.particlenativeapi.api.ParticleNativeAPI;
|
||||||
import com.github.fierioziy.particlenativeapi.plugin.ParticleNativePlugin;
|
import com.github.fierioziy.particlenativeapi.plugin.ParticleNativePlugin;
|
||||||
import org.aleabodo.fireworksmc.Commands.Fireworkshow;
|
import org.aleabodo.fireworksmc.Commands.Fireworkshow;
|
||||||
|
import org.aleabodo.fireworksmc.Commands.SpawnRocket;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
@ -57,6 +58,8 @@ public final class Fireworks_Mc extends JavaPlugin {
|
|||||||
*/
|
*/
|
||||||
Objects.requireNonNull(getCommand("fireworkshow")).setExecutor(new Fireworkshow());
|
Objects.requireNonNull(getCommand("fireworkshow")).setExecutor(new Fireworkshow());
|
||||||
Objects.requireNonNull(getCommand("fs")).setExecutor(new Fireworkshow()); //Command alias for fireworkshow
|
Objects.requireNonNull(getCommand("fs")).setExecutor(new Fireworkshow()); //Command alias for fireworkshow
|
||||||
|
Objects.requireNonNull(getCommand("rocket")).setExecutor(new SpawnRocket());
|
||||||
|
Objects.requireNonNull(getCommand("r")).setExecutor(new SpawnRocket());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -64,6 +67,12 @@ public final class Fireworks_Mc extends JavaPlugin {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void reload() {
|
||||||
|
if (Fireworks_Mc.config != null) {
|
||||||
|
Fireworks_Mc.config.reload();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* ################### GETTER ###################
|
* ################### GETTER ###################
|
||||||
*/
|
*/
|
||||||
|
16
src/main/java/org/aleabodo/fireworksmc/Patterns/PRandom.java
Normal file
16
src/main/java/org/aleabodo/fireworksmc/Patterns/PRandom.java
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
package org.aleabodo.fireworksmc.Patterns;
|
||||||
|
|
||||||
|
import org.aleabodo.fireworksmc.Tempo;
|
||||||
|
|
||||||
|
public class PRandom extends Pattern {
|
||||||
|
|
||||||
|
PRandom(long seed, int duration, int bpm, Tempo tempo) {
|
||||||
|
super(seed, duration, bpm, tempo);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void generate() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,10 +1,81 @@
|
|||||||
package org.aleabodo.fireworksmc.Patterns;
|
package org.aleabodo.fireworksmc.Patterns;
|
||||||
|
|
||||||
public class Pattern {
|
import java.util.PriorityQueue;
|
||||||
private int duration = 10;
|
|
||||||
|
|
||||||
public Pattern(int duration) {
|
import org.aleabodo.fireworksmc.Fireworks_Mc;
|
||||||
|
import org.aleabodo.fireworksmc.Tempo;
|
||||||
|
import org.bukkit.FireworkEffect;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
||||||
|
public abstract class Pattern {
|
||||||
|
protected int duration; // Delay of pattern in ticks
|
||||||
|
protected long seed;
|
||||||
|
protected int bpm;
|
||||||
|
protected Tempo tempo;
|
||||||
|
protected int startDelay; // Start delay in ticks until the first rocket detonates
|
||||||
|
private boolean cancel = false;
|
||||||
|
protected PriorityQueue<ScheduledThing> scheduledThings = new PriorityQueue<>();
|
||||||
|
|
||||||
|
Pattern(long seed, int duration, int bpm, Tempo tempo) {
|
||||||
|
this.seed = seed;
|
||||||
|
this.duration = duration;
|
||||||
|
this.bpm = bpm;
|
||||||
|
this.tempo = tempo;
|
||||||
|
|
||||||
|
this.generate();
|
||||||
|
this.startDelay = scheduledThings.peek().getScheduleTime();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Start pattern
|
||||||
|
*/
|
||||||
|
public void start() {
|
||||||
|
if (scheduledThings.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
new BukkitRunnable() {
|
||||||
|
int tick = scheduledThings.peek().getScheduleTime(); //Zecke
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
if (cancel) {
|
||||||
|
this.cancel();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (scheduledThings.peek().getScheduleTime() == tick) {
|
||||||
|
scheduledThings.poll().schedule();
|
||||||
|
if (scheduledThings.isEmpty()) {
|
||||||
|
this.cancel();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tick++;
|
||||||
|
}
|
||||||
|
}.runTaskTimer(Fireworks_Mc.getPlugin(), 0, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stop/cancel execution of pattern
|
||||||
|
*/
|
||||||
|
public void stop() {
|
||||||
|
this.cancel = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate pattern
|
||||||
|
*/
|
||||||
|
protected abstract void generate();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Schedule rocket
|
||||||
|
*/
|
||||||
|
protected void scheduleRocket(int explosionTime, int flightDuration, Location location, FireworkEffect effect) {
|
||||||
|
//scheduledThings.add();
|
||||||
|
//TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -12,6 +83,28 @@ public class Pattern {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
public int getDuration() {
|
public int getDuration() {
|
||||||
return duration;
|
return this.duration;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getStartDelay() {
|
||||||
|
return this.duration;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* ################### SETTER ###################
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pattern duration in ticks
|
||||||
|
*/
|
||||||
|
void setDuration(int duration) {
|
||||||
|
this.duration = duration;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pattern bpm in ticks
|
||||||
|
*/
|
||||||
|
void setBpm(int bpm) {
|
||||||
|
this.bpm = bpm;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -0,0 +1,14 @@
|
|||||||
|
package org.aleabodo.fireworksmc.Patterns;
|
||||||
|
|
||||||
|
public class ScheduledRocket extends ScheduledThing {
|
||||||
|
|
||||||
|
public ScheduledRocket() {
|
||||||
|
//TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void schedule() {
|
||||||
|
//TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,20 @@
|
|||||||
|
package org.aleabodo.fireworksmc.Patterns;
|
||||||
|
|
||||||
|
public abstract class ScheduledThing implements Comparable<ScheduledThing>{
|
||||||
|
protected int scheduleTime = 0;
|
||||||
|
|
||||||
|
public abstract void schedule();
|
||||||
|
|
||||||
|
protected void setScheduleTime(int scheduleTime) {
|
||||||
|
this.scheduleTime = scheduleTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getScheduleTime() {
|
||||||
|
return this.scheduleTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int compareTo(ScheduledThing other) {
|
||||||
|
return this.scheduleTime - other.scheduleTime;
|
||||||
|
}
|
||||||
|
}
|
@ -7,24 +7,26 @@ import org.bukkit.entity.EntityType;
|
|||||||
import org.bukkit.entity.Firework;
|
import org.bukkit.entity.Firework;
|
||||||
import org.bukkit.inventory.meta.FireworkMeta;
|
import org.bukkit.inventory.meta.FireworkMeta;
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
import java.util.SortedMap;
|
||||||
import java.security.MessageDigest;
|
import java.util.SortedSet;
|
||||||
import java.security.NoSuchAlgorithmException;
|
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
public class Show {
|
public class Show {
|
||||||
private long seed;
|
private long seed;
|
||||||
private Location location;
|
private Location location;
|
||||||
private Direction direction;
|
private Direction direction;
|
||||||
private int duration; //in seconds
|
private int duration; //in game-ticks
|
||||||
private int bpm;
|
private int bpm;
|
||||||
|
private SortedSet<Integer> highlights;
|
||||||
|
private SortedMap<Integer,Tempo> tempo;
|
||||||
|
|
||||||
public Show(long seed, Location location, Direction direction, int duration, int bpm) {
|
public Show(long seed, Location location, Direction direction, int duration, int bpm, SortedSet<Integer> highlights, SortedMap<Integer,Tempo> tempo) {
|
||||||
this.seed = seed;
|
this.seed = seed;
|
||||||
this.location = location;
|
this.location = location;
|
||||||
this.direction = direction;
|
this.direction = direction;
|
||||||
this.duration = duration;
|
this.duration = duration;
|
||||||
this.bpm = bpm;
|
this.bpm = bpm;
|
||||||
|
this.highlights = highlights;
|
||||||
|
this.tempo = tempo;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -38,33 +40,7 @@ public class Show {
|
|||||||
* Executes the firework show
|
* Executes the firework show
|
||||||
*/
|
*/
|
||||||
public void start() {
|
public void start() {
|
||||||
spawnRocket(this.location);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void spawnRocket(Location location) {
|
|
||||||
Firework firework = (Firework) location.getWorld().spawnEntity(location, EntityType.FIREWORK);
|
|
||||||
FireworkMeta fireworkMeta = firework.getFireworkMeta();
|
|
||||||
|
|
||||||
// Create a firework effect
|
|
||||||
FireworkEffect effect = FireworkEffect.builder()
|
|
||||||
.flicker(true)
|
|
||||||
.trail(true)
|
|
||||||
.withColor(Color.RED)
|
|
||||||
.withFade(Color.YELLOW)
|
|
||||||
.with(FireworkEffect.Type.BALL_LARGE)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
fireworkMeta.addEffect(effect);
|
|
||||||
fireworkMeta.setPower(1); // Number of times the firework will explode
|
|
||||||
firework.setFireworkMeta(fireworkMeta);
|
|
||||||
|
|
||||||
// Schedule the firework to be removed after a delay
|
|
||||||
new BukkitRunnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
firework.detonate();
|
|
||||||
}
|
|
||||||
}.runTaskLater(Fireworks_Mc.getPlugin(), 20); // 20 ticks = 1 second
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -6,6 +6,9 @@ commands:
|
|||||||
fireworkshow:
|
fireworkshow:
|
||||||
description: All fireworks show related commands
|
description: All fireworks show related commands
|
||||||
aliases: [fs]
|
aliases: [fs]
|
||||||
|
rocket:
|
||||||
|
description: Spawn a rocket for testing purposes.
|
||||||
|
aliases: [ r ]
|
||||||
depend: [ParticleNativeAPI]
|
depend: [ParticleNativeAPI]
|
||||||
permissions:
|
permissions:
|
||||||
fireworksmc.setseed:
|
fireworksmc.setseed:
|
||||||
|
Reference in New Issue
Block a user