2727import com .dre .brewery .api .events .barrel .BarrelDestroyEvent ;
2828import com .dre .brewery .configuration .ConfigManager ;
2929import com .dre .brewery .configuration .files .Lang ;
30- import com .github .Anon8281 .universalScheduler .scheduling .schedulers .TaskScheduler ;
3130import org .bukkit .Bukkit ;
3231import org .bukkit .ChatColor ;
3332import org .bukkit .Color ;
5958import java .util .concurrent .ThreadLocalRandom ;
6059import java .util .regex .Matcher ;
6160import java .util .regex .Pattern ;
62- import java .util .stream .Stream ;
6361import java .util .stream .IntStream ;
62+ import java .util .stream .Stream ;
6463
6564public final class BUtil {
6665
@@ -186,25 +185,26 @@ public static Player getPlayerfromString(String nameOrUUID) {
186185 * @param onlyIfStronger Optionally only overwrite if the new one is stronger, i.e. has higher level or longer duration
187186 */
188187 public static void reapplyPotionEffect (Player player , PotionEffect effect , boolean onlyIfStronger ) {
189- final PotionEffectType type = effect .getType ();
190- if (player .hasPotionEffect (type )) {
191- PotionEffect plEffect ;
192- if (VERSION .isOrLater (MinecraftVersion .V1_11 )) {
193- plEffect = player .getPotionEffect (type );
194- } else {
195- plEffect = player .getActivePotionEffects ().stream ().filter (e -> e .getType ().equals (type )).findAny ().get ();
196- }
188+ BreweryPlugin .getScheduler ().execute (player , () -> {
189+ final PotionEffectType type = effect .getType ();
190+ if (player .hasPotionEffect (type )) {
191+ PotionEffect plEffect ;
192+ if (VERSION .isOrLater (MinecraftVersion .V1_11 )) {
193+ plEffect = player .getPotionEffect (type );
194+ } else {
195+ plEffect = player .getActivePotionEffects ().stream ().filter (e -> e .getType ().equals (type )).findAny ().get ();
196+ }
197197
198- if (!onlyIfStronger ||
199- plEffect .getAmplifier () < effect .getAmplifier () ||
200- (plEffect .getAmplifier () == effect .getAmplifier () && plEffect .getDuration () < effect .getDuration ())) {
201- player .removePotionEffect (type );
202- } else {
203- return ;
198+ if (!onlyIfStronger ||
199+ plEffect .getAmplifier () < effect .getAmplifier () ||
200+ (plEffect .getAmplifier () == effect .getAmplifier () && plEffect .getDuration () < effect .getDuration ())) {
201+ player .removePotionEffect (type );
202+ } else {
203+ return ;
204+ }
204205 }
205- }
206-
207- BreweryPlugin .getScheduler ().execute (player , () -> effect .apply (player ));
206+ effect .apply (player );
207+ });
208208 }
209209
210210 /**
@@ -282,6 +282,7 @@ public static int indexOfStart(List<String> list, String lineStart) {
282282
283283 /**
284284 * Escapes any backslashes or double quotes, and surrounds the string in double quotes if it contains spaces.
285+ *
285286 * @param input The input string
286287 * @return The quoted string
287288 */
@@ -297,16 +298,19 @@ public static String quote(String input) {
297298 * Splits a string by spaces, unless enclosed in double quotes.
298299 * Uses backslash as escape character for quotes and other backslashes.
299300 * Multiple spaces will be treated as one space.
301+ *
300302 * @param input The input string
301303 * @return List of strings in the input, quoted strings will have their start and end quotes removed
302304 */
303305 public static List <String > splitStringKeepingQuotes (String input ) {
304306 return splitStringKeepingQuotesVerbose (input ).strings ;
305307 }
308+
306309 /**
307310 * Splits a string by spaces, unless enclosed in double quotes.
308311 * Uses backslash as escape character for quotes and other backslashes.
309312 * Multiple spaces will be treated as one space.
313+ *
310314 * @param input The input string
311315 * @return List of strings in the input, quoted strings will have their start and end quotes removed
312316 */
@@ -341,7 +345,8 @@ public static SplitResult splitStringKeepingQuotesVerbose(String input) {
341345 return new SplitResult (result , inQuotes );
342346 }
343347
344- public record SplitResult (List <String > strings , boolean inQuotes ) {}
348+ public record SplitResult (List <String > strings , boolean inQuotes ) {
349+ }
345350
346351 /**
347352 * Replaces the Placeholders %player_name% and %quality% in the given input string
@@ -570,9 +575,10 @@ public static int getRandomIntInRange(String string) {
570575
571576 /**
572577 * Chooses a random element from a list.
578+ *
573579 * @param list the list to choose from
580+ * @param <T> type of element in list
574581 * @return a random element, or null if the list is empty
575- * @param <T> type of element in list
576582 */
577583 public static <T > @ Nullable T choose (List <T > list ) {
578584 if (list .isEmpty ()) {
@@ -584,7 +590,8 @@ public static int getRandomIntInRange(String string) {
584590 /**
585591 * Finds the minimum element in a collection.
586592 * If multiple elements have the same minimum value, they will all be returned.
587- * @param <T> the type of elements in the collection
593+ *
594+ * @param <T> the type of elements in the collection
588595 * @param collection the collection to search for minimum elements
589596 * @return a list of all minimum elements in the collection, will be empty if the collection is empty
590597 */
@@ -611,6 +618,7 @@ public static <T extends Comparable<T>> List<T> multiMin(Collection<T> collectio
611618
612619 /**
613620 * Determines if two floats are close enough to be considered "equal" (difference < 1e-6)
621+ *
614622 * @param a first float
615623 * @param b second float
616624 * @return true if the floats are close
@@ -641,6 +649,7 @@ public static OptionalInt parseInt(@Nullable String string) {
641649
642650 /**
643651 * Parses a non-infinite, non-NaN floating-point double.
652+ *
644653 * @param string the input string
645654 * @return the optional
646655 */
@@ -661,6 +670,7 @@ public static OptionalDouble parseDouble(@Nullable String string) {
661670
662671 /**
663672 * Parses a non-infinite, non-NaN floating-point float.
673+ *
664674 * @param string the input string
665675 * @return the optional
666676 */
0 commit comments