138 lines
6.5 KiB
Java
138 lines
6.5 KiB
Java
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;
|
|
|
|
public class VanishCommand implements CommandExecutor {
|
|
|
|
SimpleVanish plugin;
|
|
|
|
public VanishCommand(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(ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("whenconsole")));
|
|
return true;
|
|
}
|
|
|
|
Player player = (Player) sender;
|
|
|
|
if(!player.hasPermission("sloudpl.vanish")){
|
|
player.sendMessage(ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("noperms")));
|
|
return true;
|
|
}
|
|
|
|
if(plugin.inVanishList.contains(player)){
|
|
for(Player other : Bukkit.getOnlinePlayers()){
|
|
other.showPlayer(player);
|
|
other.sendMessage(ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("unvanishmsg").replace("[Player]", player.getName())));
|
|
}
|
|
plugin.inVanishList.remove(player);
|
|
player.removePotionEffect(PotionEffectType.NIGHT_VISION);
|
|
player.sendMessage(ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("unvanish")));
|
|
|
|
} else {
|
|
for(Player other : Bukkit.getOnlinePlayers()){
|
|
if(!other.hasPermission("sloudpl.vanish.see")){
|
|
other.hidePlayer(player);
|
|
other.sendMessage(ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("vanishmsg").replace("[Player]", player.getName())));
|
|
}
|
|
}
|
|
plugin.inVanishList.add(player);
|
|
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)) {
|
|
cancel();
|
|
return;
|
|
}
|
|
|
|
String actionmsg = ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("actionbarmsg"));
|
|
player.spigot().sendMessage(ChatMessageType.ACTION_BAR, new TextComponent(actionmsg));
|
|
}
|
|
}.runTaskTimer(plugin, 0L, 40L);
|
|
}
|
|
|
|
player.sendMessage(ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("vanish")));
|
|
}
|
|
|
|
} else if(args.length == 1){
|
|
|
|
if(!sender.hasPermission("sloudpl.vanish.others")){
|
|
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("noperms")));
|
|
return true;
|
|
}
|
|
|
|
Player target = Bukkit.getPlayerExact(args[0]);
|
|
if(target == null){
|
|
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("playerdoesntexist")));
|
|
return true;
|
|
}
|
|
|
|
if(plugin.inVanishList.contains(target)){
|
|
for(Player other : Bukkit.getOnlinePlayers()){
|
|
other.showPlayer(target);
|
|
other.sendMessage(ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("unvanishmsg").replace("[Player]", target.getName())));
|
|
}
|
|
plugin.inVanishList.remove(target);
|
|
target.removePotionEffect(PotionEffectType.NIGHT_VISION);
|
|
target.sendMessage(ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("unvanish")));
|
|
|
|
String otherUnVanishMessage = plugin.getConfig().getString("other.unvanish");
|
|
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', otherUnVanishMessage.replace("[Target]", target.getName())));
|
|
} else {
|
|
for(Player other : Bukkit.getOnlinePlayers()){
|
|
if(!other.hasPermission("sloudpl.vanish.see")){
|
|
other.hidePlayer(target);
|
|
other.sendMessage(ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("vanishmsg").replace("[Player]", target.getName())));
|
|
}
|
|
}
|
|
plugin.inVanishList.add(target);
|
|
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)) {
|
|
cancel();
|
|
return;
|
|
}
|
|
|
|
String actionmsg = ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("actionbarmsg"));
|
|
target.spigot().sendMessage(ChatMessageType.ACTION_BAR, new TextComponent(actionmsg));
|
|
}
|
|
}.runTaskTimer(plugin, 0L, 40L);
|
|
}
|
|
target.sendMessage(ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("vanish")));
|
|
|
|
String otherVanishMessage = plugin.getConfig().getString("other.vanish");
|
|
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', otherVanishMessage.replace("[Target]", target.getName())));
|
|
}
|
|
|
|
} else {
|
|
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("usage")));
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
}
|