Spawns pet

This commit is contained in:
LCastr0 2017-03-14 09:57:34 -03:00
parent 13238eb4ad
commit f5a85f2a54
6 changed files with 68 additions and 42 deletions

View File

@ -0,0 +1,27 @@
package mineplex.core.cosmetic.ui.page.custompet;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import mineplex.core.cosmetic.ui.page.GadgetPage;
import mineplex.core.cosmetic.ui.page.Menu;
import mineplex.core.pet.PetType;
import mineplex.core.shop.item.IButton;
public class ActivateCustomPetButton implements IButton
{
private GadgetPage _page;
public ActivateCustomPetButton(GadgetPage page)
{
_page = page;
}
@Override
public void onClick(Player player, ClickType clickType)
{
_page.playAcceptSound(player);
_page.getPlugin().getPetManager().addPetOwner(player, PetType.CUSTOM, player.getLocation());
_page.getShop().openPageForPlayer(player, new Menu(_page.getPlugin(), _page.getShop(), _page.getClientManager(), _page.getDonationManager(), player));
}
}

View File

@ -25,6 +25,12 @@ public class CustomPetBasePage extends GadgetPage
protected void buildPage()
{
// TODO
// EDIT PET
// DISABLE PET
// RENAME PET
// RESET PET
int slot = 10;
for (CustomPet.CustomPetType customPetType : CustomPet.CustomPetType.values())

View File

@ -7,6 +7,7 @@ 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.button.activate.ActivatePetButton;
import mineplex.core.cosmetic.ui.page.GadgetPage;
import mineplex.core.donation.DonationManager;
import mineplex.core.pet.custom.CustomPet;
@ -40,17 +41,15 @@ public class CustomPetConfirmPage extends GadgetPage
for (int aConfirm : confirm)
{
addButton(aConfirm, confirmItem, (player, clickType) ->
{
// TODO
});
addButton(aConfirm, confirmItem, new ActivateCustomPetButton(this));
}
for (int aCancel : cancel)
{
addButton(aCancel, cancelItem, (player, clickType) ->
{
// TODO
player.closeInventory();
CustomPet.removeCustomPet(player);
});
}

View File

@ -22,6 +22,8 @@ import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPigZombie;
import org.bukkit.entity.Ageable;
import org.bukkit.entity.Blaze;
import org.bukkit.entity.Creature;
import org.bukkit.entity.Creeper;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.PigZombie;
import org.bukkit.entity.Player;
@ -54,7 +56,6 @@ import mineplex.core.common.Rank;
import mineplex.core.common.shape.ShapeWings;
import mineplex.core.common.skin.SkinData;
import mineplex.core.common.util.F;
import mineplex.core.common.util.NautHashMap;
import mineplex.core.common.util.UtilAction;
import mineplex.core.common.util.UtilAlg;
import mineplex.core.common.util.UtilEnt;
@ -72,6 +73,7 @@ import mineplex.core.disguise.disguises.DisguiseZombie;
import mineplex.core.donation.DonationManager;
import mineplex.core.inventory.InventoryManager;
import mineplex.core.itemstack.ItemStackFactory;
import mineplex.core.pet.custom.CustomPet;
import mineplex.core.pet.repository.PetRepository;
import mineplex.core.pet.repository.token.ClientPetTokenWrapper;
import mineplex.core.updater.UpdateType;
@ -88,11 +90,11 @@ public class PetManager extends MiniClientPlugin<PetClient>
private BlockRestore _blockRestore;
private Map<String, PetType> _activePetOwnerTypes = new HashMap<>();
private NautHashMap<String, Creature> _activePetOwners;
private NautHashMap<String, Integer> _failedAttempts;
private Map<String, Entity> _activePetOwners;
private Map<String, Integer> _failedAttempts;
private Map<String, PetType> _petOwnerQueue = new HashMap<>();
private NautHashMap<String, String> _petRenameQueue = new NautHashMap<String, String>();
private Map<String, String> _petRenameQueue = new HashMap<>();
private DonationManager _donationManager;
private CoreClientManager _clientManager;
private InventoryManager _inventoryManager;
@ -120,8 +122,8 @@ public class PetManager extends MiniClientPlugin<PetClient>
_clientManager = clientManager;
_inventoryManager = inventoryManager;
_activePetOwners = new NautHashMap<String, Creature>();
_failedAttempts = new NautHashMap<String, Integer>();
_activePetOwners = new HashMap<>();
_failedAttempts = new HashMap<>();
}
public void addPetOwnerToQueue(String playerName, PetType petType)
@ -169,7 +171,7 @@ public class PetManager extends MiniClientPlugin<PetClient>
if (player != null && player.isOnline())
{
Creature activePet = getActivePet(playerName);
Entity activePet = getActivePet(playerName);
if (activePet != null)
{
activePet.setCustomNameVisible(true);
@ -424,7 +426,7 @@ public class PetManager extends MiniClientPlugin<PetClient>
UtilEnt.vegetate(pet);
}
public Creature getPet(Player player)
public Entity getPet(Player player)
{
return _activePetOwners.get(player.getName());
}
@ -433,7 +435,7 @@ public class PetManager extends MiniClientPlugin<PetClient>
{
if (_activePetOwners.containsKey(player.getName()))
{
final Creature pet = _activePetOwners.get(player.getName());
final Entity pet = _activePetOwners.get(player.getName());
//Wither Silverfish
if (pet.getPassenger() != null)
@ -494,7 +496,7 @@ public class PetManager extends MiniClientPlugin<PetClient>
{
String playerName = null;
for (Entry<String,Creature> entry : _activePetOwners.entrySet())
for (Entry<String, Entity> entry : _activePetOwners.entrySet())
{
if (entry.getValue() == event.getEntity())
playerName = entry.getKey();
@ -518,28 +520,28 @@ public class PetManager extends MiniClientPlugin<PetClient>
public void onUpdate(UpdateEvent event)
{
for (Entry<String, Creature> entry : _activePetOwners.entrySet())
for (Entry<String, Entity> entry : _activePetOwners.entrySet())
{
String playerName = entry.getKey();
Creature creature = entry.getValue();
Entity entity = entry.getValue();
if (event.getType() == UpdateType.TICK)
{
if (creature instanceof PigZombie)
if (entity instanceof PigZombie)
{
UtilParticle.PlayParticleToAll(ParticleType.LARGE_SMOKE, creature.getLocation(), 0.2f, 0.0f, 0.2f, 0.0f, 4, ViewDist.NORMAL);
if(event.getTick() % 3 == 0) creature.getWorld().playSound(creature.getLocation(), Sound.BLAZE_BREATH, 0.03f, 0f);
if(!((CraftPigZombie) creature).getHandle().isSilent())
UtilParticle.PlayParticleToAll(ParticleType.LARGE_SMOKE, entity.getLocation(), 0.2f, 0.0f, 0.2f, 0.0f, 4, ViewDist.NORMAL);
if(event.getTick() % 3 == 0) entity.getWorld().playSound(entity.getLocation(), Sound.BLAZE_BREATH, 0.03f, 0f);
if(!((CraftPigZombie) entity).getHandle().isSilent())
{
((CraftPigZombie) creature).getHandle().setSilent(true);
((CraftPigZombie) entity).getHandle().setSilent(true);
}
}
}
else if (event.getType() == UpdateType.FAST)
{
if (creature instanceof Blaze)
if (entity instanceof Blaze)
{
Location loc = creature.getLocation().clone().add(0, .5, 0).add(creature.getLocation().getDirection().multiply(-0.2));
Location loc = entity.getLocation().clone().add(0, .5, 0).add(entity.getLocation().getDirection().multiply(-0.2));
_grimReaperWings.display(loc);
_grimReaperWingsEdge.display(loc);
}
@ -548,7 +550,7 @@ public class PetManager extends MiniClientPlugin<PetClient>
PetType petType = getActivePetType(playerName);
if (petType == PetType.CUPID_PET)
{
Location loc = creature.getLocation().clone().add(0, .5, 0).add(creature.getLocation().getDirection().multiply(-0.2));
Location loc = entity.getLocation().clone().add(0, .5, 0).add(entity.getLocation().getDirection().multiply(-0.2));
_cupidWings.displayColored(loc, Color.PINK);
_cupidWingsWhite.displayColored(loc, Color.WHITE);
@ -561,7 +563,7 @@ public class PetManager extends MiniClientPlugin<PetClient>
PetType petType = getActivePetType(playerName);
if (petType == PetType.CUPID_PET)
{
Location loc = creature.getLocation().clone().add(0, .5, 0);
Location loc = entity.getLocation().clone().add(0, .5, 0);
UtilParticle.PlayParticle(ParticleType.HEART, loc, 0.25f, 0.25f, 0.25f, 0.25f, 3, ViewDist.NORMAL);
}
}
@ -581,7 +583,7 @@ public class PetManager extends MiniClientPlugin<PetClient>
String playerName = ownerIterator.next();
Player owner = Bukkit.getPlayer(playerName);
Creature pet = _activePetOwners.get(playerName);
Entity pet = _activePetOwners.get(playerName);
Location petSpot = pet.getLocation();
Location ownerSpot = owner.getLocation();
xDiff = Math.abs(petSpot.getBlockX() - ownerSpot.getBlockX());
@ -690,7 +692,7 @@ public class PetManager extends MiniClientPlugin<PetClient>
{
if (event.getEntity() instanceof Zombie)
{
if (_activePetOwners.containsValue((Creature) event.getEntity()))
if (_activePetOwners.containsValue(event.getEntity()))
{
event.setCancelled(true);
}
@ -718,7 +720,7 @@ public class PetManager extends MiniClientPlugin<PetClient>
return _activePetOwnerTypes.get(name);
}
public Creature getActivePet(String name)
public Entity getActivePet(String name)
{
return _activePetOwners.get(name);
}
@ -734,7 +736,7 @@ public class PetManager extends MiniClientPlugin<PetClient>
removePet(player, true);
}
public Collection<Creature> getPets()
public Collection<Entity> getPets()
{
return _activePetOwners.values();
}

View File

@ -16,10 +16,10 @@ import org.bukkit.inventory.meta.ItemMeta;
import mineplex.core.account.CoreClientManager;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilEnt;
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
@ -29,7 +29,6 @@ public abstract class CustomPet
protected Player _player;
protected EntityType _entityType;
protected DisguiseBase _disguiseBase;
protected int _step = 0;
private String _name;
private List<String> _lines = new ArrayList<>();
@ -43,7 +42,7 @@ public abstract class CustomPet
public void spawn(Entity entity)
{
// TODO
UtilEnt.silence(entity, true);
onSpawn(entity);
}
@ -53,11 +52,6 @@ public abstract class CustomPet
public abstract GadgetPage getPreviousStep(CosmeticManager plugin, CosmeticShop shop, CoreClientManager clientManager, DonationManager donationManager);
public DisguiseBase getDisguiseBase()
{
return _disguiseBase;
}
public void setName(String name)
{
_name = name;

View File

@ -18,7 +18,6 @@ import mineplex.core.cosmetic.ui.page.custompet.equipment.CustomPetHelmetPage;
import mineplex.core.cosmetic.ui.page.custompet.equipment.CustomPetLeggingsPage;
import mineplex.core.cosmetic.ui.page.custompet.name.CustomPetNamePage;
import mineplex.core.cosmetic.ui.page.custompet.zombie.CustomPetZombieTypePage;
import mineplex.core.disguise.DisguiseFactory;
import mineplex.core.disguise.disguises.DisguiseZombie;
import mineplex.core.donation.DonationManager;
@ -36,10 +35,9 @@ public class CustomPetZombie extends CustomPetEquipment
@Override
public void onSpawn(Entity entity)
{
// TODO
_disguiseBase = DisguiseFactory.createDisguise(entity, _entityType);
DisguiseZombie disguiseZombie = (DisguiseZombie) _disguiseBase;
DisguiseZombie disguiseZombie = new DisguiseZombie(entity);
disguiseZombie.setBaby(isBaby());
disguiseZombie.setVillager(_villager);
if (getHelmet() != null)
{
disguiseZombie.setHelmet(getHelmet());