add PetPage and CustomerSupport#getPetRepository

This commit is contained in:
Spencer 2018-01-06 01:03:13 -05:00 committed by Alexander Meech
parent cf515036f7
commit d53222e243
4 changed files with 110 additions and 0 deletions

View File

@ -40,6 +40,11 @@ public class MultiPageManager<ItemType>
this.ELEMENTS_PER_PAGE = elements;
}
public int getElementsPerPage()
{
return ELEMENTS_PER_PAGE;
}
public void setPage(int page)
{
_page = page;

View File

@ -45,6 +45,7 @@ import mineplex.core.donation.Donor;
import mineplex.core.donation.repository.token.CoinTransactionToken;
import mineplex.core.donation.repository.token.TransactionToken;
import mineplex.core.inventory.InventoryManager;
import mineplex.core.pet.repository.PetRepository;
import mineplex.core.powerplayclub.PowerPlayClubRepository;
import mineplex.core.powerplayclub.PowerPlayData;
import mineplex.core.stats.PlayerStats;
@ -72,6 +73,7 @@ public class CustomerSupport extends MiniPlugin implements ResultSetCallable
private SupportRepository _repository;
private PowerPlayClubRepository _powerPlayRepo;
private PetRepository _petRepository;
private NautHashMap<Integer, List<String>> _accountBonusLog = new NautHashMap<>();
@ -87,6 +89,7 @@ public class CustomerSupport extends MiniPlugin implements ResultSetCallable
_repository = new SupportRepository();
_powerPlayRepo = powerPlayRepo;
_inventoryManager = Managers.require(InventoryManager.class);
_petRepository = new PetRepository();
_allowWeatherChange = true;
Bukkit.getWorlds().get(0).setStorm(false);
@ -135,6 +138,11 @@ public class CustomerSupport extends MiniPlugin implements ResultSetCallable
return _powerPlayRepo;
}
public PetRepository getPetRepository()
{
return _petRepository;
}
@EventHandler
public void Join(PlayerJoinEvent event)
{

View File

@ -13,6 +13,7 @@ import mineplex.core.shop.item.ShopItem;
import mineplex.staffServer.customerSupport.CustomerSupport;
import mineplex.staffServer.ui.chest.SupportChestPage;
import mineplex.staffServer.ui.currency.SupportCurrencyPage;
import mineplex.staffServer.ui.pet.SupportPetPage;
import mineplex.staffServer.ui.ppc.SupportPowerplayPage;
import mineplex.staffServer.ui.rank.SupportRankBonusPage;
import mineplex.staffServer.ui.rank.SupportRankListPage;
@ -106,5 +107,10 @@ public class SupportHomePage extends SupportPage
C.mBody + "and monthly bonus",
C.mBody +"items to " + C.cYellow + _target.getName()
}, 1, false, true), SupportRankListPage.class);
buildPageButton(getSlotIndex(2, 4), new ShopItem(Material.BONE, "Pets", new String[] {
C.mBody + "Click to give pets",
C.mBody + "to " + C.cYellow + _target.getName()
}, 1, false, true), SupportPetPage.class);
}
}

View File

@ -0,0 +1,91 @@
package mineplex.staffServer.ui.pet;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.stream.Collectors;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import mineplex.core.account.CoreClient;
import mineplex.core.common.util.C;
import mineplex.core.itemstack.ItemBuilder;
import mineplex.core.pet.PetType;
import mineplex.core.pet.repository.token.PetChangeToken;
import mineplex.core.shop.item.ShopItem;
import mineplex.core.shop.page.MultiPageManager;
import mineplex.staffServer.customerSupport.CustomerSupport;
import mineplex.staffServer.ui.SupportPage;
import mineplex.staffServer.ui.SupportShop;
public class SupportPetPage extends SupportPage
{
private MultiPageManager<PetType> _multiPageManager;
public SupportPetPage(CustomerSupport plugin, SupportShop shop, Player player, CoreClient target, SupportPage previousPage)
{
super(plugin, shop, player, target, previousPage, "Pets");
_multiPageManager = new MultiPageManager<>(this, this::getPetTypeList, this::addPet);
buildPage();
}
private ItemStack getPetIcon(PetType petType)
{
ItemStack item = petType.getDisplayItem().clone();
ItemMeta meta = item.getItemMeta();
meta.setDisplayName(C.cGreenB + petType.getName());
meta.setLore(Arrays.asList(
C.mBody + "Click to give this",
C.mBody + "player a " + C.cYellow + petType.getName() + " Pet"
));
item.setItemMeta(meta);
return new ShopItem(item, false, true);
}
private void addPet(PetType petType, int slot)
{
addButton(slot, getPetIcon(petType), (p, c) ->
{
PetChangeToken token = new PetChangeToken();
token.AccountId = _target.getAccountId();
token.Name = _target.getName();
token.PetType = petType.toString();
token.PetName = petType.getName();
getPlugin().getPetRepository().AddPet(token);
getPlugin().getInventoryManager().addItemToInventoryForOffline((success) ->
{
if (success)
{
playSuccess();
message("Successfully gave " + C.cYellow + petType.getName() + " Pet" + C.mBody + " to " + C.cYellow + _target.getName());
}
else
{
playFail();
message("Unable to give " + C.cYellow + petType.getName() + " Pet" + C.mBody + " to " + C.cYellow + _target.getName() + C.mBody + ", please try again later.");
}
}, _target.getAccountId(), petType.toString(), 1);
});
}
private LinkedList<PetType> getPetTypeList()
{
return Arrays.stream(PetType.values()).collect(Collectors.toCollection(LinkedList::new));
}
@Override
protected void buildPage()
{
super.buildPage();
_multiPageManager.buildPage();
}
}