From 4eb9b097ef4f5bc57cee468ba90aa01cc324fb9c Mon Sep 17 00:00:00 2001 From: XenKys Date: Mon, 1 Jul 2024 15:41:22 +0200 Subject: [PATCH] chore: initial commit --- .gitignore | 113 +++++++++++ README.md | 20 ++ pom.xml | 71 +++++++ .../me/xenkys/curseofvanishing/Broadcast.java | 26 +++ .../curseofvanishing/CurseOfVanishing.java | 19 ++ .../curseofvanishing/VanishCommand.java | 112 +++++++++++ .../xenkys/curseofvanishing/VanishEvents.java | 190 ++++++++++++++++++ .../curseofvanishing/VanishManager.java | 30 +++ .../xenkys/curseofvanishing/VanishPlayer.java | 65 ++++++ src/main/resources/plugin.yml | 11 + 10 files changed, 657 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 pom.xml create mode 100644 src/main/java/me/xenkys/curseofvanishing/Broadcast.java create mode 100644 src/main/java/me/xenkys/curseofvanishing/CurseOfVanishing.java create mode 100644 src/main/java/me/xenkys/curseofvanishing/VanishCommand.java create mode 100644 src/main/java/me/xenkys/curseofvanishing/VanishEvents.java create mode 100644 src/main/java/me/xenkys/curseofvanishing/VanishManager.java create mode 100644 src/main/java/me/xenkys/curseofvanishing/VanishPlayer.java create mode 100644 src/main/resources/plugin.yml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..87d4436 --- /dev/null +++ b/.gitignore @@ -0,0 +1,113 @@ +# User-specific stuff +.idea/ + +*.iml +*.ipr +*.iws + +# IntelliJ +out/ + +# Compiled class file +*.class + +# Log file +*.log + +# BlueJ files +*.ctxt + +# Package Files # +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* + +*~ + +# temporary files which can be created if a process still has a handle open of a deleted file +.fuse_hidden* + +# KDE directory preferences +.directory + +# Linux trash folder which might appear on any partition or disk +.Trash-* + +# .nfs files are created when an open file is removed but is still being accessed +.nfs* + +# General +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +# Windows thumbnail cache files +Thumbs.db +Thumbs.db:encryptable +ehthumbs.db +ehthumbs_vista.db + +# Dump file +*.stackdump + +# Folder config file +[Dd]esktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msix +*.msm +*.msp + +# Windows shortcuts +*.lnk + +target/ + +pom.xml.tag +pom.xml.releaseBackup +pom.xml.versionsBackup +pom.xml.next + +release.properties +dependency-reduced-pom.xml +buildNumber.properties +.mvn/timing.properties +.mvn/wrapper/maven-wrapper.jar +.flattened-pom.xml + +# Common working directory +run/ \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..b145d9d --- /dev/null +++ b/README.md @@ -0,0 +1,20 @@ +# CurseOfVanishing +A Minecraft plugin that allows to be invisible + +⚠ This plugin requires [PaperMC](https://papermc.io/) + +ℹ When a player vanishes it becomes invisible, uncollidable and invulnerable, it can fly even if it isn't in creative or spectator gamemode, it can open chests, shulker boxes and barrels as if it is in spectator gamemode and its messages of join, quit, death and advancement done are visibile in green only by players with the permission `cov.vanish.read`. + +## Commands +/vanish: To vanish yourself + +/vanish : To vanish an other player + +/vanish list: To show the list of vanished players + +## Permissions +`cov.vanish.use`: To use the /vanish command + +`cov.vanish.see`: To see the vanished players + +`cov.vanish.read`: To read the vanish notifications (e.g. Player1234 vanished) \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..ae7d1e3 --- /dev/null +++ b/pom.xml @@ -0,0 +1,71 @@ + + + 4.0.0 + + me.xenkys + CurseOfVanishing + 1.0-SNAPSHOT + jar + + CurseOfVanishing + + + 1.8 + UTF-8 + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + 16 + 16 + + + + org.apache.maven.plugins + maven-shade-plugin + 3.2.4 + + + package + + shade + + + + + + + + src/main/resources + true + + + + + + + papermc-repo + https://repo.papermc.io/repository/maven-public/ + + + sonatype + https://oss.sonatype.org/content/groups/public/ + + + + + + io.papermc.paper + paper-api + 1.21-R0.1-SNAPSHOT + provided + + + diff --git a/src/main/java/me/xenkys/curseofvanishing/Broadcast.java b/src/main/java/me/xenkys/curseofvanishing/Broadcast.java new file mode 100644 index 0000000..0d36749 --- /dev/null +++ b/src/main/java/me/xenkys/curseofvanishing/Broadcast.java @@ -0,0 +1,26 @@ +package me.xenkys.curseofvanishing; + +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.TextColor; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; + +public class Broadcast { + public static void announceSilentMessage(Component message) { + for (Player onlinePlayer : Bukkit.getOnlinePlayers()) { + if (onlinePlayer.hasPermission("cov.vanish.read")) { + onlinePlayer.sendMessage(message.color(TextColor.color(85, 255, 85))); + } + } + } + + public static void announcePlayerVanish(Player player) { + VanishPlayer vanishPlayer = VanishManager.get(player); + + for (Player onlinePlayer : Bukkit.getOnlinePlayers()) { + if (onlinePlayer.hasPermission("cov.vanish.read")) { + onlinePlayer.sendMessage("§a" + player.getName() + (vanishPlayer.isVanished() ? " vanished" : " appeared")); + } + } + } +} diff --git a/src/main/java/me/xenkys/curseofvanishing/CurseOfVanishing.java b/src/main/java/me/xenkys/curseofvanishing/CurseOfVanishing.java new file mode 100644 index 0000000..c7c3ff7 --- /dev/null +++ b/src/main/java/me/xenkys/curseofvanishing/CurseOfVanishing.java @@ -0,0 +1,19 @@ +package me.xenkys.curseofvanishing; + +import org.bukkit.plugin.java.JavaPlugin; + +public final class CurseOfVanishing extends JavaPlugin { + @Override + public void onEnable() { + getCommand("vanish").setExecutor(new VanishCommand()); + + getServer().getPluginManager().registerEvents(new VanishEvents(), this); + + getLogger().info("Enabled"); + } + + @Override + public void onDisable() { + getLogger().info("Disabled"); + } +} diff --git a/src/main/java/me/xenkys/curseofvanishing/VanishCommand.java b/src/main/java/me/xenkys/curseofvanishing/VanishCommand.java new file mode 100644 index 0000000..4705bd7 --- /dev/null +++ b/src/main/java/me/xenkys/curseofvanishing/VanishCommand.java @@ -0,0 +1,112 @@ +package me.xenkys.curseofvanishing; + +import org.bukkit.Bukkit; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.command.ConsoleCommandSender; +import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; + +import java.util.ArrayList; +import java.util.UUID; + +public class VanishCommand implements CommandExecutor { + @Override + public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) { + if (sender instanceof Player player) { + if (args.length == 0) { + VanishPlayer vanishPlayer = VanishManager.get(player); + + vanishPlayer.setVanish(!vanishPlayer.isVanished()); + + Broadcast.announcePlayerVanish(player); + } else if (args[0].equals("list")) { + ArrayList vanishedPlayersUniqueIds = VanishManager.getVanishedPlayersUniqueIds(); + + if (vanishedPlayersUniqueIds.isEmpty()) { + player.sendMessage("§cThere are no vanished players!"); + + return true; + } + + StringBuilder message = new StringBuilder(); + + for (int i = 0; i < vanishedPlayersUniqueIds.size(); i++) { + if (i > 0) { + message.append(", "); + } + + message.append(Bukkit.getOfflinePlayer(vanishedPlayersUniqueIds.get(i)).getName()); + } + + player.sendMessage("§aCurrently vanished players: " + message); + } else { + VanishPlayer target = VanishManager.get(Bukkit.getPlayer(args[0])); + + if (target.getPlayer() == null) { + player.sendMessage("§cThe player " + args[0] + " doesn't exists!"); + + return true; + } + + if (!target.getPlayer().isOnline()) { + player.sendMessage("§c" + target.getPlayer().getName() + " isn't online!"); + + return true; + } + + target.setVanish(!target.isVanished()); + + Broadcast.announcePlayerVanish(target.getPlayer()); + } + } else if (sender instanceof ConsoleCommandSender) { + if (args.length == 0) { + sender.sendMessage("§cYou don't entered the nickname of a player!"); + + return true; + } else if (args[0].equals("list")) { + ArrayList vanishedPlayersUniqueIds = VanishManager.getVanishedPlayersUniqueIds(); + + if (vanishedPlayersUniqueIds.isEmpty()) { + sender.sendMessage("§cThere are no vanished players!"); + + return true; + } + + StringBuilder message = new StringBuilder(); + + for (int i = 0; i < vanishedPlayersUniqueIds.size(); i++) { + if (i > 0) { + message.append(", "); + } + + message.append(Bukkit.getOfflinePlayer(vanishedPlayersUniqueIds.get(i)).getName()); + } + + + sender.sendMessage("§aCurrently vanished players: " + message); + } else { + VanishPlayer target = VanishManager.get(Bukkit.getPlayer(args[0])); + + if (target.getPlayer() == null) { + sender.sendMessage("§cThe player " + args[0] + " doesn't exists!"); + + return true; + } + + if (!target.getPlayer().isOnline()) { + sender.sendMessage("§c" + target.getPlayer().getName() + " isn't online!"); + + return true; + } + + target.setVanish(!target.isVanished()); + + Broadcast.announcePlayerVanish(target.getPlayer()); + } + } + + return true; + } +} \ No newline at end of file diff --git a/src/main/java/me/xenkys/curseofvanishing/VanishEvents.java b/src/main/java/me/xenkys/curseofvanishing/VanishEvents.java new file mode 100644 index 0000000..e17c359 --- /dev/null +++ b/src/main/java/me/xenkys/curseofvanishing/VanishEvents.java @@ -0,0 +1,190 @@ +package me.xenkys.curseofvanishing; + +import net.kyori.adventure.text.Component; +import org.bukkit.Bukkit; +import org.bukkit.GameMode; +import org.bukkit.Material; +import org.bukkit.block.Block; +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.block.BlockReceiveGameEvent; +import org.bukkit.event.entity.*; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.event.inventory.InventoryType; +import org.bukkit.event.player.*; +import org.bukkit.event.raid.RaidTriggerEvent; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.InventoryHolder; + +public class VanishEvents implements Listener { + @EventHandler + public void onEntityTargetLivingEntity(EntityTargetLivingEntityEvent event) { + if (event.getTarget() instanceof Player player) { + VanishPlayer target = VanishManager.get(player); + + if (!target.isVanished()) return; + + event.setCancelled(true); + event.setTarget(null); + } + } + + @EventHandler + public void onFoodLevelChange(FoodLevelChangeEvent event) { + if (event.getEntity() instanceof Player player) { + VanishPlayer vanishPlayer = VanishManager.get(player); + + if (!vanishPlayer.isVanished()) return; + + event.setCancelled(true); + } + } + + @EventHandler + public void onPlayerInteract(PlayerInteractEvent event) { + Player player = event.getPlayer(); + VanishPlayer vanishPlayer = VanishManager.get(player); + + if (!vanishPlayer.isVanished()) return; + + Block clickedBlock = event.getClickedBlock(); + + if (clickedBlock == null) return; + + if (event.getAction() == Action.RIGHT_CLICK_BLOCK) { + if (player.getGameMode() == GameMode.SPECTATOR) return; + + if (player.isSneaking() && !player.getActiveItem().isEmpty() && player.getActiveItem().getType() != Material.AIR) return; + + if (clickedBlock.getType() == Material.ENDER_CHEST) { + event.setCancelled(true); + + player.openInventory(player.getEnderChest()); + } + + if (clickedBlock.getType() == Material.CHEST || clickedBlock.getType() == Material.TRAPPED_CHEST || clickedBlock.getType() == Material.ENDER_CHEST || clickedBlock.getType().toString().endsWith("SHULKER_BOX") || clickedBlock.getType() == Material.BARREL) { + if (clickedBlock.getState() instanceof InventoryHolder inventoryHolder) { + event.setCancelled(true); + + Inventory inventory = inventoryHolder.getInventory(); + Inventory clonedInventory = Bukkit.createInventory(inventoryHolder, inventory.getSize(), inventory.getType().defaultTitle()); + + clonedInventory.setContents(inventory.getContents()); + player.openInventory(clonedInventory); + } + } + } else if (event.getAction() == Action.PHYSICAL) { + if (clickedBlock.getType().toString().endsWith("PRESSURE_PLATE") || clickedBlock.getType().toString().startsWith("TRIPWIRE") || clickedBlock.getType() == Material.FARMLAND || clickedBlock.getType() == Material.TURTLE_EGG || clickedBlock.getType() == Material.BIG_DRIPLEAF || clickedBlock.getType() == Material.SCULK_SENSOR || clickedBlock.getType() == Material.SCULK_SHRIEKER || clickedBlock.getType() == Material.CALIBRATED_SCULK_SENSOR) { + event.setCancelled(true); + } + } + } + + @EventHandler + public void onInventoryClick(InventoryClickEvent event) { + if (event.getWhoClicked() instanceof Player player) { + if (player.getGameMode() == GameMode.SPECTATOR) return; + + VanishPlayer vanishPlayer = VanishManager.get(player); + + if (!vanishPlayer.isVanished()) return; + + Inventory inventory = event.getInventory(); + + if (inventory.getType() == InventoryType.CHEST || inventory.getType() == InventoryType.SHULKER_BOX || inventory.getType() == InventoryType.BARREL) { + event.setCancelled(true); + } + } + } + + @EventHandler + public void onBlockReceiveGame(BlockReceiveGameEvent event) { + if (event.getEntity() instanceof Player player) { + VanishPlayer vanishPlayer = VanishManager.get(player); + + if (!vanishPlayer.isVanished()) return; + + event.setCancelled(true); + } + } + + @EventHandler + public void onRaidTrigger(RaidTriggerEvent event) { + VanishPlayer vanishPlayer = VanishManager.get(event.getPlayer()); + + if (!vanishPlayer.isVanished()) return; + + event.setCancelled(true); + } + + @EventHandler + public void onPlayerJoin(PlayerJoinEvent event) { + VanishPlayer vanishPlayer = VanishManager.get(event.getPlayer()); + + if (!vanishPlayer.isVanished()) return; + + Component message = event.joinMessage(); + + event.joinMessage(null); + + vanishPlayer.vanish(); + + vanishPlayer.setVanishSuperPowers(true); + + Broadcast.announceSilentMessage(message); + } + + @EventHandler + public void onPlayerQuit(PlayerQuitEvent event) { + VanishPlayer vanishPlayer = VanishManager.get(event.getPlayer()); + + if (!vanishPlayer.isVanished()) return; + + Component message = event.quitMessage(); + + event.quitMessage(null); + + vanishPlayer.appear(); + + Broadcast.announceSilentMessage(message); + } + + @EventHandler + public void onPlayerDeath(PlayerDeathEvent event) { + VanishPlayer vanishPlayer = VanishManager.get(event.getEntity()); + + if (!vanishPlayer.isVanished()) return; + + Component message = event.deathMessage(); + + event.deathMessage(null); + + Broadcast.announceSilentMessage(message); + } + + @EventHandler + public void onPlayerAdvancementDone(PlayerAdvancementDoneEvent event) { + VanishPlayer vanishPlayer = VanishManager.get(event.getPlayer()); + + if (!vanishPlayer.isVanished()) return; + + Component message = event.message(); + + if (message == null) return; + + event.message(null); + + Broadcast.announceSilentMessage(message); + } + + @EventHandler + public void onPlayerRespawn(PlayerRespawnEvent event) { + VanishPlayer vanishPlayer = VanishManager.get(event.getPlayer()); + + if (!vanishPlayer.isVanished()) return; + + vanishPlayer.setVanishSuperPowers(true); + } +} \ No newline at end of file diff --git a/src/main/java/me/xenkys/curseofvanishing/VanishManager.java b/src/main/java/me/xenkys/curseofvanishing/VanishManager.java new file mode 100644 index 0000000..a0fc0b0 --- /dev/null +++ b/src/main/java/me/xenkys/curseofvanishing/VanishManager.java @@ -0,0 +1,30 @@ +package me.xenkys.curseofvanishing; + +import org.bukkit.entity.Player; + +import java.util.ArrayList; +import java.util.UUID; + +public class VanishManager { + private static final ArrayList vanishedPlayersUniqueIds = new ArrayList<>(); + + public static ArrayList getVanishedPlayersUniqueIds() { + return vanishedPlayersUniqueIds; + } + + public static VanishPlayer get(Player player) { + return VanishPlayer.from(player); + } + + public static boolean has(Player player) { + return vanishedPlayersUniqueIds.contains(player.getUniqueId()); + } + + public static void add(Player player) { + vanishedPlayersUniqueIds.add(player.getUniqueId()); + } + + public static void remove(Player player) { + vanishedPlayersUniqueIds.remove(player.getUniqueId()); + } +} diff --git a/src/main/java/me/xenkys/curseofvanishing/VanishPlayer.java b/src/main/java/me/xenkys/curseofvanishing/VanishPlayer.java new file mode 100644 index 0000000..4985642 --- /dev/null +++ b/src/main/java/me/xenkys/curseofvanishing/VanishPlayer.java @@ -0,0 +1,65 @@ +package me.xenkys.curseofvanishing; + +import org.bukkit.Bukkit; +import org.bukkit.GameMode; +import org.bukkit.entity.Player; + +public class VanishPlayer { + private final CurseOfVanishing plugin = CurseOfVanishing.getPlugin(CurseOfVanishing.class); + private final Player player; + + private VanishPlayer(Player player) { + this.player = player; + } + + public static VanishPlayer from(Player player) { + return new VanishPlayer(player); + } + + public Player getPlayer() { + return player; + } + + public void setVanishSuperPowers(boolean vanished) { + player.setCollidable(!vanished); + player.setCanPickupItems(!vanished); + player.setInvulnerable(vanished); + player.setAllowFlight(vanished || (player.getGameMode() == GameMode.CREATIVE || player.getGameMode() == GameMode.SPECTATOR)); + } + + public void vanish() { + for (Player onlinePlayer : Bukkit.getOnlinePlayers()) { + if (!onlinePlayer.hasPermission("cov.vanish.see")) { + onlinePlayer.hidePlayer(plugin, player); + } + } + } + + public void appear() { + for (Player onlinePlayer : Bukkit.getOnlinePlayers()) { + if (!onlinePlayer.hasPermission("cov.vanish.see")) { + onlinePlayer.showPlayer(plugin, player); + } + } + } + + public boolean isVanished() { + return VanishManager.has(player); + } + + public void setVanish(boolean enabled) { + if (enabled) { + vanish(); + + setVanishSuperPowers(true); + + VanishManager.add(player); + } else { + appear(); + + setVanishSuperPowers(false); + + VanishManager.remove(player); + } + } +} diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml new file mode 100644 index 0000000..db37367 --- /dev/null +++ b/src/main/resources/plugin.yml @@ -0,0 +1,11 @@ +name: CurseOfVanishing +version: 1.0.0 +main: me.xenkys.curseofvanishing.CurseOfVanishing +api-version: "1.21" +commands: + vanish: + description: Vanish command + usage: / + permission: cov.vanish.use + aliases: + - v \ No newline at end of file