|
@@ -1,149 +1,139 @@
|
|
|
package com.gmail.nossr50.util.experience;
|
|
|
|
|
|
import com.gmail.nossr50.config.experience.ExperienceConfig;
|
|
|
+import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
|
|
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
|
|
|
import com.gmail.nossr50.util.StringUtils;
|
|
|
+import org.bukkit.ChatColor;
|
|
|
+import org.bukkit.Server;
|
|
|
import org.bukkit.boss.*;
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
|
|
|
/**
|
|
|
* A visual representation of a players skill level progress for a PrimarySkillType
|
|
|
*/
|
|
|
-public class ExperienceBar {
|
|
|
+public class ExperienceBarWrapper {
|
|
|
|
|
|
private final PrimarySkillType primarySkillType; //Primary Skill
|
|
|
- protected String experienceBarTitle; //Name Shown Above XP Bar
|
|
|
- protected BarColor barColor; //Color of the XP Bar
|
|
|
- protected BarStyle barStyle;
|
|
|
- protected Player player;
|
|
|
- protected double progress;
|
|
|
- protected boolean isVisible;
|
|
|
-
|
|
|
- public ExperienceBar(PrimarySkillType primarySkillType, Player player)
|
|
|
+ private BossBar bossBar;
|
|
|
+ private final Server server;
|
|
|
+ protected final McMMOPlayer mcMMOPlayer;
|
|
|
+ private int lastLevelUpdated;
|
|
|
+
|
|
|
+ /*
|
|
|
+ * This is stored to help optimize updating the title
|
|
|
+ */
|
|
|
+ protected String niceSkillName;
|
|
|
+ protected String title;
|
|
|
+
|
|
|
+ public ExperienceBarWrapper(PrimarySkillType primarySkillType, McMMOPlayer mcMMOPlayer)
|
|
|
{
|
|
|
- this.player = player;
|
|
|
+ this.mcMMOPlayer = mcMMOPlayer;
|
|
|
+ this.server = mcMMOPlayer.getPlayer().getServer(); //Might not be good for bungee to do this
|
|
|
this.primarySkillType = primarySkillType;
|
|
|
- experienceBarTitle = StringUtils.getCapitalized(primarySkillType.getName());
|
|
|
- barColor = ExperienceConfig.getInstance().getExperienceBarColor(primarySkillType);
|
|
|
- barStyle = BarStyle.SOLID;
|
|
|
- isVisible = false;
|
|
|
- progress = 0.0D;
|
|
|
- }
|
|
|
+ title = "";
|
|
|
+ lastLevelUpdated = 0;
|
|
|
|
|
|
- public String getTitle() {
|
|
|
- return experienceBarTitle;
|
|
|
- }
|
|
|
+ //These vars are stored to help reduce operations involving strings
|
|
|
+ niceSkillName = StringUtils.getCapitalized(primarySkillType.toString());
|
|
|
|
|
|
- public void setTitle(String s) {
|
|
|
- experienceBarTitle = s;
|
|
|
+ //Create the bar
|
|
|
+ initBar();
|
|
|
}
|
|
|
|
|
|
- public BarColor getColor() {
|
|
|
- return barColor;
|
|
|
+ private void initBar()
|
|
|
+ {
|
|
|
+ title = getTitleTemplate();
|
|
|
+ createBossBar();
|
|
|
}
|
|
|
|
|
|
- public void setColor(BarColor barColor) {
|
|
|
- this.barColor = barColor;
|
|
|
+ public void updateTitle() {
|
|
|
+ title = getTitleTemplate();
|
|
|
+ bossBar.setTitle(title);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- public BarStyle getStyle() {
|
|
|
- //TODO: Add config for style
|
|
|
- return barStyle;
|
|
|
+ private String getTitleTemplate() {
|
|
|
+ return niceSkillName + " Lv." + ChatColor.GOLD + getLevel();
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- public void setStyle(BarStyle barStyle) {
|
|
|
- this.barStyle = barStyle;
|
|
|
+ private int getLevel() {
|
|
|
+ return mcMMOPlayer.getSkillLevel(primarySkillType);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- public void removeFlag(BarFlag barFlag) {
|
|
|
- //Do nothing
|
|
|
+ public String getTitle() {
|
|
|
+ return bossBar.getTitle();
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- public void addFlag(BarFlag barFlag) {
|
|
|
- //Do nothing
|
|
|
+ public void setTitle(String s) {
|
|
|
+ bossBar.setTitle(s);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- public boolean hasFlag(BarFlag barFlag) {
|
|
|
- return false;
|
|
|
+ public BarColor getColor() {
|
|
|
+ return bossBar.getColor();
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- public void setProgress(double v) {
|
|
|
- //Clamp progress between 0.00 -> 1.00
|
|
|
-
|
|
|
- if(v < 0)
|
|
|
- progress = 0.0D;
|
|
|
- else if(progress > 1)
|
|
|
- progress = 1.0D;
|
|
|
- else progress = v;
|
|
|
+ public void setColor(BarColor barColor) {
|
|
|
+ bossBar.setColor(barColor);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- public double getProgress() {
|
|
|
- return progress;
|
|
|
+ public BarStyle getStyle() {
|
|
|
+ return bossBar.getStyle();
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- public void addPlayer(Player player) {
|
|
|
- //Do nothing
|
|
|
+ public void setStyle(BarStyle barStyle) {
|
|
|
+ bossBar.setStyle(barStyle);
|
|
|
}
|
|
|
|
|
|
+ public void setProgress(double v) {
|
|
|
+ //Clamp Values
|
|
|
+ if(v < 0)
|
|
|
+ bossBar.setProgress(0.0D);
|
|
|
|
|
|
- public void removePlayer(Player player) {
|
|
|
- //Do nothing
|
|
|
- }
|
|
|
-
|
|
|
+ else if(v > 1)
|
|
|
+ bossBar.setProgress(1.0D);
|
|
|
+ else
|
|
|
+ bossBar.setProgress(v);
|
|
|
|
|
|
- public void removeAll() {
|
|
|
- //Do nothing
|
|
|
+ //Every time progress updates we need to check for a title update
|
|
|
+ if(getLevel() != lastLevelUpdated)
|
|
|
+ {
|
|
|
+ updateTitle();
|
|
|
+ lastLevelUpdated = getLevel();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- public List<Player> getPlayers() {
|
|
|
- List<Player> players = new ArrayList<>();
|
|
|
- players.add(player);
|
|
|
- return players;
|
|
|
+ public double getProgress() {
|
|
|
+ return bossBar.getProgress();
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- public void setVisible(boolean b) {
|
|
|
- isVisible = b;
|
|
|
-
|
|
|
- if(isVisible)
|
|
|
- showExperienceBar();
|
|
|
+ public List<Player> getPlayers() {
|
|
|
+ return bossBar.getPlayers();
|
|
|
}
|
|
|
|
|
|
-
|
|
|
public boolean isVisible() {
|
|
|
- return isVisible;
|
|
|
+ return bossBar.isVisible();
|
|
|
}
|
|
|
|
|
|
- public void showExperienceBar()
|
|
|
+ public void hideExperienceBar()
|
|
|
{
|
|
|
- player.getServer().createBossBar()
|
|
|
+ bossBar.setVisible(false);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * @deprecated
|
|
|
- */
|
|
|
-
|
|
|
- public void show() {
|
|
|
- //Do nothing
|
|
|
+ public void showExperienceBar()
|
|
|
+ {
|
|
|
+ bossBar.setVisible(true);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * @deprecated
|
|
|
- */
|
|
|
+ /*public NamespacedKey getKey()
|
|
|
+ {
|
|
|
+ return bossBar
|
|
|
+ }*/
|
|
|
|
|
|
- public void hide() {
|
|
|
- //Do nothing
|
|
|
+ private void createBossBar()
|
|
|
+ {
|
|
|
+ bossBar = mcMMOPlayer.getPlayer().getServer().createBossBar(title, ExperienceConfig.getInstance().getExperienceBarColor(primarySkillType), ExperienceConfig.getInstance().getExperienceBarStyle(primarySkillType));
|
|
|
+ bossBar.addPlayer(mcMMOPlayer.getPlayer());
|
|
|
}
|
|
|
}
|