From 83bb7f316d2c9f30e34cc78ea3ed62e3f8fb74ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lorenzo=20Dellac=C3=A0?= Date: Mon, 10 Aug 2020 23:43:02 +0200 Subject: [PATCH] added vanish feature --- .idea/libraries/spigot_1_15_2.xml | 2 +- .idea/workspace.xml | 34 +++++------- src/net/mindoverflow/kissplugin/Main.java | 3 ++ .../kissplugin/commands/SpookCommand.java | 3 +- .../kissplugin/commands/VanishCommand.java | 53 +++++++++++++++++++ .../listeners/PlayerJoinListener.java | 50 +++++++++++++++++ .../kissplugin/utils/MindCache.java | 10 ++++ src/plugin.yml | 6 ++- 8 files changed, 138 insertions(+), 23 deletions(-) create mode 100644 src/net/mindoverflow/kissplugin/commands/VanishCommand.java create mode 100644 src/net/mindoverflow/kissplugin/listeners/PlayerJoinListener.java create mode 100644 src/net/mindoverflow/kissplugin/utils/MindCache.java diff --git a/.idea/libraries/spigot_1_15_2.xml b/.idea/libraries/spigot_1_15_2.xml index c2058b3..88bd44c 100644 --- a/.idea/libraries/spigot_1_15_2.xml +++ b/.idea/libraries/spigot_1_15_2.xml @@ -1,7 +1,7 @@ - + diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 0e72118..10db0ff 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -25,22 +25,13 @@ - - - - - - - - - - - - - + + + + - - + + - - + + + - - + + + + \ No newline at end of file diff --git a/src/net/mindoverflow/kissplugin/Main.java b/src/net/mindoverflow/kissplugin/Main.java index 7c51927..b40e880 100644 --- a/src/net/mindoverflow/kissplugin/Main.java +++ b/src/net/mindoverflow/kissplugin/Main.java @@ -3,6 +3,7 @@ package net.mindoverflow.kissplugin; import net.mindoverflow.kissplugin.commands.*; import net.mindoverflow.kissplugin.listeners.CollisionListener; import net.mindoverflow.kissplugin.listeners.PlayerDeathListener; +import net.mindoverflow.kissplugin.listeners.PlayerJoinListener; import net.mindoverflow.kissplugin.utils.RunningTask; import org.bukkit.plugin.java.JavaPlugin; @@ -26,9 +27,11 @@ public class Main extends JavaPlugin getCommand("kiss").setExecutor(new KissCommand(this)); getCommand("spook").setExecutor(new SpookCommand(this)); getCommand("angry").setExecutor(new AngryCommand(this)); + getCommand("vanish").setExecutor(new VanishCommand()); getServer().getPluginManager().registerEvents(new CollisionListener(this), this); getServer().getPluginManager().registerEvents(new PlayerDeathListener(), this); + getServer().getPluginManager().registerEvents(new PlayerJoinListener(), this); runningTask.task = getServer().getScheduler().runTaskTimer(this, runningTask, 10, 10); } diff --git a/src/net/mindoverflow/kissplugin/commands/SpookCommand.java b/src/net/mindoverflow/kissplugin/commands/SpookCommand.java index fd5f868..3ff81a2 100644 --- a/src/net/mindoverflow/kissplugin/commands/SpookCommand.java +++ b/src/net/mindoverflow/kissplugin/commands/SpookCommand.java @@ -30,7 +30,8 @@ public class SpookCommand implements CommandExecutor ArrayListspookedPlayers = new ArrayList<>(); @Override - public boolean onCommand(CommandSender commandSender, Command command, String s, String[] args) { + public boolean onCommand(CommandSender commandSender, Command command, String s, String[] args) + { if(commandSender instanceof Player) { diff --git a/src/net/mindoverflow/kissplugin/commands/VanishCommand.java b/src/net/mindoverflow/kissplugin/commands/VanishCommand.java new file mode 100644 index 0000000..5cd7228 --- /dev/null +++ b/src/net/mindoverflow/kissplugin/commands/VanishCommand.java @@ -0,0 +1,53 @@ +package net.mindoverflow.kissplugin.commands; + +import net.mindoverflow.kissplugin.utils.MindCache; +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 VanishCommand implements CommandExecutor +{ + + @Override + public boolean onCommand(CommandSender commandSender, Command command, String s, String[] args) + { + if(!commandSender.hasPermission("funplugin.vanish")) + { + commandSender.sendMessage("§cNo permissions!"); + return true; + } + + if(!(commandSender instanceof Player)) + { + commandSender.sendMessage("Only players!"); + return true; + } + + Player player = (Player) commandSender; + String username = player.getName(); + + if(!MindCache.vanishedPlayers.contains(username)) + { + for(Player hideTo : Bukkit.getServer().getOnlinePlayers()) + { + hideTo.hidePlayer(player); + } + + MindCache.vanishedPlayers.add(username); + player.sendMessage("§bHidden to everyone!"); + } + else + { + for(Player showTo : Bukkit.getServer().getOnlinePlayers()) + { + showTo.showPlayer(player); + } + + MindCache.vanishedPlayers.remove(username); + player.sendMessage("§eShown to everyone!"); + } + return true; + } +} diff --git a/src/net/mindoverflow/kissplugin/listeners/PlayerJoinListener.java b/src/net/mindoverflow/kissplugin/listeners/PlayerJoinListener.java new file mode 100644 index 0000000..21fb65b --- /dev/null +++ b/src/net/mindoverflow/kissplugin/listeners/PlayerJoinListener.java @@ -0,0 +1,50 @@ +package net.mindoverflow.kissplugin.listeners; + +import net.mindoverflow.kissplugin.utils.MindCache; +import org.bukkit.Bukkit; +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; + +public class PlayerJoinListener implements Listener +{ + @EventHandler + public void onPlayerJoin(PlayerJoinEvent event) + { + for(String username : MindCache.vanishedPlayers) + { + Player hiddenPlayer = Bukkit.getPlayer(username); + if(hiddenPlayer != null) + { + event.getPlayer().hidePlayer(hiddenPlayer); + } + } + } + + @EventHandler + public void onPlayerQuit(PlayerQuitEvent event) + { + for(String username : MindCache.vanishedPlayers) + { + Player hiddenPlayer = Bukkit.getPlayer(username); + if(hiddenPlayer != null) + { + event.getPlayer().showPlayer(hiddenPlayer); + } + } + + Player player = event.getPlayer(); + String username = player.getName(); + if(MindCache.vanishedPlayers.contains(username)) + { + for(Player onlinePlayer : Bukkit.getServer().getOnlinePlayers()) + { + onlinePlayer.showPlayer(player); + } + } + + MindCache.vanishedPlayers.remove(username); + } +} diff --git a/src/net/mindoverflow/kissplugin/utils/MindCache.java b/src/net/mindoverflow/kissplugin/utils/MindCache.java new file mode 100644 index 0000000..2a2bae2 --- /dev/null +++ b/src/net/mindoverflow/kissplugin/utils/MindCache.java @@ -0,0 +1,10 @@ +package net.mindoverflow.kissplugin.utils; + +import java.util.ArrayList; +import java.util.List; + +public class MindCache +{ + public static List vanishedPlayers = new ArrayList<>(); + +} diff --git a/src/plugin.yml b/src/plugin.yml index 0c34516..4fa1723 100644 --- a/src/plugin.yml +++ b/src/plugin.yml @@ -21,4 +21,8 @@ commands: clearchat: usage: / description: Clear the chat! - aliases: [cc] \ No newline at end of file + aliases: [cc] + vanish: + usage: / + description: Vanish! + aliases: [v, va] \ No newline at end of file