Skip to content
This repository has been archived by the owner on Jun 29, 2023. It is now read-only.

Commit

Permalink
Mounts fixed in 1.13-1.14
Browse files Browse the repository at this point in the history
  • Loading branch information
iSach committed Aug 15, 2019
1 parent 1e294ad commit 51f3387
Show file tree
Hide file tree
Showing 49 changed files with 2,845 additions and 853 deletions.
361 changes: 181 additions & 180 deletions core/src/main/java/be/isach/ultracosmetics/cosmetics/mounts/Mount.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,184 +37,185 @@
* @since 08-03-2015
*/
public abstract class Mount<E extends Entity> extends Cosmetic<MountType> implements Updatable {

/**
* The Entity, if it isn't a Custom Entity.
*/
public E entity;

protected boolean beingRemoved = false;

public Mount(UltraPlayer ultraPlayer, MountType type, UltraCosmetics ultraCosmetics) {
super(ultraCosmetics, Category.MOUNTS, ultraPlayer, type);
}

/**
* Equips the pet.
*/
@Override
public void onEquip() {
if (getOwner().getCurrentMount() != null) {
getOwner().removeMount();
}

EntitySpawningManager.setBypass(true);
this.entity = (E) getPlayer().getWorld().spawnEntity(getPlayer().getLocation(), getType().getEntityType());
EntitySpawningManager.setBypass(false);
if (entity instanceof Ageable) {
((Ageable) entity).setAdult();
} else {
if (entity instanceof Slime) {
((Slime) entity).setSize(4);
}
}
entity.setCustomNameVisible(true);
entity.setCustomName(getType().getName(getPlayer()));
entity.setPassenger(getPlayer());
if (entity instanceof Horse) {
((Horse) entity).setDomestication(1);
((Horse) entity).getInventory().setSaddle(new ItemStack(Material.SADDLE));
}
runTaskTimerAsynchronously(UltraCosmeticsData.get().getPlugin(), 0, getType().getRepeatDelay());
entity.setMetadata("Mount", new FixedMetadataValue(UltraCosmeticsData.get().getPlugin(), "UltraCosmetics"));
getOwner().setCurrentMount(this);
}

@Override
public void run() {
try {
if (entity.getPassenger() != getPlayer()
&& entity.getTicksLived() > 10
&& !beingRemoved) {
clear();
cancel();
return;
}
if (!entity.isValid()) {
cancel();
return;
}
if (getOwner() != null
&& Bukkit.getPlayer(getOwnerUniqueId()) != null
&& getOwner().getCurrentMount() != null
&& getOwner().getCurrentMount().getType() == getType()) {
onUpdate();
} else {
cancel();
}

} catch (NullPointerException exc) {
exc.printStackTrace();
clear();
cancel();
}
}

@Override
protected void onClear() {
if (entity != null) {
entity.remove();
}

getOwner().setCurrentMount(null);

try {
cancel();
} catch (Exception exc) {
//ignore.
}
}

protected void removeEntity() {
entity.remove();
}

public E getEntity() {
return entity;
}

@EventHandler
public void onPlayerToggleSneakEvent(VehicleExitEvent event) {
if (event.getVehicle().getType() == EntityType.BOAT
|| event.getVehicle().getType().toString().contains("MINECART")) {
return;
}

String name = null;
try {
name = getType().getName(getPlayer());
} catch (Exception e) {
}

if (name != null
&& getOwner() != null
&& getPlayer() != null
&& getOwner() != null
&& event.getVehicle() != null
&& event.getExited() != null
&& event.getVehicle().getCustomName() != null
&& event.getVehicle().getCustomName().equals(name)
&& event.getExited() == getPlayer()
&& !beingRemoved) {
beingRemoved = true;
clear();
}
}

@EventHandler
public void onEntityDamage(EntityDamageEvent event) {
if (event.getEntity() == getEntity()) {
event.setCancelled(true);
}

if (event.getEntity() == getPlayer()
&& getOwner().getCurrentMount() != null
&& getOwner().getCurrentMount().getType() == getType()) {
event.setCancelled(true);
}
}

@EventHandler
public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
if (event.getEntity() == getEntity())
event.setCancelled(true);
}

@EventHandler
public void teleportEvent(PlayerTeleportEvent event) {
if (getOwner() != null
&& getPlayer() != null
&& getOwner().getCurrentMount() == this
&& event.getPlayer() == getPlayer()) {
if ((event.getFrom().getBlockX() != event.getTo().getBlockX()
|| event.getFrom().getBlockY() != event.getTo().getBlockY()
|| event.getFrom().getBlockZ() != event.getTo().getBlockZ()
|| !event.getFrom().getWorld().getName().equalsIgnoreCase(event.getTo().getWorld().getName()))) {
//clear();
}
}
}

@EventHandler
public void openInv(InventoryOpenEvent event) {
if (getType() == MountType.valueOf("druggedhorse")
|| getType() == MountType.valueOf("ecologisthorse")
|| getType() == MountType.valueOf("glacialsteed")
|| getType() == MountType.valueOf("infernalhorror")
|| getType() == MountType.valueOf("mountoffire")
|| getType() == MountType.valueOf("mountofwater")
|| getType() == MountType.valueOf("walkingdead")
|| getType() == MountType.valueOf("rudolph")) {
if (getOwner() != null
&& getPlayer() != null
&& event.getPlayer() == getPlayer()
&& event.getInventory().equals(((InventoryHolder) entity).getInventory())) {
event.setCancelled(true);
}
}
}

public void setBeingRemoved(boolean beingRemoved) {
this.beingRemoved = beingRemoved;
}

/**
* The Entity, if it isn't a Custom Entity.
*/
public E entity;

protected boolean beingRemoved = false;

public Mount(UltraPlayer ultraPlayer, MountType type, UltraCosmetics ultraCosmetics) {
super(ultraCosmetics, Category.MOUNTS, ultraPlayer, type);
}

/**
* Equips the pet.
*/
@Override
public void onEquip() {
if (getOwner().getCurrentMount() != null) {
getOwner().removeMount();
}

EntitySpawningManager.setBypass(true);
this.entity = (E) getPlayer().getWorld().spawnEntity(getPlayer().getLocation(), getType().getEntityType());
EntitySpawningManager.setBypass(false);
if (entity instanceof Ageable) {
((Ageable) entity).setAdult();
} else {
if (entity instanceof Slime) {
((Slime) entity).setSize(4);
}
}
entity.setCustomNameVisible(true);
entity.setCustomName(getType().getName(getPlayer()));
entity.setPassenger(getPlayer());
if (entity instanceof Horse) {
((Horse) entity).setDomestication(1);
((Horse) entity).getInventory().setSaddle(new ItemStack(Material.SADDLE));
}
runTaskTimerAsynchronously(UltraCosmeticsData.get().getPlugin(), 0, getType().getRepeatDelay());
entity.setMetadata("Mount", new FixedMetadataValue(UltraCosmeticsData.get().getPlugin(), "UltraCosmetics"));
getOwner().setCurrentMount(this);
}

@Override
public void run() {
try {
if (entity.getPassenger() != getPlayer()
&& entity.getTicksLived() > 10
&& !beingRemoved) {
clear();
cancel();
return;
}
if (!entity.isValid()) {
cancel();
return;
}
if (getOwner() != null
&& Bukkit.getPlayer(getOwnerUniqueId()) != null
&& getOwner().getCurrentMount() != null
&& getOwner().getCurrentMount().getType() == getType()) {
onUpdate();
} else {
cancel();
}

} catch (NullPointerException exc) {
exc.printStackTrace();
clear();
cancel();
}
}

@Override
protected void onClear() {
if (entity != null) {
entity.remove();
}

if (getOwner() != null)
getOwner().setCurrentMount(null);

try {
cancel();
} catch (Exception exc) {
//ignore.
}
}

protected void removeEntity() {
entity.remove();
}

public E getEntity() {
return entity;
}

@EventHandler
public void onPlayerToggleSneakEvent(VehicleExitEvent event) {
if (event.getVehicle().getType() == EntityType.BOAT
|| event.getVehicle().getType().toString().contains("MINECART")) {
return;
}

String name = null;
try {
name = getType().getName(getPlayer());
} catch (Exception e) {
}

if (name != null
&& getOwner() != null
&& getPlayer() != null
&& getOwner() != null
&& event.getVehicle() != null
&& event.getExited() != null
&& event.getVehicle().getCustomName() != null
&& event.getVehicle().getCustomName().equals(name)
&& event.getExited() == getPlayer()
&& !beingRemoved) {
beingRemoved = true;
clear();
}
}

@EventHandler
public void onEntityDamage(EntityDamageEvent event) {
if (event.getEntity() == getEntity()) {
event.setCancelled(true);
}

if (event.getEntity() == getPlayer()
&& getOwner().getCurrentMount() != null
&& getOwner().getCurrentMount().getType() == getType()) {
event.setCancelled(true);
}
}

@EventHandler
public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
if (event.getEntity() == getEntity())
event.setCancelled(true);
}

@EventHandler
public void teleportEvent(PlayerTeleportEvent event) {
if (getOwner() != null
&& getPlayer() != null
&& getOwner().getCurrentMount() == this
&& event.getPlayer() == getPlayer()) {
if ((event.getFrom().getBlockX() != event.getTo().getBlockX()
|| event.getFrom().getBlockY() != event.getTo().getBlockY()
|| event.getFrom().getBlockZ() != event.getTo().getBlockZ()
|| !event.getFrom().getWorld().getName().equalsIgnoreCase(event.getTo().getWorld().getName()))) {
//clear();
}
}
}

@EventHandler
public void openInv(InventoryOpenEvent event) {
if (getType() == MountType.valueOf("druggedhorse")
|| getType() == MountType.valueOf("ecologisthorse")
|| getType() == MountType.valueOf("glacialsteed")
|| getType() == MountType.valueOf("infernalhorror")
|| getType() == MountType.valueOf("mountoffire")
|| getType() == MountType.valueOf("mountofwater")
|| getType() == MountType.valueOf("walkingdead")
|| getType() == MountType.valueOf("rudolph")) {
if (getOwner() != null
&& getPlayer() != null
&& event.getPlayer() == getPlayer()
&& event.getInventory().equals(((InventoryHolder) entity).getInventory())) {
event.setCancelled(true);
}
}
}

public void setBeingRemoved(boolean beingRemoved) {
this.beingRemoved = beingRemoved;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ public MountDragon(UltraPlayer owner, UltraCosmetics ultraCosmetics) {

@Override
public void onUpdate() {
if (entity.getPassenger() == null)
if (entity.getPassenger() == null) {
clear();

return;
}

Vector vector = getPlayer().getLocation().toVector();

double rotX = getPlayer().getLocation().getYaw();
Expand Down
Loading

0 comments on commit 51f3387

Please sign in to comment.