diff --git a/README.md b/README.md
index 4e57fcd..16f8159 100644
--- a/README.md
+++ b/README.md
@@ -8,4 +8,6 @@ Permissions:
/vanish player - sloudpl.vanish.others
+/sloudvanish reload - sloudpl.reload
+
To see vanished players - sloudpl.vanish.see
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 251ee17..84efea6 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
pl.sloudpl
SloudVanish
- 1.2.2
+ 1.3
jar
SloudVanish
@@ -64,7 +64,7 @@
org.spigotmc
spigot-api
- 1.12-R0.1-SNAPSHOT
+ 1.16.5-R0.1-SNAPSHOT
provided
diff --git a/src/main/java/pl/sloudpl/simplevanish/SimpleVanish.java b/src/main/java/pl/sloudpl/simplevanish/SimpleVanish.java
index a541d5f..c148861 100644
--- a/src/main/java/pl/sloudpl/simplevanish/SimpleVanish.java
+++ b/src/main/java/pl/sloudpl/simplevanish/SimpleVanish.java
@@ -1,8 +1,12 @@
package pl.sloudpl.simplevanish;
+import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;
import pl.sloudpl.simplevanish.bstats.Metrics;
+import pl.sloudpl.simplevanish.cmds.SloudVanishCMD;
+import pl.sloudpl.simplevanish.cmds.SloudVanishCMD1_16;
import pl.sloudpl.simplevanish.cmds.VanishCommand;
+import pl.sloudpl.simplevanish.cmds.VanishCommand1_16;
import pl.sloudpl.simplevanish.events.onJoinEvent;
import pl.sloudpl.simplevanish.events.onLeaveEvent;
import pl.sloudpl.simplevanish.events.onPlayerDamage;
@@ -24,14 +28,21 @@ public final class SimpleVanish extends JavaPlugin {
saveDefaultConfig();
- new VanishCommand(this);
+ if (isVersionAtMost_1_16_0()) {
+
+ new VanishCommand(this);
+ new SloudVanishCMD(this);
+
+ } else {
+
+ new VanishCommand1_16(this);
+ new SloudVanishCMD1_16(this);
+
+ }
new onJoinEvent(this);
new onLeaveEvent(this);
-
- if(getConfig().getBoolean("vanish-damage")){
- new onPlayerDamage(this);
- }
+ new onPlayerDamage(this);
new UpdateChecker(this, 108713).getLatestVersion(version -> {
String current = this.getDescription().getVersion();
@@ -52,4 +63,32 @@ public final class SimpleVanish extends JavaPlugin {
}
+
+ public boolean isVersionAtMost_1_16_0() {
+ String version = Bukkit.getBukkitVersion();
+ String[] mainParts = version.split("-")[0].split("\\.");
+
+ try {
+ int major = Integer.parseInt(mainParts[0]);
+ int minor = Integer.parseInt(mainParts[1]);
+ int patch = mainParts.length > 2 ? Integer.parseInt(mainParts[2]) : 0;
+
+ if (major < 1) {
+ return true;
+ } else if (major == 1) {
+ if (minor < 16) {
+ return true;
+ } else if (minor == 16) {
+ return patch == 0;
+ } else {
+ return false;
+ }
+ } else {
+ return false;
+ }
+ } catch (Exception e) {
+ return false;
+ }
+ }
+
}
diff --git a/src/main/java/pl/sloudpl/simplevanish/cmds/SloudVanishCMD.java b/src/main/java/pl/sloudpl/simplevanish/cmds/SloudVanishCMD.java
new file mode 100644
index 0000000..58c2c19
--- /dev/null
+++ b/src/main/java/pl/sloudpl/simplevanish/cmds/SloudVanishCMD.java
@@ -0,0 +1,48 @@
+package pl.sloudpl.simplevanish.cmds;
+
+import net.md_5.bungee.api.ChatColor;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandExecutor;
+import org.bukkit.command.CommandSender;
+import pl.sloudpl.simplevanish.SimpleVanish;
+
+public class SloudVanishCMD implements CommandExecutor {
+
+ SimpleVanish plugin;
+
+ public SloudVanishCMD(SimpleVanish plugin){
+ this.plugin = plugin;
+ plugin.getCommand("sloudvanish").setExecutor(this);
+ }
+
+ @Override
+ public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
+
+ if(args.length == 1){
+
+ if(args[0].equalsIgnoreCase("reload")){
+ if(sender.hasPermission("sloudpl.reload")){
+
+ plugin.reloadConfig();
+ sender.sendMessage(ChatColor.GREEN + "Config was reloaded!");
+
+ } else {
+ sender.sendMessage(ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("noperms")));
+ }
+
+ } else {
+
+ sender.sendMessage(ChatColor.RED + "Usage: /sloudvanish reload");
+
+ }
+
+ } else {
+
+ sender.sendMessage(ChatColor.RED + "Usage: /sloudvanish reload");
+
+ }
+
+ return false;
+ }
+
+}
diff --git a/src/main/java/pl/sloudpl/simplevanish/cmds/SloudVanishCMD1_16.java b/src/main/java/pl/sloudpl/simplevanish/cmds/SloudVanishCMD1_16.java
new file mode 100644
index 0000000..c88aa9b
--- /dev/null
+++ b/src/main/java/pl/sloudpl/simplevanish/cmds/SloudVanishCMD1_16.java
@@ -0,0 +1,49 @@
+package pl.sloudpl.simplevanish.cmds;
+
+import net.md_5.bungee.api.ChatColor;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandExecutor;
+import org.bukkit.command.CommandSender;
+import pl.sloudpl.simplevanish.SimpleVanish;
+import pl.sloudpl.simplevanish.utils.ColorUtils;
+
+public class SloudVanishCMD1_16 implements CommandExecutor {
+
+ SimpleVanish plugin;
+
+ public SloudVanishCMD1_16(SimpleVanish plugin){
+ this.plugin = plugin;
+ plugin.getCommand("sloudvanish").setExecutor(this);
+ }
+
+ @Override
+ public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
+
+ if(args.length == 1){
+
+ if(args[0].equalsIgnoreCase("reload")){
+ if(sender.hasPermission("sloudpl.reload")){
+
+ plugin.reloadConfig();
+ sender.sendMessage(ChatColor.GREEN + "Config was reloaded!");
+
+ } else {
+ sender.sendMessage(ColorUtils.convertHexColors(ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("noperms"))));
+ }
+
+ } else {
+
+ sender.sendMessage(ChatColor.RED + "Usage: /sloudvanish reload");
+
+ }
+
+ } else {
+
+ sender.sendMessage(ChatColor.RED + "Usage: /sloudvanish reload");
+
+ }
+
+ return false;
+ }
+
+}
diff --git a/src/main/java/pl/sloudpl/simplevanish/cmds/VanishCommand1_16.java b/src/main/java/pl/sloudpl/simplevanish/cmds/VanishCommand1_16.java
new file mode 100644
index 0000000..98ee3a8
--- /dev/null
+++ b/src/main/java/pl/sloudpl/simplevanish/cmds/VanishCommand1_16.java
@@ -0,0 +1,147 @@
+package pl.sloudpl.simplevanish.cmds;
+
+import net.md_5.bungee.api.ChatColor;
+import net.md_5.bungee.api.ChatMessageType;
+import net.md_5.bungee.api.chat.TextComponent;
+import org.bukkit.Bukkit;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandExecutor;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+import org.bukkit.potion.PotionEffect;
+import org.bukkit.potion.PotionEffectType;
+import org.bukkit.scheduler.BukkitRunnable;
+import pl.sloudpl.simplevanish.SimpleVanish;
+import pl.sloudpl.simplevanish.utils.ColorUtils;
+
+public class VanishCommand1_16 implements CommandExecutor {
+
+ SimpleVanish plugin;
+
+ public VanishCommand1_16(SimpleVanish plugin){
+ this.plugin = plugin;
+ plugin.getCommand("vanish").setExecutor(this);
+ }
+
+ @Override
+ public boolean onCommand(CommandSender sender, Command command, String label, String[] args){
+
+ if(args.length == 0){
+
+ if(!(sender instanceof Player)){
+ sender.sendMessage(ColorUtils.convertHexColors(ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("whenconsole"))));
+ return true;
+ }
+
+ Player player = (Player) sender;
+
+ if(!player.hasPermission("sloudpl.vanish")){
+ player.sendMessage(ColorUtils.convertHexColors(ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("noperms"))));
+ return true;
+ }
+
+ if(plugin.inVanishList.contains(player.getUniqueId())){
+ for(Player other : Bukkit.getOnlinePlayers()){
+ other.showPlayer(player);
+ if(plugin.getConfig().getBoolean("vanish-message-enabled")){
+ other.sendMessage(ColorUtils.convertHexColors(ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("unvanishmsg").replace("[Player]", player.getName()))));
+ }
+ }
+ plugin.inVanishList.remove(player.getUniqueId());
+ player.removePotionEffect(PotionEffectType.NIGHT_VISION);
+ player.sendMessage(ColorUtils.convertHexColors(ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("unvanish"))));
+
+ } else {
+ for(Player other : Bukkit.getOnlinePlayers()){
+ if(!other.hasPermission("sloudpl.vanish.see")){
+ other.hidePlayer(player);
+ if(plugin.getConfig().getBoolean("vanish-message-enabled")){
+ other.sendMessage(ColorUtils.convertHexColors(ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("vanishmsg").replace("[Player]", player.getName()))));
+ }
+ }
+ }
+ plugin.inVanishList.add(player.getUniqueId());
+ player.addPotionEffect(new PotionEffect(PotionEffectType.NIGHT_VISION, Integer.MAX_VALUE, 0, false, false));
+ if(plugin.getConfig().getBoolean("actionbar")) {
+ new BukkitRunnable() {
+ @Override
+ public void run() {
+ if (!plugin.inVanishList.contains(player.getUniqueId())) {
+ cancel();
+ return;
+ }
+
+ String actionmsg = ColorUtils.convertHexColors(ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("actionbarmsg")));
+ player.spigot().sendMessage(ChatMessageType.ACTION_BAR, new TextComponent(actionmsg));
+ }
+ }.runTaskTimer(plugin, 0L, 40L);
+ }
+
+ player.sendMessage(ColorUtils.convertHexColors(ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("vanish"))));
+ }
+
+ } else if(args.length == 1){
+
+ if(!sender.hasPermission("sloudpl.vanish.others")){
+ sender.sendMessage(ColorUtils.convertHexColors(ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("noperms"))));
+ return true;
+ }
+
+ Player target = Bukkit.getPlayerExact(args[0]);
+ if(target == null){
+ sender.sendMessage(ColorUtils.convertHexColors(ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("playerdoesntexist"))));
+ return true;
+ }
+
+ if(plugin.inVanishList.contains(target.getUniqueId())){
+ for(Player other : Bukkit.getOnlinePlayers()){
+ other.showPlayer(target);
+ if(plugin.getConfig().getBoolean("vanish-message-enabled")){
+ other.sendMessage(ColorUtils.convertHexColors(ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("unvanishmsg").replace("[Player]", target.getName()))));
+ }
+ }
+ plugin.inVanishList.remove(target.getUniqueId());
+ target.removePotionEffect(PotionEffectType.NIGHT_VISION);
+ target.sendMessage(ColorUtils.convertHexColors(ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("unvanish"))));
+
+ String otherUnVanishMessage = plugin.getConfig().getString("other.unvanish");
+ sender.sendMessage(ColorUtils.convertHexColors(ChatColor.translateAlternateColorCodes('&', otherUnVanishMessage.replace("[Target]", target.getName()))));
+ } else {
+ for(Player other : Bukkit.getOnlinePlayers()){
+ if(!other.hasPermission("sloudpl.vanish.see")){
+ other.hidePlayer(target);
+ if(plugin.getConfig().getBoolean("vanish-message-enabled")){
+ other.sendMessage(ColorUtils.convertHexColors(ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("vanishmsg").replace("[Player]", target.getName()))));
+ }
+ }
+ }
+ plugin.inVanishList.add(target.getUniqueId());
+ target.addPotionEffect(new PotionEffect(PotionEffectType.NIGHT_VISION, Integer.MAX_VALUE, 0, false, false));
+ if(plugin.getConfig().getBoolean("actionbar")) {
+ new BukkitRunnable() {
+ @Override
+ public void run() {
+ if (!plugin.inVanishList.contains(target.getUniqueId())) {
+ cancel();
+ return;
+ }
+
+ String actionmsg = ColorUtils.convertHexColors(ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("actionbarmsg")));
+ target.spigot().sendMessage(ChatMessageType.ACTION_BAR, new TextComponent(actionmsg));
+ }
+ }.runTaskTimer(plugin, 0L, 40L);
+ }
+ target.sendMessage(ColorUtils.convertHexColors(ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("vanish"))));
+
+ String otherVanishMessage = plugin.getConfig().getString("other.vanish");
+ sender.sendMessage(ColorUtils.convertHexColors(ChatColor.translateAlternateColorCodes('&', otherVanishMessage.replace("[Target]", target.getName()))));
+ }
+
+ } else {
+ sender.sendMessage(ColorUtils.convertHexColors(ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("usage"))));
+ }
+
+ return true;
+ }
+
+}
diff --git a/src/main/java/pl/sloudpl/simplevanish/events/onPlayerDamage.java b/src/main/java/pl/sloudpl/simplevanish/events/onPlayerDamage.java
index 9600539..8029cb4 100644
--- a/src/main/java/pl/sloudpl/simplevanish/events/onPlayerDamage.java
+++ b/src/main/java/pl/sloudpl/simplevanish/events/onPlayerDamage.java
@@ -18,13 +18,17 @@ public class onPlayerDamage implements Listener {
@EventHandler
public void PlayerDamage(EntityDamageByEntityEvent e){
- if(e.getDamager() instanceof Player){
+ if(plugin.getConfig().getBoolean("vanish-damage")){
- Player damager = (Player) e.getDamager();
+ if(e.getDamager() instanceof Player){
- if(plugin.inVanishList.contains(damager.getUniqueId())){
+ Player damager = (Player) e.getDamager();
- e.setCancelled(true);
+ if(plugin.inVanishList.contains(damager.getUniqueId())){
+
+ e.setCancelled(true);
+
+ }
}
diff --git a/src/main/java/pl/sloudpl/simplevanish/utils/ColorUtils.java b/src/main/java/pl/sloudpl/simplevanish/utils/ColorUtils.java
new file mode 100644
index 0000000..4091d56
--- /dev/null
+++ b/src/main/java/pl/sloudpl/simplevanish/utils/ColorUtils.java
@@ -0,0 +1,28 @@
+package pl.sloudpl.simplevanish.utils;
+
+import net.md_5.bungee.api.ChatColor;
+
+import java.awt.*;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+public class ColorUtils {
+
+ public static String convertHexColors(String text) {
+ Pattern pattern = Pattern.compile("([0-9A-Fa-f]{6})");
+ Matcher matcher = pattern.matcher(text);
+ StringBuffer sb = new StringBuffer();
+ while (matcher.find()) {
+ String hex = matcher.group(1);
+ Color color = new Color(
+ Integer.valueOf(hex.substring(0, 2), 16),
+ Integer.valueOf(hex.substring(2, 4), 16),
+ Integer.valueOf(hex.substring(4, 6), 16)
+ );
+ matcher.appendReplacement(sb, ChatColor.of(color).toString());
+ }
+ matcher.appendTail(sb);
+ return sb.toString();
+ }
+
+}
diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml
index 2c02018..1a65b84 100644
--- a/src/main/resources/plugin.yml
+++ b/src/main/resources/plugin.yml
@@ -2,8 +2,9 @@ name: SloudVanish
version: '${project.version}'
main: pl.sloudpl.simplevanish.SimpleVanish
author: SloudPL
-api-version: 1.13
+api-version: 1.16
commands:
vanish:
description: Vanish
- aliases: [v]
\ No newline at end of file
+ aliases: [v]
+ sloudvanish:
\ No newline at end of file