From fae2d1580447e789ca4497d05caa0722e76bba4a Mon Sep 17 00:00:00 2001 From: Sn0wStorm Date: Wed, 11 Nov 2020 17:34:15 +0100 Subject: [PATCH] Send Hangover Bar as Title instead --- src/com/dre/brewery/BCauldron.java | 9 ++++---- src/com/dre/brewery/BPlayer.java | 33 ++++++++++++++---------------- 2 files changed, 19 insertions(+), 23 deletions(-) diff --git a/src/com/dre/brewery/BCauldron.java b/src/com/dre/brewery/BCauldron.java index bde3941..7a831fa 100644 --- a/src/com/dre/brewery/BCauldron.java +++ b/src/com/dre/brewery/BCauldron.java @@ -7,11 +7,7 @@ import com.dre.brewery.recipe.RecipeItem; import com.dre.brewery.utility.BUtil; import com.dre.brewery.utility.LegacyUtil; import com.dre.brewery.utility.Tuple; -import org.bukkit.Color; -import org.bukkit.Effect; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.Particle; +import org.bukkit.*; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.block.data.BlockData; @@ -212,6 +208,9 @@ public class BCauldron { changed = true; } } + if (P.use1_9) { + block.getWorld().playSound(block.getLocation(), Sound.ITEM_BOTTLE_FILL, 1f, 1f); + } // Bukkit Bug, inventory not updating while in event so this // will delay the give // but could also just use deprecated updateInventory() diff --git a/src/com/dre/brewery/BPlayer.java b/src/com/dre/brewery/BPlayer.java index fb18da3..6a07785 100644 --- a/src/com/dre/brewery/BPlayer.java +++ b/src/com/dre/brewery/BPlayer.java @@ -211,13 +211,10 @@ public class BPlayer { */ public void showDrunkeness(Player player) { try { - final int cacheHangover = sendDrunkenessMessage(player, 0); - // It this returns -1, then the Action Bar is not supported. Do not repeat the message as it was sent into chat - if (cacheHangover >= 0) { - // We need to cache the hangover, as this value is removed from them player on login. - // When we display the message again, use the cached hangover value - P.p.getServer().getScheduler().scheduleSyncDelayedTask(P.p, () -> sendDrunkenessMessage(player, cacheHangover), 40); - P.p.getServer().getScheduler().scheduleSyncDelayedTask(P.p, () -> sendDrunkenessMessage(player, cacheHangover), 80); + // It this returns false, then the Action Bar is not supported. Do not repeat the message as it was sent into chat + if (sendDrunkenessMessage(player)) { + P.p.getServer().getScheduler().scheduleSyncDelayedTask(P.p, () -> sendDrunkenessMessage(player), 40); + P.p.getServer().getScheduler().scheduleSyncDelayedTask(P.p, () -> sendDrunkenessMessage(player), 80); } } catch (Exception e) { e.printStackTrace(); @@ -228,20 +225,16 @@ public class BPlayer { * Send one Message to the player, showing his drunkeness or hangover * * @param player The Player to send the message to - * @param cacheHangover if > 0 Show him a cached hangover strength - * @return -1 if the message should not be repeated. if not 0, it is the hangover we should cache + * @return false if the message should not be repeated. */ - public int sendDrunkenessMessage(Player player, int cacheHangover) { + public boolean sendDrunkenessMessage(Player player) { StringBuilder b = new StringBuilder(100); int strength = drunkeness; boolean hangover = false; - int hangoverStrength = cacheHangover > 0 ? cacheHangover : offlineDrunk; - if (hangoverStrength > 0) { - strength = hangoverStrength; + if (offlineDrunk > 0) { + strength = offlineDrunk; hangover = true; - } else { - hangoverStrength = 0; } b.append(P.p.languageReader.get(hangover ? "Player_Hangover" : "Player_Drunkeness")); @@ -303,13 +296,17 @@ public class BPlayer { } } b.append("ยง7]"); - String text = b.toString(); + final String text = b.toString(); + if (hangover) { + P.p.getServer().getScheduler().scheduleSyncDelayedTask(P.p, () -> player.sendTitle("", text, 30, 100, 90), 160); + return false; + } try { player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(text)); - return hangoverStrength; + return true; } catch (UnsupportedOperationException | NoSuchMethodError e) { player.sendMessage(text); - return -1; + return false; } }