Add support for whether a player owns a given pet
This commit is contained in:
parent
9f134b5772
commit
14daa939e3
@ -8,8 +8,12 @@ import java.util.function.Consumer;
|
|||||||
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
|
||||||
import mineplex.core.account.CoreClient;
|
import mineplex.core.account.CoreClient;
|
||||||
import mineplex.core.common.util.UtilServer;
|
import mineplex.core.common.util.UtilServer;
|
||||||
|
import mineplex.core.pet.PetClient;
|
||||||
|
import mineplex.core.pet.repository.token.ClientPetTokenWrapper;
|
||||||
import mineplex.core.powerplayclub.PowerPlayData;
|
import mineplex.core.powerplayclub.PowerPlayData;
|
||||||
import mineplex.core.shop.ShopBase;
|
import mineplex.core.shop.ShopBase;
|
||||||
import mineplex.core.shop.page.ShopPageBase;
|
import mineplex.core.shop.page.ShopPageBase;
|
||||||
@ -21,6 +25,7 @@ public class SupportShop extends ShopBase<CustomerSupport>
|
|||||||
{
|
{
|
||||||
private LinkedTemporaryItem<Integer, List<BonusEntry>> _bonusLog;
|
private LinkedTemporaryItem<Integer, List<BonusEntry>> _bonusLog;
|
||||||
private LinkedTemporaryItem<Integer, PowerPlayData> _powerPlayData;
|
private LinkedTemporaryItem<Integer, PowerPlayData> _powerPlayData;
|
||||||
|
private LinkedTemporaryItem<Integer, PetClient> _petClients;
|
||||||
|
|
||||||
public SupportShop(CustomerSupport plugin)
|
public SupportShop(CustomerSupport plugin)
|
||||||
{
|
{
|
||||||
@ -28,6 +33,7 @@ public class SupportShop extends ShopBase<CustomerSupport>
|
|||||||
|
|
||||||
_bonusLog = new LinkedTemporaryItem<>();
|
_bonusLog = new LinkedTemporaryItem<>();
|
||||||
_powerPlayData = new LinkedTemporaryItem<>();
|
_powerPlayData = new LinkedTemporaryItem<>();
|
||||||
|
_petClients = new LinkedTemporaryItem<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void handleOpen(Player caller, CoreClient target)
|
public void handleOpen(Player caller, CoreClient target)
|
||||||
@ -36,8 +42,12 @@ public class SupportShop extends ShopBase<CustomerSupport>
|
|||||||
// button will just be there since the HomePage
|
// button will just be there since the HomePage
|
||||||
// knows not to put it in.
|
// knows not to put it in.
|
||||||
loadBonusLog(caller, target.getAccountId(), (bS) ->
|
loadBonusLog(caller, target.getAccountId(), (bS) ->
|
||||||
loadPowerPlay(caller, target.getAccountId(), (pS) ->
|
loadPowerPlay(caller, target.getAccountId(), (ppcS) ->
|
||||||
openPageAsync(caller, new SupportHomePage(getPlugin(), this, caller, target))));
|
loadPetClient(caller, target, (petS) ->
|
||||||
|
openPageAsync(caller, new SupportHomePage(getPlugin(), this, caller, target))
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void openPageAsync(Player player, SupportPage page)
|
public void openPageAsync(Player player, SupportPage page)
|
||||||
@ -92,16 +102,34 @@ public class SupportShop extends ShopBase<CustomerSupport>
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void loadPetClient(Player caller, CoreClient client, Consumer<Boolean> callback)
|
||||||
|
{
|
||||||
|
Gson gson = new Gson();
|
||||||
|
ClientPetTokenWrapper token;
|
||||||
|
String response = getPlugin().getClientManager().getRepository().getClientByUUID(client.getUniqueId());
|
||||||
|
token = gson.fromJson(response, ClientPetTokenWrapper.class);
|
||||||
|
|
||||||
|
PetClient petClient = new PetClient();
|
||||||
|
petClient.load(token.DonorToken);
|
||||||
|
|
||||||
|
_petClients.put(caller, client.getAccountId(), petClient);
|
||||||
|
callback.accept(true);
|
||||||
|
}
|
||||||
|
|
||||||
public Map<Integer, List<BonusEntry>> getBonusLog() { return _bonusLog.getPrimaryMap(); }
|
public Map<Integer, List<BonusEntry>> getBonusLog() { return _bonusLog.getPrimaryMap(); }
|
||||||
|
|
||||||
public Map<Integer, PowerPlayData> getPowerPlayData() { return _powerPlayData.getPrimaryMap(); }
|
public Map<Integer, PowerPlayData> getPowerPlayData() { return _powerPlayData.getPrimaryMap(); }
|
||||||
|
|
||||||
|
public Map<Integer, PetClient> getPetClients() { return _petClients.getPrimaryMap(); }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void closeShopForPlayer(Player player)
|
protected void closeShopForPlayer(Player player)
|
||||||
{
|
{
|
||||||
super.closeShopForPlayer(player);
|
super.closeShopForPlayer(player);
|
||||||
|
|
||||||
_bonusLog.remove(player);
|
_bonusLog.remove(player);
|
||||||
|
_powerPlayData.remove(player);
|
||||||
|
_petClients.remove(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -10,7 +10,6 @@ import org.bukkit.inventory.meta.ItemMeta;
|
|||||||
|
|
||||||
import mineplex.core.account.CoreClient;
|
import mineplex.core.account.CoreClient;
|
||||||
import mineplex.core.common.util.C;
|
import mineplex.core.common.util.C;
|
||||||
import mineplex.core.itemstack.ItemBuilder;
|
|
||||||
import mineplex.core.pet.PetType;
|
import mineplex.core.pet.PetType;
|
||||||
import mineplex.core.pet.repository.token.PetChangeToken;
|
import mineplex.core.pet.repository.token.PetChangeToken;
|
||||||
import mineplex.core.shop.item.ShopItem;
|
import mineplex.core.shop.item.ShopItem;
|
||||||
@ -32,16 +31,28 @@ public class SupportPetPage extends SupportPage
|
|||||||
buildPage();
|
buildPage();
|
||||||
}
|
}
|
||||||
|
|
||||||
private ItemStack getPetIcon(PetType petType)
|
private ItemStack getPetIcon(PetType petType, boolean owned)
|
||||||
{
|
{
|
||||||
ItemStack item = petType.getDisplayItem().clone();
|
ItemStack item = petType.getDisplayItem().clone();
|
||||||
|
|
||||||
ItemMeta meta = item.getItemMeta();
|
ItemMeta meta = item.getItemMeta();
|
||||||
meta.setDisplayName(C.cGreenB + petType.getName());
|
|
||||||
meta.setLore(Arrays.asList(
|
if (owned)
|
||||||
C.mBody + "Click to give this",
|
{
|
||||||
C.mBody + "player a " + C.cYellow + petType.getName() + " Pet"
|
meta.setDisplayName(C.cRedB + petType.getName());
|
||||||
));
|
meta.setLore(Arrays.asList(
|
||||||
|
C.cYellow + _target.getName() + C.mBody + " already",
|
||||||
|
C.mBody + "owns a " + C.cYellow + petType.getName() + " Pet" + C.mBody + "!"
|
||||||
|
));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
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);
|
item.setItemMeta(meta);
|
||||||
|
|
||||||
@ -50,30 +61,43 @@ public class SupportPetPage extends SupportPage
|
|||||||
|
|
||||||
private void addPet(PetType petType, int slot)
|
private void addPet(PetType petType, int slot)
|
||||||
{
|
{
|
||||||
addButton(slot, getPetIcon(petType), (p, c) ->
|
// Owns the pet
|
||||||
|
if (getShop().getPetClients().get(_target.getAccountId()).getPets().containsKey(petType))
|
||||||
{
|
{
|
||||||
PetChangeToken token = new PetChangeToken();
|
addItem(slot, getPetIcon(petType, true));
|
||||||
token.AccountId = _target.getAccountId();
|
addGlow(slot);
|
||||||
token.Name = _target.getName();
|
}
|
||||||
token.PetType = petType.toString();
|
else
|
||||||
token.PetName = petType.getName();
|
{
|
||||||
|
addButton(slot, getPetIcon(petType, false), (p, c) ->
|
||||||
getPlugin().getPetRepository().AddPet(token);
|
|
||||||
|
|
||||||
getPlugin().getInventoryManager().addItemToInventoryForOffline((success) ->
|
|
||||||
{
|
{
|
||||||
if (success)
|
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) ->
|
||||||
{
|
{
|
||||||
playSuccess();
|
if (success)
|
||||||
message("Successfully gave " + C.cYellow + petType.getName() + " Pet" + C.mBody + " to " + C.cYellow + _target.getName());
|
{
|
||||||
}
|
getShop().loadPetClient(getPlayer(), _target, (petSuccess) ->
|
||||||
else
|
{
|
||||||
{
|
playSuccess();
|
||||||
playFail();
|
message("Successfully gave " + C.cYellow + petType.getName() + " Pet" + C.mBody + " to " + C.cYellow + _target.getName());
|
||||||
message("Unable to give " + C.cYellow + petType.getName() + " Pet" + C.mBody + " to " + C.cYellow + _target.getName() + C.mBody + ", please try again later.");
|
refresh();
|
||||||
}
|
});
|
||||||
}, _target.getAccountId(), petType.toString(), 1);
|
}
|
||||||
});
|
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()
|
private LinkedList<PetType> getPetTypeList()
|
||||||
|
Loading…
Reference in New Issue
Block a user