Fix some duplicate code
This commit is contained in:
parent
07576a2b12
commit
a6fea938b9
@ -1,6 +1,16 @@
|
||||
package mineplex.core.achievement;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import mineplex.core.account.CoreClientManager;
|
||||
import mineplex.core.common.Rank;
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.common.util.UtilTime;
|
||||
import mineplex.core.stats.PlayerStats;
|
||||
import mineplex.core.stats.StatsManager;
|
||||
|
||||
/**
|
||||
* Created by Shaun on 8/21/2014.
|
||||
@ -182,6 +192,40 @@ public enum AchievementCategory
|
||||
return _friendlyStatNames;
|
||||
}
|
||||
|
||||
public void addStats(CoreClientManager clientManager, StatsManager statsManager, List<String> lore, Player player, Player target)
|
||||
{
|
||||
addStats(clientManager, statsManager, lore, Integer.MAX_VALUE, player, target);
|
||||
}
|
||||
|
||||
public void addStats(CoreClientManager clientManager, StatsManager statsManager, List<String> lore, int max, Player player, Player target)
|
||||
{
|
||||
PlayerStats stats = statsManager.Get(target);
|
||||
for (int i = 0; i < _statsToDisplay.length && i < max; i++)
|
||||
{
|
||||
// If the stat is null then just display a blank line instead
|
||||
if (_statsToDisplay[i] == null || _friendlyStatNames[i] == null)
|
||||
{
|
||||
lore.add(" ");
|
||||
continue;
|
||||
}
|
||||
|
||||
// Skip showing Losses, Kills, Deaths for other players
|
||||
if (!clientManager.Get(player).GetRank().Has(Rank.MODERATOR) && !player.equals(target) && (_statsToDisplay[i].contains("Losses") || _statsToDisplay[i].contains("Kills") || _statsToDisplay[i].contains("Deaths") || _statsToDisplay[i].equals("Time In Game") || _statsToDisplay.equals("Games Played")))
|
||||
continue;
|
||||
|
||||
int statNumber = 0;
|
||||
for (String statToPull : _statsToPull)
|
||||
statNumber += stats.getStat(statToPull + "." + _statsToDisplay[i]);
|
||||
|
||||
String statString = C.cWhite + statNumber;
|
||||
// Need to display special for time
|
||||
if (_statsToDisplay[i].equalsIgnoreCase("TimeInGame"))
|
||||
statString = C.cWhite + UtilTime.convertString(statNumber, 0, UtilTime.TimeUnit.SECONDS);
|
||||
|
||||
lore.add(C.cYellow + _friendlyStatNames[i] + ": " + statString);
|
||||
}
|
||||
}
|
||||
|
||||
public static enum GameCategory
|
||||
{
|
||||
GLOBAL, SURVIVAL, CLASSICS, CHAMPIONS, ARCADE;
|
||||
|
@ -15,13 +15,10 @@ import mineplex.core.achievement.AchievementManager;
|
||||
import mineplex.core.achievement.ui.AchievementShop;
|
||||
import mineplex.core.achievement.ui.button.ArcadeButton;
|
||||
import mineplex.core.achievement.ui.button.CategoryButton;
|
||||
import mineplex.core.common.Rank;
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.common.util.UtilTime;
|
||||
import mineplex.core.donation.DonationManager;
|
||||
import mineplex.core.shop.item.ShopItem;
|
||||
import mineplex.core.shop.page.ShopPageBase;
|
||||
import mineplex.core.stats.PlayerStats;
|
||||
import mineplex.core.stats.StatsManager;
|
||||
|
||||
/**
|
||||
@ -57,7 +54,7 @@ public class AchievementMainPage extends ShopPageBase<AchievementManager, Achiev
|
||||
|
||||
ArrayList<String> lore = new ArrayList<String>();
|
||||
lore.add(" ");
|
||||
addStats(category, lore, category == AchievementCategory.GLOBAL ? 5 : 2);
|
||||
category.addStats(ClientManager, _statsManager, lore, category == AchievementCategory.GLOBAL ? 5 : 2, Player, _target);
|
||||
lore.add(" ");
|
||||
addAchievements(category, lore, 9);
|
||||
lore.add(" ");
|
||||
@ -83,37 +80,6 @@ public class AchievementMainPage extends ShopPageBase<AchievementManager, Achiev
|
||||
addArcadeButton();
|
||||
}
|
||||
|
||||
protected void addStats(AchievementCategory category, List<String> lore, int max)
|
||||
{
|
||||
String[] statsToDisplay = category.getStatsToDisplay();
|
||||
String[] friendlyStatNames = category.getFriendlyStatNames();
|
||||
PlayerStats stats = _statsManager.Get(_target);
|
||||
for (int i = 0; i < statsToDisplay.length && i < max; i++)
|
||||
{
|
||||
// If the stat is null then just display a blank line instead
|
||||
if (statsToDisplay[i] == null || friendlyStatNames[i] == null)
|
||||
{
|
||||
lore.add(" ");
|
||||
continue;
|
||||
}
|
||||
|
||||
// Skip showing Losses, Kills, Deaths for other players
|
||||
if (!ClientManager.Get(Player).GetRank().Has(Rank.MODERATOR) && !Player.equals(_target) && (statsToDisplay[i].contains("Losses") || statsToDisplay[i].contains("Kills") || statsToDisplay[i].contains("Deaths") || statsToDisplay[i].equals("Time In Game") || statsToDisplay.equals("Games Played")))
|
||||
continue;
|
||||
|
||||
int statNumber = 0;
|
||||
for (String statToPull : category.getStatsToPull())
|
||||
statNumber += stats.getStat(statToPull + "." + statsToDisplay[i]);
|
||||
|
||||
String statString = C.cWhite + statNumber;
|
||||
// Need to display special for time
|
||||
if (statsToDisplay[i].equalsIgnoreCase("TimeInGame"))
|
||||
statString = C.cWhite + UtilTime.convertString(statNumber, 0, UtilTime.TimeUnit.SECONDS);
|
||||
|
||||
lore.add(C.cYellow + friendlyStatNames[i] + ": " + statString);
|
||||
}
|
||||
}
|
||||
|
||||
protected void addArcadeButton()
|
||||
{
|
||||
ArcadeButton button = new ArcadeButton(Shop, Plugin, _statsManager, DonationManager, ClientManager, _target);
|
||||
|
@ -16,9 +16,7 @@ import mineplex.core.achievement.AchievementCategory;
|
||||
import mineplex.core.achievement.AchievementData;
|
||||
import mineplex.core.achievement.AchievementManager;
|
||||
import mineplex.core.achievement.ui.AchievementShop;
|
||||
import mineplex.core.common.Rank;
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.common.util.UtilTime;
|
||||
import mineplex.core.donation.DonationManager;
|
||||
import mineplex.core.shop.item.ShopItem;
|
||||
import mineplex.core.shop.item.SingleButton;
|
||||
@ -157,36 +155,8 @@ public class AchievementPage extends ShopPageBase<AchievementManager, Achievemen
|
||||
Material material = Material.BOOK;
|
||||
String itemName = C.Bold + _category.getFriendlyName() + " Stats";
|
||||
List<String> lore = new ArrayList<String>();
|
||||
lore.add("");
|
||||
|
||||
PlayerStats stats = _statsManager.Get(_target);
|
||||
String[] statsToDisplay = _category.getStatsToDisplay();
|
||||
String[] friendlyStatNames = _category.getFriendlyStatNames();
|
||||
for (int i = 0; i < statsToDisplay.length; i++)
|
||||
{
|
||||
// If the stat is null then just display a blank line instead
|
||||
if (statsToDisplay[i] == null || friendlyStatNames[i] == null)
|
||||
{
|
||||
lore.add(" ");
|
||||
continue;
|
||||
}
|
||||
|
||||
// Skip showing Losses, Kills, Deaths for other players
|
||||
if (!ClientManager.Get(Player).GetRank().Has(Rank.MODERATOR) && !Player.equals(_target) && (statsToDisplay[i].contains("Losses") || statsToDisplay[i].contains("Kills") || statsToDisplay[i].contains("Deaths") || statsToDisplay[i].equals("Time In Game") || statsToDisplay.equals("Games Played")))
|
||||
continue;
|
||||
|
||||
int statNumber = 0;
|
||||
for (String statToPull : _category.getStatsToPull())
|
||||
statNumber += stats.getStat(statToPull + "." + statsToDisplay[i]);
|
||||
|
||||
String statString = C.cWhite + statNumber;
|
||||
|
||||
// Need to display special for time
|
||||
if (statsToDisplay[i].equalsIgnoreCase("TimeInGame"))
|
||||
statString = UtilTime.convertString(statNumber, 0, UtilTime.TimeUnit.SECONDS);
|
||||
|
||||
lore.add(C.cYellow + friendlyStatNames[i] + ": " + statString);
|
||||
}
|
||||
lore.add(" ");
|
||||
_category.addStats(ClientManager, _statsManager, lore, Player, _target);
|
||||
|
||||
ItemStack item = new ItemStack(material);
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
|
@ -16,7 +16,6 @@ import mineplex.core.common.util.C;
|
||||
import mineplex.core.donation.DonationManager;
|
||||
import mineplex.core.shop.item.ShopItem;
|
||||
import mineplex.core.shop.item.SingleButton;
|
||||
import mineplex.core.shop.page.ShopPageBase;
|
||||
import mineplex.core.stats.StatsManager;
|
||||
|
||||
/**
|
||||
@ -43,7 +42,7 @@ public class ArcadeMainPage extends AchievementMainPage
|
||||
|
||||
ArrayList<String> lore = new ArrayList<String>();
|
||||
lore.add(" ");
|
||||
addStats(category, lore, 2);
|
||||
category.addStats(ClientManager, _statsManager, lore, 2, Player, _target);
|
||||
lore.add(" ");
|
||||
addAchievements(category, lore, 9);
|
||||
lore.add(" ");
|
||||
|
Loading…
Reference in New Issue
Block a user