diff --git a/legacy/src/config.yml b/legacy/src/config.yml new file mode 100644 index 0000000..784f883 --- /dev/null +++ b/legacy/src/config.yml @@ -0,0 +1,48 @@ +# If you want to use special characters in this document, such as accented letters, you MUST save the file as UTF-8, not ANSI +# If it is saved as an ANSI file it will return an illegal character error +# If you receive an error while Player Visibility loads, ensure that: +# - No tabs are present: YAML only allows spaces +# - Indents are correct: YAML hierarchy is based entirely on indentation +# - Text with symbols is enclosed in single or double quotation marks + +# When using the dye option please use one of the following options: +# WHITE, ORANGE, MAGENTA, LIGHT_BLUE, YELLOW, LIME, PINK, +# GRAY, SILVER, CYAN, PURPLE, BLUE, BROWN, GREEN, RED, BLACK + +Enabled-Worlds: + - "world" + - "world 1" + - "world 2" + +enableDye: false + +item: + slot: 8 + on: + item: "SLIME_BALL" + dye: "LIME" + name: "&7Players are &aon!" + lore: "&7Toggle player visibility to &coff" + off: + item: "MAGMA_CREAM" + dye: "GRAY" + name: "&7Players are &coff!" + lore: "&7Toggle player visibility to &aon" + +messages: + actionbar: true + prefix: "&9Visibility > " + toggle: + on: "&7All players are turned &aon!" + off: "&7All players are turned &coff!" + already: + on: "&7All players are already &aon!" + off: "&7All players are already &coff!" + permission: "&cYou don't have the permissions to do that." + cooldown: "&7Please wait 10 seconds before toggling again." + world: "&cYou can't hide/unhide players in this world." + switch: "&cYou can't change this item its place." + +cooldown: 10 + +config: "2.2" diff --git a/legacy/src/nl/tomudding/plugins/visibility/Visibility.java b/legacy/src/nl/tomudding/plugins/visibility/Visibility.java new file mode 100644 index 0000000..bf9a5e0 --- /dev/null +++ b/legacy/src/nl/tomudding/plugins/visibility/Visibility.java @@ -0,0 +1,145 @@ +package nl.tomudding.plugins.visibility; + +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; +import java.util.logging.Logger; + +import org.apache.commons.lang.StringUtils; +import org.bukkit.Bukkit; +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.java.JavaPlugin; + +import nl.tomudding.plugins.visibility.commands.Commands; +import nl.tomudding.plugins.visibility.listeners.PlayerListener; +import nl.tomudding.plugins.visibility.managers.ChatManager; +import nl.tomudding.plugins.visibility.managers.PlayerManager; + +public class Visibility extends JavaPlugin { + + public final Logger logger = Logger.getLogger("Minecraft"); + protected Logger log; + public PlayerManager settings = PlayerManager.getInstance(); + + /** + * Boolean variables + */ + public static boolean isDyeEnabled = false; + public static boolean actionBar = true; + + /** + * Int variables + */ + public static int timeCooldown = 10; + public static int itemSlot = 8; + + /** + * String variables + */ + public static String itemIdOn = "SLIME_BALL"; + public static String itemIdOff = "MAGMA_CREAM"; + public static String dyeColorOn = "LIME"; + public static String dyeColorOff = "GRAY"; + public static String itemNameOn = "&7Players are &aon!"; + public static String itemNameOff = "&7Players are &coff!"; + public static String itemLoreOn = "&7Toggle player visibility to &coff"; + public static String itemLoreOff = "&7Toggle player visibility to &aon"; + + public static String messagePrefix = "&9Visibility > "; + public static String messageCooldown = "&7Please wait 10 seconds before toggling again."; + public static String messagePermission = "&cYou don't have the permissions to do that."; + public static String messageToggleOn = "&7All players are turned &aon!"; + public static String messageToggleOff = "&7All players are turned &coff!"; + public static String messageWorld = "&cYou can't hide/unhide players in this world."; + public static String messageAlreadyOn = "&7All players are already &aon!"; + public static String messageAlreadyOff = "&7All players are already &coff!"; + public static String messageNoSwitch = "&cYou can't change this item its place."; + public static String configVersion = "0.0"; + + /** + * List variables + */ + public static List enabledWorlds; + public static ArrayList inCooldown = new ArrayList(); + + public void onEnable() { + ChatManager.getInstance().log("Starting Player Visibility for Bukkit"); + + if (!(getServerVersion().startsWith("v1_8_"))) { + ChatManager.getInstance().log("&c=========================================="); + ChatManager.getInstance().log("&cWARNING: Your server software is not 1.8!"); + ChatManager.getInstance().log("&cWARNING: This plugin requires"); + ChatManager.getInstance().log("&cWARNING: Minecraft version 1.8.*."); + ChatManager.getInstance().log("&c=========================================="); + ChatManager.getInstance().log("Disabling Player Visibility for Bukkit"); + Plugin plugin = Bukkit.getPluginManager().getPlugin("Visibility"); + plugin.getPluginLoader().disablePlugin(plugin); + return; + } + + saveDefaultConfig(); + + this.settings.setup(this); + this.settings.saveData(); + + loadConfig(); + + if (!StringUtils.substring(getDescription().getVersion(), 0, 3).equals(configVersion)) { + ChatManager.getInstance().log("&cWARNING: Config.yml version: "+Visibility.configVersion+". Plugin version: "+getDescription().getVersion()+"!"); + ChatManager.getInstance().log("&cWARNING: Config.yml is not the correct version, delete 'config.yml' and restart the server!"); + } else { + ChatManager.getInstance().log("&aConfig.yml version matches required version."); + } + + getServer().getPluginManager().registerEvents(new PlayerListener(this), this); + getCommand("visibility").setExecutor(new Commands(this)); + getCommand("hide").setExecutor(new Commands(this)); + getCommand("show").setExecutor(new Commands(this)); + + ChatManager.getInstance().log("Player Visibility for Bukkit is now enabled"); + } + + public void onDisable() { + ChatManager.getInstance().log("Disabling Player Visibility for Bukkit"); + ChatManager.getInstance().log("Player Visibility for Bukkit is now disabled"); + } + + public static String getServerVersion() { + return Bukkit.getServer().getClass().getPackage().getName().substring(23); + } + + public static Class getNMSClass(String nmsClassName) throws ClassNotFoundException { + return Class.forName("net.minecraft.server." + Bukkit.getServer().getClass().getPackage().getName().replace(".", ",").split(",")[3] + "." + nmsClassName); + } + + public void loadConfig() { + Visibility.isDyeEnabled = getConfig().getBoolean("enableDye"); + Visibility.actionBar = getConfig().getBoolean("messages.actionbar"); + + Visibility.dyeColorOn = getConfig().getString("item.true.dye"); + Visibility.dyeColorOff = getConfig().getString("item.false.dye"); + Visibility.itemIdOn = getConfig().getString("item.true.item"); + Visibility.itemIdOff = getConfig().getString("item.false.item"); + + Visibility.timeCooldown = getConfig().getInt("cooldown"); + Visibility.itemSlot = getConfig().getInt("item.slot"); + + Visibility.itemNameOn = getConfig().getString("item.true.name"); + Visibility.itemNameOff = getConfig().getString("item.false.name"); + Visibility.itemLoreOn = getConfig().getString("item.true.lore"); + Visibility.itemLoreOff = getConfig().getString("item.false.lore"); + + Visibility.messagePrefix = getConfig().getString("messages.prefix"); + Visibility.messageCooldown = getConfig().getString("messages.cooldown"); + Visibility.messagePermission = getConfig().getString("messages.permission"); + Visibility.messageToggleOn = getConfig().getString("messages.toggle.true"); + Visibility.messageToggleOff = getConfig().getString("messages.toggle.false"); + Visibility.messageWorld = getConfig().getString("messages.world"); + Visibility.messageAlreadyOn = getConfig().getString("messages.toggle.already.true"); + Visibility.messageAlreadyOff = getConfig().getString("messages.toggle.already.false"); + + Visibility.enabledWorlds = getConfig().getStringList("Enabled-Worlds"); + + Visibility.configVersion = getConfig().getString("config"); + } +} diff --git a/legacy/src/nl/tomudding/plugins/visibility/commands/Commands.java b/legacy/src/nl/tomudding/plugins/visibility/commands/Commands.java new file mode 100644 index 0000000..91063e6 --- /dev/null +++ b/legacy/src/nl/tomudding/plugins/visibility/commands/Commands.java @@ -0,0 +1,125 @@ +package nl.tomudding.plugins.visibility.commands; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.scheduler.BukkitScheduler; + +import nl.tomudding.plugins.visibility.Visibility; +import nl.tomudding.plugins.visibility.listeners.PlayerListener; +import nl.tomudding.plugins.visibility.managers.ChatManager; +import nl.tomudding.plugins.visibility.managers.PlayerManager; + +public class Commands implements CommandExecutor { + + private Visibility plugin; + + public Commands(Visibility plugin) { + this.plugin = plugin; + } + + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender instanceof Player) { + Player player = (Player) sender; + + if (cmd.getName().equalsIgnoreCase("visibility")) { + if (args.length == 0) { + ChatManager.getInstance().sendCommandMessage(player, ChatColor.YELLOW + "---------- " + ChatColor.GRAY + "Player Visibility" + ChatColor.YELLOW + " ----------"); + ChatManager.getInstance().sendCommandMessage(player, ChatColor.GOLD + "/"+cmd.getName().toLowerCase().toString()+"" + ChatColor.DARK_AQUA + " - This help menu"); + ChatManager.getInstance().sendCommandMessage(player, ChatColor.GOLD + "/"+cmd.getName().toLowerCase().toString()+" info" + ChatColor.DARK_AQUA + " - Information about the plugin"); + ChatManager.getInstance().sendCommandMessage(player, ChatColor.GOLD + "/hide" + ChatColor.DARK_AQUA + " - Hide players"); + ChatManager.getInstance().sendCommandMessage(player, ChatColor.GOLD + "/show" + ChatColor.DARK_AQUA + " - Show players"); + return true; + } else if ((args.length == 1) && (args[0].equalsIgnoreCase("info"))) { + ChatManager.getInstance().sendCommandMessage(player, ChatColor.YELLOW + "---------- " + ChatColor.GRAY + "Player Visibility" + ChatColor.YELLOW + " ----------"); + ChatManager.getInstance().sendCommandMessage(player, ChatColor.DARK_AQUA + "Plugin by - " + ChatColor.GOLD + "tomudding"); + ChatManager.getInstance().sendCommandMessage(player, ChatColor.DARK_AQUA + "Plugin version - " + ChatColor.GOLD + plugin.getDescription().getVersion()); + return true; + } + } else if (cmd.getName().equalsIgnoreCase("hide")) { + if (!player.hasPermission("visibility.command.hide")) { ChatManager.getInstance().sendCommandMessage(player, Visibility.messagePermission); return true; } + if (!Visibility.enabledWorlds.contains(player.getLocation().getWorld().getName().toString())) { ChatManager.getInstance().sendCommandMessage(player, Visibility.messageWorld); return true; } + if (PlayerManager.getInstance().getToggleState(player.getUniqueId()) == false) { ChatManager.getInstance().sendCommandMessage(player, Visibility.messageAlreadyOff); return true; } + if (Visibility.inCooldown.contains(player.getUniqueId())) { + ChatManager.getInstance().sendMessage(player, Visibility.messageCooldown); + return true; + } else { + for (Player onlinePlayers : Bukkit.getOnlinePlayers()) { + if (!onlinePlayers.hasPermission("visibility.ignore")) { + player.hidePlayer(onlinePlayers); + } + } + + player.getInventory().setItem(Visibility.itemSlot, PlayerListener.createItemStack(false)); + PlayerManager.getInstance().setToggle(player.getUniqueId(), false); + + if (!player.hasPermission("visibility.cooldown")) { + Visibility.inCooldown.add(player.getUniqueId()); + + BukkitScheduler scheduler = Bukkit.getServer().getScheduler(); + scheduler.scheduleSyncDelayedTask(this.plugin, new Runnable() { + @Override + public void run() { + Visibility.inCooldown.remove(player.getUniqueId()); + } + }, Visibility.timeCooldown * 20); + } + + ChatManager.getInstance().sendMessage(player, Visibility.messageToggleOff); + return true; + } + } else if (cmd.getName().equalsIgnoreCase("show")) { + if (!player.hasPermission("visibility.command.show")) { ChatManager.getInstance().sendCommandMessage(player, Visibility.messagePermission); return true; } + if (!Visibility.enabledWorlds.contains(player.getLocation().getWorld().getName().toString())) { ChatManager.getInstance().sendCommandMessage(player, Visibility.messageWorld); return true; } + if (PlayerManager.getInstance().getToggleState(player.getUniqueId()) == true) { ChatManager.getInstance().sendCommandMessage(player, Visibility.messageAlreadyOn); return true; } + if (Visibility.inCooldown.contains(player.getUniqueId())) { + ChatManager.getInstance().sendMessage(player, Visibility.messageCooldown); + return true; + } else { + for (Player onlinePlayers : Bukkit.getOnlinePlayers()) { + player.showPlayer(onlinePlayers); + } + + player.getInventory().setItem(Visibility.itemSlot, PlayerListener.createItemStack(false)); + PlayerManager.getInstance().setToggle(player.getUniqueId(), false); + + if (!player.hasPermission("visibility.cooldown")) { + Visibility.inCooldown.add(player.getUniqueId()); + + BukkitScheduler scheduler = Bukkit.getServer().getScheduler(); + scheduler.scheduleSyncDelayedTask(this.plugin, new Runnable() { + @Override + public void run() { + Visibility.inCooldown.remove(player.getUniqueId()); + } + }, Visibility.timeCooldown * 20); + } + + ChatManager.getInstance().sendMessage(player, Visibility.messageToggleOn); + return true; + } + } + } else { + if (cmd.getName().equalsIgnoreCase("visibility")) { + if (args.length == 0) { + ChatManager.getInstance().log(ChatColor.YELLOW + "---------- " + ChatColor.GRAY + "Player Visibility" + ChatColor.YELLOW + " ----------"); + ChatManager.getInstance().log(ChatColor.GOLD + "/"+cmd.getName().toLowerCase().toString()+"" + ChatColor.DARK_AQUA + " - This help menu"); + ChatManager.getInstance().log(ChatColor.GOLD + "/"+cmd.getName().toLowerCase().toString()+" info" + ChatColor.DARK_AQUA + " - Information about the plugin"); + return true; + } else if ((args.length == 1) && (args[0].equalsIgnoreCase("info"))) { + ChatManager.getInstance().log(ChatColor.YELLOW + "---------- " + ChatColor.GRAY + "Player Visibility" + ChatColor.YELLOW + " ----------"); + ChatManager.getInstance().log(ChatColor.DARK_AQUA + "Plugin by - " + ChatColor.GOLD + "tomudding"); + ChatManager.getInstance().log(ChatColor.DARK_AQUA + "Plugin version - " + ChatColor.GOLD + plugin.getDescription().getVersion()); + return true; + } + } else if ((cmd.getName().equalsIgnoreCase("hide")) || (cmd.getName().equalsIgnoreCase("show"))) { + ChatManager.getInstance().log("&cThis command is player-only."); + return true; + } + } + return false; + } +} diff --git a/legacy/src/nl/tomudding/plugins/visibility/listeners/PlayerListener.java b/legacy/src/nl/tomudding/plugins/visibility/listeners/PlayerListener.java new file mode 100644 index 0000000..eadb415 --- /dev/null +++ b/legacy/src/nl/tomudding/plugins/visibility/listeners/PlayerListener.java @@ -0,0 +1,310 @@ +package nl.tomudding.plugins.visibility.listeners; + +import java.util.LinkedList; +import java.util.UUID; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.DyeColor; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.block.Action; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.event.player.PlayerChangedWorldEvent; +import org.bukkit.event.player.PlayerDropItemEvent; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerRespawnEvent; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; +import org.bukkit.material.Dye; +import org.bukkit.scheduler.BukkitScheduler; + +import nl.tomudding.plugins.visibility.Visibility; +import nl.tomudding.plugins.visibility.managers.ChatManager; +import nl.tomudding.plugins.visibility.managers.PlayerManager; + +public class PlayerListener implements Listener { + private Visibility plugin; + + public PlayerListener(Visibility plugin) { + this.plugin = plugin; + } + + @EventHandler + public void onPlayerJoin(PlayerJoinEvent event) { + Player player = event.getPlayer(); + UUID uuid = player.getUniqueId(); + + if (Visibility.enabledWorlds.contains(player.getLocation().getWorld().getName().toString())) { + if (PlayerManager.getInstance().checkIfExists(uuid) == false) { + ChatManager.getInstance().log("Player " + uuid + " is not in data.yml, injecting..."); + + PlayerManager.getInstance().setToggle(uuid, true); + for (Player onlinePlayers : Bukkit.getOnlinePlayers()) { + player.showPlayer(onlinePlayers); + } + + player.getInventory().setItem(Visibility.itemSlot, createItemStack(true)); + ChatManager.getInstance().sendMessage(player, Visibility.messageToggleOn); + } else if (PlayerManager.getInstance().checkIfExists(uuid) == true) { + ChatManager.getInstance().log("Player " + uuid + " is in data.yml"); + + if (PlayerManager.getInstance().getToggleState(uuid) == true) { + for (Player onlinePlayers : Bukkit.getOnlinePlayers()) { + if (Visibility.enabledWorlds.contains(onlinePlayers.getWorld().getName().toString())) { + player.showPlayer(onlinePlayers); + } + } + + player.getInventory().setItem(Visibility.itemSlot, createItemStack(true)); + ChatManager.getInstance().sendMessage(player, Visibility.messageToggleOn); + } else if (PlayerManager.getInstance().getToggleState(uuid) == false) { + for (Player onlinePlayers : Bukkit.getOnlinePlayers()) { + if (Visibility.enabledWorlds.contains(onlinePlayers.getWorld().getName().toString())) { + if (!onlinePlayers.hasPermission("visibility.ignore")) { + player.hidePlayer(onlinePlayers); + } + } + } + + player.getInventory().setItem(Visibility.itemSlot, createItemStack(false)); + ChatManager.getInstance().sendMessage(player, Visibility.messageToggleOff); + } + } + + for (Player onlinePlayers : Bukkit.getOnlinePlayers()) { + if (Visibility.enabledWorlds.contains(onlinePlayers.getLocation().getWorld().getName().toString())) { + if (PlayerManager.getInstance().getToggleState(onlinePlayers.getUniqueId()) == true) { + onlinePlayers.showPlayer(player); + } else if (PlayerManager.getInstance().getToggleState(onlinePlayers.getUniqueId()) == false) { + if (!player.hasPermission("visibility.ignore")) { + onlinePlayers.hidePlayer(player); + } + } + } + } + } + } + + @EventHandler + public void onPlayerInteract(PlayerInteractEvent event) { + Player player = event.getPlayer(); + if (player.getInventory().getItemInHand().equals(null) || player.getInventory().getItemInHand().equals(Material.AIR)) return; + if (player.getInventory().getItemInHand().equals(createItemStack(true))) { + if (!Visibility.enabledWorlds.contains(player.getLocation().getWorld().getName().toString())) { ChatManager.getInstance().sendMessage(player, Visibility.messageWorld); return; } + if (event.getAction().equals(Action.LEFT_CLICK_AIR) || event.getAction().equals(Action.LEFT_CLICK_BLOCK)) return; + if (event.getItem().getType().isBlock()) event.setCancelled(true); + if (player.hasPermission("visibility.hide")) { + if (!Visibility.inCooldown.contains(player.getUniqueId())) { + for (Player onlinePlayers : Bukkit.getOnlinePlayers()) { + if (!onlinePlayers.hasPermission("visibility.ignore")) { + player.hidePlayer(onlinePlayers); + } + } + + player.getInventory().setItem(Visibility.itemSlot, createItemStack(false)); + PlayerManager.getInstance().setToggle(player.getUniqueId(), false); + + if (!player.hasPermission("visibility.cooldown")) { + Visibility.inCooldown.add(player.getUniqueId()); + + BukkitScheduler scheduler = Bukkit.getServer().getScheduler(); + scheduler.scheduleSyncDelayedTask(this.plugin, new Runnable() { + @Override + public void run() { + Visibility.inCooldown.remove(player.getUniqueId()); + } + }, Visibility.timeCooldown * 20); + } + + ChatManager.getInstance().sendMessage(player, Visibility.messageToggleOff); + } else { + ChatManager.getInstance().sendMessage(player, Visibility.messageCooldown); + } + } else { + ChatManager.getInstance().sendMessage(player, Visibility.messagePermission); + } + } else if (player.getInventory().getItemInHand().equals(createItemStack(false))) { + if (!Visibility.enabledWorlds.contains(player.getLocation().getWorld().getName().toString())) { ChatManager.getInstance().sendMessage(player, Visibility.messageWorld); return; } + if (event.getAction().equals(Action.LEFT_CLICK_AIR) || event.getAction().equals(Action.LEFT_CLICK_BLOCK)) return; + if (event.getItem().getType().isBlock()) event.setCancelled(true); + if (player.hasPermission("visibility.show")) { + if (!Visibility.inCooldown.contains(player.getUniqueId())) { + for (Player onlinePlayers : Bukkit.getOnlinePlayers()) { + player.showPlayer(onlinePlayers); + } + + player.getInventory().setItem(Visibility.itemSlot, createItemStack(true)); + PlayerManager.getInstance().setToggle(player.getUniqueId(), true); + + if (!player.hasPermission("visibility.cooldown")) { + Visibility.inCooldown.add(player.getUniqueId()); + + BukkitScheduler scheduler = Bukkit.getServer().getScheduler(); + scheduler.scheduleSyncDelayedTask(this.plugin, new Runnable() { + @Override + public void run() { + Visibility.inCooldown.remove(player.getUniqueId()); + } + }, Visibility.timeCooldown * 20); + } + + ChatManager.getInstance().sendMessage(player, Visibility.messageToggleOn); + } else { + ChatManager.getInstance().sendMessage(player, Visibility.messageCooldown); + } + } else { + ChatManager.getInstance().sendMessage(player, Visibility.messagePermission); + } + } + } + + @EventHandler + public void onWorldChange(PlayerChangedWorldEvent event) { + Player player = event.getPlayer(); + + if (Visibility.enabledWorlds.contains(player.getLocation().getWorld().getName().toString())) { + if (PlayerManager.getInstance().getToggleState(player.getUniqueId()) == true) { + player.getPlayer().getInventory().setItem(Visibility.itemSlot, createItemStack(true)); + } else if (PlayerManager.getInstance().getToggleState(player.getUniqueId()) == false) { + player.getPlayer().getInventory().setItem(Visibility.itemSlot, createItemStack(false)); + } + + for (Player onlinePlayers : Bukkit.getOnlinePlayers()) { + if (onlinePlayers.getWorld().equals(player.getLocation().getWorld())) { + if (PlayerManager.getInstance().getToggleState(player.getUniqueId()) == true) { + player.showPlayer(onlinePlayers); + } else if (PlayerManager.getInstance().getToggleState(player.getUniqueId()) == false) { + if (!onlinePlayers.hasPermission("visibility.ignore")) { + player.hidePlayer(onlinePlayers); + } + } + + if (PlayerManager.getInstance().getToggleState(onlinePlayers.getUniqueId()) == true) { + onlinePlayers.showPlayer(player); + } else if (PlayerManager.getInstance().getToggleState(onlinePlayers.getUniqueId()) == false) { + if (!player.hasPermission("visibility.ignore")) { + onlinePlayers.hidePlayer(player); + } + } + } + } + + if (PlayerManager.getInstance().getToggleState(player.getUniqueId()) == true) { + ChatManager.getInstance().sendMessage(player, Visibility.messageToggleOn); + } else if (PlayerManager.getInstance().getToggleState(player.getUniqueId()) == false) { + ChatManager.getInstance().sendMessage(player, Visibility.messageToggleOff); + } + } else { + for (Player onlinePlayers : Bukkit.getOnlinePlayers()) { + player.showPlayer(onlinePlayers); + onlinePlayers.showPlayer(player); // Not sure about this one + } + + if (player.getInventory().contains(createItemStack(true))) { + player.getInventory().remove(createItemStack(false)); + } else if (player.getInventory().contains(createItemStack(false))) { + player.getInventory().remove(createItemStack(false)); + } + } + } + + @EventHandler + public void onRespawn(PlayerRespawnEvent event) { + Player player = event.getPlayer(); + if (Visibility.enabledWorlds.contains(event.getRespawnLocation().getWorld().getName().toString())) { + player.getInventory().setItem(Visibility.itemSlot, createItemStack(PlayerManager.getInstance().getToggleState(player.getUniqueId()))); + } else { + for (Player onlinePlayers : Bukkit.getOnlinePlayers()) { + player.showPlayer(onlinePlayers); + onlinePlayers.showPlayer(player); // Not sure about this one + } + } + } + + @EventHandler(priority=EventPriority.NORMAL) + public void onDropItem(PlayerDropItemEvent event) { + Player player = event.getPlayer(); + if (Visibility.enabledWorlds.contains(player.getLocation().getWorld().getName().toString()) && player.getInventory().getHeldItemSlot() == Visibility.itemSlot) { + event.setCancelled(true); + ChatManager.getInstance().sendMessage(player, Visibility.messageNoSwitch); + } + } + + @EventHandler + public void onClickInventory(InventoryClickEvent event) { + if (Visibility.enabledWorlds.contains(event.getWhoClicked().getLocation().getWorld().getName().toString()) && + event.getSlot() == Visibility.itemSlot) { + event.setCancelled(true); + ChatManager.getInstance().sendMessage(plugin.getServer().getPlayer(event.getWhoClicked().getUniqueId()), Visibility.messageNoSwitch); + } + } + + public static ItemStack createItemStack(boolean toggleState) { + ItemStack itemStack = null; + LinkedList itemLore = new LinkedList(); + DyeColor dyeColor = null; + + if (toggleState) { + if (Visibility.isDyeEnabled) { + Dye dye = new Dye(); + + try { + dyeColor = DyeColor.valueOf(Visibility.dyeColorOn); + } catch (Exception exception) { + ChatManager.getInstance().log("&cWARNING: Config.yml contains invalid DyeColor type (for 'on' state)!"); + dyeColor = DyeColor.LIME; // fallback + } + + dye.setColor(dyeColor); + itemStack = dye.toItemStack(1); + } else { + try { + itemStack = new ItemStack(Material.valueOf(Visibility.itemIdOn)); + } catch (Exception exception) { + ChatManager.getInstance().log("&cWARNING: Config.yml contains invalid ItemStack type (for 'on' state)!"); + itemStack = new ItemStack(Material.SLIME_BALL); // fallback + } + } + + ItemMeta itemMeta = itemStack.getItemMeta(); + itemLore.add(ChatColor.translateAlternateColorCodes('&', Visibility.itemLoreOn)); + itemMeta.setDisplayName(ChatColor.translateAlternateColorCodes('&', Visibility.itemNameOn)); + itemMeta.setLore(itemLore); + itemStack.setItemMeta(itemMeta); + } else { + if (Visibility.isDyeEnabled) { + Dye dye = new Dye(); + + try { + dyeColor = DyeColor.valueOf(Visibility.dyeColorOff); + } catch (Exception exception) { + ChatManager.getInstance().log("&cWARNING: Config.yml contains invalid DyeColor type (for 'off' state)!"); + dyeColor = DyeColor.GRAY; // fallback + } + + dye.setColor(dyeColor); + itemStack = dye.toItemStack(1); + } else { + try { + itemStack = new ItemStack(Material.valueOf(Visibility.itemIdOff)); + } catch (Exception exception) { + ChatManager.getInstance().log("&cWARNING: Config.yml contains invalid ItemStack type (for 'off' state)!"); + itemStack = new ItemStack(Material.MAGMA_CREAM); // fallback + } + } + + ItemMeta itemMeta = itemStack.getItemMeta(); + itemLore.add(ChatColor.translateAlternateColorCodes('&', Visibility.itemLoreOff)); + itemMeta.setDisplayName(ChatColor.translateAlternateColorCodes('&', Visibility.itemNameOff)); + itemMeta.setLore(itemLore); + itemStack.setItemMeta(itemMeta); + } + + return itemStack; + } +} diff --git a/legacy/src/nl/tomudding/plugins/visibility/managers/ChatManager.java b/legacy/src/nl/tomudding/plugins/visibility/managers/ChatManager.java new file mode 100644 index 0000000..ffd7293 --- /dev/null +++ b/legacy/src/nl/tomudding/plugins/visibility/managers/ChatManager.java @@ -0,0 +1,45 @@ +package nl.tomudding.plugins.visibility.managers; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; + +import nl.tomudding.plugins.visibility.Visibility; + +public class ChatManager { + private static ChatManager instance = new ChatManager(); + + public static ChatManager getInstance() { + return instance; + } + + public void log(String s) { + Bukkit.getConsoleSender().sendMessage(ChatColor.BLUE + "Player Visibility >> " + ChatColor.translateAlternateColorCodes('&', s)); + } + + public void sendMessage(Player player, String message) { + if (Visibility.actionBar) { + try { + if (Visibility.getServerVersion().startsWith("v1_8_")) { + // if the server does not use this version it should have been disabled + Object chatComponentText = Visibility.getNMSClass("ChatComponentText").getConstructor(new Class[] { String.class }).newInstance(new Object[] { ChatColor.translateAlternateColorCodes('&', message)}); + Class iChatBaseComponent = Visibility.getNMSClass("IChatBaseComponent"); + Object packetPlayOutChat = Visibility.getNMSClass("PacketPlayOutChat").getConstructor(new Class[] { iChatBaseComponent, Byte.TYPE }).newInstance(new Object[] { chatComponentText, Byte.valueOf((byte) 2) }); + + Object playerNMS = player.getClass().getMethod("getHandle", new Class[0]).invoke(player, new Object[0]); + Object playerConnection = playerNMS.getClass().getField("playerConnection").get(playerNMS); + Class playerPacket = Visibility.getNMSClass("Packet"); + playerConnection.getClass().getMethod("sendPacket", new Class[] { playerPacket }).invoke(playerConnection, new Object[] { packetPlayOutChat }); + } + } catch (Exception exception) { + exception.printStackTrace(); + } + } else { + player.sendMessage(ChatColor.translateAlternateColorCodes('&', Visibility.messagePrefix + message)); + } + } + + public void sendCommandMessage(Player player, String message) { + player.sendMessage(ChatColor.translateAlternateColorCodes('&', message)); + } +} diff --git a/legacy/src/nl/tomudding/plugins/visibility/managers/PlayerManager.java b/legacy/src/nl/tomudding/plugins/visibility/managers/PlayerManager.java new file mode 100644 index 0000000..f90838b --- /dev/null +++ b/legacy/src/nl/tomudding/plugins/visibility/managers/PlayerManager.java @@ -0,0 +1,79 @@ +package nl.tomudding.plugins.visibility.managers; + +import java.io.File; +import java.io.IOException; +import java.util.UUID; + +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.plugin.Plugin; + +import nl.tomudding.plugins.visibility.Visibility; + +public class PlayerManager { + static PlayerManager instance = new PlayerManager(); + private Visibility p; + + FileConfiguration data; + File dfile; + + public static PlayerManager getInstance() { + return instance; + } + + public Plugin getPlugin() { + return this.p; + } + + public void setup(Visibility p) { + this.dfile = new File(p.getDataFolder(), "data.yml"); + + if (!this.dfile.exists()) { + ChatManager.getInstance().log("&cWARNING: data.yml does not exist."); + ChatManager.getInstance().log("Creating data.yml."); + try { + this.dfile.createNewFile(); + ChatManager.getInstance().log("&aSuccessfully created data.yml."); + } catch (IOException e) { + ChatManager.getInstance().log("&cWARNING: Could not create data.yml."); + } + } + this.data = YamlConfiguration.loadConfiguration(this.dfile); + } + + public FileConfiguration getData() { + return this.data; + } + + public void saveData() { + try { + this.data.save(this.dfile); + } catch (IOException e) { + ChatManager.getInstance().log("&cWARNING: Could not save data.yml!"); + } + } + + public void reloadData() { + data = YamlConfiguration.loadConfiguration(this.dfile); + } + + public boolean getToggleState(UUID uuid) { + String playerData = uuid.toString(); + return data.getBoolean(playerData); + } + + public boolean checkIfExists(UUID uuid) { + String UUID = uuid.toString(); + if(data.contains(UUID)) { + return true; + } else { + return false; + } + } + + public void setToggle(UUID uuid, Boolean state) { + String p = uuid.toString(); + data.set(p, state); + saveData(); + } +} diff --git a/legacy/src/plugin.yml b/legacy/src/plugin.yml new file mode 100644 index 0000000..1da6ccc --- /dev/null +++ b/legacy/src/plugin.yml @@ -0,0 +1,39 @@ +name: Visibility +author: tomudding +main: nl.tomudding.plugins.visibility.Visibility +version: 2.2 + +commands: + hide: + description: Hide other players + usage: / + show: + description: Show other players + usage: / + visibility: + description: The help for Player Visibility + usage: / + +permissions: + visibility.*: + description: Gives access to all Visibility permissions + default: op + children: + visibility.cooldown: true + visibility.hide: true + visibility.command.hide: true + visibility.ignore: true + visibility.show: true + visibility.command.show: true + visibility.cooldown: + description: A bypass for the cooldown + visibility.hide: + description: Allows a player to hide other players + visibility.command.hide: + description: Allows a player to hide other players using the command + visibility.ignore: + description: A bypass to stay visible when toggled invisible + visibility.show: + description: Allows a player to show other players + visibility.command.show: + description: Allows a player to show other players using the command