Advertisement
Guest User

Particle Statics v1.0

a guest
Jul 19th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.10 KB | None | 0 0
  1. import java.util.ArrayList;
  2.  
  3. import org.bukkit.Bukkit;
  4. import org.bukkit.Location;
  5. import org.bukkit.World;
  6. import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
  7. import org.bukkit.entity.Player;
  8.  
  9. import net.minecraft.server.v1_8_R3.EnumParticle;
  10. import net.minecraft.server.v1_8_R3.PacketPlayOutWorldParticles;
  11.  
  12.  
  13. public class Particle {
  14.    
  15.    
  16.     //Send a particle to one player at a specific location
  17.     public static void playerSendParticle(Player player, Location loc, EnumParticle particle) {
  18.         float x = (float) loc.getX();
  19.         float y = (float) loc.getY();
  20.         float z = (float) loc.getZ();
  21.         PacketPlayOutWorldParticles packet = new PacketPlayOutWorldParticles(particle,true, (float)x, (float)y, (float)z, 0, 0, 0, 0, 1);
  22.         ((CraftPlayer)player).getHandle().playerConnection.sendPacket(packet);
  23.     }
  24.    
  25.     //Send a particle to all players at a specific location
  26.     public static void sendParticleAll(Location loc, EnumParticle particle) {
  27.         double x = loc.getX();
  28.         double y = loc.getY();
  29.         double z = loc.getZ();
  30.         PacketPlayOutWorldParticles packet = new PacketPlayOutWorldParticles(particle,true, (float)x, (float)y, (float)z, 0, 0, 0, 0, 1);
  31.         for(Player online : Bukkit.getOnlinePlayers()) {
  32.             ((CraftPlayer)online).getHandle().playerConnection.sendPacket(packet);
  33.         }
  34.     }
  35.    
  36.     //Send a particle to all players except one player
  37.     public static void sendParticleAllExept(Location loc, EnumParticle particle, Player exception) {
  38.         double x = loc.getX();
  39.         double y = loc.getY();
  40.         double z = loc.getZ();
  41.         PacketPlayOutWorldParticles packet = new PacketPlayOutWorldParticles(particle,true, (float)x, (float)y, (float)z, 0, 0, 0, 0, 1);
  42.         for(Player online : Bukkit.getOnlinePlayers()) {
  43.             if(online != exception) {
  44.                 ((CraftPlayer)online).getHandle().playerConnection.sendPacket(packet);
  45.             }
  46.         }
  47.     }
  48.    
  49.     //Send a particle to all players apart from a list of players
  50.     public static void sendParticleAllExeptMulti(Location loc, EnumParticle particle, ArrayList<Player>exception) {
  51.         double x = loc.getX();
  52.         double y = loc.getY();
  53.         double z = loc.getZ();
  54.         PacketPlayOutWorldParticles packet = new PacketPlayOutWorldParticles(particle,true, (float)x, (float)y, (float)z, 0, 0, 0, 0, 1);
  55.         for(Player online : Bukkit.getOnlinePlayers()) {
  56.             if(!exception.contains(online)) {
  57.                 ((CraftPlayer)online).getHandle().playerConnection.sendPacket(packet);
  58.             }
  59.         }
  60.     }
  61.    
  62.     //Send a spiral cone to all players at a location
  63.     public static void sendConeAll(Location loc, EnumParticle particle) {
  64.         double phi = 0;
  65.         phi = phi + Math.PI/8;                                
  66.         double x, y, z;                
  67.         for (double t = 0; t <= 2*Math.PI; t = t + Math.PI/16){
  68.             for (double i = 0; i <= 1; i = i + 1){
  69.                 x = 0.4*(2*Math.PI-t)*0.5*Math.cos(t + phi + i*Math.PI);
  70.                 y = 0.5*t;
  71.                 z = 0.4*(2*Math.PI-t)*0.5*Math.sin(t + phi + i*Math.PI);
  72.                 loc.add(x, y, z);
  73.                 PacketPlayOutWorldParticles packet = new PacketPlayOutWorldParticles(particle,true, (float) loc.getX(), (float) (loc.getY() ), (float) (loc.getZ() ), 0, 0, 0, 0, 1);
  74.                 for(Player online : Bukkit.getOnlinePlayers()) {
  75.                     ((CraftPlayer)online).getHandle().playerConnection.sendPacket(packet);
  76.                 }
  77.                 loc.subtract(x,y,z);
  78.             }
  79.         }
  80.     }
  81.     //Send a halo effect to all players at a specific location
  82.     public static void sendHaloAll(Location loc, EnumParticle particle, double radius, int amount) {
  83.         ArrayList<Location> locs = getCircle(loc, radius, amount);
  84.         for(Location newloc : locs) {
  85.             sendParticleAll(newloc,particle);
  86.         }
  87.     }
  88.    
  89.     public static ArrayList<Location> getCircle(Location center, double radius, int amount)
  90.     {
  91.         World world = center.getWorld();
  92.         double increment = (2 * Math.PI) / amount;
  93.         ArrayList<Location> locations = new ArrayList<Location>();
  94.         for(int i = 0;i < amount; i++)
  95.         {
  96.             double angle = i * increment;
  97.             double x = center.getX() + (radius * Math.cos(angle));
  98.             double z = center.getZ() + (radius * Math.sin(angle));
  99.             locations.add(new Location(world, x, center.getY(), z));
  100.         }
  101.         return locations;
  102.     }
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement