Spider mount improvements.

This commit is contained in:
Mysticate 2015-10-08 23:18:37 -04:00
parent 90d0fcb36d
commit fb4d08931c

View File

@ -2,9 +2,7 @@ package mineplex.core.mount.types;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Map.Entry;
import java.util.Set;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
@ -13,12 +11,7 @@ import mineplex.core.common.util.UtilBlock;
import mineplex.core.common.util.UtilEnt;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.disguise.disguises.DisguiseBase;
import mineplex.core.disguise.disguises.DisguiseBat;
import mineplex.core.disguise.disguises.DisguiseChicken;
import mineplex.core.disguise.disguises.DisguiseEnderman;
import mineplex.core.disguise.disguises.DisguiseSpider;
import mineplex.core.disguise.disguises.DisguiseWither;
import mineplex.core.mount.HorseMount;
import mineplex.core.mount.MountManager;
import mineplex.core.recharge.Recharge;
@ -26,8 +19,6 @@ import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import net.minecraft.server.v1_7_R4.EntityLiving;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.block.Block;
@ -38,8 +29,6 @@ import org.bukkit.entity.Horse.Style;
import org.bukkit.entity.Horse.Variant;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.player.PlayerToggleFlightEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.util.Vector;
@ -57,8 +46,7 @@ public class MountSpider extends HorseMount
C.cWhite + "ride a cute and cuddly spider!",
C.cBlack,
C.cYellow + "Look Up" + C.cGray + " to use " + C.cGreen + "Wall Climb",
C.cYellow + "Jump" + C.cGray + " to use " + C.cGreen + "Jump",
C.cYellow + "Double Jump" + C.cGray + " to use " + C.cGreen + "Leap",
C.cYellow + "Jump" + C.cGray + " to use " + C.cGreen + "Leap",
C.cBlack,
C.cPurple + "Only available during " + C.Line + "Halloween 2015",
C.cPurple + "Purchase at " + C.Line + "www.mineplex.com/shop"
@ -154,51 +142,50 @@ public class MountSpider extends HorseMount
}
}
}
private Set<Horse> _jumpCancel = new HashSet<Horse>();
@EventHandler(priority = EventPriority.LOW)
public void doubleJump(PlayerToggleFlightEvent event)
{
Player player = event.getPlayer();
if (player.getGameMode() == GameMode.CREATIVE)
return;
if (!GetActive().containsKey(player))
return;
if (GetActive().get(player).getPassenger() != event.getPlayer())
return;
//Chicken Cancel
DisguiseBase disguise = Manager.getDisguiseManager().getDisguise(player);
if (disguise != null && ((disguise instanceof DisguiseChicken && !((DisguiseChicken)disguise).isBaby()) || disguise instanceof DisguiseBat || disguise instanceof DisguiseEnderman || disguise instanceof DisguiseWither))
return;
Horse horse = GetActive().get(event.getPlayer());
if (!UtilEnt.isGrounded(horse))
return;
_jumpCancel.remove(horse);
event.setCancelled(true);
player.setFlying(false);
//Disable Flight
player.setAllowFlight(false);
//Velocity
UtilAction.velocity(horse, 1.4, 0.38, 1, true);
//Sound
player.playSound(horse.getLocation(), Sound.SPIDER_IDLE, .4F, 1.0F);
}
// @EventHandler(priority = EventPriority.LOW)
// public void doubleJump(PlayerToggleFlightEvent event)
// {
// Player player = event.getPlayer();
//
// if (player.getGameMode() == GameMode.CREATIVE)
// return;
//
// if (!GetActive().containsKey(player))
// return;
//
// if (GetActive().get(player).getPassenger() != event.getPlayer())
// return;
//
// //Chicken Cancel
// DisguiseBase disguise = Manager.getDisguiseManager().getDisguise(player);
// if (disguise != null && ((disguise instanceof DisguiseChicken && !((DisguiseChicken)disguise).isBaby()) || disguise instanceof DisguiseBat || disguise instanceof DisguiseEnderman || disguise instanceof DisguiseWither))
// return;
//
// Horse horse = GetActive().get(event.getPlayer());
//
// if (!UtilEnt.isGrounded(horse))
// return;
//
// event.setCancelled(true);
// player.setFlying(false);
//
// //Disable Flight
// player.setAllowFlight(false);
//
// //Velocity
// UtilAction.velocity(horse, 1.4, 0.38, 1, true);
//
// //Sound
// player.playSound(horse.getLocation(), Sound.SPIDER_IDLE, .4F, 1.0F);
// }
@EventHandler
public void jump(UpdateEvent event)
{
if (event.getType() != UpdateType.TICK)
return;
for (Player player : GetActive().keySet())
{
final Horse horse = GetActive().get(player);
@ -206,6 +193,9 @@ public class MountSpider extends HorseMount
if (!UtilEnt.isGrounded(horse))
continue;
if (!Recharge.Instance.use(player, "Spider Mount Jump", 100, false, false))
continue;
try
{
Field jump = EntityLiving.class.getDeclaredField("bc");
@ -213,33 +203,20 @@ public class MountSpider extends HorseMount
jump.setAccessible(true);
boolean isJumping = jump.getBoolean(((CraftPlayer) player).getHandle());
jump.setAccessible(accessable);
if (!isJumping)
continue;
if (!Recharge.Instance.use(player, "Spider Mount Jump", 100, false, false))
continue;
//Not jumping anymore
((CraftPlayer) player).getHandle().f(false);
_jumpCancel.add(horse);
//Prevent jump effect when the mount double jumps
Bukkit.getScheduler().scheduleSyncDelayedTask(Manager.getPlugin(), new Runnable()
{
@Override
public void run()
{
if (!_jumpCancel.contains(horse))
return;
_jumpCancel.remove(horse);
UtilAction.velocity(horse, new Vector(horse.getVelocity().getX(), 0.5, horse.getVelocity().getZ()));
}
}, 5);
//Velocity
UtilAction.velocity(horse, 1.4, 0.38, .8, true);
//Sound
player.playSound(horse.getLocation(), Sound.SPIDER_IDLE, .4F, 1.0F);
}
catch (Exception ex)
{