├── .github ├── banner.png └── workflows │ └── gradle-wrapper-validation.yml ├── .gitignore ├── LICENSE ├── README.md ├── build.gradle.kts ├── bungee ├── build.gradle.kts └── src │ └── main │ └── java │ └── dev │ └── bluetree242 │ └── advancedplhide │ └── bungee │ ├── AdvancedPlHideBungee.java │ ├── AdvancedPlHideCommand.java │ ├── Metrics.java │ ├── impl │ ├── completer │ │ ├── StringCommandCompleter.java │ │ └── StringCommandCompleterList.java │ └── subcompleter │ │ ├── StringSubCommandCompleter.java │ │ └── StringSubCommandCompleterList.java │ └── listener │ ├── event │ └── BungeeEventListener.java │ └── packet │ └── BungeePacketListener.java ├── core ├── build.gradle.kts └── src │ └── main │ └── java │ └── dev │ └── bluetree242 │ └── advancedplhide │ ├── AdvancedPlHide.java │ ├── CommandCompleter.java │ ├── CommandCompleterList.java │ ├── CompleterModifier.java │ ├── Group.java │ ├── PlatformPlugin.java │ ├── PluginInfo.java │ ├── SubCommandCompleter.java │ ├── SubCommandCompleterList.java │ ├── config │ ├── ConfManager.java │ ├── Config.java │ ├── DefaultGroupImpl.java │ └── subcompleter │ │ ├── ConfSubCompleter.java │ │ └── ConfSubCompleterList.java │ ├── exceptions │ └── ConfigurationLoadException.java │ ├── impl │ ├── completer │ │ ├── RootCommandCompleter.java │ │ ├── RootNodeCommandCompleter.java │ │ ├── SuggestionCommandCompleter.java │ │ └── SuggestionCommandCompleterList.java │ ├── group │ │ └── GroupCompleter.java │ ├── subcompleter │ │ ├── SuggestionSubCommandCompleter.java │ │ └── SuggestionSubCommandCompleterList.java │ └── version │ │ └── UpdateCheckResult.java │ └── utils │ ├── Constants.java │ ├── HTTPRequestMultipartBody.java │ └── UsedMap.java ├── gradle.properties ├── gradle ├── libs.versions.toml └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── settings.gradle ├── spigot ├── build.gradle.kts ├── modern │ ├── V1_19_3_NMS │ │ ├── build.gradle.kts │ │ └── src │ │ │ └── main │ │ │ └── java │ │ │ └── dev │ │ │ └── bluetree242 │ │ │ └── advancedplhide │ │ │ └── spigot │ │ │ └── modern │ │ │ └── V1_19_3_Handler.java │ ├── V1_19_NMS │ │ ├── build.gradle.kts │ │ └── src │ │ │ └── main │ │ │ └── java │ │ │ └── dev │ │ │ └── bluetree242 │ │ │ └── advancedplhide │ │ │ └── spigot │ │ │ └── modern │ │ │ └── V1_19_Handler.java │ ├── V1_20_5_NMS │ │ ├── build.gradle.kts │ │ └── src │ │ │ └── main │ │ │ └── java │ │ │ └── dev │ │ │ └── bluetree242 │ │ │ └── advancedplhide │ │ │ └── spigot │ │ │ └── modern │ │ │ └── V1_20_5_Handler.java │ ├── build.gradle.kts │ └── src │ │ └── main │ │ └── java │ │ └── dev │ │ └── bluetree242 │ │ └── advancedplhide │ │ └── spigot │ │ └── modern │ │ └── ModernHandler.java └── src │ └── main │ └── java │ └── dev │ └── bluetree242 │ └── advancedplhide │ └── spigot │ ├── AdvancedPlHideCommand.java │ ├── AdvancedPlHideSpigot.java │ ├── Metrics.java │ ├── impl │ ├── completer │ │ ├── StringCommandCompleter.java │ │ └── StringCommandCompleterList.java │ └── subcompleter │ │ ├── StringSubCommandCompleter.java │ │ └── StringSubCommandCompleterList.java │ └── listener │ ├── event │ └── SpigotEventListener.java │ └── packet │ └── SpigotPacketListener.java └── velocity ├── build.gradle.kts └── src └── main └── java └── dev └── bluetree242 └── advancedplhide └── velocity ├── AdvancedPlHideCommand.java ├── AdvancedPlHideVelocity.java ├── Metrics.java ├── impl ├── completer │ ├── OfferCommandCompleter.java │ └── OfferCompleterList.java └── subcompleter │ ├── OfferSubCommandCompleter.java │ └── OfferSubCommandCompleterList.java └── listener ├── event └── VelocityEventListener.java └── packet └── VelocityPacketListener.java /.github/banner.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlueTree242/AdvancedPlHide/0bae74b5d149a21365c78fbce15036541dacba67/.github/banner.png -------------------------------------------------------------------------------- /.github/workflows/gradle-wrapper-validation.yml: -------------------------------------------------------------------------------- 1 | name: "Validate Gradle Wrapper" 2 | on: [ push, pull_request ] 3 | 4 | jobs: 5 | validation: 6 | name: "Validation" 7 | runs-on: ubuntu-latest 8 | steps: 9 | - uses: actions/checkout@v4 10 | - uses: gradle/wrapper-validation-action@v3 -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled class file 2 | *.class 3 | 4 | # Log file 5 | *.log 6 | 7 | # BlueJ files 8 | *.ctxt 9 | 10 | # Mobile Tools for Java (J2ME) 11 | .mtj.tmp/ 12 | 13 | # Package Files # 14 | *.war 15 | *.nar 16 | *.ear 17 | *.zip 18 | *.tar.gz 19 | *.rar 20 | 21 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 22 | hs_err_pid* 23 | 24 | 25 | 26 | 27 | # Custom files 28 | build/ 29 | .idea/ 30 | .gradle/ -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 |
3 | AdvancePlHide 4 | 5 | 6 | 7 | [Document (not finshed)]:https://img.shields.io/badge/-Document-blue.svg?logo=Wikipedia&style=for-the-badge&logoColor=black 8 | 9 | [Discord]:https://img.shields.io/badge/-Discord-5865F2.svg?logo=discord&style=for-the-badge&logoColor=white 10 | 11 | [Spigot]:https://img.shields.io/badge/-SpigotMC-ef9023.svg?logo=Accenture&style=for-the-badge&logoColor=grey 12 | 13 | [SpigotRating]:https://img.shields.io/spiget/rating/98645?style=flat-square 14 | 15 | [GitHubStar]:https://img.shields.io/github/stars/BlueTree242/AdvancedPlHide 16 | 17 | [TestedVersion]: https://img.shields.io/spiget/tested-versions/98645?label=Tested%20on&style=flat-square 18 | 19 | [CodeSize]:https://img.shields.io/github/languages/code-size/BlueTree242/AdvancedPlHide 20 | 21 | [![Discord]](https://discordsrvutils.xyz/support) 22 | [![Spigot]](https://spigotmc.org/resources/98645) 23 |

[![TestedVersion]](https://spigotmc.org/resources/98645) ![SpigotRating] 24 |
![GitHubStar] ![CodeSize] 25 |
26 | 27 | ## Table of Contents 28 | 29 | * [Introduction](#introduction) 30 | * [Reasons](#Reasons) 31 | * [Features](#features) 32 | * [Requirements](#Requirements) 33 | * [Installation](#Installation) 34 | 35 | ## Introduction 36 | 37 | ### Reasons 38 | 39 | * This plugin was made to replace any paid plugin hiding 40 | 41 | ### Features 42 | 43 | * Group merging. 44 | * Hides /pl (/plugins). 45 | * blacklist or whitelist tab commands. 46 | * Others. 47 | 48 | ### Requirements 49 | 50 | * ProtocolLib (Spigot) 51 | * Protocolize (Proxy) 52 | * Luckperms or some other perm plugin 53 | 54 | ### Supported Platforms 55 | 56 | * Spigot/Paper or any forks. 57 | * BungeeCord 58 | * Velocity 59 | 60 | ### Installation 61 | 62 | When you Download AdvancedPlHide Also download ProtocolLib. 63 | 64 | When using a proxy AdvancedPlHide needs Protocolize 65 | 66 | ### License 67 | 68 | [License]:https://img.shields.io/github/license/Bluetree242/AdvancedPlHide?color=e 69 | [![License]](https://github.com/Bluetree242/AdvancedPlHide/blob/master/LICENSE) 70 | -------------------------------------------------------------------------------- /build.gradle.kts: -------------------------------------------------------------------------------- 1 | import net.kyori.blossom.BlossomExtension 2 | 3 | /* 4 | * LICENSE 5 | * AdvancedPlHide 6 | * ------------- 7 | * Copyright (C) 2021 - 2021 BlueTree242 8 | * ------------- 9 | * This program is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as 11 | * published by the Free Software Foundation, either version 3 of the 12 | * License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public 20 | * License along with this program. If not, see 21 | * . 22 | * END 23 | */ 24 | plugins { 25 | id("java") 26 | id("com.github.johnrengelman.shadow") version "8.1.1" 27 | id("net.kyori.blossom") version "1.3.1" apply false 28 | id("io.papermc.paperweight.userdev") version "1.6.0" apply false 29 | } 30 | repositories { 31 | mavenCentral() 32 | } 33 | val buildNumber = project.properties["buildNumber"]?.toString() ?: "NONE" 34 | val commit = System.getenv("GIT_COMMIT") ?: System.getProperty("GIT_COMMIT") ?: System.getenv("GITHUB_SHA") ?: "UNKNOWN" 35 | println("Build number is $buildNumber") 36 | println("Commit hash is $commit") 37 | 38 | tasks.build { 39 | finalizedBy(tasks.shadowJar) 40 | } 41 | subprojects { 42 | apply(plugin = "java") 43 | apply(plugin = "maven-publish") 44 | tasks.jar { 45 | archiveBaseName = "AdvancedPlHide-" + project.name 46 | archiveClassifier.set("") 47 | } 48 | dependencies { 49 | compileOnly("org.jetbrains:annotations:24.1.0") 50 | } 51 | repositories { 52 | mavenCentral() 53 | } 54 | java { 55 | disableAutoTargetJvm() 56 | } 57 | tasks.compileJava { 58 | options.release.set(8) 59 | } 60 | afterEvaluate { 61 | if (plugins.hasPlugin("com.github.johnrengelman.shadow")) { 62 | tasks.build { 63 | finalizedBy(tasks.shadowJar) 64 | } 65 | } 66 | } 67 | } 68 | 69 | subprojects { 70 | if (name == "core") { 71 | apply(plugin = "net.kyori.blossom") 72 | extensions.configure { 73 | val main = "src/main/java/dev/bluetree242/advancedplhide/PluginInfo.java" 74 | replaceToken("{version}", version, main) 75 | replaceToken("{build_number}", buildNumber, main) 76 | replaceToken("{commit}", commit, main) 77 | replaceToken("{build_date}", System.currentTimeMillis(), main) 78 | replaceToken("{description}", rootProject.description, main) 79 | } 80 | } 81 | } 82 | 83 | dependencies { 84 | implementation(project(":spigot")) 85 | implementation(project(":velocity")) 86 | implementation(project(":bungee")) 87 | } -------------------------------------------------------------------------------- /bungee/build.gradle.kts: -------------------------------------------------------------------------------- 1 | /* 2 | * LICENSE 3 | * AdvancedPlHide 4 | * ------------- 5 | * Copyright (C) 2021 - 2024 BlueTree242 6 | * ------------- 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as 9 | * published by the Free Software Foundation, either version 3 of the 10 | * License, or (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public 18 | * License along with this program. If not, see 19 | * . 20 | * END 21 | */ 22 | plugins { 23 | id("net.minecrell.plugin-yml.bungee") version "0.6.0" 24 | id("com.github.johnrengelman.shadow") 25 | } 26 | 27 | repositories { 28 | maven("https://oss.sonatype.org/content/repositories/snapshots") 29 | maven("https://mvn.exceptionflug.de/repository/exceptionflug-public/") 30 | maven("https://libraries.minecraft.net") 31 | } 32 | 33 | dependencies { 34 | implementation(project(":core")) 35 | compileOnly(libs.protocolize) 36 | compileOnly(libs.bungee) 37 | } 38 | 39 | bungee { 40 | name = rootProject.name 41 | description = rootProject.description 42 | version = project.version.toString() 43 | main = "dev.bluetree242.advancedplhide.bungee.AdvancedPlHideBungee" 44 | author = "BlueTree242" 45 | depends = setOf("Protocolize") 46 | } -------------------------------------------------------------------------------- /bungee/src/main/java/dev/bluetree242/advancedplhide/bungee/AdvancedPlHideBungee.java: -------------------------------------------------------------------------------- 1 | /* 2 | * LICENSE 3 | * AdvancedPlHide 4 | * ------------- 5 | * Copyright (C) 2021 - 2024 BlueTree242 6 | * ------------- 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as 9 | * published by the Free Software Foundation, either version 3 of the 10 | * License, or (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public 18 | * License along with this program. If not, see 19 | * . 20 | * END 21 | */ 22 | 23 | package dev.bluetree242.advancedplhide.bungee; 24 | 25 | import dev.bluetree242.advancedplhide.Group; 26 | import dev.bluetree242.advancedplhide.PlatformPlugin; 27 | import dev.bluetree242.advancedplhide.bungee.listener.event.BungeeEventListener; 28 | import dev.bluetree242.advancedplhide.bungee.listener.packet.BungeePacketListener; 29 | import dev.bluetree242.advancedplhide.impl.version.UpdateCheckResult; 30 | import dev.bluetree242.advancedplhide.utils.Constants; 31 | import dev.simplix.protocolize.api.Protocolize; 32 | import net.md_5.bungee.api.ChatColor; 33 | import net.md_5.bungee.api.ProxyServer; 34 | import net.md_5.bungee.api.connection.ProxiedPlayer; 35 | import net.md_5.bungee.api.plugin.Listener; 36 | import net.md_5.bungee.api.plugin.Plugin; 37 | 38 | import java.io.File; 39 | import java.util.ArrayList; 40 | import java.util.List; 41 | 42 | public class AdvancedPlHideBungee extends Plugin implements Listener { 43 | private final AdvancedPlHideBungee.Impl platformPlugin = new Impl(); 44 | private BungeePacketListener listener; 45 | private List groups = new ArrayList<>(); 46 | 47 | public Group getGroupForPlayer(ProxiedPlayer player) { 48 | if (player.hasPermission("plhide.no-group")) return null; 49 | List groups = new ArrayList<>(); 50 | for (Group group : platformPlugin.getGroups()) { 51 | if (player.hasPermission("plhide.group." + group.getName())) { 52 | groups.add(group); 53 | } 54 | } 55 | return groups.isEmpty() ? platformPlugin.getGroup("default") : platformPlugin.mergeGroups(groups); 56 | } 57 | 58 | public void onLoad() { 59 | PlatformPlugin.setPlatform(platformPlugin); 60 | platformPlugin.initConfigManager(); 61 | } 62 | 63 | public void onEnable() { 64 | platformPlugin.reloadConfig(); 65 | Protocolize.listenerProvider().registerListener(listener = new BungeePacketListener(this)); 66 | getProxy().getPluginManager().registerListener(this, new BungeeEventListener(this)); 67 | ProxyServer.getInstance().getPluginManager().registerCommand(this, new AdvancedPlHideCommand(this)); 68 | new Metrics(this, 13709); 69 | ProxyServer.getInstance().getConsole().sendMessage(ChatColor.translateAlternateColorCodes('&', Constants.startupMessage())); 70 | performStartUpdateCheck(); 71 | } 72 | 73 | public void onDisable() { 74 | Protocolize.listenerProvider().unregisterListener(listener); 75 | } 76 | 77 | public void loadGroups() { 78 | groups = new ArrayList<>(); 79 | platformPlugin.getConfig().groups().forEach((name, val) -> { 80 | if (getGroup(name) == null) 81 | groups.add(new Group(name, val.tabcomplete())); 82 | else { 83 | getLogger().warning("Group " + name + " is repeated."); 84 | } 85 | }); 86 | if (getGroup("default") == null) { 87 | getLogger().warning("Group default was not found. If someone has no permission for any group, no group applies on them"); 88 | } 89 | 90 | } 91 | 92 | public void performStartUpdateCheck() { 93 | ProxyServer.getInstance().getScheduler().runAsync(this, () -> { 94 | try { 95 | UpdateCheckResult result = Impl.get().updateCheck(); 96 | String msg = result.getVersionsBehind() == 0 ? 97 | ChatColor.translateAlternateColorCodes('&', Constants.DEFAULT_UP_TO_DATE) : 98 | ChatColor.translateAlternateColorCodes('&', Constants.DEFAULT_BEHIND.replace("{versions}", result.getVersionsBehind() + "") 99 | .replace("{download}", result.getUpdateUrl())); 100 | if (result.getMessage() != null) { 101 | msg = ChatColor.translateAlternateColorCodes('&', result.getMessage()); 102 | } 103 | switch (result.getLoggerType()) { 104 | case "INFO": 105 | getLogger().info(msg); 106 | break; 107 | case "WARNING": 108 | getLogger().warning(msg); 109 | break; 110 | case "ERROR": 111 | getLogger().severe(msg); 112 | break; 113 | } 114 | } catch (Throwable ex) { 115 | getLogger().severe(String.format("Could not check for updates: %s", ex.getMessage())); 116 | } 117 | }); 118 | } 119 | 120 | public Group getGroup(String name) { 121 | for (Group group : groups) { 122 | if (group.getName().equals(name)) return group; 123 | } 124 | return null; 125 | } 126 | 127 | public List getGroups() { 128 | return groups; 129 | } 130 | 131 | 132 | public class Impl extends PlatformPlugin { 133 | @Override 134 | public void loadGroups() { 135 | AdvancedPlHideBungee.this.loadGroups(); 136 | } 137 | 138 | @Override 139 | public File getDataFolder() { 140 | return AdvancedPlHideBungee.this.getDataFolder(); 141 | } 142 | 143 | @Override 144 | public List getGroups() { 145 | return AdvancedPlHideBungee.this.getGroups(); 146 | } 147 | 148 | @Override 149 | public Group getGroup(String name) { 150 | return AdvancedPlHideBungee.this.getGroup(name); 151 | } 152 | 153 | @Override 154 | public String getPluginForCommand(String s) { 155 | return null; 156 | } 157 | 158 | @Override 159 | public Type getType() { 160 | return Type.BUNGEE; 161 | } 162 | } 163 | 164 | } 165 | -------------------------------------------------------------------------------- /bungee/src/main/java/dev/bluetree242/advancedplhide/bungee/AdvancedPlHideCommand.java: -------------------------------------------------------------------------------- 1 | /* 2 | * LICENSE 3 | * AdvancedPlHide 4 | * ------------- 5 | * Copyright (C) 2021 - 2024 BlueTree242 6 | * ------------- 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as 9 | * published by the Free Software Foundation, either version 3 of the 10 | * License, or (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public 18 | * License along with this program. If not, see 19 | * . 20 | * END 21 | */ 22 | 23 | package dev.bluetree242.advancedplhide.bungee; 24 | 25 | import dev.bluetree242.advancedplhide.PlatformPlugin; 26 | import dev.bluetree242.advancedplhide.exceptions.ConfigurationLoadException; 27 | import net.md_5.bungee.api.ChatColor; 28 | import net.md_5.bungee.api.CommandSender; 29 | import net.md_5.bungee.api.ProxyServer; 30 | import net.md_5.bungee.api.plugin.Command; 31 | 32 | import java.util.concurrent.TimeUnit; 33 | 34 | public class AdvancedPlHideCommand extends Command { 35 | private final AdvancedPlHideBungee core; 36 | 37 | public AdvancedPlHideCommand(AdvancedPlHideBungee core) { 38 | super("advancedplhidebungee", null, "aphb", "plhideb"); 39 | this.core = core; 40 | } 41 | 42 | @Override 43 | public void execute(CommandSender sender, String[] args) { 44 | if (args.length == 0) { 45 | sender.sendMessage(ChatColor.GREEN + "Running AdvancedPlHide v." + ChatColor.YELLOW + core.getDescription().getVersion()); 46 | return; 47 | } else { 48 | if (args[0].equalsIgnoreCase("reload")) { 49 | if (!sender.hasPermission("plhide.reload")) { 50 | sender.sendMessage(ChatColor.RED + "You don't have permission to run this command"); 51 | } else { 52 | ProxyServer.getInstance().getScheduler().schedule(core, () -> { 53 | try { 54 | PlatformPlugin.get().reloadConfig(); 55 | sender.sendMessage(ChatColor.GREEN + "Configuration Reloaded"); 56 | } catch (ConfigurationLoadException e) { 57 | sender.sendMessage(ChatColor.RED + "Could not reload " + e.getConfigName()); 58 | } 59 | }, 0, TimeUnit.SECONDS); 60 | } 61 | return; 62 | } 63 | } 64 | sender.sendMessage(ChatColor.RED + "SubCommand not found"); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /bungee/src/main/java/dev/bluetree242/advancedplhide/bungee/impl/completer/StringCommandCompleter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * LICENSE 3 | * AdvancedPlHide 4 | * ------------- 5 | * Copyright (C) 2021 - 2024 BlueTree242 6 | * ------------- 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as 9 | * published by the Free Software Foundation, either version 3 of the 10 | * License, or (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public 18 | * License along with this program. If not, see 19 | * . 20 | * END 21 | */ 22 | 23 | package dev.bluetree242.advancedplhide.bungee.impl.completer; 24 | 25 | import dev.bluetree242.advancedplhide.CommandCompleter; 26 | 27 | public class StringCommandCompleter implements CommandCompleter { 28 | private final String name; 29 | private final StringCommandCompleterList list; 30 | 31 | public StringCommandCompleter(String name, StringCommandCompleterList list) { 32 | this.list = list; 33 | this.name = name.replaceFirst("/", ""); 34 | } 35 | 36 | @Override 37 | public String getName() { 38 | return name; 39 | } 40 | 41 | @Override 42 | public void remove() { 43 | list.remove(this); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /bungee/src/main/java/dev/bluetree242/advancedplhide/bungee/impl/completer/StringCommandCompleterList.java: -------------------------------------------------------------------------------- 1 | /* 2 | * LICENSE 3 | * AdvancedPlHide 4 | * ------------- 5 | * Copyright (C) 2021 - 2024 BlueTree242 6 | * ------------- 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as 9 | * published by the Free Software Foundation, either version 3 of the 10 | * License, or (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public 18 | * License along with this program. If not, see 19 | * . 20 | * END 21 | */ 22 | 23 | package dev.bluetree242.advancedplhide.bungee.impl.completer; 24 | 25 | import dev.bluetree242.advancedplhide.CommandCompleter; 26 | import dev.bluetree242.advancedplhide.CommandCompleterList; 27 | 28 | import java.util.ArrayList; 29 | import java.util.List; 30 | 31 | public class StringCommandCompleterList extends CommandCompleterList { 32 | private final List list; 33 | 34 | public StringCommandCompleterList(List list) { 35 | this.list = list; 36 | for (String s : list) { 37 | add(new StringCommandCompleter(s, this)); 38 | } 39 | } 40 | 41 | 42 | @Override 43 | public List export() { 44 | List cmds = new ArrayList<>(); 45 | for (CommandCompleter completer : this) { 46 | cmds.add("/" + completer.getName()); 47 | } 48 | return cmds; 49 | } 50 | 51 | @Override 52 | public boolean remove(Object o) { 53 | if (!(o instanceof CommandCompleter)) throw new IllegalArgumentException("May only Remove CommandCompleter"); 54 | CommandCompleter completer = (CommandCompleter) o; 55 | list.remove("/" + completer.getName()); 56 | return super.remove(o); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /bungee/src/main/java/dev/bluetree242/advancedplhide/bungee/impl/subcompleter/StringSubCommandCompleter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * LICENSE 3 | * AdvancedPlHide 4 | * ------------- 5 | * Copyright (C) 2021 - 2024 BlueTree242 6 | * ------------- 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as 9 | * published by the Free Software Foundation, either version 3 of the 10 | * License, or (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public 18 | * License along with this program. If not, see 19 | * . 20 | * END 21 | */ 22 | 23 | package dev.bluetree242.advancedplhide.bungee.impl.subcompleter; 24 | 25 | import dev.bluetree242.advancedplhide.SubCommandCompleter; 26 | 27 | public class StringSubCommandCompleter implements SubCommandCompleter { 28 | private final StringSubCommandCompleterList list; 29 | private final String text; 30 | 31 | public StringSubCommandCompleter(StringSubCommandCompleterList list, String text) { 32 | this.list = list; 33 | this.text = text; 34 | } 35 | 36 | @Override 37 | public String getText() { 38 | return text; 39 | } 40 | 41 | @Override 42 | public void remove() { 43 | list.remove(this); 44 | } 45 | 46 | 47 | } 48 | -------------------------------------------------------------------------------- /bungee/src/main/java/dev/bluetree242/advancedplhide/bungee/impl/subcompleter/StringSubCommandCompleterList.java: -------------------------------------------------------------------------------- 1 | /* 2 | * LICENSE 3 | * AdvancedPlHide 4 | * ------------- 5 | * Copyright (C) 2021 - 2024 BlueTree242 6 | * ------------- 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as 9 | * published by the Free Software Foundation, either version 3 of the 10 | * License, or (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public 18 | * License along with this program. If not, see 19 | * . 20 | * END 21 | */ 22 | 23 | package dev.bluetree242.advancedplhide.bungee.impl.subcompleter; 24 | 25 | import dev.bluetree242.advancedplhide.SubCommandCompleter; 26 | import dev.bluetree242.advancedplhide.SubCommandCompleterList; 27 | 28 | import java.util.ArrayList; 29 | import java.util.List; 30 | 31 | public class StringSubCommandCompleterList extends SubCommandCompleterList { 32 | private final String command; 33 | private final String[] args; 34 | private final List suggestions; 35 | 36 | public StringSubCommandCompleterList(List suggestions, String notCompleted) { 37 | this.suggestions = suggestions; 38 | for (String suggestion : suggestions) { 39 | add(new StringSubCommandCompleter(this, suggestion)); 40 | } 41 | String[] split = notCompleted.trim().split(" "); 42 | command = split[0].replaceFirst("/", ""); 43 | List list = new ArrayList<>(); 44 | for (String s : split) { 45 | if (!s.equalsIgnoreCase("/" + command)) { 46 | if (notCompleted.endsWith(" ")) 47 | list.add(s); 48 | else { 49 | if (!s.equals(split[split.length - 1])) { 50 | list.add(s); 51 | } 52 | } 53 | } 54 | } 55 | args = list.toArray(new String[0]); 56 | } 57 | 58 | @Override 59 | public List export() { 60 | return suggestions; 61 | } 62 | 63 | @Override 64 | public String[] getArgs() { 65 | return args; 66 | } 67 | 68 | @Override 69 | public String getName() { 70 | return command; 71 | } 72 | 73 | public boolean remove(Object e) { 74 | if (!(e instanceof SubCommandCompleter)) 75 | throw new IllegalArgumentException("May only remove a SubCommandCompleter"); 76 | SubCommandCompleter completer = (SubCommandCompleter) e; 77 | for (String suggestion : new ArrayList<>(suggestions)) { 78 | if (suggestion.equalsIgnoreCase(completer.getText())) { 79 | super.remove(completer); 80 | return suggestions.remove(suggestion); 81 | } 82 | } 83 | return false; 84 | } 85 | 86 | } 87 | -------------------------------------------------------------------------------- /bungee/src/main/java/dev/bluetree242/advancedplhide/bungee/listener/event/BungeeEventListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * LICENSE 3 | * AdvancedPlHide 4 | * ------------- 5 | * Copyright (C) 2021 - 2024 BlueTree242 6 | * ------------- 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as 9 | * published by the Free Software Foundation, either version 3 of the 10 | * License, or (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public 18 | * License along with this program. If not, see 19 | * . 20 | * END 21 | */ 22 | 23 | package dev.bluetree242.advancedplhide.bungee.listener.event; 24 | 25 | import dev.bluetree242.advancedplhide.PlatformPlugin; 26 | import dev.bluetree242.advancedplhide.bungee.AdvancedPlHideBungee; 27 | import dev.bluetree242.advancedplhide.impl.version.UpdateCheckResult; 28 | import dev.bluetree242.advancedplhide.utils.Constants; 29 | import net.md_5.bungee.api.ChatColor; 30 | import net.md_5.bungee.api.ProxyServer; 31 | import net.md_5.bungee.api.connection.ProxiedPlayer; 32 | import net.md_5.bungee.api.event.ChatEvent; 33 | import net.md_5.bungee.api.event.PostLoginEvent; 34 | import net.md_5.bungee.api.plugin.Listener; 35 | import net.md_5.bungee.event.EventHandler; 36 | 37 | public class BungeeEventListener implements Listener { 38 | private final AdvancedPlHideBungee core; 39 | 40 | 41 | public BungeeEventListener(AdvancedPlHideBungee core) { 42 | this.core = core; 43 | } 44 | 45 | @EventHandler 46 | public void onChat(ChatEvent e) { 47 | if (e.getMessage().startsWith("/")) { 48 | if (e.getSender() instanceof ProxiedPlayer) { 49 | ProxiedPlayer sender = (ProxiedPlayer) e.getSender(); 50 | if (sender.hasPermission("plhide.command.use")) return; 51 | String cmd = e.getMessage().toLowerCase().split(" ")[0]; 52 | if (cmd.equalsIgnoreCase("/plugins") || cmd.equalsIgnoreCase("/pl") || cmd.equalsIgnoreCase("/bukkit:pl") || cmd.equalsIgnoreCase("/bukkit:plugins")) { 53 | e.setCancelled(true); 54 | if (!PlatformPlugin.get().getConfig().pl_message().isEmpty()) { 55 | sender.sendMessage(ChatColor.translateAlternateColorCodes('&', PlatformPlugin.get().getConfig().pl_message())); 56 | } 57 | } 58 | } 59 | } 60 | } 61 | 62 | @EventHandler 63 | public void onPlayerJoin(PostLoginEvent e) { 64 | if (e.getPlayer().hasPermission("plhide.updatechecker")) { 65 | ProxyServer.getInstance().getScheduler().runAsync(core, () -> { 66 | try { 67 | UpdateCheckResult result = PlatformPlugin.get().updateCheck(); 68 | String msg = result.getVersionsBehind() == 0 ? null : ChatColor.translateAlternateColorCodes('&', "&e[APH&r-&2Bungee&e] " + Constants.DEFAULT_BEHIND.replace("{versions}", result.getVersionsBehind() + "").replace("{download}", result.getUpdateUrl())); 69 | if (result.getMessage() != null) { 70 | msg = ChatColor.translateAlternateColorCodes('&', "&e[APH&r-&2Bungee&e] &c" + result.getMessage()); 71 | } 72 | if (msg != null) { 73 | e.getPlayer().sendMessage(msg); 74 | } 75 | } catch (Throwable ex) { 76 | core.getLogger().severe(String.format("Could not check for updates: %s", ex.getMessage())); 77 | } 78 | }); 79 | } 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /bungee/src/main/java/dev/bluetree242/advancedplhide/bungee/listener/packet/BungeePacketListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * LICENSE 3 | * AdvancedPlHide 4 | * ------------- 5 | * Copyright (C) 2021 - 2024 BlueTree242 6 | * ------------- 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as 9 | * published by the Free Software Foundation, either version 3 of the 10 | * License, or (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public 18 | * License along with this program. If not, see 19 | * . 20 | * END 21 | */ 22 | 23 | package dev.bluetree242.advancedplhide.bungee.listener.packet; 24 | 25 | import dev.bluetree242.advancedplhide.CompleterModifier; 26 | import dev.bluetree242.advancedplhide.bungee.AdvancedPlHideBungee; 27 | import dev.bluetree242.advancedplhide.bungee.impl.completer.StringCommandCompleterList; 28 | import dev.bluetree242.advancedplhide.bungee.impl.subcompleter.StringSubCommandCompleterList; 29 | import dev.bluetree242.advancedplhide.impl.completer.RootNodeCommandCompleter; 30 | import dev.bluetree242.advancedplhide.impl.completer.SuggestionCommandCompleterList; 31 | import dev.bluetree242.advancedplhide.impl.subcompleter.SuggestionSubCommandCompleterList; 32 | import dev.bluetree242.advancedplhide.utils.Constants; 33 | import dev.bluetree242.advancedplhide.utils.UsedMap; 34 | import dev.simplix.protocolize.api.Direction; 35 | import dev.simplix.protocolize.api.Protocolize; 36 | import dev.simplix.protocolize.api.listener.AbstractPacketListener; 37 | import dev.simplix.protocolize.api.listener.PacketReceiveEvent; 38 | import dev.simplix.protocolize.api.listener.PacketSendEvent; 39 | import net.md_5.bungee.api.ProxyServer; 40 | import net.md_5.bungee.api.connection.ProxiedPlayer; 41 | import net.md_5.bungee.protocol.packet.Commands; 42 | import net.md_5.bungee.protocol.packet.TabCompleteRequest; 43 | import net.md_5.bungee.protocol.packet.TabCompleteResponse; 44 | 45 | import java.util.UUID; 46 | 47 | public class BungeePacketListener extends AbstractPacketListener { 48 | private final UsedMap commandsWaiting = new UsedMap<>(); 49 | private final AdvancedPlHideBungee core; 50 | 51 | public BungeePacketListener(AdvancedPlHideBungee core) { 52 | super(TabCompleteResponse.class, Direction.UPSTREAM, 0); 53 | this.core = core; 54 | Protocolize.listenerProvider().registerListener(new BungeePacketListener.RequestListener()); 55 | Protocolize.listenerProvider().registerListener(new CommandsListener()); 56 | } 57 | 58 | 59 | @Override 60 | public void packetReceive(PacketReceiveEvent e) { 61 | //it is impossible to get this packet 62 | } 63 | 64 | @Override 65 | public void packetSend(PacketSendEvent e) { 66 | boolean legacy = e.player().protocolVersion() <= 340; 67 | ProxiedPlayer player = ProxyServer.getInstance().getPlayer(e.player().uniqueId()); 68 | if (player == null || !player.isConnected()) { 69 | e.cancelled(true); 70 | return; 71 | } 72 | TabCompleteResponse packet = e.packet(); 73 | String notCompleted = this.commandsWaiting.get(e.player().uniqueId()); 74 | if (notCompleted == null) notCompleted = "/"; 75 | if (!notCompleted.trim().startsWith("/")) notCompleted = "/" + notCompleted; 76 | if (legacy) { 77 | if (!notCompleted.contains(" ")) { 78 | StringCommandCompleterList list = new StringCommandCompleterList(packet.getCommands()); 79 | CompleterModifier.handleCompleter(list, core.getGroupForPlayer(player), player.hasPermission(Constants.WHITELIST_MODE_PERMISSION)); 80 | } else { 81 | StringSubCommandCompleterList list = new StringSubCommandCompleterList(packet.getCommands(), notCompleted); 82 | CompleterModifier.handleSubCompleter(list, core.getGroupForPlayer(player), player.hasPermission(Constants.WHITELIST_MODE_PERMISSION)); 83 | if (list.isCancelled()) e.cancelled(true); 84 | } 85 | } else { 86 | if (!notCompleted.contains(" ")) { 87 | SuggestionCommandCompleterList list = new SuggestionCommandCompleterList(packet.getSuggestions()); 88 | CompleterModifier.handleCompleter(list, core.getGroupForPlayer(player), player.hasPermission("plhide.whitelist-mode")); 89 | } else { 90 | SuggestionSubCommandCompleterList suggestions = new SuggestionSubCommandCompleterList(e.packet().getSuggestions(), notCompleted); 91 | CompleterModifier.handleSubCompleter(suggestions, core.getGroupForPlayer(player), player.hasPermission(Constants.WHITELIST_MODE_PERMISSION)); 92 | if (suggestions.isCancelled()) e.cancelled(true); 93 | } 94 | } 95 | } 96 | 97 | public class CommandsListener extends AbstractPacketListener { 98 | 99 | protected CommandsListener() { 100 | super(Commands.class, Direction.UPSTREAM, 0); 101 | } 102 | 103 | @Override 104 | public void packetReceive(PacketReceiveEvent e) { 105 | 106 | } 107 | 108 | @Override 109 | public void packetSend(PacketSendEvent e) { 110 | ProxiedPlayer player = ProxyServer.getInstance().getPlayer(e.player().uniqueId()); 111 | if (player == null || !player.isConnected()) { 112 | e.cancelled(true); 113 | return; 114 | } 115 | Commands packet = e.packet(); 116 | RootNodeCommandCompleter completer = new RootNodeCommandCompleter(packet.getRoot()); 117 | CompleterModifier.handleCompleter(completer, core.getGroupForPlayer(player), player.hasPermission(Constants.WHITELIST_MODE_PERMISSION)); 118 | } 119 | } 120 | 121 | public class RequestListener extends AbstractPacketListener { 122 | 123 | protected RequestListener() { 124 | super(TabCompleteRequest.class, Direction.UPSTREAM, Integer.MAX_VALUE); 125 | } 126 | 127 | @Override 128 | public void packetReceive(PacketReceiveEvent e) { 129 | if (!e.cancelled()) 130 | commandsWaiting.put(e.player().uniqueId(), e.packet().getCursor()); 131 | } 132 | 133 | @Override 134 | public void packetSend(PacketSendEvent e) { 135 | 136 | } 137 | } 138 | } 139 | 140 | -------------------------------------------------------------------------------- /core/build.gradle.kts: -------------------------------------------------------------------------------- 1 | import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar 2 | 3 | /* 4 | * LICENSE 5 | * AdvancedPlHide 6 | * ------------- 7 | * Copyright (C) 2021 - 2021 BlueTree242 8 | * ------------- 9 | * This program is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as 11 | * published by the Free Software Foundation, either version 3 of the 12 | * License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public 20 | * License along with this program. If not, see 21 | * . 22 | * END 23 | */ 24 | 25 | gradle.projectsEvaluated { 26 | rootProject.allprojects { 27 | if (plugins.hasPlugin("com.github.johnrengelman.shadow")) { 28 | tasks.withType(ShadowJar::class.java) { 29 | if (project != rootProject) archiveBaseName = "AdvancedPlHide-" + project.name 30 | if (project != project(":core")) archiveClassifier.set("") 31 | val prefix = "dev.bluetree242.advancedplhide.dependencies" 32 | relocate("space.arim.dazzleconf", "$prefix.dazzleconf") 33 | relocate("org.yaml.snakeyaml", "$prefix.yaml") 34 | relocate("org.json", "$prefix.json") 35 | relocate("com.intellectualsites.http", "$prefix.http4j") 36 | } 37 | } 38 | } 39 | } 40 | 41 | repositories { 42 | maven("https://repo.destroystokyo.com/repository/maven-public/") 43 | maven("https://libraries.minecraft.net") 44 | } 45 | 46 | dependencies { 47 | implementation(libs.dazzleconf) 48 | compileOnly(libs.brigadier) 49 | implementation(libs.http4j) { 50 | exclude(group = "org.jetbrains") // It keeps shading it. 51 | } 52 | implementation(libs.json) 53 | } 54 | -------------------------------------------------------------------------------- /core/src/main/java/dev/bluetree242/advancedplhide/AdvancedPlHide.java: -------------------------------------------------------------------------------- 1 | /* 2 | * LICENSE 3 | * AdvancedPlHide 4 | * ------------- 5 | * Copyright (C) 2021 - 2024 BlueTree242 6 | * ------------- 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as 9 | * published by the Free Software Foundation, either version 3 of the 10 | * License, or (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public 18 | * License along with this program. If not, see 19 | * . 20 | * END 21 | */ 22 | 23 | package dev.bluetree242.advancedplhide; 24 | 25 | public class AdvancedPlHide { 26 | /** 27 | * @return The Plugin main instance core 28 | * @see PlatformPlugin 29 | */ 30 | public static PlatformPlugin get() { 31 | return PlatformPlugin.get(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /core/src/main/java/dev/bluetree242/advancedplhide/CommandCompleter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * LICENSE 3 | * AdvancedPlHide 4 | * ------------- 5 | * Copyright (C) 2021 - 2024 BlueTree242 6 | * ------------- 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as 9 | * published by the Free Software Foundation, either version 3 of the 10 | * License, or (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public 18 | * License along with this program. If not, see 19 | * . 20 | * END 21 | */ 22 | 23 | package dev.bluetree242.advancedplhide; 24 | 25 | public interface CommandCompleter { 26 | 27 | /** 28 | * @return The name of the command, if the completer is `/help` this would return `help` 29 | */ 30 | String getName(); 31 | 32 | /** 33 | * This method is only used if this is included in a {@link CommandCompleterList} 34 | * 35 | * @throws UnsupportedOperationException if this is not in a list 36 | */ 37 | void remove(); 38 | 39 | 40 | } 41 | -------------------------------------------------------------------------------- /core/src/main/java/dev/bluetree242/advancedplhide/CommandCompleterList.java: -------------------------------------------------------------------------------- 1 | /* 2 | * LICENSE 3 | * AdvancedPlHide 4 | * ------------- 5 | * Copyright (C) 2021 - 2024 BlueTree242 6 | * ------------- 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as 9 | * published by the Free Software Foundation, either version 3 of the 10 | * License, or (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public 18 | * License along with this program. If not, see 19 | * . 20 | * END 21 | */ 22 | 23 | package dev.bluetree242.advancedplhide; 24 | 25 | import java.util.ArrayList; 26 | import java.util.function.Consumer; 27 | 28 | public abstract class CommandCompleterList extends ArrayList { 29 | 30 | 31 | @Override 32 | public void forEach(Consumer e) { 33 | for (CommandCompleter commandCompleter : new ArrayList<>(this)) { 34 | e.accept(commandCompleter); 35 | } 36 | 37 | } 38 | 39 | /** 40 | * @return Exported value of the original completer list 41 | */ 42 | public abstract Object export(); 43 | 44 | /** 45 | * Never use this method, most likely won't affect the list final result 46 | */ 47 | public final boolean add(CommandCompleter s) { 48 | return super.add(s); 49 | } 50 | 51 | 52 | } 53 | -------------------------------------------------------------------------------- /core/src/main/java/dev/bluetree242/advancedplhide/CompleterModifier.java: -------------------------------------------------------------------------------- 1 | /* 2 | * LICENSE 3 | * AdvancedPlHide 4 | * ------------- 5 | * Copyright (C) 2021 - 2024 BlueTree242 6 | * ------------- 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as 9 | * published by the Free Software Foundation, either version 3 of the 10 | * License, or (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public 18 | * License along with this program. If not, see 19 | * . 20 | * END 21 | */ 22 | 23 | package dev.bluetree242.advancedplhide; 24 | 25 | import dev.bluetree242.advancedplhide.config.subcompleter.ConfSubCompleterList; 26 | 27 | import java.util.ArrayList; 28 | import java.util.Arrays; 29 | import java.util.List; 30 | 31 | public class CompleterModifier { 32 | private static final List BAD_COMMANDS = Arrays.asList("ver", "version", "plugins", "bukkit:plugins", "bukkit:ver", "bukkit:version", "about", "bukkit:about", "?", "minecraft:?"); 33 | 34 | public static void removePluginPrefix(CommandCompleterList list) { 35 | for (CommandCompleter completer : new ArrayList<>(list)) { 36 | if (completer.getName().contains(":")) completer.remove(); 37 | } 38 | } 39 | 40 | 41 | public static void handleCompleter(CommandCompleterList list, Group playerGroup, boolean whitelist) { 42 | if (PlatformPlugin.get().getConfig().remove_plugin_prefix()) 43 | removePluginPrefix(list); 44 | 45 | if (playerGroup != null) { 46 | if (!whitelist) applyBlacklist(list, playerGroup.getCompleteCommands()); 47 | else applyWhitelist(list, playerGroup.getCompleteCommands()); 48 | } 49 | } 50 | 51 | public static void handleSubCompleter(SubCommandCompleterList list, Group playerGroup, boolean whitelist) { 52 | if (BAD_COMMANDS.contains(list.getName().toLowerCase())) { 53 | list.removeAll(); 54 | } 55 | if (playerGroup == null) return; 56 | ConfSubCompleterList originConfList = playerGroup.getSubCompleters(); 57 | List cmds = playerGroup.getCompleteCommands(); 58 | boolean includedConfig = cmds.stream().anyMatch(c -> c.getName().equalsIgnoreCase(list.getName()) || 59 | (c.getName().startsWith("from:") && PlatformPlugin.get().getPluginForCommand(list.getName()) != null && 60 | PlatformPlugin.get().getPluginForCommand(list.getName()).equalsIgnoreCase(c.getName().replaceFirst("from:", "")))); 61 | if (((whitelist && !includedConfig) || (!whitelist && includedConfig))) { 62 | list.removeAll(); //this command is not visible to player they might not see it's sub args 63 | return; 64 | } 65 | ConfSubCompleterList confList = originConfList.ofCommand(list.getName()); 66 | if (!whitelist) applyBlacklist(list, confList); 67 | else applyWhitelist(list, confList); 68 | } 69 | 70 | public static void applyBlacklist(SubCommandCompleterList list, ConfSubCompleterList originConfList) { 71 | for (SubCommandCompleter completer : new ArrayList<>(list)) { 72 | ConfSubCompleterList confList = originConfList.ofArgs(list.getArgs(completer)); 73 | if (!confList.isEmpty()) { 74 | completer.remove(); 75 | } 76 | } 77 | } 78 | 79 | public static void applyWhitelist(SubCommandCompleterList list, ConfSubCompleterList originConfList) { 80 | if (originConfList.isEmpty()) return; 81 | for (SubCommandCompleter completer : new ArrayList<>(list)) { 82 | ConfSubCompleterList confList = originConfList.ofArgs(list.getArgs(completer)); 83 | if (confList.isEmpty()) { 84 | completer.remove(); 85 | } 86 | } 87 | } 88 | 89 | 90 | public static void applyBlacklist(CommandCompleterList list, List toBlacklist) { 91 | List commands = new ArrayList<>(); 92 | List plugins = new ArrayList<>(); 93 | for (CommandCompleter completer : toBlacklist) { 94 | if (!completer.getName().startsWith("from:")) 95 | commands.add(completer.getName()); 96 | else { 97 | String name = completer.getName().replaceFirst("from:", ""); 98 | plugins.add(name); 99 | } 100 | } 101 | for (CommandCompleter completer : new ArrayList<>(list)) { 102 | if (commands.contains(completer.getName())) { 103 | completer.remove(); 104 | } else if (plugins.contains(PlatformPlugin.get().getPluginForCommand(completer.getName()))) { 105 | completer.remove(); 106 | } 107 | } 108 | } 109 | 110 | public static void applyWhitelist(CommandCompleterList list, List toWhitelist) { 111 | List commands = new ArrayList<>(); 112 | List plugins = new ArrayList<>(); 113 | for (CommandCompleter completer : toWhitelist) { 114 | if (!completer.getName().startsWith("from:")) 115 | commands.add(completer.getName()); 116 | else { 117 | String name = completer.getName().replaceFirst("from:", ""); 118 | plugins.add(name); 119 | } 120 | } 121 | for (CommandCompleter completer : new ArrayList<>(list)) { 122 | if (!commands.contains(completer.getName())) { 123 | if (!plugins.contains(PlatformPlugin.get().getPluginForCommand(completer.getName()))) 124 | completer.remove(); 125 | } 126 | } 127 | } 128 | } 129 | -------------------------------------------------------------------------------- /core/src/main/java/dev/bluetree242/advancedplhide/Group.java: -------------------------------------------------------------------------------- 1 | /* 2 | * LICENSE 3 | * AdvancedPlHide 4 | * ------------- 5 | * Copyright (C) 2021 - 2024 BlueTree242 6 | * ------------- 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as 9 | * published by the Free Software Foundation, either version 3 of the 10 | * License, or (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public 18 | * License along with this program. If not, see 19 | * . 20 | * END 21 | */ 22 | 23 | package dev.bluetree242.advancedplhide; 24 | 25 | import dev.bluetree242.advancedplhide.config.subcompleter.ConfSubCompleter; 26 | import dev.bluetree242.advancedplhide.config.subcompleter.ConfSubCompleterList; 27 | import dev.bluetree242.advancedplhide.impl.group.GroupCompleter; 28 | 29 | import java.util.ArrayList; 30 | import java.util.List; 31 | 32 | /** 33 | * Group that inherit some completers. 34 | * **Handling infinite loops of group parents:** 35 | * Parent groups inherited would not be repeated. 36 | */ 37 | public class Group { 38 | private final String name; 39 | private final List completers; 40 | private final ConfSubCompleterList subCompleters; 41 | private final List originCompleters; 42 | 43 | public Group(String name, List completers) { 44 | this.originCompleters = completers; 45 | this.name = name; 46 | List completersFinal = new ArrayList<>(); 47 | ConfSubCompleterList subCompletersFinal = new ConfSubCompleterList(); 48 | for (String completer : completers) { 49 | String[] split = completer.trim().split(" "); 50 | if (split.length == 1) completersFinal.add(new GroupCompleter(split[0])); 51 | else { 52 | subCompletersFinal.add(ConfSubCompleter.of(completer)); 53 | } 54 | } 55 | this.completers = completersFinal; 56 | this.subCompleters = subCompletersFinal; 57 | } 58 | 59 | /** 60 | * @return Name of group 61 | */ 62 | public String getName() { 63 | return name; 64 | } 65 | 66 | /** 67 | * @return list of completer strings. the raw ones in config 68 | */ 69 | public List getOriginCompleters() { 70 | return originCompleters; 71 | } 72 | 73 | /** 74 | * @return list of sub completers 75 | */ 76 | public ConfSubCompleterList getSubCompleters() { 77 | return subCompleters; 78 | } 79 | 80 | 81 | /** 82 | * @return List of commands for group, either used as whitelist or blacklist. The commands are considered not in a list. this will not contain any sub commands 83 | */ 84 | public List getCompleteCommands() { 85 | return completers; 86 | } 87 | 88 | 89 | @Override 90 | public String toString() { 91 | return getName(); 92 | } 93 | 94 | } 95 | -------------------------------------------------------------------------------- /core/src/main/java/dev/bluetree242/advancedplhide/PlatformPlugin.java: -------------------------------------------------------------------------------- 1 | /* 2 | * LICENSE 3 | * AdvancedPlHide 4 | * ------------- 5 | * Copyright (C) 2021 - 2024 BlueTree242 6 | * ------------- 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as 9 | * published by the Free Software Foundation, either version 3 of the 10 | * License, or (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public 18 | * License along with this program. If not, see 19 | * . 20 | * END 21 | */ 22 | 23 | package dev.bluetree242.advancedplhide; 24 | 25 | import com.intellectualsites.http.EntityMapper; 26 | import com.intellectualsites.http.HttpClient; 27 | import com.intellectualsites.http.HttpResponse; 28 | import dev.bluetree242.advancedplhide.config.ConfManager; 29 | import dev.bluetree242.advancedplhide.config.Config; 30 | import dev.bluetree242.advancedplhide.exceptions.ConfigurationLoadException; 31 | import dev.bluetree242.advancedplhide.impl.version.UpdateCheckResult; 32 | import dev.bluetree242.advancedplhide.utils.HTTPRequestMultipartBody; 33 | import org.json.JSONObject; 34 | 35 | import java.io.File; 36 | import java.nio.charset.StandardCharsets; 37 | import java.util.ArrayList; 38 | import java.util.List; 39 | import java.util.Objects; 40 | 41 | /** 42 | * Platform is the platform the plugin runs on, we can also call it the plugin core as it contains some methods related to the plugin itself too 43 | * 44 | * @see AdvancedPlHide#get() 45 | * @see PlatformPlugin#get() 46 | */ 47 | public abstract class PlatformPlugin { 48 | private static PlatformPlugin platformPlugin = null; 49 | 50 | private ConfManager confManager; 51 | private Config config; 52 | 53 | 54 | public static PlatformPlugin get() { 55 | return platformPlugin; 56 | } 57 | 58 | public static void setPlatform(PlatformPlugin val) { 59 | if (platformPlugin != null) throw new IllegalStateException("Platform already set"); 60 | platformPlugin = val; 61 | } 62 | 63 | public Config getConfig() { 64 | return config; 65 | } 66 | 67 | public void reloadConfig() throws ConfigurationLoadException { 68 | confManager.reloadConfig(); 69 | config = confManager.getConfigData(); 70 | loadGroups(); 71 | } 72 | 73 | public void initConfigManager() { 74 | confManager = ConfManager.create(getDataFolder().toPath(), "config.yml", Config.class); 75 | } 76 | 77 | public abstract void loadGroups(); 78 | 79 | public abstract File getDataFolder(); 80 | 81 | public abstract List getGroups(); 82 | 83 | public abstract Group getGroup(String name); 84 | 85 | public abstract String getPluginForCommand(String s); 86 | 87 | public Group mergeGroups(List groups) { 88 | List tabcomplete = new ArrayList<>(); 89 | for (Group group : groups) { 90 | tabcomplete.addAll(group.getOriginCompleters()); 91 | } 92 | List names = new ArrayList<>(); 93 | for (Group group : groups) { 94 | names.add(group.getName()); 95 | } 96 | String name = "Merged Group: " + String.join(", ", names); 97 | return new Group(name, tabcomplete); 98 | } 99 | 100 | private static final HttpClient client = HttpClient.newBuilder() 101 | .withBaseURL("https://advancedplhide.bluetree242.dev") 102 | .withEntityMapper(new EntityMapper().registerSerializer(HTTPRequestMultipartBody.class, new HTTPRequestMultipartBody.MultiPartSerializer())) 103 | .build(); 104 | public UpdateCheckResult updateCheck() throws Throwable { 105 | HTTPRequestMultipartBody multipartBody = new HTTPRequestMultipartBody.Builder() 106 | .addPart("version", PluginInfo.VERSION) 107 | .addPart("buildNumber", PluginInfo.BUILD_NUMBER) 108 | .addPart("buildDate", PluginInfo.BUILD_DATE) 109 | .addPart("commit", PluginInfo.COMMIT) 110 | .addPart("devUpdatechecker", String.valueOf(getConfig().dev_updatechecker())) 111 | .build(); 112 | HttpResponse response = client.post("/updatecheck") 113 | .withHeader("Content-Type", multipartBody.getContentType()) 114 | .withInput(() -> multipartBody) 115 | .execute(); 116 | JSONObject json = new JSONObject(new String(Objects.requireNonNull(response).getRawResponse(), StandardCharsets.UTF_8)); 117 | return new UpdateCheckResult(json.getInt("versions_behind"), json.isNull("message") ? null : json.getString("message"), json.isNull("type") ? "INFO" : json.getString("type"), json.getString("downloadUrl")); 118 | } 119 | 120 | public abstract Type getType(); 121 | 122 | public enum Type { 123 | SPIGOT("Spigot"), VELOCITY("Velocity"), BUNGEE("Bungee"); 124 | private final String name; 125 | 126 | Type(String name) { 127 | this.name = name; 128 | } 129 | 130 | public String getName() { 131 | return name; 132 | } 133 | } 134 | } 135 | -------------------------------------------------------------------------------- /core/src/main/java/dev/bluetree242/advancedplhide/PluginInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * LICENSE 3 | * AdvancedPlHide 4 | * ------------- 5 | * Copyright (C) 2021 - 2024 BlueTree242 6 | * ------------- 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as 9 | * published by the Free Software Foundation, either version 3 of the 10 | * License, or (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public 18 | * License along with this program. If not, see 19 | * . 20 | * END 21 | */ 22 | 23 | package dev.bluetree242.advancedplhide; 24 | 25 | public class PluginInfo { 26 | public static final String DESCRIPTION = "{description}"; 27 | public static final String VERSION = "{version}"; 28 | public static final String BUILD_NUMBER = "{build_number}"; 29 | public static final String BUILD_DATE = "{build_date}"; 30 | public static final String COMMIT = "{commit}"; 31 | } 32 | -------------------------------------------------------------------------------- /core/src/main/java/dev/bluetree242/advancedplhide/SubCommandCompleter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * LICENSE 3 | * AdvancedPlHide 4 | * ------------- 5 | * Copyright (C) 2021 - 2024 BlueTree242 6 | * ------------- 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as 9 | * published by the Free Software Foundation, either version 3 of the 10 | * License, or (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public 18 | * License along with this program. If not, see 19 | * . 20 | * END 21 | */ 22 | 23 | package dev.bluetree242.advancedplhide; 24 | 25 | public interface SubCommandCompleter { 26 | 27 | /** 28 | * @return Text of completer 29 | */ 30 | String getText(); 31 | 32 | 33 | /** 34 | * This method is only used if this is included in a {@link SubCommandCompleterList} 35 | * 36 | * @throws UnsupportedOperationException if this is not in a list 37 | */ 38 | void remove(); 39 | 40 | } 41 | -------------------------------------------------------------------------------- /core/src/main/java/dev/bluetree242/advancedplhide/SubCommandCompleterList.java: -------------------------------------------------------------------------------- 1 | /* 2 | * LICENSE 3 | * AdvancedPlHide 4 | * ------------- 5 | * Copyright (C) 2021 - 2024 BlueTree242 6 | * ------------- 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as 9 | * published by the Free Software Foundation, either version 3 of the 10 | * License, or (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public 18 | * License along with this program. If not, see 19 | * . 20 | * END 21 | */ 22 | 23 | package dev.bluetree242.advancedplhide; 24 | 25 | import java.util.ArrayList; 26 | import java.util.Collections; 27 | import java.util.List; 28 | import java.util.function.Consumer; 29 | 30 | public abstract class SubCommandCompleterList extends ArrayList { 31 | 32 | @Override 33 | public void forEach(Consumer e) { 34 | for (SubCommandCompleter commandCompleter : new ArrayList<>(this)) { 35 | e.accept(commandCompleter); 36 | } 37 | 38 | } 39 | 40 | /** 41 | * @return Exported value of the original sub-completer list 42 | */ 43 | public abstract Object export(); 44 | 45 | 46 | /** 47 | * @return Array of args, does not include the command, this never includes parts that aren't completed by the player (part which all completers are supposed to complete) 48 | */ 49 | public abstract String[] getArgs(); 50 | 51 | /** 52 | * @param completer sub completer to use 53 | * @return {@link SubCommandCompleterList#getArgs()} but ends with the text of the sub completer 54 | */ 55 | public String[] getArgs(SubCommandCompleter completer) { 56 | List result = new ArrayList<>(); 57 | Collections.addAll(result, getArgs()); 58 | result.add(completer.getText()); 59 | return result.toArray(new String[0]); 60 | } 61 | 62 | /** 63 | * @return Name of the command used, without / 64 | */ 65 | public abstract String getName(); 66 | 67 | 68 | public void removeAll() { 69 | for (SubCommandCompleter subCommandCompleter : new ArrayList<>(this)) { 70 | subCommandCompleter.remove(); 71 | } 72 | } 73 | 74 | /** 75 | * Checks if the packet (or event) should be cancelled 76 | * 77 | * @return if this should be cancelled, currently true only when list is empty 78 | * @throws IllegalStateException if this isn't supposed to be for a cancellable event/packet 79 | */ 80 | public boolean isCancelled() { 81 | return isEmpty(); 82 | } 83 | 84 | /** 85 | * Never use this method, most likely won't affect the list final result 86 | * 87 | * @deprecated 90% won't affect the list final result 88 | */ 89 | @Deprecated 90 | public final boolean add(SubCommandCompleter s) { 91 | return super.add(s); 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /core/src/main/java/dev/bluetree242/advancedplhide/config/ConfManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * LICENSE 3 | * AdvancedPlHide 4 | * ------------- 5 | * Copyright (C) 2021 - 2024 BlueTree242 6 | * ------------- 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as 9 | * published by the Free Software Foundation, either version 3 of the 10 | * License, or (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public 18 | * License along with this program. If not, see 19 | * . 20 | * END 21 | */ 22 | 23 | package dev.bluetree242.advancedplhide.config; 24 | 25 | import dev.bluetree242.advancedplhide.exceptions.ConfigurationLoadException; 26 | import space.arim.dazzleconf.ConfigurationFactory; 27 | import space.arim.dazzleconf.ConfigurationOptions; 28 | import space.arim.dazzleconf.error.ConfigFormatSyntaxException; 29 | import space.arim.dazzleconf.error.InvalidConfigException; 30 | import space.arim.dazzleconf.ext.snakeyaml.CommentMode; 31 | import space.arim.dazzleconf.ext.snakeyaml.SnakeYamlConfigurationFactory; 32 | import space.arim.dazzleconf.ext.snakeyaml.SnakeYamlOptions; 33 | import space.arim.dazzleconf.helper.ConfigurationHelper; 34 | import space.arim.dazzleconf.sorter.AnnotationBasedSorter; 35 | 36 | import java.io.IOException; 37 | import java.nio.file.Path; 38 | import java.util.HashMap; 39 | import java.util.Map; 40 | 41 | public class ConfManager extends ConfigurationHelper { 42 | private String confname; 43 | private volatile C configData; 44 | 45 | private ConfManager(Path configFolder, String fileName, ConfigurationFactory factory) { 46 | super(configFolder, fileName, factory); 47 | } 48 | 49 | public static ConfManager create(Path configFolder, String fileName, Class configClass) { 50 | // SnakeYaml example 51 | SnakeYamlOptions yamlOptions = new SnakeYamlOptions.Builder() 52 | .useCommentingWriter(true) 53 | .commentMode(CommentMode.alternativeWriter("%s")) 54 | // Enables writing YAML comments 55 | .build(); 56 | ConfManager val = new ConfManager<>(configFolder, fileName, 57 | new SnakeYamlConfigurationFactory<>(configClass, new ConfigurationOptions.Builder().sorter(new AnnotationBasedSorter()).build(), yamlOptions)); 58 | val.confname = fileName; 59 | return val; 60 | } 61 | 62 | public static Map defaultGroups() { 63 | Map groups = new HashMap<>(); 64 | groups.put("default", new DefaultGroupImpl()); 65 | return groups; 66 | } 67 | 68 | public void reloadConfig() { 69 | try { 70 | configData = reloadConfigData(); 71 | } catch (IOException ex) { 72 | throw new ConfigurationLoadException(ex, confname); 73 | 74 | } catch (ConfigFormatSyntaxException ex) { 75 | configData = getFactory().loadDefaults(); 76 | 77 | throw new ConfigurationLoadException(ex, confname); 78 | 79 | } catch (InvalidConfigException ex) { 80 | configData = getFactory().loadDefaults(); 81 | 82 | throw new ConfigurationLoadException(ex, confname); 83 | } 84 | } 85 | 86 | public C getConfigData() { 87 | C configData = this.configData; 88 | if (configData == null) { 89 | throw new IllegalStateException("Configuration has not been loaded yet"); 90 | } 91 | return configData; 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /core/src/main/java/dev/bluetree242/advancedplhide/config/Config.java: -------------------------------------------------------------------------------- 1 | /* 2 | * LICENSE 3 | * AdvancedPlHide 4 | * ------------- 5 | * Copyright (C) 2021 - 2024 BlueTree242 6 | * ------------- 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as 9 | * published by the Free Software Foundation, either version 3 of the 10 | * License, or (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public 18 | * License along with this program. If not, see 19 | * . 20 | * END 21 | */ 22 | 23 | package dev.bluetree242.advancedplhide.config; 24 | 25 | import space.arim.dazzleconf.annote.ConfComments; 26 | import space.arim.dazzleconf.annote.ConfDefault; 27 | import space.arim.dazzleconf.annote.ConfHeader; 28 | import space.arim.dazzleconf.annote.SubSection; 29 | import space.arim.dazzleconf.sorter.AnnotationBasedSorter; 30 | 31 | import java.util.List; 32 | import java.util.Map; 33 | 34 | @ConfHeader("# You should read this before doing anything with the plugin, to understand how stuff work: https://github.com/BlueTree242/AdvancedPlHide/wiki/") 35 | public interface Config { 36 | 37 | @AnnotationBasedSorter.Order(10) 38 | @ConfComments("#Message to send when the player tries to run /plugins, bypass: plhide.command.use") 39 | @ConfDefault.DefaultString("&cWe won't show you the plugin list for sure.") 40 | String pl_message(); 41 | 42 | @AnnotationBasedSorter.Order(20) 43 | @ConfComments("#Removes the plugin:command from tabcompleter, it function better than spigot does it") 44 | @ConfDefault.DefaultBoolean(true) 45 | Boolean remove_plugin_prefix(); 46 | 47 | @AnnotationBasedSorter.Order(30) 48 | @ConfComments("\n# https://github.com/BlueTree242/AdvancedPlHide/wiki/groups") 49 | //space between the groups and the conf options up 50 | @ConfDefault.DefaultObject("dev.bluetree242.advancedplhide.config.ConfManager.defaultGroups") 51 | Map groups(); 52 | 53 | @AnnotationBasedSorter.Order(40) 54 | @ConfComments("# If you disable this, we will not notify you of new dev builds but of new major or beta updates") 55 | @ConfDefault.DefaultBoolean(true) 56 | boolean dev_updatechecker(); 57 | 58 | interface Group { 59 | @AnnotationBasedSorter.Order(10) 60 | List tabcomplete(); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /core/src/main/java/dev/bluetree242/advancedplhide/config/DefaultGroupImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * LICENSE 3 | * AdvancedPlHide 4 | * ------------- 5 | * Copyright (C) 2021 - 2024 BlueTree242 6 | * ------------- 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as 9 | * published by the Free Software Foundation, either version 3 of the 10 | * License, or (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public 18 | * License along with this program. If not, see 19 | * . 20 | * END 21 | */ 22 | 23 | package dev.bluetree242.advancedplhide.config; 24 | 25 | import java.util.ArrayList; 26 | import java.util.List; 27 | 28 | public class DefaultGroupImpl implements Config.Group { 29 | protected DefaultGroupImpl() { 30 | } 31 | 32 | @Override 33 | public List tabcomplete() { 34 | List result = new ArrayList<>(); 35 | result.add("serverlistplus"); 36 | result.add("pl"); 37 | result.add("plugins"); 38 | result.add("version"); 39 | result.add("example1"); 40 | result.add("example2"); 41 | return result; 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /core/src/main/java/dev/bluetree242/advancedplhide/config/subcompleter/ConfSubCompleter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * LICENSE 3 | * AdvancedPlHide 4 | * ------------- 5 | * Copyright (C) 2021 - 2024 BlueTree242 6 | * ------------- 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as 9 | * published by the Free Software Foundation, either version 3 of the 10 | * License, or (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public 18 | * License along with this program. If not, see 19 | * . 20 | * END 21 | */ 22 | 23 | package dev.bluetree242.advancedplhide.config.subcompleter; 24 | 25 | import org.jetbrains.annotations.NotNull; 26 | 27 | import java.util.ArrayList; 28 | import java.util.Arrays; 29 | import java.util.List; 30 | import java.util.Objects; 31 | 32 | public class ConfSubCompleter { 33 | private final String name; 34 | private final String[] args; 35 | 36 | public ConfSubCompleter(@NotNull String name, @NotNull String[] args) { 37 | this.name = name; 38 | this.args = args; 39 | } 40 | 41 | /** 42 | * @param cmd - command in config, the full string with 0 modifications 43 | * @return {@link ConfSubCompleter} of this command 44 | */ 45 | public static ConfSubCompleter of(@NotNull String cmd) { 46 | String[] split = cmd.trim().split(" "); 47 | String name = split[0]; 48 | List args = new ArrayList<>(Arrays.asList(split)); 49 | args.remove(name); 50 | return new ConfSubCompleter(name, args.toArray(new String[0])); 51 | } 52 | 53 | public String getName() { 54 | return name; 55 | } 56 | 57 | public String[] getArgs() { 58 | return args; 59 | } 60 | 61 | @Override 62 | public boolean equals(Object o) { 63 | if (this == o) return true; 64 | if (!(o instanceof ConfSubCompleter)) return false; 65 | ConfSubCompleter that = (ConfSubCompleter) o; 66 | return getName().equals(that.getName()) && Arrays.equals(getArgs(), that.getArgs()); 67 | } 68 | 69 | @Override 70 | public int hashCode() { 71 | int result = Objects.hash(getName()); 72 | result = 31 * result + Arrays.hashCode(getArgs()); 73 | return result; 74 | } 75 | 76 | @Override 77 | public String toString() { 78 | return name + " " + String.join(" ", args); 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /core/src/main/java/dev/bluetree242/advancedplhide/config/subcompleter/ConfSubCompleterList.java: -------------------------------------------------------------------------------- 1 | /* 2 | * LICENSE 3 | * AdvancedPlHide 4 | * ------------- 5 | * Copyright (C) 2021 - 2024 BlueTree242 6 | * ------------- 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as 9 | * published by the Free Software Foundation, either version 3 of the 10 | * License, or (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public 18 | * License along with this program. If not, see 19 | * . 20 | * END 21 | */ 22 | 23 | package dev.bluetree242.advancedplhide.config.subcompleter; 24 | 25 | import java.util.ArrayList; 26 | 27 | public class ConfSubCompleterList extends ArrayList { 28 | 29 | /** 30 | * @param cmd Command to fetch all completers of 31 | * @return {@link ConfSubCompleterList} of completers with this command 32 | */ 33 | public ConfSubCompleterList ofCommand(String cmd) { 34 | ConfSubCompleterList result = new ConfSubCompleterList(); 35 | for (ConfSubCompleter completer : this) { 36 | if (completer.getName().equalsIgnoreCase(cmd)) { 37 | result.add(completer); 38 | } 39 | } 40 | return result; 41 | } 42 | 43 | /** 44 | * This method tries to find commands with this args, respects * and ~ 45 | * 46 | * @param args args of the command 47 | * @return list of sub completers that have this args 48 | */ 49 | public ConfSubCompleterList ofArgs(String[] args) { 50 | ConfSubCompleterList result = new ConfSubCompleterList(); 51 | for (ConfSubCompleter completer : this) { 52 | boolean equal = true; 53 | int length = 0; 54 | if (completer.getArgs().length == args.length) { 55 | for (String arg : completer.getArgs()) { 56 | if (equal) { 57 | equal = args[length].equalsIgnoreCase(arg) || arg.equals("*"); 58 | } 59 | length++; 60 | } 61 | } else { 62 | equal = false; 63 | } 64 | if (equal) result.add(completer); 65 | } 66 | return result; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /core/src/main/java/dev/bluetree242/advancedplhide/exceptions/ConfigurationLoadException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * LICENSE 3 | * AdvancedPlHide 4 | * ------------- 5 | * Copyright (C) 2021 - 2024 BlueTree242 6 | * ------------- 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as 9 | * published by the Free Software Foundation, either version 3 of the 10 | * License, or (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public 18 | * License along with this program. If not, see 19 | * . 20 | * END 21 | */ 22 | 23 | package dev.bluetree242.advancedplhide.exceptions; 24 | 25 | import space.arim.dazzleconf.error.ConfigFormatSyntaxException; 26 | 27 | public class ConfigurationLoadException extends RuntimeException { 28 | 29 | private final Throwable cause; 30 | private final String confname; 31 | 32 | public ConfigurationLoadException(Throwable ex, String confname) { 33 | this.cause = ex; 34 | this.confname = confname; 35 | } 36 | 37 | @Override 38 | public Throwable getCause() { 39 | return cause; 40 | } 41 | 42 | @Override 43 | public String getMessage() { 44 | 45 | return "Error Loading/Reloading the " + confname + "." + (cause instanceof ConfigFormatSyntaxException ? " Check the syntax at https://yaml-online-parser.appspot.com/" : " Please make sure all options have right types"); 46 | } 47 | 48 | public String getConfigName() { 49 | return confname; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /core/src/main/java/dev/bluetree242/advancedplhide/impl/completer/RootCommandCompleter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * LICENSE 3 | * AdvancedPlHide 4 | * ------------- 5 | * Copyright (C) 2021 - 2024 BlueTree242 6 | * ------------- 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as 9 | * published by the Free Software Foundation, either version 3 of the 10 | * License, or (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public 18 | * License along with this program. If not, see 19 | * . 20 | * END 21 | */ 22 | 23 | package dev.bluetree242.advancedplhide.impl.completer; 24 | 25 | import com.mojang.brigadier.tree.CommandNode; 26 | import dev.bluetree242.advancedplhide.CommandCompleter; 27 | 28 | public class RootCommandCompleter implements CommandCompleter { 29 | private final CommandNode node; 30 | private final RootNodeCommandCompleter list; 31 | 32 | public RootCommandCompleter(CommandNode node, RootNodeCommandCompleter list) { 33 | this.list = list; 34 | this.node = node; 35 | } 36 | 37 | @Override 38 | public String getName() { 39 | return node.getName(); 40 | } 41 | 42 | @Override 43 | public void remove() { 44 | list.remove(this); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /core/src/main/java/dev/bluetree242/advancedplhide/impl/completer/RootNodeCommandCompleter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * LICENSE 3 | * AdvancedPlHide 4 | * ------------- 5 | * Copyright (C) 2021 - 2024 BlueTree242 6 | * ------------- 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as 9 | * published by the Free Software Foundation, either version 3 of the 10 | * License, or (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public 18 | * License along with this program. If not, see 19 | * . 20 | * END 21 | */ 22 | 23 | package dev.bluetree242.advancedplhide.impl.completer; 24 | 25 | import com.mojang.brigadier.tree.CommandNode; 26 | import com.mojang.brigadier.tree.RootCommandNode; 27 | import dev.bluetree242.advancedplhide.CommandCompleterList; 28 | 29 | import java.util.ArrayList; 30 | 31 | public class RootNodeCommandCompleter extends CommandCompleterList { 32 | private final RootCommandNode node; 33 | 34 | public RootNodeCommandCompleter(RootCommandNode root) { 35 | for (Object child : root.getChildren()) { 36 | add(new RootCommandCompleter((CommandNode) child, this)); 37 | } 38 | this.node = root; 39 | } 40 | 41 | @Override 42 | public RootCommandNode export() { 43 | return node; 44 | } 45 | 46 | @Override 47 | public boolean remove(Object e) { 48 | if (!(e instanceof RootCommandCompleter)) 49 | throw new IllegalArgumentException("May only remove RootCommandCompleter"); 50 | RootCommandCompleter completer = (RootCommandCompleter) e; 51 | for (Object child : new ArrayList<>(node.getChildren())) { 52 | CommandNode real = (CommandNode) child; 53 | if (completer.getName().equalsIgnoreCase(real.getName())) { 54 | super.remove(completer); 55 | return node.getChildren().remove(real); 56 | } 57 | } 58 | return false; 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /core/src/main/java/dev/bluetree242/advancedplhide/impl/completer/SuggestionCommandCompleter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * LICENSE 3 | * AdvancedPlHide 4 | * ------------- 5 | * Copyright (C) 2021 - 2024 BlueTree242 6 | * ------------- 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as 9 | * published by the Free Software Foundation, either version 3 of the 10 | * License, or (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public 18 | * License along with this program. If not, see 19 | * . 20 | * END 21 | */ 22 | 23 | package dev.bluetree242.advancedplhide.impl.completer; 24 | 25 | import com.mojang.brigadier.suggestion.Suggestion; 26 | import dev.bluetree242.advancedplhide.CommandCompleter; 27 | 28 | public class SuggestionCommandCompleter implements CommandCompleter { 29 | private final Suggestion suggestion; 30 | private final SuggestionCommandCompleterList list; 31 | 32 | public SuggestionCommandCompleter(Suggestion suggestion, SuggestionCommandCompleterList list) { 33 | this.list = list; 34 | this.suggestion = suggestion; 35 | } 36 | 37 | @Override 38 | public String getName() { 39 | return suggestion.getText(); 40 | } 41 | 42 | @Override 43 | public void remove() { 44 | list.remove(this); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /core/src/main/java/dev/bluetree242/advancedplhide/impl/completer/SuggestionCommandCompleterList.java: -------------------------------------------------------------------------------- 1 | /* 2 | * LICENSE 3 | * AdvancedPlHide 4 | * ------------- 5 | * Copyright (C) 2021 - 2024 BlueTree242 6 | * ------------- 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as 9 | * published by the Free Software Foundation, either version 3 of the 10 | * License, or (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public 18 | * License along with this program. If not, see 19 | * . 20 | * END 21 | */ 22 | 23 | package dev.bluetree242.advancedplhide.impl.completer; 24 | 25 | import com.mojang.brigadier.suggestion.Suggestion; 26 | import com.mojang.brigadier.suggestion.Suggestions; 27 | import dev.bluetree242.advancedplhide.CommandCompleter; 28 | import dev.bluetree242.advancedplhide.CommandCompleterList; 29 | 30 | public class SuggestionCommandCompleterList extends CommandCompleterList { 31 | private final Suggestions suggestions; 32 | 33 | public SuggestionCommandCompleterList(Suggestions suggestions) { 34 | this.suggestions = suggestions; 35 | for (Suggestion suggestion : suggestions.getList()) { 36 | add(new SuggestionCommandCompleter(suggestion, this)); 37 | } 38 | } 39 | 40 | @Override 41 | public Suggestions export() { 42 | return suggestions; 43 | } 44 | 45 | 46 | @Override 47 | public boolean remove(Object e) { 48 | if (!(e instanceof CommandCompleter)) throw new IllegalArgumentException("May only remove a CommandCompleter"); 49 | CommandCompleter completer = (CommandCompleter) e; 50 | for (Suggestion suggestion : suggestions.getList()) { 51 | if (suggestion.getText().equalsIgnoreCase(completer.getName())) { 52 | super.remove(completer); 53 | return suggestions.getList().remove(suggestion); 54 | } 55 | } 56 | return false; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /core/src/main/java/dev/bluetree242/advancedplhide/impl/group/GroupCompleter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * LICENSE 3 | * AdvancedPlHide 4 | * ------------- 5 | * Copyright (C) 2021 - 2024 BlueTree242 6 | * ------------- 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as 9 | * published by the Free Software Foundation, either version 3 of the 10 | * License, or (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public 18 | * License along with this program. If not, see 19 | * . 20 | * END 21 | */ 22 | 23 | package dev.bluetree242.advancedplhide.impl.group; 24 | 25 | import dev.bluetree242.advancedplhide.CommandCompleter; 26 | 27 | public class GroupCompleter implements CommandCompleter { 28 | private final String name; 29 | 30 | public GroupCompleter(String name) { 31 | this.name = name; 32 | } 33 | 34 | @Override 35 | public String getName() { 36 | return name; 37 | } 38 | 39 | @Override 40 | public void remove() { 41 | throw new UnsupportedOperationException("Completer not in a list"); 42 | } 43 | 44 | @Override 45 | public String toString() { 46 | return "CC:" + getName(); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /core/src/main/java/dev/bluetree242/advancedplhide/impl/subcompleter/SuggestionSubCommandCompleter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * LICENSE 3 | * AdvancedPlHide 4 | * ------------- 5 | * Copyright (C) 2021 - 2024 BlueTree242 6 | * ------------- 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as 9 | * published by the Free Software Foundation, either version 3 of the 10 | * License, or (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public 18 | * License along with this program. If not, see 19 | * . 20 | * END 21 | */ 22 | 23 | package dev.bluetree242.advancedplhide.impl.subcompleter; 24 | 25 | import dev.bluetree242.advancedplhide.SubCommandCompleter; 26 | 27 | public class SuggestionSubCommandCompleter implements SubCommandCompleter { 28 | private final SuggestionSubCommandCompleterList list; 29 | private final String text; 30 | 31 | public SuggestionSubCommandCompleter(SuggestionSubCommandCompleterList list, String text) { 32 | this.list = list; 33 | this.text = text; 34 | } 35 | 36 | @Override 37 | public String getText() { 38 | return text; 39 | } 40 | 41 | @Override 42 | public void remove() { 43 | list.remove(this); 44 | } 45 | 46 | 47 | } 48 | -------------------------------------------------------------------------------- /core/src/main/java/dev/bluetree242/advancedplhide/impl/subcompleter/SuggestionSubCommandCompleterList.java: -------------------------------------------------------------------------------- 1 | /* 2 | * LICENSE 3 | * AdvancedPlHide 4 | * ------------- 5 | * Copyright (C) 2021 - 2024 BlueTree242 6 | * ------------- 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as 9 | * published by the Free Software Foundation, either version 3 of the 10 | * License, or (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public 18 | * License along with this program. If not, see 19 | * . 20 | * END 21 | */ 22 | 23 | package dev.bluetree242.advancedplhide.impl.subcompleter; 24 | 25 | import com.mojang.brigadier.suggestion.Suggestion; 26 | import com.mojang.brigadier.suggestion.Suggestions; 27 | import dev.bluetree242.advancedplhide.SubCommandCompleter; 28 | import dev.bluetree242.advancedplhide.SubCommandCompleterList; 29 | 30 | import java.util.ArrayList; 31 | import java.util.List; 32 | 33 | public class SuggestionSubCommandCompleterList extends SubCommandCompleterList { 34 | private final Suggestions suggestions; 35 | private final String command; 36 | private final String[] args; 37 | 38 | public SuggestionSubCommandCompleterList(Suggestions suggestions, String notCompleted) { 39 | this.suggestions = suggestions; 40 | for (Suggestion suggestion : suggestions.getList()) { 41 | add(new SuggestionSubCommandCompleter(this, suggestion.getText())); 42 | } 43 | String[] split = notCompleted.trim().split(" "); 44 | command = split[0].replaceFirst("/", ""); 45 | List list = new ArrayList<>(); 46 | for (String s : split) { 47 | if (!s.equalsIgnoreCase("/" + command)) { 48 | if (notCompleted.endsWith(" ")) 49 | list.add(s); 50 | else { 51 | if (!s.equals(split[split.length - 1])) { 52 | list.add(s); 53 | } 54 | } 55 | } 56 | } 57 | args = list.toArray(new String[0]); 58 | } 59 | 60 | @Override 61 | public Suggestions export() { 62 | return suggestions; 63 | } 64 | 65 | @Override 66 | public String[] getArgs() { 67 | return args; 68 | } 69 | 70 | @Override 71 | public String getName() { 72 | return command; 73 | } 74 | 75 | @Override 76 | public boolean remove(Object e) { 77 | if (!(e instanceof SubCommandCompleter)) 78 | throw new IllegalArgumentException("May only remove a SubCommandCompleter"); 79 | SubCommandCompleter completer = (SubCommandCompleter) e; 80 | for (Suggestion suggestion : suggestions.getList()) { 81 | if (suggestion.getText().equalsIgnoreCase(completer.getText())) { 82 | super.remove(completer); 83 | return suggestions.getList().remove(suggestion); 84 | } 85 | } 86 | return false; 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /core/src/main/java/dev/bluetree242/advancedplhide/impl/version/UpdateCheckResult.java: -------------------------------------------------------------------------------- 1 | /* 2 | * LICENSE 3 | * AdvancedPlHide 4 | * ------------- 5 | * Copyright (C) 2021 - 2024 BlueTree242 6 | * ------------- 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as 9 | * published by the Free Software Foundation, either version 3 of the 10 | * License, or (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public 18 | * License along with this program. If not, see 19 | * . 20 | * END 21 | */ 22 | 23 | package dev.bluetree242.advancedplhide.impl.version; 24 | 25 | public class UpdateCheckResult { 26 | private final int versionsBehind; 27 | private final String message; 28 | private final String loggerType; 29 | private final String updateUrl; 30 | 31 | public UpdateCheckResult(int versionsBehind, String message, String loggerType, String updateUrl) { 32 | this.versionsBehind = versionsBehind; 33 | this.message = message; 34 | this.loggerType = loggerType; 35 | this.updateUrl = updateUrl; 36 | } 37 | 38 | public int getVersionsBehind() { 39 | return versionsBehind; 40 | } 41 | 42 | public String getMessage() { 43 | return message; 44 | } 45 | 46 | public String getLoggerType() { 47 | return loggerType; 48 | } 49 | 50 | public String getUpdateUrl() { 51 | return updateUrl; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /core/src/main/java/dev/bluetree242/advancedplhide/utils/Constants.java: -------------------------------------------------------------------------------- 1 | /* 2 | * LICENSE 3 | * AdvancedPlHide 4 | * ------------- 5 | * Copyright (C) 2021 - 2024 BlueTree242 6 | * ------------- 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as 9 | * published by the Free Software Foundation, either version 3 of the 10 | * License, or (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public 18 | * License along with this program. If not, see 19 | * . 20 | * END 21 | */ 22 | 23 | package dev.bluetree242.advancedplhide.utils; 24 | 25 | import dev.bluetree242.advancedplhide.PlatformPlugin; 26 | import dev.bluetree242.advancedplhide.PluginInfo; 27 | 28 | public class Constants { 29 | public static final String DEFAULT_UP_TO_DATE = "&aYou are up to date"; 30 | public static final String DEFAULT_BEHIND = "&cYou are {versions} Behind. Please Update ASAP. Download from {download}"; 31 | public static final String WHITELIST_MODE_PERMISSION = "plhide.whitelist-mode"; 32 | 33 | @SuppressWarnings({"ConstantValue", "MismatchedStringCase"}) 34 | public static String startupMessage() { 35 | return "\n[]=====[&2Enabling AdvancedPlHide&r]=====[]\n" + 36 | "| &cInformation:\n&r" + 37 | "| &cName: &rAdvancedPlHide\n&r" + 38 | "| &cDevelopers: &rBlueTree242\n&r" + 39 | "| &cVersion: &r" + PluginInfo.VERSION + "\n&r" + 40 | (!PluginInfo.BUILD_NUMBER.equals("NONE") ? "| &cBuild Number: &r#" + PluginInfo.BUILD_NUMBER + "\n&r" : "") + 41 | "| &cRunning on: &r" + PlatformPlugin.get().getType().getName() + "\n&r" + 42 | "| &cSupport:\n&r" + 43 | "| &cGithub: &rhttps://github.com/BlueTree242/AdvancedPlHide/issues\n" + 44 | "| &cDiscord: &rhttps://advancedplhide.ml/support\n" + 45 | "[]================================[]"; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /core/src/main/java/dev/bluetree242/advancedplhide/utils/HTTPRequestMultipartBody.java: -------------------------------------------------------------------------------- 1 | /* 2 | * LICENSE 3 | * AdvancedPlHide 4 | * ------------- 5 | * Copyright (C) 2021 - 2024 BlueTree242 6 | * ------------- 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as 9 | * published by the Free Software Foundation, either version 3 of the 10 | * License, or (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public 18 | * License along with this program. If not, see 19 | * . 20 | * END 21 | */ 22 | 23 | package dev.bluetree242.advancedplhide.utils; 24 | 25 | import com.intellectualsites.http.ContentType; 26 | import com.intellectualsites.http.EntityMapper; 27 | import org.jetbrains.annotations.NotNull; 28 | 29 | import java.io.ByteArrayOutputStream; 30 | import java.io.IOException; 31 | import java.math.BigInteger; 32 | import java.nio.charset.StandardCharsets; 33 | import java.security.SecureRandom; 34 | import java.util.ArrayList; 35 | import java.util.List; 36 | 37 | public class HTTPRequestMultipartBody { 38 | // From https://varaprasadh.medium.com/how-to-send-multipart-form-data-requests-using-java-native-httpclient-989f6921dbfa 39 | private final byte[] bytes; 40 | private String boundary; 41 | 42 | private HTTPRequestMultipartBody(byte[] bytes, String boundary) { 43 | this.bytes = bytes; 44 | this.boundary = boundary; 45 | } 46 | 47 | public String getBoundary() { 48 | return boundary; 49 | } 50 | 51 | public void setBoundary(String boundary) { 52 | this.boundary = boundary; 53 | } 54 | 55 | public String getContentType() { 56 | return "multipart/form-data; boundary=" + this.getBoundary(); 57 | } 58 | 59 | public byte[] getBody() { 60 | return this.bytes; 61 | } 62 | 63 | public static class Builder { 64 | List parts; 65 | 66 | public Builder() { 67 | this.parts = new ArrayList<>(); 68 | } 69 | 70 | public Builder addPart(String fieldName, String fieldValue) { 71 | MultiPartRecord part = new MultiPartRecord(); 72 | part.setFieldName(fieldName); 73 | part.setContent(fieldValue); 74 | String DEFAULT_MIMETYPE = "text/plain"; 75 | this.parts.add(part); 76 | return this; 77 | } 78 | 79 | public Builder addPart(String fieldName, String fieldValue, String contentType) { 80 | MultiPartRecord part = new MultiPartRecord(); 81 | part.setFieldName(fieldName); 82 | part.setContent(fieldValue); 83 | this.parts.add(part); 84 | return this; 85 | } 86 | 87 | public Builder addPart(String fieldName, String fieldValue, String contentType, String fileName) { 88 | MultiPartRecord part = new MultiPartRecord(); 89 | part.setFieldName(fieldName); 90 | part.setContent(fieldValue); 91 | this.parts.add(part); 92 | return this; 93 | } 94 | 95 | public HTTPRequestMultipartBody build() throws IOException { 96 | String boundary = new BigInteger(256, new SecureRandom()).toString(); 97 | ByteArrayOutputStream out = new ByteArrayOutputStream(); 98 | for (MultiPartRecord record : parts) { 99 | out.write(("--" + boundary + "\r\n" + "Content-Disposition: form-data; name=\"" + record.getFieldName()).getBytes(StandardCharsets.UTF_8)); 100 | out.write(("\"\r\n").getBytes(StandardCharsets.UTF_8)); 101 | Object content = record.getContent(); 102 | out.write(("\r\n").getBytes(StandardCharsets.UTF_8)); 103 | out.write(((String) content).getBytes(StandardCharsets.UTF_8)); 104 | out.write("\r\n".getBytes(StandardCharsets.UTF_8)); 105 | } 106 | out.write(("--" + boundary + "--\r\n").getBytes(StandardCharsets.UTF_8)); 107 | 108 | return new HTTPRequestMultipartBody(out.toByteArray(), boundary); 109 | } 110 | 111 | public static class MultiPartRecord { 112 | private String fieldName; 113 | private String content; 114 | 115 | public String getFieldName() { 116 | return fieldName; 117 | } 118 | 119 | public void setFieldName(String fieldName) { 120 | this.fieldName = fieldName; 121 | } 122 | 123 | public Object getContent() { 124 | return content; 125 | } 126 | 127 | public void setContent(String content) { 128 | this.content = content; 129 | } 130 | } 131 | } 132 | 133 | public static class MultiPartSerializer implements EntityMapper.EntitySerializer { 134 | 135 | @Override 136 | public byte @NotNull [] serialize(@NotNull HTTPRequestMultipartBody input) { 137 | return input.getBody(); 138 | } 139 | 140 | @Override 141 | public ContentType getContentType() { 142 | return ContentType.STRING_UTF8; // No input... Must overwrite. 143 | } 144 | } 145 | } 146 | -------------------------------------------------------------------------------- /core/src/main/java/dev/bluetree242/advancedplhide/utils/UsedMap.java: -------------------------------------------------------------------------------- 1 | /* 2 | * LICENSE 3 | * AdvancedPlHide 4 | * ------------- 5 | * Copyright (C) 2021 - 2024 BlueTree242 6 | * ------------- 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as 9 | * published by the Free Software Foundation, either version 3 of the 10 | * License, or (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public 18 | * License along with this program. If not, see 19 | * . 20 | * END 21 | */ 22 | 23 | package dev.bluetree242.advancedplhide.utils; 24 | 25 | import java.util.HashMap; 26 | 27 | public class UsedMap extends HashMap { 28 | 29 | } 30 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # 2 | # LICENSE 3 | # AdvancedPlHide 4 | # ------------- 5 | # Copyright (C) 2021 - 2024 BlueTree242 6 | # ------------- 7 | # This program is free software: you can redistribute it and/or modify 8 | # it under the terms of the GNU General Public License as 9 | # published by the Free Software Foundation, either version 3 of the 10 | # License, or (at your option) any later version. 11 | # 12 | # This program is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | # GNU General Public License for more details. 16 | # 17 | # You should have received a copy of the GNU General Public 18 | # License along with this program. If not, see 19 | # . 20 | # END 21 | # 22 | group=dev.bluetree242 23 | name=AdvancedPlHide 24 | version=2.5 25 | description=A plugin that allows you to remove parts of tab completion and hide plugins from the tabcompleter! -------------------------------------------------------------------------------- /gradle/libs.versions.toml: -------------------------------------------------------------------------------- 1 | metadata.format.version = "1.1" 2 | 3 | [versions] 4 | 5 | # Plugins 6 | protocolLib = "5.1.0" 7 | protocolize = "2.3.3" 8 | 9 | # Shaded 10 | json = "20240303" 11 | dazzleconf = "1.3.0-M2" 12 | http4j = "1.3" 13 | 14 | # Server Software 15 | spigot = "1.13-R0.1-SNAPSHOT" 16 | velocity = "3.3.0-SNAPSHOT" 17 | bungee = "1.20-R0.2" 18 | 19 | # Common 20 | brigadier = "1.0.500" 21 | 22 | [libraries] 23 | protocolLib = { group = "com.comphenix.protocol", name = "ProtocolLib", version.ref = "protocolLib" } 24 | protocolize = { group = "dev.simplix", name = "protocolize-api", version.ref = "protocolize" } 25 | 26 | 27 | json = { group = "org.json", name = "json", version.ref = "json" } 28 | dazzleconf = { group = "space.arim.dazzleconf", name = "dazzleconf-ext-snakeyaml", version.ref = "dazzleconf" } 29 | http4j = { group = "com.intellectualsites.http", name = "HTTP4J", version.ref = "http4j" } 30 | 31 | spigot = { group = "org.spigotmc", name = "spigot-api", version.ref = "spigot" } 32 | velocity-api = { group = "com.velocitypowered", name = "velocity-api", version.ref = "velocity" } 33 | velocity-proxy = { group = "com.velocitypowered", name = "velocity-proxy", version.ref = "velocity" } 34 | bungee = { group = "net.md-5", name = "bungeecord-api", version.ref = "bungee" } 35 | 36 | brigadier = { group = "com.mojang", name = "brigadier", version.ref = "brigadier" } 37 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlueTree242/AdvancedPlHide/0bae74b5d149a21365c78fbce15036541dacba67/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | # 2 | # LICENSE 3 | # AdvancedPlHide 4 | # ------------- 5 | # Copyright (C) 2021 - 2024 BlueTree242 6 | # ------------- 7 | # This program is free software: you can redistribute it and/or modify 8 | # it under the terms of the GNU General Public License as 9 | # published by the Free Software Foundation, either version 3 of the 10 | # License, or (at your option) any later version. 11 | # 12 | # This program is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | # GNU General Public License for more details. 16 | # 17 | # You should have received a copy of the GNU General Public 18 | # License along with this program. If not, see 19 | # . 20 | # END 21 | # 22 | distributionBase=GRADLE_USER_HOME 23 | distributionPath=wrapper/dists 24 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip 25 | zipStoreBase=GRADLE_USER_HOME 26 | zipStorePath=wrapper/dists 27 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | # 4 | # LICENSE 5 | # AdvancedPlHide 6 | # ------------- 7 | # Copyright (C) 2021 - 2024 BlueTree242 8 | # ------------- 9 | # This program is free software: you can redistribute it and/or modify 10 | # it under the terms of the GNU General Public License as 11 | # published by the Free Software Foundation, either version 3 of the 12 | # License, or (at your option) any later version. 13 | # 14 | # This program is distributed in the hope that it will be useful, 15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | # GNU General Public License for more details. 18 | # 19 | # You should have received a copy of the GNU General Public 20 | # License along with this program. If not, see 21 | # . 22 | # END 23 | # 24 | 25 | ############################################################################## 26 | ## 27 | ## Gradle start up script for UN*X 28 | ## 29 | ############################################################################## 30 | 31 | # Attempt to set APP_HOME 32 | # Resolve links: $0 may be a link 33 | PRG="$0" 34 | # Need this for relative symlinks. 35 | while [ -h "$PRG" ] ; do 36 | ls=`ls -ld "$PRG"` 37 | link=`expr "$ls" : '.*-> \(.*\)$'` 38 | if expr "$link" : '/.*' > /dev/null; then 39 | PRG="$link" 40 | else 41 | PRG=`dirname "$PRG"`"/$link" 42 | fi 43 | done 44 | SAVED="`pwd`" 45 | cd "`dirname \"$PRG\"`/" >/dev/null 46 | APP_HOME="`pwd -P`" 47 | cd "$SAVED" >/dev/null 48 | 49 | APP_NAME="Gradle" 50 | APP_BASE_NAME=`basename "$0"` 51 | 52 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 53 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 54 | 55 | # Use the maximum available, or set MAX_FD != -1 to use that value. 56 | MAX_FD="maximum" 57 | 58 | warn () { 59 | echo "$*" 60 | } 61 | 62 | die () { 63 | echo 64 | echo "$*" 65 | echo 66 | exit 1 67 | } 68 | 69 | # OS specific support (must be 'true' or 'false'). 70 | cygwin=false 71 | msys=false 72 | darwin=false 73 | nonstop=false 74 | case "`uname`" in 75 | CYGWIN* ) 76 | cygwin=true 77 | ;; 78 | Darwin* ) 79 | darwin=true 80 | ;; 81 | MINGW* ) 82 | msys=true 83 | ;; 84 | NONSTOP* ) 85 | nonstop=true 86 | ;; 87 | esac 88 | 89 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 90 | 91 | 92 | # Determine the Java command to use to start the JVM. 93 | if [ -n "$JAVA_HOME" ] ; then 94 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 95 | # IBM's JDK on AIX uses strange locations for the executables 96 | JAVACMD="$JAVA_HOME/jre/sh/java" 97 | else 98 | JAVACMD="$JAVA_HOME/bin/java" 99 | fi 100 | if [ ! -x "$JAVACMD" ] ; then 101 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 102 | 103 | Please set the JAVA_HOME variable in your environment to match the 104 | location of your Java installation." 105 | fi 106 | else 107 | JAVACMD="java" 108 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 109 | 110 | Please set the JAVA_HOME variable in your environment to match the 111 | location of your Java installation." 112 | fi 113 | 114 | # Increase the maximum file descriptors if we can. 115 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 116 | MAX_FD_LIMIT=`ulimit -H -n` 117 | if [ $? -eq 0 ] ; then 118 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 119 | MAX_FD="$MAX_FD_LIMIT" 120 | fi 121 | ulimit -n $MAX_FD 122 | if [ $? -ne 0 ] ; then 123 | warn "Could not set maximum file descriptor limit: $MAX_FD" 124 | fi 125 | else 126 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 127 | fi 128 | fi 129 | 130 | # For Darwin, add options to specify how the application appears in the dock 131 | if $darwin; then 132 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 133 | fi 134 | 135 | # For Cygwin or MSYS, switch paths to Windows format before running java 136 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then 137 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 138 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 139 | 140 | JAVACMD=`cygpath --unix "$JAVACMD"` 141 | 142 | # We build the pattern for arguments to be converted via cygpath 143 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 144 | SEP="" 145 | for dir in $ROOTDIRSRAW ; do 146 | ROOTDIRS="$ROOTDIRS$SEP$dir" 147 | SEP="|" 148 | done 149 | OURCYGPATTERN="(^($ROOTDIRS))" 150 | # Add a user-defined pattern to the cygpath arguments 151 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 152 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 153 | fi 154 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 155 | i=0 156 | for arg in "$@" ; do 157 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 158 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 159 | 160 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 161 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 162 | else 163 | eval `echo args$i`="\"$arg\"" 164 | fi 165 | i=`expr $i + 1` 166 | done 167 | case $i in 168 | 0) set -- ;; 169 | 1) set -- "$args0" ;; 170 | 2) set -- "$args0" "$args1" ;; 171 | 3) set -- "$args0" "$args1" "$args2" ;; 172 | 4) set -- "$args0" "$args1" "$args2" "$args3" ;; 173 | 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 174 | 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 175 | 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 176 | 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 177 | 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 178 | esac 179 | fi 180 | 181 | # Escape application args 182 | save () { 183 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 184 | echo " " 185 | } 186 | APP_ARGS=`save "$@"` 187 | 188 | # Collect all arguments for the java command, following the shell quoting and substitution rules 189 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 190 | 191 | exec "$JAVACMD" "$@" 192 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto execute 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto execute 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :execute 68 | @rem Setup the command line 69 | 70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 71 | 72 | 73 | @rem Execute Gradle 74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 75 | 76 | :end 77 | @rem End local scope for the variables with windows NT shell 78 | if "%ERRORLEVEL%"=="0" goto mainEnd 79 | 80 | :fail 81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 82 | rem the _cmd.exe /c_ return code! 83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 84 | exit /b 1 85 | 86 | :mainEnd 87 | if "%OS%"=="Windows_NT" endlocal 88 | 89 | :omega 90 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * LICENSE 3 | * AdvancedPlHide 4 | * ------------- 5 | * Copyright (C) 2021 - 2021 BlueTree242 6 | * ------------- 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as 9 | * published by the Free Software Foundation, either version 3 of the 10 | * License, or (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public 18 | * License along with this program. If not, see 19 | * . 20 | * END 21 | */ 22 | pluginManagement { 23 | repositories { 24 | gradlePluginPortal() 25 | maven { 26 | url 'https://repo.papermc.io/repository/maven-public/' 27 | } 28 | } 29 | } 30 | rootProject.name = 'AdvancedPlHide' 31 | include 'core' 32 | include 'spigot' 33 | include 'velocity' 34 | include 'bungee' 35 | include 'spigot:modern' 36 | findProject(':spigot:modern')?.name = 'modern' 37 | include 'spigot:modern' 38 | findProject(':spigot:modern')?.name = 'modern' 39 | include 'spigot:modern:V1_19_NMS' 40 | findProject(':spigot:modern:V1_19_NMS')?.name = 'V1_19_NMS' 41 | include 'spigot:modern:V1_19_3_NMS' 42 | findProject(':spigot:modern:V1_19_3_NMS')?.name = 'V1_19_3_NMS' 43 | include 'spigot:modern:V1_20_5_NMS' 44 | findProject(':spigot:modern:V1_20_5_NMS')?.name = 'V1_20_5_NMS' 45 | 46 | -------------------------------------------------------------------------------- /spigot/build.gradle.kts: -------------------------------------------------------------------------------- 1 | /* 2 | * LICENSE 3 | * AdvancedPlHide 4 | * ------------- 5 | * Copyright (C) 2021 - 2024 BlueTree242 6 | * ------------- 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as 9 | * published by the Free Software Foundation, either version 3 of the 10 | * License, or (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public 18 | * License along with this program. If not, see 19 | * . 20 | * END 21 | */ 22 | plugins { 23 | id("net.minecrell.plugin-yml.bukkit") version "0.6.0" 24 | id("com.github.johnrengelman.shadow") 25 | } 26 | repositories { 27 | maven("https://repo.papermc.io/repository/maven-public/") 28 | maven("https://hub.spigotmc.org/nexus/content/repositories/snapshots/") 29 | maven("https://repo.dmulloy2.net/repository/public/") 30 | maven("https://repo.destroystokyo.com/repository/maven-public/") 31 | maven("https://libraries.minecraft.net") 32 | } 33 | 34 | dependencies { 35 | implementation(project(":spigot:modern")) 36 | implementation(project(":spigot:modern:V1_19_NMS", "reobf")) 37 | implementation(project(":spigot:modern:V1_19_3_NMS", "reobf")) 38 | implementation(project(":spigot:modern:V1_20_5_NMS", "reobf")) 39 | compileOnly(libs.brigadier) 40 | compileOnly(libs.spigot) 41 | implementation(project(":core")) 42 | compileOnly(libs.protocolLib) 43 | } 44 | 45 | bukkit { 46 | name = rootProject.name 47 | description = rootProject.description 48 | version = project.version.toString() 49 | main = "dev.bluetree242.advancedplhide.spigot.AdvancedPlHideSpigot" 50 | author = "BlueTree242" 51 | depend = listOf("ProtocolLib") 52 | apiVersion = "1.13" 53 | commands { 54 | register("advancedplhide") { 55 | aliases = listOf("aph", "plhide", "ph") 56 | } 57 | } 58 | } -------------------------------------------------------------------------------- /spigot/modern/V1_19_3_NMS/build.gradle.kts: -------------------------------------------------------------------------------- 1 | /* 2 | * LICENSE 3 | * AdvancedPlHide 4 | * ------------- 5 | * Copyright (C) 2021 - 2024 BlueTree242 6 | * ------------- 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as 9 | * published by the Free Software Foundation, either version 3 of the 10 | * License, or (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public 18 | * License along with this program. If not, see 19 | * . 20 | * END 21 | */ 22 | 23 | plugins { 24 | id("io.papermc.paperweight.userdev") 25 | } 26 | 27 | java { 28 | toolchain.languageVersion.set(JavaLanguageVersion.of(17)) 29 | } 30 | 31 | dependencies { 32 | paperweight.paperDevBundle("1.19.3-R0.1-SNAPSHOT") 33 | } -------------------------------------------------------------------------------- /spigot/modern/V1_19_3_NMS/src/main/java/dev/bluetree242/advancedplhide/spigot/modern/V1_19_3_Handler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * LICENSE 3 | * AdvancedPlHide 4 | * ------------- 5 | * Copyright (C) 2021 - 2024 BlueTree242 6 | * ------------- 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as 9 | * published by the Free Software Foundation, either version 3 of the 10 | * License, or (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public 18 | * License along with this program. If not, see 19 | * . 20 | * END 21 | */ 22 | 23 | package dev.bluetree242.advancedplhide.spigot.modern; 24 | 25 | import com.comphenix.protocol.PacketType; 26 | import com.comphenix.protocol.events.PacketContainer; 27 | import com.comphenix.protocol.events.PacketEvent; 28 | import com.mojang.brigadier.tree.RootCommandNode; 29 | import dev.bluetree242.advancedplhide.CompleterModifier; 30 | import dev.bluetree242.advancedplhide.Group; 31 | import dev.bluetree242.advancedplhide.impl.completer.RootNodeCommandCompleter; 32 | import net.minecraft.commands.Commands; 33 | import net.minecraft.commands.SharedSuggestionProvider; 34 | import net.minecraft.data.registries.VanillaRegistries; 35 | import net.minecraft.network.protocol.game.ClientboundCommandsPacket; 36 | 37 | public class V1_19_3_Handler implements ModernHandler { 38 | @Override 39 | public void handleCommands(PacketEvent packetEvent, Group group, boolean whitelist) { 40 | ClientboundCommandsPacket packet = (ClientboundCommandsPacket) packetEvent.getPacket().getHandle(); 41 | RootCommandNode nodeOrigin = packet.getRoot(Commands.createValidationContext(VanillaRegistries.createLookup())); // Get the command node out 42 | RootNodeCommandCompleter node = new RootNodeCommandCompleter(nodeOrigin); 43 | CompleterModifier.handleCompleter(node, group, whitelist); 44 | //noinspection unchecked 45 | packetEvent.setPacket(new PacketContainer(PacketType.Play.Server.COMMANDS, new ClientboundCommandsPacket(node.export()))); // Put the modified root node in a new packet because it's not really possible to modify 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /spigot/modern/V1_19_NMS/build.gradle.kts: -------------------------------------------------------------------------------- 1 | /* 2 | * LICENSE 3 | * AdvancedPlHide 4 | * ------------- 5 | * Copyright (C) 2021 - 2024 BlueTree242 6 | * ------------- 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as 9 | * published by the Free Software Foundation, either version 3 of the 10 | * License, or (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public 18 | * License along with this program. If not, see 19 | * . 20 | * END 21 | */ 22 | 23 | plugins { 24 | id("io.papermc.paperweight.userdev") 25 | } 26 | 27 | java { 28 | toolchain.languageVersion.set(JavaLanguageVersion.of(17)) 29 | } 30 | 31 | dependencies { 32 | paperweight.paperDevBundle("1.19-R0.1-SNAPSHOT") 33 | } -------------------------------------------------------------------------------- /spigot/modern/V1_19_NMS/src/main/java/dev/bluetree242/advancedplhide/spigot/modern/V1_19_Handler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * LICENSE 3 | * AdvancedPlHide 4 | * ------------- 5 | * Copyright (C) 2021 - 2024 BlueTree242 6 | * ------------- 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as 9 | * published by the Free Software Foundation, either version 3 of the 10 | * License, or (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public 18 | * License along with this program. If not, see 19 | * . 20 | * END 21 | */ 22 | 23 | package dev.bluetree242.advancedplhide.spigot.modern; 24 | 25 | import com.comphenix.protocol.PacketType; 26 | import com.comphenix.protocol.events.PacketContainer; 27 | import com.comphenix.protocol.events.PacketEvent; 28 | import com.mojang.brigadier.tree.RootCommandNode; 29 | import dev.bluetree242.advancedplhide.CompleterModifier; 30 | import dev.bluetree242.advancedplhide.Group; 31 | import dev.bluetree242.advancedplhide.impl.completer.RootNodeCommandCompleter; 32 | import net.minecraft.commands.CommandBuildContext; 33 | import net.minecraft.commands.SharedSuggestionProvider; 34 | import net.minecraft.core.RegistryAccess; 35 | import net.minecraft.network.protocol.game.ClientboundCommandsPacket; 36 | 37 | public class V1_19_Handler implements ModernHandler { 38 | @Override 39 | public void handleCommands(PacketEvent packetEvent, Group group, boolean whitelist) { 40 | ClientboundCommandsPacket packet = (ClientboundCommandsPacket) packetEvent.getPacket().getHandle(); 41 | RootCommandNode nodeOrigin = packet.getRoot(new CommandBuildContext(RegistryAccess.BUILTIN.get())); // Get the command node out 42 | RootNodeCommandCompleter node = new RootNodeCommandCompleter(nodeOrigin); 43 | CompleterModifier.handleCompleter(node, group, whitelist); 44 | //noinspection unchecked 45 | packetEvent.setPacket(new PacketContainer(PacketType.Play.Server.COMMANDS, new ClientboundCommandsPacket(node.export()))); // Put the modified root node in a new packet because it's not really possible to modify 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /spigot/modern/V1_20_5_NMS/build.gradle.kts: -------------------------------------------------------------------------------- 1 | /* 2 | * LICENSE 3 | * AdvancedPlHide 4 | * ------------- 5 | * Copyright (C) 2021 - 2024 BlueTree242 6 | * ------------- 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as 9 | * published by the Free Software Foundation, either version 3 of the 10 | * License, or (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public 18 | * License along with this program. If not, see 19 | * . 20 | * END 21 | */ 22 | 23 | plugins { 24 | id("io.papermc.paperweight.userdev") 25 | } 26 | 27 | java { 28 | toolchain.languageVersion.set(JavaLanguageVersion.of(21)) 29 | } 30 | 31 | tasks.compileJava { 32 | options.release.set(17) // So that it compiles, otherwise it thinks Record class doesn't exist 33 | } 34 | 35 | dependencies { 36 | paperweight.paperDevBundle("1.20.5-R0.1-SNAPSHOT") 37 | } -------------------------------------------------------------------------------- /spigot/modern/V1_20_5_NMS/src/main/java/dev/bluetree242/advancedplhide/spigot/modern/V1_20_5_Handler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * LICENSE 3 | * AdvancedPlHide 4 | * ------------- 5 | * Copyright (C) 2021 - 2024 BlueTree242 6 | * ------------- 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as 9 | * published by the Free Software Foundation, either version 3 of the 10 | * License, or (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public 18 | * License along with this program. If not, see 19 | * . 20 | * END 21 | */ 22 | 23 | package dev.bluetree242.advancedplhide.spigot.modern; 24 | 25 | import com.comphenix.protocol.PacketType; 26 | import com.comphenix.protocol.events.PacketContainer; 27 | import com.comphenix.protocol.events.PacketEvent; 28 | import com.comphenix.protocol.reflect.StructureModifier; 29 | import com.mojang.brigadier.suggestion.Suggestions; 30 | import com.mojang.brigadier.tree.RootCommandNode; 31 | import dev.bluetree242.advancedplhide.CompleterModifier; 32 | import dev.bluetree242.advancedplhide.Group; 33 | import dev.bluetree242.advancedplhide.impl.completer.RootNodeCommandCompleter; 34 | import net.minecraft.commands.Commands; 35 | import net.minecraft.commands.SharedSuggestionProvider; 36 | import net.minecraft.data.registries.VanillaRegistries; 37 | import net.minecraft.network.protocol.game.ClientboundCommandSuggestionsPacket; 38 | import net.minecraft.network.protocol.game.ClientboundCommandsPacket; 39 | 40 | import java.util.ArrayList; 41 | 42 | public class V1_20_5_Handler implements ModernHandler { 43 | @Override 44 | public void handleCommands(PacketEvent packetEvent, Group group, boolean whitelist) { 45 | ClientboundCommandsPacket packet = (ClientboundCommandsPacket) packetEvent.getPacket().getHandle(); 46 | RootCommandNode nodeOrigin = packet.getRoot(Commands.createValidationContext(VanillaRegistries.createLookup())); // Get the command node out 47 | RootNodeCommandCompleter node = new RootNodeCommandCompleter(nodeOrigin); 48 | CompleterModifier.handleCompleter(node, group, whitelist); 49 | //noinspection unchecked 50 | packetEvent.setPacket(new PacketContainer(PacketType.Play.Server.COMMANDS, new ClientboundCommandsPacket(node.export()))); // Put the modified root node in a new packet because it's not really possible to modify 51 | } 52 | 53 | @Override 54 | public Suggestions getSuggestions(PacketEvent packetEvent) { 55 | ClientboundCommandSuggestionsPacket packet = (ClientboundCommandSuggestionsPacket) packetEvent.getPacket().getHandle(); 56 | Suggestions suggestions = packet.toSuggestions(); 57 | return new Suggestions(suggestions.getRange(), new ArrayList<>(suggestions.getList())); 58 | } 59 | 60 | @Override 61 | public void writeSuggestions(PacketEvent packetEvent, StructureModifier modifier, Suggestions suggestions) { 62 | ClientboundCommandSuggestionsPacket packet = (ClientboundCommandSuggestionsPacket) packetEvent.getPacket().getHandle(); 63 | packetEvent.setPacket(new PacketContainer(PacketType.Play.Server.TAB_COMPLETE, new ClientboundCommandSuggestionsPacket(packet.id(), suggestions))); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /spigot/modern/build.gradle.kts: -------------------------------------------------------------------------------- 1 | /* 2 | * LICENSE 3 | * AdvancedPlHide 4 | * ------------- 5 | * Copyright (C) 2021 - 2024 BlueTree242 6 | * ------------- 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as 9 | * published by the Free Software Foundation, either version 3 of the 10 | * License, or (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public 18 | * License along with this program. If not, see 19 | * . 20 | * END 21 | */ 22 | 23 | repositories { 24 | maven("https://repo.dmulloy2.net/repository/public/") 25 | maven("https://libraries.minecraft.net") 26 | } 27 | 28 | subprojects { 29 | dependencies { 30 | compileOnly(project(":spigot:modern")) 31 | compileOnly(project(":core")) 32 | compileOnly(rootProject.libs.protocolLib) 33 | } 34 | repositories { 35 | maven("https://repo.dmulloy2.net/repository/public/") 36 | } 37 | } 38 | 39 | dependencies { 40 | compileOnly(project(":core")) 41 | compileOnly(libs.protocolLib) 42 | compileOnly(libs.brigadier) 43 | } -------------------------------------------------------------------------------- /spigot/modern/src/main/java/dev/bluetree242/advancedplhide/spigot/modern/ModernHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * LICENSE 3 | * AdvancedPlHide 4 | * ------------- 5 | * Copyright (C) 2021 - 2024 BlueTree242 6 | * ------------- 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as 9 | * published by the Free Software Foundation, either version 3 of the 10 | * License, or (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public 18 | * License along with this program. If not, see 19 | * . 20 | * END 21 | */ 22 | 23 | package dev.bluetree242.advancedplhide.spigot.modern; 24 | 25 | import com.comphenix.protocol.events.PacketEvent; 26 | import com.comphenix.protocol.reflect.StructureModifier; 27 | import com.mojang.brigadier.suggestion.Suggestions; 28 | import dev.bluetree242.advancedplhide.Group; 29 | 30 | public interface ModernHandler { 31 | 32 | void handleCommands(PacketEvent packetEvent, Group group, boolean whitelist); 33 | 34 | default Suggestions getSuggestions(PacketEvent packetEvent) { 35 | throw new UnsupportedOperationException(); 36 | } 37 | 38 | default void writeSuggestions(PacketEvent packetEvent, StructureModifier modifier, Suggestions suggestions) { 39 | modifier.write(0, suggestions); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /spigot/src/main/java/dev/bluetree242/advancedplhide/spigot/AdvancedPlHideCommand.java: -------------------------------------------------------------------------------- 1 | /* 2 | * LICENSE 3 | * AdvancedPlHide 4 | * ------------- 5 | * Copyright (C) 2021 - 2024 BlueTree242 6 | * ------------- 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as 9 | * published by the Free Software Foundation, either version 3 of the 10 | * License, or (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public 18 | * License along with this program. If not, see 19 | * . 20 | * END 21 | */ 22 | 23 | package dev.bluetree242.advancedplhide.spigot; 24 | 25 | import dev.bluetree242.advancedplhide.PlatformPlugin; 26 | import dev.bluetree242.advancedplhide.exceptions.ConfigurationLoadException; 27 | import org.bukkit.Bukkit; 28 | import org.bukkit.ChatColor; 29 | import org.bukkit.command.Command; 30 | import org.bukkit.command.CommandExecutor; 31 | import org.bukkit.command.CommandSender; 32 | 33 | import java.util.ArrayList; 34 | import java.util.List; 35 | 36 | public class AdvancedPlHideCommand implements CommandExecutor { 37 | private final AdvancedPlHideSpigot core; 38 | 39 | public AdvancedPlHideCommand(AdvancedPlHideSpigot core) { 40 | this.core = core; 41 | } 42 | 43 | 44 | @Override 45 | public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { 46 | if (args.length == 0) { 47 | sender.sendMessage(ChatColor.GREEN + "Running AdvancedPlHide v." + ChatColor.YELLOW + core.getDescription().getVersion()); 48 | return true; 49 | } else { 50 | if (args[0].equalsIgnoreCase("reload")) { 51 | if (!sender.hasPermission("plhide.reload")) { 52 | sender.sendMessage(ChatColor.RED + "You don't have permission to run this command"); 53 | return true; 54 | } else { 55 | Bukkit.getScheduler().runTaskAsynchronously(core, () -> { 56 | try { 57 | PlatformPlugin.get().reloadConfig(); 58 | sender.sendMessage(ChatColor.GREEN + "Configuration Reloaded"); 59 | } catch (ConfigurationLoadException e) { 60 | sender.sendMessage(ChatColor.RED + "Could not reload " + e.getConfigName()); 61 | } 62 | }); 63 | return true; 64 | } 65 | } 66 | } 67 | sender.sendMessage(ChatColor.RED + "SubCommand not found"); 68 | return true; 69 | } 70 | 71 | public static class TabCompleter implements org.bukkit.command.TabCompleter { 72 | 73 | @Override 74 | public List onTabComplete(CommandSender sender, Command command, String alias, String[] args) { 75 | List result = new ArrayList<>(); 76 | List arg1 = new ArrayList<>(); 77 | if (args.length == 1) 78 | if (sender.hasPermission("plhide.reload")) { 79 | arg1.add("reload"); 80 | } 81 | for (String s : arg1) { 82 | if (s.startsWith(args[0])) { 83 | result.add(s); 84 | } 85 | } 86 | return result; 87 | } 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /spigot/src/main/java/dev/bluetree242/advancedplhide/spigot/AdvancedPlHideSpigot.java: -------------------------------------------------------------------------------- 1 | /* 2 | * LICENSE 3 | * AdvancedPlHide 4 | * ------------- 5 | * Copyright (C) 2021 - 2024 BlueTree242 6 | * ------------- 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as 9 | * published by the Free Software Foundation, either version 3 of the 10 | * License, or (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public 18 | * License along with this program. If not, see 19 | * . 20 | * END 21 | */ 22 | 23 | package dev.bluetree242.advancedplhide.spigot; 24 | 25 | import com.comphenix.protocol.ProtocolLibrary; 26 | import com.comphenix.protocol.ProtocolManager; 27 | import dev.bluetree242.advancedplhide.Group; 28 | import dev.bluetree242.advancedplhide.PlatformPlugin; 29 | import dev.bluetree242.advancedplhide.impl.version.UpdateCheckResult; 30 | import dev.bluetree242.advancedplhide.spigot.listener.event.SpigotEventListener; 31 | import dev.bluetree242.advancedplhide.spigot.listener.packet.SpigotPacketListener; 32 | import dev.bluetree242.advancedplhide.spigot.modern.ModernHandler; 33 | import dev.bluetree242.advancedplhide.spigot.modern.V1_19_3_Handler; 34 | import dev.bluetree242.advancedplhide.spigot.modern.V1_19_Handler; 35 | import dev.bluetree242.advancedplhide.spigot.modern.V1_20_5_Handler; 36 | import dev.bluetree242.advancedplhide.utils.Constants; 37 | import org.bukkit.Bukkit; 38 | import org.bukkit.ChatColor; 39 | import org.bukkit.command.Command; 40 | import org.bukkit.command.CommandMap; 41 | import org.bukkit.command.PluginIdentifiableCommand; 42 | import org.bukkit.entity.Player; 43 | import org.bukkit.event.Listener; 44 | import org.bukkit.plugin.Plugin; 45 | import org.bukkit.plugin.java.JavaPlugin; 46 | 47 | import java.io.File; 48 | import java.lang.reflect.Field; 49 | import java.util.ArrayList; 50 | import java.util.List; 51 | 52 | 53 | public class AdvancedPlHideSpigot extends JavaPlugin implements Listener { 54 | private final SpigotPacketListener listener = new SpigotPacketListener(this); 55 | private final AdvancedPlHideSpigot.Impl platformPlugin = new Impl(); 56 | private ProtocolManager protocolManager; 57 | private boolean legacy = false; 58 | private List groups; 59 | private ModernHandler modernHandler; 60 | 61 | public Group getGroupForPlayer(Player player) { 62 | if (player.hasPermission("plhide.no-group")) return null; 63 | List groups = new ArrayList<>(); 64 | for (Group group : platformPlugin.getGroups()) { 65 | if (player.hasPermission("plhide.group." + group.getName())) { 66 | groups.add(group); 67 | } 68 | } 69 | return groups.isEmpty() ? platformPlugin.getGroup("default") : platformPlugin.mergeGroups(groups); 70 | } 71 | 72 | public void onLoad() { 73 | protocolManager = ProtocolLibrary.getProtocolManager(); 74 | PlatformPlugin.setPlatform(platformPlugin); 75 | platformPlugin.initConfigManager(); 76 | } 77 | 78 | public void onEnable() { 79 | platformPlugin.reloadConfig(); 80 | protocolManager.addPacketListener(new SpigotPacketListener(this)); 81 | getServer().getPluginManager().registerEvents(new SpigotEventListener(this), this); 82 | String mv = Bukkit.getServer().getBukkitVersion(); 83 | legacy = (mv.startsWith("1.8") || mv.startsWith("1.9") || mv.startsWith("1.10") || mv.startsWith("1.11") || mv.startsWith("1.12")); 84 | boolean modernNeeded = !(mv.startsWith("1.13") || mv.startsWith("1.14") || mv.startsWith("1.15") || mv.startsWith("1.16") || mv.startsWith("1.17") || mv.startsWith("1.18")); 85 | if (!legacy && modernNeeded) { 86 | if (mv.startsWith("1.19.1")) { 87 | modernHandler = new V1_19_Handler(); 88 | } else if (mv.startsWith("1.19.3") || mv.startsWith("1.19.4") || (mv.startsWith("1.20") && Integer.parseInt(mv.substring(5, 6)) <= 4)) { // Expect 1.19.3+ 89 | modernHandler = new V1_19_3_Handler(); 90 | } else { 91 | modernHandler = new V1_20_5_Handler(); 92 | } 93 | } 94 | getServer().getPluginCommand("advancedplhide").setExecutor(new AdvancedPlHideCommand(this)); 95 | getServer().getPluginCommand("advancedplhide").setTabCompleter(new AdvancedPlHideCommand.TabCompleter()); 96 | new Metrics(this, 13707); 97 | Bukkit.getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', Constants.startupMessage())); 98 | performStartUpdateCheck(); 99 | } 100 | 101 | public void onDisable() { 102 | protocolManager.removePacketListener(listener); 103 | } 104 | 105 | public boolean isLegacy() { 106 | return legacy; 107 | } 108 | 109 | public ModernHandler getModernHandler() { 110 | return modernHandler; 111 | } 112 | 113 | public void performStartUpdateCheck() { 114 | Bukkit.getScheduler().runTaskAsynchronously(this, () -> { 115 | try { 116 | UpdateCheckResult result = Impl.get().updateCheck(); 117 | String msg = result.getVersionsBehind() == 0 ? 118 | ChatColor.translateAlternateColorCodes('&', Constants.DEFAULT_UP_TO_DATE) : 119 | ChatColor.translateAlternateColorCodes('&', Constants.DEFAULT_BEHIND.replace("{versions}", result.getVersionsBehind() + "") 120 | .replace("{download}", result.getUpdateUrl())); 121 | if (result.getMessage() != null) { 122 | msg = ChatColor.translateAlternateColorCodes('&', result.getMessage()); 123 | } 124 | switch (result.getLoggerType()) { 125 | case "INFO": 126 | getLogger().info(msg); 127 | break; 128 | case "WARNING": 129 | getLogger().warning(msg); 130 | break; 131 | case "ERROR": 132 | getLogger().severe(msg); 133 | break; 134 | } 135 | } catch (Throwable ex) { 136 | getLogger().severe(String.format("Could not check for updates: %s", ex.getMessage())); 137 | } 138 | }); 139 | } 140 | 141 | public List getGroups() { 142 | return groups; 143 | } 144 | 145 | public void loadGroups() { 146 | groups = new ArrayList<>(); 147 | platformPlugin.getConfig().groups().forEach((name, val) -> { 148 | if (getGroup(name) == null) 149 | groups.add(new Group(name, val.tabcomplete())); 150 | else { 151 | getLogger().warning("Group " + name + " is repeated."); 152 | } 153 | }); 154 | if (getGroup("default") == null) { 155 | getLogger().warning("group default was not found. If someone has no permission for any group, no group applies on them"); 156 | 157 | } 158 | 159 | } 160 | 161 | public Group getGroup(String name) { 162 | for (Group group : groups) { 163 | if (group.getName().equals(name)) return group; 164 | } 165 | return null; 166 | } 167 | 168 | public CommandMap getCommandMap() { 169 | try { 170 | final Field bukkitCommandMap = Bukkit.getServer().getClass().getDeclaredField("commandMap"); 171 | 172 | bukkitCommandMap.setAccessible(true); 173 | return (CommandMap) bukkitCommandMap.get(Bukkit.getServer()); 174 | } catch (Exception e) { 175 | return null; 176 | } 177 | } 178 | 179 | 180 | public class Impl extends PlatformPlugin { 181 | 182 | @Override 183 | public void loadGroups() { 184 | AdvancedPlHideSpigot.this.loadGroups(); 185 | } 186 | 187 | @Override 188 | public File getDataFolder() { 189 | return AdvancedPlHideSpigot.this.getDataFolder(); 190 | } 191 | 192 | @Override 193 | public List getGroups() { 194 | return AdvancedPlHideSpigot.this.getGroups(); 195 | } 196 | 197 | @Override 198 | public Group getGroup(String name) { 199 | return AdvancedPlHideSpigot.this.getGroup(name); 200 | } 201 | 202 | @Override 203 | public String getPluginForCommand(String s) { 204 | Command command = getCommandMap().getCommand(s); 205 | if (!(command instanceof PluginIdentifiableCommand)) return "minecraft"; 206 | Plugin plugin = ((PluginIdentifiableCommand) command).getPlugin(); 207 | if (plugin == null) return null; 208 | return plugin.getName(); 209 | } 210 | 211 | @Override 212 | public Type getType() { 213 | return Type.SPIGOT; 214 | } 215 | } 216 | 217 | 218 | } 219 | -------------------------------------------------------------------------------- /spigot/src/main/java/dev/bluetree242/advancedplhide/spigot/impl/completer/StringCommandCompleter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * LICENSE 3 | * AdvancedPlHide 4 | * ------------- 5 | * Copyright (C) 2021 - 2024 BlueTree242 6 | * ------------- 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as 9 | * published by the Free Software Foundation, either version 3 of the 10 | * License, or (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public 18 | * License along with this program. If not, see 19 | * . 20 | * END 21 | */ 22 | 23 | package dev.bluetree242.advancedplhide.spigot.impl.completer; 24 | 25 | import dev.bluetree242.advancedplhide.CommandCompleter; 26 | 27 | public class StringCommandCompleter implements CommandCompleter { 28 | private final String name; 29 | private final StringCommandCompleterList list; 30 | 31 | public StringCommandCompleter(String name, StringCommandCompleterList list) { 32 | this.list = list; 33 | this.name = name.replaceFirst("/", ""); 34 | } 35 | 36 | @Override 37 | public String getName() { 38 | return name; 39 | } 40 | 41 | @Override 42 | public void remove() { 43 | list.remove(this); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /spigot/src/main/java/dev/bluetree242/advancedplhide/spigot/impl/completer/StringCommandCompleterList.java: -------------------------------------------------------------------------------- 1 | /* 2 | * LICENSE 3 | * AdvancedPlHide 4 | * ------------- 5 | * Copyright (C) 2021 - 2024 BlueTree242 6 | * ------------- 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as 9 | * published by the Free Software Foundation, either version 3 of the 10 | * License, or (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public 18 | * License along with this program. If not, see 19 | * . 20 | * END 21 | */ 22 | 23 | package dev.bluetree242.advancedplhide.spigot.impl.completer; 24 | 25 | import dev.bluetree242.advancedplhide.CommandCompleter; 26 | import dev.bluetree242.advancedplhide.CommandCompleterList; 27 | 28 | import java.util.ArrayList; 29 | import java.util.List; 30 | 31 | public class StringCommandCompleterList extends CommandCompleterList { 32 | 33 | public StringCommandCompleterList(String[] list) { 34 | for (String s : list) { 35 | add(new StringCommandCompleter(s, this)); 36 | } 37 | } 38 | 39 | 40 | @Override 41 | public String[] export() { 42 | List cmds = new ArrayList<>(); 43 | for (CommandCompleter completer : this) { 44 | cmds.add("/" + completer.getName()); 45 | } 46 | return cmds.toArray(new String[0]); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /spigot/src/main/java/dev/bluetree242/advancedplhide/spigot/impl/subcompleter/StringSubCommandCompleter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * LICENSE 3 | * AdvancedPlHide 4 | * ------------- 5 | * Copyright (C) 2021 - 2024 BlueTree242 6 | * ------------- 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as 9 | * published by the Free Software Foundation, either version 3 of the 10 | * License, or (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public 18 | * License along with this program. If not, see 19 | * . 20 | * END 21 | */ 22 | 23 | package dev.bluetree242.advancedplhide.spigot.impl.subcompleter; 24 | 25 | import dev.bluetree242.advancedplhide.SubCommandCompleter; 26 | 27 | public class StringSubCommandCompleter implements SubCommandCompleter { 28 | private final StringSubCommandCompleterList list; 29 | private final String text; 30 | 31 | public StringSubCommandCompleter(StringSubCommandCompleterList list, String text) { 32 | this.list = list; 33 | this.text = text; 34 | } 35 | 36 | @Override 37 | public String getText() { 38 | return text; 39 | } 40 | 41 | @Override 42 | public void remove() { 43 | list.remove(this); 44 | } 45 | 46 | 47 | } 48 | -------------------------------------------------------------------------------- /spigot/src/main/java/dev/bluetree242/advancedplhide/spigot/impl/subcompleter/StringSubCommandCompleterList.java: -------------------------------------------------------------------------------- 1 | /* 2 | * LICENSE 3 | * AdvancedPlHide 4 | * ------------- 5 | * Copyright (C) 2021 - 2024 BlueTree242 6 | * ------------- 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as 9 | * published by the Free Software Foundation, either version 3 of the 10 | * License, or (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public 18 | * License along with this program. If not, see 19 | * . 20 | * END 21 | */ 22 | 23 | package dev.bluetree242.advancedplhide.spigot.impl.subcompleter; 24 | 25 | import dev.bluetree242.advancedplhide.SubCommandCompleter; 26 | import dev.bluetree242.advancedplhide.SubCommandCompleterList; 27 | 28 | import java.util.ArrayList; 29 | import java.util.List; 30 | 31 | public class StringSubCommandCompleterList extends SubCommandCompleterList { 32 | private final String command; 33 | private final String[] args; 34 | 35 | public StringSubCommandCompleterList(String[] suggestions, String notCompleted) { 36 | for (String suggestion : suggestions) { 37 | add(new StringSubCommandCompleter(this, suggestion)); 38 | } 39 | String[] split = notCompleted.trim().split(" "); 40 | command = split[0].replaceFirst("/", ""); 41 | List list = new ArrayList<>(); 42 | for (String s : split) { 43 | if (!s.equalsIgnoreCase("/" + command)) { 44 | if (notCompleted.endsWith(" ")) 45 | list.add(s); 46 | else { 47 | if (!s.equals(split[split.length - 1])) { 48 | list.add(s); 49 | } 50 | } 51 | } 52 | } 53 | args = list.toArray(new String[0]); 54 | } 55 | 56 | @Override 57 | public String[] export() { 58 | List result = new ArrayList<>(); 59 | for (SubCommandCompleter sub : this) { 60 | result.add(sub.getText()); 61 | } 62 | return result.toArray(new String[0]); 63 | } 64 | 65 | @Override 66 | public String[] getArgs() { 67 | return args; 68 | } 69 | 70 | @Override 71 | public String getName() { 72 | return command; 73 | } 74 | 75 | 76 | } 77 | -------------------------------------------------------------------------------- /spigot/src/main/java/dev/bluetree242/advancedplhide/spigot/listener/event/SpigotEventListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * LICENSE 3 | * AdvancedPlHide 4 | * ------------- 5 | * Copyright (C) 2021 - 2024 BlueTree242 6 | * ------------- 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as 9 | * published by the Free Software Foundation, either version 3 of the 10 | * License, or (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public 18 | * License along with this program. If not, see 19 | * . 20 | * END 21 | */ 22 | 23 | package dev.bluetree242.advancedplhide.spigot.listener.event; 24 | 25 | import dev.bluetree242.advancedplhide.PlatformPlugin; 26 | import dev.bluetree242.advancedplhide.impl.version.UpdateCheckResult; 27 | import dev.bluetree242.advancedplhide.spigot.AdvancedPlHideSpigot; 28 | import dev.bluetree242.advancedplhide.utils.Constants; 29 | import org.bukkit.Bukkit; 30 | import org.bukkit.ChatColor; 31 | import org.bukkit.event.EventHandler; 32 | import org.bukkit.event.Listener; 33 | import org.bukkit.event.player.PlayerCommandPreprocessEvent; 34 | import org.bukkit.event.player.PlayerJoinEvent; 35 | 36 | public class SpigotEventListener implements Listener { 37 | private final AdvancedPlHideSpigot core; 38 | 39 | public SpigotEventListener(AdvancedPlHideSpigot core) { 40 | this.core = core; 41 | } 42 | 43 | @EventHandler 44 | public void onPlayerCommand(PlayerCommandPreprocessEvent e) { 45 | if (e.getPlayer().hasPermission("plhide.command.use")) return; 46 | String cmd = e.getMessage().toLowerCase().split(" ")[0]; 47 | if (cmd.equalsIgnoreCase("/plugins") || cmd.equalsIgnoreCase("/pl") || cmd.equalsIgnoreCase("/bukkit:pl") || cmd.equalsIgnoreCase("/bukkit:plugins")) { 48 | e.setCancelled(true); 49 | if (!PlatformPlugin.get().getConfig().pl_message().isEmpty()) { 50 | e.getPlayer().sendMessage(ChatColor.translateAlternateColorCodes('&', PlatformPlugin.get().getConfig().pl_message())); 51 | } 52 | } 53 | } 54 | 55 | @EventHandler 56 | public void onPlayerJoin(PlayerJoinEvent e) { 57 | if (e.getPlayer().hasPermission("plhide.updatechecker")) { 58 | Bukkit.getScheduler().runTaskAsynchronously(core, () -> { 59 | try { 60 | UpdateCheckResult result = PlatformPlugin.get().updateCheck(); 61 | String msg = result.getVersionsBehind() == 0 ? null : ChatColor.translateAlternateColorCodes('&', "&e[APH&r-&2Spigot&e] " + Constants.DEFAULT_BEHIND.replace("{versions}", result.getVersionsBehind() + "").replace("{download}", result.getUpdateUrl())); 62 | if (result.getMessage() != null) { 63 | msg = ChatColor.translateAlternateColorCodes('&', "&e[APH&r-&2Spigot&e] &c" + result.getMessage()); 64 | } 65 | if (msg != null) { 66 | e.getPlayer().sendMessage(msg); 67 | } 68 | } catch (Throwable ex) { 69 | core.getLogger().severe(String.format("Could not check for updates: %s", ex.getMessage())); 70 | } 71 | }); 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /spigot/src/main/java/dev/bluetree242/advancedplhide/spigot/listener/packet/SpigotPacketListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * LICENSE 3 | * AdvancedPlHide 4 | * ------------- 5 | * Copyright (C) 2021 - 2024 BlueTree242 6 | * ------------- 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as 9 | * published by the Free Software Foundation, either version 3 of the 10 | * License, or (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public 18 | * License along with this program. If not, see 19 | * . 20 | * END 21 | */ 22 | 23 | package dev.bluetree242.advancedplhide.spigot.listener.packet; 24 | 25 | import com.comphenix.protocol.PacketType; 26 | import com.comphenix.protocol.events.ListenerOptions; 27 | import com.comphenix.protocol.events.ListenerPriority; 28 | import com.comphenix.protocol.events.PacketAdapter; 29 | import com.comphenix.protocol.events.PacketEvent; 30 | import com.comphenix.protocol.injector.temporary.TemporaryPlayer; 31 | import com.comphenix.protocol.reflect.StructureModifier; 32 | import com.mojang.brigadier.suggestion.Suggestions; 33 | import com.mojang.brigadier.tree.RootCommandNode; 34 | import dev.bluetree242.advancedplhide.CompleterModifier; 35 | import dev.bluetree242.advancedplhide.impl.completer.RootNodeCommandCompleter; 36 | import dev.bluetree242.advancedplhide.impl.completer.SuggestionCommandCompleterList; 37 | import dev.bluetree242.advancedplhide.impl.subcompleter.SuggestionSubCommandCompleterList; 38 | import dev.bluetree242.advancedplhide.spigot.AdvancedPlHideSpigot; 39 | import dev.bluetree242.advancedplhide.spigot.impl.completer.StringCommandCompleterList; 40 | import dev.bluetree242.advancedplhide.spigot.impl.subcompleter.StringSubCommandCompleterList; 41 | import dev.bluetree242.advancedplhide.utils.Constants; 42 | import dev.bluetree242.advancedplhide.utils.UsedMap; 43 | 44 | import java.util.Arrays; 45 | import java.util.UUID; 46 | 47 | public class SpigotPacketListener extends PacketAdapter { 48 | 49 | private final UsedMap commandsWaiting = new UsedMap<>(); 50 | private final AdvancedPlHideSpigot core; 51 | 52 | public SpigotPacketListener(AdvancedPlHideSpigot core) { 53 | super(core, ListenerPriority.HIGHEST, Arrays.asList(PacketType.Play.Server.TAB_COMPLETE, PacketType.Play.Client.TAB_COMPLETE, PacketType.Play.Server.COMMANDS), ListenerOptions.ASYNC); 54 | this.core = core; 55 | } 56 | 57 | public void onPacketSending(PacketEvent e) { 58 | if (e.getPlayer() instanceof TemporaryPlayer) return; 59 | if (e.getPacketType() == PacketType.Play.Server.TAB_COMPLETE) { 60 | onTabcomplete(e); 61 | } else if (e.getPacketType() == PacketType.Play.Server.COMMANDS) { 62 | onCommands(e); 63 | } 64 | } 65 | 66 | private void onTabcomplete(PacketEvent e) { 67 | String notCompleted = this.commandsWaiting.get(e.getPlayer().getUniqueId()); 68 | if (notCompleted == null) notCompleted = "/"; 69 | if (!notCompleted.trim().startsWith("/")) notCompleted = "/" + notCompleted; 70 | if (!core.isLegacy()) { 71 | StructureModifier matchModifier = e.getPacket().getSpecificModifier(Suggestions.class); 72 | Suggestions suggestionsOrigin = matchModifier.readSafely(0); 73 | if (suggestionsOrigin == null) suggestionsOrigin = core.getModernHandler().getSuggestions(e); 74 | if (!notCompleted.contains(" ")) { 75 | SuggestionCommandCompleterList suggestions = new SuggestionCommandCompleterList(suggestionsOrigin); 76 | CompleterModifier.handleCompleter(suggestions, core.getGroupForPlayer(e.getPlayer()), e.getPlayer().hasPermission("plhide.whitelist-mode")); 77 | core.getModernHandler().writeSuggestions(e, matchModifier, suggestions.export()); 78 | } else { 79 | SuggestionSubCommandCompleterList suggestions = new SuggestionSubCommandCompleterList(suggestionsOrigin, notCompleted); 80 | CompleterModifier.handleSubCompleter(suggestions, core.getGroupForPlayer(e.getPlayer()), e.getPlayer().hasPermission(Constants.WHITELIST_MODE_PERMISSION)); 81 | if (suggestions.isCancelled()) e.setCancelled(true); 82 | core.getModernHandler().writeSuggestions(e, matchModifier, suggestions.export()); 83 | } 84 | } else { 85 | StructureModifier matchModifier = e.getPacket().getSpecificModifier(String[].class); 86 | String[] suggestionsOrigin = matchModifier.read(0); 87 | if (!notCompleted.contains(" ")) { 88 | StringCommandCompleterList suggestions = new StringCommandCompleterList(suggestionsOrigin); 89 | CompleterModifier.handleCompleter(suggestions, core.getGroupForPlayer(e.getPlayer()), e.getPlayer().hasPermission(Constants.WHITELIST_MODE_PERMISSION)); 90 | matchModifier.write(0, suggestions.export()); 91 | } else { 92 | StringSubCommandCompleterList suggestions = new StringSubCommandCompleterList(suggestionsOrigin, notCompleted); 93 | CompleterModifier.handleSubCompleter(suggestions, core.getGroupForPlayer(e.getPlayer()), e.getPlayer().hasPermission(Constants.WHITELIST_MODE_PERMISSION)); 94 | if (suggestions.isCancelled()) e.setCancelled(true); 95 | matchModifier.write(0, suggestions.export()); 96 | } 97 | } 98 | } 99 | 100 | private void onCommands(PacketEvent e) { 101 | //noinspection rawtypes 102 | StructureModifier matchModifier = e.getPacket().getSpecificModifier(RootCommandNode.class); 103 | RootCommandNode nodeOrigin = matchModifier.readSafely(0); 104 | if (nodeOrigin == null) { 105 | // Modern game, 1.19.1+ 106 | core.getModernHandler().handleCommands(e, core.getGroupForPlayer(e.getPlayer()), e.getPlayer().hasPermission(Constants.WHITELIST_MODE_PERMISSION)); 107 | return; 108 | } 109 | RootNodeCommandCompleter node = new RootNodeCommandCompleter(nodeOrigin); 110 | CompleterModifier.handleCompleter(node, core.getGroupForPlayer(e.getPlayer()), e.getPlayer().hasPermission(Constants.WHITELIST_MODE_PERMISSION)); 111 | matchModifier.write(0, node.export()); 112 | } 113 | 114 | public void onPacketReceiving(PacketEvent e) { 115 | if (e.getPlayer() instanceof TemporaryPlayer) return; 116 | if (e.isCancelled()) return; 117 | if (e.getPacketType() == PacketType.Play.Client.TAB_COMPLETE) { 118 | String s = e.getPacket().getStrings() 119 | .read(0); 120 | this.commandsWaiting.put(e.getPlayer().getUniqueId(), s); 121 | } 122 | } 123 | } 124 | -------------------------------------------------------------------------------- /velocity/build.gradle.kts: -------------------------------------------------------------------------------- 1 | /* 2 | * LICENSE 3 | * AdvancedPlHide 4 | * ------------- 5 | * Copyright (C) 2021 - 2021 BlueTree242 6 | * ------------- 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as 9 | * published by the Free Software Foundation, either version 3 of the 10 | * License, or (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public 18 | * License along with this program. If not, see 19 | * . 20 | * END 21 | */ 22 | 23 | plugins { 24 | id("com.github.johnrengelman.shadow") 25 | } 26 | 27 | 28 | repositories { 29 | maven("https://papermc.io/repo/repository/maven-public/") 30 | maven("https://maven.elytrium.net/repo/") 31 | maven("https://mvn.exceptionflug.de/repository/exceptionflug-public/") 32 | maven("https://libraries.minecraft.net") 33 | } 34 | 35 | dependencies { 36 | implementation(project(":core")) 37 | compileOnly(libs.velocity.api) 38 | annotationProcessor(libs.velocity.api) 39 | compileOnly(libs.velocity.proxy) 40 | compileOnly(libs.protocolize) 41 | } -------------------------------------------------------------------------------- /velocity/src/main/java/dev/bluetree242/advancedplhide/velocity/AdvancedPlHideCommand.java: -------------------------------------------------------------------------------- 1 | /* 2 | * LICENSE 3 | * AdvancedPlHide 4 | * ------------- 5 | * Copyright (C) 2021 - 2024 BlueTree242 6 | * ------------- 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as 9 | * published by the Free Software Foundation, either version 3 of the 10 | * License, or (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public 18 | * License along with this program. If not, see 19 | * . 20 | * END 21 | */ 22 | 23 | package dev.bluetree242.advancedplhide.velocity; 24 | 25 | import com.velocitypowered.api.command.CommandSource; 26 | import com.velocitypowered.api.command.SimpleCommand; 27 | import dev.bluetree242.advancedplhide.PlatformPlugin; 28 | import dev.bluetree242.advancedplhide.PluginInfo; 29 | import dev.bluetree242.advancedplhide.exceptions.ConfigurationLoadException; 30 | import net.kyori.adventure.text.Component; 31 | import net.kyori.adventure.text.format.NamedTextColor; 32 | import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; 33 | 34 | import java.util.ArrayList; 35 | import java.util.List; 36 | import java.util.concurrent.CompletableFuture; 37 | 38 | public class AdvancedPlHideCommand implements SimpleCommand { 39 | private final AdvancedPlHideVelocity core; 40 | 41 | public AdvancedPlHideCommand(AdvancedPlHideVelocity core) { 42 | this.core = core; 43 | } 44 | 45 | @Override 46 | public void execute(Invocation e) { 47 | String[] args = e.arguments(); 48 | CommandSource sender = e.source(); 49 | if (args.length == 0) { 50 | sender.sendMessage(LegacyComponentSerializer.legacy('&').deserialize("&aRunning AdvancedPlHide v.&e" + PluginInfo.VERSION)); 51 | return; 52 | } else { 53 | if (args[0].equalsIgnoreCase("reload")) { 54 | if (!sender.hasPermission("plhide.reload")) { 55 | sender.sendMessage(Component.text("You don't have permission to run this command").color(NamedTextColor.RED)); 56 | } else { 57 | core.server.getScheduler().buildTask(core, () -> { 58 | try { 59 | PlatformPlugin.get().reloadConfig(); 60 | sender.sendMessage(Component.text("Configuration Reloaded").color(NamedTextColor.GREEN)); 61 | } catch (ConfigurationLoadException ev) { 62 | sender.sendMessage(Component.text("Could not reload " + ev.getConfigName()).color(NamedTextColor.RED)); 63 | } 64 | }).schedule(); 65 | } 66 | return; 67 | } 68 | } 69 | sender.sendMessage(Component.text("SubCommand not found").color(NamedTextColor.RED)); 70 | } 71 | 72 | @Override 73 | public CompletableFuture> suggestAsync(Invocation invocation) { 74 | return CompletableFuture.supplyAsync(() -> { 75 | List result = new ArrayList<>(); 76 | if (invocation.arguments().length <= 2) { 77 | List arg1 = new ArrayList<>(); 78 | if (invocation.source().hasPermission("plhide.reload")) { 79 | arg1.add("reload"); 80 | } 81 | for (String s : arg1) { 82 | if (invocation.arguments().length != 0) { 83 | if (s.startsWith(invocation.arguments()[0])) { 84 | result.add(s); 85 | } 86 | } else { 87 | result.add(s); 88 | } 89 | } 90 | } 91 | return result; 92 | }); 93 | } 94 | 95 | @Override 96 | public boolean hasPermission(Invocation invocation) { 97 | return SimpleCommand.super.hasPermission(invocation); 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /velocity/src/main/java/dev/bluetree242/advancedplhide/velocity/AdvancedPlHideVelocity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * LICENSE 3 | * AdvancedPlHide 4 | * ------------- 5 | * Copyright (C) 2021 - 2024 BlueTree242 6 | * ------------- 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as 9 | * published by the Free Software Foundation, either version 3 of the 10 | * License, or (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public 18 | * License along with this program. If not, see 19 | * . 20 | * END 21 | */ 22 | 23 | package dev.bluetree242.advancedplhide.velocity; 24 | 25 | import com.velocitypowered.api.command.CommandMeta; 26 | import com.velocitypowered.api.event.Subscribe; 27 | import com.velocitypowered.api.event.proxy.ProxyInitializeEvent; 28 | import com.velocitypowered.api.plugin.Dependency; 29 | import com.velocitypowered.api.plugin.Plugin; 30 | import com.velocitypowered.api.plugin.annotation.DataDirectory; 31 | import com.velocitypowered.api.proxy.Player; 32 | import com.velocitypowered.api.proxy.ProxyServer; 33 | import dev.bluetree242.advancedplhide.Group; 34 | import dev.bluetree242.advancedplhide.PlatformPlugin; 35 | import dev.bluetree242.advancedplhide.PluginInfo; 36 | import dev.bluetree242.advancedplhide.impl.version.UpdateCheckResult; 37 | import dev.bluetree242.advancedplhide.utils.Constants; 38 | import dev.bluetree242.advancedplhide.velocity.listener.event.VelocityEventListener; 39 | import dev.bluetree242.advancedplhide.velocity.listener.packet.VelocityPacketListener; 40 | import dev.simplix.protocolize.api.Protocolize; 41 | import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; 42 | import org.slf4j.Logger; 43 | 44 | import javax.inject.Inject; 45 | import java.io.File; 46 | import java.nio.file.Path; 47 | import java.util.ArrayList; 48 | import java.util.List; 49 | 50 | @Plugin(id = "advancedplhide", 51 | name = "AdvancedPlHide", 52 | description = PluginInfo.DESCRIPTION, 53 | version = PluginInfo.VERSION, 54 | authors = {"BlueTree242"}, 55 | dependencies = {@Dependency(id = "protocolize")}) 56 | public class AdvancedPlHideVelocity extends PlatformPlugin { 57 | public final ProxyServer server; 58 | public final Logger logger; 59 | public final Path dataDirectory; 60 | private final Metrics.Factory metricsFactory; 61 | private List groups = new ArrayList<>(); 62 | 63 | @Inject 64 | public AdvancedPlHideVelocity(ProxyServer server, Logger logger, @DataDirectory Path dataDirectory, Metrics.Factory metricsFactory) { 65 | this.metricsFactory = metricsFactory; 66 | this.server = server; 67 | this.logger = logger; 68 | this.dataDirectory = dataDirectory; 69 | PlatformPlugin.setPlatform(this); 70 | initConfigManager(); 71 | } 72 | 73 | @Subscribe 74 | public void onProxyInitialization(ProxyInitializeEvent e) { 75 | reloadConfig(); 76 | CommandMeta meta = server.getCommandManager().metaBuilder("advancedplhidevelocity") 77 | // Specify other aliases (optional) 78 | .aliases("aphv", "apv", "plhidev", "phv") 79 | .build(); 80 | server.getCommandManager().register(meta, new AdvancedPlHideCommand(this)); 81 | server.getEventManager().register(this, new VelocityEventListener(this)); 82 | Protocolize.listenerProvider().registerListener(new VelocityPacketListener(this)); 83 | metricsFactory.make(this, 13708); 84 | server.getConsoleCommandSource().sendMessage(LegacyComponentSerializer.legacy('&').deserialize(Constants.startupMessage())); 85 | server.getScheduler().buildTask(this, this::performStartUpdateCheck).schedule(); 86 | } 87 | 88 | public Group getGroupForPlayer(Player player) { 89 | if (player.hasPermission("plhide.no-group")) return null; 90 | List groups = new ArrayList<>(); 91 | for (Group group : getGroups()) { 92 | if (player.hasPermission("plhide.group." + group.getName())) { 93 | groups.add(group); 94 | } 95 | } 96 | return groups.isEmpty() ? getGroup("default") : mergeGroups(groups); 97 | } 98 | 99 | public void loadGroups() { 100 | groups = new ArrayList<>(); 101 | getConfig().groups().forEach((name, val) -> { 102 | if (getGroup(name) == null) 103 | groups.add(new Group(name, val.tabcomplete())); 104 | else { 105 | getLogger().warn("Group " + name + " is repeated."); 106 | } 107 | }); 108 | if (getGroup("default") == null) { 109 | getLogger().warn("Group default was not found. If someone has no permission for any group, no group applies on them"); 110 | } 111 | 112 | } 113 | 114 | public Logger getLogger() { 115 | return logger; 116 | } 117 | 118 | public Group getGroup(String name) { 119 | for (Group group : groups) { 120 | if (group.getName().equals(name)) return group; 121 | } 122 | return null; 123 | } 124 | 125 | @Override 126 | public String getPluginForCommand(String s) { 127 | return null; 128 | } 129 | 130 | @Override 131 | public Type getType() { 132 | return Type.VELOCITY; 133 | } 134 | 135 | public List getGroups() { 136 | return groups; 137 | } 138 | 139 | public void performStartUpdateCheck() { 140 | try { 141 | UpdateCheckResult result = updateCheck(); 142 | String msg = result.getVersionsBehind() == 0 ? 143 | LegacyComponentSerializer.legacy('&').deserialize(Constants.DEFAULT_UP_TO_DATE).content() : 144 | LegacyComponentSerializer.legacy('&').deserialize(Constants.DEFAULT_BEHIND.replace("{versions}", result.getVersionsBehind() + "") 145 | .replace("{download}", result.getUpdateUrl())).content(); 146 | if (result.getMessage() != null) { 147 | msg = LegacyComponentSerializer.legacy('&').deserialize(result.getMessage()).content(); 148 | } 149 | 150 | switch (result.getLoggerType()) { 151 | case "INFO": 152 | logger.info(msg); 153 | break; 154 | case "WARNING": 155 | logger.warn(msg); 156 | break; 157 | case "ERROR": 158 | logger.error(msg); 159 | break; 160 | } 161 | } catch (Throwable ex) { 162 | logger.error(String.format("Could not check for updates: %s", ex.getMessage())); 163 | } 164 | } 165 | 166 | @Override 167 | public File getDataFolder() { 168 | return dataDirectory.toFile(); 169 | } 170 | 171 | 172 | } 173 | -------------------------------------------------------------------------------- /velocity/src/main/java/dev/bluetree242/advancedplhide/velocity/impl/completer/OfferCommandCompleter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * LICENSE 3 | * AdvancedPlHide 4 | * ------------- 5 | * Copyright (C) 2021 - 2024 BlueTree242 6 | * ------------- 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as 9 | * published by the Free Software Foundation, either version 3 of the 10 | * License, or (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public 18 | * License along with this program. If not, see 19 | * . 20 | * END 21 | */ 22 | 23 | package dev.bluetree242.advancedplhide.velocity.impl.completer; 24 | 25 | import com.velocitypowered.proxy.protocol.packet.TabCompleteResponsePacket; 26 | import dev.bluetree242.advancedplhide.CommandCompleter; 27 | 28 | public class OfferCommandCompleter implements CommandCompleter { 29 | private final OfferCompleterList list; 30 | private final String name; 31 | 32 | public OfferCommandCompleter(TabCompleteResponsePacket.Offer offer, OfferCompleterList list, boolean legacy) { 33 | this.list = list; 34 | this.name = legacy ? offer.getText().replaceFirst("/", "") : offer.getText(); 35 | 36 | } 37 | 38 | @Override 39 | public String getName() { 40 | return name; 41 | } 42 | 43 | @Override 44 | public void remove() { 45 | list.remove(this); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /velocity/src/main/java/dev/bluetree242/advancedplhide/velocity/impl/completer/OfferCompleterList.java: -------------------------------------------------------------------------------- 1 | /* 2 | * LICENSE 3 | * AdvancedPlHide 4 | * ------------- 5 | * Copyright (C) 2021 - 2024 BlueTree242 6 | * ------------- 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as 9 | * published by the Free Software Foundation, either version 3 of the 10 | * License, or (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public 18 | * License along with this program. If not, see 19 | * . 20 | * END 21 | */ 22 | 23 | package dev.bluetree242.advancedplhide.velocity.impl.completer; 24 | 25 | import com.velocitypowered.proxy.protocol.packet.TabCompleteResponsePacket; 26 | import dev.bluetree242.advancedplhide.CommandCompleter; 27 | import dev.bluetree242.advancedplhide.CommandCompleterList; 28 | 29 | import java.util.ArrayList; 30 | import java.util.List; 31 | 32 | public class OfferCompleterList extends CommandCompleterList { 33 | private final List offers; 34 | private final boolean legacy; 35 | 36 | public OfferCompleterList(List offers, boolean legacy) { 37 | this.offers = offers; 38 | this.legacy = legacy; 39 | for (TabCompleteResponsePacket.Offer offer : offers) { 40 | add(new OfferCommandCompleter(offer, this, legacy)); 41 | } 42 | } 43 | 44 | @Override 45 | public List export() { 46 | return offers; 47 | } 48 | 49 | @Override 50 | public boolean remove(Object e) { 51 | if (!(e instanceof CommandCompleter)) throw new IllegalArgumentException("May only remove CommandCompleter"); 52 | CommandCompleter completer = (CommandCompleter) e; 53 | for (TabCompleteResponsePacket.Offer offer : new ArrayList<>(offers)) { 54 | if (!legacy) { 55 | if (offer.getText().equalsIgnoreCase(completer.getName())) { 56 | super.remove(completer); 57 | return offers.remove(offer); 58 | } 59 | } else { 60 | if (offer.getText().equalsIgnoreCase("/" + completer.getName())) { 61 | super.remove(completer); 62 | return offers.remove(offer); 63 | } 64 | } 65 | } 66 | return false; 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /velocity/src/main/java/dev/bluetree242/advancedplhide/velocity/impl/subcompleter/OfferSubCommandCompleter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * LICENSE 3 | * AdvancedPlHide 4 | * ------------- 5 | * Copyright (C) 2021 - 2024 BlueTree242 6 | * ------------- 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as 9 | * published by the Free Software Foundation, either version 3 of the 10 | * License, or (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public 18 | * License along with this program. If not, see 19 | * . 20 | * END 21 | */ 22 | 23 | package dev.bluetree242.advancedplhide.velocity.impl.subcompleter; 24 | 25 | import dev.bluetree242.advancedplhide.SubCommandCompleter; 26 | 27 | public class OfferSubCommandCompleter implements SubCommandCompleter { 28 | private final OfferSubCommandCompleterList list; 29 | private final String text; 30 | 31 | public OfferSubCommandCompleter(OfferSubCommandCompleterList list, String text) { 32 | this.list = list; 33 | this.text = text; 34 | } 35 | 36 | @Override 37 | public String getText() { 38 | return text; 39 | } 40 | 41 | @Override 42 | public void remove() { 43 | list.remove(this); 44 | } 45 | 46 | 47 | } 48 | -------------------------------------------------------------------------------- /velocity/src/main/java/dev/bluetree242/advancedplhide/velocity/impl/subcompleter/OfferSubCommandCompleterList.java: -------------------------------------------------------------------------------- 1 | /* 2 | * LICENSE 3 | * AdvancedPlHide 4 | * ------------- 5 | * Copyright (C) 2021 - 2024 BlueTree242 6 | * ------------- 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as 9 | * published by the Free Software Foundation, either version 3 of the 10 | * License, or (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public 18 | * License along with this program. If not, see 19 | * . 20 | * END 21 | */ 22 | 23 | package dev.bluetree242.advancedplhide.velocity.impl.subcompleter; 24 | 25 | import com.velocitypowered.proxy.protocol.packet.TabCompleteResponsePacket; 26 | import dev.bluetree242.advancedplhide.SubCommandCompleter; 27 | import dev.bluetree242.advancedplhide.SubCommandCompleterList; 28 | 29 | import java.util.ArrayList; 30 | import java.util.List; 31 | 32 | public class OfferSubCommandCompleterList extends SubCommandCompleterList { 33 | private final List suggestions; 34 | private final String command; 35 | private final String[] args; 36 | 37 | public OfferSubCommandCompleterList(List suggestions, String notCompleted) { 38 | this.suggestions = suggestions; 39 | for (TabCompleteResponsePacket.Offer suggestion : suggestions) { 40 | add(new OfferSubCommandCompleter(this, suggestion.getText())); 41 | } 42 | String[] split = notCompleted.trim().split(" "); 43 | command = split[0].replaceFirst("/", ""); 44 | List list = new ArrayList<>(); 45 | for (String s : split) { 46 | if (!s.equalsIgnoreCase("/" + command)) { 47 | if (notCompleted.endsWith(" ")) 48 | list.add(s); 49 | else { 50 | if (!s.equals(split[split.length - 1])) { 51 | list.add(s); 52 | } 53 | } 54 | } 55 | } 56 | args = list.toArray(new String[0]); 57 | } 58 | 59 | @Override 60 | public List export() { 61 | return suggestions; 62 | } 63 | 64 | @Override 65 | public String[] getArgs() { 66 | return args; 67 | } 68 | 69 | @Override 70 | public String getName() { 71 | return command; 72 | } 73 | 74 | @Override 75 | public boolean remove(Object e) { 76 | if (!(e instanceof SubCommandCompleter)) 77 | throw new IllegalArgumentException("May only remove a SubCommandCompleter"); 78 | SubCommandCompleter completer = (SubCommandCompleter) e; 79 | for (TabCompleteResponsePacket.Offer suggestion : new ArrayList<>(suggestions)) { 80 | if (suggestion.getText().equalsIgnoreCase(completer.getText())) { 81 | super.remove(completer); 82 | return suggestions.remove(suggestion); 83 | } 84 | } 85 | return false; 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /velocity/src/main/java/dev/bluetree242/advancedplhide/velocity/listener/event/VelocityEventListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * LICENSE 3 | * AdvancedPlHide 4 | * ------------- 5 | * Copyright (C) 2021 - 2024 BlueTree242 6 | * ------------- 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as 9 | * published by the Free Software Foundation, either version 3 of the 10 | * License, or (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public 18 | * License along with this program. If not, see 19 | * . 20 | * END 21 | */ 22 | 23 | package dev.bluetree242.advancedplhide.velocity.listener.event; 24 | 25 | import com.velocitypowered.api.event.Subscribe; 26 | import com.velocitypowered.api.event.command.CommandExecuteEvent; 27 | import com.velocitypowered.api.event.command.PlayerAvailableCommandsEvent; 28 | import com.velocitypowered.api.event.connection.PostLoginEvent; 29 | import com.velocitypowered.api.proxy.ConsoleCommandSource; 30 | import dev.bluetree242.advancedplhide.CompleterModifier; 31 | import dev.bluetree242.advancedplhide.PlatformPlugin; 32 | import dev.bluetree242.advancedplhide.impl.completer.RootNodeCommandCompleter; 33 | import dev.bluetree242.advancedplhide.impl.version.UpdateCheckResult; 34 | import dev.bluetree242.advancedplhide.utils.Constants; 35 | import dev.bluetree242.advancedplhide.velocity.AdvancedPlHideVelocity; 36 | import net.kyori.adventure.text.Component; 37 | import net.kyori.adventure.text.event.ClickEvent; 38 | import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; 39 | 40 | public class VelocityEventListener { 41 | private final AdvancedPlHideVelocity core; 42 | 43 | public VelocityEventListener(AdvancedPlHideVelocity core) { 44 | this.core = core; 45 | } 46 | 47 | @Subscribe 48 | public void onPlayerJoin(PostLoginEvent e) { 49 | if (e.getPlayer().hasPermission("plhide.updatechecker")) { 50 | core.server.getScheduler().buildTask(core, () -> { 51 | try { 52 | UpdateCheckResult result = AdvancedPlHideVelocity.get().updateCheck(); 53 | Component msg = result.getVersionsBehind() == 0 ? null : LegacyComponentSerializer.legacy('&').deserialize("&e[APH&r-&2Velocity&e] " + Constants.DEFAULT_BEHIND.replace("{versions}", result.getVersionsBehind() + "").replace("{download}", result.getUpdateUrl())); 54 | if (result.getMessage() != null) { 55 | msg = LegacyComponentSerializer.legacy('&').deserialize("&e[APH&r-&2Velocity&e] &c" + result.getMessage()); 56 | } 57 | if (msg != null) { 58 | msg = msg.clickEvent(ClickEvent.clickEvent(ClickEvent.Action.OPEN_URL, result.getUpdateUrl())); 59 | e.getPlayer().sendMessage(msg); 60 | } 61 | } catch (Throwable ex) { 62 | core.getLogger().error(String.format("Could not check for updates: %s", ex.getMessage())); 63 | } 64 | }).schedule(); 65 | } 66 | } 67 | 68 | @Subscribe 69 | public void onCommandExecute(CommandExecuteEvent e) { 70 | if (e.getCommandSource() instanceof ConsoleCommandSource) return; 71 | String cmd = "/" + e.getCommand().split(" ")[0]; 72 | if (cmd.equalsIgnoreCase("/plugins") || cmd.equalsIgnoreCase("/pl") || cmd.equalsIgnoreCase("/bukkit:pl") || cmd.equalsIgnoreCase("/bukkit:plugins")) { 73 | if (!e.getCommandSource().hasPermission("plhide.command.use")) { 74 | if (!PlatformPlugin.get().getConfig().pl_message().isEmpty()) { 75 | Component response = LegacyComponentSerializer.legacy('&').deserialize(PlatformPlugin.get().getConfig().pl_message()); 76 | e.getCommandSource().sendMessage(response); 77 | } 78 | e.setResult(CommandExecuteEvent.CommandResult.denied()); 79 | } 80 | } 81 | } 82 | 83 | @Subscribe 84 | public void onCommands(PlayerAvailableCommandsEvent e) { 85 | RootNodeCommandCompleter node = new RootNodeCommandCompleter(e.getRootNode()); 86 | CompleterModifier.handleCompleter(node, core.getGroupForPlayer(e.getPlayer()), e.getPlayer().hasPermission(Constants.WHITELIST_MODE_PERMISSION)); 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /velocity/src/main/java/dev/bluetree242/advancedplhide/velocity/listener/packet/VelocityPacketListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * LICENSE 3 | * AdvancedPlHide 4 | * ------------- 5 | * Copyright (C) 2021 - 2024 BlueTree242 6 | * ------------- 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as 9 | * published by the Free Software Foundation, either version 3 of the 10 | * License, or (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public 18 | * License along with this program. If not, see 19 | * . 20 | * END 21 | */ 22 | 23 | package dev.bluetree242.advancedplhide.velocity.listener.packet; 24 | 25 | import com.velocitypowered.api.proxy.Player; 26 | import com.velocitypowered.proxy.protocol.packet.TabCompleteRequestPacket; 27 | import com.velocitypowered.proxy.protocol.packet.TabCompleteResponsePacket; 28 | import dev.bluetree242.advancedplhide.CompleterModifier; 29 | import dev.bluetree242.advancedplhide.utils.Constants; 30 | import dev.bluetree242.advancedplhide.utils.UsedMap; 31 | import dev.bluetree242.advancedplhide.velocity.AdvancedPlHideVelocity; 32 | import dev.bluetree242.advancedplhide.velocity.impl.completer.OfferCompleterList; 33 | import dev.bluetree242.advancedplhide.velocity.impl.subcompleter.OfferSubCommandCompleterList; 34 | import dev.simplix.protocolize.api.Direction; 35 | import dev.simplix.protocolize.api.Protocolize; 36 | import dev.simplix.protocolize.api.listener.AbstractPacketListener; 37 | import dev.simplix.protocolize.api.listener.PacketReceiveEvent; 38 | import dev.simplix.protocolize.api.listener.PacketSendEvent; 39 | 40 | import java.util.UUID; 41 | 42 | public class VelocityPacketListener extends AbstractPacketListener { 43 | private final UsedMap commandsWaiting = new UsedMap<>(); 44 | private final AdvancedPlHideVelocity core; 45 | 46 | public VelocityPacketListener(AdvancedPlHideVelocity core) { 47 | super(TabCompleteResponsePacket.class, Direction.UPSTREAM, 0); 48 | this.core = core; 49 | Protocolize.listenerProvider().registerListener(new VelocityPacketListener.RequestListener()); 50 | } 51 | 52 | 53 | @Override 54 | public void packetReceive(PacketReceiveEvent e) { 55 | //it is impossible to get this packet 56 | } 57 | 58 | @Override 59 | public void packetSend(PacketSendEvent e) { 60 | boolean legacy = e.player().protocolVersion() <= 340; 61 | Player player = core.server.getPlayer(e.player().uniqueId()).orElse(null); 62 | if (player == null || !player.isActive()) { 63 | e.cancelled(true); 64 | return; 65 | } 66 | String notCompleted = commandsWaiting.get(e.player().uniqueId()); 67 | if (notCompleted == null) notCompleted = "/"; 68 | if (!notCompleted.trim().startsWith("/")) notCompleted = "/" + notCompleted; 69 | if (legacy) { 70 | if (!notCompleted.contains(" ")) { 71 | OfferCompleterList list = new OfferCompleterList(e.packet().getOffers(), true); 72 | CompleterModifier.handleCompleter(list, core.getGroupForPlayer(player), player.hasPermission(Constants.WHITELIST_MODE_PERMISSION)); 73 | } else { 74 | OfferSubCommandCompleterList list = new OfferSubCommandCompleterList(e.packet().getOffers(), notCompleted); 75 | CompleterModifier.handleSubCompleter(list, core.getGroupForPlayer(player), player.hasPermission(Constants.WHITELIST_MODE_PERMISSION)); 76 | if (list.isCancelled()) e.cancelled(true); 77 | } 78 | } else { 79 | if ((!notCompleted.contains(" "))) { 80 | OfferCompleterList list = new OfferCompleterList(e.packet().getOffers(), false); 81 | CompleterModifier.handleCompleter(list, core.getGroupForPlayer(player), player.hasPermission(Constants.WHITELIST_MODE_PERMISSION)); 82 | } else { 83 | OfferSubCommandCompleterList list = new OfferSubCommandCompleterList(e.packet().getOffers(), notCompleted); 84 | CompleterModifier.handleSubCompleter(list, core.getGroupForPlayer(player), player.hasPermission(Constants.WHITELIST_MODE_PERMISSION)); 85 | if (list.isCancelled()) e.cancelled(true); 86 | } 87 | } 88 | } 89 | 90 | public class RequestListener extends AbstractPacketListener { 91 | 92 | protected RequestListener() { 93 | super(TabCompleteRequestPacket.class, Direction.UPSTREAM, Integer.MAX_VALUE); 94 | } 95 | 96 | @Override 97 | public void packetReceive(PacketReceiveEvent e) { 98 | if (!e.cancelled()) 99 | commandsWaiting.put(e.player().uniqueId(), e.packet().getCommand()); 100 | } 101 | 102 | @Override 103 | public void packetSend(PacketSendEvent e) { 104 | 105 | } 106 | } 107 | } 108 | --------------------------------------------------------------------------------