Skip to content

Instantly share code, notes, and snippets.

@Phoenix616
Last active May 24, 2018 15:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Phoenix616/80b63922bbfaa20a3058 to your computer and use it in GitHub Desktop.
Save Phoenix616/80b63922bbfaa20a3058 to your computer and use it in GitHub Desktop.
Click on particles...
HashMap<UUID,Location> stands = new HashMap<UUID, Location>();
double particleHeight = 1.5;
public void onEnable() {
getServer().getPluginManager().registerEvents(this, this);
Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
@Override
public void run() {
for(Location loc : stands.values()) {
loc.getWorld().spigot().playEffect(loc, Effect.COLOURED_DUST, 0, 0, 0f, 0f, 0f, 30, 2, 64);
}
}
}, 20L, 10L);
}
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if(sender instanceof Player) {
Player p = (Player) sender;
ArmorStand as = (ArmorStand) p.getLocation().getWorld().spawnEntity(p.getLocation(), EntityType.ARMOR_STAND);
as.setGravity(false);
as.setVisible(false);
stands.put(as.getUniqueId(), as.getLocation().add(0, particleHeight, 0));
}
return false;
}
@EventHandler
public void onStandClick(PlayerInteractAtEntityEvent event) {
if(event.getRightClicked().getType() == EntityType.ARMOR_STAND && stands.containsKey(event.getRightClicked().getUniqueId())) {
Location clicked = event.getRightClicked().getLocation().add(event.getClickedPosition());
Location loc = event.getRightClicked().getLocation().add(0, particleHeight, 0);
double distance = clicked.distance(loc);
this.getLogger().info("Distance: " + distance);
if (distance < 0.39) // max distance e.g. volume depends on the particle!
event.getPlayer().sendMessage(ChatColor.GREEN + "[Particle] You clicked me!");
}
}
@Phoenix616
Copy link
Author

The clicked position is a strange one... this is not really that usable as the distance to the particles point varies. Maybe there is a better entity for this job? Or could just use vectors properly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment