Last active
May 24, 2018 15:03
-
-
Save Phoenix616/80b63922bbfaa20a3058 to your computer and use it in GitHub Desktop.
Click on particles...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.