mirror of
https://github.com/DieReicheErethons/Brewery.git
synced 2025-01-24 21:31:22 +01:00
Show drunkeness as ActionBar graphic
This commit is contained in:
parent
39e2e922bf
commit
ec624ab3c7
@ -103,3 +103,5 @@ Player_WakeNoPoints: '&cEs wurden noch keine Aufwachpunkte erstellt!'
|
||||
Player_WakeNotExist: '&cDer Aufwachpunkt mit der id: &6&v1 &cexistiert nicht!'
|
||||
Player_WakeTeleport: 'Teleport zu Aufwachpunkt mit der id: &6&v1&f An Position: &6&v2 &v3, &v4, &v5'
|
||||
Player_ShopSealBrew: '&eBrewery Tränke sollten vor dem verkaufen versiegelt werden'
|
||||
Player_Drunkeness: 'Betrunkenheit'
|
||||
Player_Hangover: 'Dein Kater'
|
||||
|
@ -103,3 +103,5 @@ Player_WakeNoPoints: '&cThere are no Wakeup Points!'
|
||||
Player_WakeNotExist: '&cThe Wakeup Point with the id: &6&v1 &cdoesn''t exist!'
|
||||
Player_WakeTeleport: 'Teleport to Wakeup Point with the id: &6&v1&f At position: &6&v2 &v3, &v4, &v5'
|
||||
Player_ShopSealBrew: '&eBrews should be sealed before selling them'
|
||||
Player_Drunkeness: 'Drunkeness'
|
||||
Player_Hangover: 'Your Hangover'
|
||||
|
@ -104,3 +104,5 @@ Player_WakeNoPoints: '&c¡No hay puntos de activación!'
|
||||
Player_WakeNotExist: '&cEl Punto de Despertar con el id: &6&v1 &c¡No existe!'
|
||||
Player_WakeTeleport: 'Teletransporte al punto de activación con la identificación: &6&v1&f En la posición: &6&v2 &v3, &v4, &v5'
|
||||
Player_ShopSealBrew: '&eLas cervezas deben sellarse antes de venderlas.'
|
||||
Player_Drunkeness: 'Ebriedad'
|
||||
Player_Hangover: 'Tu resaca'
|
||||
|
@ -103,3 +103,5 @@ Player_WakeNoPoints: '&cIl n´y a pas de point de réveil !'
|
||||
Player_WakeNotExist: '&cLe point de réveil avec l´ID: &6&v1 &cdn´existe pas !'
|
||||
Player_WakeTeleport: 'Téléportation vers le point de réveil avec l´ID : &6&v1&f A la position: &6&v2 &v3, &v4, &v5'
|
||||
Player_ShopSealBrew: '&eles boissons doivent être scellées avant d´être vendues'
|
||||
Player_Drunkeness: 'Ivresse'
|
||||
Player_Hangover: 'Gueule de bois'
|
||||
|
@ -103,3 +103,5 @@ Player_WakeNoPoints: '&cNon ci sono punti di risveglio!'
|
||||
Player_WakeNotExist: '&cIl punto di risveglio con id &6&v1 &cnon esiste!'
|
||||
Player_WakeTeleport: 'Teletrasportato al punto di risveglio di id &6&v1&f alla posizione &6&v2 &v3, &v4, &v5'
|
||||
Player_ShopSealBrew: '&eBrews should be sealed before selling them'
|
||||
Player_Drunkeness: 'Ubriacatura'
|
||||
Player_Hangover: 'Hangover'
|
||||
|
@ -103,3 +103,5 @@ Player_WakeNoPoints: '&cЗдесь нет Точки Пробуждения!'
|
||||
Player_WakeNotExist: '&cТочка Пробуждения под номером: &6&v1 &cне существует!'
|
||||
Player_WakeTeleport: 'Телепорт на Точку Пробуждения под номером: &6&v1&f по координатам: &6&v2 &v3, &v4, &v5'
|
||||
Player_ShopSealBrew: '&eБражка должна быть запечатана перед продажей'
|
||||
Player_Drunkeness: 'Пьянство'
|
||||
Player_Hangover: 'Твое похмелье'
|
||||
|
@ -103,3 +103,5 @@ Player_WakeNoPoints: '&c沒有喚醒點!'
|
||||
Player_WakeNotExist: '&c這個喚醒點 id: &6&v1 &c不存在!'
|
||||
Player_WakeTeleport: '傳送到這個喚醒點 id: &6&v1&f 在位置: &6&v2 &v3, &v4, &v5'
|
||||
Player_ShopSealBrew: '&eBrews should be sealed before selling them'
|
||||
Player_Drunkeness: '醉酒'
|
||||
Player_Hangover: '你的宿醉'
|
||||
|
@ -103,3 +103,5 @@ Player_WakeNoPoints: '&c目前没有设定任何一个苏醒处!'
|
||||
Player_WakeNotExist: '&cid为: &6&v1 &c的苏醒处并不存在!'
|
||||
Player_WakeTeleport: '前往id为: &6&v1 &f坐标为: &6&v2 &v3, &v4, &v5 &r的苏醒处.'
|
||||
Player_ShopSealBrew: '&eBrews should be sealed before selling them'
|
||||
Player_Drunkeness: '醉酒'
|
||||
Player_Hangover: '你的宿醉'
|
||||
|
@ -5,8 +5,11 @@ import com.dre.brewery.api.events.PlayerPukeEvent;
|
||||
import com.dre.brewery.api.events.PlayerPushEvent;
|
||||
import com.dre.brewery.api.events.brew.BrewDrinkEvent;
|
||||
import com.dre.brewery.filedata.BConfig;
|
||||
import com.dre.brewery.lore.BrewLore;
|
||||
import com.dre.brewery.recipe.BEffect;
|
||||
import com.dre.brewery.utility.BUtil;
|
||||
import net.md_5.bungee.api.ChatMessageType;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import org.apache.commons.lang.mutable.MutableInt;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
@ -197,10 +200,117 @@ public class BPlayer {
|
||||
bPlayer.drinkCap(player);
|
||||
}
|
||||
bPlayer.syncToSQL(false);
|
||||
//player.sendMessage("Betrunkenheit: §8[§7⭑⭑⭑⭒§0⭑§8] §8[§6|||||||||||||||||§0|||||||||§8]");
|
||||
bPlayer.showDrunkeness(player);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the Player his current drunkeness and quality as an Actionbar graphic or when unsupported, in chat
|
||||
*/
|
||||
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);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
public int sendDrunkenessMessage(Player player, int cacheHangover) {
|
||||
StringBuilder b = new StringBuilder(100);
|
||||
|
||||
int strength = drunkeness;
|
||||
boolean hangover = false;
|
||||
int hangoverStrength = cacheHangover > 0 ? cacheHangover : offlineDrunk;
|
||||
if (hangoverStrength > 0) {
|
||||
strength = hangoverStrength;
|
||||
hangover = true;
|
||||
} else {
|
||||
hangoverStrength = 0;
|
||||
}
|
||||
|
||||
b.append(P.p.languageReader.get(hangover ? "Player_Hangover" : "Player_Drunkeness"));
|
||||
|
||||
// Drunkeness or Hangover Strength Bars
|
||||
b.append(": §7[");
|
||||
// Show 25 Bars, color one per 4 drunkeness
|
||||
int bars;
|
||||
if (strength <= 0) {
|
||||
bars = 0;
|
||||
} else if (strength == 1) {
|
||||
bars = 1;
|
||||
} else {
|
||||
bars = Math.round(strength / 4.0f);
|
||||
}
|
||||
int noBars = 25 - bars;
|
||||
if (bars > 0) {
|
||||
b.append(hangover ? "§c" : "§6");
|
||||
}
|
||||
for (int addedBars = 0; addedBars < bars; addedBars++) {
|
||||
b.append("|");
|
||||
if (addedBars == 20) {
|
||||
// color the last 4 bars red
|
||||
b.append("§c");
|
||||
}
|
||||
}
|
||||
if (noBars > 0) {
|
||||
b.append("§0");
|
||||
for (; noBars > 0; noBars--) {
|
||||
b.append("|");
|
||||
}
|
||||
}
|
||||
b.append("§7] ");
|
||||
|
||||
|
||||
int quality;
|
||||
if (hangover) {
|
||||
quality = 11 - getHangoverQuality();
|
||||
} else {
|
||||
quality = strength > 0 ? getQuality() : 0;
|
||||
}
|
||||
|
||||
// Quality Stars
|
||||
int stars = quality / 2;
|
||||
boolean half = quality % 2 > 0;
|
||||
int noStars = 5 - stars - (half ? 1 : 0);
|
||||
|
||||
b.append("§7[").append(BrewLore.getQualityColor(quality));
|
||||
for (; stars > 0; stars--) {
|
||||
b.append("⭑");
|
||||
}
|
||||
if (half) {
|
||||
b.append("⭒");
|
||||
}
|
||||
if (noStars > 0) {
|
||||
b.append("§0");
|
||||
for (; noStars > 0; noStars--) {
|
||||
b.append("⭑");
|
||||
}
|
||||
}
|
||||
b.append("§7]");
|
||||
String text = b.toString();
|
||||
try {
|
||||
player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(text));
|
||||
return hangoverStrength;
|
||||
} catch (UnsupportedOperationException | NoSuchMethodError e) {
|
||||
player.sendMessage(text);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
// Player has drunken too much
|
||||
public void drinkCap(Player player) {
|
||||
quality = getQuality() * 100;
|
||||
@ -246,6 +356,9 @@ public class BPlayer {
|
||||
if (offlineDrunk == 0) {
|
||||
return true;
|
||||
}
|
||||
if (drunkeness == 0) {
|
||||
drunkeness--;
|
||||
}
|
||||
quality = getQuality();
|
||||
if (drunkeness <= -offlineDrunk) {
|
||||
syncToSQL(true);
|
||||
@ -362,6 +475,7 @@ public class BPlayer {
|
||||
}
|
||||
if (offlineDrunk > 20) {
|
||||
hangoverEffects(player);
|
||||
showDrunkeness(player);
|
||||
}
|
||||
if (drunkeness <= 0) {
|
||||
// wird der spieler noch gebraucht?
|
||||
|
@ -331,6 +331,7 @@ public class CommandListener implements CommandExecutor {
|
||||
bPlayer.remove();
|
||||
} else {
|
||||
bPlayer.setData(drunkeness, quality);
|
||||
bPlayer.showDrunkeness(player);
|
||||
}
|
||||
|
||||
if (drunkeness > 100) {
|
||||
@ -348,7 +349,8 @@ public class CommandListener implements CommandExecutor {
|
||||
|
||||
public void cmdInfo(CommandSender sender, String playerName) {
|
||||
|
||||
if (playerName == null) {
|
||||
boolean selfInfo = playerName == null;
|
||||
if (selfInfo) {
|
||||
if (sender instanceof Player) {
|
||||
Player player = (Player) sender;
|
||||
playerName = player.getName();
|
||||
@ -368,7 +370,11 @@ public class CommandListener implements CommandExecutor {
|
||||
if (bPlayer == null) {
|
||||
p.msg(sender, p.languageReader.get("CMD_Info_NotDrunk", playerName));
|
||||
} else {
|
||||
p.msg(sender, p.languageReader.get("CMD_Info_Drunk", playerName, "" + bPlayer.getDrunkeness(), "" + bPlayer.getQuality()));
|
||||
if (selfInfo) {
|
||||
bPlayer.showDrunkeness(player);
|
||||
} else {
|
||||
p.msg(sender, p.languageReader.get("CMD_Info_Drunk", playerName, "" + bPlayer.getDrunkeness(), "" + bPlayer.getQuality()));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -167,6 +167,7 @@ public class PlayerListener implements Listener {
|
||||
BPlayer bplayer = BPlayer.get(player);
|
||||
if (bplayer != null) {
|
||||
bplayer.drainByItem(player, item.getType());
|
||||
bplayer.showDrunkeness(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user