├── .gitignore ├── .gitlab-ci.yml ├── LICENSE ├── README.md ├── pom.xml └── src └── main ├── java └── de │ └── myzelyam │ ├── api │ └── vanish │ │ ├── PlayerHideEvent.java │ │ ├── PlayerShowEvent.java │ │ ├── PlayerVanishStateChangeEvent.java │ │ ├── PostPlayerHideEvent.java │ │ ├── PostPlayerShowEvent.java │ │ └── VanishAPI.java │ └── supervanish │ ├── LayeredPermissionChecker.java │ ├── PlaceholderConverter.java │ ├── SuperVanish.java │ ├── SuperVanishPlugin.java │ ├── VanishPlayer.java │ ├── commands │ ├── CommandAction.java │ ├── Executable.java │ ├── SubCommand.java │ ├── SubCommandMgr.java │ ├── VanishCommand.java │ └── subcommands │ │ ├── BroadcastLogin.java │ │ ├── BroadcastLogout.java │ │ ├── InvalidUsage.java │ │ ├── PrintStacktrace.java │ │ ├── RecreateFiles.java │ │ ├── Reload.java │ │ ├── ShowHelp.java │ │ ├── ToggleItemPickups.java │ │ ├── VanishOther.java │ │ ├── VanishSelf.java │ │ └── VanishedList.java │ ├── config │ ├── ConfigMgr.java │ ├── ConfigurableFile.java │ ├── FileMgr.java │ ├── PluginFile.java │ └── StorageFile.java │ ├── features │ ├── Broadcast.java │ ├── Feature.java │ ├── FeatureMgr.java │ ├── HideAdvancementMessages.java │ ├── NightVision.java │ ├── NoDripLeafTilt.java │ ├── NoMobSpawn.java │ ├── NoPush.java │ ├── NoRaidTrigger.java │ ├── NoSculkSensorDetection.java │ ├── NoTurtleEggBreaking.java │ ├── SilentOpenChest.java │ ├── SilentOpenChestPacketAdapter.java │ └── VanishIndication.java │ ├── hooks │ ├── CitizensHook.java │ ├── DynmapHook.java │ ├── EssentialsHook.java │ ├── InvalidPluginHookException.java │ ├── MVdWPlaceholderAPIHook.java │ ├── PlaceholderAPIHook.java │ ├── PluginHook.java │ ├── PluginHookMgr.java │ └── TrailGUIHook.java │ ├── listeners │ ├── GeneralListener.java │ ├── JoinListener.java │ ├── LoginListener.java │ ├── PlayerBlockModifyListener.java │ ├── QuitListener.java │ ├── TabCompleteListener.java │ └── WorldChangeListener.java │ ├── net │ └── UpdateNotifier.java │ ├── utils │ ├── BukkitPlayerHidingUtil.java │ ├── ExceptionHandler.java │ ├── ExceptionLogger.java │ ├── Requirement.java │ ├── Validation.java │ └── VersionUtil.java │ └── visibility │ ├── ActionBarMgr.java │ ├── FileVanishStateMgr.java │ ├── PaperServerPingListener.java │ ├── ServerListPacketListener.java │ ├── VanishStateMgr.java │ ├── VisibilityChanger.java │ └── hiders │ ├── PlayerHider.java │ ├── PreventionHider.java │ └── modules │ ├── PlayerInfoModule.java │ └── TabCompleteModule.java └── resources ├── config.yml ├── messages.yml └── plugin.yml /.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | target/ 3 | out/ 4 | 5 | # Mobile Tools for Java (J2ME) 6 | .mtj.tmp/ 7 | 8 | # IntelliJ files 9 | .idea/ 10 | *.eml 11 | *.iml 12 | 13 | 14 | # Eclipse files 15 | .settings 16 | 17 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 18 | hs_err_pid* 19 | -------------------------------------------------------------------------------- /.gitlab-ci.yml: -------------------------------------------------------------------------------- 1 | image: maven:3-jdk-9-slim 2 | 3 | cache: 4 | paths: 5 | - .m2/repository 6 | 7 | variables: 8 | MAVEN_OPTS: "-Dmaven.repo.local=.m2/repository -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=WARN -Dorg.slf4j.simpleLogger.showDateTime=true -Djava.awt.headless=true" 9 | MAVEN_CLI_OPTS: "--batch-mode --errors --fail-at-end --show-version -DinstallAtEnd=true -DdeployAtEnd=true" 10 | 11 | stages: 12 | - build 13 | - deploy 14 | 15 | build: 16 | stage: build 17 | script: 18 | - apt update 19 | - apt install wget -y 20 | - wget https://gitlab.com/cubekrowd/mavenrepo/raw/master/build2.sh 21 | - bash build2.sh 22 | artifacts: 23 | paths: 24 | - "*.jar" 25 | 26 | deploy: 27 | stage: deploy 28 | script: 29 | - apt update 30 | - apt install wget -y 31 | - wget https://gitlab.com/cubekrowd/mavenrepo/raw/master/deploy1.sh 32 | - bash deploy1.sh 33 | only: 34 | - master 35 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Leon Mangler 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SuperVanish 2 | Website: https://www.spigotmc.org/resources/supervanish-be-invisible.1331/ 3 | 4 | Bukkit-Plugin for Spigot/CraftBukkit (modded Minecraft server) 5 | 6 | Allows server admins to be completely invisible and undetectable for other players, which helps them with their administrative work. 7 | 8 | Please note that I currently do not have much time to dedicate to this plugin and as such can not do extensive testing of pull requests. I appreciate pull requests, but please keep them as small and simple as possible. Please report issues on SpigotMC via PM! 9 | 10 | ## Maven Repository 11 | ``` 12 | 13 | 14 | jitpack.io 15 | https://jitpack.io 16 | 17 | 18 | 19 | 20 | 21 | 22 | com.github.LeonMangler 23 | SuperVanish 24 | 6.2.18-3 25 | 26 | 27 | ``` 28 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | de.myzelyam 8 | SuperVanish 9 | 6.2.20 10 | 11 | 12 | UTF-8 13 | 14 | 15 | 16 | 17 | 18 | org.apache.maven.plugins 19 | maven-compiler-plugin 20 | 3.8.1 21 | 22 | 17 23 | 17 24 | 25 | 26 | org.projectlombok 27 | lombok 28 | 1.18.30 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | src/main/resources 37 | true 38 | 39 | 40 | 41 | 42 | 43 | 44 | papermc-repo 45 | https://papermc.io/repo/repository/maven-public/ 46 | 47 | 48 | essentials-repo 49 | https://repo.essentialsx.net/releases 50 | 51 | 52 | dmulloy2-repo 53 | https://repo.dmulloy2.net/nexus/repository/public/ 54 | 55 | 56 | jitpack.io 57 | https://jitpack.io 58 | 59 | 60 | citizens-repo 61 | https://repo.citizensnpcs.co/ 62 | 63 | 64 | placeholderapi-repo 65 | https://repo.extendedclip.com/content/repositories/placeholderapi/ 66 | 67 | 68 | dynmap-repo 69 | https://repo.mikeprimm.com/ 70 | 71 | 72 | minecraft-libraries 73 | Minecraft Libraries 74 | https://libraries.minecraft.net 75 | 76 | 77 | mvdw-software-repo 78 | MVdW Public Repositories 79 | https://repo.mvdw-software.com/content/groups/public/ 80 | 81 | 82 | 83 | 84 | 85 | io.papermc.paper 86 | paper-api 87 | 1.20.1-R0.1-SNAPSHOT 88 | provided 89 | 90 | 91 | 92 | org.projectlombok 93 | lombok 94 | 1.18.30 95 | provided 96 | 97 | 98 | 99 | net.essentialsx 100 | EssentialsX 101 | 2.19.0 102 | provided 103 | 104 | 105 | org.bstats 106 | bstats-bukkit 107 | 108 | 109 | 110 | 111 | 112 | com.comphenix.protocol 113 | ProtocolLib 114 | 4.8.0 115 | provided 116 | 117 | 118 | 119 | com.github.MilkBowl 120 | VaultAPI 121 | 1.7.1 122 | provided 123 | 124 | 125 | org.bukkit 126 | bukkit 127 | 128 | 129 | org.bukkit 130 | craftbukkit 131 | 132 | 133 | 134 | 135 | 136 | net.citizensnpcs 137 | citizensapi 138 | 2.0.28-SNAPSHOT 139 | provided 140 | 141 | 142 | 143 | com.github.SinnDevelopment 144 | TrailGUI 145 | 37659dda03 146 | provided 147 | 148 | 149 | 150 | us.dynmap 151 | dynmap-api 152 | 3.1 153 | provided 154 | 155 | 156 | 157 | be.maximvdw 158 | MVdWPlaceholderAPI 159 | 3.1.1-SNAPSHOT 160 | provided 161 | 162 | 163 | org.spigotmc 164 | spigot 165 | 166 | 167 | 168 | 169 | 170 | me.clip 171 | placeholderapi 172 | 2.10.10 173 | provided 174 | 175 | 176 | 177 | com.mojang 178 | brigadier 179 | 1.0.18 180 | 181 | 182 | 183 | -------------------------------------------------------------------------------- /src/main/java/de/myzelyam/api/vanish/PlayerHideEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015, Leon Mangler and the SuperVanish contributors 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | 9 | package de.myzelyam.api.vanish; 10 | 11 | import org.bukkit.entity.Player; 12 | import org.bukkit.event.Cancellable; 13 | import org.bukkit.event.HandlerList; 14 | import org.bukkit.event.player.PlayerEvent; 15 | 16 | public class PlayerHideEvent extends PlayerEvent implements Cancellable { 17 | 18 | private static final HandlerList handlers = new HandlerList(); 19 | private boolean silent; 20 | private boolean isCancelled = false; 21 | 22 | public PlayerHideEvent(Player p, boolean silent) { 23 | super(p); 24 | this.silent = silent; 25 | } 26 | 27 | public static HandlerList getHandlerList() { 28 | return handlers; 29 | } 30 | 31 | public boolean isSilent() { 32 | return silent; 33 | } 34 | 35 | public void setSilent(boolean silent) { 36 | this.silent = silent; 37 | } 38 | 39 | @Override 40 | public boolean isCancelled() { 41 | return isCancelled; 42 | } 43 | 44 | @Override 45 | public void setCancelled(boolean cancel) { 46 | isCancelled = cancel; 47 | } 48 | 49 | @Override 50 | public HandlerList getHandlers() { 51 | return handlers; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/de/myzelyam/api/vanish/PlayerShowEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015, Leon Mangler and the SuperVanish contributors 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | 9 | package de.myzelyam.api.vanish; 10 | 11 | import org.bukkit.entity.Player; 12 | import org.bukkit.event.Cancellable; 13 | import org.bukkit.event.HandlerList; 14 | import org.bukkit.event.player.PlayerEvent; 15 | 16 | public class PlayerShowEvent extends PlayerEvent implements Cancellable { 17 | 18 | private static final HandlerList handlers = new HandlerList(); 19 | private boolean silent; 20 | private boolean isCancelled = false; 21 | 22 | public PlayerShowEvent(Player p, boolean silent) { 23 | super(p); 24 | this.silent = silent; 25 | } 26 | 27 | public static HandlerList getHandlerList() { 28 | return handlers; 29 | } 30 | 31 | public boolean isSilent() { 32 | return silent; 33 | } 34 | 35 | public void setSilent(boolean silent) { 36 | this.silent = silent; 37 | } 38 | 39 | @Override 40 | public boolean isCancelled() { 41 | return isCancelled; 42 | } 43 | 44 | @Override 45 | public void setCancelled(boolean cancel) { 46 | isCancelled = cancel; 47 | } 48 | 49 | @Override 50 | public HandlerList getHandlers() { 51 | return handlers; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/de/myzelyam/api/vanish/PlayerVanishStateChangeEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015, Leon Mangler and the SuperVanish contributors 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | 9 | package de.myzelyam.api.vanish; 10 | 11 | import org.bukkit.event.Cancellable; 12 | import org.bukkit.event.Event; 13 | import org.bukkit.event.HandlerList; 14 | 15 | import java.util.UUID; 16 | 17 | public class PlayerVanishStateChangeEvent extends Event implements Cancellable { 18 | 19 | private static final HandlerList handlers = new HandlerList(); 20 | private final boolean vanishing; 21 | private final UUID uuid; 22 | private final String name; 23 | private final String cause; 24 | 25 | private boolean isCancelled = false; 26 | 27 | public PlayerVanishStateChangeEvent(UUID uuid, String name, boolean vanishing, String cause) { 28 | this.vanishing = vanishing; 29 | this.uuid = uuid; 30 | this.name = name; 31 | this.cause = cause; 32 | } 33 | 34 | public static HandlerList getHandlerList() { 35 | return handlers; 36 | } 37 | 38 | @Override 39 | public boolean isCancelled() { 40 | return isCancelled; 41 | } 42 | 43 | /** 44 | * Cancels the operation, it's recommended to send a message to the cause 45 | */ 46 | @Override 47 | public void setCancelled(boolean cancel) { 48 | isCancelled = cancel; 49 | } 50 | 51 | /** 52 | * @return TRUE if the player is vanishing, FALSE if the player is reappearing 53 | */ 54 | public boolean isVanishing() { 55 | return vanishing; 56 | } 57 | 58 | /** 59 | * @return The name of the player who is vanishing/reappearing 60 | */ 61 | public String getName() { 62 | return name; 63 | } 64 | 65 | /** 66 | * @return The UUID of the player who is vanishing/reappearing 67 | */ 68 | public UUID getUUID() { 69 | return uuid; 70 | } 71 | 72 | /** 73 | * @return The name of the command sender who caused the vanish state change or null if the cause is 74 | * either not specified or it's SuperVanish itself, please note that if this returns 'CONSOLE' then it's 75 | * the console which caused this state change 76 | */ 77 | public String getCause() { 78 | return cause; 79 | } 80 | 81 | @Override 82 | public HandlerList getHandlers() { 83 | return handlers; 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /src/main/java/de/myzelyam/api/vanish/PostPlayerHideEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015, Leon Mangler and the SuperVanish contributors 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | 9 | package de.myzelyam.api.vanish; 10 | 11 | import org.bukkit.entity.Player; 12 | import org.bukkit.event.HandlerList; 13 | import org.bukkit.event.player.PlayerEvent; 14 | 15 | public class PostPlayerHideEvent extends PlayerEvent { 16 | 17 | private static final HandlerList handlers = new HandlerList(); 18 | private final boolean silent; 19 | 20 | public PostPlayerHideEvent(Player p, boolean silent) { 21 | super(p); 22 | this.silent = silent; 23 | } 24 | 25 | public static HandlerList getHandlerList() { 26 | return handlers; 27 | } 28 | 29 | public boolean isSilent() { 30 | return silent; 31 | } 32 | 33 | @Override 34 | public HandlerList getHandlers() { 35 | return handlers; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/de/myzelyam/api/vanish/PostPlayerShowEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015, Leon Mangler and the SuperVanish contributors 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | 9 | package de.myzelyam.api.vanish; 10 | 11 | import org.bukkit.entity.Player; 12 | import org.bukkit.event.HandlerList; 13 | import org.bukkit.event.player.PlayerEvent; 14 | 15 | public class PostPlayerShowEvent extends PlayerEvent { 16 | 17 | private static final HandlerList handlers = new HandlerList(); 18 | private final boolean silent; 19 | 20 | public PostPlayerShowEvent(Player p, boolean silent) { 21 | super(p); 22 | this.silent = silent; 23 | } 24 | 25 | public static HandlerList getHandlerList() { 26 | return handlers; 27 | } 28 | 29 | public boolean isSilent() { 30 | return silent; 31 | } 32 | 33 | @Override 34 | public HandlerList getHandlers() { 35 | return handlers; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/de/myzelyam/api/vanish/VanishAPI.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015, Leon Mangler and the SuperVanish contributors 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | 9 | package de.myzelyam.api.vanish; 10 | 11 | import de.myzelyam.supervanish.SuperVanish; 12 | import de.myzelyam.supervanish.utils.Validation; 13 | 14 | import org.bukkit.configuration.file.FileConfiguration; 15 | import org.bukkit.entity.Player; 16 | 17 | import java.util.ArrayList; 18 | import java.util.List; 19 | import java.util.UUID; 20 | 21 | /** 22 | * Static API for SuperVanish on Bukkit 23 | */ 24 | @SuppressWarnings("unused") 25 | public class VanishAPI { 26 | 27 | private static SuperVanish PLUGIN; 28 | 29 | /** 30 | * @return A collection of the UUIDs of all online vanished players 31 | */ 32 | public static List getInvisiblePlayers() { 33 | return new ArrayList<>(PLUGIN.getVanishStateMgr().getOnlineVanishedPlayers()); 34 | } 35 | 36 | /** 37 | * @return A collection of the UUIDs of all vanished players, both online and offline players 38 | */ 39 | public static List getAllInvisiblePlayers() { 40 | return new ArrayList<>(PLUGIN.getVanishStateMgr().getVanishedPlayers()); 41 | } 42 | 43 | /** 44 | * Player must be online for this to return true if MySQL is enabled 45 | * 46 | * @param p - the player. 47 | * @return TRUE if the player is invisible, FALSE otherwise. 48 | */ 49 | public static boolean isInvisible(Player p) { 50 | Validation.checkNotNull("Player cannot be null!", p); 51 | return PLUGIN.getVanishStateMgr().isVanished(p.getUniqueId()); 52 | } 53 | 54 | /** 55 | * Checks if a player is invisible, online or not 56 | *

57 | * Deprecated: Will cause minor lag if mysql is enabled, use asynchronously or sparingly 58 | * 59 | * @param uuid - the player's UUID. 60 | * @return TRUE if the player is invisible, FALSE otherwise. 61 | */ 62 | public static boolean isInvisibleOffline(UUID uuid) { 63 | Validation.checkNotNull("UUID cannot be null!", uuid); 64 | return PLUGIN.getVanishStateMgr().isVanished(uuid); 65 | } 66 | 67 | /** 68 | * Hides a player using SuperVanish 69 | * 70 | * @param p - the player. 71 | */ 72 | public static void hidePlayer(Player p) { 73 | Validation.checkNotNull("Player cannot be null!", p); 74 | PLUGIN.getVisibilityChanger().hidePlayer(p); 75 | } 76 | 77 | /** 78 | * Shows a player using SuperVanish 79 | * 80 | * @param p - the player. 81 | */ 82 | public static void showPlayer(Player p) { 83 | Validation.checkNotNull("Player cannot be null!", p); 84 | PLUGIN.getVisibilityChanger().showPlayer(p); 85 | } 86 | 87 | /** 88 | * Checks if a player is allowed to see another player 89 | * 90 | * @param viewer - the viewer 91 | * @param viewed - the viewed player 92 | * @return TRUE if viewed is not vanished or viewer has the permission to see viewed 93 | */ 94 | public static boolean canSee(Player viewer, Player viewed) { 95 | return PLUGIN.canSee(viewer, viewed); 96 | } 97 | 98 | public static FileConfiguration getConfiguration() { 99 | return PLUGIN.getSettings(); 100 | } 101 | 102 | public static FileConfiguration getMessages() { 103 | return PLUGIN.getMessages(); 104 | } 105 | 106 | public static FileConfiguration getPlayerData() { 107 | return PLUGIN.getPlayerData(); 108 | } 109 | 110 | public static void reloadConfig() { 111 | PLUGIN.reload(); 112 | } 113 | 114 | public static SuperVanish getPlugin() { 115 | return PLUGIN; 116 | } 117 | 118 | public static void setPlugin(SuperVanish plugin) { 119 | VanishAPI.PLUGIN = plugin; 120 | } 121 | } -------------------------------------------------------------------------------- /src/main/java/de/myzelyam/supervanish/LayeredPermissionChecker.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015, Leon Mangler and the SuperVanish contributors 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | 9 | package de.myzelyam.supervanish; 10 | 11 | import org.bukkit.command.CommandSender; 12 | import org.bukkit.configuration.file.FileConfiguration; 13 | import org.bukkit.entity.Player; 14 | 15 | public class LayeredPermissionChecker { 16 | 17 | private final SuperVanish plugin; 18 | private final FileConfiguration settings; 19 | 20 | public LayeredPermissionChecker(SuperVanish plugin) { 21 | this.plugin = plugin; 22 | settings = plugin.getSettings(); 23 | } 24 | 25 | /** 26 | * @return TRUE if sender has *permission* to use /sv on, else FALSE; TRUE doesn't mean that sender can 27 | * actually use /sv on 28 | */ 29 | public boolean hasPermissionToVanish(CommandSender sender) { 30 | if (settings.getBoolean( 31 | "IndicationFeatures.LayeredPermissions.LayeredSeeAndUsePermissions", false)) { 32 | if (sender.hasPermission("sv.use")) return true; 33 | int permissionLevel; 34 | if (sender instanceof Player) 35 | permissionLevel = plugin.getVanishPlayer((Player) sender).getUsePermissionLevel(); 36 | else permissionLevel = getLayeredPermissionLevel(sender, "use"); 37 | return permissionLevel > 0 && sender.hasPermission("sv.use.level" + permissionLevel); 38 | } else return sender.hasPermission("sv.use"); 39 | } 40 | 41 | public boolean hasPermissionToSee(Player viewer, Player viewed) { 42 | if (viewer == null) 43 | throw new IllegalArgumentException("viewer cannot be null"); 44 | if (viewer == viewed) return true; 45 | if (settings.getBoolean( 46 | "IndicationFeatures.LayeredPermissions.LayeredSeeAndUsePermissions", false)) { 47 | VanishPlayer vanishViewer = plugin.getVanishPlayer(viewer); 48 | VanishPlayer vanishViewed = plugin.getVanishPlayer(viewed); 49 | int viewerLevel = vanishViewer.getSeePermissionLevel(); 50 | if (viewerLevel == 0) return false; 51 | int viewedLevel = Math.max(1, vanishViewed.getUsePermissionLevel()); 52 | return viewerLevel >= viewedLevel; 53 | } else { 54 | boolean enableSeePermission = settings 55 | .getBoolean("IndicationFeatures.LayeredPermissions.EnableSeePermission", true); 56 | return enableSeePermission && viewer.hasPermission("sv.see"); 57 | } 58 | } 59 | 60 | public int getLayeredPermissionLevel(CommandSender sender, String permission) { 61 | boolean enableSeePermission = settings 62 | .getBoolean("IndicationFeatures.LayeredPermissions.EnableSeePermission", true); 63 | if (!enableSeePermission && permission.equalsIgnoreCase("see")) 64 | return 0; 65 | int maxLevel = settings.getInt("IndicationFeatures.LayeredPermissions.MaxLevel", 100); 66 | int level = sender.hasPermission("sv." + permission) ? 1 : 0; 67 | for (int i = 1; i <= maxLevel; i++) 68 | if (sender.hasPermission("sv." + permission + ".level" + i)) 69 | level = i; 70 | return level; 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/main/java/de/myzelyam/supervanish/SuperVanishPlugin.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015, Leon Mangler and the SuperVanish contributors 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | 9 | package de.myzelyam.supervanish; 10 | 11 | import de.myzelyam.supervanish.visibility.VanishStateMgr; 12 | 13 | import java.util.logging.Level; 14 | import java.util.logging.Logger; 15 | 16 | public interface SuperVanishPlugin { 17 | 18 | void log(Level level, String msg); 19 | 20 | void log(Level level, String msg, Throwable ex); 21 | 22 | Logger getLogger(); 23 | 24 | void logException(Throwable e); 25 | 26 | VanishStateMgr getVanishStateMgr(); 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/de/myzelyam/supervanish/VanishPlayer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015, Leon Mangler and the SuperVanish contributors 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | 9 | package de.myzelyam.supervanish; 10 | 11 | import org.bukkit.entity.Player; 12 | 13 | import lombok.Getter; 14 | import lombok.Setter; 15 | 16 | import java.util.Objects; 17 | import java.util.UUID; 18 | 19 | 20 | /** 21 | * Holds additional information about players in the context of vanishing 22 | */ 23 | public class VanishPlayer { 24 | 25 | private final SuperVanish plugin; 26 | @Getter 27 | private final UUID playerUUID; 28 | @Setter 29 | private boolean itemPickUps; 30 | @Getter 31 | private int seePermissionLevel, usePermissionLevel; 32 | 33 | VanishPlayer(Player player, SuperVanish plugin, boolean itemPickUps) { 34 | this.plugin = plugin; 35 | this.playerUUID = player.getUniqueId(); 36 | this.itemPickUps = itemPickUps; 37 | if (plugin.getSettings().getBoolean("IndicationFeatures.LayeredPermissions.LayeredSeeAndUsePermissions", false)) { 38 | seePermissionLevel = plugin.getLayeredPermissionLevel(player, "see"); 39 | usePermissionLevel = plugin.getLayeredPermissionLevel(player, "use"); 40 | } 41 | } 42 | 43 | public boolean isOnlineVanished() { 44 | return plugin.getVanishStateMgr().isVanished(playerUUID); 45 | } 46 | 47 | public boolean hasItemPickUpsEnabled() { 48 | return itemPickUps; 49 | } 50 | 51 | @Override 52 | public boolean equals(Object o) { 53 | if (this == o) return true; 54 | if (o == null || getClass() != o.getClass()) return false; 55 | VanishPlayer that = (VanishPlayer) o; 56 | return Objects.equals(playerUUID, that.playerUUID); 57 | } 58 | 59 | @Override 60 | public int hashCode() { 61 | return Objects.hash(playerUUID); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/main/java/de/myzelyam/supervanish/commands/CommandAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015, Leon Mangler and the SuperVanish contributors 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | 9 | package de.myzelyam.supervanish.commands; 10 | 11 | import de.myzelyam.supervanish.SuperVanish; 12 | import de.myzelyam.supervanish.utils.Validation; 13 | 14 | import org.bukkit.command.CommandSender; 15 | 16 | import java.util.ArrayList; 17 | import java.util.List; 18 | 19 | import lombok.Getter; 20 | import lombok.RequiredArgsConstructor; 21 | 22 | @RequiredArgsConstructor 23 | public enum CommandAction { 24 | VANISH_SELF( 25 | "sv.use", 26 | false, 27 | "/sv [on|off]", 28 | "Toggles your visibility") { 29 | @Override 30 | public boolean checkPermission(CommandSender sender, SuperVanish plugin) { 31 | Validation.checkNotNull(plugin, "plugin cannot be null"); 32 | return plugin.hasPermissionToVanish(sender); 33 | } 34 | }, 35 | VANISH_OTHER( 36 | "sv.others", 37 | true, 38 | "/sv [on|off] ", 39 | "Shows or hides a player"), 40 | VANISHED_LIST( 41 | "sv.list", 42 | true, 43 | "/sv list", 44 | "Shows a list of vanished players"), 45 | BROADCAST_LOGIN( 46 | "sv.login", 47 | false, 48 | "/sv login", 49 | "Broadcasts a fake login message"), 50 | BROADCAST_LOGOUT( 51 | "sv.logout", 52 | false, 53 | "/sv logout", 54 | "Broadcasts a fake logout message"), 55 | TOGGLE_ITEM_PICKUPS( 56 | "sv.toggleitems", 57 | false, 58 | "/sv tipu", 59 | "Toggles picking up items") { 60 | @Override 61 | public boolean checkPermission(CommandSender sender, SuperVanish plugin) { 62 | return sender.hasPermission(getMainPermission()) || sender.hasPermission("sv.toggleitempickups"); 63 | } 64 | }, 65 | RECREATE_FILES( 66 | "sv.recreatefiles", 67 | true, 68 | "/sv recreatefiles", 69 | "Recreates the config") { 70 | @Override 71 | public boolean checkPermission(CommandSender sender, SuperVanish plugin) { 72 | return sender.hasPermission(getMainPermission()) || sender.hasPermission("sv.updatecfg"); 73 | } 74 | }, 75 | RELOAD( 76 | "sv.reload", 77 | true, 78 | "/sv reload", 79 | "Reloads all settings and messages"), 80 | PRINT_STACKTRACE( 81 | "sv.stacktrace", 82 | true, 83 | "/sv stacktrace", 84 | "Logs info for a bug report"), 85 | SHOW_HELP( 86 | "sv.help", 87 | true, 88 | "/sv help", 89 | "Shows this help page"); 90 | 91 | /** 92 | * Use {@link #checkPermission(CommandSender, SuperVanish)} to check whether a {@link CommandSender} has 93 | * permission to perform an action or not 94 | */ 95 | @Getter 96 | private final String mainPermission; 97 | private final boolean console; 98 | @Getter 99 | private final String usage, description; 100 | 101 | static List getAvailableFirstArguments(CommandSender sender, SuperVanish plugin) { 102 | Validation.checkNotNull(plugin, "plugin cannot be null"); 103 | List list = new ArrayList<>(); 104 | if (SHOW_HELP.checkPermission(sender, plugin)) 105 | list.add("help"); 106 | if (RECREATE_FILES.checkPermission(sender, plugin)) 107 | list.add("recreatefiles"); 108 | if (RELOAD.checkPermission(sender, plugin)) 109 | list.add("reload"); 110 | if (VANISHED_LIST.checkPermission(sender, plugin)) 111 | list.add("list"); 112 | if (VANISH_SELF.checkPermission(sender, plugin)) 113 | list.add("on"); 114 | if (VANISH_SELF.checkPermission(sender, plugin)) 115 | list.add("off"); 116 | if (TOGGLE_ITEM_PICKUPS.checkPermission(sender, plugin)) 117 | list.add("tipu"); 118 | if (PRINT_STACKTRACE.checkPermission(sender, plugin)) 119 | list.add("stacktrace"); 120 | return list; 121 | } 122 | 123 | public static boolean hasAnyCmdPermission(CommandSender sender, SuperVanish plugin) { 124 | for (CommandAction action : CommandAction.values()) 125 | if (action.checkPermission(sender, plugin)) 126 | return true; 127 | return false; 128 | } 129 | 130 | public boolean checkPermission(CommandSender sender, SuperVanish plugin) { 131 | return sender.hasPermission(getMainPermission()); 132 | } 133 | 134 | public boolean usableByConsole() { 135 | return console; 136 | } 137 | } -------------------------------------------------------------------------------- /src/main/java/de/myzelyam/supervanish/commands/Executable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015, Leon Mangler and the SuperVanish contributors 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | 9 | package de.myzelyam.supervanish.commands; 10 | 11 | import org.bukkit.command.Command; 12 | import org.bukkit.command.CommandSender; 13 | 14 | public interface Executable { 15 | 16 | void execute(Command cmd, CommandSender sender, String[] args, String label); 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/de/myzelyam/supervanish/commands/SubCommand.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015, Leon Mangler and the SuperVanish contributors 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | 9 | package de.myzelyam.supervanish.commands; 10 | 11 | import de.myzelyam.supervanish.SuperVanish; 12 | 13 | import org.bukkit.command.CommandSender; 14 | import org.bukkit.entity.Player; 15 | 16 | import java.util.Collection; 17 | import java.util.UUID; 18 | 19 | public abstract class SubCommand implements Executable { 20 | 21 | protected final SuperVanish plugin; 22 | 23 | public SubCommand(SuperVanish plugin) { 24 | this.plugin = plugin; 25 | } 26 | 27 | protected Collection getAllVanishedPlayers() { 28 | return plugin.getVanishStateMgr().getVanishedPlayers(); 29 | } 30 | 31 | protected Collection getOnlineVanishedPlayers() { 32 | return plugin.getVanishStateMgr().getOnlineVanishedPlayers(); 33 | } 34 | 35 | public void hidePlayer(Player player) { 36 | plugin.getVisibilityChanger().hidePlayer(player); 37 | } 38 | 39 | public void showPlayer(Player player) { 40 | plugin.getVisibilityChanger().showPlayer(player); 41 | } 42 | 43 | 44 | public boolean isVanished(UUID uuid) { 45 | return plugin.getVanishStateMgr().isVanished(uuid); 46 | } 47 | 48 | public boolean canDo(CommandSender sender, CommandAction action, boolean sendErrors) { 49 | if (!(sender instanceof Player)) 50 | if (!action.usableByConsole()) { 51 | if (sendErrors) 52 | plugin.sendMessage(sender, "InvalidSender", sender); 53 | return false; 54 | } 55 | if (!action.checkPermission(sender, plugin)) { 56 | if (sendErrors) 57 | plugin.sendMessage(sender, "NoPermission", sender); 58 | return false; 59 | } 60 | return true; 61 | } 62 | } -------------------------------------------------------------------------------- /src/main/java/de/myzelyam/supervanish/commands/VanishCommand.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015, Leon Mangler and the SuperVanish contributors 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | 9 | package de.myzelyam.supervanish.commands; 10 | 11 | import de.myzelyam.supervanish.SuperVanish; 12 | 13 | import org.bukkit.command.Command; 14 | import org.bukkit.command.CommandSender; 15 | 16 | import java.util.List; 17 | 18 | public class VanishCommand { 19 | 20 | private final SuperVanish plugin; 21 | private final SubCommandMgr subCommandMgr; 22 | 23 | public VanishCommand(SuperVanish plugin) { 24 | this.plugin = plugin; 25 | subCommandMgr = new SubCommandMgr(plugin); 26 | } 27 | 28 | public void execute(Command command, CommandSender sender, String commandLabel, String[] args) { 29 | subCommandMgr.execute(command, sender, args, commandLabel); 30 | } 31 | 32 | public List tabComplete(Command command, CommandSender sender, String alias, String[] args) 33 | throws IllegalArgumentException { 34 | return subCommandMgr.onTabComplete(command, sender, alias, args); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/de/myzelyam/supervanish/commands/subcommands/BroadcastLogin.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015, Leon Mangler and the SuperVanish contributors 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | 9 | package de.myzelyam.supervanish.commands.subcommands; 10 | 11 | import de.myzelyam.supervanish.SuperVanish; 12 | import de.myzelyam.supervanish.commands.CommandAction; 13 | import de.myzelyam.supervanish.commands.SubCommand; 14 | 15 | import org.bukkit.Bukkit; 16 | import org.bukkit.command.Command; 17 | import org.bukkit.command.CommandSender; 18 | import org.bukkit.entity.Player; 19 | 20 | public class BroadcastLogin extends SubCommand { 21 | 22 | public BroadcastLogin(SuperVanish plugin) { 23 | super(plugin); 24 | } 25 | 26 | @Override 27 | public void execute(Command cmd, CommandSender p, String[] args, String label) { 28 | if (canDo(p, CommandAction.BROADCAST_LOGIN, true)) { 29 | for (Player onlinePlayer : Bukkit.getOnlinePlayers()) 30 | plugin.sendMessage(onlinePlayer, "ReappearMessage", p, onlinePlayer); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/de/myzelyam/supervanish/commands/subcommands/BroadcastLogout.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015, Leon Mangler and the SuperVanish contributors 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | 9 | package de.myzelyam.supervanish.commands.subcommands; 10 | 11 | import de.myzelyam.supervanish.SuperVanish; 12 | import de.myzelyam.supervanish.commands.CommandAction; 13 | import de.myzelyam.supervanish.commands.SubCommand; 14 | 15 | import org.bukkit.Bukkit; 16 | import org.bukkit.command.Command; 17 | import org.bukkit.command.CommandSender; 18 | import org.bukkit.entity.Player; 19 | 20 | public class BroadcastLogout extends SubCommand { 21 | 22 | public BroadcastLogout(SuperVanish plugin) { 23 | super(plugin); 24 | } 25 | 26 | @Override 27 | public void execute(Command cmd, CommandSender p, String[] args, String label) { 28 | if (canDo(p, CommandAction.BROADCAST_LOGOUT, true)) { 29 | for (Player onlinePlayer : Bukkit.getOnlinePlayers()) 30 | plugin.sendMessage(onlinePlayer, "VanishMessage", p, onlinePlayer); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/de/myzelyam/supervanish/commands/subcommands/InvalidUsage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015, Leon Mangler and the SuperVanish contributors 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | 9 | package de.myzelyam.supervanish.commands.subcommands; 10 | 11 | import de.myzelyam.supervanish.SuperVanish; 12 | import de.myzelyam.supervanish.commands.CommandAction; 13 | import de.myzelyam.supervanish.commands.SubCommand; 14 | 15 | import org.bukkit.command.Command; 16 | import org.bukkit.command.CommandSender; 17 | 18 | public class InvalidUsage extends SubCommand { 19 | 20 | public InvalidUsage(SuperVanish plugin) { 21 | super(plugin); 22 | } 23 | 24 | @Override 25 | public void execute(Command cmd, CommandSender sender, String[] args, String label) { 26 | if (!CommandAction.hasAnyCmdPermission(sender, plugin)) { 27 | plugin.sendMessage(sender, "NoPermission", sender); 28 | return; 29 | } 30 | plugin.sendMessage(sender, "InvalidUsage", sender); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/de/myzelyam/supervanish/commands/subcommands/PrintStacktrace.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015, Leon Mangler and the SuperVanish contributors 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | 9 | package de.myzelyam.supervanish.commands.subcommands; 10 | 11 | import de.myzelyam.supervanish.SuperVanish; 12 | import de.myzelyam.supervanish.commands.CommandAction; 13 | import de.myzelyam.supervanish.commands.SubCommand; 14 | 15 | import org.bukkit.command.Command; 16 | import org.bukkit.command.CommandSender; 17 | 18 | public class PrintStacktrace extends SubCommand { 19 | 20 | public PrintStacktrace(SuperVanish plugin) { 21 | super(plugin); 22 | } 23 | 24 | @Override 25 | public void execute(Command cmd, CommandSender sender, String[] args, String label) { 26 | if (canDo(sender, CommandAction.PRINT_STACKTRACE, true)) { 27 | plugin.sendMessage(sender, "PrintedStacktrace", sender); 28 | plugin.logException(null); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/de/myzelyam/supervanish/commands/subcommands/RecreateFiles.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015, Leon Mangler and the SuperVanish contributors 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | 9 | package de.myzelyam.supervanish.commands.subcommands; 10 | 11 | import de.myzelyam.supervanish.SuperVanish; 12 | import de.myzelyam.supervanish.commands.CommandAction; 13 | import de.myzelyam.supervanish.commands.SubCommand; 14 | 15 | import org.bukkit.ChatColor; 16 | import org.bukkit.command.Command; 17 | import org.bukkit.command.CommandSender; 18 | import org.bukkit.entity.Player; 19 | 20 | import java.io.File; 21 | 22 | public class RecreateFiles extends SubCommand { 23 | 24 | public RecreateFiles(SuperVanish plugin) { 25 | super(plugin); 26 | } 27 | 28 | @Override 29 | public void execute(Command cmd, CommandSender p, String[] args, String label) { 30 | if (canDo(p, CommandAction.RECREATE_FILES, true)) { 31 | String updates; 32 | String changes; 33 | if (plugin.getConfigMgr().isSettingsUpdateRequired() 34 | && plugin.getConfigMgr().isMessagesUpdateRequired()) { 35 | updates = "the config and the messages file"; 36 | changes = "all settings and messages"; 37 | } else if (plugin.getConfigMgr().isSettingsUpdateRequired()) { 38 | updates = "the config"; 39 | changes = "all settings"; 40 | } else { 41 | updates = "the messages file"; 42 | changes = "all messages"; 43 | } 44 | if (args.length != 2) { 45 | if (!plugin.getConfigMgr().isSettingsUpdateRequired() 46 | && !plugin.getConfigMgr().isMessagesUpdateRequired()) { 47 | plugin.sendMessage(p, "NoConfigUpdateAvailable", p); 48 | return; 49 | } 50 | plugin.sendMessage(p, plugin.getMessage("UpdateWarning").replace("%changes%", changes) 51 | .replace("%updates%", updates), p); 52 | return; 53 | } 54 | if (args[1].equalsIgnoreCase("confirm") || args[1].equalsIgnoreCase("force")) { 55 | if (!plugin.getConfigMgr().isSettingsUpdateRequired() 56 | && !plugin.getConfigMgr().isMessagesUpdateRequired() 57 | && !args[1].equalsIgnoreCase("force")) { 58 | plugin.sendMessage(p, "NoConfigUpdateAvailable", p); 59 | return; 60 | } 61 | if (args[1].equalsIgnoreCase("force")) { 62 | updates = "the config and the messages file"; 63 | changes = "all settings and messages"; 64 | } 65 | // delete necessary files 66 | boolean success = false; 67 | if (plugin.getConfigMgr().isSettingsUpdateRequired() 68 | || args[1].equalsIgnoreCase("force")) { 69 | File file = new File(plugin.getDataFolder().getPath() + File.separator + "config.yml"); 70 | success = file.delete(); 71 | plugin.getConfigMgr().getSettingsFile().save(); 72 | plugin.getConfigMgr().getSettingsFile().reload(); 73 | plugin.getConfigMgr().setSettings(plugin.getConfigMgr().getSettingsFile().getConfig()); 74 | } 75 | if (plugin.getConfigMgr().isMessagesUpdateRequired() 76 | || args[1].equalsIgnoreCase("force")) { 77 | File file2 = new File(plugin.getDataFolder().getPath() + File.separator + "messages.yml"); 78 | success &= file2.delete(); 79 | plugin.getConfigMgr().getMessagesFile().save(); 80 | plugin.getConfigMgr().getMessagesFile().reload(); 81 | plugin.getConfigMgr().setMessages(plugin.getConfigMgr().getMessagesFile().getConfig()); 82 | 83 | } 84 | if (!success) { 85 | p.sendMessage(ChatColor.RED + 86 | "Cannot update config, failed to delete file. Are the file permissions valid?"); 87 | return; 88 | } 89 | plugin.sendMessage(p, plugin.getMessage("RecreatedConfig") 90 | .replace("%changes%", changes) 91 | .replace("%updates%", updates), p); 92 | // update update-information 93 | plugin.getConfigMgr().checkFilesForLeftOvers(); 94 | } else if (args[1].equalsIgnoreCase("dismiss")) { 95 | String currentVersion = plugin.getDescription().getVersion(); 96 | boolean isDismissed = 97 | plugin.getPlayerData().getBoolean("PlayerData." + (p instanceof Player ? ((Player) p) 98 | .getUniqueId() 99 | .toString() : "CONSOLE") + ".dismissed." + currentVersion.replace(".", "_"), false); 100 | plugin.getPlayerData().set("PlayerData." + (p instanceof Player ? ((Player) p).getUniqueId().toString() 101 | : "CONSOLE") + ".dismissed." + currentVersion.replace(".", "_"), !isDismissed); 102 | plugin.getConfigMgr().getPlayerDataFile().save(); 103 | if (!isDismissed) 104 | plugin.sendMessage(p, "DismissedRecreationWarning", p); 105 | else 106 | plugin.sendMessage(p, "UndismissedRecreationWarning", p); 107 | } 108 | } 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /src/main/java/de/myzelyam/supervanish/commands/subcommands/Reload.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015, Leon Mangler and the SuperVanish contributors 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | 9 | package de.myzelyam.supervanish.commands.subcommands; 10 | 11 | import de.myzelyam.supervanish.SuperVanish; 12 | import de.myzelyam.supervanish.commands.CommandAction; 13 | import de.myzelyam.supervanish.commands.SubCommand; 14 | 15 | import org.bukkit.Bukkit; 16 | import org.bukkit.ChatColor; 17 | import org.bukkit.command.Command; 18 | import org.bukkit.command.CommandSender; 19 | 20 | public class Reload extends SubCommand { 21 | 22 | public Reload(SuperVanish plugin) { 23 | super(plugin); 24 | } 25 | 26 | @Override 27 | public void execute(Command cmd, CommandSender p, String[] args, String label) { 28 | if (canDo(p, CommandAction.RELOAD, true)) { 29 | long before = System.currentTimeMillis(); 30 | plugin.reload(); 31 | if (!Bukkit.getPluginManager().isPluginEnabled(plugin)) { 32 | p.sendMessage(ChatColor.RED + 33 | "Failed to reload SuperVanish since it failed to restart itself. " + 34 | "More information is in the console. (" 35 | + (System.currentTimeMillis() - before) + "ms)"); 36 | return; 37 | } 38 | plugin.sendMessage(p, plugin.getMessage("PluginReloaded").replace("%time%", 39 | (System.currentTimeMillis() - before) + ""), p); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/de/myzelyam/supervanish/commands/subcommands/ShowHelp.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015, Leon Mangler and the SuperVanish contributors 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * license, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | 9 | package de.myzelyam.supervanish.commands.subcommands; 10 | 11 | 12 | import de.myzelyam.supervanish.SuperVanish; 13 | import de.myzelyam.supervanish.commands.CommandAction; 14 | import de.myzelyam.supervanish.commands.SubCommand; 15 | 16 | import org.bukkit.command.Command; 17 | import org.bukkit.command.CommandSender; 18 | 19 | public class ShowHelp extends SubCommand { 20 | 21 | public ShowHelp(SuperVanish plugin) { 22 | super(plugin); 23 | } 24 | 25 | @Override 26 | public void execute(Command cmd, CommandSender sender, String[] args, String label) { 27 | if (canDo(sender, CommandAction.SHOW_HELP, true)) { 28 | plugin.sendMessage(sender, "HelpHeader", sender); 29 | for (CommandAction action : CommandAction.values()) { 30 | if (canDo(sender, action, false)) { 31 | plugin.sendMessage(sender, plugin.getMessage("HelpFormat") 32 | .replace("%usage%", action.getUsage()) 33 | .replace("%description%", action.getDescription()) 34 | .replace("%permission%", action.getMainPermission()), sender); 35 | } 36 | } 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/de/myzelyam/supervanish/commands/subcommands/ToggleItemPickups.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015, Leon Mangler and the SuperVanish contributors 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | 9 | package de.myzelyam.supervanish.commands.subcommands; 10 | 11 | import de.myzelyam.supervanish.SuperVanish; 12 | import de.myzelyam.supervanish.VanishPlayer; 13 | import de.myzelyam.supervanish.commands.CommandAction; 14 | import de.myzelyam.supervanish.commands.SubCommand; 15 | 16 | import org.bukkit.command.Command; 17 | import org.bukkit.command.CommandSender; 18 | import org.bukkit.entity.Player; 19 | 20 | public class ToggleItemPickups extends SubCommand { 21 | 22 | public ToggleItemPickups(SuperVanish plugin) { 23 | super(plugin); 24 | } 25 | 26 | @Override 27 | public void execute(Command cmd, CommandSender sender, String[] args, String label) { 28 | if (canDo(sender, CommandAction.TOGGLE_ITEM_PICKUPS, true)) { 29 | Player p = (Player) sender; 30 | plugin.sendMessage(p, plugin.getMessage("ToggledPickingUpItems" 31 | + (toggleState(plugin.getVanishPlayer(p)) ? "On" : "Off")), p); 32 | } 33 | } 34 | 35 | private boolean toggleState(VanishPlayer vp) { 36 | boolean hasEnabled = plugin.getPlayerData().getBoolean("PlayerData." 37 | + vp.getPlayerUUID() + ".itemPickUps"); 38 | plugin.getPlayerData().set("PlayerData." + vp.getPlayerUUID() + ".itemPickUps", !hasEnabled); 39 | vp.setItemPickUps(!hasEnabled); 40 | plugin.getConfigMgr().getPlayerDataFile().save(); 41 | return !hasEnabled; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/de/myzelyam/supervanish/commands/subcommands/VanishOther.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015, Leon Mangler and the SuperVanish contributors 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | 9 | package de.myzelyam.supervanish.commands.subcommands; 10 | 11 | import de.myzelyam.supervanish.SuperVanish; 12 | import de.myzelyam.supervanish.commands.CommandAction; 13 | import de.myzelyam.supervanish.commands.SubCommand; 14 | 15 | import org.bukkit.Bukkit; 16 | import org.bukkit.command.Command; 17 | import org.bukkit.command.CommandSender; 18 | import org.bukkit.entity.Player; 19 | 20 | import java.util.UUID; 21 | 22 | public class VanishOther extends SubCommand { 23 | 24 | private Player specifiedPlayer; 25 | 26 | public VanishOther(SuperVanish plugin) { 27 | this(null, plugin); 28 | } 29 | 30 | public VanishOther(Player specifiedPlayer, SuperVanish plugin) { 31 | super(plugin); 32 | this.specifiedPlayer = specifiedPlayer; 33 | } 34 | 35 | @Override 36 | public void execute(Command cmd, CommandSender sender, String[] args, String label) { 37 | if (canDo(sender, CommandAction.VANISH_OTHER, true)) { 38 | boolean hide = false, offline = false, silent = false; 39 | Player target; 40 | String name; 41 | UUID uuid; 42 | if (specifiedPlayer == null) { 43 | if (args[0].equalsIgnoreCase("on") || args[0].equalsIgnoreCase("enable") 44 | || args[0].equalsIgnoreCase("vanish")) 45 | hide = true; 46 | target = Bukkit.getPlayer(args[1]); 47 | name = target == null ? args[1] : target.getName(); 48 | } else { 49 | target = specifiedPlayer; 50 | name = specifiedPlayer.getName(); 51 | hide = !isVanished(target.getUniqueId()); 52 | } 53 | if (target == null) { 54 | offline = true; 55 | uuid = plugin.getVanishStateMgr().getVanishedUUIDFromNameOnFile(name); 56 | if (uuid == null) { 57 | plugin.sendMessage(sender, "PlayerNonExistent", sender, name); 58 | return; 59 | } 60 | } else { 61 | name = target.getName(); 62 | uuid = target.getUniqueId(); 63 | } 64 | if (!offline && sender instanceof Player && sender != target 65 | && target.hasPermission("sv.notoggle")) { 66 | plugin.sendMessage(sender, "CannotHideOtherPlayer", sender, name); 67 | return; 68 | } 69 | if (plugin.getSettings().getBoolean( 70 | "IndicationFeatures.LayeredPermissions.HideInvisibleInCommands", false) && target != null 71 | && sender instanceof Player && !plugin.hasPermissionToSee((Player) sender, target)) { 72 | plugin.sendMessage(sender, "PlayerNonExistent", sender, name); 73 | return; 74 | } 75 | if (hide && (offline ? isVanished(uuid) : isVanished(uuid))) { 76 | plugin.sendMessage(sender, "AlreadyInvisibleMessage", sender, name); 77 | return; 78 | } else if (!hide && !(offline ? isVanished(uuid) : isVanished(uuid))) { 79 | plugin.sendMessage(sender, "AlreadyVisibleMessage", sender, name); 80 | return; 81 | } 82 | if (args.length == 3) 83 | silent = args[2].equalsIgnoreCase("-s"); 84 | else if (args.length == 2) 85 | silent = args[1].equalsIgnoreCase("-s"); 86 | if (!offline) { 87 | if (hide) { 88 | plugin.getVisibilityChanger().hidePlayer(target, sender.getName(), silent); 89 | plugin.sendMessage(sender, "HideOtherMessage", sender, name); 90 | } else { 91 | plugin.getVisibilityChanger().showPlayer(target, sender.getName()); 92 | plugin.sendMessage(sender, "ShowOtherMessage", sender, name, silent); 93 | } 94 | } else { 95 | if (hide) { 96 | plugin.getVanishStateMgr().setVanishedState(uuid, name, true, sender.getName()); 97 | plugin.sendMessage(sender, "HideOtherMessage", sender, name); 98 | } else { 99 | plugin.getVanishStateMgr().setVanishedState(uuid, name, false, sender.getName()); 100 | plugin.sendMessage(sender, "ShowOtherMessage", sender, name); 101 | } 102 | } 103 | } 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /src/main/java/de/myzelyam/supervanish/commands/subcommands/VanishSelf.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015, Leon Mangler and the SuperVanish contributors 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | 9 | package de.myzelyam.supervanish.commands.subcommands; 10 | 11 | import de.myzelyam.supervanish.SuperVanish; 12 | import de.myzelyam.supervanish.commands.CommandAction; 13 | import de.myzelyam.supervanish.commands.SubCommand; 14 | 15 | import org.bukkit.command.Command; 16 | import org.bukkit.command.CommandSender; 17 | import org.bukkit.entity.Player; 18 | 19 | public class VanishSelf extends SubCommand { 20 | 21 | public VanishSelf(SuperVanish plugin) { 22 | super(plugin); 23 | } 24 | 25 | @Override 26 | public void execute(Command cmd, CommandSender s, String[] args, String label) { 27 | if (canDo(s, CommandAction.VANISH_SELF, true)) { 28 | Player p = (Player) s; 29 | if (args.length == 0) { 30 | if (isVanished(p.getUniqueId())) 31 | showPlayer(p); 32 | else 33 | hidePlayer(p); 34 | } else if (args.length == 1) { 35 | if (args[0].equalsIgnoreCase("off") 36 | || args[0].equalsIgnoreCase("reappear") 37 | || args[0].equalsIgnoreCase("disable")) { 38 | if (!isVanished(p.getUniqueId())) { 39 | plugin.sendMessage(p, "NotVanishedError", p); 40 | return; 41 | } 42 | showPlayer(p); 43 | } else if (args[0].equalsIgnoreCase("-s")) { 44 | if (isVanished(p.getUniqueId())) 45 | plugin.getVisibilityChanger().showPlayer(p, null, true); 46 | else 47 | plugin.getVisibilityChanger().hidePlayer(p, null, true); 48 | } else { 49 | if (isVanished(p.getUniqueId())) { 50 | plugin.sendMessage(p, "AlreadyVanishedError", p); 51 | return; 52 | } 53 | hidePlayer(p); 54 | } 55 | } 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/de/myzelyam/supervanish/commands/subcommands/VanishedList.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015, Leon Mangler and the SuperVanish contributors 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | 9 | package de.myzelyam.supervanish.commands.subcommands; 10 | 11 | import com.google.common.collect.ImmutableList; 12 | 13 | import de.myzelyam.supervanish.SuperVanish; 14 | import de.myzelyam.supervanish.commands.CommandAction; 15 | import de.myzelyam.supervanish.commands.SubCommand; 16 | 17 | import org.bukkit.Bukkit; 18 | import org.bukkit.ChatColor; 19 | import org.bukkit.command.Command; 20 | import org.bukkit.command.CommandSender; 21 | 22 | import java.util.List; 23 | import java.util.UUID; 24 | 25 | public class VanishedList extends SubCommand { 26 | 27 | public VanishedList(SuperVanish plugin) { 28 | super(plugin); 29 | } 30 | 31 | @Override 32 | public void execute(Command cmd, final CommandSender sender, final String[] args, String label) { 33 | if (canDo(sender, CommandAction.VANISHED_LIST, true)) { 34 | String listMessage = plugin.getMessage("ListMessagePrefix"); 35 | StringBuilder stringBuilder = new StringBuilder(); 36 | List allInvisiblePlayerUUIDs = ImmutableList.copyOf(getAllVanishedPlayers()); 37 | if (allInvisiblePlayerUUIDs.isEmpty()) { 38 | stringBuilder.append("none"); 39 | } 40 | for (int i = 0; i < allInvisiblePlayerUUIDs.size(); i++) { 41 | UUID playerUUID = allInvisiblePlayerUUIDs.get(i); 42 | String name = Bukkit.getOfflinePlayer(playerUUID).getName(); 43 | if (Bukkit.getPlayer(playerUUID) == null) { 44 | name = name + ChatColor.RED + "[offline]" + ChatColor.WHITE; 45 | } 46 | stringBuilder.append(name); 47 | if (i != allInvisiblePlayerUUIDs.size() - 1) { 48 | stringBuilder.append(ChatColor.GREEN).append(", ").append(ChatColor.WHITE); 49 | } 50 | } 51 | listMessage = listMessage.replace("%l", stringBuilder.toString()); 52 | plugin.sendMessage(sender, listMessage, sender); 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/de/myzelyam/supervanish/config/ConfigMgr.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015, Leon Mangler and the SuperVanish contributors 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | 9 | package de.myzelyam.supervanish.config; 10 | 11 | import de.myzelyam.supervanish.SuperVanish; 12 | 13 | import org.bukkit.Bukkit; 14 | import org.bukkit.ChatColor; 15 | import org.bukkit.configuration.file.FileConfiguration; 16 | 17 | import java.util.Collections; 18 | import java.util.logging.Level; 19 | 20 | import lombok.Data; 21 | 22 | import static de.myzelyam.supervanish.SuperVanish.*; 23 | 24 | @Data 25 | public class ConfigMgr { 26 | 27 | private final SuperVanish plugin; 28 | private final FileMgr fileMgr; 29 | private boolean settingsUpdateRequired, messagesUpdateRequired; 30 | private FileConfiguration settings, messages, playerData; 31 | private ConfigurableFile messagesFile, settingsFile; 32 | private StorageFile playerDataFile; 33 | 34 | public ConfigMgr(SuperVanish plugin) { 35 | this.plugin = plugin; 36 | fileMgr = new FileMgr(plugin); 37 | } 38 | 39 | public void prepareFiles() { 40 | // messages 41 | messagesFile = (ConfigurableFile) fileMgr.addFile("messages", FileMgr.FileType.CONFIG); 42 | messages = messagesFile.getConfig(); 43 | // settings 44 | settingsFile = (ConfigurableFile) fileMgr.addFile("config", FileMgr.FileType.CONFIG); 45 | settings = settingsFile.getConfig(); 46 | // data 47 | playerDataFile = (StorageFile) fileMgr.addFile("data", FileMgr.FileType.STORAGE); 48 | playerData = playerDataFile.getConfig(); 49 | playerData.addDefault("InvisiblePlayers", Collections.emptyList()); 50 | playerData.options().copyDefaults(true); 51 | playerData.options().header("SuperVanish v" + plugin.getDescription().getVersion() + " - Data file"); 52 | playerDataFile.save(); 53 | 54 | checkFilesForLeftOvers(); 55 | } 56 | 57 | public void checkFilesForLeftOvers() { 58 | try { 59 | String currentSettingsVersion = settings.getString("ConfigVersion"); 60 | String newestVersion = plugin.getDescription().getVersion(); 61 | String currentMessagesVersion = messages.getString("MessagesVersion"); 62 | messagesUpdateRequired = fileRequiresRecreation(currentMessagesVersion, false); 63 | settingsUpdateRequired = fileRequiresRecreation(currentSettingsVersion, true); 64 | if (newestVersion.equals(currentSettingsVersion)) 65 | settingsUpdateRequired = false; 66 | if (newestVersion.equals(currentMessagesVersion)) 67 | messagesUpdateRequired = false; 68 | if (settingsUpdateRequired || messagesUpdateRequired) { 69 | String currentVersion = plugin.getDescription().getVersion(); 70 | boolean isDismissed = playerData.getBoolean("PlayerData.CONSOLE.dismissed." 71 | + currentVersion.replace(".", "_"), false); 72 | if (!isDismissed) plugin.log(Level.WARNING, "At least one config file is outdated, " + 73 | "it's recommended to regenerate it using '/sv recreatefiles'"); 74 | } 75 | if (currentSettingsVersion.startsWith("1.5.") || currentSettingsVersion.startsWith("1.4.")) { 76 | Bukkit.getConsoleSender().sendMessage(ChatColor.YELLOW + "You have a very outdated " + 77 | "config file, your settings will not work until you regenerate your SV-files " + 78 | "using /sv recreatefiles"); 79 | } 80 | } catch (Exception e) { 81 | plugin.logException(e); 82 | } 83 | } 84 | 85 | private boolean fileRequiresRecreation(String currentVersion, boolean isSettingsFile) { 86 | if (currentVersion == null) return true; 87 | for (String ignoredVersion : isSettingsFile ? NON_REQUIRED_SETTINGS_UPDATES 88 | : NON_REQUIRED_MESSAGES_UPDATES) { 89 | if (currentVersion.equalsIgnoreCase(ignoredVersion)) return false; 90 | } 91 | return true; 92 | } 93 | 94 | public FileMgr getFileMgr() { 95 | return fileMgr; 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /src/main/java/de/myzelyam/supervanish/config/ConfigurableFile.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015, Leon Mangler and the SuperVanish contributors 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | 9 | package de.myzelyam.supervanish.config; 10 | 11 | import de.myzelyam.supervanish.SuperVanish; 12 | 13 | import org.bukkit.configuration.file.FileConfiguration; 14 | import org.bukkit.configuration.file.YamlConfiguration; 15 | 16 | import java.io.File; 17 | import java.io.IOException; 18 | import java.io.InputStreamReader; 19 | import java.io.Reader; 20 | 21 | public class ConfigurableFile implements PluginFile { 22 | 23 | private final SuperVanish plugin; 24 | private String name; 25 | private File file; 26 | private FileConfiguration fileConfiguration; 27 | private FileConfiguration defaultFileConfiguration; 28 | 29 | public ConfigurableFile(String name, SuperVanish plugin) { 30 | this.name = name + ".yml"; 31 | this.plugin = plugin; 32 | setup(); 33 | } 34 | 35 | @Override 36 | public String getName() { 37 | return name; 38 | } 39 | 40 | private void setup() { 41 | file = new File(plugin.getDataFolder(), name); 42 | try (Reader reader = new InputStreamReader(plugin.getResource(name))) { 43 | defaultFileConfiguration = YamlConfiguration.loadConfiguration(reader); 44 | } catch (IOException e) { 45 | e.printStackTrace(); 46 | } 47 | save(); 48 | } 49 | 50 | @Override 51 | public void reload() { 52 | fileConfiguration = YamlConfiguration.loadConfiguration(file); 53 | } 54 | 55 | @Override 56 | public FileConfiguration getConfig() { 57 | if (fileConfiguration == null) { 58 | reload(); 59 | } 60 | return fileConfiguration; 61 | } 62 | 63 | @Override 64 | public void save() { 65 | if (!file.exists()) { 66 | plugin.saveResource(name, false); 67 | } 68 | } 69 | 70 | public FileConfiguration getDefaultConfig() { 71 | return defaultFileConfiguration; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/main/java/de/myzelyam/supervanish/config/FileMgr.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015, Leon Mangler and the SuperVanish contributors 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | 9 | package de.myzelyam.supervanish.config; 10 | 11 | import de.myzelyam.supervanish.SuperVanish; 12 | import de.myzelyam.supervanish.SuperVanishPlugin; 13 | 14 | import java.util.HashMap; 15 | import java.util.Map; 16 | 17 | public class FileMgr { 18 | 19 | private final SuperVanishPlugin plugin; 20 | private Map> files; 21 | 22 | public FileMgr(SuperVanishPlugin plugin) { 23 | this.plugin = plugin; 24 | files = new HashMap<>(); 25 | } 26 | 27 | public PluginFile addFile(String name, FileType type) { 28 | if (name == null) 29 | throw new IllegalArgumentException("The file name cannot be null!"); 30 | if (type == FileType.STORAGE) { 31 | StorageFile file = new StorageFile(name, (SuperVanish) plugin); 32 | files.put(name, file); 33 | return file; 34 | } else if (type == FileType.CONFIG) { 35 | ConfigurableFile file = new ConfigurableFile(name, (SuperVanish) plugin); 36 | files.put(name, file); 37 | return file; 38 | } else { 39 | throw new IllegalArgumentException("The FileType cannot be null!"); 40 | } 41 | } 42 | 43 | public void reloadFile(String fileName) { 44 | PluginFile file = files.get(fileName); 45 | if (file != null) 46 | file.reload(); 47 | else 48 | throw new IllegalArgumentException("Specified file doesn't exist!"); 49 | } 50 | 51 | public void reloadAll() { 52 | for (String fileName : files.keySet()) 53 | reloadFile(fileName); 54 | } 55 | 56 | public enum FileType { 57 | STORAGE, CONFIG 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/de/myzelyam/supervanish/config/PluginFile.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015, Leon Mangler and the SuperVanish contributors 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | 9 | package de.myzelyam.supervanish.config; 10 | 11 | public interface PluginFile { 12 | 13 | String getName(); 14 | 15 | void reload(); 16 | 17 | CT getConfig(); 18 | 19 | void save(); 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/de/myzelyam/supervanish/config/StorageFile.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015, Leon Mangler and the SuperVanish contributors 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | 9 | package de.myzelyam.supervanish.config; 10 | 11 | import de.myzelyam.supervanish.SuperVanish; 12 | 13 | import org.bukkit.configuration.file.FileConfiguration; 14 | import org.bukkit.configuration.file.YamlConfiguration; 15 | 16 | import java.io.File; 17 | import java.io.IOException; 18 | 19 | public class StorageFile implements PluginFile { 20 | 21 | private final SuperVanish plugin; 22 | private String name; 23 | private File file; 24 | private FileConfiguration config; 25 | 26 | public StorageFile(String name, SuperVanish plugin) { 27 | this.name = name; 28 | this.plugin = plugin; 29 | setup(); 30 | } 31 | 32 | @Override 33 | public String getName() { 34 | return name; 35 | } 36 | 37 | private void setup() { 38 | file = new File(plugin.getDataFolder().getPath() + File.separator 39 | + name + ".yml"); 40 | config = YamlConfiguration.loadConfiguration(file); 41 | save(); 42 | } 43 | 44 | @Override 45 | public void reload() { 46 | setup(); 47 | } 48 | 49 | @Override 50 | public FileConfiguration getConfig() { 51 | return config; 52 | } 53 | 54 | @Override 55 | public void save() { 56 | try { 57 | config.save(file); 58 | } catch (IOException e) { 59 | e.printStackTrace(); 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/main/java/de/myzelyam/supervanish/features/Broadcast.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015, Leon Mangler and the SuperVanish contributors 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | 9 | package de.myzelyam.supervanish.features; 10 | 11 | import de.myzelyam.api.vanish.PlayerShowEvent; 12 | import de.myzelyam.api.vanish.PostPlayerHideEvent; 13 | import de.myzelyam.supervanish.SuperVanish; 14 | import org.bukkit.Bukkit; 15 | import org.bukkit.entity.Player; 16 | import org.bukkit.event.EventHandler; 17 | import org.bukkit.event.EventPriority; 18 | 19 | public class Broadcast extends Feature { 20 | 21 | public Broadcast(SuperVanish plugin) { 22 | super(plugin); 23 | } 24 | 25 | public static void announceSilentJoin(Player vanished, SuperVanish plugin) { 26 | if (plugin.getSettings().getBoolean("MessageOptions.AnnounceRealJoinQuitToAdmins", true)) { 27 | for (Player onlinePlayer : Bukkit.getOnlinePlayers()) { 28 | if (vanished == onlinePlayer) 29 | continue; 30 | if (plugin.canSee(onlinePlayer, vanished)) { 31 | plugin.sendMessage(onlinePlayer, "SilentJoinMessageForAdmins", vanished, onlinePlayer); 32 | } 33 | } 34 | } 35 | } 36 | 37 | public static void announceSilentDeath(Player p, SuperVanish plugin, String deathMessage) { 38 | if (plugin.getSettings().getBoolean("MessageOptions.AnnounceDeathToAdmins", true)) { 39 | for (Player onlinePlayer : Bukkit.getOnlinePlayers()) { 40 | if (p == onlinePlayer) 41 | continue; 42 | if (plugin.canSee(onlinePlayer, p)) { 43 | String message = plugin.getMessage("SilentDeathMessage") 44 | .replace("%deathmsg%", deathMessage); 45 | plugin.sendMessage(onlinePlayer, message, p, onlinePlayer); 46 | } 47 | } 48 | } 49 | } 50 | 51 | public static void announceSilentQuit(Player p, SuperVanish plugin) { 52 | if (plugin.getSettings().getBoolean("MessageOptions.AnnounceRealJoinQuitToAdmins", true)) { 53 | for (Player onlinePlayer : Bukkit.getOnlinePlayers()) { 54 | if (p == onlinePlayer) 55 | continue; 56 | if (plugin.canSee(onlinePlayer, p)) { 57 | plugin.sendMessage(onlinePlayer, "SilentQuitMessageForAdmins", p, onlinePlayer); 58 | } 59 | } 60 | } 61 | } 62 | 63 | @Override 64 | public boolean isActive() { 65 | return plugin.getSettings().getBoolean("MessageOptions.FakeJoinQuitMessages.BroadcastFakeQuitOnVanish") 66 | || plugin.getSettings().getBoolean("MessageOptions.FakeJoinQuitMessages" + 67 | ".BroadcastFakeQuitOnReappear"); 68 | } 69 | 70 | @EventHandler 71 | public void onVanish(PostPlayerHideEvent e) { 72 | final Player p = e.getPlayer(); 73 | if (plugin.getSettings().getBoolean("MessageOptions.FakeJoinQuitMessages.BroadcastFakeQuitOnVanish") 74 | && !e.isSilent()) { 75 | for (Player onlinePlayer : Bukkit.getOnlinePlayers()) { 76 | if (!plugin.canSee(onlinePlayer, p)) { 77 | if (!plugin.getSettings().getBoolean( 78 | "MessageOptions.FakeJoinQuitMessages.SendMessageOnlyToAdmins")) 79 | plugin.sendMessage(onlinePlayer, "VanishMessage", p, onlinePlayer); 80 | } else if (!plugin.getSettings().getBoolean( 81 | "MessageOptions.FakeJoinQuitMessages.SendMessageOnlyToUsers")) 82 | if (!plugin.getSettings().getBoolean( 83 | "MessageOptions.FakeJoinQuitMessages.AnnounceVanishReappearToAdmins")) 84 | plugin.sendMessage(onlinePlayer, "VanishMessage", p, onlinePlayer); 85 | else if (onlinePlayer == p && !plugin.getSettings().getBoolean( 86 | "MessageOptions.FakeJoinQuitMessages.SendMessageOnlyToAdmins")) 87 | plugin.sendMessage(onlinePlayer, "VanishMessage", p, onlinePlayer); 88 | else if (onlinePlayer != p) 89 | plugin.sendMessage(onlinePlayer, "VanishMessageWithPermission", p, onlinePlayer); 90 | } 91 | } 92 | } 93 | 94 | @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) 95 | public void onReappear(PlayerShowEvent e) { 96 | Player p = e.getPlayer(); 97 | if (plugin.getSettings().getBoolean( 98 | "MessageOptions.FakeJoinQuitMessages.BroadcastFakeJoinOnReappear") && !e.isSilent()) { 99 | for (Player onlinePlayer : Bukkit.getOnlinePlayers()) { 100 | if (!plugin.canSee(onlinePlayer, p)) { 101 | if (!plugin.getSettings().getBoolean( 102 | "MessageOptions.FakeJoinQuitMessages.SendMessageOnlyToAdmins")) 103 | plugin.sendMessage(onlinePlayer, "ReappearMessage", p, onlinePlayer); 104 | } else if (!plugin.getSettings().getBoolean( 105 | "MessageOptions.FakeJoinQuitMessages.SendMessageOnlyToUsers")) 106 | if (!plugin.getSettings().getBoolean( 107 | "MessageOptions.FakeJoinQuitMessages.AnnounceVanishReappearToAdmins")) 108 | plugin.sendMessage(onlinePlayer, "ReappearMessageWithPermission", p, onlinePlayer); 109 | else if (onlinePlayer == p && !plugin.getSettings().getBoolean( 110 | "MessageOptions.FakeJoinQuitMessages.SendMessageOnlyToAdmins")) 111 | plugin.sendMessage(onlinePlayer, "ReappearMessage", p, onlinePlayer); 112 | else if (onlinePlayer != p) 113 | plugin.sendMessage(onlinePlayer, "ReappearMessageWithPermission", p, onlinePlayer); 114 | } 115 | } 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /src/main/java/de/myzelyam/supervanish/features/Feature.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015, Leon Mangler and the SuperVanish contributors 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | 9 | package de.myzelyam.supervanish.features; 10 | 11 | import de.myzelyam.supervanish.SuperVanish; 12 | 13 | import org.bukkit.event.Listener; 14 | 15 | /** 16 | * Represents a toggleable feature of SuperVanish 17 | */ 18 | public abstract class Feature implements Listener { 19 | 20 | protected final SuperVanish plugin; 21 | 22 | public Feature(SuperVanish plugin) { 23 | this.plugin = plugin; 24 | } 25 | 26 | public void onEnable() { 27 | } 28 | 29 | public void onDisable() { 30 | } 31 | 32 | public abstract boolean isActive(); 33 | 34 | protected void delay(Runnable runnable) { 35 | plugin.getServer().getScheduler().runTaskLater(plugin, runnable, 1); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/de/myzelyam/supervanish/features/FeatureMgr.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015, Leon Mangler and the SuperVanish contributors 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | 9 | package de.myzelyam.supervanish.features; 10 | 11 | import de.myzelyam.supervanish.SuperVanish; 12 | import de.myzelyam.supervanish.utils.Requirement; 13 | 14 | import org.bukkit.Bukkit; 15 | import org.bukkit.event.HandlerList; 16 | 17 | import java.lang.reflect.InvocationTargetException; 18 | import java.util.Arrays; 19 | import java.util.Collection; 20 | import java.util.Collections; 21 | import java.util.HashMap; 22 | import java.util.HashSet; 23 | import java.util.Map; 24 | import java.util.Set; 25 | 26 | import lombok.Data; 27 | 28 | public class FeatureMgr { 29 | 30 | private static final Requirement protocolLibInstalled = featureInfo -> Bukkit.getPluginManager().isPluginEnabled("ProtocolLib"), 31 | oneDotEightOrHigher = featureInfo -> featureInfo.getPlugin().getVersionUtil().isOneDotXOrHigher(8), 32 | oneDotSeventeenOrHigher = featureInfo -> featureInfo.getPlugin().getVersionUtil().isOneDotXOrHigher(17), 33 | supportedServer = featureInfo -> Bukkit.getServer().getName().equals("Paper") || Bukkit.getServer().getName().equals("Purpur"); 34 | private final Map registeredFeatures = new HashMap<>(); 35 | private final Set activeFeatures = new HashSet<>(); 36 | private final SuperVanish plugin; 37 | 38 | public FeatureMgr(SuperVanish plugin) { 39 | this.plugin = plugin; 40 | registeredFeatures.put("SilentOpenChest", new FeatureInfo(SilentOpenChest.class, plugin, 41 | Arrays.asList(protocolLibInstalled, oneDotEightOrHigher))); 42 | registeredFeatures.put("NightVision", new FeatureInfo(NightVision.class, plugin, 43 | Arrays.asList(protocolLibInstalled, oneDotEightOrHigher))); 44 | registeredFeatures.put("VanishIndication", new FeatureInfo(VanishIndication.class, plugin, 45 | Arrays.asList(protocolLibInstalled, oneDotEightOrHigher))); 46 | registeredFeatures.put("Broadcast", new FeatureInfo(Broadcast.class, plugin)); 47 | registeredFeatures.put("NoSculkSensorDetection", new FeatureInfo(NoSculkSensorDetection.class, plugin, 48 | Collections.singletonList(oneDotSeventeenOrHigher))); 49 | registeredFeatures.put("NoTurtleEggBreaking", new FeatureInfo(NoTurtleEggBreaking.class, plugin, 50 | Collections.singletonList(oneDotSeventeenOrHigher))); 51 | registeredFeatures.put("NoDripLeafTilt", new FeatureInfo(NoDripLeafTilt.class, plugin, 52 | Collections.singletonList(oneDotSeventeenOrHigher))); 53 | registeredFeatures.put("NoRaidTrigger", new FeatureInfo(NoRaidTrigger.class, plugin, 54 | Collections.singletonList(oneDotSeventeenOrHigher))); 55 | registeredFeatures.put("NoMobSpawn", new FeatureInfo(NoMobSpawn.class, plugin, 56 | Collections.singletonList(supportedServer))); 57 | registeredFeatures.put("HideAdvancementMessages", new FeatureInfo(HideAdvancementMessages.class, plugin, 58 | Collections.singletonList(supportedServer))); 59 | } 60 | 61 | public void enableFeatures() { 62 | featureLoop: 63 | for (String id : registeredFeatures.keySet()) { 64 | FeatureInfo featureInfo = registeredFeatures.get(id); 65 | for (Requirement requirement : featureInfo.getRequirements()) { 66 | if (!requirement.fulfilledBy(featureInfo)) continue featureLoop; 67 | } 68 | Feature feature; 69 | try { 70 | feature = featureInfo.getFeatureClass().getConstructor(SuperVanish.class).newInstance(plugin); 71 | } catch (NoSuchMethodException | InvocationTargetException 72 | | InstantiationException | IllegalAccessException e) { 73 | plugin.logException(e); 74 | continue; 75 | } 76 | if (!feature.isActive()) continue; 77 | activeFeatures.add(feature); 78 | Bukkit.getPluginManager().registerEvents(feature, plugin); 79 | feature.onEnable(); 80 | } 81 | } 82 | 83 | public void disableFeatures() { 84 | for (Feature feature : activeFeatures) { 85 | feature.onDisable(); 86 | HandlerList.unregisterAll(feature); 87 | } 88 | activeFeatures.clear(); 89 | } 90 | 91 | public T getFeature(Class featureClass) { 92 | for (Feature feature : activeFeatures) { 93 | if (feature.getClass().equals(featureClass)) { 94 | //noinspection unchecked 95 | return (T) feature; 96 | } 97 | } 98 | return null; 99 | } 100 | 101 | public Set getActiveFeatures() { 102 | return activeFeatures; 103 | } 104 | 105 | @Data 106 | private static class FeatureInfo { 107 | private final Class featureClass; 108 | private final Collection> requirements; 109 | private final SuperVanish plugin; 110 | 111 | FeatureInfo(Class featureClass, SuperVanish plugin, 112 | Collection> requirements) { 113 | this.featureClass = featureClass; 114 | this.requirements = requirements; 115 | this.plugin = plugin; 116 | } 117 | 118 | FeatureInfo(Class featureClass, SuperVanish plugin) { 119 | this(featureClass, plugin, Collections.emptySet()); 120 | } 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /src/main/java/de/myzelyam/supervanish/features/HideAdvancementMessages.java: -------------------------------------------------------------------------------- 1 | package de.myzelyam.supervanish.features; 2 | 3 | import de.myzelyam.supervanish.SuperVanish; 4 | import net.kyori.adventure.text.Component; 5 | import org.bukkit.entity.Player; 6 | import org.bukkit.event.EventHandler; 7 | import org.bukkit.event.player.PlayerAdvancementDoneEvent; 8 | 9 | // This feature is paper-only because the PlayerAdvancementDoneEvent#message() method doesn't exist in Spigot 10 | public class HideAdvancementMessages extends Feature { 11 | 12 | private boolean suppressErrors = false; 13 | 14 | public HideAdvancementMessages(SuperVanish plugin) { 15 | super(plugin); 16 | } 17 | 18 | @EventHandler 19 | public void onAdvancementDone(PlayerAdvancementDoneEvent e) { 20 | try { 21 | Player p = e.getPlayer(); 22 | Component message = e.message(); 23 | if (message == null) return; 24 | if (!plugin.getVanishStateMgr().isVanished(p.getUniqueId())) return; 25 | if (e.message() == null) return; 26 | e.message(null); 27 | p.sendMessage(message); 28 | } catch (Exception er) { 29 | if (!suppressErrors) { 30 | plugin.logException(er); 31 | suppressErrors = true; 32 | } 33 | } 34 | } 35 | 36 | @Override 37 | public boolean isActive() { 38 | return plugin.getSettings().getBoolean("MessageOptions.HideAdvancementMessages", true); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/de/myzelyam/supervanish/features/NightVision.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015, Leon Mangler and the SuperVanish contributors 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | 9 | package de.myzelyam.supervanish.features; 10 | 11 | import de.myzelyam.api.vanish.PlayerHideEvent; 12 | import de.myzelyam.api.vanish.PlayerShowEvent; 13 | import de.myzelyam.supervanish.SuperVanish; 14 | import org.bukkit.Bukkit; 15 | import org.bukkit.entity.Player; 16 | import org.bukkit.event.EventHandler; 17 | import org.bukkit.event.EventPriority; 18 | import org.bukkit.event.player.PlayerChangedWorldEvent; 19 | import org.bukkit.event.player.PlayerJoinEvent; 20 | import org.bukkit.event.player.PlayerQuitEvent; 21 | import org.bukkit.event.player.PlayerTeleportEvent; 22 | import org.bukkit.potion.PotionEffect; 23 | import org.bukkit.potion.PotionEffectType; 24 | 25 | import java.util.HashMap; 26 | import java.util.Map; 27 | import java.util.UUID; 28 | 29 | public class NightVision extends Feature implements Runnable { 30 | 31 | public static final int INFINITE_POTION_EFFECT_LENGTH = 32767; 32 | 33 | private final Map playerPreviousPotionEffectMap = new HashMap<>(); 34 | 35 | public NightVision(SuperVanish plugin) { 36 | super(plugin); 37 | } 38 | 39 | @Override 40 | public void onEnable() { 41 | plugin.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, this, 20 * 60 * 2, 20 * 60 * 2); 42 | } 43 | 44 | @Override 45 | public boolean isActive() { 46 | return plugin.getSettings().getBoolean("InvisibilityFeatures.NightVisionEffect"); 47 | } 48 | 49 | @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) 50 | public void onVanish(PlayerHideEvent e) { 51 | Player p = e.getPlayer(); 52 | // getPotionEffect(..) is 1.10+ API 53 | if (plugin.getVersionUtil().isOneDotXOrHigher(10)) { 54 | if (p.getPotionEffect(PotionEffectType.NIGHT_VISION) != null) { 55 | playerPreviousPotionEffectMap.put(p.getUniqueId(), p.getPotionEffect(PotionEffectType.NIGHT_VISION)); 56 | } 57 | } 58 | sendAddPotionEffect(p); 59 | } 60 | 61 | @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) 62 | public void onReappear(PlayerShowEvent e) { 63 | Player p = e.getPlayer(); 64 | sendRemovePotionEffect(p); 65 | if (playerPreviousPotionEffectMap.containsKey(p.getUniqueId())) { 66 | p.addPotionEffect(playerPreviousPotionEffectMap.remove(p.getUniqueId())); 67 | } 68 | } 69 | 70 | @EventHandler 71 | public void onJoin(PlayerJoinEvent e) { 72 | Player p = e.getPlayer(); 73 | if (!plugin.getVanishStateMgr().isVanished(p.getUniqueId())) { 74 | if (playerPreviousPotionEffectMap.containsKey(p.getUniqueId())) { 75 | p.addPotionEffect(playerPreviousPotionEffectMap.remove(p.getUniqueId())); 76 | } 77 | } else { 78 | sendAddPotionEffect(p); 79 | } 80 | } 81 | 82 | @EventHandler 83 | public void onQuit(PlayerQuitEvent e) { 84 | Player p = e.getPlayer(); 85 | if (!plugin.getVanishStateMgr().isVanished(p.getUniqueId())) 86 | return; 87 | sendRemovePotionEffect(p); 88 | } 89 | 90 | @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) 91 | public void onTeleport(PlayerTeleportEvent e) { 92 | Player p = e.getPlayer(); 93 | if (!plugin.getVanishStateMgr().isVanished(p.getUniqueId())) 94 | return; 95 | if (e.getFrom().getWorld() == null || e.getTo() == null || e.getTo().getWorld() == null 96 | || e.getFrom().getWorld().getName().equals(e.getTo().getWorld().getName())) return; 97 | sendRemovePotionEffect(p); 98 | } 99 | 100 | @EventHandler 101 | public void onWorldChange(PlayerChangedWorldEvent e) { 102 | Player p = e.getPlayer(); 103 | if (!plugin.getVanishStateMgr().isVanished(p.getUniqueId())) 104 | return; 105 | sendAddPotionEffect(p); 106 | } 107 | 108 | @Override 109 | public void run() { 110 | // renew every now and then to prevent blinking bug 111 | for (UUID uuid : plugin.getVanishStateMgr().getOnlineVanishedPlayers()) { 112 | Player p = Bukkit.getPlayer(uuid); 113 | if (p == null) continue; 114 | sendRemovePotionEffect(p); 115 | sendAddPotionEffect(p); 116 | } 117 | } 118 | 119 | private void sendAddPotionEffect(Player p) { 120 | p.addPotionEffect(new PotionEffect(PotionEffectType.NIGHT_VISION, 121 | INFINITE_POTION_EFFECT_LENGTH, 0, true, false)); 122 | } 123 | 124 | private void sendRemovePotionEffect(Player p) { 125 | p.removePotionEffect(PotionEffectType.NIGHT_VISION); 126 | } 127 | } 128 | -------------------------------------------------------------------------------- /src/main/java/de/myzelyam/supervanish/features/NoDripLeafTilt.java: -------------------------------------------------------------------------------- 1 | package de.myzelyam.supervanish.features; 2 | 3 | import de.myzelyam.supervanish.SuperVanish; 4 | import org.bukkit.entity.Player; 5 | import org.bukkit.event.EventHandler; 6 | import org.bukkit.event.EventPriority; 7 | import org.bukkit.event.block.Action; 8 | import org.bukkit.event.player.PlayerInteractEvent; 9 | 10 | public class NoDripLeafTilt extends Feature { 11 | 12 | public NoDripLeafTilt(SuperVanish plugin) { 13 | super(plugin); 14 | } 15 | 16 | @EventHandler(priority = EventPriority.HIGH) 17 | public void onInteract(PlayerInteractEvent e) { 18 | Player p = e.getPlayer(); 19 | if (!plugin.getVanishStateMgr().isVanished(p.getUniqueId())) return; 20 | if (!e.getAction().equals(Action.PHYSICAL) || e.getClickedBlock() == null 21 | || !e.getClickedBlock().getType().toString().equals("BIG_DRIPLEAF")) 22 | return; 23 | e.setCancelled(true); 24 | } 25 | 26 | 27 | @Override 28 | public boolean isActive() { 29 | return plugin.getSettings().getBoolean("InvisibilityFeatures.DisableDripLeaf", true); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/de/myzelyam/supervanish/features/NoMobSpawn.java: -------------------------------------------------------------------------------- 1 | package de.myzelyam.supervanish.features; 2 | 3 | import com.destroystokyo.paper.event.entity.PlayerNaturallySpawnCreaturesEvent; 4 | import com.destroystokyo.paper.event.entity.PreSpawnerSpawnEvent; 5 | import com.destroystokyo.paper.event.entity.SkeletonHorseTrapEvent; 6 | import de.myzelyam.supervanish.SuperVanish; 7 | import org.bukkit.Bukkit; 8 | import org.bukkit.GameMode; 9 | import org.bukkit.entity.HumanEntity; 10 | import org.bukkit.entity.Player; 11 | import org.bukkit.event.EventHandler; 12 | 13 | import java.util.List; 14 | import java.util.UUID; 15 | 16 | public class NoMobSpawn extends Feature { 17 | 18 | private boolean suppressErrors = false; 19 | 20 | public NoMobSpawn(SuperVanish plugin) { 21 | super(plugin); 22 | } 23 | 24 | @EventHandler 25 | public void onSkeletonHorseTrap(SkeletonHorseTrapEvent e) { 26 | try { 27 | List humans = e.getEligibleHumans(); 28 | int humansCount = humans.size(); 29 | for (HumanEntity human : humans) { 30 | if (human instanceof Player) { 31 | Player p = (Player) human; 32 | if (plugin.getVanishStateMgr().isVanished(p.getUniqueId())) { 33 | humansCount--; 34 | } 35 | } 36 | } 37 | if (humansCount == 0) 38 | e.setCancelled(true); 39 | } catch (Exception er) { 40 | if (!suppressErrors) { 41 | plugin.logException(er); 42 | suppressErrors = true; 43 | } 44 | } 45 | } 46 | 47 | @EventHandler 48 | public void onEntitySpawn(PlayerNaturallySpawnCreaturesEvent e) { 49 | try { 50 | if (plugin.getVanishStateMgr().isVanished(e.getPlayer().getUniqueId())) 51 | e.setCancelled(true); 52 | } catch (Exception er) { 53 | if (!suppressErrors) { 54 | plugin.logException(er); 55 | suppressErrors = true; 56 | } 57 | } 58 | } 59 | 60 | @EventHandler 61 | public void onEntitySpawnerSpawn(PreSpawnerSpawnEvent e) { 62 | try { 63 | // First check if a non-spectator vanished player is in range 64 | boolean vanishedPlayerInRange = false; 65 | for (UUID vanishedUUID : plugin.getVanishStateMgr().getOnlineVanishedPlayers()) { 66 | Player p = Bukkit.getPlayer(vanishedUUID); 67 | if (p == null) continue; 68 | if (p.getWorld().equals(e.getSpawnerLocation().getWorld()) && 69 | p.getLocation().distanceSquared(e.getSpawnerLocation()) <= 256 && 70 | p.getGameMode() != GameMode.SPECTATOR) 71 | vanishedPlayerInRange = true; 72 | } 73 | if (!vanishedPlayerInRange) return; 74 | 75 | // If so, only cancel if no non-vanished player is in range 76 | for (Player p : Bukkit.getOnlinePlayers()) { 77 | if (p.getWorld().equals(e.getSpawnerLocation().getWorld()) && 78 | p.getLocation().distanceSquared(e.getSpawnerLocation()) <= 256 && 79 | p.getGameMode() != GameMode.SPECTATOR && 80 | !plugin.getVanishStateMgr().isVanished(p.getUniqueId())) 81 | return; 82 | } 83 | e.setCancelled(true); 84 | } catch (Exception er) { 85 | if (!suppressErrors) { 86 | plugin.logException(er); 87 | suppressErrors = true; 88 | } 89 | } 90 | } 91 | 92 | @Override 93 | public boolean isActive() { 94 | return plugin.getSettings().getBoolean("InvisibilityFeatures.PreventMobSpawning", true); 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /src/main/java/de/myzelyam/supervanish/features/NoPush.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015, Leon Mangler and the SuperVanish contributors 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | 9 | package de.myzelyam.supervanish.features; 10 | 11 | import de.myzelyam.api.vanish.PlayerHideEvent; 12 | import de.myzelyam.api.vanish.PlayerShowEvent; 13 | import de.myzelyam.supervanish.SuperVanish; 14 | 15 | import org.bukkit.entity.Player; 16 | import org.bukkit.event.EventHandler; 17 | import org.bukkit.event.EventPriority; 18 | import org.bukkit.event.player.PlayerJoinEvent; 19 | import org.bukkit.event.player.PlayerQuitEvent; 20 | import org.bukkit.scheduler.BukkitRunnable; 21 | import org.bukkit.scoreboard.Team; 22 | 23 | public class NoPush extends Feature { 24 | 25 | public NoPush(SuperVanish plugin) { 26 | super(plugin); 27 | } 28 | 29 | @Override 30 | public boolean isActive() { 31 | return plugin.getSettings().getBoolean("InvisibilityFeatures.DisablePush"); 32 | } 33 | 34 | public void setCantPush(Player p) { 35 | Team team = p.getScoreboard().getTeam("Vanished"); 36 | if (team == null) { 37 | team = p.getScoreboard().registerNewTeam("Vanished"); 38 | } 39 | try { 40 | team.setOption(Team.Option.COLLISION_RULE, Team.OptionStatus.NEVER); 41 | team.addEntry(p.getName()); 42 | } catch (NoSuchMethodError | NoClassDefFoundError ignored) { 43 | } 44 | } 45 | 46 | public void setCanPush(Player p) { 47 | Team team = p.getScoreboard().getTeam("Vanished"); 48 | if (team != null) 49 | team.removeEntry(p.getName()); 50 | } 51 | 52 | @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) 53 | public void onVanish(PlayerHideEvent e) { 54 | setCantPush(e.getPlayer()); 55 | } 56 | 57 | @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) 58 | public void onReappear(PlayerShowEvent e) { 59 | setCanPush(e.getPlayer()); 60 | } 61 | 62 | @EventHandler 63 | public void onJoin(final PlayerJoinEvent e) { 64 | if (plugin.getVanishStateMgr().isVanished(e.getPlayer().getUniqueId())) 65 | new BukkitRunnable() { 66 | @Override 67 | public void run() { 68 | setCantPush(e.getPlayer()); 69 | } 70 | }.runTaskLater(plugin, 5); 71 | } 72 | 73 | @EventHandler 74 | public void onQuit(PlayerQuitEvent e) { 75 | setCanPush(e.getPlayer()); 76 | } 77 | 78 | } 79 | -------------------------------------------------------------------------------- /src/main/java/de/myzelyam/supervanish/features/NoRaidTrigger.java: -------------------------------------------------------------------------------- 1 | package de.myzelyam.supervanish.features; 2 | 3 | import de.myzelyam.supervanish.SuperVanish; 4 | import org.bukkit.entity.Player; 5 | import org.bukkit.event.EventHandler; 6 | import org.bukkit.event.EventPriority; 7 | import org.bukkit.event.block.Action; 8 | import org.bukkit.event.player.PlayerInteractEvent; 9 | import org.bukkit.event.raid.RaidEvent; 10 | import org.bukkit.event.raid.RaidTriggerEvent; 11 | 12 | public class NoRaidTrigger extends Feature { 13 | 14 | public NoRaidTrigger(SuperVanish plugin) { 15 | super(plugin); 16 | } 17 | 18 | @EventHandler(priority = EventPriority.HIGH) 19 | public void onInteract(RaidTriggerEvent e) { 20 | Player p = e.getPlayer(); 21 | if (!plugin.getVanishStateMgr().isVanished(p.getUniqueId())) return; 22 | e.setCancelled(true); 23 | } 24 | 25 | @Override 26 | public boolean isActive() { 27 | return plugin.getSettings().getBoolean("InvisibilityFeatures.PreventRaidTriggering", true); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/de/myzelyam/supervanish/features/NoSculkSensorDetection.java: -------------------------------------------------------------------------------- 1 | package de.myzelyam.supervanish.features; 2 | 3 | import de.myzelyam.supervanish.SuperVanish; 4 | import org.bukkit.entity.Player; 5 | import org.bukkit.event.EventHandler; 6 | import org.bukkit.event.EventPriority; 7 | import org.bukkit.event.block.Action; 8 | import org.bukkit.event.block.BlockReceiveGameEvent; 9 | import org.bukkit.event.player.PlayerInteractEvent; 10 | 11 | public class NoSculkSensorDetection extends Feature { 12 | 13 | public NoSculkSensorDetection(SuperVanish plugin) { 14 | super(plugin); 15 | } 16 | 17 | @EventHandler(priority = EventPriority.HIGH) 18 | public void onSculkSensorTrigger(BlockReceiveGameEvent e) { 19 | if (!(e.getEntity() instanceof Player)) return; 20 | Player p = (Player) e.getEntity(); 21 | if (!plugin.getVanishStateMgr().isVanished(p.getUniqueId())) return; 22 | e.setCancelled(true); 23 | } 24 | 25 | @EventHandler(priority = EventPriority.HIGH) 26 | public void onInteract(PlayerInteractEvent e) { 27 | Player p = e.getPlayer(); 28 | if (!plugin.getVanishStateMgr().isVanished(p.getUniqueId())) return; 29 | if (!e.getAction().equals(Action.PHYSICAL) || e.getClickedBlock() == null) return; 30 | if (!e.getClickedBlock().getType().toString().matches("SCULK_SENSOR|CALIBRATED_SCULK_SENSOR|SCULK_SHRIEKER")) return; 31 | e.setCancelled(true); 32 | } 33 | 34 | @Override 35 | public boolean isActive() { 36 | return plugin.getSettings().getBoolean("InvisibilityFeatures.PreventSculkSensorActivation", true); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/de/myzelyam/supervanish/features/NoTurtleEggBreaking.java: -------------------------------------------------------------------------------- 1 | package de.myzelyam.supervanish.features; 2 | 3 | import de.myzelyam.supervanish.SuperVanish; 4 | import org.bukkit.entity.Player; 5 | import org.bukkit.event.EventHandler; 6 | import org.bukkit.event.EventPriority; 7 | import org.bukkit.event.block.Action; 8 | import org.bukkit.event.player.PlayerInteractEvent; 9 | 10 | public class NoTurtleEggBreaking extends Feature { 11 | 12 | public NoTurtleEggBreaking(SuperVanish plugin) { 13 | super(plugin); 14 | } 15 | 16 | @EventHandler(priority = EventPriority.HIGH) 17 | public void onInteract(PlayerInteractEvent e) { 18 | Player p = e.getPlayer(); 19 | if (!plugin.getVanishStateMgr().isVanished(p.getUniqueId())) return; 20 | if (!e.getAction().equals(Action.PHYSICAL) || e.getClickedBlock() == null 21 | || !e.getClickedBlock().getType().toString().equals("TURTLE_EGG")) 22 | return; 23 | e.setCancelled(true); 24 | } 25 | 26 | @Override 27 | public boolean isActive() { 28 | return plugin.getSettings().getBoolean("InvisibilityFeatures.PreventTurtleEggBreaking", true); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/de/myzelyam/supervanish/features/SilentOpenChestPacketAdapter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015, Leon Mangler and the SuperVanish contributors 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | 9 | package de.myzelyam.supervanish.features; 10 | 11 | import com.comphenix.protocol.events.ListenerPriority; 12 | import com.comphenix.protocol.events.PacketAdapter; 13 | import com.comphenix.protocol.events.PacketEvent; 14 | import com.comphenix.protocol.reflect.FieldAccessException; 15 | import com.comphenix.protocol.wrappers.EnumWrappers; 16 | import com.comphenix.protocol.wrappers.PlayerInfoData; 17 | import com.google.common.collect.ImmutableList; 18 | import org.bukkit.Bukkit; 19 | import org.bukkit.entity.Player; 20 | 21 | import java.util.ArrayList; 22 | import java.util.List; 23 | 24 | import static com.comphenix.protocol.PacketType.Play.Server.*; 25 | 26 | /** 27 | * This is currently unused on Minecraft 1.19 or higher 28 | */ 29 | public class SilentOpenChestPacketAdapter extends PacketAdapter { 30 | 31 | private final SilentOpenChest silentOpenChest; 32 | 33 | private boolean suppressErrors = false; 34 | 35 | public SilentOpenChestPacketAdapter(SilentOpenChest silentOpenChest) { 36 | super(silentOpenChest.plugin, ListenerPriority.LOW, PLAYER_INFO, ABILITIES, 37 | ENTITY_METADATA); 38 | this.silentOpenChest = silentOpenChest; 39 | } 40 | 41 | @Override 42 | public void onPacketSending(PacketEvent event) { 43 | try { 44 | Player receiver = event.getPlayer(); 45 | if (receiver == null) return; 46 | if (event.getPacketType() == PLAYER_INFO) { 47 | // multiple events share same packet object 48 | event.setPacket(event.getPacket().shallowClone()); 49 | 50 | List infoDataList = new ArrayList<>( 51 | event.getPacket().getPlayerInfoDataLists().read(0)); 52 | for (PlayerInfoData infoData : ImmutableList.copyOf(infoDataList)) { 53 | if (!silentOpenChest.plugin.getVisibilityChanger().getHider() 54 | .isHidden(infoData.getProfile().getUUID(), receiver) 55 | && silentOpenChest.plugin.getVanishStateMgr() 56 | .isVanished(infoData.getProfile().getUUID())) { 57 | Player vanishedTabPlayer = Bukkit.getPlayer(infoData.getProfile().getUUID()); 58 | if (infoData.getGameMode() == EnumWrappers.NativeGameMode.SPECTATOR 59 | && silentOpenChest.hasSilentlyOpenedChest(vanishedTabPlayer) 60 | && event.getPacket().getPlayerInfoAction().read(0) 61 | == EnumWrappers.PlayerInfoAction.UPDATE_GAME_MODE) { 62 | int latency; 63 | try { 64 | latency = infoData.getLatency(); 65 | } catch (NoSuchMethodError e) { 66 | latency = 21; 67 | } 68 | PlayerInfoData newData = new PlayerInfoData(infoData.getProfile(), 69 | latency, EnumWrappers.NativeGameMode.SURVIVAL, 70 | infoData.getDisplayName()); 71 | infoDataList.remove(infoData); 72 | infoDataList.add(newData); 73 | } 74 | } 75 | } 76 | event.getPacket().getPlayerInfoDataLists().write(0, infoDataList); 77 | } else if (event.getPacketType() == GAME_STATE_CHANGE) { 78 | // Currently unused due to ProtocolLib class loading bug 79 | if (silentOpenChest.plugin.getVanishStateMgr().isVanished( 80 | receiver.getUniqueId())) { 81 | try { 82 | if (event.getPacket().getIntegers().read(0) != 3) return; 83 | } catch (FieldAccessException e) { 84 | // TODO 85 | } 86 | if (!silentOpenChest.hasSilentlyOpenedChest(receiver)) return; 87 | event.setCancelled(true); 88 | } 89 | } else if (event.getPacketType() == ABILITIES) { 90 | if (silentOpenChest.plugin.getVanishStateMgr().isVanished( 91 | receiver.getUniqueId())) { 92 | if (!silentOpenChest.hasSilentlyOpenedChest(receiver)) return; 93 | event.setCancelled(true); 94 | } 95 | } else if (event.getPacketType() == ENTITY_METADATA) { 96 | int entityID = event.getPacket().getIntegers().read(0); 97 | if (entityID == receiver.getEntityId()) { 98 | if (silentOpenChest.plugin.getVanishStateMgr().isVanished( 99 | receiver.getUniqueId())) { 100 | if (!silentOpenChest.hasSilentlyOpenedChest(receiver)) return; 101 | event.setCancelled(true); 102 | } 103 | } 104 | } 105 | } catch (Exception | NoClassDefFoundError e) { 106 | if (!suppressErrors) { 107 | if (e.getMessage() == null 108 | || !e.getMessage().endsWith("is not supported for temporary players.")) { 109 | silentOpenChest.plugin.logException(e); 110 | silentOpenChest.plugin.getLogger().warning("IMPORTANT: Please make sure that you are using the latest " + 111 | "dev-build of ProtocolLib and that your server is up-to-date! This error likely " + 112 | "happened inside of ProtocolLib code which is out of SuperVanish's control. It's part " + 113 | "of an optional feature module and can be removed safely by disabling " + 114 | "OpenChestsSilently in the config file. Please report this " + 115 | "error if you can reproduce it on an up-to-date server with only latest " + 116 | "ProtocolLib and latest SV installed."); 117 | suppressErrors = true; 118 | } 119 | } 120 | } 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /src/main/java/de/myzelyam/supervanish/hooks/CitizensHook.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015, Leon Mangler and the SuperVanish contributors 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | 9 | package de.myzelyam.supervanish.hooks; 10 | 11 | import de.myzelyam.supervanish.SuperVanish; 12 | 13 | import net.citizensnpcs.api.ai.speech.SpeechContext; 14 | import net.citizensnpcs.api.ai.speech.Talkable; 15 | import net.citizensnpcs.api.ai.speech.event.NPCSpeechEvent; 16 | import net.citizensnpcs.api.ai.speech.event.SpeechEvent; 17 | 18 | import org.bukkit.Bukkit; 19 | import org.bukkit.entity.Entity; 20 | import org.bukkit.entity.Player; 21 | import org.bukkit.event.EventHandler; 22 | import org.bukkit.event.EventPriority; 23 | 24 | import java.util.Iterator; 25 | import java.util.UUID; 26 | 27 | public class CitizensHook extends PluginHook { 28 | 29 | 30 | public CitizensHook(SuperVanish superVanish) { 31 | super(superVanish); 32 | } 33 | 34 | @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) 35 | public void onNPCTarget(NPCSpeechEvent e) { 36 | e.setCancelled(!checkContext(e.getContext())); 37 | } 38 | 39 | @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) 40 | public void onSpeechTargeted(SpeechEvent e) { 41 | e.setCancelled(!checkContext(e.getContext())); 42 | } 43 | 44 | /** 45 | * @return FALSE if the event should be cancelled, TRUE otherwise 46 | */ 47 | private boolean checkContext(SpeechContext context) { 48 | // don't let it talk about hidden players 49 | for (UUID uuid : superVanish.getVanishStateMgr().getOnlineVanishedPlayers()) { 50 | if (context.getMessage().contains(Bukkit.getPlayer(uuid).getName())) { 51 | return false; 52 | } 53 | } 54 | // don't let hidden players receive it 55 | Iterator iterator = context.iterator(); 56 | while (iterator.hasNext()) { 57 | Talkable recipient = iterator.next(); 58 | Entity entity = recipient.getEntity(); 59 | if (!(entity instanceof Player)) 60 | continue; 61 | Player player = (Player) entity; 62 | if (superVanish.getVanishStateMgr().isVanished(player.getUniqueId())) { 63 | iterator.remove(); 64 | } 65 | } 66 | // cancel contexts with only hidden recipients 67 | return context.hasRecipients(); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/main/java/de/myzelyam/supervanish/hooks/DynmapHook.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015, Leon Mangler and the SuperVanish contributors 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | 9 | package de.myzelyam.supervanish.hooks; 10 | 11 | import de.myzelyam.api.vanish.PlayerHideEvent; 12 | import de.myzelyam.api.vanish.PlayerShowEvent; 13 | import de.myzelyam.supervanish.SuperVanish; 14 | import org.bukkit.entity.Player; 15 | import org.bukkit.event.EventHandler; 16 | import org.bukkit.event.EventPriority; 17 | import org.bukkit.event.player.PlayerJoinEvent; 18 | import org.bukkit.event.player.PlayerQuitEvent; 19 | import org.dynmap.DynmapAPI; 20 | 21 | public class DynmapHook extends PluginHook { 22 | 23 | private final boolean sendJoinLeave; 24 | private final SuperVanish superVanish; 25 | 26 | public DynmapHook(SuperVanish superVanish) { 27 | super(superVanish); 28 | this.superVanish = superVanish; 29 | sendJoinLeave 30 | = superVanish.getSettings().getBoolean("HookOptions.DynmapSendJoinLeaveMessages") 31 | && !superVanish.getMessage("DynmapFakeJoin").equals(""); 32 | } 33 | 34 | @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) 35 | public void onVanish(PlayerHideEvent e) { 36 | Player p = e.getPlayer(); 37 | DynmapAPI dynmap = (DynmapAPI) plugin; 38 | 39 | dynmap.setPlayerVisiblity(p, false); 40 | if (sendJoinLeave) 41 | dynmap.sendBroadcastToWeb("", 42 | superVanish.replacePlaceholders(superVanish.getMessage("DynmapFakeQuit"), p)); 43 | } 44 | 45 | @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) 46 | public void onReappear(PlayerShowEvent e) { 47 | Player p = e.getPlayer(); 48 | DynmapAPI dynmap = (DynmapAPI) plugin; 49 | 50 | dynmap.setPlayerVisiblity(p, true); 51 | if (sendJoinLeave) 52 | dynmap.sendBroadcastToWeb("", 53 | superVanish.replacePlaceholders(superVanish.getMessage("DynmapFakeJoin"), p)); 54 | } 55 | 56 | @EventHandler(priority = EventPriority.LOWEST) 57 | public void onJoin(PlayerJoinEvent e) { 58 | Player p = e.getPlayer(); 59 | DynmapAPI dynmap = (DynmapAPI) plugin; 60 | 61 | if (superVanish.getVanishStateMgr().isVanished(p.getUniqueId())) { 62 | dynmap.setPlayerVisiblity(p, false); 63 | } 64 | } 65 | 66 | @EventHandler(priority = EventPriority.MONITOR) 67 | public void onQuit(PlayerQuitEvent e) { 68 | Player p = e.getPlayer(); 69 | DynmapAPI dynmap = (DynmapAPI) plugin; 70 | 71 | if (superVanish.getVanishStateMgr().isVanished(p.getUniqueId())) { 72 | dynmap.setPlayerVisiblity(p, true); 73 | } 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /src/main/java/de/myzelyam/supervanish/hooks/EssentialsHook.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015, Leon Mangler and the SuperVanish contributors 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | 9 | package de.myzelyam.supervanish.hooks; 10 | 11 | import com.earth2me.essentials.Essentials; 12 | import com.earth2me.essentials.User; 13 | import de.myzelyam.api.vanish.PlayerHideEvent; 14 | import de.myzelyam.api.vanish.PostPlayerShowEvent; 15 | import de.myzelyam.supervanish.SuperVanish; 16 | import de.myzelyam.supervanish.commands.CommandAction; 17 | import org.bukkit.Bukkit; 18 | import org.bukkit.entity.Player; 19 | import org.bukkit.event.EventHandler; 20 | import org.bukkit.event.EventPriority; 21 | import org.bukkit.event.player.PlayerCommandPreprocessEvent; 22 | import org.bukkit.event.player.PlayerJoinEvent; 23 | import org.bukkit.plugin.Plugin; 24 | import org.bukkit.scheduler.BukkitRunnable; 25 | import org.bukkit.scheduler.BukkitTask; 26 | 27 | import java.util.HashSet; 28 | import java.util.Locale; 29 | import java.util.Set; 30 | import java.util.UUID; 31 | 32 | public class EssentialsHook extends PluginHook { 33 | 34 | private final Set preVanishHiddenPlayers = new HashSet<>(); 35 | private Essentials essentials; 36 | private BukkitRunnable forcedInvisibilityRunnable = new BukkitRunnable() { 37 | 38 | @Override 39 | public void run() { 40 | try { 41 | if (!Bukkit.getPluginManager().isPluginEnabled("Essentials")) return; 42 | for (UUID uuid : superVanish.getVanishStateMgr().getOnlineVanishedPlayers()) { 43 | Player p = Bukkit.getPlayer(uuid); 44 | User user = essentials.getUser(p); 45 | if (user == null) continue; 46 | if (!user.isHidden()) 47 | user.setHidden(true); 48 | } 49 | } catch (Exception e) { 50 | cancel(); 51 | superVanish.logException(e); 52 | } 53 | } 54 | }; 55 | 56 | private BukkitTask forcedInvisibilityTask; 57 | 58 | public EssentialsHook(SuperVanish superVanish) { 59 | super(superVanish); 60 | } 61 | 62 | @Override 63 | public void onPluginEnable(Plugin plugin) { 64 | essentials = (Essentials) plugin; 65 | forcedInvisibilityTask = forcedInvisibilityRunnable.runTaskTimer(superVanish, 0, 100); 66 | forcedInvisibilityRunnable.run(); 67 | } 68 | 69 | @Override 70 | public void onPluginDisable(Plugin plugin) { 71 | essentials = null; 72 | forcedInvisibilityTask.cancel(); 73 | } 74 | 75 | @EventHandler(priority = EventPriority.LOW) 76 | public void onJoin(PlayerJoinEvent e) { 77 | User user = essentials.getUser(e.getPlayer()); 78 | if (user == null) return; 79 | if (superVanish.getVanishStateMgr().isVanished(e.getPlayer().getUniqueId()) && !user.isHidden()) 80 | user.setHidden(true); 81 | else user.setHidden(false); 82 | } 83 | 84 | @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) 85 | public void onVanish(PlayerHideEvent e) { 86 | User user = essentials.getUser(e.getPlayer()); 87 | if (user == null) return; 88 | if (user.isVanished()) user.setVanished(false); 89 | preVanishHiddenPlayers.remove(e.getPlayer().getUniqueId()); 90 | user.setHidden(true); 91 | } 92 | 93 | @EventHandler 94 | public void onReappear(PostPlayerShowEvent e) { 95 | User user = essentials.getUser(e.getPlayer()); 96 | if (user == null) return; 97 | user.setHidden(false); 98 | } 99 | 100 | @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) 101 | public void onCommand(final PlayerCommandPreprocessEvent e) { 102 | if (!CommandAction.VANISH_SELF.checkPermission(e.getPlayer(), superVanish)) return; 103 | if (superVanish.getVanishStateMgr().isVanished(e.getPlayer().getUniqueId())) return; 104 | String command = e.getMessage().toLowerCase(Locale.ENGLISH).split(" ")[0].replace("/", "") 105 | .toLowerCase(Locale.ENGLISH); 106 | if (command.split(":").length > 1) command = command.split(":")[1]; 107 | if (command.equals("supervanish") || command.equals("sv") 108 | || command.equals("v") || command.equals("vanish")) { 109 | final User user = essentials.getUser(e.getPlayer()); 110 | if (user == null || !user.isAfk()) return; 111 | user.setHidden(true); 112 | preVanishHiddenPlayers.add(e.getPlayer().getUniqueId()); 113 | superVanish.getServer().getScheduler().runTaskLater(superVanish, new Runnable() { 114 | @Override 115 | public void run() { 116 | if (preVanishHiddenPlayers.remove(e.getPlayer().getUniqueId())) { 117 | user.setHidden(false); 118 | } 119 | } 120 | }, 1); 121 | } 122 | } 123 | } 124 | -------------------------------------------------------------------------------- /src/main/java/de/myzelyam/supervanish/hooks/InvalidPluginHookException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015, Leon Mangler and the SuperVanish contributors 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | 9 | package de.myzelyam.supervanish.hooks; 10 | 11 | public class InvalidPluginHookException extends RuntimeException { 12 | 13 | public InvalidPluginHookException() { 14 | } 15 | 16 | public InvalidPluginHookException(String message) { 17 | super(message); 18 | } 19 | 20 | public InvalidPluginHookException(Throwable cause) { 21 | super(cause); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/de/myzelyam/supervanish/hooks/PlaceholderAPIHook.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015, Leon Mangler and the SuperVanish contributors 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | 9 | package de.myzelyam.supervanish.hooks; 10 | 11 | import de.myzelyam.supervanish.SuperVanish; 12 | import me.clip.placeholderapi.PlaceholderAPI; 13 | import me.clip.placeholderapi.expansion.PlaceholderExpansion; 14 | import org.bukkit.Bukkit; 15 | import org.bukkit.OfflinePlayer; 16 | import org.bukkit.entity.Player; 17 | 18 | import java.util.Collection; 19 | import java.util.UUID; 20 | 21 | public class PlaceholderAPIHook extends PluginHook { 22 | 23 | private final String yes, no, prefix, suffix; 24 | 25 | public PlaceholderAPIHook(SuperVanish superVanish) { 26 | super(superVanish); 27 | yes = superVanish.getMessage("PlaceholderIsVanishedYes"); 28 | no = superVanish.getMessage("PlaceholderIsVanishedNo"); 29 | prefix = superVanish.getMessage("PlaceholderVanishPrefix"); 30 | suffix = superVanish.getMessage("PlaceholderVanishSuffix"); 31 | new SVPlaceholderExpansion().register(); 32 | } 33 | 34 | public static String translatePlaceholders(String msg, Player p) { 35 | return PlaceholderAPI.setPlaceholders((OfflinePlayer) p, msg); 36 | } 37 | 38 | public class SVPlaceholderExpansion extends PlaceholderExpansion { 39 | 40 | @Override 41 | public boolean persist() { 42 | return true; 43 | } 44 | 45 | @Override 46 | public boolean canRegister() { 47 | return true; 48 | } 49 | 50 | @Override 51 | public String getAuthor() { 52 | return superVanish.getDescription().getAuthors().toString(); 53 | } 54 | 55 | @Override 56 | public String getIdentifier() { 57 | return "supervanish"; 58 | } 59 | 60 | @Override 61 | public String getVersion() { 62 | return superVanish.getDescription().getVersion(); 63 | } 64 | 65 | @Override 66 | public String onRequest(OfflinePlayer op, String id) { 67 | try { 68 | Player p; 69 | if (op instanceof Player) 70 | p = (Player) op; 71 | else 72 | p = null; 73 | if (id.equalsIgnoreCase("isvanished") 74 | || id.equalsIgnoreCase("isinvisible") 75 | || id.equalsIgnoreCase("vanished") 76 | || id.equalsIgnoreCase("invisible")) 77 | return p != null && superVanish.getVanishStateMgr().isVanished(p.getUniqueId()) 78 | ? yes : no; 79 | if (id.equalsIgnoreCase("vanishprefix")) 80 | return p != null && superVanish.getVanishStateMgr().isVanished(p.getUniqueId()) 81 | ? prefix : ""; 82 | if (id.equalsIgnoreCase("vanishsuffix")) 83 | return p != null && superVanish.getVanishStateMgr().isVanished(p.getUniqueId()) 84 | ? suffix : ""; 85 | if (id.equalsIgnoreCase("onlinevanishedplayers") 86 | || id.equalsIgnoreCase("onlinevanished") 87 | || id.equalsIgnoreCase("invisibleplayers") 88 | || id.equalsIgnoreCase("vanishedplayers") 89 | || id.equalsIgnoreCase("hiddenplayers")) { 90 | Collection onlineVanishedPlayers = superVanish.getVanishStateMgr() 91 | .getOnlineVanishedPlayers(); 92 | String playerListMessage = ""; 93 | for (UUID uuid : onlineVanishedPlayers) { 94 | Player onlineVanished = Bukkit.getPlayer(uuid); 95 | if (onlineVanished == null) continue; 96 | if (superVanish.getSettings().getBoolean( 97 | "IndicationFeatures.LayeredPermissions.HideInvisibleInCommands", false) 98 | && !superVanish.hasPermissionToSee(p, onlineVanished)) { 99 | continue; 100 | } 101 | playerListMessage = playerListMessage + onlineVanished.getName() + ", "; 102 | } 103 | return playerListMessage.length() > 3 104 | ? playerListMessage.substring(0, playerListMessage.length() - 2) 105 | : playerListMessage; 106 | } 107 | if (id.equalsIgnoreCase("playercount") 108 | || id.equalsIgnoreCase("onlineplayers")) { 109 | int playercount = Bukkit.getOnlinePlayers().size(); 110 | for (UUID uuid : superVanish.getVanishStateMgr() 111 | .getOnlineVanishedPlayers()) { 112 | Player onlineVanished = Bukkit.getPlayer(uuid); 113 | if (onlineVanished == null) continue; 114 | if (p == null || !superVanish.canSee(p, onlineVanished)) playercount--; 115 | } 116 | return playercount + ""; 117 | } 118 | } catch (Exception e) { 119 | superVanish.logException(e); 120 | } 121 | return null; 122 | } 123 | } 124 | } 125 | -------------------------------------------------------------------------------- /src/main/java/de/myzelyam/supervanish/hooks/PluginHook.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015, Leon Mangler and the SuperVanish contributors 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | 9 | package de.myzelyam.supervanish.hooks; 10 | 11 | import de.myzelyam.supervanish.SuperVanish; 12 | 13 | import org.bukkit.event.Listener; 14 | import org.bukkit.plugin.Plugin; 15 | 16 | /** 17 | * Represents a hook into a plugin to support its functionality or make it support SuperVanish's 18 | * functionality 19 | */ 20 | public abstract class PluginHook implements Listener { 21 | 22 | protected final SuperVanish superVanish; 23 | protected Plugin plugin; 24 | 25 | public PluginHook(SuperVanish superVanish) { 26 | this.superVanish = superVanish; 27 | } 28 | 29 | public void onPluginEnable(Plugin plugin) { 30 | } 31 | 32 | public void onPluginDisable(Plugin plugin) { 33 | } 34 | 35 | public Plugin getPlugin() { 36 | return plugin; 37 | } 38 | 39 | void setPlugin(Plugin plugin) { 40 | this.plugin = plugin; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/de/myzelyam/supervanish/hooks/PluginHookMgr.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015, Leon Mangler and the SuperVanish contributors 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | 9 | package de.myzelyam.supervanish.hooks; 10 | 11 | import de.myzelyam.supervanish.SuperVanish; 12 | 13 | import org.bukkit.Bukkit; 14 | import org.bukkit.event.EventHandler; 15 | import org.bukkit.event.Listener; 16 | import org.bukkit.event.server.PluginDisableEvent; 17 | import org.bukkit.event.server.PluginEnableEvent; 18 | import org.bukkit.plugin.Plugin; 19 | 20 | import java.util.HashMap; 21 | import java.util.HashSet; 22 | import java.util.Map; 23 | import java.util.Set; 24 | import java.util.logging.Level; 25 | 26 | public class PluginHookMgr implements Listener { 27 | 28 | private static final Map> REGISTERED_HOOKS 29 | = new HashMap>() {{ 30 | put("Essentials", EssentialsHook.class); 31 | put("Citizens", CitizensHook.class); 32 | put("PlaceholderAPI", PlaceholderAPIHook.class); 33 | put("dynmap", DynmapHook.class); 34 | put("TrailGUI", TrailGUIHook.class); 35 | put("MVdWPlaceholderAPI", MVdWPlaceholderAPIHook.class); 36 | }}; 37 | private final SuperVanish plugin; 38 | private Set activeHooks = new HashSet<>(); 39 | 40 | public PluginHookMgr(SuperVanish plugin) { 41 | this.plugin = plugin; 42 | plugin.getServer().getPluginManager().registerEvents(this, plugin); 43 | for (Plugin alreadyEnabledPlugin : Bukkit.getPluginManager().getPlugins()) 44 | if (alreadyEnabledPlugin.isEnabled()) 45 | onPluginEnable(new PluginEnableEvent(alreadyEnabledPlugin)); 46 | } 47 | 48 | @EventHandler 49 | public void onPluginEnable(PluginEnableEvent e) { 50 | Plugin plugin = e.getPlugin(); 51 | if (REGISTERED_HOOKS.get(plugin.getName()) == null) return; 52 | if (isHookDisabled(plugin.getName())) return; 53 | PluginHook hook = null; 54 | try { 55 | hook = REGISTERED_HOOKS.get(plugin.getName()).getConstructor(SuperVanish.class). 56 | newInstance(PluginHookMgr.this.plugin); 57 | hook.setPlugin(plugin); 58 | hook.onPluginEnable(plugin); 59 | Bukkit.getPluginManager().registerEvents(hook, plugin); 60 | activeHooks.add(hook); 61 | PluginHookMgr.this.plugin.log( 62 | Level.INFO, "Hooked into " + plugin.getName()); 63 | } catch (NoClassDefFoundError er) { 64 | Bukkit.getLogger().warning("NoClassDefFoundError for SV-Hook(v" 65 | + this.plugin.getDescription().getVersion() + ") " 66 | + (hook != null ? hook.getClass().getSimpleName() : "?") + " of plugin " 67 | + plugin.getName() + " v" + plugin.getDescription().getVersion() 68 | + ", please report this if you are using the latest version of that" + 69 | " plugin!"); 70 | } catch (Exception er) { 71 | if (er.getMessage() != null 72 | && er.getMessage().contains("Unable to find handler list for event")) { 73 | this.plugin.log(Level.WARNING, "" + er.getMessage() 74 | + "; This is not an issue with SuperVanish"); 75 | return; 76 | } else if (er.getCause() != null && er.getCause().getMessage() != null && er.getCause() 77 | .getMessage().contains("Unable to find handler list for event ")) { 78 | this.plugin.log(Level.WARNING, "" + er.getCause() 79 | .getMessage() + "; This is not an issue with SuperVanish"); 80 | return; 81 | } 82 | this.plugin.logException(new InvalidPluginHookException(er)); 83 | this.plugin.log(Level.WARNING, "Affected by this error is only the " 84 | + plugin.getName() + "-Hook, all other hooks and features aren't affected."); 85 | } 86 | } 87 | 88 | private boolean isHookDisabled(String pluginName) { 89 | if (pluginName.equalsIgnoreCase("dynmap")) 90 | return !plugin.getSettings().getBoolean("HookOptions.EnableDynmapHook"); 91 | return !plugin.getSettings().getBoolean("HookOptions.Enable" + pluginName + "Hook", true); 92 | } 93 | 94 | @EventHandler 95 | public void onPluginDisable(PluginDisableEvent e) { 96 | Plugin plugin = e.getPlugin(); 97 | PluginHook hook = getActiveHook(plugin); 98 | if (hook == null) return; 99 | try { 100 | hook.onPluginDisable(plugin); 101 | } catch (Exception e1) { 102 | this.plugin.logException(new InvalidPluginHookException(e1)); 103 | } 104 | hook.setPlugin(null); 105 | activeHooks.remove(hook); 106 | } 107 | 108 | private PluginHook getActiveHook(Plugin plugin) { 109 | for (PluginHook hook : activeHooks) if (hook.getPlugin() == plugin) return hook; 110 | return null; 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /src/main/java/de/myzelyam/supervanish/hooks/TrailGUIHook.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015, Leon Mangler and the SuperVanish contributors 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | 9 | package de.myzelyam.supervanish.hooks; 10 | 11 | import de.myzelyam.supervanish.SuperVanish; 12 | 13 | import org.bukkit.event.EventHandler; 14 | import org.bukkit.event.Listener; 15 | import org.bukkit.event.player.PlayerMoveEvent; 16 | import org.bukkit.plugin.Plugin; 17 | 18 | import java.util.logging.Level; 19 | 20 | import ca.jamiesinn.trailgui.Listeners; 21 | import ca.jamiesinn.trailgui.TrailGUI; 22 | 23 | public class TrailGUIHook extends PluginHook { 24 | 25 | public TrailGUIHook(SuperVanish superVanish) { 26 | super(superVanish); 27 | } 28 | 29 | @Override 30 | public void onPluginEnable(Plugin plugin) { 31 | if (!(plugin instanceof TrailGUI)) { 32 | superVanish.log(Level.WARNING, 33 | "Failed to hook into TrailGUI. (PluginNotFound)"); 34 | return; 35 | } 36 | PlayerMoveEvent.getHandlerList().unregister(plugin); 37 | final Listeners trailGUIListeners = new Listeners((TrailGUI) plugin); 38 | plugin.getServer().getPluginManager().registerEvents(new Listener() { 39 | 40 | @EventHandler 41 | public void onPlayerMove(PlayerMoveEvent event) { 42 | if (superVanish.getVanishStateMgr() 43 | .getOnlineVanishedPlayers().contains( 44 | event.getPlayer().getUniqueId())) 45 | return; 46 | trailGUIListeners.onPlayerMove(event); 47 | } 48 | }, plugin); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/de/myzelyam/supervanish/listeners/GeneralListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015, Leon Mangler and the SuperVanish contributors 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | 9 | package de.myzelyam.supervanish.listeners; 10 | 11 | import de.myzelyam.supervanish.SuperVanish; 12 | import de.myzelyam.supervanish.VanishPlayer; 13 | import de.myzelyam.supervanish.features.Broadcast; 14 | import org.bukkit.configuration.file.FileConfiguration; 15 | import org.bukkit.entity.Player; 16 | import org.bukkit.event.EventHandler; 17 | import org.bukkit.event.EventPriority; 18 | import org.bukkit.event.Listener; 19 | import org.bukkit.event.block.Action; 20 | import org.bukkit.event.entity.*; 21 | import org.bukkit.event.player.PlayerInteractEvent; 22 | import org.bukkit.event.player.PlayerPickupItemEvent; 23 | 24 | 25 | public class GeneralListener implements Listener { 26 | 27 | private final SuperVanish plugin; 28 | 29 | private final FileConfiguration config; 30 | 31 | public GeneralListener(SuperVanish plugin) { 32 | this.plugin = plugin; 33 | config = plugin.getSettings(); 34 | } 35 | 36 | @EventHandler(priority = EventPriority.HIGH) 37 | public void onDamage(EntityDamageByEntityEvent e) { 38 | try { 39 | if (!(e.getDamager() instanceof Player)) return; 40 | if (e.getEntity() == null) return; 41 | Player p = (Player) e.getDamager(); 42 | if (plugin.getVanishStateMgr().isVanished(p.getUniqueId())) { 43 | if (config.getBoolean("RestrictiveOptions.PreventHittingEntities") 44 | && !p.hasPermission("sv.damageentities") && !p.hasPermission("sv.damage")) { 45 | plugin.sendMessage(p, "EntityHitDenied", p); 46 | e.setCancelled(true); 47 | } 48 | } 49 | } catch (Exception er) { 50 | plugin.logException(er); 51 | } 52 | } 53 | 54 | @EventHandler(priority = EventPriority.HIGH) 55 | public void onPlayerDeath(PlayerDeathEvent e) { 56 | try { 57 | Player p = e.getEntity(); 58 | if (plugin.getVanishStateMgr().isVanished(p.getUniqueId())) { 59 | String deathMessage = e.getDeathMessage(); 60 | e.setDeathMessage(null); 61 | if (deathMessage != null) 62 | Broadcast.announceSilentDeath(p, plugin, deathMessage); 63 | } 64 | } catch (Exception er) { 65 | plugin.logException(er); 66 | } 67 | } 68 | 69 | @EventHandler(priority = EventPriority.HIGH) 70 | public void onFoodLevelChange(FoodLevelChangeEvent e) { 71 | try { 72 | if (e.getEntity() instanceof Player && config.getBoolean("InvisibilityFeatures.DisableHunger")) { 73 | Player p = (Player) e.getEntity(); 74 | if (plugin.getVanishStateMgr().isVanished(p.getUniqueId()) 75 | && e.getFoodLevel() <= p.getFoodLevel()) 76 | e.setCancelled(true); 77 | } 78 | } catch (Exception er) { 79 | plugin.logException(er); 80 | } 81 | } 82 | 83 | @EventHandler(priority = EventPriority.HIGH) 84 | public void onDamage(EntityDamageEvent e) { 85 | try { 86 | if (!(e.getEntity() instanceof Player)) return; 87 | Player p = (Player) e.getEntity(); 88 | if (!config.getBoolean("InvisibilityFeatures.DisableDamage")) return; 89 | if (plugin.getVanishStateMgr().isVanished(p.getUniqueId())) { 90 | e.setCancelled(true); 91 | } 92 | } catch (Exception er) { 93 | plugin.logException(er); 94 | } 95 | } 96 | 97 | @EventHandler(priority = EventPriority.HIGH) 98 | public void onTarget(EntityTargetEvent e) { 99 | try { 100 | if (!(e.getTarget() instanceof Player)) return; 101 | if (!config.getBoolean("InvisibilityFeatures.DisableMobTarget")) return; 102 | Player p = (Player) e.getTarget(); 103 | if (plugin.getVanishStateMgr().isVanished(p.getUniqueId())) { 104 | e.setCancelled(true); 105 | } 106 | } catch (Exception er) { 107 | plugin.logException(er); 108 | } 109 | } 110 | 111 | @EventHandler(priority = EventPriority.HIGH) 112 | public void onItemPickUp(PlayerPickupItemEvent e) { 113 | try { 114 | VanishPlayer vanishPlayer = plugin.getVanishPlayer(e.getPlayer()); 115 | if (vanishPlayer == null || !vanishPlayer.isOnlineVanished()) return; 116 | if (!vanishPlayer.hasItemPickUpsEnabled()) 117 | e.setCancelled(true); 118 | if (plugin.getSettings().getBoolean("RestrictiveOptions.PreventModifyingOwnInventory") 119 | && !e.getPlayer().hasPermission("sv.modifyowninv")) { 120 | e.setCancelled(true); 121 | } 122 | } catch (Exception er) { 123 | plugin.logException(er); 124 | } 125 | } 126 | 127 | @EventHandler 128 | public void onPlayerCropTrample(PlayerInteractEvent e) { 129 | try { 130 | if (!plugin.getVanishStateMgr().isVanished(e.getPlayer().getUniqueId())) return; 131 | if (e.getAction() != Action.PHYSICAL) return; 132 | if (e.getClickedBlock() != null && e.getClickedBlock().getType().toString().matches("SOIL|FARMLAND")) 133 | e.setCancelled(true); 134 | } catch (Exception er) { 135 | plugin.logException(er); 136 | } 137 | } 138 | } 139 | -------------------------------------------------------------------------------- /src/main/java/de/myzelyam/supervanish/listeners/JoinListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015, Leon Mangler and the SuperVanish contributors 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | 9 | package de.myzelyam.supervanish.listeners; 10 | 11 | import de.myzelyam.supervanish.SuperVanish; 12 | import de.myzelyam.supervanish.features.Broadcast; 13 | 14 | import org.bukkit.Bukkit; 15 | import org.bukkit.entity.Player; 16 | import org.bukkit.event.Event; 17 | import org.bukkit.event.Listener; 18 | import org.bukkit.event.player.PlayerJoinEvent; 19 | import org.bukkit.metadata.FixedMetadataValue; 20 | import org.bukkit.plugin.EventExecutor; 21 | import org.bukkit.scheduler.BukkitRunnable; 22 | 23 | public class JoinListener implements EventExecutor, Listener { 24 | 25 | private final SuperVanish plugin; 26 | 27 | public JoinListener(SuperVanish plugin) { 28 | this.plugin = plugin; 29 | } 30 | 31 | @Override 32 | public void execute(Listener l, Event event) { 33 | try { 34 | if (event instanceof PlayerJoinEvent) { 35 | PlayerJoinEvent e = (PlayerJoinEvent) event; 36 | final Player p = e.getPlayer(); 37 | // vanished: 38 | if (plugin.getVanishStateMgr().isVanished(p.getUniqueId())) { 39 | // hide self 40 | for (Player onlinePlayer : Bukkit.getOnlinePlayers()) 41 | if (!plugin.hasPermissionToSee(onlinePlayer, p)) 42 | plugin.getVisibilityChanger().getHider().setHidden(p, onlinePlayer, true); 43 | // Join message 44 | if (plugin.getSettings().getBoolean("MessageOptions.HideRealJoinQuitMessages")) { 45 | e.setJoinMessage(null); 46 | Broadcast.announceSilentJoin(p, plugin); 47 | } 48 | // reminding message 49 | if (plugin.getSettings().getBoolean("MessageOptions.RemindVanishedOnJoin")) { 50 | plugin.sendMessage(p, "RemindingMessage", p); 51 | } 52 | // re-add action bar 53 | if (plugin.getActionBarMgr() != null && plugin.getSettings().getBoolean( 54 | "MessageOptions.DisplayActionBar")) { 55 | plugin.getActionBarMgr().addActionBar(p); 56 | } 57 | // sleep state 58 | p.setSleepingIgnored(true); 59 | // adjust fly 60 | if (plugin.getSettings().getBoolean("InvisibilityFeatures.Fly.Enable")) { 61 | p.setAllowFlight(true); 62 | } 63 | // metadata 64 | p.setMetadata("vanished", new FixedMetadataValue(plugin, true)); 65 | } else { 66 | // not vanished: 67 | // metadata 68 | p.removeMetadata("vanished", plugin); 69 | } 70 | // not necessarily vanished: 71 | // recreate files msg 72 | if ((p.hasPermission("sv.recreatecfg") || p.hasPermission("sv.recreatefiles")) 73 | && (plugin.getConfigMgr().isSettingsUpdateRequired() 74 | || plugin.getConfigMgr().isMessagesUpdateRequired())) { 75 | String currentVersion = plugin.getDescription().getVersion(); 76 | boolean isDismissed = 77 | plugin.getPlayerData().getBoolean("PlayerData." + p.getUniqueId() + ".dismissed." 78 | + currentVersion.replace(".", "_"), false); 79 | if (!isDismissed) 80 | new BukkitRunnable() { 81 | @Override 82 | public void run() { 83 | plugin.sendMessage(p, "RecreationRequiredMsg", p); 84 | } 85 | }.runTaskLater(plugin, 1); 86 | } 87 | // hide others 88 | for (Player onlinePlayer : Bukkit.getOnlinePlayers()) 89 | if (plugin.getVanishStateMgr().isVanished(onlinePlayer.getUniqueId()) 90 | && !plugin.hasPermissionToSee(p, onlinePlayer)) 91 | plugin.getVisibilityChanger().getHider().setHidden(onlinePlayer, p, true); 92 | } 93 | } catch (Exception er) { 94 | plugin.logException(er); 95 | } 96 | } 97 | } -------------------------------------------------------------------------------- /src/main/java/de/myzelyam/supervanish/listeners/LoginListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015, Leon Mangler and the SuperVanish contributors 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | 9 | package de.myzelyam.supervanish.listeners; 10 | 11 | import de.myzelyam.supervanish.SuperVanish; 12 | import de.myzelyam.supervanish.commands.CommandAction; 13 | 14 | import org.bukkit.Bukkit; 15 | import org.bukkit.entity.Player; 16 | import org.bukkit.event.EventHandler; 17 | import org.bukkit.event.EventPriority; 18 | import org.bukkit.event.Listener; 19 | import org.bukkit.event.player.PlayerLoginEvent; 20 | 21 | 22 | public class LoginListener implements Listener { 23 | 24 | private final SuperVanish plugin; 25 | 26 | public LoginListener(SuperVanish plugin) { 27 | this.plugin = plugin; 28 | } 29 | 30 | @EventHandler(priority = EventPriority.MONITOR) 31 | public void onLogin(PlayerLoginEvent e) { 32 | try { 33 | if (e.getResult() != PlayerLoginEvent.Result.ALLOWED) return; 34 | final Player p = e.getPlayer(); 35 | boolean vanished = plugin.getVanishStateMgr().isVanished(p.getUniqueId()); 36 | boolean itemPickUps = plugin.getPlayerData().getBoolean( 37 | "PlayerData." + p.getUniqueId() + ".itemPickUps", 38 | plugin.getSettings().getBoolean("InvisibilityFeatures.DefaultPickUpItemsOption")); 39 | plugin.createVanishPlayer(p, itemPickUps); 40 | if (vanished && plugin.getSettings().getBoolean("VanishStateFeatures.CheckPermissionOnLogin", false) 41 | && !CommandAction.VANISH_SELF.checkPermission(p, plugin)) { 42 | vanished = false; 43 | } 44 | if (!vanished && p.hasPermission("sv.joinvanished") 45 | && plugin.getSettings().getBoolean("VanishStateFeatures.AutoVanishOnJoin", false)) { 46 | plugin.getVanishStateMgr().setVanishedState(p.getUniqueId(), p.getName(), true, null); 47 | vanished = true; 48 | } 49 | if (vanished) { 50 | // hide self 51 | for (Player onlinePlayer : Bukkit.getOnlinePlayers()) 52 | if (!plugin.hasPermissionToSee(onlinePlayer, p)) 53 | plugin.getVisibilityChanger().getHider().setHidden(p, onlinePlayer, true); 54 | } 55 | 56 | // hide others 57 | for (Player onlinePlayer : Bukkit.getOnlinePlayers()) 58 | if (plugin.getVanishStateMgr().isVanished(onlinePlayer.getUniqueId()) 59 | && !plugin.hasPermissionToSee(p, onlinePlayer)) 60 | plugin.getVisibilityChanger().getHider().setHidden(onlinePlayer, p, true); 61 | } catch (Exception er) { 62 | plugin.logException(er); 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/de/myzelyam/supervanish/listeners/PlayerBlockModifyListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015, Leon Mangler and the SuperVanish contributors 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | 9 | package de.myzelyam.supervanish.listeners; 10 | 11 | import de.myzelyam.supervanish.SuperVanish; 12 | 13 | import org.bukkit.entity.Player; 14 | import org.bukkit.event.EventHandler; 15 | import org.bukkit.event.EventPriority; 16 | import org.bukkit.event.Listener; 17 | import org.bukkit.event.block.Action; 18 | import org.bukkit.event.block.BlockBreakEvent; 19 | import org.bukkit.event.block.BlockPlaceEvent; 20 | import org.bukkit.event.player.PlayerInteractEvent; 21 | 22 | import java.util.Arrays; 23 | import java.util.Collection; 24 | import java.util.List; 25 | import java.util.UUID; 26 | 27 | public class PlayerBlockModifyListener implements Listener { 28 | 29 | private final SuperVanish plugin; 30 | 31 | public PlayerBlockModifyListener(SuperVanish plugin) { 32 | this.plugin = plugin; 33 | } 34 | 35 | @EventHandler(priority = EventPriority.HIGH) 36 | public void onInteract(PlayerInteractEvent e) { 37 | try { 38 | if (!plugin.getVanishStateMgr().isVanished(e.getPlayer().getUniqueId())) 39 | return; 40 | if (e.getAction().equals(Action.PHYSICAL) && e.getClickedBlock() != null) { 41 | if (!plugin.getSettings().getBoolean("InvisibilityFeatures.DisablePressurePlates")) 42 | return; 43 | String material = e.getClickedBlock().getType().toString(); 44 | List disallowedMaterials = Arrays.asList("STONE_PLATE", "GOLD_PLATE", "IRON_PLATE", 45 | "WOOD_PLATE"/* <- LEGACY*/, "TRIPWIRE", "PRESSURE_PLATE"); 46 | for (String disallowedMaterial : disallowedMaterials) 47 | if (material.equals(disallowedMaterial) || material.contains(disallowedMaterial)) { 48 | e.setCancelled(true); 49 | } 50 | } 51 | } catch (Exception er) { 52 | plugin.logException(er); 53 | } 54 | } 55 | 56 | @EventHandler(priority = EventPriority.HIGH) 57 | public void onPlace(BlockPlaceEvent e) { 58 | try { 59 | if (plugin.getSettings().getBoolean("RestrictiveOptions.PreventBlockPlacing")) { 60 | Player p = e.getPlayer(); 61 | Collection vanishedPlayers = plugin.getVanishStateMgr().getOnlineVanishedPlayers(); 62 | if (vanishedPlayers.contains(p.getUniqueId()) && !p.hasPermission("sv.placeblocks")) { 63 | e.setCancelled(true); 64 | plugin.sendMessage(e.getPlayer(), "BlockPlaceDenied", e.getPlayer()); 65 | } 66 | } 67 | } catch (Exception er) { 68 | plugin.logException(er); 69 | } 70 | } 71 | 72 | @EventHandler(priority = EventPriority.HIGH) 73 | public void onBreak(BlockBreakEvent e) { 74 | try { 75 | if (plugin.getSettings().getBoolean("RestrictiveOptions.PreventBlockBreaking")) { 76 | Player p = e.getPlayer(); 77 | if (plugin.getVanishStateMgr().isVanished(p.getUniqueId()) && !p.hasPermission("sv.breakblocks")) { 78 | e.setCancelled(true); 79 | plugin.sendMessage(e.getPlayer(), "BlockBreakDenied", e.getPlayer()); 80 | } 81 | } 82 | } catch (Exception er) { 83 | plugin.logException(er); 84 | } 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /src/main/java/de/myzelyam/supervanish/listeners/QuitListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015, Leon Mangler and the SuperVanish contributors 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | 9 | package de.myzelyam.supervanish.listeners; 10 | 11 | import de.myzelyam.supervanish.SuperVanish; 12 | import de.myzelyam.supervanish.commands.CommandAction; 13 | import de.myzelyam.supervanish.features.Broadcast; 14 | 15 | import org.bukkit.configuration.file.FileConfiguration; 16 | import org.bukkit.entity.Player; 17 | import org.bukkit.event.Event; 18 | import org.bukkit.event.Listener; 19 | import org.bukkit.event.player.PlayerQuitEvent; 20 | import org.bukkit.plugin.EventExecutor; 21 | 22 | public class QuitListener implements EventExecutor, Listener { 23 | 24 | private final SuperVanish plugin; 25 | 26 | public QuitListener(SuperVanish plugin) { 27 | this.plugin = plugin; 28 | } 29 | 30 | @Override 31 | public void execute(Listener l, Event event) { 32 | try { 33 | if (event instanceof PlayerQuitEvent) { 34 | PlayerQuitEvent e = (PlayerQuitEvent) event; 35 | FileConfiguration config = plugin.getConfig(); 36 | Player p = e.getPlayer(); 37 | // if is invisible 38 | if (plugin.getVanishStateMgr().isVanished(p.getUniqueId())) { 39 | // remove action bar 40 | if (plugin.getActionBarMgr() != null && plugin.getSettings().getBoolean( 41 | "MessageOptions.DisplayActionBar")) { 42 | plugin.getActionBarMgr().removeActionBar(p); 43 | } 44 | // check auto-reappear-option 45 | boolean noMsg = false; 46 | if (plugin.getSettings().getBoolean("VanishStateFeatures.ReappearOnQuit") 47 | || plugin.getSettings().getBoolean("VanishStateFeatures.CheckPermissionOnQuit") 48 | && !CommandAction.VANISH_SELF.checkPermission(p, plugin)) { 49 | plugin.getVanishStateMgr().setVanishedState(p.getUniqueId(), p.getName(), false, null); 50 | // check if it should handle the quit msg 51 | if (!config.getBoolean("MessageOptions.ReappearOnQuitHideLeaveMsg")) 52 | noMsg = true; 53 | } 54 | // check remove-quit-msg option 55 | if (!noMsg && config.getBoolean("MessageOptions.HideRealJoinQuitMessages")) { 56 | e.setQuitMessage(null); 57 | Broadcast.announceSilentQuit(p, plugin); 58 | } 59 | } 60 | // remove VanishPlayer 61 | plugin.removeVanishPlayer(plugin.getVanishPlayer(p)); 62 | } 63 | } catch (Exception er) { 64 | plugin.logException(er); 65 | } 66 | } 67 | } -------------------------------------------------------------------------------- /src/main/java/de/myzelyam/supervanish/listeners/TabCompleteListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015, Leon Mangler and the SuperVanish contributors 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * license, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | 9 | package de.myzelyam.supervanish.listeners; 10 | 11 | import de.myzelyam.supervanish.SuperVanish; 12 | import org.bukkit.Bukkit; 13 | import org.bukkit.entity.HumanEntity; 14 | import org.bukkit.entity.Player; 15 | import org.bukkit.event.EventHandler; 16 | import org.bukkit.event.Listener; 17 | import org.bukkit.event.server.TabCompleteEvent; 18 | 19 | import java.util.Iterator; 20 | import java.util.Locale; 21 | import java.util.Objects; 22 | import java.util.Set; 23 | import java.util.stream.Collectors; 24 | import java.util.stream.Stream; 25 | 26 | public class TabCompleteListener implements Listener { 27 | 28 | private final SuperVanish plugin; 29 | 30 | private boolean errorLogged = false; 31 | 32 | public TabCompleteListener(SuperVanish plugin) { 33 | this.plugin = plugin; 34 | } 35 | 36 | @EventHandler 37 | public void onTabComplete(TabCompleteEvent e) { 38 | try { 39 | if (!(e.getSender() instanceof Player)) return; 40 | Player p = (Player) e.getSender(); 41 | Set hiddenNames = plugin.getVanishStateMgr().getOnlineVanishedPlayers().stream() 42 | .map(Bukkit::getPlayer).filter(Objects::nonNull) 43 | .filter(vanishedPlayer -> !plugin.canSee(p, vanishedPlayer)) 44 | .map(HumanEntity::getName) 45 | .map(name -> name.toLowerCase(Locale.ENGLISH)) 46 | .collect(Collectors.toSet()); 47 | Iterator it = e.getCompletions().iterator(); 48 | while (it.hasNext()) { 49 | String completion = it.next(); 50 | boolean allowedCompletion = !hiddenNames.contains(completion.toLowerCase(Locale.ENGLISH)); 51 | if (!allowedCompletion) { 52 | it.remove(); 53 | } 54 | } 55 | } catch (UnsupportedOperationException uoe) { 56 | if (!errorLogged) { 57 | plugin.getLogger().warning("UnsupportedOperationException while modifying TabCompleteEvent"); 58 | errorLogged = true; 59 | } 60 | } catch (Exception er) { 61 | if (!errorLogged) { 62 | plugin.logException(er); 63 | errorLogged = true; 64 | } 65 | } 66 | } 67 | 68 | } 69 | -------------------------------------------------------------------------------- /src/main/java/de/myzelyam/supervanish/listeners/WorldChangeListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015, Leon Mangler and the SuperVanish contributors 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | 9 | package de.myzelyam.supervanish.listeners; 10 | 11 | import de.myzelyam.supervanish.SuperVanish; 12 | import de.myzelyam.supervanish.commands.CommandAction; 13 | 14 | import org.bukkit.entity.Player; 15 | import org.bukkit.event.EventHandler; 16 | import org.bukkit.event.EventPriority; 17 | import org.bukkit.event.Listener; 18 | import org.bukkit.event.player.PlayerChangedWorldEvent; 19 | 20 | public class WorldChangeListener implements Listener { 21 | 22 | private final SuperVanish plugin; 23 | 24 | public WorldChangeListener(SuperVanish plugin) { 25 | this.plugin = plugin; 26 | } 27 | 28 | @EventHandler(priority = EventPriority.MONITOR) 29 | public void onWorldChange(PlayerChangedWorldEvent e) { 30 | try { 31 | final Player p = e.getPlayer(); 32 | if (!plugin.getVanishStateMgr().isVanished(p.getUniqueId())) 33 | return; 34 | // check auto-reappear option 35 | if (plugin.getSettings().getBoolean("VanishStateFeatures.ReappearOnWorldChange") 36 | || plugin.getSettings().getBoolean("VanishStateFeatures.CheckPermissionOnWorldChange") 37 | && !CommandAction.VANISH_SELF.checkPermission(p, plugin)) { 38 | plugin.getVisibilityChanger().showPlayer(p); 39 | } 40 | } catch (Exception er) { 41 | plugin.logException(er); 42 | } 43 | } 44 | } -------------------------------------------------------------------------------- /src/main/java/de/myzelyam/supervanish/net/UpdateNotifier.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015, Leon Mangler and the SuperVanish contributors 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | 9 | package de.myzelyam.supervanish.net; 10 | 11 | import de.myzelyam.supervanish.SuperVanish; 12 | 13 | import org.bukkit.Bukkit; 14 | import org.bukkit.entity.Player; 15 | import org.bukkit.event.EventHandler; 16 | import org.bukkit.event.Listener; 17 | import org.bukkit.event.player.PlayerJoinEvent; 18 | import org.bukkit.scheduler.BukkitRunnable; 19 | import org.bukkit.scheduler.BukkitTask; 20 | 21 | import java.io.BufferedReader; 22 | import java.io.InputStreamReader; 23 | import java.net.URL; 24 | import java.util.HashSet; 25 | import java.util.Set; 26 | import java.util.UUID; 27 | import java.util.logging.Level; 28 | 29 | import javax.net.ssl.HttpsURLConnection; 30 | 31 | import lombok.Getter; 32 | 33 | public class UpdateNotifier { 34 | 35 | // 20 minutes 36 | private static final long CHECK_INTERVAL = 20 * 60 * 20; 37 | 38 | private final SuperVanish plugin; 39 | private final BukkitTask checkTask; 40 | @Getter 41 | private final String currentVersion; 42 | private final Set notifiedPlayers = new HashSet<>(); 43 | @Getter 44 | private volatile String latestVersion; 45 | private boolean notifiedConsole = false; 46 | 47 | public UpdateNotifier(final SuperVanish plugin) { 48 | this.plugin = plugin; 49 | currentVersion = plugin.getDescription().getVersion(); 50 | checkTask = start(); 51 | Bukkit.getPluginManager().registerEvents(new Listener() { 52 | @EventHandler 53 | public void onJoin(final PlayerJoinEvent e) { 54 | new BukkitRunnable() { 55 | @Override 56 | public void run() { 57 | if (!isUpToDate()) 58 | notifyPlayer(e.getPlayer()); 59 | } 60 | }.runTaskLater(plugin, 2); 61 | } 62 | }, plugin); 63 | } 64 | 65 | public boolean isUpToDate() { 66 | try { 67 | if (latestVersion == null) throw new NumberFormatException(); 68 | int comparision = plugin.getVersionUtil().compareVersions(currentVersion, latestVersion); 69 | return comparision >= 0; 70 | } catch (NumberFormatException e) { 71 | return currentVersion.equals(latestVersion); 72 | } 73 | } 74 | 75 | private void notifyPlayer(Player p) { 76 | if (p.hasPermission("sv.notify") && latestVersion != null) { 77 | if (notifiedPlayers.contains(p.getUniqueId())) return; 78 | notifiedPlayers.add(p.getUniqueId()); 79 | plugin.sendMessage(p, 80 | plugin.getMessage("PluginOutdated").replace("%new%", latestVersion) 81 | .replace("%current%", currentVersion), p); 82 | } 83 | } 84 | 85 | private void notifyAdmins() { 86 | for (Player p : plugin.getServer().getOnlinePlayers()) { 87 | notifyPlayer(p); 88 | } 89 | } 90 | 91 | private void notifyConsole() { 92 | if (!notifiedConsole) { 93 | plugin.log(Level.INFO, "Your current version of SuperVanish is outdated" + 94 | " - New version: '" + latestVersion + "'; Currently: '" + currentVersion + "'"); 95 | notifiedConsole = true; 96 | } 97 | } 98 | 99 | private BukkitTask start() { 100 | if (checkTask != null) throw new IllegalStateException("Task is already running"); 101 | return new BukkitRunnable() { 102 | @Override 103 | public void run() { 104 | String latestVersion = fetchLatestVersion(); 105 | UpdateNotifier.this.latestVersion = latestVersion.equals("Error") 106 | ? UpdateNotifier.this.latestVersion == null 107 | ? currentVersion 108 | : UpdateNotifier.this.latestVersion 109 | : latestVersion; 110 | if (!isUpToDate()) 111 | new BukkitRunnable() { 112 | @Override 113 | public void run() { 114 | notifyConsole(); 115 | if (plugin.getSettings().getBoolean( 116 | "MiscellaneousOptions.UpdateChecker.NotifyAdmins")) notifyAdmins(); 117 | } 118 | }.runTask(plugin); 119 | } 120 | }.runTaskTimerAsynchronously(plugin, 0, CHECK_INTERVAL); 121 | } 122 | 123 | private String fetchLatestVersion() { 124 | try { 125 | HttpsURLConnection con = (HttpsURLConnection) new URL( 126 | "https://api.spigotmc.org/legacy/update.php?resource=1331").openConnection(); 127 | con.setConnectTimeout(20 * 1000); 128 | con.setReadTimeout(20 * 1000); 129 | String version; 130 | try (BufferedReader reader = new BufferedReader(new InputStreamReader(con.getInputStream()))) { 131 | version = reader.readLine(); 132 | } 133 | con.disconnect(); 134 | if (version.length() <= 7) 135 | return version; 136 | else throw new RuntimeException("'" + version + "' is not a valid version"); 137 | } catch (Exception e) { 138 | plugin.log(Level.WARNING, "Failed to check for an update: " 139 | + e.getMessage()); 140 | return "Error"; 141 | } 142 | } 143 | } 144 | -------------------------------------------------------------------------------- /src/main/java/de/myzelyam/supervanish/utils/BukkitPlayerHidingUtil.java: -------------------------------------------------------------------------------- 1 | package de.myzelyam.supervanish.utils; 2 | 3 | import de.myzelyam.supervanish.SuperVanish; 4 | 5 | import org.bukkit.entity.Player; 6 | 7 | public class BukkitPlayerHidingUtil { 8 | 9 | private BukkitPlayerHidingUtil() { 10 | } 11 | 12 | public static void hidePlayer(Player player, Player viewer, SuperVanish plugin) { 13 | if (isNewPlayerHidingAPISupported(viewer)) 14 | viewer.hidePlayer(plugin, player); 15 | else 16 | //noinspection deprecation 17 | viewer.hidePlayer(player); 18 | } 19 | 20 | public static void showPlayer(Player player, Player viewer, SuperVanish plugin) { 21 | if (isNewPlayerHidingAPISupported(viewer)) 22 | viewer.showPlayer(plugin, player); 23 | else 24 | //noinspection deprecation 25 | viewer.showPlayer(player); 26 | } 27 | 28 | public static boolean isNewPlayerHidingAPISupported(Player testPlayer) { 29 | return false; // New API doesn't seem to work with SuperVanish 30 | /* 31 | Class playerClass = testPlayer.getClass(); 32 | try { 33 | playerClass.getMethod("hidePlayer", Plugin.class, Player.class); 34 | } catch (NoSuchMethodException e) { 35 | return false; 36 | } 37 | return true;*/ 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/de/myzelyam/supervanish/utils/ExceptionHandler.java: -------------------------------------------------------------------------------- 1 | package de.myzelyam.supervanish.utils; 2 | 3 | public interface ExceptionHandler { 4 | 5 | void handle(Exception e); 6 | } 7 | -------------------------------------------------------------------------------- /src/main/java/de/myzelyam/supervanish/utils/ExceptionLogger.java: -------------------------------------------------------------------------------- 1 | package de.myzelyam.supervanish.utils; 2 | 3 | import de.myzelyam.supervanish.SuperVanish; 4 | 5 | import org.bukkit.Bukkit; 6 | import org.bukkit.plugin.Plugin; 7 | 8 | import java.util.logging.Level; 9 | 10 | public class ExceptionLogger { 11 | 12 | private ExceptionLogger() { 13 | } 14 | 15 | public static void logException(Throwable e, SuperVanish plugin) { 16 | try { 17 | final boolean realEx = e != null; 18 | Level loggingLevel = realEx ? Level.WARNING : Level.INFO; 19 | if (realEx) plugin.log(loggingLevel, "Unknown exception occurred!"); 20 | else plugin.log(loggingLevel, "Printing information..."); 21 | if (plugin.getConfigMgr().isSettingsUpdateRequired() 22 | || plugin.getConfigMgr().isMessagesUpdateRequired()) { 23 | if (realEx) plugin.log(loggingLevel, "You have an outdated configuration, " + 24 | "regenerating it by using '/sv recreatefiles' might fix this problem!"); 25 | else plugin.log(loggingLevel, "Configuration is outdated."); 26 | } else if (realEx) plugin.log(loggingLevel, "Please report this issue!"); 27 | if (!realEx) e = new RuntimeException("Information for reporting an issue"); 28 | plugin.log(loggingLevel, "Message: "); 29 | plugin.log(loggingLevel, " " + e.getMessage()); 30 | plugin.log(loggingLevel, "General information: "); 31 | StringBuilder plugins = new StringBuilder(); 32 | for (Plugin pl : Bukkit.getServer().getPluginManager().getPlugins()) { 33 | if (pl.getName().equalsIgnoreCase("SuperVanish")) continue; 34 | plugins.append(pl.getName()).append(" v") 35 | .append(pl.getDescription().getVersion()).append(", "); 36 | } 37 | plugins = new StringBuilder(plugins.substring(0, plugins.length() - 1)); 38 | plugin.log(loggingLevel, " ServerVersion: " + plugin.getServer().getVersion()); 39 | plugin.log(loggingLevel, " PluginVersion: " 40 | + plugin.getDescription().getVersion()); 41 | plugin.log(loggingLevel, " ServerPlugins: " + plugins); 42 | try { 43 | plugin.log(loggingLevel, "Settings:"); 44 | plugin.log(loggingLevel, " MsgsVersion: " 45 | + plugin.getMessages().getString("MessagesVersion")); 46 | StringBuilder settings = new StringBuilder("||"); 47 | for (String key : plugin.getSettings().getKeys(true)) { 48 | if (!plugin.getSettings().getString(key).contains("MemorySection")) 49 | settings.append(key).append(">") 50 | .append(plugin.getSettings().getString(key)).append("||"); 51 | } 52 | plugin.log(loggingLevel, " Settings: " + settings); 53 | } catch (Exception er) { 54 | plugin.log(Level.SEVERE, ">> Error occurred while trying to print config info <<"); 55 | } 56 | plugin.log(loggingLevel, "StackTrace: "); 57 | e.printStackTrace(); 58 | if (realEx) { 59 | if (plugin.getConfigMgr().isSettingsUpdateRequired() 60 | || plugin.getConfigMgr().isMessagesUpdateRequired()) 61 | plugin.log(loggingLevel, "You have an outdated configuration, " + 62 | "regenerating it by using '/sv recreatefiles' might fix this problem!"); 63 | plugin.log(loggingLevel, "Please include this information"); 64 | plugin.log(loggingLevel, "if you report the issue."); 65 | } else 66 | plugin.log(loggingLevel, "End of information."); 67 | } catch (Exception e2) { 68 | plugin.log(Level.WARNING, 69 | "An exception occurred while trying to print a detailed stacktrace, " + 70 | "printing an undetailed stacktrace of both exceptions:"); 71 | plugin.log(Level.SEVERE, "ORIGINAL EXCEPTION:"); 72 | if (e != null) { 73 | e.printStackTrace(); 74 | } 75 | plugin.log(Level.SEVERE, "SECOND EXCEPTION:"); 76 | e2.printStackTrace(); 77 | } 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/main/java/de/myzelyam/supervanish/utils/Requirement.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015, Leon Mangler and the SuperVanish contributors 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * license, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | 9 | package de.myzelyam.supervanish.utils; 10 | 11 | public interface Requirement { 12 | boolean fulfilledBy(T testSubject); 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/de/myzelyam/supervanish/utils/Validation.java: -------------------------------------------------------------------------------- 1 | package de.myzelyam.supervanish.utils; 2 | 3 | import org.bukkit.Bukkit; 4 | 5 | import java.util.logging.Level; 6 | 7 | public abstract class Validation { 8 | 9 | public static void checkNotNull(Object... objects) { 10 | checkNotNull(null, objects); 11 | } 12 | 13 | public static void checkIsTrue(boolean... bool) { 14 | checkIsTrue(null, bool); 15 | } 16 | 17 | public static void checkNotNull(String message, Object... objects) { 18 | for (Object obj : objects) { 19 | if (obj == null) { 20 | if (message != null) 21 | log(Level.SEVERE, message); 22 | throw new IllegalArgumentException(message == null ? "" : message); 23 | } 24 | } 25 | } 26 | 27 | 28 | public static void checkIsTrue(String message, boolean... booleans) { 29 | for (boolean bool : booleans) { 30 | if (!bool) { 31 | if (message != null) 32 | log(Level.SEVERE, message); 33 | throw new IllegalArgumentException(message == null ? "" : message); 34 | } 35 | } 36 | } 37 | 38 | private static void log(Level level, String message) { 39 | try { 40 | Class.forName("org.bukkit.plugin.java.JavaPlugin"); 41 | Bukkit.getLogger().log(level, message); 42 | } catch (ClassNotFoundException e) { 43 | e.printStackTrace(); 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/de/myzelyam/supervanish/utils/VersionUtil.java: -------------------------------------------------------------------------------- 1 | package de.myzelyam.supervanish.utils; 2 | 3 | import de.myzelyam.supervanish.SuperVanish; 4 | 5 | import java.util.regex.Pattern; 6 | 7 | public class VersionUtil { 8 | 9 | private final SuperVanish plugin; 10 | private final String minecraftVersion; 11 | 12 | public VersionUtil(SuperVanish plugin) { 13 | this.plugin = plugin; 14 | // saves versions in the format x.x.x (e.g. 1.20.1) 15 | minecraftVersion = plugin.getServer().getBukkitVersion().split(Pattern.quote("-"))[0]; 16 | } 17 | 18 | public int compareVersions(String version1, String version2) { 19 | String[] levels1 = version1.split("\\."); 20 | String[] levels2 = version2.split("\\."); 21 | int length = Math.max(levels1.length, levels2.length); 22 | for (int i = 0; i < length; i++) { 23 | Integer v1 = i < levels1.length ? Integer.parseInt(levels1[i]) : 0; 24 | Integer v2 = i < levels2.length ? Integer.parseInt(levels2[i]) : 0; 25 | int compare = v1.compareTo(v2); 26 | if (compare != 0) { 27 | return compare; 28 | } 29 | } 30 | return 0; 31 | } 32 | 33 | public boolean isOneDotX(int majorRelease) { 34 | return minecraftVersion.equals("1." + majorRelease) || minecraftVersion.startsWith("1." + majorRelease + "."); 35 | } 36 | 37 | public boolean isOneDotXOrHigher(int majorRelease) { 38 | for (int i = majorRelease; i < 40; i++) 39 | if (minecraftVersion.equals("1." + i) || minecraftVersion.startsWith("1." + i + ".")) return true; 40 | return minecraftVersion.startsWith("2."); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/de/myzelyam/supervanish/visibility/ActionBarMgr.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015, Leon Mangler and the SuperVanish contributors 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | 9 | package de.myzelyam.supervanish.visibility; 10 | 11 | import com.comphenix.protocol.PacketType; 12 | import com.comphenix.protocol.ProtocolLibrary; 13 | import com.comphenix.protocol.events.PacketContainer; 14 | import com.comphenix.protocol.wrappers.EnumWrappers; 15 | import com.comphenix.protocol.wrappers.WrappedChatComponent; 16 | import de.myzelyam.supervanish.SuperVanish; 17 | import net.md_5.bungee.api.ChatMessageType; 18 | import net.md_5.bungee.api.chat.TextComponent; 19 | import org.bukkit.ChatColor; 20 | import org.bukkit.entity.Player; 21 | import org.bukkit.scheduler.BukkitRunnable; 22 | 23 | import java.lang.reflect.InvocationTargetException; 24 | import java.util.ArrayList; 25 | import java.util.List; 26 | 27 | public class ActionBarMgr { 28 | 29 | private final SuperVanish plugin; 30 | private final List actionBars = new ArrayList<>(); 31 | 32 | public ActionBarMgr(SuperVanish plugin) { 33 | this.plugin = plugin; 34 | startTask(); 35 | } 36 | 37 | private void startTask() { 38 | new BukkitRunnable() { 39 | 40 | @Override 41 | public void run() { 42 | for (Player p : actionBars) { 43 | try { 44 | sendActionBar(p, plugin.replacePlaceholders(plugin.getMessage("ActionBarMessage"), p)); 45 | } catch (Exception | NoSuchMethodError | NoClassDefFoundError e) { 46 | cancel(); 47 | plugin.logException(e); 48 | plugin.getLogger().warning("IMPORTANT: Please make sure that you are using the latest " + 49 | "dev-build of ProtocolLib and that your server is up-to-date! This error likely " + 50 | "happened inside of ProtocolLib code which is out of SuperVanish's control. It's part " + 51 | "of an optional feature module and can be removed safely by disabling " + 52 | "DisplayActionBar in the config file. Please report this " + 53 | "error if you can reproduce it on an up-to-date server with only latest " + 54 | "ProtocolLib and latest SV installed."); 55 | } 56 | } 57 | } 58 | }.runTaskTimer(plugin, 0, 2 * 20); 59 | } 60 | 61 | private void sendActionBar(Player p, String bar) { 62 | try { 63 | Class.forName("net.md_5.bungee.api.chat.ComponentBuilder"); 64 | p.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(bar)); 65 | } catch (ClassNotFoundException | NoSuchMethodError | NoClassDefFoundError er) { 66 | String json = "{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', bar) + "\"}"; 67 | WrappedChatComponent msg = WrappedChatComponent.fromJson(json); 68 | PacketContainer chatMsg = new PacketContainer(PacketType.Play.Server.CHAT); 69 | chatMsg.getChatComponents().write(0, msg); 70 | if (plugin.getVersionUtil().isOneDotXOrHigher(12)) 71 | try { 72 | chatMsg.getChatTypes().write(0, EnumWrappers.ChatType.GAME_INFO); 73 | } catch (NoSuchMethodError e) { 74 | p.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText 75 | ("SuperVanish: Please update ProtocolLib")); 76 | } 77 | else 78 | chatMsg.getBytes().write(0, (byte) 2); 79 | try { 80 | ProtocolLibrary.getProtocolManager().sendServerPacket(p, chatMsg); 81 | } catch (InvocationTargetException e) { 82 | throw new RuntimeException("Cannot send packet " + chatMsg, e); 83 | } 84 | } 85 | } 86 | 87 | public void addActionBar(Player p) { 88 | actionBars.add(p); 89 | } 90 | 91 | public void removeActionBar(Player p) { 92 | actionBars.remove(p); 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /src/main/java/de/myzelyam/supervanish/visibility/FileVanishStateMgr.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015, Leon Mangler and the SuperVanish contributors 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | 9 | package de.myzelyam.supervanish.visibility; 10 | 11 | import de.myzelyam.api.vanish.PlayerVanishStateChangeEvent; 12 | import de.myzelyam.supervanish.SuperVanish; 13 | 14 | import org.bukkit.Bukkit; 15 | 16 | import java.util.ArrayList; 17 | import java.util.Collection; 18 | import java.util.HashSet; 19 | import java.util.List; 20 | import java.util.Set; 21 | import java.util.UUID; 22 | import java.util.logging.Level; 23 | 24 | public class FileVanishStateMgr extends VanishStateMgr { 25 | 26 | private final SuperVanish plugin; 27 | 28 | public FileVanishStateMgr(SuperVanish plugin) { 29 | super(plugin); 30 | this.plugin = plugin; 31 | } 32 | 33 | @Override 34 | public boolean isVanished(final UUID uuid) { 35 | return getVanishedPlayersOnFile().contains(uuid); 36 | } 37 | 38 | @Override 39 | public void setVanishedState(final UUID uuid, String name, boolean hide, String causeName) { 40 | PlayerVanishStateChangeEvent event = new PlayerVanishStateChangeEvent(uuid, name, hide, causeName); 41 | Bukkit.getPluginManager().callEvent(event); 42 | if (event.isCancelled()) return; 43 | List vanishedPlayerUUIDStrings = plugin.getPlayerData().getStringList("InvisiblePlayers"); 44 | if (hide) 45 | vanishedPlayerUUIDStrings.add(uuid.toString()); 46 | else 47 | vanishedPlayerUUIDStrings.remove(uuid.toString()); 48 | plugin.getPlayerData().set("InvisiblePlayers", vanishedPlayerUUIDStrings); 49 | if (hide) 50 | plugin.getPlayerData().set("PlayerData." + uuid + ".information.name", name); 51 | plugin.getConfigMgr().getPlayerDataFile().save(); 52 | } 53 | 54 | @Override 55 | public Set getVanishedPlayers() { 56 | return getVanishedPlayersOnFile(); 57 | } 58 | 59 | @Override 60 | public Collection getOnlineVanishedPlayers() { 61 | Set onlineVanishedPlayers = new HashSet<>(); 62 | for (UUID vanishedUUID : getVanishedPlayers()) { 63 | if (Bukkit.getPlayer(vanishedUUID) != null) 64 | onlineVanishedPlayers.add(vanishedUUID); 65 | } 66 | return onlineVanishedPlayers; 67 | } 68 | 69 | public UUID getVanishedUUIDFromNameOnFile(String name) { 70 | for (UUID uuid : getVanishedPlayersOnFile()) { 71 | if (plugin.getPlayerData().getString("PlayerData." + uuid + ".information.name") 72 | .equalsIgnoreCase(name)) { 73 | return uuid; 74 | } 75 | } 76 | return null; 77 | } 78 | 79 | private Set getVanishedPlayersOnFile() { 80 | List vanishedPlayerUUIDStrings = plugin.getPlayerData().getStringList("InvisiblePlayers"); 81 | Set vanishedPlayerUUIDs = new HashSet<>(); 82 | for (String uuidString : new ArrayList<>(vanishedPlayerUUIDStrings)) { 83 | try { 84 | vanishedPlayerUUIDs.add(UUID.fromString(uuidString)); 85 | } catch (IllegalArgumentException e) { 86 | vanishedPlayerUUIDStrings.remove(uuidString); 87 | plugin.log(Level.WARNING, 88 | "The data.yml file contains an invalid player uuid," + 89 | " deleting it."); 90 | plugin.getPlayerData().set("InvisiblePlayers", vanishedPlayerUUIDStrings); 91 | plugin.getConfigMgr().getPlayerDataFile().save(); 92 | } 93 | } 94 | return vanishedPlayerUUIDs; 95 | } 96 | 97 | private void setVanishedPlayersOnFile(Set vanishedPlayers) { 98 | List vanishedPlayerUUIDStrings = new ArrayList<>(); 99 | for (UUID uuid : vanishedPlayers) 100 | vanishedPlayerUUIDStrings.add(uuid.toString()); 101 | plugin.getPlayerData().set("InvisiblePlayers", 102 | vanishedPlayerUUIDStrings); 103 | plugin.getConfigMgr().getPlayerDataFile().save(); 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /src/main/java/de/myzelyam/supervanish/visibility/PaperServerPingListener.java: -------------------------------------------------------------------------------- 1 | package de.myzelyam.supervanish.visibility; 2 | 3 | import com.destroystokyo.paper.event.server.PaperServerListPingEvent; 4 | import com.destroystokyo.paper.profile.PlayerProfile; 5 | import de.myzelyam.supervanish.SuperVanish; 6 | import org.bukkit.Bukkit; 7 | import org.bukkit.configuration.file.FileConfiguration; 8 | import org.bukkit.event.EventHandler; 9 | import org.bukkit.event.EventPriority; 10 | import org.bukkit.event.Listener; 11 | 12 | import java.util.Collection; 13 | import java.util.List; 14 | import java.util.UUID; 15 | 16 | public class PaperServerPingListener implements Listener { 17 | 18 | private boolean errorLogged = false; 19 | 20 | private final SuperVanish plugin; 21 | 22 | public PaperServerPingListener(SuperVanish plugin) { 23 | this.plugin = plugin; 24 | } 25 | 26 | @EventHandler(priority = EventPriority.HIGH) 27 | public void onServerListPing(PaperServerListPingEvent e) { 28 | try { 29 | final FileConfiguration settings = plugin.getSettings(); 30 | if (!settings.getBoolean("ExternalInvisibility.ServerList.AdjustAmountOfOnlinePlayers") 31 | && !settings.getBoolean("ExternalInvisibility.ServerList.AdjustListOfLoggedInPlayers")) 32 | return; 33 | Collection onlineVanishedPlayers = plugin.getVanishStateMgr().getOnlineVanishedPlayers(); 34 | int vanishedPlayersCount = onlineVanishedPlayers.size(), 35 | playerCount = Bukkit.getOnlinePlayers().size(); 36 | if (settings.getBoolean("ExternalInvisibility.ServerList.AdjustAmountOfOnlinePlayers")) { 37 | e.setNumPlayers(playerCount - vanishedPlayersCount); 38 | } 39 | if (settings.getBoolean("ExternalInvisibility.ServerList.AdjustListOfLoggedInPlayers")) { 40 | List playerSample = e.getPlayerSample(); 41 | 42 | playerSample.removeIf(profile -> onlineVanishedPlayers.contains(profile.getId())); 43 | } 44 | } catch (Exception er) { 45 | if (!errorLogged) { 46 | plugin.logException(er); 47 | errorLogged = true; 48 | } 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/de/myzelyam/supervanish/visibility/ServerListPacketListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015, Leon Mangler and the SuperVanish contributors 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | 9 | package de.myzelyam.supervanish.visibility; 10 | 11 | import com.comphenix.protocol.PacketType; 12 | import com.comphenix.protocol.ProtocolLibrary; 13 | import com.comphenix.protocol.events.ListenerPriority; 14 | import com.comphenix.protocol.events.PacketAdapter; 15 | import com.comphenix.protocol.events.PacketEvent; 16 | import com.comphenix.protocol.wrappers.WrappedGameProfile; 17 | import com.comphenix.protocol.wrappers.WrappedServerPing; 18 | 19 | import de.myzelyam.supervanish.SuperVanish; 20 | 21 | import org.bukkit.Bukkit; 22 | import org.bukkit.configuration.file.FileConfiguration; 23 | 24 | import java.util.ArrayList; 25 | import java.util.Collection; 26 | import java.util.Iterator; 27 | import java.util.List; 28 | import java.util.UUID; 29 | import java.util.logging.Level; 30 | 31 | public class ServerListPacketListener extends PacketAdapter { 32 | 33 | private final SuperVanish plugin; 34 | 35 | private boolean errorLogged = false; 36 | 37 | public ServerListPacketListener(SuperVanish plugin) { 38 | super(plugin, ListenerPriority.NORMAL, PacketType.Status.Server.SERVER_INFO); 39 | this.plugin = plugin; 40 | } 41 | 42 | /** 43 | * Constructor for legacy ProtocolLib API 44 | */ 45 | public ServerListPacketListener(SuperVanish plugin, boolean use_legacy) { 46 | //noinspection deprecation 47 | super(plugin, ListenerPriority.NORMAL, PacketType.Status.Server.OUT_SERVER_INFO); 48 | this.plugin = plugin; 49 | } 50 | 51 | public static void register(SuperVanish plugin) { 52 | // Use Paper event listener if available 53 | try { 54 | Class.forName("com.destroystokyo.paper.event.server.PaperServerListPingEvent"); 55 | plugin.getLogger().log(Level.INFO, "Hooked into PaperSpigot for server list ping support"); 56 | plugin.getServer().getPluginManager().registerEvents(new PaperServerPingListener(plugin), plugin); 57 | } catch (ClassNotFoundException ignored) { 58 | // Otherwise use ProtocolLib 59 | if (plugin.getVersionUtil().isOneDotXOrHigher(19)) { 60 | ProtocolLibrary.getProtocolManager().addPacketListener(new ServerListPacketListener(plugin)); 61 | } else { 62 | ProtocolLibrary.getProtocolManager().addPacketListener(new ServerListPacketListener(plugin, true)); 63 | } 64 | } 65 | } 66 | 67 | public static boolean isEnabled(SuperVanish plugin) { 68 | final FileConfiguration config = plugin.getSettings(); 69 | return config.getBoolean( 70 | "ExternalInvisibility.ServerList.AdjustAmountOfOnlinePlayers") 71 | || config.getBoolean( 72 | "ExternalInvisibility.ServerList.AdjustListOfLoggedInPlayers"); 73 | } 74 | 75 | @Override 76 | public void onPacketSending(PacketEvent e) { 77 | try { 78 | final FileConfiguration settings = plugin.getSettings(); 79 | if (!settings.getBoolean("ExternalInvisibility.ServerList.AdjustAmountOfOnlinePlayers") 80 | && !settings.getBoolean("ExternalInvisibility.ServerList.AdjustListOfLoggedInPlayers")) 81 | return; 82 | WrappedServerPing ping = e.getPacket().getServerPings().read(0); 83 | Collection onlineVanishedPlayers = plugin.getVanishStateMgr().getOnlineVanishedPlayers(); 84 | int vanishedPlayersCount = plugin.getVanishStateMgr().getOnlineVanishedPlayers().size(), 85 | playerCount = Bukkit.getOnlinePlayers().size(); 86 | if (settings.getBoolean("ExternalInvisibility.ServerList.AdjustAmountOfOnlinePlayers")) { 87 | ping.setPlayersOnline(playerCount - vanishedPlayersCount); 88 | } 89 | if (settings.getBoolean("ExternalInvisibility.ServerList.AdjustListOfLoggedInPlayers")) { 90 | List wrappedGameProfiles = new ArrayList<>(ping.getPlayers()); 91 | Iterator iterator = wrappedGameProfiles.iterator(); 92 | while (iterator.hasNext()) { 93 | if (onlineVanishedPlayers.contains(iterator.next().getUUID())) { 94 | iterator.remove(); 95 | } 96 | } 97 | ping.setPlayers(wrappedGameProfiles); 98 | } 99 | e.getPacket().getServerPings().write(0, ping); 100 | } catch (Exception er) { 101 | if (!errorLogged) { 102 | if (er.getMessage() != null && er.getMessage().contains("Unable to construct new instance using public net.minecraft.network.protocol.status.ServerPing")) { 103 | plugin.getLogger().warning("The spigot-sided serverlist features are not supported by ProtocolLib on your server. Please make sure you are using the latest ProtocolLib dev build. (" + er.getMessage() + ")\n"); 104 | } else if (er.getMessage() != null && er.getMessage().contains("Cannot assign field \"online\" because \"this.playerSample\" is null")) { 105 | plugin.getLogger().warning("The spigot-sided serverlist features are not supported yet by ProtocolLib. Please make sure you are using the latest ProtocolLib dev build."); 106 | } else { 107 | plugin.logException(er); 108 | } 109 | errorLogged = true; 110 | } 111 | } 112 | } 113 | } -------------------------------------------------------------------------------- /src/main/java/de/myzelyam/supervanish/visibility/VanishStateMgr.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015, Leon Mangler and the SuperVanish contributors 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | 9 | package de.myzelyam.supervanish.visibility; 10 | 11 | import de.myzelyam.supervanish.SuperVanishPlugin; 12 | 13 | import java.util.Collection; 14 | import java.util.Set; 15 | import java.util.UUID; 16 | 17 | public abstract class VanishStateMgr { 18 | 19 | protected final SuperVanishPlugin plugin; 20 | 21 | public VanishStateMgr(SuperVanishPlugin plugin) { 22 | this.plugin = plugin; 23 | } 24 | 25 | public abstract boolean isVanished(final UUID uuid); 26 | 27 | public abstract void setVanishedState(final UUID uuid, String name, boolean hide, String causeName); 28 | 29 | public final void setVanishedState(final UUID uuid, String name, boolean hide) { 30 | setVanishedState(uuid, name, hide, null); 31 | } 32 | 33 | public abstract Set getVanishedPlayers(); 34 | 35 | public abstract Collection getOnlineVanishedPlayers(); 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/de/myzelyam/supervanish/visibility/hiders/PlayerHider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015, Leon Mangler and the SuperVanish contributors 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | 9 | package de.myzelyam.supervanish.visibility.hiders; 10 | 11 | import com.google.common.collect.ImmutableSet; 12 | 13 | import de.myzelyam.supervanish.SuperVanish; 14 | 15 | import org.bukkit.entity.Player; 16 | import org.bukkit.event.EventHandler; 17 | import org.bukkit.event.EventPriority; 18 | import org.bukkit.event.Listener; 19 | import org.bukkit.event.player.PlayerQuitEvent; 20 | 21 | import java.util.HashSet; 22 | import java.util.Map; 23 | import java.util.Set; 24 | import java.util.UUID; 25 | import java.util.concurrent.ConcurrentHashMap; 26 | 27 | public abstract class PlayerHider implements Listener { 28 | 29 | protected final SuperVanish plugin; 30 | protected final Map> playerHiddenFromPlayersMap = new ConcurrentHashMap<>(); 31 | 32 | public PlayerHider(SuperVanish plugin) { 33 | this.plugin = plugin; 34 | registerQuitListener(); 35 | } 36 | 37 | public abstract String getName(); 38 | 39 | public boolean isHidden(Player player, Player viewer) { 40 | return !player.getUniqueId().equals(viewer.getUniqueId()) 41 | && playerHiddenFromPlayersMap.containsKey(player) 42 | && playerHiddenFromPlayersMap.get(player).contains(viewer); 43 | } 44 | 45 | public boolean isHidden(UUID playerUUID, Player viewer) { 46 | if (playerUUID.equals(viewer.getUniqueId())) return false; 47 | for (Player p : playerHiddenFromPlayersMap.keySet()) { 48 | if (p.getUniqueId().equals(playerUUID)) { 49 | return playerHiddenFromPlayersMap.get(p).contains(viewer); 50 | } 51 | } 52 | return false; 53 | } 54 | 55 | public boolean isHidden(String playerName, Player viewer) { 56 | if (playerName.equalsIgnoreCase(viewer.getName())) return false; 57 | for (Player p : playerHiddenFromPlayersMap.keySet()) { 58 | if (p.getName().equalsIgnoreCase(playerName)) { 59 | return playerHiddenFromPlayersMap.get(p).contains(viewer); 60 | } 61 | } 62 | return false; 63 | } 64 | 65 | /** 66 | * @return TRUE if the operation changed the state, FALSE if it did not 67 | */ 68 | public boolean setHidden(Player player, Player viewer, boolean hidden) { 69 | if (!playerHiddenFromPlayersMap.containsKey(player)) 70 | playerHiddenFromPlayersMap.put(player, new HashSet()); 71 | if (viewer == player) return false; 72 | Set hiddenFromPlayers = playerHiddenFromPlayersMap.get(player); 73 | if (hidden && !hiddenFromPlayers.contains(viewer)) { 74 | hiddenFromPlayers.add(viewer); 75 | return true; 76 | } else if (!hidden && hiddenFromPlayers.contains(viewer)) { 77 | hiddenFromPlayers.remove(viewer); 78 | return true; 79 | } 80 | return false; 81 | } 82 | 83 | public Set getHiddenPlayerKeys() { 84 | return playerHiddenFromPlayersMap.keySet(); 85 | } 86 | 87 | private void registerQuitListener() { 88 | plugin.getServer().getPluginManager().registerEvents(new Listener() { 89 | 90 | @EventHandler(priority = EventPriority.MONITOR) 91 | public void onQuit(final PlayerQuitEvent e) { 92 | plugin.getServer().getScheduler().runTaskLater(plugin, new Runnable() { 93 | @Override 94 | public void run() { 95 | playerHiddenFromPlayersMap.remove(e.getPlayer()); 96 | for (Player p : ImmutableSet.copyOf(playerHiddenFromPlayersMap.keySet())) { 97 | playerHiddenFromPlayersMap.get(p).remove(e.getPlayer()); 98 | } 99 | } 100 | }, 1); 101 | } 102 | }, plugin); 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /src/main/java/de/myzelyam/supervanish/visibility/hiders/PreventionHider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015, Leon Mangler and the SuperVanish contributors 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | 9 | package de.myzelyam.supervanish.visibility.hiders; 10 | 11 | import de.myzelyam.supervanish.SuperVanish; 12 | import de.myzelyam.supervanish.utils.BukkitPlayerHidingUtil; 13 | import de.myzelyam.supervanish.visibility.hiders.modules.PlayerInfoModule; 14 | import de.myzelyam.supervanish.visibility.hiders.modules.TabCompleteModule; 15 | import org.bukkit.entity.Player; 16 | 17 | public class PreventionHider extends PlayerHider implements Runnable { 18 | 19 | private int taskId; 20 | 21 | public PreventionHider(SuperVanish plugin) { 22 | super(plugin); 23 | taskId = plugin.getServer().getScheduler().runTaskTimer(plugin, this, 1, 1).getTaskId(); 24 | if (plugin.isUseProtocolLib() && plugin.getVersionUtil().isOneDotXOrHigher(8) 25 | && !plugin.getVersionUtil().isOneDotXOrHigher(19) 26 | && plugin.getSettings().getBoolean("InvisibilityFeatures.ModifyTablistPackets", true)) 27 | PlayerInfoModule.register(plugin, this); 28 | if (plugin.isUseProtocolLib() 29 | && plugin.getSettings().getBoolean("InvisibilityFeatures.ModifyTabCompletePackets", true)) 30 | TabCompleteModule.register(plugin, this); 31 | } 32 | 33 | @Override 34 | public boolean setHidden(Player player, Player viewer, boolean hide) { 35 | boolean wasHidden = isHidden(player, viewer); 36 | 37 | if (!wasHidden && hide && player != viewer) { 38 | BukkitPlayerHidingUtil.hidePlayer(player, viewer, plugin); 39 | } 40 | 41 | boolean stateChanged = super.setHidden(player, viewer, hide); 42 | 43 | if (wasHidden && !hide && player != viewer) { 44 | BukkitPlayerHidingUtil.showPlayer(player, viewer, plugin); 45 | } 46 | return stateChanged; 47 | } 48 | 49 | @Override 50 | public String getName() { 51 | return "Prevention"; 52 | } 53 | 54 | @Override 55 | public void run() { 56 | for (Player hidden : playerHiddenFromPlayersMap.keySet()) { 57 | if (BukkitPlayerHidingUtil.isNewPlayerHidingAPISupported(hidden)) { 58 | plugin.getServer().getScheduler().cancelTask(taskId); 59 | return; 60 | } 61 | for (Player viewer : playerHiddenFromPlayersMap.get(hidden)) { 62 | BukkitPlayerHidingUtil.hidePlayer(hidden, viewer, plugin); 63 | } 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/main/java/de/myzelyam/supervanish/visibility/hiders/modules/PlayerInfoModule.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015, Leon Mangler and the SuperVanish contributors 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * license, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | 9 | package de.myzelyam.supervanish.visibility.hiders.modules; 10 | 11 | import com.comphenix.protocol.PacketType; 12 | import com.comphenix.protocol.ProtocolLibrary; 13 | import com.comphenix.protocol.events.ListenerPriority; 14 | import com.comphenix.protocol.events.PacketAdapter; 15 | import com.comphenix.protocol.events.PacketEvent; 16 | import com.comphenix.protocol.wrappers.PlayerInfoData; 17 | import com.google.common.collect.ImmutableList; 18 | import de.myzelyam.supervanish.SuperVanish; 19 | import de.myzelyam.supervanish.visibility.hiders.PlayerHider; 20 | import org.bukkit.entity.Player; 21 | 22 | import java.util.ArrayList; 23 | import java.util.List; 24 | 25 | /** 26 | * This is currently unused on Minecraft 1.19 or higher 27 | */ 28 | public class PlayerInfoModule extends PacketAdapter { 29 | 30 | private final PlayerHider hider; 31 | private final SuperVanish plugin; 32 | 33 | private boolean errorLogged = false; 34 | 35 | public PlayerInfoModule(SuperVanish plugin, PlayerHider hider) { 36 | super(plugin, ListenerPriority.HIGH, PacketType.Play.Server.PLAYER_INFO); 37 | this.plugin = plugin; 38 | this.hider = hider; 39 | } 40 | 41 | public static void register(SuperVanish plugin, PlayerHider hider) { 42 | ProtocolLibrary.getProtocolManager().addPacketListener(new PlayerInfoModule(plugin, hider)); 43 | } 44 | 45 | @Override 46 | public void onPacketSending(PacketEvent event) { 47 | // multiple events share same packet object 48 | event.setPacket(event.getPacket().shallowClone()); 49 | try { 50 | List infoDataList = new ArrayList<>(event.getPacket().getPlayerInfoDataLists().read(0)); 51 | 52 | Player receiver = event.getPlayer(); 53 | for (PlayerInfoData infoData : ImmutableList.copyOf(infoDataList)) { 54 | if (hider.isHidden(infoData.getProfile().getUUID(), receiver)) { 55 | infoDataList.remove(infoData); 56 | } 57 | } 58 | if (infoDataList.isEmpty()) { 59 | event.setCancelled(true); 60 | } 61 | event.getPacket().getPlayerInfoDataLists().write(0, infoDataList); 62 | } catch (Exception | NoClassDefFoundError e) { 63 | if (e.getMessage() == null 64 | || !e.getMessage().endsWith("is not supported for temporary players.")) { 65 | if (errorLogged) return; 66 | plugin.logException(e); 67 | plugin.getLogger().warning("IMPORTANT: Please make sure that you are using the latest " + 68 | "dev-build of ProtocolLib and that your server is up-to-date! This error likely " + 69 | "happened inside of ProtocolLib code which is out of SuperVanish's control. It's part " + 70 | "of an optional invisibility module and can be removed safely by disabling " + 71 | "ModifyTablistPackets in the config. Please report this " + 72 | "error if you can reproduce it on an up-to-date server with only latest " + 73 | "ProtocolLib and latest SV installed."); 74 | errorLogged = true; 75 | } 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/main/java/de/myzelyam/supervanish/visibility/hiders/modules/TabCompleteModule.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2015, Leon Mangler and the SuperVanish contributors 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * license, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | 9 | package de.myzelyam.supervanish.visibility.hiders.modules; 10 | 11 | import com.comphenix.protocol.PacketType; 12 | import com.comphenix.protocol.ProtocolLibrary; 13 | import com.comphenix.protocol.events.ListenerPriority; 14 | import com.comphenix.protocol.events.PacketAdapter; 15 | import com.comphenix.protocol.events.PacketEvent; 16 | import com.comphenix.protocol.reflect.FieldAccessException; 17 | import com.mojang.brigadier.suggestion.Suggestion; 18 | import com.mojang.brigadier.suggestion.Suggestions; 19 | import de.myzelyam.supervanish.SuperVanish; 20 | import de.myzelyam.supervanish.visibility.hiders.PlayerHider; 21 | 22 | import java.util.ArrayList; 23 | import java.util.Arrays; 24 | import java.util.Iterator; 25 | import java.util.List; 26 | 27 | public class TabCompleteModule extends PacketAdapter { 28 | private final PlayerHider hider; 29 | private final SuperVanish plugin; 30 | 31 | private boolean errorLogged = false; 32 | 33 | public TabCompleteModule(SuperVanish plugin, PlayerHider hider) { 34 | super(plugin, ListenerPriority.HIGH, PacketType.Play.Server.TAB_COMPLETE); 35 | this.plugin = plugin; 36 | this.hider = hider; 37 | } 38 | 39 | public static void register(SuperVanish plugin, PlayerHider hider) { 40 | ProtocolLibrary.getProtocolManager().addPacketListener(new TabCompleteModule(plugin, hider)); 41 | } 42 | 43 | 44 | @Override 45 | public void onPacketSending(PacketEvent event) { 46 | try { 47 | if (plugin.getVersionUtil().isOneDotXOrHigher(13)) { 48 | try { 49 | Suggestions suggestions = event.getPacket().getSpecificModifier(Suggestions.class).read(0); 50 | Iterator iterator = suggestions.getList().iterator(); 51 | boolean containsHiddenPlayer = false; 52 | while (iterator.hasNext()) { 53 | Suggestion suggestion = iterator.next(); 54 | String completion = suggestion.getText(); 55 | if (completion.contains("/")) continue; 56 | if (hider.isHidden(completion, event.getPlayer())) { 57 | iterator.remove(); 58 | containsHiddenPlayer = true; 59 | } 60 | } 61 | if (containsHiddenPlayer) { 62 | event.getPacket().getSpecificModifier(Suggestions.class).write(0, suggestions); 63 | } 64 | } catch (FieldAccessException e) { 65 | if (errorLogged) return; 66 | plugin.getLogger().warning("Could not intercept tab-completions using ProtocolLib: " 67 | + e.getMessage()); 68 | errorLogged = true; 69 | } 70 | } else { 71 | String[] suggestions = event.getPacket().getStringArrays().read(0); 72 | boolean containsHiddenPlayer = false; 73 | List suggestionList = new ArrayList<>(Arrays.asList(suggestions)); 74 | for (String suggestion : suggestions) { 75 | if (suggestion.contains("/")) continue; 76 | if (hider.isHidden(suggestion, event.getPlayer())) { 77 | suggestionList.remove(suggestion); 78 | containsHiddenPlayer = true; 79 | } 80 | } 81 | if (containsHiddenPlayer) { 82 | event.getPacket().getStringArrays().write(0, 83 | suggestionList.toArray(new String[suggestionList.size()])); 84 | } 85 | } 86 | } catch (Exception | NoClassDefFoundError e) { 87 | if (e.getMessage() == null 88 | || !e.getMessage().endsWith("is not supported for temporary players.")) { 89 | if (errorLogged) return; 90 | plugin.logException(e); 91 | plugin.getLogger().warning("IMPORTANT: Please make sure that you are using the latest " + 92 | "dev-build of ProtocolLib and that your server is up-to-date! This error likely " + 93 | "happened inside of ProtocolLib code which is out of SuperVanish's control. It's part " + 94 | "of an optional invisibility module and can be removed safely by disabling " + 95 | "ModifyTabCompletePackets in the config. Please report this " + 96 | "error if you can reproduce it on an up-to-date server with only latest " + 97 | "ProtocolLib and latest SV installed."); 98 | errorLogged = true; 99 | } 100 | } 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /src/main/resources/messages.yml: -------------------------------------------------------------------------------- 1 | # SuperVanish v${project.version} - Messages 2 | # 3 | # Information: 4 | # <..> means that .. is required; [..] means that .. is optional and can be left out; | inside [] or <> stands for 'OR' 5 | # You can use the & character for color codes; Example: '&cThe color of this text would be red!' 6 | # You can use #XXXXXX for HEX color codes. Example: '#663EF6This text would be purple!' 7 | # You can use %p% to get the player's name; Example: '&4&l%p%, you aren't allowed to execute this command!' 8 | # You can use %other% to get the name of the target or cause 9 | # You can use %d% to get the player's display name; if you use Essentials then the display name contains the prefix too 10 | # You can use %tab% to get the player's name in the player list (TAB) 11 | # You can use %prefix% to get the player's prefix (Requires Vault) 12 | # You can use %suffix% to get the player's suffix (Requires Vault) 13 | # You can use %group% to get the player's group (Requires Vault) 14 | # You can use %nick% to get the player's nickname (Requires Essentials) 15 | # Some messages allow different, unique variables too 16 | # 17 | # NOTE: You can get WAY more placeholders by installing PlaceholderAPI or MVdWPlaceholderAPI 18 | # 19 | # Empty messages will not be sent 20 | # Using \n starts a new line 21 | # 22 | # Important: 23 | # You must double single quotes if you want to use them inside a message. 24 | # You must NOT use any tab characters inside this file (indent key) otherwise YAML will spam your console with errors! 25 | # !! If there are errors in the console after editing this file paste it into an online YAML parser to see if 26 | # there are any YAML syntax errors !! 27 | Messages: 28 | NoPermission: '&4Denied access! You are not allowed to do this.' 29 | InvalidUsage: '&cInvalid usage, you can use &6/sv help&c for a list of commands.' 30 | VanishMessage: '&e%p% left the game' 31 | ReappearMessage: '&e%p% joined the game' 32 | VanishMessageWithPermission: '&a[SV] %p% vanished.' 33 | ReappearMessageWithPermission: '&a[SV] %p% reappeared.' 34 | OnVanish: '&aYou are now invisible!' 35 | OnReappear: '&aYou are no longer invisible!' 36 | OnVanishCausedByOtherPlayer: '&a%other% hid you, you are now invisible!' 37 | OnReappearCausedByOtherPlayer: '&a%other% showed you, you are now visible!' 38 | AlreadyVanishedError: '&cYou are already invisible!' 39 | NotVanishedError: '&cYou are not invisible!' 40 | SilentJoinMessageForAdmins: '&a[SV] %p% joined silently.' 41 | SilentQuitMessageForAdmins: '&a[SV] %p% left silently.' 42 | SilentDeathMessage: '&a[SV] %deathmsg%' 43 | RemindingMessage: '&aYou are still invisible!' 44 | ListMessagePrefix: '&aInvisible Players:&f %l' 45 | ActionBarMessage: '&aYou are invisible to other players!' 46 | HideOtherMessage: '&aPlayer &e%other%&a is now invisible!' 47 | ShowOtherMessage: '&aPlayer &e%other%&a is now visible!' 48 | CannotHideOtherPlayer: '&cYou''re not allowed to change %other%''s visibility!' 49 | AlreadyInvisibleMessage: '&cPlayer &e%other%&c is already invisible!' 50 | AlreadyVisibleMessage: '&cPlayer &e%other%&c is already visible!' 51 | PluginReloaded: '&aSuccessfully reloaded SuperVanish (%time%ms)!' 52 | InvalidSender: '&cYou must be a player to execute this command!' 53 | PlayerNotOnline: '&cThat player is not online!' 54 | PlayerNonExistent: '&cThat player doesn''t exist!' 55 | ToggledPickingUpItemsOn: '&ePicking up items is now turned &aON&e.' 56 | ToggledPickingUpItemsOff: '&ePicking up items is now turned &cOFF&e.' 57 | UpdateWarning: '&cWarning! Recreating %updates% resets %changes%. Please use &e/sv recreatefiles confirm&c if you''d like to continue.' 58 | RecreatedConfig: '&aSuccessfully recreated %updates%! Please check %changes%.' 59 | NoConfigUpdateAvailable: '&eYour SuperVanish-files are up to date!' 60 | RecreationRequiredMsg: '&c[SV] Your SuperVanish-files are not up to date, you can use &e/sv recreatefiles&c to recreate them 61 | or use /sv recreatefiles dismiss to dismiss this message. 62 | Recreating SuperVanish''s files gives you access to newer settings and features of the plugin.' 63 | DismissedRecreationWarning: '&eYou are no longer receiving notifications about this recreation.' 64 | UndismissedRecreationWarning: '&eYou are now receiving notifications about this recreation.' 65 | PrintedStacktrace: '&eSuccessfully created a stacktrace, see console!' 66 | EntityHitDenied: '&c[SV] You can''t hit players or mobs in vanish!' 67 | BlockPlaceDenied: '&c[SV] You can''t place blocks in vanish!' 68 | BlockBreakDenied: '&c[SV] You can''t break blocks in vanish!' 69 | PluginOutdated: '&c[SV] Your current version of SuperVanish is outdated. New version: ''%new%''; Currently: ''%current%''' 70 | DynmapFakeJoin: '%d% joined' 71 | DynmapFakeQuit: '%d% quit' 72 | HelpHeader: "&a<---------------&e SuperVanish-Help &a--------------->" 73 | HelpFormat: "&6%usage% &7- &b%description% &c(%permission%)" 74 | PlaceholderIsVanishedYes: "Yes" 75 | PlaceholderIsVanishedNo: "No" 76 | PlaceholderVanishPrefix: '&a[V] &r' 77 | PlaceholderVanishSuffix: ' &r&a[V]' 78 | MessagesVersion: ${project.version} 79 | -------------------------------------------------------------------------------- /src/main/resources/plugin.yml: -------------------------------------------------------------------------------- 1 | name: SuperVanish 2 | main: de.myzelyam.supervanish.SuperVanish 3 | author: MyzelYam 4 | description: Advanced /vanish plugin which makes other players think that you're not on the server 5 | version: ${project.version} 6 | api-version: 1.13 7 | website: https://www.spigotmc.org/resources/supervanish-be-invisible.1331/ 8 | softdepend: 9 | - ProtocolLib 10 | - LibsDisguises 11 | - DisguiseCraft 12 | - dynmap 13 | - Essentials 14 | - TrailGUI 15 | - PlaceholderAPI 16 | - CustomParticleEffects 17 | - NametagEdit 18 | - MVdWPlaceholderAPI 19 | - Vault 20 | commands: 21 | sv: 22 | usage: /sv 23 | description: SuperVanish's main command 24 | aliases: [supervanish, v, vanish] 25 | permissions: 26 | sv.*: 27 | children: 28 | sv.use: true 29 | sv.see: true 30 | sv.reload: true 31 | sv.logout: true 32 | sv.login: true 33 | sv.others: true 34 | sv.list: true 35 | sv.keepfly: true 36 | sv.toggleitems: true 37 | sv.recreatefiles: true 38 | sv.notoggle: true 39 | sv.joinvanished: true 40 | sv.notify: true 41 | sv.breakblocks: true 42 | sv.placeblocks: true 43 | sv.damage: true 44 | sv.stacktrace: true 45 | sv.silentchest: true 46 | description: Grants you all SuperVanish permissions 47 | supervanish.*: 48 | children: 49 | sv.*: true 50 | description: Grants you all SuperVanish permissions 51 | sv.see: 52 | description: You can see other vanished players 53 | sv.notoggle: 54 | description: Other players cannot hide/show you if you're online 55 | sv.keepfly: 56 | description: You can always keep flying when you reappear 57 | sv.joinvanished: 58 | description: You always join vanished (must be enabled in config) 59 | sv.silentchest: 60 | description: You can open chests silently --------------------------------------------------------------------------------