Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package me.thevipershow.simpleparticles.Particles;
- import me.thevipershow.simpleparticles.Simpleparticles;
- import org.bukkit.Bukkit;
- import org.bukkit.ChatColor;
- import org.bukkit.Location;
- import org.bukkit.Particle;
- import org.bukkit.command.Command;
- import org.bukkit.command.CommandExecutor;
- import org.bukkit.command.CommandSender;
- import org.bukkit.entity.Player;
- import org.bukkit.event.EventHandler;
- import org.bukkit.event.Listener;
- import org.bukkit.event.player.PlayerJoinEvent;
- import org.bukkit.event.player.PlayerQuitEvent;
- import org.bukkit.plugin.java.JavaPlugin;
- import org.bukkit.scheduler.BukkitRunnable;
- import java.util.HashMap;
- import java.util.Map;
- import java.util.Objects;
- import java.util.concurrent.atomic.AtomicReference;
- import static me.thevipershow.simpleparticles.Simpleparticles.*;
- public class NewPlayer implements Listener, CommandExecutor {
- private String chat(String input) {
- return ChatColor.translateAlternateColorCodes('&', input);
- }
- private void drawparticle(Player player, AtomicReference<Double> k, String particella) {
- if (player.isOnline()) {
- /*Location loc = player.getLocation();
- double px = loc.getX();
- double py = loc.getY();
- double pz = loc.getZ();*/
- double x = (player.getLocation().getX()) + (Simpleparticles.plugin.getConfig().getDouble("main.value.radius") * Math.cos(k.get() * Simpleparticles.plugin.getConfig().getDouble("main.value.factor-spirals"))),
- z = (player.getLocation().getZ()) + (Simpleparticles.plugin.getConfig().getDouble("main.value.radius") * Math.sin(Simpleparticles.plugin.getConfig().getDouble("main.value.factor-spirals") * k.get())),
- y = player.getLocation().getY() + (k.get() / Simpleparticles.plugin.getConfig().getDouble("main.value.height-factor2")) + Simpleparticles.plugin.getConfig().getDouble("main.value.height-factor");
- Objects.requireNonNull(Bukkit.getWorld(player.getWorld().getUID())).spawnParticle(Particle.valueOf(particella.toUpperCase()), x, y, z, 0, 0, 0, 0);
- }
- }
- private void updateConfig(JavaPlugin plugin, Player player) {
- plugin.reloadConfig();
- player.sendMessage(chat("&7» &aPlugin has been reloaded."));
- }
- @Override
- public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
- if (!(sender instanceof Player)) {
- log.info(ANSI_RED + "» You cannot run this command from system console!");
- } else if (sender.hasPermission("simpleparticles.enable")) {
- Player player = (Player) sender;
- switch (args.length) {
- case 0:
- player.sendMessage(chat("&7» &b&lSimpleParticles &7help page:"));
- player.sendMessage(chat("&7» &3/particles enable &a<particle>"));
- player.sendMessage(chat("&7» &3/particles disable"));
- player.sendMessage(chat("&7» &3/particles reload"));
- break;
- case 1:
- switch (args[0].toLowerCase()) {
- case "reload":
- if (player.hasPermission("simpleparticles.reload")) {
- updateConfig(plugin, player);
- } else {
- player.sendMessage(chat(plugin.getConfig().getString("main.messages.no-permission")));
- }
- break;
- case "rl":
- updateConfig(plugin, player);
- break;
- case "disable":
- if (player.hasPermission("simpleparticles.remove") && player_runnables.containsKey(player)) {
- player.sendMessage(chat(plugin.getConfig().getString("main.messages.disable-particles")));
- player_runnables.get(player).cancel();
- player_runnables.remove(player);
- }
- break;
- case "list":
- player.sendMessage(chat(plugin.getConfig().getString("main.messages.particles-list")));
- for (Map.Entry entry : particles2.entrySet()) {
- player.sendMessage(chat("&8» &a" + entry.getKey()));
- }
- break;
- default:
- player.sendMessage(chat(plugin.getConfig().getString("main.messages.invalid-argument")));
- break;
- }
- case 2:
- switch (args[0].toLowerCase()) {
- case "enable":
- if (player.hasPermission("simpleparticles." + args[1].toLowerCase()) && !player_runnables.containsKey(player) && player.isOnline()) {
- if (particles2.containsKey(args[1].toLowerCase())) {
- player.sendMessage(chat(plugin.getConfig().getString("main.messages.enabled-particles").replace("%pname%", args[1].toUpperCase())));
- AtomicReference<Double> k = new AtomicReference<>(0.00);
- BukkitRunnable runnable_player = new BukkitRunnable() {
- public void run() {
- drawparticle(player, k, Simpleparticles.particles2.get(args[1]).toUpperCase());
- k.updateAndGet(v -> v + plugin.getConfig().getDouble("main.value.runnable2"));
- if (k.get() > plugin.getConfig().getDouble("main.value.runnable3max")) {
- k.set((double) 0);
- }
- }
- };
- runnable_player.runTaskTimer(plugin, 0, Simpleparticles.plugin.getConfig().getLong("main.value.runnable") * 20);
- player_runnables.put(player, runnable_player);
- }
- } else {
- player.sendMessage(chat(plugin.getConfig().getString("main.messages.no-permission")));
- }
- break;
- }
- }
- }
- return false;
- }
- @EventHandler
- public void quit(PlayerQuitEvent event) {
- Player player = event.getPlayer();
- if (player_runnables.containsKey(player)) {
- //player_runnables.get(player).cancel();
- //player_runnables.remove(player);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement