Custom pets

This commit is contained in:
LCastr0 2017-03-13 10:33:23 -03:00
parent 441e2ab30f
commit 137220d58f
8 changed files with 411 additions and 11 deletions

View File

@ -21,7 +21,6 @@ import org.bukkit.Material;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
@ -37,10 +36,10 @@ import mineplex.core.cosmetic.ui.button.PetButton;
import mineplex.core.cosmetic.ui.button.RenamePetButton;
import mineplex.core.cosmetic.ui.button.activate.ActivatePetButton;
import mineplex.core.cosmetic.ui.button.deactivate.DeactivatePetButton;
import mineplex.core.cosmetic.ui.page.custompet.CustomPetBase;
import mineplex.core.donation.DonationManager;
import mineplex.core.pet.PetExtra;
import mineplex.core.pet.PetType;
import mineplex.core.shop.item.IButton;
import mineplex.core.shop.item.ShopItem;
import mineplex.core.shop.page.AnvilContainer;
import mineplex.core.shop.page.ShopPageBase;
@ -63,7 +62,7 @@ public class PetPage extends ShopPageBase<CosmeticManager, CosmeticShop>
for (PetType pet : pets)
{
List<String> itemLore = new ArrayList<String>();
List<String> itemLore = new ArrayList<>();
itemLore.add(C.cBlack);
if (pet.getLore().isPresent())
@ -232,7 +231,7 @@ public class PetPage extends ShopPageBase<CosmeticManager, CosmeticShop>
slot += 2;
}
slot = 49;
slot = 48;
for (PetExtra petExtra : PetExtra.values())
{
List<String> itemLore = new ArrayList<String>();
@ -255,13 +254,13 @@ public class PetPage extends ShopPageBase<CosmeticManager, CosmeticShop>
slot++;
}
addButton(4, new ShopItem(Material.BED, C.cGray + " \u21FD Go Back", new String[]{}, 1, false), new IButton()
{
public void onClick(Player player, ClickType clickType)
{
getShop().openPageForPlayer(getPlayer(), new Menu(getPlugin(), getShop(), getClientManager(), getDonationManager(), player));
}
});
// Custom pet
addButton(50, new ShopItem(Material.GLASS, C.cGreen + "Custom", new String[]{}, 1, false), (player, clickType) ->
getShop().openPageForPlayer(getPlayer(), new CustomPetBase(getPlugin(), getShop(), getClientManager(), getDonationManager(), "Custom Pet", player)));
addButton(4, new ShopItem(Material.BED, C.cGray + " \u21FD Go Back", new String[]{}, 1, false), (player, clickType) ->
getShop().openPageForPlayer(getPlayer(), new Menu(getPlugin(), getShop(), getClientManager(), getDonationManager(), player)));
}
public void purchasePet(final Player player, final PetType petType)

View File

@ -0,0 +1,62 @@
package mineplex.core.cosmetic.ui.page.custompet;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import mineplex.core.account.CoreClientManager;
import mineplex.core.common.util.C;
import mineplex.core.cosmetic.CosmeticManager;
import mineplex.core.cosmetic.ui.CosmeticShop;
import mineplex.core.cosmetic.ui.page.GadgetPage;
import mineplex.core.cosmetic.ui.page.Menu;
import mineplex.core.donation.DonationManager;
import mineplex.core.pet.custom.CustomPet;
import mineplex.core.pet.custom.CustomPetAgeable;
import mineplex.core.shop.item.ShopItem;
public class CustomPetAge extends GadgetPage
{
public CustomPetAge(CosmeticManager plugin, CosmeticShop shop, CoreClientManager clientManager, DonationManager donationManager, String name, Player player)
{
super(plugin, shop, clientManager, donationManager, name, player);
}
@Override
protected void buildPage()
{
// 20
// 24
CustomPet customPet = CustomPet.getCustomPet(getPlayer());
if (customPet == null)
{
CustomPet.removeCustomPet(getPlayer());
getPlayer().closeInventory();
return;
}
if (!(customPet instanceof CustomPetAgeable))
{
CustomPet.removeCustomPet(getPlayer());
getPlayer().closeInventory();
return;
}
CustomPetAgeable customPetAgeable = (CustomPetAgeable) customPet;
addButton(20, new ShopItem(Material.SEEDS, "Baby", 1, false), (player, clickType) ->
{
customPetAgeable.setBaby(true);
getShop().openPageForPlayer(getPlayer(), customPet.createNextStep(getPlugin(), getShop(), getClientManager(), getDonationManager()));
});
addButton(4, new ShopItem(Material.BED, C.cGray + " \u21FD Go Back", new String[]{}, 1, false), (player, clickType) ->
{
getShop().openPageForPlayer(getPlayer(), new Menu(getPlugin(), getShop(), getClientManager(), getDonationManager(), player));
CustomPet.removeCustomPet(player);
});
}
}

View File

@ -0,0 +1,56 @@
package mineplex.core.cosmetic.ui.page.custompet;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import mineplex.core.account.CoreClientManager;
import mineplex.core.common.util.C;
import mineplex.core.cosmetic.CosmeticManager;
import mineplex.core.cosmetic.ui.CosmeticShop;
import mineplex.core.cosmetic.ui.page.GadgetPage;
import mineplex.core.cosmetic.ui.page.Menu;
import mineplex.core.donation.DonationManager;
import mineplex.core.pet.custom.CustomPet;
import mineplex.core.shop.item.ShopItem;
public class CustomPetBase extends GadgetPage
{
public CustomPetBase(CosmeticManager plugin, CosmeticShop shop, CoreClientManager clientManager, DonationManager donationManager, String name, Player player)
{
super(plugin, shop, clientManager, donationManager, name, player);
}
@Override
protected void buildPage()
{
int slot = 10;
for (CustomPet.CustomPetType customPetType : CustomPet.CustomPetType.values())
{
addButton(slot, new ShopItem(customPetType.getMaterial(), customPetType.getData(), customPetType.getName(), new String[]{}, 1, false, false), (player, clickType) ->
{
CustomPet customPet = CustomPet.getCustomPet(player);
if (customPet == null)
{
customPet = customPetType.getCustomPet(player);
}
getShop().openPageForPlayer(getPlayer(), customPet.createNextStep(getPlugin(), getShop(), getClientManager(), getDonationManager()));
});
slot++;
if (slot == 17)
slot += 2;
}
addButton(4, new ShopItem(Material.BED, C.cGray + " \u21FD Go Back", new String[]{}, 1, false), (player, clickType) ->
{
getShop().openPageForPlayer(getPlayer(), new Menu(getPlugin(), getShop(), getClientManager(), getDonationManager(), player));
CustomPet.removeCustomPet(player);
});
}
}

View File

@ -237,6 +237,7 @@ import mineplex.core.mount.MountManager;
import mineplex.core.mount.event.MountActivateEvent;
import mineplex.core.packethandler.PacketHandler;
import mineplex.core.pet.PetManager;
import mineplex.core.pet.custom.CustomPet;
import mineplex.core.preferences.PreferencesManager;
import mineplex.core.projectile.ProjectileManager;
import mineplex.core.treasure.TreasureManager;
@ -1000,6 +1001,9 @@ public class GadgetManager extends MiniPlugin
event.getPlayer().setWalkSpeed(0.2f);
event.getPlayer().setFlySpeed(0.1f);
_soulManager.giveSoul(event.getPlayer());
// Removes custom pet
CustomPet.removeCustomPet(event.getPlayer());
}
@EventHandler

View File

@ -0,0 +1,124 @@
package mineplex.core.pet.custom;
import java.util.HashMap;
import java.util.Map;
import org.bukkit.Material;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import mineplex.core.account.CoreClientManager;
import mineplex.core.cosmetic.CosmeticManager;
import mineplex.core.cosmetic.ui.CosmeticShop;
import mineplex.core.cosmetic.ui.page.GadgetPage;
import mineplex.core.disguise.disguises.DisguiseBase;
import mineplex.core.donation.DonationManager;
public abstract class CustomPet
{
private static Map<Player, CustomPet> _customPet = new HashMap<>();
protected Player _player;
protected EntityType _entityType;
protected DisguiseBase _disguiseBase;
protected int _step = 0;
private String _name;
public CustomPet(Player player, EntityType entityType)
{
_player = player;
_entityType = entityType;
_customPet.put(player, this);
}
public void spawn(Entity entity)
{
// TODO
onSpawn(entity);
}
public abstract void onSpawn(Entity entity);
public abstract GadgetPage createNextStep(CosmeticManager plugin, CosmeticShop shop, CoreClientManager clientManager, DonationManager donationManager);
public DisguiseBase getDisguiseBase()
{
return _disguiseBase;
}
public void setName(String name)
{
_name = name;
}
public String getName()
{
return _name;
}
public static CustomPet getCustomPet(Player player)
{
if (_customPet.containsKey(player))
{
return _customPet.get(player);
}
return null;
}
public static void removeCustomPet(Player player)
{
if (_customPet.containsKey(player))
{
_customPet.remove(player);
}
}
public enum CustomPetType
{
ZOMBIE("Zombie", Material.GLASS);
private String _name;
private Material _material;
private byte _data;
CustomPetType(String name, Material material, byte data)
{
_name = name;
_material = material;
_data = data;
}
CustomPetType(String name, Material material)
{
this(name, material, (byte) 0);
}
public String getName()
{
return _name;
}
public Material getMaterial()
{
return _material;
}
public byte getData()
{
return _data;
}
public CustomPet getCustomPet(Player player)
{
switch (this)
{
case ZOMBIE:
return new CustomPetZombie(player);
default:
return new CustomPetZombie(player);
}
}
}
}

View File

@ -0,0 +1,25 @@
package mineplex.core.pet.custom;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
public abstract class CustomPetAgeable extends CustomPet
{
private boolean _baby = false;
public CustomPetAgeable(Player player, EntityType entityType)
{
super(player, entityType);
}
public void setBaby(boolean baby)
{
_baby = baby;
}
protected boolean isBaby()
{
return _baby;
}
}

View File

@ -0,0 +1,59 @@
package mineplex.core.pet.custom;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
public abstract class CustomPetEquipment extends CustomPetAgeable
{
private ItemStack _helmet;
private ItemStack _chestplate;
private ItemStack _leggings;
private ItemStack _boots;
public CustomPetEquipment(Player player, EntityType entityType)
{
super(player, entityType);
}
public void setHelmet(ItemStack helmet)
{
_helmet = helmet;
}
public void setChestplate(ItemStack chestplate)
{
_chestplate = chestplate;
}
public void setLeggings(ItemStack leggings)
{
_leggings = leggings;
}
public void setBoots(ItemStack boots)
{
_boots = boots;
}
public ItemStack getHelmet()
{
return _helmet;
}
public ItemStack getChestplate()
{
return _chestplate;
}
public ItemStack getLeggings()
{
return _leggings;
}
public ItemStack getBoots()
{
return _boots;
}
}

View File

@ -0,0 +1,71 @@
package mineplex.core.pet.custom;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import mineplex.core.account.CoreClientManager;
import mineplex.core.cosmetic.CosmeticManager;
import mineplex.core.cosmetic.ui.CosmeticShop;
import mineplex.core.cosmetic.ui.page.GadgetPage;
import mineplex.core.cosmetic.ui.page.custompet.CustomPetAge;
import mineplex.core.disguise.DisguiseFactory;
import mineplex.core.disguise.disguises.DisguiseZombie;
import mineplex.core.donation.DonationManager;
public class CustomPetZombie extends CustomPetEquipment
{
public CustomPetZombie(Player player)
{
super(player, EntityType.ZOMBIE);
}
@Override
public void onSpawn(Entity entity)
{
// TODO
_disguiseBase = DisguiseFactory.createDisguise(entity, _entityType);
DisguiseZombie disguiseZombie = (DisguiseZombie) _disguiseBase;
disguiseZombie.setBaby(isBaby());
if (getHelmet() != null)
{
disguiseZombie.setHelmet(getHelmet());
}
if (getChestplate() != null)
{
disguiseZombie.setChestplate(getChestplate());
}
if (getLeggings() != null)
{
disguiseZombie.setLeggings(getLeggings());
}
if (getBoots() != null)
{
disguiseZombie.setBoots(getBoots());
}
if (getName() != null)
{
disguiseZombie.setCustomNameVisible(true);
disguiseZombie.setName(getName());
}
else
{
disguiseZombie.setCustomNameVisible(false);
}
}
@Override
public GadgetPage createNextStep(CosmeticManager plugin, CosmeticShop shop, CoreClientManager clientManager, DonationManager donationManager)
{
switch (_step)
{
case 0:
_step++;
return new CustomPetAge(plugin, shop, clientManager, donationManager, "Zombie Age", _player);
default:
_step++;
return new CustomPetAge(plugin, shop, clientManager, donationManager, "Zombie Age", _player);
}
}
}