Refactor PowerPlayClubItem instead of using an event

This commit is contained in:
cnr 2017-01-25 21:10:32 -06:00
parent f93794f14d
commit 70948b6967
5 changed files with 56 additions and 111 deletions

View File

@ -21,7 +21,6 @@ import mineplex.core.bonuses.BonusManager;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.donation.DonationManager;
import mineplex.core.gui.GuiItem;
import mineplex.core.inventory.InventoryManager;
import mineplex.core.powerplayclub.PowerPlayClubRepository;
@ -36,16 +35,12 @@ public class PowerPlayClubButton implements GuiItem
private Player _player;
private PowerPlayClubRepository _powerPlayClubRepository;
private InventoryManager _inventoryManager;
private DonationManager _donationManager;
private BonusManager _bonusManager;
public PowerPlayClubButton(Player player, BonusManager manager)
{
_player = player;
_bonusManager = manager;
_powerPlayClubRepository = manager.getPowerPlayClubRepository();
_inventoryManager = manager.getInventoryManager();
_donationManager = manager.getDonationManager();
}
@Override
@ -132,7 +127,7 @@ public class PowerPlayClubButton implements GuiItem
itemName = C.cRedB + "Power Play Club";
lore.add(C.cYellow + YearMonth.now().getMonth().getDisplayName(TextStyle.FULL, Locale.US) + "'s Cosmetic");
lore.add(C.cWhite + " " + PowerPlayClubRewards.rewards().get(YearMonth.now()).getPrize());
lore.add(C.cWhite + " " + PowerPlayClubRewards.rewards().get(YearMonth.now()).getPrizeName());
lore.add(" ");
lore.addAll(buildOtherRewardsLore(1));
lore.add(C.cRed + "Get Power Play Club months at");
@ -152,7 +147,7 @@ public class PowerPlayClubButton implements GuiItem
.forEach(entry ->
{
YearMonth yearMonth = entry.getKey();
lore.add(C.cWhite + " " + entry.getValue().getPrize() + " " + C.cGold + yearMonth.getMonth().getDisplayName(TextStyle.SHORT, Locale.US) + " " + yearMonth.getYear());
lore.add(C.cWhite + " " + entry.getValue().getPrizeName() + " " + C.cGold + yearMonth.getMonth().getDisplayName(TextStyle.SHORT, Locale.US) + " " + yearMonth.getYear());
});
lore.add(" ");
return lore;

View File

@ -72,7 +72,6 @@ import mineplex.core.inventory.InventoryManager;
import mineplex.core.itemstack.ItemStackFactory;
import mineplex.core.pet.repository.PetRepository;
import mineplex.core.pet.repository.token.ClientPetTokenWrapper;
import mineplex.core.powerplayclub.event.PowerPlayRewardPetEvent;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
@ -625,15 +624,6 @@ public class PetManager extends MiniClientPlugin<PetClient>
}
}
@EventHandler
public void onPowerPlayRewardPet(PowerPlayRewardPetEvent event)
{
Player player = event.getPlayer();
PetType petType = event.getPetType();
if (!Get(player).getPets().containsKey(petType))
Get(player).getPets().put(petType, petType.getName());
}
@Override
protected PetClient addPlayer(UUID uuid)
{

View File

@ -26,7 +26,6 @@ import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.account.CoreClientManager;
import mineplex.core.account.ILoginProcessor;
import mineplex.core.donation.DonationManager;
import mineplex.core.powerplayclub.event.PowerPlayRewardPetEvent;
import mineplex.serverdata.database.DBPool;
public class PowerPlayClubRepository implements Listener {
@ -106,22 +105,7 @@ public class PowerPlayClubRepository implements Listener {
List<PowerPlayClubRewards.PowerPlayClubItem> list = PowerPlayClubRewards.rewardsForMonths(cached.getUsableCosmeticMonths());
for (PowerPlayClubRewards.PowerPlayClubItem item : list)
{
if (item.isPet())
{
PowerPlayRewardPetEvent ppcRewardPetEvent = new PowerPlayRewardPetEvent(player, item.getPetType());
Bukkit.getPluginManager().callEvent(ppcRewardPetEvent);
}
else
{
_donationManager.Get(player).addOwnedUnknownSalesPackage(item.getPrize());
}
}
/*PowerPlayClubRewards.rewardsForMonths(cached.getUsableCosmeticMonths()).stream()
.map(PowerPlayClubRewards.PowerPlayClubItem::getPrize)
.forEach(_donationManager.Get(player)::addOwnedUnknownSalesPackage);*/
PowerPlayClubRewards.rewardsForMonths(cached.getUsableCosmeticMonths()).forEach(item -> item.reward(player));
// Gives Metal Man for anyone subscribed
if (cached.getUsableCosmeticMonths().size() > 0)

View File

@ -8,18 +8,19 @@ import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import com.google.common.collect.ImmutableMap;
import mineplex.core.common.skin.SkinData;
import mineplex.core.Managers;
import mineplex.core.common.util.BukkitFuture;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.donation.DonationManager;
import mineplex.core.inventory.InventoryManager;
import mineplex.core.inventory.data.Item;
import mineplex.core.pet.PetClient;
import mineplex.core.pet.PetManager;
import mineplex.core.pet.PetType;
public class PowerPlayClubRewards
@ -28,55 +29,72 @@ public class PowerPlayClubRewards
public static final int CHESTS_PER_MONTH = 1;
private static final Map<YearMonth, PowerPlayClubItem> rewards = ImmutableMap.<YearMonth, PowerPlayClubItem>builder()
.put(YearMonth.of(2016, Month.SEPTEMBER), new PowerPlayClubItem("Squid Morph", new ItemStack(Material.INK_SACK)))
.put(YearMonth.of(2016, Month.OCTOBER), new PowerPlayClubItem("Witch Morph", SkinData.WITCH.getSkull()))
.put(YearMonth.of(2016, Month.NOVEMBER), new PowerPlayClubItem("Turkey Morph", SkinData.TURKEY.getSkull()))
.put(YearMonth.of(2016, Month.DECEMBER), new PowerPlayClubItem("Santa Morph", SkinData.SANTA.getSkull()))
.put(YearMonth.of(2017, Month.JANUARY), new PowerPlayClubItem("Over Easy Morph", new ItemStack(Material.EGG)))
.put(YearMonth.of(2017, Month.FEBRUARY), new PowerPlayClubItem(PetType.TRUE_LOVE_PET, new ItemStack(Material.APPLE)))
.put(YearMonth.of(2016, Month.SEPTEMBER), new UnknownSalesPackageItem("Squid Morph"))
.put(YearMonth.of(2016, Month.OCTOBER), new UnknownSalesPackageItem("Witch Morph"))
.put(YearMonth.of(2016, Month.NOVEMBER), new UnknownSalesPackageItem("Turkey Morph"))
.put(YearMonth.of(2016, Month.DECEMBER), new UnknownSalesPackageItem("Santa Morph"))
.put(YearMonth.of(2017, Month.JANUARY), new UnknownSalesPackageItem("Over Easy Morph"))
.put(YearMonth.of(2017, Month.FEBRUARY), new PetItem(PetType.TRUE_LOVE_PET))
.build();
public static class PowerPlayClubItem
public interface PowerPlayClubItem
{
private final String _prize;
private final ItemStack _display;
private final boolean _isPet;
private final PetType _petType;
// The name of the Power Play Club prize to be shown as lore in Carl's GUI
String getPrizeName();
// Give the player this reward
void reward(Player player);
}
PowerPlayClubItem(String prize, ItemStack display)
private static class UnknownSalesPackageItem implements PowerPlayClubItem
{
private static final DonationManager _donationManager = Managers.require(DonationManager.class);
private final String _name;
UnknownSalesPackageItem(String name)
{
_prize = prize;
_display = display;
_isPet = false;
_petType = null;
_name = name;
}
PowerPlayClubItem(PetType prize, ItemStack display)
@Override
public String getPrizeName()
{
_prize = prize.getName();
_display = display;
_isPet = true;
_petType = prize;
return _name;
}
public String getPrize()
@Override
public void reward(Player player)
{
return _prize;
_donationManager.Get(player).addOwnedUnknownSalesPackage(_name);
}
}
private static class PetItem implements PowerPlayClubItem
{
private final PetType _type;
PetItem(PetType type)
{
_type = type;
}
public ItemStack getDisplay()
@Override
public String getPrizeName()
{
return _display;
return _type.getName() + " Pet";
}
public boolean isPet()
@Override
public void reward(Player player)
{
return _isPet;
}
public PetType getPetType()
{
return _petType;
PetManager petManager = Managers.get(PetManager.class);
if (petManager != null)
{
PetClient client = petManager.Get(player);
if (!client.getPets().containsKey(_type))
{
client.getPets().put(_type, _type.getName());
}
}
}
}

View File

@ -1,42 +0,0 @@
package mineplex.core.powerplayclub.event;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import mineplex.core.pet.PetType;
public class PowerPlayRewardPetEvent extends Event
{
private static final HandlerList handlers = new HandlerList();
private final Player _player;
private final PetType _petType;
public PowerPlayRewardPetEvent(Player player, PetType petType)
{
_player = player;
_petType = petType;
}
public Player getPlayer()
{
return _player;
}
public PetType getPetType()
{
return _petType;
}
public HandlerList getHandlers()
{
return handlers;
}
public static HandlerList getHandlerList()
{
return handlers;
}
}