Allow pets to be given from the support server
This commit is contained in:
parent
60fad6316b
commit
6d9d42cfdd
@ -1,6 +1,5 @@
|
||||
package mineplex.staffServer.salespackage;
|
||||
|
||||
import mineplex.staffServer.salespackage.salespackages.*;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
@ -10,10 +9,32 @@ import mineplex.core.common.jsonchat.JsonMessage;
|
||||
import mineplex.core.common.util.NautHashMap;
|
||||
import mineplex.core.donation.DonationManager;
|
||||
import mineplex.core.inventory.InventoryManager;
|
||||
import mineplex.core.pet.PetFactory;
|
||||
import mineplex.core.pet.repository.PetRepository;
|
||||
import mineplex.core.powerplayclub.PowerPlayClubRepository;
|
||||
import mineplex.core.stats.StatsManager;
|
||||
import mineplex.staffServer.salespackage.command.DisplayPackageCommand;
|
||||
import mineplex.staffServer.salespackage.command.Sales;
|
||||
import mineplex.staffServer.salespackage.salespackages.AncientChest;
|
||||
import mineplex.staffServer.salespackage.salespackages.ApplyKits;
|
||||
import mineplex.staffServer.salespackage.salespackages.ClanBannerEditor;
|
||||
import mineplex.staffServer.salespackage.salespackages.ClanBannerUsage;
|
||||
import mineplex.staffServer.salespackage.salespackages.Coins;
|
||||
import mineplex.staffServer.salespackage.salespackages.DefaultRank;
|
||||
import mineplex.staffServer.salespackage.salespackages.FreedomChest;
|
||||
import mineplex.staffServer.salespackage.salespackages.HauntedChest;
|
||||
import mineplex.staffServer.salespackage.salespackages.IlluminatedChest;
|
||||
import mineplex.staffServer.salespackage.salespackages.LifetimeHero;
|
||||
import mineplex.staffServer.salespackage.salespackages.LifetimeLegend;
|
||||
import mineplex.staffServer.salespackage.salespackages.LifetimeTitan;
|
||||
import mineplex.staffServer.salespackage.salespackages.LifetimeUltra;
|
||||
import mineplex.staffServer.salespackage.salespackages.MythicalChest;
|
||||
import mineplex.staffServer.salespackage.salespackages.OldChest;
|
||||
import mineplex.staffServer.salespackage.salespackages.OmegaChest;
|
||||
import mineplex.staffServer.salespackage.salespackages.Pet;
|
||||
import mineplex.staffServer.salespackage.salespackages.PowerPlayClub;
|
||||
import mineplex.staffServer.salespackage.salespackages.RuneAmplifier;
|
||||
import mineplex.staffServer.salespackage.salespackages.SalesPackageBase;
|
||||
|
||||
public class SalesPackageManager extends MiniPlugin
|
||||
{
|
||||
@ -22,6 +43,8 @@ public class SalesPackageManager extends MiniPlugin
|
||||
private InventoryManager _inventoryManager;
|
||||
private StatsManager _statsManager;
|
||||
private PowerPlayClubRepository _powerPlayRepo;
|
||||
private PetRepository _petRepo;
|
||||
private PetFactory _petFactory;
|
||||
|
||||
private NautHashMap<String, SalesPackageBase> _salesPackages = new NautHashMap<String, SalesPackageBase>();
|
||||
|
||||
@ -34,6 +57,10 @@ public class SalesPackageManager extends MiniPlugin
|
||||
_inventoryManager = inventoryManager;
|
||||
_statsManager = statsManager;
|
||||
_powerPlayRepo = powerPlayRepo;
|
||||
|
||||
_petRepo = new PetRepository(plugin, plugin.getConfig().getString("webServer"));
|
||||
_petFactory = new PetFactory(_petRepo);
|
||||
|
||||
|
||||
//Strutt20 asked me to remove some of the stuff from the menu
|
||||
AddSalesPackage(new Coins(this, 5000));
|
||||
@ -65,6 +92,11 @@ public class SalesPackageManager extends MiniPlugin
|
||||
AddSalesPackage(new PowerPlayClub(this, true));
|
||||
AddSalesPackage(new OmegaChest(this));
|
||||
AddSalesPackage(new HauntedChest(this));
|
||||
|
||||
for (mineplex.core.pet.Pet pet : _petFactory.GetPets())
|
||||
{
|
||||
AddSalesPackage(new Pet(this, pet.getName(), pet.getPetType()));
|
||||
}
|
||||
}
|
||||
|
||||
private void AddSalesPackage(SalesPackageBase salesPackage)
|
||||
@ -98,6 +130,16 @@ public class SalesPackageManager extends MiniPlugin
|
||||
{
|
||||
return _powerPlayRepo;
|
||||
}
|
||||
|
||||
public PetRepository getPetRepo()
|
||||
{
|
||||
return _petRepo;
|
||||
}
|
||||
|
||||
public PetFactory getPetFactory()
|
||||
{
|
||||
return _petFactory;
|
||||
}
|
||||
|
||||
public void help(Player player)
|
||||
{
|
||||
@ -115,6 +157,7 @@ public class SalesPackageManager extends MiniPlugin
|
||||
JsonMessage chestBuilder = new JsonMessage("Chest Packages : ").color("blue");
|
||||
JsonMessage clanBuilder = new JsonMessage("Clan Packages : ").color("blue");
|
||||
JsonMessage powerPlayBuilder = new JsonMessage("Power Play Club Packages : ").color("blue");
|
||||
JsonMessage petBuilder = new JsonMessage("Pet Packages : ").color("blue");
|
||||
|
||||
for (SalesPackageBase salesPackage : _salesPackages.values())
|
||||
{
|
||||
@ -134,6 +177,10 @@ public class SalesPackageManager extends MiniPlugin
|
||||
{
|
||||
powerPlayBuilder = powerPlayBuilder.extra("[").color("gray").extra(salesPackage.getName()).color("green").click("run_command", "/display " + playerName + " " + salesPackage.getName()).extra("] ").color("gray");
|
||||
}
|
||||
else if (salesPackage instanceof Pet)
|
||||
{
|
||||
petBuilder = petBuilder.extra("[").color("gray").extra(salesPackage.getName()).color("green").click("run_command", "/display " + playerName + " " + salesPackage.getName()).extra("] ").color("gray");
|
||||
}
|
||||
else
|
||||
{
|
||||
packageBuilder = packageBuilder.extra("[").color("gray").extra(salesPackage.getName()).color("green").click("run_command", "/display " + playerName + " " + salesPackage.getName()).extra("] ").color("gray");
|
||||
@ -145,6 +192,7 @@ public class SalesPackageManager extends MiniPlugin
|
||||
packageBuilder.sendToPlayer(caller);
|
||||
clanBuilder.sendToPlayer(caller);
|
||||
powerPlayBuilder.sendToPlayer(caller);
|
||||
petBuilder.sendToPlayer(caller);
|
||||
}
|
||||
|
||||
public StatsManager getStatsManager()
|
||||
|
@ -0,0 +1,102 @@
|
||||
package mineplex.staffServer.salespackage.command;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
|
||||
import mineplex.core.command.CommandBase;
|
||||
import mineplex.core.common.Rank;
|
||||
import mineplex.core.common.util.Callback;
|
||||
import mineplex.core.common.util.F;
|
||||
import mineplex.core.pet.Pet;
|
||||
import mineplex.core.pet.PetClient;
|
||||
import mineplex.core.pet.repository.token.ClientPetTokenWrapper;
|
||||
import mineplex.core.pet.repository.token.PetChangeToken;
|
||||
import mineplex.staffServer.salespackage.SalesPackageManager;
|
||||
|
||||
public class PetCommand extends CommandBase<SalesPackageManager>
|
||||
{
|
||||
public PetCommand(SalesPackageManager plugin)
|
||||
{
|
||||
super(plugin, Rank.MODERATOR, "pet");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void Execute(final Player caller, String[] args)
|
||||
{
|
||||
if (args.length < 2)
|
||||
return;
|
||||
|
||||
final String playerName = args[0];
|
||||
int petId = Integer.parseInt(args[1]);
|
||||
|
||||
if ((petId < 0 || petId >= EntityType.values().length) || Plugin.getPetFactory().getPet(EntityType.values()[petId]) == null)
|
||||
{
|
||||
caller.sendMessage(F.main(Plugin.getName(), "You have entered an invalid Pet Type."));
|
||||
return;
|
||||
}
|
||||
|
||||
final EntityType petType = EntityType.values()[petId];
|
||||
|
||||
Plugin.getClientManager().loadClientByName(playerName, client ->
|
||||
{
|
||||
final UUID uuid = Plugin.getClientManager().loadUUIDFromDB(playerName);
|
||||
|
||||
if (uuid != null)
|
||||
{
|
||||
final Callback<PetClient> clientCallback = new Callback<PetClient>()
|
||||
{
|
||||
public void run(PetClient petClient)
|
||||
{
|
||||
if (petClient.getPets().containsKey(petType))
|
||||
{
|
||||
caller.sendMessage(F.main(Plugin.getName(), F.elem(playerName) + " already has that Pet!"));
|
||||
}
|
||||
else
|
||||
{
|
||||
Pet pet = Plugin.getPetFactory().getPet(petType);
|
||||
PetChangeToken token = new PetChangeToken();
|
||||
token.AccountId = client.getAccountId();
|
||||
token.Name = playerName;
|
||||
token.PetType = petType.toString();
|
||||
token.PetName = pet.getName();
|
||||
|
||||
Plugin.getPetRepo().AddPet(token);
|
||||
Plugin.getInventoryManager().addItemToInventoryForOffline(success ->
|
||||
{
|
||||
if (success)
|
||||
{
|
||||
caller.sendMessage(F.main(Plugin.getName(), F.elem(playerName) + " has been given their Pet!"));
|
||||
}
|
||||
else
|
||||
{
|
||||
caller.sendMessage(F.main(Plugin.getName(), "Attempt to give Pet has failed!"));
|
||||
}
|
||||
}, client.getAccountId(), petType.toString(), 1);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Plugin.runAsync(() ->
|
||||
{
|
||||
Gson gson = new Gson();
|
||||
ClientPetTokenWrapper token = null;
|
||||
String response = Plugin.getClientManager().getRepository().getClientByUUID(uuid);
|
||||
token = gson.fromJson(response, ClientPetTokenWrapper.class);
|
||||
|
||||
PetClient petClient = new PetClient();
|
||||
petClient.load(token.DonorToken);
|
||||
|
||||
clientCallback.run(petClient);
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
caller.sendMessage(F.main(Plugin.getName(), "Couldn't find " + playerName + "'s account!"));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -24,6 +24,7 @@ public class Sales extends MultiCommandBase<SalesPackageManager>
|
||||
AddCommand(new LifetimeTitanCommand(plugin));
|
||||
AddCommand(new KitsCommand(plugin));
|
||||
AddCommand(new PowerPlayCommand(plugin));
|
||||
AddCommand(new PetCommand(plugin));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -0,0 +1,26 @@
|
||||
package mineplex.staffServer.salespackage.salespackages;
|
||||
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import mineplex.staffServer.salespackage.SalesPackageManager;
|
||||
|
||||
public class Pet extends SalesPackageBase
|
||||
{
|
||||
private String _petName;
|
||||
private EntityType _petType;
|
||||
|
||||
public Pet(SalesPackageManager manager, String petName, EntityType petType)
|
||||
{
|
||||
super(manager, "1 " + petName + " Pet");
|
||||
_petName = petName;
|
||||
_petType = petType;
|
||||
}
|
||||
|
||||
public void displayToAgent(Player agent, String playerName)
|
||||
{
|
||||
addButton(agent, "/sales pet " + playerName + " " + _petType.ordinal(), "Give 1 " + _petName + " Pet.");
|
||||
agent.sendMessage(" ");
|
||||
addBackButton(agent, playerName);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user