Improve the Level Rewards system
This commit is contained in:
parent
5b77b099b2
commit
9a4995d212
@ -8,11 +8,18 @@ import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import mineplex.core.account.CoreClientManager;
|
||||
import mineplex.core.account.ILoginProcessor;
|
||||
import mineplex.core.common.util.UtilServer;
|
||||
|
||||
public abstract class MiniDbClientPlugin<DataType extends Object> extends MiniClientPlugin<DataType> implements ILoginProcessor
|
||||
{
|
||||
|
||||
protected CoreClientManager ClientManager = null;
|
||||
|
||||
|
||||
public MiniDbClientPlugin(String moduleName)
|
||||
{
|
||||
this(moduleName, UtilServer.getPlugin(), Managers.require(CoreClientManager.class));
|
||||
}
|
||||
|
||||
public MiniDbClientPlugin(String moduleName, JavaPlugin plugin, CoreClientManager clientManager)
|
||||
{
|
||||
super(moduleName, plugin);
|
||||
|
@ -1405,7 +1405,7 @@ public enum Achievement
|
||||
|
||||
private static int[] getExperienceLevels()
|
||||
{
|
||||
int[] levels = new int[LevelingManager.MAX_LEVEL];
|
||||
int[] levels = new int[LevelingManager.getMaxLevel()];
|
||||
|
||||
int expReq = 0;
|
||||
|
||||
|
@ -1,8 +1,18 @@
|
||||
package mineplex.core.achievement.leveling;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import mineplex.core.MiniPlugin;
|
||||
import mineplex.core.account.CoreClientManager;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.AbstractMap.SimpleEntry;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import mineplex.core.MiniDbClientPlugin;
|
||||
import mineplex.core.achievement.Achievement;
|
||||
import mineplex.core.achievement.AchievementManager;
|
||||
import mineplex.core.achievement.leveling.rewards.LevelChestReward;
|
||||
@ -16,60 +26,34 @@ import mineplex.core.common.util.C;
|
||||
import mineplex.core.donation.DonationManager;
|
||||
import mineplex.core.itemstack.ItemBuilder;
|
||||
import mineplex.core.treasure.TreasureType;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public class LevelingManager extends MiniPlugin
|
||||
public class LevelingManager extends MiniDbClientPlugin<List<Integer>>
|
||||
{
|
||||
|
||||
private static final Map<Integer, LevelReward> REWARDS = ImmutableMap.<Integer, LevelReward>builder()
|
||||
.put(1, new LevelCurrencyReward(GlobalCurrency.GEM, 1000))
|
||||
.put(2, new LevelCurrencyReward(GlobalCurrency.GEM, 2000))
|
||||
.put(3, new LevelCurrencyReward(GlobalCurrency.GEM, 3000))
|
||||
.put(4, new LevelCurrencyReward(GlobalCurrency.GEM, 4000))
|
||||
.put(5, new LevelChestReward(TreasureType.OLD, 1))
|
||||
.put(6, new LevelCurrencyReward(GlobalCurrency.GEM, 6000))
|
||||
.put(7, new LevelCurrencyReward(GlobalCurrency.GEM, 7000))
|
||||
.put(100, new LevelCurrencyReward(GlobalCurrency.GEM, 1))
|
||||
.put(250, new LevelChestReward(TreasureType.MYTHICAL, 1))
|
||||
.put(500, new LevelChestReward(TreasureType.ILLUMINATED, 1))
|
||||
.build();
|
||||
// That is a big old number
|
||||
public static final int MAX_LEVEL = 500;
|
||||
public static final int MAX_LEVEL_MAIN_MENU = 100;
|
||||
private static final int MAX_LEVEL = 500;
|
||||
public static int getMaxLevel()
|
||||
{
|
||||
return MAX_LEVEL;
|
||||
}
|
||||
|
||||
private final AchievementManager _achievement;
|
||||
private final CoreClientManager _client;
|
||||
private final LevelingRepository _repository;
|
||||
|
||||
private final Map<UUID, List<Integer>> _claimedRewards;
|
||||
|
||||
private final LevelRewardShop _shop;
|
||||
|
||||
private final List<Entry<Integer, LevelReward>> _rewards;
|
||||
|
||||
public LevelingManager(AchievementManager achievementManager)
|
||||
{
|
||||
super("Level");
|
||||
super("Level Rewards");
|
||||
|
||||
_achievement = achievementManager;
|
||||
_client = require(CoreClientManager.class);
|
||||
_repository = new LevelingRepository(this, _client);
|
||||
_repository = new LevelingRepository();
|
||||
_shop = new LevelRewardShop(this, ClientManager, require(DonationManager.class));
|
||||
|
||||
_claimedRewards = new HashMap<>();
|
||||
|
||||
_shop = new LevelRewardShop(this, _client, require(DonationManager.class));
|
||||
_rewards = new ArrayList<>(120);
|
||||
|
||||
populateRewards();
|
||||
addCommand(new CommandBase<LevelingManager>(this, Rank.ALL, "level")
|
||||
{
|
||||
|
||||
@ -81,7 +65,38 @@ public class LevelingManager extends MiniPlugin
|
||||
});
|
||||
}
|
||||
|
||||
public void onLogin(UUID player, ResultSet resultSet)
|
||||
private void populateRewards()
|
||||
{
|
||||
addCurrencyReward(1, GlobalCurrency.GEM, 100);
|
||||
addCurrencyReward(2, GlobalCurrency.GEM, 200);
|
||||
addChestReward(3, TreasureType.OLD, 1);
|
||||
addCurrencyReward(4, GlobalCurrency.GEM, 250);
|
||||
addCurrencyReward(5, GlobalCurrency.GEM, 250);
|
||||
addChestReward(6, TreasureType.OLD, 2);
|
||||
addCurrencyReward(7, GlobalCurrency.GEM, 250);
|
||||
addCurrencyReward(8, GlobalCurrency.GEM, 250);
|
||||
addCurrencyReward(9, GlobalCurrency.GEM, 500);
|
||||
addChestReward(10, TreasureType.OLD, 2);
|
||||
addChestReward(10, TreasureType.ANCIENT, 1);
|
||||
// TODO implement full rewards
|
||||
|
||||
addChestReward(100, TreasureType.OMEGA, 5);
|
||||
addChestReward(101, TreasureType.OMEGA, 6);
|
||||
addChestReward(102, TreasureType.OMEGA, 7);
|
||||
}
|
||||
|
||||
private void addCurrencyReward(int level, GlobalCurrency type, int amount)
|
||||
{
|
||||
_rewards.add(new SimpleEntry<>(level, new LevelCurrencyReward(type, amount)));
|
||||
}
|
||||
|
||||
private void addChestReward(int level, TreasureType type, int amount)
|
||||
{
|
||||
_rewards.add(new SimpleEntry<>(level, new LevelChestReward(type, amount)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processLoginResultSet(String playerName, UUID uuid, int accountId, ResultSet resultSet) throws SQLException
|
||||
{
|
||||
List<Integer> levels = new ArrayList<>(50);
|
||||
|
||||
@ -97,22 +112,19 @@ public class LevelingManager extends MiniPlugin
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
_claimedRewards.put(player, levels);
|
||||
Set(uuid, levels);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void playerJoin(PlayerJoinEvent event)
|
||||
@Override
|
||||
protected List<Integer> addPlayer(UUID uuid)
|
||||
{
|
||||
UUID player = event.getPlayer().getUniqueId();
|
||||
|
||||
// If there was no entries in the database for this player, then onLogin won't be called.
|
||||
_claimedRewards.putIfAbsent(player, new ArrayList<>());
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void playerQuit(PlayerQuitEvent event)
|
||||
@Override
|
||||
public String getQuery(int accountId, String uuid, String name)
|
||||
{
|
||||
_claimedRewards.remove(event.getPlayer().getUniqueId());
|
||||
return "SELECT level FROM accountLevelReward WHERE accountId=" + accountId + ";";
|
||||
}
|
||||
|
||||
public int getLevel(Player player)
|
||||
@ -122,35 +134,48 @@ public class LevelingManager extends MiniPlugin
|
||||
|
||||
public int getFirstUnclaimedLevel(Player player)
|
||||
{
|
||||
List<Integer> claimed = _claimedRewards.get(player.getUniqueId());
|
||||
List<Integer> claimed = Get(player);
|
||||
|
||||
for (int i = 1; i <= MAX_LEVEL; i++)
|
||||
for (Entry<Integer, LevelReward> entry : _rewards)
|
||||
{
|
||||
LevelReward reward = getLevelReward(i);
|
||||
int level = entry.getKey();
|
||||
|
||||
if (reward == null)
|
||||
if (!claimed.contains(level))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!claimed.contains(i))
|
||||
{
|
||||
return i;
|
||||
return level;
|
||||
}
|
||||
}
|
||||
|
||||
return MAX_LEVEL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
public LevelReward getLevelReward(int level)
|
||||
public List<LevelReward> getLevelRewards(int level)
|
||||
{
|
||||
return REWARDS.get(level);
|
||||
List<LevelReward> rewards = new ArrayList<>();
|
||||
|
||||
for (Entry<Integer, LevelReward> entry : _rewards)
|
||||
{
|
||||
int rewardLevel = entry.getKey();
|
||||
|
||||
if (level == rewardLevel)
|
||||
{
|
||||
rewards.add(entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
return rewards;
|
||||
}
|
||||
|
||||
public ItemStack getLevelItem(Player player, LevelReward reward, int level)
|
||||
public List<Entry<Integer, LevelReward>> getLevelRewards()
|
||||
{
|
||||
return _rewards;
|
||||
}
|
||||
|
||||
public ItemStack getLevelItem(Player player, List<LevelReward> rewards, int level)
|
||||
{
|
||||
boolean claimed = hasClaimed(player, level);
|
||||
boolean canClaim = canClaim(player, level);
|
||||
boolean exclusive = level > 100;
|
||||
|
||||
Material material;
|
||||
byte data = 0;
|
||||
@ -169,36 +194,43 @@ public class LevelingManager extends MiniPlugin
|
||||
// Hasn't claimed and could claim
|
||||
else if (canClaim)
|
||||
{
|
||||
material = level >= 100 ? Material.DIAMOND_BLOCK : Material.EMERALD_BLOCK;
|
||||
material = exclusive ? Material.DIAMOND_BLOCK : Material.EMERALD_BLOCK;
|
||||
title = C.cGreen + title;
|
||||
bottomLine = C.cGreen + "Click to claim this reward.";
|
||||
bottomLine = C.cGreen + "Click to claim this reward!";
|
||||
builder.setGlow(true);
|
||||
}
|
||||
// Hasn't claimed and can't claim
|
||||
else
|
||||
{
|
||||
material = level >= 100 ? Material.OBSIDIAN : Material.REDSTONE_BLOCK;
|
||||
material = exclusive ? Material.OBSIDIAN : Material.REDSTONE_BLOCK;
|
||||
title = C.cRed + title;
|
||||
bottomLine = C.cRed + "You aren't a high enough level to claim this.";
|
||||
bottomLine = C.cRed + "You aren't a high enough level to claim this reward.";
|
||||
}
|
||||
|
||||
builder.setType(material);
|
||||
builder.setData(data);
|
||||
builder.setTitle(title);
|
||||
builder.addLore("", " " + reward.getDescription(), "", bottomLine);
|
||||
builder.addLore("");
|
||||
|
||||
for (LevelReward reward : rewards)
|
||||
{
|
||||
builder.addLore(" " + reward.getDescription());
|
||||
}
|
||||
|
||||
builder.addLore("", bottomLine);
|
||||
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
public void claim(Player player, int level)
|
||||
{
|
||||
_claimedRewards.get(player.getUniqueId()).add(level);
|
||||
_repository.claimReward(_client.Get(player), level);
|
||||
Get(player).add(level);
|
||||
_repository.claimReward(ClientManager.Get(player), level);
|
||||
}
|
||||
|
||||
public boolean hasClaimed(Player player, int level)
|
||||
{
|
||||
return _claimedRewards.get(player.getUniqueId()).contains(level);
|
||||
return Get(player).contains(level);
|
||||
}
|
||||
|
||||
public boolean canClaim(Player player, int level)
|
||||
|
@ -1,49 +1,18 @@
|
||||
package mineplex.core.achievement.leveling;
|
||||
|
||||
import mineplex.core.account.CoreClient;
|
||||
import mineplex.core.account.CoreClientManager;
|
||||
import mineplex.core.account.ILoginProcessor;
|
||||
import mineplex.serverdata.database.DBPool;
|
||||
import mineplex.serverdata.database.RepositoryBase;
|
||||
import mineplex.serverdata.database.column.ColumnInt;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.UUID;
|
||||
|
||||
public class LevelingRepository extends RepositoryBase implements ILoginProcessor
|
||||
public class LevelingRepository extends RepositoryBase
|
||||
{
|
||||
|
||||
private static final String GET_CLAIMED_REWARDS = "SELECT level FROM accountLevelReward WHERE accountId=";
|
||||
private static final String CLAIM_REWARD = "INSERT INTO accountLevelReward VALUES (?,?);";
|
||||
|
||||
private final LevelingManager _levelingManager;
|
||||
|
||||
public LevelingRepository(LevelingManager levelingManager, CoreClientManager clientManager)
|
||||
LevelingRepository()
|
||||
{
|
||||
super(DBPool.getAccount());
|
||||
|
||||
_levelingManager = levelingManager;
|
||||
|
||||
clientManager.addStoredProcedureLoginProcessor(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName()
|
||||
{
|
||||
return "Level Rewards";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processLoginResultSet(String playerName, UUID uuid, int accountId, ResultSet resultSet) throws SQLException
|
||||
{
|
||||
_levelingManager.onLogin(uuid, resultSet);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getQuery(int accountId, String uuid, String name)
|
||||
{
|
||||
return GET_CLAIMED_REWARDS + accountId + ";";
|
||||
}
|
||||
|
||||
public void claimReward(CoreClient client, int level)
|
||||
|
@ -1,8 +1,10 @@
|
||||
package mineplex.core.achievement.leveling.rewards;
|
||||
|
||||
import mineplex.core.treasure.TreasureType;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.treasure.TreasureType;
|
||||
|
||||
public class LevelChestReward implements LevelReward
|
||||
{
|
||||
|
||||
@ -18,12 +20,12 @@ public class LevelChestReward implements LevelReward
|
||||
@Override
|
||||
public void claim(Player player)
|
||||
{
|
||||
INVENTORY.addItemToInventory(null, player, _chest.getItemName(), 1);
|
||||
INVENTORY.addItemToInventory(null, player, _chest.getItemName(), _amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription()
|
||||
{
|
||||
return "+" + _amount + " " + _chest.getName();
|
||||
return C.cWhite + "- " + _amount + " " + _chest.getName();
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package mineplex.core.achievement.leveling.rewards;
|
||||
|
||||
import mineplex.core.common.currency.GlobalCurrency;
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.common.util.F;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@ -25,6 +26,6 @@ public class LevelCurrencyReward implements LevelReward
|
||||
@Override
|
||||
public String getDescription()
|
||||
{
|
||||
return "+" + F.currency(_type, _amount);
|
||||
return C.cWhite + "- " + F.currency(_type, _amount);
|
||||
}
|
||||
}
|
||||
|
@ -1,48 +1,51 @@
|
||||
package mineplex.core.achievement.leveling.ui.button;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
|
||||
import mineplex.core.achievement.leveling.LevelingManager;
|
||||
import mineplex.core.achievement.leveling.rewards.LevelReward;
|
||||
import mineplex.core.achievement.leveling.ui.LevelRewardShop;
|
||||
import mineplex.core.achievement.leveling.ui.page.LevelRewardMainPage;
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.common.util.F;
|
||||
import mineplex.core.recharge.Recharge;
|
||||
import mineplex.core.shop.item.IButton;
|
||||
import mineplex.core.shop.page.ShopPageBase;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
|
||||
public class LevelRewardButton implements IButton
|
||||
{
|
||||
|
||||
private LevelingManager _plugin;
|
||||
private ShopPageBase<LevelingManager, LevelRewardShop> _menu;
|
||||
private final LevelReward _reward;
|
||||
private final List<LevelReward> _rewards;
|
||||
private final int _level;
|
||||
|
||||
public LevelRewardButton(ShopPageBase<LevelingManager, LevelRewardShop> menu, LevelReward reward, int level)
|
||||
public LevelRewardButton(ShopPageBase<LevelingManager, LevelRewardShop> menu, List<LevelReward> rewards, int level)
|
||||
{
|
||||
_plugin = menu.getPlugin();
|
||||
_menu = menu;
|
||||
_reward = reward;
|
||||
_rewards = rewards;
|
||||
_level = level;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(Player player, ClickType clickType)
|
||||
{
|
||||
if (_plugin.hasClaimed(player, _level) || !_plugin.canClaim(player, _level))
|
||||
if (_plugin.hasClaimed(player, _level) || !_plugin.canClaim(player, _level) || !Recharge.Instance.use(player, "Claim Level Reward", 250, true, false))
|
||||
{
|
||||
_menu.playDenySound(player);
|
||||
return;
|
||||
}
|
||||
|
||||
// Give the player the reward
|
||||
_reward.claim(player);
|
||||
_rewards.forEach(reward -> reward.claim(player));
|
||||
_plugin.claim(player, _level);
|
||||
|
||||
// Give some feedback
|
||||
_menu.playAcceptSound(player);
|
||||
player.sendMessage(F.main(_plugin.getName(), "You claimed " + _reward.getDescription() + C.mBody + "."));
|
||||
player.sendMessage(F.main(_plugin.getName(), "You claimed rewards for level " + F.elem(_level) + ":"));
|
||||
_rewards.forEach(reward -> player.sendMessage(F.main(_plugin.getName(), reward.getDescription())));
|
||||
|
||||
// Rebuild the menu
|
||||
_menu.refresh();
|
||||
|
@ -1,83 +0,0 @@
|
||||
package mineplex.core.achievement.leveling.ui.page;
|
||||
|
||||
import mineplex.core.account.CoreClientManager;
|
||||
import mineplex.core.achievement.leveling.LevelingManager;
|
||||
import mineplex.core.achievement.leveling.rewards.LevelReward;
|
||||
import mineplex.core.achievement.leveling.ui.LevelRewardShop;
|
||||
import mineplex.core.achievement.leveling.ui.button.LevelRewardButton;
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.common.util.UtilInv;
|
||||
import mineplex.core.common.util.UtilUI;
|
||||
import mineplex.core.donation.DonationManager;
|
||||
import mineplex.core.itemstack.ItemBuilder;
|
||||
import mineplex.core.shop.item.IButton;
|
||||
import mineplex.core.shop.page.ShopPageBase;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class LevelRewardExclusivePage extends ShopPageBase<LevelingManager, LevelRewardShop>
|
||||
{
|
||||
|
||||
private static final ItemStack GO_BACK = new ItemBuilder(Material.BED)
|
||||
.setTitle(C.cGreen + "Click to go back.")
|
||||
.build();
|
||||
private static final ItemStack MAXED = new ItemBuilder(Material.FIREWORK)
|
||||
.setTitle(C.cPurpleB + "Congratulations")
|
||||
.addLore("You have reached the maximum", "level possible, you must really love Mineplex!", "From all of us here at Mineplex we'd like to thank you", "for putting the in crazy number of hours to achieve this", "Unless you are an admin, in which you cheated", C.cPurple + "<3")
|
||||
.build();
|
||||
private static final int[] MAPPINGS = {
|
||||
10, 11, 12, 13, 14, 15, 16,
|
||||
19, 20, 21, 22, 23, 24, 25,
|
||||
28, 29, 30, 31, 32, 33, 34
|
||||
};
|
||||
|
||||
private ShopPageBase<LevelingManager, LevelRewardShop> _menu;
|
||||
|
||||
public LevelRewardExclusivePage(LevelingManager plugin, LevelRewardShop shop, ShopPageBase<LevelingManager, LevelRewardShop> menu, CoreClientManager clientManager, DonationManager donationManager, Player player)
|
||||
{
|
||||
super(plugin, shop, clientManager, donationManager, "Exclusive Level Rewards", player);
|
||||
|
||||
_menu = menu;
|
||||
|
||||
buildPage();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void buildPage()
|
||||
{
|
||||
int level = _plugin.getLevel(_player);
|
||||
int menuIndex = 0;
|
||||
|
||||
for (int i = LevelingManager.MAX_LEVEL_MAIN_MENU; i <= LevelingManager.MAX_LEVEL; i++)
|
||||
{
|
||||
LevelReward reward = _plugin.getLevelReward(i);
|
||||
|
||||
if (reward == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
addButton(MAPPINGS[menuIndex++], _plugin.getLevelItem(_player, reward, i), new LevelRewardButton(this, reward, i));
|
||||
}
|
||||
|
||||
// This would occur if the max level was reached and claimed
|
||||
if (level == LevelingManager.MAX_LEVEL && _plugin.hasClaimed(_player, level))
|
||||
{
|
||||
addButtonNoAction(41, MAXED);
|
||||
}
|
||||
|
||||
addButton(49, GO_BACK, new GoBackButton());
|
||||
}
|
||||
|
||||
private class GoBackButton implements IButton
|
||||
{
|
||||
|
||||
@Override
|
||||
public void onClick(Player player, ClickType clickType)
|
||||
{
|
||||
_shop.openPageForPlayer(player, _menu);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,32 +1,45 @@
|
||||
package mineplex.core.achievement.leveling.ui.page;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import mineplex.core.account.CoreClientManager;
|
||||
import mineplex.core.achievement.leveling.LevelingManager;
|
||||
import mineplex.core.achievement.leveling.rewards.LevelReward;
|
||||
import mineplex.core.achievement.leveling.ui.LevelRewardShop;
|
||||
import mineplex.core.achievement.leveling.ui.button.LevelRewardButton;
|
||||
import mineplex.core.common.Rank;
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.common.util.UtilMath;
|
||||
import mineplex.core.donation.DonationManager;
|
||||
import mineplex.core.itemstack.ItemBuilder;
|
||||
import mineplex.core.shop.item.IButton;
|
||||
import mineplex.core.shop.page.ShopPageBase;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class LevelRewardMainPage extends ShopPageBase<LevelingManager, LevelRewardShop>
|
||||
{
|
||||
|
||||
private static final int MID_INDEX = 13;
|
||||
private static final int VIEW_ALL_INDEX = 22;
|
||||
private static final ItemStack VIEW_ALL = new ItemBuilder(Material.BOOK)
|
||||
.setTitle(C.cGreen + "View All Rewards")
|
||||
.addLore("Click to view all rewards.")
|
||||
.build();
|
||||
private static final ItemStack EXCLUSIVE = new ItemBuilder(Material.DIAMOND_BLOCK)
|
||||
.setTitle(C.cAquaB + "Exclusive Rewards")
|
||||
.addLore("", "Click to view the exclusive rewards", "for players who have reached level 100+!")
|
||||
private static final ItemStack MAX_LEVEL = new ItemBuilder(Material.FIREWORK)
|
||||
.setTitle(C.cPurpleB + "Congratulations!")
|
||||
.addLore(
|
||||
"You have achieved the maximum level",
|
||||
"possible on Mineplex! From all of us",
|
||||
"here at Mineplex, we thank you for",
|
||||
"dedicating so much time to the server.",
|
||||
"",
|
||||
"Unless you're an " + Rank.ADMIN.getTag(true, true) + C.mBody + " in which case",
|
||||
"you cheated " + C.cPurple + "<3" + C.cGray + "."
|
||||
)
|
||||
.build();
|
||||
|
||||
public LevelRewardMainPage(LevelingManager plugin, LevelRewardShop shop, CoreClientManager clientManager, DonationManager donationManager, Player player)
|
||||
@ -39,42 +52,96 @@ public class LevelRewardMainPage extends ShopPageBase<LevelingManager, LevelRewa
|
||||
@Override
|
||||
protected void buildPage()
|
||||
{
|
||||
int level = _plugin.getFirstUnclaimedLevel(_player);
|
||||
int start = level - 2;
|
||||
int end = level + 2;
|
||||
int menuIndex = MID_INDEX - 2;
|
||||
int currentLevel = start;
|
||||
int current = _plugin.getFirstUnclaimedLevel(_player);
|
||||
int previousA = getPreviousLevel(current);
|
||||
int previousB = getPreviousLevel(previousA);
|
||||
int nextA = getNextLevel(current);
|
||||
int nextB = getNextLevel(nextA);
|
||||
|
||||
for (int i = start; i <= end; )
|
||||
{
|
||||
if (i <= 0)
|
||||
{
|
||||
i++;
|
||||
menuIndex++;
|
||||
currentLevel++;
|
||||
continue;
|
||||
}
|
||||
List<LevelReward> previousARewards = _plugin.getLevelRewards(previousA);
|
||||
List<LevelReward> previousBRewards = _plugin.getLevelRewards(previousB);
|
||||
List<LevelReward> currentRewards = _plugin.getLevelRewards(current);
|
||||
List<LevelReward> nextARewards = _plugin.getLevelRewards(nextA);
|
||||
List<LevelReward> nextBRewards = _plugin.getLevelRewards(nextB);
|
||||
|
||||
if (currentLevel >= LevelingManager.MAX_LEVEL_MAIN_MENU)
|
||||
{
|
||||
addButton(level >= LevelingManager.MAX_LEVEL_MAIN_MENU ? MID_INDEX : menuIndex, EXCLUSIVE, new ExclusiveRewardsButton());
|
||||
break;
|
||||
}
|
||||
// Order of display
|
||||
// previousB -> previousA -> current -> nextA -> nextB
|
||||
|
||||
LevelReward reward = _plugin.getLevelReward(currentLevel);
|
||||
|
||||
if (reward == null)
|
||||
{
|
||||
currentLevel++;
|
||||
continue;
|
||||
}
|
||||
|
||||
addButton(menuIndex++, _plugin.getLevelItem(_player, reward, currentLevel), new LevelRewardButton(this, reward, currentLevel));
|
||||
i++;
|
||||
currentLevel++;
|
||||
}
|
||||
addButton(11, previousB, previousBRewards);
|
||||
addButton(12, previousA, previousARewards);
|
||||
addButton(13, current, currentRewards);
|
||||
addButton(14, nextA, nextARewards);
|
||||
addButton(15, nextB, nextBRewards);
|
||||
|
||||
addButton(VIEW_ALL_INDEX, VIEW_ALL, new ViewAllRewardsButton());
|
||||
|
||||
// Claimed all the rewards
|
||||
if (current == -1)
|
||||
{
|
||||
addButtonNoAction(13, MAX_LEVEL);
|
||||
|
||||
for (int i = 0; i < getSize(); i++)
|
||||
{
|
||||
if (i == 13 || i == VIEW_ALL_INDEX)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
addButtonNoAction(i, new ItemBuilder(Material.STAINED_GLASS_PANE, (byte) UtilMath.r(15))
|
||||
.setTitle(C.cBlack)
|
||||
.build());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void addButton(int slot, int level, List<LevelReward> rewards)
|
||||
{
|
||||
if (level < 0 || rewards.isEmpty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
addButton(slot, _plugin.getLevelItem(_player, rewards, level), new LevelRewardButton(this, rewards, level));
|
||||
}
|
||||
|
||||
private int getPreviousLevel(int level)
|
||||
{
|
||||
int previous = 0;
|
||||
|
||||
for (Entry<Integer, LevelReward> entry : _plugin.getLevelRewards())
|
||||
{
|
||||
int currentLevel = entry.getKey();
|
||||
|
||||
if (currentLevel == level)
|
||||
{
|
||||
return previous;
|
||||
}
|
||||
|
||||
previous = currentLevel;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
private int getNextLevel(int level)
|
||||
{
|
||||
boolean foundSearch = false;
|
||||
|
||||
for (Entry<Integer, LevelReward> entry : _plugin.getLevelRewards())
|
||||
{
|
||||
int currentLevel = entry.getKey();
|
||||
|
||||
if (currentLevel == level)
|
||||
{
|
||||
foundSearch = true;
|
||||
}
|
||||
else if (foundSearch)
|
||||
{
|
||||
return currentLevel;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
private class ViewAllRewardsButton implements IButton
|
||||
@ -86,21 +153,4 @@ public class LevelRewardMainPage extends ShopPageBase<LevelingManager, LevelRewa
|
||||
_shop.openPageForPlayer(player, new LevelRewardViewAllPage(getPlugin(), getShop(), LevelRewardMainPage.this, getClientManager(), getDonationManager(), player, 1));
|
||||
}
|
||||
}
|
||||
|
||||
private class ExclusiveRewardsButton implements IButton
|
||||
{
|
||||
|
||||
@Override
|
||||
public void onClick(Player player, ClickType clickType)
|
||||
{
|
||||
if (_plugin.getLevel(player) < LevelingManager.MAX_LEVEL_MAIN_MENU)
|
||||
{
|
||||
playDenySound(player);
|
||||
return;
|
||||
}
|
||||
|
||||
_shop.openPageForPlayer(player, new LevelRewardExclusivePage(getPlugin(), getShop(), LevelRewardMainPage.this, getClientManager(), getDonationManager(), player));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,5 +1,12 @@
|
||||
package mineplex.core.achievement.leveling.ui.page;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import mineplex.core.account.CoreClientManager;
|
||||
import mineplex.core.achievement.leveling.LevelingManager;
|
||||
import mineplex.core.achievement.leveling.rewards.LevelReward;
|
||||
@ -10,23 +17,23 @@ import mineplex.core.donation.DonationManager;
|
||||
import mineplex.core.itemstack.ItemBuilder;
|
||||
import mineplex.core.shop.item.IButton;
|
||||
import mineplex.core.shop.page.ShopPageBase;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class LevelRewardViewAllPage extends ShopPageBase<LevelingManager, LevelRewardShop>
|
||||
{
|
||||
|
||||
public static final int DISPLAY_SIZE = 45;
|
||||
private static final int DISPLAY_SIZE = 45;
|
||||
private static final ItemStack UNKNOWN_REWARD = new ItemBuilder(Material.OBSIDIAN)
|
||||
.setTitle(C.cRed + "???")
|
||||
.addLore("", C.cRed + "You aren't a high enough level to claim this reward.")
|
||||
.build();
|
||||
private static final ItemStack GO_BACK = new ItemBuilder(Material.BED)
|
||||
.setTitle(C.cGreen + "Click to go back.")
|
||||
.build();
|
||||
|
||||
private ShopPageBase<LevelingManager, LevelRewardShop> _menu;
|
||||
private final ShopPageBase<LevelingManager, LevelRewardShop> _menu;
|
||||
private int _startingLevel;
|
||||
|
||||
public LevelRewardViewAllPage(LevelingManager plugin, LevelRewardShop shop, ShopPageBase<LevelingManager, LevelRewardShop> menu, CoreClientManager clientManager, DonationManager donationManager, Player player, int startingLevel)
|
||||
LevelRewardViewAllPage(LevelingManager plugin, LevelRewardShop shop, ShopPageBase<LevelingManager, LevelRewardShop> menu, CoreClientManager clientManager, DonationManager donationManager, Player player, int startingLevel)
|
||||
{
|
||||
super(plugin, shop, clientManager, donationManager, "All Level Rewards", player);
|
||||
|
||||
@ -40,28 +47,39 @@ public class LevelRewardViewAllPage extends ShopPageBase<LevelingManager, LevelR
|
||||
protected void buildPage()
|
||||
{
|
||||
int level = _startingLevel;
|
||||
int playerLevel = _plugin.getLevel(_player);
|
||||
boolean lastPage = false;
|
||||
|
||||
// No i++ ?! look down
|
||||
for (int i = 0; i < DISPLAY_SIZE; )
|
||||
{
|
||||
if (level >= LevelingManager.MAX_LEVEL_MAIN_MENU)
|
||||
if (level >= LevelingManager.getMaxLevel())
|
||||
{
|
||||
lastPage = true;
|
||||
break;
|
||||
}
|
||||
|
||||
LevelReward reward = _plugin.getLevelReward(level);
|
||||
List<LevelReward> rewards = _plugin.getLevelRewards(level);
|
||||
|
||||
// No reward for that level
|
||||
if (reward == null)
|
||||
if (rewards.isEmpty())
|
||||
{
|
||||
level++;
|
||||
continue;
|
||||
}
|
||||
|
||||
addButton(i++, _plugin.getLevelItem(_player, reward, level), new LevelRewardButton(this, reward, level));
|
||||
ItemStack itemStack;
|
||||
|
||||
if (level > 100 && playerLevel < level)
|
||||
{
|
||||
itemStack = UNKNOWN_REWARD;
|
||||
}
|
||||
else
|
||||
{
|
||||
itemStack = _plugin.getLevelItem(_player, rewards, level);
|
||||
}
|
||||
|
||||
addButton(i++, itemStack, new LevelRewardButton(this, rewards, level));
|
||||
level++;
|
||||
}
|
||||
|
||||
@ -81,11 +99,9 @@ public class LevelRewardViewAllPage extends ShopPageBase<LevelingManager, LevelR
|
||||
|
||||
private ItemStack getChangePageItem(boolean previous)
|
||||
{
|
||||
ItemBuilder builder = new ItemBuilder(Material.SIGN);
|
||||
|
||||
builder.setTitle(C.cYellow + (previous ? "Previous Page" : "Next Page"));
|
||||
|
||||
return builder.build();
|
||||
return new ItemBuilder(Material.SIGN)
|
||||
.setTitle(previous ? "Previous Page" : "Next Page")
|
||||
.build();
|
||||
}
|
||||
|
||||
private class LevelRewardChangePageButton implements IButton
|
||||
|
@ -46,7 +46,7 @@ public class SetLevelCommand extends CommandBase<StatsManager>
|
||||
return;
|
||||
}
|
||||
|
||||
if (level < 0 || level > LevelingManager.MAX_LEVEL)
|
||||
if (level < 0 || level > LevelingManager.getMaxLevel())
|
||||
{
|
||||
UtilPlayer.message(caller, F.main("Stats", "That level is invalid"));
|
||||
return;
|
||||
|
Loading…
Reference in New Issue
Block a user