Expand ParticleBuilder more with hasReceivers, fix empty receivers list

This commit is contained in:
Aikar 2018-06-06 21:27:50 -04:00
parent 11cb276a4a
commit fd4a65c566
No known key found for this signature in database
GPG Key ID: 401ADFC9891FAAFE

View File

@ -1,4 +1,4 @@
From 50ea02411e05bfeafc16c29acb4c95087b9082a1 Mon Sep 17 00:00:00 2001
From 4d48c8f3cf54c6845922fb62b32adcab7d1558dd Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
Date: Tue, 29 Aug 2017 23:58:48 -0400
Subject: [PATCH] Expand World.spawnParticle API and add Builder
@ -10,10 +10,10 @@ This adds a new Builder API which is much friendlier to use.
diff --git a/src/main/java/com/destroystokyo/paper/ParticleBuilder.java b/src/main/java/com/destroystokyo/paper/ParticleBuilder.java
new file mode 100644
index 00000000..a3d8caae
index 00000000..ef07ab3c
--- /dev/null
+++ b/src/main/java/com/destroystokyo/paper/ParticleBuilder.java
@@ -0,0 +1,349 @@
@@ -0,0 +1,363 @@
+package com.destroystokyo.paper;
+
+import com.google.common.collect.Lists;
@ -87,6 +87,19 @@ index 00000000..a3d8caae
+ }
+
+ /**
+ * Example use:
+ *
+ * builder.receivers(16);
+ * if (builder.hasReceivers()) {
+ * sendParticleAsync(builder);
+ * }
+ * @return If this particle is going to be sent to someone
+ */
+ public boolean hasReceivers() {
+ return receivers == null || !receivers.isEmpty();
+ }
+
+ /**
+ * Sends this particle to all players in the world
+ */
+ public ParticleBuilder allPlayers() {
@ -95,16 +108,17 @@ index 00000000..a3d8caae
+ }
+
+ /**
+ * @param receivers List of players to receive this particle, or null
+ * @param receivers List of players to receive this particle, or null for all players in the world
+ */
+ public ParticleBuilder receivers(@Nullable List<Player> receivers) {
+ // Had to keep this as we first made API List<> and not Collection, but removing this may break plugins compiled on older jars
+ // TODO: deprecate?
+ return receivers((Collection<Player>) receivers);
+ this.receivers = receivers != null ? Lists.newArrayList(receivers) : null;
+ return this;
+ }
+
+ /**
+ * @param receivers List of players to receive this particle, or null
+ * @param receivers List of players to receive this particle, or null for all players in the world
+ */
+ public ParticleBuilder receivers(@Nullable Collection<Player> receivers) {
+ this.receivers = receivers != null ? Lists.newArrayList(receivers) : null;
@ -112,10 +126,10 @@ index 00000000..a3d8caae
+ }
+
+ /**
+ * @param receivers List of players to be receive this particle, or null
+ * @param receivers List of players to be receive this particle, or null for all players in the world
+ */
+ public ParticleBuilder receivers(Player... receivers) {
+ this.receivers = receivers != null && receivers.length > 0 ? Lists.newArrayList(receivers) : null;
+ this.receivers = receivers != null ? Lists.newArrayList(receivers) : null;
+ return this;
+ }
+