Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import org.bukkit.Bukkit;
- import org.bukkit.Location;
- import org.bukkit.World;
- import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
- import org.bukkit.entity.Player;
- import net.minecraft.server.v1_8_R3.EnumParticle;
- import net.minecraft.server.v1_8_R3.PacketPlayOutWorldParticles;
- public class Particle {
- //Send a particle to one player at a specific location
- public static void playerSendParticle(Player player, Location loc, EnumParticle particle) {
- float x = (float) loc.getX();
- float y = (float) loc.getY();
- float z = (float) loc.getZ();
- PacketPlayOutWorldParticles packet = new PacketPlayOutWorldParticles(particle,true, (float)x, (float)y, (float)z, 0, 0, 0, 0, 1);
- ((CraftPlayer)player).getHandle().playerConnection.sendPacket(packet);
- }
- //Send a particle to all players at a specific location
- public static void sendParticleAll(Location loc, EnumParticle particle) {
- double x = loc.getX();
- double y = loc.getY();
- double z = loc.getZ();
- PacketPlayOutWorldParticles packet = new PacketPlayOutWorldParticles(particle,true, (float)x, (float)y, (float)z, 0, 0, 0, 0, 1);
- for(Player online : Bukkit.getOnlinePlayers()) {
- ((CraftPlayer)online).getHandle().playerConnection.sendPacket(packet);
- }
- }
- //Send a particle to all players except one player
- public static void sendParticleAllExept(Location loc, EnumParticle particle, Player exception) {
- double x = loc.getX();
- double y = loc.getY();
- double z = loc.getZ();
- PacketPlayOutWorldParticles packet = new PacketPlayOutWorldParticles(particle,true, (float)x, (float)y, (float)z, 0, 0, 0, 0, 1);
- for(Player online : Bukkit.getOnlinePlayers()) {
- if(online != exception) {
- ((CraftPlayer)online).getHandle().playerConnection.sendPacket(packet);
- }
- }
- }
- //Send a particle to all players apart from a list of players
- public static void sendParticleAllExeptMulti(Location loc, EnumParticle particle, ArrayList<Player>exception) {
- double x = loc.getX();
- double y = loc.getY();
- double z = loc.getZ();
- PacketPlayOutWorldParticles packet = new PacketPlayOutWorldParticles(particle,true, (float)x, (float)y, (float)z, 0, 0, 0, 0, 1);
- for(Player online : Bukkit.getOnlinePlayers()) {
- if(!exception.contains(online)) {
- ((CraftPlayer)online).getHandle().playerConnection.sendPacket(packet);
- }
- }
- }
- //Send a spiral cone to all players at a location
- public static void sendConeAll(Location loc, EnumParticle particle) {
- double phi = 0;
- phi = phi + Math.PI/8;
- double x, y, z;
- for (double t = 0; t <= 2*Math.PI; t = t + Math.PI/16){
- for (double i = 0; i <= 1; i = i + 1){
- x = 0.4*(2*Math.PI-t)*0.5*Math.cos(t + phi + i*Math.PI);
- y = 0.5*t;
- z = 0.4*(2*Math.PI-t)*0.5*Math.sin(t + phi + i*Math.PI);
- loc.add(x, y, z);
- PacketPlayOutWorldParticles packet = new PacketPlayOutWorldParticles(particle,true, (float) loc.getX(), (float) (loc.getY() ), (float) (loc.getZ() ), 0, 0, 0, 0, 1);
- for(Player online : Bukkit.getOnlinePlayers()) {
- ((CraftPlayer)online).getHandle().playerConnection.sendPacket(packet);
- }
- loc.subtract(x,y,z);
- }
- }
- }
- //Send a halo effect to all players at a specific location
- public static void sendHaloAll(Location loc, EnumParticle particle, double radius, int amount) {
- ArrayList<Location> locs = getCircle(loc, radius, amount);
- for(Location newloc : locs) {
- sendParticleAll(newloc,particle);
- }
- }
- public static ArrayList<Location> getCircle(Location center, double radius, int amount)
- {
- World world = center.getWorld();
- double increment = (2 * Math.PI) / amount;
- ArrayList<Location> locations = new ArrayList<Location>();
- for(int i = 0;i < amount; i++)
- {
- double angle = i * increment;
- double x = center.getX() + (radius * Math.cos(angle));
- double z = center.getZ() + (radius * Math.sin(angle));
- locations.add(new Location(world, x, center.getY(), z));
- }
- return locations;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement