players) throws ParticleVersionException, ParticleDataException {
- if (!this.isSupported()) {
- throw new ParticleVersionException("This particle effect is not supported by your server version");
- }
- if (!this.requiresData) {
- throw new ParticleDataException("This particle effect does not require additional data");
- }
- new ParticlePacket(this, direction, speed, isLongDistance(center, players), data).sendTo(center, players);
- }
-
- /**
- * Represents the particle data for effects like
- * {@link ParticleEffect#ITEM_CRACK}, {@link ParticleEffect#BLOCK_CRACK} and
- * {@link ParticleEffect#BLOCK_DUST}
- *
- * This class is part of the ParticleEffect Library and follows the
- * same usage conditions
- *
- * @author DarkBlade12
- * @since 1.6
- */
- public static abstract class ParticleData {
- private final Material material;
- private final byte data;
- private int[] packetData;
-
- /**
- * Construct a new particle data
- *
- * @param material Material of the item/block
- * @param data Data value of the item/block
- */
- public ParticleData(final Material material, final byte data) {
- this.material = material;
- this.data = data;
- this.packetData = new int[] { material.getId(), data };
- }
-
- /**
- * Returns the material of this data
- *
- * @return The material
- */
- public Material getMaterial() {
- return this.material;
- }
-
- /**
- * Returns the data value of this data
- *
- * @return The data value
- */
- public byte getData() {
- return this.data;
- }
-
- /**
- * Returns the data as an int array for packet construction
- *
- * @return The data for the packet
- */
- public int[] getPacketData() {
- return this.packetData;
- }
-
- /**
- * Returns the data as a string for pre 1.8 versions
- *
- * @return The data string for the packet
- */
- public String getPacketDataString() {
- return "_" + this.packetData[0] + "_" + this.packetData[1];
- }
-
- /**
- * Sets the packet data. Should be an integer array. For ITEM_CRACK and
- * BLOCK_DUST, it should be [id, meta] but for BLOCK_CRACK it should be
- * [id + (meta * 4096)]
- *
- * @param data The packet data.
- */
- public void setPacketData(final int[] data) {
- this.packetData = data;
- }
- }
-
- /**
- * Represents the item data for the {@link ParticleEffect#ITEM_CRACK} effect
- *
- * This class is part of the ParticleEffect Library and follows the
- * same usage conditions.
- *
- * @author DarkBlade12
- * @since 1.6
- */
- public static final class ItemData extends ParticleData {
- /**
- * Construct a new item data.
- *
- * @param material Material of the item
- * @param data Data value of the item
- * @see ParticleData#ParticleData(Material, byte)
- */
- public ItemData(final Material material, final byte data) {
- super(material, data);
- }
- }
-
- /**
- * Represents the block data for the {@link ParticleEffect#BLOCK_CRACK} and
- * {@link ParticleEffect#BLOCK_DUST} effects
- *
- * This class is part of the ParticleEffect Library and follows the
- * same usage conditions
- *
- * @author DarkBlade12
- * @since 1.6
- */
- public static final class BlockData extends ParticleData {
- /**
- * Construct a new block data
- *
- * @param material Material of the block
- * @param data Data value of the block
- * @throws IllegalArgumentException If the material is not a block
- * @see ParticleData#ParticleData(Material, byte)
- */
- public BlockData(final Material material, final byte data) throws IllegalArgumentException {
- super(material, data);
- if (!material.isBlock()) {
- throw new IllegalArgumentException("The material is not a block");
- }
-
- this.setPacketData(new int[] { material.getId() + (data * 4096) });
- }
- }
-
- /**
- * Represents a runtime exception that is thrown if the displayed particle
- * effect requires data and has none or vice-versa
- *
- * This class is part of the ParticleEffect Library and follows the
- * same usage conditions
- *
- * @author DarkBlade12
- * @since 1.6
- */
- private static final class ParticleDataException extends RuntimeException {
- private static final long serialVersionUID = 3203085387160737484L;
-
- /**
- * Construct a new particle data exception
- *
- * @param message Message that will be logged
- * @param cause Cause of the exception
- */
- public ParticleDataException(final String message) {
- super(message);
- }
- }
-
- /**
- * Represents a runtime exception that is thrown if the displayed particle
- * effect requires a newer version
- *
- * This class is part of the ParticleEffect Library and follows the
- * same usage conditions
- *
- * @author DarkBlade12
- * @since 1.6
- */
- private static final class ParticleVersionException extends RuntimeException {
- private static final long serialVersionUID = 3203085387160737484L;
-
- /**
- * Construct a new particle version exception
- *
- * @param message Message that will be logged
- * @param cause Cause of the exception
- */
- public ParticleVersionException(final String message) {
- super(message);
- }
- }
-
- /**
- * Represents a particle effect packet with all attributes which is used for
- * sending packets to the players
- *
- * This class is part of the ParticleEffect Library and follows the
- * same usage conditions
- *
- * @author DarkBlade12
- * @since 1.5
- */
- public static final class ParticlePacket {
- private static int version;
- private static Class> enumParticle;
- private static Constructor> packetConstructor;
- private static Method getHandle;
- private static Field playerConnection;
- private static Method sendPacket;
- private static boolean initialized;
- private final ParticleEffect effect;
- private final float offsetX;
- private final float offsetY;
- private final float offsetZ;
- private final float speed;
- private final int amount;
- private final boolean longDistance;
- private final ParticleData data;
- private Object packet;
-
- /**
- * Construct a new particle packet
- *
- * @param effect Particle effect
- * @param offsetX Maximum distance particles can fly away from the
- * center on the x-axis
- * @param offsetY Maximum distance particles can fly away from the
- * center on the y-axis
- * @param offsetZ Maximum distance particles can fly away from the
- * center on the z-axis
- * @param speed Display speed of the particles
- * @param amount Amount of particles
- * @param longDistance Indicates whether the maximum distance is
- * increased from 256 to 65536
- * @param data Data of the effect
- * @throws IllegalArgumentException If the speed is lower than 0 or the
- * amount is lower than 1
- * @see #initialize()
- */
- public ParticlePacket(final ParticleEffect effect, final float offsetX, final float offsetY, final float offsetZ, final float speed, final int amount, final boolean longDistance, final ParticleData data) throws IllegalArgumentException {
- initialize();
- if (speed < 0) {
- throw new IllegalArgumentException("The speed is lower than 0");
- }
- this.effect = effect;
- this.offsetX = offsetX;
- this.offsetY = offsetY;
- this.offsetZ = offsetZ;
- this.speed = speed;
- this.amount = amount;
- this.longDistance = longDistance;
- this.data = data;
- }
-
- /**
- * Construct a new particle packet of a single particle flying into a
- * determined direction
- *
- * @param effect Particle effect
- * @param direction Direction of the particle
- * @param speed Display speed of the particle
- * @param longDistance Indicates whether the maximum distance is
- * increased from 256 to 65536
- * @param data Data of the effect
- * @throws IllegalArgumentException If the speed is lower than 0
- * @see #initialize()
- */
- public ParticlePacket(final ParticleEffect effect, final Vector direction, final float speed, final boolean longDistance, final ParticleData data) throws IllegalArgumentException {
- initialize();
- if (speed < 0) {
- throw new IllegalArgumentException("The speed is lower than 0");
- }
- this.effect = effect;
- this.offsetX = (float) direction.getX();
- this.offsetY = (float) direction.getY();
- this.offsetZ = (float) direction.getZ();
- this.speed = speed;
- this.amount = 0;
- this.longDistance = longDistance;
- this.data = data;
- }
-
- /**
- * Initializes {@link #packetConstructor}, {@link #getHandle},
- * {@link #playerConnection} and {@link #sendPacket} and sets
- * {@link #initialized} to true
if it succeeds
- *
- * Note: These fields only have to be initialized once, so it
- * will return if {@link #initialized} is already set to
- * true
- *
- * @throws VersionIncompatibleException if your bukkit version is not
- * supported by this library
- */
- public static void initialize() throws VersionIncompatibleException {
- if (initialized) {
- return;
- }
- try {
- version = Integer.parseInt(PackageType.getServerVersion().split("_")[1]);
- if (version > 7) {
- enumParticle = PackageType.MINECRAFT_SERVER.getClass("EnumParticle");
- }
- final Class> packetClass = PackageType.MINECRAFT_SERVER.getClass(version < 7 ? "Packet63WorldParticles" : "PacketPlayOutWorldParticles");
- packetConstructor = ReflectionHandler.getConstructor(packetClass);
- getHandle = ReflectionHandler.getMethod("CraftPlayer", PackageType.CRAFTBUKKIT_ENTITY, "getHandle");
- playerConnection = ReflectionHandler.getField("EntityPlayer", PackageType.MINECRAFT_SERVER, false, "playerConnection");
- sendPacket = ReflectionHandler.getMethod(playerConnection.getType(), "sendPacket", PackageType.MINECRAFT_SERVER.getClass("Packet"));
- }
- catch (final Exception exception) {
- throw new VersionIncompatibleException("Your current bukkit version seems to be incompatible with this library", exception);
- }
- initialized = true;
- }
-
- /**
- * Returns the version of your server (1.x)
- *
- * @return The version number
- */
- public static int getVersion() {
- return version;
- }
-
- /**
- * Determine if {@link #packetConstructor}, {@link #getHandle},
- * {@link #playerConnection} and {@link #sendPacket} are initialized
- *
- * @return Whether these fields are initialized or not
- * @see #initialize()
- */
- public static boolean isInitialized() {
- return initialized;
- }
-
- /**
- * Sends the packet to a single player and caches it
- *
- * @param center Center location of the effect
- * @param player Receiver of the packet
- * @throws PacketInstantiationException if instantion fails due to an
- * unknown error
- * @throws PacketSendingException if sending fails due to an unknown
- * error
- */
- public void sendTo(final Location center, final Player player) throws PacketInstantiationException, PacketSendingException {
- if (this.packet == null) {
- try {
- this.packet = packetConstructor.newInstance();
- Object id;
- if (version < 8) {
- id = this.effect.getName();
- if (this.data != null) {
- id += this.data.getPacketDataString();
- }
- } else {
- id = enumParticle.getEnumConstants()[this.effect.getId()];
- }
- ReflectionHandler.setValue(this.packet, true, "a", id);
- ReflectionHandler.setValue(this.packet, true, "b", (float) center.getX());
- ReflectionHandler.setValue(this.packet, true, "c", (float) center.getY());
- ReflectionHandler.setValue(this.packet, true, "d", (float) center.getZ());
- ReflectionHandler.setValue(this.packet, true, "e", this.offsetX);
- ReflectionHandler.setValue(this.packet, true, "f", this.offsetY);
- ReflectionHandler.setValue(this.packet, true, "g", this.offsetZ);
- ReflectionHandler.setValue(this.packet, true, "h", this.speed);
- ReflectionHandler.setValue(this.packet, true, "i", this.amount);
- if (version > 7) {
- ReflectionHandler.setValue(this.packet, true, "j", this.longDistance);
- ReflectionHandler.setValue(this.packet, true, "k", this.data == null ? new int[0] : this.data.getPacketData());
- }
- }
- catch (final Exception exception) {
- throw new PacketInstantiationException("Packet instantiation failed", exception);
- }
- }
- try {
- sendPacket.invoke(playerConnection.get(getHandle.invoke(player)), this.packet);
- }
- catch (final Exception exception) {
- throw new PacketSendingException("Failed to send the packet to player '" + player.getName() + "'", exception);
- }
- }
-
- /**
- * Sends the packet to all players in the list
- *
- * @param center Center location of the effect
- * @param players Receivers of the packet
- * @throws IllegalArgumentException If the player list is empty
- * @see #sendTo(Location center, Player player)
- */
- public void sendTo(final Location center, final List players) throws IllegalArgumentException {
- if (players.isEmpty()) {
- throw new IllegalArgumentException("The player list is empty");
- }
- for (final Player player : players) {
- this.sendTo(center, player);
- }
- }
-
- /**
- * Sends the packet to all players in a certain range
- *
- * @param center Center location of the effect
- * @param range Range in which players will receive the packet (Maximum
- * range for particles is usually 16, but it can differ for
- * some types)
- * @throws IllegalArgumentException If the range is lower than 1
- * @see #sendTo(Location center, Player player)
- */
- public void sendTo(final Location center, final double range) throws IllegalArgumentException {
- if (range < 1) {
- throw new IllegalArgumentException("The range is lower than 1");
- }
-
- final double squared = range * range;
- for (final Player player : Bukkit.getOnlinePlayers()) {
- if (player.getWorld() != center.getWorld() || player.getLocation().distanceSquared(center) > squared) {
- continue;
- }
- this.sendTo(center, player);
- }
- }
-
- /**
- * Represents a runtime exception that is thrown if a bukkit version is
- * not compatible with this library
- *
- * This class is part of the ParticleEffect Library and follows
- * the same usage conditions
- *
- * @author DarkBlade12
- * @since 1.5
- */
- private static final class VersionIncompatibleException extends RuntimeException {
- private static final long serialVersionUID = 3203085387160737484L;
-
- /**
- * Construct a new version incompatible exception
- *
- * @param message Message that will be logged
- * @param cause Cause of the exception
- */
- public VersionIncompatibleException(final String message, final Throwable cause) {
- super(message, cause);
- }
- }
-
- /**
- * Represents a runtime exception that is thrown if packet instantiation
- * fails
- *
- * This class is part of the ParticleEffect Library and follows
- * the same usage conditions
- *
- * @author DarkBlade12
- * @since 1.4
- */
- private static final class PacketInstantiationException extends RuntimeException {
- private static final long serialVersionUID = 3203085387160737484L;
-
- /**
- * Construct a new packet instantiation exception
- *
- * @param message Message that will be logged
- * @param cause Cause of the exception
- */
- public PacketInstantiationException(final String message, final Throwable cause) {
- super(message, cause);
- }
- }
-
- /**
- * Represents a runtime exception that is thrown if packet sending fails
- *
- * This class is part of the ParticleEffect Library and follows
- * the same usage conditions
- *
- * @author DarkBlade12
- * @since 1.4
- */
- private static final class PacketSendingException extends RuntimeException {
- private static final long serialVersionUID = 3203085387160737484L;
-
- /**
- * Construct a new packet sending exception
- *
- * @param message Message that will be logged
- * @param cause Cause of the exception
- */
- public PacketSendingException(final String message, final Throwable cause) {
- super(message, cause);
- }
+ public void display(Location loc, int amount, double offsetX, double offsetY, double offsetZ, double extra, Object data) {
+ if (dataClass.isAssignableFrom(Void.class) || data == null || !dataClass.isAssignableFrom(data.getClass())) {
+ display(loc, amount, offsetX, offsetY, offsetZ, extra);
+ } else {
+ loc.getWorld().spawnParticle(particle, loc, amount, offsetX, offsetY, offsetZ, extra, data, true);
}
}
}
diff --git a/src/com/projectkorra/projectkorra/util/PassiveHandler.java b/src/com/projectkorra/projectkorra/util/PassiveHandler.java
index 443308a6..636ec584 100644
--- a/src/com/projectkorra/projectkorra/util/PassiveHandler.java
+++ b/src/com/projectkorra/projectkorra/util/PassiveHandler.java
@@ -34,7 +34,10 @@ public class PassiveHandler {
}
public static void checkExhaustionPassives(final Player player) {
- if (!CoreAbility.getAbility(AirSaturation.class).isEnabled() && !CoreAbility.getAbility(ChiSaturation.class).isEnabled()) {
+ CoreAbility airsat = CoreAbility.getAbility(AirSaturation.class);
+ CoreAbility chisat = CoreAbility.getAbility(ChiSaturation.class);
+
+ if ((airsat == null || !airsat.isEnabled()) && (chisat == null || !chisat.isEnabled())) {
return;
}
@@ -55,11 +58,11 @@ public class PassiveHandler {
return;
}
- if (!PassiveManager.hasPassive(player, CoreAbility.getAbility(AirSaturation.class))) {
+ if (!PassiveManager.hasPassive(player, airsat)) {
air = 0;
}
- if (!PassiveManager.hasPassive(player, CoreAbility.getAbility(ChiSaturation.class))) {
+ if (!PassiveManager.hasPassive(player, chisat)) {
chi = 0;
}
diff --git a/src/com/projectkorra/projectkorra/util/ReflectionHandler.java b/src/com/projectkorra/projectkorra/util/ReflectionHandler.java
index 04f7d261..d83c87a9 100644
--- a/src/com/projectkorra/projectkorra/util/ReflectionHandler.java
+++ b/src/com/projectkorra/projectkorra/util/ReflectionHandler.java
@@ -30,8 +30,7 @@ import org.bukkit.Bukkit;
*/
public final class ReflectionHandler {
// Prevent accidental construction.
- private ReflectionHandler() {
- }
+ private ReflectionHandler() {}
/**
* Returns the constructor of a given class with the given parameter types
diff --git a/src/com/projectkorra/projectkorra/util/RevertChecker.java b/src/com/projectkorra/projectkorra/util/RevertChecker.java
index d238272d..df122483 100644
--- a/src/com/projectkorra/projectkorra/util/RevertChecker.java
+++ b/src/com/projectkorra/projectkorra/util/RevertChecker.java
@@ -1,13 +1,13 @@
package com.projectkorra.projectkorra.util;
-import java.util.ArrayList;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.Map;
+import java.util.Set;
import java.util.concurrent.Callable;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Future;
-import org.bukkit.Chunk;
import org.bukkit.Server;
import org.bukkit.block.Block;
import org.bukkit.configuration.file.FileConfiguration;
@@ -17,6 +17,8 @@ import com.projectkorra.projectkorra.ProjectKorra;
import com.projectkorra.projectkorra.ability.EarthAbility;
import com.projectkorra.projectkorra.configuration.ConfigManager;
+import io.papermc.lib.PaperLib;
+
public class RevertChecker implements Runnable {
private final ProjectKorra plugin;
@@ -34,19 +36,19 @@ public class RevertChecker implements Runnable {
public static void revertAirBlocks() {
for (final int ID : airRevertQueue.keySet()) {
- EarthAbility.revertAirBlock(ID);
+ PaperLib.getChunkAtAsync(EarthAbility.getTempAirLocations().get(ID).getState().getBlock().getLocation()).thenAccept(result -> EarthAbility.revertAirBlock(ID));
RevertChecker.airRevertQueue.remove(ID);
}
}
public static void revertEarthBlocks() {
for (final Block block : earthRevertQueue.keySet()) {
- EarthAbility.revertBlock(block);
+ PaperLib.getChunkAtAsync(block.getLocation()).thenAccept(result -> EarthAbility.revertBlock(block));
earthRevertQueue.remove(block);
}
}
- private Future> returnFuture;
+ private Future>> returnFuture;
private void addToAirRevertQueue(final int i) {
if (!airRevertQueue.containsKey(i)) {
@@ -72,50 +74,51 @@ public class RevertChecker implements Runnable {
try {
this.returnFuture = this.plugin.getServer().getScheduler().callSyncMethod(this.plugin, new getOccupiedChunks(this.plugin.getServer()));
- final ArrayList chunks = this.returnFuture.get();
+ final Set