-={ Intro }=- I was bored today, so I decided to make a tutorial. I always wondered how servers like Mineplex and Hypixel made that floating text. I saw the Hologram plugins out there, but I wanted to write my own from scratch so I understand it better. Today I will share with you the secret of how it all works, and rejoice there is no nms or packets involved! By the way, I will not be covering touchscreen holograms in this tutorial, that involves lots of trigonometry and I am lazy. -={ Explanation }=- So how exactly do these holograms work? Well, they actually are very simple. All that happens is an Armor Stand is spawned, made invisible, and given a name. That's literally it! -={ Code }=- The code to do all this is very easy. Feel free to modify it as much as you want! PHP: ArmorStand as = (ArmorStand) location.getWorld().spawnEntity(location, EntityType.ARMOR_STAND); //Spawn the ArmorStand as.setGravity(false); //Make sure it doesn't fall as.setCanPickupItems(false); //I'm not sure what happens if you leave this as it is, but you might as well disable it as.setCustomName(text); //Set this to the text you want as.setCustomNameVisible(true); //This makes the text appear no matter if your looking at the entity or not as.setVisible(false); //Makes the ArmorStand invisible This snippet (Thanks to @MCAeolus ) prevents players from right clicking items onto the armorstand: PHP: @EventHandler public void manipulate(PlayerArmorStandManipulateEvent e) { if(!e.getRightClicked().isVisible()) { e.setCancelled(true); } } P.S. If this helped you at all, remember to leave a rating! It really helps me out!
Very nice tutorial! I made a little command for utilizing it if anyone would want to see an example: Code (Text): public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) { if(cmd.getName().equals("hologram")){ if(sender instanceof Player){ if(args.length != 0) { Location location = ((Player) sender).getLocation(); ArmorStand as = (ArmorStand) location.getWorld().spawnEntity(location, EntityType.ARMOR_STAND); //Spawn the ArmorStand String myString = ""; //we're going to store the arguments here String arg; for(int i = 0; i < args.length; i++){ //loop threw all the arguments if(i != args.length - 1) { arg = args[i] + " "; //get the argument, and add a space so that the words get spaced out }else{ arg = args[i]; //So there will be no space after last argument } myString = myString + arg; //add the argument to myString } String textFinal = ChatColor.translateAlternateColorCodes('&',myString); as.setGravity(false); //Make sure it doesn't fall as.setCanPickupItems(false); //I'm not sure what happens if you leave this as it is, but you might as well disable it as.setCustomName(textFinal); //Set this to the text you want as.setCustomNameVisible(true); //This makes the text appear no matter if your looking at the entity or not as.setVisible(false); //Makes the ArmorStand invisible }else{ sender.sendMessage("No extra parameter set!"); } }else{ System.out.println("Only players can do this."); } } return false; }
Lol, wasn't sure what you meant about placing items until I did this... ANYWAYS, until @Assossa puts together something better, I made a little getover fix to stop that from happening. Simply add this event: Code (Text): @EventHandler public void manipulate(PlayerArmorStandManipulateEvent e){ if(!e.getRightClicked().isVisible()){ e.setCancelled(true); } } Hope that helps
If you don't have the knowledge to create touchscreen holograms out of this... You should REALLY look at the docs/learn Java...
I guess you would do it using a PlayerInteractEntityEvent or EntityDamageByEntityEvent, but the problem with that is that you need to hit below the text to get it working, I think @HarrysMc ment that when you actually touch the text something happens
I do not think That hypixel and mineplex are using this method .. They could use armorstand but with packets .
Not really. The text appears above the entity. So a entity interact event would not work. You would have to check for all right clicks, then check if the player is in range and if they are looking in the same direction as the entity. They do use armorstands, and they probably do use packets. Unfortunately, I am not well versed in packets.
First: I already know how to do it it was just an idea for a follow up tutorial. Second: You are saying that by learning Java only you would be able to do that and that is not true you would need to know quite a bit of Bukkit first.
Will this interfere with other plugins that modify existing entities and/or armor stands? I use similar code but it does it all through packets, so the server doesn't see them but the client does, so there's no way for the server to accidentally delete the entities. This is a great tutorial either way. It is very straightforward and easy to follow. I'm glad you posted it!