From bcc950f25f85f52eac931c9a29e3642cfc518267 Mon Sep 17 00:00:00 2001 From: Lorenzo Date: Thu, 9 Apr 2020 18:20:14 +0200 Subject: [PATCH] initial commit --- .idea/artifacts/Spigot_Plugin_jar.xml | 8 ++ .idea/description.html | 0 .idea/encodings.xml | 6 + .idea/libraries/spigot_1_15_2.xml | 11 ++ .idea/misc.xml | 6 + .idea/modules.xml | 8 ++ .idea/project-template.xml | 3 + .idea/template-meta.xml | 5 + .idea/uiDesigner.xml | 124 ++++++++++++++++++ .idea/vcs.xml | 6 + .idea/workspace.xml | 70 ++++++++++ Kisses.iml | 23 ++++ src/net/mindoverflow/kissplugin/Main.java | 40 ++++++ .../kissplugin/commands/AngryCommand.java | 81 ++++++++++++ .../kissplugin/commands/ClearChatCommand.java | 40 ++++++ .../kissplugin/commands/FunCommand.java | 37 ++++++ .../kissplugin/commands/KissCommand.java | 87 ++++++++++++ .../kissplugin/commands/SpookCommand.java | 82 ++++++++++++ .../listeners/CollisionListener.java | 65 +++++++++ .../kissplugin/utils/RunningTask.java | 47 +++++++ src/plugin.yml | 24 ++++ 21 files changed, 773 insertions(+) create mode 100644 .idea/artifacts/Spigot_Plugin_jar.xml create mode 100644 .idea/description.html create mode 100644 .idea/encodings.xml create mode 100644 .idea/libraries/spigot_1_15_2.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/project-template.xml create mode 100644 .idea/template-meta.xml create mode 100644 .idea/uiDesigner.xml create mode 100644 .idea/vcs.xml create mode 100644 .idea/workspace.xml create mode 100644 Kisses.iml create mode 100644 src/net/mindoverflow/kissplugin/Main.java create mode 100644 src/net/mindoverflow/kissplugin/commands/AngryCommand.java create mode 100644 src/net/mindoverflow/kissplugin/commands/ClearChatCommand.java create mode 100644 src/net/mindoverflow/kissplugin/commands/FunCommand.java create mode 100644 src/net/mindoverflow/kissplugin/commands/KissCommand.java create mode 100644 src/net/mindoverflow/kissplugin/commands/SpookCommand.java create mode 100644 src/net/mindoverflow/kissplugin/listeners/CollisionListener.java create mode 100644 src/net/mindoverflow/kissplugin/utils/RunningTask.java create mode 100644 src/plugin.yml diff --git a/.idea/artifacts/Spigot_Plugin_jar.xml b/.idea/artifacts/Spigot_Plugin_jar.xml new file mode 100644 index 0000000..3f270da --- /dev/null +++ b/.idea/artifacts/Spigot_Plugin_jar.xml @@ -0,0 +1,8 @@ + + + $PROJECT_DIR$/../../# Server per Test Plugins #/plugins + + + + + \ No newline at end of file diff --git a/.idea/description.html b/.idea/description.html new file mode 100644 index 0000000..e69de29 diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..97626ba --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/libraries/spigot_1_15_2.xml b/.idea/libraries/spigot_1_15_2.xml new file mode 100644 index 0000000..187dfd3 --- /dev/null +++ b/.idea/libraries/spigot_1_15_2.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..0548357 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..f42ea96 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/project-template.xml b/.idea/project-template.xml new file mode 100644 index 0000000..2ec4f5e --- /dev/null +++ b/.idea/project-template.xml @@ -0,0 +1,3 @@ + \ No newline at end of file diff --git a/.idea/template-meta.xml b/.idea/template-meta.xml new file mode 100644 index 0000000..7089c7e --- /dev/null +++ b/.idea/template-meta.xml @@ -0,0 +1,5 @@ + \ No newline at end of file diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 0000000..e96534f --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..1a2f609 --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,70 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1583790923733 + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Kisses.iml b/Kisses.iml new file mode 100644 index 0000000..687a4df --- /dev/null +++ b/Kisses.iml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/net/mindoverflow/kissplugin/Main.java b/src/net/mindoverflow/kissplugin/Main.java new file mode 100644 index 0000000..4ad6f24 --- /dev/null +++ b/src/net/mindoverflow/kissplugin/Main.java @@ -0,0 +1,40 @@ +package net.mindoverflow.kissplugin; + +import net.mindoverflow.kissplugin.commands.*; +import net.mindoverflow.kissplugin.listeners.CollisionListener; +import net.mindoverflow.kissplugin.utils.RunningTask; +import org.bukkit.plugin.java.JavaPlugin; + +import java.util.logging.Level; +import java.util.logging.Logger; + +public class Main extends JavaPlugin +{ + // Initializing needed variables. + private Logger logger; + public RunningTask runningTask = new RunningTask(this); + + // Method called when the plugin is being loaded. + @Override + public void onEnable() { + logger = getLogger(); + logger.log(Level.INFO, "Plugin Successfully Loaded!"); + + getCommand("fun").setExecutor(new FunCommand()); + getCommand("clearchat").setExecutor(new ClearChatCommand()); + getCommand("kiss").setExecutor(new KissCommand(this)); + getCommand("spook").setExecutor(new SpookCommand(this)); + getCommand("angry").setExecutor(new AngryCommand(this)); + + getServer().getPluginManager().registerEvents(new CollisionListener(this), this); + + runningTask.task = getServer().getScheduler().runTaskTimer(this, runningTask, 10, 10); + } + + // Method called when the plugin is being unloaded. + @Override + public void onDisable() { + getServer().getScheduler().cancelTasks(this); + logger.log(Level.INFO, "Plugin Successfully Unloaded!"); + } +} diff --git a/src/net/mindoverflow/kissplugin/commands/AngryCommand.java b/src/net/mindoverflow/kissplugin/commands/AngryCommand.java new file mode 100644 index 0000000..401ee0f --- /dev/null +++ b/src/net/mindoverflow/kissplugin/commands/AngryCommand.java @@ -0,0 +1,81 @@ +package net.mindoverflow.kissplugin.commands; + +import net.mindoverflow.kissplugin.Main; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import java.time.LocalTime; +import java.time.format.DateTimeFormatter; + +public class AngryCommand implements CommandExecutor +{ + + private Main plugin; + public AngryCommand(Main plugin) + { + this.plugin = plugin; + } + + @Override + public boolean onCommand(CommandSender commandSender, Command command, String s, String[] args) { + + if(commandSender instanceof Player) + { + Player sender = (Player)commandSender; + + if(plugin.runningTask.angryPlayers.containsKey(sender.getName())) + { + noLongerAngry(sender.getName(), plugin); + return true; + } + + int howLong = 60; + if(args.length == 0) + { + plugin.runningTask.angryPlayers.put(sender.getName(), howLong * plugin.runningTask.multiplier); + + + LocalTime timeOfDay = LocalTime.ofSecondOfDay(howLong); + String time = timeOfDay.format(DateTimeFormatter.ofPattern("HH:mm:ss")); + + time = time.replaceFirst(":", " hours, "); + time = time.replaceFirst(":", " minutes, and "); + time = time + " seconds"; + sender.sendMessage("§7You will be angry for §c" + time + "§7!"); + sender.sendMessage("§7You did not specify for how long! Use §c/angry §7 to set a specific time."); + } + else + { + howLong = Integer.parseInt(args[0]); + if(howLong > 86399) howLong = 86399; + plugin.runningTask.angryPlayers.put(sender.getName(), howLong * plugin.runningTask.multiplier); + + + LocalTime timeOfDay = LocalTime.ofSecondOfDay(howLong); + String time = timeOfDay.format(DateTimeFormatter.ofPattern("HH:mm:ss")); + time = time.replaceFirst(":", " hours, "); + time = time.replaceFirst(":", " minutes, and "); + time = time + " seconds"; + sender.sendMessage("§7You will be angry for §c" + time + "§7!"); + } + + plugin.getServer().broadcastMessage("§c" + sender.getName() + "§e is now angry!"); + + } + + return true; + } + + public static void noLongerAngry(String playerName, Main plugin) + { + + plugin.runningTask.angryPlayers.remove(playerName); + plugin.getServer().broadcastMessage("§a" + playerName + "§e is no longer angry!"); + + Player player = plugin.getServer().getPlayer(playerName); + if(player == null) return; + player.sendMessage("§aYou are no longer angry!"); + } +} diff --git a/src/net/mindoverflow/kissplugin/commands/ClearChatCommand.java b/src/net/mindoverflow/kissplugin/commands/ClearChatCommand.java new file mode 100644 index 0000000..bcd0617 --- /dev/null +++ b/src/net/mindoverflow/kissplugin/commands/ClearChatCommand.java @@ -0,0 +1,40 @@ +package net.mindoverflow.kissplugin.commands; + +import org.bukkit.Bukkit; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class ClearChatCommand implements CommandExecutor +{ + public static String permission = "funplugin.clearchat"; + + @Override + public boolean onCommand(CommandSender commandSender, Command command, String s, String[] strings) { + + + if(commandSender.hasPermission(permission)) + { + String message = "§7Chat cleared by §c" + commandSender.getName(); + + + for(Player p : Bukkit.getServer().getOnlinePlayers()) + { + for(int i = 0; i < 200; i++) + { + p.sendMessage(""); + } + + p.sendMessage(message); + } + + Bukkit.getConsoleSender().sendMessage(message); + } + else + { + commandSender.sendMessage("§cMissing permission: §4" + permission); + } + return true; + } +} diff --git a/src/net/mindoverflow/kissplugin/commands/FunCommand.java b/src/net/mindoverflow/kissplugin/commands/FunCommand.java new file mode 100644 index 0000000..31cd8c0 --- /dev/null +++ b/src/net/mindoverflow/kissplugin/commands/FunCommand.java @@ -0,0 +1,37 @@ +package net.mindoverflow.kissplugin.commands; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; + +public class FunCommand implements CommandExecutor +{ + + private CommandSender sender; + + @Override + public boolean onCommand(CommandSender commandSender, Command command, String s, String[] args) { + + sender = commandSender; + + sendMessage("§6------------[ FunPlugin ]------------"); + sendMessage("§c/kiss§7: give a kiss to the nearest player!"); + sendMessage("§7You can also walk towards the player to give a kiss."); + sendMessage(""); + sendMessage("§d/spook§7: spook the nearest player!"); + sendMessage("§7Be careful not to give too many spooks!"); + sendMessage(""); + sendMessage("§4/angry §7: become angry for a specified time!"); + sendMessage("§7You will keep spawning angry particles for that long."); + sendMessage(""); + sendMessage("§e/clearchat§7: clear everybody's chat."); + sendMessage("§7Only admins can run this command! (§8" + ClearChatCommand.permission + "§7)"); + + return true; + } + + private void sendMessage(String message) + { + sender.sendMessage(message); + } +} diff --git a/src/net/mindoverflow/kissplugin/commands/KissCommand.java b/src/net/mindoverflow/kissplugin/commands/KissCommand.java new file mode 100644 index 0000000..1f27b35 --- /dev/null +++ b/src/net/mindoverflow/kissplugin/commands/KissCommand.java @@ -0,0 +1,87 @@ +package net.mindoverflow.kissplugin.commands; + +import net.mindoverflow.kissplugin.Main; +import org.bukkit.Effect; +import org.bukkit.Location; +import org.bukkit.Particle; +import org.bukkit.Sound; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; +import org.bukkit.util.Vector; + +public class KissCommand implements CommandExecutor +{ + + private Main plugin; + public KissCommand(Main plugin) + { + this.plugin = plugin; + } + + @Override + public boolean onCommand(CommandSender commandSender, Command command, String label, String[] args) { + + if(commandSender instanceof Player) + { + Player sender = (Player)commandSender; + + for(Entity e : sender.getNearbyEntities(3, 3, 3)) + { + if(e instanceof Player) + { + Player nearPlayer = (Player)e; + + sendKiss(sender, nearPlayer, true, true, true, true, 5, 5, 10); + + return true; + } + } + + commandSender.sendMessage("§7There is no one to kiss around you! =("); + return true; + } + else + { + commandSender.sendMessage("§cOnly players can kiss other people!"); + } + return true; + } + + + public static void sendKiss(Player sender, Player nearPlayer, boolean sendMessage, boolean playSound, boolean sendTitle, boolean spawnParticle, int titleFadeIn, int titleFadeOut, int particleCount) + { + if(sendMessage) + { + sender.sendMessage("§7You kissed §c" + nearPlayer.getName() + "§7!"); + nearPlayer.sendMessage("§c" + sender.getName() + " §7kissed you!"); + } + + if(sendTitle) + { + sender.sendTitle("", "§c❤ §7You kissed §c" + nearPlayer.getName() + "§7! §c❤", titleFadeIn, 20, titleFadeOut); + nearPlayer.sendTitle("", "§c❤ §c" + sender.getName() + " §7kissed you! §c❤", titleFadeIn, 20, titleFadeOut); + } + + + if(spawnParticle) + { + sender.spawnParticle(Particle.HEART, nearPlayer.getEyeLocation(), particleCount, 0.3, 0.2, 0.3); + nearPlayer.spawnParticle(Particle.HEART, sender.getEyeLocation(), particleCount, 0.3, 0.2, 0.3); + } + + if(playSound) + { + sender.playSound(sender.getLocation(), Sound.BLOCK_NOTE_BLOCK_PLING, 0.3f, 0.6f); + sender.playSound(sender.getLocation(), Sound.BLOCK_NOTE_BLOCK_PLING, 0.3f, 0.8f); + sender.playSound(sender.getLocation(), Sound.BLOCK_NOTE_BLOCK_PLING, 0.3f, 1f); + + nearPlayer.playSound(nearPlayer.getLocation(), Sound.BLOCK_NOTE_BLOCK_PLING, 0.3f, 0.6f); + nearPlayer.playSound(nearPlayer.getLocation(), Sound.BLOCK_NOTE_BLOCK_PLING, 0.3f, 0.8f); + nearPlayer.playSound(nearPlayer.getLocation(), Sound.BLOCK_NOTE_BLOCK_PLING, 0.3f, 1f); + } + } + +} diff --git a/src/net/mindoverflow/kissplugin/commands/SpookCommand.java b/src/net/mindoverflow/kissplugin/commands/SpookCommand.java new file mode 100644 index 0000000..fd5f868 --- /dev/null +++ b/src/net/mindoverflow/kissplugin/commands/SpookCommand.java @@ -0,0 +1,82 @@ +package net.mindoverflow.kissplugin.commands; + +import net.mindoverflow.kissplugin.Main; +import org.bukkit.Sound; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; + +import java.util.ArrayList; +import java.util.Random; + +public class SpookCommand implements CommandExecutor +{ + + private Main plugin; + public SpookCommand(Main plugin) + { + this.plugin = plugin; + } + ArrayListspookSounds = new ArrayList(){{ + add(Sound.AMBIENT_CAVE); + add(Sound.ENTITY_GENERIC_EXPLODE); + add(Sound.ENTITY_DRAGON_FIREBALL_EXPLODE); + }}; + + ArrayListspookedPlayers = new ArrayList<>(); + + @Override + public boolean onCommand(CommandSender commandSender, Command command, String s, String[] args) { + + if(commandSender instanceof Player) + { + + Player sender = (Player)commandSender; + + + for(Entity e : sender.getNearbyEntities(6, 6, 6)) + { + if(e instanceof Player) + { + Player nearPlayer = (Player)e; + String name = nearPlayer.getName(); + + if(spookedPlayers.contains(name)) + { + sender.sendMessage("§7You already spooked §c" + name + "§7 recently!"); + return true; + } + + spookedPlayers.add(name); + plugin.getServer().getScheduler().runTaskLaterAsynchronously(plugin, ()-> + { + spookedPlayers.remove(name); + }, 1200); + + + nearPlayer.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 40, 1, false, false, false)); + nearPlayer.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, 40, 1, false, false, false)); + nearPlayer.playSound(nearPlayer.getLocation(), getRandomSound(spookSounds), 1, 1); + nearPlayer.sendTitle("§4Boo!", "§cYou got spooked by " + sender.getName() + "!", 0, 60, 10); + nearPlayer.getWorld().strikeLightningEffect(nearPlayer.getLocation()); + + return true; + } + + } + commandSender.sendMessage("§7there is no one to spook around you! =("); + } + + return true; + } + + private Sound getRandomSound(ArrayList list) + { + Random random = new Random(); + return list.get(random.nextInt(list.size())); + } +} diff --git a/src/net/mindoverflow/kissplugin/listeners/CollisionListener.java b/src/net/mindoverflow/kissplugin/listeners/CollisionListener.java new file mode 100644 index 0000000..10025ea --- /dev/null +++ b/src/net/mindoverflow/kissplugin/listeners/CollisionListener.java @@ -0,0 +1,65 @@ +package net.mindoverflow.kissplugin.listeners; + +import net.mindoverflow.kissplugin.Main; +import net.mindoverflow.kissplugin.commands.KissCommand; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.block.Action; +import org.bukkit.event.player.PlayerInteractEntityEvent; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.event.player.PlayerMoveEvent; + +public class CollisionListener implements Listener +{ + private Main plugin; + public CollisionListener(Main plugin) + { + this.plugin = plugin; + } + + /*@EventHandler + public void onPlayerMove(PlayerMoveEvent event) + { + + for(Entity e : event.getPlayer().getNearbyEntities(0.1, 0.1, 0.1)) + { + if(e instanceof Player) + { + /*plugin.getServer().getScheduler().runTaskLater(plugin, ()-> + { + for(Entity newE : event.getPlayer().getNearbyEntities(0.2, 0.2, 0.2)) + { + if(newE instanceof Player && newE.getName().equals(e.getName())) + {*/ + //KissCommand.sendKiss(event.getPlayer(), (Player)e, false, false, true, true, 0, 5, 3); + /* } + } + }, 10);*/ + /*} + } + }*/ + + /*@EventHandler + public void onPlayerMove(PlayerMoveEvent event) + { + for(Entity e : event.getPlayer().getNearbyEntities(0.1, 0.1, 0.1)) + { + if (e instanceof Player) + { + KissCommand.sendKiss(event.getPlayer(), (Player) e, false, false, true, true, 0, 5, 3); + } + } + }*/ + + @EventHandler + public void onPlayerRightClick(PlayerInteractEntityEvent event) + { + if(event.getRightClicked() instanceof Player) + { + KissCommand.sendKiss(event.getPlayer(), (Player)event.getRightClicked(), false, false, true, true, 0, 5, 3); + } + + } +} diff --git a/src/net/mindoverflow/kissplugin/utils/RunningTask.java b/src/net/mindoverflow/kissplugin/utils/RunningTask.java new file mode 100644 index 0000000..e928dad --- /dev/null +++ b/src/net/mindoverflow/kissplugin/utils/RunningTask.java @@ -0,0 +1,47 @@ +package net.mindoverflow.kissplugin.utils; + +import net.mindoverflow.kissplugin.Main; +import net.mindoverflow.kissplugin.commands.AngryCommand; +import org.bukkit.Particle; +import org.bukkit.entity.Player; +import org.bukkit.scheduler.BukkitTask; + +import java.util.HashMap; + +public class RunningTask implements Runnable +{ + + public int multiplier = 2; + + private Main plugin; + public RunningTask(Main plugin) + { + this.plugin = plugin; + } + + // + public HashMapangryPlayers = new HashMap<>(); + + public BukkitTask task; + + @Override + public void run() { + + for(String s : angryPlayers.keySet()) + { + Player p = plugin.getServer().getPlayer(s); + if(angryPlayers.get(s) > 0) + { + p.getWorld().spawnParticle(Particle.VILLAGER_ANGRY, p.getEyeLocation(), 2,0.3, 0.2, 0.3); + + angryPlayers.put(s, angryPlayers.get(s) - 1); + } + else + { + AngryCommand.noLongerAngry(s, plugin); + } + + } + + } +} diff --git a/src/plugin.yml b/src/plugin.yml new file mode 100644 index 0000000..3a50da1 --- /dev/null +++ b/src/plugin.yml @@ -0,0 +1,24 @@ +name: FunPlugin +version: 0.5.0 +author: mind_overflow +main: net.mindoverflow.kissplugin.Main +api-version: 1.15 +commands: + fun: + usage: / + description: Main command for this plugin. Show all the info and usage. + aliases: [info] + kiss: + usage: / + description: Give kisses + aliases: [k] + spook: + usage: / + description: Spook someone! + angry: + usage: /