Send Hangover Bar as Title instead

This commit is contained in:
Sn0wStorm 2020-11-11 17:34:15 +01:00
parent 823f5a4204
commit fae2d15804
2 changed files with 19 additions and 23 deletions

View File

@ -7,11 +7,7 @@ import com.dre.brewery.recipe.RecipeItem;
import com.dre.brewery.utility.BUtil; import com.dre.brewery.utility.BUtil;
import com.dre.brewery.utility.LegacyUtil; import com.dre.brewery.utility.LegacyUtil;
import com.dre.brewery.utility.Tuple; import com.dre.brewery.utility.Tuple;
import org.bukkit.Color; import org.bukkit.*;
import org.bukkit.Effect;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Particle;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.BlockFace; import org.bukkit.block.BlockFace;
import org.bukkit.block.data.BlockData; import org.bukkit.block.data.BlockData;
@ -212,6 +208,9 @@ public class BCauldron {
changed = true; 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 // Bukkit Bug, inventory not updating while in event so this
// will delay the give // will delay the give
// but could also just use deprecated updateInventory() // but could also just use deprecated updateInventory()

View File

@ -211,13 +211,10 @@ public class BPlayer {
*/ */
public void showDrunkeness(Player player) { public void showDrunkeness(Player player) {
try { try {
final int cacheHangover = sendDrunkenessMessage(player, 0); // It this returns false, then the Action Bar is not supported. Do not repeat the message as it was sent into chat
// It this returns -1, then the Action Bar is not supported. Do not repeat the message as it was sent into chat if (sendDrunkenessMessage(player)) {
if (cacheHangover >= 0) { P.p.getServer().getScheduler().scheduleSyncDelayedTask(P.p, () -> sendDrunkenessMessage(player), 40);
// We need to cache the hangover, as this value is removed from them player on login. P.p.getServer().getScheduler().scheduleSyncDelayedTask(P.p, () -> sendDrunkenessMessage(player), 80);
// 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);
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
@ -228,20 +225,16 @@ public class BPlayer {
* Send one Message to the player, showing his drunkeness or hangover * Send one Message to the player, showing his drunkeness or hangover
* *
* @param player The Player to send the message to * @param player The Player to send the message to
* @param cacheHangover if > 0 Show him a cached hangover strength * @return false if the message should not be repeated.
* @return -1 if the message should not be repeated. if not 0, it is the hangover we should cache
*/ */
public int sendDrunkenessMessage(Player player, int cacheHangover) { public boolean sendDrunkenessMessage(Player player) {
StringBuilder b = new StringBuilder(100); StringBuilder b = new StringBuilder(100);
int strength = drunkeness; int strength = drunkeness;
boolean hangover = false; boolean hangover = false;
int hangoverStrength = cacheHangover > 0 ? cacheHangover : offlineDrunk; if (offlineDrunk > 0) {
if (hangoverStrength > 0) { strength = offlineDrunk;
strength = hangoverStrength;
hangover = true; hangover = true;
} else {
hangoverStrength = 0;
} }
b.append(P.p.languageReader.get(hangover ? "Player_Hangover" : "Player_Drunkeness")); b.append(P.p.languageReader.get(hangover ? "Player_Hangover" : "Player_Drunkeness"));
@ -303,13 +296,17 @@ public class BPlayer {
} }
} }
b.append("§7]"); 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 { try {
player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(text)); player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(text));
return hangoverStrength; return true;
} catch (UnsupportedOperationException | NoSuchMethodError e) { } catch (UnsupportedOperationException | NoSuchMethodError e) {
player.sendMessage(text); player.sendMessage(text);
return -1; return false;
} }
} }