Академический Документы
Профессиональный Документы
Культура Документы
utils;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Player;
version = Bukkit.getServer().getClass().getPackage().getName()
.split("\\.")[3];
packetType = Class.forName(getPacketPlayOutParticles());
Class<?> typeCraftPlayer =
Class.forName(getCraftPlayerClasspath());
Class<?> typeNMSPlayer = Class.forName(getNMSPlayerClasspath());
Class<?> typePlayerConnection = Class
.forName(getPlayerConnectionClasspath());
getHandle = typeCraftPlayer.getMethod("getHandle");
playerConnection = typeNMSPlayer.getField("playerConnection");
sendPacket = typePlayerConnection.getMethod("sendPacket",
Class.forName(getPacketClasspath()));
} catch (Exception e) {
System.out
.println("Failed to setup reflection for
PacketPlayOutWorldParticles");
e.printStackTrace();
}
}
// Particle Effects
public static void spawnParticles(Location loc, Player receivingPacket,
String packetname, int amount) throws ClassNotFoundException,
IllegalAccessException, InstantiationException,
NoSuchMethodException, NoSuchFieldException,
IllegalArgumentException, InvocationTargetException {
packet = packetType.newInstance();
setField("a", packetname); // Particle name
setField("b", loc.getBlockX()); // Block X
setField("c", loc.getBlockY()); // Block Y
setField("d", loc.getBlockZ()); // Block Z
setField("e", 1); // Random X Offset
setField("f", 1); // Random Y Offset
setField("g", 1); // Random Z Offset
setField("h", 0); // Speed/data of particles
setField("i", amount); // Amount of particles
sendPacket.invoke(connection, packet);
}