commands, show initial setup
This commit is contained in:
@ -1,5 +0,0 @@
|
|||||||
package org.aleabodo.fireworksmc;
|
|
||||||
|
|
||||||
public class Commands {
|
|
||||||
|
|
||||||
}
|
|
@ -0,0 +1,101 @@
|
|||||||
|
package org.aleabodo.fireworksmc.Commands;
|
||||||
|
|
||||||
|
import org.aleabodo.fireworksmc.Direction;
|
||||||
|
import org.aleabodo.fireworksmc.Fireworks_Mc;
|
||||||
|
import org.aleabodo.fireworksmc.Message;
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.command.TabCompleter;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
public class Fireworkshow implements CommandExecutor, TabCompleter {
|
||||||
|
@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();
|
||||||
|
|
||||||
|
switch (args[0]) {
|
||||||
|
case "setlocation":
|
||||||
|
//Set location
|
||||||
|
Fireworks_Mc.show.setLocation(player.getLocation());
|
||||||
|
Message.sendInfo(player, "Location successfully set to your position.");
|
||||||
|
break;
|
||||||
|
case "setdirection":
|
||||||
|
//Set direction
|
||||||
|
switch (args[1]) {
|
||||||
|
case "north":
|
||||||
|
Fireworks_Mc.show.setDirection(Direction.NORTH);
|
||||||
|
break;
|
||||||
|
case "east":
|
||||||
|
Fireworks_Mc.show.setDirection(Direction.EAST);
|
||||||
|
break;
|
||||||
|
case "south":
|
||||||
|
Fireworks_Mc.show.setDirection(Direction.SOUTH);
|
||||||
|
break;
|
||||||
|
case "west":
|
||||||
|
Fireworks_Mc.show.setDirection(Direction.WEST);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
Message.sendWarning(player, "Please enter either 'north', 'east', 'south', or 'west'!");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "setduration":
|
||||||
|
//Set duration
|
||||||
|
try {
|
||||||
|
int duration = Integer.parseInt(args[1]);
|
||||||
|
Fireworks_Mc.show.setDuration(duration);
|
||||||
|
Message.sendInfo(player, "Duration successfully set to " + duration);
|
||||||
|
return true;
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
Message.sendWarning(player, "Please enter an integer for the duration (in seconds)!");
|
||||||
|
}
|
||||||
|
case "setseed":
|
||||||
|
//Set seed
|
||||||
|
StringBuilder result = new StringBuilder(args[1]);
|
||||||
|
for (int i = 1; i<args.length; i++) {
|
||||||
|
result.append(" ").append(args[i]);
|
||||||
|
}
|
||||||
|
Fireworks_Mc.show.setSeed(String.valueOf(result));
|
||||||
|
Message.sendInfo(player, "Seed successfully changed to '" + result + "'");
|
||||||
|
return true;
|
||||||
|
case "start":
|
||||||
|
Fireworks_Mc.show.start();
|
||||||
|
default:
|
||||||
|
Message.sendWarning(player, "Invalid command!");
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @Nullable List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command,
|
||||||
|
@NotNull String label, @NotNull String[] args) {
|
||||||
|
List<String> completions = new ArrayList<>();
|
||||||
|
|
||||||
|
if (args.length == 1) {
|
||||||
|
completions.add("setlocation");
|
||||||
|
completions.add("setdirection");
|
||||||
|
completions.add("setduration");
|
||||||
|
completions.add("setseed");
|
||||||
|
completions.add("start");
|
||||||
|
} else if (args.length == 2 && args[0].equals("setdirection")) {
|
||||||
|
completions.add("north");
|
||||||
|
completions.add("east");
|
||||||
|
completions.add("south");
|
||||||
|
completions.add("west");
|
||||||
|
}
|
||||||
|
|
||||||
|
return completions;
|
||||||
|
}
|
||||||
|
}
|
8
src/main/java/org/aleabodo/fireworksmc/Direction.java
Normal file
8
src/main/java/org/aleabodo/fireworksmc/Direction.java
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
package org.aleabodo.fireworksmc;
|
||||||
|
|
||||||
|
public enum Direction {
|
||||||
|
NORTH,
|
||||||
|
EAST,
|
||||||
|
SOUTH,
|
||||||
|
WEST
|
||||||
|
}
|
@ -1,21 +1,81 @@
|
|||||||
package org.aleabodo.fireworksmc;
|
package org.aleabodo.fireworksmc;
|
||||||
|
|
||||||
|
import com.github.fierioziy.particlenativeapi.api.ParticleNativeAPI;
|
||||||
|
import com.github.fierioziy.particlenativeapi.plugin.ParticleNativePlugin;
|
||||||
|
import org.aleabodo.fireworksmc.Commands.Fireworkshow;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import java.io.Console;
|
import java.io.Console;
|
||||||
|
import java.security.MessageDigest;
|
||||||
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.Random;
|
||||||
|
import java.util.UUID;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
public final class Fireworks_Mc extends JavaPlugin {
|
public final class Fireworks_Mc extends JavaPlugin {
|
||||||
|
private static ParticleNativeAPI particlesAPI;
|
||||||
|
private static Fireworks_Mc plugin;
|
||||||
|
|
||||||
|
public static Show show;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
getLogger().log(Level.INFO, "awdawawdawawdawawdawawdawawdawawdawawdawawdaw");
|
Fireworks_Mc.plugin = this;
|
||||||
|
|
||||||
|
getLogger().info("Starting Fireworks-MC plugin ...");
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Initialize Particles API
|
||||||
|
* Requires the ParticlesNativeAPI plugin
|
||||||
|
*/
|
||||||
|
if (!ParticleNativePlugin.isValid()) {
|
||||||
|
getLogger().log(Level.SEVERE, "Error occurred while loading Particles API dependency.");
|
||||||
|
this.setEnabled(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
particlesAPI = ParticleNativePlugin.getAPI();
|
||||||
|
|
||||||
|
//Initialize show with default values
|
||||||
|
Fireworks_Mc.show = new Show("Survival-Pi",
|
||||||
|
new Location(Fireworks_Mc.getWorld("world"), 0, 80, 0),
|
||||||
|
Direction.NORTH,
|
||||||
|
60);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Initialize command executors
|
||||||
|
*/
|
||||||
|
Objects.requireNonNull(getCommand("fireworkshow")).setExecutor(new Fireworkshow());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* ################### GETTER ###################
|
||||||
|
*/
|
||||||
|
|
||||||
|
public static World getWorld(UUID worldUUID) {
|
||||||
|
return Fireworks_Mc.plugin.getServer().getWorld(worldUUID);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static World getWorld(String worldName) {
|
||||||
|
return Fireworks_Mc.plugin.getServer().getWorld(worldName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Fireworks_Mc getPlugin() {
|
||||||
|
return plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* ################### SETTER ###################
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
125
src/main/java/org/aleabodo/fireworksmc/Message.java
Normal file
125
src/main/java/org/aleabodo/fireworksmc/Message.java
Normal file
@ -0,0 +1,125 @@
|
|||||||
|
package org.aleabodo.fireworksmc;
|
||||||
|
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
|
import net.kyori.adventure.text.format.TextColor;
|
||||||
|
import net.kyori.adventure.text.format.TextDecoration;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
public class Message {
|
||||||
|
|
||||||
|
public static void sendInfo(@NotNull Player player, Component ... content) {
|
||||||
|
Component textComponent = Component.text().color(NamedTextColor.GRAY).build()
|
||||||
|
.append(Component.text("[Fireworks] ")
|
||||||
|
.color(TextColor.color(0,213,255))
|
||||||
|
.decoration(TextDecoration.BOLD, true));
|
||||||
|
for (Component comp : content) {
|
||||||
|
textComponent = textComponent.append(comp);
|
||||||
|
}
|
||||||
|
|
||||||
|
player.sendMessage(textComponent);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void sendInfo(@NotNull Player player, String content) {
|
||||||
|
sendInfo(player, Component.text(content));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void sendInfo(Collection<Player> players, Component ... content) {
|
||||||
|
for (Player p : players) {
|
||||||
|
sendInfo(p, content);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void sendInfo(Collection<Player> players, String content) {
|
||||||
|
for (Player p : players) {
|
||||||
|
sendInfo(p, content);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* #############################################################################
|
||||||
|
* Warning
|
||||||
|
*/
|
||||||
|
|
||||||
|
public static void sendWarning(@NotNull Player player, Component ... content) {
|
||||||
|
Component textComponent = Component.text().color(NamedTextColor.GRAY).build()
|
||||||
|
.append(Component.text("[Fireworks] ")
|
||||||
|
.color(TextColor.color(255, 3, 4))
|
||||||
|
.decoration(TextDecoration.BOLD, true));
|
||||||
|
|
||||||
|
for (Component comp : content) {
|
||||||
|
textComponent = textComponent.append(comp);
|
||||||
|
}
|
||||||
|
|
||||||
|
player.sendMessage(textComponent);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void sendWarning(@NotNull Player player, String content) {
|
||||||
|
sendWarning(player, Component.text(content));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void sendWarning(Collection<Player> players, Component ... content) {
|
||||||
|
for (Player p : players) {
|
||||||
|
sendWarning(p, content);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void sendWarning(Collection<Player> players, String content) {
|
||||||
|
for (Player p : players) {
|
||||||
|
sendWarning(p, content);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* #############################################################################
|
||||||
|
* Broadcast
|
||||||
|
*/
|
||||||
|
|
||||||
|
public static void sendBroadcast(Component ... content) {
|
||||||
|
Component textComponent = Component.text().color(NamedTextColor.GRAY).build()
|
||||||
|
.append(Component.text("[Fireworks] ")
|
||||||
|
.color(TextColor.color(255, 153, 0))
|
||||||
|
.decoration(TextDecoration.BOLD, true));
|
||||||
|
|
||||||
|
for (Component comp : content) {
|
||||||
|
textComponent = textComponent.append(comp);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||||
|
p.sendMessage(textComponent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void sendBroadcast(String content) {
|
||||||
|
sendBroadcast(Component.text(content));
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* #############################################################################
|
||||||
|
* Debug
|
||||||
|
*/
|
||||||
|
|
||||||
|
public static void sendDebug(Component ... content) {
|
||||||
|
Component textComponent = Component.text().color(NamedTextColor.GRAY).build()
|
||||||
|
.append(Component.text("[Fireworks] ")
|
||||||
|
.color(TextColor.color(255, 0, 245))
|
||||||
|
.decoration(TextDecoration.BOLD, true));
|
||||||
|
|
||||||
|
for (Component comp : content) {
|
||||||
|
textComponent = textComponent.append(comp);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||||
|
if (p.hasPermission("beacon.debug"))
|
||||||
|
p.sendMessage(textComponent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void sendDebug(String content) {
|
||||||
|
sendDebug(Component.text(content));
|
||||||
|
}
|
||||||
|
}
|
127
src/main/java/org/aleabodo/fireworksmc/Show.java
Normal file
127
src/main/java/org/aleabodo/fireworksmc/Show.java
Normal file
@ -0,0 +1,127 @@
|
|||||||
|
package org.aleabodo.fireworksmc;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Color;
|
||||||
|
import org.bukkit.FireworkEffect;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.entity.EntityType;
|
||||||
|
import org.bukkit.entity.Firework;
|
||||||
|
import org.bukkit.inventory.meta.FireworkMeta;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
||||||
|
import java.security.MessageDigest;
|
||||||
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
public class Show {
|
||||||
|
private String seed;
|
||||||
|
private Location location;
|
||||||
|
private Direction direction;
|
||||||
|
private int duration; //in seconds
|
||||||
|
|
||||||
|
public Show(String seed, Location location, Direction direction, int duration) {
|
||||||
|
this.seed = seed;
|
||||||
|
this.location = location;
|
||||||
|
this.direction = direction;
|
||||||
|
this.duration = duration;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Executes the firework show
|
||||||
|
*/
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param seedString Random seed as string
|
||||||
|
* @return Random number between 0 and based on the seed
|
||||||
|
*/
|
||||||
|
private double generateRandomValueFromSeed(String seedString) {
|
||||||
|
try {
|
||||||
|
MessageDigest md = MessageDigest.getInstance("SHA-256");
|
||||||
|
byte[] hashBytes = md.digest(seedString.getBytes());
|
||||||
|
|
||||||
|
// Convert the first 8 bytes of the hash to a long value
|
||||||
|
long hashValue = 0;
|
||||||
|
for (int i = 0; i < 8; i++) {
|
||||||
|
hashValue = (hashValue << 8) | (hashBytes[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
//Convert long (hastValue) into random number between 0 and 1.
|
||||||
|
return new Random(hashValue).nextDouble();
|
||||||
|
} catch (NoSuchAlgorithmException e) {
|
||||||
|
throw new RuntimeException("Hashing algorithm not available. (Have to check or Intellij complains.", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* ################### GETTER ###################
|
||||||
|
*/
|
||||||
|
|
||||||
|
public String getSeed() {
|
||||||
|
return seed;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Location getLocation() {
|
||||||
|
return location;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Direction getDirection() {
|
||||||
|
return direction;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getDuration() {
|
||||||
|
return duration;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* ################### SETTER ###################
|
||||||
|
*/
|
||||||
|
|
||||||
|
public void setSeed(String seed) {
|
||||||
|
this.seed = seed;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLocation(Location location) {
|
||||||
|
this.location = location;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDirection(Direction direction) {
|
||||||
|
this.direction = direction;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDuration(int duration) {
|
||||||
|
this.duration = duration;
|
||||||
|
}
|
||||||
|
}
|
@ -2,3 +2,20 @@ name: Fireworks-Mc
|
|||||||
version: '${project.version}'
|
version: '${project.version}'
|
||||||
main: org.aleabodo.fireworksmc.Fireworks_Mc
|
main: org.aleabodo.fireworksmc.Fireworks_Mc
|
||||||
api-version: '1.20'
|
api-version: '1.20'
|
||||||
|
commands:
|
||||||
|
fireworkshow:
|
||||||
|
description: All fireworks show related commands
|
||||||
|
depend: [ParticleNativeAPI]
|
||||||
|
permissions:
|
||||||
|
fireworksmc.setseed:
|
||||||
|
description: Set the random seed for generating the fireworks show.
|
||||||
|
default: op
|
||||||
|
fireworksmc.setlocation:
|
||||||
|
description: Set the location of the fireworks show.
|
||||||
|
default: op
|
||||||
|
fireworksmc.setdirection:
|
||||||
|
description: Set the direction/rotation of the firework (north,east).
|
||||||
|
default: op
|
||||||
|
fireworksmc.debug:
|
||||||
|
description: Get debug messages
|
||||||
|
default: op
|
Reference in New Issue
Block a user